I know the PEP-8 convention for class names is ClassName. But we often use small classes as pseudo-namespaces, enums etc. In other words, not a real class that you’re going to instantiate. We’ve opted for a lowercase naming convention for such “classes”, because they’re really a namespace/enum name.
Does anyone else have in-house styles for this, or other ways of achieving the same thing?
An example:
import urllib2
class config: # pseudo-namespace for module-level config variables
api_url = 'http://example.com/api'
timeout = 1.5
debug = True
class countries: # pseudo-enum
new_zealand = 1
united_states = 2
def func():
if config.debug:
print 'Calling func()'
return urllib2.urlopen(config.api_url)
For all enums and constants, I prefer to use capitalized versions.
It is still ok with me, if the class name is not all capitalized. Since, any way it is tied up with the enum values. I am always going to use it like
Countries.NEW_ZEALAND, which tells me that it is an enum.