一种简单的方法是使用函数作用域来控制文件中的导入可见性:
def prepare_parser(): from pyparsing import Word, alphas, Optional, ... # do stuff, and get the final thing to return return ...parser = prepare_parser()

一种简单的方法是使用函数作用域来控制文件中的导入可见性:
def prepare_parser(): from pyparsing import Word, alphas, Optional, ... # do stuff, and get the final thing to return return ...parser = prepare_parser()