Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType
On 28/04/2019 15:56, David wrote: > I'm sorry to hear it's such a headache. It sounds like the list > manager interface for that task is dreadful. It should be able to take > you straight to the configuration for the user who wrote the message. Its not that bad but it does involve copying the address then switching screens twice then doing a search for the email address then clicking an option and finally submitting the page. Then navigating back to the moderate queue to handle the next message. > I think our timezones are out of sync. It seems to take around a day > for my messages to reach the list. Quite possibly. I'm based in the UK and read the queue twice a day, so if you miss my early morning scan it will be 8-10 hours later before I look again. Then 12-16 hours before the next morning. Timing is everything! :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType
On Sun, 28 Apr 2019 at 02:57, Alan Gauld via Tutor wrote: > On 27/04/2019 01:22, David wrote: > > > It's no big deal, but I wonder why you wouldn't approve an address > > the first time you see that it is being used for legitimate discussion. > > Time... > > It takes about 10 seconds to scan a message and click the button > to pass it through (or reject it). It takes about 2-3 minutes to > navigate to the admin screens, find the email address and change the > moderation settings. > > So its only if I see the same address multiple times I feel the > need to take the time to de-moderate it. If its only an occasional > post its easier to just click Accept a few times. Thanks for replying. I'm sorry to hear it's such a headache. It sounds like the list manager interface for that task is dreadful. It should be able to take you straight to the configuration for the user who wrote the message. Or even automatically change the moderation status of the user, after one (or some configurable number) of their messages is approved. I think our timezones are out of sync. It seems to take around a day for my messages to reach the list. I guess I'll just remain as a reader, and only write if I have questions. It's not a problem. I'm grateful for the fact that it's a mailing list, not a forum. Thanks for keeping it spam free. I've written a question occasionally, but I usually manage to answer them myself while writing them, before hitting send, so I didn't trouble you with those :) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType
On 27/04/2019 01:22, David wrote: > It's no big deal, but I wonder why you wouldn't approve an address > the first time you see that it is being used for legitimate discussion. Time... It takes about 10 seconds to scan a message and click the button to pass it through (or reject it). It takes about 2-3 minutes to navigate to the admin screens, find the email address and change the moderation settings. So its only if I see the same address multiple times I feel the need to take the time to de-moderate it. If its only an occasional post its easier to just click Accept a few times. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType
On Sat, 27 Apr 2019 at 02:14, Alan Gauld via Tutor wrote: > On 26/04/2019 13:48, Arup Rakshit wrote: > > > BTW, one thing I would like to know about this list is that, everytime I > > send an email I see it the in list after 2 hours approx. Is this for me > > or everybody? I am just curious. > > Just for you! ...And every other new poster :-) > > It stays on moderation until the volume increases > to the point where I get to recognise the email address. > Around which point I get motivated to change the moderation > setting. I've just done that for you so they should > come through a little quicker now. I've been reading here for years, and I take this opportunity to give my sincere thanks to everyone who shares their knowledge here. I very occasionally respond to questions here, if I'm confident of what I have to say. I've always wondered why my responses often seemed to be ignored by other participants. Now I know. It's no big deal, but I wonder why you wouldn't approve an address the first time you see that it is being used for legitimate discussion. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType
On 26/04/19 8:58 PM, Alan Gauld via Tutor wrote: On 26/04/2019 13:48, Arup Rakshit wrote: BTW, one thing I would like to know about this list is that, everytime I send an email I see it the in list after 2 hours approx. Is this for me or everybody? I am just curious. Just for you! ...And every other new poster :-) It stays on moderation until the volume increases to the point where I get to recognise the email address. Around which point I get motivated to change the moderation setting. I've just done that for you so they should come through a little quicker now. Thanks Alan Gauld. As my post was taking hours to come to this, I asked a beginner question to the other list https://mail.python.org/pipermail/python-list/2019-April/740629.html . :) Next time I will be here only. -- Thanks, Arup Rakshit ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType
On Fri, Apr 26, 2019 at 06:18:32PM +0530, Arup Rakshit wrote: > BTW, one thing I would like to know about this list is that, everytime I > send an email I see it the in list after 2 hours approx. Is this for me > or everybody? I am just curious. Just you, I think. Looking at the headers of your post, I see when you sent the post: Received: from arup.local ([117.194.106.70]) by smtp.gmail.com Fri, 26 Apr 2019 05:48:35 -0700 (PDT) and then a few hops through google, to mail.python.org, and then there seems to be a long delay before mail.python.org sends it back out again. Perhaps you are stuck in the moderator queue? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType
On 26/04/2019 13:48, Arup Rakshit wrote: > BTW, one thing I would like to know about this list is that, everytime I > send an email I see it the in list after 2 hours approx. Is this for me > or everybody? I am just curious. Just for you! ...And every other new poster :-) It stays on moderation until the volume increases to the point where I get to recognise the email address. Around which point I get motivated to change the moderation setting. I've just done that for you so they should come through a little quicker now. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType
On 26/04/19 11:10 AM, Steven D'Aprano wrote: On Thu, Apr 25, 2019 at 02:52:07PM +0530, Arup Rakshit wrote: Here it is: *3.3.2.1. Customizing module attribute access* (https://docs.python.org/3/reference/datamodel.html#customizing-module-attribute-access) Oh! That's brand new in 3.7, no wonder I didn't know about it. I did see the core developers talking about adding this feature, but I didn't know that they had done so. Your original question was: In the simple code like what are the advantages we get from? Is this so that we can implement more special methods than just __getattr__ and __dir__ in the module level? Yes, that's what the documentation says. I don't see any reason not to believe it. Well I believed it, but I was not sure if I understood it correctly. So I was trying to confirm myself by those who understand the language. BTW, one thing I would like to know about this list is that, everytime I send an email I see it the in list after 2 hours approx. Is this for me or everybody? I am just curious. Oh, this is cool! I'm going to enjoy playing with this... py> from types import ModuleType py> class Magic(ModuleType): ... count = 0 ... @property ... def spam(self): ... self.count += 1 ... return ' '.join(['spam']*self.count) ... py> import sys py> sys.modules['__main__'].__class__ = Magic py> import __main__ py> __main__.spam 'spam' py> __main__.spam 'spam spam' py> __main__.spam 'spam spam spam' -- Thanks, Arup Rakshit ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType
On Thu, Apr 25, 2019 at 02:52:07PM +0530, Arup Rakshit wrote: > Here it is: *3.3.2.1. Customizing module attribute access* > (https://docs.python.org/3/reference/datamodel.html#customizing-module-attribute-access) Oh! That's brand new in 3.7, no wonder I didn't know about it. I did see the core developers talking about adding this feature, but I didn't know that they had done so. Your original question was: > In the simple code like what are the advantages we get from? Is this > so that we can implement more special methods than just __getattr__ > and __dir__ in the module level? Yes, that's what the documentation says. I don't see any reason not to believe it. Oh, this is cool! I'm going to enjoy playing with this... py> from types import ModuleType py> class Magic(ModuleType): ... count = 0 ... @property ... def spam(self): ... self.count += 1 ... return ' '.join(['spam']*self.count) ... py> import sys py> sys.modules['__main__'].__class__ = Magic py> import __main__ py> __main__.spam 'spam' py> __main__.spam 'spam spam' py> __main__.spam 'spam spam spam' -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType
On 25/04/19 1:21 PM, Steven D'Aprano wrote: On Thu, Apr 25, 2019 at 11:30:28AM +0530, Arup Rakshit wrote: On 25/04/19 3:52 AM, Alan Gauld via Tutor wrote: On 24/04/2019 12:22, Arup Rakshit wrote: In the simple code like what are the advantages we get from? I'm not really sure what you are asking about? Ok. My question is that when people add such a class to the module? What is the goal/intention they met by setting such __class__ attribute of a module. The documentation I am reading just shown this technique but didn't dig into this. They didn't explain why/when should we use this technique, but the how. Can to share which documentation you are reading? I've been using Python since version 1.5, and I've never heard of this technique. Thanks. Hello Steven, Here it is: *3.3.2.1. Customizing module attribute access* (https://docs.python.org/3/reference/datamodel.html#customizing-module-attribute-access) -- Thanks, Arup Rakshit ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType
On Thu, Apr 25, 2019 at 11:30:28AM +0530, Arup Rakshit wrote: > On 25/04/19 3:52 AM, Alan Gauld via Tutor wrote: > >On 24/04/2019 12:22, Arup Rakshit wrote: > >>In the simple code like what are the advantages we get from? > >I'm not really sure what you are asking about? > > Ok. My question is that when people add such a class to the module? What > is the goal/intention they met by setting such __class__ attribute of a > module. The documentation I am reading just shown this technique but > didn't dig into this. They didn't explain why/when should we use this > technique, but the how. Can to share which documentation you are reading? I've been using Python since version 1.5, and I've never heard of this technique. Thanks. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType
On 25/04/19 3:52 AM, Alan Gauld via Tutor wrote: On 24/04/2019 12:22, Arup Rakshit wrote: In the simple code like what are the advantages we get from? I'm not really sure what you are asking about? Ok. My question is that when people add such a class to the module? What is the goal/intention they met by setting such __class__ attribute of a module. The documentation I am reading just shown this technique but didn't dig into this. They didn't explain why/when should we use this technique, but the how. Is this so that we can implement more special methods than just __getattr__ and __dir__ in the module level? Is it just the inheritance from ModuleType? Or is it the assignment of the __class__ attribute? Yes the reason of this assignment. Or something else? import sys from types import ModuleType class VerboseModule(ModuleType): def __repr__(self): return f'Verbose {self.__name__}' def __setattr__(self, attr, value): print(f'Setting {attr}...') super().__setattr__(attr, value) sys.modules[__name__].__class__ = VerboseModule There are many things in Python that are not generally used by ordinary Python programmers. In many cases these are things used by the core developers or are intended for advanced meta programming type tasks. As a general rule of thumb any time you see code that accesses dunder attributes (ie those with leading and trailing __ markers) directly it's probably an advanced technique you are unlikely to ever need... That's a good catch. I am currently reading https://docs.python.org/3/reference/index.html source, and it seems like they touched everything possible in Python, without saying which is advance and which is basic part. Very often I get stuck, and coming here to ask and understand it. As the author didn't give the hints anything about what is advanced part, I am assuming these all a Python developer should know irrespective of their years of Python experience and keep readiing. But it feels like a lot in one go. But if you want to increase your understanding carry on asking but please be as specific as possible about what it is you want the answer to. -- Thanks, Arup Rakshit ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType
On 24/04/2019 12:22, Arup Rakshit wrote: > In the simple code like what are the advantages we get from? I'm not really sure what you are asking about? > Is this so that we can implement more special methods > than just __getattr__ and __dir__ in the module level? Is it just the inheritance from ModuleType? Or is it the assignment of the __class__ attribute? Or something else? > import sys > from types import ModuleType > > class VerboseModule(ModuleType): > def __repr__(self): > return f'Verbose {self.__name__}' > > def __setattr__(self, attr, value): > print(f'Setting {attr}...') > super().__setattr__(attr, value) > sys.modules[__name__].__class__ = VerboseModule There are many things in Python that are not generally used by ordinary Python programmers. In many cases these are things used by the core developers or are intended for advanced meta programming type tasks. As a general rule of thumb any time you see code that accesses dunder attributes (ie those with leading and trailing __ markers) directly it's probably an advanced technique you are unlikely to ever need... But if you want to increase your understanding carry on asking but please be as specific as possible about what it is you want the answer to. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor