Need a hint on customizing import of modules

Discussion in 'Python' started by F. GEIGER, Jun 8, 2004.

  1. F. GEIGER

    F. GEIGER Guest

    Hi all,

    I use Leo for programming. Among other goodies Leo provides it let's me
    easily share code between different Python apps. When I have an app
    consisting of more than one file, they usually do

    from other import AClassOfIt
    import yetanother

    When I then want to investigate a specific problem I share code with a
    lab file, e.g. LabByOpenGL.py. This app is flat then, i.e. it does not
    need to

    from other import AClassOfIt
    import yetanother

    because all classes of other are flattened into LabPyOpenGL.py.

    So I have to write within LabPyOpenGL.py

    try:
    from other import AClassOfIt
    except ImportError:
    pass # Assume it being w/i this module

    Instantiation of AClassOfIt now works in both worlds, i.e. in the
    "structured" app and in the flat app.

    But what should I do with

    import yetanother ?

    When code is used from yetanother, it is ref'ed like so:

    myUseful = yetanother.UseFullClass()

    This does not work in the flat file, because yetanother could not be
    imported.

    So I thought of something like

    try:
    import yetanother
    except ImportError:
    yetanother = __module__ # alas, does not work

    which then would make calls like

    myUseful = yetanother.UseFullClass()

    possible as before.

    Any hint how I shall proceed? Should I consider writing an import hook?
    How would such a beast look like?

    Many thanks in advance
    Franz GEIGER
    F. GEIGER, Jun 8, 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. Marek

    How to create a hint?

    Marek, Dec 27, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    1,539
    =?Utf-8?B?a2VybWl0?=
    Dec 27, 2004
  2. Remy Cool
    Replies:
    1
    Views:
    429
    Remy Cool
    Aug 27, 2003
  3. GHUM

    need hint for refactoring

    GHUM, Aug 9, 2006, in forum: Python
    Replies:
    1
    Views:
    287
    Diez B. Roggisch
    Aug 9, 2006
  4. Podrzut_z_Laweczki

    need a hint

    Podrzut_z_Laweczki, Aug 5, 2006, in forum: C++
    Replies:
    5
    Views:
    382
    Jerry Coffin
    Aug 6, 2006
  5. Gerr
    Replies:
    4
    Views:
    122
Loading...

Share This Page