Advice on the style to use in imports

Marco Bizzarri marco.bizzarri at gmail.com
Sat Aug 30 13:30:18 EDT 2008


On Sat, Aug 30, 2008 at 4:53 PM, Eric Wertman <ewertman at gmail.com> wrote:
>> I read the PEP8 and the "importing Python Modules" article. However,
>> I'm still a little confused on what should the general rules for
>> importing modules.
>>
>> I'm showing what I used in my current project, and will accept your
>> advices on how I should change them.
>
>> import module
>>
>> and then use
>>
>> module.MyClass
>>
>> ( in case of a flat module)
>>
>> or
>>
>> from package.subpackage import module
>>
>> and then use
>>
>> module.MyClass
>>
>> (( for a package/subpackage structure ))
>
> My opinion is that this is the preffered way, generally speaking.  Not
> only does it avoid namespace issues as effbot pointed out, but it also
> makes code easier to read later.  As examples, I tend to break those
> rules frequently with these :
>
> from pprint import pprint  # Because pprint.pprint is just redundant
> from lxml import etree # Actually I guess this doesn't break the rule.
> from datetime import datetime  # This might be a bad idea... I haven't
> had problems yet though.  datetime.datetime gets on my nerves though.
>
> just my .02
>
> Eric
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Thanks Eric; your 02 cents are worthy for me ;)

Regards
Marco



-- 
Marco Bizzarri
http://iliveinpisa.blogspot.com/
http://notenotturne.blogspot.com/



More information about the Python-list mailing list