one way would be

l = [('0', '0'), ('5', '8'), ('10', '-14'), ('15', '5')]

l2 = [ (int(i[0]),int(i[1])) for i in l]


print l2

On Mon, Apr 23, 2012, at 18:17, Ron Ganbar wrote:

Hi guys,
I have this: [('0', '0'), ('5', '8'), ('10', '-14'), ('15', '5')]
It's the output of a RegEx script.

Now, I figure I probably can't use this for keyframes as the
numbers are actually strings.
Any idea how I can easily convert them to numbers?
Thanks,
Ron Ganbar
email: [1][email protected]
tel: +44 (0)7968 007 309 [UK]
     +972 (0)54 255 9765 [Israel]
url: [2]http://ronganbar.wordpress.com/
On 19 April 2012 13:43, Ron Ganbar <[3][email protected]> wrote:

If I need it to be as simple as this, I'll stay with Ivan's
solution.
If I'll need to condition it somehow, I'll switch to a regular
loop.
Thanks guy!
Ron Ganbar
email: [4][email protected]
tel: [5]+44 (0)7968 007 309 [UK]
     [6]+972 (0)54 255 9765 [Israel]
url: [7]http://ronganbar.wordpress.com/
On 19 April 2012 12:49, Howard Jones <[8][email protected]>
wrote:

I still steer clear from list comprehensions for the reasons Ivan
mentions, though something like that example is pretty clear.
However the speed increase is likely to be negligible for
something like that isn't it Ivan? or not?

Howard
  ____________________________________________________________

From: Ivan Busquets <[9][email protected]>
To: Nuke Python discussion
<[10][email protected]>
Sent: Thursday, 19 April 2012, 6:54
Subject: Re: [Nuke-python] Writing a Curve
Yes, it's a list comprehension, which is just a quick way to
create a list from a series of statements, in this case a for
loop.

But I see you already got that. The only reason I mentioned
readability is that, when you start adding nested loops and
conditions to the mix, then list comprehensions get increasingly
hard to read. On the other hand, they are generally a little
faster than the equivalent for loop(s).

So, your choice :) I just meant that not for being shorter it was
necessarily a better approach.

Cheers,
Ivan
On Wed, Apr 18, 2012 at 10:27 PM, Ron Ganbar
<[11][email protected]> wrote:

Isn't what you have there simply a for loop, just written
differently? It's very readable anyway.

Thanks again,
R

On Apr 19, 2012 8:24 AM, "Ivan Busquets"
<[12][email protected]> wrote:

Yes, because addKey() takes either an AnimationKey or a list of
them, I just built a list of them using a list comprehension
structure, which is essentially a loop.



But if a for loop makes more sense, then by all means you should
use that. Shorter is not always better, and the more readable you
make it for yourself, the easier it will be to go back and make
changes to it :)



On Wed, Apr 18, 2012 at 10:07 PM, Ron Ganbar
<[13][email protected]> wrote:

Thanks Ivan,
I figured it probably just needs a loop, but yours is far shorter
than mine.
I'll have a look at those tutorials.

Ron Ganbar
email: [14][email protected]
tel: +44 (0)7968 007 309 [UK]
     +972 (0)54 255 9765 [Israel]
url: [15]http://ronganbar.wordpress.com/

On 19 April 2012 03:44, Ivan Busquets
<[16][email protected]> wrote:

  Hey Ron,
  I assume you just want the shortest possible version of
  setting the whole curve from values you already have, right?
  So, say you have an animated knob that you've created like
  this:

  node = nuke.createNode( 'Blur' )
  k = node['size']
  k.setAnimated()

  And then you have list of keys and values that you want to
  feed at once as an animation curve.
  One thing you can do is put them all in a list of
  (frame,value) tuples, like this:
  keys = [(0,20), (1,30), (5,70), (8,90)]
  And then get the AnimationCurve object for that knob, and add
  them all like this:
  anim = k.animation(0)
  anim.addKey([nuke.AnimationKey(frame, value) for (frame,value)
  in keys])
  Of course, that is just an example for doing it in just a
  couple of lines. Depending on how your initial data is
  formatted, you might want to take a different approach.
  If you want to dig any deeper into it, you can find more info
  and some examples in the Python Developers Guide, under
  "Animation".
  Also check these two great tutorials from Nathan:
  [17]http://www.nukepedia.com/python/knob-animation-and-python-
  a-primer/
  [18]http://www.nukepedia.com/python/animationcurve-and-animati
  onkey-objects/
  Hope that helps.
  Cheers,
  Ivan

