Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 Python2.6 中将十进制转换为八进制,从 1 到 100000?我也想将此转换后的结果作为 .txt 获得。有人能帮我吗?
使用oct功能:
oct
print oct(9) # prints 011
这应该可以解决问题:
text = '\n'.join(str(oct(i)) for i in xrange(100000)) f = open('foo.txt', 'w') f.write(text) f.close()