Python模块'os'没有属性'mknod' [英] Python module 'os' has no attribute 'mknod'

查看:3815
本文介绍了Python模块'os'没有属性'mknod'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用mknod命令在Python中创建一个新文件,但出现错误:

os.mknod();
AttributeError: module 'os' has no attribute 'mknod'

我正在使用Windows,并且'mknod'以外的属性都在起作用.

解决方案

os提供与您所使用的操作系统密切相关的功能.如果可以从os访问大多数其他属性(这意味着当前目录中没有os.py文件掩盖了标准模块),则AttributeError将99%表示您的操作系统不支持该功能. >

在Windows上使用os.mknod就是这种情况.据我了解,在Windows中创建命名管道具有非常不同的语义

无论哪种方式,如果您尝试使用mknod创建命名管道,则最好使用 mkfifo() (同样,仅支持Unix).如果要使用它创建普通文件,请不要使用可移植的open().

I want to create a new file in Python for that I am using mknod command, but getting error as:

os.mknod();
AttributeError: module 'os' has no attribute 'mknod'

I am using windows and attributes other than 'mknod' are working.

解决方案

os offers functionality that is closely related to the OS you're using. If most other attributes can be accessed from os (meaning you haven't got a os.py file in the current dir masking the standard module) an AttributeError will 99% signal an unsupported function on your Operating System.

This is what the case is with os.mknod on Windows. Creating named pipes in Windows has, as far as I can understand, very different semantics.

Either way, if you are trying to use mknod to create named pipes you'd probably be better using mkfifo() (again, only Unix supported) . If you're using it to create ordinary files, don't, use open() which is portable.

这篇关于Python模块'os'没有属性'mknod'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