Вот мой CSV-файл:
Simon,/home/user/Desktop/simon.jpeg
Вот мой код Python:
#! /usr/bin/python3
import csv
import subprocess
LatexContent = '''\\documentclass[12pt, twocolumn, letterpaper]{report}
\\usepackage[utf8]{inputenc}
\\usepackage{graphicx}
\\renewcommand{\familydefault}{\\sfdefault}
\\begin{document}
Run Satus: \\textsc{%(sampleid)s}
%(sampleid)s
\\includegraphics[width=20cm]{%(coveragegraph)s}
\\end{document}'''
###== Look at the database ==##
# open the database into python
my_db_file = open('automate.testing.csv', 'r')
# read the database
my_db = csv.reader(my_db_file, delimiter=',',skipinitialspace=True)
###== TeX files processing and generating ==###
#skip the header of the database
next(my_db)
#then for each row of the database
for row in my_db :
## Assign the items of the row to the variables that will fill up the
## blanks of the LaTeX code
sampleid = str(row[0]) #caution, first item of a row = index '0'
coveragegraph = str(row[1])
#define the TeX file name
TexFileName = sampleid + '.tex'
## create a new LaTeX file with the blanks filled
#create a new file
TexFile = open(TexFileName,'w')
#fill the blanks with the previously read informations
TexFile.write(LatexContent %{"sampleid" : sampleid, "coveragegraph" : coveragegraph})
#close the file
TexFile.close()
## compile the file you've just created with LaTeX
subprocess.Popen(['pdflatex',TexFileName],shell=False)
##repeat for each row
#close the database file
my_db_file.close()
Я хочу иметь возможность выполнить скрипт Python, чтобы он читался в CSVфайл и поместите значения в секцию latexcontent
, которая затем будет выполнена с pdflatex
.
Когда я нажимаю ввод, кажется, что он работает нормально, без кодов ошибок.Но в каталоге нет файла .tex
.
Какие изменения я должен внести в Python, чтобы он заработал, я знаю, что я близко ...