Anonymous committed ddf211d

be more pythonic

* if you iterate over a file descriptor, the iterators yields lines.
for l in fd.readlines(): is thus the same as for l in fd:
* file descriptor get closed when leaving the function
* if the expression is simple, a list comprehension is nice to use
* map is nice for small, repetitive operations

  • Participants
  • Parent commits ecfab96

Comments (0)

Files changed (1)

 from mercurial.i18n import _
 from hgext.fetch import fetch
 from mercurial import hg
-import os
+import os, string
 def subrepo(ui, repo, **opts):
     '''allows for easy(er) management of mutiple subrepositories at once
 def getSubreposFromHgsub(repo):
     root = repo.root
     f = open(root + "/.hgsub")
-    d = f.readlines()
-    result = [];
-    for x in d:
-        x = x.split('=')
-        result.append([x[0].strip(), x[1].strip()])
-    f.close()
-    return result
+    return [map(string.strip, line.split('=')) for line in f]
 def listSubrepos(ui, repo):
     for local, remote in getSubreposFromHgsub(repo):