Page 1 of 1

Creating classes in the Jython User Library

Posted: Mon Oct 17, 2011 7:15 pm
by tomw
If you want to create some "classes" (in the Object Oriented Programming sense) in your Jython User Library, here's a template to get you started:

Code: Select all

class What:
   def __init__(self, v):
     self.x = v;
   def get(self):
     return self.x
   def set(self, v):
     self.x = v;

[Note that the "self" as the first parameter of each method is required, and that the
__init__(self, v):
is the constructor for this class.]

"Save" this and then in the Jython shell, you can do the following to check it out. Note that "z" and "m" are different instances of the class "What"....the possibilities are endless....

z=What(13)
print z.get()
13
z.set(99)
print z.get()
99
m = What(15)
print m.get()
15
print z.get()
99