0

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.

Pycz
  • 366
  • 3
  • 12
  • 2
    As long as you're consistent, any of the line continuation styles from the PEP is OK. One per line will take up a lot of vertical space, though. – jonrsharpe Aug 12 '14 at 07:28
  • 2
    possible duplicate of [Is there a recommended format for multi-line imports?](http://stackoverflow.com/questions/14376900/is-there-a-recommended-format-for-multi-line-imports) – root-11 Aug 12 '14 at 07:29
  • But maybe some of this is prefered or looks cleaner? – Pycz Aug 12 '14 at 07:29
  • @Pycz how could that be anything but opinion-based? – jonrsharpe Aug 12 '14 at 07:33
  • @jonrsharpe Ok, thanks, I just thought about some common practices... – Pycz Aug 12 '14 at 07:36

1 Answers1

2

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)
andrean
  • 6,717
  • 2
  • 36
  • 43