From the course: Effective Serialization with Python
Unlock the full course today
Join today to access over 22,700 courses taught by industry experts or purchase this course individually.
Serialization with repr - Python Tutorial
From the course: Effective Serialization with Python
Serialization with repr
- [Narrator] There are two ways to represent python objects as a string, str and repr. Str is for external representation, and repr is for developers. Lets have a look. So iphython, and we are going to define i and s as the integer one and the string one. If I'm going to print them out i and s, they look exactly the same. However, they're of different types. If you print the repr, so print repr of i and repr of s, we now see the difference. Repr is usually a way a to create such an object. It means that if you take the repr of i and use it in the python prompt, you will get an integer. So, I am going to copy the repr of i, and then do i one equal and then paste what I got, and the type of i1 is an integer. And if i'll take the repr of s, and copy it over, and then do s1 and paste what I got, I'll get a str. I highly recommend that you'll add a repr to your own types, and use the repr format when logging. This way you…