Great tutorials overrall. 10/10. By the way, I just wanted to make a note. This probably came afterwards, considering how old the video is. A simple solution is: __repr__ = __str__. However, I'd be interested to read any feedback on this solution. Thank you
here's some helpfull link : pyformat.info/ a lit explanation on old format python used 'value' % (value) in new format can be used as 'value'.format(value) if used self on return value on format need to use self=self to represent the self correct me if i'm wrong
The left hand side of "self" is the local variable passed into the return "{self.__class}...." , the right hand side of "self" is the actual self received from the function __repr__(self) , which represents the actual object itself.
I understand what you mean in the different use cases for both methods, but may I ask, why is it like that?. Why did the communitty agree that str is better for readability and repr for 'debugging'
Hello, I have a question about extracting values from a dictionary array embedded in a csv data file. A snapshot of the dictionary looks like this: {"geodesic":false, "type":"Point", "coordinates": [35.9, 24.9]} How can I extract the coordinates from the dictionary and save them in separate column or export it to a csv file? I have had difficulty in getting this done. Appreciate your help. Thank you!
Yes, 'repr' refers to representation. As for your second question: not quite. While in principle you could place a string or a docstring within ___repr___ , that's not its pythonic/intended purpose. As mentioned in the video, ___repr___ needs to provide an unambiguous description of the *object*; a docstring is simply human readable description of the class. Moreover, docstrings, if they are provided, are already handled by the ___doc___ attribute. You can read it more about it here: www.python.org/dev/peps/pep-0257/
im seven months late but to my knowledge: No. I mean, if you want to print a bunch of messages when the method is called, you can do that, because there's nothing special about dunder methods except that they're automatically called by different functions. You can return a tuple of strings if you'd like, but why? def __str__(self): print('ran dunder str') return (self.__class__.__name__, 'another string', 'third string')
Great tutorials overrall. 10/10.
By the way, I just wanted to make a note. This probably came afterwards, considering how old the video is.
A simple solution is: __repr__ = __str__.
However, I'd be interested to read any feedback on this solution. Thank you
so far most clear & best tutorial about this topic on yt. You have made a great video with amazing effort.
This explanation is better than I found in paid course.
Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.
Amazing content, first of all very informative, second your voice and delivery are amazing. Thank you for this video.
Great video! Thanks for your effort on making these videos!!!
You're welcome! :-)
I like '...the Pythonic way to do this...' xD
import this
I'm in love with this channel ❤
Could you Please explain
self = self
I would really like an explanation of this as well
Me too
here's some helpfull link :
pyformat.info/
a lit explanation on old format python used 'value' % (value)
in new format can be used as 'value'.format(value)
if used self on return value on format need to use self=self to represent the self
correct me if i'm wrong
The left hand side of "self" is the local variable passed into the return "{self.__class}...." , the right hand side of "self" is the actual self received from the function __repr__(self) , which represents the actual object itself.
TsungJui Wang why is that necessary?
Great insight I had been struggling to comprehend this subject for quite some time ,this video helped a lot
Thanks for insightful video. Got it checked.
pretty explanatory and useful, thanks for this tutorial
Watching this tutorial could literally pay you money in the future LOL😆
very elegantly explained, thank you!
thank your for your efforts. Could you tell me the name of the package, which shows method details as you write?
press ctrl and click on the method name if you use pycharm
Thx from Brazil!!
Hi there, great video! What do you mean by inspecting the car object? 3:52
Very helpful explanation!
I'm glad you liked it!
this video helps me a lot 😍💚 thanks a lot man
great video
great explanation
I understand what you mean in the different use cases for both methods, but may I ask, why is it like that?. Why did the communitty agree that str is better for readability and repr for 'debugging'
Really helpful and concise. Thanks
You're welcome!
Thanks!
Great video(s). But you should have quotes around the {self.color}, no? So that repr(my_car) outputs: Car('red', 37281)
No
bro i love you
Great job, I have just a small question: what should I do if i want to get car("red","37281"), the diffrence is the quotation. Thank youuuuu
Note that you can add `!r` to the format string, so `{self.color!r}` and you get the repr of the child object for free!
Thanks for sharing! :-)
So finally I understood that developers are not humans :D
what program are you using for python?
thanks!
Came straight to the comment section to post something about “Dunder Mifflin… I know why I never learn shit
Hi! What font are you using in this video?
Your python terminal looks cool with the auto-complete, etc. Are you using some third party software for that?
Installed and it works great. Thanks. Also, in love with your whole series!
Daniel is using bpython for the interpreter.
Say you have a child class ElectricCar, can you make str(myElectricCar) print out the same str as the parent class?
Hello, I have a question about extracting values from a dictionary array embedded in a csv data file. A snapshot of the dictionary looks like this:
{"geodesic":false, "type":"Point", "coordinates": [35.9, 24.9]}
How can I extract the coordinates from the dictionary and save them in separate column or export it to a csv file? I have had difficulty in getting this done. Appreciate your help. Thank you!
Does repr mean representation? So you could put in almost like a doc string to help define the class?
Yes, 'repr' refers to representation.
As for your second question: not quite. While in principle you could place a string or a docstring within ___repr___ , that's not its pythonic/intended purpose. As mentioned in the video, ___repr___ needs to provide an unambiguous description of the *object*; a docstring is simply human readable description of the class. Moreover, docstrings, if they are provided, are already handled by the ___doc___ attribute. You can read it more about it here: www.python.org/dev/peps/pep-0257/
which editor is that, looks cool
I mainly use Sublime Text 3
thank you
You're very welcome!
man how do u change font and theme for jango ...///
Are you using PyCharm?
Python Shell
can __str__ and __repr__ return more than one string??? and if yes how
im seven months late but to my knowledge: No. I mean, if you want to print a bunch of messages when the method is called, you can do that, because there's nothing special about dunder methods except that they're automatically called by different functions. You can return a tuple of strings if you'd like, but why?
def __str__(self):
print('ran dunder str')
return (self.__class__.__name__, 'another string', 'third string')
For us JAVA folks, __str__ is "toString". Call me old fashion, but prefer to call it a "to string method" and not "dunder string". :-)
Thanks for sharing! :-)
For real, when I first heard someone say "dunder" I thought they flat out made a mistake.
Yeah
What text editor it is?
:o did RUclips finally added shortcut "k" to pause/continue or was I retarded?
7:06
dunder mifflin
Not a simple explanation
human consumption? youre not gunna eat the code lmao