Created
July 4, 2016 20:38
-
-
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
This file contains 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
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