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

Discussion in 'Python' started by Dr. Phillip M. Feldman, Oct 8, 2009.

  1. 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-be...of-return-arguments--tp25803294p25803294.html
    Sent from the Python - python-list mailing list archive at Nabble.com.
     
    Dr. Phillip M. Feldman, Oct 8, 2009
    #1
    1. Advertising

  2. Dr. Phillip M. Feldman

    Paul Rubin Guest

    "Dr. Phillip M. Feldman" <> 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.
     
    Paul Rubin, Oct 8, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    863
  2. Paul Rubin
    Replies:
    5
    Views:
    440
    Hendrik van Rooyen
    Aug 6, 2009
  3. Ethan Furman
    Replies:
    2
    Views:
    292
    Ethan Furman
    Oct 8, 2009
  4. Navaneeth
    Replies:
    4
    Views:
    573
    Kenny McCormack
    Nov 20, 2010
  5. Replies:
    20
    Views:
    403
    Ethan Furman
    Nov 16, 2012
Loading...

Share This Page