Python Forum
when to make attributes private?
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
when to make attributes private?
#3
That's rather odd. Getters and setters don't make sense in Python. Since there are no private attributes (such as those in Java), they don't provide any security. Therefore all they can do is slow things down.

I'm not even sure why they are using the term 'private attribute'. If you really need security in Python, as in you need to make sure foo.spam changes every time foo.eggs changes, you use properties.

I do often provide ways for others to not have to access the attributes of the class directly, but I do this to make my classes easier to use. For example, say I have an class that's has a list attribute and some extra tracking attributes. I will override __iter__ so you can just do for knight in round_table: rather than for knight in round_table.knights:.

What is the name of the book you are using?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
when to make attributes private? - by sneakyimp - Jan-10-2019, 01:08 AM
RE: when to make attributes private? - by stullis - Jan-10-2019, 02:48 AM
RE: when to make attributes private? - by sneakyimp - Jan-10-2019, 10:10 PM
RE: when to make attributes private? - by ichabod801 - Jan-10-2019, 02:50 AM
RE: when to make attributes private? - by snippsat - Jan-11-2019, 04:04 AM
RE: when to make attributes private? - by snippsat - Jan-11-2019, 06:11 PM
RE: when to make attributes private? - by snippsat - Jan-11-2019, 07:13 PM
RE: when to make attributes private? - by nilamo - Jan-11-2019, 07:13 PM
RE: when to make attributes private? - by sneakyimp - Jan-21-2019, 02:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Lint and private var names PatM 1 726 Dec-15-2022, 05:08 PM
Last Post: deanhystad
  Unable to import Private Repo using setup.py Bob786 1 1,783 Sep-02-2021, 04:19 PM
Last Post: snippsat
  python 3 dns lookup private domain didact 1 2,607 Sep-19-2020, 06:01 PM
Last Post: bowlofred
  [split] Помощь по приватным ключам/Private key help sairam17519 0 1,624 Sep-07-2020, 12:55 PM
Last Post: sairam17519
  Download file from Private GitHub rep vinuvt 0 2,000 Jul-27-2020, 11:38 AM
Last Post: vinuvt
  Private package distribution abomination disadvantages research andreir 2 2,194 May-07-2020, 12:32 AM
Last Post: andreir
  Помощь по приватным ключам/Private key help vlrubl777 5 6,059 Mar-15-2019, 08:16 PM
Last Post: vlrubl777
  Fetching private ip address from instances of an autoscaling group deepsonune 0 3,301 May-18-2018, 10:32 AM
Last Post: deepsonune
  Inheritance private attributes vaison 5 12,876 May-03-2018, 09:22 AM
Last Post: vaison
  Can access class private variable? Michael 2 7,211 Aug-11-2017, 01:59 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020