Re: process command line parameter

2009-01-18 Thread Thorsten Kampe
* asit (Sat, 17 Jan 2009 13:28:12 -0800 (PST))
 Recently I was coding a link extractor. It's a command line stuff and
 takes parameter as argument.
 I found that the in operator is not always helpful.
 eg. if --all in sys.argv:
print all links will be printed
 
 its not helpful when some attribute value is sent in command line
 parameter.
 hence I want to process some data like find=.co.uk
 
 How can i do this ???

Use optparse
--
http://mail.python.org/mailman/listinfo/python-list


Re: process command line parameter

2009-01-17 Thread Cameron Simpson
On 17Jan2009 13:28, asit lipu...@gmail.com wrote:
| Recently I was coding a link extractor. It's a command line stuff and
| takes parameter as argument.
| I found that the in operator is not always helpful.
| eg. if --all in sys.argv:
|print all links will be printed

Indeed. While I can't speak for your particular app, usually command
line parameters are context sensitive. Therefore one normally processes
them in order (especially if you want to support the fairly normal --
option which means no more options after this, useful if you need to
supply a filename called --app).

If you dont want to use the getopt standard module and thus its
conventionaly argument syntax, then one alternative is like this:

| its not helpful when some attribute value is sent in command line
| parameter.
| hence I want to process some data like find=.co.uk

  all_links=False
  find=None
  for arg in sys.argv[1:]:
if arg == --:
  break
elif arg ==--all:
  all_links=True
elif arg.startswith(find=):
  find=arg[5:]
else:
  # unhandled argument: complain or drop out of loop

Cheers,
-- 
Cameron Simpson c...@zip.com.au DoD#743
http://www.cskk.ezoshosting.com/cs/
--
http://mail.python.org/mailman/listinfo/python-list