Forum: Poser - OFFICIAL


Subject: New Reality (lux render) Plugin over at Daz...time for Poser Plugin Update?

Ridley5 opened this issue on Jul 26, 2010 · 1724 posts


odf posted Thu, 12 August 2010 at 9:21 PM

Quote - > Quote - In a completely unrelated note, I just realized that I can use list comprehensions. I've been avoiding generator expressions since they would not work in Poser 6, which uses Python 2.2. But list comprehensions were introduced in 2.0. Awesome!

Err... carry on. 😊

Maybe it makes sense to have different versions of some functions? 
Kind of this: if PYTHON_VERSION >= 2.4 : # Fast and memory efficent def topological_order(children): seen = set() result = num.zeros( ... ) ....

    if not v in seen :
      seen.add(v)
    ...

else:
  # remarkable slower 
  def topological_order(children):
    seen = {}
    result = []
    ....

Hmm, I guess that particular example might work, but your strategy still would not allow me to use syntax from, say, Python 2.4 in an older version that does not understand that syntax. In that case, I'd have to put my 2.4-specific code in a separate file and import that file only if the Python version allowed that. That seems quite convoluted, and so I'd only do that for features that gave me a significant speed gain. I don't think that's the case for generator expressions, at least not in this particular project.

But back to list comprehensions (which I can use in Python 2.2). Compare this:

   
odd_squares = [n*n for n in xrange(20) if n %
2]<br></br>

with this:

   
odd_squares = []<br></br>
    for n in xrange(20):<br></br>
      if n % 2:
odd_squares.append(n*n)<br></br>

Any idea which I'd prefer to write?


Of course, there's also this:

    odd_squares = map(lambda n: n*n, filter(lambda n: n % 2, xrange(20)))

which looks quite horrible, but only because Python's syntax is a bit clumsy when it comes to functional programming support. In Ruby, I could write this:

   
odd_squares =
 0.upto(19).select { |n| n % 2 >
0 }.map { |n| n*n }

and in Scala this:

    val
odd_squares = 0 to 19 filter (n => n % 2 > 0) map (n =>
n*n)<br></br>

or this:

    val
odd_squares = for (n <- 0 to 19 if n % 2 > 0) yield
n*n<br></br>

-- I'm not mad at you, just Westphalian.