Search code examples
pythonpython-2.7indentation

IndentationError: unexpected indent after comment


I am trying to write some Python example code with a line commented out:

user_by_email = session.query(User)\
    .filter(Address.email=='one')\
    #.options(joinedload(User.addresses))\
    .first()

I also tried:

user_by_email = session.query(User)\
    .filter(Address.email=='one')\
#    .options(joinedload(User.addresses))\
    .first()

But I get IndentationError: unexpected indent. If I remove the commented out line, the code works. I am decently sure that I use only spaces (Notepad++ screenshot):

enter image description here


Solution

  • Enclose the statement in parentheses.

    user_by_email = (session.query(User)
         .filter(Address.email=='one')
         #.options(joinedload(User.addresses))
         .first())