#๐Ÿ”’ indentation error

10 messages ยท Page 1 of 1 (latest)

paper forge
#

hi guys. i am struggling to indent the print line in my command window in the flask shell please let me know what i might be doing wrong ">>> from sqlalchemy import text

with db.engine.connect() as connection:
... result = connection.execute(text("SELECT 1"))
... print(result.scalar()) "

plucky terraceBOT
#

@paper forge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

mighty copper
#

!traceback

plucky terraceBOT
#
Traceback

Please provide the full traceback for your exception in order to help us identify your issue.
While the last line of the error message tells us what kind of error you got,
the full traceback will tell us which line, and other critical information to solve your problem.
Please avoid screenshots so we can copy and paste parts of the message.

A full traceback could look like:

Traceback (most recent call last):
  File "my_file.py", line 5, in <module>
    add_three("6")
  File "my_file.py", line 2, in add_three
    a = num + 3
        ~~~~^~~
TypeError: can only concatenate str (not "int") to str

If the traceback is long, use our pastebin.

tough blade
#

The >>> and ... suggest you're in repl. If you want to return to no-indent level, you gotta hit enter twice, to exit the multiline continuation mode (which ... means)

#

!repl

plucky terraceBOT
#
Read-Eval-Print Loop (REPL)

A REPL is an interactive shell where you can execute individual lines of code one at a time, like so:

>>> x = 5
>>> x + 2
7
>>> for i in range(3):
...     print(i)
...
0
1
2
>>>

To enter the REPL, run python (py on Windows) in the command line without any arguments. The >>> or ... at the start of some lines are prompts to enter code, and indicate that you are in the Python REPL. Any other lines show the output of the code.

Trying to execute commands for the command-line (such as pip install xyz) in the REPL will throw an error. To run these commands, exit the REPL first by running exit() and then run the original command.

tough blade
#
>>> if True: # starting a block                 
...   a=1 # <- the prompt at the beginning of thd line changes and i gotta put indented lines here
... b=1 # if i write something without the indent...
  File "<stdin>", line 5
    b=1 # if i write something without the indent...
    ^
SyntaxError: invalid syntax
>>>
>>> # to do it properly, you gotta hit enter twice to exit the '...'
>>> if True:
...   a=1
...
>>> b=1 # after hitting enter twice, we get back to normal mode and can run code without error
>>>
plucky terraceBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.