How to use import

opposite_ai.py


import math
#AI for the opposite
class Oppai:
    #processing
    pass

hent_ai.py


#Grab motion AI
class Hentai:
    #processing
    pass

app.json.py


import hent_ai
from hent_ai import Hentai #Hentai()Can be instantiated with
import opposite_ai as oppai #opposite at oppai_You can use ai.
import opposite_ai.math #oppai.You don't have to write math.
try:
    setai=__import__("set_ai")#Advanced Setting. With or without

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("Enter something")
        return

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

Recommended Posts

How to use import
How to use xml.etree.ElementTree
How to use virtualenv
How to use Seaboan
How to use image-match
How to use shogun
How to use Pandas 2
How to use Virtualenv
How to use numpy.vectorize
How to use pytest_report_header
How to use partial
How to use SymPy
How to use x-means
How to use WikiExtractor.py
How to use IPython
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
How to use TokyoTechFes2015
How to use venv
How to use dictionary {}
How to use Pyenv
How to use list []
How to use python-kabusapi
How to use OptParse
How to use dotenv
How to use pyenv-virtualenv
How to use imutils
[Python] How to use import sys sys.argv
How to use search sorted
[gensim] How to use Doc2Vec
Understand how to use django-filter
How to use the generator
[Python] How to use list 1
How to use FastAPI ③ OpenAPI
How to use Python argparse
How to use IPython Notebook
How to use Pandas Rolling
[Note] How to use virtualenv
How to use redis-py Dictionaries
Python: How to use pydub
[Python] How to use checkio
[Go] How to use "... (3 periods)"
How to use Django's GeoIp2
[Python] How to use input ()
How to use the decorator
[Introduction] How to use open3d
How to use Python lambda
How to use Jupyter Notebook
[Python] How to use virtualenv
python3: How to use bottle (3)
How to use Google Colaboratory
How to use Python bytes
How to use cron (personal memo)
Python: How to use async with
How to use the zip function
How to use the optparse module
Summary of how to use pandas.DataFrame.loc
How to install and use Tesseract-OCR
How to use classes in Theano