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 3213120
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:54:32+00:00 2026-05-17T14:54:32+00:00

Consider the following (broken) code: import functools class Foo(object): def __init__(self): def f(a,self,b): print

  • 0

Consider the following (broken) code:

import functools                                                            
class Foo(object):                                                          
  def __init__(self):                                                 
    def f(a,self,b):                                            
      print a+b                                           
    self.g = functools.partial(f,1)                             
x=Foo()                                                                     
x.g(2)

What I want to do is take the function f and partially apply it, resulting in a function g(self,b). I would like to use this function as a method, however this does not currently work and instead I get the error

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    x.g(2)
TypeError: f() takes exactly 3 arguments (2 given)

Doing x.g(x,2) however works, so it seem the issue is that g is considered a “normal” function instead of a method of the class. Is there a way to get x.g to behave like a method (i.e implicitly pass the self parameter) instead of a function?

  • 1 1 Answer
  • 2 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-05-17T14:54:32+00:00Added an answer on May 17, 2026 at 2:54 pm

    This will work. But I’m not sure if this is what you are looking for

    class Foo(object):                                                          
      def __init__(self):                                                 
        def f(a,self,b):                                            
          print a+b                                           
        self.g = functools.partial(f,1, self) # <= passing `self` also.
    
    x = Foo()
    x.g(2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: #include <iostream> class Bar { public: void foo(bool b =
Consider following code, I want to make it a thread safe class, so that
Background Consider the following code: #include <utility> namespace ns { struct foo { foo()
Consider following situation: Object > MyClass > MyClassA, MyClassB If I want something in
Consider the following code: class Program { static Program() { Program.program1.Value = 5; }
Consider following piece of code void foo( bool forwad ) { vector<MyObject>::iterator it, end_it;
Consider following code: public sealed class Program { public static void Main() { System.Console.WriteLine(Hi);
Consider following code: My problem is: 1) I can't seem to cast the errors
Consider following string Some string with quotes and \pre-slashed\ quotes Using regex, I want
Consider following 2 programs giving same error First calss: public class Testing { Testing

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.