From: Junio C Hamano Date: Thu, 09 Feb 2012 03:58:54 GMT Subject: Re: [StGit PATCH] Parse commit object header correctly Message-ID: <7v39akzmgx.fsf@alter.siamese.dyndns.org> In-Reply-To: "Frans Klaver" writes: >>>> for line in lines: >>>> try: >>>> key, value = line.rstrip('\n').split(' ', 1) >>>> except ValueError: >>>> continue >>> >>> This is generally considered more pythonic: "It's easier to ask for >>> forgiveness than to get permission". >> >> Given that Junio explicitly wanted to allow lines with no spaces, I >> assume that lack of a space is not an error but rather a conceivable >> future extension. If my assumption is correct, then it is misleading >> (and inefficient) to handle it via an exception. > > I find the documenting more convincing than the efficiency, but from > the phrasing I think you do too. A line that consists entirely of non-SP may or may not a conceivable future extension, but the point is to "skip without barfing anything you do not understand". I wouldn't oppose the rewrite that uses try/except ValueError if "everything in this try block will parse what I understand correctly, and any ValueError exception this try block throws is an indication that I encountered what I do not understand and I must skip" is the more pythonic way to express that principle. Python is not my primary language as I said, and in addition StGit may have its own style I haven't learned.