473,785 Members | 2,325 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

python's OOP question

There's a program, it's result is "unexpected aaa", i want it to be
"expected aaa". how to make it work?

Expand|Select|Wrap|Line Numbers
  1.  
  2. class C1(object):
  3. def v(self, o):
  4. return "expected "+o
  5.  
  6. class C2(object):
  7. def v(self, o):
  8. return "unexpected "+o
  9. def m(self):
  10. print self.v("aaa")
  11.  
  12. class C3(object):
  13. def nothing(self):
  14. pass
  15.  
  16. def test1():
  17. o = C3()
  18. setattr(o,"m",C2().m)
  19. setattr(o,"v",C1().v)
  20. o.m()
  21.  
  22. test1()
  23.  
  24.  
Oct 16 '06
23 1515
"neoedmund" <ne*******@gmai l.comwrites:
Bruno Desthuilliers wrote:
neoedmund wrote:
in real life, a class is not defined so well that any method is
needed by sub-class.
Then perhaps is it time to refactor. A class should be a highly
cohesive unit. If you find yourself needing only a specific subset
of a class, it may be time to extract this subset in it's own
class.

I donnot agree with your "it's time to refactory" very much, man has
probly never has time to do such things.
I respectfully suggest that the *reason* you find yourself with little
time to refactor is probably related to the fact that you *need* to
refactor. If your code is crufty and poorly-designed, it is costing
you every time you need to maintain it.

Would it help if we called it "preventati ve maintenance"?

--
\ "I bought a dog the other day. I named him Stay. It's fun to |
`\ call him. 'Come here, Stay! Come here, Stay!' He went insane. |
_o__) Now he just ignores me and keeps typing." -- Steven Wright |
Ben Finney

Oct 18 '06 #21
On 2006-10-18, neoedmund <ne*******@gmai l.comwrote:
ivestgating the web, i found something similiar with my approch:
http://en.wikipedia.org/wiki/Duck_typing
"Duck-typing avoids tests using type() or isinstance(). Instead, it
typically employs hasattr() tests"
It's pity it didn't get called quack typing. One ckecks if
some unknown noun can quack, not if a duck can do something
unknown.

--
Neil Cerutti
Oct 18 '06 #22
Neil Cerutti wrote:
On 2006-10-18, neoedmund <ne*******@gmai l.comwrote:
>ivestgating the web, i found something similiar with my approch:
http://en.wikipedia.org/wiki/Duck_typing
"Duck-typing avoids tests using type() or isinstance(). Instead, it
typically employs hasattr() tests"

It's pity it didn't get called quack typing.
That's because the quacks recommend static typing.

Peter

Oct 18 '06 #23
Neil Cerutti wrote:
On 2006-10-18, neoedmund <ne*******@gmai l.comwrote:
>ivestgating the web, i found something similiar with my approch:
http://en.wikipedia.org/wiki/Duck_typing
"Duck-typing avoids tests using type() or isinstance(). Instead, it
typically employs hasattr() tests"

It's pity it didn't get called quack typing.
That's because the quacks prescribe static typing.

Peter

Oct 18 '06 #24

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

Similar topics

44
3424
by: Carl | last post by:
"Nine Language Performance Round-up: Benchmarking Math & File I/O" http://www.osnews.com/story.php?news_id=5602 I think this is an unfair comparison! I wouldn't dream of developing a numerical application in Python without using prebuilt numerical libraries and data objects such as dictionaries and lists. I have been experimenting with numerical algorithms in Python with a heavy use of the Numeric module. My experience is that Python...
114
9886
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
68
5897
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
50
5740
by: diffuser78 | last post by:
I have just started to learn python. Some said that its slow. Can somebody pin point the issue. Thans
112
13866
by: mystilleef | last post by:
Hello, What is the Pythonic way of implementing getters and setters. I've heard people say the use of accessors is not Pythonic. But why? And what is the alternative? I refrain from using them because they smell "Javaish." But now my code base is expanding and I'm beginning to appreciate the wisdom behind them. I welcome example code and illustrations.
158
6428
by: Giovanni Bajo | last post by:
Hello, I just read this mail by Brett Cannon: http://mail.python.org/pipermail/python-dev/2006-October/069139.html where the "PSF infrastracture committee", after weeks of evaluation, recommends using a non open source tracker (called JIRA - never heard before of course) for Python itself. Does this smell "Bitkeeper fiasco" to anyone else than me? --
4
2128
by: Martitza | last post by:
Hi. I work for a small company (actually in process of forming) interested in embedding or extending python as part of our commercial non-open-source product. We have legal counsel, but are interested in the spirit as well as the letter of the law. Not much seems to have been written about the python license since version 2, so pointers to more recent discussions or contacts are appreciated. If this is not the right place to ask these...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10341
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...
1
10095
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8979
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
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
6741
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
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.