[Tutor] Pass By Reference
Bill Mill
bill.mill at gmail.com
Tue Apr 12 19:46:12 CEST 2005
On Apr 12, 2005 12:20 PM, Gooch, John <John.Gooch at echostar.com> wrote:
>
> I have a class named 'Dir' that I want to be put into another class
> 'DirList' ( essential a linked list of Dir objects ) using the 'insert()'
> method. The syntax is 'DirList.insert( Dir )' which works, but then I try to
> access the 'getSize()' function of the 'Dir' class from *inside* of the
> DirList class, it gives me this ->
> 'I added a node for dir d:/ with size <bound method Dir.getSize of
> <__main__.Dir instance at 0x00E18CD8>>'
>
> Any ideas on what I am doing wrong?
>
1) Linked lists are almost always worthless in python. Why not use a
list instead?
2) what's being printed is a function reference - i.e. you're doing:
self.a_dir_instance.getSize
instead of:
self.a_dir_instance.getSize()
which actually calls the function, instead of just returning a pointer to it.
Peace
Bill Mill
bill.mill at gmail.com
More information about the Tutor
mailing list