这应该能解决问题: text = '\n'.join(str(oct(i)) for i in xrange(100000)) f = open('foo.txt', 'w') f.write(text) f.close()