By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

Command line input

P: n/a
How do I receive input from the command line in Python?
Mar 31 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Mon, 31 Mar 2008 12:39:54 -0700, hexusnexus wrote:
How do I receive input from the command line in Python?
Direct way `sys.argv`, comfortable way `optparse`.

Ciao,
Marc 'BlackJack' Rintsch
Mar 31 '08 #2

P: n/a
On 31 Mar 2008 20:13:05 GMT, Marc 'BlackJack' Rintsch <bj****@gmx.netwrote:
On Mon, 31 Mar 2008 12:39:54 -0700, hexusnexus wrote:
>How do I receive input from the command line in Python?

Direct way `sys.argv`, comfortable way `optparse`.
I have a feeling he doesn't mean command-line arguments to the
program, but typing on the keyboard after the program has started.
If that is the case:

Direct way `sys.stdin`, many other fancy ways.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se R'lyeh wgah'nagl fhtagn!
Mar 31 '08 #3

P: n/a
On Mar 31, 2:39 pm, hexusne...@gmail.com wrote:
How do I receive input from the command line in Python?
As long as we are all guessing, do you perhaps mean raw_input?

my_name = raw_input("What is your name? ")
What is your name? Rick <ENTER>
>>my_name
'Rick'

Mar 31 '08 #4

P: n/a
On Mar 31, 4:04 pm, Rick Dooling <rpdool...@gmail.comwrote:
On Mar 31, 2:39 pm, hexusne...@gmail.com wrote:
How do I receive input from the command line in Python?

As long as we are all guessing, do you perhaps mean raw_input?

my_name = raw_input("What is your name? ")
What is your name? Rick <ENTER>>>my_name

'Rick'
Yeah, sorry for being vague. Thanks.
Apr 1 '08 #5

P: n/a

On Mon, 2008-03-31 at 12:39 -0700, he********@gmail.com wrote:
How do I receive input from the command line in Python?
I have used:

sys.argv[ 1 ]

I have been doing Python for around 2 days now, so please do double check that!

--Paul
All Email originating from UWC is covered by disclaimer
http://www.uwc.ac.za/portal/public/p...disclaimer.htm

Apr 1 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.