'When instantiating a class, are there rules for not using the same name for the instantiated object as for the class itself?

Suppose I have a class in a module:

class c():
    some_var = "abc"

    def f(self):
        print("ok")

In a script, I am importing this class and using it as follows:

from my_module import c

c = c()
c.f()  # will print "ok"
print(c.some_var)  # will print "abc"

I would be doing this because of:

  1. readability for the object name; I'm not using the class itself anywhere else, if I have to come up with a different name as the classname itself it would be dubious.
  2. avoiding global variables (some_var)

Are there any rules for/against it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source