Created
March 12, 2011 01:29
-
-
Save tstachl/866918 to your computer and use it in GitHub Desktop.
Search and replace a string in a file as a python one-liner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Search and replace a string in a file as a python one-liner | |
@author Thomas Stachl | |
@created Mar 12, 2011 | |
@license Attribution 3.0 Unported (CC BY 3.0) | |
This work is licensed under the Creative Commons Attribution 3.0 | |
Unported License. To view a copy of this license, visit | |
http://creativecommons.org/licenses/by/3.0/ or send a letter to | |
Creative Commons, 171 Second Street, Suite 300, San Francisco, | |
California, 94105, USA. | |
""" | |
def replaceInFile(file, pattern, subst): | |
open(file, "r+").write(open(file, "r").read().replace(pattern, subst)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment