Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102903

Re: How do i instantiate a class_name passed via cmd line

From "Veek. M" <vek.m1234@gmail.com>
Newsgroups comp.lang.python
Subject Re: How do i instantiate a class_name passed via cmd line
Date 2016-02-14 11:09 +0530
Organization Home
Message-ID <n9p3pb$41b$1@dont-email.me> (permalink)
References <n9p0ba$s7b$1@dont-email.me> <7142528d-6465-4825-af4f-85d6c7640b16@googlegroups.com>

Show all headers | View raw


Rick Johnson wrote:

> 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)
> instanceN.pack()
>     
> Note: You won't need to call "mainloop" when testing this
> code on the command line, only in a script or in the IDLE
> shell.
> 
>>>> root.mainloop()
Nope - this is what i'm doing:

class Foo():
 pass

x = 'Foo'

How do i use 'x' to create an instance of class Foo?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How do i instantiate a class_name passed via cmd line "Veek. M" <vek.m1234@gmail.com> - 2016-02-14 10:10 +0530
  Re: How do i instantiate a class_name passed via cmd line Rick Johnson <rantingrickjohnson@gmail.com> - 2016-02-13 21:31 -0800
    Re: How do i instantiate a class_name passed via cmd line "Veek. M" <vek.m1234@gmail.com> - 2016-02-14 11:09 +0530
      Re: How do i instantiate a class_name passed via cmd line Rick Johnson <rantingrickjohnson@gmail.com> - 2016-02-13 21:55 -0800
  Re: How do i instantiate a class_name passed via cmd line Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-02-14 18:41 +1300
    Re: How do i instantiate a class_name passed via cmd line "Veek. M" <vek.m1234@gmail.com> - 2016-02-14 11:21 +0530
    Re: How do i instantiate a class_name passed via cmd line Peter Otten <__peter__@web.de> - 2016-02-14 14:48 +0100
  Re: How do i instantiate a class_name passed via cmd line Cameron Simpson <cs@zip.com.au> - 2016-02-14 16:20 +1100

csiph-web