python

Grouping on an attribute using itertools.groupby

I have a list of instances of the class 'Chromosome'. The list is sorted on the Chromosome attribute 'equation' I now want to remove instances where the attribute 'equation' is the same, leaving only one. I don't know how to pass the key, ie the ?, so that it groups on 'equation'. b = [a for a,b in groupby(list, ?)] ...

Python + SVN + Windows/Mac = Invalid syntax?

I'm pretty sure the following error is related to the fact that I'm sharing code via SVN with a colleague that is using a Windows system. Myself, I use Python on Mac, editing with TextMate. #!/usr/bin/python import os from google.appengine.api import users from google.appengine.ext import webapp ... When running that code, I get a...

How to start a long running process from Django view?

What I need to do is run a process that might take hours to complete from a Django view. I don't need to the state or communicate with it but I need that view to redirect away right after starting the process. I've tried using subprocess.Popen, using it within a new threading.Thread, multiprocessing.Process - parent process keeps hangin...

python import error

I'm trying to use some python-2.1 code to control another program (ArcGIS). The version of python I am using is 2.5. I am getting the following error message when I run the code. <type'exceptions.ImportError'>: No module named win32api Failed to execute (polyline2geonetwork2). I tried installing pywin32-214.win32-py2.5.exe but I still...

with python's win32com and parsing html problem

hello, I'm new to python. I want to extract some text from the CNN website. I want to use python win32com module. EDIT: on [why win32com] Because of javascript in website... I thought of using win32com; I have looked for other solution but without success in regard to my requirement. In fact, I wanted to use mechanize or a similiar solut...

How to extract the member from single-member set in python?

I recently encountered a scenario in which if a set only contained a single element, I wanted to do something with that element. To get the element, I settled on this approach: element = list(myset)[0] But this isn't very satisfying, as it creates an unnecessary list. It could also be done with iteration, but iteration seems unnatur...

Using Python Regular Expression in Django.

I have an web address: http://www.example.com/org/companyA I want to be able to pass CompanyA to a view using regular expressions. This is what I have: (r'^org/?P<company_name>\w+/$',"orgman.views.orgman") and it doesn't match. Ideally all URL's that look like example.com/org/X would pass x to the view. Thanks in advance! ...

[PyQt] Problems using PyQt's Resource System

I am trying to use PyQt's Resource System but it appears I have no clue what I am doing! I already have to application created, along with its GUI I am just trying to import some images to use with the program. I used the QtDesigner to create the resource file and I compiled it using pyrcc4.exe. But when I attempt to import the resource...

Extracting decimals from a number in Python

I am writing a function to extract decimals from a number. Ignore the exception and its syntax, I am working on 2.5.2 (default Leopard version). My function does not yet handle 0's. My issue is, the function produces random errors with certain numbers, and I don't understand the reason. I will post an error readout after the code. Func...

name a column and then call items with name instead of index

I have a list of columns that I will be analyzing. Instead of referring back to the specific index such as data[1][2], I'd like to assign a name to a column and then loop through the rows of the columns for different tasks. How do I assign a name to a column and then is this the correct format to refer back to it? for x in range (len(...

What is causing this Python exception?

I have a C++ app that uses Python to load some scripts. It calls some functions in the scripts, and everything works fine until the app exits and calls Py_Finalize. Then it displays the following: (GetName is a function in one of the scripts) Exception AttributeError: "'module' object has no attribute 'GetName'" in 'garbage collection' ...

Are there any mature vector drawing libraries for Python? (that work on Windows)

I've tried endlessly to get pycairo to work on Windows, but version 1.8.8 won't install. Is there something comparable out there that actually works on Windows? ...

In Django, how to clear all the memcached keys and values?

I don't want to restart the memcached server! ...

In Django, how can I embed something in CSS?

background: url({{ MEDIA_URL }}/bg.jpg); That does not work, because this Django template function only works in .html! ...

Sankey diagrams in Python

Is there a Python library for generating Sankey diagrams? I've seen this list of Sankey diagram software, but no Python. ...

str.format(list) with negative index doesn't work in Python

I use a negative index in replacement fields to output a formatted list,but it raises a TypeError.The codes are as follows: >>> a=[1,2,3] >>> a[2] 3 >>> a[-1] 3 >>> 'The last:{0[2]}'.format(a) 'The last:3' >>> 'The last:{0[-1]}'.format(a) Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers...

What is a light python library that can eliminate HTML tags? (and only text)

I know that NLTK has it. But any else? ...

Python: advantages and disvantages of _mysql vs MySQLdb?

Two libraries for Mysql. I've always used _mysql because it's simpler. Can anyone tell me the difference, and why I should use which one in certain occasions? ...

Installing satchmo without ssh access

Hi I want to install satchmo in my virtual hosting, but they dont provide ssh access for it. I want to know if it is possible. As i can see, adding some Satchmo requirements(http://www.satchmoproject.com/docs/svn/requirements.html) to pythonpath in my .fcgi file seems to be working, but some requirements like pycrypto and trml2pdf look ...

Send and receive messages via (libpurple) messenger protocols

I had an idea that would require me be able to send and receive messages via the standard messenger protocols such as msn, icq, aim, skype, etc... I am currently only familiar with PHP and Python and would thus enjoy a library which I can access from said languages. I have found phurple (http://sourceforge.net/projects/phurple/) for php...