python - What are some Pythonic ways to share variables with objects defined in a module? -


I am creating a module where there are many different objects, which need to be controlled by multiple variables.

If it was, then I would pass the objects into an indicator / variable / object, which I want to see, the variables in the application need to be changed, and the objects in the module will "see" new Values.

In the module foo.py:

  square foo (object): def __init __ (auto, varToWatch): self.varToWatch = varToWatch def DoSomething (print): Print Self.varToWatch  

In the application, bar.py:

  import foo x = "before" y = foo.foo (x) y. This definitely does not work, because what does the original value of x (or the context of x's original value) do? ) Is stored in Y  

Therefore, I will try ...

  1. Pass a global name, and name the global name by foo. None, because in place of the global application, not in the module
  2. To make a global use in Fu namespace, but I do not know how to address that location by variable name, instead of importing it * is importing from foo * it is painful to change Will happen.
  3. Make a dictionary in the module and pass the objects in the module to the name of any key in the dictionary. Manipulate the content of the dictionary from the application. Actually, I'm defining a new global space and sticking the variable in it. I do not see any reason that this will not work, but it seems unclear to me, do I just have to be unfamiliar with Python?

    I am not getting such a beautiful solution, which is used to see me easily with a dragon, so I suspect that I am missing something

    Suggestions?

    TIA, - Tim.

    How to insert control variables in a separate module - say, Settings < / Code> - and a different import settings ? You can then see settings.bar and settings.quux from foo import * to to close your main namespace. ;-) You can also use a global object to store your settings, mostly with the same effect.

    Of course, with such problems, you will be surprised that a import Foo for the reconstruction of things will not help things long ... knowing the problem It is impossible to do without justice, however, so I will give you this problem.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -