I am creating objects that I will eventually graph and using an api for the data. For the object attribute that I intend to graph, I am using a lambda function so that it will return the particular data I need for each new object.
The Lambda function passes two arguments through the api call, the first a
, references the objects .name
attribute, and works perfectly. When I try to reference the second lambda argument b
which references the objects .time
attribute, I get an error b is an invalid key argument for __new__()
default = 'USD'
asset1_input = 'ETH'
asset2_input = 'DAI'
class Asset:
def __init__(self, name, time, allocate, perform):
self.name = name
self.time = time
self.allocate = allocate
self.perform = perform(name, time)[name][default]
perform = lambda a, b : cryptocompare.get_historical_price(a, 'USD', datetime.today() - timedelta(b=5))
asset1 = Asset(asset1_input, 'days', .2, perform)
print(asset1.perform)
datetime
is expecting days or weeks. If I manually put one of these in then it works fine. Part of the problem may be that datetime isn't expecting a string days
, its just expecting days, however when I put days in as the value for time, I get days undefined
. Was considering an if
statement and a for
loop in the lambda function (if some input == 'days'
, and a for
loop to iterate the days
value) however other stack posts mentioned that you cant iterate with a for loop in lambda function.