473,414 Members | 1,688 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,414 software developers and data experts.

the problem of import module

follow the dive into python
-----------------------------------------------------------------
>>import sys
sys.path
sys.path.append('E:\achieve\book\diveintopytho n-pdfzh-cn-5.4b\diveintopythonzh-cn-5.4b\py')
-----------------------------------------------------------------
I append the filepath of <<dive into python>>'s examples into
sys.path,but
-----------------------------------------------------------------
>>sys.path
['C:\\Python25\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python25.zip',
'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-
win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\
\site-packages', 'E:\x07chieve\x08ook\\diveintopython-pdfzh-cn-5.4b\
\diveintopythonzh-cn-5.4b\\py']
>>import fileinfo#fileinfo is a module in the path
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
import fileinfo
ImportError: No module named fileinfo

-----------------------------------------------------------------
Can anyone tell me the reason of the above and how to add paths to
python path except adding them in the enviroment path.
Thanks.
Mar 7 '08 #1
1 1761
ft*****@gmail.com wrote:
follow the dive into python
-----------------------------------------------------------------
>>>import sys
sys.path
sys.path.append('E
\achieve\book\diveintopython-pdfzh-cn-5.4b\diveintopythonzh-cn-5.4b\py')
-----------------------------------------------------------------
I append the filepath of <<dive into python>>'s examples into
sys.path,but
-----------------------------------------------------------------
>>>sys.path
['C:\\Python25\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python25.zip',
'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-
win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\
\site-packages', 'E:\x07chieve\x08ook\\diveintopython-pdfzh-cn-5.4b\
\diveintopythonzh-cn-5.4b\\py']
>>>import fileinfo#fileinfo is a module in the path

Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
import fileinfo
ImportError: No module named fileinfo

-----------------------------------------------------------------
Can anyone tell me the reason of the above and how to add paths to
python path except adding them in the enviroment path.
Thanks.
The path you append to sys.path is not properly escaped:
>>"E:\archive"
'E:\x07rchive' # \a has become the single character chr(7)

Use double backslashes or raw strings instead:
>>"E:\\archive"
'E:\\archive'
>>r"E:\archive"
'E:\\archive'

When you print it the extra backslash will be gone:
>>print "E:\\archive" # \\ is the escape sequence for the backslash
E:\archive

Peter
Mar 7 '08 #2

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

Similar topics

0
by: Stian Søiland | last post by:
all examples performed with: Python 2.3+ (#2, Aug 10 2003, 11:09:33) on linux2 (2, 3, 0, 'final', 1) This is a recursive import:
9
by: Paul Rubin | last post by:
That's what the Python style guides advise. They don't seem to like def frob(x): import re if re.search('sdfxyz', x): ... instead preferring that you pollute your module's global namespace...
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...
4
by: Steve Holden | last post by:
I'm trying to load module code from a database, which stores for each module its full name, code, load date and a Boolean indicating whether it's a package or not. The following simple program:...
5
by: Steve Holden | last post by:
This is even stranger: it makes it if I import the module a second time: import dbimp as dbimp import sys if __name__ == "__main__": dbimp.install() #k = sys.modules.keys() #k.sort() #for...
16
by: didier.doussaud | last post by:
I have a stange side effect in my project : in my project I need to write "gobal" to use global symbol : .... import math .... def f() : global math # necessary ?????? else next line...
23
by: Shane Hathaway | last post by:
Here's a heretical idea. I'd like a way to import modules at the point where I need the functionality, rather than remember to import ahead of time. This might eliminate a step in my coding...
7
by: Ron Adam | last post by:
from __future__ import absolute_import Is there a way to check if this is working? I get the same results with or without it. Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win 32 ...
3
by: kwatch | last post by:
What is the condition of module name which is available in 'from .. import ..' statement ? ---------------------------------------- import os print os.path # <module 'posixpath'...
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...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.