在Python2中导入一些python3模块

在Python2中导入一些python3模块

本文介绍了在Python2中导入一些python3模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将Python 3模块导入到Python 2脚本中?我想在Django应用程序中使用一些Python 3模块,并且在Internet上什么都没看到.有任何线索吗?

Is there a way to import Python 3 modules into Python 2 scripts? I want to use some Python 3 modules in a Django application and haven't seen anything on the Internet. Any clues?

推荐答案

我认为这真的是不可能的,不是.解释器的相同实例必须处理给定应用程序中导入的每个模块,因此没有明显的方法来混合和匹配解释器.如果您需要使用Python 3模块来完成离散任务,则可以尝试制作命令行脚本来完成任务,然后从Python 2应用程序中将该脚本作为子进程调用,但这至少可以说是尴尬的

I don't think it's really possible, no. The same instance of the interpreter has to handle every module imported in a given app, so there's no obvious way to mix and match interpreters. If you need to accomplish a discrete task with a Python 3 module, you could try making a command-line script to accomplish your task and then calling that script as a subprocess from your Python 2 app, but that would be awkward to say the least.

请注意,我认为实际上并没有很多仅Python 3的模块,目前大多数模块都支持两个版本,或者仅支持Python 2.

Note that I don't think there are really a whole lot of Python 3-only modules -- most modules at this point either support both versions, or only Python 2.

这篇关于在Python2中导入一些python3模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 07:20