There is a config with the following content:

[config] fontname = Times fontsize = 12 ffpmeg_path = ffmpeg/bin/ffmpeg.exe mp3-wav = -acodec pcm_u8 -ar 22050 wav-mp3 = -vn -ar 44100 -ac 2 -ab 192 -f mp3 fextensions = mp1,mp2,mp3,mp4,ogg,avi,flac [ru_RU] mainwin = ffmpeg GUI filemenu = Файл openfile = Открыть appquit = Выход choosefile = Выберите файл filepath_cells = Файл filesize_cells = Размер fileffi_cells = Формат fileffo_cells = Результат accept = Ок cancel = Отмена [en_EN] mainwin = ffmpeg GUI formatswin = File format filemenu = File openfile = Open appquit = Quit choosefile = Choose file filepath_cells = File filesize_cells = Size fileffi_cells = Input fileffo_cells = Output accept = Ok cancel = Cancel 

And the function to handle this config:

  def get_info(self,section,key,rv=0,rt=str,sep=None): cf = configparser.ConfigParser( allow_no_value=True, interpolation=configparser.ExtendedInterpolation() ) cf.readfp(codecs.open('config.ini','r','utf8')) if sep == None: return ''.join(rt(cf[section][key])) else: return ''.join(cf[section][key].split(sep)) 

When I try to call print(main.get_info(0,'config','fontname')) error pops up:

 Traceback (most recent call last): File "main.py", line 132, in <module> print(main.get_info(0,'config','fontname')) File "main.py", line 124, in get_info cf.readfp(codecs.open('config.ini','r','utf8')) File "C:\Python34\lib\configparser.py", line 735, in readfp self.read_file(fp, source=filename) File "C:\Python34\lib\configparser.py", line 690, in read_file self._read(f, source) File "C:\Python34\lib\configparser.py", line 1057, in _read raise MissingSectionHeaderError(fpname, lineno, line) configparser.MissingSectionHeaderError: File contains no section headers. file: 'config.ini', line: 1 '\ufeff[config]\r\n' 

At the beginning of the file there is "# - -coding: utf-8- -". I tried to edit the config through a regular notepad - it works. As soon as I open it through "Sublime Text 3" all Russian characters "break". What am I doing wrong?

  • Does the usual notebook already utf-8? - vp_arth
  • # - - coding: cp1251 - - - vadim vaduxa

0