Import some python3 modules in Python2

倾然丶 夕夏残阳落幕 提交于 2019-12-30 10:00:11

问题


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?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/10689523/import-some-python3-modules-in-python2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!