Reputation: 2101
in my helper.py I have a class and a function definition:
class Suites():
NAME_SUITE = ['NATE', 'TOM', 'TED', 'JAN', 'SAM']
def check_suite(name, suite):
my_suite = Suites[suite] #I want my_suite to = ['NATE', 'TOM', 'TED', 'JAN', 'SAM']
return name in suite #I want to return True or False
and in views.py I'm trying to find out that user_in_suite is True
from .helper import check_suite
from .helper import Suites
def apps(request):
user_name = 'NATE'
suite_to_check = 'NAME_SUITE'
user_in_suite = check_suite(name=user_name, suite=suite_to_check)
But I'm getting an error for helper.py: 'classobj' object has no attribute '__getitem__
Upvotes: 0
Views: 32
Reputation: 164
def check_suite(name, suite):
my_suite = Suites.__dict__[suite] # __dict__ gives you access to the dictionary of class.
return name in my_suite
This should solve your problem.
Upvotes: 1