python

Is it possible to update an entry on Google App Engine datastore through the object's dictionary?

I tried the following code and it didn't work: class SourceUpdate(webapp.RequestHandler): def post(self): id = int(self.request.get('id')) source = Source.get_by_id(id) for property in self.request.arguments(): if property != 'id': source.__dict__[property] = self.request.get(property) source.put() se...

printing python version in output

in a python program i want to print python version (lets say 2.5.2 or 2.4) in the output. means system has python version lets say 2.5.2. i have written a program in python, now i want in the output. it should print python version. what is the code for this. ...

How to check null value for UserProperty in Google App Engine

Hello, In Google App Engine, datastore modelling, I would like to ask how can I check for null value of a property with class UserProperty? for example: I have this code: class Entry(db.Model): title = db.StringProperty() description = db.StringProperty() author = db.UserProperty() editor = db.UserProperty() creationdate = db...

PIL Image.resize() not resizing the picture

I have some strange problem with PIL not resizing the image. def handle_uploaded_image(i, u): # resize image from PIL import Image img = Image.open(i) if img.mode not in ('L', 'RGB'): img = img.convert('RGB') width, height = img.size if width == height: img.thumbnail(settings.THUMB_SIZE, Image.ANTIAL...

Django + Jquery, expanding AJAX div

How can I, when a user clicks a link, open a div right underneath the link which loads it's content via AJAX? Thanks for the help; I cannot find out how to. Just statically filling the div on the server side while loading the page works fine, but it's too much content for that. I'm kind of looking for a specific Django version of the...

Python and web-tags regex

Hello, i have need webpage-content. I need to get some data from it. It looks like: < div class="deg">DATA< /div> As i understand, i have to use regex, but i can't choose one. I tried the code below but had no any results. Please, correct me: regexHandler = re.compile('(<div class="deg">(?P<div class="deg">.*?)</div>)') result = ...

Is there an object unique identifier in Python

This would be similar to the java.lang.Object.hashcode() method. I need to store objects I have no control over in a set, and make sure that only if two objects are actually the same object (not contain the same values) will the values be overwritten. ...

sort dictionary by another dictionary

I've been having a problem with making sorted lists from dictionaries. I have this list list = [ d = {'file_name':'thisfile.flt', 'item_name':'box', 'item_height':'8.7', 'item_width':'10.5', 'item_depth':'2.2', 'texture_file': 'red.jpg'}, d = {'file_name':'thatfile.flt', 'item_name':'teapot', 'item_height':'6.0', 'item_width':'...

Which path module or class do Python folks use instead of os.path?

Just wondering how many people use a path module in Python such as Jason Orendorff's one, instead of using os.path for joining and splitting paths? Have you used: Jason's path module (updated for PEP 355) Mike Orr's Unipath, basically a more modern version of the above Noam Raphael's alternative path module that subclasses tuple instea...

Book Recommendations for Moving from Novice to Advanced Python Programming?

I have a friend who I have been trying to help learn computer programming and I have a question on his behalf. He's interested in doing some biological modeling for his own research and needs to visualize his data using graphical elements, but he needs more power than can be found in Excel or similar solutions. I naturally sent him to Py...

Why would traceback.extract_stack() return [] when there is definitely a call stack?

I have a class that calls traceback.extract_stack() in its __init__(), but whenever I do that, the value of traceback.extract_stack() is []. What are some reasons that this could be the case? Is there another way to get a traceback that will be more reliable? I think the problem is that the code is running in Pylons. Here is some co...

How to include and use .eggs/pkg_resources within a project directory targeting python 2.5.1

I have python .egg files that are stored in a relative location to some .py code. The problem is, I am targeting python 2.5.1 computers which require my project be self contained in a folder (hundreds of thousands of OLPC XO 8.2.1 release laptops running Sugar). This means I cannot just ./ez_install to perform a system-wide setuptools/...

Distributing my python scripts as jars with jython?

Hi all, I have been a python programmer for almost 2 years and I am used to writing small scripts to automate some repetitive tasks I had to do at office. Now, apparently my colleagues noticed this and they want those scripts too. Some of them have macs, some windows, I made these on windows. I investigated the possibility of using py2e...

Google Web Toolkit like application in Django

I'm trying to develop an application that would be perfect for GWT, however I am using this app as a learning example for Django. Is there some precedence for this type of application in Django? ...

Why does subprocess.Popen() with shell=True work differently on Linux vs Windows?

When using subprocess.Popen(args, shell=True) to run "gcc --version" (just as an example), on Windows we get this: >>> from subprocess import Popen >>> Popen(['gcc', '--version'], shell=True) gcc (GCC) 3.4.5 (mingw-vista special r3) ... So it's nicely printing out the version as I expect. But on Linux we get this: >>> from subprocess...

Which libraries have been ported to different programming languages?

Since I am working with different Platforms and programming languages, I found there are many good libraries that are ported with different programming language than its original. For example JUnit and Log4j which has been ported into several different languages. Sometimes if I am already used to working with these libraries, I would fin...

Looking for online Judge Engine that support Python

I am writing a website which intends to be a place for use to paste/answer coding questions. Especially Python. So, I am looking for an "online judge" engine that could support Python(c/c++/java/# could be a plus), so that the guy who paste the question could provide a simple test, then others could answer it with the onlinejudge to ver...

Is there an easy way to pickle a python function (or otherwise serialize its code)?

I'm trying to transfer a transfer a function across a network connection (using asyncore). Is there an easy way to serialize a python function (one that, in this case at least, will have no side affects) for transfer like this? I would ideally like to have a pair of functions similar to these: def transmit(func): obj = pickle.dumps...

get_allowed_auths() in paramiko

Hi all, I am trying to get supported auth methods from a running SSH server in Python. I found this method in the ServerInterface class in Paramiko but I can't understand if it is usable in a simple client-like snippet of code (I am writing something that accomplish in ONLY this task). Anyone can suggest me some links with examples, ot...

Suggestion Needed - Networking in Python - A good idea ?

Hello, I am considering programming the network related features of my application in Python instead of the C/C++ API. The intended use of networking is to pass text messages between two instances of my application, similar to a game passing player positions as often as possible over the network. Although the python socket modules seem...