0

我想生成以下行

1 & {\QPCSymbols\XeTeXglyph 2}  & \textarabic{الحمدلله} & \texttt{!} & \verb$\XeTeXglyph 2$  \\
\hline

假设第一个数字是n,第二个数字是n+1,的内容\textarabic是从获得的,从的f_nusoos内容。两个文件的行数相同。\textttf_keys

我创建了一个 Python3 脚本,它应该可以得到我想要的,但我最终得到了新的行符号 ( \n)。

这是我到目前为止所拥有的,

#! python3
import linecache

f_nusoos = 'symbol_nass_list.txt'
f_keys   = 'symbol_key_list.txt'
contentfile = open('content.tex', 'w+', encoding="utf-8")

theLine = " "

for x in range(3):
  contentfile.write('{} & {{\QPCSymbols\XeTeXglyph {}}}  & \\textarabic{{{}}} & \\texttt{{{}}} & \\verb$\XeTeXglyph {}$  \\\\'.format(x+1, x+2,linecache.getline(f_nusoos, x+1).rstrip('\n'), linecache.getline(f_keys, x+1), x+2).rstrip('\n'))
  contentfile.write('\hline')

执行后的内容content.tex是,

1 & {\QPCSymbols\XeTeXglyph 2}  & \textarabic{بسم الله الرحمن الرحيم} & \texttt{!
} & \verb$\XeTeXglyph 2$  \\\hline2 & {\QPCSymbols\XeTeXglyph 3}  & \textarabic{بسم الله الرحمن الرحيم} & \texttt{"
} & \verb$\XeTeXglyph 3$  \\\hline3 & {\QPCSymbols\XeTeXglyph 4}  & \textarabic{بسم الله الرحمن الرحيم} & \texttt{#
} & \verb$\XeTeXglyph 4$  \\\hline

然而,我的期望是,

1 & {\QPCSymbols\XeTeXglyph 2}  & \textarabic{بسم الله الرحمن الرحيم} & \texttt{!} & \verb$\XeTeXglyph 2$\\
\hline
2 & {\QPCSymbols\XeTeXglyph 3}  & \textarabic{بسم الله الرحمن الرحيم} & \texttt{"} & \verb$\XeTeXglyph 3$\\
\hline
3 & {\QPCSymbols\XeTeXglyph 4}  & \textarabic{بسم الله الرحمن الرحيم} & \texttt{#} & \verb$\XeTeXglyph 4$\\
\hline

问题似乎是在texttt{CONTENT. 我不知道这是为什么。

内容f_nusoos.txt

بسم الله الرحمن الرحيم
بسم الله الرحمن الرحيم
بسم الله الرحمن الرحيم

内容f_keys.txt

!
"
#
4

1 回答 1

0

我盯着这个看太久了。

代替

contentfile.write('{} & {{\QPCSymbols\XeTeXglyph {}}}  & \\textarabic{{{}}} & \\texttt{{{}}} & \\verb$\XeTeXglyph {}$  \\\\'.format(x+1, x+2,linecache.getline(f_nusoos, x+1).rstrip('\n'), linecache.getline(f_keys, x+1), x+2).rstrip('\n'))

它应该是

contentfile.write('{} & {{\QPCSymbols\XeTeXglyph {}}}  & \\textarabic{{{}}} & \\texttt{{{}}} & \\verb$\XeTeXglyph {}$  \\\\'.format(x+1, x+2,linecache.getline(f_nusoos, x+1).rstrip('\n'), linecache.getline(f_keys, x+1).rstrip('\n'), x+2))

rstrip()应该用于来自文件的输入,而不是用于计数器。

于 2016-06-02T16:19:33.347 回答