python

Rake:task equivalent in Django

I have a django application where i'll like to have a script that i'll run once a day to validate the models in the database, and delete some objects. How cand i make it ? I want something equivalent to rake:task in rails. ...

generating equation representations in python/on the web

Is it possible to take something like x^2+5 and have it generate this: http://imgur.com/Muq2X.gif I'll be using Python so anything based in Python would work, but I'm open to other solutions such as latex output. ...

Django: ImportError: No module named ?z?

Hi I am trying to deploy a django app with uwsgi. I keep getting Import Errors that look like this: ImportError: No module named ?z? -or- ImportError: No module named ?j? -or- ImportError: No module named `?6 So basically the output of the module seems like gibberish and I am unable to figure out the problem. Does anybody have an i...

Binding a list of strings to an IN clause

Consider this (using apsw here): s = ["A", "B", "C"] c.execute("SELECT foo.y FROM foo WHERE foo.x in (?)", (s, )) This doesn't work, because a binding parameter cannot be a list. I want to bind a list of strings to ?. I know how to build the appropriate query-string manually, but I wonder if there is a way to do this with bindings. ...

nosetests --cover-html does not generate html docs

I have installed nose for python 2.6 and it works fine , but I was trying use the --cover-html option to generate a html report. I typed the following command from the commandline nosetests --cover-html and nothing happend , it ran the tests but did not generate the html. Am i missing something ? I have python 2.6 , nose 0.11.3 , runni...

how to find if the file is a link file, and find the path of the target file (actual file pointed by the link file)

how to find if the file is a link file, and find the path of the target file (actual file pointed by the link file) ...

Unknown Python Syntax

Hi I've found the following syntax in a python file: units = ( (100, 1 << 30, _('%.0f GB')), (10, 1 << 30, _('%.1f GB')), (1, 1 << 30, _('%.2f GB')), (100, 1 << 20, _('%.0f MB')), (10, 1 << 20, _('%.1f MB')), (1, 1 << 20, _('%.2f MB')), (100, 1 << 10, _('%.0f KB')), (10, ...

How do I extract the names from a simple function?

I've got this piece of code: import inspect import ast def func(foo): return foo.bar - foo.baz s = inspect.getsource(func) xx = ast.parse(s) class VisitCalls(ast.NodeVisitor): def visit_Name(self, what): if what.id == 'foo': print ast.dump(what.ctx) VisitCalls().visit(xx) From function 'func' I'd like t...

Writing a 'print' function in Python

I want to create a function that works like the build-in print function in Python: print 'test', i, 'started' So a call like this should work: log('test', i, 'started) The log function should call the logging.info() function (from the Python logging module). How can I create such a function? This is my first try: import logging ...

Numpy transpose multiplication problem

I tried to find the eigenvalues of a matrix multiplied by its transpose but I couldn't do it using numpy. testmatrix = numpy.array([[1,2],[3,4],[5,6],[7,8]]) prod = testmatrix * testmatrix.T print eig(prod) I expected to get the following result for the product: 5 11 17 23 11 25 39 53 17 39 61 83 23 53 ...

Vim's omnicompletion fails with "from" imports in Python

Omnicompletion for Python seems to fail when there is a "from" import instead of a normal one. For example, if I have these two files: Test.py: class Test: def method(self): pass main.py: from Test import Test class Test2: def __init__(self): self.x = Test() If I try to activate omnicompletion for self.x......

Case-insensitive query that supports multiple search words

I'm trying to perform a case-insensitive query. I would generally use __icontains, but since it doesn't support the .split() method, I'm stuck to using __in instead: def search(request): query = request.GET.get('q', '') query = query.lower() product_results = [] category_results = [] if query: product_result...

numpy arrays type conversion in C

Hi, I would like to convert the numpy double array to numpy float array in C(Swig). I am trying to use PyObject *object = PyArray_FROM_OT(input,NPY_FLOAT) or PyObject *object = PyArray_FROMANY(input,NPY_FLOAT,0,0,NPY_DEFAULT) or PyObject *object = PyArray_FromObject(input,NPY_FLOAT,0,0) or PyObject *object = PyArray_Contiguou...

form.cleaned_data as a dictionary

Why when I call a function like this : function(request, **form.cleaned_data) I can send form's data as a dictionary, but when I try doing like this : data = **form.cleaned_data I'm getting error ? ...

keep alive thread in PyQt4

Hey, I have a PyQt4 application, which at some point packs a big file using the tarfile module. Since the tarfile module does not implement any callback strategy, it blocks and the Qt GUI gets unresponsive. I want the GUI to keep updating during that time. The only possibility is a separate thread. So, I start a QThread. What do I have...

Parse Raw HTTP in Python

I am looking for a library or function call in python or an associated library that would let me feed in a raw stream of text data representing an HTTP req/res and that would spit out that information is some sort of meaningful form like a dictionary or list. I do not want to use some built in class or create a bunch of new objects, in m...

Lines of Code in Eclipse PyDev Projects

I'm wondering if anyone has had any luck using the Eclipse Metrics Plugin with Projects that are not in Java (specifically I'm trying to generate code metrics for a couple of PyDev Projects). I've read through the walk-through for the Metrics project but it indicates that I should be in the Java Perspective before accessing the Properti...

Elegant parsing of this? "a,b,c",d,"e,f"

I'm looking to parse these kinds of strings into lists in Python: "a,b,c",d,"e,f" => ['a','b','c'] , ['d'] , ['e','f'] "a,b,c",d,e => ['a','b','c'] , ['d'] , ['e'] a,b,"c,d,e,f" => ['a'],['b'],['c','d','e','f'] a,"b,c,d",{x(a,b,c-d)} => ['a'],['b','c','d'],[('x',['a'],['b'],['c-d'])] It nests, so I suspe...

What is the fastest way to initialize an integer array in python?

Say I wanted to create an array (NOT list) of 1,000,000 twos in python, like this: array = [2, 2, 2, ...... , 2] What would be a fast but simple way of doing it? ...

How to retrieve a time stamp with the right formatting from a sql database using python

I want to retrieve a time stamp from a sql database with proper formatting. This is the partial code I am using: import MySQLdb def connectDB(self): global cursor DATABASE = MySQLdb.connect( host = self.HOST, user = self.USER, passwd = self.PASS, db = self.DB, port = self.P...