Reputation: 67
I am a python newbie, and I've written so many lines of code in a python script. I initially started copying and pasting each line in the iPython console and I feel like it is taking forever. Is there a more efficient way to do this?
Lets say I have a script called "movie_analysis.py" saved in my current working directory. How can I ask the program to read in the file, and then execute every line in the script one after the order (i.e in the order they were written).
Thanks in advance!!!
Upvotes: 1
Views: 5360
Reputation: 20371
From the iPython console, you'd just do (assuming file is accessible in sys.path
- this would include the CWD):
In [1]: import movie_analysis
That would then run your file, and output everything within that shell as if you had run it by double-click.
Upvotes: 2
Reputation: 3526
If you're interested in running the script step-by-step, for example for debugging purposes, you can have a look at IPython Notebook. It's quite neat and interactive, you can divide your code in cells, then run the cells individually.
Another alternative of course would be to use an IDE with an actual debugger, for example Pydev, a Python IDE for eclipse. However, this might be a bit of an overkill in your situation, as it takes some time learning to use it.
If you're interested in running the entire script, I would suggest going with
$ python movie_analysis.py
as suggested by sshashank124, or import movie_analysis
.
Upvotes: 2
Reputation: 32189
Why not just execute the script. You can do it as follows from the command-line (cmd for windows or sh for unix):
python movie_analysis.py
Or instead, if you want to use selected functions
, methods
and classes
(assuming you don't have any script outside of a method that would get executed immediately), you can do:
import movie_analysis.py
from the command line
Upvotes: 1