title: Python reading hex numbers from file and writing to another. "Invalid literal" in 'int' assignment
body: <p><code>/dev/input/event0: 0003 0001 000081a5</code></p>
  
  <p>Should become  </p>
  
  <pre><code>sendevent 0003 0001 000081a5
  </code></pre>
  
  <p>in new file.</p>
  
  <p>Code is </p>
  
  <pre><code>import sys
  import fileinput
  
  prefix = 'sendevent '
  
  inputline = None
  complete = None
  part1len = 0
  part1 = None
  part2 = None
  
  num1 = 0
  num2 = 0
  num3 = 0
  
  rawfile = None
  outfile = None
  filename = None
  
  rawfile = sys.argv[-1]
  
  fo = open(rawfile, 'r')
  
  filename = rawfile.find('.');
  outfile = rawfile[:filename] + '.scr'
  
  fw = open(outfile, 'w')
  
  fw.write('#!/bin/sh' + '\n')
  
  fw.write('echo Running - signature function ' + '\n')
  
  for inputline in fo.read().split('\n'):
      part1len = inputline.find(':');
  
      if part1len &gt; -1:
          part1 = inputline[:part1len]
  
          part2 = inputline.split(' ')
  
          num1 = int(part2[1], 16)
          num2 = int(part2[2], 16)
          num3 = int(part2[3], 16)
  
          complete = prefix + part1 + " " + str(num1) + " " + str(num2) + " " + str(num3)
  
          fw.write(complete + '\n')
  
  print 'Processing complete'
  print 'File created: ', outfile
  print
  print 'Copy file to the device'
  print 'adb push ' + outfile + ' /sdcard/' + outfile
  print
  print 'Run the script'
  print 'adb shell sh /sdcard/' + outfile
  
  fo.close()
  fw.close()
  </code></pre>
  
  <p>Error in output command line is :</p>
  
  <pre><code>Traceback (most recent call last):
    File "Android\decs.py", line 41, in &lt;module&gt;
      num1 = int(part2[1], 16)
  ValueError: invalid literal for int() with base 16: '='
  </code></pre>
  
  <p>Just started learning Python today. I am not sure what is going wrong. Have gone through similar errors posted online but cannot find a solution.</p>
  
  <p>Thanks</p>