Why would I learn Python over other languages?

  • Thread starter Charif Lakchiri
  • Start date
C

Charif Lakchiri

Okay, here's what I know so far about Python:
It's an object-oriented scripting language, supported on many platforms.

Now here are my questions:
It is easy to learn?
Does it support GUI programming?
Does it support server-side programming, say for web apps?
Does it have extensions and libraries, say for DB connectivity, serial com
or network programming...?
Can it be used for administrative tasks, say as perl...?
Also, can it be compiled to native code?

Also much appreciated would be simple comparisons with say JAVA (my other
candidate), and pointers to sites and docs where to start.

Thank you in advance.
 
S

Steve Lamb

It is easy to learn?

Yes. Of all the languages I've looked at Python's been one of the
easiest.
Does it support GUI programming?

Yes; in several different flavors. TK, QT, GTK just to name 3.
Does it support server-side programming, say for web apps?

Yes. mod-python and zope come to mind.
Does it have extensions and libraries, say for DB connectivity, serial com
or network programming...?

Yes. Standard, in fact.
Can it be used for administrative tasks, say as perl...?

Yes. I Python has replaced Perl for my admin tasks since I find Python
far more maintainable than Perl in the long run.
Also, can it be compiled to native code?

No. However on i386 there is Psyco which provides some impressive speed
boosts.
 
A

Anthony Roberts

I was ready to write a long response, but then I realized that all you
probably need to know is speed. As in, how fast can I learn this?

Java will take you months to get good, years if you don't know any other
languages yet. It will take books, large time investments, lots of
busywork as you get comfortable with stuff, and lots of false starts as
you discover new parts of the API. You can be good at Python in weeks.

The Java API dwarfs anything else I know. There are literally thousands
of classes. I know the API well enough to make experienced programmers
go "Woah! I never knew Java could do that!" and I still sometimes find
it easier to write my own stuff than go looking for it in the docs. It's
intimidating to newcomers, and it should be. It's pretty clean, but it's
vast beyond any one person's ability to grasp.

Python can do everything Java can do, but you can eyeball the whole
module list every time you're trying to figure something out. It's
easier to try stuff as you go (interactive interpreter), and a lot of
the busywork and toil has been rolled into language features that make
it trivial. That ultimately makes everything less work and more fun.

To put it in perspective, I learned Java 3 years before Python. It was
my language of choice. It took me two weekends with Python before I was
more productive with it than with Java.
 
P

Paul Rubin

Charif Lakchiri said:
Now here are my questions:
It is easy to learn?

For the most part I'd say yes.
Does it support GUI programming?

Hmm, yes, although the official GUI toolkit (tkinter) is cumbersome,
doesn't look so great on the screen, and is poorly documented.
Does it support server-side programming, say for web apps?

There's a cgi module. There's various third party packages for fancier
types of web apps.
Does it have extensions and libraries, say for DB connectivity,
serial com or network programming...?

There are reasonably good libraries included for various network protocols.
There are third party extensions for DB connectivity and serial com.
Can it be used for administrative tasks, say as perl...?

Sure, so can any language. I'd say it's generally simpler to toss off
a 5-line perl script for some admin task than a comparable Python
script. Python is better for somewhat more complex tasks, where Perl
programs start getting hopelessly disorganized.
Also, can it be compiled to native code?

There's a JIT compiler called psyco which isn't yet officially part of
Python but which is coming along nicely. There's no ahead-of-time
native code compiler and the language doesn't lend itself very well to
that.
Also much appreciated would be simple comparisons with say JAVA (my other
candidate), and pointers to sites and docs where to start.

www.python.org
 
E

Eric Brunel

Sorry: I couldn't resist:
Hmm, yes, although the official GUI toolkit (tkinter) is cumbersome,

