Hi

My cryptic subject is perhaps not sufficient - I'll try to make it a little 
better:
Assume you'd like to write something like: 

import someClass
x = someClass.open("someFile")

Here '.open' should read in the data and initialize the instance - with or 
without calling __init__. 
How is this to implement? Up to now I rather wrote something like x = 
someClass(somePrepFunction("someFile")) where the return value of 
somePrepFunction was used 
to initialize x or called the conventional 'open' within __init__. But is there 
no direct approach like 
in my pseudo-code?
My problem is that if I simply define open as a method of someClass (with 
def open(self,file_name): 
        #somecode
        pass
) all I get is:
TypeError: unbound method open() must be called with someClass instance as 
first argument 
(got str instance instead)
Which is perfectly understandable. But what is a possible workaround? (Instead 
of 'open' I could, 
of course, better use some other keyword which is no Python keyword.)

Any hints?

Thanks a lot in advance.
Christian
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to