self Questions

0

I have been exploring different abstractions in Swift, and I found myself stumped on how to determine the type of a tuple's element from its own type. I know the compiler and Xcode are quick to pro...
Planography asked 24/8 at 23:4

6

Solved

I have an Obj-C object with a bunch of methods inside of it. Sometimes a method needs to call another method inside the same object. I can't seem to figure out how to get a C method to call a Obj-C...
Computerize asked 14/8, 2009 at 20:28

9

Solved

So I need to have some routes inside a class, but the route methods need to have the self attr (to access the class' attributes). However, FastAPI then assumes self is its own required argument and...
Morelos asked 11/9, 2020 at 20:20

2

Solved

Is it possible to do something like self:: in PHP to not need to specify the class-name tro call a static method within the same class. See how I do it: public class Foo public static void blaa()...
Kushner asked 27/3, 2014 at 22:55

12

Solved

If I have a class ... class MyClass: def method(arg): print(arg) ... which I use to create an object ... my_object = MyClass() ... on which I call method("foo") like so ... >>&...
Swagerty asked 29/5, 2014 at 23:27

14

Solved

Can one write something like: class Test(object): def _decorator(self, foo): foo() @self._decorator def bar(self): pass This fails: self in @self is unknown I also tried: @Test._decorato...
Laws asked 11/8, 2009 at 23:1

4

Solved

I want a decorator that would add the decorated function to list, like this : class My_Class(object): def __init__(self): self.list=[] @decorator def my_function(self) print 'Hi' I expect...
Peal asked 4/12, 2011 at 14:10

3

Solved

Consider this small example: import datetime as dt class Timed(object): def __init__(self, f): self.func = f def __call__(self, *args, **kwargs): start = dt.datetime.now() ret = self.func(*...
Vivie asked 7/5, 2015 at 14:29

6

Solved

What is the purpose of checking self.__class__ ? I've found some code that creates an abstract interface class and then checks whether its self.__class__ is itself, e.g. class abstract1 (object): ...
Lassa asked 15/12, 2013 at 20:27

4

Solved

In Swift, let's say I want to add a static factory method that returns an instance: class MyClass { static func getInstance() { return MyClass(someProperty); } } But what if I don't want to w...
Cappuccino asked 3/2, 2016 at 11:32

7

Solved

Here is some code: class Person def initialize(age) @age = age end def age @age end def age_difference_with(other_person) (self.age - other_person.age).abs end protected :age end Wh...
Argumentative asked 7/11, 2009 at 14:37

5

Solved

I'm having some real trouble with timing a function from within an instance of a class. I'm not sure I'm going about it the right way (never used timeIt before) and I tried a few variations of the ...
Denude asked 31/8, 2010 at 12:46

3

Solved

I have the code below: from tkinter import * class Window(Frame): def __init__(self, master = None): Frame.__init__(self, master) self.master = master self.init_window() def init_wi...
Stringy asked 8/5, 2017 at 3:59

7

Solved

While playing in a Swift playground I noticed that Self, with capital "S", is available along with the lowercase self. Is there any difference between them? If so, what are usages for these two, es...
Wendy asked 9/1, 2015 at 15:24

7

Why is cls sometimes used instead of self as an argument in Python classes? For example: class Person: def __init__(self, firstname, lastname): self.firstname = firstname self.lastname = lastn...
Saturable asked 6/1, 2011 at 8:17

11

Solved

I have been learning Python by following some pygame tutorials. Therein I found extensive use of the keyword self, and coming from a primarily Java background, I find that I keep forgetting to typ...
Counterpressure asked 31/12, 2009 at 5:50

8

Solved

Toward the end of a program I'm looking to load a specific variable from all the instances of a class into a dictionary. For example: class Foo(): def __init__(self): self.x = {} foo1 = Foo() fo...
Homologous asked 24/8, 2012 at 0:55

10

Solved

I am new to Swift and I'm wondering what self is used for and why. I have seen it in classes and structures but I really don't find them essential nor necessary to even mention them in my code. Wh...
Atingle asked 10/11, 2014 at 0:26

2

Solved

I've got a WPF Window, and somewhere there is a ListView where I bind a List<string> to. Now somewhere in my ListView there is a TextBox and the Content property is set to {Binding}. But th...
Spree asked 15/12, 2009 at 10:45

4

Solved

My module definition looks like this: module RG::Stats def self.sum(a, args = {}) a.inject(0){ |accum, i| accum + i } end end To use this method I simply require the file containing this defi...
Filemon asked 24/9, 2015 at 1:4

2

Solved

I was coding something, and there was an error in one part. But I can't find why the error occurs. Code (Sample; similar to the error part): class Test: def __init__(self,a=0): self.x = a self....
Bland asked 17/6, 2017 at 11:21

0

I am trying to implement an answer to an old question. Here is that answer https://mcmap.net/q/1104389/-corebluetooth-refreshing-local-name-of-an-already-discovered-peripheral And here are the code...
Roscoeroscommon asked 6/5, 2022 at 17:3

1

Solved

I'm a new programmer in lua, and there are lots of things I still probably don't know about. I googled what self is in lua, but I still don't understand it. If anyone could give me the easiest expl...
Miley asked 23/3, 2022 at 0:3

2

Stack: Mac OS 10.15.6, Xcode Version 12.0 (12A7209) I have a self sizing collection cell. I override preferredLayoutAttributesFitting to get the self sizing feature. Everything works great PRIOR ...
Sneaky asked 21/9, 2020 at 16:24

5

Solved

Take the following simplified example. class A(object): variable_A = 1 variable_B = 2 def functionA(self, param): print(param+self.variable_A) print(A.functionA(3)) In the above example, I...
Sanmicheli asked 30/1, 2017 at 11:51

© 2022 - 2024 — McMap. All rights reserved.