Search and replace a string in a file as a python one-liner
""" | |
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