[Tutor] Only appending one object to list, when I am expecting more than 1
Alex Kleider
akleider at sonic.net
Wed Feb 27 22:03:26 EST 2019
On 2019-02-27 05:25, AdamC wrote:
> That's great - bug found. Thanks. However the next question is, how do
> I
> create an instance of a class with variable parameters (i.e. with
> dateAdded
> already computed and stored, or with dateAdded created for the first
> time)?
Might this work?
class myClass(object):
__init__(self, added_date=None):
if added_date:
self.date_attribute = added_date
else:
self.date_attribute = my_way_of_calculating_added_date()
You can then instantiate in either of these ways:
my_instance = myClass()
or
my_instance = myClass(my_way_of_calculating_added_date())
More information about the Tutor
mailing list