[Tutor] puzzled by modes in os.mkdir()
Brian van den Broek
bvande at po-box.mcgill.ca
Mon Apr 5 18:59:39 EDT 2004
Hi all,
I've made my first foray into the Library Reference, and I am a
bit confused.
I am using Python 2.3.3 on WinMe.
What I am doing is creating a function that asks the user to input
a directory name, checks such a directory exists, and if not, asks
if one should be created. (I haven't checked if such a function is
readily available; at my stage of learning, reinventing the wheel
for simple things seems worth doing for the learning.) All is good
until the creation part.
I thought I should use os.mkdir( path[, mode]) for the creation.
It takes an optional mode argument. Reading the Library Reference
on this function (in section 6.1.4) it says:
mkdir( path[, mode])
Create a directory named path with numeric mode mode. The default
mode is 0777 (octal). On some systems, mode is ignored. Where it
is used, the current umask value is first masked out.
Availability: Macintosh, Unix, Windows.
This is opaque to me, I am afraid.
Here are my questions:
1) Are the modes here referred to the same ones as it the stat
module? They don't seem to me to be, but the description of
os.cmod(path, mode) references stat and nothing else.
2) Either way, I'd appreciate a pointer on what to read so that I
can understand the Lib Ref's description of mkdir. (I don't know
what is going on well enough to do a fruitful google-search.) In
particular, I need to know what "0777 octal" means. (Knowing about
the other options would be nice, too.)
3) I assume nothing will go wrong if I create a directory using
the default mode argument for mkdir. Is this correct? I am going
to keep going without knowing, but would want to be sure before I
used my function for anything that matters.
4) What is the preferred syntax in postings, etc., for referring
to functions that require arguments? "mkdir()" seems misleading in
suggesting that it can be called with zero arguments,
"mkdir(path)" seems too verbose.
Thanks and best,
Brian vdB
More information about the Tutor
mailing list