22 2210
beliavsky> Is there a more recent set of Python style guidelines than
beliavsky> PEP 8, "Style Guide for Python Code", by van Rossum and
beliavsky> Warsaw, at http://www.python.org/peps/pep-0008.html , which
beliavsky> is dated July 5, 2001?
Is there something missing you think should be there? There's no particular
reason a PEP needs to be continually updated. In particular, notions of
good Python style haven't changed a lot over the past ten years.
Skip
> Is there something missing you think should be there? There's no particular reason a PEP needs to be continually updated. In particular, notions of good Python style haven't changed a lot over the past ten years.
Skip
I agree, those are good guidelines, but I don't agree with:
- Don't compare boolean values to True or False using == (bool
types are new in Python 2.3):
No: if greeting == True:
Yes: if greeting:
What would happened if you do: a='test' if a.find('foo'):
.... print "foo was found"
....
foo was found
I think you should never do a direct boolean comparison. Instead
one should use a more elaborate boolean expresion like:
a='test' if a.find('foo') >= 0:
.... print "foo was found"
....
You will have problems specially if you come from languages where
values minor than zero are considered to be false. I think the
previous sintax is ambiguous.
Regards,
Josef
Josef Meile wrote: Is there something missing you think should be there? There's no particular reason a PEP needs to be continually updated. In particular, notions of good Python style haven't changed a lot over the past ten years.
Skip I agree, those are good guidelines, but I don't agree with:
- Don't compare boolean values to True or False using == (bool types are new in Python 2.3):
No: if greeting == True: Yes: if greeting:
What would happened if you do:
>>> a='test' >>> if a.find('foo'): ... print "foo was found" ... foo was found
I think you should never do a direct boolean comparison. Instead one should use a more elaborate boolean expresion like: >>> a='test' >>> if a.find('foo') >= 0:
... print "foo was found" ...
You will have problems specially if you come from languages where values minor than zero are considered to be false. I think the previous sintax is ambiguous.
I think your find() example has nothing to do with
if boolVal == True:
versus
if boolVal:
though it might be a pitfall for people coming from languages with 1-based
indices. If you discard the index it returns anyway, you could use the
clearer
if "foo" in a:
instead.
As to the original issue, I disagree with you and prefer the recommended
style. I find it natural even for non-booleans:
greeting = "Hi"
if greeting:
print greeting
If you expect a boolean value and fear that you may erroneously encounter
something else, the value == True test will not be sufficient anyway,
because treating, say, "Hi" as False may be an error, too. It's
if greeting == True:
...
elif greeting == False:
pass
else:
raise AssertionError, "greeting must be True or False"
versus
assert greeting in (True, False), "greeting must be True or False"
if greeting:
...
then, and again the last wins at in my eyes.
Peter
On Thu, 11 Mar 2004 10:48:35 +0100,
Josef Meile <jm****@hotmail .com> wrote: Is there something missing you think should be there? There's no particular reason a PEP needs to be continually updated. In particular, notions of good Python style haven't changed a lot over the past ten years. Skip I agree, those are good guidelines, but I don't agree with:
- Don't compare boolean values to True or False using == (bool types are new in Python 2.3):
No: if greeting == True: Yes: if greeting:
What would happened if you do: a='test' if a.find('foo'): ... print "foo was found" ... foo was found
a.find does not return a boolean, so that particular style guideline
does not apply. if a.find( 'foo' ) == True:
.... print 'foo was found'
probably isn't what you want either. ;-)
Regards,
Heather
--
Heather Coppersmith
That's not right; that's not even wrong. -- Wolfgang Pauli
Skip Montanaro <sk**@pobox.com > wrote in message news:<ma******* *************** *************** *@python.org>.. . beliavsky> Is there a more recent set of Python style guidelines than beliavsky> PEP 8, "Style Guide for Python Code", by van Rossum and beliavsky> Warsaw, at http://www.python.org/peps/pep-0008.html , which beliavsky> is dated July 5, 2001?
Is there something missing you think should be there? There's no particular reason a PEP needs to be continually updated. In particular, notions of good Python style haven't changed a lot over the past ten years.
Skip
I am not qualified to say what should be in Python style guidelines. I
have now read the PEP 8 style guidelines and see that Python versions
up to 2.3 are covered. I think the Post-History date of July 5, 2001
is incorrect and should be updated. be*******@aol.c om writes: Skip Montanaro <sk**@pobox.com > wrote in message news:<ma******* *************** *************** *@python.org>.. . beliavsky> Is there a more recent set of Python style guidelines than beliavsky> PEP 8, "Style Guide for Python Code", by van Rossum and beliavsky> Warsaw, at http://www.python.org/peps/pep-0008.html , which beliavsky> is dated July 5, 2001?
Is there something missing you think should be there? There's no particular reason a PEP needs to be continually updated. In particular, notions of good Python style haven't changed a lot over the past ten years.
Skip
I am not qualified to say what should be in Python style guidelines. I have now read the PEP 8 style guidelines and see that Python versions up to 2.3 are covered. I think the Post-History date of July 5, 2001 is incorrect and should be updated.
How so? It hasn't been posted to comp.lang.pytho n since then, and
that's what the Post-History: records.
Cheers,
mwh
--
If I had wanted your website to make noise I would have licked
my finger and rubbed it across the monitor.
-- signature of "istartedi" on slashdot.org
>>>>>a='test' >if a.find('foo'):
... print "foo was found" ... foo was found
a.find does not return a boolean, so that particular style guideline does not apply.
I know, but I found this on the Zope source, which
means that there is people thinking that the False
on python includes negative values.
Josef Meile wrote: >> a='test' >> if a.find('foo'):
... print "foo was found" ... foo was found a.find does not return a boolean, so that particular style guideline does not apply.
I know, but I found this on the Zope source, which means that there is people thinking that the False on python includes negative values.
I believe it's more likely they just forgot what find() did return, as
they were writing the code. I've done the same, thinking it was a
boolean, not thinking that it returned a negative but that negatives
were considered false.
-Peter
In article <40********@pfa ff2.ethz.ch>,
Josef Meile <jm****@hotmail .com> wrote: I agree, those are good guidelines, but I don't agree with:
- Don't compare boolean values to True or False using == (bool types are new in Python 2.3):
No: if greeting == True: Yes: if greeting:
What would happened if you do:
a='test' if a.find('foo'):... print "foo was found" ... foo was found 'foo' in 'test'
False
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/
"Do not taunt happy fun for loops. Do not change lists you are looping over."
--Remco Gerlich, comp.lang.pytho n This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: E. Robert Tisdale |
last post by:
C++ Programming Style Guidelines
http://geosoft.no/development/cppstyle.html
I think that these guidelines are almost *all* wrong.
For example:
11. Private class variables should have underscore suffix.
class SomeClass {
private:
|
by: jamilur_rahman |
last post by:
What is the BIG difference between checking the "if(expression)" in A
and B ? I'm used to with style A, "if(0==a)", but my peer reviewer
likes style B, how can I defend myself to stay with style A ?
style A:
....
....
int a = 1;
if(0==a)
{
|
by: seb.haase |
last post by:
Hi,
Is it true that that "Python 3000" is dead ?
Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would
just break to much code :-(
On the otherhand I'm using Python as "Matlab replacement" and would
generally like 5/2 ==2.5
So, I was contemplating to default all my modules/scripts to start with
"from __future__ import division"
but if it is never coming (in this decade, that is) then it would be a
|
by: Fredrik Lundh |
last post by:
(reposted from doc-sig, which seems to be mostly dead
these days).
over at the pytut wiki, "carndt" asked:
Are there any guidelines about conventions concerning
punctuation, text styles and language style (e.g. how
to address the reader)?
any suggestions from this list ?
|
by: Steve Howell |
last post by:
I've always thought that the best way to introduce new
programmers to Python is to show them small code
examples.
When you go to the tutorial, though, you have to wade
through quite a bit of English before seeing any
Python examples.
Below is my attempt at generating ten fairly simple,
representative Python programs that expose new users
| |
by: MartinRinehart |
last post by:
There's a lot of dumb stuff out there. "Algorithms should be coded
efficiently ..." Thanks, I'll keep that in mind.
van Rossum's guidelines tend toward "pick something and stick to it"
which is OK if you have enough experience to pick something Pythonic.
I'm a relative newbie, not qualified to pick.
Anything written somewhere that's thorough? Any code body that should
serve as a reference?
|
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...
|
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,...
|
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...
|
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...
|
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...
| |
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();...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |