2

First, I am fully aware about PEP8, but sometimes it isn't very clear about how should you name things.

Let's assume we have ABC as an abbreviation.

  • Module should be named: abc
  • Class inside the module should be named: Abc or ABC? (not sure)
  • Instance variable should be named abc
# abc.py CONSTANT = "foo" class Abc(object): pass # test.py import abc print abc.CONSTANT abc_ = abc.Abc() # oops, if I use `abc` will lose ability to access abc.FOO ? 

If you have a constant inside the abc module, you may want to access it using abc.CONSTANT from outside but if you also have the instance with the same name it will not be clear?

If there a clean way to solve this kind of problem? Is the solution different if instead of an acronym you just have a simple word?

Note: Abc() class acts most of the time as Singleton, so for this reason I wasn't able to find another name for the instance.

2
  • 1
    Usually one module is not limited to a single class in Python, so you can avoid naming problems there already. Try to group common class objects in a more general module. Commented Oct 27, 2011 at 11:47
  • for Singletons the naming convention [className]Instance is often used. E.g: abcInstance Commented Oct 28, 2011 at 9:24

2 Answers 2

1

Module: abc Class: Abc

Instance: the instance can be named like the class, but it is definitively not required. In your case, I'd give the variable a name describing the instance to avoid the naming clash!

Example:

class Car: pass audi = Car() myCar = Car() myBrothersCar = Car() 
Sign up to request clarification or add additional context in comments.

1 Comment

Instance names should use underscore as delimiter.
0

Class name could be Abc or ABC, depending if it's an abbreviation or a plain name.

Example with abbreviation: CRCCheckerTool.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.