file-writing:formatting

Wojtek Walczak gminick at hacker.pl
Fri Dec 13 15:38:33 EST 2002


Dnia Fri, 13 Dec 2002 19:13:20 +0100, Christoph Lehmann napisał(a):
> x looks like (1234.1234, 1, 2345,2345, 'left')
A working code:
---
import types
x = (1234.1234, 1, 2345.2345, 'blah')

f = open("blah.txt", "w")

for i in x:
   if type(i) == types.FloatType:
      f.write("%.2f\n" % (i))
   else:
      f.write(str(i)+"\n")
---

HTH.

-- 
[ ] gminick (at) underground.org.pl  http://gminick.linuxsecurity.pl/ [ ]
[ "Po prostu lubie poranna samotnosc, bo wtedy kawa smakuje najlepiej." ]



More information about the Python-list mailing list