1

I want to have the column names of my sqlalchemy query but I do not find how I can do this.

I tried a few ways

first way I have tried was to make a new class, because the names had to be different of the column names

class DosierWeergave():
    def __init__(self, code_arg, year_registr, period_registr, staynum, status):
        self.Code_Arg = str(code_arg)
        self.Year_registr = str(year_registr)
        self.Period_registr = str(period_registr)
        self.Staynum = str(staynum)
        self.Status = str(status)

And then I maked an object of this

a = DosierWeergave(187,2010,4,"0000010000", "inbehandeling")

I get then the right names but not in the right order. Does anybody know how I can get the columnnames (class attributes) in the right order.

Another way was to use the function: columns.keys()

HeaderDosiers = Dosiers2.__table__.columns.keys()

but her I got all the column headers and I do not find how I can filter them has anybody an idea how I can fix this problems or has anybody got a better way to do it

1 Answer 1

1

What do you want to do with the column names; if you want to print them, create a str function:

def __str__(self):
    str  = 'Code Arg', self._code_arg
    str += 'Year_registr', self.Year_registr
    ...

    return str

I would not suggest using reflection.

Sign up to request clarification or add additional context in comments.

1 Comment

I want to use them for my column headers in my pyramid project and I am using therefor ZPT.tal:repeat

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.