下面的代码作为python代码运行良好(没有gdb模块),但它不能在gdb中运行?
#!/usr/bin/env python
import csv
import gdb
list = []
x = open("file.txt")
with x as csv_data:
entries = csv.reader(csv_data, delimiter=",")
for entry in entries:
list.append({
"name": entry[0],
"type": entry[1],
"link": entry[2],
"level": entry[3]
})错误是:
(gdb) source script.py
File "script.py", line 6
with x as csv_data:
^
SyntaxError: invalid syntaxfile.txt是:
Mac, char, list, one
John, char, list, three
...
...似乎with和as关键字有问题。
发布于 2013-07-05 03:31:42
gdb可能链接到不同版本的Python,而不是您所期望的版本。
您可以使用常用的Python方法或"ldd gdb“来检查这一点。
Python允许您从"future“导入"with”--搜索这个。
https://stackoverflow.com/questions/17448736
复制相似问题