hidden built-in module

G

gigs

koara said:
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 *
 
K

koara

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.
 
K

koara

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.
 
D

Diez B. Roggisch

koara said:
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
 
G

Gabriel Genellina

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"
 
K

koara

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top