how to change current working directory while using pdb within emacs

D

duyanning

I have written a pyhton script that will process data file in current
working directory.
My script is in an different directory to data file.
When I debug this script using pdb within emacs, emacs will change the
current working directory to the directory which include the script,
so my script cannot find the data file.

I think this is the problem of emacs because when I start pdb from
console directly, it will not change current working directory to the
one of script being debugged.

please help me.
thank you.
 
D

Diez B. Roggisch

duyanning said:
I have written a pyhton script that will process data file in current
working directory.
My script is in an different directory to data file.
When I debug this script using pdb within emacs, emacs will change the
current working directory to the directory which include the script,
so my script cannot find the data file.

I think this is the problem of emacs because when I start pdb from
console directly, it will not change current working directory to the
one of script being debugged.

Just issue

import os
os.chdir('whatever')

inside the pdb-session. Unfortunate, but should work.

Diez
 
R

R. Bernstein

duyanning said:
I have written a pyhton script that will process data file in current
working directory.
My script is in an different directory to data file.
When I debug this script using pdb within emacs, emacs will change the
current working directory to the directory which include the script,
so my script cannot find the data file.

I think this is the problem of emacs because when I start pdb from
console directly, it will not change current working directory to the
one of script being debugged.

please help me.
thank you.

pydb (http://bashdb.sf.net/pydb) has an option to set the current
working directory on invocation. For example, from emacs I can run:

M-x pydb --cd=/tmp --annotate=3 ~/python/hanoi.py 3

And then when I type
import os; os.getcwd()

I get:
'/tmp'

Inside pydb, there is a "cd" command saving you the trouble of
importing os; the "directory" command can be used to set a search path
for source files. All same as you would do in gdb.

Begin digression ---

The --annotate option listed above, is similar to gdb's annotation
mode. It is a very recent addition and is only in CVS. With annotation
mode turned on, the effect is similar to running gdb (gdb-ui.el) in
Emacs 22. Emacs internal buffers track the state of local variables,
breakpoints and the stack automatically as the code progresses. If the
variable pydb-many-windows is set to true, the each of these buffers
appear in a frame.

For those of you who don't start pydb initially bug enter via a call
such as set_trace() or debugger() and do this inside an Emacs comint
shell with pydb-tracking turned on, issue "set annotation 3" same as
you would if you were in gdb.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top