[英]python: can't open file 'Functions.py': [Errno 2
I am trying to run my sample code containing functions but get the following error when running from the command line. 我试图运行包含函数的示例代码,但是从命令行运行时出现以下错误。
python: can't open file 'Functions.py': [Errno 2
python:无法打开文件“ Functions.py”:[Errno 2
I have checked my environment variables and also reviewed my code. 我检查了我的环境变量,并查看了我的代码。 I am currently using JetBrains Pycharm 2018.3.2 version, could this be the issue?
我当前正在使用JetBrains Pycharm 2018.3.2版本,这可能是问题吗?
Based on your comments, your code should be like this: 根据您的评论,您的代码应如下所示:
def My1st():
firstVar = 1
secondVar = 2
result = firstVar + secondVar
print("The result is ", result)
if __name__ == '__main__':
My1st()
Notice the concatenation in the print
statement and the name attribute. 请注意
print
语句和name属性中的串联。 and then if you're on windows(as it looks like you are), 然后如果您在Windows上(看起来像您一样),
py Functions.py
should give you the output: 3 应该给你输出:3
Errno 2
points out at a file or directory not being found (in this case 'Functions.py'). Errno 2
指出未找到文件或目录(在本例中为“ Functions.py”)。 Could you check whether your path to Functions.py is correct? 您能否检查您到Functions.py的路径是否正确?
there was an error in below line of your code 您的代码下面的行有错误
print("The result is " + result)
print(“结果为” +结果)
the problem is that you can't concatenate string with int value 问题是你不能用int值连接字符串
and also i am not able to understand you problem but below are some code that you may want from your problem statement. 而且我也无法理解您的问题,但是下面是您可能希望从问题陈述中得到的一些代码。
def My1st():
firstVar = 1
secondVar = 2
result = firstVar + secondVar
print("The result is ", result)
if __name__ == "__main__" :
My1st()
OR 要么
def My1st():
firstVar = 1
secondVar = 2
result = firstVar + secondVar
print("The result is ", result)
My1st()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.