title: Python - String with timestamp changing
body: <p>I'm attempting to initialize a string variable in Python using the datetime package.  I expect that string to stay the same once it's been initialized, but for some strange reason (at least strange to me), it's changing.</p>
  
  <p>Essentially, when I attempt:</p>
  
  <pre><code>timestamp = datetime.datetime.now().strftime('%m-%d-%Y.%I_%M_%S_%p')
  base_directory = "C:\\Users\\Ben\\report_" + timestamp + "\\"
  print base_directory #prints C:\Users\Ben\report_02-13-2015_02_02_24_PM
  time.sleep(5)
  logs_directory = base_directory + "logs\\"
  </code></pre>
  
  <p>When I go back to use the logs_directory variable, I expect it to be </p>
  
  <pre><code>C:\Users\Ben\report_02-13-2015_02_02_24_PM\logs\
  </code></pre>
  
  <p>However, instead it is:</p>
  
  <pre><code>C:\Users\Ben\report_02-13-2015_02_02_29_PM\logs\ #!!!
  </code></pre>
  
  <p>It's as if when I access the logs directory variable, it's going back and reevaluating the base_directory variable again, instead of retrieving the value base_directory has already been set to.  Is this intended functionality in Python?  I don't it is since I can't seem to trigger this issue from the IDLE shell - it's only occurring when I run my Python program from pydev.  However, if this is intended functionality, how do I rewrite my code to achieve the results I'm expecting?  Thanks!</p>
  
  <p>I'm not sure if it's relevant, but I'm accessing this variable in nose unit tests.  This is in Python 2.7.</p>
  
  <hr>
  
  <p>UPDATE: Here's some standalone code that better illustrates what's going on.  It does in fact look like it is related to nose in some way:</p>
  
  <pre><code>import nose, os, sys, time
  
  timestamp = time.strftime('%m-%d-%Y.%I_%M_%S_%p')
  base_directory = "C:\\Users\\Ben\\Desktop\\report_" + timestamp + "\\"
  logs_directory = base_directory + "logs\\"
  
  def test_me():
      print base_directory
      print logs_directory
  
  if __name__ == '__main__':
      os.makedirs(base_directory)
      os.makedirs(logs_directory)
      print base_directory
      print logs_directory
  
      time.sleep(5)
  
      #Without the nocapture argument, nose will internally log all
      #stdout output, and will not output anything to the console.
      argv = (sys.argv[:])
      argv.insert(1, "--nocapture")
      nose.main(argv=argv)  #This will run test_me()
  </code></pre>
  
  <p>And here's the output:</p>
  
  <pre><code>C:\Users\Ben\Desktop\report_02-13-2015.04_27_32_PM\
  C:\Users\Ben\Desktop\report_02-13-2015.04_27_32_PM\logs\
  C:\Users\Ben\Desktop\report_02-13-2015.04_27_37_PM\
  C:\Users\Ben\Desktop\report_02-13-2015.04_27_37_PM\logs\
  </code></pre>
  
  <p>I was expecting: </p>
  
  <pre><code>C:\Users\Ben\Desktop\report_02-13-2015.04_27_32_PM\
  C:\Users\Ben\Desktop\report_02-13-2015.04_27_32_PM\logs\
  C:\Users\Ben\Desktop\report_02-13-2015.04_27_32_PM\
  C:\Users\Ben\Desktop\report_02-13-2015.04_27_32_PM\logs\
  </code></pre>
  
  <p>What's going on?  Why is nose re-evaluating strings that have already been initialized?  How do I rewrite my code so that it does what I was expecting?  Thanks!</p>