0

input file:

1
2
3
4
5

what I have at this time:

filename=input("Please enter the filename or path: ")
with open(filename, 'r') as file:
    filecontents=tuple(map(int, file.read().split()))

print(filecontents)

output: (1,2,3,4,5)

intended output:

1
2
3
4
5
kuro
  • 3,214
  • 3
  • 15
  • 31
  • you converted strings to numbers so you removed `'\n`. And you keep it in `tuple` so you get it as `(..., ...)`. You would have to use `for`-loop to display every value separatelly and then `print()` will display it in separated lines. – furas Jun 11 '21 at 05:16
  • if you want intended output then you should read `filecontents = file.read()` - without spliting, converting to integer, and keeping in tuple. OR you have to convert integers back to strings and use `"\n".join()` to reverse `split()` – furas Jun 11 '21 at 05:16

0 Answers0