I am using enums and string.join() method to form a help string in Python:
I have the following code segment:
from enum import Enum
class Estimators(Enum):
rsac = 1
msac = 2
Now, I create a help string as follows:
est_help = 'Valid options are: [' + (str(i.name) + ', ' for i in Estimators) + ']'
This throws a TypeError exception as:
TypeError: cannot concatenate 'str' and 'generator' objects
I was wondering what I am doing wrong. The i.name is of string type.
(str(i.name) + ', ' for i in RobustEstimators)is a generator, so you can't add it to a string, exactly as the error message tells you. Did you mean', '.join(...)?est_help = 'Valid options are: [' + str(i.name) + ', ' for i in RobustEstimators + ']'?+ ']', I thought that it's a list comprehension. Sorry for this :P