Gregory Ewing wrote:
> Something like this should do it:
>
>instance = getattr(module, class_name)(module_name, product)
>
> If the class name is always the same as the module name with the
> first letter capitalized, you could use
>
>instance = getattr(module, module_name.capitalize())
On Saturday, February 13, 2016 at 11:39:56 PM UTC-6, Veek. M wrote:
> Nope - this is what i'm doing:
>
> class Foo():
> pass
>
> x = 'Foo'
>
> How do i use 'x' to create an instance of class Foo?
Use the builtin function `getattr` on the module that contains
the class named "Foo".
For exampl
On 14Feb2016 10:10, Veek. M wrote:
I'm writing a price parser. I need to do the equivalent of perl's
$$var to instantiate a class where $car is the class_name.
I'm passing 'Ebay' or 'Newegg' or 'Amazon' via cmd-line. I have a module
named ebay.py and a class called Ebay (price parser). I do som
Gregory Ewing wrote:
> Veek. M wrote:
>> I'm writing a price parser. I need to do the equivalent of perl's
>> $$var to instantiate a class where $car is the class_name.
>>
>> I'm passing 'Ebay' or 'Newegg' or 'Amazon' via cmd-line. I have a
>> module named ebay.py and a class called Ebay (price p
Veek. M wrote:
I'm writing a price parser. I need to do the equivalent of perl's
$$var to instantiate a class where $car is the class_name.
I'm passing 'Ebay' or 'Newegg' or 'Amazon' via cmd-line. I have a module
named ebay.py and a class called Ebay (price parser). I do something
like:
\> m
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 = ["Butt
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()
>