AUTHORED BY
Andrew Cross
DATE
08/26/2014
CATEGORY
WORD COUNT
166
REV
0
REFERENCE IMAGE
NOTES
  1. Google teaches a "class" on Python
  2. Running a script from the command line (IPython) can be done with %run
SOCIAL REACH

I ran into a hiccup working through Google’s Python Class. I came across the need to run a script with command line flags:

./wordcount.py {--count | --topcount} file

Since I’m using the Spyder IDE with the built-in IPython console, I could running this script from the command line like so:

%run wordcount.py --count alice.txt

The problem with running the script this way is that the IDE completely ignores any breakpoints I have set, so debugging isn’t possible. Alternatively, using Spyder’s “Run” button observes the breakpoints, but ignores the command line flags!

Using Spyder to Run a Python Script

Using Spyder to Run a Python Script

The Solution

The solution is actually pretty obvious. It involves modifying the Run Settings, as shown in the picture below.

Run a Python Script in Spyder with Command Line Options

Run a Python Script in Spyder with Command Line Options

Now, the “Run” button will consider the command line options. The script runs as desired with the ability to debug the code!

Profile picture of Andrew standing at the Southern-most point in the United States.
Andrew Cross

Andrew is currently a mechanical R&D engineer for a medical imaging company. He enjoys good food, motivated people, and road biking. He has still not completely come to terms with the fact he will never play center field for the Kansas City Royals.