python - pythonic way to write the code for search and replace string -
this question has answer here:
- search , replace operation 2 answers
i have written code search , replace string in make command per user input
make language='english' id=234 version=v1 path='/bin'
in above code searched version=v1
, replace version version=v2
import re strings = "make language='english' id=234 version=v1 path='/bin'" search_pattern= re.search('version=(.*?)\s', strings) old_str = search_pattern.group(1) print test.replace(old_str, "v2")
can me write above code in pythonic way or other way write above code
it's easy if use str.replace
string = "make language='english' id=234 version=v1 path='/bin'" string = string.replace("version=v1", "version=v2")
Comments
Post a Comment