[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Property with Arguments

Lie Ryan

1/11/2008 10:52:00 AM

Is there a way to create a property with arguments? Or an index value
like a list?

To be used in the form like:

someClass.someProperty['arguments'] = 'some value'
or
someClass.someProperty('argument1', 'argument2') = 'some value'

2 Answers

Fredrik Lundh

1/11/2008 11:21:00 AM

0

Lie wrote:

> Is there a way to create a property with arguments?

That's called method in Python, and has it's own syntax. You cannot
assign to methods.

> Or an index value like a list?

Make the property that returns a list-like object (hooking __getitem__,
__setitem__, etc).

</F>

Lie Ryan

1/11/2008 6:29:00 PM

0

On Jan 11, 6:20 pm, Fredrik Lundh <fred...@pythonware.com> wrote:
> Lie wrote:
> > Is there a way to create a property with arguments?
>
> That's called method in Python, and has it's own syntax.  You cannot
> assign to methods.

So you've got to use methods? It was in VB.NET that I learned about
property with arguments, which is basically passing multiple values to
the property, one of which is considered the real value and the others
are metadata values. Now that I thought about it, I could use tuple to
pass multiple values... well there is a missing semantic concerning
which are real values and metadata values, but it doesn't really
matter.

>  > Or an index value like a list?
>
> Make the property that returns a list-like object (hooking __getitem__,
> __setitem__, etc).
>

well, I want to avoid creating an object or (worse) modifying existing
object, as the program I'm working on is very short and simple, and I
want to keep it that way.