I am writing scripts for JMRI. I have run the following example in JMRI scripting environment that uses Jython2.7. The following code snippet lacks the import statements but I do not think they are relevant. Here goes.
class MyClass:
"""A Test - MyClass is a test"""
x=1
def __init__(self):
self.y = x
print 'Initialized'
def printMe(self):
print self.y
a = MyClass
print a.x,a.y,a.__doc__
In the above code snippet, I get the following error message:
Caused by: Traceback (most recent call last): File "", line 20, in AttributeError: class MyClass has no attribute 'y'
The last line prints a.x (1) before producing the error message. I have built other objects that have methods that assign Class variables to local variables. I can use them successfully with the instance.attribute form. But in this example, 'Initialized' does not print and y remains undefined.
Any ideas?
This does not instantiate a new MyClass object, it sets
ato the classMyClass. Let's see:Instead you probably wanted: