1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-28 13:55:08 +03:00
Files
libgpiod/bindings/python/examples/gpiodetect.py
Bartosz Golaszewski 1d87088b1e bindings: python: examples: close chip objects where needed
Unlike the C++ bindings: we can't expect the python runtime to call
the Chip object's destructor when all references are dropped. We need
to close each chip explicitly. Either call the close() method directly
or use controlled execution in all examples.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-07-31 14:30:46 +02:00

19 lines
457 B
Python
Executable File

#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of libgpiod.
#
# Copyright (C) 2017-2018 Bartosz Golaszewski <bartekgola@gmail.com>
#
'''Reimplementation of the gpiodetect tool in Python.'''
import gpiod
for chip in gpiod.ChipIter():
print('{} [{}] ({} lines)'.format(chip.name(),
chip.label(),
chip.num_lines()))
chip.close()