I'm doing this in Maya, but the core issue is from Python. It all boils down to why or
doesn't work in this case :
>>> a = ["something",]
>>> b = a[1] or "empty"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
More details:
I need a file's name without the path and extension, and do actions with that in a variable.
So I thought I could just do name = basenamde(cmds.file(q=True, sn-True).split(".")[-2] or []
But when doing it in an empty unsaved scene (which returns nothing when asked the file name it doesn't have), it returns that error. I know I could just declare the variable empty first, then check if the file name exists before assigning it to the variable, but it doesn't sound "elegant" to me. I love short one-liners.
I also have seen this answer that encourages doing this:
b, = a[1] or "empty"
Which I would love to use here, but it doesn't seem to work in Maya 2018 (Python 2.7) with the same error list index out of range
.