Note that there are some explanatory texts on larger screens.

plurals
  1. POregex replace from a list
    text
    copied!<p>I have a Latex Table that for weekly lesson plans, I want to pull data from syllabi that I will store as lists.(They will be read in from csv) So the syllabus is a list of 50 chapters and the latex has spaces for 2 lessons a week for 4th grade and 3 for sixth, I want to chomp the first lesson and stick in in the first token, then the next . . . right now my code would just give me chapter1 on Monday, Wed and Fri instead of ch1, ch2, ch3</p> <pre><code>math6 = ['chapter1', 'chapter2', 'chapter3', 'chapter1-3test'] math4= ['chapter1.1', 'chapter1.2-3', 'chapter2'] \begin{tabular}{|p{0.7in}|p{0.8in}|p{2.2in}|p{.9in}|p{2.6in}|p{1.6in}|} 6${}^{th}$ Math \newline M\newline &amp; _math6_&amp; 6${}^{th}$ Math \newline W \newline &amp; _math6_ &amp; 6${}^{th}$ Math \newline F \newline &amp; _math6_ &amp; 4${}^{th}$ Math \newline M\newline &amp; &amp; _math4_ &amp; 4${}^{th}$ Math \newline W\newline &amp; &amp; _math4_ &amp; \end{tabular} </code></pre> <p>here is the python</p> <pre><code>import re template = file('file1.txt', 'r').read() lost= ["geography", "physics", "hairdressing", "torah"] n =0 while n&lt;len(lost): temp=lost[n] page= re.sub(r'_thing_', temp, template) print page n+=1 #page= re.sub(r'_thing_', "martha", template) #file('result.txt', 'w').write(page) </code></pre> <p>which gives me</p> <pre><code>#contents of file1 # Really long Latex #File that has # geography, geography, mary, tom, susan, geography #that I want to replace #read file1 in as a string, replace, save again #contents of file1 # Really long Latex #File that has # physics, physics, mary, tom, susan, physics #that I want to replace #read file1 in as a string, replace, save again #contents of file1 # Really long Latex #File that has # hairdressing, hairdressing, mary, tom, susan, hairdressing #that I want to replace #read file1 in as a string, replace, save again #contents of file1 # Really long Latex #File that has # torah, torah, mary, tom, susan, torah #that I want to replace #read file1 in as a string, replace, save again </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload