In my app I need to watch a directory for new files. The amount of traffic is very large and there are going to be a minimum of hundreds of new files per second appearing. Currently I'm using a busy loop with this kind of idea:
while True:
time.sleep(0.2)
if len(os.listdir('.')) > 0:
# do stuff
After running profiling I'm seei...
I'm currently using Django 1.1 beta for some personal projects, and plan to start messing arround with the trunk to see the new stuff under the hood. But I might start using it on a professional basis, and I'd need to know if trunk is stable enough for using in production, or I should stick to 1.0 for mission critical systems.
Edit
Put...
I have a process that I run every day. It uses Python logging. How would I configure the python logging module to write to a file containing the current date in the file name?
Because I restart the process every morning the TimedRotatingFileHandler won't work. The project is larger, so I would be interested in keeping the code requir...
Let's say I have the following:
def with_connection(f):
def decorated(*args, **kwargs):
f(get_connection(...), *args, **kwargs)
return decorated
@with_connection
def spam(connection):
# Do something
I want to test the spam function without going through the hassle of setting up a connection (or whatever the decora...
When using Python's textwrap library, how can I turn this:
short line,
long line xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
into this:
short line,
long line xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxx
I tried:
w = textwrap.TextWrapper(width=90,break_long_words...
In order to do quality assurance in a critical multicore (8) workstation, I want to run the same code in different processors but not in parallel or concurrently.
I need to run it 8 times, one run for each processor.
What I don't know is how to select the processor I want.
How can this be accomplished in Python?
...
So you can use distutils to create a file, such as
PIL-1.1.6.win32-py2.5.exe
which you can run and use to easily install something. However, the installation requires user input to proceed (you have to click 'OK' three times). I want to create an easily installable windows version that you can just run as a cmd line program, that does...
I understand I am able to filter queryset of Foreignkey or Many2ManyFields, however, how do I do that for a simple CharField that is a Select Widget (Select Tag).
For example:
PRODUCT_STATUS = (
("unapproved", "Unapproved"),
("approved", "Listed"),
#("Backorder","Backorder"),
...
How should I install (or where should I put and organize) usual python libraries in Google App Engine.
Some libraries require to be installed using setuptools. How can I install that libraries.
...
I want to imitate a normal python list, except whenever elements are added or removed via slicing, I want to 'save' the list. Is this possible? This was my attempt but it will never print 'saving'.
class InterceptedList(list):
def addSave(func):
def newfunc(self, *args):
func(self, *args)
print 'savi...
I am trying to develop a plasmoid using python. I have tried eclipse with pydev, vim with pythoncomplete, PIDA and also Komodo, but none of them could give me autocmpletion for method names or members for the classes belonging to PyQT4 or PyKDE4. I added the folders in /usr/share/pyshare in the PYTHONPATH list for the IDEs.
Do I need ...
I'm looking for a way to automatically determine the natural language used by a website page, given its URL.
In Python, a function like:
def LanguageUsed (url):
#stuff
Which returns a language specifier (e.g. 'en' for English, 'jp' for Japanese, etc...)
Summary of Results:
I have a reasonable solution working in Python using cod...
I have a class like the following:
class User:
def __init__(self):
self.data = []
self.other_data = []
def doSomething(self, source):
// if source = 'other_data' how to access self.other_data
I want to pass a string for the source variable in doSomething and access the class member of the same name.
I...
I am getting ready to deploy my first Django application and am hitting a bit of a roadblock. My base template relies on me passing in the session object so that it can read out the currently logged in user's name. This isn't a problem when I control the code that is calling a template.
However, as part of getting this app ready to be...
In Java, for example, the @Override annotation not only provides compile-time checking of an override but makes for excellent self-documenting code. I'm just looking for documentation (although if it's an indicator to some checker like pylint, that's a bonus). I can add a comment or docstring somewhere, but what is the idiomatic way to i...
It appears to me that Django and Pylons have different ideas on how middleware should work. I like that Pylons follows the standardized PEP 333, but Django seems to have more widespread adoption. Is it possible to write middleware to be used in both?
The project that involves said middleware is porting a security toolkit called ESAPI fr...
Hello,
I am currently using the following code to get the intersection date column
of two sets of financial data. The arrays include date, o,h,l,cl
#find intersection of date strings
def intersect(seq1, seq2):
res = [] # start empty
for x in seq1: # scan seq1
if x in seq2: #...
Hey everyone,
I'm writing a pretty basic application in python (it's only one file at the moment). My question is how do I get it so the python script is able to be run in /usr/bin without the .py extension?
For example, instead of running
python htswap.py args
from the directory where it currently is, I want to be able to cd to any...
Just tooling around for my own amusement, and I want to use a lambda, because I feel like it. Can I replace this function with a lambda?
def isodd(number):
if (number%2 == 0):
return False
else:
return True
Elementary, yes. But I'm interested to know...
...
Jon Skeet has the following reputation tracker which is built by C#.
I am interested in building a similar app by Python such that at least the following modules are used
beautiful soup
defaultdict
We apparently need
to parse the reputation from the site 'http://stackoverflow.com/users/#user-id#' by Bautiful soup
to store the dat...