1

When I run a script with PDB, I find that I have to put for loops into one line to run correctly. When I try to nest for loops as shown below, I get a SyntaxError. How can I run nested for loops??

(pdb) for input in range(20): print input*2 0 2 4 ... 36 38 (pdb) for input in range(20): for output in range(10): print input*2 *** SyntaxError: invalid syntax(<stdin>, line 1) 
1

1 Answer 1

2

This does not have to do with pdb, but is just python (this fails in the normal python repl).

The grammar for a for statement is defined as:

for_stmt ::= "for" target_list "in" expression_list ":" suite ["else" ":" suite] 

where suite is either a list of simple statements or a newline and a list of statements. the for statment is a compound statement so it cannot be inlined like that.

Sign up to request clarification or add additional context in comments.

2 Comments

And I can't do newlines in PDB, so how do I iterate an operation over two variables in PDB?
run help commands in pdb, this is most likely the command you are looking for.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.