导入模块时,如何在Jupyter中解决“ IndentationError:预期为缩进块?”

问题描述 投票:0回答:2

我是Python和Jupyter Notebook的新手,我遇到了一些问题。昨天,我创建了一个名为“ edhec_risk_kit”的“工具箱”,其中包含在开发新项目时希望调用的所有功能。该文件的位置是:

“ / Users / MyName /使用Python / edhec_risk_kit.py介绍Ptf.construction和分析。

现在我正尝试将工具箱“导入”为Jupyter Notebook,但出现以下错误消息:

Traceback (most recent call last):

  File "/Users/MyName/opt/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3331, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-1-d8b39bc3a411>", line 1, in <module>
    import edhec_risk_kit as RiskKit

  File "/Users/MyName/Intro to Ptf.construction and Analysis with Python/edhec_risk_kit.py", line 123
    '''

^
IndentationError: expected an indented block

我在做什么错?昨晚我可以导入“工具包”,但现在我只收到错误消息

python python-3.x jupyter-notebook indentation
2个回答
1
投票

检查工具包文件的第123行。

  File "/Users/MyName/Intro to Ptf.construction and Analysis with Python/edhec_risk_kit.py", line 123
    '''

^
IndentationError: expected an indented block

0
投票

我同意另一个答案(我赞成),另外请注意,使用'''需要小心,其缩进级别必须与普通的新代码行相同(与#不同,您可以将其插入任何位置)

© www.soinside.com 2019 - 2024. All rights reserved.