#!/usr/bin/python
import urllib
import sys
string = sys.argv[1]
string = unicode(string,"gbk")
utf8_string = string.encode("utf-8")
gbk_string=string.encode("gbk")
gbk=urllib.quote(gbk_string)
utf8=urllib.quote(utf8_string)
print gbk
print utf8

解码使用unqute和decode函数

Posted on April 13, 2007 8:35 PM | | Comments (0) | TrackBacks (0)

早就听说python是一个十分不错的脚本语言,语法简洁而且开发效率很高。在从http://www.python.org下 载了最新的windows版本的python解释器后,我又从eclipse的插件网下了pydev这个支持Python在Eclipse开发的插件。 Python虽然是unix/linux下的东西,但是由于其执行和编写都很简单,所以在时常工作中能够快速解决一些小问题。同时,对于以后我需要研究算 法,做论文的时候,也可以用python来快速开发一个算法的测试demo,尽量不必纠缠于程序具体实现时候的困难。

Continue reading "使用python为Java项目增加一个预编译脚本[转]"
Posted on March 25, 2007 1:12 PM | | Comments (0) | TrackBacks (0)

Develop for the Web with Django and Python

The Python Django Web framework, from install to finished Web site


Level: Intermediate

Ian Maurer (ian@itmaurer.com), Senior Consultant, Brulant, Inc.

06 Jun 2006

In this first article of a two-part series, we show off Django, an open-source model-view-controller (MVC)-style Web application framework powered by the Python programming language. With Django, you can create high-quality, easy-to-maintain, database-driven Web applications in minutes.

The Django project is a custom-built framework that originated with an online newspaper Website and was released as open source in July 2005. The core components of the Django framework are:

  • Object-relational mapping for creating models
  • Polished administrator interface designed for end users
  • Elegant URL design
  • Designer-friendly template language
  • Caching system

This is the first article in a two-part series on Python Web frameworks. The secord article will introduce you to the TurboGears framework.

To use and understand the code in this article, you need to have Python installed and know how to use it at a beginner level. Check to see if you have Python, and what version, by typing python -V. Django requires, at a minimum, version 2.3.5, which is available at the Python Web site (see the Resources section later in this article for a link). You should also be at least passingly familiar with the MVC architecture.

Continue reading "Python Web frameworks, Part 1"
Posted on February 8, 2007 9:53 PM | | Comments (1) | TrackBacks (0)

Web development with TurboGears and Python

An online shopping application illustrates the basics

Level: Intermediate

Ian Maurer (ian@itmaurer.com), Senior Consultant, Brulant, Inc.

11 Jul 2006

In this second article of a two-part series, we demonstrate TurboGears, another open source MVC-style Web application framework based on Python. Where the first article was an introduction to the Django framework, this article shows how to use TurboGears to create a Web-based shopping application and concludes with a comparison between Turbogears and Django.

The TurboGears developers call this project a "megaframework," because it is made up of several pre-existing subprojects. TurboGears helps glue together a number of main components:

  • MochiKit: JavaScript library
  • Kid: Templating language
  • CherryPy: Base Web framework
  • SQLObject: Object-relational mapper (ORM)
Continue reading "Python Web frameworks, Part 2"
Posted on February 8, 2007 9:47 PM | | Comments (0) | TrackBacks (0)

在各种开放源代码系统中,内容管理领域的火拼可能是最严重的了。最早的包括PHPNuke、XOOPS,到现在包括Drupal、Mambo,开源内容管理系统不下30多种。


在激烈的竞争中,Plone(plone.org)逐步脱颖而出。Plone基于发展多年的web应用服务器Zope和内容管理框架CMF。站在巨 人的肩膀上,Plone拥有强大的特性,包括易用、灵活的工作流引擎,能够对用户进行分组管理,还可以对内容的元数据、皮肤、文本格式转换、评注及讨论等 进行管理。


2002年,Plone 1.0刚出来,就在开源内容管理大会(OSCOM)得到好评。2003年Plone做为O'Relly首选的开源项目代表参与了COMDEX大会,成为开源社区的一只黑马。


2004年,Plone 2.0发布。Plone得到众多媒体的赞誉。Plone被eWeek杂志评定为2004年度10个最佳产品; InformationWeek则评论Plone是一个世界级的内容管理系统。同时,冠群公司(CA)也将Plone列为首批开放源代码资助项目之一,并 在Plone基金会中占有董事席位。


