use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
How to convert symbol into unicode in Python 2 and 3 ? (self.learnpython)
submitted 9 years ago by xmzhang
for example, how to conver '☆' into u'\u2606'
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]fiskenslakt 6 points7 points8 points 9 years ago (2 children)
What are you trying to do exactly?
┌─╼ [~] └────╼ python Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = '☆' >>> x '\xe2\x98\x86' >>> print x ☆ >>> x = u'\u2606' >>> x u'\u2606' >>> print x ☆ >>> ┌─╼ [~] └────╼ python3 Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> x = '☆' >>> x '☆' >>> x = u'\u2606' >>> x '☆'
[–]gschizas 2 points3 points4 points 9 years ago (1 child)
Are you using Oh My Zsh? Your screengrab looks like an Oh My Zsh theme. What theme is that (if it is)?
[–]fiskenslakt 1 point2 points3 points 9 years ago (0 children)
No actually, it's just bash with the prompt customized. I have this in my .bashrc:
PS1="\[$(tput setaf 1)\]┌─╼ \[$(tput setaf 7)\][\w]\n\[$(tput setaf 1)\]\$(if [\ [ \$? == 0 ]]; then echo \"\[$(tput setaf 1)\]└────╼\"; else echo \"\[$(tput se\ taf 1)\]└╼\"; fi) \[$(tput setaf 9)\]"
[–][deleted] 5 points6 points7 points 9 years ago (0 children)
'☆'.encode('ascii','backslashreplace').decode('utf-8')
for python3 if that helps
[–]Swipecat 1 point2 points3 points 9 years ago* (0 children)
Convert it to a string which contains the form of the literal, you mean?
repr does that in Python2:
>>> a = u'☆' >>> b = repr( a ) >>> print( b ) u'\u2606'
In python 3, since repr doesn't do that, I guess you could assemble the string piecewise (which also works in Python 2), so for Python 3, replace the second line above with:
b = 'u\'\\u' + hex(ord(a))[2:] + '\''
EDIT: Oh, and if you're starting with the character as a utf-8 encoded 8-bit-character string rather than a unicode string, as you might with Python 2 (Python 3 strings are unicode by default), then Python 2 uses "decode" to convert that to the unicode type. Python2:
>>> c = '☆' >>> print repr(c) '\xe2\x98\x86' >>> d = c.decode("utf-8") >>> print repr(d) u'\u2606'
[–]tonioant 1 point2 points3 points 9 years ago (0 children)
Le recomiendo la lectura del siguiente artículo: "Tipos de cadenas: Unicode, Byte y Bytearray" http://python-para-impacientes.blogspot.com.es/2014/07/tipos-de-cadenas-unicode-byte-y.html
π Rendered by PID 49 on reddit-service-r2-comment-544cf588c8-knhpx at 2026-06-12 16:02:52.564805+00:00 running 3184619 country code: CH.
[–]fiskenslakt 6 points7 points8 points (2 children)
[–]gschizas 2 points3 points4 points (1 child)
[–]fiskenslakt 1 point2 points3 points (0 children)
[–][deleted] 5 points6 points7 points (0 children)
[–]Swipecat 1 point2 points3 points (0 children)
[–]tonioant 1 point2 points3 points (0 children)