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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:19:06+00:00 2026-05-20T19:19:06+00:00

Is that possible to define a function without referencing to self this way? def

  • 0

Is that possible to define a function without referencing to self this way?

def myfunc(var_a,var_b)

But so that it could also get sender data, like if I defined it like this:

def myfunc(self, var_a,var_b)

That self is always the same so it looks a little redundant here always to run a function this way: myfunc(self,'data_a','data_b'). Then I would like to get its data in the function like this sender.fields.

UPDATE:
Here is some code to understand better what I mean.
The class below is used to show a page based on Jinja2 templates engine for users to sign up.

class SignupHandler(webapp.RequestHandler):
    def get(self, *args, **kwargs):
        utils.render_template(self, 'signup.html')

And this code below is a render_template that I created as wrapper to Jinja2 functions to use it more conveniently in my project:

def render_template(response, template_name, vars=dict(), is_string=False):
    template_dirs = [os.path.join(root(), 'templates')]
    logging.info(template_dirs[0])
    env = Environment(loader=FileSystemLoader(template_dirs))
    try:
        template = env.get_template(template_name)
    except TemplateNotFound:
        raise TemplateNotFound(template_name)
    content = template.render(vars)
    if is_string:
        return content
    else:
        response.response.out.write(content)

As I use this function render_template very often in my project and usually the same way, just with different template files, I wondered if there was a way to get rid of having to call it like I do it now, with self as the first argument but still having access to that object.

  • 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-05-20T19:19:07+00:00Added an answer on May 20, 2026 at 7:19 pm

    If you don’t need self, you can use the staticmethod decorator to create a method which does not receive the object as its first argument:

    class Foo(object):
        @staticmethod
        def foo(bar, baz, qux):
            pass
    

    If you’re writing code which deals only with class-global data, by contrast, you can use a class method:

    class Foo(object):
        global_cache={}
        @classmethod
        def set(cls, key, value):
            cls.global_cache[key] = value
    

    If, by contrast, you’re writing code which really does need to refer to the object instance — self is part of the language. Part of the Zen of Python is that “Explicit is better than implicit”, and the use of self is an example of this.

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

Sidebar

Related Questions

I want to define a constant inside a function that could be used outside
Is it possible to define a class in C# such that class GenericCollection<T> :
Is it possible to define a timestamp column in a MySQL table that will
How is it possible that .NET is finding the wrong MyType in this scenario?
In scala it is possible to define a local block in a function. The
I'd like to define a helper function that has the ability to modify a
I'd like to decorate a function, using a pattern like this: def deco(func): def
Is that possible to switch an Open Source Project license from GPL to LGPL
Is that possible? I mean, can both ends of the many to many relationship
Is that possible to have a single PHP SOAP server which will handle requests

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.