I have a problem with the fact that when I open a file and import a line with command f.readline ().I run the module then It works good. It shows the number 600 or it doesn’t matter what number it is. But how I can get that number to be used in further calculations? When I type the next calculation command, it says something like for command int it should be a string or a number. But how I turn that text file number to number that I can calculate with and Python understands?
from math import *
with open('C:\\Users\\admin\\Desktop\\terehommik.txt', 'r') as f:
for line in f:
s = f.readline()
and from that line comes the number, and now i need to convert string number to real number
so i could after calculate with bank rate
Use the
intfunction:So,
ADDENDUM:
OP, does your input file contain one number per line? That’s what I’ll assume for now.
If the contents of
myfileare:then the above code will work, printing:
N.B., for floats, use the aptly named
floatfunction instead.