473,769 Members | 4,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why and how "there is only one way to do something"?


As far as I know, Perl is known as "there are many ways to do
something" and Python is known as "there is only one way". Could you
please explain this? How is this possible and is it *really* a good
concept?

Dec 15 '05
44 4209
[Steve Holden, to bonono]
...
I believe I have also suggested that the phrases of the Zen aren't to be
taken too literally.
Heretic.
You seem to distinguish between "obvious" meaning "obvious to Steve
but not necessarily to me" and "really obvious" meaning "obvious to both
Steve and me". So where does the subjectivity creep in?
For those who have ears to hear, it's sufficient to note that:

There should be one-- and preferably only one --obvious way to do it.

is followed by:

Although that way may not be obvious at first unless you're Dutch.
And are you going to spend the rest of your life arguing trivial semantics?


A more interesting question is how many will spend the rest of their
lives responding ;-)

perfect-dutchness-is-a-journey-not-a-destination-ly y'rs - tim
Dec 15 '05 #31
In article <ma************ *************** ************@py thon.org>,
Steve Holden <st***@holdenwe b.com> wrote:
Aahz wrote:
In article <ma************ *************** ************@py thon.org>,
Steve Holden <st***@holdenwe b.com> wrote:

(Part of) Python's credo (which you can read in context by typing

import this

at an interactive command prompt) is "There should be one (and
preferably only one) way to do it".


Actually, I've gotten used to doing

python -c 'import this'


Faster:

python -m this


Only in Python 2.4 and later:

starship:~> python2.3 -m this
Unknown option: -m
usage: python2.3 [option] ... [-c cmd | file | -] [arg] ...
Try `python -h' for more information.

Why, oh why, do so many people on this newsgroup only consider the latest
version "correct"? I've been guilty myself on occasion, but I do try to
label my suggestions with version warnings.
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

"Don't listen to schmucks on USENET when making legal decisions. Hire
yourself a competent schmuck." --USENET schmuck (aka Robert Kern)
Dec 15 '05 #32
Simon Brunning wrote:
On 12/15/05, Steve Holden <st***@holdenwe b.com> wrote:
Aahz wrote:
python -c 'import this'


Faster:

python -m this

So, there's two ways to do it. ;-)

You want a clip round the ear?

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Dec 15 '05 #33
On Thu, 15 Dec 2005 14:57:18 +0000 in comp.lang.pytho n, Steve Holden
<st***@holdenwe b.com> wrote:

[...]
Would you say

do:
suite
while condition

or what? Basically do ... while and do ... until most naturally put the
Works for me, though I wouldn't cry if the "while" was changed to
"until" to make the difference between this form and the "while" loop
more obvious. I don't think there's a good argument for _both_
do-while and do-until, but one or the other would be useful.

The biggest objection I see is the addition of one or two more
keywords, but I don't recall using "do" or "until" as a name in any of
my programs...
test after the loop body (suite), and it's difficult to think of a
consistent and natural syntax for expressing the construct. Not that
this stopped lots of people from coming forward with their personal
favourites ... some suggestions even offered "n and a half" looping
possibilitie s.


Syntax is the problem? Specifically the position of the condition
after the loop body? How do you explain the syntax of the new Python
ternary operation, with the test in the middle, even though it
logically has to be done first?

Right now, I tend to write these loops something like

while 1:
do_stuff()
if exit_condition: break

which offends my sense of aesthetics, but it works.

Regards,
-=Dave

--
Change is inevitable, progress is not.
Dec 15 '05 #34
On Thu, 15 Dec 2005 16:28:30 +0100,
Xavier Morel <xa**********@m asklinn.net> wrote:
$ python -m this
(no quotes needed btw)
*Three*. *Three* ways to do it: import, -c, -m, and an almost
fanatical devotion to the Pope.
It's usually useful to pipe it through grep too, in order to get only
the piece of zen knowledge you need.


That's just wrong. [throws hands and arms up in [mock] disgust]

Enlightenment does not come in discrete pieces, to be learned one at a
time, to be applied selectively.

Regards,
Dan

--
Dan Sommers
<http://www.tombstoneze ro.net/dan/>
Dec 15 '05 #35
Aahz wrote:
In article <ma************ *************** ************@py thon.org>,
Steve Holden <st***@holdenwe b.com> wrote:
Aahz wrote:
In article <ma************ *************** ************@py thon.org>,
Steve Holden <st***@holdenwe b.com> wrote:

(Part of) Python's credo (which you can read in context by typing

import this

at an interactive command prompt) is "There should be one (and
preferabl y only one) way to do it".

Actually, I've gotten used to doing

python -c 'import this'


Faster:

python -m this

Only in Python 2.4 and later:

starship:~> python2.3 -m this
Unknown option: -m
usage: python2.3 [option] ... [-c cmd | file | -] [arg] ...
Try `python -h' for more information.

Why, oh why, do so many people on this newsgroup only consider the latest
version "correct"? I've been guilty myself on occasion, but I do try to
label my suggestions with version warnings.


Why, oh why, do people who don't run the latest version assume that a
solution for a more recent version labels their original solution
"incorrect" ?

Dammit, the only word in my post apart from the command was "faster".
Not "wronger" or "righter" or even "better". So climb down off that high
horse. Sheesh.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Dec 15 '05 #36
>>>>> "bonono" == bonono <bo****@gmail.c om> writes:

