473,396 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

accessing class variables of private classes

Hi,

I need to access class variables of a class I'd like to make private:

i.e.
class __Bar(object):
pass

class __Foo(__Bar):
def __init__(self):
super(__Foo, self).__init__()
__Foo() Name Error: global name '_Foo__Foo' is not defined

Here I want to prevent the user of instanciating __Foo from outside of the
module.
i.e.
class __A:
a_list = []
def __init__(self):
__A.a_list.append(self)
__A()

NameError: global name '_A__A' is not defined

Here I want to keep a list of instanciated objects of class __A, so I can
update internal values if they are changed.
Any ideas?

Thanks
Uwe
Jul 18 '05 #1
2 1336
Uwe Mayer wrote:
I need to access class variables of a class I'd like to make private:

i.e.
class __Bar(object):
pass

class __Foo(__Bar):
def __init__(self):
super(__Foo, self).__init__()
__Foo() Name Error: global name '_Foo__Foo' is not defined

Here I want to prevent the user of instanciating __Foo from outside of the
module.
i.e.
class __A:
a_list = []
def __init__(self):
__A.a_list.append(self)
__A()
NameError: global name '_A__A' is not defined

Here I want to keep a list of instanciated objects of class __A, so I can
update internal values if they are changed.
Any ideas?


Use single underscores. Even better: don't impose bogus restrictions on
users of your module. I know, we're all dissenting children, but still...

Thanks
Uwe


Jul 18 '05 #2
Uwe Mayer wrote:
Hi,

I need to access class variables of a class I'd like to make private:

Use single underscores instead of double underscores--you won't have to
workaround the name mangling. Besides, nothing's really private anyway.

// m
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes....
10
by: Not Available | last post by:
On the host server: namespace JCart.Common public class JCartConfiguration : IConfigurationSectionHandler private static String dbConnectionString; public static String ConnectionString { get...
2
by: Rustam Asgarov | last post by:
how can i access variables defined in the parent class from the child class: By some way other than passing as parameter to constructor. I mean. class Parent{ public int b; public...
5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
1
by: jgamble | last post by:
Hi, Here's a question for you all. Under "classic" ASP any ASP page could have any number of #Include files. Using #Include files I could have functions which were common to my whole site and...
8
by: dwok | last post by:
I have been wondering this for a while now. Suppose I have a class that contains some private member variables. How should I access the variables throughout the class? Should I use properties that...
5
by: Cyril Gupta | last post by:
Hello, I have a class inside another class. The Scenario is like Car->Engine, where Car is a class with a set of properties and methods and Engine is another class inside it with its own set of...
5
by: MrJim | last post by:
How should variables be declared and referenced in both the base and derived form so they can be accessed?
6
by: earthwormgaz | last post by:
Is the following legal? class Outer { class Inner { private: Inner() { } };
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.