Two Classes In Two Files

Max M maxm at mxm.dk
Wed Aug 9 15:36:23 EDT 2006


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.

Probably none that are better.

1:
import one
class Two(one.One)

2:
put both classes in the same file.


It's just the way it is. Why worry about it?


> 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.
> 


-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science

Phone:  +45 66 11 84 94
Mobile: +45 29 93 42 96



More information about the Python-list mailing list