python interpreter, text editor, ide for udacity CS101

Introduction

In my spare time this summer, I’ve been working through CS101: Building a Search Engine on udacity. I’ve written critical things about the new wave of massive online courses before, in part because I’ve never finished one. That’s not exactly a fair position from which to criticize, even if it’s a reality shared by the vast majority of people who sign up for these things. And, given this week’s announcement from Coursera that a dozen universities have signed on to offer courses through their platform, a little more critical participation may be in order to see the order of things to come. Or at least the order for the 5% who finish these classes.

So, I’ve been working through CS101, answering a few questions in the forum, and getting a feel for the community that exists around the class. One question that has come up repeatedly in the forums is how to access the Python Interpreter to work on solutions for problems before entering them into the course’s interactive programming environment. (BTW, that environment is pretty nifty, and appears to run on a virtual machine that is spun up and persist per session.) There seems to be a fair amount of confusion at times one how to access Python on student’s home machine. Surprising, the python reference included on the course site never covers this. And, the instructor (Dave Evans from U.Va.) frequently references trying things out in the interpreter. I find it a bit curious that the course materials essentially assume students will do all their work on the course site, which means that code snippets don’t get saved and built upon on the student’s own machine. (It’s very easy to take the class in this way, but I think weakens it.) Of course, CS101 isn’t a programming class, but an introduction to computer science principles. That means that most students likely have no programming background, which makes the absence of a tutorial on setting up a local programming environment all-the-more unusual.

In the interest of giving back to a free course, sharing both with those taking the course, and with other first-time programmers, I figure I might as well provide a tutorial of a few options myself. I’m not a professional programmer, but picked up these bits and pieces along the way when I first started to learn some Python.

For CS101 (and similar) students, you have three main options for interacting with the Python Interpreter:

  1. In interactive mode from the command line.
  2. With an Integrated Development Environment (IDE).
  3. With a text editor.

But first…

Installing Python

A side note on which version of Python to use. The programming environment for the class uses Python 2.6.6. You can check it for yourself the next time you’re answering a question on the site. Just add this code and hit run:

import os
print os.system("python --version")

Given that the course is taught using a 2.x version, it’s highly suggested to install that on your local machine as well. Python 3.x makes a number of backwards incompatible changes to the language. This in one instance where the “latest” isn’t actually preferable.

Some operating systems have python already installed. Some don’t. Before one can work with/in python on their local machine, we have to make sure it’s there!

Easiest to hardest:

Linux

Python comes pre-installed on all the different linux distributions. If you use linux, I’m guessing you already know that! Nonetheless, to prove it to yourself. Simply open your Terminal application and enter python at the prompt:

$ python

Assuming you’re distribution isn’t too old, your version of python is likely fine for the CS101 course. If not, use your distro’s package manager to upgrade python.

OS X

Guess what! Python comes pre-installed on Mac OS X too! Open up Terminal.app and do the same as described above.

$ python

You’ll get the same. Depending on which version of OS X you’re using, you’ll likely have either 2.5.1 (Leopard), 2.6.1 (Snow Leopard) or 2.6.7 (Lion). For CS101, any three of those is fine.

If you’d like to use a different version of python DO NOT trash the default installation. That will cause real problems. Instead, follow the instructions here to install python with Homebrew.

Windows

Microsoft does not deliver its Windows product with python pre-installed. The easiest option for a Windows user is to take advantage of python.org’s binary installer. Simply go to the download page and chose the appropriate installer. This installer will provide access to python, including the at the command prompt, from your start menu. The installer will create a C:\Python27 directory. You can also simply open a command prompt and type:

c:\>; python

That will put you in the interpreter.

So, now to use the interpreter…

1. Interactive Mode

Python can be used in two different ways. Normally, one would write a script in an IDE or a text editor, an then have the interpreter run the script. In interactive mode, the interpreter evaluates each line of code as you type it in, giving immediate feedback. This is done on the command line (or prompt) as you’ve seen above.

When started, interactive mode will look something like this:

Python 2.6.7 (r267:88850, Jul 31 2011, 19:30:54) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>;>;>;

The prompt will take your input, immediately evaluate it, and return the result (if any) to the terminal:

>;>;>; print "I'm enrolled in CS101."
I'm enrolled in CS101

If you make a mistake, you’ll get back immediate feedback as well:

>;>;>; print 3+' Three'
Traceback (most recent call last):
  File "<;stdin>;", line 1, in <;module>;
TypeError: unsupported operand type(s) for +: 'int' and 'str'

Here, the error is trying to concatenate an integer and a string.

There are advantages and disadvantages to using interactive mode.

