How do I call a parent class's method from a child class in Python?

When creating a simple object hierarchy in Python, I'd like to be able to invoke methods of the parent class from a derived class. In Perl and Java, there is a keyword for this (super). In Perl,...

Abstract variables in Java?

I am coming from c# where this was easy, and possible. I have this code: public abstract class clsAbstractTable { public abstract String TAG; public abstract void init(); } but Eclipse...

Accessing a class' member variables in Python?

class Example(object): def the_example(self): itsProblem = "problem" theExample = Example() print(theExample.itsProblem) How do I access a class's variable? I've tried adding this...

Why can a class not be defined as protected?

Why can we not define a class as protected? I know that we can't, but why? There should be some specific reason.

How to call a function within class?

I have this code which calculates the distance between two coordinates. The two functions are both within the same class. However how do I call the function distToPoint in the function...

Python function overloading

I know that Python does not support method overloading, but I've run into a problem that I can't seem to solve in a nice Pythonic way. I am making a game where a character needs to shoot a variety...

Get name of current class?

How do I get the name of the class I am currently in? Example: def get_input(class_name): [do things] return class_name_result class foo(): input = get_input([class name goes...

How to add methods dynamically

I'm trying to add methods dynamically from external files. Right now I have __call method in my class so when i call the method I want, __call includes it for me; the problem is I want to call...

How to create an immutable dictionary in python?

I want to subclass dict in python such that all the dictionaries of the sub-class are immutable. I don't understand how does __hash__ affects the immutability, since in my understanding it just...

java compiled classes contain dollar signs

I've been using Eclipse as my development IDE. I also use it to export my application into a .jar file. When I look at my classes in the .jar file, a few of my classes contain the name of that...

How to add property to object in PHP >= 5.3 strict mode without generating error

This has to be simple, but I can't seem to find an answer.... I have a generic stdClass object $foo with no properties. I want to add a new property $bar to it that's not already defined. If I do...

XXX is not a valid entity or mapped super class // and config options

I just started to use Doctrine2 and I have an error when I want to persist an entity. Here is my error: 'Class "Myapp\app\entity\user" is not a valid entity or mapped super class.' eAccelerator...

Size of C++ classes

Here is the code which prints size of different classes #include <iostream> using namespace std; class EmptyClass { }; class AbstractClass { public: virtual void funcOne() =...

Java: Two jars in project with same class.

I have a java project that is using two imported jars with the same class (com.sun.mail.imap.IMAPFolder). Is there a way to explicitly say which jar to use when importing the class? ...

Template in Fortran?

I have a module that defines three types and and some operations on them. In a separate module, I want to define an algorithm that operates on either one of these types using the operations...

How to import correct package for StdDraw?

I want to use the StdDraw package, and I've tried many different ways of importing it. Of course I tried: import StdDraw; But, when I look at the documentation from Princeton here, it shows that...

Typescript class: "Overload signature is not compatible with function implementation"

I created the following class: export class MyItem { public name: string; public surname: string; public category: string; public address: string; constructor(); ...

Class constructor type in typescript?

How can I declare a class type, so that I ensure the object is a constructor of a general class? In the following example, I want to know which type should I give to AnimalClass so that it could...

How to pass variable of one method in other method within the same class in Python

I am new to python and trying to figure out the issues in my first python code. I am taking an input temp from user in method parameter and i want to compare this temp with another variable...

Something like "if constexpr" but for class definition

if constexpr is a big step for getting rid of preprocessor in C++ programs. However it works only in functions - like in this example: enum class OS { Linux, MacOs, MsWindows, ...

how can i add foreign key to existing class in django

I have two simple models of country and town: from django.db import models class Country(models.Model): name = models.CharField(max_length=50) class Town(models.Model): belongs_to =...

Employee Classes - Python

Write a class named Employee that holds the following data about an employee in attributes: name, ID number, department, and job title. Once you have written the class, write a program that...

Guarantees about the lifetime of a reference in a local variable

In Swift, I can use the ARC mechanism to manage the lifetime of resources external to the process because instances of classes are de-initialized predictably. This is in contrast to environments...

Python: replacing a function within a class of a module

I'm trying to replace a function defined within a class in order to modify its function (as in inner workings) without changing the actual code. I've never done this before, and, hence, am having...

Putting all constants in one class android

There are similar posts to mine but they date back to early 2010's so I'm not sure if things have changed. I just got some code review back and the reviewer suggested I put all of my constants in...

How to solve duplicate classes issue for Flutter?

after adding location: ^1.4.1 to my dependencies in pubspec.yaml: dependencies: flutter: sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the...

Trouble understanding classes in python

I am a beginner in python and I am having trouble understanding classes. I have a task that requires me to create a class that should return a students information e.g. name, id, age and marks. I...

How to update the class object in system verilog after constructing?

This is a follow up question for my question on NOA error in system verilog (https://stackoverflow.com/questions/68526543/null-object-access-error-in-system-verilog). I am trying to build binary...

What are sealed classes in Java 17

Today I updated my java version from 16 to 17 and I found that sealed class is a new feature in it. I think it can be declared like this - public sealed class Main{ } But what is the use of...

Python match/case using global variables in the cases (solvable by use of classes)

I wanted to implement match/case by matching inputs stored in variables. The intended logic should be like: match x: case y: print(...) case z: print(...) Turns out...