[Tutor] python 2.2 and 2.3
peter hodgson
py at humnet.ucla.edu
Sat Apr 3 01:43:31 EST 2004
OUCH! i just discovered that the function printTwice() was presumed to
be already defined in the interactive session in question: but i'm
still in the dark about the interactive syntax, and 2.3 vs. 2.2 in
general;
minutes ago i wrote:
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():
>>> 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:
>>> 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