469,626 Members | 1,167 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

file -> open in stdlib patch

Hi list,

AFAIK using file( ) to open a file is deprecated in favor of open( )
and while grepping through the stdlib I noticed a couple of occurences
of file( ) in the latest revision. I made a patch for getting rid of
them; it passes all the tests. Although the change is almost trivial,
since this is my first patch maybe it's better if someone
knowledgeable takes a look at it before submitting it to SF.

Daniel

Index: Lib/site.py
================================================== =================
--- Lib/site.py (revision 53548)
+++ Lib/site.py (working copy)
@@ -274,7 +274,7 @@
for filename in self.__files:
filename = os.path.join(dir, filename)
try:
- fp = file(filename, "rU")
+ fp = open(filename, "rU")
data = fp.read()
fp.close()
break
Index: Lib/webbrowser.py
================================================== =================
--- Lib/webbrowser.py (revision 53548)
+++ Lib/webbrowser.py (working copy)
@@ -216,7 +216,7 @@
cmdline = [self.name] + raise_opt + args

if remote or self.background:
- inout = file(os.devnull, "r+")
+ inout = open(os.devnull, "r+")
else:
# for TTY browsers, we need stdin/out
inout = None
@@ -340,7 +340,7 @@
else:
action = "openURL"

- devnull = file(os.devnull, "r+")
+ devnull = open(os.devnull, "r+")
# if possible, put browser in separate process group, so
# keyboard interrupts don't affect browser as well as Python
setsid = getattr(os, 'setsid', None)
Index: Lib/pstats.py
================================================== =================
--- Lib/pstats.py (revision 53548)
+++ Lib/pstats.py (working copy)
@@ -173,7 +173,7 @@

def dump_stats(self, filename):
"""Write the profile data to a file we know how to load back."""
- f = file(filename, 'wb')
+ f = open(filename, 'wb')
try:
marshal.dump(self.stats, f)
finally:
Jan 24 '07 #1
0 1079

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by chris | last post: by
7 posts views Thread by Joseph | last post: by
3 posts views Thread by StGo | last post: by
1 post views Thread by Mika M | last post: by
reply views Thread by thjwong | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.