C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Training   ASP.NET Web Hosting    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

Play Silverlight Games or Submit your Silverlight applications and earn 90% AdSense revenue.

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Resources » Articles » General »

Creating properties in Ironpython


Posted Date: 29 May 2007    Resource Type: Articles    Category: General
Author: Sunil PottumuttuMember Level: Silver    
Rating: Points: 10



Creating propeties in ironpython is some what different from c#. we can use property function to achieve this . below code demonstrates this


CODE]
class testclass1(object):
def __init__(self):
self.__x = None
self.__y = "y"

def getx(self):
return self._x

def setx(self, value):
self._x = value

def delx(self):
del self._x

x = property(getx, setx, delx, "I'm the 'x' property.")

def gety(self):
return self.__y
#read only property
y = property(gety,None,None, "I'm the 'y' property.")


obj = testclass1()
obj.x = "x";
print obj.x
print obj.y


class Parrot(object):
def __init__(self):
self._voltage = 100000

#Another way of defining ready only property using decorators
@property
def voltage(self):
"""Get the current voltage."""
return self._voltage


objparrot = Parrot()

#this gives error as it is read only property
#objparrot.voltage = "20000"
print objparrot.voltage





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Tips for using Microsoft Excel
Previous Resource: Leech FTP -- An elegant effective FTP management solution
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use