Base conversion method or module
Fredrik Lundh
fredrik at pythonware.com
Sun Dec 7 18:40:46 EST 2003
Jeff Wagner wrote:
> I found the Python cookbook recipe you were referring to. It is as follows:
(what's wrong with just posting an URL?)
> I am getting an error when I import this module and call it.
>
> #!/usr/bin/python
>
> import BaseConvert
> print BaseConvert.convert(90,BASE10,BASE2)
>
> Name Error: name 'Base10' is not defined.
>
> This probably has something to do with namespaces which was biting me
> a while ago. I thought that since the 'Base' definitions were global to this
> module (BaseConvert.py) by being defined outside the function (convert),
> that when I imported this module, they would be global, too.
in Python, "global" means "belonging to a module", not "visible in all
modules in my entire program"
> What am I still missing?
change the call to use BaseConvert.BASE10 and BaseConvert.BASE2
to learn more about local and global names, read this:
http://www.python.org/doc/current/ref/naming.html
</F>
More information about the Python-list
mailing list