Quantcast

Forums | MacLife

You are not logged in.

#1 2007-10-01 12:22 pm

Gipetto
Yankee Doodle's noodle
Royal Wombat
From: People! Ahg!!
Registered: 2000-09-24
Posts: 9941
Website

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 smile

Offline

 

#3 2007-10-01 12:44 pm

Gipetto
Yankee Doodle's noodle
Royal Wombat
From: People! Ahg!!
Registered: 2000-09-24
Posts: 9941
Website

Re: Is Python syntax indent based?

Love it or hate it: just so long as I understand it!
wink

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

Gipetto
Yankee Doodle's noodle
Royal Wombat
From: People! Ahg!!
Registered: 2000-09-24
Posts: 9941
Website

Re: Is Python syntax indent based?

Damn!

Offline

 

#6 2007-10-01 1:10 pm

Gipetto
Yankee Doodle's noodle
Royal Wombat
From: People! Ahg!!
Registered: 2000-09-24
Posts: 9941
Website

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

akb825
ph34r teh master sword
From: In a secluded room
Registered: 2003-12-25
Posts: 6434
Website

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 tongue)


My software

"Standards are for n00bs!!!" -Microsoft

Offline

 

#8 2007-10-01 10:05 pm

Miles
Now I fight for wisdom!
Administrator
From: Michigan
Registered: 2001-07-21
Posts: 4506
Website

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

Gipetto
Yankee Doodle's noodle
Royal Wombat
From: People! Ahg!!
Registered: 2000-09-24
Posts: 9941
Website

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 wink

Offline

 

#10 2007-10-02 12:52 am

Miles
Now I fight for wisdom!
Administrator
From: Michigan
Registered: 2001-07-21
Posts: 4506
Website

Re: Is Python syntax indent based?

repr() is probably the most similar.  dir() is also useful, since it will (usually) give you a list of the methods and attributes of an object.

Offline

 

#11 2007-10-02 1:30 am

Gipetto
Yankee Doodle's noodle
Royal Wombat
From: People! Ahg!!
Registered: 2000-09-24
Posts: 9941
Website

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

Gipetto
Yankee Doodle's noodle
Royal Wombat
From: People! Ahg!!
Registered: 2000-09-24
Posts: 9941
Website

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

 

Board footer

Powered by PunBB 1.2.6
© Copyright 2002–2005 Rickard Andersson