python

django template does not render complete context

Hello, I am using templates with django. I am having a problem where the Context is not being rendered. The meta_k is null. The meta_description is not. t = get_template('projects.html') html = t.render(Context({ 'completed': completed, 'current':current, 'description': sp.description, 'project_tit...

Confusion about django app's name

I learned Django following django book and the document. In the django book exmaple, the project is called mysite and there's an app called book inside this project. So in this case, the app is called "book". I've no problem with it. My confusion arises in front of reusable apps. Reusable apps usually reside outside the project. For exa...

Encrypting a Sqlite db file that will be bundled in a pyexe file.

I have been working on developing this analytical tool to help interpret and analyze a database that is bundled within the package. It is very important for us to secure the database in a way that can only be accessed with our software. What is the best way of achieving it in Python? I am aware that there may not be a definitive soluti...

Retrieving YAML parameters during runtime in App Engine (Python)

Is it possible to programmatically retrieve any of the YAML parameters during run-time? Are they stored in the environment somewhere? Good example would be to automatically find the application version and to add it as a comment in the landing HTML page. ...

How to map a tuple of data to a tuple of functions?

I have the following Python code: data = ['1', '4.6', 'txt'] funcs = [int, float, str] How to call every function with data in corresponding index as an argument to the function? Now I'm using the code: result = [] for i, func in enumerate(funcs): result.append(func(data[i])) map(funcs, data) don't work with tuple of function...

Python: a could be rounded to b in the general case.

As a part of some unit testing code that I'm writing, I wrote the following function. The purpose of which is to determine if 'a' could be rounded to 'b', regardless of how accurate 'a' or 'b' are. def couldRoundTo(a,b): """Can you round a to some number of digits, such that it equals b?""" roundEnd = len(str(b)) if a == b:...

Python: Why Lists do not have a find method?

I was trying to write an answer to this question and was quite surprised to find out that there is no find method for lists, lists have only the index method (strings have find and index). Can anyone tell me the rationale behind that? Why strings have both? ...

IndentationError: unindent does not match any outer indentation level

def LCS(word_list1, word_list2): m = len(word_list1) n = len(word_list2) print m print n C = [[0] * (n+1) for i in range(m+1)] # IndentationError: unindent does not match any outer indentation level print C i=0 j=0 for word in word_list1: j=0 for word in word_list2: i...

Python: how to use value stored in a variable to decide which class instance to initiate?

I'm building a Django site. I need to model many different product categories such as TV, laptops, women's apparel, men's shoes, etc. Since different product categories have different product attributes, each category has its own separate Model: TV, Laptop, WomensApparel, MensShoes, etc. And for each Model I created a ModelForm. Hence ...

Ruby/Python - generating and parsing C/C++ code

Hi, I need to generate C structs and arrays from data stored in a db table, and alternately parse similar info. I use both ruby and python for this task, and was wondering if anyone heard of a module/lib that handles this for either/both languages? I could do this on my own with some string processing, but wanted to check if there's a k...

Extending python Queue.PriorityQueue (worker priority, work package types)

Hi! I would like to extend the Queue.PriorityQueue described here: http://docs.python.org/library/queue.html#Queue.PriorityQueue The queue will hold work packages with a priority. Workers will get work packages and process them. I want to make the following additions: Workers have a priority too. When multiple workers are idle the on...

Python mechanize: read table element next to input

I'm using mechanize to fill out a form that has a series of rows. Each row is an <input type="checkbox"> followed by <td>name of the checkbox</td>. How do I read the name so I know whether to check the box? Thanks ...

sum of products for multiple lists in python

Trying to imitate Excel's SUMPRODUCT function: SUMPRODUCT(v1, v2, ..., vN) = v1[0]*v2[0]*...*vN[0] + v1[1]*v2[1]*...*vN[1] + ... + v1[n]*v2[n]*...*vN[n] where n is the number of elements in each vector. This is similar to dot product, but for multiple vectors. I read the very detailed discussion of the regular dot product, but I ...

python glade: window doesn't appear

I initially had a GladeXML object error. But I solved it after reading this post --> http://stackoverflow.com/questions/2668618/python-glade-could-not-create-gladexml-object I've tried both the solutions mentioned there. However the window still doesn't appear. ...

WSAEventSelect with FD_ACCEPT, recv returns WSAEWOULDBLOCK

I'm trying to setup a socket that won't block on accept(...), using the following code: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(("127.0.0.1", 1234)) event = win32event.CreateEvent(None, True, False, None) win32file.WSAEventSelect(sock.fileno(), event, win32file.FD_ACCEPT) sock.listen(5) rc = win32event.WaitFor...

Can Python + Qt combination produce a real time spectral analysis tool?

Hi I want to develop a tool that does the following things. take in a live voice recording produce a real time spectrogram show the time-domain signal output few values extracted from the spectral analysis All of these have to be kept updated in a window as the voice is recorded. I have worked with numpy. But I'm completely new to...

Python: How to remove /n from a list element?

I'm trying to get Python to a read line from a .txt file and write the elements of the first line into a list. The elements in the file were separated with a TAB so I used split("\t") to separate the elements. Because the .txt file has a lot of elements I saved the data found in each line into a separate list (data from the first lin...

How to call a static method of a class using method name and class name

Starting with a class like this: class FooClass(object): @staticmethod def static_method(x): print x normally, I would call the static method of the class with: FooClass.static_method('bar') Is it possible to invoke this static method having just the class name and the method name? class_name = 'FooClass' method_n...

Update status facebook using python

i'm trying the solve problem update status using facebook API with pyfacebook so i look at here http://stackoverflow.com/questions/1907662/update-facebook-pages-status-using-pyfacebook and i think doesn't work anymore well, finally i solve the problem #!/usr/bin/python import facebook # Replace these with your app's credentials api_key ...

pairwise traversal of a list or tuple

a = [5, 66, 7, 8, 9, ...] Is it possible to make an iteration instead of writing like this? a[1] - a[0] a[2] - a[1] a[3] - a[2] a[4] - a[3] ... Thank you! ...