Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import date
- from time import sleep
- from ServoTwo import *
- # Most of this is directly from the python.org website under the docs. sections.
- class FirstOfMonthDate(date):
- "Always choose the first day of the month"
- def __new__(cls, year, month, day):
- return super().__new__(cls, year, month, 1)
- class NamedInt(int):
- "Allow text names for some numbers"
- xlat = {'zero': 0, 'one': 1, 'ten': 10}
- def __new__(cls, value):
- value = cls.xlat.get(value, value)
- return super().__new__(cls, value)
- class TitleStr(str):
- "Convert str to name suitable for a URL path"
- def __new__(cls, s):
- s = s.lower().replace(' ', '-')
- s = ''.join([c for c in s if c.isalnum() or c == '-'])
- return super().__new__(cls, s)
- NamedInt('ten')
- TitleStr('monkey men stealing my hovercraft!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement