Уведомления

Группа в Telegram: @pythonsu

#1 Март 27, 2012 18:14:28

ctocopok
От:
Зарегистрирован: 2011-04-09
Сообщения: 21
Репутация: +  0  -
Профиль   Отправить e-mail  

gettext - ничего не понимаю :)

Есть набор из нескольких .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

Что я делаю не так? :(



Advertising the only makes people buy things they don't need.

Офлайн

#2 Март 28, 2012 09:48:15

ctocopok
От:
Зарегистрирован: 2011-04-09
Сообщения: 21
Репутация: +  0  -
Профиль   Отправить e-mail  

gettext - ничего не понимаю :)

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

идиотский вопрос, конечно, жаль, что в доках про бинарность файлов не помечено отдельно :)



Advertising the only makes people buy things they don't need.

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version