Python Forum
insert value to specific line in CSV file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
insert value to specific line in CSV file
#1
Hello,

I have a CSV.file that looks something like this:

Carrot
Cake
Other,Values
test1,test
Abc,test,test1
MyString
The CSV values might change.
In case, IF "MyString" is in the CSV file, I want to add two new values('myValue1','myValue2') between first two, so between 'Carrot' and 'Cake' in this case. Then the CSV file will be:

Carrot
myValue1
myValue2
Cake
Other,Values
test1,test
Abc,test,test1
MyString
If "myString" is not in the CSV file then the original file remains the same.
Reply
#2
You can use any text editor to do this
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Extracting specific file from an archive tester_V 4 523 Jan-29-2024, 06:41 PM
Last Post: tester_V
  Python Serial: How to read the complete line to insert to MySQL? sylar 1 833 Mar-21-2023, 10:06 PM
Last Post: deanhystad
  File "<string>", line 19, in <module> error is related to what? Frankduc 9 12,588 Mar-09-2023, 07:22 AM
Last Post: LocklearSusan
  Getting last line of each line occurrence in a file tester_V 1 877 Jan-31-2023, 09:29 PM
Last Post: deanhystad
  Reading Specific Rows In a CSV File finndude 3 995 Dec-13-2022, 03:19 PM
Last Post: finndude
  python insert blank line in logger mg24 1 2,861 Nov-02-2022, 08:36 AM
Last Post: snippsat
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,387 Sep-27-2022, 01:38 PM
Last Post: buran
  How to extract specific data from .SRC (note pad file) Shinny_Shin 2 1,284 Jul-27-2022, 12:31 PM
Last Post: Larz60+
  Insert a multiple constant value after header in csv file using python shantanu97 1 1,159 Apr-24-2022, 10:04 AM
Last Post: Pedroski55
  Print to a New Line when Appending File DaveG 0 1,228 Mar-30-2022, 04:14 AM
Last Post: DaveG

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020