Python 2.4 内联 if 语句
我正在 dreamhost Web 服务器上设置一个现有的 django 项目,到目前为止我已经让一切正常工作。不过我在 python 2.5 下开发,dreamhost 默认使用 python 2.4。由于 if 关键字,以下行似乎给出了语法错误:
'parent': c.parent.pk if c.parent is not None else None
^
这种形式的 if
语句是否是在 Python 2.5 中引入的,如果是,是否有一个简单的更改可以使其与Python 2.4?
或者,我应该改为Python 2.5。我已经将python 2.5安装到我的home目录下的一个目录中,并成功在2.5下运行python解释器。如果我想使用 Python 2.5 来做所有事情,我可以在哪里设置呢?
I am setting up an existing django project on a dreamhost web server, so far I have got everything to work correctly. However I developed under python 2.5 and dreamhost by default uses python 2.4. The following line seems gives a syntax error because of the if keyword:
'parent': c.parent.pk if c.parent is not None else None
^
Is it the case that this form of if
statement was introduced in Python 2.5, if so is there an easy change that would make it compatible with Python 2.4?
Or, should I just change to Python 2.5. I have already installed python 2.5 to a directory under my home directory, and have succeeded in running the python interpreter under 2.5. If I wish to use Python 2.5 for everything, where can I set this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这种内联 if 2.5 中添加了,发布了近 4 个几年前。您可以这样更新您的 Dreamhost 版本
Yes, this kind of inline if was added with 2.5, released almost 4 years ago. You can update your Dreamhost version like this
http://www.diveintopython.net/power_of_introspection/and_or.html
http://www.diveintopython.net/power_of_introspection/and_or.html