Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
76e55387
Commit
76e55387
authored
Oct 08, 2008
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some more notes about bytes/string filename APIs.
parent
bcbfa645
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
22 deletions
+34
-22
Doc/library/functions.rst
Doc/library/functions.rst
+5
-6
Doc/library/os.path.rst
Doc/library/os.path.rst
+6
-0
Doc/library/os.rst
Doc/library/os.rst
+23
-16
No files found.
Doc/library/functions.rst
View file @
76e55387
...
@@ -710,12 +710,11 @@ are always available. They are listed here in alphabetical order.
...
@@ -710,12 +710,11 @@ are always available. They are listed here in alphabetical order.
Open
a
file
.
If
the
file
cannot
be
opened
,
:
exc
:`
IOError
`
is
raised
.
Open
a
file
.
If
the
file
cannot
be
opened
,
:
exc
:`
IOError
`
is
raised
.
*
file
*
is
either
a
string
or
bytes
object
giving
the
name
(
and
the
*
file
*
is
either
a
string
or
bytes
object
giving
the
name
(
and
the
path
if
path
if
the
file
isn
't in the current working directory) of the
the
file
isn
't in the current working directory) of the file to be opened or
file to be opened or an integer file descriptor of the file to be
an integer file descriptor of the file to be wrapped. (If a file descriptor
wrapped. (If a file descriptor is given, it is closed when the
is given, it is closed when the returned I/O object is closed, unless
returned I/O object is closed, unless *closefd* is set to
*closefd* is set to ``False``.)
``False``.)
*mode* is an optional string that specifies the mode in which the file is
*mode* is an optional string that specifies the mode in which the file is
opened. It defaults to ``'
r
'`` which means open for reading in text mode.
opened. It defaults to ``'
r
'`` which means open for reading in text mode.
...
...
Doc/library/os.path.rst
View file @
76e55387
...
@@ -19,6 +19,12 @@ path names. Vice versa, using bytes objects cannot represent all file
...
@@ -19,6 +19,12 @@ path names. Vice versa, using bytes objects cannot represent all file
names on Windows (in the standard ``mbcs`` encoding), hence Windows
names on Windows (in the standard ``mbcs`` encoding), hence Windows
applications should use string objects to access all files.
applications should use string objects to access all files.
.. note::
All of these functions accept either only bytes or only string objects as
their parameters. The result is an object of the same type, if a path or
file name is returned.
.. warning::
.. warning::
On Windows, many of these functions do not properly support UNC pathnames.
On Windows, many of these functions do not properly support UNC pathnames.
...
...
Doc/library/os.rst
View file @
76e55387
...
@@ -22,6 +22,12 @@ interface).
...
@@ -22,6 +22,12 @@ interface).
Extensions peculiar to a particular operating system are also available through
Extensions peculiar to a particular operating system are also available through
the :mod:`os` module, but using them is of course a threat to portability!
the :mod:`os` module, but using them is of course a threat to portability!
.. note::
All functions accepting path or file names accept both bytes and string
objects, and result in an object of the same type, if a path or file name is
returned.
.. note::
.. note::
If not separately noted, all functions that claim "Availability: Unix" are
If not separately noted, all functions that claim "Availability: Unix" are
...
@@ -693,15 +699,16 @@ Files and Directories
...
@@ -693,15 +699,16 @@ Files and Directories
.. function:: getcwd()
.. function:: getcwd()
Return a string representing the current working directory.
Return a string representing the current working directory. On Unix
May raise UnicodeDecodeError if the current directory path fails
platforms, this function may raise :exc:`UnicodeDecodeError` if the name of
to decode in the file system encoding.
the current directory is not decodable in the file system encoding. Use
Availability: Unix, Windows.
:func:`getcwdb` if you need the call to never fail. Availability: Unix,
Windows.
.. function:: getcwdb()
.. function:: getcwdb()
Return a bytestring
representing the current working directory.
Return a bytestring representing the current working directory.
Availability: Unix, Windows.
Availability: Unix, Windows.
...
@@ -798,15 +805,15 @@ Files and Directories
...
@@ -798,15 +805,15 @@ Files and Directories
.. function:: listdir(path)
.. function:: listdir(path)
Return a list containing the names of the entries in the directory. The list
is
Return a list containing the names of the entries in the directory. The list
i
n arbitrary order. It does not include the special entries ``'.'
`` and
i
s in arbitrary order. It does not include the special entries ``.
`` and
``
'..'`` even if they are present in the directory. Availability:
``
..`` even if they are present in the directory. Availability: Unix,
Unix,
Windows.
Windows.
If *path* is a Unicode object, the result will be a list of Unicode objects.
This function can be called with a bytes or string argument. In the bytes
If a filename can not be decoded to unicode, it is skipped. If *path* is a
case, all filenames will be listed as returned by the underlying API. In the
bytes string, the result will be list of bytes objects included files
string case, filenames will be decoded using the file system encoding, and
skipped
by the unicode version
.
skipped
if a decoding error occurs
.
.. function:: lstat(path)
.. function:: lstat(path)
...
@@ -920,9 +927,9 @@ Files and Directories
...
@@ -920,9 +927,9 @@ Files and Directories
be converted to an absolute pathname using ``os.path.join(os.path.dirname(path),
be converted to an absolute pathname using ``os.path.join(os.path.dirname(path),
result)``.
result)``.
If the *path* is a
n Unicode object, the result will also be a Unicode object
If the *path* is a
string object, the result will also be a string object,
and
may raise an UnicodeDecodeError. If the *path* is a bytes object, the
and
the call may raise an UnicodeDecodeError. If the *path* is a bytes
result will be a bytes object.
object, the
result will be a bytes object.
Availability: Unix.
Availability: Unix.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment