15

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.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
Manthan Sharma
  • 329
  • 1
  • 3
  • 12
  • 1
    To expand vaultahs comment: You might have an own file called `os.py` which shadows the built-in package. – Matthias Sep 21 '15 at 09:48
  • Hmm - a guess - are you on Windows...? As you're talking about `os` calls, The Operating System you're working on is essential information... – J Richard Snape Sep 21 '15 at 10:11
  • 2
    Why are you trying to create a filesystem node without specifying a name? – PM 2Ring Sep 21 '15 at 10:24
  • first: you must have `os.py` in your path that shadows builtin module; second: why you are using mknod for the file? use `open`; third mknod without parameters? and what is this semicolon at the end? ;) – Jerzyk Jul 01 '16 at 10:41

1 Answers1

9

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.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253