Python Forum
Listing Attributes of Objects & Classes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Listing Attributes of Objects & Classes
#2
You could define your own function, such as
def report(obj, name=None):
    name = name or 'obj'
    L = ['{} Object of Class {}'.format(name, type(obj).__name__)]
    for k, v in vars(obj).items():
        L.append('{}.{} = {}'.format(name, k, repr(v)))
    return '\n'.join(L)

print(report(london, 'london'))
Reply


Messages In This Thread
RE: Listing Attributes of Objects & Classes - by Gribouillis - Aug-27-2020, 06:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [solved] Classes, assign an attributes to a class not to instances.. SpongeB0B 4 1,126 May-20-2023, 04:08 PM
Last Post: SpongeB0B
  Listing directories (as a text file) kiwi99 1 950 Feb-17-2023, 12:58 PM
Last Post: Larz60+
  Read directory listing of files and parse out the highest number? cubangt 5 2,686 Sep-28-2022, 10:15 PM
Last Post: Larz60+
  Listing All Methods Of Associated With A Class JoeDainton123 3 2,480 May-10-2021, 01:46 AM
Last Post: deanhystad
  Listing files with glob. MathCommander 9 5,258 Oct-26-2020, 02:04 AM
Last Post: MathCommander
  Listing data from a list ebolisa 1 1,840 Sep-29-2020, 02:24 PM
Last Post: DeaD_EyE
  Getting attributes from a list containing classes midarq 2 2,282 Dec-03-2019, 12:42 AM
Last Post: midarq
  Listing groups tharpa 2 2,692 Nov-26-2019, 07:25 AM
Last Post: DeaD_EyE
  AWS lambda script help - Listing untagged volumes jutler 0 2,321 Feb-13-2019, 02:36 PM
Last Post: jutler
  Classes and Objects - question AI_ML_Neophyte 3 3,105 Dec-11-2018, 01:52 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020