Python Forum
Converted Pipe Delimited text file to CSV file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converted Pipe Delimited text file to CSV file
#1
Hello, I'm trying to add some columns with values such as index but I have an error in line 16. Hope anyone can help. Thanks!

import csv
import glob

header = ['NAME','ADDRESS','PHONE','EMAIL']

# with pipe delimter data
with open("datafile.txt", mode='r') as text_pipe:
    reader_pipe = csv.reader(text_pipe, delimiter = '|')
   
    with open("output.csv", 'w', newline = '') as file_comma:
        writer_delim = csv.writer(file_comma, delimiter = ',')
        writer_delim.writerow(header) # add header
        record_index = 1 # index sequence
        
        for row in reader_pipe: # loop to read file
            writer_delim.writerow(record_index,row) # print value in each line
            record_index = record_index + 1
Error:
Exception has occurred: TypeError writerow() takes exactly one argument (2 given) writer_delim.writerow(record_index,row) # print value in each line
Reply


Messages In This Thread
Converted Pipe Delimited text file to CSV file - by atomxkai - Feb-04-2022, 11:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to Randomly Print a Quote From a Text File When User Types a Command on Main Menu BillKochman 13 1,072 Apr-24-2024, 05:47 AM
Last Post: Bronjer
  very newbie problem on text file zapad 2 272 Apr-12-2024, 06:50 PM
Last Post: zapad
  Tab Delimited Strings? johnywhy 7 633 Jan-13-2024, 10:34 PM
Last Post: sgrey
  file open "file not found error" shanoger 8 1,209 Dec-14-2023, 08:03 AM
Last Post: shanoger
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,547 Nov-09-2023, 10:56 AM
Last Post: mg24
  Replace a text/word in docx file using Python Devan 4 3,624 Oct-17-2023, 06:03 PM
Last Post: Devan
  Need to replace a string with a file (HTML file) tester_V 1 795 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  How can I change the uuid name of a file to his original file? MaddoxMB 2 970 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  save values permanently in python (perhaps not in a text file)? flash77 8 1,278 Jul-07-2023, 05:44 PM
Last Post: flash77
  Converted EXE file size is too large Rajasekaran 0 1,546 Mar-30-2023, 11:50 AM
Last Post: Rajasekaran

Forum Jump:

User Panel Messages

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