If this number is written in the text file in.txt
, it will be substituted for the list data
by writing:
with open('in.txt', 'r') as f:
data = [ ]
line=f.readline()# Read line 1
while line:
Exclude data.append(line.rstrip())#line because it also contains newline characters
# (Note that this excludes blank characters.)
line=f.readline()# Read the next line
This is a one-liner solution for external file entry.
import sys
data = [n.trip() for n in sys.stdin.readlines()]
print(data)
Behavioral Demo: https://wandbox.org/permlink/pr6r7UrTzkU8rRhj
© 2024 OneMinuteCode. All rights reserved.