![]() It depends on mental picture of the solved problem.Īnyway, the feature mentioned in the question is probably a by-product of the language implementation/design. Sometimes functions are more appropriate than the object methods, sometimes the reverse is true. more natural and more versatile than pure OO or pure procedural languages. A programming language is considered good if it contains constructs that one needs. It may also look that the second way is a syntactic sugar for the third approach.Ī programming language is a means to express abstract ideas formally, to be executed by the machine. To add to Lennart Regebro's answer There is even the third way that can be used: encoded3 = str.encode(original, 'utf-8')Īnyway, it is actually exactly the same as the first approach. Now my question is, why are there 2 methods that seem to do the same thing, and is either better than the other (and why?) I've been trying to find answer to this on google, but no luck. U'something'.encode('utf-8') will generate b'something', but so does bytes(u'something', 'utf-8').Īnd b'bytes'.decode('utf-8') seems to do the same thing as str(b'bytes', 'utf-8'). So the idea in python 3 is, that every string is unicode, and can be encoded and stored in bytes, or decoded back into unicode string again. I've read some good posts, that made it all much clearer, however I see there are 2 methods on python 3, that handle encoding and decoding, and I'm not sure which one to use. I am new to python3, coming from python2, and I am a bit confused with unicode fundamentals.
0 Comments
Leave a Reply. |