本文整理汇总了Python中copy.__file__方法的典型用法代码示例。如果您正苦于以下问题:Python copy.__file__方法的具体用法?Python copy.__file__怎么用?Python copy.__file__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类copy
的用法示例。
在下文中一共展示了copy.__file__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_py2_stdlib_module
# 需要导入模块: import copy [as 别名]
# 或者: from copy import __file__ [as 别名]
def is_py2_stdlib_module(m):
"""
Tries to infer whether the module m is from the Python 2 standard library.
This may not be reliable on all systems.
"""
if PY3:
return False
if not 'stdlib_path' in is_py2_stdlib_module.__dict__:
stdlib_files = [contextlib.__file__, os.__file__, copy.__file__]
stdlib_paths = [os.path.split(f)[0] for f in stdlib_files]
if not len(set(stdlib_paths)) == 1:
# This seems to happen on travis-ci.org. Very strange. We'll try to
# ignore it.
flog.warn('Multiple locations found for the Python standard '
'library: %s' % stdlib_paths)
# Choose the first one arbitrarily
is_py2_stdlib_module.stdlib_path = stdlib_paths[0]
if m.__name__ in sys.builtin_module_names:
return True
if hasattr(m, '__file__'):
modpath = os.path.split(m.__file__)
if (modpath[0].startswith(is_py2_stdlib_module.stdlib_path) and
'site-packages' not in modpath[0]):
return True
return False