Last active
August 29, 2015 14:21
-
-
Save bfueldner/8ae82cd64218100dcfef to your computer and use it in GitHub Desktop.
Replace keywords in string from dict
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
import re | |
ifile = open("smybol.txt, "r") | |
data = ifile.read() | |
ifile.close() | |
map = {} | |
map["DEVICE"] = "Resistor" | |
map["VALUE"] = "10k" | |
res = re.sub("\$(\w+)", lambda m: map[m.group(1)] if m.group(1) in map else m.group(0), data) | |
print res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment