Re: Using eval, or something like it...

2008-11-24 Thread Gabriel Genellina
En Fri, 21 Nov 2008 13:58:59 -0200, r0g [EMAIL PROTECTED] escribió: I hadn't really appreciated the consequences of this till now though e.g. that an instance might do a = a + 1 without affecting it's siblings but that b.append(fish) would affect b for everyone. I don't know if I will find any

Re: Using eval, or something like it...

2008-11-21 Thread r0g
Scott David Daniels wrote: r0g wrote: ... A class is like a template which combines a complex data type (made from a combination of other data types) and the methods that operate on that data type. You generally don't work with classes directly but you make instances of them, each instance

Re: Using eval, or something like it...

2008-11-21 Thread Joe Strout
On Nov 21, 2008, at 8:58 AM, r0g wrote: I hadn't really appreciated the consequences of this till now though e.g. that an instance might do a = a + 1 without affecting it's siblings but that b.append(fish) would affect b for everyone. I don't know if I will find any uses for that kind of

Re: Using eval, or something like it...

2008-11-21 Thread Scott David Daniels
I forgot to include a few cases: (1) Inspired by your calling the class attributes templates: class Demo3(object): pass d = Demo3() print d.non_template # raises exception d.non_template = 45 print d.non_template print Demo3.non_template # raises exception

Re: Using eval, or something like it...

2008-11-21 Thread r0g
Scott David Daniels wrote: I forgot to include a few cases: (1) Inspired by your calling the class attributes templates: I did no such thing, I likened classes to templates and as far as I can tell they are _like_ templates albeit dynamic ones. class Demo3(object): All the above to

Re: Using eval, or something like it...

2008-11-20 Thread Scott David Daniels
r0g wrote: John Machin wrote: You mention variables of a class but you then proceed to poke at an instance of the class Check out setattr (and getattr) in the docs. The former i.e. the variables of an instance of a class. Thanks :-) Careful here. Your wording seems to indicate you

Re: Using eval, or something like it...

2008-11-20 Thread r0g
Scott David Daniels wrote: r0g wrote: John Machin wrote: You mention variables of a class but you then proceed to poke at an instance of the class Check out setattr (and getattr) in the docs. The former i.e. the variables of an instance of a class. Thanks :-) Careful here. Your

Re: Using eval, or something like it...

2008-11-20 Thread Chris Rebert
On Thu, Nov 20, 2008 at 3:54 PM, r0g [EMAIL PROTECTED] wrote: Scott David Daniels wrote: r0g wrote: John Machin wrote: You mention variables of a class but you then proceed to poke at an instance of the class Check out setattr (and getattr) in the docs. The former i.e. the

Re: Using eval, or something like it...

2008-11-20 Thread Scott David Daniels
r0g wrote: ... A class is like a template which combines a complex data type (made from a combination of other data types) and the methods that operate on that data type. You generally don't work with classes directly but you make instances of them, each instance has it's own internal state and

Re: Using eval, or something like it...

2008-11-20 Thread George Sakkis
On Nov 20, 6:54 pm, r0g [EMAIL PROTECTED] wrote: It would seem from this setattr function that the proper term for these is 'attributes'. That for many years I have considered pretty much any named thing that may vary a 'variable' might be at the root of the problem here as it's a very

Re: Using eval, or something like it...

2008-11-20 Thread Steven D'Aprano
On Thu, 20 Nov 2008 11:12:56 +1000, James Mills wrote: DON'T USE eval! If you're going to make a sweeping generalization like that, at least offer some alternatives, and explain why eval should be avoided. Otherwise your advice is just cargo-cult programming. eval is not inherently bad, it

Using eval, or something like it...

2008-11-19 Thread r0g
Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a class e.g. class Foo(): bar = 1 gum = 2 mylist = ['bar','gum'] a = Foo() for each in mylist:

Re: Using eval, or something like it...

2008-11-19 Thread James Mills
DON'T USE eval! On Thu, Nov 20, 2008 at 10:44 AM, r0g [EMAIL PROTECTED] wrote: Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a class e.g. class

Re: Using eval, or something like it...

2008-11-19 Thread George Sakkis
On Nov 19, 7:44 pm, r0g [EMAIL PROTECTED] wrote: Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a class e.g. class Foo():   bar = 1   gum = 2

Re: Using eval, or something like it...

2008-11-19 Thread John Machin
On Nov 20, 11:44 am, r0g [EMAIL PROTECTED] wrote: Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a class e.g. class Foo():   bar = 1   gum = 2

Re: Using eval, or something like it...

2008-11-19 Thread r0g
George Sakkis wrote: On Nov 19, 7:44 pm, r0g [EMAIL PROTECTED] wrote: Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a class e.g. class Foo():

Re: Using eval, or something like it...

2008-11-19 Thread r0g
John Machin wrote: On Nov 20, 11:44 am, r0g [EMAIL PROTECTED] wrote: Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a class e.g. class Foo():