Jump to content
  • Advertisement
Sign in to follow this  
Storyyeller

Python __slots__

This topic is 2532 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any reason to ever not use __slots__ in Python, besides the extra work of specifying your attributes? I searched online, but I couldn't find aything except vaue warnings about that it "breaks PIckle".

Share this post


Link to post
Share on other sites
Advertisement

Is there any reason to ever not use __slots__ in Python, besides the extra work of specifying your attributes? I searched online, but I couldn't find aything except vaue warnings about that it "breaks PIckle".


I'm not too familiar with __slots__ in Python. Can you tell us what you're trying to do, exactly?

For reference, here's the Python documentation on __slots__: http://docs.python.org/reference/datamodel.html#slots

Share this post


Link to post
Share on other sites

Does anyone know?


Like I said, what are you trying to do exactly? From my perspective, this is a rather obscure Python feature. If you want us to be able to answer your question, we need context.

Share this post


Link to post
Share on other sites

Well the idea is to save memory and improve performance. What I'm wondering is if there is any reason to ever not use them.


That's still pretty vague. We still don't know anything about your code.

Are you looking at this because you're experiencing a bottleneck in some code? Or are you asking about this purely from an academic/conceptual standpoint?

I think if you read through the Python docs on __slots__, you'll find pretty much everything you need to know about the effects/side effects.

As I mentioned above, this is a pretty obscure feature. If you're trying to solve a specific performance problem, run your code through a profiler (http://docs.python.org/library/profile.html, for example), then make your changes and see if there's an improvement.

Lastly, if you're worried about some functionality breaking, write tests! (If you're not writing test code already, start now.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!