Original Imic Manual Mac Silver Puck

Mac OS 9: The Missing Manual is a warm, witty, jargon-free guide to the Macintosh platform's popular system software. Written with enough patience for the novice and enough depth for the power user, the book includes the shortcuts, surprises,. Some Special Mac Instructions. I will assume a version of Max OSX of at least High Sierra (10.13 or later). Upgrades are free. This document supersedes any conflicting instructions in the tutorial itself. As versions of Python and operating systems have changed, some old usage instructions get out date.

  1. Original Imic Manual Mac Silver Puck Case
  2. Original Imic Manual Mac Silver Puck Recipe

I will assume a version of Max OSX of at least High Sierra (10.13 or later). Upgrades are free.

This document supersedes any conflicting instructions in the tutorial itself.As versions of Python and operating systems have changed, some old usage instructions get outdate. I am keeping all the latest system information in this document.

I will use Python 3.7+ to mean the current version of Python, with version number at least3.7.3.Make sure you have the latest recommended version installed from https://www.python.org/downloads/.Download the pkg file and double click to execute.

The normal place for you to have my examples folder is under your home folder,which has the same name as your Login ID. If you are just creating a login ID,it will save some hassle in Chapter 4, if your login ID doesnot have a space in it.'Andy' or 'AndyHarrington' would be fine for me, but

'Andy Harrington'

would bomb the server in Chapter 4.

If You Have a Blank in your Login ID

The local server program central to chapter 4 bombs withfolder paths with a blank in the name.

If you have a blank in your Login ID, it is not so easy to change.Instead make a folder outside of your home folder:

  1. Go to the Macintosh HD folder and create a folder (like 'comp150')with no blank in it! You will need administrative privileges,and will be prompted to enter your password.
  2. I suggest that you move my examples folder, or just the sub-folderwww so it is under your new folder. For Chapter 4test my examples and add your work there.

Wherever you plan to unzip my Python examples folder fromhttp://anh.cs.luc.edu/python/hands-on/3.1/examples.zipyou need to make sure thatmy www folder, and any other folder where you put later .cgi filesdoes not have a blank in its name,or any folder in which it is a sub-folder.If you have a 'comp 150' parent folder, you might rename it 'comp150'.

Editing by Default

You will be working mostly with files ending in .py -- Python source files.Most of the time you will be editing them and running them in IDLE, so the bestdefault behavior when opening a file with extension .py is to have it open inIdle 3.7+. If you can double click on a .py file in my examples,and Idle opens as soon as you have installed Python 3.7+, great - you should skip the rest of this section.

If Idle did not open, here is how to change the default behavior:

  1. In the Finder go to a file in my examples folder with the .py extension.and right click or control click on it. Select Get Info.
  2. In the Info window that pops up, In the drop-down menu for Open with:,you want to seeIDLE.app on the top line (meaning it is already the default).You may possibly also see the version listed if you have several. Presumablyyou are going through this because you do not see IDLE.app there.
  3. You may see IDLE.app lower down in the list of options. Then select it there.
  4. If you did not see IDLE.app in the drop-down list at all:
    • Select Other....
    • A window of apps pops up.Toward the bottom is a check box for 'Always Open With'. Check it.
    • If you do not see a Python folder in the list, just below the bottom ofthe page change Recommended Applications to All Applications
    • Now you should see a Python 3.6 folder. Open it and select Idle.app.
  5. The Info window should become active again. Be sure that now underOpen with: you see IDLE.app.
  6. Under the IDLE.app you should see a button, Change All....So that you never have to go through all these steps again, be sure to clickthat button. A confirmation window will pop up. Select Continue.
  7. Now you can close the Info window, and you should be able to open all .pyfiles directly in Idle for editing by double clicking in the Finder!

Starting The Idle Shell

Options

  • Use Spotlight with idle.app. If there is more than one version of idle.app,make sure you choose one for Python 3.7+.This is a good approach the first time to check thatIdle is properly installed.The disadvantage of this approach is that Idlestarts in your Documents folder (more below).
  • You may open a Python file ending in .py into an Idle Edit window byselecting it directly in a Finder window if the defaults are set asdiscussed above. Instead youcan Ctrl-click on the file, select Open With, and then choose Idlefor Python 3.7+.

Opening Files from Inside Idle

You may select Open in the File menu inside Idle.

Caution: the behaviordepends on what window is active at the moment - a file editing window or the Shell window:

  • If the active window is some file editing window when you use the IdleFile menu to open a file,your search will start in the same folder as the file you are editing(generally the desiredbehavior).
  • If you select File Open fromthe Shell window, the starting folder depends on how you started Idle:
    • If you started Idle from Spotlight or opened a file in the Finder,then your search will start in your Documents folder,probably not what you want.
    • If you started Idle from a terminal, you open to the directory whereyou gave the command to start Idle.

Saving Files

If you have modified a file and want to save it under a new name, make surethe file is in the active window (the shell window is not active), go tothe File menu and Save. It is easiest ifyou save all files in the same folder: my examples folder (except in Chapter 4). The default is to save the file as a Python file, ending in '.py'. If that is not what you want, note the Format field at the bottom of the Save dialog and change it to All Files.

Running Program Files

Make the Edit window for the file you want active by clicking in its window,then go to the Runmenu and select Run Module. Note the F5 shortcut key.

