简体   繁体   中英

Python2.6 Decimal to Octal

How can i convert decimal to Octal in Python2.6, for 1 to 100000? I wanna get this converted result as .txt too. Can someone help me?

使用oct函数:

print oct(9) # prints 011

This should do the trick:

text = '\n'.join(str(oct(i)) for i in xrange(100000))
f = open('foo.txt', 'w')
f.write(text)
f.close()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM