0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【日記】pythonでタブ文字を「print」しようとしたけどできなかった

Posted at

エクセルやスプレッドシートにラクにコピペするため、タブ文字を出力したくなりました。
しかし、コード上でタブ文字を記述しても上手く出力されません。

tab.py
print('hoge' + '	' + 'foo') #タブ文字
# hoge    foo 自分の環境ではいくつかの半角スペースになった

エスケープシーケンスを使っても、printしてしまうと半角スペースになってしまいます。

tab.py
print('hoge' + '\t' + 'foo') #タブ文字
# hoge    foo

たぶんファイル出力とかしたらいい感じになるんだろうな~って思ったんですけど、ファイルには出力したくない。
結局のところ、半角スペースx4固定で出力⇒別途テキストエディタでタブ文字に置換。という手順で我慢しました。
c94b4e7d54032619c5bd640963d7caa1.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?