I have downloaded a python file xxxxxx.py that is supposed to run on the command line by
typing: python xxxxxx.py filename1 filename2
and that should take these two files as arguments.
I was wondering if there is a way I can use IDLE to pass in these arguments. Is there a way other than setting sys.argv
?
Thanks
It depends on the content of your Python file. If it is well-written, like:
#! /usr/bin/env python
def process(files):
for file in files:
# ...
if __name__ == '__main__'
# some error checking on sys.argv
process(sys.argv[1:])
sys.exit(0)
Then you could simply import the python file and run it like:
import name_of_file
# ...
name_of_file.process([file1, file2, file3])
# ...
So, it really depends on how it is written. If it isn't written well but you can edit it, I would refactor it so that it can be used as a library; otherwise, I would use the subprocess module to invoke the program.
You can do this from the command line with:
idle.py -r scriptname.py put arguments here
You can try a different IDE like ActivePython
Or you can patch IDLE:
http://bugs.python.org/issue5680
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