[英]How to use use Python to import (.tex file), create a new (.tex file) and append the new (.tex file) from the imported (.tex file)
[英]Export a tex file file from python script: “TypeError: a float is required”
这是要写入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)d'中的'%(index)s'(以及'index':3中的'index':str(3)),但我仍然遇到相同的错误。 谢谢
您的文本包含另一个%
字符(第三行)。 由于%
之后的第一个非空格字符是f
,因此将其解释为%f
(即浮点格式)。 您想通过加倍( %%
)来逃避%
的这种情况,或者要使用format
方法代替%
运算符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.