Its called string formatting

ex:
age = '16'
print "Hi, I am " + age + " years old"

is the same as:

print "Hi, I am %s years old" % age

It has the advantage of making clearer string writing as well as
converting int and floats to string as well

ex:

"I am %s years old and I have %s dollars" % (10 , 3.5)




On Mon, Apr 23, 2012, at 12:00, Adam Hazard wrote:

ok, cool, I think I understand it better now. Thanks, guys. Also,
if you don't mind, another question, what exactly is the '%'
doing in this code. And I have used 'int' before, and seen the
'16' posted around, what exactly are those doing, I am guessing
that is what converts the value from string to integer?
-Adam
On 04/23/2012 10:48 AM, Nathan Rusch wrote:

The problem isn’t hex vs. int; the value you’re getting back from
the Python knob is identical to the hex value returned by the
nuke.tcl call. The issue you’re running into is that the nuke.tcl
call is returning the hex value as a string, so you need to cast
it to a numeric type before you can actually use it.

n = nuke.selectedNode()
tile_color = int(nuke.tcl('value [topnode %s].tile_color' %
n.name()), 16)


-Nathan


From: [1]Adam Hazard
Sent: Monday, April 23, 2012 10:12 AM
To: [2]Nuke user discussion
Subject: Re: [Nuke-users] python [topnode] equivalent

Thanks Ivan.
This was pretty much exactly what I was looking for. However I
had to change it a little bit because this was returning the tile
color hex value, if I understand all this correctly, and my
function needs just the integer value. As I can't assign or set a
tile_color using hex, or I haven't been able to figure it out.
Anyways, for whatever reason this does the trick, kinda mixing
your code with what I had before. I am still not very sure why
the tile_color has 2 different value formats.
n = nuke.selectedNode()
topnode_name = nuke.tcl("full_name [topnode %s]" % n.name())
topnode = nuke.toNode(topnode_name)
tile_col = topnode['tile_color'].value()
Thanks again and much appreciated.
Adam
On 04/20/2012 06:47 PM, Ivan Busquets wrote: Or if you just want
the tile_color of the top node, you could of course do:

n = nuke.selectedNode()

tile_color = nuke.tcl("value [topnode %s].tile_color" %
[3]n.name())
Hope that helps
On Fri, Apr 20, 2012 at 6:41 PM, Ivan Busquets
<[4][email protected]> wrote:
You can use nuke.tcl() within python to execute a tcl command.
So, in your case, something like this should work:

n = nuke.selectedNode()

topnode_name = nuke.tcl("full_name [topnode %s]" % [5]n.name())

topnode = nuke.toNode(topnode_name)
On Fri, Apr 20, 2012 at 6:30 PM, Adam Hazard
<[6][email protected]> wrote:
Hopefully a quick question,
If I currently have a node selected somewhere in a tree, and I
want to access the topnodes tile color using python, how would I
do so? Using [[topnode].tile_color] doesn't seem to work as it is
tcl? Looking around it seems you need to check dependecies of all
the nodes or something, but I haven't been able to get anything
to work.  Is there no way to convert the tcl function to work in
python?
Thanks in advance for any help,
Adam
_______________________________________________
Nuke-users mailing list
[7][email protected],
[8]http://forums.thefoundry.co.uk/
[9]http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-
users



_______________________________________________
Nuke-users mailing list
[10][email protected], [11]http://forums.thefoundry.co.u
k/
[12]http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users

  ____________________________________________________________

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



_______________________________________________
Nuke-users mailing list
[16][email protected], [17]http://forums.thefoundry.co.u
k/
[18]http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users

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

References

1. mailto:[email protected]
2. mailto:[email protected]
3. http://n.name/
4. mailto:[email protected]
5. http://n.name/
6. mailto:[email protected]
7. mailto:[email protected]
8. http://forums.thefoundry.co.uk/
9. http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
  10. mailto:[email protected]
  11. http://forums.thefoundry.co.uk/
  12. http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
  13. mailto:[email protected]
  14. http://forums.thefoundry.co.uk/
  15. http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
  16. mailto:[email protected]
  17. http://forums.thefoundry.co.uk/
  18. http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
  19. mailto:[email protected]
  20. http://forums.thefoundry.co.uk/
  21. http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users


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

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

Reply via email to