Forum: Poser Python Scripting


Subject: Name of the file PZ3

minuitdixhuit opened this issue on Dec 15, 2021 ยท 7 posts


adp001 posted Sun, 19 December 2021 at 9:26 AM

structure posted at 9:06 AM Sat, 18 December 2021 - #4432058

another way 

import poser
scene = poser.Scene()

def get_document(scene):
    return scene.DocumentPath() if not scene.DocumentPath() is None else "Untitled"

document=get_document(scene)

Sorry for the " lecturer mode": but this is a good example of when you achieve a degradation with supposed code optimizations.

The function that returns the result is always called twice. Just to save one line of code.

The better (and more readable) way:

def get_document(scene):
  d = scene.DocumentPath()
  return d if d else "Untitled"

(In the end it's even less typed keys :))