python: set 'sw' cleverly