<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Apr 29, 2010, at 10:22 PM, elsa wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Hi people,<br><br>I'm having a problem getting the info I need out of a file.<br><br>I've opened the file with f=open('myFile','r').<br><br>Next, I take out the first line with line=f.readline()<br><br>line looks like this:<br><br>'83927 300023_25_5_09_FL 9086 9134 F3LQ2BE01AQLXF 1 49 + 80<br>ZA8Z89HIB7M'<br><br>I then split it into parts with parts = line.split()<br><br>['83927', '300023_25_5_09_FL', '9086', '9134', 'F3LQ2BE01AQLXF', '1',<br>'49', '+', '80', 'ZA8Z89HIB7M']<br><br>Now, I need to test whether I can call int(parts[0]) or not. Some of<br>the lines in my file start with a value which represents and integer<br>(as above), while others are just strings of characters. I want to<br>extract just the lines like the one above, that start with an integer.<br>Any suggestions?<font class="Apple-style-span" color="#000000"><font class="Apple-style-span" color="#144FAE"><br></font></font></div></blockquote><br></div><div>Take a look at try and except. Using int(parts[0]) will raise an exception</div><div>when it fails. Catch the exception and only save the lines when the try</div><div>does not fail.</div><div><br></div><div>Tommy</div></body></html>