473,789 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

the problem of import module

follow the dive into python
-----------------------------------------------------------------
>>import sys
sys.path
sys.path.appe nd('E:\achieve\ book\diveintopy thon-pdfzh-cn-5.4b\diveintopy thonzh-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\\s ystem32\\python 25.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\x 08ook\\diveinto python-pdfzh-cn-5.4b\
\diveintopython zh-cn-5.4b\\py']
>>import fileinfo#filein fo 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 1777
ft*****@gmail.c om wrote:
follow the dive into python
-----------------------------------------------------------------
>>>import sys
sys.path
sys.path.app end('E
\achieve\book\d iveintopython-pdfzh-cn-5.4b\diveintopy thonzh-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\\s ystem32\\python 25.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\x 08ook\\diveinto python-pdfzh-cn-5.4b\
\diveintopython zh-cn-5.4b\\py']
>>>import fileinfo#filein fo 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:\\archiv e"
'E:\\archive'
>>r"E:\archiv e"
'E:\\archive'

When you print it the extra backslash will be gone:
>>print "E:\\archiv e" # \\ 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
6913
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
2945
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 with the names of all your imports. What's the point of that? It gets worse when you want to do something like
0
1996
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 __import__ hook to trace the actual activity. The source code for the hook is below. There are several examples of the problem in the trace; this is one particularly juicy one. -----------Part 1 ---------------- '0059' Import 'TypeAdapter'...
4
3589
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: import dbimp, sys if __name__ == "__main__": dbimp.install()
5
2479
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 kk in k:
16
3116
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 generate an error message ?????
23
6423
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 process. Currently, my process is I change code and later scan my changes to make matching changes to the import statements. The scan step is error prone and time consuming. By importing inline, I'd be able to change code without the extra scan...
7
20574
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 _Ron
3
2009
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' from '/usr/local/ lib/python2.5/posixpath.pyc'> from posixpath import sep # (no errors) from os.path import sep # (no errors, wow!) path = os.path
10
1887
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 OK: reraise # Import the 'management' module within each installed app, to register # dispatcher events. for app_name in settings.INSTALLED_APPS: try: __import__(app_name + '.management', {}, {}, )
0
10412
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9986
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5422
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2909
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.