I've written an auction system in Django. I want to write unit tests but the application is time sensitive (e.g. the amount advertisers are charged is a function of how long their ad has been active on a website). What's a good approach for testing this type of application?
Here's one possible solution: a DateFactory class which provi...
I need to check if some number of years have been since some date. Currently I've got timedelta from datetime module and I don't know how to convert it to years.
...
Trying to understand S3...How do you limit access to a file you upload to S3? For example, from a web application, each user has files they can upload, but how do you limit access so only that user has access to that file? It seems like the query string authentication requires an expiration date and that won't work for me, is there ano...
I was looking for a way to print a string backwards, and after a quick search on google, I found this method:
Suppose 'a' is a string variable. This will return the 'a' string backwards:
a[::-1]
Can anyone explain how that works?
...
What is the proper way to compare 2 times in Python in order to speed test a section of code? I tried reading the API docs. I'm not sure I understand the timedelta thing.
So far I have this code:
from datetime import datetime
tstart = datetime.now()
print t1
# code to speed test
tend = datetime.now()
print t2
# what am I missing?
# ...
How do I make a python regex like "(.*)" such that, given "a (b) c (d) e" python matches "b" instead of "b) c (d"?
I know that I can use "[^)]" instead of ".", but I'm looking for a more general solution that keeps my regex a little cleaner. Is there any way to tell python "hey, match this as soon as possible"?
...
Problem: I need to output the TOP X Contributors determined by the amount of messages posted.
Data: I have a collection of the messages posted. This is not a Database/SQL question by the sample query below just give an overview of the code.
tweetsSQL = db.GqlQuery("SELECT * FROM TweetModel ORDER BY date_created DESC")
My Model:
clas...
Is there a way to have mod_wsgi reload all modules (maybe in a particular directory) on each load?
While working on the code, it's very annoying to restart apache every time something is changed. The only option I've found so far is to put modname = reload(modname) below every import.. but that's also really annoying since it means I'm ...
I ask this for deployable reasons. As in, if I write a solution in python, I feel bound to write to 2.x due to the lack of adoption of python 3. This is a major daily concern of mine, and I want to figure out what's going on.
For many of the python-based questions here, people are giving solutions that simply do not work in python 3.x.
...
In the django.contrib.auth middleware
I see the code:
class AuthenticationMiddleware(object):
def process_request(self, request):
assert hasattr(request, 'session'), "requires session middleware"
request.__class__.user = LazyUser()
return None
Please avdise me why such a form
request._ class _.user = L...
Duplicate of: http://stackoverflow.com/questions/774925/detect-when-users-take-screenshots-of-my-program
There are various ways to take screenshots of a running application in Windows. However, I hear that an application can be tailored such that it can notice when a screenshot is being taken of it, through some windows event handlers p...
I'm trying to overwrite a __init__ method, but when I call the super method the attributes created in that method are not available.
I can see that it's not an inheritance problem since class B still has the attributes available.
I think the code sample will explain it better :-)
Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4...
Do you know a tool for creating nice html reports for pyunit?
...
Can you elaborate on the current state of "blocks" (in the Ruby sense) in Python?
What are the language constructs that exist in python? How do they compare to other languages (like Ruby, Smalltalk, [insert more])? Or does python lack of such constructs?
I have so far understood the lambda thing; it is only one-line, but maybe it comes...
I updated my python version on windows 2003 server from 2.4 to 2.5.
In 2.4 I could import a file "sub1.py" from a subdirectory c:\application\subdir\ like this:
import sub1
as long as the calling script main.py that lives in c:\application was started like this:
c:\application\subdir>python ..\main.py
But in 2.5 it no longer works...
I need to create ZIP archives on demand, using either Python zipfile module or unix command line utilities.
Resources to be zipped are often > 1GB and not necessarily compression-friendly.
How do I efficiently estimate its creation time / size?
...
I want to know how much time an import takes for both built-in as well as user defined modules.
...
Last couple of days, I have refrained myself from master's studies and have been focusing on this (seemingly simple) puzzle:
There is this 10*10 grid which constitutes a square of 100 available places to go. The aim is to start from a corner and traverse through all the places with respect to some simple "traverse rules" and reach n...
As a follow-up to this question, I have a new question:
What is happening internally in os.remove(module_name) and del sys.modules["module_name"]?
I need an urgent help for this.Please help me out.
...
In Perl, it's often nice to be able to assign an object, but specify some fall-back value if the variable being assigned from is 'undef'. For instance:
my $x = undef;
my $y = 2;
my $a = $x || $y;
After this,
$a == 2
Is there a concise way to achieve this in Python if the value x is None, or would a full-on ...
if x is not None
...