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)但我仍然有相同的錯誤。 謝謝