gdb-python: why below code is not working under gdb?

隐身守侯 提交于 2019-12-12 00:27:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!