473,396 Members | 2,010 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.

Problems with import of modules

I am within a directory

\doc\template\

I launch script.py

within this script.py, I like to import a module from the doc directory.

this here does not work:

form ..\..\module_name import this_one

how do I go back in the directory hierarchy to import something?

If this is not possible:

How can I modify the python search-path from within the script, thus it
contains the doc directory?

..

--
http://lazaridis.com
Jan 23 '06 #1
3 1301
> How can I modify the python search-path from within the script, thus it
contains the doc directory?


Hi,

The sys.path variable is a list of strings that contains the current
module search path. You can add your own path to this list:

import sys
sys.path.append('../')

-Farshid
Jan 23 '06 #2
Ilias Lazaridis wrote:
I am within a directory

\doc\template\

I launch script.py

within this script.py, I like to import a module from the doc directory.

this here does not work:

form ..\..\module_name import this_one
Well, if you are in linux you can do this easily by changing your
PYTHONPATH environment variable, either by changing it explicitely or by
editing it in your .rc files to append the /doc directory.

Although I don't know specifically where this variable might be if you
are using windows, in either case(windows or linux), you can alter this
from python using sys.path

import sys
sys.path.append("/doc")

Hope that helps,

-carl
how do I go back in the directory hierarchy to import something?

If this is not possible:

How can I modify the python search-path from within the script, thus it
contains the doc directory?

.

--

Carl J. Van Arsdall
cv*********@mvista.com
Build and Release
MontaVista Software

Jan 23 '06 #3
the sys.path.append has done the work.

thanks.

..

--
http://lazaridis.com
Jan 27 '06 #4

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

Similar topics

2
by: Olaf Meyer | last post by:
I'm having some problems compiling Python 2.3.3 on HP-UX (B.11.00). I've tried sevral different options for the configure script (e.g. enabling/disabling gcc, aCC) but I always get the same problem...
5
by: simo | last post by:
I've written a pretty big wxPython script, and I thought I'd split the source into a few files. I'm going to have a main.py file which includes global defs, wxApp initialisation code,...
0
by: John Roth | last post by:
I've found a case where it seems that Python is importing two copies of a module without any reason or indication. It took me a while to verify that this is what is occuring: I had to write a...
2
by: Fritz Bosch | last post by:
Hi experts Is is possible to import/manipulate a module such that I can supply its __dict__? I want to supply my own dict subclass object to be filled by the import, e.g. a class like: >>>...
3
by: praveenkumar.117 | last post by:
Hi All, What is the difference between import string and from string import * Regards, Praveen
1
by: jmalone | last post by:
I have a python script that I need to freeze on AIX 5.1 (customer has AIX and does not want to install Python). The python script is pretty simple (the only things it imports are sys and socket)....
4
by: Frank | last post by:
Hi, I have the following weird behavior when I load modules: 8 Everything is fine. Traceback (most recent call last):
2
by: Bill Jackson | last post by:
Once again, I am having issues with imports... Until now, I thought the general guidelines were to rarely use 'from x import y' syntax, except when you really want to copy names over. However, I...
10
by: Thomas Guettler | last post by:
If you look at this code, you see there are two kind of ImportErrors: 1. app_name has no attribute or file managment.py: That's OK. 2. managment.py exists, but raises an ImportError: That's not...
5
by: Peter Otten | last post by:
Urizev wrote: Do you see it now I snipped the irrelevant output? The problem is the structure of your program. The myset module is imported twice by Python, once as "myset" and once as...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.