Using String Methods In Jump Tables

2010-08-19 Thread Tim Daneliuk
Problem: Given tuples in the form (key, string), use 'key' to determine what string method to apply to the string: key operation --- llower() uupper() ttitle() ... Commentary: Easy, right? Wel

Re: expression in an if statement

2010-08-19 Thread ernest
On 19 Ago, 08:40, Frederic Rentsch wrote: > On Thu, 2010-08-19 at 00:12 +0200, Thomas Jollans wrote: > > On Wednesday 18 August 2010, it occurred to John Nagle to exclaim: > > > On 8/18/2010 11:24 AM, ernest wrote: > > > > Hi, > > > > > In this code: > > > > > if set(a).union(b) == set(a): pass >

Re: Using String Methods In Jump Tables

2010-08-19 Thread Chris Rebert
On Thu, Aug 19, 2010 at 4:27 PM, Tim Daneliuk wrote: > Problem: > >  Given tuples in the form (key, string), use 'key' to determine >  what string method to apply to the string: > >    key           operation >    --- > >     l            lower() >     u            upper() >  

Re: extra rows in a CSV module output when viewed in excel 2007

2010-08-19 Thread JonathanB
On Aug 13, 3:52 pm, alex23 wrote: > On Aug 13, 4:22 pm, JonathanB wrote: > > >         writer = csv.writer(open(output, 'w'), dialect='excel') > > I think - not able to test atm - that if you open the file in 'wb' > mode instead it should be fine. changed that to writer = csv.writer(open(output,

Re: extra rows in a CSV module output when viewed in excel 2007

2010-08-19 Thread MRAB
JonathanB wrote: On Aug 13, 3:52 pm, alex23 wrote: On Aug 13, 4:22 pm, JonathanB wrote: writer = csv.writer(open(output, 'w'), dialect='excel') I think - not able to test atm - that if you open the file in 'wb' mode instead it should be fine. changed that to writer = csv.writer(op

Re: extra rows in a CSV module output when viewed in excel 2007

2010-08-19 Thread JonathanB
On Aug 20, 9:10 am, MRAB wrote: > JonathanB wrote: > > On Aug 13, 3:52 pm, alex23 wrote: > >> On Aug 13, 4:22 pm, JonathanB wrote: > > >>>         writer = csv.writer(open(output, 'w'), dialect='excel') > >> I think - not able to test atm - that if you open the file in 'wb' > >> mode instead it

Re: How far can stack [LIFO] solve do automatic garbage collection and prevent memory leak ?

2010-08-19 Thread Richard Harter
On Thu, 19 Aug 2010 04:14:42 -0700 (PDT), spinoza wrote: >On Aug 18, 1:44=A0am, James Kanze wrote: >> On Aug 17, 6:21 pm, Standish P wrote: >> >> > > Garbage collection doesn't use a stack. It uses a "heap", >> > > which is in the abstract a collection of memory blocks of >> > > different l

Re: Using String Methods In Jump Tables

2010-08-19 Thread Steven D'Aprano
On Thu, 19 Aug 2010 18:27:11 -0500, Tim Daneliuk wrote: > Problem: > > Given tuples in the form (key, string), use 'key' to determine what > string method to apply to the string: >>> table = {'l': str.lower, 'u': str.upper} >>> table['u']('hello world') 'HELLO WORLD' [...] > As I said, I k

Re: Iterative vs. Recursive coding

2010-08-19 Thread Steven D'Aprano
On Thu, 19 Aug 2010 22:00:16 +, Martin Gregorie wrote: > Recursion can be quite a trick to get your mind round at first Really? Do people actually find the *concept* of recursion to be tricky? If I remember correctly, my puzzlement about recursion lasted about 15 seconds. I remember thinkin

Re: Using String Methods In Jump Tables

2010-08-19 Thread Tim Daneliuk
On 8/19/2010 7:23 PM, Steven D'Aprano wrote: > On Thu, 19 Aug 2010 18:27:11 -0500, Tim Daneliuk wrote: > >> Problem: >> >> Given tuples in the form (key, string), use 'key' to determine what >> string method to apply to the string: > table = {'l': str.lower, 'u': str.upper} table['u

Re: Using String Methods In Jump Tables

2010-08-19 Thread Tim Daneliuk
On 8/19/2010 6:41 PM, Chris Rebert wrote: > >> >> How do you get a reference to a method found in one object instance, but >> actually apply it to another instance of the same class? I'm guessing >> this may >> involve fiddling with some of the internal __ variables, but I'm not >> qu

Problem with tarfile module to open *.tar.gz files - unreliable ?

2010-08-19 Thread m_ahlenius
Hi, I am relatively new to doing serious work in python. I am using it to access a large number of log files. Some of the logs get corrupted and I need to detect that when processing them. This code seems to work for quite a few of the logs (all same structure) It also correctly identifies som

Re: 79 chars or more?

2010-08-19 Thread Steven D'Aprano
On Fri, 20 Aug 2010 15:09:39 +1200, Lawrence D'Oliveiro wrote: > In message , Terry > Reedy wrote: > >> A reason not mentioned much is that some people have trouble following >> packed lines that are too much longer. Wide-page textbooks routinely >> put text in two columns for easier reading. >

Re: Iterative vs. Recursive coding

2010-08-19 Thread John Nagle
On 8/19/2010 2:41 PM, Thomas Jollans wrote: On Thursday 19 August 2010, it occurred to Baba to exclaim: This is not recursive. In fact, it's exactly the same approach as the first one, plus a bit of an if statement. Right. The original poster seems to be getting their ideas from "http:/

Assert statements in python 3.1

2010-08-19 Thread genxtech
This is more of a curiosity question then anything else... I was just wondering why in version 3 of python assertions weren't converted to use parenthesis, since print was. I am just asking because it seems the following line of code would seem more readable as a function: assert 2 + 2 == 5, "

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Cameron Simpson
On 19Aug2010 21:50, Nik Gr wrote: | Στις 19/8/2010 6:58 μμ, ο/η Tim Chase έγραψε: | >It can be written as a non-3-quote string, you just have to escape | >the inner quotes (single & double) and the backslash to be seen: | > | > name = 'My name is "Nikos" and I\'m from Thessaloniki\\Greece' | >

Re: String substitution VS proper mysql escaping

2010-08-19 Thread Nik Gr
Στις 20/8/2010 8:22 πμ, ο/η Cameron Simpson έγραψε: [...snip...] | Why does the page variable which is actually a string needs to be a | tuple or a list and not just as a string which is what it actually | is? With regard to the "%" operator, it considers the string on the left to be a format s

Re: expression in an if statement

2010-08-19 Thread John Nagle
On 8/18/2010 3:12 PM, Thomas Jollans wrote: On Wednesday 18 August 2010, it occurred to John Nagle to exclaim: On 8/18/2010 11:24 AM, ernest wrote: Hi, In this code: if set(a).union(b) == set(a): pass Does Python compute set(a) twice? CPython does. Shed Skin might optimize. Don't kn

<    1   2