Outputting Japanese Characters to a File using Python

后端 未结 1 1321
青春惊慌失措
青春惊慌失措 2021-01-21 14:49

Goal --> I am trying to automate the query execution process using Python

Detail --> My Source is Teradata Database a

1条回答
  •  后悔当初
    2021-01-21 15:38

    Let's solve the title problem. To output Japanese (or any language) to a file:

    1. Start with a Unicode string.
    2. Open the file for writing and specify an encoding.
    3. Write the string to the file.

    Example using Python 3:

    s = 'ペット用品'
    with open('results.txt','w',encoding='utf8') as f:
        f.write(s)
    

    Your rows isn't a Unicode string, but a list with a tuple with an incorrect string. That's another problem you'll have to solve.

    0 讨论(0)
提交回复
热议问题