Importing module of data dicts and constants

Fredrik Lundh fredrik at pythonware.com
Sat Nov 25 09:32:18 EST 2006


Nathan Harmston wrote:

  > I ve got a single module which I m using to contain a lot of
> dictionaries, constants, general information, which are used by
> various other modules. However I can't seem to access them:
> 
> in data.py
> _SEQTYPE_DNA = 0
> _SEQTYPE_RNA = 1
> _SEQTYPE_PROT = 2
> _seqType = { "DNA":_SEQTYPE_DNA, "RNA":_SEQTYPE_RNA, "PROTEIN":_SEQTYPE_PROT }

why do they all start with an underscore?

> but in test.py

> from data import *

as clearly stated in the documentation, "from import *" consider names 
that start with an underscore to be private.

also see:

     http://effbot.org/pyref/reserved-identifier-classes.htm

> I think I m doing something incredibly wrong/stupid here....

well, you're only supposed to be using "from import *" if you know
what you're doing, so if you need to ask, you've obviously broken
the rules ;-)

</F>




More information about the Python-list mailing list