python

django datefield filter

I'd like to use an object filter similar to the following Shipment.objects.filter(date__gte=datetime.date(2005,1,1)) However there doesn't seem to be support for comparison operators on datetime objects. Is there a method I'm unaware of or should I look into writing a custom filter. ...

How to write the output of this code to HTML file?

from HTMLParser import HTMLParser from urllib import urlopen class Spider(HTMLParser): def __init__(self, url): HTMLParser.__init__(self) req = urlopen(url) self.feed(req.read()) def handle_starttag(self, tag, attrs): if tag == 'a' and attrs: ...

Finding the MAC address of the sender of a multicast UDP message in Python?

I have some code that listens for "announcements" via UDP multicast. I can get the IP address of the sender, but what I really need is the MAC address of the sender (since the IP address can and will change). Is there an easy way to do this in Python? A code snippet is included for reference, but likely unnecessary. sock = socket.sock...

403 error in Google App Engine with staticdir

Hi, For some reason I can't get static_dir to work. In my app.ymal I have: - url: /ui static_dir: ui - url: /dump static_dir: dump Loading static files from /ui works (i.e /ui/images/logo.png). But when I try to access something from /dumo I just get: INFO 2009-11-12 14:03:55,497 dev_appserver.py:3034] "GET /dump/ka...

Which CAS implementation to use in django?

Which CAS implementation should i use to enable CAS single sign on to my django app (trusing a specified CAS server, I'm not interested in creating a CAS provider) ? What I can find are the following: http://code.google.com/p/django-cas/ http://github.com/Nitron/django-cas-consumer I've used django-cas before, and it seems to work b...

Dynamically hiding ToscaWidgets fields

I am trying to dynamically hide fields depending on some data. With dynamically, I don't mean JavaScript, but server-side: class EditUserForm(TableForm): class fields(WidgetsList): user_id = HiddenField() user_name = TextField(label_text=u"User Name") reject_member = SubmitButton(default=u"Reject Membership")...

Twisted/tkinter program crashes on exit.

I am running an app using twisted and tkinter that sends the result to the server, waits for the server to send back a confirmation, and then exits. So, the function I use to exit is this: def term(): '''To end the program''' reactor.stop() root.quit() root.destroy() This is then set in the factory and called in the da...

Is the first entry in sys.path supposed to represent the current working directory?

I had always assumed that the first entry in sys.path by default was the current working directory. But as it turns out, on my system the first entry is the path on which the script resides. So if I'm executing a script that's in /usr/bin from /some/directory, the first entry in sys.path is /usr/bin. Is something misconfigured on my s...

Multiple programs using the same UDP port? Possible?

I currently have a small Python script that I'm using to spawn multiple executables, (voice chat servers), and in the next version of the software, the servers have the ability to receive heartbeat signals on the UDP port. (There will be possibly thousands of servers on one machine, ranging from ports 7878 and up) My problem is that the...

Find (and keep) duplicates of sublist in python

Hi, I have a list of lists (sublist) that contains numbers and I only want to keep those exists in all (sub)lists. Example: x = [ [1, 2, 3, 4], [3, 4, 6, 7], [2, 3, 4, 6, 7]] output => [3, 4] How can I do this? ...

python function slowing down for no apparent reason

I have a python function defined as follows which i use to delete from list1 the items which are already in list2. I am using python 2.6.2 on windows XP def compareLists(list1, list2): curIndex = 0 while curIndex < len(list1): if list1[curIndex] in list2: list1.pop(curIndex) else: curIndex...

aspect-oriented techniques in python?

So I have an interesting problem in Python, that could possibly be solved with aspect-oriented techniques. Here's the situation: I have a bunch of modules, each of which has a bunch of functions. I have an executable that calls some set of functions in those modules. When the executable calls one of those functions, I want a log statem...

How to split the file content by space and end-of-line character?

When I do the following list comprehension I end up with nested lists: channel_values = [x for x in [ y.split(' ') for y in open(channel_output_file).readlines() ] if x and not x == '\n'] Basically I have a file composed of this: 7656 7653 7649 7646 7643 7640 7637 7634 7631 7627 7624 7621 7618 7615 8626 8623 8620 8617 8614 8610 8...

Referencing classes in Python

Hi all I'm having a spot of bother with Python (using for app engine). I'm fairly new to it (more used to Java), but I had been enjoying....until now. The following won't work! class SomeClass(db.Model): item = db.ReferenceProperty(AnotherClass) class AnotherClass(db.Model): otherItem = db.ReferenceProperty(SomeClass) As far as...

Django: Exclude on a many-to-many relationship through a third table

I have a problem making "exclude" querys on tables which have a many-to-many relationship through a third table. I have a table with projects, a table with people and a relationsship table with the flags "is_green, is_yellow, is_red", like: class Project(models.Model): ... class Person(models.Model): projects = models.ManyToMan...

How could I print out the nth letter of the alphabet in Python?

ASCII math doesn't seem to work in Python: 'a' + 5 DOESN'T WORK How could I quickly print out the nth letter of the alphabet without having an array of letters? My naive solution is this: letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',...

Just curious about result from NumPy function!

I have used NumPy for my Master thesis. I've converted parts of the code from MATLAB code, but I have doubts in NumPy/Python when I reference: m = numpy.ones((10,2)) m[:,0] which returns: array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]) and when I ref to: m[:,0:1] it returns: array([[ 1.], [ 1.], [ 1.], ...

Dynamically Display field values in Django template (object.x)

Hi Guys, I am currently working on an app that uses custom annotate querysets. Currently i have 2 urls setup, but i would need one for each field that the users would like to summarize data for. This could be configured manually, but it would violate DRY! I would basically have +-8 urls that basically do the same thing. So here is wha...

Deleting duplicate dictionaries in a list in python

I have two lists of dictionaries list1 = [ {..}, {..}, ..] list2 = [ {..}, {..}, ..] I want to remove the dictionaries in list1 which are in list2. I had a similar problem where I had a list of lists instead of a dictionary and it is solved here http://stackoverflow.com/questions/1723494/python-function-slowing-down-for-no-apparent-r...

How can I use PHP's gettext in conjunction with python's gettext?

I have an app that I'm migrating portions of to Django, but python and php have a different string format. E.g. "Hello %1s" in php vs. "Hello {0}" or "Hello {name}" in python. We'll be maintaining both apps for a while, but is there a way to use the python format in PHP or vice versa? ...