Re: [Tutor] Question about exception handling
On 17/12/06, Asrarahmed Kadri <[EMAIL PROTECTED]> wrote: Hi Folks, Is it possible to catch exception raised in module A to be caught in module B. If yes, then please let me know how to do it. You can easily test this yourself. First right a quick module, something like this will do: def exception_test(): raise Exception then start an interpreter and do the following import your_module try: ... your_module.exception_test() ... except: ... print "Caught it!" ... HTH, Adam ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Question about exception handling
Hi Folks, Is it possible to catch exception raised in module A to be caught in module B. If yes, then please let me know how to do it. TIA. Regards, Asrarahmed Kadri -- To HIM you shall return. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Splitting a file
Antonio Rodriguez wrote: > I'm attempting to split a binary file into 5 component files, as a > "challenge". I thought that the following would work: > > f = open('/home/taser/Desktop/inputfile.bin') > f1 = [] > f2 = [] > f3 = [] > f4 = [] > f5 = [] > while 1: > try: > bytes = list(f.read(5)) > f1.append(bytes[0]) > f2.append(bytes[1]) > f3.append(bytes[2]) > f4.append(bytes[3]) > f5.append(bytes[4]) > except: > break > ff1 = open('/home/taser/Desktop/ff1.file','w') > ff1.write(''.join(f1)) > ff1.close() > > I've only dealt with one of the lists, since I want to test it before > doing the rest. > > I'm unsure if I'm going about this correctly, since I'm manipulating > binary data as if it were a text file. You should read and write the file in binary mode or you will corrupt the data: f = open('/home/taser/Desktop/inputfile.bin', 'rb') ff1 = open('/home/taser/Desktop/ff1.file','wb') Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Splitting a file
I'm attempting to split a binary file into 5 component files, as a "challenge". I thought that the following would work: f = open('/home/taser/Desktop/inputfile.bin') f1 = [] f2 = [] f3 = [] f4 = [] f5 = [] while 1: try: bytes = list(f.read(5)) f1.append(bytes[0]) f2.append(bytes[1]) f3.append(bytes[2]) f4.append(bytes[3]) f5.append(bytes[4]) except: break ff1 = open('/home/taser/Desktop/ff1.file','w') ff1.write(''.join(f1)) ff1.close() I've only dealt with one of the lists, since I want to test it before doing the rest. I'm unsure if I'm going about this correctly, since I'm manipulating binary data as if it were a text file. Also, I'm told that I should be able to have Python itself determine the type of file it is, since the file contains a "magic number". However, I haven't had any luck in my searches for how to do that in Python. Any help would be appreciated. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor