Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 17d82ce

Browse files
committed
Added readfile() and readopenfile() functions.
1 parent 261cbb2 commit 17d82ce

2 files changed

Lines changed: 46 additions & 4 deletions

File tree

Lib/lib-old/util.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1-
# Module 'util' -- some useful functions that dont fit elsewhere
1+
# Module 'util' -- some useful functions that don't fit elsewhere
22

3-
# Remove an item from a list at most once
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.
47
#
58
def remove(item, list):
69
for i in range(len(list)):
710
if list[i] = item:
811
del list[i]
912
break
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

Lib/util.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1-
# Module 'util' -- some useful functions that dont fit elsewhere
1+
# Module 'util' -- some useful functions that don't fit elsewhere
22

3-
# Remove an item from a list at most once
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.
47
#
58
def remove(item, list):
69
for i in range(len(list)):
710
if list[i] = item:
811
del list[i]
912
break
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

0 commit comments

Comments
 (0)