Chapter 2: Python Basics
In the following examples we'll be using a couple of programming things which are simple enough that, should you not be familiar with them, you might be able to figure out from the context. While the experienced programmers will tap their feet impatiently for this to finish, and the newbies are struggling to pick their dicts from their strings: a very short overview of the stuff you're missing.
-
Conditional statements: if a condition is met: execute a specific block of your script.
if 1+1 == 2:
print "still true"
else:
print "oops"still true
-
Compound statements: for each item in this list: execute a seperate block of your script.
for item in [1, 2, 3, "a"]:
print item1
2
3
"a" - Assignment: this is basically setting something to a new value, or attaching a name to something.
a = 10
print a10
- strings: text, letters, words, are called strings and they live between quotes. In order to allow quotes in strings you have several quote alternatives:
# examples of strings
a = "a string"
b = 'a string too'
c = 'a "string" too'
d = """a triple quoted string - but still just a string."""
e = '''a triple quoted string - but still just a string.''' - numbers: whole numbers, decimal numbers. You don't need to do anything special to make them, just write them.
# examples of numbers
a = 1900
b = -239345
c = 1.349683
d = 0 - lists: sequences can be written between brackets. You've seen one earlier. Lists are powerful things to keep stuff in order. Some objects can behave like lists. List objects have useful methods to manipulate them.
# examples of lists
aList = [4, "a", 2, 1]
aListInAList = [ [1, 2], [3, 4] ]
print len(aList)
sort(aList)
print aList4
[1, 2, 4, 'a'] - dictionaries: these are similar to lists, but rather than just store a sequence, a dictionary stores a key: value pair. In order to get the value, you need to provide the key. Dictionaries are written between {braces}. Some objects can behave like dictionaries. Dictionary objects have useful methods to manipulate them. While lists have their sequencential order, dictionaries don't, something to remember when you're iterating.
# examples of dicts
aDict = {"key": "value", 100: 200}
print aDict.keys()
print aDict.values()
print aDict.items()
print len(aDict)[100, 'key']
[200, 'value']
[(100, 200), ('key', 'value')]
2 - tuples - sequences between parentheses, rather than square brackets. Tuples are very much like lists, except that you can't really change them. For instance a tuple can't sort like a list can.
# examples of tuples
aTuple = (1, 2, 3)
aTuple = ("a", "b", "c")
And that's really all we're going to say about this. Figure out the rest yourself.
More step by step sections:
- 00: RoboFab Step by step: An overview of step by step explanations of common procedures and objects.
- 01: Editors: Where to use RoboFab, where to edit.
- 03: Font object, Info object: Introduction to Font and Info objects, with examples.
- 04: Glyph object and Pen object: Introduction to Glyph and Pen objects
- 05: Kerning object and glyph building: Introduction to the Kerning object, and a closer look at building glyphs from parts.
- 06: Interpolation: Scripting for interpolation
- 07: Production: Scripting for production
- 08: NoneLab: Adventures in NoneLab, scripting outside the box
- 09: Dialog Kit: Interface toolkit for FontLab
- 10: Printable manual: This documentation, formatted for print, all in one file.

