SteveS
SteveS

Reputation: 4040

How to print all values of an object methods?

I have the output list of dir(requests) and I want to print all of the values.

Something like this:

from flask import Flask, request
for i in dir(request):
    print(i)
    print(request.i)

But it doesn't seem to work, please advise what I am missing?

Upvotes: 1

Views: 140

Answers (1)

mgostIH
mgostIH

Reputation: 466

i is a string here, you can't directly access methods like this, the getattr function is what has to be used:

for i in dir(request):
    print(i)
    print(getattr(request, i))

Upvotes: 3

Related Questions