python

Getting auto completion with Eclipse + PyDev for function arguments

Hello, I am using Eclipse and PyDev with Iron Python on a Windows XP machine. I have a class definition that takes an object as an argument which is itself an instantiation of another class like this: myObject1 = MyClass1() myObject2 = MyClass2(myObject1) The two class definitions are in different modules, myclass1.py and myclass2....

Python IDLE compatible with multithreading?

It seems that IDLE (part of the standard Python Windows install) will not execute multithreaded programs correctly without nasty hangs or bugout crashes. Does anyone know of a way to fix this? The following program will always hang in IDLE but complete normally when executed with the Python interpreter directly: import threading, time...

lexical analyse or series of regular expressions to parse unstructured text into structured form

I am trying to write some code that will function like google calendars quick add feature . You know the One where you can input any of the following : 1) 24th sep 2010 , Johns Birthday 2) John's Birthday , 24/9/10 3) 24 September 2010 , Birthday of John Doe 4) 24-9-2010 : John Does Birthday 5) John Does Birthday 24th of September 2010 ...

Cleaning up and removing tags with BeautifulSoup

Hey again all, I have the following script so far: from mechanize import Browser from BeautifulSoup import BeautifulSoup import re import urllib2 br = Browser() br.open("http://www.foo.com") html = br.response().read(); soup = BeautifulSoup(html) items = soup.findAll(id="info") and it runs perfectly, and results in the following ...

Using Pygments with PHP (Python in PHP)

Is it possible to use Python (specifically Pygments) with PHP? Currently, I have a phpBB forum that I'm developing for and JS Syntax Highlighters just haven't been working for me. There's already a GeSHI mod, but I want to develop something myself just for experience. Also, would there be performance issues? ...

slice (unsorted) array at value in python

Given the array a = [1,1,12,3,5,8,13,21] I can slice off the first 3 elements like a[:3] giving [1,1,2]. What I want is to slice off up to the element of vlaue i (e.g. if i=8 I want [1,1,12,3,5,8] or [1,1,12,3,5] (I can work with either)). This works: return a[:a.index(i)] but only if I give it a value that's in the array. Is ther...

Django installation on a Mac running Leopard

Here's my problem. I have a mac with 2.5 installed & was using django 1.1 with it. I had no problems until I decided to upgrade python & django. I uninstalled django from my mac as per the djangoproject.com website recommends. I left python 2.5 on my mac as not to interfere with pre-installed mac programs. I put python 2.6 & 3.1 on my ma...

creating and intersecting hexahedrons with CGAL

Using the Python bindings for CGAL, I can't work out how create a hexahedron, nor how to calculate its intersection with another hexahedron. I have 8 input points, which are the corners of the hexahedron: My code does this: P = Polyhedron_3() bottom = P.make_tetrahedron(p[0],p[1],p[2],p[3]) top = P.make_tetrahedron(p[4],p[5],p[6],p[...

Python XLWT adjusting column widths

I am enormously impressed with the ease of use of XLWT, but there is one thing I have not figured out how to do. I am trying to adjust certain rows to the minimum width they would need to display all characters (in other words, what excel would do if you double clicked on the divider between cells). I know how to adjust the column wi...

What should itertools.product() yield when supplied an empty list?

I guess it's an academic question, but the second result does not make sense to me. Shouldn't it be as thoroughly empty as the first? What is the rationale for this behavior? from itertools import product one_empty = [ [1,2], [] ] all_empty = [] print [ t for t in product(*one_empty) ] # [] print [ t for t in product(*all_empty) ] #...

How to add a LogEntry for all other staff Users in django?

i have a LogEntry in django admin for superadministrator users, but, now i need a LogEntry for the other "staff" users, it's this possible? Thanks folks! ...

ctypes initializing c_int array by reading file

Hi all - Using a Python array, I can initialize a 32,487,834 integer array (found in a file HR.DAT) using the following (not perfectly Pythonic, of course) commands: F = open('HR.DAT','rb') HR = array('I',F.read()) F.close() I need to do the same in ctypes. So far the best I have is: HR = c_int * 32487834 I'm not sure how to initi...

How to mock a free function in python?

I have a python program with a global function that is painful to test (it needs a large dataset to work properly). What is the best way to get around this while testing functions that call it? I've found that the following works (but it make me feel dirty to use it). module foo: def PainLiesHere(): return 4; #guaranteed to be rando...

python human readable large numbers

is there a python library that would make numbers such as this more human readable $187,280,840,422,780 edited: for example iw ant the output of this to be 187 Trillion not just comma separated. So I want output to be trillions, millions, billions etc ...

Breaking a parent function from within a child function (PHP Preferrably)

I was challenged how to break or end execution of a parent function without modifying the code of the parent, using PHP I cannot figure out any solution, other than die(); in the child, which would end all execution, and so anything after the parent function call would end. Any ideas? code example: function victim() { echo "I shou...

Django form.save step by step

Let's say I have a form for adding/editing products (with field 'user' being a foreign key to my User) triggered from two separate view functions - add/edit : def product_add(request): userprofile = UserProfile.objects.get(user=request.user) if request.method == 'POST': form = ProductAddForm(request.POST, request.FILES,)...

Problem about recursion

Hi, Please suggest me the solution to the following problem consider a function function recurse(a): for child in a.childs: recurse(child) Now I want to execute some code lets say print "Program ends here" when the program is done with recursion,so how can I know when the recursion will end? Thank you ...

extract parts of the string in python

I have to parse an input string in python and extract certain parts from it. the format of the string is (xx,yyy,(aa,bb,...)) // Inner parenthesis can hold one or more characters in it I want a function to return xx, yyyy and a list containing aa, bb ... etc I can ofcourse do it by trying to split of the parenthesis and stuff but I...

Global Exception Handling in Google App Engine

Instead of encapsulating my entire code in a try{} except{} block, is there someway of catching exceptions globally? Basically I am looking for a way to have a global exception handler which will handle all unhandled exceptions in the my python application written for google app engine ...

Good resources to start python for web development?

I'm really interested in learning Python for web development. Can anyone point me in the right direction? I've been looking at stuff on Google, but haven't really found anything that shows proper documentation and how to get started. Any recommended frameworks? Tutorials? I've been doing PHP for 5 years now, so I just want to try someth...