Login Register






Python for Newbies filter_list
Author
Message
RE: Python for Newbies #5
Hey @Artmer

nice to see you here too. I've seen this tutorial also on HS. It's great, it has charme and you put a lot of effort into this.

Nevertheless I saw some inaccuracies here and there.

Quote:Python is a scripted, i.e. interpreted, language. Unlike C, which has a compiler, we have in Python the...(drum roll please)...Python interpreter.

The distinction between interpreted or compiled is not a matter of the language, but the language implementation. You are using the CPython implementation, which means your Python code is compiled to bytecode (the .pyc files) and afterwards interpreted by the VM. So no, CPython is not solely interpreted.

Saying "unlike C" is also not true. C has interpreters too, i.e.
http://root.cern.ch/drupal/content/cint
http://www.softintegration.com/

I would probably remove this sentence entirely from a language introduction as it doesn't really matter which language implementation you use if you want to start with programming Python.

Quote:If I put something in a script, it most likely means you only get the effect from a script and it won't work in interactive mode. Sorry.

Possibly I don't understand that, but you can load the file in interactive mode. So it is no problem writing some function in a file and using them interactively.

Quote:#!/usr/bin/python

This line, like you should've read, is only needed for Unix users. It tells your shell where the python executable is so it can run the script.
#You only need the above line for Unix; replace that with your path to python

It's called shebang, just in case you want to name it. It's not only used on Unix, but also Linux and Mac. Maybe you should say "Unix-like operating systems" instead.

Quote:Any good programmer knows that you need comments in your code

No you don't. You need documentation (in Python docstrings). You don't need comments. They are most of the time perfume for bad smelling code.

Quote:so just put # and anything after that on that line is a comment and will be ignored by the interpreter.

It is ignored by the compiler. The interpreter doesn't get any comments from the compiled bytecode.

Quote:A word on variable names: I'm not quite sure exactly how long Python allows them to be (should I know?)

For Python the only limit is the memory available.

Quote:First, you see the if, then a conditional statement. [...] Next comes a colon, then a newline. You need this newline.

No you don't need the newline. The colon is there to separate the statements

Code:
>>> if 2 > 1: print "a" ... a

Quote:every statement has its own line

No, this works too:

Code:
>>> print "a"; print "b" a b

Quote:But you might say this odd for loop is lacking because it doesn't go through, for example, the numbers from 1 to 10 and put them in i, like in *other* languages. That is easily overcome with the ubiquitously useful range() function

xrange() should always be prefered in a for loop, because it is lazy evaluated, whereas range() computes the whole list and saves it in memory before it even can be used.

Ok, I read about half your tutorial now and have to go offline. Maybe later more.

Regards
Deque
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]






Messages In This Thread
Python for Newbies - by Artmer - 06-26-2013, 01:49 AM