Re: Advice on the style to use in imports



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
.



Relevant Pages

  • Re: Loss of Precision in DateTime
    ... How are you verifying it? ... DateTime - it can't physically be stored without the Time although it may ... If it's showing that way client side, ... > // Snip set db access obj ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Date format
    ... select * from #tmp ... > This will not work because the fiel I'm loading the data> into is a datetime datatype. ... >>If you want the time portion also, you want to use> different style like 100. ... How can I have this showing the actual time ...
    (microsoft.public.sqlserver.programming)
  • Re: Use of Interval Datatype
    ... error in the wrong place (the interval column when it was the datetime ... '11:19:03' to DATETIME HOUR TO MINUTE ... showing 5 digits for the years). ...
    (comp.databases.informix)
  • Re: Use of Interval Datatype
    ... error in the wrong place (the interval column when it was the datetime ... '11:19:03' to DATETIME HOUR TO MINUTE ... showing 5 digits for the years). ...
    (comp.databases.informix)
  • Re: Use of Interval Datatype
    ... error in the wrong place (the interval column when it was the datetime ... '11:19:03' to DATETIME HOUR TO MINUTE ... showing 5 digits for the years). ...
    (comp.databases.informix)