Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8367577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:11:43+00:00 2026-06-09T13:11:43+00:00

This Class should accept an argument to the Keys property, but when I try

  • 0

This Class should accept an argument to the Keys property, but when I try MyUserInstance.Keys('foo'), it doesn’t work. Instead it says TypeError: Keys() takes exactly 2 arguments (1 given). How is it wrong?

# User
class User:
    def __init__(self,
            Username = 'New User',
            **kwargs):
        self.Username = Username
        self.__dict__.update(kwargs)

    @property
    def Keys(self,collection):
        try:
            return {k:1 for k in db.UserPreferences.find_one({
                'Type':'VisibleKeys',
                'UserID':self._id,
                'CollectionName':collection})['Keys']}
        except:
            return None

    def __repr__(self):
        return '<User: "%s">' % self.Username
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:11:44+00:00Added an answer on June 9, 2026 at 1:11 pm

    Keys is a bound property of an instance of your class. That means you must first have an instance.

    user = User()
    user.Keys = "foo"
    

    Also get rid of the collection arg. Thats a getter. You can only define the arg on setters.

    It looks like it really should be just a method. So actually, get rid of the property decorator and use: user.keys(“foo”)

    You can read about how to define getter, setter, and deleter here: http://docs.python.org/library/functions.html#property

    Also python convention would normally reserve the uppercase for class names. It would be User.keys

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my Selenium browser test class (a derived one, but should not be
how should I document this piece of code: // Is this class? colors =
Scala programmer should have known that this sort of writing : class Person{ var
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
Suppose I have a class with a string instance attribute. Should I initialize this
what am I doing wrong in this code.. I should get the class name
[NSThread detachNewThreadSelector:@selector(colourChange) toTarget:del withObject:nil]; This should call the colourChange method in the class' delegate(del)
There are many classes having this provider suffix. (Data,membership,modelmetadata,...). When should be a class
Consider this... I am writing a class named Cache which will accept either a
I should get this by now, but I'm just not getting it yet. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.