When running a python script in IDLE, is there a way to pass in command line arguments (args)?

前端 未结 11 839
猫巷女王i
猫巷女王i 2020-12-02 13:08

I\'m testing some python code that parses command line input. Is there a way to pass this input in through IDLE? Currently I\'m saving in the IDLE editor and running from a

11条回答
  •  孤城傲影
    2020-12-02 13:58

    Auto-detect IDLE and Prompt for Command-line Arguments

    #! /usr/bin/env python3
    
    import sys
    
    # Prompt user for (optional) command line arguments, when run from IDLE:
    if 'idlelib' in sys.modules: sys.argv.extend(input("Args: ").split())
    


    Change "input" to "raw_input" for Python2.

提交回复
热议问题