本文整理匯總了Python中lib2to3.main.main方法的典型用法代碼示例。如果您正苦於以下問題:Python main.main方法的具體用法?Python main.main怎麽用?Python main.main使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類lib2to3.main
的用法示例。
在下文中一共展示了main.main方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: tearDown
# 需要導入模塊: from lib2to3 import main [as 別名]
# 或者: from lib2to3.main import main [as 別名]
def tearDown(self):
# Clean up logging configuration down by main.
del logging.root.handlers[:]
if self.temp_dir:
shutil.rmtree(self.temp_dir)
示例2: run_2to3_capture
# 需要導入模塊: from lib2to3 import main [as 別名]
# 或者: from lib2to3.main import main [as 別名]
def run_2to3_capture(self, args, in_capture, out_capture, err_capture):
save_stdin = sys.stdin
save_stdout = sys.stdout
save_stderr = sys.stderr
sys.stdin = in_capture
sys.stdout = out_capture
sys.stderr = err_capture
try:
return main.main("lib2to3.fixes", args)
finally:
sys.stdin = save_stdin
sys.stdout = save_stdout
sys.stderr = save_stderr
示例3: tearDown
# 需要導入模塊: from lib2to3 import main [as 別名]
# 或者: from lib2to3.main import main [as 別名]
def tearDown(self):
# Clean up logging configuration down by main.
del logging.root.handlers[:]
示例4: script_to_py3
# 需要導入模塊: from lib2to3 import main [as 別名]
# 或者: from lib2to3.main import main [as 別名]
def script_to_py3(script):
"""Convert a script to Python3 syntax if required."""
if sys.version_info[0] < 3:
return script
import tempfile
f = tempfile.NamedTemporaryFile(suffix=".py", delete=False)
f.write(script.encode())
f.flush()
filename = f.name
f.close()
# 2to3 is way too chatty
import logging
logging.basicConfig(filename=os.devnull)
from lib2to3.main import main
if main("lib2to3.fixes", ['--no-diffs', '-w', '-n', filename]):
raise Exception('py3 conversion failed')
f2 = open(filename)
try:
return f2.read()
finally:
f2.close()
os.remove(filename)