blob: 7a9caf7317df940db509ed83b06af7630ba7d829 [file] [log] [blame]
Guido van Rossum17d82ce1991-02-19 13:04:40 +00001# Module 'util' -- some useful functions that don't fit elsewhere
Guido van Rossumc6360141990-10-13 19:23:40 +00002
Guido van Rossum17d82ce1991-02-19 13:04:40 +00003
4# Remove an item from a list.
5# No complaints if it isn't in the list at all.
6# If it occurs more than once, remove the first occurrence.
Guido van Rossumc6360141990-10-13 19:23:40 +00007#
8def remove(item, list):
9 for i in range(len(list)):
10 if list[i] = item:
11 del list[i]
12 break
Guido van Rossum17d82ce1991-02-19 13:04:40 +000013
14
15# Return a string containing a file's contents.
16#
17def readfile(fn):
18 return readopenfile(open(fn, 'r'))
19
20
21# Read an open file until EOF.
22#
23def readopenfile(fp):
24 BUFSIZE = 512*8
25 data = ''
26 while 1:
27 buf = fp.read(BUFSIZE)
28 if not buf: break
29 data = data + buf
30 return data