473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Completely INNOCENT Indentation question

Is there a way in python to indicate that you want your
"base level of indentation" to be four spaces instead of
zero?

As far as I know now, the only way is by introducing some
sort of language statement, for example:

if (1):
### begin python script
foo = 1
bar = 2
print foo
print bar

Is there a way to accomplish this without introducing
the "throwaway if statement" ??
Jul 18 '05 #1
8 1429
On Wed, 2004-10-13 at 06:32 -0700, valued customer wrote:
Is there a way in python to indicate that you want your
"base level of indentation" to be four spaces instead of
zero?

As far as I know now, the only way is by introducing some
sort of language statement, for example:

if (1):
### begin python script
foo = 1
bar = 2
print foo
print bar

Is there a way to accomplish this without introducing
the "throwaway if statement" ??


I don't think so. Just out of curiosity, why would you want to do that?
If you're unable to see the leftmost characters, just try dragging your
editor window a bit to the right <wink>

--
Cliff Wells <cl************@comcast.net>

Jul 18 '05 #2
quoth the valued customer:
Is there a way in python to indicate that you want your
"base level of indentation" to be four spaces instead of
zero?

As far as I know now, the only way is by introducing some
sort of language statement, for example:

if (1):
### begin python script
foo = 1
bar = 2
print foo
print bar

Is there a way to accomplish this without introducing
the "throwaway if statement" ??


def main():
#python script here

if __name__ == '__main__':
main()

Will that work for ya?

--
Darren Kirby :: Part of the problem since 1976 :: http://badcomputer.no-ip.com
Get my public key from
http://keyserver.linux.it/pks/lookup...earch=bulliver
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQBBbTL+OrzWcOwL7mwRAt1KAJ9vAzsxqTTmqkhmZXgzcr iG/UGlBwCgnXuL
8+9V76yuK8KpnzjsgN/o/Q4=
=aAra
-----END PGP SIGNATURE-----

Jul 18 '05 #3
> > Is there a way in python to indicate that you want your
"base level of indentation" to be four spaces instead of
zero?
I don't think so. Just out of curiosity, why would you want to do that?


The question was just to make sure I hadn't overlooked some
feature or setting of the programming language that would enable
what I had asked about (short of introducing any of the various
language constructs that we all can imagine and you need not
elaborate here).

As far as 'why would anyone want to do that' one reason that
never fails is *personal preference* ... there probably isn't
a stylistic or programming practice in existence that can't be
explained at least partially by that. Therefore if someone asks,
there must be at least *that* reason.

For those who are not satisfied with that kind of answer, here
is an example:

Suppose you are editing source code in such a way
that you only want *comments* to be flush left, and the rest of
the code to be indented.

(but Why would you want do that?)

Because you work with a text editor that shows an 'outline'
of your code based on the indentation, and you want the outline
structure to be reflected in the comments.

### documentation
""" This is a python script that does some stuff.
Not only does it do stuff, it's documented stuff.
"""
### initialize python
import foo
import bar

### do some stuff
print foo.frobilize()

### do some other stuff
print bar.babelize()

### end of python
Yes the question may remain ... why would anyone wanna do
that? Well, there are reasons. Whatever the justifications
may be, the 'additional language statements' workaround will
apparently have to suffice.

Thanks for the input though.
Jul 18 '05 #4
Because you work with a text editor that shows an 'outline'
of your code based on the indentation, and you want the outline
structure to be reflected in the comments.

### documentation
""" This is a python script that does some stuff.
Not only does it do stuff, it's documented stuff.
"""
### initialize python
import foo
import bar

### do some stuff
print foo.frobilize()

### do some other stuff
print bar.babelize()

### end of python
Yes the question may remain ... why would anyone wanna do
that? Well, there are reasons. Whatever the justifications
may be, the 'additional language statements' workaround will
apparently have to suffice.

Considering that many text editors, program editors, IDEs, etc., come
with syntax highlighting, would using different colors for comments be
sufficient? They tend work well for me. In terms of an outline, many
editors also have the ability to pull out comments of a certain format,
pull out function and class names, etc.

I'm curious as to what editor you use that has such an outline feature.

- Josiah

Jul 18 '05 #5
sc******@hotmail.com (valued customer) wrote:

As far as 'why would anyone want to do that' one reason that
never fails is *personal preference* ... there probably isn't
a stylistic or programming practice in existence that can't be
explained at least partially by that. Therefore if someone asks,
there must be at least *that* reason.


Unfortunately, it's impossible to satisfy "personal preferences" for
spacing in a language where spacing is a fundamental part of the syntax.
It's somewhat similar to asking why # could not be used as a comment
character in C.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #6
> Unfortunately, it's impossible to satisfy "personal preferences" for
spacing in a language where spacing is a fundamental part of the syntax.
It's somewhat similar to asking why # could not be used as a comment
character in C.


