Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Global config option - import issues again.....

Reply
Thread Tools

Global config option - import issues again.....

 
 
Simon John
Guest
Posts: n/a
 
      08-21-2004
I have a program that consists of one main module and lots of small
sub-modules.

In the main module I open a text file and grep for a language setting,
this language setting will then be used as the module name of a config
file to import.

E.g. "Language=en" means config_en.py is imported as config,
"Language=fr" means config_fr.py is imported as config....

I manage this by executing a string of the language/import commmand
such as:

# execute string like "import config_en as config"
global lang_import
lang_import = "import config_" + language + " as config"
exec lang_import

Then the modules imported by the main module refer to config.CONSTANT

The problem is, that lang_import cannot be seen outside of the main
module, it's not truly global, so "exec lang_import" in the sub-modules
doesn't work.

I tried defining a method and importing that, but it doesn't work, e.g.

# main module
def lang():
import config_en as config

# sub-module
from main_module import lang;
lang()

Any ideas? Maybe some other way to import a module with a dynamic
name....

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dll config and web.config and Label Expressions (binding label text to dll config settings) CSharpner ASP .Net 0 04-09-2007 09:00 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
Web.config and app.config issues kalyankp78@gmail.com ASP .Net 4 04-05-2006 10:22 AM
g++ -pg option and -shared option Julien ROUZIERES C++ 1 12-21-2004 02:30 PM



Advertisments