手机网站设计背景图片,企业信息查询系统官网湖北,网站开发微博,企装网怎么样解决#xff1a;AttributeError: module ‘os’ has no attribute ‘mknod’ 文章目录 解决#xff1a;AttributeError: module os has no attribute mknod背景报错问题报错翻译报错位置代码报错原因解决方法今天的分享就到此结束了 背景 在使用之前的代码时#xff0c;报错…解决AttributeError: module ‘os’ has no attribute ‘mknod’ 文章目录 解决AttributeError: module os has no attribute mknod背景报错问题报错翻译报错位置代码报错原因解决方法今天的分享就到此结束了 背景 在使用之前的代码时报错 os.mknod(rC:\learn\test.txt) AttributeError: module ‘os’ has no attribute ‘mknod’ 注该代码在Ubuntu 系统上没有问题在windows 上出现的这个错误 报错问题
os.mknod(rC:\learn\test.txt)
AttributeError: module os has no attribute mknod
截图如下 报错翻译
主要报错信息内容翻译如下所示
os.mknod(rC:\learn\test.txt)
AttributeError: module os has no attribute mknod
翻译 os.mknod(rC:\learn\test.txt)
AttributeError模块“os”没有属性“mknod”报错位置代码
...os.mknod(rC:\learn\test.txt)... 报错原因
经过查阅资料发现是在 windows 上面 不支持 mknod 所以需要使用 windows 支持的 open 创建文件。
小伙伴们按下面的解决方法即可解决 解决方法
要解决这个错误需要在创建文件使用 open open 支持打开文件没有文件的时候就创建文件 记得使用 w 也就是open(xxxx,w) 其中参数w 的意思是打开一个文件只用于写入。如果该文件已存在则打开文件并从开头开始编辑即原有内容会被删除。如果该文件不存在创建新文件。
正确的代码是 open(rC:\learn\test.txt,w)完整示例如下
# 导入os模块
import os# 使用os模块中的open函数创建新文件
with open(test.txt, w) as f:f.write(This is a new file.)# 输出文件创建成功的消息
print(文件test.txt已成功创建。) 今天的分享就到此结束了 欢迎点赞评论关注三连