python

Is there a pure Python Lucene?

The ruby folks have Ferret. Someone know of any similar initiative for Python? We're using PyLucene at current, but I'd like to investigate moving to pure Python searching. ...

Exception handling of a function in Python

Suppose I have a function definiton: def test(): print 'hi' I get a TypeError whenever I gives an argument. Now, I want to put the def statement in try. How do I do this? ...

I've got an existing Django app with a lack of database indexes. Is there a way to automatically generate a list of columns that need indexing?

The beauty of ORM lulled me into a soporific sleep. I was thinking maybe some middleware that logs which columns are involved in WHERE clauses? but is there anything built into MySQL that might help? ...

How to call java objects and functions from CPython?

I have a python program, which runs on the CPython implementation, and inside it I must call a function defined in a java program. How can I do this? It would be nice to be able to use some java objects too. Jython is not an option. I must run the python part in CPython. ...

How to convert a list of longs into a comma separated string in python

Hi, I'm new to python, and have a list of longs which I want to join together into a comma separated string. In PHP I'd do something like this: $output = implode(",", $array) In Python, I'm not sure how to do this. I've tried using join, but this doesn't work since the elements are the wrong type (i.e., not strings). Do I need to cr...

Help in FileNotFoundException -Python

This is my code: try: import clr, sys from xml.dom.minidom import parse import datetime sys.path.append("C:\\teest") clr.AddReference("TCdll") from ClassLibrary1 import Class1 cl = Class1() except ( ImportError ) : print "Module may not be existing " My TCdll is in C:\test.I just gave it as C:\teest to ...

How do you create a list like PHP's in Python?

This is an incredibly simple question (I'm new to Python). I basically want a data structure like a PHP array -- i.e., I want to initialise it and then just add values into it. As far as I can tell, this is not possible with Python, so I've got the maximum value I might want to use as an index, but I can't figure out how to create an e...

Is there a label in Python ?

Is there a label or any equivalent implementation in Python? ...

How do I stop a program when an exception is raised in Python ?

I need to stop my program when an exception is raised in Python. How do I implement this? ...

random Decimal in python

How can I get a random decimal.Decimal? it appears that the random module only returns floats which are a pita to convert to Decimals. ...

PIL vs RMagick/ruby-gd

Hi, For my next project I plan to create images with text and graphics. I'm comfortable with ruby, but interested in learning python. I figured this may be a good time because PIL looks like a great library to use. However, I don't know how it compares to what ruby has to offer (e.g. RMagick and ruby-gd). From what I can gather PIL ...

Is a PHP, Python, PostgreSQL design suitable for a business application?

I'm looking for some quick thoughts about a business application I am looking to build. I'd like to separate the three layers of presentation, domain logic, and data using PHP, Python, and PostgreSQL, respectively. I would like to hear, possibly from other folks who have gone down this path before, if there are problems with this approa...

Re-creating threading and concurrency knowledge in increasingly popular languages

I am primarily a Java developer, and I've been reading a lot of in-depth work on threads and concurrency. Many very smart people (Doug Lea, Brian Goetz, etc) have authored books on these topics and made contributions to new concurrency libraries for Java. As I start to learn more about Python, Ruby, and other languages, I'm wondering: ...

make a parent function return - super return?

there is a check I need to perform after each subsequent step in a function, so I wanted to define that step as a function within a function. >>> def gs(a,b): ... def ry(): ... if a==b: ... return a ... ... ry() ... ... a += 1 ... ry() ... ... b*=2 ... ry() ... >>> gs(1,2) # should return 2 >>> gs(1,1) # should re...

unicode() vs. str.decode() for a utf8 encoded byte string (python 2.x)

Is there any reason to prefer unicode(somestring, 'utf8') as opposed to somestring.decode('utf8')? My only thought is that .decode() is a bound method so python may be able to resolve it more efficiently, but correct me if I'm wrong. ...

Extracting Embedded Images From Outlook Email

I am using Microsoft's CDO (Collaboration Data Objects) to programatically read mail from an Outlook mailbox and save embedded image attachments. I'm trying to do this from Python using the Win32 extensions, but samples in any language that uses CDO would be helpful. So far, I am here... The following Python code will read the last em...

python, sorting a list by a key that's a substring of each element

Part of a programme builds this list, [u'1 x Affinity for war', u'1 x Intellect', u'2 x Charisma', u'2 x Perception', u'3 x Population growth', u'4 x Affinity for the land', u'5 x Morale'] I'm currently trying to sort it alphabetically by the name of the evolution rather than by the number. Is there any way I can do this without just ...

Installing Python 3.0 on Cygwin

The Question What is the correct way to install Python 3.0 alongside Python 2.x using Cygwin? Notes I already have a working copy of Cygwin, and Python 2.x is installed within Cygwin (/lib/python2.x, not c:\python2.x). Also, I would like to be able to call python 3 separately (and only intentionally) by leaving python pointing to Pyt...

Python classes from a for loop

I've got a piece of code which contains a for loop to draw things from an XML file; for evoNode in node.getElementsByTagName('evolution'): evoName = getText(evoNode.getElementsByTagName( "type")[0].childNodes) evoId = getText(evoNode.getElementsByTagName( "typeid")[0].childNodes) evoLevel = get...

Reading Command Line Arguments of Another Process (Win32 C code)

I need to be able to list the command line arguments (if any) passed to other running processes. I have the PIDs already of the running processes on the system, so basically I need to determine the arguments passed to process with given PID XXX. I'm working on a core piece of a Python module for managing processes. The code is written ...