How to pass in command line arguments when using ideone?

前端 未结 3 523
轻奢々
轻奢々 2021-02-13 07:25

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?

3条回答
  •  Happy的楠姐
    2021-02-13 07:58

    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
    

提交回复
热议问题