Advice on the style to use in imports

M

Marco Bizzarri

Hi all.

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.

The style is consistently the following:

from package.subpackge.module import MyClass

Is this an accepted way to write imports? According to what I
understood in articles, I don't think so.

If I understand it correctly, it should be:

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 ))

Thank you all for your attention

Regards
Marco
 
B

Bruno Desthuilliers

Marco Bizzarri a écrit :
Hi all.

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.

The style is consistently the following:

from package.subpackge.module import MyClass

Is this an accepted way to write imports?

Yes, BUT : it means that if package.subpackge.module.MyClass is rebound
during program execution (ie: after you imported it), your own code
won't see that change.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top