Python Forum
Running operations without compiling code multiple times - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Running operations without compiling code multiple times (/thread-734.html)



Running operations without compiling code multiple times - arka7886 - Nov-01-2016

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.


RE: Running operations without compiling code multiple times - micseydel - Nov-01-2016

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.


RE: Running operations without compiling code multiple times - arka7886 - Nov-02-2016

Thanks a lot !


RE: Running operations without compiling code multiple times - nilamo - Nov-07-2016

(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.