当前位置: 动力学知识库 > 问答 > 编程问答 >

python - How should I indent the import of many classes from single module

问题描述:

If I need import some Class1, Class2, ... , ClassN from module module, how should I indent it?

from module import (

Class1,

Class2,

...

ClassN

)

or maybe

from module import (

Class1, Class2, ...,

..., ClassN

)

Can't find any information in PEP specification.

网友答案:

If the number of classes you import is higher, you should consider importing only their parent module, and access the classes through it, like:

import module

module.Class1
module.Class2

On the other hand, if there really aren't that many classes, but still exceeds the 80 char limit, I usually import using the following style:

from module import (Class1,
                    Class2,
                    Class3,
                    Class4)
分享给朋友:
您可能感兴趣的文章:
随机阅读: