I have a text file with about 5 million lines and each line contains three numbers, like for example:
33.56 77.32 12.54
The numbers always have the same length.
Now I have to add a minus sign before the last number to get the following output:
33.56 77.32 -12.54
How can I do that in Python?
with open("filename.csv") as fh:
for line in fh:
line = line.strip()
print(line[:12] + "-" + line[12:])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.