bash - Python command line argument semicolon-loop error -
first, noticed python , semicolon in title , want furiously bash me up, deeply apologize, , in command mode
i trying out python -mtimeit
so put python -mtimeit "n = 0; while n < 10: pass"
invalid syntax error showed up. same semicolon , loop.
however, when try semicolon , loop individually. both worked fine.
python -c "for in range(10): print(n)" python -c "n = 1; n = 2; print(n)"
why , how can test while loop in timeit? thank much!
while
, for
can't have semicolon before, need on 1 line. if looked @ python grammar:
compound_stmt ::= if_stmt | while_stmt | for_stmt | try_stmt | with_stmt | funcdef | classdef | decorated suite ::= stmt_list newline | newline indent statement+ dedent statement ::= stmt_list newline | compound_stmt stmt_list ::= simple_stmt (";" simple_stmt)* [";"]
you see statements part of compound_stmt
need 1 one line alone. statements can separated semicolon simple_stmt
group:
simple_stmt ::= expression_stmt | assert_stmt | assignment_stmt | augmented_assignment_stmt | pass_stmt | del_stmt | print_stmt | return_stmt | yield_stmt | raise_stmt | break_stmt | continue_stmt | import_stmt | global_stmt | exec_stmt
Comments
Post a Comment