self

Takes exactly 3 arguments (4 given)

▼魔方 西西 提交于 2020-01-28 09:59:35
问题 i'm refactoring code in order to add object orientation and am just testing the code. pattern = r"((([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])[ (\[]?(\.|dot)[ )\]]?){3}([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5]))" class Lineobject(object): def __init__(self, pattern, line): self.ip = self.getip(self, pattern, line) def getip (self, pattern, line): for match in re.findall(pattern, line): results = '' ips = match[0] usergeneratedblacklist.write(ips) usergeneratedblacklist.write('\n') return ips When

PHP: self:: vs parent:: with extends

我只是一个虾纸丫 提交于 2020-01-22 05:19:17
问题 I'm wondering what is the difference between using self:: and parent:: when a static child class is extending static parent class e.g. class Parent { public static function foo() { echo 'foo'; } } class Child extends Parent { public static function func() { self::foo(); } public static function func2() { parent::foo(); } } Is there any difference between func() and func2() and if so then what is it ? Thank you Regards 回答1: Child has foo() Parent has foo() self::foo() YES YES Child foo() is

Objective-C: _variable

 ̄綄美尐妖づ 提交于 2020-01-14 04:13:14
问题 OK, this must have been asked before but I looked like mad and found nothing: I have a simple array in my iphone app which I define like so: @property (nonatomic, strong) NSArray *pages; @synthesize pages = _pages; I've seen this in Apples sample code and thought this is a nice short-cut for writing self.pages (i.e. _pages replaces self.pages) like so: _pages = [[NSArray alloc] init]; but then Apple has this again (not exactly like this, but it appears as if they keep swapping randomly): self

Difference between class property mVar and instance variable self.mVar

心已入冬 提交于 2020-01-09 10:51:49
问题 I am some what confused as to the difference between accessing an instance variable via self or just by name (when working inside the class). For instance, take this class: //In .h file: @interface Register : NSObject { NSString *mName; } - (id) initWithName:(NSString *) name; //In .m file: - (id) initWithName:(NSString *)name { if (self == [super init]) { mName = name; } return self; } What's the difference between accessing the instance variable via self.mName = name; vs mName = name; Which

How to access “self” inside the scope of a class?

喜夏-厌秋 提交于 2020-01-05 12:12:19
问题 I've crossed an interesting problem. Suppose we have a class, and in its constructor we take a boolean as an argument. How can I define methods inside the class based on the instance's condition/boolean? For example: class X(): def __init__(self, x): self.x = x if self.x == true: # self is unreachable outside a method. def trueMethod(): print "The true method was defined." if self.x == false: # self is unreachable outside a method. def falseMethod(): print "The false method was defined." 回答1:

KnockoutJS computed observable within an observable

被刻印的时光 ゝ 提交于 2020-01-05 05:03:35
问题 I have a ViewModel containing the following observable: self.obFoo = ko.observable({ foo: ko.observable(""), bar: ko.observable("") }); Now I want to add a new computed observable to obFoo that depends on both foo and bar, something like this: self.obFoo = ko.observable({ foo: ko.observable(""), bar: ko.observable(""), foobar: ko.computed(function(){ return foo() + bar(); }) }); The problem is that foo and bar are not defined within the scope of foobar. I tried adding 'this' or even 'self

Why can't I change the value of self?

无人久伴 提交于 2020-01-03 11:17:09
问题 How come I'm allowed to change "self" this way: self.map! {|x| x*2} Or this way: self.replace(self.map {|x| x*2}) But not this way: self = self.map {|x| x*2} Why doesn't Ruby allow me to change the object that the "self" variable points to, but does allow me to change the object's attributes? 回答1: Not an answer, just a clue. a=[1,2] =>[1,2] a.object_id =>2938 a.map!{|x| x*2} =>[2,4] a.object_id # different data but still the same object =>2938 a.replace(a.map {|x| x*2}) =>[4,8] a.object_id #

Why can't I change the value of self?

醉酒当歌 提交于 2020-01-03 11:17:07
问题 How come I'm allowed to change "self" this way: self.map! {|x| x*2} Or this way: self.replace(self.map {|x| x*2}) But not this way: self = self.map {|x| x*2} Why doesn't Ruby allow me to change the object that the "self" variable points to, but does allow me to change the object's attributes? 回答1: Not an answer, just a clue. a=[1,2] =>[1,2] a.object_id =>2938 a.map!{|x| x*2} =>[2,4] a.object_id # different data but still the same object =>2938 a.replace(a.map {|x| x*2}) =>[4,8] a.object_id #

Difference between static:: and $this::

风流意气都作罢 提交于 2020-01-03 08:07:38
问题 I know there is a difference between static:: and self:: like in this example ( from https://stackoverflow.com/a/13613718/2342518 ) <?php class One { const TEST = "test1"; function test() { echo static::TEST; } } class Two extends One { const TEST = "test2"; } $c = new Two(); $c->test(); Which returns test2 when static::TEST is used and test1 when self::TEST is used. But it also returns test2 when $this::TEST is used. static::TEST can be used inside a static method, whereas $this::TEST

Why is `self` not used in this method?

不羁岁月 提交于 2020-01-03 02:57:09
问题 I was under the impression that methods within Python classes always require the self argument (I know that it doesn't actually have to be self , just some keyword). But, this class that I wrote doesn't require it: import ZipFile import os class Zipper: def make_archive(dir_to_zip): zf = zipfile.ZipFile(dir_to_zip + '.zip', 'w') for filename in files: zf.write(os.path.join(dirname, filename)) zf.close() See? No self . When I include a self argument to make_archive , I get a TypeError: make