Hi,
I know in java , we can use
class.ForName("classname")
to get an instance of the class 'classname' from a
string , in python , how do I do that ?
Thanks in advance !
--
http://mail.python.org/mailman/listinfo/python-list
Bo Yang:
> to get an instance of the class 'classname' from a
> string , in python , how do I do that ?
This is a possibile way:
class C: pass
c = locals()["C"]()
print c
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Bo Yang wrote:
> Hi,
> I know in java , we can use
>
> class.ForName("classname")
>
>
> to get an instance of the class 'classname' from a
> string , in python , how do I do that ?
You can use
getattr(module, classname)(*arguments)
Diez
--
http://mail.python.org/mailman/listinfo/python
Bo Yang wrote:
> I know in java , we can use
>
> class.ForName("classname")
>
>
> to get an instance of the class 'classname' from a
> string , in python , how do I do that ?
In Python, classes are first class objects, so normally you would pass
the class itself around, rather than use the names
Luke Plant wrote:
> Bo Yang wrote:
>
>> I know in java , we can use
>>
>> class.ForName("classname")
>>
>>
>> to get an instance of the class 'classname' from a
>> string , in python , how do I do that ?
>
> In Python, classes are first class objects, so normally you would pass
> the class itsel
On 23 Feb 2006 05:22:25 -0800
"Luke Plant" <[EMAIL PROTECTED]> wrote:
> In Python, classes are first class objects, so normally
> you would pass the class itself around, rather than use
> the names of classes. Of course that might not be
> practical or applicable in your situation.
It is in fact,
Is there anything particularly bad with
obj = eval(classname + "()")
?
It appears to work, but I'm a noobie so I could be missing something
nasty, in which any edication would be gratefully received.
Mike
--
http://mail.python.org/mailman/listinfo/python-list
Mike Woodhouse wrote:
> Is there anything particularly bad with
> obj = eval(classname + "()")
> It appears to work, but I'm a noobie so I could be missing something
> nasty, in which any edication would be gratefully received.
It is a little too indirect. Usually wanting to use "eval" or "
On Fri, 24 Feb 2006 06:37:27 -0800, Mike Woodhouse wrote:
> Is there anything particularly bad with
>
> obj = eval(classname + "()")
>
> ?
>
> It appears to work, but I'm a noobie so I could be missing something
> nasty, in which any edication would be gratefully received.
In your own code, th
Hi!
Perso, I like this...
MCI
--
http://mail.python.org/mailman/listinfo/python-list
10 matches
Mail list logo