Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6218021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:31:41+00:00 2026-05-24T07:31:41+00:00

I posted a question yesterday here: Finding and adding to a .kml file using

  • 0

I posted a question yesterday here: Finding and adding to a .kml file using python

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

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

<name> (for example <name>TO-101</name>) 

and add a line right below the name line with a:

<description> <img src=TO-101.jpg></description>. 

So, I have the code written, but I just can’t seem to get it to find the . Which is always written:

"\t\t\t<name>TO-XXX</name>\n".

So, here is the 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 < 20000:   #There are about 17,000 lines in the .kml file
    readxml = source.readline()
    while i < len(images):
        word = images[i]
        if readxml == "\t\t\t<name>%s</name>\n" % word[:6]: #!!!!!!!!! the problem is here
            print readxml #output the <name>
            print word[:6] #output the <description>
            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

I just can’t seem to get it to recognize the lines. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:31:43+00:00Added an answer on May 24, 2026 at 7:31 am

    Because indentation is syntax in python you really need to be careful about where things are located. This may come closer. It’s not 100% complete, but it will point you in the right direction:

    with open(infile) as fhi, open(outfile, 'w') as fho:
      for line in fhi:
        if line == 'myMatchString':
          fho.write(line.replace('this', 'that'))
    

    That uses the multiple file syntax for the with statement, which was introduced in 2.7. Prior to 2.7 you’ll have to nest a second with to get the second file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I posted a question yesterday which was answered, sadly though I now have a
Yesterday I posted this question regarding using lambdas inside of a Join() method to
Following on from a question I posted yesterday about GUIs, I have another problem
I have posted question: how to use log4j in Multithread using java? . i
I posted a question about this earlier, but I have more information now and
ok, yesterday I posted almost identical question here , but I wasn't able to
I posted a similar question yesterday with the same code, I have rewritten and
Similar to the question I posted yesterday , I have this problem that I
I posted this question yesterday evening, which has led me to discover a huge
I posted a question yesterday, which I intend to get back to today however

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.