Advantages:

  • Get immediate feedback as you type a script in, including errors.
  • No need to write files to disk, and then run them. From the terminal this means not having to call the specific file like this:

    $ python path/to/your/script.py

  • Quick and easy to try something simple.

Disadvantages:

  • No syntax highlighting. You don’t get color to mark parts of your code.
  • If you make a mistake with, for example, indentation while writing a function, you’ll have to start over.
  • There’s no persistence. Once the code has run, you’ll have to type it in all over again to retry or tweak it.
  • It’s not suitable for longer scripts.

For CS101, interactive mode can be a useful way to try out solutions to simple bits of code, especially in answering Quiz questions. But, for the problem sets, the limitations noted become much more important. So, how to get persistence?

2. Integrated Development Environments

An Integrated Development Environment (IDE) is a software program that, well, integrates all the tools you would need for software development. IDEs range from very simple to highly bloated with support for many different languages, code completion, debugging, source control, and more. Most IDEs are probably overkill for CS101 students.

IDLE

For an experience most like the examples demonstrated by Dave in the course lectures, and the option to work in either interactive or normal mode, give a IDLE a try. IDLE is a very simple IDE bundled with python distributions. It offers both an interactive shell, and the ability to write scripts as files and run them from within IDLE. Moreover, in both interactive mode and normal mode, IDLE gives syntax highlighting as seen in CS101. This is very helpful, especially for making sure you close your strings in quotes! Also, in interactive mode IDLE will highlight the spot where syntax errors occur.

Errors show up in red, like a professor marking something wrong.

To write to a file, simply open a new window and start typing. To run that file, on a Mac at least, simply press F5. Output of the script will show up in IDLE’s interactive shell. Files can be saved and opened in the way you’re used to with other programs on your system. For CS101, this means you can maintain a file with all the functions that form the search engine. Or, you can maintain separate files for individual Problem Set assignments.

To open IDLE on a Mac, type idle in the terminal:

$ idle

On Windows, you can chose IDLE from the start menu, as part of the python bundle.

Many distros of Linux don’t include IDLE, but it can be installed by your package manager as either python-tools (Fedora) or idle (Ubuntu).

Other IDEs

I would argue that full-scale IDEs are overkill for CS101, especially as they usually involve build tools for languages that need to be compiled before execution (which Python does for you). Some cross-platform IDEs include Eclipse (targeted mostly at Java and C/C++ development), Apple’s Xcode (targeted mostly at Objective-C development for OSX and iOS), and NetBeans (also rooted in the Java world). Here’s a much more complete list by language.

3. Text Editors

In my opinion, text editors offer the best option for those new to programming, and especially to people like me who come from an academic humanities background. Some text editors have very high learning curves, like Vim or Emacs. Others are simple to use and quickly powerful. Text Editors tend to be very personal decisions as well, resulting in the kind of fanatical devotion that personal decisions elicit.

The workflow on a powerful text editor is still quite simple. Open a new file, enter your code, and run it from within the editor along the way, either sent to the terminal or within the editor. This may sound a lot like IDLE, but a good text editor is much more powerful. You get code folding, tab completion, line numbering, automatic indentation, some level of debugging, syntax highlighting, and some level of code templating. And not only for python, but for a number of languages. All that, without the complexity or bloat of a full-scale IDE.

I use Textmate, a program I’ve come back to many times after trying to leave it. (This post is written in Textmate with markdown.) When I start a new Unit in the class, I open two windows in Textmate — one for notetaking, and one for code. While following along with the lectures, I take notes in the one file, and start building the code snippets in the other. To try a piece of code written in Textmate, I have two options–>; CMD-R runs the code and sends the output to a Textmate pop-up window while SHIFT-CMD-R will open a Terminal window, and run the script there. There are bundles for all kinds of programming and markup languages for Textmate, each of which makes writing in the editor easier and more efficient. These instructions are particular to Textmate, and each editor will have it’s own quirks.

There are many text editor options, both free and for purchase, available for all three platforms. Some to consider:

Linux

OS X

Windows

These are only a few of many options.

Conclusion

Once you have Python installed, and have experimented with the Interactive Terminal, IDLE, and maybe a Text Editor, you should have a sandbox to play in on your own machine while working through the course. I hope that you’ll find making progress through CS101 a bit easier.

One final note, I’m frequently surprised at the number of questions asked in the forum whose solutions are very simple to find with a google or duck-duck-go or bing search. It should be taken as a truism that if you are interested in learning in the MOOC setting of a udacity or coursera course, you must be willing to hone your google foo. For MOOCs to be successful at all, the participants must approach them with a hefty sense of D.I.Y., though hopefully mixed together with a sense of community — a community of D.I.Y.’ers

