syntax questions

Daniel Fackrell dfackrell at DELETETHIS.linuxmail.org
Wed Jul 24 14:13:00 EDT 2002


"Philippe Gendreau" <philippe.gendreau at savoirfairelinux.com> wrote in
message news:mailman.1027530996.5219.python-list at python.org...
> * Chris Liechti <cliechti at gmx.net> [2002-07-24 18:50]:
> > note that "dir" is somewhat a bad name for that variable because
> > a) there is a builtin function that name that you hide
> > b) its not a directory name but a filename without path in the above
case
>
> Note taken.
> I know about the dir() function,  but I'm surprised that my list object
> hides a function object (even if they have the same name).
> Is that how python treats names all the time? Does it mean you can't
> have a class, def and variable of the same name?


At least not in the same scope.  For example, you could have a function foo
in a class instance foo:

foo.foo()

but having that, doing foo=3 would reassign foo so that the class instance
is no longer accessible (unless it's referenced elsewhere), while foo.foo=3
would do the same thing to the function for the instance.

On the bright side, this is related to the fact that python tries to treat
everything as equally as possible, which leads to useful behaviors as being
able to pass functions or classes, along with other objects, to functions.

--
Daniel Fackrell (dfackrell at linuxmail.org)
When we attempt the impossible, we can experience true growth.





More information about the Python-list mailing list