Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Are the property Function really useful? yes.

Reply
Thread Tools

Re: Are the property Function really useful? yes.

 
 
Dave Angel
Guest
Posts: n/a
 
      08-30-2012
On 08/29/2012 07:46 AM, Dave Angel wrote:
> On 08/29/2012 06:32 AM, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>
>


I was trying to point out that your question was empty (no content in
the message). Mark also apparently saw an empty message. However, now
that Dieter has responded, with apparent quotes from your message, i see
what the problem was.

You composed an html message and sent it to a text forum. Many people
make that mistake, and the problem it usually causes is that source code
indentation is messed up. However, most mail programs send a text part
as well, and that's what we see. In your case, the text part was
empty, so I saw nothing but the subject line.

Please tell your mail program to compose TEXT message, not html, or this
problem could occur again.


Now to your question.

>> <div>&nbsp;</div>
>> <div>Where can i use the property function?</div></div></body></html>


In some languages, you get computed properties by writing getter and
setter functions, with names to match. Python lets you hide the fact
that the "property" is hidden, by letting you use ordinary syntax to
access it. For example, suppose you had a Point class, which stored the
x and y coordinates of a point on a plane. Suppose also that sometimes
you wanted to use polar coordinates. You might like the user of the
class to just interchangeably use the real attributes and the computed
ones, without having to use parentheses on some of them. (untested)

class Point(object):
def __init__(self, x, y):
self.x = x
self.y = y
@property
def radius(self):
return self.sqrt(self.x * self.x, self.y * self.y)
@property
def theta(self):
return math.atan(self.x, self.y)

Now, once you have a Point instance, you can use all four attributes pretty much interchangeably.

--

DaveA

 
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: Are the property Function really useful? Dieter Maurer Python 0 08-30-2012 07:36 AM
Re: Are the property Function really useful? Mark Lawrence Python 0 08-29-2012 12:53 PM
OT : But help really really needed re: Domain Name selling, hosting etc. problem nc HTML 1 02-03-2005 07:24 PM
REALLY REALLY WERID PROBLEM!!!!pls take a look Amir ASP .Net 3 01-23-2004 06:01 PM
really really mysterious IE6 problem--secure site ultraviolet353 Computer Support 7 11-22-2003 07:56 PM



Advertisments