开发者

Pydevd with virtual code or (source provider)

we´re having python source code stored in a sql database, the code is build together to a virtual python module and can be executed. We wan开发者_JAVA技巧t to debug this modules but then of course the Eclipse debugger host doesnt know where to find the source code for these modules.

Is there a way to provide pydevd with the location of the source code, even if that means to write down the files to disk?


Write it to the disk and when doing the compile pass the filename for the code (and, when you're not in debug mode, just don't write it and pass '<string>' as the filename).

See the example below:

from tempfile import mktemp

my_code = '''
a = 10
print a
'''

tmp_filename = mktemp('.py', 'temp_file_')
with open(tmp_filename, 'w') as f:
    f.write(my_code)
obj = compile(my_code, tmp_filename, 'exec')
exec obj #Place breakpoint here: when stepping in it should get to the code.


You need to add module to PYTHONPATH in Eclipse project settings and import it using the standard Python import. Then PyDev debugger should find it without any problems.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