singleton in python
📁 Advanced Python Topics, AI
Implemented singleton from Wiki()
My code:
class SpriteManager(object): def __new__(cls): if not hasattr(cls, 'instance'): cls.instance = super(SpriteManager, cls).__new__(cls) retu cls.instance def __init__(self): self.setSprite = set()Every time I call SpriteManager() the constructor is called. According to the singleton concept
I don't know a way to end input with a specific key, but I know another method:
var = """".join(iter(input, """"))In this case, input will end when you press enter on an empty line.
Since people are upvoting, I think it's worth explaining the code:iter(input, """") will yield the result of calling the input function without arguments, until input() returns an empty string (""""). Then we simply join all the results from this generator using """".
Log in to leave an answer
Blogs