python - How to avoid excessive parameter passing? -


I am developing a medium-sized program in Python spread in 5 modules. The program accepts command line arguments using OptionParser in the main module. Main.py The use of these options is determined later on in ways that behave in other modules (eg. A.py, b.py). As I give the user the ability to adapt behavior or program, I think I need this user-defined parameter in a method that is called main.py directly, but it is called the second A. Py:

  import ap = some_command_line_argument_value a.meth1 (p)  

method in A. Py:

  meth1 (p): # some code res = meth2 (p) # and some code w / res meth2 (p): do something with #p  

This excessive passing parameter looks useless and wrong, but I try not to think about a design pattern that can solve this problem. When I had some formal CS education (minor in my BSc during CS), I have come to appreciate only really good coding practices since I started using Python. Please help me become a better programmer!

Maybe you should organize your code into classes and objects? As I was writing this, Jimmy showed a class-installation based answer, so this is a pure class-based answer. If you want to practice only one, it will be most useful; If any chance you want to separate something differently from different times, then you should use simple object-oriented programming in Python, for example passing class examples with the property P set in class example.

  Class Eclass (object): P = none = classmathap def init_p (cls, value): p = value @classmethod def meth1 (cls): # some code res = cls.meth2 ( ) #Some more code w / res @classmethod def meth2 (CLS): # Acquisition of ac acit.p (some_command_line_argument_value) ac.meth1 () ac.meth2 ()  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -