Problems of **arg in Python
<p>I'll post my code first, and then ask questions.</p>

<pre><code>def menu(**arg):
    if len(arg) == 0:
        name = raw_input("Enter your name: ")
        location = raw_input("Enter your name: ")
    else:
        for i,j in arg.items():
            globals()[i] = j
    print "Name: %s | Location: %s" % (name, location)
</code></pre>

<p>The goal of this function is to print out something like this:</p>

<blockquote>
  <p>Name: someone | Location: somewhere</p>
</blockquote>

<p>If I just input </p>

<blockquote>
  <p>menu()</p>
</blockquote>

<p>OK, no problem, but if I type</p>

<blockquote>
  <p>menu(name='someone', location='somewhere')</p>
</blockquote>

<p>something went wrong...</p>

<p>If I rewrite it like this:</p>

<pre><code>def menu(**arg):
    if len(arg) == 0:
        pass
    else:
        for i,j in arg.items():
            globals()[i] = j
    print "Name: %s | Location: %s" % (name, location)
</code></pre>

<p>and I type</p>

<blockquote>
  <p>menu(name='someone', location='somewhere')</p>
</blockquote>

<p>it worked... but I don't know why</p>

<p>Also, why can't I replace vars() with globals() in the "rewritten version"?  <br/>
  <br/>
And my last question is ...  <br/>
I found this code verbose and redundant..  <br/>
Is there any way to make it cleaner and neater?</p>

<p>Thanks for your patience!</p>
