0

「gi.repository Notification」に新しい行を表示できません。プログラム内で文字列定数を使用すると機能しますが、ConfigParser クラスを使用して構成ファイルから文字列を読み取ると失敗します。

test.ini

[NOTIFICATIONS]
test1 = Hello,\n{username}!

test.py:

import ConfigParser
from gi.repository import Notify

# notifyText = "Hello, {username}" - will work
data = {'username': 'sudo', 'test': 'test'}


if __name__ == '__main__':
    cfg = ConfigParser.ConfigParser()                              
    cfg.read('test.ini')
    notifyText = cfg.get('NOTIFICATIONS', 'test1').format(**data)

    Notify.init('Test')
    notification = Notify.Notification('Test', notifyText)
    notification.show()

現在のプログラムの出力は次のようになります: 'Hello\nsudo!' ただし、プログラムでこの文字列 (コメント行) をハードコードすると、本来のように表示されます。

4

1 に答える 1