Automatic import ?

MRAB python at mrabarnett.plus.com
Fri Mar 26 23:50:00 EDT 2010


C. B. wrote:
> At first, thank you all for your answers.
> 
> Some more details about what I'm coding and what I need...
> 
> The classes AAA and BBB are just given as examples. In fact, BBB's
> constructor accepts several parameters, meaning it can be different
> for each creation of AAA. So it can't be simply skipped from the AAA's
> one, even if there can be a default value.
> 
> Making AAA do the call to BBB is a solution, but, in that case, the
> end-user loses the reference to the used BBB instance.
> 
> Concerning the reason why I wish to avoid importing, once again AAA
> and BBB were just examples. I plan to add more classes, so AAA will
> also need CCC, DDD, and so on to work.
> 
> It takes time to write the relative importations, that's ok, but I
> think it could be more pleasant for the end-user to not have to write
> a huge list of "from mymodule import xxx" if it is possible to take
> advantage of automatic importations.
> 
Couldn't you just have:

     import mymodule as m

and then use:

     m.AAA
     m.BBB

and so on?

It's not much longer and it avoids 'magic'.



More information about the Python-list mailing list