python

Python (and Django) best import practices

Out of the various ways to import code, are there some ways that are preferable to use, compared to others? This link http://effbot.org/zone/import-confusion.htm in short states that from foo.bar import MyClass is not the preferred way to import MyClass under normal circumstances or unless you know what you are doing. (Rather, a bette...

Python threading test not working. [SOLVED]

EDIT I solved the issue by forking the process instead of using threads. From the comments and links in the comments, I don't think threading is the right move here. Thanks everyone for your assistance. FINISHED EDIT I haven't done much with threading before. I've created a few simple example "Hello World" scripts but nothing that ac...

Can I use Django 1.1 with django-search-lucene for full-text searching, and if so, what resources/links/docs can I reference to get it up and running?

A little background: I want to use Django Search with Lucene I have Django 1.1 w/ Python 2.5 installed MySQL 5.1 is being used My local machine is running Windows Vista x64, but we will deploy to Red Hat Linux Yes, I wish that right about now I was running Linux. ...

Is there a simple process-based parallel map for python?

I'm looking for a simple process-based parallel map for python, that is, a function parmap(function,[data]) that would run function on each element of [data] on a different process (well, on a different core, but AFAIK, the only way to run stuff on different cores in python is to start multiple interpreters), and return a list of resu...

Get uncompressed size of a .gz file in python

Using gzip, tell() returns the offset in the uncompressed file. In order to show a progress bar, I want to know the original (uncompressed) size of the file. Is there an easy way to find out? ...

I want to use ZopeInterfaces, however my project is based on Python 3.x - any suggestions?

Zope Interfaces are a great way to get some Java-style "design by contract" into a python program. It provides some great features such as implement-able interfaces and a really neat pattern for writing adaptors for objects. Unfortunately, since it's part of a very mature platform which runs just fine on Python 2.x the developers of Zo...

Difference between yield in Python and yield in C#

What is the difference between yield keyword in Python and yield keyword in C#? ...

The easiest DHT to implement

Which Distributed Hash Table (DHT) is easiest to implement in Python? Any good example that is not bloated? I not am looking for a definition of DHT because I am more oriented and focused on design and implementation of such. ...

Abandoned Apache process, how long will it go on?

So lets say there's a server process that takes way too long. The client complains that it "times out." Correct me if I'm wrong, but this particular timeout could have to do with apache's timeout setting, but not necessarily. I believe this to be the case because when testing the page in question we couldn't get it to time out reliably ...

Convert gzipped data fetched by urllib2 to HTML

I currently use mechanize to read gzipped web page as below: br = mechanize.Browser() br.set_handle_gzip(True) response = br.open(url) data = response.read() I wonder how to decompress gzipped data fetched by urllib2 to HTML text? req = urllib2.Request(url) opener = urllib2.build_opener() response = opener.open(req) data = response.r...

Find images with similar color palette with Python

Suppose there are 10,000 JPEG, PNG images in a gallery, how to find all images with similar color palettes to a selected image sorted by descending similarity? ...

Initializing numpy matrix to something other than zero or one

I have the following code: r = numpy.zeros(shape = (width, height, 9)) It creates a width x height x 9 matrix filled with zeros. Instead, I'd like to know if there's a function or way to initialize them instead to NaN. Is there any? Without having to resort to manually doing loops and such? Thanks ...

Python library for Linux process management

Hello, Through my web interface I would like to start/stop certain processes and determine whether a started process is still running. My existing website is Python based and running on a Linux server, so do you know of a suitable library that supports this functionality? Thanks ...

Python Form Processing alternatives

django.forms is very nice, and does almost exactly what I want to do on my current project, but unfortunately, Google App Engine makes most of the rest of Django unusable, and so packing it along with the app seems kind of silly. I've also discovered FormAlchemy, which is an SQLAlchemy analog to Django forms, and I intend to explore t...

Python Twisted and database connections

Hi all, Our projects at work include synchronous applications (short lived) and asynchronous Twisted applications (long lived). We're re-factoring our database and are going to build an API module to decouple all of the SQL in that module. I'd like to create that API so both synchronous and asynchronous applications can use it. For the ...

Organize a python library as plugins

I would like to create a library, say foolib, but to keep different subpackages separated, so to have barmodule, bazmodule, all under the same foolib main package. In other words, I want the client code to be able to do import foolib.barmodule import foolib.bazmodule but to distribute barmodule and bazmodule as two independent entitie...

finding cycle of 3 nodes ( or triangles) in a graph

hi all, i am working with complex networks. I want to find group of nodes which forms cycle of 3 nodes ( or triangles) in a given graph. As my graph contains about million edges, so the use simple iterative (multiple "for" loop) is not very efficient. If someone knows any algorithm which can be used for finding triangles in graphs, kind...

ImportError running Google's python appengine on Ubuntu

I'm trying to teach myself python using Google's AppEngine, and I can't get the dev server running. I get this error: Traceback (most recent call last): File "/opt/google_appengine/google_appengine_1.2.7/dev_appserver.py", line 60, in run_file(file, globals()) File "/opt/google_appengine/google_appengine_1.2.7/dev_apps...

Python Markdown: Markdown Inside HTML Blocks

Is there an extra for Python Markdown that supports Markdown inside HTML block elements, e.g. div, p i.e. is there a way to convert this: <div id="content"> [Google](http://www.google.com) </div> to <div id="content"> <a href="http://www.google.com&gt;Google&lt;/a&gt; </div> using Python Markdown or a Python Markdown exten...

Problem with making object callable in python

I wrote code like this >>> class a(object): def __init__(self): self.__call__ = lambda x:x >>> b = a() I expected that object of class a should be callable object but eventually it is not. >>> b() Traceback (most recent call last): File "<pyshell#5>", line 1, in <module> b() TypeError: 'a' object is not callable >>> ...