[Tutor] after string.split()

Rob Andrews randrews@planhouse.com
Thu, 10 May 2001 13:18:12 -0500


Thanks! I've been hacking something together, but it's definitely a hack and
has *undocumented features* to prove it. And yours has brevity and elegance
in comparison with mine, as well.

Would you object if I posted your code along with mine on Useless Python to
show the difference between a program and a hack?

Rob

Well, since no-one seems to have replied, here is my attempt:

--- cut here ---

#!/usr/bin/env python

import fileinput
import string
import sys

def process(line):
	line=string.join(string.split(line,",")[1:],",")
	sys.stdout.write(line)

for line in fileinput.input(sys.argv[1:], inplace=1, backup='.old'):
	process(line)

--- cut here ---

You can then use this as follows:

	$./remove_first_field.py file1 file2

And this should leave you with a backup of the original file (.old).

Hope that helps,

Kindest regards,

	--ibs.

--
Sometimes you get an almost irresistible urge to go on living.

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor