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

2019-02-27 Thread Alex Kleider
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(ob

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

2019-02-27 Thread Alan Gauld via Tutor
On 27/02/2019 13: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)? > > I hope that makes sense. Not

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

2019-02-27 Thread Mats Wichmann
Without spending a lot of time on an answer, you can use default arguments in the cases where only the number of arts differs in your instance creation. If there's larger differences, look into @classmethod. On February 27, 2019 5:25:02 AM PST, AdamC wrote: >That's great - bug found. Thanks. Ho

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

2019-02-27 Thread Tobiah
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'

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

2019-02-27 Thread AdamC
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 wro

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

2019-02-26 Thread Tobiah
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 g

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

2019-02-26 Thread AdamC
Sorry folks - my code didn't work due to my debug var count to ensure that I was looping properly. It should be: media = [] def loadFile(): filename = input('Filename? ') f = open(filename, 'r') createObjects(f) def createObjects(f): '''Takes a file object and iterates through en

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

2019-02-26 Thread Cameron Simpson
Thank you for a well formed problem description. However, as Steven has remarked the code you've included doesn't run. Can you follow up/reply with your actual working script, and also include some of the output you get. That said, I've a few small remarks about the code you have posted: On

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

2019-02-26 Thread Peter Otten
AdamC wrote: > I'm creating lots of objects from json in a file. Part of reading the json > back means that it iterates over the file and loads a json object and then > creates the object from the dictionary. > > This is my file: > > {"name": "Dwarf Fortress", "platform": "steam", "dateAdded":

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

2019-02-26 Thread Steven D'Aprano
On Tue, Feb 26, 2019 at 09:09:56AM +, AdamC wrote: > def createObjects(f): > '''Takes a file object and iterates through entries, passing them to > create > object, depending on what object it is.''' > for line in f: > count = count + 1 This cannot be the code you are actu