2005年8月份,Plone 2.1发布。Plone 2.1在易用性上进一步大大改善,性能也成倍提升,主要内容采用基于语义引擎Archetypes编写。Plone 2.1是Plone发展史上的一个让用户能够流畅使用的重要产品。


Plone拥有庞大的社区,Plone的核心开发人员来自全世界各个国家,多达近百人。这注定Plone是一个世界级的产品。Plone支持40多种语言。安装中文支持插件后,Plone能够全面支持中文,包括中文搜索、中文标题到拼音ID的转换等。


Plone之所以流行,另外和Plone注重市场和用户需求有关系。Plone拥有简洁的工业级的界面,她第一眼就会吸引你;Plone拥有"傻瓜"型的windows安装程序,你可迅速下载使用;Plone十分易用,你不必专门的学习就可掌握。


另外,Plone也非常注重符合标准,包括W3C的xhtml、CSS和美国政府的网站可达性指南方面的条款。Plone的网站可用于各种浏览器。


Plone内置基于内容语义引擎Archetypes的开发框架,大大简化了Plone的扩展开发过程,也解决了Zope 2/CMF扩展开发学习曲线陡的问题。掌握Plone的开发,需要掌握Python语言、Zope的页面模板语言,以及Archetypes扩展开发框 架。


Plone拥有丰富的扩展产品,包括论坛、Blog、Wiki、投票、问卷、考试、Portlet、版本管理、邮件列表等。Plone团队谨慎选择产品,不断丰富自己的核心。


Plone现在也逐步走向更加激动人心的技术,那就是新一代的基于组件框架的Zope 3应用服务器技术以及AJAX人机界面技术。即将正式发布的Plone 2.5版本,使用Zope 3的技术重新改写了大量内核;而计划在2007年初发布的Plone 3.0则将更加侧重用户界面改善,AJAX技术的大量引入是这个版本的重要亮点。Plone的发展空间是无限广阔的。


Plone可用于有着严格要求的很多大型的网站,包括政府、跨国公司的网站。美国农业部和能源部门就是Plone的用户,巴西政府的下议院、瑞士首 都 borne均采用Plone构建门户网站;其他的大型案例,包括迪斯尼公司的知识管理系统、摩托罗拉、牛津饥荒救济会的网站、BMC(全球第五大独立软件 公司)的门户网站。


在国内,中文Zope/Plone用户组(www.czug.org)是专业中文Plone技术社区。国内的Plone应用已经逐步开花,包括网易知识门户系统、上海航空公司、上海电信、光大银行南京分行、文化部文化共享工程主站等众多案例。


Posted on February 8, 2007 6:06 PM | | Comments (0) | TrackBacks (0)

前身应该是所谓ZMapServer,基于MapServer的Python封装,目前改名为这个名字,包括2个项目:

PrimaGIS


Create web maps for Plone using OGC compliant web services or a variety of locally hosted GIS data backends, including your Plone site catalog.


Python Cartographic Library


Packages for programming applications such as PrimaGIS, or for use with the Python web framework of your choice.



后者是基础类库,前者是一个WebGIS应用。特点包括:



  • Geo-aware proxy objects for spatially enabling any ArcheTypes based content object, that allows them to be used as data for the map without need for modify the original objects.

  • IGeoAware interface for making custom objects work as spatial data for PrimaGIS maps.

  • AJAX style background communication  for efficient map rendering. All AJAX (and DOM) operations are done using the excellent MochiKit library.

  • Info-on-map using JavaScript popups with the overlib-library. Moving on location on the map will popup a small window showing information for the referred object(s).

  • Extension classes for ArcheTypes developers for creating natively geo-aware objects usable as-is with PrimaGIS. See the Making existing AT objects IGeoAWare article for a simple example or take a look at the GeoAwareObjects product.

  • Zooming, drag panning, previous view, session-based default view.

  • Named views for creating easy access to points of interest on the maps. The views (PrimaGISView objects) also implement the IGeoAware interface, so you can just put them in a PrimaGISDataLayer to visualize them on the map in addition to using them for navigation. This is demonstrated in the demo map's "Areas of interest" layer.

  • Export of PrimaGISDataLayers to Geography Markup Language (GML). See http://www.primagis.fi/demo/index_html/capitals/data.gml for a GML dump of the "European capitals" layer for an example. Using a tool, such as ogr2ogr, you can easily convert the GML file to other vector formats, e.g. shapefile.

  • Export of PrimaGISDataLayers to Keyhole Markup Language (KML) for use with Google Earth. You can try out the feature by adding a new Network Link to your Google Earth client using http://www.primagis.fi/demo/index_html/capitals/data.kml as the URL.



  • Works with both Plone 2.0 and 2.1 series and Zope 2.7 and 2.8 series. Tested with Zope 2.7.8/Plone 2.0.5 and Zope 2.8.4/Plone 2.1.1.


