I'm working on a text-based adventure game, and this code searches through a room file and pulls a substring from it that adds it to a list of enemies.
with y.index("~") as _0:
self.room_enemies.append(y[_0:_0])
print(y[_0:_0])
However, when I run it, it gives me this:
AttributeError: __enter__
If this isn't enough information for a good answer, please let me know.
withis not variable assignment. If you want to assign variables, use the equal sign.(Though
_0is an extremely bizarre variable name)withis used with context managers, such as opened files or database connections, and it's sort of like Java's try-with-resources block. It won't work on arbitrary data types that haven't been designed with the construct in mind.