Skip to content

Instantly share code, notes, and snippets.

@bfueldner
Last active August 29, 2015 14:21
Show Gist options
  • Save bfueldner/8ae82cd64218100dcfef to your computer and use it in GitHub Desktop.
Save bfueldner/8ae82cd64218100dcfef to your computer and use it in GitHub Desktop.
Replace keywords in string from dict
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