Example Problem:
Entities:
User contains name and a list of friends (User references)
Blog Post contains title, content, date and Writer (User)
Requirement:
I want a page that displays the title and a link to the blog of the last 10 posts by a user's friend. I would also like the ability to keep paging back through older entries.
...
Client-side code submits an object (in the POST request body) or query string (if using GET method) via ajax request to a python cgi script. Please note that the object/query string parameters are not coming from a
<form> or <isindex>.
How can I retrieve these parameters from within the server-side python script using standard library...
Hi All,
On Windows I am able to sent SCSI passthrough to devices using win32file.DeviceIOControl(..), on UN*X I can do it using fnctl.ioctl(...).
I have been searching for something equivalent in OSX that would allow me to send the IOCTL commands using only native python.
I would to send commands to hard drives specifically, not USB d...
Variations of this question have been asked, but I'm still unable to get my stylesheets to load correctly when my templates are rendered.
I'm attempting to serve static media from the Django process during development - which is strongly discouraged in production, I'm aware. I'll post my configuration and my template, and hopefully some...
If I have a python script that requires at least a particular
version of python, what is the correct way to fail gracefully
when an earlier version of python is used to launch the script?
How do I get control early enough to issue an error message
and exit?
For example, I have a program that uses the ternery operator (new in 2.5) and "...
What are the possible return values from the following command?
import sys
print sys.platform
I know there is a lot of possibilities, so I'm mainly interested in the "main" ones (Windows, Linux, Mac OS)
...
Using Python 2.5, I have some text in stored in a unicode object:
Dinis e Isabel, uma difı´cil relac¸a˜o
conjugal e polı´tica
This appears to be decomposed Unicode. Is there a generic way in Python to reverse the decomposition, so I end up with:
Dinis e Isabel, uma difícil relação
conjugal e política
...
I want to write a piece of software which is essentially a regex data scrubber. I am going to take a contact list in CSV and remove all non-word characters and such from the person's name.
This project has Perl written all over it but my client base is largely non-technical and installing Perl on Windows would not be worth it for them.
...
I want to get out of a function when an exception occurs or so.
I want to use other method than 'return'
Help in this.
...
I read somewhere that currently urllib2 doesn't support authenticated https connection. My proxy uses a basic authentication only, but how to open an https based webpage through it .
Please help me.
Thanks.
...
I'm interested in writing a python client for a web-service, and for testing purposes it would be very interesting also to have a simple stub server. I'm using python 2.3, and ZSI 2.0.
My problem is that I do not manage to return an exception from the server.
If I raise an exception of the type used for the soap fault in the wsdl, I ge...
I wanted to experiment a little with python 3.0 at home. I got python 3.0 working, I've played around with some scripts, and I thought it would be fun to try to make a small web-project with it.
As I was googling, it turned out, that mod_python, for some reasons, will not be able to support python 3.0.
The only other alternative I've f...
Hi,
One of the biggest annoyances I find in Python is the inability of the re module to save its state without explicitly doing it in a match object. Often, one needs to parse lines and if they comply a certain regex take out values from them by the same regex. I would like to write code like this:
if re.match('foo (\w+) bar (\d+)', li...
I've never been sure that I understand the difference between str/unicode decode and encode.
I know that str().decode() is for when you have a string of bytes that you know has a certain character encoding, given that encoding name it will return a unicode string.
I know that unicode().encode() converts unicode chars into a string of b...
I have the following code in my index view.
latest_entry_list = Entry.objects.filter(is_published=True).order_by('-date_published')[:10]
for entry in latest_entry_list:
entry.views = entry.views + 1
entry.save()
If there are ten (the limit) rows returned from the initial query, will the save issue 10 seperate updated calls to ...
Is there any way to decrypting a pdf protected by an aes-256 bit key?
I have the correct password and I need a command-line tool (or library - perhaps in python :P ) for decrypting the file and then doing some operation over it.
The best thing could be if the file could be saved decrypted, then I elaborate it and then I can remove it.....
I think this must be a stupid question, but why do the results of urlsafe_b64encode() always end with a '=' for me?
'=' isn't url safe?
from random import getrandbits
from base64 import urlsafe_b64encode
from hashlib import sha256
from time import sleep
def genKey():
keyLenBits = 64
a = str(getrandbits(keyLenBits))
b = urlsafe...
I have threaded code where each thread needs to write to the same file. To prevent concurrency issues, I am using a Lock object.
My question is whether I am using the Lock correctly. If I set the lock from within each thread, is that lock global or only specific to that specific thread?
Basically, should I create a Lock first and pas...
I'm about to port a smallish library from Java to Python and wanted some advice (smallish ~ a few thousand lines of code). I've studied the Java code a little, and noticed some design patterns that are common in both languages. However, there were definitely some Java-only idioms (singletons, etc) present that are generally not-well-re...
I'm using google app engine, and am having trouble writing querys to filter ReferenceProperties.
eg.
class Group(db.Model):
name = db.StringProperty(required=True)
creator = db.ReferenceProperty(User)
class GroupMember(db.Model):
group = db.ReferenceProperty(Group)
user = db.ReferenceProperty(User)
And I have tried w...