Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Is there a better way to code variable number of return arguments?

Reply
Thread Tools

Is there a better way to code variable number of return arguments?

 
 
Dr. Phillip M. Feldman
Guest
Posts: n/a
 
      10-08-2009

I currently have a function that uses a list internally but then returns the
list items as separate return
values as follows:

if len(result)==1: return result[0]
if len(result)==2: return result[0], result[1]

(and so on). Is there a cleaner way to accomplish the same thing?
--
View this message in context: http://www.nabble.com/Is-there-a-bet...p25803294.html
Sent from the Python - python-list mailing list archive at Nabble.com.

 
Reply With Quote
 
 
 
 
Paul Rubin
Guest
Posts: n/a
 
      10-08-2009
"Dr. Phillip M. Feldman" <(E-Mail Removed)> writes:
> if len(result)==1: return result[0]
> if len(result)==2: return result[0], result[1]
>
> (and so on). Is there a cleaner way to accomplish the same thing?


That is poor style. Just return the result as a list.
 
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
Re: Is there a better way to code variable number of return arguments? Ethan Furman Python 2 10-08-2009 06:05 PM
Re: Parsing Binary Structures; Is there a better way / What is your way? Paul Rubin Python 5 08-06-2009 08:06 AM
Is splint really better than lint? Is there a better tool than splint? Peter Bencsik C Programming 2 09-21-2006 10:02 PM
Build a Better Blair (like Build a Better Bush, only better) Kenny Computer Support 0 05-06-2005 04:50 AM
is there a better way to optimise this code Sid C Programming 24 08-27-2004 03:58 AM



Advertisments