Base conversion method or module

John Roth newsgroups at jhrothjr.com
Sun Dec 7 19:08:47 EST 2003


"Jeff Wagner" <JWagner at hotmail.com> wrote in message
news:jid7tvcfkf9hhc3vvut4gfbpl7i1g46t6o at 4ax.com...
> On Sun, 7 Dec 2003 15:45:41 -0500, "Francis Avila"
<francisgavila at yahoo.com> wrotf:
>
>
> 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.
>
> From one of my books, it says, "An import statement creates a new
namespace that contains all the
> attributes of the module. To access an attribute in this namespace, use
the name of the module
> object as a prefix:     import MyModule ...    a = MyModule.f( )" which is
what I thought I was
> doing.
>
> What am I still missing?

print BaseConvert.convert(90, BaseConvert.BASE10, BaseConvert.BASE2)

John Roth
>
> Thanks,
> Jeff






More information about the Python-list mailing list