在OpenShift的书籍示例中使用Python 3.3 [英] Using Python 3.3 in OpenShift's book example

查看:86
本文介绍了在OpenShift的书籍示例中使用Python 3.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenShift最近出版了一本书,"OpenShift入门".对于刚起步的人来说,这是一个很好的指南.

OpenShift recently published a book, "Getting Started with OpenShift". It is a good guide for someone just starting out.

在第3章中,他们展示了如何修改模板应用程序以使用Python 2.7和Flask.我们的要求是Python 3.3.

In Chapter 3 they show how to modify a template application to use Python 2.7 and Flask. Our requirement is for Python 3.3.

在第19页上,对wsgi.py的修改之一是:execfile(virtualenv,dict( file = virtualenv)). execfile在3.x中已删除. StackOverflow中有一些有关如何翻译的示例,但我不清楚如何将其应用于这种情况.

On Page 19, one of the modifications to wsgi.py is: execfile(virtualenv, dict(file=virtualenv)). execfile was done away with in 3.x. There are examples in StackOverflow on how to translate but it is not clear to me how to apply those to this case.

有人对这个问题有见识吗?

Does anyone have any insight into this issue?

推荐答案

作者

exec(compile(open(virtualenv, 'rb').read(), virtualenv, 'exec'), dict(__file__=virtualenv))

我认为,最好将其分解为几个简单的部分.另外,我们应该使用上下文处理程序进行文件处理:

In my opinion, it would be better to break this up into a few simpler pieces. Also we should use a context handler for the file handling::

with open(virtualenv, 'rb') as exec_file:
    file_contents = exec_file.read()
compiled_code = compile(file_contents, virtualenv, 'exec')
exec_namespace = dict(__file__=virtualenv)
exec(compiled_code, exec_namespace)

以这种方式破坏它也将使调试更加容易(实际上:可能).我还没有测试过,但是应该可以.

Breaking it up in this way will also make debugging easier (actually: possible). I haven't tested this but it should work.

这篇关于在OpenShift的书籍示例中使用Python 3.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