[Tutor] Object instance package wide with Jython 2.7
Jorge L.
dalveen at gmail.com
Thu Jun 26 17:40:39 CEST 2014
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140626/a1cee8e7/attachment.html>
More information about the Tutor
mailing list