[Tutor] Only appending one object to list, when I am expecting more than 1

Tobiah toby at tobiah.org
Wed Feb 27 10:18:38 EST 2019


Without fully understanding what you're getting at, I'll offer this:

	class Car(object):

	        def __init__(self, **kwargs):

	                self.features = {
	                        'make': 'Hyundai',
	                        'color': 'purple'
	                }

	                self.features.update(kwargs)


	c = Car(color='yellow', year=2017)


	print c.features

output:

	{'color': 'yellow', 'make': 'Hyundai', 'year': 2017}





On 2/27/19 5:25 AM, 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)?
> 
> I hope that makes sense.
> 
> Adam
> 
> On Tue, 26 Feb 2019 at 18:24, Tobiah <toby at tobiah.org> wrote:
> 
>>
>>
>> On 2/26/19 6:39 AM, AdamC wrote:
>>> Sorry folks - my code didn't work due to my debug var count to ensure
>> that
>>> I was looping properly.
>>>
>>> It should be:
>>
>> As was pointed out, the problem is not in your code.  It's in your
>> data.  You only have one record with a proper 'tpe' value, so that's
>> all you get in your media list.
>>
>>
>> Toby
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
> 
> 


More information about the Tutor mailing list