GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — example-code-2e/11-pythonic-obj/slots.rst at master · FerMatPy/example-code-2e

Expand file tree

/

slots.rst

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
52 lines (47 loc) · 1.07 KB
/

slots.rst

Copy path

File metadata and controls

52 lines (47 loc) · 1.07 KB
Raw
Copy raw file
Download raw file
Edit and raw actions

# tag::PIXEL[] >>> class Pixel: ... __slots__ = ('x', 'y') # <1> ... >>> p = Pixel() # <2> >>> p.__dict__ # <3> Traceback (most recent call last):

...

AttributeError: 'Pixel' object has no attribute '__dict__' >>> p.x = 10 # <4> >>> p.y = 20 >>> p.color = 'red' # <5> Traceback (most recent call last):

...

AttributeError: 'Pixel' object has no attribute 'color'

# end::PIXEL[]

# tag::OPEN_PIXEL[] >>> class OpenPixel(Pixel): # <1> ... pass ... >>> op = OpenPixel() >>> op.__dict__ # <2> {} >>> op.x = 8 # <3> >>> op.__dict__ # <4> {} >>> op.x # <5> 8 >>> op.color = 'green' # <6> >>> op.__dict__ # <7> {'color': 'green'}

# end::OPEN_PIXEL[]

# tag::COLOR_PIXEL[] >>> class ColorPixel(Pixel): ... __slots__ = ('color',) # <1> >>> cp = ColorPixel() >>> cp.__dict__ # <2> Traceback (most recent call last):

...

AttributeError: 'ColorPixel' object has no attribute '__dict__' >>> cp.x = 2 >>> cp.color = 'blue' # <3> >>> cp.flavor = 'banana' Traceback (most recent call last):

...

AttributeError: 'ColorPixel' object has no attribute 'flavor'

# end::COLOR_PIXEL[]

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.