[Tutor] Permissions oddness

Michael P. Reilly arcege@speakeasy.net
Sun, 13 Jan 2002 21:13:15 -0500


On Sun, Jan 13, 2002 at 08:14:18PM -0500, dman wrote:
> For directories :
>     Read means you can list the contents.
>     Write means you can modify the contents.
>     Execute means you can 'cd' to the directory.

FYI, the execute bit on a directory means more than just 'can you cd'.
It allows a program to traverse into the directory to open files.
Try this:

import os
os.mkdir('trythis', 0777)
open('trythis/test.txt', 'w').write('hi there\n')

os.chmod('trythis', 0666)
f = open('trythis/test.txt', 'r')

At this point, you'll get an exception of "Permission denied".  We're not
changing the current directory, just trying to access a file in it.

  -Arcege