I don't know if you have ever been confused, that is, when reading and writing txt
data 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 txt
the data format read directly from the file is of string
type, so we need to make a new conversion for this type. Here we use float
keywords.
For convenience, txt
only one data is stored in the test file. As follows:
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 txt
that the scientific notation type data in the file can be directly converted into float
types 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~