0

I'm trying to edit a csv file and replacing some commas in the data. I'm calling my function using:

with open(my_data,'r') as file:
        for i in range(3):
            print(my_func(file.readline()))

and this is my code

def my_func(data):
    my_string=""
    my_string=my_string+(data[0:len(data)]) #add first line of csv file
    stripped=data.strip()
    stripped=stripped.replace(",","") #remove comma from every line
    my_string=my_string+(stripped)
    print(stripped)

Output returns original data, my edit, None: Not sure where the None values come from.

This,is,the,alphabet #first line of original data
Thisisthealphabet #first line of original data, with replacement of comma applied
None
A,B,C #second line of original data
ABC #second line of original data, with replacement of comma applied
None
D,E,F #third line
DEF
None

Expected:

This,is,the,alphabet #WITH commas, as in original data
ABC
DEF
catzen
  • 51
  • 4
  • 3
    There's no need to print the `None` returned from `my_func()`. You have two options: 1. Just call `my_func(...)` from your loop. 2. Instead of `print(stripped)`, change it to `return stripped`. – quamrana Aug 15 '20 at 17:18
  • 1
    can you please provide the input and expected output in code blocks separately? – Akshay Sehgal Aug 15 '20 at 17:27

0 Answers0