下面的代码作为 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 syntax
file.txt 是:
Mac, char, list, one
John, char, list, three
...
...
似乎with
和as
关键字有问题。