On Wed, Dec 1, 2021 at 8:18 PM Abdulla Al Kathiri <alkathiri.abdu...@gmail.com> wrote: > > > > > On 1 Dec 2021, at 12:01 PM, Chris Angelico <ros...@gmail.com> wrote: > > > > On Wed, Dec 1, 2021 at 6:43 PM Abdulla Al Kathiri > > <alkathiri.abdu...@gmail.com> wrote: > >>> On 1 Dec 2021, at 10:16 AM, Chris Angelico <ros...@gmail.com> wrote: > >>> 3) If "yes" to question 1, would you use it for any/all of (a) mutable > >>> defaults, (b) referencing things that might have changed, (c) > >>> referencing other arguments, (d) something else? > >> I will definitely use it for default mutable collections like list, set, > >> dictionary etc. I will also use it to reference things that might have > >> changed. For example, when making callbacks to GUI push buttons, I find > >> myself at the start of the function/callback to be fetching the values > >> from other widgets so we can do something with them. Now those values can > >> be directly passed as late-bound defaults from their respective widgets > >> (e.g., def callback(self, text1 => self.line_edit.text()): …). > >>> > > > > Very interesting. That doesn't normally seem like a function default - > > is the callback ever going to be passed two arguments (self and actual > > text) such that the default would be ignored? > Yeah. Let’s say the callback prints the text on the main window console. I > could use the same function to print something on the console not related to > the default widget changing text. Maybe another push button that prints > literal “WOW”. If I made the second argument a default widget (def > callback(self, line_edit=self.line_edit):...) and then call line_edit.text() > inside the function, I would be able to pass any other widget that has the > method text() but I wouldn’t be able to pass a literal text. >
Ahh gotcha. Then yes, you have a function that takes up to two parameters (or one if you don't count self), and yes, omitting the second argument will have the same effect as fetching the text from that control. So, sounds like a great use for it! ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/7GUNW4R3TSJC6UXQ5D4P7QQ3XBF75NK2/ Code of Conduct: http://python.org/psf/codeofconduct/