<div class="gmail_quote">On Mon, Jun 1, 2009 at 3:55 PM, Alan Gauld <span dir="ltr"><<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
"W W" <<a href="mailto:srilyk@gmail.com" target="_blank">srilyk@gmail.com</a>> wrote<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
class C:<div class="im"><br>
@constructor<br>
def LoadFromFile(fname, count): ...<br>
@constructor<br>
def Create(valueTuple):...<br>
<br>
Personally I prefer the Delphi style sincve it makes the constructor<br>
call explicit and adds to the documentation.<br>
<br>
Alan G<br>
<br>
</div></blockquote><div class="im">
<br>
That does make it problematic... although I suppose checking the type would<br>
be a workaround - still, not simple or beautiful. Has this been introduced<br>
as a PEP?<br>
</div></blockquote>
<br>
Type checking is the problem. Until Python can distinguish methods based<br>
on types (which introduces other issues) thisi is difficult with the C/Java style.<br>
<br>
We can fake the Delphi style by using a default constructor and then just<br>
calling the "constructors" after initialisation:<br>
<br>
class C:<br>
def __init__(): pass<div class="im"><br>
@constructor<br>
def LoadFromFile(fname, count): ...<br>
@constructor<br>
def Create(valueTuple):...<br>
<br></div>
c = C()<br>
c.LoadFromFile(fn, cnt)<br>
<br>
But its two lines not one... :-(<br>
<br>
And so far as I know it has not been PEPd although I'm sure it has<br>
been discussed.</blockquote><div><br></div><div>I'm not sure how types are implemented in the underlying C, but it seems that it should be a somewhat trivial addition. I mean, type checking is already built-in to python, i.e. type('a') o/p: <type 'str'>, so just building a handler specific to the __init__ method, or modifying it if it's already unique, should be able to take care of it.</div>
<div><br></div><div>I guess one way you could try to parse it on your own is build a list of types: f1 = [type(''), type(1), type(())], f2 = [type([]), type(1)]] and compare the types of arguments provided from *args. I suppose really, one could go so far as to build a dict of lists with the lengths:</div>
<div><br></div><div>spam = {1:[[type(''))],], 2:[[type([]), type(())], [type(1), type(1.0)]</div><div><br></div><div>then compare then lengths of args first.</div><div><br></div><div>That's a lot of work, though :P</div>
<div>-Wayne</div></div>