警告
This function should not be called directly: use the
PyConfig
API with the
PyConfig_SetBytesString()
function which ensures that
Python is preinitialized
.
This function must not be called before
Python is preinitialized
and so that the LC_CTYPE locale is properly configured: see the
Py_PreInitialize()
函数。
Decode a byte string from the
文件系统编码和错误处理程序
. If the error handler is
surrogateescape (替代转义) 错误处理程序
, undecodable bytes are decoded as characters in range U+DC80..U+DCFF; and if a byte sequence can be decoded as a surrogate character, the bytes are escaped using the surrogateescape error handler instead of decoding them.
Return a pointer to a newly allocated wide character string, use
PyMem_RawFree()
来释放内存。若尺寸不是
NULL
, write the number of wide characters excluding the null character into
*size
返回
NULL
当解码错误或内存分配出错时。若
size
不是
NULL
,
*size
被设为
(size_t)-1
当内存出错时或设为
(size_t)-2
当解码错误时。
The
文件系统编码和错误处理程序
are selected by
PyConfig_Read()
: see
filesystem_encoding
and
filesystem_errors
成员对于
PyConfig
.
解码错误应从不发生,除非 C 库存在 Bug。
使用
Py_EncodeLocale()
函数将字符串编码回字节字符串。
-
char
*
Py_EncodeLocale
(
const
wchar_t
*
text
,
size_t
*
error_pos
)
¶
-
属于
稳定 ABI (应用程序二进制接口)
since version 3.7.
Encode a wide character string to the
文件系统编码和错误处理程序
. If the error handler is
surrogateescape (替代转义) 错误处理程序
, surrogate characters in the range U+DC80..U+DCFF are converted to bytes 0x80..0xFF.
Return a pointer to a newly allocated byte string, use
PyMem_Free()
to free the memory. Return
NULL
on encoding error or memory allocation error.
若 error_pos 不是
NULL
,
*error_pos
被设为
(size_t)-1
on success, or set to the index of the invalid character on encoding error.
The
文件系统编码和错误处理程序
are selected by
PyConfig_Read()
: see
filesystem_encoding
and
filesystem_errors
成员对于
PyConfig
.
使用
Py_DecodeLocale()
函数将字节字符串解码回宽字符串。
系统函数
¶
These are utility functions that make functionality from the
sys
module accessible to C code. They all work with the current interpreter thread’s
sys
module’s dict, which is contained in the internal thread state structure.
-
PyObject
*
PySys_GetObject
(
const
char
*
名称
)
¶
-
返回值:借位引用。
属于
稳定 ABI (应用程序二进制接口)
.
返回对象
name
从
sys
模块或
NULL
若不存在,则不设置异常。
-
int
PySys_SetObject
(
const
char
*
名称
,
PyObject
*
v
)
¶
-
属于
稳定 ABI (应用程序二进制接口)
.
Set
name
在
sys
module to
v
unless
v
is
NULL
,在这种情况下
name
is deleted from the sys module. Returns
0
当成功时,
-1
当出错时。
-
void
PySys_ResetWarnOptions
(
)
¶
-
属于
稳定 ABI (应用程序二进制接口)
.
重置
sys.warnoptions
to an empty list. This function may be called prior to
Py_Initialize()
.
Deprecated since version 3.13, will be removed in version 3.15:
Clear
sys.warnoptions
and
warnings.filters
代替。