Python txt file contains scientific notation type data can be directly converted to float type

I don't know if you have ever been confused, that is, when reading and writing txtdata in a file, if the data in a txt file is expressed in scientific notation, can it be all out? The answer is yes. We know that txtthe data format read directly from the file is of stringtype, so we need to make a new conversion for this type. Here we use floatkeywords.

For convenience, txtonly one data is stored in the test file. As follows:
txt test data
Then we use the following code to read in the data.

with open(r"C:\Users\15025\Desktop\debug1.txt", "r") as f:
    all_data = f.readlines()
    print(float(all_data[0]))
#
# 6.317438621610765e-05

We can see that in the end we successfully read the corresponding value, so we say txtthat the scientific notation type data in the file can be directly converted into floattypes and other types that can be calculated.

If you find it useful, please raise your hand to give a like and let me recommend it for more people to see~

Guess you like

Origin blog.csdn.net/u011699626/article/details/110944887