How to execute (not import) a python script from python tooltip?

I need to execute a Python script from an already running Python session, as if it were running from the command line. I am thinking about how to make source in bash or sh.

+6
python import bash module
source share
2 answers

In Python 2, the built-in execfile function does this.

 execfile(filename) 
+11
source share

If you are using ipython (which I highly recommend for interactive python sessions), you can enter:

 %run filename 

or

 %run filename.py 

execute the module (and not import it). You will get file name completion, which is great for ReallyLongModuleName.py (not for you to name your modules like that or somehow).

+3
source share

All Articles