Two Classes In Two Files
Thomas Nelson
thn at mail.utexas.edu
Thu Aug 10 09:57:53 EDT 2006
Perhaps __init__.py has what you're looking for?
THN
dhable at gmail.com wrote:
> 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