On Wed, Apr 18, 2012 at 3:16 AM, Ron Ganbar
<[19][email protected]> wrote:

Hi guys,
quick question, back in Shake it was easy to type an animation
curve, it was simply hermite(0, 0@1, 15@10, 44@100).
Is there a way to easily create an animation curve like that in
Nuke?
I know about setValueAt(), but that's for each keyframe rather
than a whole curve.
Thanks!
Ron Ganbar
email: [20][email protected]
tel: +44 (0)7968 007 309 [UK]
     +972 (0)54 255 9765 [Israel]
url: [21]http://ronganbar.wordpress.com/

  _______________________________________________
  Nuke-python mailing list
  [22][email protected],
  [23]http://forums.thefoundry.co.uk/
  [24]http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/n
  uke-python


  _______________________________________________
  Nuke-python mailing list
  [25][email protected],
  [26]http://forums.thefoundry.co.uk/
  [27]http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/n
  uke-python


  _______________________________________________
  Nuke-python mailing list
  [28][email protected],
  [29]http://forums.thefoundry.co.uk/
  [30]http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/n
  uke-python


  _______________________________________________
  Nuke-python mailing list
  [31][email protected],
  [32]http://forums.thefoundry.co.uk/
  [33]http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/n
  uke-python


  _______________________________________________
  Nuke-python mailing list
  [34][email protected],
  [35]http://forums.thefoundry.co.uk/
  [36]http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/n
  uke-python


_______________________________________________
Nuke-python mailing list
[37][email protected],
[38]http://forums.thefoundry.co.uk/
[39]http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke
-python

  _______________________________________________
  Nuke-python mailing list
  [40][email protected],
  [41]http://forums.thefoundry.co.uk/
  [42]http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/n
  uke-python


_______________________________________________

Nuke-python mailing list

[43][email protected],
[44]http://forums.thefoundry.co.uk/

[45]http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke
-python

References

1. mailto:[email protected]
2. http://ronganbar.wordpress.com/
3. mailto:[email protected]
4. mailto:[email protected]
5. tel:%2B44%20%280%297968%20007%20309
6. tel:%2B972%20%280%2954%20255%209765
7. http://ronganbar.wordpress.com/
8. mailto:[email protected]
9. mailto:[email protected]
  10. mailto:[email protected]
  11. mailto:[email protected]
  12. mailto:[email protected]
  13. mailto:[email protected]
  14. mailto:[email protected]
  15. http://ronganbar.wordpress.com/
  16. mailto:[email protected]
  17. http://www.nukepedia.com/python/knob-animation-and-python-a-primer/
  18. http://www.nukepedia.com/python/animationcurve-and-animationkey-objects/
  19. mailto:[email protected]
  20. mailto:[email protected]
  21. http://ronganbar.wordpress.com/
  22. mailto:[email protected]
  23. http://forums.thefoundry.co.uk/
  24. http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
  25. mailto:[email protected]
  26. http://forums.thefoundry.co.uk/
  27. http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
  28. mailto:[email protected]
  29. http://forums.thefoundry.co.uk/
  30. http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
  31. mailto:[email protected]
  32. http://forums.thefoundry.co.uk/
  33. http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
  34. mailto:[email protected]
  35. http://forums.thefoundry.co.uk/
  36. http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
  37. mailto:[email protected]
  38. http://forums.thefoundry.co.uk/
  39. http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
  40. mailto:[email protected]
  41. http://forums.thefoundry.co.uk/
  42. http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
  43. mailto:[email protected]
  44. http://forums.thefoundry.co.uk/
  45. http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python


-- 
  Hugo Léveillé
  TD Compositing, Vision Globale
  [email protected]

_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to