Re: reflection as in Java: how to create an instance from a classname

2009-01-06 Thread guss
Hi Carl thanks for your improved forname method. Regarding the high level reflection API, it is true that we don't need an API as complex as in Java considering the dynamic aspect of Python but you have a forname function I needed one so it could be nice to have it (and other services related to

Re: reflection as in Java: how to create an instance from a classname

2009-01-06 Thread Carl Banks
On Jan 6, 2:24 am, guss wrote: > hi Thanks for the tip but I had to play with the __import__ func a > bit. > Indeed to load not only the top module with __import__ one needs to > try to load an object from the module: > > Here is my forname: > > def forname(modname, classname): >     module = __im

Re: reflection as in Java: how to create an instance from a classname

2009-01-06 Thread guss
hi Thanks for the tip but I had to play with the __import__ func a bit. Indeed to load not only the top module with __import__ one needs to try to load an object from the module: Here is my forname: def forname(modname, classname): module = __import__(modname,globals(),locals(),['NoName'],-1)

Re: reflection as in Java: how to create an instance from a classname

2009-01-05 Thread Quentin Gallet-Gilles
On Mon, Jan 5, 2009 at 5:34 PM, Bruno Desthuilliers wrote: > guss a écrit : > >> I cannot find a satisfying answer to this question on the web so let's >> try here. >> >> My problem is the following, I would like to instantiate some object >> from a configuration file that would contain class nam

Re: reflection as in Java: how to create an instance from a classname

2009-01-05 Thread Bruno Desthuilliers
guss a écrit : I cannot find a satisfying answer to this question on the web so let's try here. My problem is the following, I would like to instantiate some object from a configuration file that would contain class names like for example classname=org.common.resource.MyResource. Here my resourc

reflection as in Java: how to create an instance from a classname

2009-01-05 Thread guss
I cannot find a satisfying answer to this question on the web so let's try here. My problem is the following, I would like to instantiate some object from a configuration file that would contain class names like for example classname=org.common.resource.MyResource. Here my resource is the class to