I'm writing a python script to extract data out of our 2GB Apache access log. Here's one line from the log.
81.52.143.15 - - [01/Apr/2008:00:07:20 -0600] "GET /robots.txt HTTP/1.1" 200 29 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1) VoilaBot BETA 1.2 (http://www.voila.com/)"
I'm trying to get the date portion from that...
Given a date range how to calculate the number of weekends partially or wholly within that range?
(A few definitions as requested:
take 'weekend' to mean Saturday and Sunday.
The date range is inclusive i.e. the end date is part of the range
'wholly or partially' means that any part of the weekend falling within the date range means the...
I have implemented in my python code a callback for variable arguments similar to what can be found here:
hxxp://docs.python.org/library/optparse.html#callback-example-6-variable-arguments
Adding the option like this:
parser.add_option("-c", "--callback", dest="vararg_attr", action="callback", callback=vararg_callback)
The problem ...
EDIT: I used, finally, inotify. As stefanB says, inotify is the thing to use. I found a tail clone that uses inotify to implement the -f mode, inotail.
Original question text:
I'm trying to implement the "tail -f" logic in a C project, for prototyping purposes I developed it in python as follow:
# A forever loop, each 5 seconds w...
Hi, I've had some problems with a Django application after I deployed it. I use a Apache + mod-wsgi on a ubuntu server. A while after I reboot the server the time goes foobar, it's wrong by around -10 hours. I made a Django view that looks like:
def servertime():
return HttpResponse( datetime.now() )
and after I reboot the server an...
I recently saw a reference to "exotic signatures" and the fact they had been deprecated in 2.6 (and removed in 3.0). The example given is
def exotic_signature((x, y)=(1,2)): return x+y
What makes this an "exotic" signature?
...
Hi all,
I have the modulus of an RSA public key. I want to use this public key with the Python library "M2Crypto", but it requires a public key in PEM format.
Thus, I have to convert the RSA modulus to a PEM file.
The modulus can be found here.
Any ideas?
Thanks a lot,
hevalbaranov
...
have this code
import threading
def Thread(f):
def decorator(*args,**kargs):
print(args)
thread = threading.Thread(target=f, args=args)
thread.start()
thread.join()
decorator.__name__ = f.__name__
return decorator
@Thread
def add_item(a, b):
return a+b
print(add_item(2,2))
but ...
Hi Pythonistas,
I'd like to serialize Python objects to and from the plist format (this can be done with plistlib). My idea was to write a class PlistObject which wraps other objects:
def __init__(self, anObject):
self.theObject = anObject
and provides a "write" method:
def write(self, pathOrFile):
plistlib.writeToPlist(se...
Hi there,
I am a Python newbie so please be gentle :)
I have a Python script that I want to use as a controller to another Python script. I have a server with 64 processors, so want to spawn up to 64 child processes of this second Python script. The child script is called:
%> python create_graphs.py --name=NAME
where NAME is somethi...
I have a date of the form specified by RFC 2822 -- say Fri, 15 May 2009 17:58:28 +0000, as a string. Is there a quick and/or standard way to get it as a datetime object in Python 2.5? I tried to produce a strptime format string, but the +0000 timezone specifier confuses the parser.
...
I've got a bunch of classes that inherit from a common base class. This common base class does some cleaning up in its delete method.
class Base(models.Model):
def delete(self):
print "foo"
class Child(Base):
def delete(self):
print "bar"
super(Child, self).delete()
When I call delete on the Child from...
This is a newbie theory question - I'm just starting to use Python and looking into Django and orm. Question: If I develop my objects and through additional development modify the base object structures, inheritance, etc. - would Django's ORM solution modify the database automatically OR do I need to perform a conversion (if the app is ...
I'm using Turbogears2 and SQLAlchemy to develop a webapp. I have two mapped tables O1 and O2.
O2 has a sorted list of O1s in 'ones'.
At some point I want to query all O2's and the referenced O1's.
Unfortunately the query below fails because table O2 is aliased in the query and the column referenced by the order_by phrase is no longer kn...
I am creating a custom wxPython dialog by subclassing wx.Dialog. When I press Enter while using it, (and while being focused on one of the form elements,) it just takes the focus to the next form element, while I want it to press the ok button.
How do I solve this?
...
I'm working on writing a very simple client/server application as an excuse to start learning network/gui programming in python. At the moment I'm stuck on transitioning from my login frame to the main frame of the application.
The login frame is a subclass of wx.Frame, and basically I just want to close it and open the main frame when...
If I have a list in Python like
[1, 2, 2, 2, 2, 1, 1, 1, 2, 2, 1, 1]
how do I calculate the greatest number of repeats for any element? In this case 2 is repeated a maximum of 4 times and 1 is repeated a maximum of 3 times.
Is there a way to do this but also record the index at which the longest run began?
...
I am building an application to distribute to fellow academics. The application will take three parameters that the user submits and output a list of dates and codes related to those events. I have been building this using a dictionary and intended to build the application so that the dictionary loaded from a pickle file when the appli...
I'm trying to use the dnspython library, and am a little confused by their example for querying MX records on this page: www.dnspython.org/examples.html:
import dns.resolver
answers = dns.resolver.query('dnspython.org', 'MX')
for rdata in answers:
print 'Host', rdata.exchange, 'has preference', rdata.preference
In the python CLI,...
MySQL has a RENAME TABLE statemnt that will allow you to change the name of a table.
The manual mentions
The rename operation is done atomically, which means that no other session can
access any of the tables while the rename is running
The manual does not (to my knowedge) state how this renaming is accomplished. Is an enti...