473,378 Members | 1,360 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,378 software developers and data experts.

property () for Java Programmers ?

Hi there,

I am somewhat confused by the following :

class C(object):
def getx(self): return self.__x
def setx(self, value): self.__x = "extended" + value
def delx(self): del self.__x
x = property(getx, setx, delx, "I'm the 'x' property.")

So far so good :-) But what to do with this now
c = C
c <class '__main__.C'> dir (c) ['__class__', '__delattr__', '__dict__', '__doc__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'__weakref__', 'delx', 'getx', 'setx', 'x'] c.x <property object at 0x401edbbc>


?????? What can I do with this "property object" now.

Confused greetings

Michael
Jul 18 '05 #1
2 1066
michael wrote:
Hi there,

I am somewhat confused by the following :

class C(object):
def getx(self): return self.__x
def setx(self, value): self.__x = "extended" + value
def delx(self): del self.__x
x = property(getx, setx, delx, "I'm the 'x' property.")

So far so good :-) But what to do with this now

c = C
c
<class '__main__.C'>
dir (c)
['__class__', '__delattr__', '__dict__', '__doc__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'__weakref__', 'delx', 'getx', 'setx', 'x']
c.x


<property object at 0x401edbbc>
?????? What can I do with this "property object" now.


Well, if you actually want your getx/setx/delx to be called, then you
need an *instance* of class C:

py> c = C()
py> c.x
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "<interactive input>", line 2, in getx
AttributeError: 'C' object has no attribute '_C__x'
py> c.x = "42"
py> c.x
'extended42'
py> del c.x
py> c.x
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "<interactive input>", line 2, in getx
AttributeError: 'C' object has no attribute '_C__x'

Note that I used 'c = C()' instead of 'c = C' as in your code.

STeve
Jul 18 '05 #2
> Note that I used 'c = C()' instead of 'c = C' as in your code.
Hello,

thanks that was the problem. *hmpf* :-)

Michael

Jul 18 '05 #3

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

Similar topics

73
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities...
8
by: Ray | last post by:
Hello there, I've been programming in Java for about 8 years now, but lately I've been hearing a lot about Python and I'm really interested in learning more about it. I've read the tutorial, and...
21
by: asj | last post by:
well, at least for the forseeable future, it looks like. i've always thought mauricio aguilar was a loony for continuing to post these job stats, when we all know C#/.NET jobs HAVE to go up...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
133
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
5
by: TZESENG | last post by:
DECEMBER 13, 2005 . Editions: N. America | Europe | Asia | Edition Preference News Analysis By Steve Hamm Source: http://www.businessweek.com/technology/content/dec2005/tc20051213_042973.htm...
28
by: liorm | last post by:
Hi everyone, I need to write a web app, that will support millions of user accounts, template-based user pages and files upload. The client is going to be written in Flash. I wondered if I coudl...
20
by: mayershome | last post by:
Hi! I'dont have any experiences in programming... what language should I start learning???? C? C++ or Java`? greetz
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
350
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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...

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.