<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Ryan Kelly wrote:
<blockquote cite="mid:1271889190.2827.11.camel@durian" type="cite">
  <pre wrap="">On Tue, 2010-04-20 at 14:43 +0100, Alan Harris-Reid wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">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?
    </pre>
  </blockquote>
  <pre wrap=""><!---->

Please don't take this as in invitation to disregard the excellent
advice already received in this thread - I just want to point out that
python can usually be bent to your will.  Observe:

  
  from withhacks import namespace

  with namespace(class1):
      attr1 = 1
      attr2 = 2


This will do pretty much what you get from the "with" statement in
javascript (I assume it's similar to Visual Foxpro).


But don't use this in any real code.  Seriously, don't even think about
it.  You don't want to know the kind of abuses that go on under the
covers to make this kind of syntax hacking work...



  Cheers,

     Ryan</pre>
</blockquote>
Hi Ryan, thanks for that.<br>
<br>
No - I will not be adopting that solution.  Is there anything Python
can't do if you bend the rules far enough? <span class="moz-smiley-s3"><span>
;-) </span></span><br>
<br>
Regards,<br>
Alan<br>
</body>
</html>