Python

来自开放百科 - 灰狐
(版本间的差异)
跳转到: 导航, 搜索
第89行: 第89行:
 
  Type "help", "copyright", "credits" or "license" for more information.
 
  Type "help", "copyright", "credits" or "license" for more information.
 
  >>>
 
  >>>
  ln -s /usr/local/lib/python2.4 /usr/bin/python
+
  ln -s /usr/local/bin/python2.4 /usr/bin/python
  
 
设置环境, 共存多个python版本, Default python version in Debian
 
设置环境, 共存多个python版本, Default python version in Debian

2007年3月7日 (三) 12:57的版本

Python-logo.gif

Python 最新版:2.5 , 下载最新版: http://download.huihoo.com/python/

Python 是一种面向对象的解释性的计算机程序设计语言,也是一种功能强大而完善的 通用型语言,已经具有十多年的发展历史,成熟且稳定。

Python-powered-w-100x40.png

At Google, python is one of the 3 "official languages" alongside with C++ and Java. Python at Google, Google Group, code.google.com 等服务基于 Python 构建。

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

有点意思 :)

目录

版本

Python框架

更多: Huihoo Python Applications

Python应用

Python and Grid

Python Web Services

Python IDE & Editor

更多 IDEs: http://wiki.python.org/moin/IntegratedDevelopmentEnvironments

pygame

Python Enhancement Proposals(PEPs)

PEPs 有点类似 Java JSRs

更多 PEPs : http://www.python.org/dev/peps/

Linux

Python 2.3 on Debian

Debian 3.1 安装后自带 Python 2.3.5

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

Debian

#apt-get install python2.3-psycopg // Python 2.3 module for PostgreSQL
or wget from http://www.initd.org/pub/software/psycopg/PSYCOPG-2-0/
#apt-get install python2.3-pygresql
su postgres
createdb test
python
>>> from pyPgSQL import PgSQL
>>> cx = PgSQL.connect(database="mydb", client_encoding="utf-8", unicode_results=1)
>>> cu = cx.cursor()
>>> cu.execute("set client_encoding to unicode")
>>> cu.execute("insert into test(v) values (%s)", (u'\x99sterreich',))
>>> cu.execute("select v from test")
>>> cu.fetchone()
[u'\x99sterreich']
>>>

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

pysqlite

ORM/Persistence

Modules

Python Modules

相关链接

联机文档

成功应用

分享您的观点
个人工具
名字空间

变换
操作
导航
工具箱