Home > Software design >  Writing on csv file with extra spacings
Writing on csv file with extra spacings

Time:11-18

I'm generating numbers with 21 characters, I want to write each number generated on a csv file.

The output has spaces between each character of every number so instead of "001657618586303086816" I have "0 0 1 6 5 ... 1 6".

Here is my code:

def generate_numbers(n):
    f=open("data.csv","a",newline='')
    writer=csv.writer(f,delimiter=' ')

    for i in range(n):
        numb='0016'   str(randint(111111111111111,999999999999999))   '16'
    
        writer.writerow(nib)
        
f.close()

CodePudding user response:

But, you are yourself adding the spaces, aren't you?

(f,delimiter=' ')

you have spaces between the single quotes

  • Related