Getting Started
Standard beginning : any questions about anything so far?
- Basically, I expect you to act like responsible adults.
nuts'n'bolts
Dylan (dylanm@marlboro.edu) is the CS tutor this term - stay tuned for details of where/when.
You can also email me (mahoney@marlboro.edu) with questions
or setup times to work individually as needed.
The textbook is available at the bookstore, and there are other copies around (the library, Sci217 usually, friends, ...).
software tools : editor + command prompt + python (ideally)
Your first task is to get to the point where you can write and run a python program on your computer. (Or, if you don't have a computer, on the lab computers. If so, please do check in with me.)
It's common for people taking this course to have very different experience levels.
- If getting up and running is easy for you, great. I encourage you to brush up on your current skills, and try to stretch a bit wherever you feel you need it.
- If all this is brand new, that's OK: get help as needed, and plug away at getting all the pieces in place.
The basics look like this :
- Set up a folder on your computer for your work for this semester. (If you're not sure how to do this, check in with me or Cory for assistance soon.)
- Choose a texteditor (see above) and create a python program (i.e. hello.py; see below). Don't use a word processor - you'll get extra funky stuff in your source file, and you won't have nice color syntax hints.
- Get to a command prompt (how varies with your computer; see wikipedia: command line interface; called "Terminal" on Mac) and type "python" to see if your computer already has it. If not, install it from one of the choices at http://www.python.org/getit/ . Windows : I recommend GitBash ... see the recipe from interactivepython , below.
- Install Python - see my resources page. Run python on your program in the terminal.
- Ask for help from me, Dylan, Logan, or any of the CS students if you're confused.
We'll use version python version 2.7 this semester.
On Windows, getting python up and running and using it may be more convoluted than on a Mac or Unix system, because it isn't already built-in by default. Try this recipe :
or ... Python in the cloud
In other words, running in your browser which is connected to someone else's computer which is doing all the work.
These cloud environments are relatively new but are becoming more common. Most are designed to accomplish something fairly specific, i.e. execute short snips of code as a teaching tool, deploy a dynamic web site, or do scientific visualization. For this course, some of the assignments could be done easily this way; others (those that use Zelle's graphics library or other data files) would be trickier.
Here are a few of them you may want to check out.
or ... Jupyter Notebook via Anaconda
One sweet (and scientific friendly) python environment is the Jupyter Notebook, which runs a browser-based-but-local IPython. You can get it as part of Anaconda's python installation suite.
I use this environment often for annotated and graphical pythonic workbooks.
... on a chromebook
Googling "python chromebook" turns up
which has some options.
Resources
Python has extensive online documentation, tutorials, and even browser consoles and editors where you can execute python in the cloud. See the
resources page for lots of options.
The most important one is
If you have a specific question or error, don't underestimate the power of just googling for what you want to know - often that will jump you to the right place in the documentation, or turn up someone else with that issue.
A First Program
Here's the "hello world" program in python :
# This file is hello.py - a first short program in python.
print "Hello world"
From a terminal program (the $ is the prompt waiting for you to type), in the same folder as the file (see below for more)
$ python hello.py
Hello world!
You should have this working this week. Again - you need help, ask, don't wait and get behind.
command line vs GUI
A bit more on the command line.
Mac/Unix:
# Mac: The application is /Applications/Utilities/Terminal
# Unix: depends; look for "Terminal" in application menu
$ cd /folder/name # change directory
$ ls # list directory
$ pwd # print working directory
$ python file.py # run python program in file.py
Windows
# XP: Start ... Programs ... Accessories ... Command Prompt
> cd \folder\name # change directory
> dir # list directory
> cd # show current directory
> python file.py # run python program in file.py
running python
And a bit more on running python.
In general, programming can be done with text editors and the command line (which is the "old school" way I'll be showing you) or with an IDE (Integrated Development Environment). Some people swear by IDEs. My opinion is that they hide the details of what's going on, and when you're starting out (like in this class), it's good to understand those details.
The difference between an editor and an IDE is essentially how much can be done from within the application to compile, run, debug etc the program. Or in larger settings, the programming project. If you think you'd rather try an IDE, the list at
http://wiki.python.org/moin/PythonEditors may be helpful.
On a lab mac, run python by launching the "Terminal" program in Applications/Utilities. Then get to right folder, and type "python".
Do make sure you know what folder you're in while you're working with a python file or at the command prompt. If nothing is working, there's a good chance that you're just in the wrong folder.
You can also run python and edit files over the network, by logging in to cs.marlboro.edu - the same machine that's serving up these web pages. The "ssh" (secure shell) program can connect you to your_username@cs.marlboro.edu (after I give you an account; ask if you want one).
One particularly powerful python implementation that comes
in a "just install it" format is ipython.org's ("interactive python").
The
anaconda download
will give you the whole shebang. I'll show some examples
of what that looks like in later classes, though usually I'll just be
using the generic python at the terminal.
Also, all of this can be done on the lab computers or those in Sci 217. (I think - I'll have to confirm that.)
an example
Demo the chaos program
- type it in, save to a folder, run it.
discuss overview of computers and terminology
- memory / disk / cache
- source code
- compiler
- process
- shell
- operating system
- library
- network
random
chap 2 topics
... if we get that far
- First: have a plan
- comments
- variables
- variable names
- assignment statements : "x = 5" ; "x = x + 1"
- range(n) : a list of things
- "for" loops
- python "gotcha's" (every language has it's quirks) :
- input("prompt") # do use ()
- print "stuff" # don't use ()
- other functions :