在使用 Python 3.x 的脚本中,使用 Python 2.7 导入其他脚本,如何在导入时单独制作特定脚本 运行 2.7?

In a script using Python 3.x, importing other script using Python 2.7, how to make that specific script running with 2.7 separately when importing it?

在python脚本运行Python3.x中,导入另一个python脚本运行Python2.7,是可以告诉程序在导入特定脚本时使用 Python 2.7 解释器吗?

在此"mainfile.py"运行Python3.x

导入另一个文件27

一旦 "anotherfile27.py" 正在导入,所有内容都会自动 运行,"anotherfile27.py" 中的任何功能都不需要在 "mainfile.py" 中重用。只会生成几个.csv脚本,以备后用。

是否可以在"anotherfile27.py"或"mainfile.py"中写一行代码告诉程序只将解释器从Python 3更改为Python 2.7什么时候运行宁"anotherfile27.py"?

这是一个基本示例:

import subprocess
import platform

print("Running ", platform.python_version())
old_version = subprocess.check_output("python2 --version", encoding="utf-8")
print("Old version", old_version)