Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyDescript
#python 3.6.9 #PyDescript #MustChar code credit goes to internet sites on python #rest of the code is created by Rezaul Hoque on January 21,2022; #contact: jewelmrh@yahoo.com,Dhaka, Bangladesh #note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; class MustChar: def __set_name__(self, garden, name): print(f'__set_name__ was called with garden={garden} and name={name}') self.property_name = name def __get__(self, instance, garden): print(f'__get__ was called with instance={instance} and garden={garden}') if instance is None: return self return instance.__dict__[self.property_name] or None def __set__(self, instance, value): print(f'__set__ was called with instance={instance} and value={value}') if not isinstance(value, str): raise ValueError(f'The {self.property_name} must a string') if len(value) == 0: raise ValueError(f'The {self.property_name} cannot be empty') instance.__dict__[self.property_name] = value class Garden: name = MustChar() location = MustChar() @property def row(self): return self._row @row.setter def row(self,val): if not isinstance(val,int): raise ValueError(f'It must be a number.') self._row = val g = Garden() print(g.__dict__) g.name='The Garden' g.location= 'Backyard' g.row= 2 print(g.__dict__)
run
|
edit
|
history
|
help
0
HW. InsertionSort in Descending order
IP Networks splitting calculator
Like.C.M.
Fiboncaci series in recursion
hi
Hello Dear
Gedanken Tests - inner Class, Struct ..
Ej2_python_204676887
Guessing game
word repeat