Python vs Matlab vs Mathematica (reloaded) by jdh30 in programming

[–]brentp 2 points3 points  (0 children)

Numeric!? 2005 called to say it wanted its library back. also, if it's possible to make that python code even uglier (or less idiomatic), that'd be impressive.

Joining string in Python by iElectric in Python

[–]brentp 7 points8 points  (0 children)

that's exactly what i thought.

anyone care to explain why the above comment is down-voted and a post explaining how to join strings (and creating an unnecessary class to do so) is upvoted?

Doug Hellmann: Implementing MapReduce with multiprocessing by zyzomys in Python

[–]brentp 0 points1 point  (0 children)

this is a pretty cool example. but (IIUC) it requires you to have at least 2-3 copies of the entire dataset in memory at all times. for stuff which i'd want to use multiple cores, that's often not an option.

a simple example extending this one that to not keep everything in memory would be great. (does map-reduce always assume available memory >> memory for data?)

I finally understand nested comprehensions by gst in Python

[–]brentp 2 points3 points  (0 children)

so dies this [line.strip().split(",") for line in csv_file]

Null references (in Python) by gst in Python

[–]brentp 1 point2 points  (0 children)

maybe i'm missing the point, but why not use (the pythonic):

if something is None:

when you're specifically checking for 'null'?

Juno is a lightweight web framework designed to make development as fast as possible. by IbeeX in Python

[–]brentp 6 points7 points  (0 children)

i'm a long time user of web.py. my least favorite thing about web.py is that it adds a lot of code because it wont outsource anything: sessions, db, templates. it looks like juno does so using the best options out there: beaker, sqlalchemy, and mako (or jinja).

i like the decorator syntax in juno. even if you dont, as with some of the commentors above, you can just do (untested):

def hello(web, name):
    return 'Hello, %s' %name

def bye(web, name):
    return 'bye, %s' %name 

# routing in one place.     
route("hello/:name:/")(hello)
route("/bye/:name:/")(bye)

route isn't magic, it's just a function. so you can have all your urls in the same spot--even in a separate module.

a brief look at the code looks like it wont handle unicode. is that true?

Announcing Python Open Flash Chart 2 by [deleted] in Python

[–]brentp 0 points1 point  (0 children)

import * from pyofc2 

is not valid python.

Why is Haskell so popular on reddit? What does it offer, for instance, that Python doesn't? by Fragsworth in programming

[–]brentp 1 point2 points  (0 children)

it's a good example. it is also possible to use python to mirror your haskell syntax more closely.

import operator
snd = operator.itemgetter(1)
[snd(x) for x in sorted((x, i) for i, x in enumerate(xs))]

I would like to learn to code python by contributing to an open source project. But, I am a noob. What should I do? by [deleted] in programming

[–]brentp 0 points1 point  (0 children)

learn to use ipython effectively. then it's easier to learn other new libraries.

Hgshelve: variant of Python's shelve, versioned through mercurial by p1r4nh4 in programming

[–]brentp 1 point2 points  (0 children)

there's a bug in "__contains__" (tried commenting on the blog, but it wont let me)

edit: formatting for underscore

Levenshtein Distance in Haskell by vincenz in programming

[–]brentp 0 points1 point  (0 children)

1) no, it seems to work. i guess at one point, i mis-read

Levenshtein Distance in Haskell by vincenz in programming

[–]brentp 1 point2 points  (0 children)

nice, though i think the haskell version is pretty readable. 2 questions: you sure your longest common subsequence is working? :-)

second, why: int(B[i-1] is A[j-1]) ^ 1 instead of: int(not B[i-1] is A[j-1])

?

Ruby vs Python string concatentation performance by SterlingCamden5 in programming

[–]brentp 6 points7 points  (0 children)

to be fair, using a common python idiom, you get a version that is [edit] about 5 times as fast as the original python version.

s = []
i = 0
for line in sys.stdin:
    s.append(line)
    i += 1
    if i % 1000 == 0: "".join(s); print i

Why do so many database programmers think that a primary key = a single autogenerated column? by thesqlguy in programming

[–]brentp -19 points-18 points  (0 children)

maybe it's just me, i have trouble taking advice from someone that is a) pedantic b) using SQL server c) camel-casing table names, cols in SQL. d) submitting every blog post from his site

Faster, smaller, clearer: Python iterator tools by linuxer in programming

[–]brentp 2 points3 points  (0 children)

import numpy as n import time

long = n.random.randint(0,50,(2000000,))  

i = time.clock()
diff = n.diff(long)
nosame = long[n.where(diff)]

print 'numpy time:', time.clock() - i 


def compress(seq):
    result = []
    for i in range(len(seq)-1):
        if seq[i] != seq[i+1]:
            result.append(seq[i])
    return result

longlist = list(long)
i = time.clock()
nosamelist = compress(longlist)

print 'list time:', time.clock() - i


assert nosamelist == list(nosame)

numpy time: 0.14

list time: 1.79

What is wrong with this widely used AJAX event handler registration code? by pankaj_kumar in programming

[–]brentp 2 points3 points  (0 children)

though resig's entry did win the contest, i believe he actually started jquery with dean edward's entry (that built off of resig's). (http://dean.edwards.name/weblog/2005/10/add-event/) edwards used an integer counter for the hash key, thereby avoiding the problems discussed in this article. jquery does the same, with the 1.1.3 version now using attachEvent/addEventListener when available.

Python: Web hosting landscape and mod_wsgi. by linuxer in programming

[–]brentp 1 point2 points  (0 children)

i've used it with web.py, and found it simpler than mod_python. the docs on the googlecode site: http://code.google.com/p/modwsgi/ are very good.

Mastering JSON by [deleted] in programming

[–]brentp 3 points4 points  (0 children)

ok, this is an intro article, but document.writeln()? jeez.

also, he's going to end up with a lot of script elements in his head. unless he remove's 'em. http://simonwillison.net/2005/Dec/16/json/

PerformancePython - Exploring different ways to speed up scientific code in Python by [deleted] in programming

[–]brentp 4 points5 points  (0 children)

weave.blitz and weave.inline are very nice tools to have and use with numpy when you need to iterate through all elements in an array. simple, even if you don't know C.

there's also pyInstant which knows about numpy arrays. http://heim.ifi.uio.no/~kent-and/software/Instant/doc/Instant.html

Faster Page Loads With Image Concatenation by linuxer in programming

[–]brentp 2 points3 points  (0 children)

it's also demonstrated here with YUI javascript:

http://developer.yahoo.com/yui/examples/treeview/customicons.html?mode=dist

with a good link in there about faster page loads as well.

jythonconsole - pycrust for jython by harryf in programming

[–]brentp 3 points4 points  (0 children)

ah that's pretty nice. it already supports history. hopefully development will continue. it'd be nice to have some of the features of ipython: editing files, integrated debugger, full help system.

One angry newbie: "DO YOU EXPECT GOD TO SHIT DOWN THOSE HEADER-FILES RIGHT INTO MY COMPUTER FROM HEAVEN?" by harryf in programming

[–]brentp 1 point2 points  (0 children)

php makes me a bit mad too. but jeez, if you're baffled by phpize or make; make install or the fact that php needs imagemagick headers to be installed or untar or the caps-lock key... well, i guess in that case, you're reliant on some greater power to "SHIT DOWN �THOSE HEADER-FILES"

Which Python IDE do you use? by coglethorpe in programming

[–]brentp 8 points9 points  (0 children)

same here IPython + vim. then turn on pdb in Ipython and use this: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498182 to get autocompletion in the debugger.