python encoding error

python encoding error

  • 에러 메세지 : UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xff in position 0: invalid

  • 해결 방법 : encoding 부분을 utf-8에서 utf-16으로 바꿔주니까 된다. ( python3 기준 )

  • 예시 코드

    # -*- coding: utf-8 -*-:
    import csv
    f = open('1_50000.csv', 'r', encoding='utf-16')
    rdr = csv.reader(f)
    for line in rdr:
        print(line)
    f.close()

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×