Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using "from" as a script argument in Python

Tags:

python

My assignment requires that "from" be used as an argument for the command line input.

p = optparse.OptionParser()
p.add_option("--from")
p.add_option("--to")
p.add_option("--file", default="carla_coder.ics")
options, arguments = p.parse_args()

print options.from

obviously, "from" is a Python keyword... is there any way to get around this? Basically, the script should be run using file.py --from=dd/mm/yyyy --to=dd/mm/yyyy --file=file

like image 606
Tyler Sebastian Avatar asked Nov 21 '25 01:11

Tyler Sebastian


1 Answers

Use the dest attribute to specify a name:

p.add_option("--from", dest="foo")

print options.foo
like image 159
lc. Avatar answered Nov 24 '25 23:11

lc.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!