Hi Andy,<div><br></div><div>Thanks for your comment.  I could wrap this in a class but I&#39;m not so sure how it would save me to have to do something like this.</div><div><br></div><div>class ReturnWrapper(object):</div>
<div>     def __init__(error_code, error_message, real_return_result)</div><div>           ....</div><div><br></div><div>def f1(arg):</div><div>    try</div><div>        x = some_function()</div><div>    except IndexError, e</div>
<div>        return ReturnWrapper(-1,&#39;some error message&#39; , None)</div><div>    # all good here</div><div>    return ReturnWrapper(0, None, &#39;some good value&#39;)</div><div><br></div><div>def f1caller()</div><div>
    obj = f1(param1)</div><div>    if (obj.error_code &lt; 0):</div><div>       # handle some error or just return obj</div><div>       return obj</div><div>    foo....</div><div>    obj = f1(param2)</div><div>    if (obj.error_code &lt; 0):</div>
<div>       # handle some error or just return obj</div><div>       return obj</div><div>    bar....</div><div><br></div><div><br></div><div>I still have to use this pattern     if (obj.error_code &lt; 0):  .... </div><div>
It does not really make my code smaller than using tuple.</div><div>I used to code C similar to what you said I did not expect to have to do the </div><div>same thing in python</div><div><br></div><div>Thanks,</div><div><br>
<div class="gmail_quote">On Tue, Oct 5, 2010 at 9:42 PM, Andy Wiggin <span dir="ltr">&lt;<a href="mailto:andywiggin@gmail.com">andywiggin@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I must agree with the &quot;it&#39;s an unmitigated disaster&quot; comments already<br>
posted. But it does remind me of a C coding convention that was the<br>
standard at a company worked at a long time ago. Here, the return<br>
value from a function was always a coded int value where part of the<br>
int told you the boolean pass/fail info, part encoded the severity,<br>
part the product id, and part the specific message that could be<br>
looked up to print. All packed into 32 bits. The analogy I can think<br>
of is that you might want to return an instance of a standard class<br>
instead of a raw tuple. It could have pass/fail info, perhaps more<br>
extended info, plus a generic &quot;payload&quot; that would carry whatever the<br>
function was really trying to return. This would at least save you<br>
from interpreting ad hoc tuples everywhere, and might be a basis for<br>
building something a bit more elegant.<br>
<font color="#888888"><br>
-Andy<br>
</font><div><div></div><div class="h5"><br>
On Tue, Oct 5, 2010 at 9:16 PM, Nick S Kanakakorn &lt;<a href="mailto:bbdada@gmail.com">bbdada@gmail.com</a>&gt; wrote:<br>
&gt; I don&#39;t want to do this.  There is someone that against throwing exception<br>
&gt; and that person has more seniority than me. He put in a guideline.  I lost<br>
&gt; in the debate.  There is no proper research done and all the decisions were<br>
&gt; made in less than 1 day.<br>
&gt;<br>
&gt; On Tue, Oct 5, 2010 at 9:03 PM, Tung Wai Yip &lt;<a href="mailto:tungwaiyip@yahoo.com">tungwaiyip@yahoo.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Why do you want to do this? Is this just an internal coding guideline? Or<br>
&gt;&gt; is it done for interfacing to another language or running on non-standard<br>
&gt;&gt; VM? Is this apply to new code only or do you want to update existing code as<br>
&gt;&gt; well?<br>
&gt;&gt;<br>
&gt;&gt; There is no equivalent of C macro in Python. Just apply every code change<br>
&gt;&gt; as you describe it. Build a tuple every time you return something. Change<br>
&gt;&gt; raise into returning tuple. And change ever function call to expecting a<br>
&gt;&gt; tuple return value. I can&#39;t think of anything smarter. it looks like a<br>
&gt;&gt; complete disaster anyway.<br>
&gt;&gt;<br>
&gt;&gt; Wai yip<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;&gt; Let&#39;s skip the rationale discussion although I feel better for your<br>
&gt;&gt;&gt; sympathy.  One non python solution I can think of is Macro (C/C++) or add<br>
&gt;&gt;&gt; a<br>
&gt;&gt;&gt; new command  which could work in any stack frame (TCL).<br>
&gt;&gt;&gt; However, I&#39;m quite new to python so I&#39;m not so sure if there are some<br>
&gt;&gt;&gt; ways<br>
&gt;&gt;&gt; around this.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Can we have something similar to macro in python ?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Tue, Oct 5, 2010 at 7:27 PM, Glen Jarvis &lt;<a href="mailto:glen@glenjarvis.com">glen@glenjarvis.com</a>&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &gt; My work place has imposed a rules for no use of exception (catching is<br>
&gt;&gt;&gt;&gt; allowed).<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; What?!?<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Forgive my reaction, I&#39;m just very surprised. Why has your workplace<br>
&gt;&gt;&gt;&gt; implemented this policy? Has anyone else on BayPIGgies seen a  policy<br>
&gt;&gt;&gt;&gt; like<br>
&gt;&gt;&gt;&gt; this? What&#39;s the rationale?  Am I a Luddite for not hearing on this?<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I&#39;m sorry. I know you asked a genuine question and I haven&#39;t answered<br>
&gt;&gt;&gt;&gt; it. I<br>
&gt;&gt;&gt;&gt; just found this very odd and am first getting my head around the<br>
&gt;&gt;&gt;&gt; question.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Cheers,<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Glen<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; Using Opera&#39;s revolutionary e-mail client: <a href="http://www.opera.com/mail/" target="_blank">http://www.opera.com/mail/</a><br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Baypiggies mailing list<br>
&gt;&gt; <a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>
&gt;&gt; To change your subscription options or unsubscribe:<br>
&gt;&gt; <a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; -Nick Kanakakorn<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Baypiggies mailing list<br>
&gt; <a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>
&gt; To change your subscription options or unsubscribe:<br>
&gt; <a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a><br>
&gt;<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>-Nick Kanakakorn<br>
</div>