title: How to slice and loop through a netCDF variable in Python?
body: <p>I have a netCDF variable with 372 time-steps, I need to slice this variable to read in each individual time-step for subsequent processing.</p>
  
  <p>I have used glob. to read in my 12 netCDF files and then defined the variables.
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>NAME_files = glob.glob('RGL*nc')
  NAME_files = NAME_files[0:12]
  
  for n in (NAME_files):    
      RGL = Dataset(n, mode='r')
      footprint = RGL.variables['fp'][:]
      lons = RGL.variables['lon'][:]
      lats = RGL.variables['lat'][:]</code></pre>
  </div>
  </div>
  </p>
  
  <p>I now need to repeat the code below in a loop for each of the 372 time-steps of the variable 'footprint'. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>footprint_2 =  RGL.variables['fp'][:,:,1:2]</code></pre>
  </div>
  </div>
  </p>
  
  <p>I'm new to Python and have a poor grasp of looping. Any help would be appreciated, including better explanation/description of my issue.</p>