The graphics window likely comes up behind an unneeded Console Window. You canclose the console window, and click on the graphics window title bar tobring it to the front. If you run the program from inside Idle,

Remember this is the time when it is critical not to have .cgi files under a folderwith a blank in the name. See the earlier discussion.

CGI Files on My Server Do Not Work!

The administrators of my server changed the security parameters, so now thelinks to run cgi scripts on my server do not work. Just use the onesthe the local server on your machine, as discussed below. Do not click on Ch4 links to URL's at anh.cs.luc.edu.

Opening .cgi Files in Idle

By convention the server programs that you will be writing end in '.cgi'.That is not an extension that is automatically associated with Idle for editing.You will want to change the association. Do it the same way as the instructionsabove for getting .py files to open in Idle by default, except choose a .cgi file in my wwwfolder, and go through the same procedure.

Setup: Making CGI Scripts Executable

Make sure you have completed the previous section successfully beforegoing on to this section.

A complication on a Mac, like any Unix derived system, is that programsthat you run must be explicitly marked executable. (On Windows it follows fromthe file extension, like .exe.) The examples/www folder may nothave the cgi files marked executable (nor have several other technical things right).

Original Imic Manual Mac Silver Puck

The example program examples/www/CGIfix.py is needed to give directUnix/Mac/Linux executability to CGI files for Chapter 4.

Remember the www directory cannot have a directory name in the path down tothat directory with a space in it. If you got that wrong,go back to the previous section.

In the finder open your www directory. You can open CGIfix.py in Idle and run it.Note the comment that the file cgiServerScript was created. You need thatin the next section:

Running CGI Scripts

Important! Particularly if you later copy in a CGI script from a Windowsmachine, or if you create any new cgi script in the www directory, make sureit becomes executable (and possibly fix some other technical things) bylaunching CGIfix.py again.

Original Imic Manual Mac Silver Puck

If you forget this, and the file is not executable,nothing happens in the browser when you try to run it,and the error message in the server window is very unhelpful -it says '... File not found ...'. Make sure you make new CGI filesexecutable (with CGIfix.py)!

If you create andedit a cgi file inside Idle, remember you cannot run it from insideIdle. After editing, be sure to check the syntax,using alt/option-X.You should close the file in Idle before running CGIfix.py.

When you want to test a cgi script, you first need to have launchedthe local CGI Server, howeveropening and running localCGIServer.py in Idle does not work!

Instead make sure all your files needed by the cgi server(.html, .cgi, localCGIServer.py) are in thesame folder as the file created there by fixCGI.py: cgiServerScript.(Distinguish the separate file for Windows, startServer.cmd: Ignore that.)

In the Finder double click on cgiServerScript.This should start a window announcing the start of the CGI server.(Then you can leave it running for as longas you want to test .cgi files in the same folder.) Do not have severalcopies of the CGI server running at once!

At this point you can do all the web server based activities in Chapter4, with the only extra step being the running of CGIfix.py when youcreate a new CGI script in the www directory, or copy one from Windows.There are a number of steps: be sure you carefully go through the list in the tutorial.Remember, html files calling a cgi file, and cgi files used directly are only run in your web browserwith a URL starting with localhost:8080/. Otherwise nothing dynamic happens.

To use the Hands-on Python Tutorial, the information above should be sufficientto get your Mac usage going. Terminals are quite useful in other contexts:There are many things that can bedone from such a window that cannot be done from the Finder or with an App.

If you would like a bit more background, read on.

Navigation

OS X and Unix (from which OS X is derived)have a concept of the current directoryDirectory is the older term for folder from when there were not pictures offolders in a graphical interface.

You start in your home directory. My login id is anh, so my home directory is/Users/anh. Substitute your login id for your machine.The slashes separate nested directories. The top hard drivedirectory is /, which contains the directory Users which containsusers' home directories, like my anh. A shorthand in a terminal for your home directoryis ~.

The terminal shows a system prompt when it is ready for user input. The promptcan be set to show many things. The end of the prompt is often $.Before that is often some indication of your current directory, like ~ forthe home directory.

If you want to see the full name of the current directory enter the command

pwd

Single commands are executed after you press the Enter key.

You can list the contents of a directory with the ls command.Unix tends to abbreviate words in commands.

If you use the ls command in your home directory, you should seeDesktop, Documents, Downloads, ... listed.

To change directory, use the cd command followed bythe directory you would like to change to. You can use the fullname of the directory starting with /, but more commonly you just indicatewhere to go relative to where you are now. Desktop is a subdirectory ofyour home directory, so from the home directory you can just enter

Original Imic Manual Mac Silver Puck Case

cd Desktop

Here is a sequence on my computer after starting a terminal (skipping mostof the output from ls:

Notice that the last use of the cd command used directory ...That stands for the parent directory, the directory containing thecurrent directory.

If you unzipped the examples from your Desktop, you can go there with

cd ~/Desktop/examples

Alter this if you put your examples somewhere else!

It is useful to be in the examples folder. If you start Idle from there,it is easy to open any of the example programs.

Original Imic Manual Mac Silver Puck Recipe

When scripts are directly called by the operating system, they lookfor the proper interpreter to read them. Our scripts are set up to look forpython3.

To start a regular python program from the current directory, like hello_you.py,you would enter a command with python3 and the file name, like

python3 hello_you.py

Instead of shifting to a separate Shell as in Idle, the output appears right in theterminal window.