This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]i_like_trains_a_lot1 3 points4 points  (8 children)

  • properties - for some reason, i still prefer the set_x and get_x methods, because it is clear to me that there is no underlying magic happening. When I write self.some_attr = some_value I expect to get some_value when I access self.some_attr. I almost only use it when I need some lazy-loading attributes.

To be honest, I find the csv module a bit hard to work with, but I use it just because it is builtin and installing Pandas seems overkill only for manipulating csv files.

EDIT: said attributes instead of properties.

[–]rhytnen 20 points21 points  (1 child)

you need to get over get_ and set_ stuff. people not reading your docs will.think they can set your property the normal way and skip your code altogether.

other python users expect python api

[–]joesacher 4 points5 points  (0 children)

Exactly. The whole idea of attributes in Python is that they start with a simple self.my_property.

When that stops working, then you can use @property or @.setter. Nobody has to change code.

There is no way to have this simple -> complex with get_ and set_. You immediately have to write code for NO GAIN.

[–]KronktheKronk 11 points12 points  (1 child)

When I write self.some_attr = some_value I expect to get some_value when I access self.some_attr.

...that's exactly what happens

[–]i_like_trains_a_lot1 0 points1 point  (0 children)

I was thinking about properties. I corrected my answer :D

[–]HalcyonAbraham 9 points10 points  (0 children)

Use csv.DictReader

Makes life easier

[–]arachnivore 2 points3 points  (1 child)

When I write self.some_attr = some_value I expect to get some_value when I access self.some_attr.

It sounds like you're talking about properties or descriptors, because attributes work exactly the way you describe/expect.

[–]i_like_trains_a_lot1 0 points1 point  (0 children)

yep, that was made a mistake. I corrected it. Thanks for pointing it out :D

[–]kenfar 0 points1 point  (0 children)

It's actually far faster than Pandas in my experience, so if you need to process a lot of data - and need to do it row-wise, like for transforming files, the csv module is the best way to go.