Obviously depends on who's talking: I personnaly always found *other* GUI
toolkits cumbersome (I've tested wxPython and PyQT)
doesn't look so great on the screen,

It seems to be the general opinion, but there is some work to make it better on
the tcl/tk side; see http://tcl.projectforum.com/tk/Home
and is poorly documented.

No it isn't; there are a lot of Tkinter resources around, not to mention plain
tk ones. I do agree that they may be hard to find, but they exist. The docs for
the other toolkits I've tried were usually worse than the ones for Tkinter
(things may have improved for wxPython, since I tested it quite a while ago)
 
A

Alan Gauld

Hmm, yes, although the official GUI toolkit (tkinter) is cumbersome,
doesn't look so great on the screen, and is poorly documented.

I won't dispute the other points but Tkinter is better documented
than any other Python GUI toolkit IMHO. Not only does it have the
Pythonware web site, it also has a book by Grayson and all the
Tcl/Tk documentation(books and web sites)

I'd argue that the amount of documentation for Tk (and thus
Tkinter) exceeds any GUI tookit other than X or Microsoft's
various efforts.

Picking nits,

Alan G.

Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
 
E

Ed Suominen

Charif said:
Does it support server-side programming, say for web apps?
Does it have extensions and libraries, say for DB connectivity, serial com
or network programming...?

