hidden built-in module

Discussion in 'Python' started by gigs, Mar 5, 2008.

  1. gigs

    gigs Guest

    koara wrote:
    > Hello, is there a way to access a module that is hidden because
    > another module (of the same name) is found first?
    >
    > More specifically, i have my own logging.py module, and inside this
    > module, depending on how initialization goes, i may want to do 'from
    > logging import *' from the built-in logging.
    >
    > I hope my description was clear, cheers.
    >
    > I am using python2.4.

    you can add your own logging module in extra directory that have __init__.py and
    import it like: from extradirectory.logging import *

    and builtin: from logging import *
     
    gigs, Mar 5, 2008
    #1
    1. Advertising

  2. gigs

    koara Guest

    Hello, is there a way to access a module that is hidden because
    another module (of the same name) is found first?

    More specifically, i have my own logging.py module, and inside this
    module, depending on how initialization goes, i may want to do 'from
    logging import *' from the built-in logging.

    I hope my description was clear, cheers.

    I am using python2.4.
     
    koara, Mar 7, 2008
    #2
    1. Advertising

  3. gigs

    koara Guest

    On Mar 5, 1:39 pm, gigs <-com.hr> wrote:
    > koara wrote:
    > > Hello, is there a way to access a module that is hidden because
    > > another module (of the same name) is found first?

    >
    > > More specifically, i have my own logging.py module, and inside this
    > > module, depending on how initialization goes, i may want to do 'from
    > > logging import *' from the built-in logging.

    >
    > > I hope my description was clear, cheers.

    >
    > > I am using python2.4.

    >
    > you can add your own logging module in extra directory that have __init__.py and
    > import it like: from extradirectory.logging import *
    >
    > and builtin: from logging import *



    Thank you for your reply gigs. However, the point of this namespace
    harakiri is that existing code which uses 'import logging' ...
    'logging.info()'... etc. continues working without any change.
    Renaming my logging.py file is not an option -- if it were, i wouldn't
    bother naming my module same as a built-in :)

    Cheers.
     
    koara, Mar 7, 2008
    #3
  4. koara schrieb:
    > On Mar 5, 1:39 pm, gigs <-com.hr> wrote:
    >> koara wrote:
    >>> Hello, is there a way to access a module that is hidden because
    >>> another module (of the same name) is found first?
    >>> More specifically, i have my own logging.py module, and inside this
    >>> module, depending on how initialization goes, i may want to do 'from
    >>> logging import *' from the built-in logging.
    >>> I hope my description was clear, cheers.
    >>> I am using python2.4.

    >> you can add your own logging module in extra directory that have __init__.py and
    >> import it like: from extradirectory.logging import *
    >>
    >> and builtin: from logging import *

    >
    >
    > Thank you for your reply gigs. However, the point of this namespace
    > harakiri is that existing code which uses 'import logging' ...
    > 'logging.info()'... etc. continues working without any change.
    > Renaming my logging.py file is not an option -- if it were, i wouldn't
    > bother naming my module same as a built-in :)


    You can only try and search the sys-path for the logging-module, using

    sys.prefix

    and then look for logging.py. Using

    __import__(path)

    you get a reference to that module.

    Diez
     
    Diez B. Roggisch, Mar 7, 2008
    #4
  5. En Fri, 07 Mar 2008 12:15:04 -0200, koara <> escribi�:
    > On Mar 5, 1:39 pm, gigs <-com.hr> wrote:
    >> koara wrote:
    >> > Hello, is there a way to access a module that is hidden because
    >> > another module (of the same name) is found first?

    >>
    >> > More specifically, i have my own logging.py module, and inside this
    >> > module, depending on how initialization goes, i may want to do 'from
    >> > logging import *' from the built-in logging.

    >>
    >> you can add your own logging module in extra directory that have
    >> __init__.py and
    >> import it like: from extradirectory.logging import *
    >> and builtin: from logging import *

    >
    > Thank you for your reply gigs. However, the point of this namespace
    > harakiri is that existing code which uses 'import logging' ...
    > 'logging.info()'... etc. continues working without any change.
    > Renaming my logging.py file is not an option -- if it were, i wouldn't
    > bother naming my module same as a built-in :)


    Read a very recent post from Bruno Desthuilliers with subject "Altering
    imported modules"

    --
    Gabriel Genellina
     
    Gabriel Genellina, Mar 7, 2008
    #5
  6. gigs

    koara Guest

    > You can only try and search the sys-path for the logging-module, using
    >
    > sys.prefix
    >
    > and then look for logging.py. Using
    >
    > __import__(path)
    >
    > you get a reference to that module.
    >
    > Diez



    Thank you Diez, that's the info i'd been looking for :)

    So the answer is sys module + __import__

    Cheers!
     
    koara, Mar 7, 2008
    #6
    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. JimmyT
    Replies:
    1
    Views:
    321
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Sep 1, 2004
  2. Olivier Vierlinck

    built-in function- module name clash

    Olivier Vierlinck, Sep 6, 2004, in forum: Python
    Replies:
    2
    Views:
    319
    Alex Martelli
    Sep 6, 2004
  3. Alex Stapleton
    Replies:
    0
    Views:
    413
    Alex Stapleton
    Jun 5, 2005
  4. Rick
    Replies:
    3
    Views:
    8,570
    Alexey Smirnov
    Apr 13, 2010
  5. SolarCanine
    Replies:
    2
    Views:
    337
    SolarCanine
    Sep 20, 2005
Loading...

Share This Page