我有一个带有函数(lib.py)的python文件,没有类.每个功能都有以下风格:
def fnc1(a,b,c):
'''
This fonction does something.
:param a: lalala
:type a: str
:param b: hahaha
:type b: int
:param c: hohoho
:type c: int
:rtype: int
'''
print a
d = b + c
return d
Run Code Online (Sandbox Code Playgroud)
我只想用Sphinx记录每个功能(输入和输出).
在做了sphinx-quickstart之后,我用lib.py 在conf.py中定义了路径.但输出html文件(欢迎页面)为空.
如果我在index.rst写自己:
.. function:: func1(a,b,c)
This fonction does something.
:param a: lalala
:type a: str
:param b: hahaha
:type b: int
:param c: hohoho
:type c: int
:rtype: int
Run Code Online (Sandbox Code Playgroud)
没关系,它显示了html文件中的输入和输出.但是如何自动完成呢?
通常,我认为,必须在执行sphinx-apidoc -o之后在lib.rst中执行 …
我使用autodoc记录了一些函数.在当地它运作良好.当我提交GitHub时,文档是基于ReadTheDocs构建的,但是没有我用"automodule"记录的函数.
我在conf.py中添加了:
import mock
MOCK_MODULES = ['numpy', 'scipy']
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = mock.Mock()
Run Code Online (Sandbox Code Playgroud)
但它没有帮助.
这可能与我使用自己的C库这一事实有关吗?(我有我编译的.c文件来获取.so)
我有一个阵列.我想更换值> 5与1和值<= 5有0.我还必须考虑无效值(999).
1)我的阵列:
>>> import numpy
>>> a = numpy.array([ [[2, 5, 999],[0, 12, 1]], [[999, 8, 7],[7, 11, 6]] ])
>>> a
array([[[ 2, 5, 999],
[ 0, 12, 1]],
[[999, 8, 7],
[ 7, 11, 6]]])
Run Code Online (Sandbox Code Playgroud)
2)我屏蔽了无效值:
>>> mask_a = (a==999)
>>> a_masked = numpy.ma.masked_array(a, mask = mask_a)
>>> print a_masked
[[[2 5 --]
[0 12 1]]
[[-- 8 7]
[7 11 6]]]
Run Code Online (Sandbox Code Playgroud)
3)我用零替换值<= 5:
>>> a_masked[a_masked<=5]=0 …Run Code Online (Sandbox Code Playgroud) 我在conf.py中更改了项目的版本号:
version = '0.0.2'
Run Code Online (Sandbox Code Playgroud)
但是当我生成一个新的html(make html)时,版本始终是:0.0.1。
有什么建议么?