Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4567)

Side by Side Diff: Doc/library/os.rst

Issue 15177: Support os.walk(dir_fd=) and os.fwalk(dir_fd=)
Patch Set: Created 10 months, 3 weeks ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/os.py » ('j') | Lib/os.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 :mod:`os` --- Miscellaneous operating system interfaces 1 :mod:`os` --- Miscellaneous operating system interfaces
2 ======================================================= 2 =======================================================
3 3
4 .. module:: os 4 .. module:: os
5 :synopsis: Miscellaneous operating system interfaces. 5 :synopsis: Miscellaneous operating system interfaces.
6 6
7 7
8 This module provides a portable way of using operating system dependent 8 This module provides a portable way of using operating system dependent
9 functionality. If you just want to read or write a file see :func:`open`, if 9 functionality. If you just want to read or write a file see :func:`open`, if
10 you want to manipulate paths, see the :mod:`os.path` module, and if you want to 10 you want to manipulate paths, see the :mod:`os.path` module, and if you want to
(...skipping 2190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2201 # CAUTION: This is dangerous! For example, if top == '/', it 2201 # CAUTION: This is dangerous! For example, if top == '/', it
2202 # could delete all your disk files. 2202 # could delete all your disk files.
2203 import os 2203 import os
2204 for root, dirs, files in os.walk(top, topdown=False): 2204 for root, dirs, files in os.walk(top, topdown=False):
2205 for name in files: 2205 for name in files:
2206 os.remove(os.path.join(root, name)) 2206 os.remove(os.path.join(root, name))
2207 for name in dirs: 2207 for name in dirs:
2208 os.rmdir(os.path.join(root, name)) 2208 os.rmdir(os.path.join(root, name))
2209 2209
2210 2210
2211 .. function:: fwalk(top, topdown=True, onerror=None, followlinks=False) 2211 .. function:: fwalk(top='.', topdown=True, onerror=None, followlinks=False, *, d ir_fd=None)
2212 2212
2213 .. index:: 2213 .. index::
2214 single: directory; walking 2214 single: directory; walking
2215 single: directory; traversal 2215 single: directory; traversal
2216 2216
2217 This behaves exactly like :func:`walk`, except that it yields a 4-tuple 2217 This behaves exactly like :func:`walk`, except that it yields a 4-tuple
2218 ``(dirpath, dirnames, filenames, dirfd)``. 2218 ``(dirpath, dirnames, filenames, dirfd)``, and it supports ``dir_fd``.
storchaka 2012/06/25 14:08:10 But walk also supports dir_fd.
larry 2012/06/25 15:04:13 Wishful thinking for now ;-) but, Done.
2219 2219
2220 *dirpath*, *dirnames* and *filenames* are identical to :func:`walk` output, 2220 *dirpath*, *dirnames* and *filenames* are identical to :func:`walk` output,
2221 and *dirfd* is a file descriptor referring to the directory *dirpath*. 2221 and *dirfd* is a file descriptor referring to the directory *dirpath*.
2222 2222
2223 This function always supports :ref:`paths relative to directory descriptors
2224 <dir_fd>`.
2225
2223 .. note:: 2226 .. note::
2224 2227
2225 Since :func:`fwalk` yields file descriptors, those are only valid until 2228 Since :func:`fwalk` yields file descriptors, those are only valid until
2226 the next iteration step, so you should duplicate them (e.g. with 2229 the next iteration step, so you should duplicate them (e.g. with
2227 :func:`dup`) if you want to keep them longer. 2230 :func:`dup`) if you want to keep them longer.
2228 2231
2229 This example displays the number of bytes taken by non-directory files in eac h 2232 This example displays the number of bytes taken by non-directory files in eac h
2230 directory under the starting directory, except that it doesn't look under any 2233 directory under the starting directory, except that it doesn't look under any
2231 CVS subdirectory:: 2234 CVS subdirectory::
2232 2235
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
3318 3321
3319 .. function:: urandom(n) 3322 .. function:: urandom(n)
3320 3323
3321 Return a string of *n* random bytes suitable for cryptographic use. 3324 Return a string of *n* random bytes suitable for cryptographic use.
3322 3325
3323 This function returns random bytes from an OS-specific randomness source. Th e 3326 This function returns random bytes from an OS-specific randomness source. Th e
3324 returned data should be unpredictable enough for cryptographic applications, 3327 returned data should be unpredictable enough for cryptographic applications,
3325 though its exact quality depends on the OS implementation. On a Unix-like 3328 though its exact quality depends on the OS implementation. On a Unix-like
3326 system this will query /dev/urandom, and on Windows it will use CryptGenRando m. 3329 system this will query /dev/urandom, and on Windows it will use CryptGenRando m.
3327 If a randomness source is not found, :exc:`NotImplementedError` will be raise d. 3330 If a randomness source is not found, :exc:`NotImplementedError` will be raise d.
OLDNEW
« no previous file with comments | « no previous file | Lib/os.py » ('j') | Lib/os.py » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7