[Tutor] 2.2 and 2.3

peter hodgson py at humnet.ucla.edu
Sat Apr 3 01:38:11 EST 2004


[running 2.3 on a gentoo box]

i'm afraid my python 2.2 tutorial may be out of step with python 2.3;

HERE'S THE EXCERPT FROM THE 2.2 TUTORIAL

def catTwice(part1, part2):
  cat = part1 + part2
  printTwice(cat)

This function takes two arguments, concatenates them, and then prints
the result twice. We can call the function with two strings:

>>> chant1 = "Pie Jesu domine, "
>>> chant2 = "Dona eis requiem."
>>> catTwice(chant1, chant2)
Pie Jesu domine, Dona eis requiem. Pie Jesu domine, Dona eis requiem. 

HERE'S WHAT HAPPENED WHEN I TRIED TO TEST THE SUSPICIOUS  printTwice():
IS printTwice SOMETHING NO LONGER ACTIVE IN 2.3?

>>> printTwice('forty')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'printTwice' is not defined

HERE'S WHAT HAPPENED WHEN I TRIED TO DEFINE THE FUNCTION AND CALL IT:
ARE THERE NEW PROTOCOLS IN 2.3 FOR INTERACTIVE SYNTAX ?

>>> def catTwice(part1, part2)
  File "<stdin>", line 1
    def catTwice(part1, part2)
                             ^
SyntaxError: invalid syntax
>>> def catTwice(part1, part2):
...    cat = part1 + part2
...    printTwice(cat)
... chant1 = "pie Jesu domine,"
  File "<stdin>", line 4
    chant1 = "pie Jesu domine,"
         ^
SyntaxError: invalid syntax
>>> 

HERE'S WHAT HAPPENED WHEN I TRIED TO RUN THE FILE cat.py:

bash-2.05b$ python cat.py
Traceback (most recent call last):
  File "cat.py", line 7, in ?
    catTwice(chant1, chant2)
  File "cat.py", line 3, in catTwice
    printTwice(cat)
NameError: global name 'printTwice' is not defined






More information about the Tutor mailing list