有没有办法知道我的代码支持哪些版本的python?

You may know the Windows compliance tool that helps people to know if their code is supported by any version of the MS OS.

I am looking something similar for Python.

I am writing a lib with Python 2.6 and I realized that it was not compatible with Python 2.5 due to the use of the with keyword.

I would like to know if there is a simple and automatic way to avoid this situation in the future.

I am also interested in something similar to know which OS are supported.

Thanks for your help

#0

In response to a previous question about this, I wrote pyqver. If you have any improvements, please feel free to fork and contribute!

#1

I recommend you rather use automated tests than a code analysis tool.

Be aware that there are subtle behaviour changes in the Python standard library that your code may or may not depend upon. For example httplib: When uploading files, it is normal to give the data as a str. In Python 2.6 you can give stream objects instead (useful for >1GB files) if you nudge them correctly, but in Python 2.5 you will get an error.

A comprehensive set of unit tests and integration tests will be much more reliable because they test that your program actually works on Python version X.Y.

$ python2.6 tests/run_all.py
.................................
33 tests passed
[OK]

You're Python 2.6 compatible.

$ python2.4 tests/run_all.py
...........EEE.........EEE.......
27 tests passed, 6 errors
[FAIL]

You're not Python 2.4 compatible.

#2

Python 2.5 can still be saved, since it can use the with keyword:

from __future__ import with_statement

推荐文章

如何在web.config中保存sftp服务器连接?

如何在web.config中保存sftp服务器连接?

推荐文章

asp.net用户控件scroolIntoView正在滚动整个页面

asp.net用户控件scroolIntoView正在滚动整个页面

推荐文章

Android中的水平和垂直滚动条是否带有tablelayout?

Android中的水平和垂直滚动条是否带有tablelayout?

推荐文章

如何使用c#在文本框中复制文本文件?

如何使用c#在文本框中复制文本文件?

推荐文章

使用批处理文件中文件名的前2个字符创建子目录

使用批处理文件中文件名的前2个字符创建子目录

推荐文章

如何使用媒体插件(而不是HTML选项)上传vimeo视频

如何使用媒体插件(而不是HTML选项)上传vimeo视频

推荐文章

如何在cakephp中创建自定义url

如何在cakephp中创建自定义url

推荐文章

保存并还原ExpandableListActivity的展开/折叠状态

保存并还原ExpandableListActivity的展开/折叠状态

推荐文章

django-manytomany上的查询筛选器为空

django-manytomany上的查询筛选器为空

推荐文章

独立开发的轻量级版本控制系统

独立开发的轻量级版本控制系统

推荐文章

学习java移动应用程序开发的教程

学习java移动应用程序开发的教程

推荐文章

XMLStreamReader问题

XMLStreamReader问题

推荐文章

从CSV生成Excel电子表格(ASP.NET C#)

从CSV生成Excel电子表格(ASP.NET C#)

推荐文章

如何从Twitter更新Identi.ca

如何从Twitter更新Identi.ca

推荐文章

在Gtk/Gtk中绘制图表#

在Gtk/Gtk中绘制图表#

推荐文章

在Flex 3文本区域中,如何实现文本搜索功能

在Flex 3文本区域中,如何实现文本搜索功能