![](/img/trans.png)
[英]Error in Jupyter notebook “IndentationError: expected an indented block”
[英]How to solve “IndentationError: expected an indented block” in Jupyter when importing a module?
我对 Python 和 Jupyter Notebook 很陌生,遇到了一些问题。 昨天,我创建了一个名为“edhec_risk_kit”的“工具包”,它包含了我在处理新项目时希望调用的所有函数。 该文件的位置是:
“/Users/MyName/Ptf.construction and Analysis with Python/edhec_risk_kit.py 简介”
现在我正在尝试将工具包“导入”为 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
我究竟做错了什么? 昨晚我能够导入“工具包”,但现在我只收到错误消息
检查工具包文件的第 123 行。
File "/Users/MyName/Intro to Ptf.construction and Analysis with Python/edhec_risk_kit.py", line 123
'''
^
IndentationError: expected an indented block
我同意另一个答案(我赞成),另外请注意您需要小心使用'''
,它的缩进级别需要与正常的新代码行相同(与#
不同,您可以插入任意位置)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.