python

side effect gotchas in python/numpy? horror stories and narrow escapes wanted

I am considering moving from Matlab to Python/numpy for data analysis and numerical simulations. I have used Matlab (and SML-NJ) for years, and am very comfortable in the functional environment without side effects (barring I/O), but am a little reluctant about the side effects in Python. Can people share their favorite gotchas regarding...

Function to create in-memory zip file and return as http response

I am avoiding the creation of files on disk, this is what I have got so far: def get_zip(request): import zipfile, StringIO i = open('picture.jpg', 'rb').read() o = StringIO.StringIO() zf = zipfile.ZipFile(o, mode='w') zf.writestr('picture.jpg', i) zf.close() o.seek(0) response = HttpResponse(o.read()) ...

Regex - Special alpha characters? - Python

I have a list of simple names such as Márquez, because of the á (?< name >[a-zA-Z]+) doesn't seem to be working! Help would be very much appreciated! ...

Python Socket Send Buffer Vs. Str

I am trying to get a basic server (copied from Beginning Python) to send a str. The error: c.send( "XXX" ) TypeError: must be bytes or buffer, not str It seems to work when pickling an object. All of the examples I found, seem to be able to send a string no problem. Any help would be appreciated, Stephen import socket import pic...

GUI options with python 3.x

Hello all: I was wondering what options are available for Python 3.x? I know Tkinter is available as well as qt, but what about the other libraries? Any word on when some of them may be ported over to 3.x? ...

Mercurial Issue when updating

I am trying to do a terminal update and I keep getting this error, no matter what. /Volumes/www/working/.hg/wlock.break /Library/Python/2.6/site-packages/mercurial/dispatch.py:157: DeprecationWarning: use lock.release instead of del lock return -1 Any ideas as to what this is? Out of date versions? I am running Snow Leopard 10.6.2 ...

Getting information from scripts/command line calls in C#

I've been writing a couple of apps which use C# as the Gui, but under the hood do all the work via scripts (which may be Python, Ruby etc.). To pass information from the script back to the GUI (for example error reporting etc.) I've usually resorted to calling the script via Process and either Redirected the input (StartInfo.Redirec...

Is it possible to delete/remove a wx.aui.AuiManager pane?

Hello, I want to remove a pane from the wx.aui.AuiManager. Is it possible? ...

PyGTK StatusIcon with transparency

Hi, I'm trying to create a PyGTK StatusIcon with transparent background. I need to draw the contents of the StatusIcon at runtime. StatusIcon wants a Pixbuf object (which can have transparency). No problem with that: pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, width, height) pixbuf.fill(0xffffffff) The problem is, I can...

separating JSS from CSS at plone.htmlhead

Hey there! I'm using Plone 3.1.7 in a project that needs performance tweaks. One of the tweaks requests that CSS should be at the top of page and the JS should be at the bottom. However both are located at <div tal:replace="structure provider:plone.htmlhead" /> In main_template. How do I split these ones? Thanks in advance ...

Serializing a suds object in python

Ok I'm working on getting better with python, so I'm not sure this is the right way to go about what I'm doing to begin with, but here's my current problem... I need to get some information via a SOAP method, and only use part of the information now but store the entire result for future uses (we need to use the service as little as pos...

List of Dicts comparision to match between lists and detect value change in python

I have a list of dictionaries that I get back from a web service call. listA = [{'name':'foo', 'val':'x'}, {'name':'bar', 'val':'1'}, {'name':'alice','val':'2'}] I need to compare results from the previous call to the service and pull out changes. so on next call I may get: listB = [{'name':'foo', 'val':'y'}, ...

Python program doesn't quit when finished

I have the following script 186.py: S=[] study=set([524287]) tmax=10**7 D={} DF={} dudcount=0 callcount=0 def matchval(t1,t2): if t1==t2: global dudcount dudcount+=1 else: global callcount callcount+=1 D.setdefault(t1,set([])) D.setdefault(t2,set([])) D[t1].add(t2) ...

Good ways to sort a queryset? - Django

Hi folks, what I'm trying to do is this: get the 30 Authors with highest score ( Author.objects.order_by('-score')[:30] ) order the authors by last_name Any suggestions? ...

Circular import issues with Django apps that have dependencies on each other

Hi, I am writing a couple of django apps wich by design is coupled together. But i get sircular import problems. I know it might be bad design, so please give examples of better solutions, but i cant seem to find a better suited design. So if there isnt a better design, how to solve this one? It is basically two django apps, with some ...

timedelta convert to time or int and store it in GAE (python) datastore

It looks like this has been covered somewhat in other questions, but I'm still fairly confused on how to actually do this. My lack of experience isn't helping much with that. I have two DateTimeProperties - StartTime and EndTime. I'm subtracting StartTime from EndTime to get the Duration. From my previous question (thank you to all that...

Get decorated function object by string name

def log(func): def wraper(*a, **kw): return func(*a, **kw) return wraper @log def f(): print 'f' print locals()['f'] # - prints <function wraper at 0x00CBF3F0>. How do you get the real f object (not decorator wrap)? ...

Web service API - which language is better?

Hi, I wrote a web service API which services REST requests in php. It didn't take much time to actually setup this on apache. But, I am more comfortable writing python code rather than php code. Can python be used as a server-side scripting language like php? What changes are necessary to make it work with apache? Thanks Bala Mudiam ...

how to convert a timedelta object into a datetime object

What is the proper way to convert a timedelta object into a datetime object? I immediately think of something like datetime(0)+deltaObj but that's not very nice... isn't there a toDateTime() function or something of the sort? ...

weighted std in numpy?

Hi Folks, numpy.average() has a weights option, but numpy.std() does not. Do folks have suggestions for a workaround? Thanks! /YGA ...