Answer the question
In order to leave comments, you need to log in
How to make it so that there are no encoding errors when pasted into a QTextBrowser?
I insert lines from a file into qtextbrowser, then I save them to a file like this (when changing qtextbrowser)
self.accounts = []
lists = self.all_accounts_task.toPlainText().split('\n')
for l in lists:
if l != '' and l != '\n':
self.accounts.append(l)
self.all_accs_task.setText(str(len(self.accounts)))
cfg = ConfigParser()
cfg.read('settings/default/tasks.ini', encoding='utf-8')
cfg[self.task_name].update({'accs': '\n'.join(self.accounts).replace('%', '%%')})
cfg[self.task_name].update({'all_accs_task': str(len(self.accounts))})
with open('settings/default/tasks.ini', 'w', encoding='utf-8') as setfile:
cfg.write(setfile)
UnicodeEncodeError: 'utf-8' codec can't encode character '\uda36' in position 20: surrogates not allowed
Answer the question
In order to leave comments, you need to log in
use io library:
import io
with io.open('test.txt', 'w') as f:
pass
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question