problems opening files

MRAB google at mrabarnett.plus.com
Fri Feb 13 14:40:51 EST 2009


mike wrote:
> I have aprogram that manipulates several text files, does some math
> and saves new files then exits.
> 
> The program worked fine on the original set of data, but with new data
> does not open the files as needed.  When I copy and paste the 'open
> line' from the module to IDLE the file opens.
> 
> section of code that is not working and import statements below:
> 
> import statements------------
> 
> # combine point source data
> 
> from numpy import *
> from string import *
> import point_input
> 
> section of code-----------------
> 
> pathincbp=path+'/sub'+sub+'/cbp_'+npdes+'.txt'
>     flag='false'
>     while flag=='false':
>         try:
>             cbpin=open(pathincbp,'r')
>             flag='true'
> 
> stopping the module manually------------------------------
> 
> Traceback (most recent call last):
>   File "C:\Python25\point_sources\combine_point_sources_swat.py", line
> 155, in <module>
>     print pathincbp+' not found'
> KeyboardInterrupt
> 
> IDLE commands---------------------------
> 
>>>> cbpin=open(pathincbp,'r')
>>>> cbpin
> <open file 'c:/potomac_points_data/sub1/cbp_PA0026051.txt', mode 'r'
> at 0x01450380>
> 
> I am running in windows xp professional 2002 service pack 3 on a Xeon
> dell
> 
What exception is the open() raising? From the partial code you've
provided I can't tell whether the 'try' is catching any exception. The
traceback just tells me that you interrupted the script, not what "is
not working" actually means.



More information about the Python-list mailing list