Python - text file with all values 0 to 2^24 in HEX
<p>I am trying to create a file with all possible values for 0 up to 2^24 in HEX.</p>

<p>This is what I have so far:</p>

<pre><code>file_name = "values.txt"
counter = 0
value = 0x0000000000
with open (file_name, 'w') as writer:
    while counter &lt; 16777216:
        data_to_write = str(value) + '\n' 
        writer.write(data_to_write)
        counter = counter + 1
        value = value + 0x0000000001
</code></pre>

<p>This do what I want but with integers. Is there an easy way to turn this to HEX values in file instead (still as string)?</p>

<p>Thank you</p>

<p>Thank you for your help.</p>

<p>It is working now:</p>

<pre><code>file_name = "value.txt"
counter = 0
value = 0x0000000000
with open (file_name, 'w') as writer:
    while counter &lt; 10000:
        data_to_write = str(hex(value)[2:].zfill(6)) + '\n' 
        writer.write(data_to_write)
        counter = counter + 1
        value = value + 0x0000000001
</code></pre>

python