Python command line argument semicolon-loop error

后端 未结 4 2055
猫巷女王i
猫巷女王i 2020-12-10 17:56

I was trying out python -mtimeitso I put python -mtimeit \"n = 0; while n < 10: pass\" Then an invalid syntax error showed up. same with semicol

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 18:18

    timeit can take two parameters: the setup code and the code to time.

    python -mtimeit "n = 0" "while n < 10: pass"
    

    Also, you should change that pass to n += 1 or you'll be in an infinite loop.

提交回复
热议问题