Try this
Step 1: Go to Settings
Step 2: Click 'Apps'
Step 3: Click on 'Defaults apps'
Step 4: Click 'Choose default apps by file type'
Step 5: Scroll down to '.py' file types
Step 6: Click on 'Choose a default' if there is no default app, otherwise click the current default app and choose 'spyder'.
Done!