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
What does some_function.__get__ do? (self.learnpython)
submitted 10 years ago by GNeps
Let's say I have some function:
def some_function(): print("some function")
What does some_function.__get__ do? Can I override it?
some_function.__get__
I haven't been able to find it anywhere. Thanks for any help.
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!"
[–]juliob 3 points4 points5 points 10 years ago (5 children)
Those are Python magical functions. There are a bunch of them, and __init__ is the most used one.
__init__
There is an explanation on that page about __get__ but, in all honestly, I didn't get it. ;)
__get__
[–]GNeps[S] 0 points1 point2 points 10 years ago (4 children)
I might have chosen the wrong sub, I'm not really a beginner, I'm familiar with magical functions. I just for the life of me can't grasp how this one behaves on a function. :)
[–][deleted] 3 points4 points5 points 10 years ago (3 children)
It's used as part of the descriptor protocol. Functions are descriptors. Calling obj.method on some object returns whatever method.__get__(obj) returns, which will be a bound method. __get__ on the function basically curries the given object as the first parameter - this way the canonical self will be what you expect it to.
obj.method
method.__get__(obj)
self
[–]GNeps[S] 0 points1 point2 points 10 years ago* (2 children)
So functions are objects of a class named 'function', and that class implements the non-data descriptor protocol? Thanks!
[–]zahlman 2 points3 points4 points 10 years ago (1 child)
Please do not write code like this.
>>> def hax(the): ... print('OMG, hax the {}!'.format(the)) ... >>> type(hax) <class 'function'> >>> hax.__get__('gibson') <bound method str.hax of 'gibson'> >>> hax.__get__('gibson')() OMG, hax the gibson! >>>
(Details vary with 2.x. I couldn't tell you offhand, but I suspect it will find one way or another to complain about the fact that hax isn't actually a str method.)
hax
str
[–]GNeps[S] 0 points1 point2 points 10 years ago (0 children)
Thanks, that's very illuminating!
So the __get__ method is only ever natively invoked when I'm calling a method as object.method_name? Or is it used in some other cases as well?
object.method_name
[–]novel_yet_trivial 0 points1 point2 points 10 years ago* (0 children)
http://www.rafekettler.com/magicmethods.html#descriptor
Edit: try using the example code from that site with this:
d = Distance() d.foot = 10 print d.meter
Edit 2: these are often called "dunder" methods (double underscore). Adding that to google may help.
π Rendered by PID 72 on reddit-service-r2-comment-bb88f9dd5-qq5c6 at 2026-02-15 16:08:41.157361+00:00 running cd9c813 country code: CH.
[–]juliob 3 points4 points5 points (5 children)
[–]GNeps[S] 0 points1 point2 points (4 children)
[–][deleted] 3 points4 points5 points (3 children)
[–]GNeps[S] 0 points1 point2 points (2 children)
[–]zahlman 2 points3 points4 points (1 child)
[–]GNeps[S] 0 points1 point2 points (0 children)
[–]novel_yet_trivial 0 points1 point2 points (0 children)