Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > classes

Reply
Thread Tools

classes

 
 
Pablo
Guest
Posts: n/a
 
      07-19-2003
Hello everyone

I'm rather new to Python and have a problem I hope someone can help me
solve.
I'm used to Java syntax and would like to make a class which holds a
connection object to PostgreSQL database.
I want to make this class as a singleton, and
allow creation only of one instance of the class.

code in Java would like more or less like this:

class Connection{
private static Connection instance = null;
private DBConnection = null; // in python's case it would be pgobject returned
be connect()

private Connection(){
DBConnection = pg.DB();
}

public static Connection getInstance(){
if(instance == null)
instance = new Connection();
return instance;
};

How can I do the same thing in Python?
How can I declare a static field (and private) of a class and allow access to it only by
a static method?
Can I forbid to instantiate more than one object?

I'd be grateful if someone can explain it to me or send me to the good
resource with description about classes which would have some comparisons
of syntax regardig Java or C++.

Best regards
Pablo
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Classes within classes David ASP .Net 2 07-22-2005 07:13 PM
What is the difference between nested classes and inner classes ? Razvan Java 5 07-27-2004 07:59 PM
Modifiers applied to attributes, local variables, member functions, classes and inncer classes ! Razvan Java 11 07-17-2004 08:57 PM
Can I using reflection to get all child classes or classes undera package dynamically? Carfield Yim Java 1 05-31-2004 05:33 PM
How to access inner classes variables & methods from outer classes lonelyplanet999 Java 1 11-13-2003 01:54 PM



Advertisments