468,284 Members | 1,521 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,284 developers. It's quick & easy.

hidden built-in module

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.
Mar 7 '08 #1
5 1307
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 *
Mar 7 '08 #2
On Mar 5, 1:39 pm, gigs <g...@hi.t-com.hrwrote:
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.
Mar 7 '08 #3
koara schrieb:
On Mar 5, 1:39 pm, gigs <g...@hi.t-com.hrwrote:
>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
Mar 7 '08 #4
En Fri, 07 Mar 2008 12:15:04 -0200, koara <ko***@atlas.czescribi�:
On Mar 5, 1:39 pm, gigs <g...@hi.t-com.hrwrote:
>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

Mar 7 '08 #5
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!
Mar 7 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by D. Alvarado | last post: by
2 posts views Thread by Christoph | last post: by
6 posts views Thread by Angus Comber | last post: by
5 posts views Thread by anonymousstar | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.