self Questions

26

Solved

Consider this example: class MyClass: def func(self, name): self.name = name I know that self refers to the specific instance of MyClass. But why must func explicitly include self as a parameter...
Tunicle asked 25/4, 2010 at 20:22

2

Solved

I wonder if there is a way to make a self referencing update in MongoDB, so you can use object's params on a $set query. Here is an example: > db.labels.save({"name":"label1", "test":"hello"}) ...
Leodora asked 15/1, 2012 at 8:58

1

Solved

Hi i'm trying to destroy a class object if the condition of an if statement(inside a while is met) global variablecheck class createobject: def __init__(self,userinput): self.userinput = input ...
Softshoe asked 21/8, 2020 at 10:27

10

Solved

When defining a method on a class in Python, it looks something like this: class MyClass(object): def __init__(self, x, y): self.x = x self.y = y But in some other languages, such as C#...
Metacarpus asked 16/9, 2008 at 0:39

2

Solved

I'm trying to use self instead of typing the class name inside propery_exists function as follows : private static function instantiate($record){ $user = new self; foreach($record as $name =>...
Kymry asked 23/8, 2013 at 15:36

3

Solved

I don't want to write a long text, because it is a short question. PHPUnit tests contain several methods that are static. For example all those \PHPUnit\Framework\Assert::assert*() methods and also...
Kilgore asked 4/5, 2015 at 22:47

4

Solved

I am learning Delphi reading Marco Cantu's book and it's super complete. It's very clear but I have a doubt about the keyword Self. I already have experience with OOP and I have the basics of it. M...
Pneumodynamics asked 11/8, 2016 at 10:36

1

Solved

I am trying to do the equivalent of: class A: def __init__(self): self.b = self.get_b() def get_b(self): return 1 using @dataclass. I want to use a @dataclass here because there are other (om...
Savour asked 24/7, 2020 at 0:39

6

Solved

I've just run into blocks and I think they are just what I'm looking for, except for one thing: is it possible to call a method [self methodName] from within a block? This is what I'm trying to do...
Toplevel asked 16/2, 2011 at 23:42

6

So I just started programming in python and I don't understand the whole reasoning behind 'self'. I understand that it is used almost like a global variable, so that data can be passed betwee...
Sclera asked 8/9, 2013 at 2:27

5

Solved

I have seen a fair amount of blogs & videos on Go and as far as I recall, none of the authors use 'self' or 'this' for the receiver variable when writing methods. However there seems to b...
Halonna asked 5/5, 2014 at 21:17

3

Solved

This works and happily prints 81: class X: mypow = pow print(X().mypow(3, 4)) But why? Isn't the method given the extra "self" argument and should be utterly confused? For comparison, I also ...
Pegu asked 7/6, 2015 at 12:38

4

Solved

I can access a python function's attribute inside of function itself by below code: def aa(): print aa.__name__ print aa.__hash__ # other simliar However, if above aa() function is a template...
Mastoid asked 21/2, 2011 at 8:7

2

Solved

I know there is a difference between static:: and self:: like in this example ( from https://mcmap.net/q/173977/-overriding-class-constants-vs-properties ) <?php class One { const TEST = "test...
Neon asked 29/6, 2014 at 12:48

2

Solved

I have created a class where I wanted to pass an self.variable into an optional argument within a method. The reason being because I want to store information in the Self.variable made in an other ...
Valvule asked 11/6, 2019 at 3:9

4

Solved

How exacyly do you get variables within a program with self? Like in Java you have: private int a public void sa(int a) { this.a = a} public void ga() { return this.a } VB has 'ME' and C# has ...
Albertoalberts asked 22/6, 2013 at 22:21

1

Solved

Hey I'm working on SSR app with express. when the request hits, render server(running on localhost:3000) send request to api server(running on localhost:3001) for initial user's session store. but ...
Sheelagh asked 2/3, 2019 at 15:13

4

Solved

I am looking for a "self" reference to the current class in JAVA in a static context manner like in PHP Scope Resolution Operator? Solution: Break out of scope? BEWARE, this is compared to a stati...
Jonquil asked 11/3, 2011 at 9:18

3

Solved

I have read something in some foreign code and I want to check my assumption: @synchronized(self) is used to get rid of the self prefix when setting a property. So in my example below, I'm sett...
Greenhorn asked 11/1, 2011 at 5:23

4

Solved

I'm learning the details of how each works in ruby, and I tried out the following line of code: p [1,2,3,4,5].each { |element| el } And the result is an array of [1,2,3,4,5] Why is the return val...
Turret asked 22/7, 2012 at 0:27

4

Solved

I have noticed a few people in the industry will use the self keyword even when not explicitly required (i.e. outside of closures). Example: import UIKit import MapView import CoreLocation clas...
Lebron asked 8/10, 2018 at 23:2

1

Solved

Inside my app I created a Protocol called "Positions" and extended the UIView class to conform to this protocol in order to add some properties to the UIView class. I used the code below. import F...
Bellringer asked 9/10, 2018 at 18:35

4

Solved

I had done a bit of Python long back. I am however moving over to Java now. I wanted to know if there were any differences between the Python "self" method and Java "this". I know that "self" is n...
Lucania asked 11/2, 2014 at 6:40

6

Solved

Can I write a function that returns iteself? I was reading some description on closures - see Example 6 - where a function was returning a function, so you could call func()(); as valid JavaScript...
Valentinevalentino asked 5/8, 2011 at 16:21

2

I learned that static is better than self because self does late static binding. But I wonder which would be best at referencing const variable. class Black { const color = 'black'; public fun...
Xiphoid asked 1/8, 2017 at 3:23

© 2022 - 2024 — McMap. All rights reserved.