[ale] Python - read in text minus "\n"

Jeff Hubbs hbbs at comcast.net
Sat Jan 8 17:01:42 EST 2005


Will  input =  x.readline()[-1] work?

Jeff

On Sat, 2005-01-08 at 15:10, Benjamin Scherrey wrote:
> Since the grep result is providing the newline then that's the correct 
> behaviour (to give you the /n char in your input). But the simplest way 
> to get rid of it is to cut it off.
> 
> input =  x.readline()
> input = input[-1] // or input[-2] for a cr/lf input like from Windows
> 
> That do it or did I missunderstand your question?
> 
>        Ben Scherrey
> 
> Jay Loden wrote:
> 
> >I have a question for any Python programmers/hackers out there.
> >
> >I am reading (with popen() ) the return from a grep search.  However, using 
> >read()  or readlines() also reads in "\n" after every result.  Anyone know 
> >how I can read it in without the newlines?  
> >
> >I could of course read through the list and remove the last two characters of 
> >every item, but before i do that I wanted to make sure there isn't a function 
> >that reads without including \n, \t, \r and such.  Alternatively, maybe 
> >someone can suggest a regex to parse it out (I don't know regular expressions 
> >yet). 
> >
> >Thanks for any input!
> >-Jay
> >_______________________________________________
> >Ale mailing list
> >Ale at ale.org
> >http://www.ale.org/mailman/listinfo/ale
> >
> >  
> >
> 
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale



More information about the Ale mailing list