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まで、10進数を8進数に変換するにはどうすればよいですか?この変換された結果も.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()