python

Pure Python implementation of MongoDB?

Looking around for a noSQL database implementation that has an ORM syntax (pref. like Django's), lets me store and retrieve nested dictionary attributes but written entirely in Python to ease deployment and avoids Javascript syntax for map/reduce. Even better if it has a context-aware (menus), python-based console, as well as being able ...

Is there a DotNetOpenAuth equivalent that runs on a LAMP stack?

I really love the way the StackExchange family of sites allow someone to log in using their OpenID or OAuth provider, which has been open-sourced as DotNetOpenAuth. This is absolutely wonderful, but I am unable to use it on a *AMP stack. Is there anything analogous that runs in PHP, Perl, Python or Ruby? ...

understanding zip function

All discussion is about python 3.1.2; see Python docs for the source of my question. I know what zip does; I just don't understand why it can be implemented like this: def zip(*iterables): # zip('ABCD', 'xy') --> Ax By iterables = map(iter, iterables) while iterables: yield tuple(map(next, iterables)) Let's say I ...

Clicking links by regexp in python selenium

I've been looking around and trying to find a way to click on a link in selenium that's matched by a regexp. Here is the code that works; from selenium import selenium sel = selenium("localhost", 4444, "*chrome", "http://www.ncbi.nlm.nih.gov/") sel.start() sel.open('/pubmed') sel.type("search_term", "20032207[uid]") sel.click("search")...

How do I escape the - character in SQLite FTS3 queries?

I'm using Python and SQLAlchemy to query a SQLite FTS3 (full-text) store and I would like to prevent my users from using the - as an operator. How should I escape the - so users can search for a term containing the - (enabled by changing the default tokenizer) instead of it signifying "does not contain the term following the -"? ...

sorting by first group element in python

Hi, I was wondering how can I make python order my collection of tuples so that first similar items would appear grouped and groups ordered by first item. order group 3 1 4 2 2 2 1 1 After sort order group 1 1 3 1 2 2 4 2 Python list unordered = [(3, 1), (4, 2), (2, 2), (1, 1)] ...

Translating PHP’s preg_match_all to Python

Can I have a translation of PHP’s preg_match_all('/(https?:\/\/\S+)/', $text, $links) in Python, please? (ie) I need to get the links present in the plain text argument in an array. ...

Can this Python postfix notation (reverse polish notation) interpreter be made more efficient and accurate?

Here is a Python postfix notation interpreter which utilizes a stack to evaluate the expressions. Is it possible to make this function more efficient and accurate? #!/usr/bin/env python import operator import doctest class Stack: """A stack is a collection, meaning that it is a data structure that contains multiple el...

Trouble getting code parameter on facebook oauth callback

Hello, I'm writing a Django app requesting permission to post on facebook. I can access authorization and callback, but I can't get the parameter 'code' that facebook needs to continue with oauth. def connect_fb(request): return redirect("https://graph.facebook.com/oauth/authorize?" +"client_id=MY_ID&" +...

MySQL: Get dates with and without category/subcategory in ONE query (and sorted)

I have a database with 4 tables with this structure: categories subcategories dates events We have events, that can have multiple dates. Events are categorized in categories and subcategories, but can have only a category and no subcategory, too. I tried this query: SELECT t.id as sortid, t.numprint, s.titel, s.int...

SQL templating engine to mix SQL with dynamic language? (similar to Ruby's erb)

Has anyone comes across a SQL templating engine which allows one to mix SQL with a dynamic language like Ruby or Python? I'm looking for something similar to Ruby erb templates. For example, in Ruby on Rails you can have various templates for a view: customers.html.erb (html + ruby) customers.js.erb (javascript + ruby) Though I want s...

plotting histograms whose bar heights sum to 1 in matplotlib

I'd like to plot a normalized histogram from a vector using matplotlib. I tried the following: plt.hist(myarray, normed=True) as well as: plt.hist(myarray, normed=1) but neither option produces a y-axis from [0, 1] such that the bar heights of the histogram sum to 1. I'd like to produce such a histogram -- how can I do it? thanks...

django error: 'unicode' object is not callable

hi all, im attempting to do the django tutorial from the django website, and ive run into a bit of an issue: ive got to adding my __unicode__ methods to my models classes, but when ever i try to return the objects of that model i get the following error: in __unicode__ return self.question() TypeError: 'unicode' object is not call...

How do I replace the current working MySQL database with a .sql file?

Hello, I'm trying to restore the current working database to the data stored in a .sql file from within Django. Whats the best way to do this? Does django have an good way to do this or do I need to grab the connection string from the settings.py file and send command line mysql commands to do this? Thanks for your help. ...

Converting a python numeric expression to LaTeX.

I need to convert strings with valid python syntax such as: '1+2**(x+y)' and get the equivalent LaTeX: $1+2^{x+y}$ I have tried sympy's latex function but it processes actual expression, rather than the string form of it: >>> latex(1+2**(x+y)) '$1 + 2^{x + y}$' >>> latex('1+2**(x+y)') '$1+2**(x+y)$' but to even do this, it requ...

How to build 32bit python 2.6 on 64bit Linux ?

Hi folks, I'm stuck for a full afternoon now trying to get python to build in 32bit mode. I run a 64bit Linux machine with openSUSE 11.3, I have the necessary -devel and -32bit packages installed to build applications in 32bit mode. The problem with the python build seems to be not in the make run itself, but in the afterwards run of s...

Please Help: IPython for Emacs on Windows crashes

Questions Update: Why there is no In[1]: prompt? Please see the following output of IPython command line in Emacs. Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] Type "copyright", "credits" or "license" for more information. IPython 0.10 -- An enhanced Interactive Python. ? -> Introduction and ove...

Comparing Python lists

Hi, I have several long lists in python and have compare them and find the lists that are equal to each other except the last elements in the them. Which is the fastest way? ...

Pylons + Mako -- Access POST data from templates

How can I access my request.params post data from my Mako template with Pylons? ...

Descriptor that auto-detects the name of another attribute passed to it?

Can a descriptor auto-detect the name of an object passed to it? class MyDecorator( object ): def __init__(self, wrapped): # Detect that wrapped's name is 'some_attr' here pass class SomeClass( object ): some_attr = dict() wrapper = MyDecorator( some_attr ) ...