# coding: utf-8 # !/usr/bin/python # クラス定義 class HelloWorld(object): ''' HelloWorldのコンテキストクラス ''' def __enter__(self): ''' __enter__ ''' self.__out = '' self.__string = ['0x48', '0x65', '0x6c', '0x6c', '0x6f', '0x20', '0x57', '0x6f', '0x72', '0x6c', '0x64', '0x21'] return self def __exit__(self, exc_type, exc_value, traceback): ''' __exit__ ''' print(self.__out) return True def get_out(self): ''' outのゲッター ''' return self.__out def set_out(self, asc): ''' outのセッター ''' self.__out += chr(int(asc, 16)) def get_string(self): ''' stringのゲッター ''' return self.__string # propertyの設定 out = property(get_out, set_out) string = property(get_string) # メインの処理 def main(): count = ans = 0 with HelloWorld() as hello: while True: ans = hello.string[count] hello.out = ans count += 1 # 直接呼び出されているか if __name__ == '__main__': main() else: print('Hello World!')