Am 16.05.2010 14:45, schrieb Yutao Deng:
LOL, try...except is a good idea.
i fix it  lick this:

############
with open("data2.pickle","rb") as file_stream:
    c = 0
    while True:
        try:
            i = cPickle.load(file_stream)
            print i
            c += 1
        except:
            print "Numer of pickled objects is %s." %c
            break
#############


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
Just a remark on your except statement: You should not use "except:" without specifying a concrete exception class, because all kind of exceptions are then handled by the except block (and therefore hidden). If for example an IOError occurs while reading the file (for what ever reason...), it would be handled by your except block and you would never know that there was a problem reading the file. If you use "except EOFError:" the exception block is evaluated only when the EOFError occurs. All other exceptions are raised as usual.

Best regards,

Jan
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to