如果我想在ipython中重新定义先前定义的类的成员,我想知道一个好的方法.说:我已经定义了类下面的类介绍,后来我想重新定义函数定义_print_api的一部分.没有重新输入它的任何方式.
class intro(object):
def _print_api(self,obj):
def _print(key):
if key.startswith('_'):
return ''
value = getattr(obj,key)
if not hasattr(value,im_func):
doc = type(valuee).__name__
else:
if value.__doc__ is None:
doc = 'no docstring'
else:
doc = value.__doc__
return ' %s :%s' %(key,doc)
res = [_print(element) for element in dir(obj)]
return '\n'.join([element for element in res if element != ''])
def __get__(self,instance,klass):
if instance is not None:
return self._print(instance)
else:
return self._print_api(klass)
Run Code Online (Sandbox Code Playgroud) 我想知道python2.5,pysqlite和apsw的 sqlite3之间的区别?当我尝试使用python2.5在windows vista上安装pysqlite时,我有一个颠簸的运行,请参阅以下内容:
windows/system32文件夹中并将sqlite3.dll放入c:/python25/Lib文件夹当试图在python shell中运行以下时:
>>> from pysqlite2 import test
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pysqlite2\test\__init__.py", line 35, in <module>
from pysqlite2.test import dbapi, types, userfunctions, factory, transactions,\
File "pysqlite2\test\dbapi.py", line 27, in <module>
import pysqlite2.dbapi2 as sqlite
File "pysqlite2\dbapi2.py", line 27, in <module>
from pysqlite2._sqlite import *
ImportError: No module named _sqlite
Run Code Online (Sandbox Code Playgroud)我想知道任何有以上三种类型的sqlite绑定到python的经验可以评论他们的优点和缺点如表演我想知道是否值得尝试pysqlite或apsw
谢谢
我正在使用openbabel的 swig包装器(用C++编写,并通过swig提供python包装器)
下面我只是用它来读取分子结构文件并获得它的unitcell属性.
import pybel
for molecule in pybel.readfile('pdb','./test.pdb'):
unitcell = molecule.unitcell
print unitcell
|..>
|..>
<openbabel.OBUnitCell; proxy of <Swig Object of type 'OpenBabel::OBUnitCell *' at 0x17b390c0> >
Run Code Online (Sandbox Code Playgroud)
unitcell具有CellMatrix()功能,
unitcell.GetCellMatrix()
<22> <openbabel.matrix3x3; proxy of <Swig Object of type 'OpenBabel::matrix3x3 *' at 0x17b3ecf0> >
Run Code Online (Sandbox Code Playgroud)
OpenBabel :: matrix3x3是这样的:
1 2 3
4 5 6
7 8 9
Run Code Online (Sandbox Code Playgroud)
我想知道如何打印矩阵3*3的内容.我曾尝试__str__与__repr__它.
在python中使用swing包装的矩阵的内容的任何一般方法?
谢谢
我有一台机器安装了我常用的python包.我想在另一台机器或具有不同python版本的同一台机器上安装相同的软件包.我想知道pip或easy-install或其他方法是否允许我批量安装这些软件包.当我使用perl时,它有类似bundle包,如何在python中做到这一点?