Giulio Piancastelli avatar Giulio Piancastelli committed d26de11

Avoid shadowing built-in names.

Comments (0)

Files changed (2)

python 2/koans/about_iteration.py

 
         try:
             # Files act like a collection of lines
-            file = open("example_file.txt")
+            f = open("example_file.txt")
 
             try:   
                 def make_upcase(line):
                     return line.strip().upper()
-                upcase_lines = map(make_upcase, file.readlines())
+                upcase_lines = map(make_upcase, f.readlines())
                 self.assertEqual(__, list(upcase_lines))
             
                 # NOTE: You can create your own collections that work with each,
             finally:
                 # Arg, this is ugly.
                 # We will figure out how to fix this later.
-                file.close()
+                f.close()
         except IOError:
             # should never happen
             self.fail()

python 2/koans/about_with_statements.py

 class AboutWithStatements(Koan):
     def count_lines(self, file_name):
         try:
-            file = open(file_name)
+            f = open(file_name)
             try:
                 count = 0
-                for line in file.readlines():
+                for line in f.readlines():
                     count += 1
                 return count
             finally:
-                file.close()
+                f.close()
         except IOError:
             # should never happen
             self.fail()
         
     def find_line(self, file_name):
         try:
-            file = open(file_name)
+            f = open(file_name)
             try:
-                for line in file.readlines():
+                for line in f.readlines():
                     match = re.search('e', line)
                     if match:
                         return line
             finally:
-                file.close()
+                f.close()
         except IOError:
             # should never happen
             self.fail()
     # Now we write:
     
     def count_lines2(self, file_name):
-        with self.FileContextManager(file_name) as file:
+        with self.FileContextManager(file_name) as f:
             count = 0
-            for line in file.readlines():
+            for line in f.readlines():
                 count += 1
         return count
     
     # ------------------------------------------------------------------
     
     def count_lines3(self, file_name):
-        with open(file_name) as file:
+        with open(file_name) as f:
             count = 0
-            for line in file.readlines():
+            for line in f.readlines():
                 count += 1
             return count
     
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.