Re: Get named groups from a regular expression

2014-07-03 Thread Philip Shaw
On 2014-07-01, Florian Lindner mailingli...@xgm.de wrote:

 Is there a way I can extract the named groups from a regular
 expression?  e.g. given (?Ptestgrp\d) I want to get something
 like [testgrp].

The match object has an attribute called groupdict, so you can get
the found named groups using match.groupdict.keys. I can't remember
what happens to unnamed groups (I prefer to name every group I want),
but ISTR that there is a list of capture groups in which the indexes
are the capture groups number (i.e. what you'd use to backreference
them).

 Can I make the match object to return default values for named
 groups, even if no match was produced?

A lazy solution I've used was to write a default dict, then update it
with the groupdict. I doubt that's all that efficient, but the
defaults were constant strings and the program was network-bound
anyway.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: try/except/finally

2014-06-09 Thread Philip Shaw
On 2014-06-08, Dave Angel da...@davea.name wrote:
 Frank B fbick...@gmail.com Wrote in message:
 Ok; this is a bit esoteric.
 
 So finally is executed regardless of whether an exception occurs, so states 
 the docs.
 
 But, I thought, if I return from my function first, that should take 
 precedence.
 
 au contraire
 
 Turns out that if you do this:
 
 try:
   failingthing()
 except FailException:
   return 0
 finally:
   return 1
 
 Then finally really is executed regardless... even though you told it to 
 return.
 
 That seems odd to me.
 

 The thing that's odd to me is that a return is permissible inside
  a finally block. That return
 should be at top level,  even with the finally line. And of course
  something else should be in the body of the finally
  block.

It does have some legitimate uses, for example:

try:
failingThing()
finally:
simple_cleanup()
if(that_worked())
return
complicated
cleanup
with
lots
of
blocks

OTOH, it could just be that Guido didn't think of banning it when
exceptions were first added and doesn't want to introduce an
incompatability later.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to use SQLite (sqlite3) more efficiently

2014-06-09 Thread Philip Shaw
On 2014-06-06, Mark Lawrence breamore...@yahoo.co.uk wrote:
 On 06/06/2014 22:58, Dave Angel wrote:
 Chris Angelico ros...@gmail.com Wrote in message:
 On Sat, Jun 7, 2014 at 4:15 AM, R Johnson
 ps16thypresenceisfullnessof...@gmail.com wrote:
 The subject line isn't as important as a header, carried invisibly
 through, that says that you were replying to an existing post. :)

 Sorry for my ignorance, but I've never edited email headers
 before and didn't find any relevant help on Google. Could you
 please give some more details about how to do what you're
 referring to, or perhaps point me to a link that would explain
 more about it? (FYI, I read the Python mailing list on Google
 Groups, and reply to posts in Thunderbird, sending them to the
 Python-list email address.)

 The simple answer is: You don't have to edit headers at all. If
 you want something to be part of the same thread, you hit Reply
 and don't change the subject line. If you want something to be a
 spin-off thread, you hit Reply and *do* change the subject. If you
 want it to be a brand new thread, you don't hit Reply, you start a
 fresh message.  Any decent mailer will do the work for you.

 Replying is more than just quoting a bunch of text and copying in
 the subject line with Re: at the beginning. :)


 set up a newsgroup in Thunderbird from gmane.comp.python.general.


 That doesn't sound right to me.  Surely you set up the newgroup
 news.gmane.org and then subscribe to the mailing lists, blog feeds
 or whatever it is that you want?


In usenet parlance, news.gmane.org is a newsserver, and
gmane.comp.python.general is a newsgroup.

gmane runs a series of mail-news gateways for several mailing lists,
but there are others as well: someone also bridges the list to
the group comp.lang.python, which is where I'm reading this.
-- 
https://mail.python.org/mailman/listinfo/python-list