What's wrong with this bit of python code using lambda?
Some python code that keeps throwing up an invalid syntax error: stat.sort(lambda x1, y1: 1 if x1.created_at < y1.created_at else -1) ...
Some python code that keeps throwing up an invalid syntax error: stat.sort(lambda x1, y1: 1 if x1.created_at < y1.created_at else -1) ...
Hi SO, This is probably a db design issue, but I couldn't figure out any better. Among several others, I have these models: class User(models.Model): name = models.CharField( max_length=40 ) # some fields omitted bands = models.ManyToManyField( Band ) and class Band(models.Model): creator = models.ForeignKey( User ) # some...
Here'a an example: If I have these classses class Author(models.Model): name = models.CharField(max_length=45) class Book(models.Model): name = models.CharField(max_length=45) authors = models.ManyToManyField(Author) In the database I have one Author with the name "George" and another one with the name "Georfe". The last...
It seems that if I do not create a ModelForm from a model, and create a new object and save it, it will not respect the field's upload directory. How do I change the directory of a InMemoryUploadedFile so I can manually implement the upload dir? Because the InMemoryUploadedFile obj is just the filename, and I would like to add the uploa...
I wrote an application using Django 1.0. It works fine with the django test server. But when I tried to get it into a more likely production enviroment the Apache server fails to run the app. The server I use is WAMP2.0. I've been a PHP programmer for years now and I've been using WAMPServer since long ago. I installed the mod_wsgi.so an...
I'm running django 1.1rc. All of my code works correctly using django's built in development server; however, when I move it into production using Apache's mod_python, I get the following error on all of my views: Caught an exception while rendering: Reverse for '<django.contrib.auth.decorators._CheckLogin What might I look for that'...
I have a trivial example: def func1(): local_var = None def func(args): print args, print "local_var:", local_var local_var = "local" func("first") func("second") func1() I expect the output to be: first local_var: None second local_var: local However, my actual output is: first local...
I have text files with a lot of uniform rows that I'd like to load into a mysql database, but the files are not completely uniform. There are several rows at the beginning for some miscellaneous information, and there are timestamps about every 6 lines. "LOAD DATA INFILE" doesn't seem like the answer here because of my file format. It d...
I see that Google App Engine can host web applications that will return html, etc. But what about web services that communicate over http and accept / return xml? Does anyone know how this is being done in Goggle App Engine with Python or for that matter in Java (JAS-WX is not supported)? Any links o samples or articles is greatly appr...
Hello, I am trying to make a many to one relationship and want to be able to control it (add -remove etc) via the admin panel. So this is my model.py: from django.db import models class Office(models.Model): name = models.CharField(max_length=30) class Province(models.Model): numberPlate = models.IntegerField(primary_key=True...
I need to give user ability to enter a time in form hh:mm:ss (with appropriate validation of course). And standard function appuifw.query(u'Label', 'time') works almost fine except that it allows to enter only hours and minutes (hh:mm). So I want to look though its source and write my own that enhances it in the stated manner. I've foun...
I'm a python newbie, so sorry for the simple question. I'm trying to port a shell script to the much more readable python version. The original shell script starts several processes (utilities, monitors, etc.) in the background with "&". How can I achieve the same effect in python? I'd like these processes not to die when the python scr...
I have some python modules in a shared folder on a Windows machine. The file is \mtl12366150\test\mymodule.py os.path.exists tells me this path is valid. I appended to sys.path the folder \mtl12366150\test (and os.path.exists tells me this path is valid). When I try to import mymodule I get an error saying the module doesn't exist. ...
I'd like to build a function in Django that iterates over a set of objects in a queryset and does something based on the value of an arbitrary attribute. The type of the objects is fixed; let's say they're guaranteed to be from the Comment model, which looks like this: class Comment(models.Model): name = models.CharField(max_length=...
Hi all What I want to achieve is to get a website screenshot from any website in python. Env: Linux ...
I've got a string that I'm trying to split into chunks based on blank lines. Given a string s, I thought I could do this: re.split('(?m)^\s*$', s) This works in some cases: >>> s = 'foo\nbar\n \nbaz' >>> re.split('(?m)^\s*$', s) ['foo\nbar\n', '\nbaz'] But it doesn't work if the line is completely empty: >>> s = 'foo\nbar\n\nbaz'...
How can write tag "copyblock" for Django templates? For such a functional:: <title> {% block title %} some title... {% endblock %} </title> <h1>{% copyblock title %}</h1> Thx! ...
How do I have actions occur when a field gets changed in one of my models? In this particular case, I have this model: class Game(models.Model): STATE_CHOICES = ( ('S', 'Setup'), ('A', 'Active'), ('P', 'Paused'), ('F', 'Finished') ) name = models.CharField(max_length=100) owner = mode...
I need to convert any html entity into its ASCII equivalent using Python. My use case is that I am cleaning up some HTML used to build emails to create plaintext emails from the HTML. Right now, I only really know how to create unicode from these entities when I need ASCII (I think) so that the plaintext email reads correctly with thin...
It seems that this is specific to windows, here is an example that reproduces the effect: import wx def makegrid(window): grid = wx.GridSizer(24, 10, 1, 1) window.SetSizer(grid) for i in xrange(240): cell = wx.Panel(window) cell.SetBackgroundColour(wx.Color(i, i, i)) grid.Add(cell, flag=wx.EXPAND) ...