The text file contains an integer.

file = open('file.txt') print(int(file)) file.close() 
  • 2
    переменная = int(file.read().strip()) - andreymal

1 answer 1

To open files, better use the with as construct.

 with open("file.txt") as file: int_number = file.read() print(int_number) 

Close the file, do not take care of it python