Jun-11-2019, 06:17 PM
Hi everyone,
Rather new to python and have had no luck in researching this, so assuming the answer is no, but here is what I am trying to see if is possible:
Have an object that has open attributes(possible), have an array(...obviously possible). Now the tricky part, name the attributes based off of the names in the array.
So my example, which doesn't work at all, but I hope get's the idea across if it is possible, is below:
Anyhow, thanks in advance.
Cheers,
Mac
Rather new to python and have had no luck in researching this, so assuming the answer is no, but here is what I am trying to see if is possible:
Have an object that has open attributes(possible), have an array(...obviously possible). Now the tricky part, name the attributes based off of the names in the array.
So my example, which doesn't work at all, but I hope get's the idea across if it is possible, is below:
fields = ["test","testing","ing"] Class sns(object): pass i = 0 obj = sns() while i < len(fields): obj.fields[i] = "data" i += 1With the expected results, being the object "obj", with the properties/attributes obj.test, obj.testing, obj.ing. The idea is that I'd like to take something like a csv file, dynamically take the first row, and create objects with attributes named after that first row, if that makes any sense.
Anyhow, thanks in advance.
Cheers,
Mac