Post #5039: Anyway, thank you for your support. Thanks to you, I can post the link now.

📋 Metadata

🏷️ Tags

scripting beginner intermediate solved

  • Python Scripting
  • Property Editor

💬 Content

Anyway, thank you for your support. Thanks to you, I can post the link now.

Firstly, props().my_prop and props('my_prop') return the same object. You can check the variations of how to use props() on this page.
PME doc: Scripting

value = props("MyProperty")  # get
value = props().MyProperty  # get
props("MyProperty", value)  # set
props().MyProperty = value  # set

The second point is about unpacking. This is a common technique in Python. It allows you to assign values to multiple variables from objects that have multiple elements, such as tuples or lists.

my_prop = ("Hello", "PME")  # A tuple with two elements
a, b = my_prop  # Unpacking into variables a and b
print(f'{a} {b}')  # Output: Hello PME

my_prop = ["Hello", "PME", "Python", "is", "awesome!"]  # A list with several elements
# Uncomment the next line to see the error
# a, b = my_prop  # Raises ValueError: too many values to unpack

a, b, *rest = my_prop  # Unpacking with variable-length arguments
print(f'{a} {b}')  # Output: Hello PME
print(rest)  # Output: ['Python', 'is', 'awesome!']

my_strings = "Hello PME"  # In fact, a string is like a list
first, *middle, last = my_strings  # This time, we are interested in the first and last elements
print(f'First: {first}, Middle: {middle}, Last: {last}')
# Output: First: H, Middle: ['e', 'l', 'l', 'o', ' ', 'P', 'M'], Last: E

❤️ 1 likes


🔗 View on Blender Artists