这是要在tex文件中写入的内容:
content=r'''\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs} % for much better looking tables
\usepackage{multirow}
\usepackage{caption}
\captionsetup{labelformat=empty}
\begin{document}
\begin{table}[htbp]\caption{Common Prediction}
\centering
\input{common%(index)s}
\end{table}
\end{document}
'''
Run Code Online (Sandbox Code Playgroud)
我想用积分值替换'index'.我写的时候:
with open(directoryPath + os.sep +'commonTables3.tex','w') as f:
f.write(content%({'index':str(3)}))
Run Code Online (Sandbox Code Playgroud)
我有以下错误:
f.write(content%({'index':str(3)}))
TypeError: a float is required
Run Code Online (Sandbox Code Playgroud)
我不明白我的错误在哪里.我尝试在'%(index)d'中更改'%(index)s'('index'中的'index':str(3):3)但我仍然有相同的错误.谢谢