Skip to content

Instantly share code, notes, and snippets.

@taylanpince
Created May 4, 2016 19:58
Show Gist options
  • Save taylanpince/755adf9a69f6d500461dc36baf67d63a to your computer and use it in GitHub Desktop.
Save taylanpince/755adf9a69f6d500461dc36baf67d63a to your computer and use it in GitHub Desktop.
Python read/write
f = open("doc.txt", "r+")
contents = f.read()
contents = contents.replace("word", "another")
f.seek(0)
f.write(contents)
f.truncate()
f.close()
print contents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment