Static class variables in Python
Is it possible to have static class variables or methods in python? What syntax is required to do this? ...
Is it possible to have static class variables or methods in python? What syntax is required to do this? ...
If I have a class with an attr_accessor, it defaults to creating an instance variable along with the corresponding getters and setters. But instead of creating an instance variable, is there a way to get it to create a class variable or a class instance variable instead? ...
class << self attr_accessor :n, :totalX, :totalY end The syntax above is used for defining class instance variables. But when I think about what syntax implies, it doesn't make any sense to me, so I'm wondering if this type of syntax is used for any other types of definitions. My point of confusion here is this: class << self The ap...
PHP runs in a shared-nothing environment, which in this context means that every web request is run in a clean environment. You can not access another request's data except through a separate persistence layer (filesystem, database, etc.). What about Ruby on Rails? I just read a blog post stating that separate requests might access ...
I know that, in Delphi, instance variables and global variables are initialized to zero (this has been asked here before). However, what about static variables (class var)? I would expect class vars to be initialized to zero, just like global variables. But I've seen too many new Delphi compiler features that were still half-baked to as...
If a class implements a singleton pattern, should all the variables be declared static? Is there any reason they shouldn't be declared static? Does it make a difference? ...
Let's say I have a class like this (and also further assume that all the private variables: public class Item { private String _id = null; private String _name = null; private String _description = null; ... } Now, if I want to build a toString() representation of this class, I would do something like this inside ...
If instance variables belong to an instance of a class, class variables would belong to an instance of a metaclass, I should think. But my experience with the Objective-C metaclass tells me that this is unlikely. I'm wondering what class_getClassVariable does as opposed to class_getInstanceVariable, and why there is not a class_setClass...
The ruby class-instance stuff is giving me a headache. I understand given this... class Foo @var = 'bar' end ...that @var is a variable on the created class's instance. But how do I create a sub-class overridable class variable? Here is an example of what I would do in Python: class Fish: var = 'fish' def v(self): return sel...
I used hash of hashes to store settings in my code. I wonder if I can have something like class variable that is the same for all instances of the class for my @profile hash. So both profiles below would have general profile variable equal to both of them. I want the solution to use hash. @profile = { "vB4Discussions" => { #profile...
I know it's wired to have such a case but somehow I have it: class foo #static method @staticmethod def test(): pass # class variable c = {'name' : <i want to reference test method here.>} What's the way to it? Just for the record: I believe this should be considered as python worst practices. Using static methods is ...
I want to have some kind of single list that is initialized in a seperate module, then can be included in a controller and modified at the controller-class level, and accessed at the controller-instance level. I thought class variables would work here, but something strange is happening, they don't seem to be being initialized within my ...
I am working with Active Directory using C#. Instantiating the PrincipalContext object seems to be expensive, so I'd like to store one in a class variable. When using PrincipalContext as a local variable, I can use the convenient using syntax. When storing an IDisposable object in a static variable, how do I ensure the object is properl...
Hey guys, I noticed that I rarely use properties, due to the fact that I rarely need to access my object's variables outside my class ;) So I usually do : NSMutableArray *myArray; // not a property ! My question is : even if i don't declare myArray as a property, does iphone make a retain anyway if I do myArray = arrayPassedToMe;...
I'm trying to set a static pointer variable in a class but I'm getting these errors for each variable I try to set. error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2040: 'xscroll' : 'int' differs in levels of indirection from 'float *' error C2440: 'initializing' : cannot convert from '...
I have a base class A with a constant static variable a. I need that instances of class B have a different value for the static variable a. How could this be achieved, preferably with static initialization ? class A { public: static const int a; }; const int A::a = 1; class B : public A { // ??? // How to set *a* to a valu...
In the following code: <script type="text/javascript"> var i = 10; function Circle(radius) { this.r = radius; this.i = radius; } Circle.i = 123; Circle.prototype.area = function() { alert(i); } var c = new Circle(1); var a = c.area(); </script>...
I have some doubt about python's class variables. As my understanding, if I define a class variable, which is declared outside the __init__() function, this variable will create only once as a static variable in C++. This seems right for some python types, for instance, dict and list type, but for those base type, e.g. int,float, is no...
Hi, I'm new to Python and it's OOP stuff and can't get it to work. Here's my code: class Tree: root = None; data = []; def __init__(self, equation): self.root = equation; def appendLeft(self, data): self.data.insert(0, data); def appendRight(self, data): self.data.append(data); def c...
In almost all of my classes, I have a mixture of properties and internal class variables. I have always chosen one or the other by the rule "property if you need it externally, class variable if not". But there are many other issues which make me rethink this often, e.g.: at some point I want to use an internal variable from outside th...