Python: Data Object or class

Posted by arg20 on Stack Overflow See other posts from Stack Overflow or by arg20
Published on 2012-10-06T15:13:58Z Indexed on 2012/10/06 15:37 UTC
Read the original article Hit count: 211

Filed under:
|
|

I enjoy all the python libraries for scraping websites and I am experimenting with BeautifulSoup and IMDB just for fun.

As I come from Java, I have some Java-practices incorporated into my programming styles. I am trying to get the info of a certain movie, I can either create a Movie class or just use a dictionary with keys for the attributes.

My question is, should I just use dictionaries when a class will only contain data and perhaps almost no behaviour? In other languages creating a type will help you enforce certain restrictions and because of type checks the IDE will help you program, this is not always the case in python, so what should I do?

Should I resort to creating a class only when there's both, behaviour and data? Or create a movie class even though it'll probably be just a data container?

This all depends on your model, in this particular case either one is fine but I'm wondering about what's a good practice.

© Stack Overflow or respective owner

Related posts about python

Related posts about class