title: How to iterate over the file in python
body: <p>I have a text file with some hexadecimal numbers and i am trying to convert it to decimal. I could successfully convert it, but it seems before the loop exist it reads some unwanted character and so i am getting the following error.</p>
  
  <pre><code>Traceback (most recent call last):
    File "convert.py", line 7, in &lt;module&gt;
      print &gt;&gt;g, int(x.rstrip(),16)
  ValueError: invalid literal for int() with base 16: ''
  </code></pre>
  
  <p>My code is as follows</p>
  
  <pre><code>f=open('test.txt','r')
  g=open('test1.txt','w')
  #for line in enumerate(f):  
  while True:
      x=f.readline()
      if x is None: break
      print &gt;&gt;g, int(x.rstrip(),16)
  </code></pre>
  
  <p>Each hexadecimal number comes in a new line for input</p>