title: Appending Datetime into an Array (Python)
body: <p><strong>Scope</strong>: to produce a script that fetches the task list from windows cmd, stores it as an array, appends an identical timestamp to each task, and then appends it to a text file as a comma-delimited table so an analyst can load it into excel later.</p>
  <p><strong>Trouble</strong>: The question here is how to create an additional column in the array, and then populate it with the timestamp. The standard numpy functions (append) don't seem to quite do what I need, and accessing specific columns in an array and referencing them in a loop is still unclear to me. I'm new enough to arrays that I might be missing a key piece of logic</p>
  <p><strong>Code so far</strong>:</p>
  <pre><code>import os, sys, subprocess, numpy, csv, datetime
  
  
  # Set the output location to a user provided location, where a txt simply named with the date will be stored for that day.
  date_ = datetime.datetime.now()
  date = date_.strftime('%Y%m%d')
  timestamp = date_.strftime('%x %X')
  output_ = raw_input(&quot;Please enter the directory where you would like the task list to be compiled:&quot;)
  location = output_ +'\\tasklist_' + str(date) +'.txt'
  
  
  # Create the array from tasklist
  subprocess.check_output('tasklist /fo csv &gt; %userprofile%\desktop\processes.csv')
  arrays = [numpy.array(map(str, line.split(',')))for line in open('C:\Users\[USER]\Desktop\processes.csv')]
  
  
  # Iterate over the array, and append the timestamp:
  rows = len(x)
  count = 0
  
  for task in arrays:
      if count &lt;= rows:
          count =+ 1
          ## ADD TIMESTAMP
  
  
  # Check for output txt. If it exists, append to it. if it doesnt, write over it.
  if os.path.isfile(location) == True:
      numpy.delete(arrays,(0),axis=0)
      with open(location, &quot;a+&quot;) as save:
          save.write(arrays)
  else:
      with open(location, &quot;a+&quot;) as save:
          save.write(arrays)
  </code></pre>
  <p><strong>Helpful mentions</strong>: This question <a href="https://stackoverflow.com/questions/13525882/tasklist-output">here</a> helped me set up the Task List procedure.</p>
  <p>Thanks for viewing!</p>