How to delete the first line of a text file?

前端 未结 8 1950
醉梦人生
醉梦人生 2020-11-29 09:10

I have been searching online, but have not found any good solution.

Here is my text file:

[54, 95, 45, -97, -51, 84, 0, 32, -55, 14, 50, 54, 68, -3,          


        
相关标签:
8条回答
  • 2020-11-29 09:53

    I too wanted to read the first line of a file:

    # open the file and read the contents
    fp = open(file_path_name)
    content = fp.readline()                 # read just the first line
    print(content)
    

    Worked well for me.

    0 讨论(0)
  • 2020-11-29 09:56

    Just a suggestion, cause I faced the same problem with the difference that I didn't want to delete the first raw from the original .txt file just to use the content from the 2nd raw and on.

    I use the simple solution of

    with open(file) as f:
        content = f.readlines()
        content = content[1:]
    

    This is always the case if you don't want to permanently delete the content of the file.

    0 讨论(0)
提交回复
热议问题