1

I using a 'for loop' to record the IMEI number from multiple files in an array.

When, but when no IMEI is detected the for loop stops indicating AttributeError:rint.

    result = getattr(asarray(obj), method)(*args, **kwds)
    AttributeError: rint

I have used this method:

for IMEI in file():
    try:
        detect the IMEI from the files()
        Append them to the array()
    exception AttributeError:
        print 'File name'
        pass

What I would like to do is to skip the error if the IMEI is not detected in the file and then continue with the loop looking for IMEI in other files.

IMEI refers to 16Digit AlphaNumeric code. I use it as a 'string'.

There are 3200 '.dat' files which I processed for finding such a Alpha Numeric text in each file. Each dat file has some HEX data in it.

1
  • Maybe you should add a reference to what IMEI and file is in your question, as it is now, your answer to the question makes little sense and makes the question less useful to others. Commented Jul 16, 2014 at 9:16

2 Answers 2

3
try:
    execute_something()
except AttributeError:
    caught_error()

This is how we catch an error in python. Just add the above code snippet in your for loop. Replace the functions i used with your own code.

Please ask more if something is still wrong.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I am not sure what I should add instead of caught_error(). Can you please give an example. As I tried the AttribueError: handling in similar way.
just write 'continue' instead of caught_error(). Your way is wrong, that might fail at runtime. So its better to use try...except here
2

I found the answer, which works in my case.

Answer:

if IMEI is None:
    continue

This helps in skipping the loop if the return value is None and as in my case the AttributeError meant the same.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.