欢迎大家赞助一杯啤酒🍺 我们准备了下酒菜:Formal mathematics/Isabelle/ML, Formal verification/Coq/ACL2, C++/F#/Lisp
Python
小 (→Python 2.3 on Debian) |
|||
(未显示3个用户的131个中间版本) | |||
第1行: | 第1行: | ||
− | [[Image:Python- | + | [[Image:Python-90x90.png|right]] |
− | + | ||
− | + | ||
Python 是一种面向对象的解释性的计算机程序设计语言,也是一种功能强大而完善的 通用型语言,已经具有十多年的发展历史,成熟且稳定。 | Python 是一种面向对象的解释性的计算机程序设计语言,也是一种功能强大而完善的 通用型语言,已经具有十多年的发展历史,成熟且稳定。 | ||
+ | [[Image:python-powered-w-100x40.png|right]] | ||
+ | |||
+ | ==新闻== | ||
+ | {{SeeWikipedia|Python (programming language)}} | ||
+ | <rss>http://planetpython.org/rss20.xml|short|date|max=8</rss> | ||
+ | |||
+ | ==简介== | ||
+ | Python是[[Data_science|数据科学]]和[[Artificial intelligence|人工智能]]的交互语言 :) | ||
At Google, python is one of the 3 "official languages" alongside with C++ and Java. [http://panela.blog-city.com/python_at_google_greg_stein__sdforum.htm Python at Google], Google Group, code.google.com 等服务基于 Python 构建。 | At Google, python is one of the 3 "official languages" alongside with C++ and Java. [http://panela.blog-city.com/python_at_google_greg_stein__sdforum.htm Python at Google], Google Group, code.google.com 等服务基于 Python 构建。 | ||
+ | |||
+ | [[Unladen Swallow]]: A faster implementation of Python, Google发起的项目, 值得关注 | ||
+ | |||
+ | 将 Python 带入企业级应用: [[Enterprise Python]] | ||
==版本== | ==版本== | ||
− | * Python 2.5 (September 19, 2006) | + | 主要分支:2.7、3.4、3.5、3.6、3.7 |
− | + | *[https://www.zhihu.com/question/19698598 Python 2 和 Python 3 有哪些主要区别?] | |
− | + | *[http://docs.huihoo.com/python/3/howto/pyporting.html Porting Python 2 Code to Python 3] [http://docs.huihoo.com/python/3/howto/cporting.html Porting Extension Modules to Python 3] | |
− | + | *[http://docs.huihoo.com/python/3/ Python 3.x] | |
− | + | *[http://docs.huihoo.com/python/2/ Python 2.x] | |
− | + | * [http://www.python.org/download/releases/2.5 Python 2.5] (September 19, 2006) | |
− | + | * [http://www.python.org/download/releases/2.4.4 Python 2.4.4] (October 18, 2006) | |
− | + | * [http://www.python.org/download/releases/2.3.6 Python 2.3.6] (November 1, 2006) | |
− | == | + | * [http://www.python.org/download/releases/2.2.3 Python 2.2.3] (May 30, 2003) |
+ | * [http://www.python.org/download/releases/2.1.3 Python 2.1.3] (April 8, 2002) | ||
+ | * [http://www.python.org/download/releases/2.0.1 Python 2.0.1] (June 2001) | ||
+ | * [http://www.python.org/download/releases/1.6.1 Python 1.6.1] (September 2000) | ||
+ | * [http://www.python.org/download/releases/1.5 Python 1.5.2] (April 1999) | ||
+ | |||
+ | |||
+ | ==指南== | ||
+ | $ python3 -m sysconfig // 返回非常多的配置信息 | ||
+ | |||
+ | Python 2.4.4 (#1, Feb 3 2007, 09:56:56) | ||
+ | [GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2 | ||
+ | Type "help", "copyright", "credits" or "license" for more information. | ||
+ | >>> 'Ruby' > 'Python' | ||
+ | True | ||
+ | >>> 'Ruby' > 'Java' | ||
+ | True | ||
+ | >>> 'Ruby' > 'C/C++' | ||
+ | True | ||
+ | 有点意思 :) | ||
+ | |||
+ | 安装 pip3,如 [[Debian]] 环境 | ||
+ | $ sudo apt update | ||
+ | $ sudo apt install python3-pip | ||
+ | $ pip3 --version | ||
+ | |||
+ | ==实现== | ||
+ | *[[CPython]] | ||
+ | *[[IronPython]] | ||
+ | *[[Jython]] | ||
+ | *[[PyPy]] | ||
+ | *[https://github.com/bjpop/berp/ Berp] an implementation of Python 3 written in [[Haskell]]. [https://wiki.python.org/moin/PythonVsHaskell Python vs Haskell] | ||
+ | |||
+ | ==函数式编程== | ||
+ | 通过lambda关键字,可以创建很小的匿名函数。 | ||
+ | >>> def make_incrementor(n): | ||
+ | ... return lambda x: x + n | ||
+ | ... | ||
+ | >>> f = make_incrementor(42) | ||
+ | >>> f(0) | ||
+ | 42 | ||
+ | >>> f(1) | ||
+ | 43 | ||
+ | *[http://docs.huihoo.com/python/pycon/2014/decorators-a-powerful-weapon-in-your-python-arsenal.pdf Decorators: A Powerful Weapon in Your Python Arsenal] | ||
+ | *[http://docs.huihoo.com/python/pycon/2014/advanced-methods-for-creating-decorators.pdf Advanced methods for creating decorators] | ||
+ | *[http://www.infoq.com/cn/articles/fn.py-functional-programming-python Fn.py:享受Python中的函数式编程] | ||
+ | *[http://program-think.blogspot.com/2012/02/why-choose-python-4-fp.html 作为函数式编程语言的Python] 要翻墙 | ||
+ | |||
+ | ==项目== | ||
+ | *[https://github.com/vinta/awesome-python Awesome Python][[文件:awesome.png]] | ||
*[[Quixote]] | *[[Quixote]] | ||
*[[Django]] | *[[Django]] | ||
第24行: | 第83行: | ||
*[[Karrigell]] | *[[Karrigell]] | ||
*[[webpy]] | *[[webpy]] | ||
+ | *[[Tornado]] | ||
*[[CherryPy]] | *[[CherryPy]] | ||
*[[Myghty]] | *[[Myghty]] | ||
+ | *[[Mako]] | ||
*[[Pylons]] | *[[Pylons]] | ||
− | *[[Anaconda | + | *[[Anaconda python]] |
− | + | ||
*[[Zope]] | *[[Zope]] | ||
*[[Plone]] | *[[Plone]] | ||
更多: [[Huihoo Python Applications]] | 更多: [[Huihoo Python Applications]] | ||
+ | |||
+ | ==桌面== | ||
+ | 将 Python 带入桌面环境:[[PyQt]]、[[PyGTK]]、[[wxPython]] | ||
+ | |||
+ | [https://github.com/PySimpleGUI/PySimpleGUI PySimpleGUI] | ||
+ | |||
+ | ==Web Server== | ||
+ | [[WSGI]] Server | ||
+ | *[[flup]] | ||
+ | *[[Gunicorn]] | ||
+ | *[[uWSGI]] | ||
+ | *[[CherryPy]] | ||
+ | *[[Twisted]] Web | ||
+ | *[https://github.com/GrahamDumpleton/mod_wsgi mod_wsgi] | ||
+ | |||
+ | ==Python应用== | ||
+ | *[[Python and Math]] | ||
+ | *Python 企业级应用 [[Enterprise Python]] | ||
+ | *[[IMDbPY]] | ||
+ | *[[Zenoss]] | ||
+ | |||
+ | ===Python and Grid=== | ||
+ | *[[Python Core]] - http://dev.globus.org/wiki/Python_Core | ||
+ | |||
+ | ===Python Web Services=== | ||
+ | |||
+ | *Python Web 服务开发者 - http://www-128.ibm.com/developerworks/cn/webservices/ws-pyth/index.html | ||
==Python IDE & Editor== | ==Python IDE & Editor== | ||
+ | *使用 [[Aptana]] 进行 Python 应用开发。 | ||
*[[Vim]] | *[[Vim]] | ||
*[[GNU Emacs]] | *[[GNU Emacs]] | ||
+ | *[[Eric]] | ||
*[[PyDev]] | *[[PyDev]] | ||
− | *[[ | + | *[[ActivePython]] |
*[[Boa Constructor]] | *[[Boa Constructor]] | ||
*[[DrPython]] | *[[DrPython]] | ||
− | 更多 IDEs: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments | + | *[[PythonCard]] |
+ | *[[ActiveGrid]] | ||
+ | *[[EasyEclipse for Python]] | ||
+ | 更多 IDEs: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments | ||
+ | |||
==pygame== | ==pygame== | ||
*[[pygame 1945|1945]] | *[[pygame 1945|1945]] | ||
第53行: | 第146行: | ||
==Linux== | ==Linux== | ||
+ | |||
+ | ===Python 3 on Debian=== | ||
+ | $ curl -O https://www.python.org/ftp/python/3.8.9/Python-3.8.9.tar.xz | ||
+ | $ tar -xf Python-3.8.9.tar.xz | ||
+ | $ make -j 4 | ||
+ | $ sudo make altinstall | ||
+ | $ python3.8 --version | ||
+ | |||
===Python 2.3 on Debian=== | ===Python 2.3 on Debian=== | ||
− | Debian 3.1 安装后自带 Python 2.3 | + | from module import * in Python is like use module in Perl; import module in Python is like require module in Perl. |
+ | from module import * in Python is like import module.* in Java; import module in Python is like import module in Java. | ||
+ | |||
+ | Debian 3.1 安装后自带 Python 2.3.5 | ||
+ | >>> import sys | ||
+ | >>> sys.path.append('/home/allen/test/diveintopython-5.4/py') // apihelper.py 在 py 目录下 | ||
+ | >>> import apihelper | ||
+ | >>> sys.path | ||
+ | |||
===Python 2.4 on Debian=== | ===Python 2.4 on Debian=== | ||
− | wget http:// | + | #apt-get install python2.4 |
− | tar zxvf Python-2.4. | + | 设置环境 |
− | cd Python-2.4. | + | export PYTHONPATH = /usr/lib/python2.4 |
+ | or | ||
+ | wget http://download.huihoo.com/python/2.4.3/Python-2.4.3.tgz | ||
+ | tar zxvf Python-2.4.3.tgz | ||
+ | cd Python-2.4.3 | ||
./configure | ./configure | ||
make | make | ||
make install // installed to /usr/local/lib/python2.4 | make install // installed to /usr/local/lib/python2.4 | ||
/usr/local/bin/python2.4 | /usr/local/bin/python2.4 | ||
− | Python 2.4. | + | Python 2.4.3 (#1, Mar 5 2007, 15:20:37) |
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2 | [GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2 | ||
Type "help", "copyright", "credits" or "license" for more information. | Type "help", "copyright", "credits" or "license" for more information. | ||
− | >>> | + | >>> |
+ | ln -s /usr/local/bin/python2.4 /usr/bin/python | ||
+ | |||
+ | 设置环境, 共存多个python版本, Default python version in Debian | ||
===Python 2.5 on Debian=== | ===Python 2.5 on Debian=== | ||
+ | [[Python 2.5新特性]] | ||
wget http://www.python.org/ftp/python/2.5/Python-2.5.tgz | wget http://www.python.org/ftp/python/2.5/Python-2.5.tgz | ||
tar zxvf Python-2.5.tgz | tar zxvf Python-2.5.tgz | ||
第75行: | 第192行: | ||
make | make | ||
make install | make install | ||
+ | 设置环境 | ||
+ | export PYTHONPATH = | ||
+ | |||
==Solaris== | ==Solaris== | ||
==FreeBSD== | ==FreeBSD== | ||
+ | FreeBSD 6.1 安装有 Python 2.4.2 | ||
+ | |||
==Windows== | ==Windows== | ||
http://download.huihoo.com/python/2.5/python-2.5.msi | http://download.huihoo.com/python/2.5/python-2.5.msi | ||
set path=%path%;C:\Python25 | set path=%path%;C:\Python25 | ||
+ | set lib=%lib%;C:\Python25\lib | ||
运行命令行或集成开发环境 IDLE | 运行命令行或集成开发环境 IDLE | ||
>>> help() | >>> help() | ||
第110行: | 第233行: | ||
http://www.modpython.org/examples/psp_site.tgz | http://www.modpython.org/examples/psp_site.tgz | ||
http://localhost/psp_site/ | http://localhost/psp_site/ | ||
+ | |||
==Database== | ==Database== | ||
+ | DB-API 标准 | ||
+ | * [http://www.python.org/dev/peps/pep-0249 Python Database API Specification v2.0] | ||
+ | * [http://www.python.org/dev/peps/pep-0248 Python Database API Specification v1.0] | ||
+ | |||
===MySQL=== | ===MySQL=== | ||
http://sourceforge.net/projects/mysql-python/ | http://sourceforge.net/projects/mysql-python/ | ||
+ | 获得 MySQL-python.exe-1.2.1_p2.win32-py2.4.exe | ||
+ | 包安装到 C:\Python24\Lib\site-packages\MySQLdb | ||
+ | or Debian | ||
+ | #apt-get install python2.3-mysqldb | ||
+ | >>> import MySQLdb | ||
+ | >>> db = MySQLdb.connect("localhost","root","password","mysql") | ||
+ | >>> cursor = db.cursor() | ||
+ | >>> sql = "select * from db" | ||
+ | >>> cursor.execute(sql) | ||
+ | >>> data = cursor.fetchone() | ||
+ | >>> print data | ||
+ | >>> db.close() | ||
+ | |||
===PostgreSQL=== | ===PostgreSQL=== | ||
− | *http://initd.org/projects/psycopg1 | + | *[[psycopg]]: http://initd.org/projects/psycopg1 |
− | *http://pypgsql.sourceforge.net/ | + | *[[pyPgSQL]]: http://pypgsql.sourceforge.net/ |
+ | *[[PySQLite]] | ||
+ | *[[PyGreSQL]] | ||
+ | |||
+ | ===Berkeley DB=== | ||
+ | *anydbm: Generic interface to DBM-style database modules. | ||
+ | *whichdb: Guess which DBM-style module created a given database. | ||
+ | *dbm: The standard ``database'' interface, based on ndbm. | ||
+ | *gdbm: GNU's reinterpretation of dbm. | ||
+ | *dbhash: DBM-style interface to the BSD database library. | ||
+ | *[[Python bsddb|bsddb]]: Interface to Berkeley DB database library | ||
+ | *dumbdbm: Portable implementation of the simple DBM interface. | ||
+ | http://pybsddb.sourceforge.net/ | ||
+ | >>> import anydbm | ||
+ | >>> db = anydbm.open('cache', 'c') | ||
+ | >>> db['www.python.org'] = 'Python Website' | ||
+ | >>> db['www.huihoo.com'] = 'Open Source Community' | ||
+ | >>> for k, v in db.iteritems(): | ||
+ | print k, '\t', v | ||
+ | |||
+ | www.huihoo.com Open Source Community | ||
+ | www.python.org Python Website | ||
+ | |||
===SQLite=== | ===SQLite=== | ||
− | http:// | + | Python 2.5 内置了对 sqlite3 的支持- http://docs.huihoo.com/python/2.5/lib/module-sqlite3.html |
+ | |||
+ | [[pysqlite]] | ||
+ | |||
+ | ===ORM/Persistence=== | ||
+ | *[[SQLObject]] | ||
+ | *[[SQLAlchemy]] | ||
+ | *[[Modeling Object-Relational Bridge for python|Modeling]] | ||
+ | *[[Durus]] | ||
+ | *[[Python Database Objects]] | ||
+ | |||
+ | ==LDAP== | ||
+ | *[[python-ldap]] | ||
+ | |||
==Modules== | ==Modules== | ||
− | + | [[Python Modules]] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | == | + | ==C/C++== |
− | * | + | >>> import dl, time |
− | * | + | >>> a = dl.open('/lib/libc.so.6') |
+ | >>> a.call('time') | ||
+ | 1207223740 | ||
+ | ==技巧== | ||
+ | 看一个module包含的函数 | ||
+ | import sys | ||
+ | content = dir(sys) | ||
+ | print content | ||
+ | |||
+ | ==问题== | ||
+ | 'import site' failed; use -v for traceback | ||
+ | |||
+ | unable to open /usr/lib/python2.3/config/Makefile (No such file or directory) | ||
+ | #apt-get install python2.3-dev | ||
+ | |||
+ | ==应用== | ||
+ | *http://groups.google.com | ||
+ | *http://reddit.com | ||
+ | *http://www.douban.com | ||
+ | *[http://highscalability.com/blog/2011/3/14/6-lessons-from-dropbox-one-million-files-saved-every-15-minu.html Python 在 Dropbox 的运用] | ||
+ | |||
+ | ==文档== | ||
+ | *[http://docs.huihoo.com/python/ Python文档]包含3.1.2, 3.1, 2.6.5, 2.5, 2.4.4, 2.4.3, 2.4.2, 2.4.1, 2.3.5, 2.3.4, 2.3.3, 2.3等版本文档。 | ||
+ | *Python 研究([http://diveintopython.org/ Dive Into Python)] | ||
*The Standard Python Library - http://www.effbot.org/librarybook/ | *The Standard Python Library - http://www.effbot.org/librarybook/ | ||
+ | *[http://docs.huihoo.com/scipy/scipy-zh-cn/ 用Python做科学计算] | ||
+ | *[http://docs.huihoo.com/python/python-guide/en The Hitchhiker's Guide to Python!] | ||
− | == | + | ==图书== |
− | *Python | + | *[http://book.huihoo.com/dive-into-python Dive Into Python] |
+ | *[http://book.huihoo.com/how-to-think-like-a-computer-scientist-python-version/ How to Think Like a Computer Scientist Python Version] | ||
+ | |||
+ | ==图集== | ||
+ | <gallery> | ||
+ | image:python-interpreter.png|interpreter | ||
+ | image:mindsdb.png|MindsDB | ||
+ | </gallery> | ||
+ | |||
+ | ==链接== | ||
+ | *http://www.python.org/ | ||
+ | *http://cheeseshop.python.org | ||
+ | *http://docs.huihoo.com/python/ | ||
+ | *http://download.huihoo.com/python/ | ||
+ | *http://www.pygame.org/ | ||
+ | *[http://www.woodpecker.org.cn/ 啄木鸟 Pythonic 开源社区] | ||
+ | *[http://python.cn/ Python中文社区] | ||
+ | *[http://czug.org/about/python/ Python资源] | ||
+ | *[http://pythonsource.com/ Open Source Software in Python] | ||
+ | *http://www.pocoo.org/ | ||
+ | *[http://scipy.org/ SciPy] | ||
+ | *[http://www.infoq.com/cn/news/2014/07/pycon-2014 PyCon 2014:机器学习应用占据Python的半壁江山] | ||
+ | *[https://developers.google.com/edu/python/ Google's Python Class] | ||
− | [[ | + | [[category:programming language]] |
+ | [[category:c programming language]] | ||
+ | [[category:python]] | ||
+ | [[category:huihoo]] |
2022年3月9日 (三) 05:26的最后版本
Python 是一种面向对象的解释性的计算机程序设计语言,也是一种功能强大而完善的 通用型语言,已经具有十多年的发展历史,成熟且稳定。
目录 |
[编辑] 新闻
您可以在Wikipedia上了解到此条目的英文信息 Python Thanks, Wikipedia. |
自http://planetpython.org/rss20.xml加载RSS失败或RSS源被墙
[编辑] 简介
At Google, python is one of the 3 "official languages" alongside with C++ and Java. Python at Google, Google Group, code.google.com 等服务基于 Python 构建。
Unladen Swallow: A faster implementation of Python, Google发起的项目, 值得关注
将 Python 带入企业级应用: Enterprise Python
[编辑] 版本
主要分支:2.7、3.4、3.5、3.6、3.7
- Python 2 和 Python 3 有哪些主要区别?
- Porting Python 2 Code to Python 3 Porting Extension Modules to Python 3
- Python 3.x
- Python 2.x
- Python 2.5 (September 19, 2006)
- Python 2.4.4 (October 18, 2006)
- Python 2.3.6 (November 1, 2006)
- Python 2.2.3 (May 30, 2003)
- Python 2.1.3 (April 8, 2002)
- Python 2.0.1 (June 2001)
- Python 1.6.1 (September 2000)
- Python 1.5.2 (April 1999)
[编辑] 指南
$ python3 -m sysconfig // 返回非常多的配置信息
Python 2.4.4 (#1, Feb 3 2007, 09:56:56) [GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 'Ruby' > 'Python' True >>> 'Ruby' > 'Java' True >>> 'Ruby' > 'C/C++' True
有点意思 :)
安装 pip3,如 Debian 环境
$ sudo apt update $ sudo apt install python3-pip $ pip3 --version
[编辑] 实现
- CPython
- IronPython
- Jython
- PyPy
- Berp an implementation of Python 3 written in Haskell. Python vs Haskell
[编辑] 函数式编程
通过lambda关键字,可以创建很小的匿名函数。
>>> def make_incrementor(n): ... return lambda x: x + n ... >>> f = make_incrementor(42) >>> f(0) 42 >>> f(1) 43
- Decorators: A Powerful Weapon in Your Python Arsenal
- Advanced methods for creating decorators
- Fn.py:享受Python中的函数式编程
- 作为函数式编程语言的Python 要翻墙
[编辑] 项目
- Awesome Python
- Quixote
- Django
- TurboGears
- Twisted
- ActiveGrid
- Karrigell
- webpy
- Tornado
- CherryPy
- Myghty
- Mako
- Pylons
- Anaconda python
- Zope
- Plone
更多: Huihoo Python Applications
[编辑] 桌面
将 Python 带入桌面环境:PyQt、PyGTK、wxPython
[编辑] Web Server
WSGI Server
[编辑] Python应用
- Python and Math
- Python 企业级应用 Enterprise Python
- IMDbPY
- Zenoss
[编辑] Python and Grid
[编辑] Python Web Services
- Python Web 服务开发者 - http://www-128.ibm.com/developerworks/cn/webservices/ws-pyth/index.html
[编辑] Python IDE & Editor
- 使用 Aptana 进行 Python 应用开发。
- Vim
- GNU Emacs
- Eric
- PyDev
- ActivePython
- Boa Constructor
- DrPython
- PythonCard
- ActiveGrid
- EasyEclipse for Python
更多 IDEs: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments
[编辑] pygame
[编辑] Python Enhancement Proposals(PEPs)
PEPs 有点类似 Java JSRs
- PEP 333: Python Web Server Gateway Interface v1.0
- PEP 249: Python Database API Specification v2.0
- PEP 361: Python 2.6 Release Schedule
- PEP 3100: Python 3.0 Plans
更多 PEPs : http://www.python.org/dev/peps/
[编辑] Linux
[编辑] Python 3 on Debian
$ curl -O https://www.python.org/ftp/python/3.8.9/Python-3.8.9.tar.xz $ tar -xf Python-3.8.9.tar.xz $ make -j 4 $ sudo make altinstall $ python3.8 --version
[编辑] Python 2.3 on Debian
from module import * in Python is like use module in Perl; import module in Python is like require module in Perl. from module import * in Python is like import module.* in Java; import module in Python is like import module in Java.
Debian 3.1 安装后自带 Python 2.3.5 >>> import sys >>> sys.path.append('/home/allen/test/diveintopython-5.4/py') // apihelper.py 在 py 目录下 >>> import apihelper >>> sys.path
[编辑] Python 2.4 on Debian
#apt-get install python2.4
设置环境
export PYTHONPATH = /usr/lib/python2.4 or wget http://download.huihoo.com/python/2.4.3/Python-2.4.3.tgz tar zxvf Python-2.4.3.tgz cd Python-2.4.3 ./configure make make install // installed to /usr/local/lib/python2.4 /usr/local/bin/python2.4 Python 2.4.3 (#1, Mar 5 2007, 15:20:37) [GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> ln -s /usr/local/bin/python2.4 /usr/bin/python
设置环境, 共存多个python版本, Default python version in Debian
[编辑] Python 2.5 on Debian
wget http://www.python.org/ftp/python/2.5/Python-2.5.tgz tar zxvf Python-2.5.tgz cd Python-2.5 ./configure make make install
设置环境
export PYTHONPATH =
[编辑] Solaris
[编辑] FreeBSD
FreeBSD 6.1 安装有 Python 2.4.2
[编辑] Windows
http://download.huihoo.com/python/2.5/python-2.5.msi set path=%path%;C:\Python25 set lib=%lib%;C:\Python25\lib
运行命令行或集成开发环境 IDLE
>>> help() help>modules help>sys help>modules search help>SearchEngine help>modules hash help>hashlib help>quit >>>
获得 mod_python , http://www.apache.org/dist/httpd/modpython/win/
http://www.apache.org/dist/httpd/modpython/win/3.3.0b/mod_python-3.3.0b.win32-py2.5-Apache2.2.exe 会被安装到 C:\Python25\Lib\site-packages\ 并在安装过程中提示输入 Apache 的位置, C:\apache-2.2.3 mod_python.so 被添加到 C:\apache-2.2.3\modules
修改 httpd.conf
LoadModule python_module modules/mod_python.so <Directory "C:/myweb"> SetHandler mod_python PythonHandler mod_python.publisher </Directory>
创建index.py文件
def index(name): return "Welcome %s" % name http://localhost/python/?name=huihoo (OK :)
下载 mod_python example
http://www.modpython.org/examples/psp_site.tgz http://localhost/psp_site/
[编辑] Database
DB-API 标准
[编辑] MySQL
http://sourceforge.net/projects/mysql-python/
获得 MySQL-python.exe-1.2.1_p2.win32-py2.4.exe 包安装到 C:\Python24\Lib\site-packages\MySQLdb
or Debian
#apt-get install python2.3-mysqldb >>> import MySQLdb >>> db = MySQLdb.connect("localhost","root","password","mysql") >>> cursor = db.cursor() >>> sql = "select * from db" >>> cursor.execute(sql) >>> data = cursor.fetchone() >>> print data >>> db.close()
[编辑] PostgreSQL
- psycopg: http://initd.org/projects/psycopg1
- pyPgSQL: http://pypgsql.sourceforge.net/
- PySQLite
- PyGreSQL
[编辑] Berkeley DB
- anydbm: Generic interface to DBM-style database modules.
- whichdb: Guess which DBM-style module created a given database.
- dbm: The standard ``database interface, based on ndbm.
- gdbm: GNU's reinterpretation of dbm.
- dbhash: DBM-style interface to the BSD database library.
- bsddb: Interface to Berkeley DB database library
- dumbdbm: Portable implementation of the simple DBM interface.
http://pybsddb.sourceforge.net/
>>> import anydbm >>> db = anydbm.open('cache', 'c') >>> db['www.python.org'] = 'Python Website' >>> db['www.huihoo.com'] = 'Open Source Community' >>> for k, v in db.iteritems():
print k, '\t', v
www.huihoo.com Open Source Community www.python.org Python Website
[编辑] SQLite
Python 2.5 内置了对 sqlite3 的支持- http://docs.huihoo.com/python/2.5/lib/module-sqlite3.html
[编辑] ORM/Persistence
[编辑] LDAP
[编辑] Modules
[编辑] C/C++
>>> import dl, time >>> a = dl.open('/lib/libc.so.6') >>> a.call('time') 1207223740
[编辑] 技巧
看一个module包含的函数
import sys content = dir(sys) print content
[编辑] 问题
'import site' failed; use -v for traceback
unable to open /usr/lib/python2.3/config/Makefile (No such file or directory)
#apt-get install python2.3-dev
[编辑] 应用
[编辑] 文档
- Python文档包含3.1.2, 3.1, 2.6.5, 2.5, 2.4.4, 2.4.3, 2.4.2, 2.4.1, 2.3.5, 2.3.4, 2.3.3, 2.3等版本文档。
- Python 研究(Dive Into Python)
- The Standard Python Library - http://www.effbot.org/librarybook/
- 用Python做科学计算
- The Hitchhiker's Guide to Python!