944,015 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 2510
  • Python RSS
Nov 29th, 2006
0

Python Indentation

Expand Post »
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
Similar Threads
Featured Poster
Reputation Points: 105
Solved Threads: 1
Posting Maven
mattyd is offline Offline
2,582 posts
since Oct 2006
Nov 29th, 2006
0

Re: Python Indentation

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.
Reputation Points: 625
Solved Threads: 211
Posting Virtuoso
Ene Uran is offline Offline
1,704 posts
since Aug 2005
Nov 29th, 2006
0

Re: Python Indentation

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
Featured Poster
Reputation Points: 105
Solved Threads: 1
Posting Maven
mattyd is offline Offline
2,582 posts
since Oct 2006
Dec 8th, 2006
0

Re: Python Indentation

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!"
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Dec 9th, 2006
0

Re: Python Indentation

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
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
jrcagle is offline Offline
608 posts
since Jul 2006
Dec 9th, 2006
0

Re: Python Indentation

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!
Reputation Points: 961
Solved Threads: 211
Nearly a Posting Maven
sneekula is offline Offline
2,413 posts
since Oct 2006
Dec 9th, 2006
0

Re: Python Indentation

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)
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
jrcagle is offline Offline
608 posts
since Jul 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Python GUI build: Logic Complications and Mistakes
Next Thread in Python Forum Timeline: Very basic de/encrypt program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC