News Ticker

Don’t Use Hard Tab in Python (Lesson Learned)

بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ

In the name of Allah, the Most Beneficient, the Most Merciful

So the story is I copied (and pasted) some python code from one of the lectures that I attended into my python source code, but somehow it didn’t work (!!!). I am really sure that the algorithm and syntax was fine! It was weird! And after a few searches in Google, I finally found out the culprit: the hard-tab usages!

So it turns out that it is recommended for us not to use the hard tab in our source code. Why? Because each text editor might have a different tab-to-space convertion rule, and it will eventually bites the indentation-sensitive programming languages like Python (see here and here for more explanation). So it is better for us to use soft-tab (space) in our Python source code (with each tab equals to 4 spaces).

Alright then. Lesson learned.

Advertisements
About wahidyankf (186 Articles)
JavaScript Developer. His life-motto is "Learning, Dreaming, and Enjoying life".

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: