在Python2中,我可以做类似的事情。
frames = deque(maxlen=xyz)
framesString = ''.join(frames)
在Python3中,我得到一个错误。
我应该如何改变它,以便得到一个代表deque对象的字符串?
先谢谢你,G。
来自Python官方 文件,您可以使用 deque
像这样。
from collections import deque
# With an infinite length
frames = deque('ytreza')
''.join(frames)
# It will display 'azerty'
# With a maximum length
frames = deque('ytreza', maxlen=3)
''.join(frames)
# It will display 'aze'
# With no input
assert len(deque(maxlen=3)) == 0
''.join(deque(maxlen(3)))
# It will display an empty string
如果内容是 deque
是 bytes
例如,应使用表达式生成器进行str转换。
''.join(str(element) for element in my_deque)