instance

DJANGO - How do you access the current model instance from inside a form.

class EditAdminForm(forms.ModelForm): password = username.CharField(widget=forms.TextInput()) password = forms.CharField(widget=forms.PasswordInput()) password_confirm = forms.CharField(widget=forms.PasswordInput(), initial=???) You can see what I'm trying to do here. How would I go about pre-populating the pasword_confirm ...

Multiple instances of j2me midlet problem

I have a j2me midlet running on a cell phone. The code works fine, but the issue that comes up is that the program seems to be running more than one instance of itself. I have code at the beginning of the application inside the appStart() method that runs twice when the application starts. During the lifetime of the program, the code ...

C# When to use Static Classes as opposed to Instances of Classes?

Possible Duplicate: When to Use Static Classes in C# Questions in the title..........i would greatly appreciate opinions on when it's best to use each? Regards ...

Inheriting from instance in Python

Hello, In Python, I would like to construct an instance of the Child's class directly from an instance of the Parent class. For example: A = Parent(x, y, z) B = Child(A) This is a hack that I thought might work: class Parent(object): def __init__(self, x, y, z): print "INITILIZING PARENT" self.x = x sel...

Run multiple mysql instances in mysql

Hi All, I want to use mysql server on two different ports on same machine. I made two separate cnf files for the same. when I am trying to connect to mysql server with second port which i have added I am unable to do so. I am working on Windows Vista. I tried to start mysqld from command line after specifying port. This is the sample f...

How to test if a class attribute is an instance method.

In Python I need to efficiently and generically test whether an attribute of a class is an instance method. The inputs to the call would be the name of the attribute being checked (a string) and an object. hasattr returns true regardless of whether the attribute is an instance method or not. Any suggestions? For example: class Test...

NHibernate, saving IDictionary : TransientObjectException

In my class Case I have an IDictionary with Entity (a class) as key and Roles (an enum) as value. When trying to save a new instance (non-persisted) of Case, where the IDictionary is filled with new instances of Entity I get the following error: NHibernate.TransientObjectException: object references an unsaved transient instance - sa...

Ruby instance methods from a string and a block

Is it possible to define an instance method in ruby from a string (the method name) and a block (the method's contents)? I imagine this will need to use instance_eval(), but I haven't figured out how to mix the two data types yet. Both the string and the block are dynamically determined, so it would work to create the block with the "de...

Instantiate singleton object using Class.forName()?

I want to instantiate one instance of a class from the string name of the class. ( using Class.forName().newInstance(). ) Here's the problem: I want that instance to be a singleton.. I could do this using a singleton pattern, except that newInstance calls the default constructor for a class, and with a singleton, that constructor must ...

Should I make this XmlSerializer static?

I've got a class which uses an XmlSerializer in its Read/WriteXml methods. The Serializer is currently private readonly. public class Foo : IXmlSerializable { private Bar _bar = new Bar(); private readonly XmlSerializer serBar = new XmlSerializer (typeof (Bar)); public void WriteXml (XmlWriter writer) { serBar.S...

A question regarding string instance uniqueness in python

I was trying to figure out which integers python only instantiates once (-6 to 256 it seems), and in the process stumbled on some string behaviour I can't see the pattern in. Sometimes, equal strings created in different ways share the same id, sometimes not. This code: A = "10000" B = "10000" C = "100" + "00" D = "%i"%10000 E = str(100...

Is it possible to get an instance of every class that inherits from an interface?

I have a small project that I'm making, and I'm trying to figure out if it's possible to get an instance of every class that inherits from a particular interface. Here's a simplified example of what I'm trying to accomplish: public interface IExample { string Foo(); } public class Example1 : IExample { public string Foo() ...

The difference between Classes, Objects, and Instances

What are class, object and instance in the context of java? Please illustrate your answer with examples. ...

C : How do you simulate an 'instance' ?

Let's say that I have the following code in C that represents a stack : #define MAX 1000 int arr[MAX]; static int counter = 0; isstackempty() { return counter <= 0; } void push(int n) { if (counter >= MAX) { printf("Stack is full. Couldn't push %d", n); return; } arr[counter++] = n; } int pop(int* n) ...

Limit instances creation of a class?

I am using C#. I have created a class which can be included in any c#.net project (desktop or web based), but I want that only 10 objects will be created in that application of my class. If object instances created more than 10 then it should give an error or simple will not work. There can be two situations, I'll included myclass.cs...

initialize a class by string variable in c#?

Hi, is it possible to initialize a class by a string variable? I have code in PHP. <?php $classname = "test"; $oTest = new $classname(); class test{ } ?> how do I do this in c#? ...

Java threading and the JTabbedPane dilemma

In a project I'm working on, I have a main class (named TrackWin) that extends JFrame. In this frame, I make use of a JTabbedPane. A user can create a new tab in the pane from the Menu Bar. Whenever this occurs, tabbedPane.addTab() is called in TrackWin. I also have a class called TrackTab, which extends JPanel. This class contains a...

Python : Assert that variable is instance method?

How can one check if a variable is an instance method or not? I'm using python 2.5. Something like this: class Test: def method(self): pass assert is_instance_method(Test().method) ...

Difference between accessing an instance attribute and a class attribute

Hi all, I have a Python class class pytest: i = 34 def func(self): return "hello world" When I access pytest.i, I get 34. I can also do this another way: a = pytest() a.i This gives 34 as well. If I try to access the (non-existing) pytest.j, I get Traceback (most recent call last): File "<pyshell#6>", line 1, in ...

Sharing objects

Imagine that I have a nice Deck class, in the best OO fashion. It has Cards, which have a Suit and a Rank, it has a Shuffle method, and so on. Now, I'm going to have a lot of concurrent instances of Deck (say this is a casino). The question is: Should there be a different instance of every card across all the decks? ...