473,790 Members | 3,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??

Linux kernel style guide, Guido's C style guide and (I believe) old
K&R style recommends 8 SPACES for indent.

I finally got convinced of wisdom of 8 space indentation.

Guido also likes 8 space indentation FOR C CODE.

Why style guide (PEP-8) for Python says 4 space indents???

Is breaking rule to use 8 space indents everywhere
a REALLY bad idea??

I REALLY WANT TO DO MY OPEN SOURCE PYTHON PROJECT
WITH 8 SPACE IDENTS!!!!

Chris
Jul 18 '05
21 4030
Some tabs are 8 space wide
But spaces don't cost any money
Other tabs leap 4 in one stride
They make my source code look funny
Jul 18 '05 #11
Hung Jung Lu wrote:

Peter Hansen <pe***@engcorp. com> wrote in message news:<3F******* ********@engcor p.com>...
Anyone who believes there is or will be anything new in this discussion
hasn't been reading comp.lang.pytho n or the mailing list nearly long enough.


Yeah, the eternal, never-ending war between the tabibans and the tabifans.


Careful. I think you've just attracted the attention of the Bush war machine...

:-)

-Peter
Jul 18 '05 #12
In article <m3************ @mira.informati k.hu-berlin.de>,
Martin v. =?iso-8859-15?q?L=F6wis?= <ma****@v.loewi s.de> wrote:

In non-Python-aware editors (like Usenet messages), I prefer 2-space
indentation as well. While programming larger projects, I use a
Python-aware editor, and that editor makes indentation automatically
(to four spaces), so it is just as easy to type.


Get a better newsreader. ;-) (My newsreader lets me pick any editor I
want.)
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
Jul 18 '05 #13
aa**@pythoncraf t.com (Aahz) schreef:
Get a better newsreader. ;-) (My newsreader lets me pick any editor I
want.)


And Martin uses an editor as his newsreader... :-p

--
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
Jul 18 '05 #14
Peter Hansen <pe***@engcorp. com> writes:
Hung Jung Lu wrote:

Peter Hansen <pe***@engcorp. com> wrote in message news:<3F******* ********@engcor p.com>...
Anyone who believes there is or will be anything new in this discussion
hasn't been reading comp.lang.pytho n or the mailing list nearly long enough.


Yeah, the eternal, never-ending war between the tabibans and the tabifans.


Careful. I think you've just attracted the attention of the Bush war machine...


We have always been at war with FourSpaceTabani a!

Cheers,
mwh

--
"Also, does the simple algorithm you used in Cyclops have a name?"
"Not officially, but it answers to "hey, dumb-ass!"
-- Neil Schemenauer and Tim Peters, 23 Feb 2001
Jul 18 '05 #15
On Wed, 22 Oct 2003 16:16:15 -0700, Erik Max Francis <ma*@alcyone.co m>
wrote:
Christian Seberino wrote:
I REALLY WANT TO DO MY OPEN SOURCE PYTHON PROJECT
WITH 8 SPACE IDENTS!!!!


You don't really think a style guide is going to stop you from doing
that, do you?


Exactly.

My advice is basically do what suits you. Just do it consistently.

Personally, I prefer two space indents. I'm just too lazy to type any
more if I can avoid it. But when editing existing code, in any
language, I just go with what's already there - as long as there is
some consistent indentation rule evident, anyway.
Are there any tools which can intelligently redo the indentation in a
Python source file? Preferably respecting other formatting conventions
where practical, though of course I accept that no program could
replace a programmer with an eye for readability in this respect.
--
Steve Horne

steve at ninereeds dot fsnet dot co dot uk
Jul 18 '05 #16
Stephen Horne wrote:

[snip]

Are there any tools which can intelligently redo the indentation
in a Python source file? Preferably respecting other formatting
conventions where practical, though of course I accept that no
program could replace a programmer with an eye for readability in
this respect.


If you are on Linux/UNIX or have access to the cygwin tools on MS
Windows, then try:

unexpand -4 orig.py > tmp.py
expand -2 tmp.py > dest.py

to convert from 4-space indents to 2-space indents, and

unexpand -2 orig.py > tmp.py
expand -4 tmp.py > dest.py

to convert from 2-space indents to 4-space indents.

But, it does seem like a lot of trouble to go through just so that
people will look at your code and say "Eewh! Why didn't s/he read
the style guide?" Or maybe they will smirk and say, "I'll bet s/he
uses an editor in which the Tab key doesn't work, ... something
like Notepad on MS Windows. I pity the fool."

Also, if you have the Python source distribution, look at
Tools/scripts/untabify.py. Also, in the string module (in the
standard library) and the string data type, look at the
expandtabs() method.

