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...
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...
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...
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?
...
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...
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...
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 ...
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...
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?
...
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...
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...
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...
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?
...
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 ...
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...
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,
...
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 ...
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 ...
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...
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...