Python Indentation

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2006
Posts: 2,564
Reputation: mattyd is an unknown quantity at this point 
Solved Threads: 1
Featured Poster
mattyd's Avatar
mattyd mattyd is offline Offline
Posting Maven

Python Indentation

 
0
  #1
Nov 29th, 2006
Concerning Python Indentation Syntax:

I have researched this and read some reasoning behind indentation-level enforcement. My question is: does this exist simply to ensure consistency when dealing with nested statements, a precaution against sloppy composition of code?

I am not complaining about this, and actually I somewhat like this, but it seems to always crop up while compiling, improper indentations throughout my code say, for example, if I add a snippet of code such as a RNG just to test it out; I must then stop and format everything beneath the inserted code in order to get a valid run. This is not much different than stopping to fix C++ errors before a valid compile except for those errors never really relate to indentation.

As I said, I do not dislike this feature, this rule of Python, as I pretty much like everything about Python. I just wish to understand (from someone well acquainted with this language) why the enforcement of indentation was decided upon by the designer of Python as a necessary "evil" :cheesy: . Just curious.

Regards,
sharky_machine
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Python Indentation

 
0
  #2
Nov 29th, 2006
Avoiding the endless begin/end or curly braces, and also the end of line semicolons makes code simpler to read and understand. When you use an editor made for Python, indentations become easy to follow. You absolutley have to avoid mixing spaces with tabs in your indents. That's the main reason you have problems with other folks code! I religiously use spaces (4) only, since tab settings vary so much.
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,564
Reputation: mattyd is an unknown quantity at this point 
Solved Threads: 1
Featured Poster
mattyd's Avatar
mattyd mattyd is offline Offline
Posting Maven

Re: Python Indentation

 
0
  #3
Nov 29th, 2006
Thank-you Ene Uran .

I need to stick to a set amount of spaces (indentation); I think four (4) spaces seems like a good amount.

regards,
sharky_machine
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,042
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 933
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Python Indentation

 
0
  #4
Dec 8th, 2006
Thus spoke the Lord: "Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are the devil's apples!"
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Python Indentation

 
0
  #5
Dec 9th, 2006
I think the indent requirements serve two purposes. One you have already mentioned: making blocks more human-readable. The other purpose is pedagogical, remembering that Python began as a teaching language. By having to indent his blocks, the beginner is forced to see code in blocks.

Jeff
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,279
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Python Indentation

 
0
  #6
Dec 9th, 2006
I agree with Jeff!
I have seen other computer language code like C, where the writer did not not use any indentation. Now you get lost in an ocean of { and } and ; which makes large code almost unreadable!
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Python Indentation

 
0
  #7
Dec 9th, 2006
So the real man's computing challenge would appear to be the

Obsucated Python Contest :mrgreen:

Write a program to play chess in as unclear a way possible.

Jeff

(with apologies to the real thing)
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC