473,405 Members | 2,141 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,405 software developers and data experts.

SOS - property question

Hi !

I don't understand something:

See that code:
class A(object):
__slots__=('x','a','__v')
def __init__(self):
self.__v=0
def g(self):
print "g"
return self.__v
def s(self,v):
self.__v=v
print "s"
GS=property(g,s)

a=A()
print a.g()
a.s(1)
print a.g()
#print a.GS
a.GS=2
print a.GS
print a.g()

It is working.
But when we remove slots, it is missing: the a.GS is not used as
property, it is access a local member. Why ?

class A(object):
def __init__(self):
self.__v=0
def g(self):
print "g"
return self.__v
def s(self,v):
self.__v=v
print "s"
GS=property(g,s)

a=A()
print a.g()
a.s(1)
print a.g()

#print a.GS
a.GS=2
print a.GS
print a.g()

Another question: why the __slots__ is working only if this member is in
body of A ?
Why isn't when it is in the __init__ procedure ?

def __init__(self):
self.__v=0
__slots__=('x','a','__v')
Thanx for help:
FT


Jul 18 '05 #1
1 1390
"kepes.krisztian" <ke*************@peto.hu> wrote in message
news:ma**************************************@pyth on.org...

See that code:
class A(object):
__slots__=('x','a','__v')
def __init__(self):
self.__v=0 .... Another question: why the __slots__ is working only if this member is in
body of A ?
Why isn't when it is in the __init__ procedure ?

def __init__(self):
self.__v=0
__slots__=('x','a','__v')


I can't answer your first question, but I can the second. In the first
piece of code, you have defined __slots__ (correctly) as an attribute of the
class A. In the second piece, you have created a local variable called
__slots__ within the __init__() method. As soon as the __init__ method
returns, that local variable is gone!! Changing it to self.__slots__
wouldn't work either, because that would define an attribute of the
*instance*, not of the *class*. Slots and properties belong to the class,
not to its instances.
--
I don't actually read my hotmail account, but you can replace hotmail with
excite if you really want to reach me.
Jul 18 '05 #2

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

Similar topics

7
by: jeffbernstein | last post by:
Greetings. I'm reading "How to think like a computer scientist: Learning with Python" and there's a question regarding string operations. The question is, "Can you think of a property that...
7
by: vh | last post by:
Hi, I'm new to C#. Most examples about properties I found are sth like the following: class A{ private int property; public int Property { get { return property; } set { property = value; } }...
2
by: Edward Diener | last post by:
How does one specify in a component that a property is a pointer to another component ? How is this different from a property that is actually an embedded component ? Finally how is one notified in...
62
by: djake | last post by:
Someone can explain me why to use property get and property set to access a value in a class, insted of access the value directly? What's the usefulness of property statements in VB.NET? Thanks
27
by: Just Me | last post by:
I made a Usercontrol that must have AutoScroll set to true when it is used. So I set it to True in the Load event. However the property still shows in the properties window when the control is...
3
by: Mark Jones | last post by:
I am quite new to ASP and .Net development and I am building a web-based multiple choice exam application. The web page displays the questions using a Repeater control and the answers are nested...
15
by: Sam Kong | last post by:
Hello! I got recently intrigued with JavaScript's prototype-based object-orientation. However, I still don't understand the mechanism clearly. What's the difference between the following...
10
by: Franky | last post by:
I think I misread a post and understood that if I do: System.Windows.Forms.Cursor.Current = Cursors.WaitCursor there is no need to reset the cursor to Default. So I made all the reset...
0
ADezii
by: ADezii | last post by:
The motivation for this Tip was a question asked by one of our Resident Experts, FishVal. The question was: How to Declare Default Method/Property in a Class Module? My response to the question was...
8
by: Hussein B | last post by:
Hey, I noted that Python encourage the usage of: -- obj.prop = data x = obj.prop -- to set/get an object's property value. What if I want to run some logic upon setting/getting a property?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.