python

python logging alternatives

The Python logging module is cumbersome to use. Is there a more elegant alternative? Integration with desktop notifications would be a plus. ...

Tukey five number summary in Python

I have been unable to find this function in any of the standard packages, so I wrote the one below. Before throwing it toward the Cheeseshop, however, does anyone know of an already published version? Alternatively, please suggest any improvements. Thanks. def fivenum(v): """Returns Tukey's five number summary (minimum, lower-hinge...

Python HTTP Redirect requests forbidden

Hi! I'm trying to scrape a website where the URL is redirected, however programmatically trying this gives me an 403 Error code (Forbidden). I can place the URL in the browser and the browser will properly follow the url though... to show a simple example i'm trying to go to : http://en.wikipedia.org/w/index.php?title=Mike_tyson I've...

Python pyc files (main file not compiled?)

A pretty basic Python question: I understand that when you import a module, that file is compiled into a pyc file to make it faster..? Why is the main file not also compiled to a pyc? Does this slow things down? Would it be better to keep the main file as small as possible then, or does it not matter? Thanks ...

How to replace repeated instances of a character with a single instance of that character in python

I want to replace repeated instances of the "*" character within a string with a single instance of "*". For example if the string is "***abc**de*fg******h", I want it to get converted to "*abc*de*fg*h". I'm pretty new to python (and programming in general) and tried to use regular expressions and string.replace() like: import re p...

Python programs on different Operating Systems

If I write a python script using only python standard libraries, using Python 2.6 will it work on all Operating Systems as long as python 2.6 is installed? ...

Which embedded database to use for file indexing applications

Hi, I need to develop a file indexing application in python and wanted to know which embedded database is the best one to use for indexing. Any help on this topic is appreciated. Thanks, Rajesh ...

Python Extension Can't Use library_dirs

WHen specifying library_dirs in a Python distutils.core.Extension I get this error when trying to build: /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/dist.py:263: UserWarning: Unknown distribution option: 'library_dirs' warnings.warn(msg) Why is this? I am using Python 2.5 on Mac OS X. ...

transforming an image into an array of lines to draw

How do I generate a list of lines to draw if I have pixel data for an image, so I don't have to draw every pixel? Any language will do, although I listed what I have a working knowledge for. C is ok as well. There was a limit to how many tags I could choose. Also, you can just point me toward an algorithm. ...

Downloading Mp3 using python in Windows mangles the song however in linux it doesn't?

Okay, so this is really messed. I've setup a script to download an mp3 using urllib2 in Python. url = 'example.com' req2 = urllib2.Request(url) response = urllib2.urlopen(req2) #grab the data data = response.read() mp3Name = "song.mp3" song = open(mp3Name, "w") song.write(data2) song.close() Turns out it was somehow related to me do...

how quick read 25k small txt file content with python

i download many html store in os,now get their content ,and extract data what i need to persistence to mysql, i use the traditional load file one by one ,it's not efficant cost nealy 8 mins. any advice is welcome g_fields=[ 'name', 'price', 'productid', 'site', 'link', 'smallImage', 'bigImage', 'description', 'createdOn', 'mo...

"Unable to find vcvarsall.bat" error when trying to install qrcode-0.2.1

Please help me to solve this error C:\Python26\Lib\site-packages\pyqrcode\encoder>python setup.py install running install running bdist_egg running egg_info writing qrcode.egg-info\PKG-INFO writing top-level names to qrcode.egg-info\top_level.txt writing dependency_links to qrcode.egg-info\dependency_links.txt package init file 'qrcode\...

Created HTTP response to be the same as accessing .jpg in Python

I want to server an image file but accept some attributes for processing before hand using Python and google app engine. Where I would normally have 'http://www.domain.com/image/desiredImage.jpg' as the image to server. I want to be able to add some tracking to it so I can do something similar to 'http://www.domain.com/image/desired...

Django 1.2.3 - Internationalization - makemessages does not detect all strings

Hello ! One more question about Django concerning localization of javascript files. Django provides a small and convenient javascript library which is used like gettext to internationalize strings in javascript files. I set it up successfully (at least the interpolate function works) and I could generate the po file for the French lang...

determining whether a MIME type is binary or text-based

Is there a library which allows determining whether a given content type is binary or text-based? Obviously text/* is always textual, but for things like application/json, image/svg+xml or even application/x-latex it's rather tricky without inspecting the actual data. ...

Mutable Default Argument Returns None

I have a simple code that finds paths using a graph stored in a dictionary. The code is exactly: def find_path(dct, init, depth, path=[]): if depth == 0: return path next_ = dct[init] depth-=1 find_path(dct, next_, depth) If I print the path right before return path it prints to screen the correct path (after an init...

How to check that a regular expression has matched a string completely, i.e. - the string did not contain any extra character?

I have two questions: 1) I have a regular expression ([A-Z][a-z]{0,2})(\d*) and I am using Python's re.finditer() to match appropriate strings. My problem is, that I want to match only strings that contain no extra characters, otherwise I want to raise an exception. I want to catch a following pattern: - capital letter, followed by 0,...

Downloading a webpage using urllib2 results in garbled junk? (only sometimes)

How come I hit this webpage, I get HTML text: http://itunes.apple.com/us/app/mobile/id381057839 But when I hit this webpage, I get garbled junk? http://itunes.apple.com/us/app/mobile/id375562663 I use the same download() function in python, which is here: def download(source_url): try: socket.setdefaulttimeout(10) ...

How to debug Python inside a WSC

Hi All, We're programming classic ASP for a big (legacy) web application. This works quite well using WSC (Windows script components) to separate GUI from business logic; the WSCs contain the business logic, classic asp is used for displaying returned information. The WSC's return stringvalues, ADO recordsets and in some cases vbscript...

how python manage object delete or destruction

Hi, guys, I am rather new to python and learning it to build a gui application (with wypython). I have a question related with object destruction in python. e.g. in myFrame I have onNew (create a new document) and onOpen (open a file) method. briefly, it looks like this. def onNew self.data=DataModel() self.viewwindow=ViewWind...