# 使用事务 - `Connector/Python` 
+ 使用`try-except` 
  + `try`
    + 执行`DML` 
    + `commit`
  + `except`
    + `try`
      + 处理提交失败
      + `rollback`
    + `except`
      + 处理回滚失败
-------------------------------------------------------------
```
  try:
  cursor = conn.cursor()
  cursor.execute("UPDATE country SET GNP = GNP * 1.1 WHERE Name = 'Armenia'")
  cursor.execute("UPDATE country SET GNP = GNP * 1.1 WHERE Name = 'Bermuda'")
  cursor.close()
  conn.commit()
except mysql.connector.Error as e:
  print("Transaction failed, rolling back. Error was:")
  print(e)
  try:
    conn.rollback()
  except mysql.connector.Error as er:
    print("Unable to roll back. Error was:")
    print(er)
```