Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 689 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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 
Reply

#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:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


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

#3
Quote:(01-03-2014, 01:11 AM)VolPlus Wrote:

[To see links please register here]

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

#4
Quote:(01-03-2014, 12:56 AM)Pens Wrote:

[To see links please register here]

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:


Hidden Content
You must

[To see links please register here]

or

[To see links please register here]

to view this content.


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

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

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.
Reply

#5
Quote:(01-03-2014, 01:16 AM)Pens Wrote:

[To see links please register here]

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.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through