python - 缩进错误 : unexpected indent after comment

标签 python python-2.7 indentation

<分区>

我正在尝试编写一些注释掉一行的 Python 示例代码:

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

我也试过:

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

但我得到 IndentationError:意外缩进。 如果我删除注释掉的行,代码就可以工作。 我非常确定我只使用空格(Notepad++ 屏幕截图):

enter image description here

最佳答案

将语句放在括号中

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

关于python - 缩进错误 : unexpected indent after comment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50722329/

相关文章:

python - Python 中的链式比较数字范围

python - 如何在没有换行的情况下在 Python 2.7 中打印而无需缓冲

python - kafka-python 引发 kafka.errors.ConsumerFetchSizeTooSmall

c# - 如何在数组初始化时自动格式化代码?

python - 使用 Python 正则表达式从文本中提取信息

python - 如何检查JSON数据的完整性

python - 具有不同数量参数的抽象类

python - urllib2 中的未知 url 类型错误

emacs - 凸轮模式是否缩进注释?

jasper-reports - 使用 JasperReports 在生成的 PDF 中缩进