It seems exec can’t work with locals().
  
      stackoverflow.com
  
  
      
    
  

  How does exec work with locals? 1



  python, python-3.x, exec, locals



  asked by
  
  
    ubershmekel
  
  on 12:18AM - 23 Sep 09 UTC


  
  
    
    
  
  


The below code works though.
for layer in range(1, len(num_units)):
    x = F.relu(getattr(self, f'conv{layer}')(x)