8

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

Saher Ahwal
  • 9,015
  • 32
  • 84
  • 152
  • 5
    I don't understand why people insist on thinking that IDLE is something useful. – Ignacio Vazquez-Abrams Feb 02 '11 at 00:17
  • Please, you can give me suggestions on an IDE that you think is useful for windows. I would appreciate that – Saher Ahwal Feb 02 '11 at 00:20
  • You don't pass arguments in IDLE at run time. It's easy to simply type your command at the command line. What stops you from tying `python xxxxxx.py filename1 filename2` at the command line? Or copying and pasting it at the command line? Or using up-arrow to type it again at the command line? – S.Lott Feb 02 '11 at 02:21
  • @S.Lott how does one debug with breakpoints from the command line? With IDLE you can do that easily – sgarg Mar 22 '14 at 22:49
  • @Ignacio Vazquez-Abrams: I can't tell for everyone, but to me the main reason is that IDLE is accessible virtually everywhere. This would be my tool of choice to quickly illustrate/present the Python code snippet to someone else. I saw it being used for this very purpose at "PyCons". – Nikita Vorontsov Apr 01 '14 at 21:57
  • As of 3.7.4 and 3.8.0b2, use Run ... Customized on the Run menu. – Terry Jan Reedy Jul 21 '19 at 20:43

2 Answers2

6

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.

Michael Aaron Safyan
  • 93,612
  • 16
  • 138
  • 200
4

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

cjones26
  • 3,459
  • 1
  • 34
  • 51