Interactive Shell?

B

Ben Finney

I have fun using the interactive shell, playing with strings and
functions.

Which is the best was to use Python: from the interactive shell, as a
scripting language, or as the Python.h library with C? Is the
interactive shell there for anything beyond prototyping code?

All are useful for different things. All are Python. These two
together mean that you can switch between the different modes as the
need arises.
 
A

Andrew Burton

Allow me a paragraph or two to apply a context to the question I want to ask
here.

Many moons past, when I got "Learning Python" from O'Reilly and first tried to
learn Python, I saw what I know see whenever I open Python up, the infamous >>>
prompt. At the time, it confused me, and I shelved the book. Fewer moons past,
as I fell into a hobby of reading Lisp web pages and lurking in comp.lang.lisp,
I almost started a flame war when I asked about commandline arguments in Lisp.
It took about a week of reading, replying, and sniping before I understood the
fact that Lisp, ideally, was run from an interactive shell. Such a concept was
a complete paradigm shift from my Perl, C, and Visual Basic experiences that I
had no frame of reference for it.

So, skipping ahead to late last year and this year, after a few months of Lisp
and a smattering of Cobol (learning about the importance of indentation), I've
come back to try and learn Python. Now that I am back (have arrived), having
learned what I have from Lisp, I understand the >>> prompt in "Learning Python"
and I have fun using the interactive shell, playing with strings and functions.

However, in the interest of understanding Python, making sure I grasp the
mindset of it, I wanted to ask a couple of general questions. They are general,
and I know there's no "one true answer" for them. The idea is just to get some
answers to offer me a perspective on ways to view Python. All answers and posts
are appreciated greatly. Anyway, here it is...

Which is the best was to use Python: from the interactive shell, as a scripting
language, or as the Python.h library with C? Is the interactive shell there for
anything beyond prototyping code?

Andrew Burton - tuglyraisin at aol dot com
Felecia Station on Harvestgain - http://www.darkbeast.com/
(setq line "I will not tie up my muse.")
(defun punish (x) (if (> x 0) (progn (format t "~A~%" line) (punish (- x 1)))))
(punish 500)
 
J

Josiah Carlson

learned what I have from Lisp, I understand the >>> prompt in "Learning Python"
and I have fun using the interactive shell, playing with strings and functions.

Welcome back.

Which is the best was to use Python: from the interactive shell, as a scripting
language, or as the Python.h library with C? Is the interactive shell there for
anything beyond prototyping code?

I use the interactive shell as a calculator, to process text (in various
ways), to run through ideas that I don't know will work or not (usually
having to do with strange object behavior), etc. I find it very useful
for testing mostly.

Honestly, I've never used Python.h and embedding Python in C, so I can't
comment on it.

What I have done quite often is to write full featured applications,
both for the console and with a GUI. Dropping a set of definitions
(function, class, etc.) and calls into a .py file, then running it with
'python script.py' is enough to get you on your way. I've got no less
than 100 scripts for various uses, from parsing and data compression
(lzw-like and huffman) to image manipulation (image normalization, line
detection, etc.), programming tools, etc. Heck, Idle is a .py script,
as are many thousands of other useful applications. My personal
favorite is PyPE (http://pype.sourceforge.net), but being the author, I
am biased.

There are also various utilities that allow you to bundle your Python
application/script/whatever into a binary, for those that don't want to
install the Python runtime.

If you haven't started looking through the standard module library, you
really should. There are quite a few modules that will likely make
programming with Python that much easier for you in the future. As a
quick suggestion, read about the sys, os, and optparse modules. Most
people forget to read about the first two and end up asking questions
that get asked 3 times/week. The first one is for some VERY useful
per-system constants, and optparse will make your life of dealing with
commandline arguments that much easier.

Good luck,
- Josiah
 
P

Paul Prescod

Andrew said:
...

Which is the best was to use Python: from the interactive shell, as a scripting
language, or as the Python.h library with C? Is the interactive shell there for
anything beyond prototyping code?

I would say that the vast majority of all Python use is as a scripting
language using the form:

python foo.py

The interactive interpreter shell has no memory from session to session
so you lose your work all of the time.

Wrapping your Python program in C is an extra step that is typically
only necessary when you have a C code base that you are trying to extend.

Paul Prescod
 
T

Tim Roberts

Which is the best was to use Python: from the interactive shell, as a scripting
language, or as the Python.h library with C? Is the interactive shell there for
anything beyond prototyping code?

Call me bizarre, but I use the interactive shell as a very powerful desk
calculator, and I often use it on Windows for file and directory
management. It's easy to convert a file from Unicode to UTF-8 with just a
few lines of code. One line, if I'm feeling studly.

There's yet a fourth usage model, if you will: using Pythonwin or IDLE.
Here, you have the benefit of an interactive prompt PLUS a syntax-based
editor. I find it very productive to edit a file in Pythonwin while trying
out mini-test cases or exploring standard library routines in the built-in
shell.
 
A

Alan Gauld

learn Python, I saw what I know see whenever I open Python up, the infamous >>>
prompt. At the time, it confused me, and I shelved the book. Fewer moons past,
as I fell into a hobby of reading Lisp web pages and lurking in comp.lang.lisp,

A good habit to fall into IMHO :)

However in terms of how best to view the Python >>> prompt I'd
suggest a wee excursion into Smalltalk.

The >>> prompt is very similar to the scratchpad mode of
operation in the Smalltalk environment. You create classes and
methods etc in the browser then test them out in the scratchpad.
You want to check a bit of syntax, try it in the scratchpad.

The >>> prompt is used in a similar way (by me at least!). As I
program in <insert favourite text editor here> I dip into the >>>
prompt in a separate window to check out ideas, syntax, and to
test the code I'm writing, import/reloading it, and by
instantiating classes etc and firing up the methods with test
params.

If you do objects in Python the >>> prompt makes a great testbed
for checking them out as you write them.

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

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

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,501
Latest member
Ledmyplace

Latest Threads

Top