Python dos2unix one liner
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sun Feb 28 03:48:31 EST 2010
On Sat, 27 Feb 2010 19:37:50 -0800, staticd wrote:
>> >Amusing how long those Python toes can be. In several replies I have
>> >noticed (often clueless) opinions on Perl. When do people learn that a
>> >language is just a tool to do a job?
>>
>> When do people learn that language makes a difference? I used to be a
>> Perl programmer; these days, you'd have to triple my not-small salary
>> to get me to even think about programming in Perl.
>
> dude, you nailed it. many times, if not _always_, the correct output is
> important. the method used to produce the output is irrelevant.
Oh really?
Then by that logic, you would consider that these two functions are both
equally good. Forget readability, forget maintainability, forget
efficiency, we have no reason for preferring one over the other since the
method is irrelevant.
def greet1(name):
"""Print 'Hello <name>' for any name."""
print "Hello", name
def greet2(name):
"""Print 'Hello <name>' for any name."""
count = 0
for i in range(0, ("Hello", name).__len__(), 1):
word = ("Hello", name).__getitem__(i)
for i in range(0, word[:].__len__(), 1):
c = word.__getitem__(i)
import sys
import string
empty = ''
maketrans = getattr.__call__(string, 'maketrans')
chars = maketrans.__call__(empty, empty)
stdout = getattr.__call__(sys, 'stdout')
write = getattr.__call__(stdout, 'write')
write.__call__(c)
count = count.__add__(1)
import operator
eq = getattr.__call__(operator, 'eq')
ne = getattr.__call__(operator, 'ne')
if eq.__call__(count, 2):
pass
elif not ne.__call__(count, 2):
continue
write.__call__(chr.__call__(32))
write.__call__(chr.__call__(10))
return None
There ought to be some kind of competition for the least efficient
solution to programming problems-ly y'rs,
--
Steven
More information about the Python-list
mailing list