0

I first wrote a function that took 18 arguments and turned them into 6 different lists. Here is the code:

def list_maker(val1,val2,val3,val4,val5,val6,val7,val8,val9,por1,por2,por3,hth1,hth2,hth3,sat1,sat2,sat3):

#Make the voip list
list1 = [val1,val2,val3]
list2 = [val4,val5,val6]
list3 = [val7,val8,val9]

#Make the variable list
list_por = [por1,por2,por3]
list_hth = [hth1,hth2,hth3]
list_sat = [sat1,sat2,sat3]

return list1,list2,list3,list_por,list_hth,list_sat

That part worked just fine (I'll make it look better once it actually works). Now, my idea was to use that function as input to this other function right below to create plots:

def graph_maker(listx1,listx2,listx3,list1,list2,list3):

#plot the saturation graph
por_plot = plt.plot(listx1,list1)
por_plot.ylabel('VOIP')
por_plot.xlabel('Porosity')
por_plot.show()

#plot the heigth graph
hth_plot = plt.plot(listx2,list2)
hth_plot.ylabel('VOIP')
hth_plot.xlabel('Height')
hth_plot.show()

#plot the saturation graph
sat_plot = plt.plot(listx3,list3)
sat_plot.ylabel('VOIP')
sat_plot.xlabel('Saturation')
sat_plot.show()

So I ran the code with the two following lines:

list_maker(voip1,voip2,voip3,voip4,voip5,voip6,voip7,voip8,voip9,0.3,0.2,0.15,100,150,200,0.8,0.6,0.5)
graph_maker(list_maker)

And the error I'm getting is:

graph_maker() missing 5 required positional arguments: 'listx2', 'listx3', 'list1', 'list2', and 'list3'

What I understand from it, it looks as if list_maker() is actually returning only one list, and obviously the graph_maker function needs 6 arguments. Any ideas?

Thanks for the help!

1
  • First of all you need to pass the list not the function and second of all you need to unpack the list with the star'*' operator. graph_maker(*list_maker(voip1, voip2, ...)) Commented Oct 11, 2018 at 19:43

2 Answers 2

1

Marco, when you pass list_maker into graph_maker, you're not actually passing the result of the function (the lists you want) as input to graph_maker, you're actually passing the function into it.

But it's not just a matter of doing this:

result = list_maker(voip1,voip2,voip3,voip4,voip5,voip6,voip7,voip8,voip9,0.3,0.2,0.15,100,150,200,0.8,0.6,0.5)
graph_maker(result)

Because the function list_maker returns a tuple with all the lists, you need to expand them this way:

result = list_maker(voip1,voip2,voip3,voip4,voip5,voip6,voip7,voip8,voip9,0.3,0.2,0.15,100,150,200,0.8,0.6,0.5)
graph_maker(*result)

The asterisk will expand the tuple into the 5 arguments that the function requires, does this make sense?

Sign up to request clarification or add additional context in comments.

Comments

0

You're missing part of the inner function call in the outer function call:

graph_maker(list_maker)
graph_maker(*list_maker(vars))

Or assign your initial function call to a variable and use * to unpack the values (credit to @zondo)

x=list_maker(voip1,voip2,voip3,voip4,voip5,voip6,voip7,voip8,voip9,0.3,0.2,0.15,100,150,200,0.8,0.6,0.5)
graph_maker(*x)

1 Comment

You need to use *x, as in LuRsT's answer. Otherwise, it's passing a single tuple instead of 6 arguments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.