I am pretty new to python and found out something that I do not understand about the readline()-function:
Code 1:
f = open("Files/bestTest.txt", "w")
data = f'4\rtest'
f.write(data)
f.close()
f = open("Files/bestTest.txt", "r")
x = float(f.readline())
print(2 * x)
f.close()
The first code works and prints: 8.0
Code 2:
f = open("Files/bestTest.txt", "w")
data = f'4\rtest'
f.write(data)
f.close()
f = open("Files/bestTest.txt", "r")
print(2 * float(f.readline()))
f.close()
The second code does not work and throws an error: ValueError: could not convert string to float: 'test'
I do not understand why the little difference in the code leads to the error. In the second code readline() seems to also return the second line for some reason. Maybe someone can explain that to me.
Thanks in advance