<p>我正在编写一个api,它接受两个参数“a”和“b”。在接收到参数后,它检查它们是否存在,并根据接收到的参数执行一些操作。下面是一些psudo代码。你知道吗</p>
<pre><code>args = get.parameters
if "a" in args:
print "x" # execute "x"
if "b" in args:
print "y" # execute "y"
if both exists:
print "x" # execute "x"
</code></pre>
<p>最好的办法是什么?你知道吗</p>
<pre><code>import sys
args = sys.argv;
if len(args) > 1:
args = args[1:]
if "a" in args and "b" in args: print "x"
elif "a" in args: print "x"
elif "b" in args: print "y"
</code></pre>