file -> open in stdlib patch

Daniel Nogradi nogradi at gmail.com
Wed Jan 24 17:55:51 EST 2007


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:



More information about the Python-list mailing list