Re: Refactoring; arbitrary expression in lists

2005-01-14 Thread Steve Holden
Peter Maas wrote: Steven Bethard schrieb: BJörn Lindqvist wrote: [...] I believe this can be nicelier written as: if "Makefile" in basename: +1 for "nicelier" as VOTW (Vocabulation of the week) =) Me too, because nicelier is nicer than more nicely. :) Is that really the niceliest way to express th

Re: Refactoring; arbitrary expression in lists

2005-01-13 Thread Peter Maas
Steven Bethard schrieb: BJörn Lindqvist wrote: [...] I believe this can be nicelier written as: if "Makefile" in basename: +1 for "nicelier" as VOTW (Vocabulation of the week) =) Me too, because nicelier is nicer than more nicely. :) -- --

Re: Refactoring; arbitrary expression in lists

2005-01-13 Thread Steven Bethard
BJörn Lindqvist wrote: # do other non-extension-related tests here if basename.find( "Makefile" ) != -1: return "text/x-makefile" I believe this can be nicelier written as: if "Makefile" in basename: +1 for "nicelier" as VOTW (Vocabulation of the week) =) Steve -- http://mail.python.o

Re: Refactoring; arbitrary expression in lists

2005-01-13 Thread BJörn Lindqvist
> # do other non-extension-related tests here > if basename.find( "Makefile" ) != -1: > return "text/x-makefile" I believe this can be nicelier written as: if "Makefile" in basename: -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list

Re: Refactoring; arbitrary expression in lists

2005-01-13 Thread Jeff Shannon
Stephen Thorne wrote: As for the overall efficiency concerns, I feel that talking about any of this is premature optimisation. I disagree -- using REs is adding unnecessary complication and dependency. Premature optimization is a matter of using a conceptually more-complicated method when a sim

Re: Refactoring; arbitrary expression in lists

2005-01-13 Thread Paul McGuire
Despite the regexp alternatives, I refuse to post a pyparsing solution to this! :) -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: Refactoring; arbitrary expression in lists

2005-01-13 Thread Nick Craig-Wood
Stephen Thorne <[EMAIL PROTECTED]> wrote: > Why not use a regexp based approach. Good idea... You could also use sre.Scanner which is supposed to be fast like this... import re, sre scanner = sre.Scanner([ (r"\.php$", "application/x-php"), (r"\.(cc|cpp)$", "text/x-c++-src"), (r"\.x

Re: Refactoring; arbitrary expression in lists

2005-01-12 Thread Stephen Thorne
On Thu, 13 Jan 2005 05:18:57 GMT, Bengt Richter <[EMAIL PROTECTED]> wrote: > On Thu, 13 Jan 2005 12:19:06 +1000, Stephen Thorne <[EMAIL PROTECTED]> wrote: > > >On Thu, 13 Jan 2005 01:24:29 GMT, Bengt Richter <[EMAIL PROTECTED]> wrote: > >> extensiondict = dict( > >> php = 'application/

Re: Refactoring; arbitrary expression in lists

2005-01-12 Thread Bengt Richter
On Thu, 13 Jan 2005 12:19:06 +1000, Stephen Thorne <[EMAIL PROTECTED]> wrote: >On Thu, 13 Jan 2005 01:24:29 GMT, Bengt Richter <[EMAIL PROTECTED]> wrote: >> extensiondict = dict( >> php = 'application/x-php', >> cpp = 'text/x-c-src', >> # etcetera >> xsl = 'test

Re: Refactoring; arbitrary expression in lists

2005-01-12 Thread Stephen Thorne
On Thu, 13 Jan 2005 01:24:29 GMT, Bengt Richter <[EMAIL PROTECTED]> wrote: > extensiondict = dict( > php = 'application/x-php', > cpp = 'text/x-c-src', > # etcetera > xsl = 'test/xsl' > ) > > def detectMimeType(filename): > extension = os.path.sp

Re: Refactoring; arbitrary expression in lists

2005-01-12 Thread Bengt Richter
On Wed, 12 Jan 2005 18:16:23 +, Frans Englich <[EMAIL PROTECTED]> wrote: > >As continuation to a previous thread, "PyChecker messages", I have a question >regarding code refactoring which the following snippet leads to: > >> > runner.py:200: Function (detectMimeType) has too many returns (11)

Re: Refactoring; arbitrary expression in lists

2005-01-12 Thread Jeff Shannon
Paul McGuire wrote: "Frans Englich" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] #-- def detectMimeType( filename ): extension = filename[-3:] You might consider using os.path.splitext() here, instead of always assuming

Re: Refactoring; arbitrary expression in lists

2005-01-12 Thread Frans Englich
On Wednesday 12 January 2005 18:56, [EMAIL PROTECTED] wrote: > I can not break the original code in 2.4, if I try this: [...] > > So although the dictionary solution is much nicer nothing seems wrong > with your code as it is - or am I missing something? Nope, the current code works. I'm just lo

Re: Refactoring; arbitrary expression in lists

2005-01-12 Thread [EMAIL PROTECTED]
I can not break the original code in 2.4, if I try this: import os, sys class NoMimeError(Exception): pass def detectMimeType( filename ): extension = filename[-3:] basename = os.path.basename(filename) if extension == "php": return "application/x-php" elif extension == "cpp" or extension.endswit

Re: Refactoring; arbitrary expression in lists

2005-01-12 Thread Paul McGuire
"Frans Englich" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > As continuation to a previous thread, "PyChecker messages", I have a question > regarding code refactoring which the following snippet leads to: > > > > runner.py:200: Function (detectMimeType) has too many returns (11)

Refactoring; arbitrary expression in lists

2005-01-12 Thread Frans Englich
As continuation to a previous thread, "PyChecker messages", I have a question regarding code refactoring which the following snippet leads to: > > runner.py:200: Function (detectMimeType) has too many returns (11) > > > > The function is simply a long "else-if" clause, branching out to > > diffe