Programmer's CornerHere are some python scripts, modules, and code snippets which could be of interest to fellow python programmers.
These are all used within Métamorphose, but can be used in other programs or in shell scripts.
Check each file for licensing info.
accentStrip.pyRemoves accents and splits linked letters (ligatures) from the full set of Unicode Latin characters for ASCII compatability.
import accentStrip test = u"¡ŦĦË Ɋṻîčḵ Ƀṝọẁñ Ḟøẍ Ɉṻḿṗş Ṏṽḝŗ Ŧĥệ Ⱡåẕÿ Ğṑð! ¿Cette œuvre là? Große. ॐ" # automatically choose best method print accentStrip.autoConvert(test) # full conversion, slow for large strings print accentStrip.fullConvert(test) # no squashing but much faster for large strings such as files print accentStrip.fastConvert(test)Input is Unicode, the output is Unicode which will map directly to ASCII.
Up to you to convert to/from your encoding.
greek_numb.pyConvert whole numbers to Greek numerals. In the case of a negative integer, its absolute value will be used.
Input can be an integer or a string, output will be in unicode.
Based on Greek.pm
Example usage in python:
import greek_numb as greek
greek_number = greek.int2greek(1984, arch_qoppa=True)
Variables (default values shown):
- numbersign = True
- Append the Greek numerical symbol 'ʹ' to number
- upper = False
- Return capital letters
- stigma = True
- Use stigma 'ϛ' rather than sigma-tau 'στ' for 6
- arch_qoppa = False
- Use archaic qoppa 'ϙ' rather than modern 'ϟ' for 90
Usage from command line:
Testing in bash:
for ((i=0; i<=100; i=i+1)); do ./greek_numb.py $i; done;