python

Pygame programs hanging on exit

I'm tinkering around with pygame right now, and it seems like all the little programs that I make with it hang when I try to close them. Take the following code, for example: from pygame.locals import * pygame.init() # YEEAAH! tile_file = "blue_tile.bmp" SCREEN_SIZE = (640, 480) SCREEN_DEPTH = 32 if __name__ == "__main__": screen ...

+ and += operators are different?

>>> c = [1, 2, 3] >>> print(c, id(c)) [1, 2, 3] 43955984 >>> c += c >>> print(c, id(c)) [1, 2, 3, 1, 2, 3] 43955984 >>> del c >>> c = [1, 2, 3] >>> print(c, id(c)) [1, 2, 3] 44023976 >>> c = c + c >>> print(c, id(c)) [1, 2, 3, 1, 2, 3] 26564048 What's the difference? are += and + not supposed to be merely syntactic sugar? ...

evolution plugin for crm integration via webservices

I have built a webservice into my companies self developed CRM system that we are in the process of integrating Outlook to the CRM for calendar sync and recording of emails related to clients. I want to build a plugin for the gnome evolution mail client as I use it for my work mail/calendar as I primarily run Linux. I am familiar with ...

How to put values of a list into a string

Hello, I am trying to place several values from a list into a string. The code I have is below: ID = [0, 1, 2] print 'ID {0}, {1}, and {2}.'.format(ID) or print (r'(ID\s*=\s*)(\S+)').format(ID) This does not work. Does anyone know where I'm going wrong. The code in the second line prints out the list: [0, 1, 2] the first line...

how to invoke sshfs within python script?

I want to mount a remote directory using sshfs. sshfs working fine from terminal. But how to invoke it from within python script? I tried something like this - but didn't work at all. import os cmd = "/usr/bin/sshfs [email protected]:/home/giis /mnt" os.system(cmd) ...

Storing list variables as a string and storing it as a variable

Hello, I am trying to enter list items into a string. I then want to store the string as a variable and print it out in another function. The code I have got so far is: def b(): ID = [0, 1, 2] ID2 = 'ID={0}.{1}.{2}'.format(*ID) return ID2 if __name__ == '__main__': ID2 = b() def c(ID2): print ID2 if __name__ ...

draw a border around subplots in matplotlib

Hello... anyone know how to draw a border around an individual subplot within a figure in matplotlib? I'm using pyplot. eg: import matplotlib.pyplot as plt f = plt.figure() ax1 = f.add_subplot(211) ax2 = f.add_subplot(212) # ax1.set_edgecolor('black') ..but Axes objects have no 'edgecolor', and I can't seem to find a way to outline ...

Why does not postgresql start returning rows immediately?

The following query returns data right away: SELECT time, value from data order by time limit 100; Without the limit clause, it takes a long time before the server starts returning rows: SELECT time, value from data order by time; I observe this both by using the query tool (psql) and when querying using an API. Questions/issues: ...

is something wrong with Python Shell (Google App)?

Hi there, Python Shell - shell.appspot.com is acting weird? or am I missing something? Google App Engine/1.3.0 Python 2.5.2 (r252:60911, Apr 7 2009, 17:42:26) [GCC 4.1.0] >>> mycolors = ['red','green','blue'] >>> mycolors.append('black') >>> print mycolors ['red', 'green', 'blue'] But the below result is expected ['red', 'green',...

Using Python simplejson to return pregenerated json

I have a GeoDjango model object that I want't to serialize to json. I do this in my view: lat = float(request.GET.get('lat')) lng = float(request.GET.get('lng')) a = Authority.objects.get(area__contains=Point(lng, lat)) if a: return HttpResponse(simplejson.dumps({'name': a.name, 'area': a.a...

Creating an image editing application in Python

I need a tile/sprite editor kind of like Pixen, but I couldn't find one for Windows so I thought it might be a good exercise for me to try and put one together. I use Python, so are there any libraries out there that are suited to the task of putting together a simple tile/sprite editor? ...

How do I search through regex matches in Python?

Hi, I need to try a string against multiple (exclusive - meaning a string that matches one of them can't match any of the other) regexes, and execute a different piece of code depending on which one it matches. What I have currently is: m = firstre.match(str) if m: # Do something m = secondre.match(str) if m: # Do something el...

wrapping cmd.exe with subprocess

Hi I try to wrap cmd.exe under windows with the following program but it doesn't work , it seems to wait for something and doesn't display anything. Any idea what is wrong here ? import subprocess process = subprocess.Popen('cmd.exe', shell=False, stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=None) process.stdin.write("dir\r...

invoking pylint programmatically

I'd like to invoke the pylint checker, limited to the Error signalling part, as part of my unit testing. so I checked the pylint executable script, got to the pylint.lint.Run helper class and there I got lost in a quite long __init__ function, ending with a call to sys.exit(). anybody ever tried and managed to do so? the dream-plan wo...

Equivalent of Beautiful Soup's renderContents() method in lxml?

Is there an equivalent of Beautiful Soup's tag.renderContents() method in lxml? I've tried using element.text, but that doesn't render child tags, as well as ''.join(etree.tostring(child) for child in element), but that doesn't render child text. The closest I've been able to find is etree.tostring(element), but that renders the opening...

Sorting a tuple of dicts

I am new to Python and am curious if I am doing this correctly. I have a tuple of dicts (from a database call): companies = ( { 'companyid': 1, 'companyname': 'Company C' }, { 'companyid': 2, 'companyname': 'Company A' }, { 'companyid': 3, 'companyname': 'Company B' } ) I want to sort this on companyname. ...

Complex Django query over foreign keys

I have two models in the same application. The application is called "News", and it has two classes in its model called "Article" and "Category". class Category(models.Model): name = models.CharField(_("Name"), max_length=100) slug = models.SlugField(_("Slug"), max_length=100, unique=True) class Article(models.Model): categ...

Can not remove french letters in a string returned by Python glob

I would like to rename files with french letters. I am using glob to browse the files and a function I've found on the Internet to remove the french letters. The supprime_accent seems to work ok. However, it doesn't rename files returned by the glob function. Does anybody knows what can be the reason? Is it related with glob encoding? ...

Django - Allow duplicate usernames

I'm working on a project in django which calls for having separate groups of users in their own username namespace. So for example, I might have multiple "organizations", and username should only have to be unique within that organization. I know I can do this by using another model that contains a username/organization id, but that ...

Python urllib2 Progress Hook

I am trying to create a download progress bar in python using the urllib2 http client. I've looked through the API (and on google) and it seems that urllib2 does not allow you to register progress hooks. However the older deprecated urllib does have this functionality. Does anyone know how to create a progress bar or reporting hook usin...