[英]How to solve “IndentationError: expected an indented block” in Jupyter when importing a module?
I'm quite new to Python and Jupyter Notebook and I'm running into some issues.我对 Python 和 Jupyter Notebook 很陌生,遇到了一些问题。 Yesterday, I created a "toolkit" which I named "edhec_risk_kit" and it contains all the functions which I wish to call when working on a new project.昨天,我创建了一个名为“edhec_risk_kit”的“工具包”,它包含了我在处理新项目时希望调用的所有函数。 The location of the file is:该文件的位置是:
"/Users/MyName/Intro to Ptf.construction and Analysis with Python/edhec_risk_kit.py" “/Users/MyName/Ptf.construction and Analysis with Python/edhec_risk_kit.py 简介”
Now I'm trying to "import" the toolkit to be Jupyter Notebook but I get the following error message:现在我正在尝试将工具包“导入”为 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
What am I doing wrong?我究竟做错了什么? I was able to import the "toolkit" last night but now I only get the error message昨晚我能够导入“工具包”,但现在我只收到错误消息
Check line 123 of your toolkit file.检查工具包文件的第 123 行。
File "/Users/MyName/Intro to Ptf.construction and Analysis with Python/edhec_risk_kit.py", line 123
'''
^
IndentationError: expected an indented block
I agree with the other answer (and I upvoted it), plus notice that you need to be careful with using '''
, its indentation level needs to be the same as the a normal new line of code (unlike #
, which you can insert at any position)我同意另一个答案(我赞成),另外请注意您需要小心使用'''
,它的缩进级别需要与正常的新代码行相同(与#
不同,您可以插入任意位置)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.