[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

the problem of import module

fts2012@gmail.com

3/7/2008 6:18:00 AM

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.
4 Answers

Peter Otten

3/7/2008 8:03:00 AM

0

fts2012@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

Talorthain

3/25/2010 1:45:00 PM

0

HI,

The code worked the first time it was run and allowed them to open the file,
make a back up etc... but when they saved and closed and re-opened it, it
crashed and locked up once the workbook had opened..


response :

Opened okay got to WPQ made one change, closed and reopened okay.

Went back in to WPQ and egg timer missing, no curser, all I had was a cross
and couldn't do anything

Had to use task manager to get out

Steve

WPQ is a page in the project

"Jan Karel Pieterse" <jkpieterse@netscape.net> wrote in message
news:VA.00000673.0669aea1@netscape.net...
> Hi Anthony,
>
>> The saveas line is exactly the same as the save option in the project
>> once
>> its running, but that works without any problems (although there is a
>> slight
>> pause)
>>
>> If I replace saveas with savecopy function its exactly the same.
>>
>>
>> Anyone with any ideas?
>
> Try moving the save code to a sub in a normal module and calling the save
> sub
> using Application.Ontime in the Open event.
>
> Regards,
>
> Jan Karel Pieterse
> Excel MVP
> http://www.j...
>

Jan Karel Pieterse

3/25/2010 2:21:00 PM

0

Hi Anthony,

> Went back in to WPQ and egg timer missing, no curser, all I had was a cross
> and couldn't do anything

Might be good to head over to that user and try control+break when it hangs,
maybe some code is just running in an endless loop?

Regards,

Jan Karel Pieterse
Excel MVP
http://www.j...

Talorthain

3/25/2010 3:33:00 PM

0

I managed to replicate on my HP computer for the first time.

The computer just ground to a halt, so I have used a work around, which
isn't as nice but seems to be working so far.

Set a worksheet value as true in workbook open

once workbook open and first menu sheet active

if worksheet value is true then save backup

(in the save backup set worksheet value to false)

"Jan Karel Pieterse" <jkpieterse@netscape.net> wrote in message
news:VA.00000675.06ff1277@netscape.net...
> Hi Anthony,
>
>> Went back in to WPQ and egg timer missing, no curser, all I had was a
>> cross
>> and couldn't do anything
>
> Might be good to head over to that user and try control+break when it
> hangs,
> maybe some code is just running in an endless loop?
>
> Regards,
>
> Jan Karel Pieterse
> Excel MVP
> http://www.j...
>