0

This works:

self.NN0d = [(0, 1, np.array([0, -1]))]

This does not work:

name = str("NN{}d".format(0))
self.name = [(0, 1, np.array([0, -1]))]

I'm not sure why exactly...

Ultimately, I would like to define multiple class attributes in a loop, like so:

for i in range(0, 14, 2):
    name = str("NN{}d".format(i))
    self.name = [(i, i+1, np.array([0, -1]))] 
martineau
  • 119,623
  • 25
  • 170
  • 301
Bart
  • 123
  • 3
  • 1
    `NN0d` is not a string, while your `name` is a string `"NN0d"`. Try `setattr` and `getattr` - https://stackoverflow.com/a/9561207/11516012 – h4z3 Jul 29 '19 at 10:11
  • Thank you! I think this answers my question: for i in range(0, 14, 2): setattr(self, "NN{}d".format(i), [(i, i+1, np.array([0, -1]))]) – Bart Jul 29 '19 at 10:18

0 Answers0