Why would I learn Python over other languages?

bruno modulix onurb at xiludom.gro
Thu Jul 8 18:12:22 EDT 2004


Charif Lakchiri a écrit :
> Okay, here's what I know so far about Python:
> It's an object-oriented 
right, but also imperative and a bit functional

> scripting
yes with 'scripting'='dynamic hi-level interpreted'

> language, supported on many platforms.
right

> Now here are my questions:
> It is easy to learn?
Yes. It's (also) used as scripting language for non-programmers and as 
first-language for students. If you have some working experience as a 
programmer, being productive in Python is a matter of days.

> Does it support GUI programming?
Yes. TCL, QT, GTK, wxWidget, Win32, etc...

> Does it support server-side programming, say for web apps?
Yes. The killer Python-app is Zope, a web application server - and it's 
*really* a killer-app. But there are many other solutions (plain old 
cgi, mod_python, a lot of frameworks based upon mod_python, etc...)

> Does it have extensions and libraries, say for DB connectivity, serial com 
> or network programming...?
Everything you need, and much more. Ever wrote a web server in a pair of 
lines  of code ?
http://docs.python.org/lib/module-SimpleHTTPServer.html

> Can it be used for administrative tasks, say as perl...?
Of course.

> Also, can it be compiled to native code?
No. Why ?

But have a look at swig, Psycho, and Pyrex if you feel concerned with 
raw speed...

> Also much appreciated would be simple comparisons with say JAVA (my other 
> candidate), 

Reading a text file line by line and printing each line to stdout in java:

import java.io.*

public class ReadFile {
   public static void main(String[] args) {
     try {
       BufferedReader buff =
         new BufferedReader(new FileReader("mytext.txt"));
       String line = buff.readLine();
       while (line != null) {
         System.out.printLn(line);
	line = buff.readline();
       }
     }
     buff.close();
     catch (IOException e) {
        System.out.printLn("Erreur : " + e.toString());
     }
   }
}

The same in Python

try:
   for line in File("mytext.txt"):
     print line
except IOError, e:
     print "Erreur", e

The exception handling being useless in such a context (but still 
probably mandatory in the Java version...), you can make it :

for line in File("mytext.txt"):  print line

If you go for low-level programming in an interpreted language, choose 
Java. If you prefer fun and productivity, you know where to find it.

Consider this : starting from scratch in both languages, you'll probably 
have your application up and running in Python way before you begin to 
figure out how to write it with Java.

Consider this too : There is a Java implementation of Python. So you can 
have you'r cake and eat it too. (well, almost, since you'll still have 
to learn the Java API, but what...)

> and pointers to sites and docs where to start.

http://www.python.org

> Thank you in advance.
HTH
Bruno



More information about the Python-list mailing list