Re: What is the name of the name space I am in?

2010-07-06 Thread Anthra Norell

Gregory Ewing wrote:

On 07/05/2010 11:07 AM, Anthra Norell wrote:

I try to use "new.new.classobj (name, baseclass, dict)" and have no 
clue

what the "dict" of the current name space is.


Are you sure that's what you really want to know? The
'dict' argument to classobj() defines the attributes
that you want the new class to have. It's not meant
to be the namespace in which the code creating the
class is executing.

No indeed I'm not sure. The doc explains the argument "dict" as "name 
space", a term I associated with the enclosing module's name space, 
because it is also visible from inside enclosed blocks.
 But how right you are! Passing locals () works fine inasmuch as 
the constructor doesn't complain. Looking subsequently at the class 
attributes with dir (c) or c.__dict__keys (), however, dumps the entire 
inventory of the module in addition to the attributes of the base class. 
Clearly, that can't be right.
 So, thanks to you! I very much appreciate the guidance along the 
right path.


Frederic
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is the name of the name space I am in?

2010-07-05 Thread Gregory Ewing

On 07/05/2010 11:07 AM, Anthra Norell wrote:


I try to use "new.new.classobj (name, baseclass, dict)" and have no clue
what the "dict" of the current name space is.


Are you sure that's what you really want to know? The
'dict' argument to classobj() defines the attributes
that you want the new class to have. It's not meant
to be the namespace in which the code creating the
class is executing.

--
Greg
--
http://mail.python.org/mailman/listinfo/python-list


Re: What is the name of the name space I am in?

2010-07-05 Thread Anthra Norell

Chris Rebert wrote:

On Mon, Jul 5, 2010 at 2:07 AM, Anthra Norell  wrote:
  

I try to use "new.new.classobj (name, baseclass, dict)" and have no clue



Slight tangent:
Note that both the `new` module and old-style classes (which are what
`classobj` produces) are deprecated.
To produce new-style classes dynamically, use `type`.

Cheers,
Chris
--
http://blog.rebertia.com

  

Chris,
 I noticed the deprecation situation reading the doc, but opted for 
what I thought might be more backward-compatible. Your suggestion 
prompted me to take a closer look and it turns out that "types" is 
compatible as far back as I have to go (2.5). So I use "types" with 
thanks to you.

--
http://mail.python.org/mailman/listinfo/python-list


Re: What is the name of the name space I am in?

2010-07-05 Thread Anthra Norell

Thomas Jollans wrote:

On 07/05/2010 11:07 AM, Anthra Norell wrote:
  

I try to use "new.new.classobj (name, baseclass, dict)" and have no clue
what the "dict" of the current name space is. I can name dicts of 
imported modules, because their name exists in the current name space.

If, for instance, I import a module "service" then that module's name
space would be "service.__dict__". But if I import * from service, then
I incorporate that name space into the current one and I cannot name it,
because the current module's name is not part of the module's own name
space. "dir (service)" is equivalent to "service.__dict__.keys ()" if
service is importet. "dir ()" is equivalent to "?.__dict__.keys ()"
where "?" is the name of the current module, itself not part of the
current module's name space. So the question mark stands for an implicit
name that can be neither named nor dropped. So my question is: how does
one name the dictionary of the name space one is in?



either globals() or locals(), depending on what you mean.

  

Frederic




Thomas,
Thanks a million. Just the tip I needed.
Frederic

--
http://mail.python.org/mailman/listinfo/python-list


Re: What is the name of the name space I am in?

2010-07-05 Thread Chris Rebert
On Mon, Jul 5, 2010 at 2:07 AM, Anthra Norell  wrote:
> I try to use "new.new.classobj (name, baseclass, dict)" and have no clue

Slight tangent:
Note that both the `new` module and old-style classes (which are what
`classobj` produces) are deprecated.
To produce new-style classes dynamically, use `type`.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What is the name of the name space I am in?

2010-07-05 Thread Thomas Jollans
On 07/05/2010 11:07 AM, Anthra Norell wrote:
> I try to use "new.new.classobj (name, baseclass, dict)" and have no clue
> what the "dict" of the current name space is. I can name dicts of 
> imported modules, because their name exists in the current name space.
> If, for instance, I import a module "service" then that module's name
> space would be "service.__dict__". But if I import * from service, then
> I incorporate that name space into the current one and I cannot name it,
> because the current module's name is not part of the module's own name
> space. "dir (service)" is equivalent to "service.__dict__.keys ()" if
> service is importet. "dir ()" is equivalent to "?.__dict__.keys ()"
> where "?" is the name of the current module, itself not part of the
> current module's name space. So the question mark stands for an implicit
> name that can be neither named nor dropped. So my question is: how does
> one name the dictionary of the name space one is in?

either globals() or locals(), depending on what you mean.

> 
> Frederic
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


What is the name of the name space I am in?

2010-07-05 Thread Anthra Norell
I try to use "new.new.classobj (name, baseclass, dict)" and have no clue 
what the "dict" of the current name space is. I can name dicts of  
imported modules, because their name exists in the current name space. 
If, for instance, I import a module "service" then that module's name 
space would be "service.__dict__". But if I import * from service, then 
I incorporate that name space into the current one and I cannot name it, 
because the current module's name is not part of the module's own name 
space. "dir (service)" is equivalent to "service.__dict__.keys ()" if 
service is importet. "dir ()" is equivalent to "?.__dict__.keys ()" 
where "?" is the name of the current module, itself not part of the 
current module's name space. So the question mark stands for an implicit 
name that can be neither named nor dropped. So my question is: how does 
one name the dictionary of the name space one is in?


Frederic

--
http://mail.python.org/mailman/listinfo/python-list