How to parse dates for incomplete dates in Python
<p>I am using dateutil.parser to parse dates and I want to throw an exception if the date is incomplete i.e January 1 (missing year) or January 2016 (missing day). So far I have the following </p>

<pre><code>try: 
    parse(date)
    return parse(date).isoformat()
except ValueError:
    return 'invalid'
</code></pre>

<p>Parse takes a default argument from which it takes the unspecified parts. So the easiest solution (apart from using a different library) would be to call the function with two <em>different</em> default parameters.</p>

<p>If both calls return the same value the datetime is valid, otherwise some default value was used - you can even find out what was unspecified this way.</p>

python