<div dir="ltr">I believe the Python way is not to use getFoo() or setFoo(), but obj.foo directly.<div><br></div><div>You may however like to name the actual variable something else entirely and expose foo using the property decorator  if you feel the need to manage it within some sane parameters.<br></div><div><br></div><div>- Sandip</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 11, 2016 at 10:51 AM, Craig Rodrigues <span dir="ltr"><<a href="mailto:rodrigc@freebsd.org" target="_blank">rodrigc@freebsd.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>In various Python libraries and projects, I have seen that Foo.bar = 10</div><div>is the preferred convention, since as you mentioned, there are no private/protected</div><div>keywords in Python.</div><div><br></div><div>You may want to look at the Python attrs library, which offers some interesting</div><div>ways to use classes with attributions:</div><div><br></div><div><a href="https://glyph.twistedmatrix.com/2016/08/attrs.html" target="_blank">https://glyph.twistedmatrix.<wbr>com/2016/08/attrs.html</a><br></div><div><a href="https://attrs.readthedocs.io" target="_blank">https://attrs.readthedocs.io</a><br></div><div><br></div><div>--</div><div>Craig<div><div class="h5"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 11, 2016 at 2:29 AM, Braun Brelin <span dir="ltr"><<a href="mailto:bbrelin@gmail.com" target="_blank">bbrelin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello all,<div><br></div><div>I just wanted to get the list's opinion on something. </div><div><br></div><div>Since Python doesn't really have the concept of private and protected</div><div>attribute access protections a la Java or C++ (Yes, I know you can use</div><div>the __ and _ prefixes to declare something private or protected in</div><div>Python, but that really only does name-mangling on the attribute name</div><div>rather than explicitly disallow access to the attribute from outside the class), is it better to still access the attribute directly a la </div><div>Foo.bar = 10 or use a setter/getter approach like Foo.setBar(10)?<br></div><div>It seems to me that option one is better, especially if I can use a descriptor with the attribute. </div><div><br></div><div>Any thoughts?</div><div><br></div><div>Thanks,</div><div><br></div><div>Braun Brelin</div></div></blockquote></div></div></div></div></div></div>
<br>______________________________<wbr>_________________<br>
Baypiggies mailing list<br>
<a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>
To change your subscription options or unsubscribe:<br>
<a href="https://mail.python.org/mailman/listinfo/baypiggies" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/baypiggies</a><br></blockquote></div><br></div>