On Tue, 24 May 2016 8:09 AM <[email protected]> wrote:

> Hi just a quick one.
>
> Why is it necessary to use .format():
>
> for light in all_lights:
>     light_intensity = cmds.getAttr('{0}.intensity'.format(light))
>
> rather than:
>
> for light in all_lights:
>     light_intensity = cmds.getAttr(light + '.intensity')
>
> they both work but i always see people using the .format() method, rather
> than just concatenating the strings. Is there a reason to use one rather
> than the other. The latter seems simpler also
>
> thanks,
> Sam
>

Concatenating strings creates maple copies along the way, as each pair is
concatenated and a new string is return for for the next addition. In small
use cases it won't matter. But in loops and with tons of string it would be
wasteful.

Another reason is that using the + operator only works if both sides are
strings. Whereas the format() method gives you string conversion operations
like float formatting.


> --
> 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/d32cb68b-135f-443a-923a-83d7ae1f3034%40googlegroups.com
> .
> 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/CAPGFgA3gDL1JpnJkNi2KUNyjad9cM7hj1V--v3sRMdOUhyamaw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to