Найти - Пользователи
Полная версия: gettext - ничего не понимаю :)
Начало » Python для новичков » gettext - ничего не понимаю :)
1
ctocopok
Есть набор из нескольких .mo файлов от проета на Python 2.6

Хотел с ними поработать. Но не смог подступиться.

import gettext
f = open('messages.mo','r')
cat = gettext.GNUTranslations()
print cat.gettext('marker')

Результат:
python make_def.py
Traceback (most recent call last):
File "make_def.py", line 6, in <module>
print cat.gettext('marker')
File "C:\Python26\lib\gettext.py", line 345, in gettext
tmsg = self._catalog.get(message, missing)
AttributeError: GNUTranslations instance has no attribute '_catalog'

Если сделать
import gettext
f = open('messages.mo','r')
cat = gettext.GNUTranslations(f)
print cat.gettext('marker')

получаем:
python make_def.py
Traceback (most recent call last):
File "make_def.py", line 4, in <module>
cat = gettext.GNUTranslations(f)
File "C:\Python26\lib\gettext.py", line 180, in __init__
self._parse(fp)
File "C:\Python26\lib\gettext.py", line 287, in _parse
tlen, toff = unpack(ii, buf[transidx:transidx+8])
struct.error: unpack requires a string argument of length 8

Что я делаю не так? :(
ctocopok
по первому варианту комментариев у меня нет, а по второму - файл надо открывать для чтения бинарно f=open('messages.mo','rb')

идиотский вопрос, конечно, жаль, что в доках про бинарность файлов не помечено отдельно :)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB