Questions tagged [self]

A keyword used in instance methods to refer to the object on which they are working.

In many object-oriented programming languages, self (also called this or Me) is a keyword that is used in instance methods to refer to the object on which they are working. Languages like and others such as , and use self. uses self or super; and languages which derive in style from it (such as , , and ) generally use this. Visual Basic uses Me.

Invoking a method on the self searches for the method implementation of the method in the usual manner, starting in the dispatch table of the receiving object’s class.

Example:

[self startThread];
self.hostReach = YES;
BOOL value = self.hostReach;

Here, self is a variable name that can be used in any number of ways, even assigned a new value.

Inside an instance method, self refers to the instance; inside a class method, self refers to the class object.

1538 questions
-2
votes
1 answer

Issues with declaration method ( & self) in python

While trying to experiment with classes and methods, and how to pass variables between them, I wrote a couple of scripts to try to understand the mechanics. In doing so I hit an issue where one of my functions is un-defined: NameError: name…
Stefan A
  • 37
  • 1
  • 11
-2
votes
1 answer

python - self - required positional argument

here is my code: my file which I start: from SQLhandler import SQLhandler D = SQLhandler.loadProject(4711) a part of my SQLhandler file: class SQLhandler(object): db = pymysql.connect(... ) def loadProject(self, project_id): #do some…
theother
  • 307
  • 2
  • 16
-2
votes
2 answers

In objective-c, by using self in a view controller, does this create a strong reference cycle?

I've noticed while working with Objective-C, the compiler throws error symbols enforcing the use of either self or an underscore when using a property which I think doesn't happen as harshly when using Swift. I'm now at the crossroads where I…
Laurence Wingo
  • 3,912
  • 7
  • 33
  • 61
-2
votes
3 answers

Python self being ignored in a class

I'm using 'an illustrated guide to learning python 3' to learn python. Chapter 21 is about classes. In this chapter it uses 'self' aparently incorrectly? I tried writing my own code for an example, and it didn't work, so I input the example code…
-2
votes
1 answer

Will javascript create a global x?

I was wondering in this example if x would become a global variable as if was not declared inside the local function? Will javascript exit the local function, search until it doesnt find an x, and then implicitly create a global x? function f(){ …
akotch
  • 215
  • 5
  • 11
-2
votes
1 answer

Iam trying to append items into dictionary in swift but nothing is getting inserted. Please Guide

> Iam trying to insert values into dictionary . I tried 2 ways one in which the 2 variables are used and other in which i directly pass the value inside dictionary . Both are not working for index in 0..
-2
votes
1 answer

Need help Spark SQL or SQL

I need help to get the desired results in SQL or Spark. My input is below Input Table Key Rate Invoice Date Key1 10 1/1/2017 key1 10 1/5/2017 key1 20 1/20/2017 key1 10 1/25/2017 Key2 30 2/1/2017 My desired output is…
-2
votes
1 answer

TypeError: __init__() missing 1 required positional argument: 'output_size'

Hi I'm facing the below error. Please let me know how to go about it. I'm facing error related to arguments in model.add(TimeDistributedDense(self.output_size)) from __future__ import print_function from keras.preprocessing import…
Anagha
  • 3,073
  • 8
  • 25
  • 43
-2
votes
1 answer

Please I need to get this clear PHP_SELF

I understand that it validate form data on the same page, but what if i want my form data to be handled by example.php can I use PHP_SELF and example.php together on some condition?
Iyayi Eddy
  • 37
  • 6
-2
votes
4 answers

Run time error in PHP Static Properties and Accessing Global Instance within a Class

I designed a PHP Class with a Static Properties and I get a blank page without any error log, Kindly assist me whats wrong in my PHP Code?
B.Balamanigandan
  • 4,713
  • 11
  • 68
  • 130
-2
votes
1 answer

How to update a global variable from within the same class ? Python

Problem Statement: How to update a global variable from within the same class like 'this' in Java ? Code Example: class XYZ(object): response = "Hi Pranjal!"; def talk(response): self.response = response; #Class attribute…
Pranzell
  • 2,275
  • 16
  • 21
-2
votes
2 answers

Difference in using self and this in python

Well, I am a newbie in Python and I am not able to understand the difference in using self and this keywords in Python. This is the code that uses self as parameter : class restaurant(): bankrupt = False def open_branch(self): …
Yathartha Joshi
  • 716
  • 1
  • 14
  • 29
-2
votes
1 answer

Why do I use Initializers in Swift?

I am trying to get my head around initializers in Swift. I kind of get what they do, but I dont get why I need them. For example: (from apples documentation) class NamedShape { var numberOfSides = 0 var name: String var sideLength:…
Anton Ödman
  • 451
  • 3
  • 7
  • 17
-2
votes
2 answers

Class constructor able to init with an instance of the same class object

Can python create a class that can be initialised with an instance of the same class object? I've tried this: class Class(): def __init__(self,**kwargs): print self self = kwargs.get('obj',self) print self …
G.S
  • 392
  • 2
  • 13
-2
votes
1 answer

From where does the 'self' attribute in Django get its instance?

I'm trying get a grip working around Django and Python. I've always been puzzled with what the self parameter in functions is. Example: class RegistrationForm(forms.ModelForm): email = forms.EmailField(label='Your Email') password1 =…
user248884
  • 851
  • 1
  • 11
  • 21
1 2 3
99
100