newbie question(file-delete trailing comma)
kavitha thankaian
kavithapython at yahoo.co.in
Mon Feb 26 09:55:22 EST 2007
the input file what i have is already opened with write mode.
say i have a file input.txt which has
a,b,c,d,
and i need the output also in the same input.txt,,ie., the trailing comma in the input.txt file should be deleted,,,i dont need a file output.txt,,,
is there a way??
kavitha
Mohammad Tayseer <m_tayseer82 at yahoo.com> wrote:
ok, it should be
----------
import sys
in_file = open(sys.argv[1])
out_file = open(sys.argv[2], 'w')
for line in in_file:
print >> out_file, line.strip().strip(',')
----------
strip(',') will remove the ',' char from the beginning & end of the string, not the middle. empty strip() will remove whitespaces from the beginning & end of the string
I hope this solves your problem
kavitha thankaian <kavithapython at yahoo.co.in> wrote: hi
i would like to have the output as follows:
a,b,c,d
a1,b1,c1,d1
a2,b2,c2,d2
i would like to delete only the comma at the end and not the commas inbetween.
thanks,,,
---------------------------------
Any questions? Get answers on any topic at Yahoo! Answers. Try it now.
---------------------------------
Heres a new way to find what you're looking for - Yahoo! Answers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070226/51a7bc4b/attachment.html>
More information about the Python-list
mailing list