gdb-python:为什么下面的代码不能在gdb下工作? [英] gdb-python: why below code is not working under gdb?

查看:135
本文介绍了gdb-python:为什么下面的代码不能在gdb下工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码在python代码中工作正常(没有gdb模块),但它不在gdb内部工作?

  #!/ usr / bin / env python 
import csv
import gdb

list = []
x = open(file.txt)
用x作为csv_data:
entries = csv.reader(csv_data,delimiter =,)
用于输入条目:
list.append({
name:entry [0],
type:entry [1],
link:entry [2],
level:entry [3]
})

错误是:

 < code $(gdb)source script.py 
文件script.py,第6行
with x as csv_data:
^
SyntaxError:无效语法

file.txt是:

  Mac,char,list,one 
John,char,list,three
...
...

看来存在问题关键字。



您可以使用通常的Python方法或使用ldd gdb来检查它。



Python允许您从future中导入with - 搜索此内容。 >

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.

解决方案

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.

这篇关于gdb-python:为什么下面的代码不能在gdb下工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