title: Python Read Text File Split By
body: <p>I have a text file looks the following:</p>
  
  <pre><code>164,http://www.site.com/category1
  161,http://www.site.com/category2
  162,http://www.site.com/category3
  163,http://www.site.com/category4
  </code></pre>
  
  <p>I'm trying to get each time new line category id + category url in a for loop.
  I had other method before the code looks like:</p>
  
  <pre><code>def main():
      config=ConfigParser.ConfigParser()
      config.readfp(open("settings.cfg"),"r")
      for site in config.sections():
         # ipdb.set_trace()
          settings=dict(config.items(site))
          for (url,category) in zip(settings['url'].split(","),settings['category'].split(",")):
  </code></pre>
  
  <p>Can anyone help me change the for of settings.cfg to my text file format? </p>
  
  <p>Using some research I found online this the start of how the code should look like:</p>
  
  <pre><code>with open('categories.txt','r') as f:
      for line in f:
  </code></pre>
  
  <p>but need to strip it by "," and appeand url,category each. But I'm afraid to miss first or last lines by this code will this read it all and work? Some help with this will be great!</p>