Is it okay to call the method "dot" every time when calling a class method?
Sorry for the somewhat obscure question. I'm really wondering if it is possible in Python not to mention the class name when you call the class methods iteratively? I want to write instead:
SomeClass.Fun1()
SomeClass.Fun2()
...
SomeClass.Fun100()
Something like:
DoWith SomeClass:
Fun1()
Fun2()
...
Fun100()
?
source to share
There are several ways to achieve this ( from SomeClass import *
, locals().update(SomeClass.__dict__())
), but what you are trying is not entirely logical:
In 90% of cases, you are not calling static class methods, but member functions that need one instance to work. You realize that the first argument self
that you usually see in methods is important because it gives you access to the instance namespace. So even in methods, you use self.my_member
instead my_member
. This is an important python concept and you shouldn't avoid it - there is a difference between local namespace and instance attributes.
However, you can make a short pen without any overhead:
my_instance = SomeClass() #notice, this is an instance of SomeClass, not the class or type itself
__ = my_instance
which can save you a lot of information. But I prefer the clarity of the stored typing (heck, vim
has good autocomplete plugins for Python).
source to share