Advertisement
silver2row

from docs.python.org and my changes...

Oct 30th, 2022
1,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. from datetime import date
  2. from time import sleep
  3. from ServoTwo import *
  4.  
  5. # Most of this is directly from the python.org website under the docs. sections.
  6.  
  7. class FirstOfMonthDate(date):
  8.     "Always choose the first day of the month"
  9.     def __new__(cls, year, month, day):
  10.         return super().__new__(cls, year, month, 1)
  11.  
  12. class NamedInt(int):
  13.     "Allow text names for some numbers"
  14.     xlat = {'zero': 0, 'one': 1, 'ten': 10}
  15.     def __new__(cls, value):
  16.         value = cls.xlat.get(value, value)
  17.         return super().__new__(cls, value)
  18.  
  19. class TitleStr(str):
  20.     "Convert str to name suitable for a URL path"
  21.     def __new__(cls, s):
  22.         s = s.lower().replace(' ', '-')
  23.         s = ''.join([c for c in s if c.isalnum() or c == '-'])
  24.         return super().__new__(cls, s)
  25.  
  26. NamedInt('ten')
  27. TitleStr('monkey men stealing my hovercraft!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement