Answer the question
In order to leave comments, you need to log in
How to get the content of a specific line of each file?
There are a large number of .txt data files. From each file, you need to get the contents of the second line, how to implement this? Can you please provide a python script?
Answer the question
In order to leave comments, you need to log in
I created a text document called veg, here is its content:
eggplant
pear
apple
potato
Here is my solution to your problem:
f = open(r'veg.txt', 'r', encoding='utf-8')
text = f.read().split('\n')
print(text[1])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question