So far I have this:
f = open('studs.txt')
with open('studs.txt') as inputFile:
tupless = [tuple(line.split()) for line in inputFile.readlines()]
print(tupless)
The text file format I'm opening is like this:
12345 5 G421 Hello Sir
12345 2 G782 Byeee Sir
So with this code it prints out something like this:
[('12345', '5', 'G421', 'Hello', 'Sir'), ('12345', '2', 'G782', 'Byeee' ,'Sir']
Now I want an output like this:
['12345','5','G421', 'Hello', 'Sir'] \n
['12345','2','G782', 'Byeee' ,'Sir']
etc.
Can anyone steer me in the right direction please?
with open("studs.txt") as f:
for line in f:
print(line.split())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.