#!/usr/bin/python import sys ### how to create a function def reverseFile(fname) : str = file(fname).read() str2 = '' for char in str : ### warning: this creates a new copy of str2 for each iteration, which ### is very inefficient. This is just means as an example of how to use ### files and for loops. str2 = char + str2 open(fname, 'w').write(str2) if __name__ == "__main__" : if len(sys.argv) < 2 : print "Usage: reverser.py fname" sys.exit(0) else : reverseFile(sys.argv[1])