Python Class use

S Borg spwpreston at gmail.com
Tue Feb 7 15:28:30 EST 2006


 Hello,

 I am running Python on Mac OS X. The interpreter has been great for
learning the basics, but I would now like to be able to reuse code.
How do I write reusable code? I have done it "The Java way": write
the class, and save it to my home directory, then call it from the
interpreter, here is an example.

########my saved file######
class MyClass:
  def f(self):
      return 'calling f from MyClass'

#######interpreter#########
>>> x = MyClass()
>>> (unhelpful error mesages)

I hope I have clearly explained my problem. Because I
don't know the solution top this, I have to rewrite my methods
in the interpreter every single time I need to change something, and
I am quite certain that that is not the best way to do it.

Thank you very much.

S




More information about the Python-list mailing list