chevron_left chevron_right
Login Register invert_colors photo_library


Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 0 Vote(s) - 0 Average


Argv help filter_list
Author
Message
Argv help #1
I'm new to Python, and I'm reading "learnpythonthehardway" and so far I think it's good, but i'm having some trouble with chapter 14 which talks about argvs.

My script:
PHP Code:
from sys import argv

script
user_name argv
prompt 
'> '

print "Hi %r, i'm the %r script, nice to meet you." % (user_namescript)
print 
"If you don't mind, %r, i'd like to ask you a few questions?" user_name
print "Do you like me, %r?" user_name
opinion 
raw_input(prompt)

print 
"Where do you happen to reside, %r?" user_name
residence 
raw_input(prompt)

print 
"So what operating system do you operate on, %r?" user_name
OS 
raw_input(prompt)

print 
"And lastly, what race are you?"
race raw_input(prompt)

print 
"""
So, you said %s when I asked if you liked me.
You live in %s, nice area I guess.
You operate on %s, pretty lame if you ask me.
You are %s, very interesting.
""" 
% (opinionresidenceOSrace

But then it asks me "Add another argument to your script"

So I assume it's asking me to add another argument in the second line being

PHP Code:
scriptuser_name argv 

But I don't know what to put, since i'm having trouble thinking about where I would put it.

So could anyone please just add a new arg for me to inspect to understand what I could have done?


I added a new arg called nick_name, like so:

PHP Code:
scriptuser_namenick_name argv 

My full script now:

PHP Code:
from sys import argv

script
user_namenick_name argv
prompt 
'> '

print "Hi %r, i'm the %r script, nice to meet you." % (user_namescript)
print 
"If you don't mind, %r, i'd like to ask you a few questions?" user_name
print "%r, make up a nickname please.?" user_name
nick_name 
raw_input(prompt)
print 
"%r, your nickname is %r? Wow." % (user_namenick_name)
print 
"Do you like me, %r?" user_name
opinion 
raw_input(prompt

PHP Code:
Traceback (most recent call last):
  
File "ext13.py"line 3in <module>
    
scriptuser_namenick_name argv
ValueError
need more than 2 values to unpack 
Unleash the lead from my pistol into my head bumpin' crystal

Reply

RE: Argv help #2
Your initial code is fine, you just need to specify your arguments when you run the script as that's how argv acquires them. See the following:

Code:
[pens@anus:~]$ python deng.py gay
Hi 'gay', i'm the 'deng.py' script, nice to meet you.
If you don't mind, 'gay', i'd like to ask you a few questions?
Do you like me, 'gay'?
> no
Where do you happen to reside, 'gay'?
> new york
So what operating system do you operate on, 'gay'?
> lunix
And lastly, what race are you?
> snail

So, you said no when I asked if you liked me.
You live in new york, nice area I guess.
You operate on lunix, pretty lame if you ask me.
You are snail, very interesting.

deng.py is argv[0] or "script"
gay is argv[1] or "user_name"

Reply

RE: Argv help #3
(01-03-2014, 12:56 AM)Pens Wrote: Your initial code is fine, you just need to specify your arguments when you run the script as that's how argv acquires them. See the following:

Code:
[pens@anus:~]$ python deng.py gay
Hi 'gay', i'm the 'deng.py' script, nice to meet you.
If you don't mind, 'gay', i'd like to ask you a few questions?
Do you like me, 'gay'?
> no
Where do you happen to reside, 'gay'?
> new york
So what operating system do you operate on, 'gay'?
> lunix
And lastly, what race are you?
> snail

So, you said no when I asked if you liked me.
You live in new york, nice area I guess.
You operate on lunix, pretty lame if you ask me.
You are snail, very interesting.

deng.py is argv[0] or "script"
gay is argv[1] or "user_name"

So for my second argument, it would go something like?

PHP Code:
Vulsion~# python test.py dongs rupert(for my nick_name, aka the second argument)? 
Unleash the lead from my pistol into my head bumpin' crystal

Reply

RE: Argv help #4
(01-03-2014, 01:11 AM)VolPlus Wrote: So for my second argument, it would go something like?

PHP Code:
Vulsion~# python test.py dongs rupert(for my nick_name, aka the second argument)? 

Yes if you're using the second version of the code you added (which requires 3 args including the filename).

Reply

RE: Argv help #5
(01-03-2014, 01:16 AM)Pens Wrote: Yes if you're using the second version of the code you added (which requires 3 args including the filename).

Alright, thanks, i'll try it out.
Unleash the lead from my pistol into my head bumpin' crystal

Reply






Users browsing this thread: 1 Guest(s)