Simple questions re name spaces

emile at fenx.com emile at fenx.com
Fri May 12 20:44:58 EDT 2000


Cynthia Webber <da57thJones at worldnet.att.net> wrote in message
news:<og1T4.5850$XO1.329816 at bgtnsc06-news.ops.worldnet.att.net>...
> I'm new to Python and have two simple questions requiring namespaces.
> 
> 1>
> I have written a module that defines several constants used throughout out a
> project.
> Currently when importing these constants into another module I am explicitly
> listing each constant
> 
> from constants import A
> from constants import B
> from constants import C
> .... .... ... ... ..
> 
> Is there a way to expose all of the constants without explicitly listing
> them ?
> 

from constants import *

will put A, B, C, etc into the current namespace


> 2>
> I have tried to dynamically create variables with code such as
> 
> >>> a = "b = 'dog'"
> >>> exec a
> >>> print b
> 'dog'
> 
> This works from the command line but when I included it in a module it
> fails.

Could you post a pared down example.  When I try it here in a module,
it works fine.

> The exec line executes without complaint, but the newly created variable b
> does not seem to exists ? Any Ideas
> 
> Thanks In Advance
> 
> 

HTH,

Emile van Sebille
emile at fenx.com




More information about the Python-list mailing list