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'))
>>> 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

90 out of 90 users completed this Bite.
Will you be Pythonista #91 to crack this Bite?
Resolution time: ~49 min. (avg. submissions of 5-240 min.)
Pythonistas rate 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