Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 Windows 的 IDLE 中运行带有命令行参数的脚本:
import sys print('The command line arguments are:') for i in sys.argv: print(i)
IDLE 似乎没有提供通过 GUI 执行此操作的方法,但您可以执行以下操作:
if __name__ == '__main__':在您拦截命令行参数的地方模拟它们。
if __name__ == '__main__':
try: __file__ except: sys.argv = [sys.argv[0], 'argument1', 'argument2', 'argument2']
你也可以试试,
idle.py -r scriptname.py arg1 arg2 arg3