Boost logo

Boost-Build :

Subject: Re: [Boost-build] [python] imports style
From: Anthony Foglia (AFoglia_at_[hidden])
Date: 2010-07-14 10:39:52


Vladimir Prus wrote:
> It turned out, suddenly, that I don't have much experience creating large Python
> application from scratch, so need some help on basics. Suppose I have
> tools/build/v2/build/toolset.py, which reads like this:
>
> import feature, property, generators, property_set
> from b2.util.utility import *
> from b2.util import set
>
> The modules referred to by the first 'import' line are in the same directory
> as toolset.py. Is this considered OK style, or I should do:
>
> import b2.build.feature, b2.build.property, b2.build.generators, b2.build.property_set
> from b2.util.utility import *
> from b2.util import set
>
> ? If the second form is preferrable, is there way to use 'feature.whatever' in the code,
> as opposed to 'b2.build.feature.whatever'?

(I assume your script is actually in tools/build/b2/build/toolset.py.)

I don't know what versions of Python you're targeting, but you might
want to look at relative imports.

http://docs.python.org/whatsnew/2.5.html#pep-328-absolute-and-relative-imports

Then your imports would become

from . import feature, property, generators, property_set
from ..util.utility import *
from ..util import set

-- 
Anthony Foglia
Princeton Consultants
(609) 987-8787 x233

Boost-Build list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk