Two Classes In Two Files

dhable at gmail.com dhable at gmail.com
Wed Aug 9 15:24:40 EDT 2006


I just started working with Python and ran into an annoyance. Is there
a way to avoid having to use the "from xxx import yyy" syntax from
files in the same directory? I'm sure it's been asked a million times,
but I can't seem to find the answer.

For example, I have two classes stored in separate files as such.

File: one.py
========
class One:
  def methodA(self):
    print "class One"
  def methodB(self):
    print "class One"


File two.py
========
from one import One

class Two(One):
  def methodA(self):
    print "class Two"

if __name__ == "__main__":
  x = Two()
  x.methodA()
  x.methodB()

When I run the Two.py file, I get the expected output but I'd like to
eliminate the from line in two.py.




More information about the Python-list mailing list