将多个变量写入文件

mah*_*ood 3 python

我想使用Python将两个变量写入文件.

根据这篇文章中的内容,我写道:

f.open('out','w')
f.write("%s %s\n" %str(int("0xFF",16)) %str(int("0xAA",16))
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:

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
Run Code Online (Sandbox Code Playgroud)

cmd*_*cmd 9

你没有传递足够的值%,你的格式字符串中有两个说明符,所以它需要一个长度为2的元组.试试这个:

f.write("%s %s\n" % (int("0xFF" ,16), int("0xAA", 16)))
Run Code Online (Sandbox Code Playgroud)