Skip to content

python_general

Marcel Schmalzl edited this page Jan 17, 2025 · 2 revisions

Python General

Inspect objects

Print the structure of a whole object via pprint.pprint(vars(...)):

import pprint

# Object to inspect
class PhysicalFunction:
    def __init__(self):
        self.name = "ExampleFunction"
        self.parameters = {
            "param1": 10,
            "param2": 20,
            "param3": [1, 2, 3, 4, 5],
            "param4": {"subparam1": "value1", "subparam2": "value2"}
        }
        self.description = ("This is a detailed description of the ExampleFunction. "
                            "It includes multiple parameters and nested structures.")

attributes = pprint.pprint(vars(PhysicalFunction()))

Output:

{'description': 'This is a detailed description of the ExampleFunction. It '
                'includes multiple parameters and nested structures.',
 'name': 'ExampleFunction',
 'parameters': {'param1': 10,
                'param2': 20,
                'param3': [1, 2, 3, 4, 5],
                'param4': {'subparam1': 'value1', 'subparam2': 'value2'}}}

Python 3

(un)fold
Snippets
General
Libs

Linux/bash

(un)fold
Guides
Scripts

Git

(un)fold

C/C++

(un)fold

Video

(un)fold

Databases

(un)fold

Misc

(un)fold

Windows

(un)fold

Mac

(un)fold

SW recommendations

(un)fold

(Angular) Dart

(un)fold
Clone this wiki locally