No Vordok that still would not work. Daves example is the direction he would
need to go. In the origin question, the example makes no real association
with the item and the item list. Also, if you pass a function as the default
arg like that, it will evaluate only once when the func is defined. For
wanting to have an arg that uses a default function as its value you could
do:

def myFunc(value=None):
    if value is None:
        value = someFunction()

But yes, really the issue is what Dave addresses by creating classes where a
parent class stores the child classes and also sets a reference to itself (
the parent) when adding in a child.
On Oct 4, 2011 2:11 PM, "Vordok" <[email protected]> wrote:
> Hey,
>
> Why dont you try this:
>
> if __name__ = '__main__':
> itemA = myItem()
>
> itemB = myItem()
> list = myListOfItems()
> list.showAll()
>
> I hope it work.
>
> On Sep 19, 9:17 am, Shahar Levavi <[email protected]> wrote:
>> Hello,
>> I'm trying to set a default argument to be a function result.
>> So, in the example below I'm trying to add "index" to *myItem* but having
>> index default to number of items in *myListOfItems*
>>
>> class myItem:
>>       def __init__(self, index = myListOfItems.itemCount(self)):
>>           self.index = index
>>       def __str__(self):
>>           return 'Index: %i' % (self.index)
>>
>> class myListOfItems:
>>       def __init__(self, *args):
>>           self.items = list(args)
>>       def itemCount(self):
>>           len(self.items)
>>       def showAll(self):
>>           for item in self items:
>>               print item
>>
>> if __name__ = '__main__':
>>       itemA = myItem()
>>
>>       itemB = myItem()
>>       myListOfItems.showAll()
>>
>> This wont work since myListOfItems is not defined on init, but the result
>> I'm after is:
>> 'Index: 0'
>> 'index: 1'
>>
>> How can I achieve this result?
>
> --
> view archives: http://groups.google.com/group/python_inside_maya
> change your subscription settings:
http://groups.google.com/group/python_inside_maya/subscribe

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to