Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Attributes
#1
I'm new to Python, and generally speaking am not trained as a programmer. I am using version 3.7 on Windows 8.1, and most of my work so far has been GUI related with wxPython (4.0.3). I have read various parts of PEP 8 in an attempt to learn to program "Pythonically" and so far, I think I'm doing a reasonable job.

My question has to do with the lack of private attributes, and whether it is necessary or "pythonic" to try to limit the numbers of publicly available attributes defined like: self.attribute = "string". To make various aspects of the class available to instance methods, I'm finding myself prepending almost every attribute with self. The result is that when writing code, intellisense presents everything from strings to sizers as available attributes from outside the class, even though in most cases they aren't needed outside the class.

Does this only appear to be an issue due to the use of intellisense (I'm using VS Code as an IDE), or is there a bigger issue around public attributes that I should concern myself with? I have read numerous posts and articles about how to create private-like attributes using single and double underscores, but I don't have a feeling yet regarding if or where I should apply this technique, and how liberally I should do so.

Thanks in advance for the feedback.
Reply


Messages In This Thread
Python Attributes - by CanadaGuy - Nov-02-2018, 02:15 PM
RE: Python Attributes - by ichabod801 - Nov-02-2018, 02:33 PM
RE: Python Attributes - by CanadaGuy - Nov-02-2018, 02:41 PM
RE: Python Attributes - by Gribouillis - Nov-02-2018, 02:57 PM
RE: Python Attributes - by CanadaGuy - Nov-02-2018, 03:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Accessing method attributes of python class Abedin 6 703 Apr-14-2025, 07:02 AM
Last Post: buran
  Python the regex not getting any attributes sarath_unrelax 1 2,345 Dec-19-2019, 11:06 AM
Last Post: Larz60+
  Python QGIS tool that replaces layout text labels with attributes from an input table geodenn92 1 3,537 Aug-13-2019, 06:05 AM
Last Post: buran

Forum Jump:

User Panel Messages

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