python

Exception Value field is blank when throwing custom exceptions in django

I have custom exceptions in my django project that look like this: class CustomFooError(Exception): def __init__(self, msg="Something went wrong with Foo."): self.msg = msg def __str__(self): return repr(self.msg) At various points in my code I will raise exceptions like this: raise CustomFooError("Things a...

Calling a python method from C/C++, and extracting its return value.

I'd like to call a custom function that is defined in a python module from C. I have some preliminary code to do that, but it just prints the output to stdout. mytest.py import math def myabs(x): return math.fabs(x) test.cpp #include <Python.h> int main() { Py_Initialize(); PyRun_SimpleString("import sys; sys.path.appe...

how to imitate a link click in QTextBrowser

Actualy, i have different tabs. what I wanted to achieve is, - user clicked a link from tab 1 - and it will immediately display QTextBrowser in tab 2, at the html anchor i set. Is there a way of doing this? I've managed to switch tab by using tabWidget.setCurrentWidget() now the question is, how to set the focus to the desired html an...

return SQL table as JSON in python

I'm playing around with a little web app in web.py, and am setting up a url to return a JSON object. What's the best way to convert a SQL table to JSON using python? ...

Python: How to Sort SQL statements in a text file?

The output below is from Oracle; where it generates "create table" statements using a supplied package. I feed them into the python diff tool HtmlDiff which uses difflib under the covers. Each table is followed by a number of "alter table add constraint" commands that add the various constraints. The problem is that there is no explicit...

Embedding test code or data within doctest strings

I'd like to have several of the doctests in a file share test data and/or functions. Is there a way to do this without locating them in an external file or within the code of the file being tested? update """This is the docstring for the module ``fish``. I've discovered that I can access the module under test from within the doctes...

Convert string timestamp (with timezone offset) to local time. . ? python

I am trying to convert a string timestamp into a proper datetime object. The problem I am having is that there is a timezone offset and everything I am doing doesn't seem to work. Ultimately I want to convert the string timestamp into a datetime object in my machines timezone. # string timestamp date = u"Fri, 16 Jul 2010 07:08:23 ...

How to broadcast a signal in Qt4

I'm wanting a paradigm in a Qt4 (PyQt4) program where a component is able to respond to a signal without knowing anything about where it is coming from. My intial reading suggests that I have to explicitly connect signals to slots. But what I want is for any of a number of components to be able to send a signal, and for it to be proce...

Import multiple files from a folder in Python

I have a folder in my Application directory called Commands.folder. What I want to do is import all the modules in that folder, regardless of the name, into the python file that imports. How can I do this? ...

Google AppEngine Indexing Delay

Am trying to deploy a app to Google AppEngine. But the DataStore index building seems to take forever. The contents of my index.yaml indexes: # AUTOGENERATED # This index.yaml is automatically updated whenever the dev_appserver # detects that a new type of query is run. If you want to manage the # index.yaml file manually, remove th...

Django-models. Complex request to database.

I need to make special request to database through django. For example: class Model(models.Model): name=models.CharField() date=models.DateTimeField() other=models.TextField() How do I ask for row which name containe word 'Hello' (it shoul ignor register of first letter) end it is must be in diapason of date, for exam...

Cron and virtualenv

I am trying to run a Django management command from cron. I am using virtualenv to keep my project sandboxed. I have seen examples here and elsewhere that show running management commands from within virtualenv's like: 0 3 * * * source /home/user/project/env/bin/activate && /home/user/project/manage.py command arg However, even thoug...

Reading from a plain text file

Say I have the following in a text file: car apple bike book How can I read it and put them into a dictionary or a list? ...

Issue with PPT conversion using python-Django

I was just trying to convert a PPT using the following URL http://code.google.com/p/qifei/wiki/PDFConverter python code I could see the same thing happening with the command line option too python documentconverter.py /home/rajeev/Desktop/Downloads/Industry2.ppt /home/rajeev/Desktop/test.pdf It appears that the image overlaps on some ...

Setting up Python on Apache/Windows; IDE question

I am finally learning Python after putting it off for a long time. I am setting it up on Apache (XAMPP), which version of mod_python should I choose? If I get mod_python-3.3.1.win32-py2.5-Apache2.2.exe, does that mean I have to download Python 2.5 from here? EDIT: I'll use this primarily for web development. Which IDE should I use? I l...

How to insert dynamic string in wxpython html window? (wx.html.htmlwindow)

I am making a html window in wxpython and want to print it. Before that I need to enter user input (such as his name or such things ) in the html page. How to do that nicely? Thanks in advance, ...

Why does this keep going around in a never ending loop??

def get_houseid_list(): """Returns a list of all house ids from db""" print 'Building list of all HouseIDs...' houseid_list = [] houseids = session.query(Episode.HouseID).all() for i in houseids: houseid_list.append(i[0]) return houseid_list def walkDir(top, ignore=[]): """Returns a complete list of ...

SingPath Python Help - cosine problem

Any help? I have the following: import math def cosine (a): x = (a * math.pi) / 180 return math.cos(x) The problem: Create a function that calculates the cosine of an angle (in degrees). The math module contains a function math.cos that uses radians to calculate the cosine. You will need to convert the angle to radians ...

Download a spreadsheet from Google Docs using Python

Can you produce a Python example of how to download a Google Docs spreadsheet given its key and worksheet ID (gid)? I can't. I've scoured versions 1, 2 and 3 of the API. I'm having no luck, I can't figure out their compilcated ATOM-like feeds API, the gdata.docs.service.DocsService._DownloadFile private method says that I'm unauthorize...

how to implement an implement Buffer for socket send/recv ?

i need a Buffer class for socket send/recv : 1.memmove/memcpy as less as possible 2.object creation as less as possible 3.the class user need no worry for the extend issue is there anything liks that in the standard library ? or how can i make one ? i wrote this but i can't use it for socket, because the buffer(from the standard library...