Posts

Showing posts with the label python3

Thoughts on Python 3

It's awesome. Go get some!

python3.2(svn) python2.7(svn) and the new GIL, cherrypy as a test.

Image
I've done some quick benchmarks for the unreleased python3.2 on the unreleased cherrypy webserver for python 3. Also with the unreleased python2.7. Here are the results... python3.1 Client Thread Report (1000 requests, 14 byte response body, 10 server threads): threads | Completed | Failed | req/sec | msec/req | KB/sec | 25 | 1000.0 | 0.0 | 533.32 | 1.875 | 93.75 | 50 | 1000.0 | 0.0 | 525.86 | 1.902 | 92.69 | 100 | 1000.0 | 0.0 | 522.96 | 1.912 | 92.1 | 200 | 1000.0 | 0.0 | 523.83 | 1.909 | 92.25 | 400 | 1000.0 | 0.0 | 506.92 | 1.973 | 89.27 | Average | 1000.0 | 0.0 | 522.578 | 1.9142 | 92.012 | python3.2 Client Thread Report (1000 requests, 14 byte response body, 10 server threads): threads | Completed | Failed | req/sec | msec/req | KB/sec | 25 | 1000.0 | 0.0 | 555.72 | 1.799 | 97.78 | 50 | 1000.0 | 0.0 | 558.86 | 1.789 | 98.52 | 100 | 1000.0 | 0.0 | 552.87 | 1.809...

Writing for the latest python is FUN.

Image
Writing for the latest python version is just simply... fun. Even the name 'python 3000' or py3k is amusing. It's been a joy over the last week plugging away at a few personal website and game projects using the latest python version. Over the last year I've been involved in upgrading existing code to the latest versions of python... but not really in writing it JUST for the latest versions. No need to consider backwards compatibility problems... older pythons be damned when programming for fun! I'm able to take advantage of the latest python features in deep architectural ways. To fiddle around with the new deep magic python internals. But the new deep magic parts aren't the best bits though... it's all the elegant little improvements that make a difference. It is of great delight finding python 3 compatible modules. It turns out that the modules available for python 3 are often of quite good quality - and well maintained. There's not all that ...

pywebsite.sqlitepickle. sqlite VS pickle

Image
The sqlite and pickle modules that come with python are quite useful. So lets mix them together and see what comes out. SQLITE Vs PICKLE pywebsite.sqlitepickle is a little module I just made which combines sqlite and pickle for persistence. Useful since it works with python3, and both pickle and sqlite are included with pythons (including pypy). Import the module. >>> from pywebsite import sqlitepickle An in memory db. >>> db = sqlitepickle.SQLPickle() >>> db.save('key', 'value') >>> db.get('key') 'value' Can also save to a file. So we first get a temp file name. >>> import tempfile >>> f = tempfile.NamedTemporaryFile() >>> fname = f.name >>> db = sqlitepickle.SQLPickle(fname) >>> db.save('key', 'value') >>> db.get('key') 'value' >>> db.close() The issues with this are that sqlite does not like sharing conn...

Where did the 'new' module go in python 3?

Anyone know where the 'new' module went in python 3? 2to3 can't seem to find 'new', and I can't find anywhere with my favourite search engine either... filed bug at: issue6964 . A complete 2to3 tool should know about all modules that are missing at least. It needs to actually know what to do with those modules, but should be able to at least tell you which modules are missing. I'm not sure how to get a complete top level module list sanely... I guess by scanning the libs directory of python. Or maybe there is a module to find all python modules? Each platform would be slightly different of course... and there'd be differences based on configure. Also some modules have probably stopped importing or compiling at all these days. Then you could just find the intersection and differences with the lovely set module :) # find the difference between the modules. top_level_modules_not_in_3 = set(top_level_modules3series) - set(top_level_modules1_2series) Wel...

py3k(python3) more than one year on - 0.96 % packages supporting py3k.

Python3 was released more than a year ago so far, and the release candidates and beta releases much before then. How successful has the transition been to python3 so far? One way to measure that is to look at how many python packages have been ported to py3k. One way to measure what packages are released is to look at the python package index(aka cheeseshop, aka pypi) . Not all packages ported to python3 are listed on pypi, and not all packages are listed on pypi. Also there are many packages which haven't been updated in a long time. However it is still a pretty good way to get a vague idea of how things are going. 73 packages are listed in the python3 section of pypi, and 7568 packages in total. That's 0.96% of python packages having been ported to python3. Another large project index for python is the pygame.org website. Where there are currently over 2000 projects which use pygame. I think there are 2 projects ported to python3 on there(but I can't find them at t...

python3 C API - simple slicing (sq_slice) gone.

Python3.x silently removed simple slicing support from the C API. The problem is, python3 doesn't give you a warning it won't be used... it compiles fine... just your slicing tests will fail. Since it's not documented anywhere, I will briefly mention a solution. Thanks to Campbell Barton for the idea. You can reuse your old sq_slice function and create a new function in a PyMappingMethods. You can also reuse your sq_length in the MappingMethods directly with no changes. http://docs.python.org/dev/py3k/c-api/typeobj.html#mapping-object-structures mp_subscript is it's name. Here is an example function from pygame.Color where it reuses _color_slice from the old simple slice function. static PyObject * _color_subscript(PyColor* self, PyObject* item) { #if PY_VERSION_HEX if (PyInt_Check(item)) { Py_ssize_t i; i = 0; #else if (PyIndex_Check(item)) { Py_ssize_t i; i = PyNumber_AsSsize_t(item, PyExc_IndexError); #endif if (i == ...