beginner question, function returning object.

bambam david at asdf.asdf
Thu Feb 7 08:23:26 CET 2008


I started with ths:
------------------------------
def open_pipe():
    pipe=PIPE()
    print pipe
    return pipe

pipe=open_pipe()
pipe.parent = self.parent
print pipe
------------------------------
It didn't do what I wanted: when I printed the pipe the second time it was 
not the same object as the first time.

So I changed it to this:
def open_pipe():
    pipe=PIPE()
    print pipe
    return pipe

pipe = None
pipe=open_pipe(pipe)
pipe.parent = self.parent
print pipe

It still doesn't do what I wanted: I can't assign the parent property 
because pipe type is None.

I'm not sure enough of what I am doing to tell if I have another error in my 
code causing the problem. Is either of these examples supposed to work as 
shown? Is it clear that either example is obviously wrong?







More information about the Python-list mailing list