Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > __autoinit__ (Was: Proposal: reducing self.x=x; self.y=y;self.z=z boilerplate code)

Reply
Thread Tools

__autoinit__ (Was: Proposal: reducing self.x=x; self.y=y;self.z=z boilerplate code)

 
 
falcon
Guest
Posts: n/a
 
      07-31-2005
Hello python-list,

As I Understood, semantic may be next:

def qwerty(a,a.i,b,b.i,f.j):
pass

Would work like:

def qwerty(anonymous1,anonymous2,anonymous3,anonymous4 ,anonymous5):
(a,a.i,b,b.i,f.j)=(anonymous1,anonymous2,anonymous 3,anonymous4,anonymous5)
del anonymous1
del anonymous2
del anonymous3
del anonymous4
del anonymous5

If so then I like it, because it more explicit than anything other
and it is working right now. I just tryed:

>>> class Stub:

.... pass
>>> def qwer(a1,a2,a3,a4,a5):

.... (a,a.i,b,b.i,f['i'])=(a1,a2,a3,a4,a5)
.... del a1
.... del a2
.... del a3
.... del a4
.... del a5
.... print (a,a.i,b,b.i,f['i'])
>>> f={}
>>> qwer(Stub(),1,Stub(),2,3)

(<__main__.Stub instance at 0x00C49530>, 1, <__main__.Stub instance at 0x00C498C8>, 2, 3)

So there are not too much for implement.
Another question - named arguments. How I can assign to them?
May be so:
f={}
def qwerty(a,a.i,f['i']):
print (a,a.i,f['i'])
qwerty(f['i']=3,a=Stub(),a.i=4) - ?

and for __init__:
class MyClass:
def __init__(self,self.i,self.j,self.k):
pass

MyObject = MyClass(self.i=1,self.j=2,self.k=3)

?

or may be there can be an aliase syntax?

class MyClass:
def __init__(self, self.i by i,self.j by j, self.k by k):
pass

MyObject = MyClass(i=1,j=2,k=3)

--
Sokolov Yura
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reducing import try/except boilerplate Nick Coghlan Python 1 12-21-2005 05:48 PM
Re: __autoinit__ (Was: Proposal: reducing self.x=x; self.y=y;self.z=z boilerplate code) Ralf W. Grosse-Kunstleve Python 2 07-12-2005 03:20 AM
Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code Ralf W. Grosse-Kunstleve Python 16 07-11-2005 09:28 PM
__autoinit__ (Was: Proposal: reducing self.x=x; self.y=y;self.z=z boilerplate code) Ralf W. Grosse-Kunstleve Python 18 07-11-2005 04:01 PM
Boilerplate template code for database add/update/delete dwok ASP .Net 2 05-11-2005 03:38 PM



Advertisments