bonono> What I don't quite understand is, if it is "obvious",
bonono> whether there is a Zen, people would still code it that
bonono> way(unless of course they want to hide it from others or
bonono> make it difficult to understand on purpose), there won't
bonono> be any argument of "which one is the obvious way". And if
bonono> there is an argument(or disagreement), which one is the
bonono> obvious ?

Python seems to strive for consistency in all levels. The 'obvious
way' is the one with the greatest stylistic cohesion across the rest
of the language.

When you delve into a new realm, as I have lately been investigating
the logging module, consistency helps lower the learning curve; we're
re-cycling as much knowledge as possible.

bonono> I think it is more like there is a preferred way, by the
bonono> language creator and those share his view.

You're right. There is no way to factor out the subjective nature of
what becomes orthodoxy. Guido's taste, while perhaps imperfect, still
stands out. Props.

-Chris
Dec 15 '05 #37
OhmiGod! I posted this message this morning and when I came home, I
said myself "umm, lemme check it" and I cannot believe what I see... 37
threads!

As long as Python is supported by such a hardworking and enthusiastic
community, I'm sure that he (=Python) will become the nightmare of many
other languages.

Thank you all...

Dec 15 '05 #38
bo****@gmail.co m writes:
The point is again, "obvious" is not so obvious sometimes.
You keep leaving out the context. We're writing *python*. What's
obvious when you're writing python won't be when you're writing
FORTRAN, or Scheme, or O'Caml, or Eiffel, or .... Generally (not
always, I'll admit), when you're writing python, there's one obvious
way to do something. If not, there's a good chance you're not writing
python, you're writing something else with python syntax.
For most of the question I see asking here, they are from another
language background and their obvious way is what they are asking for
that they cannot find in python.


Back in the dark ages, when computers had entire rooms, if not
buildings, dedicated to them, I worked the support desk at a large
state university. Most people learned FORTRAN as a first language, and
then some of them went on to other languages. The standing observation
was that "You can write FORTRAN in any language." This is because
people would write FORTRAN constructs no matter what language they
were using. If the language had a goto, they'd write:

if not condition: goto after
# if body
after:

If the language didn't have a goto, they'd write:

if not condition:
else:
# if body
And then they'd complain if the grader marked them down for doing
this kind of thing.

People coming from other languages trying to write the obvious way
from that language in python are doing the exact same thing as the
people who wrote the above fragments were doing: writing <fill in the
blank> in python. It's not as obviously wrong because the languages
are more recent than FORTRAN, but it's just as wrong.

<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Dec 15 '05 #39
On Thu, 15 Dec 2005, Simon Brunning wrote:
On 12/15/05, Steve Holden <st***@holdenwe b.com> wrote:
Aahz wrote:
python -c 'import this'


Faster:

python -m this


So, there's two ways to do it. ;-)


Yes, but which way do you do it if you're Dutch?
Dec 15 '05 #40

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

Similar topics

51
7006
by: Noam Raphael | last post by:
Hello, I thought about a new Python feature. Please tell me what you think about it. Say you want to write a base class with some unimplemented methods, that subclasses must implement (or maybe even just declare an interface, with no methods implemented). Right now, you don't really have a way to do it. You can leave the methods with a "pass", or raise a NotImplementedError, but even in the best solution that I know of,
6
7066
by: Mason A. Clark | last post by:
LAST WORD(s): 1. MSIE6 and Firefox will go to the top of the page on command <a href="#top">go upsy</a> even if there is NO name="top" or id="top" They know what a "top" is :-) Opera does not.
11
4221
by: Paul D.Smith | last post by:
Can Python create a variable "on-the-fly". For example I would like something like... make_variable('OSCAR', 'the grouch'); print OSCAR; ....to output... the grouch
3
1371
by: Petr Prikryl | last post by:
Hi all, My question is: How do you tackle with mixing Unicode and non-Unicode parts of your application? Context: ======== The PEP 3000 says "Make all strings be Unicode, and have a separate bytes() type."
1
4330
by: Mark E. Hamilton | last post by:
Sorry, I probably should have re-stated the problem: We're using Python 2.3.5 on AIX 5.2, and get the follow error messages from some of our code. I haven't yet tracked down exactly where it's coming from: sem_trywait: Permission denied sem_wait: Permission denied sem_post: Permission denied
10
4707
by: schears | last post by:
Why? Running on windows 2000 with all updates, 2G Memory, 117G Hard Drive space available. This was not an issue until I added some code to two of my c files. Any suggestions? Thanks
4
3839
by: Mike Cooper | last post by:
There is something about inherited classes I evidently don't know... I wrote the following class: Class Class1 inherits System.Windows.Forms.DataGridTextBoxColumn End Class There is absolutely no added functionality to it.
10
2934
by: RDI | last post by:
What's it mean? My prog runs fine. Then as soon as I press ok or cancel, the following is what's in the output area of the debugger. TIA -- RDI (remove the exclamation from the email address)
2
2626
by: John Nagle | last post by:
For some reason, Python's parser for "robots.txt" files doesn't like Wikipedia's "robots.txt" file: False The Wikipedia robots.txt file passes robots.txt validation, and it doesn't disallow unknown browsers. But the Python parser doesn't see it that way. No matter what user agent or URL is specified; for that robots.txt file, the only answer is "False". It's failing in Python 2.4 on Windows and 2.5 on Fedora Core.
56
6766
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15) says under 6.4.2(2) : case constant-expression : I propose that the case expression of the switch statement be changed from "integral constant-expression" to "integral expression".
0
9589
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
9423
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
10222
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
9999
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
9866
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
7413
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
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
3
2815
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.