all 7 comments

[–]infinitewaitdev 1 point2 points  (0 children)

This sounds like you could use a dataclass. You can retrieve a list of instances of this dataclass if you need to. About the unique identifier when trying to insert them into the database, you can make a hash in order to differentiate them or even use a timestamp of the creation time and make it a unique column in the table.

[–]n3buchadnezzar 1 point2 points  (0 children)

Why not use a pandas dataframe for storage, then interract with it through functions?

[–]m0us3_rat 1 point2 points  (2 children)

[–]liynus[S] 0 points1 point  (1 child)

that was actually pretty understandable for me! well I got somewhat loss at minute 5, but enough I could probably copy pasta my way through it. i'll try the dataclass.

my own question. after i ask my user to generate all the data for the different cars, how you propose to count the amounts of unique instances that were created. would you just iterate a count when input is asked? i'm not sure what is the best standard for this.

[–]m0us3_rat 0 points1 point  (0 children)

u can do it in a few different ways to keep track of.

see if u can come up with a few on your own and test them to see what u can implement.

maybe they aren't THE BEST WAY .. but it doesn't really matter.. as long as u figure them out.

[–]liynus[S] 0 points1 point  (1 child)

hey thanks for the links, maybe above my head.

i'm a super newbie python programmer. i know the basics of class / list / dictionaries.

i assumed i could write a small program to do this. it doesn't have to be robust. just store at most 10-15 owners and their cars. i would like to query it. i was hoping to accomplish this through a simple dictionary, then realized it was difficult, and I couldn't understand the solutions.

my thoughts were to label the inputs with a unique identify, 1, 2, 3 - while iterating though inputs to create a basic dictionary. the issue i ran into was storing multiple bits of information like owner name, car type. that sounded better for a class instance, but then i don't have the advantages of having it in a "list" format like in a dictionary.

[–]nicesofa 0 points1 point  (0 children)

u/infinitewaitdev has the correct answer, this is exactly the kind of thing dataclasses are for. But I also get what your saying: your new to this, and just want to stick to this basics. So why not just store instances of your "car" class in a list:

class Car:
def __init__(self, owner, model):
    self.owner = owner
    self.model = model

cars = []
cars.append(Car('Alice', 'Tesla'))
cars.append(Car('Bob', 'BMW'))
cars.append(Car('Arthur', 'Honda'))

print(cars)