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

  • Home
  • SEARCH
  • 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 8312093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:02:44+00:00 2026-06-08T20:02:44+00:00

I’ve got a question about defining functions and the self-parameter in python. There is

  • 0

I’ve got a question about defining functions and the self-parameter in python.

There is following code.

class Dictionaries(object):
    __CSVDescription = ["ID", "States", "FilterTime", "Reaction", "DTC", "ActiveDischarge"]

    def __makeDict(Lst):
        return dict(zip(Lst, range(len(Lst))))

    def getDict(self):
        return self.__makeDict(self.__CSVDescription)

    CSVDescription = __makeDict(__CSVDescription)

x = Dictionaries()
print x.CSVDescription
print x.getDict()

x.CSVDescription works fine. But print x.getDict() returns an error.

TypeError: __makeDict() takes exactly 1 argument (2 given)

I can add the self-parameter to the __makeDict() method, but then print x.CSVDescription wouldn’t work.

How do I use the self-parameter correctly?

  • 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-08T20:02:46+00:00Added an answer on June 8, 2026 at 8:02 pm

    A solution using @staticmethod won’t work here because calling the method from the class body itself doesn’t invoke the descriptor protocol (this would also be a problem for normal methods if they were descriptors – but that isn’t the case until after the class definition has been compiled). There are four major options here – but most of them could be seen as some level of code obfuscation, and would really need a comment to answer the question “why not just use a staticmethod?”.

    The first is, as @Marcus suggests, to always call the method from the class, not from an instance. That is, every time you would do self.__makeDict, do self.__class__.__makeDict instead. This will look strange, because it is a strange thing to do – in Python, you almost never need to call a method as Class.method, and the only time you do (in code written before super became available), using self.__class__ would be wrong.

    In similar vein, but the other way around, you could make it a staticmethod and invoke the descriptor protocol manually in the class body – do: __makeDict.__get__(None, Dictionaries)(__lst).

    Or, you could detect yourself what context its being called from by getting fancy with optional arguments:

    def __makeDict(self, Lst=None):
        if Lst is None:
           Lst = self
        ...
    

    But, by far the best way is to realise you’re working in Python and not Java – put it outside the class.

    def _makeDict(Lst):
        ...
    
    class Dictionaries(object):
       def getDict(self):
          return _makeDict(self.__CSVDescription)
    
       CSVDescription = _makeDict(__CSVDescription)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i got an object with contents of html markup in it, for example: string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I don't have much knowledge about the IPv6 protocol, so sorry if the question
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a

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.