IT 116: Introduction to Scripting
Class 2
Course Requirements
Course Work
New Material
Microphone
Readings
If you have the textbook you should read Chapter 1,
Introduction to Computers and Programming,
from the textbook, Starting Out with Python.
Homework 1
Remember, homework 1 is due this Sunday by 11:59 PM.
You will find it here.
Trouble?
Has anyone had any trouble registering for this class or anything else?
Today's Class
Today I will show you how to use the IDLE program and
exlain it's two parts.
I will also show you how to use FileZilla to copy files from your
machine to pe15.
Course Requirements
Unix Account
- In this class you will be writing short programs in the Python computer language
- You will create these programs on your computer
- But I cannot see what's on your machine
- To allow me to score your programs you must copy them to
pe15 ...
- which is a Linux computer on the CS department network
- To work on pe15 you must have a Unix account
- Each each of you must have your own Unix account ...
- which is your identity when you are connected to pe15
- Each account has a password that you must not share
- To create an account go to
http://www.cs.umb.edu/~ghoffman/linux/cs_portal.html#creating_unix_account.
- and follow the instructions you will find there
Your Home Directory
- Each account has a
home directory
that belongs to you and you alone
- A directory is what you probably call a "folder"
- A directory holds files and other directories
- When you first connect to pe15
you will be inside your home directory
- You are the only one who can make changes in this directory
- Inside your home directory is the entry it116
- This is a link to your class directory
Your Class Directory
- If you have registered for this class ...
- as I asked you to do in Class Exercise 1 ...
- you will have a class directory for this course
- The class directory is in a special place in the filesystem ...
- that makes it easy for me to find your work
- All work for this class must be copied to your it116 class directory
- I will show you how to do this later in this class
- If you have not registered for this class on the CS Portal ...
- go to
https://portal.cs.umb.edu,
log in ...
- click the check box for my section of this course, and click submit
Help with Unix Account or Class Directory
- If you have difficulty creating an account or a class directory ...
- you must get help immediately
- You will not be able to do any work in this class ...
- until you have both
- You can see me after class or during office hours
- You can contact me on Zoom during office hours
- To see how to do this go
here
- Or you can contact the
Class Assistant
- Whatever it takes, you must create a Unix account and
a class directory
Course Work
Assignments
- There are two types of assignments for this course
- Class Exercises
- Homework assignments
- In the Class Exercise you simply copy some Pyhton statements ...
- into a file on your machine
- This will give you some practice writing and fixing Python programs
- For homework assignments you write your own Python files ...
- following instructions in the assignment
- There is a Class Exercise for each class
- There is one homework assignment each week
- All Class Exercises and homework assignments are due on the Sunday after they
are assigned
- If you miss the deadline you can still submit your scripts until the following
Saturday ...
- but you will lose 2 points for each day you are late
Submitting Assignments
- The assignments ask you to write Python programs
- You will create these files on your machine and test them to make
sure they work
- If they don't work, you must fix the code to correct the problem
- If you need help with this you can
- See me after I finish talking in class
- Come to my Zoom Office hours
- Contact the Class Assistant
- Ask another student in this class
- The program file must be copied to the correct directory
inside your class directory
- Today's Class Exercise will ask you to create two directories
inside your class directory
- An hw directory for
homework assignments
- An ex directory for Class Exercise
files
- For each homework file you must create an new directory for it
under the hw directory
- The name of this directory must be "hw" followed by the homework
number
- You must do the same for each Class Exercise file
- So working on an assignment has two phases
- First you create the file on your machine and get it to work
- This you create a directory for it in either the
hw or ex
directories ....
- and copy the file to the correct directory
Software for the Class
- You need different software for each phase of your work
- For the first phase you need to download Python
- You find instructions
here
- Python comes with a program called IDLE
- You can use IDLE to run Python statements
- and create Python programs
- For the second phase you need FileZilla
- You will need FileZilla to create a directory for the assignment ...
- and to copy your file to that directory
- You will find instructions
here
- If you want to run your program on pe15.cs.umb.edu
you need an
SSH client
- The SSH client allows you to log in to a Unix machine from your computer
- If you have a Windows machine see
Connecting to a Unix machine from Windows
- If you have a Mac see
Connecting to a Unix machine from MacOS
New Material
Files
- In order to do anything in this course you have to know about about files
- A file contains data and is linear
- That means it has a beginning and and end
- Like a piece of string
- Files exist on hardware like hard drives and thumb drives (SSDs)
- These devices are called long term storage
- They store the files you create ...
- so you can use them later
- Any file you create on such devices will not disappear ...
- unless you delete it
- You create a file whenever you take a picture, save a Word document or send an email
- All the information that computers use is contained in files
- The programs you write for this course will be stored in files
Directories (Folders)
- The disk drive on your computer probably has hundreds of files
- The Unix machine we will be using for this course has even more
- It is very important that files are well organized ...
- or you will not be able to use the data that you create
- To organize your files you need to create directories ...
- which are also called folders
- The purpose of a directory is to hold files ...
- and other directories
- There is one special directory at the top
- On Unix machines this is called the root directory
- Every file on the machine is contained in this top directory ...
- or a subdirectory of the top directory ...
- or a sub-subdirectory ...
- and so on
- You can create as many directories as you want
- If you drew a diagram of all the directories on a machine ...
- it would look like a pyramid
- The top directories of a Linux machine might look like this
Working With Files
- You will create a file containing Python code for each assignment
- Both Class Exercises and homework assignments
- You will create these files on your machine
- But you must remember where you put them
- If you are careless and forget where you put a file ...
- or put it in the wrong place ...
- all your hard work will be lost until you find it
- Files never disappear ...
- unless you delete them
- If you can't find a file you created, it isn't gone
- It's just in the wrong place
- Most computers these days have a Documents directory
- You should create a python directory
inside Documents ...
- and save all your Python files there
- When your code runs properly you need to copy it to
pe15 ...
- which is a Unix machine on the CS network
- You will do this using a program called FileZilla
- But you must put them in the right directory on
pe15 ...
- or my collection scripst will not be able to find them
Types of Programming Languages
Python
- Python was conceived in the late 1980s
- It was first implemented in December 1989 by Guido van Rossum in the
Netherlands
- There are two versions of Python currently in use
- Python 2 was released in October 2000
- Python 3 is the latest version of Python
- Unfortunately, scripts written in Python 3 will not always work in Python 2
- And vice versa
- We will be using Python 3 in this course
- The Python design philosophy emphasizes code readability
- It tries to express concepts in fewer lines of code than languages such as C
- The core philosophy of Python is spelled out in the document
"PEP 20 (The Zen of Python)"
- It includes the following statements
- Beautiful is better than ugly
- Explicit is better than implicit
- Simple is better than complex
- Complex is better than complicated
- Readability counts
Downloading Python
- Go to
https://www.python.org/downloads/
and download the latest version of Python
- This will create a Python directory on your machine
- Inside this directory you will find an application named IDLE
The IDLE Program
- We will be using IDLE extensively in this class
- But IDLE has two different parts
- The interpreter
- The editor
- Each part has its own window ....
- and does different things
- When you first run IDLE you are in the interpreter window
- This window is used for learning and experimentation
- You type a Python statement inside the window ...
- hit Return or Enter ...
- and the interpreter tries to run the line
- The interpreter window does not create files
- For that you need the editor window
- Each window has its own set of menus ...
- which are similary ...
- but different
Running IDLE
- Open IDLE
- You will see a window like this
- You are now running the Python interpreter
- The three > signs,
>>>, are a prompt
- It is the interpreter's way of saying it is ready for you ...
- to type a Python statement
- Let's write a Python statement that will print a simple message
- When you hit Enter or Return ...
- the interpreter will run the statement
- The statement has printed the text inside the parentheses ...
- and issued a new prompt ...
- to say it is ready for your next statement
- When you work in this window ...
- you are talking directly to the Python interpreter
- This is called running Python in
interactive mode
- You type a Python statement ...
- and the python interpreter in IDLE executes it
Syntax Highlighting
- Notice that different parts of the text appear in different colors
print appears in purple
- That means
print is function
- The "Hello world!" inside the parenthesis appears in green
- It is a string of characters
- The output of the print statement appears in blue
- Different words mean different things
- And they appear in different colors
- This is called
syntax highlighting
- It is a feature you will find in most text editors used by programmers
- Syntax highlighting can make it easier to find mistakes in your code
Creating a Python Script
- If you click and drag down to to "New File" in the File menu ...
- you will get a new window
- Notice that there is no >>>
prompt in this window
- That's because you are not running the Python interpreter in this window
- Instead you are running the Python editor
- This is the part of IDLE you use to create Python files ...
- that you will uplaod to pe15
- These Python files are sometimg called scripts ...
- which means text files containing statements in the Python
lanuage
- When you type Python statements inside this window ...
- the text will appear with the same highlighting colors ...
- as in the interpreter window
- But if you hit Enter or Return you just go down to the next line
- The Python statement is not executed ...
- like it was in the interpreter window
- You can run the script you created
- But only if you first save the file
- To do this, go to the File menu and click and drag to down to Save
- This will bring up a dialog box
- But here you have to be careful
- You have to save it in the right directory ...
- or you will have a hard time finding it later ...
- when you need to copy it to the Unix machine
- I suggest you first create a python
directory inside your Documents directory
- Save all your scripts in this python
directory ...
- so you will know where to find them when you move them to
pe15.cs.umb.edu
- I have already created a python
directory
- So I will select that directory
- Now I have to give the script file a name
- And save it
- When I do, you can see the filename ...
- at the top of the editor window
- The file has the name hello.py
- All Python files have to have a .py extension
- But I did not type it in when I named the file
- The editor automatically supplied the .py extension
Fixing Errors in a Script
- Sometimes when you run a Python script you get an error
- When this happens you will see a big red error message ...
- in the interpreter window
- The last line of the error message is the most useful
- It says that the script has a typo
- The word "print" is misspelled
- All you have to do is go back to the editor window ...
- and fix the spelling
- Then run the script again ...
- to make sure it works
- When learning a computer language your code will often produce
errors
- But you will make fewer mistakes as you go through this course
Changing a Python Script
- What if you want to change a script you have already written?
- The first thing you need to do is run IDLE
- This will bring up the interpreter window
- In the File menu click and drag down to Open
- Select the python directory
- Then select the file and double click
- The file will appear inside an editor window
- This windows allows you make any changes you need
IDLE Has Two Different Parts
- IDLE is a single program ...
- that has two different components
- The first part allows you to write a single Python statement ...
- hit Enter or Return ...
- and have the Python interpreter run that statement
- This happens in the first window you see when you open IDLE
- In this window you are talking directly to the Python interpreter
- The second part is the editor
- In this window you write your Python programs ...
- and save them to a directory on your computer
- After you have saved them ...
- you run them in the interpreter window ...
- to see if they work properly
Python in Class Exercises
- The first several Class Exercises have two parts
- First, I ask you to type Python statements directly into the IDLE
interpreter window
- This will give you a chance to see how they work in Python ...
- and give you immediate feedback when you make a mistake
- In the beginning you will make a lot of mistakes
- But you will get better as you go along
- This is good practice for you
- But I cannot see what you have done
- So I can't assign you a score
- That is why the second part asks you to create script ...
- in the IDLE editor window ...
- run it to make sure it works ...
- and copy it to pe15.cs.umb.edu
- On pe15.cs.umb.edu I can run your script ...
- and give it a score
Using FileZilla
- In order to move your Python scripts to
pe15.cs.umb.edu
you will need to use FileZilla
- When you open FileZilla you will see a window like this
- At the top of the window are four input boxes you must fill in
- Host
- Username
- Password
- Port
- Host is the network name of the machine you are connecting to
- Here you should enter pe15.cs.umb.edu
- In the next box, enter your Unix username
- The third box is for your password
- Enter 22 in the last box
- Then click the QuickConnect Button
- The first time you do this, you will see this
- Click Save Password and OK
- When you do you will see the following
- This is a security check
- The alert box is saying that this is the first time you have connected here
- Click Always Trust this Host to proceed
- But if you see this message in the future something is terribly wrong ...
- and you had better contact the operator at operator@cs.umb.edu
- Normally you just click OK
- Then you should see something this
- The top pane shows the connection steps ...
- with several Status lines
- If there is a problem it will show up in red here
- The area below shows 4 panes
- Two on the left and two on the right
- The leftmost two panes show your machine
- The rightmost show the Unix machine
- In each set, the topmost pane allows you to select a directory
- And the bottom-most shows you what is inside that directory
- Above each set of panes are lines that shows was directory you are in
- The leftmost line has the label "Local site:"
- The righmost is labeled "Remote site:"
- Local site is your machine
- Remote site is pe15
- You will normally be using FileZilla to move files from your machine on the left ...
- to the Unix machine on the right
- Now you need to find your it116 directory on
pe15.cs.umb.edu
- First click on your home directory
- Then scroll down until the it116 directory comes into view
- When you double_click on the it116 directory ...
- the two right hand panes change
- The bottom right pane shows what is in the it116 directory
- If you right-click in the white space in this pane ...
- You will get a menu that allows you to create a directory
- Click on "New Directory" and a dialog box appears
- You need to change "New directory" to "ex
- Then click OK
- This will create the ex directory
- Double-click on the ex directory ...
- to enter that directory
- And repeat the above procedure to create an ex2 directory
- Enter the ex2 directory by double-clicking on it
- Now you need to locate the file you want to copy
- If you followed my sugggestion ...
- its should be in a python directory ...
- inside your Documents directory
- Click and drag the ex2.py file ...
- from the bottom left pane ...
- to the bottom right pane
- This is what you should see
Today's Class Exercise
- The Class Exercises give you hands on experience with Python
- The exercise asks you to run Python in interactive mode ...
- and to create the ex2.py script
- You do this on your own machine
- But the script must be copied to the correct directory on the Unix machine
pe15.cs.umb.edu
- Follow the procedure I showed you above to do this
Class Exercise
Attendance