PyHyphen - libhyphen-2.3.1 wrapped for the Python programming language

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

PyHyphen - libhyphen-2.3.1 wrapped for the Python programming language

Dr. leo

I am new to this list and just a hobby programmer. For various reasons I
found that the Python programming language needed a hyphenation feature. So
I happened to find libhyphenwith all those wonderful dictionaries and wrote
a wrapper for Python. The result is a C extension module with some Python
code on top for convenient access. I thought I let you know. Maybe you find
it useful for testing and/or working on dictionaries. There is a module
called 'dictools' in the hyphen package that can download and install
dictionaries on the fly. There is also a test framework to hyphenate
multiple word lists with multiple dictionaries. The latter are installed
automatically (provided you have internet access). All tests are logged...
The source distribution includes Windows binaries for Python 2.4 and 2.5, so
you don't need a compiler to get going. Just unpack it and enter the usual
command: "python install".

You can download PyHyphen from the Python package index at

Code example:

from hyphen import hyphenator
from hyphen.dictools import *

# Download and install some dictionaries in the default directory using the
# repository, usually the OpenOffice website
for lang in ['de_DE', 'fr_FR', 'en_UK', 'hu_HU']:
    if not is_installed(lang): install(lang)

# Create some hyphenators
h_de = hyphenator('de_DE')
h_en = hyphenator('en_US')
h_hu = hyphenator('hu_HU')

# Now hyphenate some words

print h_hu.inserted(u'asszonnyal')

print h_en.pairs('beautiful')
[[u'beau', u'tiful'], [u'beauti', u'ful']]

print h_en.wrap('beautiful', 6)
[u'beau-', u'tiful']

print h_en.wrap('beautiful', 7)
[u'beauti-', u'ful']

from textwrap2 import fill
print fill('very long text...', width = 40, use_hyphens = h_en)



To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]