blob: 6cb143342639d0c166cba45e5b36d7b2ffd91134 [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 Rossumd9d2c821991-04-07 13:43:34 +00003# 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 Rossumab2885e1991-04-21 19:34:48 +00005# compatibility (i.e. need to run with old interpreters).
Guido van Rossumd9d2c821991-04-07 13:43:34 +00006
Guido van Rossum17d82ce1991-02-19 13:04:40 +00007
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 Rossumc6360141990-10-13 19:23:40 +000011#
12def remove(item, list):
Guido van Rossumd9d2c821991-04-07 13:43:34 +000013 if item in list: list.remove(item)
Guido van Rossum17d82ce1991-02-19 13:04:40 +000014
15
16# Return a string containing a file's contents.
17#
18def readfile(fn):
19 return readopenfile(open(fn, 'r'))
20
21
22# Read an open file until EOF.
23#
24def readopenfile(fp):
Guido van Rossumd9d2c821991-04-07 13:43:34 +000025 return fp.read()