python

python and matplotlib server side to generate .pdf documents

hi ! i would like to write a server side python script that generate .pdf documents. for the moment i have Python 2.7 installed server side and matplolib installed server side too. A simple script that create a simple plot and generate a .png picture works. this is the script i use : # to access standard output : import sys # selec...

Pylons - url.current() incorrect, for '/test' shows '/test/test'?

I've got a pylons setup, using flup with nginx, and url.current() always returns totally wrong. I have a route: map.connect('testpage', '/test', controller='Main', action='test') And in that controller, I do url.current() and I get /test/test' instead of '/test'. I've tried changingSCRIPT_NAME` as various posts about using uwsgi sug...

Searching a python list quickly?

I have a dictionary and a list. The list is made up of values. The dictionary has all of the values plus some more values. I'm trying to count the number of times the values in the list show up in the dictionary per key/values pair. It looks something like this: for k in dict: count = 0 for value in dict[k]: if value in list: ...

py-appscript & events

Is it possible to subscribe to events using py-appscript ? Example: I'd like to get a callback when a user changes a rating on iTunes. ...

Concatenate sequence from a predefined datastructure

Hello, I've been struggling a little to build this piece of code, and I was wondering if there are others more simple/efficient way of doing this: fsSchema = {'published': {'renders': {'SIM': ('fold1', 'fold2'), 'REN': ('fold1', 'fold2')}}} def __buildPathFromSchema(self, schema, root=''): metaDirs = [] for dir_ in sc...

Efficiently detect sign-changes in python

I want to do exactly what this guy did: Python - count sign changes However I need to optimize it to run super fast. In brief I want to take a time series and tell every time it crosses crosses zero (changes sign). I want to record the time in between zero crossings. Since this is real data (32 bit float) I doubt I'll every have a numb...

SWIG passing argument to python callback fuction

Hi, So I'm almost done. Now I have working code which calls python callback function. Only thing I need now is how to pass argument to the python callback function. My callback.c is: #include <stdio.h> typedef void (*CALLBACK)(void); CALLBACK my_callback = 0; void set_callback(CALLBACK c); void test(void); void set_callback(CALLBA...

Mako calling function from string?

Is there an easy way to call a function given a string name in mako? ...

Where is the source code for a Python egg?

I'm attempting to add a video extension to the Python Markdown-2.0.3-py2.7.egg Things aren't working, so I want to use pdb debugger to see what's going on. I can't seem to find the source code to insert pdb. The egg is located here: /usr/local/lib/python2.7/site-packages/Markdown-2.0.3-py2.7.egg Using iPython, I can view the Pyth...

Python Facebook Authentication Get Hashtag Info from modpython URL (google.com/search#thispart)

I am trying to authenticate facebook with my Python app and when you redirect a user to the authentication URL, it returns with the authentication key for that user. The return URL looks like this: http://blah.com/facebookauthenticate#access_token=appid|authtoken|othertoken&amp;expires_in=7064 I am returned a modpython request but i c...

Does this have function have to use reduce() or is there a more pythonic way?

If I have a value, and a list of additional terms I want multiplied to the value: n = 10 terms = [1,2,3,4] Is it possible to use a list comprehension to do something like this: n *= (term for term in terms) #not working... Or is the only way: n *= reduce(lambda x,y: x*y, terms) This is on Python 2.6.2. Thanks! ...

Starting a web app now which will use python that later this need to embed nicely into a Drupal site?

This week, I want to start a web mapping and data visualization site for my work. Unfortunately, I just found out my work place will be using Drupal in a few months down the road. (Most of my web development experience is with App Engine.) My problem is that I need to make sure my web application embeds nicely into the larger Drupal s...

Increating a datime field with queryset.update

My model looks like this class MyModel(models.Model): end_time = DateTimeField() and this is what I'm trying to achieve: m=MyModel.objects.get(pk=1) m.end_time += timedelta(seconds=34) m.save() but I want to do it with update() to avoid race conditions: MyModel.objects.filter(pk=1).update(end_time=F('end_time')+timedelta(secon...

Import statement with Django

I'm having an issue with a failing import statement, it is called by a manage.py command. It works in the manage.py shell. It also recently worked, i've tried to retrace my steps to no avail. Any advice? ...

Why is the notebook control not showing up in my window?

Although I am not new to Python, this is my first attempt at using Glade to design the interface. My Python file looks like this: import gobject import gtk import gtk.glade class prefs_dialog: def __init__ (self): # Initialize the dialog self.window = gtk.glade.XML("file.glade").get_widget("prefs_dialog") ...

Why doesn't Python's `except` use `isinstance`?

The Python documentation for except says: For an except clause with an expression, that expression is evaluated, and the clause matches the exception if the resulting object is “compatible” with the exception. An object is compatible with an exception if it is the class or a base class of the exception object, [...] Why...

search list for exact match

How can I search list(s) where all the elements exactly match what I'm looking for. For instance, I want to verify if the following list consist of 'a', 'b' and 'c', and nothing more or less. lst=['a', 'b', 'c'] I did this: if 'a' in lst and 'b' in lst and 'c' in lst: #do something Many thanks in advance. ...

python app gets stuck on shuffle and loop

I am working on this small little piece in python and when I run it, It never gets past the print 'c' line and is stuck on the while loop. What am I doing wrong? link to text file: http://downloads.sourceforge.net/wordlist/12dicts-5.0.zip enter code here import sys import random inp = open('5desk.txt', 'r') lis = inp.readlines() inp.cl...

Broken Pipe when calling subprocess.Popen() within a multiprocessing.Process()

I am having an issue when making a shell call from within a multiprocessing.Process(). The error seems to be coming from Git, but I just can't figure out why it only happens from within a multiprocessing.Process(). Note, below is an example to demonstrate what's happening... in real code there is a lot more going on within the Process(...

Python: replacing method in calendar module.

Hello people in the know, I'm trying to replace two methods in calendar module: import calendar c = calendar.HTMLCalendar(calendar.MONDAY) def ext_formatday(self, day, weekday, *notes): if day == 0: return '<td class="noday">&nbsp;</td>' if len(notes) == 0: return '<td class="%s">%d<br /></td>' % (self.cssclas...