Python2.6 Decimal to Eighth

How can I convert the decimal to Octal in Python2.6, for 1 to 100000? I want to get this converted result as .txt. Can anybody help me?

+6
python decimal octal
source share
2 answers

Use the oct function:

 print oct(9) # prints 011 
+14
source share

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() 
+1
source share

All Articles