栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从Python访问errno?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从Python访问errno?

更新:在 Python 2.6+上
,使用

ctypes.get_errno()

Python 2.5

下面的代码不可靠(或全面,有多种方法

errno
可以定义),但它应该可以帮助您入门(或重新考虑您在小型扩展模块上的位置(毕竟在Debian上,
pythonsetup.py install
或者
easy_install
在构建它时应该没有问题)) 。来自
http://prespeak.net/pypy/dist/pypy/rpython/lltypesystem/ll2ctypes.py

if not hasattr(ctypes, 'get_errno'):    # Python 2.5 or older    if sys.platform == 'win32':        standard_c_lib._errno.restype = ctypes.POINTER(ctypes.c_int)        def _where_is_errno(): return standard_c_lib._errno()    elif sys.platform in ('linux2', 'freebsd6'):        standard_c_lib.__errno_location.restype = ctypes.POINTER(ctypes.c_int)        def _where_is_errno(): return standard_c_lib.__errno_location()    elif sys.platform in ('darwin', 'freebsd7'):        standard_c_lib.__error.restype = ctypes.POINTER(ctypes.c_int)        def _where_is_errno(): return standard_c_lib.__error()    ctypes.get_errno = lambda: _where_is_errno().contents.value

哪里

standard_c_lib

def get_libc_name():    if sys.platform == 'win32':        # Parses sys.version and deduces the version of the compiler        import distutils.msvccompiler        version = distutils.msvccompiler.get_build_version()        if version is None: # This logic works with official builds of Python. if sys.version_info < (2, 4):     clibname = 'msvcrt' else:     clibname = 'msvcr71'        else: if version <= 6:     clibname = 'msvcrt' else:     clibname = 'msvcr%d' % (version * 10)        # If python was built with in debug mode        import imp        if imp.get_suffixes()[0][0] == '_d.pyd': clibname += 'd'        return clibname+'.dll'    else:        return ctypes.util.find_library('c')# Make sure the name is determined during import, not at runtimelibc_name = get_libc_name() standard_c_lib = ctypes.cdll.LoadLibrary(get_libc_name())


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/403347.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号