Question

When reading the file in python, How can I remove the first line of the file?...

When reading the file in python, How can I remove the first line of the file?

Here is my text file:

Country|Population|Area
China|1,339,190,000|9,596,960.00
United States of America|309,975,000|9,629,091.00
Brazil|193,364,000|8,511,965.00
Japan|127,380,000|377,835.00

0 0
Add a comment Improve this question Transcribed image text
Answer #1
filename = input('Enter file name: ')
f = open(filename, 'r')
first_line = True
for line in f:
    if first_line:  # ignore first line
        first_line = False
    else:  # process rest of the lines
        print(line.strip())  # I am just printing rest of the lines, you can use it do anything..
f.close()
Add a comment
Know the answer?
Add Answer to:
When reading the file in python, How can I remove the first line of the file?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT