Python class method. Is there a way to reduce the number of calls?

I play with Python and I created the class in a different package from the caller. In this class, I added a class method that is called from my main function. Again, they are in separate packages. The class method call line is much longer than I thought it would be from the examples I saw elsewhere. These examples tend to call class methods from the same package, which shortens the syntax of the call.

Here is an example that I hope will help:

In the 'config' package:

class TestClass : memberdict = { } @classmethod def add_key( clazz, key, value ) : memberdict[ key ] = value 

Now in another package named 'test':

 import sys import config.TestClass def main() : config.TestClass.TestClass.add_key( "mykey", "newvalue" ) return 0 if __name__ == "__main__" : sys.exit( main() ) 

You can see how "config.TestClass.TestClass.add_key" is much more verbose than calling regular class methods. Is there any way to make it shorter? Maybe "TestClass.add_key"? I'm defining something in a weird way (case of a class matching python filename?)

+4
source share
1 answer
 from config.TestClass import TestClass TestClass.add_key( "mykey", "newvalue" ) 
+13
source

All Articles