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):
“IndentationError: unexpected indent” is raised when you indent a line of code too many times. To solve this error, make sure all of your code uses consistent indentation and that there are no unnecessary indents.
1. Unexpected indent - This line of code has more spaces at the beginning than the one before it, but the one before it does not begin a subblock. In a block, all lines of code must begin with the same string of whitespace.
Go to the setting of your code editor and enable the option which shows the tab and whitespaces. Once this feature in turned on, you will see small single dots in between your code, where each dot represents whitespace or a tab.
The Python “TabError: inconsistent use of tabs and spaces in indentation” error is raised when you try to indent code using both spaces and tabs. You fix this error by sticking to either spaces or tabs in a program and replacing any tabs or spaces that do not use your preferred method of indentation.
Enclose the statement in paranthesis
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))\
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With