python

How can I make a wxPython app constantly update and execute code?

Given the following simple program: import wx class TestDraw(wx.Panel): def __init__(self,parent=None,id=-1): wx.Panel.__init__(self,parent,id,style=wx.TAB_TRAVERSAL) self.SetBackgroundColour("#FFFFFF") self.Bind(wx.EVT_PAINT,self.onPaint) self.SetDoubleBuffered(True) self.circleX=320 ...

Creating a Colormap Legend in Matplotlib

Hi fellow Stackers! I am using imshow() in matplotlib like so: import numpy as np import matplotlib.pyplot as plt mat = '''SOME MATRIX''' plt.imshow(mat, origin="lower", cmap='gray', interpolation='nearest') plt.show() How do I add a legend showing the numeric value for the different shades of gray. Sadly, my googling has not uncover...

can't figure out serving static images in django dev environment

I've read the article (and few others on the subject), but still can't figure out how to show an image unless a link to a file existing on a web-service is hard-coded into the html template. I've got in urls.py: ... (r'^galleries/(landscapes)/(?P<path>.jpg)$', 'django.views.static.serve', {'document_root': settings.MEDIA_U...

What does the caret operator (^) in Python do?

I ran across the caret operator in python today and trying it out, I got the following output: >>> 8^3 11 >>> 8^4 12 >>> 8^1 9 >>> 8^0 8 >>> 7^1 6 >>> 7^2 5 >>> 7^7 0 >>> 7^8 15 >>> 9^1 8 >>> 16^1 17 >>> 15^1 14 >>> It seems to be based on 8, so I'm guessing some sort of byte operation? I can't seem to find much about this searching ...

Deleting object in function

Let's say I have created two objects from class foo and now want to combine the two. How, if at all possible, can I accomplish that within a function like this: def combine(first, second): first.value += second.value del second #this doesn't work, though first.value *does* get changed instead of doing something like def combi...

How can I draw to a MemoryDC using the GraphicsContext, and then blit that to a PaintDC?

I'm looking to add double buffering to a drawing function like this. dc = wx.PaintDC(self) gc = wx.GraphicsContext.Create(dc) #draw GraphicsPaths to the gc I tried to first draw to a MemoryDC and then blit that back to the PaintDC: dc = wx.MemoryDC() dc.SelectObject(wx.NullBitmap) gc = wx.GraphicsContext.Creat...

How do I handle an UnresolvedImport Eclipse (Python)

When I write import MySQLdb in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get the error to go away, but what is the right way to handle this? How can I help Eclipse know that MySQLdb is there? ...

How is it that json serialization is so much faster than yaml serialization in python?

I have code that relies heavily on yaml for cross-language serialization and while working on speeding some stuff up I noticed that yaml was insanely slow compared to other serialization methods (e.g., pickle, json). So what really blows my mind is that json is so much faster that yaml when the output is nearly identical. >>> import ya...

working with negative numbers in python

hello everyone. Thank you for your help in advance. I am a student in a concepts of programming class. The lab is run by a TA and today in lab he gave us a real simple little program to build. It was one where it would multiply by addition. Anyway, he had us use absolute to avoid breaking the prog with negatives. I whipped it up real qui...

String formatting named parameters?

I know it's a really simple question, but I have no idea how to google it. how can I do print '<a href="%s">%s</a>' % (my_url) So that my_url is used twice? I assume I have to "name" the %s and then use a dict in the params, but I'm not sure of the proper syntax? just FYI, I'm aware I can just use my_url twice in the params, but t...

Why does my buffered GraphicsContext application have a flickering problem?

import wx class MainFrame(wx.Frame): def __init__(self,parent,title): wx.Frame.__init__(self, parent, title=title, size=(640,480)) self.mainPanel=DoubleBufferTest(self,-1) self.Show(True) class DoubleBufferTest(wx.Panel): def __init__(self,parent=None,id=-1): wx.Panel.__init__(self,parent,id,st...

how to get the index or the element itself of an element found with "if element in list"

Hey, Does a direct way to do this exists? if element in aList: #get the element from the list I'm thinking something like this: aList = [ ([1,2,3],4) , ([5,6,7],8) ] element = [5,6,7] if element in aList #print the 8 ...

Python: Create a duplicate of an array

I have an double array alist[1][1]=-1 alist2=[] for x in xrange(10): alist2.append(alist[x]) alist2[1][1]=15 print alist[1][1] and I get 15. Clearly I'm passing a pointer rather than an actual variable... Is there an easy way to make a seperate double array (no shared pointers) without having to do a double for loop? Thanks, Da...

XOR swap algorithm in python?

I tried to implement XOR swap in python. x,y= 10,20 x,y,x = x^y,x^y,x^y print('%s , %s'%(x,y)) OUTPUT: 30 , 30 I am not new to python but I am unable to explain this output. It should have been 20,10. What is going on under the hood? ...

faking a filesystem / virtual filesystem

I have a web service to which users upload python scripts that are run on a server. Those scripts process files that are on the server and I want them to be able to see only a certain hierarchy of the server's filesystem (best: a temporary folder on which I copy the files I want processed and the scripts). The server will ultimately be ...

Newbie python error in regards to import

Hello. I'm a python newbie and starting out with using the Bottle web framework on Google App Engine. I've been messing with the super small, super easy Hello World sample and have already ran into problems. Heh. I finally got the code to work with this... import bottle from bottle import route from google.appengine.ext.webapp impor...

how to pass varible in function so eclipse can detect its type and work with intelli sense ?

how can we pass a variable or what we can do inside the method, so eclipse can show the intellisense. ...

Organizing Python objects for retrieval

I have a Club class and a Player Class. The player class has an attribute Fav.clubs which will have unique club values. So the user is supposed to enter various club names. Based on the club names I must retrieve those club objects and establish the relationship that this particular player has this Fav.clubs. The attribute Fav.clubs in ...

Encrypting XML database in python

i am using XML as my backend for the application... LXML is used to parse the xml. How can i encrypt this xml file to make sure that the data is protected...... thanks in advance. ...

Python evaluation order

Here's the code, I don't quite understand, how does it work. Could anyone tell, is that an expected behavior? $ipython In [1]: 1 in [1] == True Out[1]: False In [2]: (1 in [1]) == True Out[2]: True In [3]: 1 in ([1] == True) --------------------------------------------------------------------------- TypeError ...