Strange problem when running python code
James Stroud
jstroud at ucla.edu
Tue Apr 4 17:12:38 EDT 2006
ishtar2020 wrote:
> Hi everybody
>
> I've been writing my very first application in Python and everything is
> running smoothly, except for a strange problem that pops up every once
> in a while. I'm sure is the kind
> of newbie thing every seasoned programmer knows.
>
> Sometimes a receive strange Syntax Errors from parts of code that
> worked perfectly minutes ago. What's even more puzzling is that those
> errors are pointed to another part of the module when I do some random,
> innofensive changes in the code (like inserting a line or deleting some
> comments). Sometimes those changes are enough to make the error
> dissapear.
>
> Could it be that python has found a real error but is failing to tell
> me where it is?
>
I don't mean to accuse you or to start a tab v. non-tab war (is tab v.
non-tab a holy war?, it should be because tabs are so damn useful for
formatting and getting everything just-right), but don't use tabs if you
are using them. Here are the reasons: 1. they personally annoy me. 2.
you can't see the damn things (hence the basis for why they are so
annoying). "Tab" comes from the root for the Greek for "table" (or is it
the other way around?, or is it Latin? or Arabic? or Hebrew?). Thus,
tabs should be reserved for thier god-given intended purpose, which is
tab-delimited tables, where a parser can easily separate by them.
Internal, and hence annoying, tabs should not be used elsewhere because
it screws everything up. For example, here is a tab-delimited parser
written in python
table = []
for line in tab_delimited_table:
table.append(line.split('\t'))
Man that was easy! Now, when people put annoying tabs everywhere, to get
their indent just-so, then it totally screws everything up, including
this parser, which was designed for tables delimited by tabs--because
that is the tab's special purpose.
There is one exception however. Its called the tab-space-tab approach.
If you are using tabs to indent your code, then always put at least one
space between tabs. Never put two tabs together. This helps the editor
to display your code correctly.
James
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
http://www.jamesstroud.com/
More information about the Python-list
mailing list