2015-04-01 70 views
1

我正在使用Spyder IDE(Mac OS上的v.2.1.11)并编写一些代码,并且在为某个函数编写DocString(NumpyDoc格式)时,无法弄清为什么Spyder格式化为Object Inspector格式以这种奇怪的方式缩进一条线。NumpyDoc:如何解析标签?

对于像下面的一个中,在纸参考“由谢米尔计算值...缩进,这会导致奇怪的行为文档字符串:

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. 

... 

''' 

上述文档字符串产生下面的输出(Spyder的“对象检查” /帮助面板的截图),用意想不到的加粗 &缩进/列表编号的“MJ Mondry,DI巴比奇...”文本:

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中的“参考”部分,我将在某个时间点将Ref移入。)

谢谢!

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

回答

0

Spyder的开发这里)我已经成功地得到什么(我觉得)你想重新格式化文档字符串这样

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的限制(我们用来渲染文档的库)。

注意:Spyder 2.1.11是古老的!请尝试更新到我们的最新版本,它是2.3.4。

+0

谢谢!我同意这有点不幸,我不得不手工打破所有文档 - 我只是希望Spyder适当地包装文本。你知道为什么添加了编号列表吗?我已经升级了我的Spyder - 我会看看它是否仍然如此。 – Demis 2015-05-04 17:52:23

+0

我真的不知道。我认为这是Sphinx的一个问题,因为除了向Sphinx传递文档信息来呈现它们之外,我们不做任何事情:-) – 2015-05-04 18:42:39