我想将 Python2 代码翻译成 Python 3。这很简单,但它不起作用
import sys
import MySQLdb
import Cookbook
try:
conn = Cookbook.connect ()
print "Connected"
except MySQLdb.Error, e:
print "Cannot connect to server"
print "Error code:", e.args[0]
print "Error message:", e.args[1]
sys.exit (1)
conn.close ()
print "Disconnected"
我在终端得到了这个
2to3 harness.py
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Can't parse harness.py: ParseError: bad input: type=1, value='print', context=('', (9, 0))
RefactoringTool: No files need to be modified.
RefactoringTool: There was 1 error:
RefactoringTool: Can't parse harness.py: ParseError: bad input: type=1, value='print', context=('', (9, 0))
为什么?