Python: PEP 8 class name as variable By Admin

Which is the convention according to PEP 8 for writing variables that identify class names (not instances)?

That is, given two classes, A and B, which of the following statements would be the right one?

target_class = A if some_condition else B
instance = target_class()


TargetClass = A if some_condition else B
instance = TargetClass()


As stated in the style guide,


Class Names:

Class names should normally use the CapWords convention.

But also

Method Names and Instance Variables:

Use the function naming rules: lowercase with words separated by underscores as necessary to improve readability.

In my opinion, these two conventions clash and I can't find whic

  •  Open
  •  27-07-2016
  •  0
  •  141

Answers ( 0 )

No Answer Found.