python

Is this a bug in Django or what? Logging out of the Django Authentication system...will remove all sessiosn?

I'm using sessions across my application. And using logins. When I do a simple: #log out the user. logout(request) ...the request.sessions get erased. What is this??! ...

Efficient way to convert numpy record array to a list of dictionary

How do I convert the numpy record array below: recs = [('Bill', 31, 260.0), ('Fred', 15, 145.0)] r = rec.fromrecords(recs, names='name, age, weight', formats='S30, i2, f4') to a list of dictionary like: [{'name': 'Bill', 'age': 31, 'weight': 260.0}, 'name': 'Fred', 'age': 15, 'weight': 145.0}] ...

How can I optimize multiple nested SELECTs in SQLite (w/Python)?

I'm building a CGI script that polls a SQLite database and builds a table of statistics. The source database table is described below, as is the chunk of pertinent code. Everything works (functionally), but the CGI itself is very slow as I have multiple nested SELECT COUNT(id) calls. I figure my best shot at optimization is to ask the SO...

Possible to use GCJ to produce library callable from Python ?

Is it possible to compile a library intended for Java with GCJ, get a dll and call from python ctypes? I'm interested in toxilibs for now, but if anybody knows a toy example that would be great ! ...

Python: Problem with metaclasses in conjunction multiple inheritance

Hi, i have two questions converning metaclasses and multiple inheritance. The first is: Why do i get a TypeError for the class Derived but not for Derived2? class Metaclass(type): pass class Klass(object): __metaclass__ = Metaclass #class Derived(object, Klass): pass # if I uncomment this, I get a TypeError class OtherClass(ob...

Python win32com: Excel set chart type to Line

This VBA macro works: Sub Draw_Graph() Columns("A:B").Select ActiveSheet.Shapes.AddChart.Select ActiveChart.SetSourceData Source:=ActiveSheet.Range("$A:$B") ActiveChart.ChartType = xlLine End Sub This Python (near) Equivalent almost works: from win32com import client excel=client.Dispatch("Excel.Application") excel.V...

Minimal linear regression program

Hi, I am running some calculations in an external machine and at the end I get X, Y pairs. I want to apply linear regression and obtain A, B, and R2. In this machine I can not install anything (it runs Linux) and has basic stuff installed on it, python, bash (of course), etc. I wonder what would be the best approach to use a script(pyt...

Why am I getting an error about my class defining __slots__ when trying to pickle an object?

I'm trying to pickle an object of a (new-style) class I defined. But I'm getting the following error: >>> with open('temp/connection.pickle','w') as f: ... pickle.dump(c,f) ... Traceback (most recent call last): File "<stdin>", line 2, in <module> File "/usr/lib/python2.5/pickle.py", line 1362, in dump Pickler(file, protocol...

What's a good web framework and/or tool for a software developer?

I'd like to make a website, it's not a huge project, but I'm a bit out of the web design loop. The last time I made a website was probably around 2002. I figure the web frameworks and tools have come a ways since then. It's mostly the design aspect that I'd like it to make easier. I can do the backend language in any language. My qu...

Using a PFX Certificate to connect to an HTTP site

Here's the scenario: I need to connect to a web site to retrieve electronic lab results formatted in XML. In order to connect, I need to use a digital certificate. I've been able to get a version of this working in Perl. It looks like this: #!/usr/bin/env perl use strict; use WWW::Mechanize; $|++; my $username = 'xxx'; my $password...

Everything is ok, but my 127.0.0.1:8000 can't show anything, why ? I used django-sphinx

from djangosphinx.models import SphinxSearch def xx(request): queryset =File.search.query('test') #return HttpResponse(queryset)#<------1 return render_to_response('a.html',{'a':queryset})#<--------2 and class File(models.Model): name = models.CharField(max_length=200) tags = models.CharField(max_length=200) # We ...

setting help_text for each choice in a RadioSelect

I can set the help_text attribute on any form field, but is it possible to set help_text on the choices used for a RadioSelect()? I'd looking for a clean way to show some help information under each radio button. Below is the code for the model and the form, I can render the name attribute in a template with the label, input element an...

Transform items from iterable with a sequence of unary functions

I frequently find myself needing to apply a sequence of unary functions to a sequence of of the same length. My first thought is to go with map(), however this only takes a single function to be applied to all items in the sequence. In the following code for example, I wish to apply str.upper() to the first item, and int to the second i...

PIP install a Python Package without a setup.py file?

I'm trying to figure out how I can install a python package that doesn't have a setup.py file with pip. (package in question is http://code.google.com/p/django-google-analytics/) Normally I would just checkout the code from the repo and symlink into my site-packages, but I'm trying to get my whole environment frozen into a pip requireme...

Write timestamp to file every hour in Python

I have a python script that is constantly grabbing data from Twitter and writing the messages to a file. The question that I have is every hour, I want my program to write the current time to the file. Below is my script. Currently, it gets into the timestamp function and just keeps printing out the time every 10 seconds. #! /usr/bin/en...

Restricting RSS elements by date with feedparser. [Python]

I iterate a RSS feed like so where _file is the feed d = feedparser.parse(_file) for element in d.entries: print repr(element.date) The date output comes out like so u'Thu, 16 Jul 2009 15:18:22 EDT' I cant seem to understand how to actually quantify the above date output so I can use it to limit feed elements. I So what I am ...

Creating "classes" with Django

I'm just learning Django so feel free to correct me in any of my assumptions. I probably just need my mindset adjusted. What I'm trying to do is creating a "class" in an OOP style. For example, let's say we're designing a bunch of Rooms. Each Room has Furniture. And each piece of Furniture has a Type and a Color. What I can see so ...

How to redirect to a query string URL containing non-ascii characters in DJANGO?

How to redirect to a query string URL containing non-ascii characters in DJANGO? When I use "return HttpResponseRedirect(u'/page/?title=' + query_string)" where the query_string contains characters like "你好", I get an error "'ascii' codec can't encode characters in position 21-26: ordinal not in range(128), HTTP response headers must be...

Multiple database connections with Python + Pylons + SQLAlchemy

I'm trying to implement the proper architecture for multiple databases under Python + Pylons. I can't put everything in the config files since one of the database connections requires the connection info from a previous database connection (sharding). What's the best way to implement such an infrastructure? ...

How do I properly setup my python paths and permissions for Django+mod_wsgi deployment?

The issue I'm having is my wsgi file can't import the wsgi handlers properly. /var/log/apache2/error.log reports: ImportError: No module named django.core.handlers.wsgi Googling this brings up a couple results, mostly dealing with permissions errors because www-data can't read certain files and/or the pythonpath is not correct. ...