Python を使用して POST 呼び出しから返される値の Cookie があります。値が空か null
かを確認する必要があります。cookieしたがって、if 条件の関数または式が必要です。Pythonでこれを行うにはどうすればよいですか? 例えば:
if cookie == NULL
if cookie == None
PScookieは、値が格納される変数です。
これを試して:
if cookie and not cookie.isspace():
# the string is non-empty
else:
# the string is empty
None上記は、文字列がまたは一連の空白の場合を考慮しています。
Python では、シーケンスbool(sequence)がFalse空の場合です。文字列はシーケンスであるため、これは機能します。
cookie = ''
if cookie:
print "Don't see this"
else:
print "You'll see this"