Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: how to use property?

Reply
Thread Tools

Re: how to use property?

 
 
Chris Angelico
Guest
Posts: n/a
 
      09-17-2012
On Tue, Sep 18, 2012 at 7:55 AM, Fernando Jiménez <> wrote:
> Hi guys!
>
> I'm noob in python and I would know how to correctly use the property. I
> have read some things about it but I do not quite understand.
>
> But I think it's a bad habit to use _ to change the visibility of the
> attributes as in JAVA.
>
> How to correctly use the property?


The single leading underscore is nothing to do with visibility; it's a
courteous request that external referents not touch something. In a
"consenting adults" model, that's usually sufficient.

For the most part, in fact, you don't need @property at all. Just make
an object's members public and save yourself the trouble! Unlike the
recommendation in C++ and Java, Python doesn't ask you to hide things
and write code to make them available. Instead of starting with
getters and setters, just start with a flat property, and move to
getters/setters only when you find you need them.

The example you posted is adding nothing to the work flow, but it's a
good structure that you can tinker with. For instance, if you need to
log all changes for debugging purposes, @property will make that easy.
But for the bulk of attributes, it's complete overkill.

ChrisA
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Could not use ''; file already in use. M K ASP .Net 11 04-09-2008 11:35 AM
where to use CPLD & where to use FPGA? kulkarku@math.net VHDL 6 03-06-2006 07:27 AM
Can I use XPath or something to a remote Mac or Linux box and just query an xml file, not using web services and use encyrption? jake ASP .Net 0 07-06-2004 02:16 PM
Cannot use the profile "default" because it is in use, not. please.post@yur.re.ply Firefox 1 07-04-2004 03:41 AM



Advertisments