Arrie Charles Jones Arrie Charles Jones - 8 months ago 50
Python Question

Create class object instance named from string?

I can't find the answer anywhere.

I have a class called "vrf".

I have an input file.

As Python iterates through the lines of this input file, every time it sees the word vrf, I want to create an object named after the next word.

So if it reading the line "ip vrf TESTER",
I would like to dynamically create an object named TESTER of type vrf.

TESTER = vrf()

How in the world do I do this?

I've tried:

line.split()[2] = vrf()

Doesn't work.


Why don't you just use a dictionary?

object = {}
object[line.split()[2]] = vrf()