I'm trying to understand threading better. If I create a program that allows people to upload a photo and then I create a new process to resize the image in a hundred ways (taking 5 seconds or longer), and the main program returns a response HTML page to the user saying "Thanks. You're done!", can the other process still be working at th...
Iterating over a queryset, like so:
class Book(models.Model):
# <snip some other stuff>
activity = models.PositiveIntegerField(default=0)
views = models.PositiveIntegerField(default=0)
def calculate_statistics():
self.activity = book.views * 4
book.save()
def cron_job_calculate_all_book_statistics():
...
I am attempting to bundle up a Python application using py2exe 0.6.9 and Python 2.6.4 on Windows. While the executable runs just fine on the system I used to build it, it fails when I attempt to run it on another system:
C:\Documents and Settings\Administrator\Desktop\dist>.\backend.exe install
Traceback (most recent call last):
File...
Let's say I have a 2D Numpy array:
>>> a = np.random.random((4,6))
and I want to add a 1D array to each row:
>>> c = np.random.random((6,))
>>> a + c
This works. Now if I try adding a 1D array to each column, I get an error:
>>> b = np.random.random((4,))
>>> a + b
Traceback (most recent call last):
File "<stdin>", line 1, in <m...
I have been using lxml to create the xml of rss feed. But I am having trouble with the tags and cant really figure out how to to add a dynamic number of elements. Given that lxml seems to just have functions as parameters of functions, I cant seem to figure out how to loop for a dynamic number of items without remaking the entire pa...
Is it possible to load a django template tag/filter to use as a function in one of my template tags?
I'm trying to load up some of the django.contrib.humanize filters so I can apply them to the results of some of my custom template tags. I can't seem to import them at all, and I don't want to have to rewrite any of that code.
...
Im currently trying to learn Networking with Python asyncore and pyqt4.
I coded a small server, which basically listens on some port, and resends all messages it recieves to the sender.
Since both qts QApplication.exec_() and asyncore.loop() are functions which never return i could not start them both in one thread, so i stared asyncor...
Is there a more concise, efficient or simply pythonic way to do the following?
def product(list):
p = 1
for i in list:
p *= i
return p
EDIT:
I actually find that this is marginally faster than using operator.mul:
from operator import mul
# from functools import reduce # python3 compatibility
def with_lambda(list...
I have a batch file which calls .Net solution to build the project. On the dos console window, the warning and error will be in different color, green and red, looks nice. When the batch file called from Python, no color at all, all in a single color. Is it possible to get the same colorful result with python? my call to the batch file i...
Heres my code:
data = [
[5,3,0,0,7,0,0,0,0],
[6,0,0,1,9,5,0,0,0],
[0,9,8,0,0,0,0,6,0],
[8,0,0,0,6,0,0,0,3],
[4,0,0,8,0,3,0,0,1],
[7,0,0,0,2,0,0,0,6],
[0,6,0,0,0,0,2,8,0],
[0,0,0,4,1,9,0,0,5],
[0,0,0,0,8,0,0,7,9]
]
element = 4
x = 0
y = 0
data[x][y] = element
I want to replace the element at coordinates 0,0 but when i print data i...
Does anybody know how Python manage internally int and long types?
Does it choose the right type dynamically?
What is the limit for an int?
I am using Python 2.6, Is is different with previous versions?
How should I understand the code below?
>>> print type(65535)
<type 'int'>
>>> print type(65536)
<type 'int'>
>>> print type(6553...
I have 2 models with a 1-1 relation (essentially a resource pool). For the example code, I will simply use nuts and bolts. There will be many more nuts (available resources) than bolts (which will each require 1 nut). However, if a nut can only be assigned to one bolt.
The constraint is easy enough to set up with the unique=True name...
I'm a front end developer, and I've been trying to get a hang on using Jinja2 effectively. I want to tweak a current site so it has multiple base templates using inheritance, it fully uses block tags to substitute content and override it, and uses macros to support passing of arguments.
My base template contains this code (edited for si...
I've installed Django CMS (http://www.django-cms.org/) and it's almost perfect. I've been chatting on the IRC #django-cms group and it's been confirmed to me that I can't have access restricted to the pages I make in Django CMS to only a select few on the site side.
I know of the CMS_PERMISSIONS setting, but this seems to only restrict ...
Hi I have a list of Facebook Page urls
eg...
http://www.facebook.com/daftpunk
http://www.facebook.com/DavidGuetta
...
What's the best way to:
Check if these urls are actually for Facebook Pages and not Profiles
Collect details such as # of fans from these Pages
Help would be very much appreciated.
...
Hello,
So I am trying to use os.walk() to generate an XML representation of a directory structure. I seem to be getting a ton of duplicates. It properly places directories within each other and files in the right place for the first portion of the xml file; however, after it does it correctly it then continues traversing incorrectly. I a...
I want a shell that supports unicode in windows, powershell as it ships doesn't seem to.
Powershell V2 (win7 x64) :
PS C:\> powershell
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\> python
Python 2.6.2 (r262:71605, Apr 14 2009, 22:46:50) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copy...
I'm trying to help a colleague run SOATest (a web services client that makes testing SOAP services easy) on a WCF web service operation, and for "big" responses, we are seeing this error:
SOAP Message size it greater than allowed limit [SECURITY.MSGSIZE v 1.0]
This is perplexing, as the tool is actually able to get a response from the...
How can I find out how may character are there in a line before the end line in an interactive shell using python? (Usually 80)
...
In a system that accepts orders which have payments which have gateway transactions should the objects be like this:
class Order(object):
... Inside init ...
self.total_in_dollars = <Dollar Amount>
self.is_paid = <Boolean Value>
class Payment(object):
... Inside init ...
self.order = order_instan...