Skip to content
C

Custom Validating Descriptor

Mediumpython

Create a descriptor class NonEmptyString that raises a ValueError if an assigned string is empty, and use it as the name attribute on a Product class.

Approach: implement _setname, get, and set__ on NonEmptyString, attach it as Product.name, then try constructing a Product with the given input and report success or the validation error.

Input: One line: a name (possibly empty).

Output: One line: "Product created: <name>" on success, or "Error: <message>" if the name is empty.

Input (stdin)

Output

Run your code to see output here...