python

Profiling a python multiprocessing pool

I'm trying to run cProfile.runctx() on each process in a multiprocessing pool, to get an idea of what the multiprocessing bottlenecks are in my source. Here is a simplified example of what I'm trying to do: from multiprocessing import Pool import cProfile def square(i): return i*i def square_wrapper(i): cProfile.runctx("result...

Using safe filter in Django for rich text fields

I am using TinyMCE editor for textarea fileds in Django forms. Now, in order to display the rich text back to the user, I am forced to use the "safe" filter in Django templates so that HTML rich text can be displayed on the browser. Suppose JavaScript is disabled on the user's browser, TinyMCE won't load and the user could pass <script...

How do i set the PDU mode of a modem using python sms 0.3 module?

Am using python sms 0.3 module to access my modem on com port. Am trying to send an sms but am getting the following error sms.ModemError: ['\r\n', '+CMS ERROR: 304\r\n'] When i read the Modem error codes, Error code 304 is for PDU mode, am just wondering how do i set the mode using sms 0.3 Am using a USB modem, Huawei model E220. Ga...

Resources for developing Python and Google App Engine

Hi all, I would like to ask about some sources for developing applications with Python and Google App Engine. For example, some controls to generate automatically pages with the insert/update/delete of a database table, or any other useful resources are welcome. Thank you! ...

How to improve speed of this readline loop in python ?

Hi all, i'm importing several parts of a Databasedump in text Format into MySQL, the problem is that before the interesting Data there is very much non-interesting stuff infront. I wrote this loop to get to the needed data: def readloop(DBFILE): txtdb=open(DBFILE, 'r') sline = "" # loop till 1st "customernum:" is found while slin...

Does anybody use DjVu files in their production tools ?

When it's about archiving and doc portability, it's all about PDF. I heard about DjVu somes years ago, and it seems to be now mature enough for serious usages. The benefits seems to be a small size format and a fast open / read experience. But I have absolutely no feedback on how good / bad it is in the real world : Is it technically ...

[python] How to get instance type of a win32com object?

First of all, please excuse me for any incoherence in the tile of this question. It probably has some, but really don't know better. This question was raised in the context of controlling iTunes via COM from python. >>> itunes = win32com.client.Dispatch("iTunes.Application") >>> itunes <win32com.gen_py.iTunes 1.12 Type Library.IiTunes ...

GQL get ID field

On google appengine, you can retrieve the hash key value by doing a query like select __key__ from furniture But appengine datastore maintains a nicely autoincremented field ID for each kind. How can I access it from a query? select ID from furniture Doesn't work ...

How to create hover effect on StaticBitmap in wxpython?

Hi, I want to create hover effect on StaticBitmap - If the cursor of mouse is over the the bitmap, shows one image, if not, shows second image. It's trivial program (works perfectly with a button). However, StaticBitmap doesn't emit EVT_WINDOW_ENTER, EVT_WINDOW_LEAVE events. I can work with EVT_MOTION. If images are switched when the c...

Why use **kwargs in python? What are some real world advantages over using named arguments?

I come from a background in static languages. Can someone explain (hopefully through example) the real world advantages of using **kwargs over named arguments? To me it they seem to only make the function call more ambiguous. Thanks. ...

how can i obtain pattern string from compiled regexp pattern in python

I have some code like this one: >>> import re >>> p = re.compile('my pattern') >>> print p _sre.SRE_Pattern object at 0x02274380 Is it possible to get string "my pattern" from p variable? ...

Python - Virtualenv , python 3?

Seems everyone recommends virtualenv for multiple python versions (on osx), but does it even work with python 3.0? I downloaded it, and it doesn't seem to.. And I don't really understand how it works, Can you 'turn on' on env at a time or something? What I want is to leave the system python 2.5 (obviously), and to have python 3.1.1 with ...

To Ruby or not to Ruby

I know that this is a difficult question to answer, but I thought I would try anwyays.... I am just starting at a new company where they have a minimal existing code base. It probably has a month of man effort invested at this point. It is currently written in Ruby. It is also currently using Ruby on Rails -- but mostly just for the...

pythonic way to convert variable to list

I have a function whose input argument can either be an element or a list of elements. If this argument is a single element then I put it in a list so I can iterate over the input in a consistent manner. Currently I have this: def my_func(input): if not isinstance(input, list): input = [input] for e in input: ... I a...

emacs defadvice on python-mode function

Hi! In python-mode, there is a function called py-execute-region which sends a highlighted region of code to the Python buffer for evaluation. After evaluation, the cursor is in the Python buffer, but I would prefer that it remain in the script buffer so I can continue producing more code. I wrote a simple advising function: (defadvice ...

Google appengine string replacement in template file

I'm using google appengine (python, of course :) ) and I'd like to do a string.replace on a string from the template file. {% for item in items %} <p>{{ item.code.replace( '_', ' ' ) }}</p> {% endfor %} But that isn't working. So we cannot execute anything other than basic checks in the app engine templates. Is that Correct ? ...

Call Python from C++

I'm trying to call a function in a Python script from my main C++ program. The python function takes a string as the argument and returns nothing (ok.. 'None'). It works perfectly well (never thought it would be that easy..) as long as the previous call is finished before the function is called again, otherwise there is an access violat...

Python code to Daemonize a process?

Can anyone share an efficient code snipper to daemonize a process in python? ...

doing textwrap and dedent in Windows Powershell (or dotNet aka .net)

Background Python has "textwrap" and "dedent" functions. They do pretty much what you expect to any string you supply. textwrap.wrap(text[, width[, ...]]) Wraps the single paragraph in text (a string) so every line is at most width characters long. Returns a list of output lines, without final newlines. textwrap.dedent(tex...

Python: Warnings and logging verbose limit

I want to unify the whole logging facility of my app. Any warning is raise an exception, next I catch it and pass it to the logger. But the question: Is there in logging any mute facility? Sometimes logger becomes too verbose. Sometimes for the reason of too noisy warnings, is there are any verbose limit in warnings? http://docs.python....