
August 8, 2009 08:42 by
Simon
To create a property in IronPython (equivalent to a C# property) you need to create the get and set functions and then pass them into the in built property() function and assign the result to a variable with the name of the property you wish to create. For example, the code below defines a getter:
NEXT_PAGE_ID = 2
# Gets the Id of the next page
def _get_NextPage(self):
return self.NEXT_PAGE_ID
# GetNextPage - End
You then pass that into the property() function to create the property.
# Implementation of NextPageId property
NextPageId = property(_get_NextPage)
The property() function takes a number of optional parameters. The example above creates a readonly property, but you can pass in a setter as well, to make it read / write for example. You can also do the same thing with the use of decorators (attributes) but I prefer this method.
732ab072-d40a-4953-b2aa-421143682139|0|.0