Simple Modules Question
Jeff Massung
jmassung at magpiesystems.com
Thu Apr 27 17:53:40 EDT 2000
Akira Kiyomiya wrote in message <8eaaul$16p at autodesk.autodesk.com>...
>from string import atoi # imports 'string'
> # places atoi in current namespace
>print atoi("12345") # invokes 'atoi' without module name
>string.atoi("45") # NameError: string
You didn't import "string", therefore "string" is not in namespace.
import string
print string.atoi("45") # prints 45
atoi("45") # NameError: atoi
A way around this:
import string
from string import *
Now you can use either string.atoi() or atoi() - but this is redundant.
Jeff
More information about the Python-list
mailing list