怎么安装python 的扩展库-suds?

Python010

怎么安装python 的扩展库-suds?,第1张

首先建议你安装一个扩展库安装工具,推荐easy_install工具,你可以在网上下载,也可以先去下载一个 ez_setup.py ,这个程序下载后用python.exe运行一下,会自动根据你的版本帮你下载和安装一个easy_install,目前只支持到python2.6,看来python3目前还是没有太多的公司在使用啊。。。

后面就可以用这个easy_install工具进行第三方库的下载了,比如我要下载soaplib这个库,可以执行easy_install soaplib,它会自己去相关网站查找这个库,以及这个库的依赖,如果你手工安装,那依赖会把你搞疯掉的

关于哪个库更适用做webservice

现在网上查到最多的是ZSI或者叫soappy,实际上05年之后就没有更新了,而且只支持到2.5,放弃

soaplib,这个目前2.0,还是不错的,不过手册不是太好读,只有server端的用法,client我没找到suds,这个我在用,用起来比较简单,示例代码如下:

[python] view plain copy

The library is now ready to use. We start by importing the suds library, creating a client based on a SOAP url, and asking the library to print the SOAP web service methods that are available to us.

import suds

url = "http://www.ecubicle.net/iptocountry.asmx?wsdl"

client = suds.client.Client(url)

print client

From the output of the last print command, we learn that there is a method called FindCountryAsString that takes one argument: the IP address.

print client.service.FindCountryAsString("194.145.200.104")

And it shows (edited for readability):

<?xml version="1.0"?>

<IPAddressService>

<country>Netherlands</country>

</IPAddressService>

Normally you want to have the contents of the SOAP body. This is what suds provides in a very elegant way. However, you’re a bit stuck when you want to get something from the SOAP header. The author of suds realised this and made a backdoor to get the information anyway. We start by showing what the function last_received contains:

print client.last_received()

<?xml version="1.0" encoding="UTF-8"?>

<soap:Envelope>

<soap:Header>

<ResponseHeader xmlns="">

<resultCode>1000</resultCode>

<resultDescription>Success</resultDescription>

</ResponseHeader>

</soap:Header>

<soap:Body>

...

</soap:Body>

</soap:Envelope>

We can get portions of this data by doing some XML handling. Let’s say we want to print the resultCode:

print client.last_received().getChild("soap:Envelope").getChild("soap:Header")

.getChild("ResponseHeader").getChild("resultCode").getText()

就算你的项目中有大量的Python代码,你也依旧可以有条不紊地通过将其分离为多个文件或模块加以组织管理。而且你可以从一个模块中选取代码,而从另一个模块中读取属性。更棒的是,对于所有模块,Python的访问语法都是相同的。不管这个模块是Python标准库中的还是你一分钟之前创造的,哪怕是你用其他语言写的扩展都没问题!借助这些特点,你会感觉自己根据需要“扩展”了这门语言,而且你已经这么做了。

代码中的瓶颈,可能是在性能分析中总排在前面的那些热门或者一些特别强调性能的地方,可以作为Python扩展用C重写。需要重申的是,这些接口和纯Python模块的接口是一模一样的,乃至代码和对象的访问方法也是如出一辙的。唯一不同的是,这些代码为性能带来了显著的提升。自然,这全部取决你的应用程序以及它对资源的需求情况。很多时候,使用编译型代码重写程序的瓶颈部分绝对是益处多多的,因为它能明显提升整体性能。

程序设计语言中的这种可扩展性使得工程师能够灵活附加或定制工具,缩短开发周期。虽然像C、C++乃至Java等主流第三代语言(3GL)都拥有该特性,但是这么容易地使用C编写扩展确实是Python的优势。此外,还有像PyRex这样的工具,允许C和Python混合编程,使编写扩展更加轻而易举,因为它会把所有的代码都转换成C语言代码。

因为Python的标准实现是使用C语言完成的(也就是CPython),所以要使用C和C++编写Python扩展。Python 的Java实现被称作Jython,要使用Java编写其扩展。最后,还有IronPython,这是针对.NET或Mono平台的C#实现。你可以使用C#或者VB.Net扩展IronPython.