[Python-Dev] Dropping __init__.py requirement for subpackages

"Martin v. Löwis" martin at v.loewis.de
Wed Apr 26 22:17:58 CEST 2006


Phillip J. Eby wrote:
> At 11:50 AM 4/26/2006 -0700, Guido van Rossum wrote:
>> I'm not sure what you mean by "one directory read". You'd have to list
>> the entire directory, which may require reading more than one block if
>> the directory is large.
>> You have to do this to find an __init__.py too, don't you? Technically, 
> there's going to be a search for a .pyc or .pyo first, anyway.

No. Python does stat(2) and open(2) to determine whether a file is
present in a directory. Whether or not that causes a full directory
scan depends on the operating system. On most operating systems,
it is *not* a full directory scan:
- on network file systems, the directory is read only on the
 server; a full directory read would also cause a network
 transmission of the entire directory contents
- on an advanced filesystem (such as NTFS), a lookup operation
 is a search in a balanced tree, rather than a linear search,
 bypassing many directory blocks for a large directory
- on an advanced operating system (such as Linux), a repeated
 directory lookup for the file will not go to the file
 system each time, but cache the result of the lookup in
 an efficient memory structure.
In all cases, the directory contents (whether read from disk
into memory or not) does not have to be copied into python's
address space for stat(2), but does for readdir(3).
Regards,
Martin


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /