Feb-21-2021, 05:57 AM
(This post was last modified: Feb-21-2021, 05:57 AM by deanhystad.)
You can look up attributes by name.
class ChessThing(): """Standing for chess which I do not have""" def __init__(self): self.BLACK = 100 self.WHITE = 200 self.A0 = 0 self.A1 = 1 self.A2 = 2 self.A3 = 3 self.A4 = 4 self.A5 = 5 self.A6 = 6 self.A7 = 7 chess = ChessThing() # Get attributes from chess using the attribute name colors = [getattr(chess, color) for color in ['BLACK', 'WHITE']] squares = [getattr(chess, f'{r}{c}') for r in ['A'] for c in range(8)] print(colors) print(squares)
Output:[100, 200]
[0, 1, 2, 3, 4, 5, 6, 7]
Before doing that I would exhaust all efforts to see if there is any kind of collection for the A0..H7. But if you have to, you can get all 64:squares = [getattr(chess, f'{r}{c}') for r in ['ABCDEFGH'] for c in range(8)]