get first line of file python
with open('myfile.txt') as f:
first_line = f.readline()
get first line of file python
with open('myfile.txt') as f:
first_line = f.readline()
how to replace first line of a textfile python
with open("test.txt") as f:
lines = f.readlines()
lines # ['This is the first line.n', 'This is the second line.n']
lines[0] = "This is the line that's replaced.n"
lines # ["This is the line that's replaced.n", 'This is the second line.n']
with open("test.txt", "w") as f:
f.writelines(lines)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us