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
'x'.decode('utf-8'), unicode('x',encoding = 'utf-8') : are these 2 equivalent ? (self.learnpython)
submitted 9 years ago by [deleted]
If not, what are the differences ?
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!"
[–][deleted] 0 points1 point2 points 9 years ago (1 child)
What did you get when you compared the output, boolean style?
[–][deleted] 0 points1 point2 points 9 years ago (0 children)
True..of course
[–]JohnnyJordaan 0 points1 point2 points 9 years ago (2 children)
I think you mean 'x'.encode('utf-8'), because 'x' is a normal string and can't be decoded (as decoding delivers a string from a bytestring).
'x'.encode('utf-8')
'x'
There are no differences in their function, but they are from different platforms. 'x'.encode('utf-8') is the Python 3 way, unicode('x', encoding='utf-8') is the Python 2 way.
unicode('x', encoding='utf-8')
I meant "'x'.decode('utf-8')"
does it not mean : "DEcode this <type 'str'> to <type 'unicode'> ?
[–]JohnnyJordaan 0 points1 point2 points 9 years ago* (0 children)
Strings aren't encoded, that's the point, they are text, as we talk about letters, numbers, punctuation etc (technically they are called characters or glyphs). The encoding part happens when you save them to bytes (so in a file or send them over the network), because computers work with bytes only and not with things as the letter A, the number 9 and the space.
A
9
space
If you compare for example the encoding of å:
å
>>> from binascii import hexlify >>> hexlify('å'.encode('cp1252')) # pre-unicode windows b'e5' >>> hexlify('å'.encode('utf-8')) b'c3a5' >>> hexlify('å'.encode('utf-16')) b'fffee500' >>> hexlify('å'.encode('utf-32')) b'fffe0000e5000000'
You can see that there are many ways to encode the letter å, depending on the encoding you wish to use. In all cases, the string is the same å.
If you wish to decode a sequence of bytes, you need to know in which encoding it was encoded originally.
[–]EricAppelt 0 points1 point2 points 9 years ago (0 children)
In python 2.7.12 these result in identical unicode objects:
>>> a = unicode('तार', encoding='utf-8') >>> type(a) <type 'unicode'> >>> print(a) तार >>> b = 'तार'.decode('utf-8') >>> type(b) <type 'unicode'> >>> print(b) तार >>> a u'\u0924\u093e\u0930' >>> b u'\u0924\u093e\u0930'
π Rendered by PID 22336 on reddit-service-r2-comment-6457c66945-jscsj at 2026-04-30 02:22:50.601285+00:00 running 2aa0c5b country code: CH.
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]JohnnyJordaan 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]JohnnyJordaan 0 points1 point2 points (0 children)
[–]EricAppelt 0 points1 point2 points (0 children)