私はPythonについて学んでおり、Pythonでexpandtabs
コマンドを取得しました。 これは、ドキュメント内の公式な定義です:Python expandtabs文字列操作
string.expandtabs(s[, tabsize])
は現在のカラムと与えられたタブのサイズに応じて、1つ以上のスペースでそれらを置き換える文字列内のタブを展開します。列番号は、文字列内に改行があるたびにゼロにリセットされます。これは他の非印字文字やエスケープシーケンスを理解しません。タブのサイズのデフォルト値8
へそれでは、私はそれから理解することは、タブのデフォルトサイズは8であると私はことをしようとしたときのことを高めるために、我々は、他の値ので
を使用することができるということですシェル、私は次の入力を試してみました -
>>> str = "this is\tstring"
>>> print str.expandtabs(0)
this isstring
>>> print str.expandtabs(1)
this is string
>>> print str.expandtabs(2)
this is string
>>> print str.expandtabs(3)
this is string
>>> print str.expandtabs(4)
this is string
>>> print str.expandtabs(5)
this is string
>>> print str.expandtabs(6)
this is string
>>> print str.expandtabs(7)
this is string
>>> print str.expandtabs(8)
this is string
>>> print str.expandtabs(9)
this is string
>>> print str.expandtabs(10)
this is string
>>> print str.expandtabs(11)
this is string
だからここに、
0
が完全にタブ文字を削除し、1
はまさに1
のようなもので、その後、3
が- 異なっているし、再度
4
1
を使用してのようなものであると、正確にデフォルト8
よう
2
である、それは増加することが後にデフォルトである8
まで増加してから8.Butの後に増加します。なぜ0〜8の数字の奇妙なパターンですか?私はそれが8から始めるはずですが、理由は何ですか?
説明に関連する[この質問](http://stackoverflow.com/questions/2656997/python-expand-tabs-length-calculation)も参照してください。 – Jens
もっと簡単な方法で説明できますか?私は質問で追加したケースで出力がどのように変化するのか理解できません。 – WutWut
@WutWut:[tab stop](https://en.wikipedia.org/wiki/Tab_stop)が何であるかを見てみましょう。それは 'tab'(tabulator)の仕組みを理解するのに役立つはずです。 – Jens