title: Pass session as argument to user-function in Tensorflow
body: <p>As I have to run the same part of code several times in my script, I was wondering if is possible to pass a <code>tf.Session</code> as argument to an user defined function in order to run some operations inside the function, thus avoiding the repetitive code.</p>
  
  <p><strong>Update</strong>
  Example of use</p>
  
  <pre><code>with tf.Session as sess: 
          my_training(init, epochs, Xtrain, Ytrain, batch,\
                      optimizer, loss, predictions, X, Y, sess)
          validation_error = sess.run(loss, feed_dict={X:Xvalid, Y:Yvalid})
  </code></pre>
  
  <p>where optimizer, loss, inputs, outputs, Xtrain and Ytrain, etc are previously created tensors, and <code>my_training</code> is the function I created to train the NN in a separate script.</p>
  
  <pre><code>def my_training(init, epochs, Xtrain, Ytrain, batch,\
  
               optimizer, loss, predictions, X, Y, sess):   
  
      # Shuffle the training set 
      Xtrain, Ytrain = shuffle(Xtrain, Ytrain, random_state = 20)
  
      # Initialize all variables (network weights, biases and optimizer)
      sess.run(init)
  
      # Loop over the training epochs
      for epoch in range(epochs):
  
          # Loop over mini-batches in the epoch
          for offset in range(0, Xtrain.shape[0], batch):
  
              batch_x = Xtrain[offset: offset + batch]
  
              batch_y = Ytrain[offset: offset + batch]
  
              sess.run(optimizer, feed_dict = {X:batch_x, Y:batch_y})
  </code></pre>