What is a class?

castironpi at gmail.com castironpi at gmail.com
Thu Mar 6 17:40:47 CET 2008


On Mar 6, 12:17 am, "Daniel Fetchinson" <fetchin... at googlemail.com>
wrote:
> > > Where to begin?
>
> > What does exec( open( 'modA.py' ).read() ) do?
>
> The most appropriate list to ask those questions is:
>
> http://mail.python.org/mailman/listinfo/tutor

Thanks for the reference.  I'm basically experienced with Python, but
I may read there too.

I asked the question mostly rhetorically. <simile> Like when people
ask, who cares, or who knows.  They don't want the answer---- unless
there is one. </simile>

A more appropriate formulation of the 'question behind the words'
would have been, 'are there any weird corner cases in which it doesn't
import modA?  I recognize it doesn't on .pyc and .pyd files, but you
could say exec( open( 'modA.py' ).read() ) ==> import modA, even if
import modA =!=> exec( open( 'modA.py' ).read() ) all the time.

However, a way of asking that's more direct would have been, "Wait...
can't you create multiple module instances like that?", but since
we've already seen successful loadings of at least the builtins,
that's been treated.  Maybe you even hear the right thing if I say,
"Does exec( open( 'modA.py' ).read() ) do the things of import modA?"
Yes, I can read the docs, but no, I can't check every possible
combination of modules.

The idea behind a singleton is to ensure something.  You want non-
primary instances impossible to create.  However, if (wording got
tangled here) for singleton A, if class B does the same thing, just
has different allocations-- it's own-- then A is still a singleton.
The writer of B hasn't defeated or contradicted the letter or spirit
of A.

OP's question might have come from a variety of perspectives.  In some
ways yes, in others no.  That is, if you try to reinstantiate modA,
you get the same instance.  But if you try really hard, you get a new
one.  Are you looking for an extension to import modA that won't
return an instance that is old?

So far, I know this: modules and classes are both namespaces.  Are
those singletons?



More information about the Python-list mailing list