2
这是一个TEX文件中写入内容:我想用integger值来代替“指数”出口从Python脚本一个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}
'''
。 当我写:
with open(directoryPath + os.sep +'commonTables3.tex','w') as f:
f.write(content%({'index':str(3)}))
我有如下错误:
f.write(content%({'index':str(3)}))
TypeError: a float is required
我不明白的地方是我的错误。我尝试在'index'中更改'%(index)d'(和'index':str(3)中的'%(index)s':3)但我仍然有相同的错误。 谢谢