I rewrite the program in Python2 for changes in the third branch of Python. In the script there is a line in which some piece of code from the file is executed using the exec function. Namely, it is a set of language localization variables.

Here is an example of the first lines of the russian.txt file:

# -*- coding: utf-8 -*- # # Файл русской языковой локализации # string_lang_mobile_client_label = "Мобильный клиент сайта [color=#key_text_color]" string_lang_name_program = "HeaTDV4A:" string_lang_plugin = "Плагины" string_lang_articles = "Статьи" string_lang_add_answer_in_forum = "Добавить пост" 

Now when

 exec(open("russian.txt").read() 

I get the error:

 Traceback (most recent call last): File "Libs/programdata.py", line 70, in <module> exec(open("Data/Language/russian.txt").read()) File "<string>", line 1# -*- coding: utf-8 -*- ^ SyntaxError: invalid character in identifier 

Tell me where I am mistaken, since the third branch of Python is familiar only by hearsay?

  • Show the file russian.txt - gil9red
  • Well, in general, in the question I brought a piece. By the way, the solution to this problem is: exec (open ("russian.txt"), encoding = 'utf-8-sig'). Read ()) - Xyanight
  • You are right - inattentive was, I thought that this is the part of the code in which exec is called. I tried to run these lines in myself there were no problems, the encoding of that file is utf8? - gil9red
  • Yes, utf-8 encoding. - Xyanight

1 answer 1

The solution to this problem:

 exec(open("russian.txt"), encoding='utf-8-sig').read())