To avoid duplicated work: This a cross posting of a SE question: http://programmers.stackexchange.com/questions/246161/object-attribute-needed-at-package-level-with-python
Let's consider the following scenario. We have a Python 2.7 package which serves as a library for some scripting projects. We have a `jli.py` and a `server.py` modules within our package: ___init__.py: from jli import JLI from server import Server jli.py: class JLI(object): def __init__(self) pass def setup(self): # In order for this to work I actually need to set two attributes of JLI instances based on input self.foo = foo server.py: class Server(object) def __init__(self, name) self.name = name def some_operation(self) # stuff to be done with JLI.foo now I want to write the following script: from package import JLI, Server cli = JLI() cli.setup() -> cli.foo is available to use serv01 = Server('01') serv01.some_operation() with an arbitrary number of classes like `Server` most of them, needing `JLI.foo` after `setup()` is called in order to work. I don't want to use setup twice in the script or doing imports and so forth. I don't know how to implement this ... any help will be greaty appreciated.
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor