我正在尝试将此 python2.7 代码转换为 python3.6
def write_to_zip(x, zf, vocab_start):
curr_name = "{0}_S{1}_{2}".format(x['study_name'], x['subject_id'], x['repeat_num'])
vocab_string = x[vocab_start:].to_string(header = False, index = False).replace('\n','').encode("utf-8")
demo_string = ("{:<25}"*(vocab_start)).format(*x[0:vocab_start].replace(r'', np.nan, regex=True))
print(demo_string)
string_to_write = demo_string + vocab_string
zf.writestr("{}.txt".format(curr_name), string_to_write)
但我收到以下错误demo_string = ("{:<25}"*(vocab_start)).format(*x[0:vocab_start].replace(r'', np.nan, regex=True))
('不支持的格式字符串传递给 NoneType.__format__', '发生在索引 0')
x看起来像:
study_name English L1
subject_id 2
repeat_num 1
completed True
last_modified 2019-08-05 06:57 UTC
并生成demo_string一个
English L1 2 1 1 2019-08-05 06:57 UTC
vocab_start= 34 在这个例子中
我在 Python3 中用什么替换 {:<25} 以获得相同的结果?