Theiling Online    Sitemap    Conlang Mailing List HQ   

Re: Irish.py was Re: A Conlang-L FAQ, preliminary version

From:Philip Newton <philip.newton@...>
Date:Wednesday, April 10, 2002, 7:51
On 8 Apr 02, at 20:59, Peter Clark wrote:

> If you are interested, I have attached the code. Save it as "irish.py" and > include the text you want to convert in the command line, for instance, > "./irish.py irish.txt". Note that this will overwrite the file, so don't run > it on something you want to keep.
Yes? Doesn't sys.stdin mean "standard input"? If so, how would sys.stdin.readline() read from "irish.txt"?
> - --- > #!/usr/bin/python > # Licensed under the GPL by Peter Clark, 2001 > > import sys, string > for s in sys.stdin.readline(): > if s[0] == ">": > sys.stdout.write(s) > else: > s = string.replace(s, "ay", "ae") > s = string.replace(s, "ck", "ch") > s = string.replace(s, "ey", "ie") > s = string.replace(s, "ke", "che") > s = string.replace(s, "ki", "chi") > s = string.replace(s, "ye", "ie") > s = string.replace(s, "j", "i") > s = string.replace(s, "k", "c") > s = string.replace(s, "q", "c") > s = string.replace(s, "v", "u") > s = string.replace(s, "w", "u") > s = string.replace(s, "x", "gh") > s = string.replace(s, "y", "ie") > s = string.replace(s, "z", "s") > sys.stdout.write(s) > - ---
I couldn't resist :P #!/usr/bin/perl -wp BEGIN { %irish = ( 'ay' => 'ae', 'ck' => 'ch', 'ey' => 'ie', 'ke' => 'che', 'ki' => 'chi', 'ye' => 'ie', 'j' => 'i', 'k' => 'c', 'q' => 'c', 'v' => 'u', 'w' => 'u', 'x' => 'gh', 'y' => 'ie', 'z' => 's' ); } s/([jkqvwxyz]|[ae]y|ck|k[ei]|ye)/$irish{$1}/g; Invoke this as 'irish.pl' or 'irish.pl file1' or even 'irish.pl file1 file2 ...'. The output will go to stdout. The loop over standard input (or files, if given on the command line) and the printing occurs automatically thanks to the -p switch. So the main job is done by the substitution command. Cheers, Philip -- Philip Newton <Philip.Newton@...>