xxRookiexx
xxRookiexx

Reputation: 1

How do I do this with Chinese text?

The below works well for English, but not Chinese lyrics.

import pyautogui, time
time.sleep(5)
f = open('/Users/a27/爱.txt', 'r','UTF-8')
for word in f:
    pyautogui.typewrite(word)
    pyautogui.press("enter")

It says str object cannot be interpreted as an integer. How can I process Chinese strings?

Upvotes: -1

Views: 118

Answers (1)

Shark44
Shark44

Reputation: 803

The problem is in the way you are opening the file. Try to use the following syntax:
with open('/Users/a27/爱.txt', 'r', encoding='utf-8') as f:
Edited code:

import pyautogui, time
time.sleep(5)
with open('/Users/a27/爱.txt', 'r', encoding='utf-8') as f:
    for word in f:
        pyautogui.typewrite(word)
        pyautogui.press("enter")

Upvotes: 0

Related Questions