473,698 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

About the use of **args


Hi

I'm starting a new proyect and i'm in doubt about diferent interfaces
for my clases. My clases will have a lot of attributes and i'm want to
know what aproach could be the best

1) Define one SetAttribute/GetAttribute pair of method for each
attribute.
2) Define one SetAttribute/GetAttribute which argument is a key=value
format.

Any advaice?

Thanks in advance

Zunbeltz Izaola

--
Remove XXX from email: zu******@wm.lc. ehu.esXXX
Jul 18 '05
12 2008
Jacek Generowicz wrote:
I find the suggestion that a mangled name is somehow "more private"
than one with a single leading underscore, mildly insulting to the
clients of your code. The implcation is that they can neither work out
the (very complicated and cryptic[*]) mangling scheme, not use dir().


no, the implication is that they can use their own __variables without
having to think about what you're calling your private parts.

in contrast, a _variable is not hidden at all.

</F>


Jul 18 '05 #11
"Fredrik Lundh" <fr*****@python ware.com> writes:

I want to sum up some ideas in the thread:

1) setters and getters are not mandatory.

2) The usual way in Python is the direct access
[=] ... b.width # is get
b.width = # is set
del b.width # is del


3) If when setting some attribute there is necesary to have side
effects, it can be achive defining __setattr__ and doing the right
thing depend on the attribute. (It is possible to raise an
exception when the attribute is not in a list/dictionary of usable
attributes, to prevent typos and such kind of errors)

4) __getattr__ can be defined to deal with undefined attributes. For
example it can handle in different way the attributes in a list of
permited attributes (see point 3)

5) attributes that are computed in the fly, can be get like normal
attributes using "property" (property is new in 2.3 or 2.2?)

6) attributes and methods that are no part of the user interface are
named with and _ in the front. (This is a convention)

Are those ideas correct? We can continue with the discussion!!

Zunbeltz
--
Remove XXX from email: zu******@wm.lc. ehu.esXXX
Jul 18 '05 #12
Zunbeltz Izaola <zu******@wm.lc .ehu.es.XXX> writes:

[snip]
3) If when setting some attribute there is necesary to have side
effects, it can be achive defining __setattr__ and doing the right
thing depend on the attribute. (It is possible to raise an
exception when the attribute is not in a list/dictionary of usable
attributes, to prevent typos and such kind of errors)

4) __getattr__ can be defined to deal with undefined attributes. For
example it can handle in different way the attributes in a list of
permited attributes (see point 3)

5) attributes that are computed in the fly, can be get like normal
attributes using "property" (property is new in 2.3 or 2.2?)
[snip]
Are those ideas correct?


Pretty much.

Properties are available in 2.2. They only work on new style classes.

Just about anything that can be done with properties can be done with
__setattr__ &co, but I think that properties are generally preferred,
if available.
Jul 18 '05 #13

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

Similar topics

7
4175
by: Herman | last post by:
Hi everyone, I recently installed the Sun J2SE SDK on my machine, and I am having trouble running the java.exe interpreter for my Java compiled code. I remember that I had to set my environment CLASSPATH variable to whatever the current directory is, but I forgot the exact characters to denote this. Or that there was an extra call to the java interpreter (like -cp or -classpath) to indicate the current directory, but that escapes me as...
220
19038
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
45
2576
by: Edward K. Ream | last post by:
Hello all, First of all, my present state of mind re pep 318 is one of sheepish confusion. I suspect pep 318 will not affect Leo significantly, but I am most surprised that an apparently controversial feature is being added without a notice, say, in comp.lang.python.announce. I say sheepish, because everyone knows that one should make sure new proposals don't bite you. Still, I would have thought that there were other ways of keeping...
22
1754
by: lechequier | last post by:
Let's say I define a list of pairs as follows: >>l = Can anyone explain why this does not work? >>h = {}.update(l) and instead I have to go: >>h = {} >>h.update(l) to initialize a dictionary with the given list of pairs?
3
1865
by: googleboy | last post by:
Hi there. I have defined a class called Item with several (about 30 I think) different attributes (is that the right word in this context?). An abbreviated example of the code for this is: class Item(object): def __init__(self, height, length, function): params = locals()
9
2262
by: happyvalley | last post by:
I just wonder how to pass arguments to this function with a char** void oldmain(int argv, char**argc) { ........ } void main(void) { int argv;
3
1183
by: fdu.xiaojf | last post by:
Hi all, I'm not skilled at programming, so sorry for my ignorance. My questions: (1) which is the better way to calculate the value of attributes of a class ? for example: (A) def cal_attr(self, args): #do some calculations
1
1039
by: Steven W. Orr | last post by:
I have a structure I need to pack. I call struct.pack about a dozen times and each call takes about 53 arguments. I create a sequence of the arguments: a1 = 1 a2 = 2 a3 = 3 etc... a54 = 88 myseq = (a1, a2, a3, a4 etc... a53)
37
2181
by: Hilton | last post by:
Hi, for (int i = 0; i < list.Count; i++) has a hidden performance hit; i.e. list.Count gets evaluated each time, so we write something like: int listCount = list.Count; for (int i = 0; i < listCount; i++)
9
1533
by: lorlarz | last post by:
I still have a question regarding the following code, in a commonly used routine. First, Here's the code in question: Function.prototype.bind = function(){ var fn = this, args = Array.prototype.slice.call(arguments), object = args.shift(); return function(){ return fn.apply(object, args.concat(Array.prototype.slice.call(arguments)));
0
8612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8880
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.