I want to write two variable to a file using Python.
Based on what is stated in this post I wrote:
f.open('out','w')
f.write("%s %s\n" %str(int("0xFF",16)) %str(int("0xAA",16))
But I get this error:
Traceback (most recent call last):
File "process-python", line 8, in <module>
o.write("%s %s\n" %str(int("0xFF", 16)) %str(int("0xAA", 16)))
TypeError: not enough arguments for format string
"%s %s\n" % (str(int("0xFF", 16)), str(int("0xAA", 16)))str(int()), anyway?"%i %i\n" % (int("0xFF", 16), int("0xAA",16))would work just as well and, in my opinion, is a bit clearer. Also, if only hexadecimal strings are guaranteed to begin with0xthen you can useint(string, 0), as that will automatically convert properly-prefixed octal strings and handle decimal strings correctly as well. If all your strings are hex and might not be preceded by0xthen usingint(string, 16)is probably how you need to go, though.