class-variables Questions

4

Solved

I'm learning about classes and don't understand this: class MyClass: var = 1 one = MyClass() two = MyClass() print(one.var, two.var) # out: 1 1 one.var = 2 print(one.var, two.var) # out: 2 1 I...
Shenitashenk asked 5/11, 2021 at 17:9

7

Solved

I am working on a method to return all the class variables as keys and values as values of a dictionary , for instance i have: first.py class A: a = 3 b = 5 c = 6 Then in the second.py i sho...
Herbertherbicide asked 24/1, 2014 at 0:36

7

Solved

I need to make a bunch of class variables and I would like to do it by looping through a list like that: vars = ('tx', 'ty', 'tz') # plus plenty more class Foo(): for v in vars: setattr(no_idea_...
Harcourt asked 29/11, 2011 at 8:11

27

Solved

How do I create class (i.e. static) variables or methods in Python?
Gambrill asked 16/9, 2008 at 1:46

6

Solved

If I have the following code: class Foo(object): bar = 1 def bah(self): print(bar) f = Foo() f.bah() It complains NameError: global name 'bar' is not defined How can I access class/static ...
Continent asked 1/4, 2009 at 21:23

5

Solved

Suppose I have this code: class Example(object): def the_example(self): itsProblem = "problem" theExample = Example() print(theExample.itsProblem) When I try it, I get an error ...
Kazoo asked 8/8, 2010 at 14:2

3

Solved

this is my first question, so sorry... I'm a beginner with python and coding in general, and i wanted to create a class called 'Map' that would have the following class variables: class Map: hei...
Sirius asked 25/5, 2015 at 19:38

1

How can I handle the validation of an array of numbers in form data? Because I am passing data in a form-data format, I can't validate an array of numbers Actually, I don't know how to do it. This...
Bastian asked 23/9, 2021 at 19:58

8

Solved

I read When do Ruby instance variables get set? but I'm of two minds when to use class instance variables. Class variables are shared by all objects of a class, Instance variables belong to one obj...

4

Solved

I'm working as an application with classes and subclasses. For each class, both super and sub, there is a class variable called label. I would like the label variable for the super class to default...
Fourier asked 21/5, 2015 at 18:49

4

Solved

Why are Java constants declared static? class Foo { static final int FII = 2 ; } In this example I understand the use of final, But why does it have to be static? Why should it be a class variabl...
Nebiim asked 11/11, 2011 at 11:21

4

Solved

I have a class with a static var where the current online connection status is stored. I want to observe the value of ConnectionManager.online through other classes. I wanted to do this with KVO, b...
Theotokos asked 6/7, 2016 at 22:34

6

Solved

I'm working on extending the Python webapp2 web framework for App Engine to bring in some missing features (in order to make creating apps a little quicker and easier). One of the requirements her...
Pose asked 26/2, 2014 at 15:47

1

Solved

Given the class from __future__ import annotations from typing import ClassVar, Dict, Final import abc class Cipher(abc.ABC): @abc.abstractmethod def encrypt(self, plaintext: str) -> s...
Lolalolande asked 25/12, 2019 at 0:33

2

Solved

According to Reek, creating a class variable is considered a 'code smell'. What is the explanation behind this?
Sherrill asked 26/11, 2016 at 13:55

4

Solved

I know it supports automatic variables, but what about class variables?
Duffy asked 25/6, 2012 at 10:26

3

Solved

Can anyone tell me about the difference between class variables and class instance variables?
Unijugate asked 27/9, 2010 at 9:32

9

Solved

What is the difference between up-casting and down-casting with respect to class variable? For example in the following program class Animal contains only one method but Dog class contains two met...
Caracole asked 1/5, 2014 at 18:30

5

Solved

I've been programming in Ruby for a few months now, and I'm wondering when it is appropriate to use constants over class variables and vice versa. (I'm working in Rails, thinking about constants in...
Singularity asked 22/12, 2008 at 22:16

5

Solved

What are Ruby variables preceded with double at signs (@@)? My understanding of a variable preceded with an at sign is that it is an instance variable, like this in PHP: PHP version class Person ...
Pushkin asked 4/5, 2011 at 21:33

2

Solved

I am having problem getting this piece of code to run. The class is Student which has a IdCounter, and it is where the problem seems to be. (at line 8) class Student: idCounter = 0 def __init__(...
Marlow asked 4/4, 2012 at 5:22

2

Solved

I want to create somekind of event system in c++ for my needs I know that you can use fuction as other function parameter May be i missed something(But in c# you can do it with events handlers)
Credo asked 17/6, 2018 at 6:22

1

I've seen threads like this on thread-safety in Rails and various web pages on the topic, and I'm sure everyone's great at reciting what it is and giving 'tips' on what isn't thread-safe ("class va...
Extracurricular asked 26/7, 2016 at 10:39

6

Solved

First, a puzzle: What does the following code print? public class RecursiveStatic { public static void main(String[] args) { System.out.println(scale(5)); } private static final long X = scal...
Figone asked 19/3, 2018 at 14:56

8

Solved

If I have an instance in PHP, what's the easiest way to get to a static property ('class variable') of that instance ? This $classvars=get_class_vars(get_class($thing)); $property=$classvars['pro...
Strung asked 11/4, 2011 at 15:43

© 2022 - 2025 — McMap. All rights reserved.