About

Associate Professor of Early Latin America Department of History University of Tennessee-Knoxville

Tagged with: , , ,
Posted in programming
14 comments on “python interpreter, text editor, ide for udacity CS101
  1. [...] Black discusses his experiences in Udacity’s CS101 course, and reaches a key conclusion: It should be taken as a truism that if you are interested in learning in the MOOC setting of a [...]

  2. Michael says:

    I really appreciated this write up. Your intro was exactly what I was looking for. Worked exactly as described on my Mac. More problematic on the pc. Struggling a bit with the editor but will get it figured out. Thanks for your effort.

  3. Great info, just started CS101 and this is really helpful. Thanks

  4. peter says:

    thank you for the good info on python.
    as you, i have started at least 5 coursera online courses and finished none. they are either too theoretical (many) or they expect the student to spend inordinate time to discover how to use tools/etc needed to complete the course and/or they don’t ever provide the correct answer to assignments so you can learn from mistakes. [ps. i have degrees in engineeriing and information technology - though i'm not a programmer.]

  5. akhsan says:

    very well written

  6. Christopher says:

    Thanks for your most helpful contribution. I also applaud your Creative Commons copyright.

  7. orcmid says:

    Thanks Chad. I noticed some of the same disconnects that you did while working through CS101 Unit 1. Thanks for creating this useful guide to setting up to use Python off-line. It’s been years (somewhere in Python 1.x) since I used it and this is a great clarifier and refresher.

  8. Lee says:

    Really good write up. I took a Couresera class (intro to databases) and there was no explanation as to how to get these working on our own machine, even though they did have downloadable files. This is a really big barrier to overcome for a lot of people, and it’s great somehow has explained it thoroughly

  9. japo32 says:

    Reblogged this on Japo32 and commented:
    I’m still learning Python and this is a great introduction to using it in my system. Until now I only used the online interpreter in Codecademy:

    http://labs.codecademy.com/

    But there are actually a number of online interpreters available:

    http://www.codepad.org

    http://www.ideone.com

    http://people.csail.mit.edu/pgbovine/python/tutor.html#mode=edit

    http://portablepython.com/

    http://www.pythonanywhere.com/

    http://repl.it/#:languages

    http://www.learnpython.org/

    http://labs.codecademy.com/

    http://www.sourcelair.com/

    Python Fiddle – http://pythonfiddle.com/

  10. […] Here’s a more detailed series of instructions if you need it: http://parezcoydigo.wordpress.com/2012/07/19/python-interpreter-text-editor-ide-for-udacity-cs101/ […]

  11. japo32 says:

    Great post! Especially for python beginners like myself. I was wondering how to have it running on my windows machine.

    I included a link to your page on my blog post:

    http://japo32.wordpress.com/2013/05/18/python-interpreters-starting-to-learn-a-new-language/

  12. Kiran Chauhan says:

    Thank you…
    just started the Course….

  13. […] Mac. I used IDLE (for more details than you want about how to get everything all set up, check out this post). That allowed me to play around while Dave was talking and generally gave me more […]

  14. David says:

    Thanks for the time you put into this. For the Windows users:

    I’ve tried IDLE, Notepad ++, and NetBeans.

    It took me entirely too long to find the correct info for running my scripts from Notepad++. I also didn’t like that it has to execute a new shell windows every time you run a script.

    IDLE is amazing, as long as you can figure out how to get it to start up in the editor (options/general/Startup Preferences) instead of the Python Shell. It’s interface is strictly geared for Python programming – not a lot more to say about it. Oh, You get an “Edit with IDLE” entry in the right-click context menu for .py files. IDLE is probably the most like the web IDE we’ve been using so far. I think you may have said that already.

    NetBeans is a hefty installation – but finding the instructions for using it for Python was very easy (blogs.oracle.com/geertjan/entry/python_in_netbeans_ide_71), and once you’ve set it up you have a beautiful interface, collapsible functions, proj, ect management, and a built in interpreter window. It’s a lot to look at at first but it’s easy to get used to.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

parecer:
parecer:

Hacer juicio ú dictamen acerca de alguna cosa... significando que el objeto excita el juicio ú dictamen en la persona que le hace.

Deducir ante el Juez la accion ú derecho que se tiene, ó las excepciones que excluyen la accion contrária.

RAE 1737 Academia autoridades
Buy my book!



Chad Black

About:
I, your humble contributor, am Chad Black. You can also find me on the web here.
Follow

Get every new post delivered to your Inbox.

Join 50 other followers

%d bloggers like this: