Adding to a module's __dict__?

Terry Reedy tjreedy at
Tue Mar 2 12:38:55 EST 2010

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 the data out of that. Sigh.

There are Python modules to read/write pdf.

> Here's an idea, perhaps too obvious, to minimize your keystrokes:
> 1. Create a text file with the essential data:
> XYZ_FOO 0 The foo property
> XYZ_BAR 1 The bar property
> XYZ_BAZ 2 reserved for future use
> 2. Use a Python script to convert this into the desired code:
> declare('XYZ_FOO', 0, "The foo property")
> declare('XYZ_BAR', 1, "The bar property")
> declare('XYZ_BAZ', 2, "reserved for future use")
> Note:
>  >>> s
> 'XYZ_FOO 0 The foo property'
>  >>> s.split(None, 2)
> ['XYZ_FOO', '0', 'The foo property']

Given that set of triples is constant, I would think about having the 
Python script do the computation just once, instead of with every 
inport. In other words, the script should *call* the declare function 
and then write out the resulting set of dicts either to a .py or pickle 


More information about the Python-list mailing list