python newbie: some surprises

Lie Lie.1296 at gmail.com
Sun May 18 10:25:00 EDT 2008


On May 8, 2:06 pm, v4vijayakumar <vijayakumar.subbu... at gmail.com>
wrote:
> When I started coding in python, these two things surprised me.
>
> 1. my code is inconsistently indented with the combination of tabs and
> spaces. Even lines looked intended, but it is not.

The problem is in tab not Python, there is no convention on how many
spaces should tab be treated, python (by default) assumes a tab to be
equal to 8 spaces, but not everyone thinks the same, some code editor
might consider it as 4 spaces or 2 spaces. In most python-oriented
code editor, a tab might be automatically replaced with four spaces.

> 2. python requires to pass "self" to all instance methods

No, python doesn't requires self to be passed to all instance methods,
python passes the "current instance" of a class to the first argument
of a function inside the class, this first argument can be named
anything, although it is traditionally named as self. In other
programming languages, this current instance is implicitly passed (Me
in VB, this in C/C++).

> and I missed ":" often. :)

Not in your smiley though. :)



More information about the Python-list mailing list