[Tutor] Pythonic review (descriptors)

Alan Gauld alan.gauld at btinternet.com
Tue Apr 28 16:27:39 CEST 2015


On 28/04/15 10:55, Sage Hack wrote:
> I'm looking for somebody willing to review parts of this code
> https://github.com/SageHack/cloud-buster and let me know what is not
> Pythonic :P

> https://github.com/SageHack/cloud-buster/tree/master/bust/descriptor

Another point re the PageTitle class:

class PageTitle(object):

     titles = {}

     def __init__(self, url, host=None):
         self.url = url
         self.host = host

     def __get__(self, obj=None, objtype=None):...

     @property
     def id(self):
         if self.host:
             return self.url+':'+self.host
         else:
             return self.url


There is not much point in calculating the id each time,
it could simply be set in the init(). You never change
the url or host.


-- 
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




More information about the Tutor mailing list