Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从Py 3.5中的代码调用函数到Py 2环境中运行的代码_Python_Python 3.x_Python 2.7_Virtualenv - Fatal编程技术网

Python 从Py 3.5中的代码调用函数到Py 2环境中运行的代码

Python 从Py 3.5中的代码调用函数到Py 2环境中运行的代码,python,python-3.x,python-2.7,virtualenv,Python,Python 3.x,Python 2.7,Virtualenv,我有问题。我构建的大多数代码及其库都受py3.6支持,我在Py2.7中有一些旧代码。较旧的代码有很多依赖项,它们依赖于py 2.7来正常工作。将代码导出到Py3.6是解决方案,但由于时间限制,我们正在避免这样做 我可以从Py 3.6虚拟环境中运行的代码调用Py 2.7虚拟环境中运行的代码吗。它执行代码并返回响应 # Py 3.6 virtual env def foo(some_var): # Make call to Code in Py 2.7 Virtual env de

我有问题。我构建的大多数代码及其库都受py3.6支持,我在Py2.7中有一些旧代码。较旧的代码有很多依赖项,它们依赖于py 2.7来正常工作。将代码导出到Py3.6是解决方案,但由于时间限制,我们正在避免这样做

我可以从Py 3.6虚拟环境中运行的代码调用Py 2.7虚拟环境中运行的代码吗。它执行代码并返回响应

# Py 3.6 virtual env
def foo(some_var):

    # Make call to Code in Py 2.7 Virtual env
    def get_response_from_bar():
        # ....processing.....
        return response

    get_response_from_bar()

您必须实现一些(远程方法调用)。Python 2程序应该是服务器,Python 3应该是客户端。

Hi@phd,谢谢你的建议。我已经实现了这一点,它工作得非常完美。我可以用RESTAPI实现这个功能吗?任何RPC都可以;REST只是一个协议。因为您可能会在服务器程序中包含一个web微框架(如瓶子或烧瓶)。