我想要一个属性调用,比如object.x返回一些方法的结果object.other.other_method().我怎样才能做到这一点?
编辑:我很快就问了一下:看起来我可以这样做
object.__dict__['x']=object.other.other_method()
Run Code Online (Sandbox Code Playgroud)
这是一个好方法吗?
跑步时
sphinx-build . html/
Run Code Online (Sandbox Code Playgroud)
在我的doc/目录中,我得到以下输出:
$ sphinx-build . html/
Running Sphinx v0.6.4
No builder selected, using default: html
loading pickled environment... done
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
reading sources... [100%] index
reST markup error:
HIDDEN/PATH/matplotlib_visualization.py:docstring of simulator.extensions.matplotlib_visualization.beta:20: (SEVERE/4) Unexpected section title.
Run Code Online (Sandbox Code Playgroud)
这个文件有numpy导入,经过一些研究,似乎 sphinx 使用的 RST 标记在记录方式上有问题numpy。当我取出 numpy 导入时,html 构建良好。
解决此问题的最佳方法是什么?
我想要一些相当于的东西
calling method: $METHOD_NAME
args: $ARGS
output: $OUTPUT
Run Code Online (Sandbox Code Playgroud)
logging为每个(用户定义的)方法调用自动记录到文件(可能通过模块).我能想到的最好的解决方案是编写一个装饰器来执行此操作,然后将其添加到每个函数中.有没有更好的办法?
谢谢
我正在研究这个unittest包,并且我不确定在为同一个方法编写大量测试用例时构建测试用例的正确方法.假设我有一个fact计算数字阶乘的函数; 这个测试文件可以吗?
import unittest
class functions_tester(unittest.TestCase):
def test_fact_1(self):
self.assertEqual(1, fact(1))
def test_fact_2(self):
self.assertEqual(2, fact(2))
def test_fact_3(self):
self.assertEqual(6, fact(3))
def test_fact_4(self):
self.assertEqual(24, fact(4))
def test_fact_5(self):
self.assertFalse(1==fact(5))
def test_fact_6(self):
self.assertRaises(RuntimeError, fact, -1)
#fact(-1)
if __name__ == "__main__":
unittest.main()
Run Code Online (Sandbox Code Playgroud)
对于一种方法有这么多测试方法似乎很草率.我想只有一个测试方法,并放置了大量的基本测试用例(即4!== 24,3!== 6,5!== 120,依此类推),但是unittest不允许你去做.
在这种情况下构建测试文件的最佳方法是什么?
在此先感谢您的帮助.
我运行了两个程序,一个用Python编写,另一个用C++编写,我需要在它们之间共享一个二维数组(只是十进制数).我目前正在研究序列化,但pickle遗憾的是它是特定于python的.做这个的最好方式是什么?
谢谢
编辑:阵列很可能只有50个元素左右,但数据传输需要非常频繁地发生:每秒60次或更多.