Re: Adding to a module's __dict__?

2010-03-04 Thread Gregory Ewing
Roy Smith wrote: The idea is I want to put in the beginning of the module: declare('XYZ_FOO', 0, The foo property) declare('XYZ_BAR', 1, The bar property) declare('XYZ_BAZ', 2, reserved for future use) Okay, that seems like a passable excuse. One thing to watch out for is that if your

Re: Adding to a module's __dict__?

2010-03-02 Thread Jean-Michel Pichavant
Roy Smith wrote: From inside a module, I want to add a key-value pair to the module's __dict__. I know I can just do: FOO = 'bar' at the module top-level, but I've got 'FOO' as a string and what I really need to do is __dict__['Foo'] = 'bar' When I do that, I get NameError: name '__dict__'

Re: Adding to a module's __dict__?

2010-03-02 Thread Roy Smith
In article mailman.96.1267508316.23598.python-l...@python.org, Chris Rebert c...@rebertia.com wrote: On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith r...@panix.com wrote: From inside a module, I want to add a key-value pair to the module's __dict__.  I know I can just do: FOO = 'bar' at

Re: Adding to a module's __dict__?

2010-03-02 Thread Steve Holden
Roy Smith wrote: In article mailman.96.1267508316.23598.python-l...@python.org, Chris Rebert c...@rebertia.com wrote: On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith r...@panix.com wrote: From inside a module, I want to add a key-value pair to the module's __dict__. Â I know I can just do: FOO

Re: Adding to a module's __dict__?

2010-03-02 Thread Mel
Roy Smith wrote: [ ... ] Why is it unwise? The use case is I'm importing a bunch of #define constants from a C header file. I've got triples that I want to associate; the constant name, the value, and a string describing it. The idea is I want to put in the beginning of the module:

Re: Adding to a module's __dict__?

2010-03-02 Thread Roy Smith
On Mar 2, 8:33 am, Steve Holden st...@holdenweb.com wrote: And how important is it to make sure that whatever data your program processes doesn't overwrite the actual variable names you want to use to program the processing? Oh, I see what you're saying. You're thinking I was going to

Re: Adding to a module's __dict__?

2010-03-02 Thread Steve Holden
Roy Smith wrote: On Mar 2, 8:33 am, Steve Holden st...@holdenweb.com wrote: And how important is it to make sure that whatever data your program processes doesn't overwrite the actual variable names you want to use to program the processing? Oh, I see what you're saying. You're thinking

Re: Adding to a module's __dict__?

2010-03-02 Thread John Posner
On 3/2/2010 10:19 AM, Roy Smith wrote: Somewhat sadly, in my case, I can't even machine process the header file. I don't, strictly speaking, have a header file. What I have is a PDF which documents what's in the header file, and I'm manually re- typing the data out of that. Sigh. Here's an

Re: Adding to a module's __dict__?

2010-03-02 Thread Carl Banks
On Mar 2, 5:21 am, Roy Smith r...@panix.com wrote: In article mailman.96.1267508316.23598.python-l...@python.org,  Chris Rebert c...@rebertia.com wrote: On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith r...@panix.com wrote: From inside a module, I want to add a key-value pair to the module's

Re: Adding to a module's __dict__?

2010-03-02 Thread MRAB
John Posner wrote: On 3/2/2010 10:19 AM, Roy Smith wrote: Somewhat sadly, in my case, I can't even machine process the header file. I don't, strictly speaking, have a header file. What I have is a PDF which documents what's in the header file, and I'm manually re- typing the data out of

Re: Adding to a module's __dict__?

2010-03-02 Thread Terry Reedy
On 3/2/2010 11:18 AM, John Posner wrote: On 3/2/2010 10:19 AM, Roy Smith wrote: Somewhat sadly, in my case, I can't even machine process the header file. I don't, strictly speaking, have a header file. What I have is a PDF which documents what's in the header file, and I'm manually re- typing

Re: Adding to a module's __dict__?

2010-03-02 Thread Dave Angel
Terry Reedy wrote: On 3/2/2010 11:18 AM, John Posner wrote: On 3/2/2010 10:19 AM, Roy Smith wrote: Somewhat sadly, in my case, I can't even machine process the header file. I don't, strictly speaking, have a header file. What I have is a PDF which documents what's in the header file, and I'm

Adding to a module's __dict__?

2010-03-01 Thread Roy Smith
From inside a module, I want to add a key-value pair to the module's __dict__. I know I can just do: FOO = 'bar' at the module top-level, but I've got 'FOO' as a string and what I really need to do is __dict__['Foo'] = 'bar' When I do that, I get NameError: name '__dict__' is not defined. Is

Re: Adding to a module's __dict__?

2010-03-01 Thread Chris Rebert
On Mon, Mar 1, 2010 at 8:27 PM, Roy Smith r...@panix.com wrote: From inside a module, I want to add a key-value pair to the module's __dict__.  I know I can just do: FOO = 'bar' at the module top-level, but I've got 'FOO' as a string and what I really need to do is __dict__['Foo'] = 'bar'