What's the most Pythonic way to write the below append statement:
class MyClass():
my_list = None
def __init__(self):
self.attr_a = 'whatever_a_is'
# NOTE below is commented out here because it's
# NOT needed by most instances:
# self.my_list = []
my_class_instance= MyClass()
# Append 'a_certain_value' to list attribute if it exists
# else create it:
if my_class_instance.my_list:
my_class_instance.my_list.append('a_certain_value')
else:
my_class_instance.my_list = ['a_cetain_value']
Thanks for the help.
appendmethod ofMyClassso the caller doesn't need to worry about it, or just makemy_listan empty list from the start.