Exercise 0: The Setup

This exercise has no code. It is simply the exercise you complete to get your computer to run Python. You should follow these instructions as exactly as possible. For example, Mac OS X computers already have Python 2, so do not install Python 3 (or any Python).

Warning If you do not know how to use PowerShell on Windows, Terminal on OS X or bash on Linux then you need to go learn that first. You should do the exercises in Appendix A first before continuing with these exercises.

Mac OS X Do the following tasks to complete this exercise: Go to https://atom.io/ with your browser, get the Atom text editor, and install it. Put Atom (your editor) in your dock so you can reach it easily. Find your Terminal program. Search for it. You will find it. Put your Terminal in your dock as well. Run your Terminal program. It won't look like much. In your Terminal program, run python . You run things in Terminal by just typing the name and hitting RETURN. Type quit() , Enter , and get out of python . You should be back at a prompt similar to what you had before you typed python . If not, find out why. Learn how to make a directory in the Terminal. Learn how to change into a directory in the Terminal. Use your editor to create a file in this directory. You will make the file, "Save" or "Save As...," and pick this directory. Go back to Terminal using just the keyboard to switch windows. Back in Terminal, list the directory with ls to see your newly created file. OS X: What You Should See Here's me doing this on my OS X computer in Terminal. Your computer might be different, but should be similar to this. Last login: Sat Apr 24 00:56:54 on ttys001 ~ $ python Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. > >> quit () ~ $ mkdir mystuff ~ $ cd mystuff mystuff $ ls # ... Use Atom here to edit test.txt.... mystuff $ ls test.txt mystuff $

Windows Go to https://atom.io with your browser, get the Atom text editor, and install it. You do not need to be the administrator to do this. Make sure you can get to Atom easily by putting it on your desktop and/or in Quick Launch . Both options are available during setup. Run PowerShell from the Start menu. Search for it and you can just press Enter to run it. Make a shortcut to it on your desktop and/or Quick Launch for your convenience. Run your PowerShell program (which I will call Terminal later). It won't look like much. In your PowerShell (Terminal) program, run python . You run things in Terminal by just typing the name and pressing Enter . If you run python and it's not there ( python is not recognized.. ). Install it from http://python.org/download. Make sure you install Python 2, not Python 3. You may be better off with ActiveState Python especially when you do not have Administrative rights If after you install it python still isn't recognized then in PowerShell enter this: [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User") Close PowerShell and then start it again to make sure Python now runs. If it doesn't, restart may be required. Type quit() and press Enter to exit python. You should be back at a prompt similar to what you had before you typed python . If not, find out why. Learn how to make a directory in the PowerShell (Terminal). Learn how to change into a directory in the PowerShell (Terminal). Use your editor to create a file in this directory. Make the file, Save or Save As... and pick this directory. Go back to PowerShell (Terminal) using just the keyboard to switch windows. up if you can't figure it out. Back in PowerShell (Terminal), list the directory to see your newly created file. From now on, when I say "Terminal" or "shell" I mean PowerShell and that's what you should use. Warning Sometimes you install Python on Windows and it doesn't configure the path correctly. Make sure you enter [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User") in PowerShell to configure it correctly. You also have to either restart PowerShell or your whole computer to get it to really be fixed. Windows: What You Should See > python ActivePython 2.6.5.12 (ActiveState Software Inc.) based on Python 2.6.5 (r265:79063, Mar 20 2010, 14:22:52) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. > >> quit () > mkdir mystuff > cd mystuff ... Here you would use Atom to make test.txt in mystuff ... > > dir Volume in drive C is Volume Serial Number is 085C-7E02 Directory of C:\Documents and Settings\you\mystuff 04.05.2010 23:32 <DIR> . 04.05.2010 23:32 <DIR> .. 04.05.2010 23:32 6 test.txt 1 File(s) 6 bytes 2 Dir(s) 14 804 623 360 bytes free > It is still correct if you see different information than mine, but yours should be similar.

Linux Linux is a varied operating system with a bunch of different ways to install software. I'm assuming if you are running Linux then you know how to install packages so here are your instructions: Use your Linux package manager and install the Atom text editor. Make sure you can get to Atom easily by putting it in your window manager's menu. Find your Terminal program. It could be called GNOME Terminal , Konsole , or xterm . Put your Terminal in your dock as well. Run your Terminal program. It won't look like much. In your Terminal program, run python . You run things in Terminal by just typing the command name and pressing Enter . If you run python and it's not there, install it. Make sure you install Python 2 not Python 3. Type quit() and press Enter to exit python. You should be back at a prompt similar to what you had before you typed python . If not, find out why. Learn how to make a directory in Terminal . Learn how to change into a directory in Terminal . Use your editor to create a file in this directory. Typically you will make the file, Save or Save As... , and pick this directory. Go back to Terminal using just the keyboard to switch windows. Look it up if you can't figure it out. Back in Terminal , list the directory to see your newly created file. Linux: What You Should See $ python Python 2.6.5 (r265:79063, Apr 1 2010, 05:28:39) [GCC 4.4.3 20100316 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. > >> quit () $ mkdir mystuff $ cd mystuff # ... Use Atom here to edit test.txt ... $ ls test.txt $ It is still correct if you see different information than mine, but yours should be similar.

Finding Things on the Internet A major part of this book is learning to research programming topics online. I'll tell you to "search for this on the internet," and your job is to use a search engine to find the answer. The reason I have you search instead of just giving you the answer is because I want you to be an independent learner who does not need my book when you're done with it. If you can find the answers to your questions online then you are one step closer to not needing me, and that is my goal. Thanks to search engines such as Google you can easily find anything I tell you to find. If I say, "search online for the python list functions" then you simply do this: Go to http://google.com/ Type: python list functions Read the websites listed to find the best answer. Here's a screenshot of me doing this search: