Django – Rebuild a query string without one of the variables

I have a Django view that processes a GET request. I want to rebuild the query string to include all variables except for one. I was initially using list comprehension: >>> from django.http import QueryDict >>> q = QueryDict(‘a=2&b=4&c=test’) // <— make believe this is request.GET >>> z = QueryDict(”).copy() >>> z.update(dict([x for x in … Read more

How to use: while not in

I’m trying to check if a list has no member as boolean operator AND, OR, NOT. I use: while (‘AND’ and ‘OR’ and ‘NOT’) not in list: print ‘No boolean operator’ However, when my input is: a1 c2 OR c3 AND, it prints ‘No boolean operator’, which means this list is considered no boolean operator … Read more

HTML5 video element non-seekable when using Django development server

I’ve got a Django app serving a webpage with an HTML5 element. There’s a wierd “feature”, turning the video element to be non-seekable: video.seekable returns a timeRanges object with length=0, whereas it should be length=1. This means I can’t edit the video. JavaScript can’t do anything either. The thing is, when I upload the problematic … Read more

python regular expression replacing part of a matched string

i got an string that might look like this “myFunc(‘element’,’node’,’elementVersion’,’ext’,12,0,0)” i’m currently checking for validity using, which works fine myFunc\((.+?)\,(.+?)\,(.+?)\,(.+?)\,(.+?)\,(.+?)\,(.+?)\) now i’d like to replace whatever string is at the 3rd parameter.unfortunately i cant just use a stringreplace on whatever sub-string on the 3rd position since the same ‘sub-string’ could be anywhere else in that … Read more

MemoryStream analog in Python

Does some analog of C# MemoryStream exist in Python (that could allow me to write binary data from some source direct into memory)? And how would I go about using it? StringIO is one possibility: http://docs.python.org/library/stringio.html This module implements a file-like class, StringIO, that reads and writes a string buffer (also known as memory files). … Read more

psycopg2.InternalError: how can I get more useful information?

I’m running this command in a Python script: try: print sql_string cursor.execute(sql_string) except: print sys.exc_info() and getting: (<class ‘psycopg2.InternalError’>, InternalError(‘current transaction is aborted, commands ignored until end of transaction block\n’,), <traceback object at 0x1010054d0>) However if I try the sql_string from the psql command line, it works just fine. I know the script is connecting … Read more