Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    I read the code about backtrader/utils/autodict/AutoDict,but find something maybe wrong...

    General Code/Help
    2
    2
    90
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • tianjixuetu
      tianjixuetu last edited by

      class AutoDict(dict):
          
          _closed = False
      
          def _close(self):
              self._closed = True
              for key, val in self.items():
                  if isinstance(val, (AutoDict, AutoOrderedDict)):
                      val._close()
      
          def _open(self):
              self._closed = False
      
          def __missing__(self, key):
              
              if self._closed:
                  raise KeyError
      
              value = self[key] = AutoDict()
              return value
      
          def __getattr__(self, key):
              
              if False and key.startswith('_'):
                  raise AttributeError
      
              return self[key]
      
          def __setattr__(self, key, value):
              
              if False and key.startswith('_'):
                  self.__dict__[key] = value
                  return
      
              self[key] = value
      
      

      your code about : if False and some_code: do something
      I think ,it will never run do something.

      mybe you just want write this code.
      mybe,you should replace "False" with "self._closed", I guess.

      I have used backtrader for more than one year to backtest my strategy, I also find many errors, so,I have to read the source code,to understand backtrader's framework and details.

      Anyway, thank you!

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        It's code that was tested for development and considered, was left there but nullified.

        @tianjixuetu said in I read the code about backtrader/utils/autodict/AutoDict,but find something maybe wrong...:

        I also find many errors

        Which you of course duly reported.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
        $(document).ready(function () { app.coldLoad(); }); }