简体   繁体   中英

Writing on csv file with extra spacings

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()

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

(f,delimiter=' ')

you have spaces between the single quotes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM