self

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

て烟熏妆下的殇ゞ 提交于 2019-12-14 00:13:09
问题 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 if not hasattr(self,'attr1'): print 'attr1' self.attr1 = kwargs.pop('attr1',[]) if not hasattr(self,'attr2'): print 'attr2' self.attr2 = kwargs.pop('attr2',[]) print self self.attr1 = kwargs.pop('attr1',self.attr1) self.attr2 = kwargs.pop('attr2',self.attr2) print self.attr1 print self

The type of self in Swift and its use with respect to two-phase initialization

情到浓时终转凉″ 提交于 2019-12-13 17:30:56
问题 Consider the following code, which adds a gesture recognizer to a view. class ViewController: UIViewController { @IBOutlet weak var imageView: UIImageView! let gesture = UITapGestureRecognizer(target: self, action: #selector(handleGesture(gesture:))) let test1 = self @objc func handleGesture(gesture: UITapGestureRecognizer) { // some code print("hello") } override func viewDidLoad() { let test2 = self super.viewDidLoad() imageView.addGestureRecognizer(gesture) } } As per this question, the

How to write self-closing element tags using XMLStreamWriter

老子叫甜甜 提交于 2019-12-13 16:58:29
问题 I am trying to write a XML element tag that has to look like this : <case type="" player=""/> My code is : doc.writeStartElement("case"); doc.writeAttribute("type", type); doc.writeAttribute("player", ""); doc.writeEndElement(); But, as I expected, a closing tag is added at the end, so it looks like this : <case type="" player=""></case> I am trying to write a self closing element tag, but cannot find how. Does anyone know how to do that ? 回答1: Use writeEmptyElement() . But you should be

The use of self in multiple methods of a class

試著忘記壹切 提交于 2019-12-13 15:20:21
问题 So basically as a beginner programmer I created this program that calculates maximum possible evolves for different pokemon/candy combinations in pokemon go using Tkinter. I created this program before just using a function with al the code. However, I thought it would be good to use a class and after some research this was the result. However, I basically got it working by adding self to a whole bunch of variables in the different methods. My question is: Is the use of a class even relevant

python - self - required positional argument [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-13 11:08:56
问题 This question already has answers here : What is the purpose of the word 'self', in Python? (21 answers) TypeError: Missing 1 required positional argument: 'self' (5 answers) Closed last year . 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 stuff I want to use db in other functions, so I put it on the class

takes exactly 2 arguments (1 given) when including self [closed]

限于喜欢 提交于 2019-12-13 08:07:20
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . Everytime I call my function def hello(self,value) I get an error : takes exactly 2 arguments (1 given) so what could I do ? Or is there another possibility to do this: self.statusitem.setImage_(self.iconsuccess)

swift function calls: self-keyword vs without

左心房为你撑大大i 提交于 2019-12-12 15:07:21
问题 I was wondering if there is any difference between those two a function-calls in a class: self.myFuction() VS myFunction() it is working in both ways. Is there the case where it's necessary to use the self-keyword? 回答1: In most cases: there is absolutely no difference. But it's more "swiftish" if you omit "self". But there is a case, when you have to use self: in closure expressions. But since Swift 1.2, with the @noescape parameter, you can omit "self" in closures as well. 来源: https:/

Delphi Self-Pointer usage

青春壹個敷衍的年華 提交于 2019-12-12 08:13:51
问题 I need to get pointer to my class instance inside this instance. I can't use "Self" directly, I need store pointer for future usage. I tried next code: type TTest = class(TObject) public class function getClassPointer: Pointer; function getSelfPointer: Pointer; end; class function TTest.getClassPointer: Pointer; begin Result := Pointer(Self); end; function TTest.getSelfPointer: Pointer; begin Result := Pointer(Self); end; And both result are wrong - this code: test := TTest.Create; Writeln(

Python: How to call class method from imported module? “Self” argument issue

陌路散爱 提交于 2019-12-12 06:57:52
问题 I have 2 files. I know how to call a function, but cant understand how properly to call a method from imported module which has "self" as the 1st argument. I got this error: TypeError: prepare() missing 1 required positional argument: 'url' cinemas.py import requests from lxml.html import fromstring class cinemas_info(): def __init__(self, url): self.basic_cinemas_info(url) def prepare(self, url): url = requests.get(url) tree = fromstring(url.text) tree.make_links_absolute(url.url) return

PHP Form - Undefined constant ’PHP_SELF’

為{幸葍}努か 提交于 2019-12-12 02:48:50
问题 I have a contact form, it works fine when hosted on my server, but when I uploaded it to my clients server I ran into problems. Please check out the page here: http://www.conceptonegfx.com/contact.php I get the following errors at the top of the form Notice: Use of undefined constant ’PHP_SELF’ - assumed '’PHP_SELF’' in E:\Domains\c\conceptonegfx.com\user\htdocs\fns.php on line 42 Notice: Undefined index: ’PHP_SELF’ in E:\Domains\c\conceptonegfx.com\user\htdocs\fns.php on line 42" id=