Help with reading file in windows.

Hyperion AgentSmith at Matrix..com
Mon May 19 20:33:28 EDT 2003


Hi all.

 I am in the middle of creating or rather trying to create :) a script
for searching through a log file for key words etc.etc.

However I am having trouble with opening the file and getting it to
read.

I have tried.

----------------------------------------- 
asking = raw_input("what is the file? ")
reading_file = open(asking).r
text_infile = reading_file.read()
reading_file.close()
print text_infile,
-----------------------------------------

to see if it would print the text, so i could then move on to code it
some more.
It didnt work.

I also tried:

-----------------------------------------
asking = raw_input("what is the file? ")
reading_file = file(asking).read()
print reading_file,
-------------------------------------


Each one of these tries has resulted in an io error of the following:

--------------------------------------------------------------------
Traceback (most recent call last):
  File
"C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 301, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Python-scripts\readingscript.py", line 5, in ?
    reading_file = file(asking).read()
IOError: [Errno 2] No such file or directory: 'C:\\Program
Files\\mIRC\\logs\\#politics.EFNet.txt'
>>> 
-----------------------------------------------------------------------------



What I would like to no is what I doing wrong?
How am I supposed to represent the log files true path?
I use "C:\Program Files\mIRC\logs\#politics.EFNet.txt"
which is the log files path on my system, but it is still giving me a no
such file or dir, as you can see from the error.

Has anyone got any ideas what I am doing wrong? or rather were I am
going wrong?

Thanks :)
Hyperion




More information about the Python-list mailing list