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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:10:25+00:00 2026-06-15T13:10:25+00:00

class Example(wx.Frame): def __init__(self, *args, **kwargs): super(Example, self).__init__(*args, **kwargs) self.InitUI() def InitUI(self): menubar =

  • 0
class Example(wx.Frame):

    def __init__(self, *args, **kwargs):
        super(Example, self).__init__(*args, **kwargs) 

        self.InitUI()

    def InitUI(self):    

        menubar = wx.MenuBar()
        fileMenu = wx.Menu()
        viewMenu = wx.Menu()

        self.shst = viewMenu.Append(wx.ID_ANY, 'Show statubar', 
            'Show Statusbar', kind=wx.ITEM_CHECK)
...

I’ve recently started learning python and wxPython. The above code snipppet is from http://www.zetcode.com/wxpython/menustoolbars/ .
I’m trying to get my head around the self.shst variable. Why is it necessary to prefix it with the self keyword ?

From what I read, the self keyword is used in that context in the __init__ method, to “declare” instance variables, but the author has no shst declaration in __init__

Edit
In light of your answers I did the following test:

class Test(object):
    def __init__(self):
        self.x = 20
    def func(self):
        self.y = 10
    def getVal(self):
        return self.y


def main():
    t = Test()
    print t.getVal()
    print dir(t)

if __name__ == '__main__':
    main()

I am unable to access self.y in the getVal() function, and I don’t see y in the output from dir(t). Shouldn’t self.y be accessible to every function in the Test class ?

  • 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-15T13:10:25+00:00Added an answer on June 15, 2026 at 1:10 pm

    If you did not prefix shst with self., then it would just be a local variable that goes out of scope and is garbage-collected after the method exits. There is no need to declare python class/object members prior to assignment.

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

Sidebar

Related Questions

For example: class DemoFrame(wx.Frame): def __init__(self): Initializing ... self.TextA = wx.StaticText(MainPanel, id = -1,
Let's use this class definition as an example: class Person def fname @fname end
Example-I have a person class Public Class Person Private _fname As String Public Property
class Example(Document): comments = ListField(field=EmbeddedDocumentField('Comment'), db_field='z') class Comment(EmbeddedDocument): comment = StringField() date = DateTimeField()
Given: class example { public: std::vector<std::vector<int>> a; int b; } func() { example e;
I have a model: class Example(models.Model): unique_hash = models.CharField(max_length=32,unique=True) content = models.FileField(upload_to='source',blank=True,verbose_name=HTML Content File)
In the following class: public class Example<T> where T : IComparable { private T
I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
struct GPattern() { int gid; .... } class Example() { public: void run(string _filename,
I would like to modify an object private variable class Example(): __myTest1 = 1

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.