I'd like to do something like:
% python foo bar
import sys
sys.argv
to get:
% ['foo', 'bar']
but of course python dies when you enter an argument which is not a script or goes into non interactive mode if you do.
Can I do this somehow?
Use -
as script name:
python - foo bar
Test:
>>> import sys
>>> sys.argv
['-', 'foo', 'bar']
$ python - asdf asdf
Python 2.7.6 (default, Feb 15 2014, 23:06:13)
[GCC 4.8.2 20140206 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.argv
['-', 'asdf', 'asdf']
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With