python

Google Appengine and Python exceptions

In my Google Appengine application I have defined a custom exception InvalidUrlException(Exception) in the module 'gvu'. Somewhere in my code I do: try: results = gvu.article_parser.parse(source_url) except gvu.InvalidUrlException as e: self.redirect('/home?message='+str(e)) ... which works fine in the local GAE development se...

Problem with jQuery Ajax...how do I update two DIVs with ONE ajax call?

function ajaxCall(query){ $.ajax({ method:"get", url:"/main/", data:"q="+query, beforeSend:function() {}, success:function(html){ $("#main").html(html); } }); }; This is the entire code that will populate #main: <p>{{ num_results }}, you just searched for {{ query }}</p> Suppose I have another div...

Returning an instance of a class from a file in python

In my program I have a package filled with various .py files each containing a class definition. I want to make a list where each entry is an instance of one of those classes. In addition, my program doesn't know how many files are in the package or what the files or classes are called, so I can't just import each file. Ideally, I sho...

Pythonic Way to Create Union of All Values Contained in Multiple Lists

Hi all, Doing some XML processing in python. (Edit: I'm forced to use Python 2.4 for this project, boo!) I want to know what is the most Pythonic way to do this (create union of all values in multiple lists): def getUniqueAttributeValues(xml_attribute_nodes): # split attribute values by whitespace into lists result_lists=lis...

Python's subprocess.Popen object hangs gathering child output when child process does not exit

When a process exits abnormally or not at all, I still want to be able to gather what output it may have generated up until that point. The obvious solution to this example code is to kill the child process with an os.kill, but in my real code, the child is hung waiting for NFS and does not respond to a SIGKILL. #!/usr/bin/python impor...

How can I make Sphinx's inheritance_diagram readable?

Similar to this chap's post, I'm seeing Sphinx generate unreadable graphviz output: How can I generate readable output? Nothing happens if I add -Gfontsize=140 If I tell it to use neato instead of dot it produces readable output, but the graphs aren't tree-like. ...

Google App Engine Patch - How to use stylesheets?

Struggling with an install of GAE-Patch and using my stylesheets. My settings.py has the following lines included already, but the media generator is not compiling and packaging it properly: 'combined-%(LANGUAGE_DIR)s.css': ( 'global/look.css', ), 'combined-%(LANGUAGE_DIR)s.css': ( 'global/base-%(LANGUAGE_DIR...

Conditionally Require Only One Field In Django Model Form

Anyway to make a field conditionally required based on whether or not another field in the same form has been filled out? If field1 has no data, but field2 does form is valid. If field1 has no data and field2 has no data form is invalid Not looking for any javascript solutions. I feel as it should be solved with django for...

Can I get my instance of mechanize.Browser to stay on the same page after calling b.form.submit()?

In Python's mechanize.Browser module, when you submit a form the browser instance goes to that page. For this one request, I don't want that; I want it just to stay on the page it's currently on and give me the response in another object (for looping purposes). Anyone know a quick to do this? EDIT: Hmm, so I have this kind of working wi...

Blogger (Python) API: How do I retrieve a post by post ID?

Having previously obtained a post ID from a call to gdata.blogger.client.add_post()... post = client.add_post(...) post_id = post.get_post_id() ...how do I use that post id to retrieve the post in the future? I thought maybe gdata.blogger.client.Query would be the way to go, but this doesn't support post id as a query term. The exam...

How can I declare a 5x5 grid of numbers in Python?

How would I declare this? I'm thinking something along the lines of: boardPieces = ["A","O","A" "A", "A", "O" ] ...

Python: Obtain edge end points of the graph

I need the edge end points from a graph. I have installed networkx. I have some idea how to proceed. networkx.Graph.edges_iter() returns all the edges in the graph [e for e in G.edges_iter()] [(0, 1), (1, 2), (2, 3)] What I want is a list [0,1,1,2,2,3] How do I get this from the above data? ...

Python: Convert a list into a normal value

I have a list a = [3] print a [3] I want ot convert it into a normal integer print a 3 How do I do that? ...

How can I install Easy_Install for Python 2.6.4 in Mac OSX 10.4.11

I get the following errors, I've placed [my name] for anonymity: >>> python /Users/[myname]/Desktop/setuptools-0.6c11/ez_setup.py File "<stdin>", line 1 python /Users/[myname]/Desktop/setuptools-0.6c11/ez_setup.py ^ SyntaxError: invalid syntax If you can't see the ^ is under t...

how to find time at particular timezone from anywhere

I need to know the current time at CDT when my Python script is run. However this script will be run in multiple different timezones so a simple offset won't work. I only need a solution for Linux, but a cross platform solution would be ideal. ...

Python looping: idiomatically comparing successive items in a list

I need to loop over a list of objects, comparing them like this: 0 vs. 1, 1 vs. 2, 2 vs. 3, etc. (I'm using pysvn to extract a list of diffs.) I wound up just looping over an index, but I keep wondering if there's some way to do it which is more closely idiomatic. It's Python; shouldn't I be using iterators in some clever way? Simply loo...

Displaying dictionary value in django template

All, I have the following in my views.py def getgradeform(request): id1=request.user.get_pf().id sc=Sc.objects.filter(id=id1) logging.debug(sc) logging.debug("++++") dict={} dict.update({'sc': sc}) return render_to_response('content/add.html',dict) Logging.debug gives an output as [<sc: Robert>] My question is t...

Template extraction in python/php

Are there existing template extract libraries in either python or php? Perl has Template::Extract (http://search.cpan.org/%7Eautrijus/Template-Extract-0.40/lib/Template/Extract.pm), but I haven't been able to find a similar implementation in either python or php. The only thing close in python that I could find is TemplateMaker (http:/...

Filtering a list of strings based on contents

Given the list ['a','ab','abc','bac'], I want to compute a list with strings that have 'ab' in them. I.e. the result is ['ab','abc']. How can this be done in Python? ...

Custom auth handler with mechanize

I would like to use python-ntlm with mechanize.Browser() I have got HTTPNtlmAuthHandler working with urllib2 and mechanize.urlopen() and tried to use it with Browser() but it doesn't work Here is the code I'm using for urlopen passman = mechanize.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, url, user, password) auth_NTL...