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()
6 Respuestas
+ 4
Diga17 , you have shown only a part of your code. The best would be to publish the complete code here. Thanks!
+ 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.
+ 2
> You code should be :
> for line in file:
> file.read(line) line here is integere not string .
this is wrong
+ 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.
+ 1
Thanks Евгений .It is better now
0
Your code should be :
for line in file:
riga = file.readlines()
print(riga)