title: Python: Looping through multiple csv files and making multiple new csv files
body: <p>I am starting out in Python, and I am looking at csv files.</p>
  
  <p>Basically my situation is this:</p>
  
  <p>I have coordinates X, Y, Z in a csv.</p>
  
  <pre><code>X Y Z
  1 1 1
  2 2 2
  3 3 3
  </code></pre>
  
  <p>and I want to go through and add a user defined offset value to all Z values and make a new file with the edited z-values.</p>
  
  <p>here is my code so far which I think is right:</p>
  
  <pre><code># list of lists we store all data in
  allCoords = []
  # get offset from user
  offset = int(input("Enter an offset value: "))
  # read all values into memory
  with open('in.csv', 'r') as inFile: # input csv file
      reader = csv.reader(inFile, delimiter=',') 
      for row in reader:
          # do not add the first row to the list
          if row[0] != "X": 
              # create a new coord list
              coord = []
              # get a row and put it into new list
              coord.append(int(row[0]))
              coord.append(int(row[1]))
              coord.append(int(row[2]) + offset)
              # add list to list of lists
              allCoords.append(coord)
  
  # write all values into new csv file
  with open(in".out.csv", "w", newline="") as f:
      writer = csv.writer(f)
      firstRow = ['X', 'Y', 'Z']
      allCoords.insert(0, firstRow)
      writer.writerows(allCoords)
  </code></pre>
  
  <p>But now come's the hard part. How would I go about going through a bunch of csv files (in the same location), and producing a new file for each of the csv's.</p>
  
  <p>I am hoping to have something like: "filename.csv" turns into "filename_offset.csv" using the original file name as a starter for the new filename, appending ".offset" to the end.</p>
  
  <p>I think I need to use "os." functions, but I am not sure how to, so any explanation would be much appreciated along with the code! :)</p>
  
  <p>Sorry if I didn't make much sense, let me know if I need to explain more clearly. :)</p>
  
  <p>Thanks a bunch! :)</p>