[英]Importing a function from a .py file
I work in a.ipybn file, but i want to import a function from a.py file.我在 a.ipybn 文件中工作,但我想从 a.py 文件中导入 function。
My code is:我的代码是:
from function1 import my_function
However, I get the following error:但是,我收到以下错误:
SyntaxError: unexpected EOF while parsing
How can I fix this?我怎样才能解决这个问题? Ps the files are in the same folder.
ps文件在同一个文件夹中。
unexpected EOF while parsing
解析时意外的 EOF
It was able to open the file, but not parse the content correctly.它能够打开文件,但无法正确解析内容。 I would start by checking indentations (spaces vs tabs, # of spaces), quotes, colons.
我会首先检查缩进(空格与制表符,空格数)、引号、冒号。
Something to try is executing python from the command line and importing there.可以尝试从命令行执行 python 并在那里导入。 That will eliminate iPython/Jupyter notebook as a variable.
这将消除 iPython/Jupyter notebook 作为变量。
You get the error when the file's source code ended before all the blocks in it are completed.当文件的源代码在其中的所有块完成之前结束时,您会收到错误消息。 For example, if in your file is:
例如,如果在您的文件中是:
a = input("> ")
if a == 'yes':
print("hello")
As you can see, you tell the program to proceed to print before the if statement is completed.如您所见,您告诉程序在 if 语句完成之前继续打印。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.