Forums | MacLife
You are not logged in.
#1 2007-10-01 12:22 pm
Is Python syntax indent based?
I have to edit some Python templates and don't want to bork anything.
Say I have:
Code:
[if-any this_var]
[is roottype "this"]
// do this
[end]
[end]Could it mess up the code if I add <li> tags like:
Code:
[if-any this_var]
<li>[is roottype "this"]
// do this
[end]</li>
[end]Offline
#2 2007-10-01 12:38 pm
- TonyPrevite
- Slobbering Jester
- Royal Wombat

- From: Glendale, AZ
- Registered: 2002-04-14
- Posts: 3606
- Website
Re: Is Python syntax indent based?
To answer your question, YES. Indentation is part of syntax in Python! Don't you love it 
Offline
#3 2007-10-01 12:44 pm
Re: Is Python syntax indent based?
Love it or hate it: just so long as I understand it!
So you're saying that my sample above would bork?
Thanks!
Offline
#4 2007-10-01 1:08 pm
- TonyPrevite
- Slobbering Jester
- Royal Wombat

- From: Glendale, AZ
- Registered: 2002-04-14
- Posts: 3606
- Website
Re: Is Python syntax indent based?
Yup
Offline
#5 2007-10-01 1:09 pm
Re: Is Python syntax indent based?
Damn!
Offline
#6 2007-10-01 1:10 pm
Re: Is Python syntax indent based?
But I guess that's why I see so much:
Code:
<h3> This is my header </h3>
In the page output.
Offline
#7 2007-10-01 9:46 pm
Re: Is Python syntax indent based?
Just FYI, you also have to be careful with editors that decide to replace tabs with spaces. If you have 4 spaces, and a tab that is configured to be the width of 4 spaces on the screen, they will be at different indentation levels. I don't mind Python that much, but I absolutely hate the use of white space as block levels. (fortunately I mainly deal with compiled languages, so I don't have to worry about it too much
)
Offline
#8 2007-10-01 10:05 pm
Re: Is Python syntax indent based?
The templates themselves aren't written in Python, since Python can't be directly used as a template language in the way PHP can. There are many many many different template engines written in Python (such as Kid, Myghty, Cheetah, Mako, PSP, Genshi, and more...), and most of them are not whitespace sensitive. It really depends on what template library you're using. The fact that you included [end] tags in your sample would indicate indentation shouldn't matter.
Offline
#9 2007-10-02 12:36 am
Re: Is Python syntax indent based?
Yeah, I did some testing and it seems that Miles is right... I know the site is running Python, but templates aren't sensitive to whitespace. Its almost like smarty.
BTW - is there a print_r() like function in Python? I'm plum too lazy to look for myself right now 
Offline
#11 2007-10-02 1:30 am
Re: Is Python syntax indent based?
Garoovy!
I fully intended on just making sure everything in brackets stayed pristine, but, alas, I want to make a change or three.
Offline
#12 2007-10-02 9:27 am
Re: Is Python syntax indent based?
Wow, this indent structure takes a bit of mental discipline, and changing the auto-indent / tab type of the text editor. Sheesh.
Offline
