Timeline for How to convert string to bytes in Python 3
Current License: CC BY-SA 4.0
19 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 22, 2025 at 23:21 | history | edited | Shelvacu | CC BY-SA 4.0 |
str.encode works, but is not how that method is intended to be used. It should be called on the string.
|
| Jun 9, 2022 at 13:09 | history | edited | LOrD_ARaGOrN | CC BY-SA 4.0 |
print statement for clarity.
|
| Sep 25, 2019 at 13:10 | review | Low quality answers | |||
| Sep 25, 2019 at 14:29 | |||||
| Jun 14, 2019 at 12:27 | history | edited | vvvvv | CC BY-SA 4.0 |
added 1 character in body
|
| Jun 23, 2018 at 5:16 | comment | added | abarnert |
@KolobCanyon The question already shows the right way to do it—call encode as a bound method on the string. This answer suggests that you should instead call the unbound method and pass it the string. That's the only new information in the answer, and it's wrong.
|
|
| Apr 11, 2018 at 7:41 | comment | added | Antti Haapala |
... i.e. you're needlessly making an unbound method, and then calling it passing the self as the first argument
|
|
| Jun 16, 2017 at 21:14 | review | Low quality answers | |||
| Jun 17, 2017 at 3:23 | |||||
| Jun 16, 2017 at 21:13 | comment | added | ohmu | This answer looks more like a comment to me. How does this actually answer the question? | |
| May 14, 2017 at 20:20 | comment | added | Vladimir Shebuniayeu | You should be very carefull because encode create bytes but class will still be str, bytes method create bytes class. | |
| Mar 17, 2017 at 13:44 | history | edited | Ted | CC BY-SA 3.0 |
bytes is a built in function, using it as the name for a string variable was confusing. str.decode() function doesn't work as entered.
|
| Feb 1, 2017 at 8:16 | history | edited | Right leg | CC BY-SA 3.0 |
than*
|
| S May 19, 2016 at 20:57 | history | suggested | gouthamr | CC BY-SA 3.0 |
insure != ensure
|
| May 19, 2016 at 20:06 | review | Suggested edits | |||
| S May 19, 2016 at 20:57 | |||||
| Jun 22, 2015 at 11:51 | comment | added | jfs |
@Mike: use obj.method() syntax instead of cls.method(obj) syntax i.e., use bytestring = unicode_text.encode(encoding) and unicode_text = bytestring.decode(encoding).
|
|
| Aug 13, 2014 at 9:33 | comment | added | Mike | FYI: str.decode(bytes) didn't work for me (Python 3.3.3 said "type object 'str' has no attribute 'decode'") I used bytes.decode() instead | |
| Jul 2, 2014 at 2:32 | review | Suggested edits | |||
| Jul 2, 2014 at 2:41 | |||||
| S Sep 28, 2013 at 23:01 | history | suggested | Community Bot | CC BY-SA 3.0 |
fix typo - the variable in str.encode is my_str not data
|
| Sep 28, 2013 at 22:37 | review | Suggested edits | |||
| S Sep 28, 2013 at 23:01 | |||||
| Jul 6, 2013 at 7:09 | history | answered | hasanatkazmi | CC BY-SA 3.0 |