问题
below code is working fine as a python code(without gdb module), but it is not working inside 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]
})
the error is :
(gdb) source script.py
File "script.py", line 6
with x as csv_data:
^
SyntaxError: invalid syntax
file.txt is:
Mac, char, list, one
John, char, list, three
...
...
It seems there is issue with with
and as
keyword.
回答1:
gdb is probably linked against a different version of Python than whatever it is you are expecting.
You can check this using the usual Python methods, or with "ldd gdb".
Python lets you import "with" from "future" -- search for this.
来源:https://stackoverflow.com/questions/17448736/gdb-python-why-below-code-is-not-working-under-gdb