问题描述
关于使用Python创建文件/目录的指南很多,只是说将mode
设置为0o777
或其他内容,但是每个字符的实际含义是什么?
例如,在official documentation for the os
python module中:
os.makedirs(name,mode =
0o777
,exist_ok = False)递归目录创建功能。类似于mkdir(),但是使所有中间级目录都包含叶子目录。
将模式参数传递给mkdir()来创建叶子目录;请参见
mkdir() description
了解其解释方式。
指向mkdir() description
的链接,说明:
os.mkdir(path,mode = 0o777,*,dir_fd = None)¶
Create a directory named path with numeric mode mode. If the directory already exists,FileExistsError is raised. On some systems,mode is ignored. Where it is used,the current umask value is first masked out. If bits other than the last 9 (i.e. the last 3 digits of the octal representation of the mode) are set,their meaning is platform-dependent. On some platforms,they are ignored and you should call chmod() explicitly to set them. This function can also support paths relative to directory descriptors. It is also possible to create temporary directories; see the tempfile module’s tempfile.mkdtemp() function. Raises an auditing event os.mkdir with arguments path,mode,dir_fd. New in version 3.3: The dir_fd argument. Changed in version 3.6: Accepts a path-like object.
...但是,这仍然没有定义0o777
的含义以及所有可能的选项。
实际上在哪里记录了所有平台上模式值的所有可能选项以及它们的含义?
编辑:起初我以为第一个零是setuid位(但是在它和其余权限之间混有这个奇怪的“ o”),但是现在我认为0o
只是紧随其后的八进制字符串的前缀。但是如果是这样的话,0o0754
是否在所有平台上都有效? 实际上在哪里记录?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)