By Roger Whitson, Andrew Mellon Fellow, Digital Scholarship Commons (DiSC)
This is the second in a series of preliminary posts about Python. Last time, we looked at why humanists would want to use Python. This time, we're going to look at IDLE (a basic Python client) and the philosophy behind Python. A short note about the zen of python before we begin. The zen philosophy added to the Python code by Tim Peters was initially intended to be a joke. However, many programmers have noted that there are significant lessons to be learned by looking at the poem. In an interview with Bill Venners in 2003, Bruce Eckel said "One of the things I find that's remarkable about Python is that it has a very even learning curve. Maybe it's not even a curve, It's kind of a straight line. Learning Python has a zen-like quality, because Python doesn't try to make the world something else." What does this mean? Python's language is designed for simplicity. It builds upon the concepts people use everyday. This is one of the reasons why so many programmers suggest Python as a first programming language. IDLE IDLE stands for "integrated development environment" and acts as the shell interface for Python programming. Just as Python is said to have been named after Monty Python (yet another reason why humanists should program with the language), Mark Lutz and David Ascher report in Learning Python that IDLE was named after Monty Python actor Eric Idle. As a terminal or shell program, IDLE displays an interface much like older DOS systems.
Like DOS, IDLE requires some basic command codes to work. Now, many people who are faced with learning how to use a shell complain about not being able to simply rely upon a graphic interface. The shell interface is both quicker to use than Windows or other forms of OS and easier to modify when programming. Here are some great resources for beginning to use your shell and learning basic commands.
- MAC OSX Terminal Basics
- Basic Command Line Utilities, Tips and Commands
- Windows CMD commands
- Documentation for cmd.exe on Windows XP
Using IDLE Apart from the basic terminal commands, IDLE has a specific process that is used in order to run Python programs.
- Select: File > Open New Window
- Type in your basic code.
- Select: "Save as" and be sure to name your document with ".py," as Python program names end with py.
- Select: "Run Module" and select "nameofpythoncode.py"
- Watch your Python code run!
Let's unpack some of the ideas in this poem. NB: Most of these programs are adapted from Paul Berry and David Griffiths's Head First Programming.
print '"Hello World!"2. Explicit is better than implicit: Python is based upon a Boolean type, which means that it explicitly and easily processes true/false statements. In the following example, where we create a short program to determine if an input = 55, true/false is expressed by if/else. Also, note how easy it is to read the code:
print("Welcome!")
g = input("I'm thinking of a number between 1-100:")
guess = int(g)
if guess == 55:
print("Yes!")
else:
print("No!")
print("Hope You Had Fun!")The same kind of explicit philosophy is embedded in the way Python parses loops. Loops are used in programming to allow users to continue to provide answers until they get the correct one. For example, here is a loop program that continues to ask if you are my cat as long as you answer no:
answer = "no"
while answer == "no":
answer = input("Are you Roger's cat Nemo?")
print("correct!")In each, the loop and the if/else statements are written separately and explicitly from the rest of the code. This is the way that Python keeps its code human-readable and, in a word, elegant. Much of the time, you can scan Python code and (if you understand the basic underlying syntax) get a sense of what the code does. In my next post, I'll continue an introduction to Python through the Zen poem, and give you some Python programs which can directly benefit humanities teachers. I will also present you with the first in a series of homework assignments! Yay! By the way, I'm using these posts to learn Python myself, so I am sure that I will be slightly off or just plain wrong from time to time. I would appreciate any suggestions that would help my code. Further, if you have suggestions for posts and topics, I'd love to hear them.
In the Blog
- The Extraordinary World of MARBL: Tusks and Teeth
- The Extraordinary World of MARBL: Civil War Cannonballs
- The Extraordinary World of MARBL: Three Dimensional Poetry
- MARBL Launches Artists' Books Showcase
- The Extraordinary World of MARBL: The McCord Latin Prize Medal
- Announcing the Emory Center for Digital Scholarship
- Summer Reading EBooks and AudioBooks
- The Extraordinary World of MARBL: Charles H. Herty Turpentine Cup
- Postcolonial Studies @ Emory
- A Beautifully Illustrated Book in the Seydel Collection


Comments
Post new comment