473,549 Members | 2,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tab indentions on different platforms?

All,
I seem to be having problems with running my python code, written
on a Mac, on Linux and Windows boxes. It seems like the problem has to
do with tab indention, particularly I've noticed that my code will
completely ignore try statements. Has anyone had a similar problem?

Regards,
Ken
Dec 28 '07 #1
19 1596
On Dec 29, 9:51 am, xkenneth <xkenn...@gmail .comwrote:
I seem to be having problems with running my python code, written
on a Mac, on Linux and Windows boxes.
So *what* problems do you seem to be having? More to the the point,
what problems are you *actually* having?
It seems like the problem has to
do with tab indention, particularly I've noticed that my code will
completely ignore try statements. Has anyone had a similar problem?
Yes.

Set up your text editor to (a) recognise Tab and Shift-Tab keyboard
inputs as indent/dedent respectively and (b) to insert 4 spaces and
zero tab characters per indent. IOW, don't have tab characters at all
in your source files.

If after that you still have a problem, ask here again, with the
following information:

1. The shortest possible script file that reproduces the problem --
use
print open('problemde mo.py', 'rb').read()
to show the contents (a) as it appears on the Mac (b) after
transferring [how?] to Linux (c) after transferring [how?] to Windows

2. The results of executing the code in each of the three environments
-- copy/paste of the actual output, not a description.

Dec 28 '07 #2
* xkenneth (Fri, 28 Dec 2007 14:51:04 -0800 (PST))
I seem to be having problems with running my python code, written on
a Mac, on Linux and Windows boxes.
You seem to have problems or you do have problems?
It seems like the problem has to do with tab indention,
Why does it seem and what does seem?
particularly I've noticed that my code will completely ignore try
statements.
Statements are never ignored: they error or they don't.
Has anyone had a similar problem?
It doesn't matter how a particular editor (note, that's not an OS
thing!) displays indents. If you use only tabs or spaces that's just
fine. I'd personally go for spaces because:

1. I don't like things I cannot see (control characters)

2. I never had problems with spaces but plenty with tabs
Thorsten
Dec 29 '07 #3
On Sat, 29 Dec 2007 15:29:25 +0000, Thorsten Kampe wrote:
I'd personally go for spaces because:

1. I don't like things I cannot see (control characters)
You can see spaces but not tabs? Your editor is pretty weird. In all the
editors I've every used, both spaces and tabs show up as empty white
space. (Or coloured space if I set the editor to use a coloured
background.)

