I have a class in a Python file with its objects written in a separate file to keep things clean and organized. My problem is I can't add multiple instances of a class without having different names for each object. My idea to solve this is to add an increasing number next to the object. Similar to how Windows deals with duplicates of a file. Though, I can't seem to figure this out how to do it.
Example of what I want to do:
2 of "object" would be "object1", "object2"
Code in main:
objects = 0
class object:
def __init__(self, name, value):
self.name = name
self.value = value
def __str__(self):
return f"{self.name}({self.value})"
def addObject(n, v):
global objects
objects += 1
(object + objects) = object(n,v)
Code in object script:
from program import *
#Value is the worth of an object in $
addObject(objectA, 1)
addObject(objectB, 2)
addObject(objectB, 3)