python

Any way to run python TK scripts on web page?

Is there any way to run a python script that utilizes TKinter on a web page such that a user could run the script and interact with the TK windows without having to download the script or have the appropriate python interpreter? ...

Python 3 chokes on CP-1252/ANSI reading

I'm working on a series of parsers where I get a bunch of tracebacks from my unit tests like: File "c:\Python31\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 112: character maps to <undefined> T...

Python IDE that you can highlight a method/class and jump to its definition

I'm trying to use textmate, but I find it hard to navigate a project with it. I admit I probably just don't know the the IDE well enough. Is it possible to highlight a class or method and jump to its definition? ...

Data structure to store key-value pairs and retrive the key for the lowest value quickly

I'm implementing something like a cache, which works like this: If a new value for the given key arrives from some external process, store that value, and remember the time when this value arrived. If we are idle, find the oldest entry in the cache, fetch the new value for the key from external source and update the cache. Return the v...

How to switch backends in matplotlib / Python

Hi, I am struggling with the following issue. I need to generate reports that consists of a collection of charts. All these charts, except one, are made using Matplotlib default backend (TkAgg). One chart needs to be made using the Cairo backend, the reason is that I am plotting an igraph graph and that can only be plotted using Cairo. ...

How to get an attribute just from the current class and not from possible parent classes?

How to get an attribute just from the current class and not from possible parent classes? If I use getattr it traverses class hierarchy but I would like to get None if attribute is not defined in the current class (even if it is defined in some parent class). ...

Canonical URL compare in Python?

Are there any tools to do a URL compare in Python? For example, if I have http://google.com and google.com/ I'd like to know that they are likely to be the same site. If I were to construct a rule manually, I might Uppercase it, then strip off the http:// portion, and drop anything after the last alpha-numeric character.. But I can se...

Help with a custom GUI in wxpython

I'm new to wxPython, so bear with me. I'm creating a custom GUI set up and need to get two attributes. Firstly I want to create an inner boarder of a different color (The single dark boarder looks too plain). Secondly, I need to bind the dragging attribute so that only the label will allow dragging as opposed to the whole frame. Also ...

Remove items with checkboxes in Django forms

I'm writing a form with Django. The form is a model form for a certain model, Experiment. Each Experiment has several TimeSlot models associated with it, defined with a ForeignKey('Experiment'). I'd like to have a form with the option to remove one or more TimeSlot instances from the EditExperimentForm by checking boxes. Currently, I d...

Improving pure Python prime sieve by recurrence formula

I am trying to optimize further the champion solution in prime number thread by taking out the complex formula for sub-list length. len() of the same subsequence is too slow as len is expensive and generating the subsequence is expensive. This looks to slightly speed up the function but I could not yet take away the division, though I do...

wxPython Geometry problem

I'm trying to get the button to be right of the label. I set the tuple and am still not sure why it covers the label. Also is there a good tutorial available on wxpython geometry? import wx import wx.lib.agw.gradientbutton as GB def GetRoundBitmap( w, h, r ): maskColor = wx.Color(0,0,0) shownColor = wx.Color(5,5,5) b = w...

Numpy records in the c api

I'm playing with writing some C code to speed up an inner loop in my python code. This loop operates on a numpy record, e.g. soemthing like this: a = numpy.zeros((10,), dtype=[("myfvalue" ,"float"), ("myc", "int8"), ("anotheri", "uint64")]) which is then passed into c code like so: myCFunc(a, "blah") I...

CSV, DictWriter, unicode and utf-8

Hi, I am having problems with the DictWriter and non-ascii characters. A short version of my problem: #!/usr/bin/env python # -*- coding: utf-8 -*- import codecs import csv f = codecs.open("test.csv", 'w', 'utf-8') writer = csv.DictWriter(f, ['field1'], delimiter='\t') writer.writerow({'field1':u'å'.encode('utf-8')}) f.close() Giv...

Installing MySQLdb on Snow Leopard

I'm having all sorts of trouble trying to instal MySQLdb (1.2.2) on snow leopard. I am running python 2.5.1 and MySQL 5.1 32bit. Python and MySQL are running just fine. I've also installed django 1.2.1, although I don't think thats all that important, but wanted to give an idea of the stack i'm trying to install. I am using python 2.5....

Customize Python unittest report with HTML or Textile

Hey, I'm using unittest for testing my python code. I'm seeking a way that I can do the following: Customize the report of test run. Export it as HTML or Textile document. Any ideas? ...

Python: How to Capture WebPage as Image File?

I want to cache a webpage as an image upon a user request, but I don't know where to start with this. I'm developing on App Engine with python. ...

QWebView - dealing with javascript infinite loop

web_view_crash.py import sys from PyQt4.QtGui import * from PyQt4.QtCore import * from PyQt4.QtWebKit import * app = QApplication(sys.argv) view = QWebView() view.settings().setAttribute(QWebSettings.JavascriptEnabled, True) view.load(QUrl('infinite_loop.html')) view.show() app.exec_() infinite_loop.html <script> while(true) { ...

wxPython threaded UDP server

Hi, I am trying to put together a UDP server with a wxPython GUI. Here is a link to the code: UDP Server pastie.org I have linked it as its pretty lengthy. I have successfully got the UDP server running on the thread but I can not figure out how to close the socket when the stopping the thread. At the moment it will kick up a new t...

Google App Engine Python ImportError Module Not Found

I'm using Pydev 1.5.9 and the latest version of google app engine, developing in eclipse 3.6 I've set up my environment, and I have my base code executing fine. Now I'm trying to import the simplejson library using import simplejson I've tried adding the simplejson folder to a "pydev source folder" within eclipse tried adding simpl...

How to dynamically compose and access class attributes in Python?

I have a Python class that have attributes named: date1, date2, date3, etc. During runtime, I have a variable i, which is an integer. What I want to do is to access the appropriate date attribute in run time based on the value of i. For example, if i == 1, I want to access myobject.date1 if i == 2, I want to access myobject.date2 ...