Python Forum
Can the scope of a module be expanded ? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Can the scope of a module be expanded ? (/thread-11122.html)



Can the scope of a module be expanded ? - AyushExel - Jun-23-2018

I have a module named optimizer.py which has a class optimizer. The class contains 2 static member functions. Optimizer.py looks something like this:
class optimizer:
    @staticmethod
    def gradientDescentOptimizer(input,mappings,net:nn.nn,alpha=0.001,lamb=None, epoch=100,print_at=5,prnt=True):
        #Code

    @staticmethod
    def SGDOptimizer(input,mappings,net:nn.nn,mini_batch_size=64,alpha=0.001,lamb=None, epoch=5,print_at=5,prnt=True):
        #code
To access the functions in other modules, I need to follow this syntax:
import optimizer

x = optimizer.optimizer.functionName(arguments)
I was wondering if there is a way to expand the scope of the optimizer class so that the function can be accessed by referring to the optimizer class just once, like this :
import optimizer

x = optimizer.functionName(arguments)



RE: Can the scope of a module be expanded ? - gontajones - Jun-23-2018

from optimizer import optimizer