faqts : Computers : Programming : Languages : Python : Snippets

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 2 people (50%) answered Yes
Recently 0 of 1 people (0%) answered Yes

Entry

Converter space indentation -> tab indentation

Jul 5th, 2000 10:03
Nathan Wallace, Hans Nowak, Snippet 317, Magnus L. Hetland


"""
Packages: text
"""
"""
> I'm looking for a converter that converts Python files
> with space indentation  -> tab indentation.
How about a simple script like this?
"""
# -- start --
#!/usr/bin/env python
import sys, string
line = sys.stdin.readline()
while line:
    print string.replace(line,"    ","\t"),
    line = sys.stdin.readline()
# -- stop --
"""
It worked on my source files (from emacs with python-mode).
"""