Guido van Rossum | 17d82ce | 1991-02-19 13:04:40 +0000 | [diff] [blame] | 1 | # Module 'util' -- some useful functions that don't fit elsewhere |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 2 | |
Guido van Rossum | 17d82ce | 1991-02-19 13:04:40 +0000 | [diff] [blame] | 3 | |
| 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 Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 7 | # |
| 8 | def remove(item, list): |
| 9 | for i in range(len(list)): |
| 10 | if list[i] = item: |
| 11 | del list[i] |
| 12 | break |
Guido van Rossum | 17d82ce | 1991-02-19 13:04:40 +0000 | [diff] [blame] | 13 | |
| 14 | |
| 15 | # Return a string containing a file's contents. |
| 16 | # |
| 17 | def readfile(fn): |
| 18 | return readopenfile(open(fn, 'r')) |
| 19 | |
| 20 | |
| 21 | # Read an open file until EOF. |
| 22 | # |
| 23 | def 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 |