Importing Python module from the Bash

Posted by Morlock on Stack Overflow See other posts from Stack Overflow or by Morlock
Published on 2010-03-08T12:42:11Z Indexed on 2010/03/08 12:51 UTC
Read the original article Hit count: 322

Filed under:
|
|
|

I am launching a Python script from the command line (Bash) under Linux. I need to open Python, import a module, and then have lines of code interpreted. The console must then remain in Python (not quit it). How do I do that?

I have tried an alias like this one:

alias program="cd /home/myname/programs/; python; import module; line_of_code"

But this only starts python and the commands are not executed (no module import, no line of code treated).

What is the proper way of doing this, provided I need to keep Python open (not quit it) after the script is executed? Many thanks.

© Stack Overflow or respective owner

Related posts about python

Related posts about bash