0

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
  • can anyone please reply ? Commented Jul 4, 2013 at 16:52

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

4 Comments

could not resolve yet,i have python 3.0.1 installed.output ofldd gdb is libncurses.so.5 => /usr/lib64/libncurses.so.5 (0x0000003c29200000) libz.so.1 => /usr/lib64/libz.so.1 (0x0000003c17c00000)``libm.so.6 => /lib64/libm.so.6 (0x0000003c16c00000)``libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003c17400000)``libdl.so.2 => /lib64/libdl.so.2 (0x0000003c17000000)``libutil.so.1 => /lib64/libutil.so.1 (0x0000003c24600000)``libexpat.so.0 => /lib64/libexpat.so.0 (0x0000003c1b800000)``libc.so.6 => /lib64/libc.so.6 (0x0000003c16800000)``/lib64/ld-linux-x86-64.so.2 (0x0000003c16400000)
Then you've done something weird, since according to that your gdb doesn't include python at all.
but python is working inside it. Can you suggest me what should i do.? I can install it from scratch if required..
You can use any pythonic method to find the version. Offhand I don't know what these might be but I am sure they are documented. Or you an attach to a running gdb and use "info shared". Or there are probably other ways as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.