python opens text file with a space between every character

前端 未结 8 1639
野性不改
野性不改 2021-02-18 17:27

Whenever I try to open a .csv file with the python command fread = open(\'input.csv\', \'r\') it always opens the file with spaces between every single character.

8条回答
  •  無奈伤痛
    2021-02-18 17:40

    Ok, I got it with the help of Jarret Hardie's post

    this is the code that I used to convert the file to ascii

    fread = open('input.csv', 'rb').read()
    mytext = fread.decode('utf-16')
    mytext = mytext.encode('ascii', 'ignore')
    fwrite = open('input-ascii.csv', 'wb')
    fwrite.write(mytext)
    

    Thanks!

提交回复
热议问题