Skip to content
Advertisement

sqlalchemy flush() and get inserted id?

I want to do something like this: But f.id is None when I try it. How can I get this to work? Answer Your sample code should have worked as it is. SQLAlchemy should be providing a value for f.id, assuming its an autogenerating primary-key column. Primary-key attributes are populated immediately within the flush() process as they are generated, and

What is the most efficient string concatenation method in Python?

Is there an efficient mass string concatenation method in Python (like StringBuilder in C# or StringBuffer in Java)? I found following methods here: Simple concatenation using + Using a string list and the join method Using UserString from the MutableString module Using a character array and the array module Using cStringIO from the StringIO module What should be used and

How to convert a nested Python dict to object?

I’m searching for an elegant way to get data using attribute access on a dict with some nested dicts and lists (i.e. javascript-style object syntax). For example: Should be accessible in this way: I think, this is not possible without recursion, but what would be a nice way to get an object style for dicts? Answer Update: In Python 2.6

Making sure that psycopg2 database connection alive

I have a python application that opens a database connection that can hang online for an hours, but sometimes the database server reboots and while python still have the connection it won’t work with OperationalError exception. So I’m looking for any reliable method to “ping” the database and know that connection is alive. I’ve checked a psycopg2 documentation but can’t

Can’t import Numpy in Python

I’m trying to write some code that uses Numpy. However, I can’t import it: I tried the suggestions in this question: and I searched for files named numpy in that path: But nothing came up. So… Are there any other places in which Python modules are commonly installed? How can I install numpy locally in my account, if it turns

Advertisement