URN Logo
UNIX Resources » Linux » China Linux Forum » Python 编 程 » 10 » python可以调用.so或.a库吗
announcement 声明: 本页内容为中国Linux论坛的内容镜像,文章的版权以及其他所有的相关权利属于中国Linux论坛和相应文章的作者,如果转载,请注明文章来源及相关版权信息。
Resources
China Linux Forum(finished)
Linux Forum(finished)
FreeBSD China(finished)
linuxforum.net
  业界新闻与评论
  自由软件杂谈
  IT 人生
  Linux软件快递
  翻译作坊
  Linux图书与评论
  GNU Emacs/XEmacs
  Linux 中文环境和中文化
  Linux桌面与办公软件
  Linux 多媒体与娱乐版
  自由之窗Mozilla
  笔记本电脑上的Linux
  Gentoo
  Debian 一族
  网络管理技术
  Linux 安装与入门
  WEB服务器和FTP服务器
  域名服务器和邮件服务器
  Linux防火墙和代理服务器应用
  文件及打印服务器
  技术培训与认证
  Linux内核技术
  Linux 嵌入技术
  Linux设备驱动程序
  Linux 集群技术
  LINUX平台数据库
  系统和网络安全
  CPU 与 编译器
  系统计算研究所专栏
  Linux下的GUI软件开发
  C/C++编程版
  PHP 技 术
  Java&jsp技术
  Shell编程技术
  Perl 编 程
  Python 编 程
  XML/Web Service 技术
  永远的Unix
  FreeBSD世界
   
python可以调用.so或.a库吗
python可以调用.so或.a库吗 - gutounan [2005-04-27 11:35 | 158 byte(s)]
 
Re: python可以调用.so或.a库吗 - jfwan [2005-05-11 10:13 | 76 byte(s)]
 
Re: python可以调用.so或.a库吗 - limodou [2005-04-27 11:45 | 129 byte(s)]
 
Re: python可以调用.so或.a库吗 - gutounan [2005-04-27 12:18 | 1,216 byte(s)]
 
Re: python可以调用.so或.a库吗 - limodou [2005-04-27 12:37 | 432 byte(s)]
 
Re: python可以调用.so或.a库吗 - gutounan [2005-04-27 12:53 | 58 byte(s)]
 
Re: python可以调用.so或.a库吗 - nyliubing [2005-04-27 22:40 | 1,060 byte(s)]
 
Subject: python可以调用.so或.a库吗
Author: gutounan    Posted: 2005-04-27 11:35    Length: 158 byte(s)
[Original] [Print] [Top]
我有几个自己作的.so和.a文件
这几个库很重要并且不能用python重写
因为里头封装了很多的ioctl调用
请问如何在python中使用他们呢
[Original] [Print] [Top]
Subject: Re: python可以调用.so或.a库吗
Author: limodou    Posted: 2005-04-27 11:45    Length: 129 byte(s)
[Original] [Print] [Top]
.so的应该可以。建议你看一下 ctypes 模块(需要去google上搜),它提供跨平台的动链接库的直接调用。windows下是dll,*nix下是.so或.sl吧。
----
[Original] [Print] [Top]
Subject: Re: python可以调用.so或.a库吗
Author: gutounan    Posted: 2005-04-27 12:18    Length: 1,216 byte(s)
[Original] [Print] [Top]
非常好使
doc:http://starship.python.net/crew/theller/ctypes/tutorial.html

SamSuSE9:/usr/lib/python2.3/site-packages/ctypes # python
Python 2.3.4 (#1, Oct 5 2004, 00:26:51)
[GCC 3.3.4 (pre 3.3.5 20040809)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> libc = cdll.LoadLibrary("/lib/libc.so.6")
>>> libc._
libc._CdeclFuncPtr libc.__getitem__ libc._handle
libc.__class__ libc.__init__ libc._name
libc.__doc__ libc.__module__
libc.__getattr__ libc.__repr__
>>> libc._
libc._CdeclFuncPtr libc.__getitem__ libc._handle
libc.__class__ libc.__init__ libc._name
libc.__doc__ libc.__module__
libc.__getattr__ libc.__repr__
>>> myp = libc.__getitem__("printf")
>>> myp("hehe%d", 199)
hehe1997
>>>
[Original] [Print] [Top]
Subject: Re: python可以调用.so或.a库吗
Author: limodou    Posted: 2005-04-27 12:37    Length: 432 byte(s)
[Original] [Print] [Top]
我都没用过呢:)
不过你的用法有些怪:
myp = libc.__getitem__("printf")
我看可以写成:
libc["printf"]
你可以试试,这样会好看多了。因为前后带双下划线的一般是特殊用法,象__getitem__相当于["name"]的用法__getattr__相当于.name的用法。因此上面应该还可以写成:
libc.printf

这样:
libc.printf("hehe%d", 199)可能会更好。 
----
[Original] [Print] [Top]
Subject: Re: python可以调用.so或.a库吗
Author: gutounan    Posted: 2005-04-27 12:53    Length: 58 byte(s)
[Original] [Print] [Top]
多多谢过
在下彻底的初学者
呵呵
[Original] [Print] [Top]
Subject: Re: python可以调用.so或.a库吗
Author: nyliubing    Posted: 2005-04-27 22:40    Length: 1,060 byte(s)
[Original] [Print] [Top]
好文,感谢gutounan,我也很需要啊
>>> import ctypes
>>> dir(ctypes)
['ARRAY', 'Array', 'CDLL', 'CFUNCTYPE', 'FormatError', 'GetLastError', 'OleDLL', 'POINTER', 'SetPointerType', 'Structure', 'Union', 'WINFUNCTYPE', 'WinDLL', 'WinError', '_CFuncPtr', '_DLLS', '_FUNCFLAG_CDECL', '_FUNCFLAG_HRESULT', '_FUNCFLAG_STDCALL', '_FreeLibrary', '_LoadLibrary', '_Pointer', '_SimpleCData', '__builtins__', '__doc__', '__file__', '__name__', '__path__', '__version__', '_os', '_pointer_type_cache', 'addressof', 'byref', 'c_buffer', 'c_byte', 'c_char', 'c_char_p', 'c_double', 'c_float', 'c_int', 'c_long', 'c_longlong', 'c_short', 'c_ubyte', 'c_uint', 'c_ulong', 'c_ulonglong', 'c_ushort', 'c_void_p', 'c_voidp', 'c_wchar', 'c_wchar_p', 'cdll', 'oledll', 'pointer', 'sizeof', 'sys', 'windll']
>>> GMS=ctypes.cdll.LoadLibrary("e:\contour\GMS.dll")
>>> trace=GMS["trace_contour"]
>>> trace(...)
----
我爱夜空的高远,我爱琴声的冷冽
[Original] [Print] [Top]
Subject: Re: python可以调用.so或.a库吗
Author: jfwan    Posted: 2005-05-11 10:13    Length: 76 byte(s)
[Original] [Print] [Top]
可以这样:
printf = libc.printf
printf("hello ")
----
重在理解,轻在实现!
[Original] [Print] [Top]
« Previous thread
初学wxPython疑问
Python 编 程
10
Next thread »
如何安装wxPython和wxGlade
     

Copyright © 2007 UNIX Resources Network, All Rights Reserved.      About URN | Privacy & Legal | Help | Contact us
备案序号: 京ICP备05006143    webmaster: webmaster@unixresources.net
This page created on 2008-07-17 04:11:14, cost 0.041176080703735 ms.