[ale] Python - read in text minus "\n"
Jay Loden
jloden at toughguy.net
Sat Jan 8 16:49:59 EST 2005
I randomly stumbled across what i wanted in the Python docs:
def serv_list():
grep_tsk = os.popen("grep -l \"start|stop\" " + init_dir + "*")
files = grep_tsk.read().splitlines()
grp_tsk.close()
return files
splitlines([keepends]):
Return a list of the lines in the string, breaking at line boundaries. Line
breaks are not included in the resulting list unless keepends is given and
true.
Thanks for the help though!
-Jay
On Saturday 08 January 2005 3:10, Ben 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
-------------------------------------------------------
More information about the Ale
mailing list