简体   繁体   English

Python - FileNotFoundError:[Errno 2] 在 Linux 中使用“w+”写入文件时

[英]Python - FileNotFoundError: [Errno 2] when writing to file with 'w+' in Linux

My program works perfectly on Windows but I'm trying to use it on Linux now and the same code produces a "file not found" error even though I am using 'w+'.我的程序在 Windows 上运行良好,但我现在尝试在 Linux 上使用它,即使我使用的是“w+”,同样的代码也会产生“找不到文件”错误。 I tried我试过

chmod -R 777 program_directory chmod -R 777 程序目录

to no avail.无济于事。 I am completely new to Linux so I have no idea what to try next.我对 Linux 完全陌生,所以我不知道接下来要尝试什么。

Thanks a lot!非常感谢!

Oh wow.哇哦。 Linux paths are case sensitive. Linux 路径区分大小写。 Sorry about that, I didn't know.对不起,我不知道。 Thanks for all the help!感谢所有的帮助!

Following are ways to execute python programs in linux:以下是在linux中执行python程序的方法:

chmod +x codefile.py #Assigns permission to execute
./codefile.py  #executes

or或者

python code.py #executes

if you intend to invoke a particular python environment then:如果您打算调用特定的 python 环境,则:

python3 code.py

or或者

python #activates python session
import code #will import the functions and instructions of code.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM