473,396 Members | 2,057 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

importing module as filename

I am having a problem with name space contention.
I am combining two existing programs both with their own config
modules.

I have been expermenting with
import config #grab first config
sys.path.insert(0,"/usr/share/yum/")
import config as yconfig #grab second config
The first config always seems to squash the second config.
There should be a yconfig.yumconf but there is not.

any suggestions?

Dave Farning
Jul 18 '05 #1
4 1737
david farning wrote:
I am having a problem with name space contention.
I am combining two existing programs both with their own config
modules.

I have been expermenting with
import config #grab first config
sys.path.insert(0,"/usr/share/yum/")
import config as yconfig #grab second config
The first config always seems to squash the second config.
There should be a yconfig.yumconf but there is not.

any suggestions?


How about a symlink to disambiguate the module names,
e. g. ln -s config.py yumconfig.py, and then

import config, yumconfig

Somewhat more ambitious: convert the program directory into a package by
adding an __init__.py script and then

import config, yum.config

Peter
Jul 18 '05 #2
Peter Otten wrote:

How about a symlink to disambiguate the module names,
e. g. ln -s config.py yumconfig.py, and then

import config, yumconfig

Thanks, great suggestions. I will talk to the upstream maintainers about
1. changing config to something a little less ambigous ;)
2. having them add the symlink
3 me adding the symlink (I wouldn't want to muck around their sandbox too
much)

Somewhat more ambitious: convert the program directory into a package by
adding an __init__.py script and then

import config, yum.config

Peter

Dave Farning
Jul 18 '05 #3
david farning:
import config #grab first config
sys.path.insert(0,"/usr/share/yum/")
import config as yconfig #grab second config The first config always seems to squash the second config.
There should be a yconfig.yumconf but there is not.


The first 'config' is stored in sys.modules['config']. The
second import finds 'config' in the modules and uses that,
rather than reloading it.

Try this

import sys
import config #grab first config
del sys.modules["config"]
sys.path.insert(0,"/usr/share/yum/")
import config as yconfig #grab second config

In addition, you can try

config = __import__("config")
sys.path.insert(0,"/usr/share/yum/")
import config as yconfig #grab second config

Andrew
da***@dalkescientific.com
Jul 18 '05 #4
david farning wrote:

I am having a problem with name space contention.
I am combining two existing programs both with their own config
modules.

I have been expermenting with
import config #grab first config
sys.path.insert(0,"/usr/share/yum/")
import config as yconfig #grab second config

The first config always seems to squash the second config.
There should be a yconfig.yumconf but there is not.


Working from the names alone, you might find it easier
to simply execfile() the scripts. If they do nothing more
than define a bunch of constants or something like that, this
should be sufficient to avoid the problem you've seen.

Otherwise the "del sys.modules[config]" approach would seem
the most expedient, if ugly.

-Peter
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Vio | last post by:
I have a basic dynamic lib "noddy.so" which I want to 1- embed inside my executable 2- import by embedded python interpreter using an API call. I have two questions: 1- what would be the...
2
by: plb | last post by:
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'...
12
by: qwweeeit | last post by:
The pythonic way of programming requires, as far as I know, to spread a big application in plenty of more manageable scripts, using import or from ... import to connect the various modules. In...
4
by: jean-marc | last post by:
As an application programmer, I'm not well versed in the material aspects of computing (memory, cpu, bus and all). My understanding of imports in Python is such: the __main__ program is the center...
2
by: steve | last post by:
Hello, I am trying to import an image file into a form. This would be a persons picture saved in the same directory for every unique record. I don't have any problems making an action button to...
30
by: Franck PEREZ | last post by:
Hello, I'm developing a small XML marshaller and I'm facing an annoying issue. Here's some sample code: ########### My test application ############ class Foo(object): #The class I'd like to...
7
by: hg | last post by:
Hi, I have the following problem. I find in a directory hierarchy some files following a certain sets of rules: ..../.../../plugin/name1/name1.py ..... ..../.../../plugin/namen/namen.py
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
4
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...
2
by: Aaron Scott | last post by:
I've installed mod_python, and everything seems to be working, but it fails when I try to import another file into the file that's actually producing the output. I have these lines at the top of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.