Skip to content

astuple method #77

Closed
Closed
@Insoleet

Description

@Insoleet

Hello,

For the usage of attr with DB API 2.0 libraries (like Sqlite3), it would be great to have a astuple method.

This method would return the object values in a tuple, ordered by the order of declaration of it's attributes.

For example we could do things like this :

import sqlite3
import attr

@attr.s()
class Foo:
    a = attr.ib()
    b = attr.ib()

foo = Foo(2, 3)
con = sqlite3.connect(":memory:")
with con:
    con.execute("INSERT INTO foo VALUES (?, ?)", attr.astuple(foo))

This would be useful for DB API libraries but also for other needs probably.

What is your opinion about it ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions