As an example, how would I get the code for § in python. § is be represented as '\u00a7', but I would like it to give me the code 00a7, so I can use it in the creation of code files. Also I would like this to work if I just put the letter 'a'
Asked
Active
Viewed 203 times
-2
-
It's `print u"\u00a7"` in Python 2 and `print("\u00a7")` in Python 3. The u standing for Unicode. – Carson Jul 14 '17 at 20:51
-
the answer to that question doesn twork the later works and makes me feel dumb – sourrabbit Jul 14 '17 at 20:51
-
`r"\u00a7".split(r'\u')[1]` – cs95 Jul 14 '17 at 20:53
2 Answers
0
Something along the lines of this?
c = '\\u' + hex(ord(u'§'))[2:].rjust(4, '0')
print(c) # Prints \u00a7

jmd_dk
- 12,125
- 9
- 63
- 94
-
Thanks, but it doesn't exactly work since it has a limit of how it can go – sourrabbit Jul 14 '17 at 21:16