How do i instantiate a class_name passed via cmd line

Rick Johnson rantingrickjohnson at
Sun Feb 14 00:31:30 EST 2016

On Saturday, February 13, 2016 at 10:41:20 PM UTC-6, Veek. M wrote:
> how do i replace the 'Ebay' bit with a variable so that I
> can load any class via cmd line.

Is this what you're trying to do? 

(Python2.x code)
>>> import Tkinter as tk
>>> classNames = ["Button", "Label"]
>>> root = tk.Tk()
>>> for className in classNames:
	classN = getattr(tk, className)
	instanceN = classN(root, text=className)
Note: You won't need to call "mainloop" when testing this
code on the command line, only in a script or in the IDLE

>>> root.mainloop() 

More information about the Python-list mailing list