Tue Sep 9
short programs with variables, loops, input/output, and all that
First : questions about anything so far?
OK, moving on. We're looking at chaps 1 - 3 next, so please read them.
The notes here talk about getting your software and workflow in place,
and then looking at coding. (These notes will likely be more than we
can do on Tuesday, and if so we'll continue Thursday.)
editing, command line, python
Discuss where you are at the practical bits :
- installing software (editor, python)
- creating hello.py with an editor
- running "python hello.py" from the command line
I will run on Windows today, to show the recommended
workflow there. (You'll have to excuse my Microsoft-ineptness
at time, probably.)
The software I recommend installing for Windows is
- Notepad++ 6.6.9
- Gitbash (i.e. git) for Windows, which has a reasonable unixy Terminal including tab completion.
- IPython package , via Anaconda .
- Choose python 2.7 graphical installer.
- Set it to be your default python. Otherwise, take the defaults.
- You probably want the 32 bit version (depending on your hardware and OS.)
- See http://docs.continuum.io/anaconda/install
- If you install it just for you, the executable is in e.g. c:\Users\mahoney\Anacond
When I did this on Windows7 running under Parallels on my mac air on Sep 7 2015,
installing GitBash first and then Anaconda, the path was modified appropriate automatically
and it all "just worked". Your mileage may vary.
If you hit problems, ask for help - there are many variations of
systems and hardware issues that might get in the way.
Once everything is installed, my workflow is
- Create a folder for your work this term, something like python_fall2015/
- In that folder, eddit and/or create a file that ends with .py, using Notepad++ , e.g. "hello.py".
- In that folder, right-click and choose "GitBash" to launch a shell.
- type "python" (to get an interactive prompt) or "python filename" (to run a program).
On a mac or unix machine, typically python and bash (called "Terminal" on a mac) are already installed.
command line $PATH (unix) or %path% (windows)
One "gotcha" with using a command line is that
even if the software is installed somewhere on
your system the command line "shell" may not
be able to find it. So there are two things
you need to find and connect: the python program,
and the hello.py file you've created with the editor.
The command line settings are stored in "environment variables".
One of these, called "path", holds a list of folders to look in
for the program names that you type at the prompt
# Mac Terminal (bash shell)
$ echo $PATH
...
# Windows command prompt
> echo %path%
...
The python program needs to be in that list,
or you won't be able to run it from the command prompt.
This is sometimes an issue when getting (say)
GitBash to find the Anaconda python.
This site gives a recipe for setting the path for python.org's
python, so that GitBash can find it.
Feedback?
computer & software overview
To understand what programming is and how it works,
it's helpful to have good mental
model of how the parts of computer systems
function.
We have a book in the library that does
a nice job with the ideas behind all this :
Code: The Hidden Language of
Computer Hardware and Software
Let's walk through the basic concepts :
- data : everything (text, numbers, code, audio, video, ...) is binary "bits", interpreted different ways.
- hardware : from inner (fast, small) to outer (slow, big) : cpu, cache, memory, disk, network ; monitors/keyboard/speakers/printers for in/out ; various "pipes" and "buses" for moving data about
- software : layers of services built on one another : kernel, operating system, libary, process, application, GUI
Other buzzwords :
- shell, bash, command prompt, command line : all roughly the same
- compiler, programming language, (python, java, basic, perl, ruby, C, ...), source code : what we're learning about this term, eh?
Walk through what specifically happens when we "run" a "program" in python, and how that differs from other languages like C.
coming next
This week: chapter 2 & 3 in the text :
- how to go about programming
- variables, their names, and the values that go in them
- loops
- some input and output
The next assignment from those two chapters is posted - jump in and let me know
how it's going.
chap 2
software development cycle
- understand problem (can be harder than you think)
- create specs : inputs? outputs? (be very specific)
- choose algorithm: what does it do?
- implement (write the code)
- test and debug (again, can be harder than you expect)
- maintain (if used over time, needs will usually change)
- aside: python code in wiki pages
- does this have any bugs? Hmmm.
... and we'll pick this up on Thursday.