Help with reading file in windows.

Hyperion AgentSmith at Matrix..com
Tue May 20 18:20:02 EDT 2003


Can you tell me what was wrong with my code though? and why it didnt
work?





















Anand Pillai wrote:

> This is one way of doing it.
> 
> asking = raw_input("what is the file? ")
> reading_file = open(asking, 'r')
> text_infile=''
> try:
>     text_infile = reading_file.read()
> except IOError, e:
>     print e
>     return
> 
> reading_file.close()
> print text_infile
> 
> 
> Anand Pillai
> 
> Hyperion <AgentSmith at Matrix..com> wrote in message
> news:<babt4n$9ma$1 at news6.svr.pol.co.uk>...
> > 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 = concat(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