Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 PYTHON


  A Python Optimization Anecdote

Hi! I’m Pavel and I interned at Dropbox over the past summer. One of my biggest projects during this internship was optimizing Python for dynamic page generation on the website. By the end of the summer, I optimized many of dropbox.com’s pages to render 5 times faster. This came with a fair share of challenges though, which I’d like to write about today:The ProblemDropbox is a large website with lots of dynamically generated pages. The more pages that are dynamically generated from user input, the bigger the risk becomes for Cross-site scriptingattacks. To prevent thi...

2,593 0       OPTIMIZATION PYTHON EFFICIENCY ANECODATE


  Python: copying a list the right way

new = old[:]Those proficient in Python know what the previous line do. It copies the list old into new. This is confusing for beginners and should be avoided. Sadly the [:] notation is widely used, probably because most Python programmers don’t know a better way of copying lists.A little bit of pythonic theoryFirst we need to understand how Python manages objects & variables. Python doesn’t have variables like C. In C a variable is not just a name, it is a set of bits; a variable exists somewhere in memory. In Python variables are just tags ...

2,576 0       PYTHON LIST COPY REFERENCE [:] LIST()


  Before Python

This morning I had a chat with the students at Google's CAPE program. Since I wrote up what I wanted to say I figured I might as well blog it here. Warning: this is pretty unedited (or else it would never be published :-). I'm posting it in my "personal" blog instead of the "Python history" blog because it mostly touches on my career before Python. Here goes.Have you ever written a computer program? Using which language?HTMLJavascriptJavaPythonC++COther - which?[It turned out the students had used a mixture of Scratch, App Inventor, and Processing. A few students had also used Python or Java.]...

2,514 0       PROGRAMMING LANGUAGE PYTHON HISTORY B


  Five-minute Multimethods in Python

So what are multimethods? I'll give you my own definition, as I've come to understand them: a function that has multiple versions, distinguished by the type of the arguments. (Some people go beyond this and also allow versions distinguished by the value of the arguments; I'm not addressing this here.)As a very simple example, let's suppose we have a function that we want to define for two ints, two floats, or two strings. Of course, we could define it as follows:def foo(a, b): if isinstance(a, int) and isinstance(b, int): ...code for two ints... elif isinstance(a, float) and is...

2,388 0       PYTHON MULTIMETHOD ARGUMENT LIST VERSION OVERLOADDING


  Python internals: adding a new statement to Python

This article is an attempt to better understand how the front-end of Python works. Just reading documentation and source code may be a bit boring, so I’m taking a hands-on approach here: I’m going to add an until statement to Python.All the coding for this article was done against the cutting-edge Py3k branch in the Python Mercurial repository mirror.The until statementSome languages, like Ruby, have an until statement, which is the complement to while (until num == 0 is equivalent to while num != 0). In Ruby, I can write:num = 3until num == 0 do puts num num -= 1endAnd it will...

2,325 0       PYTHON RESEARCH NEW STATEMENT ADDITION


  Python object creation sequence

[The Python version described in this article is 3.x]This article aims to explore the process of creating new objects in Python. As I explained in a previous article, object creation is just a special case of calling a callable. Consider this Python code:class Joe: passj = Joe()What happens when j = Joe() is executed? Python sees it as a call to the callable Joe, and routes it to the internal function PyObject_Call, with Joe passed as the first argument. PyObject_Call looks at the type of its first argument to extract its tp_call attribute.Now, what is the type of Joe? Whenever we define a ...

2,305 0       PYTHON OBJECT CREATION


  Strangest line of python you have ever seen

The other day @HairyFotr and @zidarsk8 were doing some codegolfing with implementations of nondeterministic finite state machineand asked me to blog their results.For those of us who often forget what all of this computer science mumbo jumbo means, here’s a quick explanation from wikipedia:In the theory of computation, a nondeterministic finite state machine or nondeterministic finite automaton (NFA) is a finite state machine where for each pair of state and input symbol there may be several possible next states.Essen...

2,073 0       PYTHON STRANGE RESEARCH WORK RATIONALE


  Thoughts on Python 3

I spent the last couple of days thinking about Python 3's current state alot. While it might not appear to be the case, I do love Python as alanguage and especially the direction it's heading in. Python has been notonly part of my life for the last couple of five years, it has been thelargest part by far.Let there be a warning upfront: this is a very personal post. I counted ahundred instances of a certain capital letter in this text.That's because I am very grateful for all the opportunities I got over thelast few years to travel the world, to talk to people and to share thespirit that an ...

1,934 0       PYTHON FEATURE DRAWBACK PYTHON 3 EMBRACE