How do I write a "tab" in Python?

TIMEX picture TIMEX · Dec 20, 2010 · Viewed 468.1k times · Source

Let's say I have a file. How do I write "hello" TAB "alex"?

Answer

Simone picture Simone · Dec 20, 2010

This is the code:

f = open(filename, 'w')
f.write("hello\talex")

The \t inside the string is the escape sequence for the horizontal tabulation.