Staging
v0.5.1
https://github.com/python/cpython
Revision a608febd5fe146f0eea6780402de15c09a9d9ff4 authored by Fred Drake on 12 April 1998, 03:58:13 UTC, committed by Fred Drake on 12 April 1998, 03:58:13 UTC
1 parent ae9bc67
Raw File
Tip revision: a608febd5fe146f0eea6780402de15c09a9d9ff4 authored by Fred Drake on 12 April 1998, 03:58:13 UTC
Fix typo. (What I get for trying to fix bugs at home and running conversions
Tip revision: a608feb
crlf.py
#! /usr/local/bin/python

# Replace \r by \n -- useful after transferring files from the Mac...
# Run this on UNIX.
# Usage: crlf.py file ...

import sys
import os
import string

def main():
	args = sys.argv[1:]
	if not args:
		print 'usage:', sys.argv[0], 'file ...'
		sys.exit(2)
	for file in args:
		print file, '...'
		data = open(file, 'r').read()
		lines = string.splitfields(data, '\r')
		newdata = string.joinfields(lines, '\n')
		if newdata != data:
			print 'rewriting...'
			os.rename(file, file + '~')
			open(file, 'w').write(newdata)
			print 'done.'
		else:
			print 'no change.'

main()
back to top