Makes sense, although the original post does not ask *why*
such-and-such is
(or is not) possible, but *whether* it is possible. Moreover, just
because
such-and-such is a *fundamental* part of the syntax, it does not
necessarily
follow that it is an *immutable* part of the syntax.

As you know, some
languages and syntax formats actually *do* allow things like alternate
comment delimters, alternate quotation delimters, and even alternate
methods of specifying INDENT and DEDENT tokens.

Apparently, at least for the latter case, python does not ... which is
all the original question is asking.

(By the way ... For those curious about "outlining" text editors,
there are several out there ... just do a web search on "code folding"
to see some examples...)
Jul 18 '05 #7
Actually, it should be trivial.

1. Set the preferance in your editor
2. Write a preprocessor (in python) that you supply with your program as
a command-line argument

Your preprocessor de-dents the code. Tracebacks will still be meaningful,
because you are not changing line numbering. BTW, The code-folding in ViM
can be set to correspond to indent-level, which means you can fold and
unfold all constructs to a specific depth. Magic.

Python makes me very lazy. Writing a report in LaTeX today, it was
actually easier for me to make up a syntax for tagging math symbols (put
into comments in the LaTeX source), and extract those and build a List Of
Symbols with a python preprocessor before texification, rather than find
(and figure out how to use) the correct LaTeX package for that. More
magic.

On 13 Oct 2004 20:28:00 -0700, valued customer <sc******@hotmail.com>
wrote:
> Is there a way in python to indicate that you want your
> "base level of indentation" to be four spaces instead of
> zero?

I don't think so. Just out of curiosity, why would you want to do that?


The question was just to make sure I hadn't overlooked some
feature or setting of the programming language that would enable
what I had asked about (short of introducing any of the various
language constructs that we all can imagine and you need not
elaborate here).

As far as 'why would anyone want to do that' one reason that
never fails is *personal preference* ... there probably isn't
a stylistic or programming practice in existence that can't be
explained at least partially by that. Therefore if someone asks,
there must be at least *that* reason.

For those who are not satisfied with that kind of answer, here
is an example:

Suppose you are editing source code in such a way
that you only want *comments* to be flush left, and the rest of
the code to be indented.

(but Why would you want do that?)

Because you work with a text editor that shows an 'outline'
of your code based on the indentation, and you want the outline
structure to be reflected in the comments.

### documentation
""" This is a python script that does some stuff.
Not only does it do stuff, it's documented stuff.
"""
### initialize python
import foo
import bar

### do some stuff
print foo.frobilize()

### do some other stuff
print bar.babelize()

### end of python
Yes the question may remain ... why would anyone wanna do
that? Well, there are reasons. Whatever the justifications
may be, the 'additional language statements' workaround will
apparently have to suffice.

Thanks for the input though.


Jul 18 '05 #8
> 2. Write a preprocessor (in python) that you supply with your program as
a command-line argument
As a routine user of similar 'preprocessor tricks' to coerce other,
more klunky languages into behaving nicely, that's a great
suggestion, seems like an obvious solution (in hindsight).
Python makes me very lazy. Writing a report in LaTeX today, it was
actually easier for me to make up a syntax for tagging math symbols

With all the emphasis on "extensibility" these days, it seems the best
mechanism for extensibility is the unsung hero ... code comments ...
You can do things the original designers never anticipated.
Jul 18 '05 #9

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

Similar topics

6
by: David Lees | last post by:
I have a real basic how-to question. When I decide to reuse a piece of python code at a different indentation level than the original, is there a common trick (or set of tricks) for moving the...
0
by: Magnus Lie Hetland | last post by:
Not many members on the Atox mailing list yet, so I'll venture a request here... In Atox 0.2, I've added support for indentation tokens (somewhat like the Python indentation scheme, but a bit...
3
by: porterboy | last post by:
CONTEXT: I am using Emacs to edit Python code and sometimes also Matlab code. When I hit <return> in a loop of some sort, Emacs usually gets the nesting indentation right, which is particularly...
177
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are...
10
by: name | last post by:
When I started testing the algorithms for my wrap program, I threw together this snippet of code, which works quite well. Except that it (predictably) segfaults at the end when it tries to go...
1
by: mscertified | last post by:
How do I change the indentation in the VS 2003 editor. Its currently 4 spaces, I'd like to make it 3 characters? How does this work? If someone else opens my project will they see the code...
7
by: diffuser78 | last post by:
I am a newbie to Python. I am mainly using Eric as the IDE for coding. Also, using VIM and gedit sometimes. I had this wierd problem of indentation. My code was 100% right but it wont run...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
19
by: Eric S. Johansson | last post by:
Almar Klein wrote: there's nothing like self interest to drive one's initiative. :-) 14 years with speech recognition and counting. I'm so looking to my 15th anniversary of being injured next...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
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,...

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.