user233935
user233935

Reputation: 109

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?

Upvotes: 7

Views: 12388

Answers (2)

Michael
Michael

Reputation: 12072

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

Upvotes: 1

Andrew Hare
Andrew Hare

Reputation: 351718

Use the oct function:

print oct(9) # prints 011

Upvotes: 15

Related Questions