+ 1

How can i open a file as integer in python?

I tried to open it as integer in Python as f = open ("file.txt","r") print (int(f.read)) this is my 1st Que so please up vote so I will done the achievement

27th Sep 2018, 5:04 PM
Bhavik Mahalle
Bhavik Mahalle - avatar
1 Réponse
+ 3
f = open ("file.txt","r") print (int(f.read)) TypeError: int() argument must be a string, a bytes-like object or a number not 'builtin_function_or_method' You are trying to convert the "read" method (a function definition) to an integer. You should be calling it instead (so that you convert its output): f.read() If you want to test with a file here on SoloLearn, create the file first: ##### with open("file.txt", "w") as f: f.write("42")
27th Sep 2018, 5:10 PM
Kirk Schafer
Kirk Schafer - avatar