Check out the twisted package (http://www.twistedmatrix.com/) for an
incredibly powerful answer to these two questions.
 
R

Roy Smith

Charif Lakchiri said:
It is easy to learn?

Yes. Simplicity and ease of learning were major design criteria. There
is also a large and active user community who can provide help,
guidance, and the occasional group hug.
Does it support GUI programming?

Yes. There are several GUI libraries available. I don't do much GUI
programming, so I'll leave it to others to describe those.
Does it support server-side programming, say for web apps?

Yes. There are a variety of ways to do this. At the low-level, there's
CGI module. There's a mod-python for Apache. There's a sample HTTP
server that comes with the system which you can extend on your own. I
recently saw mention of a JSP container for writing servlets in Python.
Does it have extensions and libraries, say for DB connectivity, serial com
or network programming...?

Yes. There is a standard DB API, and adapters for all of the major
databases (Oracle, Sybase, MySql, etc).
Can it be used for administrative tasks, say as perl...?

Yes. There are modules for interacting with the file system and
operating system (process control, etc). If you want, you can execute
external commands and capture their output, just like popen in perl.
Also, can it be compiled to native code?

Yes. The compiler is called "psyco", and it's very easy to use.
Also much appreciated would be simple comparisons with say JAVA (my other
candidate), and pointers to sites and docs where to start.

A quick Java. vs. Python comparison:

Java uses a C-like syntax, Python uses it's own. The Python syntax is
very easy to learn.

Java uses static typing, Python uses dynamic typing That means Java
programs are full of typecasts and variable declarations and useless
drek like that. On the other hand, since you've pushed a lot of
checking off to run time, Python takes a performance penalty.

Java is very much into data hiding, with private/protected/public
keywords to declare classes and variables. In Python, everything is
public by default. There are some ways to do weak data hiding if you
want.

Both compile to byte-code which runs on a virtual machine. The
underlying VM's are similar enough that there is a version of Python
which compiles to java byte code and runs on a JVM! One big difference
is that the compile step is explicit in Java, but happens automatically
and behind the scenes in Python. This means you can just fire up an
interactive Python session and type code at it to try things out, which
turns out to be incredibly useful.

Both are object-oriented. Java is a bit more extreme in this philosophy
(i.e. everything is a class). In Python, you can write non-OO code if
you want, and that's often easier for quickie one-off scripts such as
are common in sysadmin work.

If you are just starting out, I would definately learn both.
 
C

Christopher T King

Obviously depends on who's talking: I personnaly always found *other* GUI
toolkits cumbersome (I've tested wxPython and PyQT)

Seconded. Only in Tkitner can you write a (legible) one-liner Hello World:

import Tkinter
Tkinter.Label(text='Hello, world!').pack()
It seems to be the general opinion, but there is some work to make it better on
the tcl/tk side; see http://tcl.projectforum.com/tk/Home

On Win32, Tk uses the native widgets, so it looks just as pretty (?) as
any other Win32 app.
No it isn't;

Also seconded. It's also a lot easier to follow Tk's Tcl documentation
than GTK or Qt's C documentation.
 
P

phil hunt

I was ready to write a long response, but then I realized that all you
probably need to know is speed. As in, how fast can I learn this?

Java will take you months to get good, years if you don't know any other
languages yet. It will take books, large time investments, lots of
busywork as you get comfortable with stuff, and lots of false starts as
you discover new parts of the API. You can be good at Python in weeks.

The Java API dwarfs anything else I know. There are literally thousands
of classes. I know the API well enough to make experienced programmers
go "Woah! I never knew Java could do that!" and I still sometimes find
it easier to write my own stuff than go looking for it in the docs. It's
intimidating to newcomers, and it should be. It's pretty clean, but it's
vast beyond any one person's ability to grasp.

Python can do everything Java can do, but you can eyeball the whole
module list every time you're trying to figure something out.

I find that Python's library does as much as Java's but with less
classes. python's libraryu focusses on gettinbg the job done,
whereas I find java's library to be pedantic and irritating.
 
G

GMTaglia

Christopher said:
Also seconded. It's also a lot easier to follow Tk's Tcl documentation
than GTK or Qt's C documentation.

Also GTK documentation is not so bad, I prefer GTK but is only my personal
taste -.-
 
J

Jorgen Grahn

I was ready to write a long response, but then I realized that all you
probably need to know is speed. As in, how fast can I learn this?

Java will take you months to get good, years if you don't know any other
languages yet. It will take books, large time investments, lots of
busywork as you get comfortable with stuff, and lots of false starts as
you discover new parts of the API. You can be good at Python in weeks. ....
To put it in perspective, I learned Java 3 years before Python. It was
my language of choice. It took me two weekends with Python before I was
more productive with it than with Java.

I second that. The thing I find remarkable about Python is precisely that:
that learning the language is a very small investment.

Just sit down over the weekend with docs.python.org, a Python installation
and a text editor with good Python support. By Monday you may not need to
make a decision ...

/Jorgen
 
R

Roy Smith

I used to work with a guy who was a Perl fanatic (Hi, Nathan). We
parted company a year to two ago, but I still talk to him every once in
a while.

A few days ago, I got some mail from him that said:
I just wanted to drop you a quick line to thank you for being the Python
evangelist at XXXX. I've started a small programming project this week
and I decided to prototype it in an interpreted language. Thus, this is
my first week working with Python! I've still got tons to learn but it
is very clean and I really like the ability to test code fragments
interactively.

and later:
So far I've been quite pleased by the amount and quality of
documentation available on the Internet. I hate to say it, but it's
more readable than Perl (the code and the docs).

I know this sounds like one of those corny fake testimonials, but those
are real cut-and-paste quotes from his email. I just can't imagine
reading the above paragraphs with "Python" crossed out and "Java"
written in with crayon.
 
B

bruno modulix

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
 
C

chuck amadi

Hi , I would like to add a comment I agree I uses to be a coder (
Systems Programmer prodominately Java and JSP and thus switched to
SysAdmin role as I wanted to get into Security and add more dimension to
my learning curve with Linux .

I have used Python quite limiting but it done the trick I also found the
books and the user group excellant going back to Java I am to take and
sit my Java 1.4 exam this November 2004 and Im not that prepared and I
don't fancy the investment I know I need to make in order to try and get
a pass .

Java is a rich dynamic language bit from a time and speed point of view
I love Python and as a Zope Admin is execellant tool in order to run
Zope/Plone CMS sites as If you may or not know Zope/Plone/CMF is making
a quite inpact in the Content Management Areana with this being written
in Python.

So ti say it again Python is a great lanaguage I it isn't for me a hugh
time investment .

Cheers

Chuck
 
A

Arthur

Okay, here's what I know so far about Python:
It's an object-oriented scripting language, supported on many platforms.

Now here are my questions:
It is easy to learn?

I, as always, will answer that question differently from most other
answers you will yet.

Depends how much previous programming experience you have. It is
widely reported, and I have no reason to doubt, that people with a
good understanding of programming principles already in place, find
Python easy to learn.

It is widely reported, that Python also is easy to learn as a first
language. Almost exclusively by people who learned their programming
principles elsewhere. They are making a logical conclusion based on
their understanding of the languages strenghts - clean syntax,
readibility, etc.

My position is that the issue is considerably more complex than that.

I can only go by my own experience. Especially when I have seem
nothing substantial contradicting it, other than verbiage.

It seems to me sensible to believe that someone can become a quite
decent, say C++ programmer, by tackling it as a first language, and
sticking with it.

I don't think that is true of Python. I think there is a layer of
Python that one cannot reasonably penetrate without stepping outside
of Python.

One can get started with Python, with Python.

But in the end I don't think Python serves as a fully adequate
introduction to itself.

Art
 
P

Peter Hansen

Arthur said:
But in the end I don't think Python serves as a fully adequate
introduction to itself.

I think you might say the same about almost any language.

And yet, many seem to get a good start in programming with,
well, almost any language... (except VB ;-) .

-Peter
 
A

Arthur

I think you might say the same about almost any language.

And yet, many seem to get a good start in programming with,
well, almost any language... (except VB ;-) .

Perhaps of any very high level language.

Guess I am feeling some frustration. Don't see a path to getting
deeper into an understanding of Python without undertaking getting
some handle on C. Mostly intuition at work.

And its not that I need (or expect to be able) to follow the Python C
code.

Python has me addicted me to the interactive prompt as a learning
tool, so was lucky to comae across CH, a C intepreter.

http://www.softintegration.com

New hope.

Art
 
D

Donn Cave

Quoth Arthur <[email protected]>:
....
| It seems to me sensible to believe that someone can become a quite
| decent, say C++ programmer, by tackling it as a first language, and
| sticking with it.
|
| I don't think that is true of Python. I think there is a layer of
| Python that one cannot reasonably penetrate without stepping outside
| of Python.

It's odd that you would pick C++ for contrast. I thought it was
nearly universally dismissed as the worst possible way to learn
object oriented programming, to the point that some people suggest
learning a real OOP language like Smalltalk first to inculcate the
basic principles.

I wouldn't claim that Python is particularly easy for pure beginners,
without more than the slim anecdotal evidence I have, but I would
be interested to hear what other sort of language experience you
believe it takes to get the whole story.

In my comment above about Smalltalk and C++, I don't mean to suggest
that Smalltalk helps anyone understand C++. It's just supposed to
present a more focused object oriented programming model, and that
sense of the important principles is what it's about. Of course it's
utterly different from C++ in most respects.

Does Python present some aspect of itself in a confused and incoherent
way? Well, yes, of course - it's a terrible introduction to functional
programming! But it's a terrible functional programming language anyway,
so a Haskell programmer wouldn't have a big advantage here. In fact
there are enough subtle differences in what variables are and so forth,
that Haskell or for that matter almost any other language is going to
be a bit of a liability.

Donn Cave, (e-mail address removed)
 
P

Paul Prescod

Arthur said:
...

I don't think that is true of Python. I think there is a layer of
Python that one cannot reasonably penetrate without stepping outside
of Python.

One can get started with Python, with Python.

But in the end I don't think Python serves as a fully adequate
introduction to itself.

In one sense I think that any language is a sufficient introduction to
itself. Given enough time and effort you learn every trick, see every
corner exposed by someone (perhaps someone with a different background
than you) and learn everything there is to possibly know. Sometimes it
is MORE EFFICIENT to step outside the language to learn it but one can
do the whole thing from the inside. It would be a lot easier to learn
physics if we could step outside the universe and experiment with the
rules but we scrape away at it from the inside and figure it out the
hard way. Python is surely simpler to understand than the universe.

In another sense, every language builds on other languages and you will
always feel you are missing something if you know the language but not
the ones it is built upon. A C++ programmer who doesn't understand
assembly language does not know what an function call "really" is (in
terms of its implementation).

Sometimes Python's implementation language leaks through. "Why is it
that way? Because it is in C?" But that is also true for C++. What does
the register keyword mean? Or ask a Lisper what "cdr" means...

I am skeptical that Python is either more or less self-revealing in
these senses than any other language.

Paul Prescod
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top