Yes, you can retrieve a list of properties that exist on instances of a class using the dir() function and filtering out the built-in attributes. Here's an example:
class NewClass:
def __init__(self, number):
self.multi = int(number) * 2
self.str = str(number)
a = NewClass(2)
properties = [attr for attr in dir(a) if not attr.startswith('__')]
property_list = ', '.join(properties)
print(property_list)
Output:
multi, str
In the above code, the dir(a) function returns a list of all attributes and methods of the instance a. By filtering out the attributes that start with __, which are built-in attributes, we obtain a list of properties specific to the instance.
We then use a list comprehension to iterate over the attributes, excluding those starting with __. Finally, the ', '.join() function is used to concatenate the properties into a single string separated by commas.
The result is the desired output, which is the list of properties: multi, str.