Hello, I want like to enhance spam protection on my site. I've found out that after being banned by ip bots don't change the Accept-Language and Accept-Charset http headers (so most of spam comes with windows-1251 accept-charset). I understand that there may be normal users with unordinary preferences, but anyways, how can I determine wh...
Let's say I have a list of arbitrary length, L:
L = list(range(1000))
What is the best way to split that list into groups of n? This is the best structure that I have been able to come up with, and for some reason it does not feel like it is the best way of accomplishing the task:
n = 25
for i in range(0, len(L), n):
chunk = L[i...
Trying to set up a dependency in C++ with a parent-child relationship. The parent contains the child and the child has a weak pointer to the parent.
I would also like to be able to derive from the parent in Python. However, when I do this, I get a weak pointer error connecting up this parent-child relationship.
C++ code:
#include <boo...
Hi all
I'm using Eclipse / PyDev trying to find a way to debug code that uses subprocess.Popen to create a child process: I want to be able to debug the child process that is created. The problem is that I cannot find a way to debug accross process boundaries, and I'm guessing that it is actually not possible. Still, you never know un...
I'm following the python tutorial at their site and I'm currently at the break continue section. I just tried this sample code.
>>> for n in range(2, 10):
... for x in range(2, n):
... if n % x == 0:
... print n, 'equals', x, '*', n/x
... break
... else:
... # loop fell through without fin...
Using PyFacebook I am trying to register a test user of my site with my facebook application. I can connect to the API fine and return a list of friends etc. However when trying to register an address using:
hashed_emails = facebook.hash_email('[email protected]')
accounts = [hashed_emails]
facebook.connect.registerUsers(accounts)
I get:
...
I have in input, which could be a single primitive or a list or tuple of primitives.
I'd like to flatten it to just a list, like so:
def flatten(values):
return list(values)
The normal case would be flatten(someiterablethatisn'tastring)
But if values = '1234', I'd get ['1', '2', '3', '4'], but I'd want ['1234']
And if values = ...
Every Django model has a default primary-key id created automatically. I want the model objects to have another attribute big_id which is calculated as:
big_id = id * SOME_CONSTANT
I want to access big_id as model_obj.big_id without the corresponding database table having a column called big_id.
Is this possible?
...
The US census bureau uses a special encoding called “soundex” to locate information about a person. The soundex is an encoding of surnames (last names) based on the way a surname sounds rather than the way it is spelled. Surnames that sound the same, but are spelled differently, like SMITH and SMYTH, have the same code and are filed toge...
Hello all,
I have the following code:
def testGeodatabase(self):
geodatabaseList = self.gp.ListWorkspaces("*","ALL")
for x in geodatabaseList:
if x == self.outputGeodatabase:
return True
else:
pass
return False
What i need to know the following: in case the if condition evaluates to...
A Django newbie question:
What is the recommended way of handling settings for local development and the production server? Some of them (like Constants, etc) can be changed/accessed in both, but some of them (like paths to static files) need to remain different, and hence should not be overwritten everytime the new code is deployed...
...
I have an email that I'm reading with the Python email lib that I need to modify the attachments of. The email Message class has the "attach" method, but does not have anything like "detach". How can I remove an attachment from a multipart message? If possible, I want to do this without recreating the message from scratch.
Essentially I...
I would like to create a class that effectively does this (mixing a little PHP with Python)
class Middle(object) :
# self.apply is a function that applies a function to a list
# e.g self.apply = [] ... self.apply.append(foobar)
def __call(self, name, *args) :
self.apply(name, *args)
Thus allowi...
Hi, I tried installing TurboGears 1.0 on Windows 7 using tgsetup.py. and got following error
error: Couldn't find a setup script in c:\users\sandre~1\appdata\local\temp\
easy_install-jimbkt\Cheetah-2.4.0.linux-i686.tar.gz
When looking into this folder I see easy_install-jimbkt folder appearing and disappearing right away. Is this some...
I have some really nice Python code to do what I need to do. I don't particularly like any of the Python GUI choices though. wxPython is nice, but for what I need, the speed on resizing, refreshing and dynamically adding controls just isn't there. I would like to create the GUI in VB.NET. I imagine I could use IronPython to link the two,...
Using only a mapper (a Python script) and no reducer, how can I output a separate file with the key as the filename, for each line of output, rather than having long files of output?
...
The following code:
class Log:
BAT_STATS = ['AB', 'R', 'H', 'HR']
def __init__(self, type):
for cat in Log.BAT_STATS:
self.cat = 0
I want the loop there to create a class property of each key in BAT_STATS, so I can go:
log = Log()
print log.HR;
Similar to PHP with $this->$$foo = 'bar' where $foo would be 'HR'.
...
I've been implementing caching in my django application, and used per view caching via the cache API and template fragment caching.
On some of my pages I use a custom django template tag, this tag is provided via a third party developer, it takes some arguments in its template tags, and then make a request to a remote server, gets the re...
I want to make sure all of my flatpages have the "www" subdomain and redirect to it if they don't. I've looked at some middlewares that redirect to www, but 1. they usually redirect all urls to www and 2. the ones I've found don't work with flatpages.
I don't want all of my site urls to redirect to include the www subdomian, just the...
Hello fellow programmers,
I am creating a GUI program in Python/PyQT and would like to know how I can connect an event which happens in a child object to the parent?
For example, if someone clicks a 'Submit' button, how would i trigger something to happen in the parent object (lets say update a QLabel on the parent)
Any help would be ...