本文整理匯總了Python中pkgutil.read_code方法的典型用法代碼示例。如果您正苦於以下問題:Python pkgutil.read_code方法的具體用法?Python pkgutil.read_code怎麽用?Python pkgutil.read_code使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pkgutil
的用法示例。
在下文中一共展示了pkgutil.read_code方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_code_from_file
# 需要導入模塊: import pkgutil [as 別名]
# 或者: from pkgutil import read_code [as 別名]
def _get_code_from_file(fname):
# Check for a compiled file first
with open(fname, "rb") as f:
code = read_code(f)
if code is None:
# That didn't work, so try it as normal source code
with open(fname, "rU") as f:
code = compile(f.read(), fname, 'exec')
return code
示例2: _get_code_from_file
# 需要導入模塊: import pkgutil [as 別名]
# 或者: from pkgutil import read_code [as 別名]
def _get_code_from_file(run_name, fname):
# Check for a compiled file first
with open(fname, "rb") as f:
code = read_code(f)
if code is None:
# That didn't work, so try it as normal source code
with open(fname, "rb") as f:
code = compile(f.read(), fname, 'exec')
return code, fname