Daily Dose of Data Science

Share this post

Use Slotted Class To Improve Your Python Code

www.blog.dailydoseofds.com

Use Slotted Class To Improve Your Python Code

Avi Chawla
Nov 17, 2022
4
2
Share

If you want to fix the attributes a class can hold, consider defining it as a slotted class.

While defining classes, __๐˜€๐—น๐—ผ๐˜๐˜€__ allows you to explicitly specify the class attributes. This means you cannot randomly add new attributes to a slotted class object. This offers many advantages.

For instance, slotted classes are memory efficient and they provide faster access to class attributes. What's more, it also helps you avoid common typos. This, at times, can be a costly mistake that can go unnoticed.

Read more: StackOverflow.

Share this post on LinkedIn: Post Link.

Thanks for reading Daily Dose of Data Science! Subscribe for free to learn something new and insightful about Python and Data Science every day. Also, get a Free Data Science PDF (250+ pages) with 200+ tips.


I like to explore, experiment and write about data science concepts and tools. You can read my articles on Medium. Also, you can connect with me on LinkedIn.

4
2
Share
Previous
Next
2 Comments
Lee Prentice
Nov 18, 2022Liked by Avi Chawla

Just wanted to say thank you for putting these daily doses out. They are really fantastic, and I look forward to reading them! They are really helpful!

Expand full comment
Reply
1 reply by Avi Chawla
1 more commentโ€ฆ
Top
New
Community

No posts

Ready for more?

ยฉ 2023 Avi Chawla
Privacy โˆ™ Terms โˆ™ Collection notice
Start WritingGet the app
Substackย is the home for great writing