0

I have this:

drwxr-xr-x 8 abc root 4096 Dec 21 19:56 javaprac

This works:

>>> fd = os.open(os.getcwd() , os.O_RDONLY)

But why do these two fail:

>>> fd = os.open(os.getcwd() , os.O_RDWR)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 21] Is a directory: '/home/abc/javaprac'

>>> fd = os.open(os.getcwd() , os.O_WRONLY)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 21] Is a directory: '/home/abc/javaprac'
2
  • 6
    Why do you want to write directly to the directory node? What are you trying to do here? Commented Dec 22, 2013 at 4:09
  • @MartijnPieters My question is simple and direct with no deeper meaning: Why can't I write to a directory like this ? Why is the behavior the way it is? Commented Dec 22, 2013 at 5:22

1 Answer 1

2

On Linux, at least, you cannot write to a directory.

$ echo hello >> .
bash: .: Is a directory

You can read from a directory, that what the ls and dir commands do.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.