[cctbxbb] Explicit import for iotbx.pdb.amino_acid_codes

Claudia Millán Nebot cmncri at ibmb.csic.es
Mon Oct 1 09:15:46 PDT 2012


Claudia Millán (cmncri at ibmb.csic.es)

Institut de Biologia Molecular de Barcelona (IBMB-CSIC)

Barcelona, Spain
Ok, thanks a lot for the suggestions. I also realised i was having some
problems with the PYTHONPATH and then other issues stop to arise. Thanks
again for a quick reply :)

Cheers,

Claudia


2012/10/1 Nathaniel Echols <nechols at lbl.gov>

> On Mon, Oct 1, 2012 at 3:29 AM, Claudia Millán Nebot
> <cmncri at ibmb.csic.es> wrote:
> > I've just started to look into the cctbx facilities, and as i'm a newbie
> in
> > both object oriented programming and in general to the system, i'm tryng
> to
> > play around and find by myself how things are working. Using the
> > cctbx.python, i realised that it is necessary to import explicitly the
> > module amino_acid_codes, while for others like atom_name_interpretation
> this
> > is done straigthforward if you do an import from a lower level (like from
> > iotbx.pdb import *). Is there some good reason because this has to be
> like
> > that?
>
> I suspect this is a Python quirk - atom_name_interpretation is
> imported at the top of iotbx/pdb/__init__.py, amino_acid_codes is not.
>  In general, however, I would recommend two rules for dealing with
> imports:
>
> 1. Always explicitly import any module you want - with the exception
> that if you do this:
>   import iotbx.pdb.amino_acid_codes
> you will also have access to iotbx.pdb as well.  In this case you
> might want to do this:
>   from iotbx.pdb import amino_acid_codes, atom_name_interpretation
> the choice of when to use "from foo import bar" versus "import
> foo.bar" is up to you, but the latter is a better idea if there is any
> ambiguity in the names of submodules (for instance, anything named
> "utils", of which there are probably a half-dozen).
>
> 2. Never use "from foo import *" - it's just a bad idea, because
> anyone else looking at the code won't be able to tell where a function
> comes from.  (Actually, we use this frequently for Boost.Python
> extensions, but we shouldn't.)
>
> -Nat
> _______________________________________________
> cctbxbb mailing list
> cctbxbb at phenix-online.org
> http://phenix-online.org/mailman/listinfo/cctbxbb
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://phenix-online.org/pipermail/cctbxbb/attachments/20121001/6d333447/attachment.htm>


More information about the cctbxbb mailing list