-3

For example if I want to compare two numbers(compare which is greater, for example) and get this input from the terminal in linux along with the filename.

Like:

python myfilename.py 2 3

This program should output 3. I think that this can be done with the help of sys module.

Sahil Babbar
  • 143
  • 1
  • 2
  • 8
  • 1
    http://docs.python.org/2/tutorial/stdlib.html#command-line-arguments or for a more powerful module, http://docs.python.org/2/library/argparse.html#module-argparse – C.B. Jan 09 '14 at 17:31
  • `python myfilename.py 2 3 & echo 3` should output 3 –  Jan 09 '14 at 17:31
  • I recommend [argparse](http://docs.python.org/3.3/library/argparse.html). – mojo Jan 09 '14 at 17:36
  • I think argparse is an overkill for such a simple use – Elisha Jan 09 '14 at 17:44

1 Answers1

0

Use sys.argv like in:

import sys
print sys.argv
Alvaro Fuentes
  • 16,937
  • 4
  • 56
  • 68