title: How to find and add new line in python if have spaces before
body: <p>I have some trouble with my code. In "line1 and line2" before the text in file have some spaces, how i can ignore them? </p>
  
  <p>Ex.:</p>
  
  <pre><code>&lt;server xmlns="urn:jboss:domain:1.2"&gt;
           &lt;/handlers&gt;
          &lt;/root-logger&gt;
      &lt;/subsystem&gt;
      &lt;subsystem xmlns="urn:jboss:domain:naming:1.1"&gt;
      &lt;bindings&gt;
  </code></pre>
  
  <p>And these spaces interfere with code to find line1 and line2.</p>
  
  <p>Below is my code</p>
  
  <pre><code>with open("xxx", "r+") as f:
  a = [x.rstrip() for x in f]
  index = 1
  line1 = '&lt;subsystem xmlns="urn:jboss:domain:naming:1.1"&gt;'
  line2 = "&lt;bindings&gt;"
  for item in a:
      if item.startswith(line1 and line2):
          a.insert(index, '&lt;simple name="java:global/nbs/app/portal/config/routes"\n\tvalue="C:\\nbs\\app\\portal\\routes.properties"/&gt;')
          break
      index += 1
  f.seek(0)
  for line in a:
      f.write(line + "\n")
  </code></pre>