python

SQLAlchemy and scalar values

Hello, I have simple question regarding SQLAlchemy, is it possible to get the rows from the result as scalars instead of tuples? In other words I want an equivalent to: [i[0] for i in self.archive.query(IRTerm.term).distinct()] Thank you ...

CherryPy behind Nginx reverse-proxy POST requests corrupted/truncated

I have put my application using Cherrypy 3.1.2 behind Nginx configured as a reverse-proxy. All is working right for GET requests, but all POST requests return HTTP 400 - Malformed header. I traced into CherryPy WSGI-Server source code to see the request-handling code and found out that if for GET requests the first request line correctl...

DJANGO Python-ldap UNWILLING TO PERFORM {'info': '00002077: SvcErr: DSID-031907B4, problem 5003 (WILL_NOT_PERFORM), data 0\n', 'desc': 'Server is unwilling to perform'}

My Django application using python-ldap library (ldap_groups django application) must add users against an Active Directory on a Windows 2003 Virtual Machine domain. My application running on a Ubuntu virtual Machine is not member of the Windows domain: Here is the code: settings.py DNS_NAME='IP_ADRESS' LDAP_PORT=389 LDAP_URL='ldap:/...

SQLAlchemy subquery - average of sums

Hello, is there any way how to write the following SQL statement in SQLAlchemy ORM: SELECT AVG(a1) FROM (SELECT sum(irterm.n) AS a1 FROM irterm GROUP BY irterm.item_id); Thank you ...

how to define generic variables in Python (syntax question)

Hello, With Python it is easy to declare something like self.x = "something" print self.x #outputs "something" I want to have something like this: param["key"] = "x" self.param["key"] = "something" #here I actually want to access this "self" parameter as below with its value defined above print self.x #supposed to output "something"...

Python: Appending to a text file

Possible Duplicates: Confused with appending to text file How can I write to the textfile with while? text_file = open("write_it.txt", "a") while 1: word = raw_input("Please add to a text file: ") if not word: break text_file.write(word) text_file.close() This code adds to the text file without spaces,...

How about having a SingletonModel in Django?

I'm making a very simple website in Django. On one of the pages there is a vertical ticker box. I need to give the client a way to edit the contents of the ticker box as an HTMLField. The first way that came to mind was to make a model Ticker which will have only one instance. Then I thought, instead of making sure manually that only on...

Should pre-commit tests use a big data set and fail if queries take too long, or use a small test database?

I am developing some Python modules that use a mysql database to insert some data and produce various types of report. I'm doing test driven development and so far I run: some CREATE / UPDATE / DELETE tests against a temporary database that is thrown away at the end of each test case, and some report generation tests doing exclusively...

Regex divide with upper-case

Hi, I would like to replace strings like 'HDMWhoSomeThing' to 'HDM Who Some Thing' with regex. So I would like to extract words which starts with an upper-case letter or consist of upper-case letters only. Notice that in the string 'HDMWho' the last upper-case letter is in the fact the first letter of the word Who - and should not be i...

Overwrite auto_now for unittest

I've defined some timestamps for events in the database as auto_now_add, as the information should be stored with it's timestamp the same time the event is stored. The description of the events is something like class NewEvent(models.Model): ''' Individual event ''' name = models.CharField(max_length=100) quantity =...

Pythonic Way to reverse nested dictionaries

I have a nested dictionary of people and item ratings, with people as the key. people may or may not share items. Example: { 'Bob' : {'item1':3, 'item2':8, 'item3':6}, 'Jim' : {'item1':6, 'item4':7}, 'Amy' : {'item1':6,'item2':5,'item3':9,'item4':2} } I'm looking for the simplest way to flip these relations, and have a new nested d...

Python: Visualisation of waves

Hello. I want to programm an easy visualisation of wave propagation. I tried this with visual python (VPython) but the programm is very slow. I want to use a 2-D visualisation now. Which module could you recommend? Tkinter? Matplotlib? For the computation i use numpy/scipy because it is fast. Thanks in advance. EDIT: Do you think ma...

pthread with callback to python VM

Let's say I have a python script which loads a shared library (SL) through ctypes. The SL sets up a pthread T1 The python script configures callbacks through the SL i.e. python script calls functions from the SL with references to python callables Now, let's say T1 calls a "callback" function, are the following assumptions true: ...

problem with editing labels in wx list control

hello do you guys have any idea how to edit the the labels in the second column in a wx.ListCtrl here is the code that i used to create that list .. Note that the first column is the only editable one . how can i make the other one editable too? self.lCUsers=wx.ListCtrl(self,style=wx.LC_EDIT_LABELS | wx.LC_REPORT |wx.LC_VRULES | wx....

Python: Can't use the command python

I want to install summon-module on windows 7. I tried python setup.py install but cmd doesn't know the command "python". I also set the path correctly. What is the problem? Thanks in advance. ...

SocketServer.ThreadingTCPServer - Cannot bind to address after program restart

As a follow-up to cannot-bind-to-address-after-socket-program-crashes, I was receiving this error after my program was restarted: socket.error: [Errno 98] Address already in use In this particular case, instead of using a socket directly, the program is starting its own threaded TCP server: httpd = SocketServer.ThreadingTCPServer(...

Why User model inheritance doesn't work properly?

I'm trying to use a User model inheritance in my django application. Model looks like this: from django.contrib.auth.models import User, UserManager class MyUser(User): ICQ = models.CharField(max_length=9) objects = UserManager() and authentication backend looks like this: import sys from django.db import models from django...

Reading binary file in python

Hi All, I wrote a python script to create a binary file of integers. import struct pos = [7623, 3015, 3231, 3829] inh = open('test.bin', 'wb') for e in pos: inh.write(struct.pack('i', e)) inh.close() It worked well, then I tried to read the 'test.bin' file using the below code. import struct inh = open('test.bin', ...

Where to put Python files to be redirected to by urls.py in Django?

Where do I put python files to be redirected to by urls.py in Django? The tutorial showed something like this: urlpatterns = patterns('', (r'^polls/$', 'mysite.polls.views.index'), Where do I set up pages to be easily linked as something.something.page like this? I am currently just trying to drop straight .py files in random...

Why does django not do for the User model the same as it does for the userprofile model?

Why doesn't django just have the model to use for User configured in the settings file? The requirements on the model specified would be that it contain a certain set of fields. Is there a reason why it couldn't be done this way? ...