avatarTeri Radichel

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1378

Abstract

an> <span class="hljs-title function_">funkyfunk</span>(<span class="hljs-params">test1, test2, test3</span>): <span class="hljs-comment">#do something with values</span> <span class="hljs-keyword">return</span> test1, test2, test3</pre></div><p id="1318">and then you call the function like this:</p><div id="9cf0"><pre><span class="hljs-built_in">test1,</span> test2 = funkyfunk(test1, test2, test3)</pre></div><p id="4b7e">that causes this error:</p><div id="8b05"><pre>ValueError: too many <span class="hljs-keyword">values</span> to <span class="hljs-keyword">unpack</span> (expected <span class="hljs-number">2</span>)</pre></div><p id="1ebd">To fix it return three and read three values:</p><div id="03d3"><pre><span class="hljs-keyword">def</span> <span class="hljs-title function_">funkyfunk</span>(<span class="hljs-params">test1, test2, test3</span>): <span class="hljs-comment">#do something with values</span> <span class="hljs-keyword">return</span> test1, test2, test3</pre></div><div id="2e49"><pre><span class="hljs-built_in">test1,</span> test2, test3 = funkyfunk(test1, test2, test3)</pre></div><p id="d6dd">Follow for updates.</p><p id="4a3a">Teri Radichel | <i>© <a href="https://2ndsightlab.com/?source=post_page---------------------------">2nd Sight Lab</a> 2022</i></p><div id="8b5f"><pre><span class="hljs-section">About Teri Radiche

Options

l:

⭐️ Author: Cybersecurity Books
⭐️ Presentations: Presentations by Teri Radichel
⭐️ Recognition: SANS Award, AWS Security Hero, IANS Faculty
⭐️ Certifications: SANS ~ GSE 240
⭐️ Education: BA Business, Master of Software Engineering, Master of Infosec
⭐️ Company: Penetration Tests, Assessments, Phone Consulting ~ 2nd Sight Lab</pre></div><div id="caae"><pre><span class="hljs-section">Need Help With Cybersecurity, Cloud, or Application Security?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span>
🔒 Request a penetration test or security assessment
🔒 Schedule a consulting call
🔒 Cybersecurity Speaker for Presentation</pre></div><div id="46f6"><pre>Follow <span class="hljs-keyword">for</span> more stories like <span class="hljs-keyword">this</span>:

❤️ Sign Up my Medium Email List ❤️ Twitter: <span class="hljs-meta">@teriradichel</span> ❤️ LinkedIn: https:<span class="hljs-comment">//www.linkedin.com/in/teriradichel</span> ❤️ Mastodon: <span class="hljs-meta">@teriradichel</span><span class="hljs-meta">@infosec</span>.exchange ❤️ Facebook: 2nd Sight Lab ❤️ YouTube: @2ndsightlab</pre></div><figure id="550c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*4oxP4LXk8l8c3mpRvO7ejg.png"><figcaption></figcaption></figure></article></body>

ValueError: too many values to unpack (expected 2)

Too many values passed back from a python function

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

⚙️ Check out my series on Automating Cybersecurity Metrics | Code.

🔒 Related Stories: Bugs | AWS Security | Secure Code

💻 Free Content on Jobs in Cybersecurity | ✉️ Sign up for the Email List

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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)

Follow for updates.

Teri Radichel | © 2nd Sight Lab 2022

About Teri Radichel:
~~~~~~~~~~~~~~~~~~~~
⭐️ Author: Cybersecurity Books
⭐️ Presentations: Presentations by Teri Radichel
⭐️ Recognition: SANS Award, AWS Security Hero, IANS Faculty
⭐️ Certifications: SANS ~ GSE 240
⭐️ Education: BA Business, Master of Software Engineering, Master of Infosec
⭐️ Company: Penetration Tests, Assessments, Phone Consulting ~ 2nd Sight Lab
Need Help With Cybersecurity, Cloud, or Application Security?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
🔒 Request a penetration test or security assessment
🔒 Schedule a consulting call
🔒 Cybersecurity Speaker for Presentation
Follow for more stories like this:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
❤️ Sign Up my Medium Email List
❤️ Twitter: @teriradichel
❤️ LinkedIn: https://www.linkedin.com/in/teriradichel
❤️ Mastodon: @teriradichel@infosec.exchange
❤️ Facebook: 2nd Sight Lab
❤️ YouTube: @2ndsightlab
Python
Valueerror
Too Many Values To Unpack
Error Message
Function
Recommended from ReadMedium