我想知道是否有可能加入with和while True循环,因为while True非常简单(一直运行到有东西破坏它),而且有点浪费缩进。
这是一些示例代码,就像我目前正在做的那样:
class Something(object):
def __init__(self):
self.num = 5
def __enter__(self):
return self
def __exit__(self, *args):
pass
while True:
with Something() as s:
print s.num如果可能,我如何将其更改为类似于此的内容?
while Something() as s:
print s.numhttps://stackoverflow.com/questions/34005266
复制相似问题