2. I never had problems with spaces but plenty with tabs
Periodically, I ask on this list what problems people have with tabs.
(I'm fully aware that mixing tabs and spaces is a Bad Thing.) I've had
little luck getting any answer except "Tabs are bad, m'kay?".

I'm only aware of two problems that some people run into due to the
consistent use of tabs rather than spaces.

* Some news clients don't display tabs correctly, thus making it hard to
copy and paste code direct out of the news reader into your source;

(But of course if you copy code using spaces, and the number of space
characters used per indent level doesn't match your source code, you'll
have problems too.)

* Some applications "helpfully" convert tabs into spaces, thus meaning
that when copy code from them, you end up with spaces instead of tabs.

What problems have you had with tabs that aren't related to buggy
applications or users that mix tabs and spaces?

--
Steven
Dec 30 '07 #4
Steven D'Aprano <st***@REMOVE-THIS-cybersource.com .auwrites:
On Sat, 29 Dec 2007 15:29:25 +0000, Thorsten Kampe wrote:
I'd personally go for spaces because:

1. I don't like things I cannot see (control characters)

You can see spaces but not tabs? Your editor is pretty weird. In all
the editors I've every used, both spaces and tabs show up as empty
white space. (Or coloured space if I set the editor to use a
coloured background.)
Though Thorsten could have been clearer, "thing that is not a space
character but shows up as white space" is a near-enough approximation
of "thing I cannot see".
2. I never had problems with spaces but plenty with tabs

Periodically, I ask on this list what problems people have with
tabs. (I'm fully aware that mixing tabs and spaces is a Bad Thing.)
I've had little luck getting any answer except "Tabs are bad,
m'kay?".
Posit: White space is most often achieved by the user inserting a
sequence of space characters (U+0020).

Posit: Tab characters (U+0009) are, in a majority of environments,
rendered visually indistinguishab le from a sequence of space
characters.

Corollary: most readers will, when seeing a stretch of white space on
a line, default to assuming that it represents a sequence of space
(U+0020) characters.

Corollary: So when a file containing either spaces or tabs is edited
in such an environment, the common way chosen by the user to get to
the same indentation level as existing lines is to prepend space
characters (using the spacebar or the Tab key or whatever facility the
editor provides) until the indentation lines up visually --
remembering the caveat that tabs and space-sequences are visually
indistinguishab le in many environments.

Argument: The user will get an unexpected result when they do the
obvious thing (prepend space characters) in a tabs-only file. With
existing spaces-only files, the obvious way to get matching
indentation gives the expected result.

Conclusion: Thus, using tabs-only is inferior to using spaces-only for
indentation, because it violates the Principle of Least Astonishment
<URL:http://en.wikipedia.or g/wiki/Principle_of_le ast_astonishmen t>.

--
\ "I object to doing things that computers can do." —Olin |
`\ Shivers |
_o__) |
Ben Finney
Dec 30 '07 #5
Thorsten Kampe wrote:
* xkenneth (Fri, 28 Dec 2007 14:51:04 -0800 (PST))
>I seem to be having problems with running my python code, written on
a Mac, on Linux and Windows boxes.

You seem to have problems or you do have problems?
>It seems like the problem has to do with tab indention,
It really should be a syntax error in Python to mix
leading tabs and leading spaces in the same file. One can argue over
which to use, but a file with both usually leads to trouble.

John Nagle
Dec 30 '07 #6
On Dec 30, 3:48 pm, John Nagle <na...@animats. comwrote:
Thorsten Kampe wrote:
* xkenneth (Fri, 28 Dec 2007 14:51:04 -0800 (PST))
I seem to be having problems with running my python code, written on
a Mac, on Linux and Windows boxes.
You seem to have problems or you do have problems?
It seems like the problem has to do with tab indention,

It really should be a syntax error in Python to mix
leading tabs and leading spaces in the same file. One can argue over
which to use, but a file with both usually leads to trouble.
It can be made to do so:

promptpython -h
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Options and arguments (and corresponding environment variables):
[snip]
-t : issue warnings about inconsistent tab usage (-tt: issue
errors)
[snip]

Further advice to the OP: run python with the -t (or -tt) option and
see what you get.
Dec 30 '07 #7
* Steven D'Aprano (Sun, 30 Dec 2007 00:37:32 -0000)
On Sat, 29 Dec 2007 15:29:25 +0000, Thorsten Kampe wrote:
I'd personally go for spaces because:

1. I don't like things I cannot see (control characters)

You can see spaces but not tabs? Your editor is pretty weird. In all the
editors I've every used, both spaces and tabs show up as empty white
space.
That's because the editor displays those invisible tab control
characters as something they're not: spaces.
2. I never had problems with spaces but plenty with tabs

What problems have you had with tabs that aren't related to buggy
applications or users that mix tabs and spaces?
Fortunately I don't remember every incident when I stumbled about
something weird behaving or looking. One thing I do remember is
reading python source code (not my own) with a pager. The source code
was badly indented. The pager was not "buggy".

Thorsten
Dec 30 '07 #8
* Ben Finney (Sun, 30 Dec 2007 15:36:12 +1100)
Steven D'Aprano <st***@REMOVE-THIS-cybersource.com .auwrites:
On Sat, 29 Dec 2007 15:29:25 +0000, Thorsten Kampe wrote:
I'd personally go for spaces because:
>
1. I don't like things I cannot see (control characters)
You can see spaces but not tabs? Your editor is pretty weird. In all
the editors I've every used, both spaces and tabs show up as empty
white space. (Or coloured space if I set the editor to use a
coloured background.)

Though Thorsten could have been clearer, "thing that is not a space
character but shows up as white space" is a near-enough approximation
of "thing I cannot see".
2. I never had problems with spaces but plenty with tabs
Periodically, I ask on this list what problems people have with
tabs. (I'm fully aware that mixing tabs and spaces is a Bad Thing.)
I've had little luck getting any answer except "Tabs are bad,
m'kay?".

Posit: White space is most often achieved by the user inserting a
sequence of space characters (U+0020).

Posit: Tab characters (U+0009) are, in a majority of environments,
rendered visually indistinguishab le from a sequence of space
characters.

Corollary: most readers will, when seeing a stretch of white space on
a line, default to assuming that it represents a sequence of space
(U+0020) characters.

Corollary: So when a file containing either spaces or tabs is edited
in such an environment, the common way chosen by the user to get to
the same indentation level as existing lines is to prepend space
characters (using the spacebar or the Tab key or whatever facility the
editor provides) until the indentation lines up visually --
remembering the caveat that tabs and space-sequences are visually
indistinguishab le in many environments.

Argument: The user will get an unexpected result when they do the
obvious thing (prepend space characters) in a tabs-only file. With
existing spaces-only files, the obvious way to get matching
indentation gives the expected result.

Conclusion: Thus, using tabs-only is inferior to using spaces-only for
indentation, because it violates the Principle of Least Astonishment
<URL:http://en.wikipedia.or g/wiki/Principle_of_le ast_astonishmen t>.
Man, how did you know what I wanted to say (but failed to to express)
:-) ? Anyway: the consequence of your well done argumentation is that
someone editing Python code has to use a specialised editor to prevent
screwing up tab indented code - and that's bad.

Thorsten
Dec 30 '07 #9
On Sun, 30 Dec 2007 20:33:19 +0000, Thorsten Kampe wrote:
* Steven D'Aprano (Sun, 30 Dec 2007 00:37:32 -0000)
>On Sat, 29 Dec 2007 15:29:25 +0000, Thorsten Kampe wrote:
I'd personally go for spaces because:

1. I don't like things I cannot see (control characters)

You can see spaces but not tabs? Your editor is pretty weird. In all
the editors I've every used, both spaces and tabs show up as empty
white space.

That's because the editor displays those invisible tab control
characters as something they're not: spaces.
Editors display tab characters as "indent to next tab stop". That's what
they're for, and any editor that doesn't behave that way is buggy.

Tab characters are no more invisible than space characters. How can you
see space characters but not tabs? Why aren't space characters invisible
too? Why do you dislike tabs *specifically* because they are invisible,
but like invisible spaces?
2. I never had problems with spaces but plenty with tabs

What problems have you had with tabs that aren't related to buggy
applications or users that mix tabs and spaces?

Fortunately I don't remember every incident when I stumbled about
something weird behaving or looking. One thing I do remember is reading
python source code (not my own) with a pager. The source code was badly
indented. The pager was not "buggy".
Given the constraints of the typical pager one-line display, and the
tendency of pagers I've seen to arbitrarily drop leading whitespace *of
any sort* from the start of lines, I'd like to know how you could tell
the indentation was wrong.

If the source code was correctly indented, but displayed wrongly by the
pager, then of course the pager was buggy. And if the source code was
incorrectly indented and the pager showed it as it was, well, that can
happen with spaces too:

x = 1
for i in range(20):
x += i
print x
No tabs there, all the indentation is done with spaces. How would you
expect a pager to display that?

--
Steven
Dec 30 '07 #10

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

Similar topics

4
1926
by: Jos van Uden | last post by:
Hello, Recently I created a validation script for a form that checks a textarea. The visitor is invited to send a list of 25 words, with each word on a new line. Before I submit the list I run a test that checks the length of each word. In order to do this I split the content of the textarea to create an array of
0
890
by: steve | last post by:
Hi, I am testing my application on a different computer with French Language Settings and Win 2000. I have English and XP Professional. We both have the same version of .NET. Apart from the decimal separators (due to language settings) I noticed that in a NumericUpDown Control , I can either use the arrows *or* enter a value manually. In...
10
2429
by: Qiangning Hong | last post by:
I'm writing a spider. I have millions of urls in a table (mysql) to check if a url has already been fetched. To check fast, I am considering to add a "hash" column in the table, make it a unique key, and use the following sql statement: insert ignore into urls (url, hash) values (newurl, hash_of_newurl) to add new url. I believe this will...
70
14968
by: axlq | last post by:
I'm trying to design my style sheets such that my pages have similar-looking fonts different platforms (Linux, Mac, Adobe, X-Windows, MS Windows, etc). The problem is, a font on one platform might be the same as a font on another platform, but with different names. I'd like to be able to specify the font names that are "most equivalent." ...
1
2684
by: bubblegum | last post by:
I am working on a script that will retrieve process info from a Linux, a Windows, a Suse and a Solaris hosts. I run this script from a RedHat 2.6 machine. The first problem I have is how to get process info from a Windows XP host. There are only two ways to do it: - directly execute a script from the RedHat machine, get the process info...
2
1554
by: hmaher15 | last post by:
Hello I am starter in this amazing language and in programming in general and I am wondering how the stream library for example works fine on many platforms (Windows,Linux etc.) does the compiler come with different versions of this library on each platform or the implementation of the library works on all platforms.
0
7446
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...
0
7956
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7808
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...
0
6040
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...
0
3498
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...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1935
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
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
757
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...

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.