Home Setting an attribute shortcut in python
Post
Cancel

Setting an attribute shortcut in python

Published on: 5th September 2022

This post was created while writing my Up & Running with Polars course. Check it out here with a free preview of the first chapters

There’s a tension between having clear verbose code and code that’s quick and easy to type.

Verbose code is great for production, but when doing rapid data exploration in ipython or jupyter you really want something quick.

To address this you can use setattr to set up an alias for your function. Code to set your attribute shortcut In my case I use value_counts() a lot, so I alias the function with vc. This means it goes from 12 characters to 2.

It’s also good to drop the underscore - these double press chars put a lot more stress on your fingers when repeated!

H/T Ritchie Vink for sharing this method with me.

Follow me if you’re interested in learning more about high performance data processing in python!

Learn more

Want to know more about Polars for high performance data science? Then you can:

or let me know if you would like a Polars workshop for your organisation.

This post is licensed under CC BY 4.0 by the author.