Catching a non-Exception object (KeyboardInterrupt)


when I try to catch ctrl+c with except KeyboardInterrupt: pychecker tells me Catching a non-Exception object (KeyboardInterrupt) It works fine, but the message indicates that it's not completely clean. How should I write the exception correctly
Posted On: Saturday 10th of November 2012 03:38:14 AM Total Views:  53
View Complete with Replies

RELATED TOPICS OF Python Programming PROGRAMMING LANGUAGE




[tarfile] Difficultis catching an exception

, I'm trying to catch an "EOFError" exception that occurs when reading truncated tarfile. Here's my routine, and below that the callback trace. Note that although I'm trying to catch all TarFile exceptions, the tarfile.EOFError ecxeption, and the global EOFError exception, the program still falls through and fails. def query_archive(batch_base): arc_name = os.path.join(archive_dir, 'B_'+batch_base+'.tar.bz2') sys.stderr.write('Archive: %s ' % arc_name) try: archive = tarfile.open(arc_name, 'r:bz2') members = archive.getmembers() except tarfile.TarError, EOFError, tarfile.EOFError: sys.stderr.write("corrupt.\n") db.execute('UPDATE Archives SET Status=2 WHERE BatchBase=', (batch_base, )) update_batchinfo(members, batch_base) return 0 Archive: f:/wafermap_archive/B_48380.tar.bz2 Traceback (most recent call last): File "./wmap", line 11, in task.run(command, args) File "/cygdrive/h/wafermaps/wmap_import.py", line 142, in run query_archive(batch_base) File "/cygdrive/h/wafermaps/wmap_import.py", line 95, in query_archive members = archive.getmembers() File "/usr/lib/python2.5/tarfile.py", line 1282, in getmembers self._load() # all members, we first have to File "/usr/lib/python2.5/tarfile.py", line 2003, in _load tarinfo = self.next() File "/usr/lib/python2.5/tarfile.py", line 1809, in next self.fileobj.seek(self.offset) EOFError: compressed file ended before the logical end-of-stream was detected
VIEWS ON THIS POST

68

Posted on:

Saturday 3rd November 2012
View Replies!

Returning to 'try' block after catching an exception

I'm not sure if Python can do this, and I can't find it on the web. So, here it goes: try: some_function() except SomeException: some_function2() some_function3() ... # somehow goto 'try' block again In case it's not clear what I meant: after executing some_function() exception SomeExcpetion gets risen. Then, in except block I do something to fix whatever is causing the exception and then I would like to go back to try block, and execute some_function() again. Is that doable
VIEWS ON THIS POST

64

Posted on:

Saturday 3rd November 2012
View Replies!

catching object

I was wondering if someone could help me explain this situation: h[1] >>> import inspect h[1] >>> inspect.getmro(ValueError) (, , , , ) h[2] >>> try: raise ValueError("argh") except object: print "why not" Traceback (most recent call last): File "", line 2, in ValueError: argh The question is, why isn't ValueError caught It *does* inherit from object (albeit indirectly), and my understanding of the wording of CPython docs is that this guarantees "compatibility" (between what is being raised and what is being caught). So, why doesn't object match ValueError (or any other exception for that matter). I am aware of "except:", but in my particular situation it is eh... unsuitable. Any hints/pointers are appreciated. ivr -- igorr: for f parenteser igorr: parenteser virker som lubrication under iterasjon igorr: velkjent
VIEWS ON THIS POST

46

Posted on:

Sunday 4th November 2012
View Replies!

using pdb and catching exception

Py'ites I am using pdb to check my code, and I would like to put a statement like equivalent of "C++gdb>catch throw". Basically, I would like debugger to start as soon as an exception is thrown. How may I do it
VIEWS ON THIS POST

115

Posted on:

Monday 5th November 2012
View Replies!

