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'))
'google.com'
>>> str(Domain.parse_url("http://pybit.es"))
'pybit.es'
>>> domain = Domain.parse_email("[email protected]")
>>> type(domain)
<class 'constructors.Domain'>
>>> str(domain)
'pybit.es'

Good luck and keep calm and code more Python!

Login and get coding
go back Intermediate level
Bitecoin 3X

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

We use Python 3.8