-
Tell me about Python
So over the summer I am going to have to teach myself the basics of Python for the lab that I'll be working in. We're going to be doing experiments involving subliminally presented stimuli (20-40 milliseconds), evaluations of pictures and movie/audio clips, and possibly recording reaction time data, as well as asking subjects basic questions - all GUI, obviously. I have programming experience with Java and C++ (I guess that's how I got stuck with this gig) but I don't know much at all about Python.- Do you know of any good books for learning Python?
- Any good online resources?
- Any tips on using Python specifically to do the things that I listed above?
- Any other things that I should know about Python and/or learning Python?
Any information would be appreciated. Thanks, guys. :cheers:
-
Things to keep in mind:
It uses a JIT compiler, so it may speed up and slow down randomly, so use the hardware timer for timing things.
It is the only programming language that I know of that is indentation sensitive. That can be very annoying, but makes code easier to read.
It's a very simple language, no direct access, nor does it have any objects. Most people consider it a scripting language more than a real programming language.
-
Python doesn't use a JIT...??? (As far as I know apart from the PyPy project)
I think you are thinking of the wrong language, ninja9578.
It is indentation sensitive, yes, but see:
Code:
>>> class A:
... def __init__(self, x):
... self.x = x
...
>>> a = A(16)
>>> a.x
16
Python is strongly object oriented.
Also, http://docs.python.org/tutorial/.
-
Python is very powerful, from what I've read. But, you have to be a super-indent/space nazi because of the lack of braces.
It shouldn't be too hard...There are good books on it out there. I have one, forgot the name. Also, that link above is where I go the basics of it.
I never got too far into it, I put it aside for C++ and Perl, the latter of which I am currently working on learning. However, GUI programming with Python is supposed to be pretty easy.
-
The indentation is a non-issue. You indent the same way you would for other imperative languages. Python just ensures that other programmers you're working with don't mis-indent a line by accident. I second the official tutorial. Python's a great language for a lot of tasks (anywhere from simple scripts to larger CLI apps to GUI apps to CGI scripts to web applications to games, etc.), and it has a really compact language definition, making it easy to keep in your head (contrast with C++ and Perl). It also has one of the easiest-to-read syntaxes of any imperative language, and Python code tends to be really concise, saving tons of development time.
-
^ The indentation is a nuisance however. Learning that before {} programming doesn't seem the way to go with me. I have only seen one language use that indenting style, and that's Python. i'm sure there are more, less known languages with that style, but for mainstream programming, {} seems better to me.
-
Haskell syntax also recognizes indentation, although it's syntactic sugar for braces iirc. Python and Haskell are two of the most efficient programming languages, in terms of productivity as opposed to performance (although Haskell code compiled with `ghc -O2' isn't much slower than the equivalent imperative code written in C), and they both ascribe syntactical meaning to whitespace. :D
-
That's why I like C++, the productivity of a powerful OOP language and the raw speed of C and inline assembly :D
Just out of curiosity, does Python have inline assembly capabilities. No optimizing compiler will ever beat a skilled assembly programmer.
-
Well, you can write a C extension module and use assembly in that... I doubt it has inline assembly, that would just tempt people to write illegible assembly in the middle of their code - negating the clarity of code that is one of python's goals :P. A maxim of python development is "write it in python first, if it is too slow then write an extension module in C".
-
C + Python is a good way to go.