title: Tensorflow variable scope: reuse if variable exists
body: <p>I want a piece of code that creates a variable within a scope if it doesn't exist, and access the variable if it already exists. I need it to be the <strong>same</strong> code since it will be called multiple times. </p>
  
  <p>However, Tensorflow needs me to specify whether I want to create or reuse the variable, like this:</p>
  
  <pre><code>with tf.variable_scope("foo"): #create the first time
      v = tf.get_variable("v", [1])
  
  with tf.variable_scope("foo", reuse=True): #reuse the second time
      v = tf.get_variable("v", [1])
  </code></pre>
  
  <p>How can I get it to figure out whether to create or reuse it automatically? I.e., I want the above two blocks of code to be the <strong>same</strong> and have the program run. </p>