0

Every day I export a csv that has values seperated by "|". I need to change a value in an output file that I know will be between the 25th and 26th occurrence of "|".

Below is what I am currently doing, which is finding each date by hand, writing it down, then inputting it.

inputFile  = open('example.csv',"r")
inputFile = ''.join([i for i in inputFile]).replace(DateToChange,ChangedDate)
outputFile = open("output.csv","w")
outputFile.writelines(inputFile)
outputFile.close()

Is there a way to find and replace text between two occurrences of the "|" character?

Jacob
  • 346
  • 3
  • 13
  • 2
    First of all, you should use the Python `csv` module. You can define '|' as your delimiter. After that, just read in the file, change the 25th element of the row you need, and write the file back. – ahota Nov 20 '18 at 20:10
  • @ahota how would I go about that? I am using the `csv` module to load in my sheet. I am sorry if this is very basic, I am just starting to learn python. – Jacob Nov 20 '18 at 20:16
  • Take a look at the answer this question got marked a duplicate of; it has a good example you can pull from. – ahota Nov 20 '18 at 20:19
  • We don't "know" this, we had to learn it first as well. For a full overview, see [the official documentation of `csv`](https://docs.python.org/3/library/csv.html) – it specifically mentions this delimiter as one of the many configurable options. If you are new to Python, you probably want to work through the official tutorial on that site site as well. – Jongware Nov 20 '18 at 20:20

0 Answers0