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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:02:29+00:00 2026-06-14T17:02:29+00:00

I’ve got a button class that you can instantiate like so: engine.createElement((0, 0), Button(code=print,

  • 0

I’ve got a button class that you can instantiate like so:

engine.createElement((0, 0), Button(code=print, args=("Stuff!",)))

And when it is clicked it will print “Stuff!”. However, I need the button to destroy itself whenever it is clicked. Something like this:

engine.createElement((0, 0), Button(code=engine.killElement, args=(self,)))

However, that would just kill the caller, because self refers to the caller at that moment. What I need to do is give the class its own ‘self’ in advance…

I thought of just making the string 'self' refer to the self variable upon click, but what if I wanted to use the string 'self' in the arguments?

What is the way to do this? Is my architecture all wrong or something?

  • 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-14T17:02:30+00:00Added an answer on June 14, 2026 at 5:02 pm

    This is impossible in general.

    However, if you’re creating the Button class, you can pass a special sentinel value that means “yourself”. For example:

    class Button(object):
        yourself = 'yourself'
        def __init__(self, code, args):
            self.code = code
            self.args = [self if arg is yourself else arg for arg in args]
    

    Then:

    engine.createElement((0, 0), Button(code=engine.killElement, args=(Button.yourself,)))
    

    Picking an appropriate sentinel can be tricky—obvious choices like None, 0, or '' may be legitimate values, and even tricky things you come up with may turn out to be useful arguments during debugging. Making yourself a class variable, or a global within the module, means that if you ever do need to redefine the sentinel, you only need to change it in one place, instead of everywhere you use it.

    See http://bytes.com/topic/python/answers/555169-sentinel-values-special-cases for a brief discussion on picking an appropriate sentinel value. There’s another blog out there with more information, but I haven’t found it in a quick search… Anyway, here are some quick ideas:

    1. None is always the best answer if it works.
    2. Define an empty class to be the sentinel. Either the class object, or any instance of the class object, can be used.
    3. Create a global instance of the object class (object()).
    4. Define an empty function and use it (or its func_code or whatever).
    5. Ellipsis (or type(Ellipsis), which is a type named ellipsis, but that name isn’t accessible) is almost always safe, because it’s only used in __getitem__ and friends (and possibly in defining slice objects to pass to them).
    6. If there’s a type that could not possibly be a valid value, and you’ve already got instances around, use one of those—e.g., the func_code member of the __init__ function.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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 doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.