1

Spyder IDE (Mac OS では v.2.1.11) を使用していくつかのコードを書いています。関数の DocString (NumpyDoc 形式) を書いているときに、Spyder Object Inspectorがインデントされた行を書式設定する理由がわかりません。この奇妙な方法。

以下のような Docstring の場合、「Calc'd by 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 の「オブジェクト インスペクター」/ヘルプ パネルのスクリーンショット) を生成し、「 MJ Mondry, DI Babic...」テキストに予期しない太字とインデント/リスト番号が表示されます。

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.

...

'''

次のように、正常に見えます。

インデントされていない紙の参照を含むオブジェクト インスペクター

それは Spyder の単なるバグですか、それともインデントの他の意図的な使用ですか? 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 on Darwin、Mac OS 10.10.2

4

1 に答える 1

0

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 にアップデートしてみてください。

于 2015-04-14T19:54:17.603 に答える