I'm lazy with those sometimes too. It depends on what I'm doing. There's a lot of times when I do a bare try/except myself even though I know I shouldn't...oh well.
Mike
···
Good point, I guess I am a bit lazy sometimes.
-Brian
Brian Fett
1280 Disc Dr
SHK224
Shakopee, MN 55379Phone: (952)402-2595
Brian.D.Fett@seagate.combrian.d.fett@seagate.com wrote:
>
> Have you "try:"ed?
>
> <CODE>
> > def FLCplus1(self):
> try:
> LR1 = linecache.getline(LogDirValue, CurrentLineCount)
> LineR1 = LR1.split('] ',1)
> LineRead1 = LineR1[1]
> for i in xrange(1,7):
> if LineRead1.find(globals()['C%iSearchString'%i]) >=0:
> Publisher.sendMessage(('C%i'%i, 'message'), [LineRead1])
> linecache.clearcache()
> except:
> pass
>
> </CODE>
>
> This will do exactly the same thing your function does, except when
> your code would fail, this one will "pass."
>
> I would try adding in a print statement to see the results of the
> split before implementing this so you know what the problem is
> (putting the print in the "try" wont help you as when you would want
> to know what is happening, it wont print). Or you could find only the
> failing lines quickly by setting it up like this:
> <CODE>
> > def FLCplus1(self):
> LR1 = linecache.getline(LogDirValue, CurrentLineCount)
> LineR1 = LR1.split('] ',1)
> try:
> LineRead1 = LineR1[1]
> for i in xrange(1,7):
> if LineRead1.find(globals()['C%iSearchString'%i]) >=0:
> Publisher.sendMessage(('C%i'%i, 'message'), [LineRead1])
> linecache.clearcache()
> except:
> print("-"*20+"Time stamp stripping failed"+"-"*20)
> print LineR1
> print("-"*50)
>
> </CODE>
>
> This will do the normal actions on all lines that work well, and print
> (in a way that is easy to find) the lines that fail
>
> -Brian
>
> Brian Fett
> 1280 Disc Dr
> SHK224
> Shakopee, MN 55379
>
> Phone: (952)402-2595
> Brian.D.Fett@seagate.comThis code would be better if you didn't catch all errors. Since the OP
is having an IndexError, that's the only one you should catch. I've been
told that it's bad form to catch all errors. Anyway, here's how I would
do it:<code>
def FLCplus1(self):
LR1 = linecache.getline(LogDirValue, CurrentLineCount)
LineR1 = LR1.split('] ',1)
try:
LineRead1 = LineR1[1]
for i in xrange(1,7):
if LineRead1.find(globals()['C%iSearchString'%i]) >=0:
Publisher.sendMessage(('C%i'%i, 'message'), [LineRead1])
linecache.clearcache()
except IndexError:
print("-"*20+"Time stamp stripping failed"+"-"*20)
print LineR1
print("-"*50)</code>
If you want to print out the original error message (not the traceback),
you can do this:except IndexError, e: print e
See also:
http://www.diveintopython.org/file_handling/index.html
http://docs.python.org/api/exceptionHandling.html
http://docs.python.org/tut/node10.html-------------------
Mike DriscollBlog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users