python言語による主の祈り

#1.はじめに
* 昔、[slashdotジャパン](https://srad.jp/)というサイトで紹介されていて見つけた「[Java言語による主の祈り](https://www.hyuki.com/prayer/prayjava.html)」。
* 当時は（今も）Javaでコードを書けませんが、コード以外の検討部分を興味深く読んだことをふと思い出し、今ならpythonでかけるかもと思いトライすることに。

#2.原文（Java）の言語
上記のサイトから

```java
/**
 * Prayer.java - Version 1.2.2
 * Programmed by Hiroshi Yuki in 1998. Revised in 1999, 2008.
 * hyuki@hyuki.com
 * http://www.hyuki.com/prayer/prayjava.html
 */

import java.net.*;
import java.io.*;
import java.util.*;
import Heaven.faith.*;
import Heaven.hope.*;
import Heaven.love.*;

public class Prayer extends HumanBeing {
    private HolySpiritualOutputStream out;
    static public void main(String args[]) {
        try {
            Prayer We = new Prayer();
            while (isAlive(We)) {
                We.worshipGod();
                We.prayForDailyNeed();
                We.Amen();
            }
        } catch (Exception e) { }
    }
    private Prayer() throws IOException {
        Socket socket = new Socket("OurFather.in.Heaven", Heaven.PRAYER_PORT);
        out = new HolySpiritualOutputStream(socket.getOutputStream());
    }
    private void worshipGod() throws IOException {
        out.write("hallowed be Your name,");
        out.write("Your kingdom come,");
        out.write("Your will be done on earth as it is in heaven.");
    }
    private void prayForDailyNeed() throws IOException {
        out.write("Give us today our daily bread.");
        out.write("Forgive us our debts,");
        out.write("as we also have forgiven our debtors.");
        out.write("And lead us not into temptation,");
        out.write("but deliver us from the evil one.");
    }
    private void Amen() throws IOException {
        out.write("for Yours is the kingdom and the power and the glory for ever.");
        out.write("Amen.");
    }
}


```


#3.pythonで
上の形式を真似して作成（中）。
Heavenライブラリってどうすりゃいいんだ。
・HolySpiritualOutputStreamってなんだろう。「主に対する祈り」だそうだけど。


```python
import socket

from Heaven import faith
from Heaven import hope
from Heaven import love

class HumanBeing(object):
	def __init__(self):
		self.isAlive = True

class Prayer(HumanBeing):
    def __init__(self):
        isAlive = super(Prayer, self).__init__()
  
    #HolySpiritualOutputStream() #
    #HolySpiritualInputStream()

    def Prayer(self):
        try:
            Socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            Socket.bind((socket.gethostname(), 1235))
        except:
            pass

    def worshipGod(self):
        print("hallowed be Your name,");
        print("Your kingdom come,");
        print("Your will be done on earth as it is in heaven.");        

    def prayForDailyNeed(self):
        print("Give us today our daily bread.")
        print("Forgive us our debts,")
        print("as we also have forgiven our debtors.")
        print("And lead us not into temptation,")
        print("but deliver us from the evil one.")        

    
    def Amen(self):
        print("for Yours is the kingdom and the power and the glory for ever.")
        print("Amen.")


We = Prayer()
while(We.isAlive):
    We.worshipGod()
    We.prayForDailyNeed()
    We.Amen()

```


実行結果（現状、ずっと続いてしまう）


    hallowed be Your name,
    Your kingdom come,
    Your will be done on earth as it is in heaven.
    Give us today our daily bread.
    Forgive us our debts,
    as we also have forgiven our debtors.
    And lead us not into temptation,
    but deliver us from the evil one.
    for Yours is the kingdom and the power and the glory for ever.
    Amen.
    hallowed be Your name,
    Your kingdom come,
    Your will be done on earth as it is in heaven.
    Give us today our daily bread.
    Forgive us our debts,
    as we also have forgiven our debtors.
    And lead us not into temptation,
    but deliver us from the evil one.
    for Yours is the kingdom and the power and the glory for ever.
    Amen.
    hallowed be Your name,
    Your kingdom come,
    Your will be done on e
    ・・・


#4.検討中
* def Prayerのsocketの使い方:socketは１回も使ったことないのでよくわからず。Javaコードのsocketと同じものとして扱っていいのか？？
* HolySpiritualOutputStream() とHolySpiritualInputStream()の扱い。これはメソッドとすればいいのか？
* Heavenライブラリをimportしたものの使ってない。
* インスタンスの生成後に死ぬタイミングの設定とか、途中でexceptionが発生する設定を要検討。