Tag Archives: python

Python – Filter directory contents

short and sweet, this python snippet will return a list containing your filtered directory import re import os filter = “.*” + searchstr + “.*” m = re.compile(filter,re.I) #if you want to ignore case use re.I, otherwise remove it filter(m.search,os.listdir(os.getcwd())) … Continue reading

Posted in Python, regex | Tagged , | Leave a comment

Python – Use regex to split hyphenated words

I was asked this question on stackoverflow, and figured I’d repost it here since I wrote it after all. s = “-this is. A – sentence;one-word what’s” re.findall(“\w+-\w+|[\w']+”,s) result: ['this', 'is', 'A', 'sentence', 'one-word', "what's"] make sure you notice that … Continue reading

Posted in Python, regex | Tagged , | Leave a comment

Python – Chunk string or data buffer

I was disappointed that there was no good way to chunk up data for string formatting or packetzing UDP data. After a bit of thought, and a desire to avoid using python code to do loops, I came up with … Continue reading

Posted in Python, regex | Tagged , | Leave a comment

Python – Convert 16bit image to 24bit image 565 to 888

Doing the following is much better than using putpixel and a for loop, as numpy uses c-functions. The actual execution speed is about .3 seconds faster on a 240×320 RGBA image. import numpy as np arr = np.fromstring(buff,dtype=np.uint16).astype(np.uint32) arr = … Continue reading

Posted in Image Processing, Python, comp-e | Tagged , , , | Leave a comment

Pythons in the ‘C’ircus

Spiffy code that is.  Stubby has made a few contributions as of late, so check them out.  I will be ragging on him to put his battleship game up, but alas it seems it’s lacking comments so we’ll see how … Continue reading

Posted in C, comp-e, forum | Tagged , , , | Leave a comment