Hi Python is a pass-by-value language. And it doesn't have pointers. That means everything you pass is a copy of the value. Now that might sound strange to some, thinking it isn't true part time. When you pass an immutable object like an int, it is obvious. But when you pass a list, what you are passing is a copy of the lost reference. That means that while you can't replace the symbol with a new list (no pointers) you can modify it's members and the same list is affected. So in the case where you want to modify and object being passed in, either return the new value, or pass a custom object that has attributes that can be modified. This is why you can advance the iterator. You pass a copy of the reference and then call next. On Jun 15, 2014 5:58 PM, "Enrico Losavio" <[email protected]> wrote:
> Hey guys, thanks for the reply (and sorry for my late reply). > I've been making some tests and yes, Marcus you're right. I thought that > the variables passed to a function were always considered as local > variables. > I studied a bit of programming years ago, so I don't remember the right > terms, but if i write for example: > > x = 5 > def double(x): > x *= 2 > double(x) > print x > > it will of course print 5, not 10. > I was looking for a way to have direct access to the outer variable. > In the case of a Maya Iterator, I've made a quick check simply printing > the iterator.index() inside the function to see if it was kepping the pace > (and it did). > def printIndex(polyIter): > print polyIter.index() > > while not polyIter.isDone(): > printIndex(polyIter) > polyIter.next() > > Justin, as I was saying i'm not a seasoned programmer and I barely know > what profiling the code means. I was just guessing that making unneeded > operations would be a loss of performance. > > So that said... how can I tell if I'm passing the variable as a local > variable or as a pointer? > I'm sorry if I look confused, but I am. Probably because I'm spending like > tens of hours everyday in front of the code, studying and working at the > same time and having random epiphanies occasionally :D > > > Il giorno martedì 10 giugno 2014 21:26:35 UTC+2, Justin Israel ha scritto: >> >> In addition to what Marcus said about passing the iterator instance, have >> you profiled your code to come to the conclusion that it is inefficient to >> create your iterator and function sets from within the function? >> On Jun 11, 2014 2:57 AM, "Marcus Ottosson" <[email protected]> wrote: >> >>> Hi Enrico, >>> >>> I’m not very acquainted with the API, and maybe I’m not understanding >>> you correctly, but Python passes everything as references to other objects. >>> >>> # This would pass `my_iterator` as reference to `maya_function` >>> maya_function(my_iterator) >>> >>> If you could provide a short snippet of your issue, I might be able to >>> help more. >>> >>> Best, >>> Marcus >>> >>> >>> >>> On 10 June 2014 14:58, Enrico Losavio <[email protected]> wrote: >>> >>>> Hi everyone. >>>> I'm new to Maya Python API. I've been studying it since a couple of >>>> months and now I'm trying to write my first script (to be later adapted >>>> into a node). >>>> I'm writing a main function to iterate through a mesh, and a few >>>> secondary functions to retrieve certain information about it. >>>> The point is, everytime i call a function I have to recreate the >>>> iterators, function sets and everything i need in order to make it work. >>>> This seems a lot like a waste of code and of performances. >>>> Do you know if there is a way to pass the iterators or any Maya object >>>> to a function as pointers? I know python doesn't deal with pointers, but it >>>> would be so much easier. I've tried to look in the MScriptUtil >>>> documentation, but i couldn't find anything helpful >>>> >>>> Thanks for the help! >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Python Programming for Autodesk Maya" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> To view this discussion on the web visit https://groups.google.com/d/ >>>> msgid/python_inside_maya/d5207b32-1472-4e51-90dd- >>>> fc4affbf4154%40googlegroups.com >>>> <https://groups.google.com/d/msgid/python_inside_maya/d5207b32-1472-4e51-90dd-fc4affbf4154%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> >>> >>> -- >>> *Marcus Ottosson* >>> [email protected] >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Python Programming for Autodesk Maya" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To view this discussion on the web visit https://groups.google.com/d/ >>> msgid/python_inside_maya/CAFRtmODmmPnGLULsPD-sMu6- >>> 8YwJX2X4-HAPZbnVNsurDyfzxA%40mail.gmail.com >>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODmmPnGLULsPD-sMu6-8YwJX2X4-HAPZbnVNsurDyfzxA%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/03bf3e54-3547-446d-b865-1d30535bd6d1%40googlegroups.com > <https://groups.google.com/d/msgid/python_inside_maya/03bf3e54-3547-446d-b865-1d30535bd6d1%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0rUy2j2J9p_Vm-NLRCKePWdY%2B3jViz2SivQ%3DixqOcKBA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
