file handling in python

1. read file and output all


lines = open("1.txt").readlines()
for l in lines[:]:
    print "%s" % l,


2.fix tiny error

f_in = open("1.txt")
f_out = open("2.txt", "w")
lines = f_in.readlines()
for line in lines:
        numbers = list(map(float, line.split()))
        print("%lf %lf %lf" % (numbers[0], numbers[1], numbers[2]))
        f_out.write("%lf %lf %lf\n" % (numbers[0], numbers[1], numbers[2]))
print("exchange done!")
f_out.close()
f_in.close()


你可能感兴趣的:(file handling in python)