0

Why do it says i need a int() value, not a str() one?

file = open("/usercode/files/books.txt", "r") #your code goes here for i in file: riga = file.read("/usercode/files/books.txt").splitlines file.close()

17th Oct 2020, 8:22 AM
Diga17
Diga17 - avatar
6 odpowiedzi
+ 4
Diga17 , you have shown only a part of your code. The best would be to publish the complete code here. Thanks!
17th Oct 2020, 11:13 AM
Lothar
Lothar - avatar
+ 2
Because file.read expects an integer value. The integer represents, how many characters will be read from the file. You can also omit the integer to read the whole file, but using string causes errors. You need the string only for opening the file, which is already done on the first line. But it anyways isn't the only error.
17th Oct 2020, 9:42 AM
Seb TheS
Seb TheS - avatar
+ 2
> You code should be : > for line in file: > file.read(line) line here is integere not string . this is wrong
17th Oct 2020, 10:34 PM
Евгений
Евгений - avatar
+ 2
HBhZ_C no, I mean it should be for line in file: print(line) You should either loop through the file for i in file: ... then you have a single line of the file in the variable "i" on every iteration. Or you should do riga = file.readlines() and then you have whole contents of the file in the array "riga", which you can iterate through using for-loop. Your original code is misleading, noone should rely on it.
17th Oct 2020, 11:10 PM
Евгений
Евгений - avatar
+ 1
Thanks Евгений .It is better now
17th Oct 2020, 10:47 PM
HBhZ_C
HBhZ_C - avatar
0
Your code should be : for line in file: riga = file.readlines() print(riga)
17th Oct 2020, 11:13 AM
HBhZ_C
HBhZ_C - avatar