站点的Demo还不错,不过Ajax的效果只是后台异步调用数据,地图还没有做到分块(几个商业IMS产品也没有),呵呵。

看来开源GIS是选择越来越多,系统架构也越来越好了。

原文出处:http://www.cnblogs.com/maweifeng/archive/2006/02/02/324927.html

Posted on February 8, 2007 5:59 PM | | Comments (1) | TrackBacks (0)

#!/usr/bin/env python
# -*-coding:UTF-8-*-#这一句告诉python用UTF-8编码
#=========================================================================
#
# NAME: Python MySQL test
#
# AUTHOR: benyur
# DATE  : 2004-12-28
#
# COMMENT: 这是一个python连接mysql的例子
#
#=========================================================================

"""
 ***** This is a MySQL test *****
 
 select:
  conn=Connection()
  conn.select_db('test')
  cur=conn.cursor()
  cur.execute('select * from user')
  cur.scroll(0)
  row1=cur.fetchone()
  row1[0]
  row1[1]
  row1[2]
  
 insert:
  cur.execute('insert into user (name,passwd) values(\'benyur\',\'12345\')')
  cur.insert_id()
  
 update:
  cur.execute('update user set passwd=\'123456\' where name=\'benyur\'')
  
 delete:
  cur.execute('delete from user where id=2')
 
 **********************************
"""


from MySQLdb import *


def conn():
 conn=Connection()
 conn.select_db('test')
 cur=conn.cursor()
 cur.execute('select * from user')
 cur.scroll(0)
 row1=cur.fetchone()
 row1[0]
 row1[1]
 row1[2]


def usage():
 print __doc__


if __name__=='__main__':
 usage()



MySQLdb下载地址:http://sourceforge.net/projects/mysql-python/
下载解压缩后放到%Python_HOME%\Lib\site-packages目录中,python会自动找到此包。
MySQLdb基本上是MySQL C API的Python版,遵循Python Database API Specification v2.0。

Continue reading "Python连接MySQL"
Posted on February 8, 2007 5:43 PM | | Comments (0) | TrackBacks (0)

本文将就自己在安装 最新版本的 Zope 2.4.1 和 SquishDot 1.3.0 中的心得写出来和大家共享。
如果你想五分钟架构一个真正的内容发布网站,非 Zope+SquishDot 莫属了。

一、下载软件:
Zope: http://www.zope.org/Products/Zope/2.4.1
SquishDot: http://www.squishdot.org/
FastCGI: http://www.fastcgi.com/

二、安装:
假设把 Zope 安装到 /usr/local ,那么:
#cd /usr/local
#tar xvfz Zope-2.4.1-XXX.tgz
#cd Zope-2.4.1-XXX
#cd lib/python/Product
#tar xvfz Squishdot-1.3.0.
#cd - (回到 /usr/local/Zope-2.4.1-XXX 目录)
#groupadd www (假设Apache 用户使用 www.www 运行)
#useradd Zope (用于跑 Zope 进程)
#./install -u Zope -g www
出现一些编译错误,可以忽略
#vi start
在 -D 前面加上 -u Zope ,
在最后面加上 & 符号,让 Zope 在后台启动。
#vi z2.py
找到 FCGI= 所在的行,把 None 修改为 '8888' ,注意,一定要加单引号!
然后,start 就可以在浏览器测试 http://localhost:8080/ 的效果了。
这样 Zope 已经架构完成,Squishdot 的功能需要到 Zope 的管理界面才能去完成。
因此要首先进入 http://localhost:8080/manage/ ,这时候,提示输入用户名和密码,
前面 ./install 的时候,其实有提醒过 admin 用户的密码的,如果你没有记下来,没有关系的。
进入 Zope 所在的目录。
#./bin/python zpasswd.py -umy_admin_name -pmy_passwd inituser 就可以了。
#./stop;./start 重新启动 Zope 。
这样你就可以用新的用户名和密码进行管理了。(以后每次有密码更改,需要重新启动Zope)
在右边的下拉框中,选择添加 Squishdot 站点,系统会要求输入 ID 和 Title ,只要输入你自己网站的名字和标题,假设名字为 publish ,那么访问:
http://localhost:8080/publish 就可以看到一个 Squishdot 站点已经克隆出来。恭喜你了!

