Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2025 Feb 05 6:41 am)
structure posted at 9:06 AM Sat, 18 December 2021 - #4432058
another way
import poserscene = 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 :))
A test for None should always look like this:
<statement> is None
or
<statement> is not None.
But not:
not <statement> is None
Why?
Once, because it is recommended by the Python documentation :).
And if you think about it, you will see that from <statement> the value is evaluated and then negated. The result is then checked for None (== None). If you write it correctly, the parameter is directly checked for != None. Which is of course more effective, and depending on what is behind <statement>, possibly also much faster.
This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.
Hello,
Is it possible in a python script to get the name of the current PZ3 file?
Thanks for your help.
M18