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

Discussion in 'Python' started by Simon John, Aug 21, 2004.

  1. Simon John

    Simon John Guest

    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....
     
    Simon John, Aug 21, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    10,349
    Kevin Spencer
    Apr 5, 2006
  2. Julien ROUZIERES

    g++ -pg option and -shared option

    Julien ROUZIERES, Dec 21, 2004, in forum: C++
    Replies:
    1
    Views:
    777
    GianGuz
    Dec 21, 2004
  3. Replies:
    2
    Views:
    405
    Robert Kern
    Jan 4, 2006
  4. Cas
    Replies:
    5
    Views:
    819
    Kevin Jones
    Aug 28, 2006
  5. CSharpner
    Replies:
    0
    Views:
    1,145
    CSharpner
    Apr 9, 2007
Loading...

Share This Page