MDN’s new design is in Beta! A sneak peek: https://blog.mozilla.org/opendesign/mdns-new-design-beta/

Python

这篇翻译不完整。请帮忙从英语翻译这篇文章

Python 是一款直译式脚本语言,支持包括 Linux、Mac OS X 和 Microsoft Windows 在内的多种平台。

学习 Python

免费的电子书

 如果你是个初学者,可以考虑看看 Dive Into Python 。虽然它最后更新的时间是2004年,但依然是一部免费而且很棒的教程。 它含括了几乎所有Python 的基本元素,还有一些平常使用 Python 可以执行什么任务,像是对 Web 请求和文件的处理。如果对于 Python 已经有了基本的概念,就可以考虑看看 Text Processing In Python,这本书对于 Python 有着更进阶的介绍。

还有其他免费的电子书和在线资源可供参考:

译者注:如果有发现其他中文教程,欢迎编写本页来分享

当你对这款语言有了基础的认识后, Code Like a Pythonista: Idiomatic Python 将帮你了解 Python 的一些特别之处,以及和其他语言的区别。

免费在线课程

Python 也用在了基于 Mozilla 的应用程序中

XPCOM 在 Mozilla 中用于支持跨语言通信(inter-language communication)。它仅原生支持 C++ <-> JavaScript 的交流。 Python 的 XPCOM 组件(也叫做 PyXPCOM)是将 Python 和 Mozilla 粘合在一块的低级别胶水(the low-level glue),使得用 JavaScript 或 C++ 编写的 XPCOM 组件既可以通过 Python 使用,反之亦然。PyXPCOM 并不默认包含在 Firefox 构建版本中,因此你须要使用第三方构建版本或自己构建一个版本来使用它。 The most known consumer of PyXPCOM is the Komodo family of products.

Starting with Mozilla 1.9, Python DOM (PyDOM) bindings are implemented. This lets chrome XUL and HTML authors use Python in their <script> tags (again, not in the official Firefox/Thunderbird builds).

Python-based tools for Mozilla development

Python is used by Mozillians for tools that do various things with Mozilla apps and infrastructure. It would be useful to have a document on Python Environment and Tools for Mozilla.

Tools are listed here: http://k0s.org/toolbox/?language=python

Use of Python at Mozilla

Mozilla has considerable infrastructure based on python:

Python in Mozilla-Central

[Stub: see https://bugzilla.mozilla.org/show_bug.cgi?id=835553]

Much of the build system, the testing system, and other tools and infrastructure in mozilla-central are python.

  • python/ contains common python code including third party packages mirrored from (e.g.) pypi.python.org
  • testing/mozbase/ contains a mirror of Mozbase packages as used in mozilla-central

A virtualenv is made in the objdir on invocation of the build at $OBJDIR/_virtualenv . To add packages to the virtualenv, edit build/virtualenv_packages.txt . These are installed on build via build/virtualenv/populate_virtualenv.py .

Python packaging

Python uses setup.py files to record metadata and installation instructions for python packages. Running (e.g.) python setup.py install will install the package, making its modules available on python's import path. For python 2.x, several distribution/installation modules exist. distutils is the only distribution package available in python's standard library. distutils has ability to upload to the python package index and to install python packages. See the Python documentation on distutils for details.

While distutils is built in to python's standard library, setuptools is a third-party ad hoc standard for packaging and distribution. It is mostly compatible with distutils, but importantly adds the ability for packages to include dependencies that are installed as prerequisites at the time setup.py is invoked as well as the ability to install python packages in development mode. This allows the files to be edited in place via .pth files which is handy if you are actively working on a project. setuptools also provides an easy_install script for installing packages and their dependencies through the web from PyPI. For instance, in order to install the PyYAML package, just run

easy_install PyYAML

Since setuptools is not included with python, you will need to install it in order to use it. You may install it from the setuptools PyPI page by downloading, extracting, and running python setup.py install. Or you can use the ez_setup.py script. You can download and run it with python (with root/Administrator privileges), or if you're in a bash shell, you can run

sudo python <(curl http://peak.telecommunity.com/dist/ez_setup.py)

setuptools is also provided with instances of virtualenv, so if you use virtualenvs for developing you may not need to install setuptools globally. distribute is a fork of setuptools written by Mozilla's own Tarek Ziade. It is compatible with setuptools and fixes a few bugs there.

Note: It's highly recommended that you use virtualenv for development!

The Python Package Index (PyPI) is the standard distribution point for python packages. If you need some functionality in python, it is a good place to look!

See also: http://k0s.org/portfolio/packaging.html

See also

文档标签和贡献者

 此页面的贡献者: xcffl
 最后编辑者: xcffl,