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 | d9d2c82 | 1991-04-07 13:43:34 +0000 | [diff] [blame] | 3 | # NB: These are now built-in functions, but this module is provided |
| 4 | # for compatibility. Don't use in new programs unless you need backward |
Guido van Rossum | ab2885e | 1991-04-21 19:34:48 +0000 | [diff] [blame] | 5 | # compatibility (i.e. need to run with old interpreters). |
Guido van Rossum | d9d2c82 | 1991-04-07 13:43:34 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | 17d82ce | 1991-02-19 13:04:40 +0000 | [diff] [blame] | 7 | |
| 8 | # Remove an item from a list. |
| 9 | # No complaints if it isn't in the list at all. |
| 10 | # If it occurs more than once, remove the first occurrence. |
Guido van Rossum | c636014 | 1990-10-13 19:23:40 +0000 | [diff] [blame] | 11 | # |
| 12 | def remove(item, list): |
Guido van Rossum | d9d2c82 | 1991-04-07 13:43:34 +0000 | [diff] [blame] | 13 | if item in list: list.remove(item) |
Guido van Rossum | 17d82ce | 1991-02-19 13:04:40 +0000 | [diff] [blame] | 14 | |
| 15 | |
| 16 | # Return a string containing a file's contents. |
| 17 | # |
| 18 | def readfile(fn): |
| 19 | return readopenfile(open(fn, 'r')) |
| 20 | |
| 21 | |
| 22 | # Read an open file until EOF. |
| 23 | # |
| 24 | def readopenfile(fp): |
Guido van Rossum | d9d2c82 | 1991-04-07 13:43:34 +0000 | [diff] [blame] | 25 | return fp.read() |