newbie question(file-delete trailing comma)
kavitha thankaian
kavithapython at yahoo.co.in
Wed Feb 28 06:34:29 EST 2007
thanks,,
now i have one more problem,,,
the strings should be seperated in an order,,,
some={1:'a', 2:7, 3:'c', 4:'d'}
i need the output to be a,c,d,7
before my code was:
field_order = [1,3,4,2]
for field in field_order:
f.writelines('\"%s\",' % someprt[field] )
do you have an idea now how should it look like???
Mikael Olofsson <mikael at isy.liu.se> wrote:
kavitha thankaian wrote:
> my script writes a dictionary to a file.but i need only the values
> from the dictionary which should be sepearted by a comma,,,so i did as
> following:
> [snip code that generates the incorrect original file]
> when i execute the above code,my test.txt file has the following:
> a,b,c,d,
> now i need to delete the comma at the end,,,this is my problem,,,
This is the first time you mention that you have control over the
generation of the original file. Then I suggest that you fix the problem
before generating the file. For instance, consider the following
interactive session.
>>> some={1:'a',2:7,3:'c',4:'d'}
>>> some
{1: 'a', 2: 7, 3: 'c', 4: 'd'}
>>> some.values()
['a', 7, 'c', 'd']
>>> [str(x) for x in some.values()]
['a', '7', 'c', 'd']
>>> ','.join([str(x) for x in some.values()])
'a,7,c,d'
Then write that to your file instead.
/MiO
--
http://mail.python.org/mailman/listinfo/python-list
---------------------------------
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/20070228/9b6d1ce5/attachment.html>
More information about the Python-list
mailing list