[Tutor] Unsure why won't work
Elizabeth Bernert
ebernert@crpud.net
Thu Jul 31 14:41:53 2003
This is a multi-part message in MIME format.
--------------060002050206020906060601
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
I changed the top line to the line the works in my comp to get programs
working, (i.e. #!c:/Python22/python.exe) but that did not work.. Does
anyone have any ideas?
--------------060002050206020906060601
Content-Type: text/plain;
name="tail.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="tail.py"
#!usr/bin/python
#
# Usage: python tail.py [file-name]
#
# Continuously look for new data in a file and write it to terminal. If
# the file name is omitted, standard input is used
#
import sys, time
# Position the file near the end, unless it's pretty small already
def findEof(input):
import os
size = os.fstat(input.fileno())[6]
if (size > 500):
# seek to 400 bytes from end of file
print 'seeking back'
input.seek(-500, 2)
# Infinitely loop looking for new data in file
def tail(input):
while 1:
line = input.readline()
if line == '':
# empty - wait and try again
time.sleep(2)
else:
# trailing comma to supress newlines (which line already has)
print line,
# actually begin the code - look for a file name
if len(sys.argv) > 1:
input = open(sys.argv[1])
else:
input = sys.stdin
findEof(input)
tail(input)
--------------060002050206020906060601--