python

Python code to find if x is following y on twitter. More Pythonic way please

I wrote a twitter application in Python. Following is the code I used for a module where I find if x is following y. This code can be obviously improved upon. A pythonic way to do that? import urllib2 import sys import re import base64 from urlparse import urlparse import simplejson def is_follows(follower, following): theurl = 'h...

Python list serialization - fastest method

Hello, I need to load (de-serialize) a pre-computed list of integers from a file in a Python script (into a Python list). The list is large (upto millions of items), and I can choose the format I store it in, as long as loading is fastest. Which is the fastest method, and why? Using import on a .py file that just contains the list as...

What is "THE" Python book.

I was wanting to know if there is the one Python book. C has K & R, Perl has the Camel book Ruby, the pick ax book etc. ...

WingIDE no autocompletion for my modules

If anyone using WingIDE for their python dev needs: For some reason I get auto-completion on all the standard python libraries (like datetime....) but not on my own modules. So if I create my own class and then import it from another class, I get no auto-completion on it. Does anyone know why this is? ...

How to get distinct Django apps on same subdomain to share session cookie?

We have a couple of Django applications deployed on the same subdomain. A few power users need to jump between these applications. I noticed that each time they bounce between applications their session cookie receives a new session ID from Django. I don't use the Django session table much except in one complex workflow. If the use...

Where should I post my python code?

Today I needed to parse some data out from an xlsx file (Office open XML Spreadsheet). I could have just opened the files in openoffice and exported to csv. However I will need to reimport data from this spreadsheet later, and I wanted to eliminate the manual operation. I searched on the net for xlsx parser, and all I found was a stacko...

Quick and dirty stripchart in python?

I have some python code that receives a message every so often containing a timestamp and an edge transition, either low-to-high, or high-to-low. I'd like to graph each transition on a stripchart for a quick and dirty visualization of the digital waveform with the minimal amount of effort. Can you recommend any methods or packages that ...

Which Version of TurboGears should I use for a new project?

I'm planing a new project and I want to use TurboGears. The problem is: I'm not sure which version to choose. There are three choices: Turbogears 1.0.8 (stable) Turbogears 1.1 (beta 3) Turbogears 2.0 (beta 4) As this is a new project I dont want to choose the wrong framework. So where are the differeneces, how "beta" is 2.0? Thanks for...

How to re-use a reusable app in Django

Hello Django experts I am trying to create my first site in Django and as I'm looking for example apps out there to draw inspiration from, I constantly stumble upon a term called "reusable apps". I understand the concept of an app that is reusable easy enough, but the means of reusing an app in Django are quite lost for me. Few questi...

Converting a database-driven (non-OO) python script into a non-database driven, OO-script.

Hi, I have some software that is heavily dependent on MySQL, and is written in python without any class definitions. For performance reasons, and because the database is really just being used to store and retrieve large amounts of data, I'd like to convert this to an object-oriented python script that does not use the database at all. ...

Make pyunit show output for every assertion

How can I make python's unittest module show output for every assertion, rather than failing at the first one per test case? It would be much easier to debug if I could see the complete pattern of failures rather than just the first one. In my case the assertions are based on a couple loops over an array containing an object plus some f...

Django - having middleware communicate with views/templates

Alright, this is probably a really silly question but I am new to Python/Django so I can't really wrap my head around its scoping concepts just yet. Right now I am writing a middleware class to handle some stuff, and I want to set 'global' variables that my views and templates can access. What is the "right" way of doing this? I consider...

How do I use easy_install and buildout when pypi is down?

I am using buildout to automatically download and setup the many dependencies of my Plone installation. buildout more or less uses easy_install to download and install a bunch of Python eggs. This usually works, but it doesn't work if any of the dependencies cannot be downloaded or if I want buildout to find an internal package not appro...

How do I suppress python-mode's output buffer?

In python-mode (for emacs), hitting Control-C\Control-C will execute the current buffer. However, when execution is finished, the output buffer springs up and splits my editing window in half. This is a complete pain, especially given that there's generally no output in the buffer anyway! Is there a way to stop the buffer from appeari...

Want procmail to run a custom python script, everytime a new mail shows up

I have a pretty usual requirement with procmail but I am unable to get the results somehow. I have procmailrc file with this content: :0 * ^To.*@myhost | /usr/bin/python /work/scripts/privilege_emails_forward.py Wherein my custom python script(privilege_emails_forward.py) will be scanning through the email currently received and do so...

Debugging web apps

I've gotten pretty used to step-through debuggers over the years, both in builder, and using the pydev debugger in Eclipse. Currently, I'm making something in Python and running it on Google App Engine, and I should add that I'm pretty new to developing any real web app; I've never really done much beyond editing HTML code. So, I'm ru...

String separation in required format, Pythonic way? (with or w/o Regex)

I have a string in the format: t='@abc @def Hello this part is text' I want to get this: l=["abc", "def"] s='Hello this part is text' I did this: a=t[t.find(' ',t.rfind('@')):].strip() s=t[:t.find(' ',t.rfind('@'))].strip() b=a.split('@') l=[i.strip() for i in b][1:] It works for the most part, but it fails when the text part h...

Plese help me write a function to determine if two numbers are nearly equal when rounded to n significant decimal digits

I have been asked to test a library provided by a 3rd party. The library is known to be accurate to n significant figures. Any less significant errors can safely be ignored. I want to write a function to help me compare the results: def nearlyequal( a, b, sigfig=5 ): The purpose of this function is to determine if two floating-point n...

Bayesian spam filtering library for Python

I am looking for a Python library which does Bayesian Spam Filtering. I looked at SpamBayes and OpenBayes, but both seem to be unmaintained (I might be wrong). Can anyone suggest a good Python (or Clojure, Common Lisp, even Ruby) library which implements Bayesian Spam Filtering? Thanks in advance. Clarification: I am actually looking ...

What is wrong with my nested loops in Python?

How do I make nested loops in Python (version 3.0)? I am trying to get the following loops to show me the products of two numbers: def PrintProductsBelowNumber(number): number1 = 1 number2 = 1 while number1 <= number: while number2 <= number: print(number1, "*", number2, "=", number1 * number2) ...