File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Module 'util' -- some useful functions that don't fit elsewhere
22
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
5+ # compatibility (with old interpreters).
6+
37
48# Remove an item from a list.
59# No complaints if it isn't in the list at all.
610# If it occurs more than once, remove the first occurrence.
711#
812def remove (item , list ):
9- for i in range (len (list )):
10- if list [i ] = item :
11- del list [i ]
12- break
13+ if item in list : list .remove (item )
1314
1415
1516# Return a string containing a file's contents.
@@ -21,10 +22,4 @@ def readfile(fn):
2122# Read an open file until EOF.
2223#
2324def 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
25+ return fp .read ()
Original file line number Diff line number Diff line change 11# Module 'util' -- some useful functions that don't fit elsewhere
22
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
5+ # compatibility (with old interpreters).
6+
37
48# Remove an item from a list.
59# No complaints if it isn't in the list at all.
610# If it occurs more than once, remove the first occurrence.
711#
812def remove (item , list ):
9- for i in range (len (list )):
10- if list [i ] = item :
11- del list [i ]
12- break
13+ if item in list : list .remove (item )
1314
1415
1516# Return a string containing a file's contents.
@@ -21,10 +22,4 @@ def readfile(fn):
2122# Read an open file until EOF.
2223#
2324def 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
25+ return fp .read ()
You can’t perform that action at this time.
0 commit comments