annotate Lib/util.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents a1097cd03348
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
151
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
1 # Module 'util' -- some useful functions that don't fit elsewhere
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
2
198
646316c99507 This is no longer needed, since all these functions are now built-in
Guido van Rossum <guido@python.org>
parents: 151
diff changeset
3 # NB: These are now built-in functions, but this module is provided
646316c99507 This is no longer needed, since all these functions are now built-in
Guido van Rossum <guido@python.org>
parents: 151
diff changeset
4 # for compatibility. Don't use in new programs unless you need backward
219
a1097cd03348 Clarify comment.
Guido van Rossum <guido@python.org>
parents: 198
diff changeset
5 # compatibility (i.e. need to run with old interpreters).
198
646316c99507 This is no longer needed, since all these functions are now built-in
Guido van Rossum <guido@python.org>
parents: 151
diff changeset
6
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
151
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
8 # Remove an item from a list.
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
9 # No complaints if it isn't in the list at all.
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
10 # If it occurs more than once, remove the first occurrence.
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 #
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 def remove(item, list):
198
646316c99507 This is no longer needed, since all these functions are now built-in
Guido van Rossum <guido@python.org>
parents: 151
diff changeset
13 if item in list: list.remove(item)
151
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
14
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
15
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
16 # Return a string containing a file's contents.
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
17 #
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
18 def readfile(fn):
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
19 return readopenfile(open(fn, 'r'))
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
20
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
21
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
22 # Read an open file until EOF.
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
23 #
9d4c7de0def4 Added readfile() and readopenfile() functions.
Guido van Rossum <guido@python.org>
parents: 5
diff changeset
24 def readopenfile(fp):
198
646316c99507 This is no longer needed, since all these functions are now built-in
Guido van Rossum <guido@python.org>
parents: 151
diff changeset
25 return fp.read()