The following bar
function will work. Note, the first parameter will be a class itself and not the name of a class, so "class_name
", which implies that it's a str
, is misleading. args
will be a tuple of args to initialize klass
objects with, *-unpacked in the calls to klass
. You said in a later comment that you wanted to "create multiple independent objects", all of the same class and initialized with the same args, so I've revised my answer to reflect that:
def bar(klass, *args):
# Now you can create multiple independent objects of type klass,
# all initialized with the same args
obj1 = klass(*args)
obj2 = klass(*args)
# ...
# do whatever you have in mind with the objs
Your "local_class
" isn't a class at all, but rather an instance of klass
, so that's a bad name; and anyway you want several of them.
Assuming Foo
objects are initialized with three int arguments, and Baz
objects with two strings, you can call bar
like so:
bar(Foo, 1, 2, 3)
bar(Baz, 'Yo', 'bro')
etc.
Especially in a dynamically-typed language like Python, reasoning about code is more difficult when variables have misleading names.