NumpyDoc:标签是如何解析的?

2024-04-20 11:00:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Spyder IDE(Mac OS上的v.2.1.11)并编写一些代码,在为函数编写DocString(NumpyDoc格式)时,无法理解Spyder对象检查器以这种奇怪的方式格式化缩进行的原因。你知道吗

对于下面这样的Docstring,sellmeier计算的“后的参考文件。。。缩进了,这导致了奇怪的行为:

def AlInGaAs(x, wl):
'''
Returns the refractive index of ~Al(x)Ga(1-x)In(1-x-y)As (lattice-matched to InP) at the specified wavelength, wl (in microns) and Aluminum content (x=0.0-1.0).  

For lattice-matching, the actual mole ratio, x, is defined as so:
InP-matched X: (Al48 In52 As)_X --> (Ga47 In53 As)_1-X

Valid for wavelengths: 0.900 - 2.100 um  &  x: 0.3 - 1.0

Calc'd by sellmeier equation, with params from
    M. J. Mondry, D. I. Babic, J. E. Bowers, and L. A. Coldren, "Refractive indexes of (Al,Ga,In)As epilayers on InP for optoelectronic applications," Phot. Tech. Lett., vol. 4, no. 6, pp. 627-630, 1992

Parameters
----------
x: float
    Mole ratio of Al, as in: Al(x) Ga(1-x) In(1-x-y) As.  Also varies In slightly for lattice-matching.

wl: float
    wavelength in microns.

...

'''

上面的DocString生成以下输出(Spyder“Object Inspector”/帮助面板的屏幕截图),在“M.J.Mondry,D.I.Babic”上有意外的加粗和缩进/列表编号。。。“文本:

Strange indentation and listing of the Paper Reference.

删除缩进时,如下所示:

def AlInGaAs(x, wl):
'''
Returns the refractive index of ~Al(x)Ga(1-x)In(1-x-y)As (lattice-matched to InP) at the specified wavelength, wl (in microns) and Aluminum content (x=0.0-1.0).  

For lattice-matching, the actual mole ratio, x, is defined as so:
InP-matched X: (Al48 In52 As)_X --> (Ga47 In53 As)_1-X

Valid for wavelengths: 0.900 - 2.100 um  &  x: 0.3 - 1.0

Calc'd by sellmeier equation, with params from
*** INDENT REMOVED BELOW ***
M. J. Mondry, D. I. Babic, J. E. Bowers, and L. A. Coldren, "Refractive indexes of (Al,Ga,In)As epilayers on InP for optoelectronic applications," Phot. Tech. Lett., vol. 4, no. 6, pp. 627-630, 1992

Parameters
----------
x: float
    Mole ratio of Al, as in: Al(x) Ga(1-x) In(1-x-y) As.  Also varies In slightly for lattice-matching.

wl: float
    wavelength in microns.

...

'''

看起来很正常,所以:

Object Inspector with un-Indented paper reference

这只是Spyder中的一个bug,还是缩进的其他预期用途?在Spyder IDE中,应该如何使用(或不使用)缩进来生成各种类型的格式(我假设是NumpyDoc格式)?
我在NumpyDoc Documentation Page上没有看到任何关于缩进和自动列表的讨论。你知道吗

只是想知道是否有一些有用的未记录的DocString功能,我可以在这里利用。 (另一方面,我注意到我可以使用DocString中的“References”部分,我会在某个时候将Ref移到其中。)

谢谢!你知道吗

我的版本如下: Spyder v2.1.11版, 达尔文上的Python 2.7.6、Qt 4.8.4、PyQt4(API v2)4.9.6, Mac OS 10.10.2


Tags: oftheinforasdocstringalinp
1条回答
网友
1楼 · 发布于 2024-04-20 11:00:36

Spyder dev here)我已经设法通过如下方式重新格式化docstring来获得(我认为)您想要的内容

def AlInGaAs(x, wl):
'''
Returns the refractive index of ~Al(x)Ga(1-x)In(1-x-y)As (lattice-matched
to InP) at the specified wavelength, wl (in microns) and Aluminum content
(x=0.0-1.0).  

For lattice-matching, the actual mole ratio, x, is defined as so:
InP-matched X: (Al48 In52 As)_X  > (Ga47 In53 As)_1-X

Valid for wavelengths: 0.900 - 2.100 um  &  x: 0.3 - 1.0

Calculated by sellmeier equation, with params from

  M. J. Mondry, D. I. Babic, J. E. Bowers, and L. A. Coldren,
  "Refractive indexes of (Al,Ga,In)As epilayers on InP for optoelectronic
  applications," Phot. Tech. Lett., vol. 4, no. 6, pp. 627-630, 1992

Parameters
     
x: float
    Mole ratio of Al, as in: Al(x) Ga(1-x) In(1-x-y) As.  Also varies In
    slightly for lattice-matching.

wl: float
    wavelength in microns.

'''

我所做的唯一一件事就是在79个纵队打断了你的长队。也许这是Sphinx(我们用来渲染docstring的库)的一个限制。你知道吗

注意:Spyder 2.1.11非常古老!!请尝试更新到我们的最新版本,即2.3.4。你知道吗

相关问题 更多 >