[Tutor] def problem

Kalle Svensson kalle@gnupung.net
Mon, 11 Jun 2001 21:12:43 +0200


Sez Ron:
> I'm having problems with "def". Here's what I put in and save as "test122"
> 
> def here():
>     print "hello"
>     print
>     print "that was a space"
> 
> This is what I get.
> 
> >>> import test123
> >>> here()
> Traceback (most recent call last):
>   File "<pyshell#1>", line 1, in ?
>     here()
> NameError: name 'here' is not defined
> >>> 

This is not a problem with def, just a misunderstanding of import. <wink>
You have to access the names of the test123 module like:

>>> import test123
>>> test123.here()
hello

that was a space
>>> 

You could also use the "from x import y" statement:

>>> from test123 import here
>>> here()
hello

that was a space
>>> 

Peace,
  Kalle
-- 
Email: kalle@gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]