python2.5 x python2.6 in interactive mode
Thomas Jollans
thomas at jollans.com
Mon Jun 7 17:42:39 EDT 2010
On 06/07/2010 01:43 PM, Alan wrote:
> Hi there,
>
> I have a code with a 'exit()' at the end. We run it usually as:
>
> python2.5 -i code.py
>
> and if everything is fine, the 'exit()' is called and there's no
> interactive terminal.
You could instead do something like this:
try:
# ...
except:
import code
code.interact()
you could even create a stub.py module, like this:
import runpy
import code
import sys
try:
mod_name = sys.argv[1]
mod_globals = {}
sys.argv = sys.argv[1:]
mod_globals = runpy.run_module(mod_name, run_name='__main__',
alter_sys=True)
except BaseException, e:
mod_globals['e'] = e
code.interact(mod_globals)
and run it with python2.6 stub.py code_module
though it's probably more useful to just use pdb.pm() instead of
code.interact here... the debugger is your friend!
>
> However, doing the same above with python2.6 and I got:
>
> amadeus[2738]:~/TMP% python2.6 -i thread_ping.py
> Traceback (most recent call last):
> File "thread_ping.py", line 42, in <module>
> exit()
> File "/sw/lib/python2.6/site.py", line 334, in __call__
> raise SystemExit(code)
> SystemExit: None
> >>>
>
> So, everything is fine except that it ended up in the interactive
> python terminal. Is there a way of having the very behaviour I have
> with python 2.5 for my code in python 2.6?
>
> Many thanks in advance,
>
> Alan
>
> --
> Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
> Department of Biochemistry, University of Cambridge.
> 80 Tennis Court Road, Cambridge CB2 1GA, UK.
> >>http://www.bio.cam.ac.uk/~awd28 <http://www.bio.cam.ac.uk/%7Eawd28><<
More information about the Python-list
mailing list