catching empty strings (I guess that's what they are)

I've began accepting user input in an old program. The input comes from a simple text file where users enter filenames (one per line). What is the appropriate way to handle blank lines that hold whitespace, but not characters Currently, I'm doing this: for user_file in user_files: # Remove whitespace and make lowercase. file_skip_list.append(user_file.strip().lower()) file_skip_list = list(sets.Set(file_skip_list)) However, if the input file has blank lines in it, I get this in my list: '' (that's two single quotes with noting in between) I thought I could do something like this: if user_file == None: pass Or this: if user_file == '': pass But, these don't work, the '' is still there. Any suggestions are appreciated! Brad
VIEWS ON THIS POST

166

Posted on:

Monday 5th November 2012
View Replies!

Creating object in function doesn't seem to create a new object.

Hi folks, I'll start off with the code I wrote... (ActivePython 2.4 on Windows XP SP2) ------------------------------- class FlightCondition(object): lsf = [0,'Low Speed Flare'] vto = [0,'Vertical Take-Off'] def get_flight_condition(flight_data): fc1 = FlightCondition() for row in flight_data: fc1.lsf[0] += 1 fc1.vto[0] += 1 print 'in function get_flight_condition' print fc1.lsf print fc1.vto return fc1 for count in range(3): fc = get_flight_condition([1,2,3]) print 'returned fc' print fc.lsf print fc.vto --------------------------------- When I run it I get... in function get_flight_condition [3, 'Low Speed Flare'] [3, 'Vertical Take-Off'] returned fc [3, 'Low Speed Flare'] [3, 'Vertical Take-Off'] in function get_flight_condition [6, 'Low Speed Flare'] [6, 'Vertical Take-Off'] returned fc [6, 'Low Speed Flare'] [6, 'Vertical Take-Off'] in function get_flight_condition [9, 'Low Speed Flare'] [9, 'Vertical Take-Off'] returned fc [9, 'Low Speed Flare'] [9, 'Vertical Take-Off'] --------------------------------- I thought that when I wrote fc1 = FlightCondition() in the function it would create a new FlightCondition object which would be passed back every time. Instead it seems to re-reference the old version and continue to add to it. --------------------------------- What I expected was... in function get_flight_condition [3, 'Low Speed Flare'] [3, 'Vertical Take-Off'] returned fc [3, 'Low Speed Flare'] [3, 'Vertical Take-Off'] in function get_flight_condition [3, 'Low Speed Flare'] [3, 'Vertical Take-Off'] returned fc [3, 'Low Speed Flare'] [3, 'Vertical Take-Off'] in function get_flight_condition [3, 'Low Speed Flare'] [3, 'Vertical Take-Off'] returned fc [3, 'Low Speed Flare'] [3, 'Vertical Take-Off'] --------------------------------- Could someone please explain to me why I get the output I did instead of what I expected. How do I code my function so I get a new fc1 every time and my deed output
VIEWS ON THIS POST

88

Posted on:

Saturday 10th November 2012
View Replies!

Re: Any way to loop through object variables?

Dave Challis wrote: > > Just wondering if there's a way to iterate through all variables which > an object has set > > Specifically, I'm using the OptionParser module, which returns an > options object, containing all command ...
VIEWS ON THIS POST

111

Posted on:

Saturday 10th November 2012
View Replies!

How can I obtain the exception object on a generlized except statement?

I am confused on one aspect of exception handling. If you specify the exception object type to match in an except statement it is possible to also obtain the exception object itself, but I can't figure out how to get ...
VIEWS ON THIS POST

92

Posted on:

Saturday 10th November 2012
View Replies!

Using file objects with elementtree

, Rather then holding my XML document in memory before writing it to disk, I want to create a file object that elementtree will write each element to has it is created. Does any one know how to do that ...
VIEWS ON THIS POST

225

Posted on:

Saturday 10th November 2012
View Replies!

matching objects by a tuple field criterion

i have a large collection of python objects, each of which contains an integer 6-tuple as part of its data payload. what i need to be able to do is select only those objects which meet a simple tuple element ...
VIEWS ON THIS POST

50

Posted on:

Saturday 10th November 2012
View Replies!

Boost::Python - Question about object ownership and lifetime

Hi folks, new to Boost Python and struggling to build a prototype at work. I thought I'd start with a conceptual question to help clarify my understanding. I already have a basic prototype working nicely but I'm having a few ...
VIEWS ON THIS POST

60

Posted on:

Saturday 10th November 2012
View Replies!

Question regarding Queue object

! I'm trying to implement a message queue among threads using Queue. The message queue has two operations: PutMsg(id, msg) # this is simple, just combine the id and msg as one and put it into the Queue. WaitMsg(ids, msg) ...
VIEWS ON THIS POST

64

Posted on:

Saturday 10th November 2012
View Replies!

Obtaining a callable class method object from a specific class

This is a contrived pseudocode example which has been broken out of a larger problem, so it may seem like a strange thing to want to do, but... I have a group of objects which inherit (single) from a common ...
VIEWS ON THIS POST

66

Posted on:

Saturday 10th November 2012
View Replies!

ANN: Pyro 3.5 beta (remote objects)

I'm glad to announce the new version of Python's own powerful remote method invocation technology -- Pyro 3.5 (beta)! You can get it via http://pyro.sourceforge.net , then go to the SF project homepage download area. It has many new features ...
VIEWS ON THIS POST

86

Posted on:

Saturday 10th November 2012
View Replies!

[ANNOUNCE] Durus object database version 1.2

Durus is a Python object database. It offers an easy way to maintain a consistent persistent collection of Python object instances used by one or more processes. This release contains the following changes: * Add 'durus' command line tool. * ...
VIEWS ON THIS POST

43

Posted on:

Saturday 10th November 2012
View Replies!

Passing function objects to timeit

The timeit.Timer class times "code snippets" -- you pass it strings rather than function objects. That's good for what it's worth, but sometimes the code you want to time is too big to easily pass as a string, or maybe ...
VIEWS ON THIS POST

37

Posted on:

Saturday 10th November 2012
View Replies!

Can my own objects support tuple unpacking?

, So, I am new to python, but I always like to learn the ins and outs of a language by trying to understand how everything fits together. Anyway, I am trying to figure out how tuple unpacking behavior works. ...
VIEWS ON THIS POST

54

Posted on:

Saturday 10th November 2012
View Replies!

placing a Python com object into Excel

Hi I have seen examples from Mark Hammonds book where a Python COM object is accessed from Excel with a VBA script. But, what if I want to Insert a Python COM into the Sheet itself When I try this, ...
VIEWS ON THIS POST

27

Posted on:

Saturday 10th November 2012
View Replies!

Re: How to get current module object

Gabriel Genellina wrote: > En Sun, 17 Feb 2008 16:25:44 -0200, Alex escribi: > >> Can I get reference to module object of current module (from which the >> code is currently executed) I know __import__('filename') should >> probably ...
VIEWS ON THIS POST

125

Posted on:

Saturday 10th November 2012
View Replies!

type, object hierarchy?

print dir(type) #__mro__ attribute is in here print dir(object) #no __mro__ attribute class Mammals(object): pass class Dog(Mammals): pass print issubclass(Dog, type) #False print Dog.__mro__ --output:-- (, , ) The output suggests that Dog actually is a subclass ...
VIEWS ON THIS POST

36

Posted on:

Saturday 10th November 2012
View Replies!