class

What is happening here in Python with OOPs while trying Diamond Shape problem

旧街凉风 提交于 2019-12-24 10:31:06
问题 I am learning OOPs with python. created below code to replicate the diamond shape problem in multiple inheritence. I am running the below code in jupyter notebook and output is generated at same. class parent: def __init__(self): self.a=2 self.b=4 def form1(self): print("calling parent from1") print('p',self.a+self.b) class child1(parent): def __init__(self): self.a=50 self.b=4 def form1(self): print('bye',self.a-self.b) def callchildform1(self): print("calling parent from child1") super()

How to initialize an array of classes in kotlin?

雨燕双飞 提交于 2019-12-24 10:25:12
问题 I get an error when I put the type and size of an array of classes I have tried: fun main(args :Array<String>) { class modul() { var nommodul: String? = null var coeff: Int? = null var note: Int? = null } var releve class notes() { var releve: array<modul>(10){""} here the erreur } } 回答1: First of all, your code has several errors. This might be an MCVE and/or copy-paste issue, but I need to address these before I get started on the arrays. var releve before the notes class isn't allowed. You

c# ignore properties that are null

落爺英雄遲暮 提交于 2019-12-24 10:23:16
问题 I am doing an C# Web Api Application using Framewrok 4.5 The method retrieve a class defined like this public class BGBAResultadoOperacion { public string Codigo { get; set; } public string Severidad { get; set; } [DataMember(Name = "Descripcion", EmitDefaultValue = false)] public string Descripcion { get; set; } } I need to NOT retrieve those Properties that are NULL . For that reason I defined Descripcion property like [DataMember(Name = "Descripcion", EmitDefaultValue = false)] As I can

When a function in a class returns a value, where is it returned to?

南楼画角 提交于 2019-12-24 10:04:00
问题 I've been learning about Classes and I got my code to work, but I'm just wondering where does the returned value go? code: from sys import exit from random import randint class Game(object): def __init__(self, start): self.pie = [ 'pie test'] self.start = start def play(self): next_room_name = self.start while True: print "\n--------" room = getattr(self, next_room_name) next_room_name = room() def rooom(self): print "Test worked. good job" return "piez" def piez(self): print "pie room" exit

Object array is not picklable

拈花ヽ惹草 提交于 2019-12-24 10:03:59
问题 I made a class in python like the following: class myClass(): _fields_ = [1, 2] where field_1 & field_2 are supposed to be integers. Then I created an array that its elements are of the class myClass as following: array = [ myClass() for i in range(5)] When I wanted to check the values of the elements of array in the variable inspector, it gives my the following message: "Spyder was unable to retrieve the value of this variable from the console." "The error message was: Object array is not

Abstract classes and Pointers

廉价感情. 提交于 2019-12-24 09:59:30
问题 I have a class // i want an abstract class. class Foo { public: virtual void bar()=0; }; // i want this abstract calss to be used all over the program :) to enjoy polymorphism. class EatFoo { public: vector<Foo> fooV; // not working vector<Foo *> fooPV; }; I get a compile time error that abstract class cannot be instantiated. Yes its true but i really want or i want to learn : how to make other programmers "have to - have to" implement some function and i donot want to use pointers in my

Python2 - printing an object's default attributes

二次信任 提交于 2019-12-24 09:49:16
问题 I'm new to OOP, but I'm trying to look at an object's vars. Other Stack-O answers have suggested using object.__dict__ or vars(object) . So I went into the Python shell to try a quick example, but I noticed neither of these answers prints the object's default attributes, only newly-assigned attributes, e.g.: >>> class Classy(): ... inty = 3 ... stringy = "whatevs" ... >>> object = Classy() >>> object.inty 3 >>> object.__dict__ {} >>> vars(object) {} >>> object.inty = 27 >>> vars(object) {

Is it undefined behavior to cast from base class to derived?

别来无恙 提交于 2019-12-24 09:43:12
问题 I've encountered myself in a problem where casting to the derived class would solve the problem. I've found an answer on S.O that says it can lead to UB, testing it, it both compiled and worked correctly. Is it undefined behavior? If it is what would be a correct approach to this problem? class A { public: A(){}; ~A(){} }; class B : public A { public: B(){}; ~B(){} void Show() { std::cout << "Show" << std::endl; } }; int _tmain(int argc, _TCHAR* argv[]) { A a; B* b = static_cast<B*>(&a); b-

Why inserting __init__() of superclass in this case?

前提是你 提交于 2019-12-24 09:39:08
问题 I am now reading HeadFirstPython and there is an example about class. >>> class NamedList(list): >>> def __init__(self, a_name): >>> list.__init__([]) >>> self.name = a_name In this case why is the statement list.__init__([]) used? And also cannot understand why it is including the empty [] . 回答1: Normally , because it is good practice to call the initializer of the class you are inheriting from. However, the author seems to have substituted self for an empty list; I'd have used one of: super

jQuery on click function nothing happening

倾然丶 夕夏残阳落幕 提交于 2019-12-24 09:37:03
问题 This jQuery function is meant to post the value of num to a PHP page and then echo it in the correct status class, any ideas why nothing is happening, I have downloaded jQuery and called the file further up (not displayed here) Any help is appreciated thanks! <script> var num = 1; function ajax_post(){ $.ajax('javas.php', { success: function(response) { $(".status").html(response); }, data: "num=" + (++num) }); } function ajax_posta(){ $.ajax('javas.php', { success: function(response) { $("