I need to write a class that takes some raw strings, and then separates them into a list which it holds as attributes. (Among other things, but that's the part I'm concerned with right now.) Something like this:
class MyClass(object):
def __init__(self, raw, index):
self.a = raw.split("\n")
self.index = index
So an instance of MyClass will have an attribute .a, that is a list containing lines from the raw string I initialize the object with, as well as an attribute .index that is the index that I give it, correct? However, I would also like to be able to generate additional instances of MyClass that contain only one line of the raw text each, but possessing the same index.
What I am currently thinking of is this:
from copy import deepcopy
foo = MyClass("lots of text", 1)
bar = []
for line in foo.a:
copy = deepcopy(MyClass)
copy.a = line
bar.append(copy)
Is this the correct way to go about doing this?