title: How to tell Python to use local name rather than global one?
body: <p><s>For some reason I need to use <code>locals()</code> explicitly to assign values to some variables; but I would like to reference those variables directly later. The example below explains what I'm thinking about:</p>
  
  <pre><code>#!/usr/bin/env python
  
  def hello():
     local = locals()
     c = 1
     for i in ['x', 'y', 'z']:
         local[i] = c
         c += 1
     print(x)
  
  hello()
  </code></pre>
  
  <p>However it is incorrect, with the error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "./ttt.py", line 11, in &lt;module&gt;
      hello()
    File "./ttt.py", line 9, in hello
      print(x)
  NameError: global name 'x' is not defined
  </code></pre>
  
  <p>Seems that Python would look the <em>global</em> 'x' rather than the <em>local</em> one. Surely I can use <code>print(local['x'])</code> at Line 9, but is there <em>another</em> way?</p>
  
  <p></s></p>
  
  <h3>update:</h3>
  
  <p>What I really need is to "automatically" create several variables related to <em>a list of strings</em>: each of these variables' <strong>name</strong> and <strong>value</strong> are a transformation of one string in the list.
  For example,</p>
  
  <pre><code># given
  list_of_string = ['clang', 'scan-build']
  # I hope to create two variables:
  clang = '/usr/bin/clang'
  scan_build = '/usr/local/bin/scan-build'
  </code></pre>
  
  <p>Here the <strong>name</strong> of the variables (<em>clang</em>, <em>scan_build</em>) is the string in <code>list_of_string</code> except that '-' is replaced with '_', and the <strong>value</strong> is the really location of the string (generated by some function works as unix <code>which</code>).</p>