This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: source command for python scripts


El miÃ, 05-11-2008 a las 11:13 -0700, Tom Tromey escribiÃ:
>     def invoke(self, arg, from_tty):
>         self.dont_repeat()
>         execfile(arg)

Just FYI, this command will not work as is, and it made me scratch my
head for a good while. When you try to source a Python script which
defines a new command, psource fails with:

NameError: global name 'ReverseBacktrace' is not defined

The funny thing is that the same script works when sourced directly with
"python execfile('reverse-backtrace.py')". Due to limitations in the
Python language which I'm not sure I understood yet, you have to change
the execfile call in the invoke method to:

    execfile(arg, globals ())

Then psource will work as expected. This is apparently a common pitfall
with execfile in Python, and you will find users struggling with it if
you search the web about the problem. I found an explanation in:

http://bytes.com/forum/thread21061.html

-- 
[]'s
Thiago Jung Bauermann
IBM Linux Technology Center


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]