Bugs That Bite
Published in

Bugs That Bite

ValueError: too many values to unpack (expected 2)

Too many values passed back from a python function

Python differs from some other languages in that you can pass back multiple values from a function. The number of values that you retrieve from a function needs to match the number of values that you return from the function.

For example, if you have this function:

def funkyfunk(test1, test2, test3):
#do something with values
return test1, test2, test3

and then you call the function like this:

test1, test2 = funkyfunk(test1, test2, test3)

that causes this error:

ValueError: too many values to unpack (expected 2)

To fix it return three and read three values:

def funkyfunk(test1, test2, test3):
#do something with values
return test1, test2, test3
test1, test2, test3 = funkyfunk(test1, test2, test3)

Teri Radichel

If you liked this story please clap and follow:

Medium: Teri Radichel or Email List: Teri Radichel
Twitter: @teriradichel or @2ndSightLab
Requests services via LinkedIn: Teri Radichel or IANS Research

© 2nd Sight Lab 2022

____________________________________________

Author:

Cybersecurity for Executives in the Age of Cloud on Amazon

Need Cloud Security Training? 2nd Sight Lab Cloud Security Training

Is your cloud secure? Hire 2nd Sight Lab for a penetration test or security assessment.

Have a Cybersecurity or Cloud Security Question? Ask Teri Radichel by scheduling a call with IANS Research.

Cybersecurity & Cloud Security Resources by Teri Radichel: Cybersecurity and Cloud security classes, articles, white papers, presentations, and podcasts

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store