SQLAlchemy docs (setting Column defaults) - How is this line syntactically valid python?

195
December 15, 2017, at 06:34 AM

While reading through the SQLAlchemy documentation for Column constructor arguments, I found this code example (edited to remove unrelated calls to Column(), see the full example at the link):

t = Table("mytable", meta,
    # define 'key' to pull its default from the 'keyvalues' table
    Column('key', String(20), default=keyvalues.select(keyvalues.c.type='type1', limit=1))
)

Specifically, I do not understand how the default argument of Column() is valid Python. To both me and to my Python interpreter, keyvalues.select(keyvalues.c.type='type1', limit=1) appears to be using the expression keyvalues.c.type as the name of a keyword argument to keyvalues.select().

The documentation glosses over the definition of keyvalues, and I haven't been able to find a way of defining keyvalues that stops my interpreter from throwing a SyntaxError.

Am I correct that expressions cannot be used as keywords? Is this actually valid syntax for a different reason? If it is valid syntax, could you provide a short example showing the necessary code to make it valid?

Rent Charter Buses Company
READ ALSO
Django models for non user-created tables

Django models for non user-created tables

I am working on a project using veekun's pokedex sqlite database, and using it in a django project

261
I want to select specific range of indexes from an array

I want to select specific range of indexes from an array

I have numpy array, and I want to select a number of values based on their index numberI am using Python3

200
Program abruptly shutting off Raspberry Pi

Program abruptly shutting off Raspberry Pi

so I have a Python program on my Raspberry Pi running on an infinite while loop that takes an image from the camera every second

199
Windows APIs to track time spent on desktop apps and web pages [on hold]

Windows APIs to track time spent on desktop apps and web pages [on hold]

I'm looking for C#NET APIs or libraries that I can use in building a windows app (that runs in the background or minimized) to track the amount of time spent by users on each application and site

197