Re: Python OOP Problem

2009-12-29 Thread Lie Ryan
On 12/29/2009 3:01 PM, Миклухо wrote: On 28 дек, 18:29, "Martin v. Loewis" wrote: In this case (you just started to learn Python), I recommend to take an explicit approach. Create a dictionary that maps class names to classes: name2class = { "MyObject" : MyObject, "MyOtherObjec

Re: Python OOP Problem

2009-12-29 Thread Миклухо
On Dec 29, 7:35 pm, Laszlo Nagy wrote: > > Thanks for reply, but it doesn't fit to my task. If I will add later > > other objects(and it will be very often) - I should stop the service, > > but that would be very bad. > > I think you meant "if you add other classes".> I'm not sure, if this is > s

Re: Python OOP Problem

2009-12-29 Thread Laszlo Nagy
Thanks for reply, but it doesn't fit to my task. If I will add later other objects(and it will be very often) - I should stop the service, but that would be very bad. I think you meant "if you add other classes". I'm not sure, if this is solution, but test passed: myimportmod = __import__(

Re: Python OOP Problem

2009-12-28 Thread Миклухо
On 28 дек, 18:29, "Martin v. Loewis" wrote: > Миклухо wrote: > > Hi, all. My problem is: > > 1) I have a database(postgresql) > > 2)I'm getting some string from database(string is a classname - > > written by me). > > 3)I need to construct new object from this string. > > In java it's done by Clas

Re: Python OOP Problem

2009-12-28 Thread Миклухо
On 28 дек, 18:29, "Martin v. Loewis" wrote: > Миклухо wrote: > > Hi, all. My problem is: > > 1) I have a database(postgresql) > > 2)I'm getting some string from database(string is a classname - > > written by me). > > 3)I need to construct new object from this string. > > In java it's done by Clas

Re: Python OOP Problem

2009-12-28 Thread Миклухо
On 28 дек, 18:29, "Martin v. Loewis" wrote: > Миклухо wrote: > > Hi, all. My problem is: > > 1) I have a database(postgresql) > > 2)I'm getting some string from database(string is a classname - > > written by me). > > 3)I need to construct new object from this string. > > In java it's done by Clas

Re: Python OOP Problem

2009-12-28 Thread Миклухо
On 28 дек, 18:02, Daniel Fetchinson wrote: > > Hi, all. My problem is: > > 1) I have a database(postgresql) > > 2)I'm getting some string from database(string is a classname - > > written by me). > > 3)I need to construct new object from this string. > > In java it's done by Class.forName().newIns

Re: Python OOP Problem

2009-12-28 Thread Martin v. Loewis
>> name2class = { "MyObject" : MyObject, >>"MyOtherObject" : MyOtherObject, >>"Etc" : Etc } >> >> Then, when you receive the string class_name, you do >> >> o = name2class[class_name] >> o.myfunction() >> > The class needs to be instantiated, so the one line should b

Re: Python OOP Problem

2009-12-28 Thread Anthony Tolle
On Dec 28, 7:29 am, "Martin v. Loewis" wrote: > > In this case (you just started to learn Python), I recommend to take > an explicit approach. Create a dictionary that maps class names to > classes: > > name2class = { "MyObject" : MyObject, >                "MyOtherObject" : MyOtherObject, >      

Re: Python OOP Problem

2009-12-28 Thread Martin v. Loewis
Миклухо wrote: > Hi, all. My problem is: > 1) I have a database(postgresql) > 2)I'm getting some string from database(string is a classname - > written by me). > 3)I need to construct new object from this string. > In java it's done by Class.forName().newInstance(); > > For instance: > 1)I receive

Re: Python OOP Problem

2009-12-28 Thread Daniel Fetchinson
> Hi, all. My problem is: > 1) I have a database(postgresql) > 2)I'm getting some string from database(string is a classname - > written by me). > 3)I need to construct new object from this string. > In java it's done by Class.forName().newInstance(); > > For instance: > 1)I receive the string: "My