Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Returning a splat
#1
I've built a function that makes a list of parameters for another function.
This is intended to be part of a library and the concerns must be separated; otherwise I'd just run the second function within the first, but I cannot.

What works now:
def foo(list_1, list_2):
    #do stuff to list_1 and list_2
    return [list_1, list_2]

params = foo(colors, names)
bar(*params)
This works perfectly but I'm preparing this for a client that wants to use only functions and the splat is a bit much for them.
What I'd like is to move the splat into the return statement or anywhere in foo:
def foo(list_1, list_2):
    #do stuff to list_1 and list_2
    return *[list_1, list_2]

params = foo(colors, names)
bar(params)
but this is invalid syntax.

It looks like even in the latest version 3.7.4 unpacking with the splat is still only possible in parameters, list creation, and dictionary creation.

Any thought on how I can return a complete parameters list that does not require the use of a splat?
Reply


Messages In This Thread
Returning a splat - by Clunk_Head - Jul-13-2019, 12:22 PM
RE: Returning a splat - by ichabod801 - Jul-13-2019, 12:27 PM
RE: Returning a splat - by Clunk_Head - Jul-13-2019, 12:39 PM
RE: Returning a splat - by ichabod801 - Jul-13-2019, 12:42 PM
RE: Returning a splat - by Clunk_Head - Jul-13-2019, 01:01 PM
RE: Returning a splat - by ichabod801 - Jul-13-2019, 01:05 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020