0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

importの使い方

Last updated at Posted at 2020-12-30
opposite_ai.py
import math
# 反対向けのAI
class Oppai:
    #処理
    pass
hent_ai.py
#つかむ動作のAI
class Hentai:
    #処理
    pass

app.json.py
import hent_ai
from hent_ai import Hentai #Hentai()でインスタンス作成できる
import opposite_ai as oppai #oppaiでopposite_aiが使える。
import opposite_ai.math #oppai.mathと書かなくてよくなる。
try:
    setai=__import__("set_ai")#詳細設定。有無が

except Exception as e:
    print(e)

class classproperty(property):
    pass

class PropertyMeta(type):

    def __new__(cls, name, bases, namespace):
        props = [(k, v) for k, v in namespace.items() if type(v) == classproperty]
        for k, v in props:
            setattr(cls, k, v)
            del namespace[k]
        return type.__new__(cls, name, bases, namespace)

class StartUp(metaclass=PropertyMeta):
    __this = None

    def __init__(self):
        self.hentai = Hentai()
        self.oppai = oppai.Oppai()
        pass
    
    @classproperty
    def value(cls):
        if cls.__this is not None:
            return cls.__this
        cls.__this = StartUp()
        return cls.__this

    @classmethod
    def main(cls):
        cls.value
        print("Hello World")
        cls.__this.input = input("何か入力")
        return

if __name__ == "__main__":
    StartUp.main()
0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?