avatar Bite 313. Alternative constructors

In this Bite your are provided 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

94 out of 94 users completed this Bite.
Will you be the 95th person to crack this Bite?
Resolution time: ~48 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 6.25 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help