Except, I don't know what these do with tabs in quoted strings.
The default behavior of unexpand is to convert only
characters at the beginning of each line. With expand, use the -i
option to convert only initial tabs.

Next, ask yourself the following questions: Why is there no
Tools/scripts/tabify.py? And, why is there no string.unexpand tabs()
method? Could there be a conspiracy to take away your right to
use tabs?

Dave

--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
dk******@rexx.c om
Jul 18 '05 #17
Dave Kuhlman wrote:
If you are on Linux/UNIX or have access to the cygwin tools on MS
Windows, then try:

unexpand -4 orig.py > tmp.py
expand -2 tmp.py > dest.py

to convert from 4-space indents to 2-space indents, and

unexpand -2 orig.py > tmp.py
expand -4 tmp.py > dest.py

to convert from 2-space indents to 4-space indents.


Blasphemy! Use a pipe and avoid the need for the temporary file
altogether:

unexpand -4 orig.py | expand -2 > dest.py

etc.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ To endure what is unendurable is true endurance.
\__/ (a Japanese proverb)
Jul 18 '05 #18
Stephen Horne wrote:
[snip]
Are there any tools which can intelligently redo the indentation in a
Python source file? Preferably respecting other formatting conventions
where practical, though of course I accept that no program could
replace a programmer with an eye for readability in this respect.

..../Python.../Tools/Scripts/reindent.py

Jul 18 '05 #19
Stephen Horne <st***@ninereed s.fsnet.co.uk> writes:
On Wed, 22 Oct 2003 16:16:15 -0700, Erik Max Francis <ma*@alcyone.co m>
wrote:
Christian Seberino wrote:
I REALLY WANT TO DO MY OPEN SOURCE PYTHON PROJECT
WITH 8 SPACE IDENTS!!!!
You don't really think a style guide is going to stop you from doing
that, do you?


Exactly.

My advice is basically do what suits you. Just do it consistently.

Personally, I prefer two space indents. I'm just too lazy to type any
more if I can avoid it. But when editing existing code, in any
language, I just go with what's already there - as long as there is
some consistent indentation rule evident, anyway.


If you never work with others, never edit code from others, and never
offer code to the OSS world, then I suppose you can do your own indent
rules. But for those of us in the connected world (and esp. those
doing XP), playing by the 4-char rule is crucial.

So the question is: How can you do the correct indents everytime,
without having to manually count them out? You should be using an
editor which understands python indents (e.g., emacs with
python-model.el). Even vi and nedit can be set up to understand
4-char indents.


Are there any tools which can intelligently redo the indentation in a
Python source file? Preferably respecting other formatting conventions
where practical, though of course I accept that no program could
replace a programmer with an eye for readability in this respect.


--
Steve Horne

steve at ninereeds dot fsnet dot co dot uk


--
ha************@ boeing.com
6-6M31 Knowledge Management
Phone: (425) 342-5601
Jul 18 '05 #20

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

Similar topics

0
1117
by: Maxim Khesin | last post by:
Is there anything like a style guide geared towards larger projects? I am particularly interested in module handling (size, complexity, intermodule dependencies). thanks max
22
2221
by: beliavsky | last post by:
Is there a more recent set of Python style guidelines than PEP 8, "Style Guide for Python Code", by van Rossum and Warsaw, at http://www.python.org/peps/pep-0008.html , which is dated July 5, 2001?
9
1502
by: Leif K-Brooks | last post by:
I try to make my code comply to the Python style guide (http://www.python.org/peps/pep-0008.html). Last time I read it, I swear that it said to use CamelCase for often-used functions and lower_case_with_underscores for rarely-used utility functions. Now it says to use low_case_with_underscores for everything, but it claims to be last updated in 2001. Am I crazy?
4
1347
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 ?
2
1964
by: Giggle Girl | last post by:
Hello there! I am a User Interface Designer at a company that only makes web apps. I am fluent in HTML, Javascript and Graphics programs. Now we are making a compiled app with VS05 in C#, and I have to make the forms by primarily drag'n'dropping controls using the WYSWIG editor built into VS05. I have these questions: QUESTION 1. Is there a horizontal rule, or vertical pipe, to visually separate the layout?
8
1426
by: Darren Dale | last post by:
I was just searching for some guidance on how to name packages and modules, and discovered some inconsistencies on the www.python.org. http://www.python.org/doc/essays/styleguide.html says "Module names can be either MixedCase or lowercase." That page also refers to PEP 8 at http://www.python.org/dev/peps/pep-0008/, which says "Modules should have short, all-lowercase names. ... Python packages should also have short, all-lowercase names...
0
9512
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,...
1
10147
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
9987
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...
0
9023
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
7531
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
5424
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...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
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.