[MOVED] Classes [advanced]: Dependent attributes

A place where you can post Python-related tutorials you made yourself, or links to tutorials made by others.

[MOVED] Classes [advanced]: Dependent attributes

Postby Mekire » Fri Jul 26, 2013 1:56 am

Last edited by Mekire on Fri Jul 26, 2013 6:40 am, edited 1 time in total.
User avatar
Mekire
 
Posts: 1710
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

Re: Classes [advanced]: Dependent attributes (and Descriptor

Postby micseydel » Fri Jul 26, 2013 6:00 am

Cool, thanks for sharing! By the way, I would replace your __repr__ body with this
Code: Select all
return "Rect({x}, {y}, {width}, {height})".format(**vars(self))
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Classes [advanced]: Dependent attributes (and Descriptor

Postby Mekire » Fri Jul 26, 2013 6:45 am

Ahh, yes. That looks much cleaner; updated. I never remember the vars function exists.

-Mek
New Users, Read This
  • Use code tags when posting code.
  • Include any errors with your post (in code tags).
  • Describe your problem; not your chosen solution.
  • Make examples the minimum length to demonstrate your issue.
User avatar
Mekire
 
Posts: 1710
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

Re: Classes [advanced]: Dependent attributes (and Descriptor

Postby micseydel » Fri Jul 26, 2013 6:49 am

I love it, and locals() for having more semantic formatting strings. I'm surprised it isn't more common. Seriously though, kudos on the post!
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest