How to handle blank form value in python
<p>I have 2 form fields in my html code, which hits to python script. Everything works perfectly if i provide both input in form. But in my case, 2nd field is optional. I am getting blank result when i submit form with 1st field only. How to handle my code to run even when 2nd field is blank/null</p>

<p>python code:</p>

<pre><code>import cgi
form = cgi.FieldStorage()
first=form["firstSix"].value
last=form["lastFour"].value
</code></pre>

<p>You can check if something is empty with a boolean.</p>

<pre><code>if not form["lastFour"]:
    print "lastFour is empty!"
else:
    print "lastFour has a value!"
</code></pre>

<p>Any string that is empty is considered false, and and that has a value is true. So <code>""</code> is false and <code>"Hello World!"</code> is true. If the form value equals <code>None</code>, you might have to check for that too.</p>

<pre><code>if not form["lastFour"]:
    print "lastFour is empty!"
elif form["lastFour"] == None:
    print "lastFour has is empty!"
else:
    print "lastFour has a value!"
</code></pre>

python