I am trying to write a class that allows users to register on a platform with a username, but checks that this username does not exist in the database.
I have this code:
class Freelancer:
"""Leaving this blank for now while I explore the functionality """
number_of_sales = 0
available_niches = ["Graphic design", "Art", "Data Analysis", "Music", "Business", "Writing and Translations"]
usernames = []
def __init__(self, username):
self.username = _check_username(username)
def _check_username(self, username):
if self.username in Freelancer.usernames:
print("This username already exist on our database, consider choosing another one")
else:
self.username = username
Freelancer.usernames.append(self.username)
print("You have successfully setup a username on our platform")
which I tested like so:
David = Freelancer("dave23")
But I got an exception: NameError: name '_check_username' is not defined
. What is wrong with the code? How can I call a private method from __init__
?