python

is it possible to read the text written in a sticky note using a script in linux?

I am using sticky notes in ubuntu . And was wondering if it would be possible to read the text written in sticky notes using any scripting language . ...

Google App Engine: Get entity key to use in a template

Assuming I have the following: class Person(db.Model): name = db.StringProperty() I would like to print all the names in an html file using a template. template_values = {'list': Person.all()} And the template will look like this: {% for person in list %} <form> <p>{{ person.name}} </p> <button type="button" name="**{{ perso...

How to create custom permission (user role) in Django ?

I have simple question. How to create user role in Django without creating it in DB manually ? EDIT: I need to create specific permission. So only users with this permission can change specific field of model. I just need make one field 'readonly' for some users. Is it possible in django? ...

Strange python's comparison behaviour

I have a sample code looking like this, values (position = 2, object.position = 3) : new_position = position old_position = object.position logging.debug("1. new_position: %s, old_position: %s" % (new_position, old_position)) if old_position != new_position: logging.debug("old position other than new positi...

any way to invoke fragment identifiers '#' in python

Is there any way to invoke fragment identifiers from python? I'm currently using python mechanize. ...

How to reliably open a file in the same directory as a Python script

I used to open files that were in the same directory as the currently running Python script by simply using a command like open("Some file.txt", "r"). However, I discovered that when the script was run in Windows by double-clicking it, it would try to open the file from the wrong directory. Since then I've used a command of the form ope...

How to call a function in a pyGTK timeout?

When I try to call a function using a timeout in pyGtk, I receive the error message TypeError: second argument not callable. All I want to do is call a very simple function from within the time out. To illustrate my proble, I have simply prepared the function do_nothing to illustrate my problem. def do_nothing(self): return True # ...

python/cgi - serves distorted images

Hello, I have been struggling for a couple hours now with serving jpg's with a python cgi site. For some reason the images always come out distorted. Here is my code: print('Content-type: image/jpg\n') path = 'C:\\Users\\Admin\\Documents\\image.jpg' print file(path, 'rb').read() This post describes a nearly identical problem, howeve...

Python/Django: Have DB TimeZoneField for user, how do I use that with datetime and time to get strftime() like '%Y-%m-%dT%H:%M:%S.000Z'?

I have a DB "TimeZoneField" type for users, how do I use that with the "datetime.datetime()" object to get a strftime() string like '%Y-%m-%dT%H:%M:%S.000Z'? ...

TypeError: 'int' object is unsubscriptable

I am running into this problem - TypeError: 'int' object is unsubscriptable This happens at the line: (more code below) sectorcalc[i][2]= ((today[2]/yesterday[2])-1) But the object today[2] is , any ideas? Also, I couldn't find a good definition of unsubscriptable for python anywhere? what does this actually mean the problem is? Tha...

Pygtk: Name is not defined

I'm trying out a few pygtk tutorials and have run across a seemingly obvious newbie mistake, but for the life of me can't figure out what's going on here. The error: Traceback (most recent call last): File "main.py", line 8, in class Base: File "main.py", line 61, in Base cv.set_line_width(9) NameError: name 'cv' is not ...

zlib module missing - python 2.4.3

I am trying to get simplejson installed on this python 2.4.3 - I cannot upgrade, I know it is old, there is nothing I can do about it, it is not my fault, please help. however when i do the ..\python.exe .\setup.py install i get: File "C:\Program Files (x86)\WorldViz\Vizard30\bin\lib\zipfile.py", line 188, in __init__ raise RuntimeErro...

AppEngine -> "AttributeError: 'unicode' object has no attribute 'has_key'" when using blobstore

There have been a number of other questions on AttributeErrors here, but I've read through them and am still not sure what's causing the type mismatch in my specific case. Thanks in advance for any thoughts on this. My model: class Object(db.Model): notes = db.StringProperty(multiline=False) other_item = db.ReferenceProperty(Other...

Does linux disk buffer cache make python cPickle more efficient than shelve?

Is IO more efficient, due to the linux disk buffer cache, when storing frequently accessed python objects as separate cPickle files instead of storing all objects in one large shelf? Does the disk buffer cache operate differently in these two scenarios with respect to efficiency? There may be thousands of large files (generally around...

How do I use simplejson to decode JSON responses to python objects?

JSON serialization Python using simpleJSON How do I create an object so that we can optimize the serialization of the object I'm using simpleJSON 1,2 are fixed variables 3 is a fixed dict of category and score 4 is an array of dicts that are fixed in length (4), the array is a length specificed at run-time. The proc...

Getting started with json

I have never worked with json before. I am trying: http://api.worldbank.org//topics?format=JSON and make things with it, but I don't even know how to get started. Following some manuals, I did this: import urllib import urllib2 import simplejson urlb = 'http://api.worldbank.org/topics' datab = urllib2.urlopen(urlb+'?'+ param) resultb =...

any way to invoke fragment identifiers '#' in python

Possible Duplicate: any way to invoke fragment identifiers '#' in python Is there any way to invoke fragment identifiers from python? I'm currently using python mechanize. ...

Using Python lxml.html how can I find images within link tags?

Hi there. I am using lxml.html to parse some hmtl to get links, however when it hits a link which contains an image it just returns blank, what it'd really like is to be able to detect if it's an image, and then try and return the image alt text. So it looks like this... from lxml.html import parse, fromstring doc = fromstring('<a hr...

multiple return statements in python "def" causes syntax error

Hi, I'm trying to test my function "def" in a python shell, but when i paste it in there are errors. It seems not to like it when i have multiple return statements inside one "def". For example: def foo(): valid = True if valid: return True return False Does anyone know why? thanks! ...

Matplotlib 2d polygone in 3d axes

Hi everybody, I'm using matplotlib to plot some data as 2d curves in a 3d axes. I use the ax=axes3d.Axes3D() to define my axes and ax.plot(x,y, zs='z') to plot my 2d curves in the 3d space. Now I want to add something that looks like what is on this page http://matplotlib.sourceforge.net/examples/mplot3d/polys3d_demo.html, but I want t...