-1

I Want to copy an specific line from a txt file (let's say the first line), so i could use that line in my program later. also i want to be able to copy other lines too.

Armin
  • 317
  • 3
  • 8
  • 5
    https://stackoverflow.com/questions/3277503/how-to-read-a-file-line-by-line-into-a-list does this answer your question? – user12758604 Mar 14 '20 at 09:28

1 Answers1

-1

readline() function should help you. It returns a list of lines which you could then use whenever you want in code.

  • hey. but how does this works? like if i want to copy the second line of my txt file i should write file.readline(2) ? – Armin Mar 14 '20 at 09:36
  • 1
    Try this(replace the path with your file path), `with open ("C:\Users\PycharmProjects\untitled\sorted_cron.txt", 'r') as f:` `line=f.readlines()` `print (line[0])` – Gokul nath Mar 16 '20 at 09:02