The question doesn’t seem to be PyTorch-related so e.g. StackOverflow might be a better place to ask these Python questions in order to get a faster response. 
Also, your code formatting is unfortunately still not working (click on the “Preformatted text” button to add code snippets).