1,02/09/15,18:00,RNGesus,Ingsoc,Y,Ingsoc
2,03/09/15,18:00,M’lady,Napoleon Wilson,Y,Napoleon Wilson
3,04/09/15,18:00,Ripley,Billy Casper,Y,Billy Casper
4,05/09/15,18:00,Jenkins,Tyler,Y,Jenkins
How do I print only the date on the 3rd line?
1,02/09/15,18:00,RNGesus,Ingsoc,Y,Ingsoc
2,03/09/15,18:00,M’lady,Napoleon Wilson,Y,Napoleon Wilson
3,04/09/15,18:00,Ripley,Billy Casper,Y,Billy Casper
4,05/09/15,18:00,Jenkins,Tyler,Y,Jenkins
How do I print only the date on the 3rd line?
This should help you:
f = open("D:\\Test.txt","r")
third_line = f.readlines()[2].strip()
f.close()
print(third_line)
Output:
3,04/09/15,18:00,Ripley,Billy Casper,Y,Billy Casper
Here's example:
with open("./records.txt") as f:
lines = f.readlines()
for i, line in enumerate(lines):
if i==3:
print(line)