You start your day, happily working with dictionaries…Life is good. >>> mydict = {‘key-a’: ‘value-a’, ‘key-b’: ‘value-b’} >>> mydict['key-a'] ‘value-a’ All of a sudden, storm clouds appear. Your dictionary variable accidentally gets assigned a list, and life is no longer good! >>> mydict = {‘key-a’: ‘value-a’, ‘key-b’: ‘value-b’} >>> mydict['key-a'] ‘value-a’ >>> mydict = [] [...]
Posts Tagged ‘Python’
Great article on Python super, __mro__, and attributes
Posted in Engineering, Open Source, Perspective, Technique, tagged Python, Python attributes, Python super(), Python __mro__ on February 20, 2010 | Leave a Comment »
I highly recommend reading this excellent writeup on Python super(), python __mro__, python attributes, and more. It is Copyright © 2005-2009 Shalabh Chaturvedi http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html#method-resolution-order
Python 3 bytes indexing returns integers!
Posted in Engineering, Technique, tagged bytes, Python, python 3 on December 31, 2009 | Leave a Comment »
While converting a bunch of werkzeug code to Python 3.1, I ran into an issue with one of the bytes objects that was previously a string. The line of code in question was originally this: if value and value[0] == value[-1] == b’"’: … If value is something, and the first and last characters are [...]
Python has keyword only parameters!
Posted in Engineering, Technique, tagged keyword arguments, programming, Python on December 8, 2009 | Leave a Comment »
Maybe I should have known this about Python by now, but… Little did I know (was wishing for it today), but there IS a way to specify that arguments MUST be keyword only. >>> def foo(a,b,*,c,d): … print(a,b,c,d) … >>> foo(1,2,3,4) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: [...]
A brief introduction to AppStruct
Posted in AppCove, AppStruct, Engineering, Open Source, Technique, tagged Apache, AppCove, AppStruct, mod_wsgi, Open Source, PostgreSQL, Python, Shank on November 21, 2009 | Leave a Comment »
Have been very busy at work lately. We made the decision about a month ago to switch (most|all) new projects over to use Python 3 with Apache, mod_wsgi, and AppStruct. You may know what the first 3 are, but the 4th?? Special thanks goes to Graham Dumpleton behind mod_wsgi, and James William Pye behind Python>>Postgresql. [...]
Python 3.1 and mod_wsgi performance notes
Posted in AppCove, Engineering, Linux, reSearch, tagged Apache, mod_wsgi, Performance, Python, python 3 on October 11, 2009 | Leave a Comment »
We’re researching the use of Python and mod_wsgi running under apache for developing some extensive web applications. Here are some notes on a performance test that we recently ran. ================================================================== Server: x86_64 Python 3.1.1 mod_wsgi 3.0c5 apache 2.2 RHEL 5.3 quad core xenon 8 GB ram Development system – not in production use. ================================================================== Application: [...]
What is a tuple?
Posted in Engineering, Interesting, Technique, tagged Python, Tuple on September 3, 2009 | Leave a Comment »
I get asked this from time to time, so for the fun of it, I’ll post this: Tuples are immutable lists in python (and other languages). Very lightweight, unchangable arrays. They are used for storing multiple values in one variable (usually a fixed number of values). x = (1, 2, 3, ‘abc’) x[0] -> 1 [...]
Basics of telnet and HTTP
Posted in Engineering, Technique, tagged Apache, HTTP, Python, telnet on January 23, 2009 | 2 Comments »
Say you want to request a webpage… Normally, one would use a web browser, right? But sometimes you just need to see what is really going on… In this blog post I will show the basics of using the telnet command to work with the HTTP protocol. For reference: http://www.w3.org/Protocols/rfc2616/rfc2616.html Most of these commands were [...]