Skip to content

Instantly share code, notes, and snippets.

@bassitone
Created July 4, 2016 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bassitone/cad3b7d0789c8e34c6f38b44bc18c1e8 to your computer and use it in GitHub Desktop.
Save bassitone/cad3b7d0789c8e34c6f38b44bc18c1e8 to your computer and use it in GitHub Desktop.
Sample converter code I'm working on - unicode (or otherwise) symbols to plain English. Python 3.x
def main():
convert_table_example = {"$": "dollar",
"%": "percent",
"@": "at",
"alt": "alt",
".": "period",
"\\": "backslash"
" ": "space",
":": "colon"}
# Convert the above as needed
#get text. This is quick and dirty, much more OOP-y in the real code
cmd = input("Enter text to convert here: \n")
#test input: cmd = 99.99%
# test input: cmd = C:\Program Files
# cmd may contain one, many, or none of the above dict entries. All present must be replaced
cmd.replace("$", "dollar")
cmd.replace("%", "percent")
cmd.replace("@", "at")
#snip ...
cmd.replace("\\", "backslash")
#above only seems to evaluate the last one for some weird reason. Weird glitch or should I try an alternate way?
# regex magic goes here instead?
print("Your converted statement: " + cmd)
#successful output: 99 period 99
#successful output: C colon backslash Program space Files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment