python

Python - efficient method to remove all non-letters and replace them with underscores.

def format_title(title): ''.join(map(lambda x: x if (x.isupper() or x.islower()) else '_', title.strip())) Anything faster? ...

Installing mypysql

In the readme file for mypysql, under the Installation section, all that is written is the following: $ svn export http://mypysql.svn.sourceforge.net/svnroot/mypysql mypysql $ cd mypysql $ make compile $ sudo make install Where would I execute such code? ...

python-tz am I wrong or it's a bug

Hi Guy, It's a bit weird it seems that when I want to get a timezone for Europe/Paris with pytz it gets me to the PMT timezone instead of GMT+1 when it seems to work for Europe/Berlin. Not clear ? Well look at this snippet : #!/usr/bin/python import os import datetime from pytz.tzfile import build_tzinfo base='/usr/share/zoneinfo/' t...

What Is The Best Way To Play Audio Through Qt?

I am building an application in pyQt4 and I want it to be able to play audio files. I was considering doing this through pyMedia as I could not get anywhere with the documentation, although the QAudio classes did initially look promising. It is important that the solution be cross-platform. Does anyone have any suggestions? ...

where is SeparatedValuesField in my code, i used sphinx.

from django.db import models from djangosphinx import SphinxSearch # A sample model from iBegin class City(models.Model): name = models.CharField(max_length=32) aliases = SeparatedValuesField(blank=True, null=True)#<-------this slug = models.SlugField(blank=True) country = models.For...

Can Large Python Scripts Drain DiskSpace?

UPDATE: Interestingly, after almost 15min, I seem to have AUTOMATICALLY restored about 500MB. Hows this happening? I'm on Mac OSX 10.5.6(Leopard). I wrote a python script for a Project-Euler problem. My script had a loop which iterated for an enormous count like 600851475143. Used Vi and Python on Mac's Terminal. I didn't get the resu...

Redirect calls to a member of a class in python

Hi, I was trying to 'extend' a closed class collections.defaultdict(lambda: 1) by addint it 2 methods, called 'vocabulary', and 'wordcount' apparently it's impossible to setattr method to builin types, nor can I inherit from defaultdic, so I decided to write a class and redirect calls to it to the type I want to extend. class BagOfW...

How to change caps lock status without key press

I am using a python program that is activate when pressing Caps Lock key and I want to be able to turn on/off the caps lock status when the program is active. I tried to send keys with virtkey but it obviously don't work since the keys just activate the app and don't change the caps lock status. So what is the best way to achieve this w...

Python: problem with list append

Here is my code - cumulative_nodes_found_list = [] cumulative_nodes_found_total_list = [] no_of_runs = 10 count = 0 while count < no_of_runs: #My program code print 'cumulative_nodes_found_list - ' + str(cumulative_nodes_found_list) cumulative_nodes_found_total_list.insert(count,cumulative_nodes_found_list) print 'cumulative_n...

How to solve an LCP (linear complementarity problem) in python ?

Is there a good library to numericly solve an LCP in python ? Edit: I need a working python code example because most libraries seem to only solve quadratic problems and i have problems converting an LCP into a QP. ...

problem with breadth first tree generation

hello, i have a problem with breadth first algorithm, my script generates curves in maya, position them, rotate and scale them so they give me the tree shape, i have these variables cs=current State, p=parent, nodes=non visited node List lvl=current depth maxlvl= max depth the problem is that i cant determine current depth, and ter...

Integrating pygame with a C module

In my Python2_6/include directory is a folder with pygame headers. I assumed that my python C module can access pygame stuff directly in C. Is this the case? How do I integrate a C module that wants to use pygame, with a python script using pygame? Right now my brain sees: pygame <-- MyCModule <-- MyScript --> pygame ie. Two pygame ins...

How to implement a client admin in Django?

I'm building a simple app, a sort of project/tasks manager where I can have several projects and several tasks that are assigned to one project. I enabled Django admin for all this sort of tasks and it's working like a charm. Also, I have some users that have projects assigned to them. So what I want now is to enable a cut down version ...

python how to -generate license- using time module

hello . I'm searching for a way to generate a (limited time license) .so when a user starts the program . it has to check license date first before the program runs. but the problem is : i tried a couple of solutions . one of them is python's time.ctime , (to check time and see if it's realy during the license time) and it returns the ti...

draw hebrew text to an image using Image module (python)

Hi I am trying to use Image module in order to make bitmaps with hebrew lettering in it. when printing from the shell (idle) I managed to print hebrew, but when trying to draw text to a bitmap it draws some ascii lettering. this is the code: import Image import ImageDraw a = "אריאל" #or any other hebrew string im=Image.new('RGB',(2...

How does len work?

How does len works on Python? Look at this example: class INT(int): pass class STR(str): def __len__(self): return INT(42) q = STR('how').__len__() print q, type(q) q = len(STR('how')) print q, type(q) The output is: 42 <class '__main__.INT'> 42 <type 'int'> How can I handdle it so len returns an INT instance? ...

converting wav to mp3 (and vice versa) using GStreamer

I am using Python bindings for Gstreamer and am using the following pipeline to convert a wav file to mp3. I used one of the suggestions in this question , with some modifications (as I was getting some errors when original syntax was used) gst.parse_launch("filesrc location=C:\\music.wav ! decodebin ! audioconvert ! lame ! files...

Python regex for matching bb code

Hi to all, I'm writing a very simple bbcode parse. If i want to replace hello i'm a [b]bold[/b] text, i have success with replacing this regex r'\[b\](.*)\[\/b\]' with this <strong>\g<1></strong> to get hello, i'm a <strong>bold</strong> text. If I have two or more tags of the same type, it fails. eg: i'm [b]bold[/b] and i'm [b]b...

Where is gsl_cdf_beta_Pinv() in PyGSL?

Hello, I'm trying to use the distribution functions in a Python program (the random functions I've got figured out; I'm looking specifically for gsl_cdf_beta_Pinv()) and I can't find it. Can someone tell me how I can use these or a fast alternative in a program? Thanks, Mark Ch. ...

Why I can't extend bool in Python?

>>> class BOOL(bool): ... print "why?" ... why? Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: Error when calling the metaclass bases type 'bool' is not an acceptable base type I thought Python trusted the programmer. ...