Hi everyone,

Just wondering if anyone could help. At the minute I need to check a command line for the parameter "--date=something", I've been using the re module with python like this

cmd = "python myapp.py --name=stephen --date=20120323 --test=testthis"
found = re.split (r"--date.*", cmd)
print found

but this prints the entire string if it matches, or "None" if not found - how would I get it to print the "--date=20120323" part and nothing else? Or is this not possible?

Many thanks in advance,
Stephen

You are looking for wrong tool, you should use http://docs.python.org/library/optparse.html or preferably the new http://docs.python.org/library/argparse.html#module-argparse for parameter aquisition.

That said it is easy to just iterate over the parameters and check which starts right way:

>>> print next(p for p in cmd.split() if p.startswith('--date'))
--date=20120323
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.