Is there function to get an iterator over an arbitrary dimension of a numpy array?
Iterating over the first dimension is easy...
In [63]: c = numpy.arange(24).reshape(2,3,4)
In [64]: for r in c :
....: print r
....:
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
[[12 13 14 15]
[16 17 18 19]
[20 21 22 23]]
But iterating o...
I'm planning an application running on Google App Engine. The only worry I would have is portability. Or just the option to have the app run on a local, private cluster.
I expected an option for Google App Engine applications to run on other systems, a compatibility layer, to spring up. I could imagine a GAE compatible framework utiliz...
Is it necessary for two SQLAlchemy models to inherit from the same instance of declarative_base() if they must participate in the same Session? This is likely to be the case when importing two or more modules that define SQLAlchemy models.
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class SomeClas...
What is the difference between initializing a variable as global var or calling globals().update(var).
Thanks
...
I want to write a program that reads stdin (unbuffered) and writes stdout (unbuffered) doing some trivial char-by-char transformation. For the sake of the example let's say I want to remove all chars x from stdin.
...
I know about urllib and urlparse, but I want to make sure I wouldn't be reinventing the wheel.
My problem is that I am going to be fetching a bunch of urls from the same domain via the urllib library. I basically want to be able to generate urls to use (as strings) with different paths and query params. I was hoping that something might...
I have recently implemented Django's excellent cache framework. However from what I understand Django will not cache a view that is passed parameters in a get request.
I have an Ajax view that is passed get parameters that I would like to cache for X seconds, what would be an easy way to do this?
In psuedo code I currently have a URL:
...
I have a Scheduled Task on a WinXP SP2 machine that is set up to run a python script:
Daily
Start time: 12:03 AM
Schedule task daily: every 1 day
Start date: some time in the past
Repeat task: every 5 minutes
Until: Duration 24 hours
Basically, i want the script to run every five minutes, for ever.
My problem is the task runs some...
Hi all,
I have a basic Monostate with Python 2.6.
class Borg(object):
__shared_state = {}
def __new__(cls, *args, **kwargs):
self = object.__new__(cls, *args, **kwargs)
self.__dict__ = cls.__shared_state
return self
def __init__(self, *args, **kwargs):
noSend = kwargs.get("noSend", False)
...
I want to sort a list using my own cmp function. For the purpose of this discussion we can use the following example which is equivalent to what I'm trying to do:
print "\n".join([str(bla) for bla in sorted(mylist, cmp = cmp_configs)])
However, because of the way I organized my code, I much prefer to put the definition of cmp_configs...
I'm looking for a super easy way to deploy django application on windows.
Basically my plan is to set up any python web server with my app on it and the boundle everything together using py2exe into a single executable.
I've tried using cherrypy however the newest (3.1.2) server doesn't work with Windows XP with Nod32 antivirus install...
Can someone suggest an advanced Python book? I want a book that covers topics such as threading, networking, memory management and so on.
...
I have this code here. The only part I can add code to is in main_____ AFTER the 'i=1' line. This script will be executing multiple times and will have some variable (might not be 'i', could be 'xy', 'var', anything), incrementing by 1 each time. I have gotten this to work by declaring 'i' as global above the method, but unfortunately, I...
What is the Clojure equivalent (for the exact algorithm) of the following Python code?
from itertools import count
from math import sqrt
def prime_gen():
primes = []
for n in count(2):
if all(n%p for p in primes if p <= sqrt(n)):
primes.append(n)
yield n
...
I have a Google Appengine app requesting pages from another server using urllib2 POSTs. I recently enabled gzip compression on the other server running Apache2, and the Appengine page requests started failing on key-error, indicating 'content-length' is not in the headers.
I am not explicitly declaring gzip as an accepted encoding in m...
I'm currently writing an application that uses Pygments to perform syntax highlighting. The problem I'm having is any code I process with Pygments has the leading and trailing whitespace in the file removed, and a single line break added to the end. Is there a way to make Pygments preserve the whitespace?
...
Hey.
I know how to generate combinations of a set and that's a builtin in Python (what I use), anyway. But how to generate combinations with replacements?
Suppose I have a set with, say, two identical elements - for example, "AABCDE".
Combinations of 3 items could be:
"AAB"
"ABC"
"CDE"
However, the program would count 'ABC' twice - ...
Is there a way knowing (at coding time) which exceptions to expect when executing python code?
I end up catching the base Exception class 90% of the time since I don't know which exception type might be thrown(and don't tell me to read the documentation. many times an exception can be propagated from the deep. and many times the documen...
I want to learn python, and my task is the run a sql server 2008 stored procedure via a cron job.
Can someone step through a script for me in python?
...
Right now I'm running 50 PHP (in CLI mode) individual workers (processes) per machine that are waiting to receive their workload (job). For example, the job of resizing an image. In workload they receive the image (binary data) and the desired size. The worker does it's work and returns the resized image back. Then it waits for more jobs...