• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
KuraiTsubasa

Need more than 1 value to unpack?

8 posts in this topic

Hi everyone i just learning execise13 from learnpythonthehardway.org and i got this error:

 

Value error:Need more than 1 value to unpack

 

And this is my script:

 

from sys import argv

script, first, second, third = argv

print "This script called.:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third

 

Is there anything wrong in my script thank you very muchbiggrin.png

0

Share this post


Link to post
Share on other sites

try this:

from sys import argv
for arg in argv:
 print(arg)

and you will see that there is a argv in your case

 

also you can check length of argv before unpacking

if len(argv) > 1:
 #do some code here
Edited by pyirrlicht
1

Share this post


Link to post
Share on other sites
Is there anything wrong in my script thank you very much

 

 

You have to call it with at least 3 arguments!

 

E.g:

 

If you execute this:

$ python ex13.py first 2nd 3rd

You should see this:

The script is called: ex13.py
Your first variable is: first
Your second variable is: 2nd
Your third variable is: 3rd


			
		
1

Share this post


Link to post
Share on other sites

Can you tell me how you call the script? The script takes three extra argumens (first, second, third). From what I get, you're supposed to call it like this:



python myscript.py somethingforfirst somethingforsecond somethingforthird

Those are called arguments. Those arguments are first taken and packed into argv. In this line:



script, first, second, third = argv

You're unpacking stuff inside argv into separate variables. How do I explain it? Just say argv is a list (array, whatever). The content of argv is like:



['myscript.py', 'somethingforfirst', 'somethingforsecond', 'somethingforthird']

When you unpack it, those items in the array go to the variables in order, so 'myscipt.py' goes to script, 'somethingforfirst' goes to first, and the rest goes like that.

 

The error you see is caused because you try to take more than argv actually has. You're likely to only pass one argument ('myscript.py'), while you try to unpack argv into four variables. Python simply tells you that she needs more items to unpack.

 

Try to make a simple list of five items, and try to unpack it into six variables. You will get the same error message.

 

 

 

Is there anything wrong in my script thank you very much

 

 

You have to call it with at least 3 arguments!

 

E.g:

 

If you execute this:



$ python ex13.py first 2nd 3rd

You should see this:



The script is called: ex13.py
Your first variable is: first
Your second variable is: 2nd
Your third variable is: 3rd


I still don't get it when i tried that it give me an error say invalid syntax.Here my script:

 

from sys import argv

$ python ex13.py first 2nd 3rd

script, first, second, third = argv

print "This script called.:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third

 

Thank you for answering my question

0

Share this post


Link to post
Share on other sites

 

try this:



from sys import argv
for arg in argv:
 print(arg)

and you will see that there is a argv in your case

 

also you can check length of argv before unpacking



if len(argv) > 1:
 #do some code here

Thank you i will try thissmile.png 

1

Share this post


Link to post
Share on other sites

 

I still don't get it when i tried that it give me an error say invalid syntax.Here my script:


 

 

from sys import argv

$ python ex13.py first 2nd 3rd

script, first, second, third = argv

print "This script called.:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third

 

Thank you for answering my question

 

 

No. It's not like that. What Renega means with this:

 


If you execute this:
$ python ex13.py first 2nd 3rd
You should see this:

 

is not for the script. It's a Linux terminal command.

 

BDnwKwD.png

 

While talking about terminal command on the Internet, people tend to use the $ to indicate that "This is run in the terminal," so what Renega is saying is that you run:

python ex13.py first 2nd 3rd

on the Command Prompt (I guess you're running on Windows).

 

There's nothing wrong with your original script. What caused the problem is that you didn't give enough arguments for the script to unpack (explained in my first post). Let me explain it with more detail. argv is a list, so when you're unpacking it like this:

script, first, second, third = argv

It's basically just like this:

script, first, second, third = 'ex13.py', '1st', '2nd', '3rd'

Because argv is actually like this:

['ex13.py', '1st', '2nd', '3rd']

And it gets those items from those arguments you pass when you call the script on the Command Prompt:

python ex13.py 1st 2nd 3rd

Try to print argv and you will get what I mean. Is it clear now? :)

2

Share this post


Link to post
Share on other sites

 

 

I still don't get it when i tried that it give me an error say invalid syntax.Here my script:



 

 

from sys import argv

$ python ex13.py first 2nd 3rd

script, first, second, third = argv

print "This script called.:", script
print "Your first variable is:", first
print "Your second variable is:", second
print "Your third variable is:", third

 

Thank you for answering my question

 

 

No. It's not like that. What Renega means with this:

 

 

 


If you execute this:
$ python ex13.py first 2nd 3rd
You should see this:

 

is not for the script. It's a Linux terminal command.

 

BDnwKwD.png

 

While talking about terminal command on the Internet, people tend to use the $ to indicate that "This is run in the terminal," so what Renega is saying is that you run:



python ex13.py first 2nd 3rd

on the Command Prompt (I guess you're running on Windows).

 

There's nothing wrong with your original script. What caused the problem is that you didn't give enough arguments for the script to unpack (explained in my first post). Let me explain it with more detail. argv is a list, so when you're unpacking it like this:



script, first, second, third = argv

It's basically just like this:



script, first, second, third = 'ex13.py', '1st', '2nd', '3rd'

Because argv is actually like this:



['ex13.py', '1st', '2nd', '3rd']

And it gets those items from those arguments you pass when you call the script on the Command Prompt:



python ex13.py 1st 2nd 3rd

Try to print argv and you will get what I mean. Is it clear now? smile.png

 

Wow i can do that now.It is really clear thank you for helping me smile.png  and sorry because i really hard to understand that biggrin.png 

0

Share this post


Link to post
Share on other sites

Wow i can do that now.It is really clear thank you for helping me smile.png  and sorry because i really hard to understand that biggrin.png

 

My pleasure.

 

Don't worry about it. Everyone starts somewhere. Fully understanding these little things in the beginning can save a whole lot of pain down the road. There are actually people who don't care about how exactly their program runs as long as it's working, and when things go wild, they can't find the source of the problem, so whenever you feel unsure about how a piece of code works, track it down until it's clear. You can always ask, of course. That's what this community is for.

 

Study hard!

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0