0

How would I call a static method from another module/app (in Django)? For example I declare the following static method

class SomeClass (object): @staticmethod def SomeStaticMethod (firstArg, **kwargs): # do something 

and in another class I want to use it like so

SomeClass.SomeStaticMethod ('first', second=2, third='three', fourth=4) 

I tried to import, but got a NameError:global name 'SomeClass' is not defined

import myapp.SomeClass 

1 Answer 1

2
>>> from somefile import SomeClass >>> SomeClass.SomeStaticMethod('first', second=2, third='three') first {'second': 2, 'third': 'three'} 

It's also good to know that static methods are completely useless in most cases, since the module itself can be used as a namespace to the function. Thus:

def SomeStaticFunction(a, **kwargs): # do something 

And:

>>> import somefile >>> somefile.SomeStaticFunction(1, second=2, third='three') 1 {'second': 2, 'third': 'three'} 
Sign up to request clarification or add additional context in comments.

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.