python

Convert Date String to DateTime Object in Python

Ok, so I have this date: 2005-08-11T16:34:33Z I need to know if this is date is before or after datetime(2009,04,01) and I can't seem to find a method that will convert that string to something that lets me compare it to datetime(2009,04,01) in a meaningful way. Surely there must be some built in method. I mean if I can't find one, I ...

Using Models and Forms outside of Django?

Is it possible to run a view file using Django Model and Form outside of the Django environment? ...

Could Python's logging SMTP Handler be freezing my thread for 2 minutes?

A rather confusing sequence of events happened, according to my log-file, and I am about to put a lot of the blame on the Python logger, which is a bold claim. I thought I should get some second opinions about whether what I am saying could be true. I am trying to explain why there is are several large gaps in my log file (around two mi...

Using PyLab to create a 2D graph from two separate lists

Hey Guys, This seems like a basic problem with an easy answer but I simply cannot figure it out no matter how much I try. I am trying to create a line graph based on two lists. For my x-axis, I want my list to be a set of strings. x_axis_list = ["Jan-06","Jul-06","Jan-07","Jul-07","Jan-08"] y_axis_list = [5,7,6,8,9] Any suggestion...

Dynamic Spacer in ReportLab

I'm automatically generating a PDF-file with Platypus that has dynamic content. This means that it might happen that the length of the text content (which is directly at the bottom of the pdf-file) may vary. However, it might happen that a page break is done in cases where the content is too long. This is because i use a "static" space...

How to do dependency injection python-way?

I've been reading a lot about python-way lately so my question is How to do dependency injection python-way? I am talking about usual scenarios when, for example, service A needs access to UserService for authorization checks. ...

Problem with number/type of arguments passed to an overloaded c++ constructor wrapped with swig.

I am trying to wrap a c++ class (let's call it "Spam") written by someone else with swig to expose it to Python. After solving several problems, I am able to import the module in python, but when I try to create an object of such class I obtain the following error: foo = Spam.Spam('abc',3) Traceback (most recent call last): File "<st...

What web frameworks are available for python?

What web frameworks are available with python? Just to be clear, python is just a language so if you want to run it on a web server (like apache?) you NEED a web framework? ...

How to install pyobjc on SnowLeopard's non-default python installation

Hi everybody. I'm having problems installing pyobjc on SnowLeopard. It came with python 2.6 but I need 2.5 so I have installed 2.5 successfully. After that I have installed xcode. After that I have installed pyobjc with "easy_install-2.5 pyobjc" But when I start my python 2.5 and from cmd line try to import Foundation, it says "no modu...

Any good python open source projects exemplifying coding standards and best practices?

In the question ...

writing a fast parser in python

I've written a hands-on recursive pure python parser for a some file format (ARFF) we use in one lecture. Now running my exercise submission is awfully slow. Turns out by far the most time is spent in my parser. It's consuming a lot of CPU time, the HD is not the bottleneck. I wonder what performant ways are there to write a parser in p...

how to find recursively for a tag of xml using LXML ?

using lxml is it possible to find recursively for tag " f1 ", i tried findall method but it works only for immediate children. I think I should go for BeautifulSoup for this !!! ...

Tokenize a command string

I have string like this: command ". / * or any other char like this" some_param="string param" some_param2=50 I want to tokenize this string into: command ". / * or any other char like this" some_param="string param" some_param2=50 I know it's possible to split with spaces but these parameters can also be seperated by commas, like:...

Python encoding ISO to UTF8

Hello everyone, I am trying to read my emails using a Python script (Python 2.5 and PyPy) Some of my results are not in ASCII and i get strings like this: =?ISO-8859-7?B?0OXm7/Dv8d/hIPP07+0gyuno4enx/u3h?=' Is there any way to decode it and convert to utf-8 so that i can process it? I tried .decode('ISO-8859-7') but i got the same s...

applicationDidFinishLaunching not being called on py2app application

applicationDidFinishLaunching on my app delegate is being called when I run my Python-Cocoa app from the Terminal (i.e. python myapp.py). However, if I then use py2app to create an .app bundle, applicationDidFinishLaunching does not get called when I open the .app bundle. ...

python: list manipulation

I have a list L of objects (for what it's worth this is in scons). I would like to create two lists L1 and L2 where L1 is L with an item I1 appended, and L2 is L with an item I2 appended. I would use append but that modifies the original list. How can I do this in Python? (sorry for the beginner question, I don't use the language much,...

Database testing in python, postgresql

How do you unit test your python DAL that is using postgresql. In sqlite you could create in-memory database for every test but this cannot be done for postgresql. I want a library that could be used to setup a database and clean it once the test is done. I am using Sqlalchemy as my ORM. ...

Why is recordset result being returned in this way for Python database query?

I have searched high and low for an answer to why query results returned in this format and how to convert to a list. data = cursor.fetchall() When I print data, it results in: (('car',), ('boat',), ('plane',), ('truck',)) I want to have the results in a list as ["car", "boat", "plane", "truck"] ...

Python Regex To VB.net

Hi everyone, I made a program in Python and now I whant to transfert it to vb.net. But I have some difficulties with the vb.net regular expression.... Someone can help me please? There are my Python regex: id = re.search('(?<=watch\?v\=)[\w|-]+|(?<=/v/)[\w|-]+', src) id = id.group(0) t = re.search('(?<=\&t\=)[\w|-]+', src) t = t.group...

How to get HTTP status message in (py)curl?

spending some time studying pycurl and libcurl documentation, i still can't find a (simple) way, how to get HTTP status message (reason-phrase) in pycurl. status code is easy: import pycurl import cStringIO curl = pycurl.Curl() buff = cStringIO.StringIO() curl.setopt(pycurl.URL, 'http://example.org') curl.setopt(pycurl.WRITEFUNCTION, ...