title: How to use named parameters and global vars with same name in Python?
body: <p>Example code from a module:</p>
  
  <pre><code>somevar = "a"
  
  def myfunc(somevar = None):
      # need to access both somevars ???
      # ... if somevar was specified print it or use the global value
      pass
  
  if __name__ == '__main__':
      somevar = "b" # this is just for fun here
      myfunc("c")
      myfunc() # should print "a" (the value of global variable)
  </code></pre>
  
  <p>There are at least two reasons for using the same name:educational (to learn how to use local/globals) and usage in modules.</p>
  
  <p>Let say that this code is part of your module: <code>mymodule</code> and you want to do things like:</p>
  
  <pre><code>import mymodule
  
  mymodule.samevar = "default"
  ...
  mymodule.myfunc(somevar = "a")
  ...
  mymodule.myfunc()
  </code></pre>
  
  <p>As you can imagine in this example is simplified, imagine that <code>somevar</code> parameter is one of many optional parameters and that myfunc is called in many places.</p>