How to access the "params" tuple?
-
Hi there,
I started with the Quickstart tutorials and found some confusing code (see attached). The "params" tuple is created with two separate tuples inside. However, I can access these inside tuples by typing params.maperiod . However, if I rename params to another name I cannot access them anymore.class TestStrategy(): params = ( ('maperiod', 15), ('printlog', False), ) def log(self, txt, dt=None, doprint=False): if self.params.printlog or doprint: dt = dt or self.datas[0].datetime.date(0) print('%s, %s' % (dt.isoformat(), txt))
-
I don't think you should rename the variable params as it is part of the default strategy that you are inheriting. You can also access it simply with .p like below:
self.p.printlog
-
@niklay said in How to access the "params" tuple?:
I started with the Quickstart tutorials and found some confusing code (see attached). The "params" tuple is created with two separate tuples inside. However, I can access these inside tuples by typing params.maperiod .
What's exactly the confusing part? You declare
params
(which you can also declare as adict
) and you can access them. It's a declarative style. As pointed out by @Laurent-Michelizza , there is a shorhand notation whereparams
is shortened top
@niklay said in How to access the "params" tuple?:
However, if I rename params to another name I cannot access them anymore.
Of course. How are you expecting the platform to know which
params
have been defined if you give the declaration a different name?