
I am inviting the community members to share the best and the coolest Python tricks you know. Please post only general tips / techniques and not the whole scripts. :)
Let's see what you come up with.
This trick is web2py related, but I love the core of it so much I think it's worth sharing:
db._common_fields.append(Field('request_tenant', default=request.env.http_host,readable=False, writable=False))
This line adds a field 'requesttenant' to every database table declared using pyDAL afterwards on that db connection. On each crud operation through pyDAL on that connection it will only work on records which have the defaulttenant set to the default value. In effect, you've just patched up your web app to be available under different domain names without conflicting with each other.
Very useful is a logging decorator. Decorate a python method and uses standard python logging library. Blackout parameters in the logfile when sensitive data goes through them. Easy for webserver debugging and api troubleshooting. source
Misael Taveras
#JSDev. Coffee :3 @taverasmisael anywhere else.
The one I use the most, is for create a simple HTTP python server for my web development, with the simple command in the terminal: "python -m http.server [port]" :D