stormholder
IS-IT--Management
Hey all,
I think I'm having a pretty basic problem - just started using python today. The code reads as follows:
f=open("sortjuly.txt","r")
for line in f:
line_txt = line
page_txt = open(line_txt,"r").read()
text = open(page_txt,"r").read()
print(page_txt + text)
Basically "sortjuly.txt" is a directory listing about 1000 htm files I need to process. In each of the htm files is a 4-6 digit number. Basically I need to get an output that gives the file name and then the text from inside the file. For example:
hmd-dyster.htm contains the string '43921'.
I need the final output to read:
"hmd-dyster.htm 43921"
The error I keep getting with this code reads:
Traceback (most recent call last):
File "C:/Documents and Settings/chagin/Desktop/HardinMD/sort-script.py", line 5, in -toplevel-
page_txt = open(line_txt,"r").read()
IOError: [Errno 2] No such file or directory: 'hmd-about.htm\n'
>>>
For some reason the string "line_txt" keeps getting the "\n" tacked onto it and I can't figure out how to get it off. I tried printing the variable and it (the "\n") didn't show up.
Thanks for any assistance!
Charles.
I think I'm having a pretty basic problem - just started using python today. The code reads as follows:
f=open("sortjuly.txt","r")
for line in f:
line_txt = line
page_txt = open(line_txt,"r").read()
text = open(page_txt,"r").read()
print(page_txt + text)
Basically "sortjuly.txt" is a directory listing about 1000 htm files I need to process. In each of the htm files is a 4-6 digit number. Basically I need to get an output that gives the file name and then the text from inside the file. For example:
hmd-dyster.htm contains the string '43921'.
I need the final output to read:
"hmd-dyster.htm 43921"
The error I keep getting with this code reads:
Traceback (most recent call last):
File "C:/Documents and Settings/chagin/Desktop/HardinMD/sort-script.py", line 5, in -toplevel-
page_txt = open(line_txt,"r").read()
IOError: [Errno 2] No such file or directory: 'hmd-about.htm\n'
>>>
For some reason the string "line_txt" keeps getting the "\n" tacked onto it and I can't figure out how to get it off. I tried printing the variable and it (the "\n") didn't show up.
Thanks for any assistance!
Charles.