Re: catching object

2008-03-14 Thread Igor V. Rafienko
[ [EMAIL PROTECTED] ] [ ... ] > I think inheritance is meant in reference to the Exception tree here. So, > the uppermost class is `BaseException`. Python 3 gives this exception > when trying to handle `object`:: > > TypeError: catching classes that do not inherit from BaseException is >

catching object

2008-03-11 Thread Igor V. Rafienko
Hi, 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

Re: getting n items at a time from a generator

2007-12-29 Thread Igor V. Rafienko
[ Terry Jones ] [ ... ] > Also consider this solution from O'Reilly's Python Cookbook (2nd Ed.) p705 > > def chop(iterable, length=2): > return izip(*(iter(iterable),) * length) Is this *always* guaranteed by the language to work? Should the iterator returned by izip() change the i

Re: non-blocking communication with imaplib

2007-08-29 Thread Igor V. Rafienko
[ Lawrence D'Oliveiro ] [ ... ] > According to the documentation > , you can override > the "read" and "readline" methods. How about replacing them with > routines that use select.select on the socket() object to implement > a timeout? Sounds like

non-blocking communication with imaplib

2007-08-22 Thread Igor V. Rafienko
Hi, I was wondering if anyone had a suggestion for the following issue. I would like to talk to an IMAP-server, imaplib being the tool of choice, of course. Unfortunately it may happen that the IMAP-server fails to respond to certain commands, and I would like to be able to detect that within a

Re: Checking default arguments

2007-02-05 Thread Igor V. Rafienko
[ George Sakkis ] First of all, thanks to everyone who replied. [ ... ] > I don't know why you might want to distinguish between the two in > practice (the unique object idea mentioned in other posts should > handle most uses cases), but if you insist, here's one way to do it: There is no act

Checking default arguments

2007-02-02 Thread Igor V. Rafienko
Hi, I was wondering whether it was possible to find out which parameter value is being used: the default argument or the user-supplied one. That is: def foo(x, y="bar"): # how to figure out whether the value of y is # the default argument, or user-supplied? foo(1, "bar") => user-sup

Re: cElementTree clear semantics

2005-09-25 Thread Igor V. Rafienko
[ Fredrik Lundh ] [ ... ] > the iterparse/clear approach works best if your XML file has a > record-like structure. if you have toplevel records with lots of > schnappi records in them, iterate over the records and use find > (etc) to locate the subrecords you're interested in: (...) The proble

cElementTree clear semantics

2005-09-25 Thread Igor V. Rafienko
Hi, I am trying to understand how cElementTree's clear works: I have a (relatively) large XML file, that I do not wish to load into memory. So, naturally, I tried something like this: from cElementTree import iterparse for event, elem in iterparse("data.xml"): if elem.tag == "schnappi":