三、和 Apache 集成
前面提到了 fastcgi 和 8888 端口,但是还没有用到过,这两个东东,就是 Zope 和 Apache 集成用的。
我们知道普通的 CGI ,每一个客户连接需要 spawn 一个新的进程,十分消耗系统资源, FastCGI,就是克服这样的毛病的,在一定的时间内, FastCGI 不会开很多进程。Zope 自己提供有 PCGI ,有同样的功能,但是速度比较慢,要不,我们要采用的这个模块怎么能叫 Fast 呢?

具体的集成过程,请看后面的文章:

http://www.freelamp.com/new/publish/1003254725

  作者 徐永久

Posted on February 6, 2007 10:05 PM | | Comments (0) | TrackBacks (0)

原地址: http://bbs.chinaunix.net/viewthread.php?tid=553745
官方网站 
http://www.python.org/
PyUnit - the standard unit testing framework for Python
http://pyunit.sourceforge.net/
Mark Hammond's Free Stuff
http://starship.python.net/crew/mhammond/
Python for Windows extensions
https://sourceforge.net/projects/pywin32/
wxPython
http://www.wxpython.org/
The ctypes module
http://starship.python.net/crew/theller/ctypes/
ActiveState Programmer Network
http://aspn.activestate.com/ASPN/Python
py2exe
http://starship.python.net/crew/theller/py2exe/
Zope
http://www.zope.org
Plone
http://plone.org/
中文Zope用户组
http://www.czug.org/
Zope and Plone Content Management Software , products directory
http://www.contentmanagementsoftware.info/
JOTWeb Web Application System
http://jotweb.tummy.com/
Twisted
http://twistedmatrix.com/
zwiki
http://zwiki.org/FrontPage
Dive Into Python
http://diveintopython.org/
Python 编程系列  
http://www-128.ibm.com/developerworks/cn/linux/theme/special/#python
jython
http://www.jython.org/
Python中文社区
http://python.cn/
中蟒
http://www.chinesepython.org/cgi_bin/cgb.cgi/home.html
啄木鸟 Pythonic 开源社区
http://www.woodpecker.org.cn/ 
深入Python 中文版
http://cn.diveintopython.org/toc.html
Writing PyGTK applications in a visual way
http://primates.ximian.com/~sandino/python-glade/ 
python 中文手册
http://i18n.linux.net.cn/others/python2.3tut/tut/
python电子书下载地址列表
http://www.miex.org/book.html
Python Imaging Library Handbook for 1.1.4
http://www.pythonware.com/library/pil/handbook/index.htm
Tkinter
http://www.pythonware.com/library/tkinter/introduction/index.htm
Thinking in Python
http://www.mindview.net/Books/TIPython
Non-Programmers Tutorial For Python
http://www.honors.montana.edu/~jjc/easytut/easytut/
Magnus’s Python Page
http://hetland.org/python/ 
简明 Python 教程
http://www.byteofpython.info/language/chinese/index.html 
MyPython.Net
http://www.mypython.net/ 
Tkinter视频教程
http://wiki.python.org/moin/Intro_to_programming_with_Python_and_Tkinter

Posted on December 1, 2006 10:36 PM | | Comments (0) | TrackBacks (0)
上一页 1 2 3 4 5 6 7 下一页
相关内容
广告计划
最新评论
[评论] 鸿雁 : 默默地为他们祈祷吧
[评论] lym328 : 客源CRM非常不错-----如有需要可以了解
[评论] kevinwu : 作用肯定是有的,Google会首先搜索站
[评论] ss : 其实还真的感觉不到sitemap的作用~
[评论] kevinwu : 谢谢你的关注 :-)
[评论] h51h : 贵博客写得非常的好,界面简洁但内
[评论] snguo : 这里很好 来这里支持下呢?
[评论] redondo : 感谢你分享知识! 这篇文章我转载到
[评论] kevinwu : 就是这本;看来我买的贵了点 - 8折;我
[评论] 安妮 : 《Flex3.0 RIA开发详解:基于ActionScript3.0