Note that there are some explanatory texts on larger screens.

plurals
  1. POPython, problems modifying a text file, searching for terms
    primarykey
    data
    text
    <p>I posted a question yesterday here: <a href="https://stackoverflow.com/questions/6944708/finding-and-adding-to-a-kml-file-using-python">Finding and adding to a .kml file using python</a></p> <p>I have read a bunch of tutorial and now have a better understanding of python and that is good. Yet I still can't seem to get my script right. I know I am so very close. Basically I want to add a bunch of jpg's to a .kml file, which is basically .xml in google earth. I want my program to find a google earth "placemarker" in the xml file called: TO-XXX </p> <p>where XXX matches the TO-XXX.jpg. I already have a folder with a bunch of .jpgs whose filename matches the name of each placemarker. I need the program to find the </p> <pre><code>&lt;name&gt; (for example &lt;name&gt;TO-101&lt;/name&gt;) </code></pre> <p>and add a line right below the name line with a:</p> <pre><code>&lt;description&gt; &lt;img src=TO-101.jpg&gt;&lt;/description&gt;. </code></pre> <p>So, I have the code written, but I just can't seem to get it to find the . Which is always written: </p> <pre><code>"\t\t\t&lt;name&gt;TO-XXX&lt;/name&gt;\n". </code></pre> <p>So, here is the code:</p> <pre><code>import os infile = 'TO-Hand-Holes2.kml' # the file I am reading outfile = 'TO-Hand-Holes-Output.kml' # the file I plan to write to, using print for now images = os.listdir("./images") # the images folder, all image names match names source = open(infile, 'r') target = open(outfile, 'w') x = 0 #an incrementer i = 0 # an incrementer readxml = source.readline while x &lt; 20000: #There are about 17,000 lines in the .kml file readxml = source.readline() while i &lt; len(images): word = images[i] if readxml == "\t\t\t&lt;name&gt;%s&lt;/name&gt;\n" % word[:6]: #!!!!!!!!! the problem is here print readxml #output the &lt;name&gt; print word[:6] #output the &lt;description&gt; hit = 'true' i = i + 1 else: hit = 'false' #print "test%s" % word[:6] i = i + 1 if hit == 'false': print ("%s") % readxml x = x + 1 </code></pre> <p>I just can't seem to get it to recognize the lines. Any suggestions?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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