That’s what’s called a list comprehension in Python. 
http://docs.python.org/tutorial/datastructures.html#list-comprehensions

It’s equivalent to this:

quoted = []
for c in comps:
    quoted.append('{%s}' % c)


The expression `'{%s}' % c` is taking one of the list items (a string) and 
formatting it into a new string, replacing the `%s` token.

It is roughly equivalent to: `'{' + c + '}'`


-Nathan



From: Mohamed Selim 
Sent: Tuesday, September 04, 2012 5:20 AM
To: [email protected] 
Subject: [Nuke-python] Re: Listing the EXR compression type in a dropdownmenu 
panel

      NathanR wrote:  
      The nuke.Panel class is basically a thin wrapper for the old-school TCL 
panels. As such, if you quote your list items in TCL syntax (using braces), 
things will work as you expect:

      # Verbose code for demonstration
      w = nuke.nodes.Write(file_type='exr')
      comps = w['compression'].values()
      quoted = ['{%s}' % c for c in comps]
      p = nuke.Panel('Compression')
      p.addEnumerationPulldown('compression', ' '.join(quoted))
      p.show()



      -Nathan
     


Works great!

Can you explain to me what this line means? ['{%s}' % c for c in comps]



--------------------------------------------------------------------------------

Mohamed Selim
Nuke Compositor
Cairo, Egypt
www.mselim.com


--------------------------------------------------------------------------------
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
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