9

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

Chris_Rands
  • 38,994
  • 14
  • 83
  • 119
Ray Hulha
  • 10,701
  • 5
  • 53
  • 53

3 Answers3

5

Enclose the statement in parentheses.

user_by_email = (session.query(User)
     .filter(Address.email=='one')
     #.options(joinedload(User.addresses))
     .first())
Sreyas
  • 461
  • 3
  • 15
1

Essentially its the same line , thats how Python interpreter reads it.

Just like you can not comment just a word in line of code. (Below)

Not allowed

user_by_email = session.query(User).filter(Address.email=='one')#comment#.first()

You need to move the comment to the end of the line.

user_by_email = session.query(User)\
    .filter(Address.email=='one')\
    .first()
#.options(joinedload(User.addresses))\
Morse
  • 8,258
  • 7
  • 39
  • 64
0

Did you try this?

user_by_email = session.query(User).\
filter(Address.email=='one').\
#options(joinedload(User.addresses)).\
first()
Vasily Bronsky
  • 435
  • 2
  • 12