Python module 'os' has no attribute 'mknod'

匿名 (未验证) 提交于 2019-12-03 08:44:33

问题:

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.

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!