Tutorial: Python Programming 101

A quick note: Tips on scripts

When you are writing a script in Vizard you should be as precise as possible. When a situation calls for brackets, make sure you use brackets. When a situation calls for indentation, make sure you use tabs. And when you refer to a variable, make sure you use the same name every time.  

 

Let's create an error in our script and see how Vizard responds. Add the following line to your script and run the script:

 

print ostrich

 

Your error should read in the output window:
 

Traceback (most recent call last):

  File "<string>", line 11, in ?

  File "scences.py", line 20, in ?

    print ostrich

NameError: name 'ostrich' is not defined

 

This line produced an error because we don't have a variable 'ostrich' in our script. Vizard identifies the error line by highlighting it in line 20. It also gives you a description of the problem. Oftentimes, this printout gives you a line number for the problem. If you want to find a specific line number, go to "Line Number" under the View menu.

 

Another useful tool in writing scripts is commenting out segments of code. Placing a '#' symbol in front of a line of code tells Vizard not to run that line. For example, place a '#' symbol front of the line we just added and run the script:

 

#print ostrich

 

We did not get an error this time because Vizard did not read the line. Commenting out is a good way to include documentation within your scripts.  To comment out several lines, just highlight those lines and go to “Comment Region” under the Edit menu. Alternatively, you can use the keyboard shortcut by highlighting the lines and pressing Alt-3.

 

As you will see in the following pages of this tutorial, indentation is an important part of writing scripts.  For Vizard to understand the indentation it must be done in tabs (and not in character spaces).

 

So when you are completing this tutorial and your script is using indentation, go to the View menu and select “Whitespace” or the “Indentation Guide”. These will reveal where your tabs are and show you how your code is lining up. To indent a chunk of script, highlight it and choose “Tabify Region” from the Edit menu.

 

 

 

 

 

Speaking Vizard's language

A quick note: Tips on scripts

Looping logic

If-then logic

Functions

An example

More about Python