Page 1 of 1

Python with braces?

Posted: Tue May 20, 2008 11:53 pm UTC
by Magitek
I have very little experience with python, but have coded in many other languages before. I would love to use python, but I really miss those braces, the thought of whitespace with semantic value horrifies me (after a brief stint with the esoteric language of Whitespace). Is there a way to code in python with braces?

Re: Python with braces?

Posted: Tue May 20, 2008 11:59 pm UTC
by ++$_
No. Well, you could try this.

Seriously, whitespace is not significant in Python except at the beginning of a line. I have never once encountered a whitespace-related problem with Python. Never. Actually, I have fewer problems, because in C you can forget a closing brace and spend a few seconds trying to figure out where it's supposed to be. In Python, you never have that problem.

Re: Python with braces?

Posted: Wed May 21, 2008 12:42 am UTC
by Jach
In time you will come to love Python's indentation. =P If that somehow doesn't happen though, you could check out Ruby which is real similar to Python but sticks an end after everything.

My philosophy is that you're supposed to be indenting properly anyway, so it might as well mean something to the computer as well.

Re: Python with braces?

Posted: Wed May 21, 2008 1:17 am UTC
by r1chard
I have had a single instance of whitespace-related buggery (er ... buggery in the sense of ... fun-related-to-a-bug :)

It was due to line that had crept into the code that was indented with a tab, in code that was otherwise indented with spaces. It took me a while to figure out too.

That's once in over 10 years of Python programming.

Now I have vim highlighting in red all tabs that appear in source files:

Code: Select all

highlight BadWhitespace ctermbg=red guibg=red
au BufRead,BufNewFile *.py,*.pyw match BadWhitespace /^\t\+/
match BadWhitespace /\s\+$/


(it also highlights unnecessary trailing whitespace in all opened files)



I should also point out that Python 3.0 (and 2.6? or perhaps it will only generate warnings) will automatically generate syntax errors if a source file has mixed tabs-n-spaces. You can get the same effect right now with the -tt command-line switch.

Re: Python with braces?

Posted: Wed May 21, 2008 1:27 am UTC
by Fat Tony
...Am I the only one who, upon reading this thread's title, began to picture a large snake with corrective dental equipment?

Re: Python with braces?

Posted: Wed May 21, 2008 2:17 am UTC
by Dropzone
On a related note: try adding from __future__ import braces as the first line of a source file (or typing it in an interactive session), and watch the interpreter's response...

Re: Python with braces?

Posted: Wed May 21, 2008 3:30 am UTC
by biolution
++$_ wrote:No. Well, you could try this.

Seriously, whitespace is not significant in Python except at the beginning of a line. I have never once encountered a whitespace-related problem with Python. Never. Actually, I have fewer problems, because in C you can forget a closing brace and spend a few seconds trying to figure out where it's supposed to be. In Python, you never have that problem.


It also has significance if you use "\" for line continuation and have a trailing space after it. Another case is when you need to line break but are in the middle of a string (common if you have a line length limit in your style guide); the implicit string concatenation doesn't work across lines unless you use \ or enclose it in parentheses. "\" is rarely used, and () isn't a big deal, though.

The OP smells like a troll, though.

Re: Python with braces?

Posted: Wed May 21, 2008 4:17 am UTC
by Magitek
biolution wrote:The OP smells like a troll, though.


Not trying to troll, I really want to use python, but the few times I tried it out I was too weirded out by it. I guess I'll give it another shot.

And the interpreter thing about future import was checked into the python svn by somebody under the guise to “Improve SyntaxErrors for bad future statements”

http://scott.yang.id.au/2006/09/python-and-braces/


P.S. I'm amazed at how fast google's crawler works. I posted this topic earlier this afternoon and it's already showing up under a google search of "python with braces"

Re: Python with braces?

Posted: Wed May 21, 2008 9:41 pm UTC
by EvanED
Okay, this thread is over. Original question is pretty much answered. I pretty crudely split & merged the second half of the thread into here. The split posts are near the bottom.