Code redundancy

Alan Harris-Reid aharrisreid at googlemail.com
Tue Apr 20 09:43:53 EDT 2010


Hi,

During my Python (3.1) programming I often find myself having to repeat 
code such as...

class1.attr1 = 1
class1.attr2 = 2
class1.attr3 = 3
class1.attr4 = 4
etc.

Is there any way to achieve the same result without having to repeat the 
class1 prefix?  Before Python my previous main language was Visual 
Foxpro, which had the syntax...

with class1
   .attr1 = 1
   .attr2 = 2
   .attr3 = 3
   .attr4 = 4
   etc.
endwith

Is there any equivalent to this in Python?

Any help would be appreciated.

Alan Harris-Reid



More information about the Python-list mailing list