How to pass in command line arguments when using ideone?

前端 未结 2 2094
陌清茗
陌清茗 2021-02-13 07:36

I\'m using the ideone online interpreter (http://ideone.com/) to test some C++ and Python programs. How do I specify the command line arguments instead of using the STDIN input?

2条回答
  •  醉酒成梦
    2021-02-13 07:44

    In python you can hardcode like this:

    import sys
    
    print sys.argv
    sys.argv[1:] = ["test1", "test2"]
    print sys.argv
    

    This will output:

    ['prog.py']
    ['prog.py', 'test1', 'test2']
    

    To read from stdin:

    import sys
    import shlex
    
    print sys.argv
    sys.argv[1:] = shlex.split(None)
    print sys.argv
    

提交回复
热议问题