Move modules to submodules question

Discussion in 'Python' started by joshua.kimball@gmail.com, Jan 11, 2013.

  1. Guest

    I have a set of utility modules that were all added to a folder called (util_mods). Recently the set of modules grew to be too large and I've been working on splitting it up into sets of sub modules, for example, util_mods\set_a. The issue is that if I start moving modules to sub folders I have to go through and update literally thousands of scripts that import the module from util_mods. I was wondering if there was a way to move these modules into submodules while still maintaining the imports. For example "import util_mods.moda " would actually import as "util_mods.set_a.moda".

    My longterm goal is to update the scripts to point to the correct submodule/module however I was hoping for a short term solution to this so I can make the change immediately and update the other scripts over time.
    , Jan 11, 2013
    #1
    1. Advertising

  2. Peter Otten Guest

    wrote:

    > I have a set of utility modules that were all added to a folder called
    > (util_mods). Recently the set of modules grew to be too large and I've
    > been working on splitting it up into sets of sub modules, for example,
    > util_mods\set_a. The issue is that if I start moving modules to sub
    > folders I have to go through and update literally thousands of scripts
    > that import the module from util_mods. I was wondering if there was a way
    > to move these modules into submodules while still maintaining the imports.
    > For example "import util_mods.moda " would actually import as
    > "util_mods.set_a.moda".
    >
    > My longterm goal is to update the scripts to point to the correct
    > submodule/module however I was hoping for a short term solution to this so
    > I can make the change immediately and update the other scripts over time.


    Put

    from .set_a import moda

    into util_mods/__init__.py

    Alternatively create an additional

    util_mods/moda.py

    containing nothing but

    from .set_a.moda import *
    Peter Otten, Jan 11, 2013
    #2
    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. TG

    access to submodules

    TG, Jul 19, 2006, in forum: Python
    Replies:
    10
    Views:
    547
  2. Frank Aune

    Python submodules and name imports

    Frank Aune, Aug 23, 2007, in forum: Python
    Replies:
    1
    Views:
    798
    =?iso-8859-1?B?UOFkcmFpZw==?=
    Aug 23, 2007
  3. Donn Ingle
    Replies:
    7
    Views:
    255
    Gabriel Genellina
    Dec 19, 2007
  4. Torsten Mohr

    Noddy with submodules?

    Torsten Mohr, Sep 7, 2009, in forum: Python
    Replies:
    1
    Views:
    285
    Gabriel Genellina
    Sep 8, 2009
  5. Massi

    Automatic import of submodules

    Massi, Nov 25, 2011, in forum: Python
    Replies:
    4
    Views:
    238
    Shambhu Rajak
    Nov 28, 2011
Loading...

Share This Page