python

How do I send single character ASCII data to a serial port with python.

I'v looked at pyserial but I can't seem to figure out how to do it. I only need to send one at a time? Please help? ...

Python sample programs for FusionCharts to integrate with MySQL.

I want to integrate Python with FusionCharts and MySQL. I have python programs to create/access MySQL DB. The same data which resides in the MySQL DB has to be projected to the user in the FusionCharts using Python scripts. Please help me out on this. ...

I have a text file of a paragraph of writing, and want to iterate through each word in Python

How would I do this? I want to iterate through each word and see if it fits certain parameters (for example is it longer than 4 letters..etc. not really important though). The text file is literally a rambling of text with punctuation and white spaces, much like this posting. ...

Python: pattern matching for a string

Im trying to check a file line by line for any_string=any_string. It must be that format, no spaces or anything else. The line must contain a string then a "=" and then another string and nothing else. Could someone help me with the syntax in python to find this please? =] pattern='*\S\=\S*' I have this, but im pretty sure its wrong h...

Caching static files in Django

I was profiling the performance of my web application using Google's Page Speed plugin for Firebug and one of the things it says is that I should 'leverage caching' — "The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources". When I dug deeper I ...

Why does Python disables MSCRT assertions when built with debug mode?

Python disables MSCRT assertions for debug mode during the initialization of exceptions module when it is built in debug mode. At least from the source code, I can see Python 2.6.5 doing this for _MSC_VER >= 1400 i.e. Visual C++ 2005. Does anyone know why? ...

Fade in/out the background color of wxpython grid cell

I've got a wxpython grid, and I'm changing the background color of a cell to show that something has happened to it. I'd like to fade the color change in/out (like JavaScript in the browser) for a smoother look. Is this possible to do? Right now, I'm just changing the background color, and then changing it back after a 1.5-second inter...

Fix depth tree in Python

I want to implement a tree structure which has fixed depth, i.e. when adding children to the leef nodes, the whole tree structure should "move up". This also means that several roots can exist simultaneously. See example beneath: In this example, the green nodes are added in iteration 1, deleting the top node (grey) and making the two b...

uWSGI + Django + Virtualenv unable to pick up _functools (import error)

OK, So I have tried this with & without a virtualenv: uwsgi --home /home/auston/new_proj/ --socket /tmp/uwsgi2.sock --chmod-socket --module app_wsgi --pp /home/auston/new_proj/nikeshere --logto /tmp/uwsgi.log --master --processes 4 -P Pretty much no matter what, I get this: *** Starting uWSGI 0.9.6.5 (32bit) on [Thu Oct 21 08:05:44 2...

python "best practice" for lists/dictionary etc

Been looking over the python docs for code formatting best practice for large lists and dictionaries, eg something = {'foo' : 'bar', 'foo2' : 'bar2', 'foo3' : 'bar3'..... 200 chars wide etc..} or something = {'foo' : 'bar', 'foo2' : 'bar2', 'foo3' : 'bar3', ... } or something = {...

converting tiff to gif in php

Hi ! I need to convert tiff file to gif . can some one give me php or python script to do that ? ...

How to calculate a sigmoid function in Python?

This is a sigmoid function: I know x. How can I calculate F(x) in Python now? Let's say x = 0.458. F(x) = ? ...

Python - go to two lines above match

In a text file like this: First Name last name # secone name Address Line 1 Address Line 2 Work Phone: Home Phone: Status: First Name last name # ....same as above... I need to match string 'Work Phone:' then go two lines up and insert character '|' in the begining of line. so pseudo code would be: if "Work Phone:" in line: go u...

How to implement "autoincrement" on Google AppEngine

I have to label something in a "strong monotone increasing" fashion. Be it Invoice Numbers, sipping label numbers or the like. A number MUST NOT BE used twice Every number SHOULD BE used when exactly all smaller numbers have been used (no holes). Fancy way of saying: I need to count 1,2,3,4 ... The number Space I have available are t...

How do I write text in subscript in the axis labels and the legend?

I have the following axis labels and legend. plt.ylabel("ratio_2") plt.xlabel("n_1") plt.legend(('alpha_1','alpha_2' ), loc = 'best',shadow = True) ...

Law of Demeter and Python

Is there a tool to check if a Python code conforms to the law of Demeter? I found a mention of Demeter in pychecker, but it seems that the tool understands this law different to what I expect: http://en.wikipedia.org/wiki/Law_of_Demeter The definition from wikipedia: the Law of Demeter for functions requires that a method M of an objec...

conversion of string representing HH:MM:SS.sss format into HH:MM:SS.ssssss format in python

I have string which is representing time in HH:MM:SS.sss format ,Now i have to convert this sting into HH:MM:SS.ssssss format.Please let me know how to do this? ...

qrcode for python on linux

Hello Friends, I have an error when i used pyqrcode. [root@localhost python2.6]# python Python 2.6.5 (r265:79063, Sep 7 2010, 07:31:57) [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import qrcode Traceback (most recent call last): File "<stdin>", li...

Django query filter combining AND and OR with Q objects don't return the expected results

I try to combine AND and OR in a filter using Q objects. It looks like that the | behave like an AND. This is related to the previous annotate which is run in the same query and not as a subquery. What is the correct way to handle this with Django? models.py class Type(models.Model): name = models.CharField(_('name'), max_length=1...

Accessing previous array element in django template for loop.

Hi! I'm new to django and can't find a way to get this to work in django templates. The idea is to check if previous items first letter is equal with current ones, like so: {% for item in items %} {% ifequal item.name[0] previous_item.name[0] %} {{ item.name[0] }} {% endifequal %} {{ item.name }}<br /> {% endforeach ...