views:

78

answers:

2

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?

+4  A: 

Use the oct function:

print oct(9) # prints 011
Andrew Hare
A: 

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()
meeselet