IndentationError: unexpected indent after comment
Question:
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):
Answers:
Did you try this?
user_by_email = session.query(User).
filter(Address.email=='one').
#options(joinedload(User.addresses)).
first()
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))
Enclose the statement in parentheses.
user_by_email = (session.query(User)
.filter(Address.email=='one')
#.options(joinedload(User.addresses))
.first())
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):
Did you try this?
user_by_email = session.query(User).
filter(Address.email=='one').
#options(joinedload(User.addresses)).
first()
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))
Enclose the statement in parentheses.
user_by_email = (session.query(User)
.filter(Address.email=='one')
#.options(joinedload(User.addresses))
.first())