Python Forum

Full Version: Running operations without compiling code multiple times
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,
I am fairly new to Python, though I have computing experience in other languages. I have a very basic question here: I want to run operations (mathematical and plotting etc.) in the python environment but I do not want to run my code over and over again as it takes a few minutes to run. 
Now I am compiling my codes in the terminal as 'python programname.py', but once the program is complied if I want to add an extra line or make an extra plot I have to run my code again. I am sure this should not be the case, there must be someway where you can compile the code in the python environment and then do operations using the lists or variables defined in the code (without running the whole program again). It would be great, if you can help me out with this. I use mac unix. Thanks in advance.
Try using -i with Python (before your script); this will run your script and then dump you in interactive mode. Note that you won't have access to any function-local variables, you'll need to make sure any state you want access to is available after the script completes.
Thanks a lot !
(Nov-01-2016, 04:17 PM)micseydel Wrote: [ -> ]Try using -i with Python (before your script); this will run your script and then dump you in interactive mode. Note that you won't have access to any function-local variables, you'll need to make sure any state you want access to is available after the script completes.

That's some dark magic, right there.  Having never actually read the arguments to python, I would have assumed -i was the default, and that it started interactive mode.  Running a script and then giving you an interactive environment at the end of it?  Wow, that's like, magic debugging material, or something.