avatar Bite 313. Alternative constructors

In this Bite your are provides with a Domain class and a DomainException custom exception class.

You will add some validation to the current constructor to check if a valid domain name is passed in.

Next you will add a __str__ special method to represent the object (basically the name attribute) and you will write two classmethods to construct domains:

1. from a URL

2. from an email

Here you can see the code in action (also make sure you check out the tests):

>>> from constructors import Domain
>>> str(Domain('google.com'))
>>> str(Domain.parse_url("http://pybit.es"))
>>> domain = Domain.parse_email("[email protected]")
>>> type(domain)
<class 'constructors.Domain'>
>>> str(domain)

Good luck and keep calm and code more Python!

Login and get coding
go back Intermediate level
Bitecoin 3X

33 out of 34 users completed this Bite.
Will you be Pythonista #34 to crack this Bite?
Resolution time: ~49 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 6.67 on a 1-10 difficulty scale.
» Up for a challenge? 💪

We use Python 3.8