fs.mode¶
Tools for managing mode strings (as used in open()
and
openbin()
).
-
class
fs.mode.
Mode
(mode)¶ A mode object provides properties that can be used to interrogate the mode strings used when opening files.
参数: mode (str) – A mode string, as used by io.open
.引发: ValueError – If the mode string is invalid. Here’s an example of typical use:
>>> mode = Mode('rb') >>> mode.reading True >>> mode.writing False >>> mode.binary True >>> mode.text False
-
appending
¶ Check if a mode permits appending.
-
binary
¶ Check if a mode specifies binary.
-
create
¶ Check if the mode would create a file.
-
exclusive
¶ Check if the mode require exclusive creation.
-
reading
¶ Check if the mode permits reading.
-
text
¶ Check if a mode specifies text.
-
to_platform
()¶ Get a mode string for the current platform.
Currently, this just removes the ‘x’ on PY2 because PY2 doesn’t support exclusive mode.
-
to_platform_bin
()¶ Get a binary mode string for the current platform.
Currently, this just removes the ‘x’ on PY2 because PY2 doesn’t support exclusive mode.
-
truncate
¶ Check if a mode would truncate an existing file.
-
updating
¶ Check if a mode permits updating (reading and writing).
-
validate
(_valid_chars=frozenset({'a', 't', '+', 'r', 'w', 'x', 'b'}))¶ Validate the mode string.
引发: ValueError – if the mode contains invalid chars.
-
validate_bin
()¶ Validate a mode for opening a binary file.
引发: ValueError – if the mode contains invalid chars.
-
writing
¶ Check if a mode permits writing.
-
-
fs.mode.
check_readable
(mode)¶ Check a mode string allows reading.
参数: mode (str) – A mode string, e.g. "rt"
返回类型: bool
-
fs.mode.
check_writable
(mode)¶ Check a mode string allows writing.
参数: mode (str) – A mode string, e.g. "wt"
返回类型: bool