#!/usr/bin/env python import sys import math try: infilename = sys.argv[1] outfilename = sys.argv[2] except: print "Usage:",sys.argv[0], "infile outfile" sys.exit(1) # Open file for reading ifile = open( infilename, 'r') # Open file for writing ofile = open(outfilename, 'w') # Define a function def myfunc(y): if y >= 0.0: return y**5*math.exp(-y) else: return 0.0 # read ifile line by line and write out transformed values: for line in ifile: pair = line.split() x = float(pair[0]) y = float(pair[1]) # transform y value fy = myfunc(y) ofile.write('%g %12.5e\n' % (x,fy)) # Close the files ifile.close() ofile.close()