简体   繁体   English

python:无法打开文件“ Functions.py”:[Errno 2

[英]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.

相关问题 找不到 >python scraper.py - 无法打开文件“scraper.py”:[Errno 2] 没有这样的文件或目录 - Cant find >python scraper.py - can't open file 'scraper.py': [Errno 2] No such file or directory PyCharm 没有找到 Anaconda Python,给出“无法打开文件 'python.py':[Errno 2] 没有这样的文件或目录?” - PyCharm not finding Anaconda Python, giving “can't open file 'python.py': [Errno 2] No such file or directory?” 无法打开文件'file.py':[Errno 2] 没有这样的文件或目录 - Can't open file 'file.py': [Errno 2] No such file or directory python:无法打开文件'python DACscrap.py&':[Errno 2]没有这样的文件或目录…但是可以吗? - python: can't open file 'python DACscrap.py &': [Errno 2] No such file or directory… but it does? python:无法打开文件“lanes.py”:[Errno 2] 没有这样的文件或目录 - python: can't open file 'lanes.py': [Errno 2] No such file or directory python:无法打开文件“manage.py”:[Errno 2] 没有这样的文件或目录 docker-compose run - python: can't open file 'manage.py': [Errno 2] No such file or directory docker-compose run python:无法打开文件“.manage.py”:[Errno 2] 没有这样的文件或目录 - python: can't open file '.manage.py': [Errno 2] No such file or directory Docker compose - python:无法打开文件“manage.py”:[Errno 2] 没有这样的文件或目录 - Docker compose - python: can't open file 'manage.py': [Errno 2] No such file or directory python:无法打开文件“django-admin.py”:[Errno 2] 没有那个文件或目录 - python: can't open file 'django-admin.py': [Errno 2] No such file or directory docker-web-1 | python:无法打开文件'/code/manage.py':[Errno 2] 没有那个文件或目录 - docker-web-1 | python: can't open file '/code/manage.py': [Errno 2] No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM