please help

Alex Martelli aleaxit at yahoo.com
Thu Dec 21 09:43:13 EST 2000


<monamant at freemail.sx.cn> wrote in message
news:91spce$tc1$1 at nnrp1.deja.com...
> Hi,
>   I am just thinking about taking Python as my first programming
> language for serious learning (after reading "how to become a hacker"),

Good idea.

> but some distrusts with python's applicability prevent me from fully
> applying myself to it. Would you kindly help clear up some of my doubts
> about Python?

Sure!

> 1. I want to use IIS 4.0 for my webserver, can I use scripts compiled
> by Python in it?

With Mark Hammond's 'win32all' extensions (already bundled in the
ActiveState distribution of Python for win32, see www.activestate.com)
Python is installed as an 'Active Scripting Language', so you can
use it for most any task for which you could use any other Active
Scripting language (such as vbscript or jscript).  IIS 4.0 is one
example of the variety of active script host programs, and chapter
21 "Active Scripting" of Hammond and Robinson's "Python Programming
on Win32" book (O'Reilly) specifically deals on how to configure
it (virtual directory -> physical directory with the Python ASP's).

> 2. What about the ASP? If I want to use ASP, can I use Python to do
> such jobs like user authentication? How well can Python be used in Web
> programming on Windows platform?

See above.  'Yes', and 'Very very well', are the answers.  Once
you've installed Python (in the ActiveState version, or with the
separate win32all extensions that you'll also find on their site
applied on top of the standard Python 2 Win32 distribution), and
set up the virtual->physical directory, you're all set.  You'll
start your ASP page with <%@ Language=Python @> and live happily
ever after (directing your commands and requests to Application,
ObjectContext, Request, Response, Server, just as you would
for any other ASP).

> 3. I used VB in the past and you can make a '.exe' file after
> compiling. But how can I actually execute the Python program in
> Windows? It seems that I can not make a .exe file for it to execute. It
> is dependent on the interpreter?

You can try Gordon McMillan's "installer" at
    http://www.mcmillan-inc.com/install1.html
to bundle the various files a given Python application needs
into a single, 'self-unpacking-and-installing', .EXE file.

This only matters if you want to distribute applications to
others who don't have Python installed, actually.

Else, to run a foo.py program, once you have Python installed,
you enter at the command prompt (or in a .BAT, or...):
    python foo.py
normally, or
    pythonw foo.py
to execute without a console (stdin/out/err), useful for GUI
apps; and/or associate python.exe and/or pythonw.exe to the
appropriate file-extensions (.py and .pyw are normally used)
so the python file or a shortcut to it can be 'double-clicked'
(a single click may actually suffice, with Active Desktop:-).

You also have many other options, for example all those
connected with Windows Scripting Host (WSH), HTML Applications
(HTA), and so on.  That YOUR program is not itself an .EXE
(except if you package with Installer) matters little.  Python
itself is mostly a DLL, by the way; python.exe and pythonw.exe
are just tiny wrappers to run the code in the DLL -- this
matters because it's easy to access the DLL itself from your
programs (in C or C++).

But on Windows, among the other myriad options, COM shines:
with Python (and win32all; or, ActiveState's python) you can
build COM objects and instantiate-and-run-them in any way
you like from any other program (including Python ones, of
course).  COM is also how ActiveScripting works, how WSH
works, how HTML pages can embed/talk with your objects and
be scripted by you, etc, etc -- even how the graphical Shell
of Windows is interacted with.


> 4. If I really sit my self to Python, does it reward equally for the
> same effort in learning C? In the aspect of the quality of programs.

Python will let you be orders of magnitude more productive
than C at most tasks: the flip side of this is *performance*.

Python is a very high-level language, while C is pretty low
level, close to the machine and far from the human being.

Python thus lets YOU, the human being, be much faster and
more productive; while C optimizes the speed with which the
*computer* can run your programs.  (C++ tries to do both,
and _also_ keeps C compatibility; but, as a result, is HUGE
and terribly complex, alas).

For most tasks these days, by far, human productivity is
what matters -- computer power has become incredibly cheap
compared to what it was back when C was invented (as the
price/performance ratio halves every 18 months or so, in
30 years there have been about 20 halvings -- i.e., a
factor of *a million to one* or so...), while human beings
are much the same as 30 years ago.  Crucial performance
aspects, such as choice of good algorithms, are _easier_
in Python, as you can better experiment and try out various
things, so you could even end up with a better/faster
program...!-)  And when the algorithm is settled and you
*DO* need to squeeze every last cycle of computation out
of your machine, that's where extensions to Python, built
in C or C++, enter the picture, *selectively* replacing
Python code with much-speedier, lower-level code.  You will
find a lot of GREAT existing extensions for such things as
numerical work ('Numeric') and image processing ('PIL'), the
kind of tasks that are computationally very intensive...
not to speak of all the existing components which you may
access (on Windows) from Python via COM (that lets you
reuse/automate such things as Microsoft Excel's engine
to handle your computations, for example).

You may eventually want to learn C, or C++, yourself, in
order to be able to write some little but crucial very
high speed component for your own programs -- but that
will only be, say, 1/10 or 2/10 of your overall program;
most of it can stay in Python, if you wish...


Alex






More information about the Python-list mailing list