starting repl programmatically

B

Brendan Miller

I have a python script that sets up some environmental stuff. I would
then like to be able to change back to interactive mode and use that
environment. What's the best way to do that?
 
S

Steven D'Aprano

I have a python script that sets up some environmental stuff. I would
then like to be able to change back to interactive mode and use that
environment. What's the best way to do that?

On most(?) Linux distros, `man python` is your friend. (Like all well-
behaviour apps, python should come with a man page.) `python --help` is
useful too, and will be platform independent. Both tell me that you want
to pass -i as an option to enter the interactive interpreter after
running a module or command:

[steve@sylar ~]$ python -c "print 'hello world'; x = 2"
hello world
[steve@sylar ~]$ python -i -c "print 'hello world'; x = 2"
hello world2

You can also set an environment variable to force the same behaviour. See
the help for details.
 
P

Patrick Maupin

I have a python script that sets up some environmental stuff. I would
then like to be able to change back to interactive mode and use that
environment. What's the best way to do that?
.... def default(self, line):
.... exec line in globals()
....(Cmd) s = 'The answer is probably to use %s'
(Cmd) print s % 'the cmd module'
The answer is probably to use the cmd module
(Cmd)

Regards,
Pat
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top