newbie-one more example of difficulty in van Rossum's tutorial

bobueland at yahoo.com bobueland at yahoo.com
Tue Dec 13 16:44:31 EST 2005


This is from 9.6 (Private variables). I quote

- "Notice that code passed to exec, eval() or evalfile() does not
consider the classname of the invoking class to be the current class;
this is similar to the effect of the global statement, the effect of
which is likewise restricted to code that is byte-compiled together.
The same restriction applies to getattr(), setattr() and delattr(), as
well as when referencing __dict__ directly."

I've read the text so far but there has been no explaination of exec,
eval() and evalfile() so far. I suspect they give ways for dynamic
execution of text strings containing Python statements.
But what does it mean that "code passed to exec, eval() or evalfile()
does not consider the classname of the invoking class to be the current
class"? What "invoking class"? What "current class".

Now there's a hint:

- "this is similar to the effect of the global statement, the effect of
which is likewise restricted to code that is byte-compiled together."

But what does this mean? So far global statement was only mention on
page 64 by the sentence

- "If a name is declared global, then all references and assignments go
directly to the middle scope containing the module's global names."

What has this to do with

- " the effect of which is likewise restricted to code that is
byte-compiled together."

At last I learn that

- "The same restriction applies to getattr(), setattr() and delattr(),
as well as when referencing __dict__ directly."

But  getattr(), setattr() and delattr() and  __dict__ has not been
mentioned as far as I recollect.

Since no examples are given I don't know what to do with this and what
the intention was putting the text above in the tutorial.. Of course I
can go to library reference and try to uncover the details there but
it's not an easy job if you are a newbie (which is why I started with
the tutorial to begin with).

Well, I don't want to complain to much about a tutorial which is rather
good but would appreciate some hint or reference which would help me to
understand the quoted text.

Bob




More information about the Python-list mailing list