All:
I am struggling with an import problem...
In my package, myapp, I have a module, logging.py. That module,
naturally, imports the library module logging with an 'import logging'
statement. However, when I use 'import myapp.logging' in my script,
the myapp.logging module tries to import itself rather than the library
logging module.
How can I prevent this from happening other than using a name that
doesn't conflict?
--PLB 2 1273 In my package, myapp, I have a module, logging.py. That module, naturally, imports the library module logging with an 'import logging' statement. However, when I use 'import myapp.logging' in my script, the myapp.logging module tries to import itself rather than the library logging module.
How can I prevent this from happening other than using a name that doesn't conflict?
Did you try the built-in 'imp' module? http://docs.python.org/lib/module-imp.html
I believe that 'load_module' is your very best friend. :-)
Another idea: rename your modules so they do not conflict with standard
modules.
Best,
Laci 2.0
--
__________________________________________________ _______________
Laszlo Nagy web: http://designasign.biz
IT Consultant mail: ga*****@geochemsource.com
Python forever!
Good call! The following snippet solved my problems portably.
path = sys.path[1:]
file, filename, description = imp.find_module('logging', path)
logging = imp.load_module('logging', file, filename, description)
Thanks!
--Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Felix Wiemann |
last post by:
Hi!
I want to create a module myproject.ui.curses, which needs to import the
curses library.
However, if I just write ``import curses``, the module imports *itself*
instead of the standard...
|
by: sophie_newbie |
last post by:
OK this might seem like a retarded question, but what is the difference
between a library and a module?
If I do:
import string
am I importing a module or a library?
And if i do...
|
by: Ben Finney |
last post by:
Howdy all,
Question: I have Python modules named without '.py' as the extension,
and I'd like to be able to import them. How can I do that?
Background:
On Unix, I write programs intended to...
|
by: rshepard |
last post by:
I'm stymied by what should be a simple Python task: accessing the value of
a variable assigned in one module from within a second module. I wonder if
someone here can help clarify my thinking. I've...
|
by: rjcarr |
last post by:
Sorry if this is a completely newbie question ...
I was trying to get information about the logging.handlers module, so
I imported logging, and tried dir(logging.handlers), but got:
...
| |
by: Peter J. Bismuti |
last post by:
I'm having trouble understanding how namespaces work in modules. I want to
execute a module within the interpreter and then have values that are
calculated persist so that other modules that get...
|
by: Peter J. Bismuti |
last post by:
How do you define a "module data member" (I want to understand out how this
works before making converting to a Class)?
Right now I'm defining variables in a module that get put into the global...
|
by: Matias Surdi |
last post by:
Hi,
Suppose I've a module named "urllib" and from it I need to import the
urllib module from the python standart library.
¿how can I do this?
The problem I found is that when I do:
|
by: Joe Strout |
last post by:
I've been using docstring to exercise each of my modules, with code
like this:
def _test():
import doctest
doctest.testmod()
if __name__ == "__main__":
_test()
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |