[Tutor] Getting Started

Oscar Benjamin oscar.j.benjamin at gmail.com
Thu Dec 19 10:48:43 CET 2013


On 19 December 2013 00:11, Chris Acreman <cacreman at austin.rr.com> wrote:
>
> "Can you be more specific about the 'Python screen' ?" -- Amit
> "How are you running Python at the moment?  Is it just the command line
> interpreter? Or do you have some kind of GUI tool?" -- Alan
>
> The "Python Screen" is what opens up when I click the Python button on the
> desktop.  The book calls it a "console window,  window that can display only
> text."  It is a command line interpreter, with no apparent GUI tools.  The
> book does have a chapter entitled "GUI Development:  The Mad Lib," so I
> assume it will include instructions for writing programs with GUIs.
>
> It is black with gray lettering.  The first four lines of text are:
>    Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012.  10:57:17) [MSC v.1600 64
> bit (AM
>    D64)] on win 32
>    Type "help", "copyright", "credits" or "license" for more information.
>    >>>
>
> The screen can be stretched vertically but not horizontally.  It is 80
> columns wide.

There are a couple of different things going on here which is a little
confusing so I'll try to explain. I apologise in advance if you
already know all/most of this.

The graphical window that you describe is called cmd.exe and it is the
standard "terminal emulator" for Windows. Terminal emulators are also
called "console windows", "terminal windows" or just "terminals". This
particular one is sometimes called "the DOS prompt" or the "DOS box" -
although both of those terms are inaccurate so I have to qualify my
statement with this caveat to discourage pedants from correcting me.
:)

http://en.wikipedia.org/wiki/Terminal_emulator

Unfortunately MS hasn't put much development effort into this
particular part of Windows (cmd.exe) over the last 10-15 years so that
it is now massively inferior to most other terminal emulators. Every
other operating system I have used (OSX, Linux etc.) ships with a
significantly better terminal emulator then cmd.exe. Hence the fact
that it is ugly, doesn't resize horizontally, doesn't handle cut and
paste very well etc.

The terminal emulator can be used to run many different programs. The
types of programs that are designed to run in a terminal emulator are
often known as "command-line programs" or "console applications". This
is to be contrasted with the "graphical" or "GUI" applications that
most computer users are familiar with.

http://en.wikipedia.org/wiki/Console_application
http://en.wikipedia.org/wiki/Graphical_user_interface

In particular python.exe on Windows is a console application so when
you run it it cmd.exe will open up to show you the output and allow
you to type input. This is what happens when you click the Python
button on your desktop. You can also run cmd.exe directly without
Python. To do this you would push Win-R i.e. hold the "Windows key"
and push the "R" key. This opens the "run" dialog. There if you type
"cmd" and hit enter it will open cmd.exe. Then you should be able to
run Python by typing "py" and hitting enter. Then you will be in the
Python console and can type Python commands. To exit Python use the
key combination Ctrl-Z. This way you can switch between typing
commands into the cmd console or into the Python console.

A Python script is a plain-text file with the .py extension that
contains Python code. If you have such a file and it is saved in
"C:\myfiles\myscript.py" then you can run it in cmd.exe without
entering the Python console by typing "py C:\myfiles\myscript.py".
This is how I would normally run my Python programs*. Here's an
example of how it looks when I run cmd.exe, Change the Directory (cd)
to where my Python script is and then run my Python script.


O:\>q:

Q:\>cd tempdir

Q:\tempdir>dir
 Volume in drive Q has no label.
 Volume Serial Number is 18AB-2D00

 Directory of Q:\tempdir

19/12/2013  09:42    <DIR>          .
19/12/2013  09:42    <DIR>          ..
19/12/2013  09:42                22 myscript.py
               1 File(s)             22 bytes
               2 Dir(s)  178,230,497,280 bytes free

Q:\tempdir>py myscript.py
Hello World!


Now here's what happens if I just type "py" to enter the Python console:


Q:\tempdir>py
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> print('Hello World!')
Hello World!
>>>  [** Here I push Ctrl-Z to exit the Python console **]

Q:\tempdir>


So you don't need to use IDLE or anything like that if you don't want.
You just need an editor that can edit plain-text files to write and
save your Python scripts and then you can run them with cmd.exe. Again
the standard plain-text editing program that ships with Windows
(notepad) is absolutely terrible - but there are many others that you
could install and use. The standard editor on the Windows systems
where I work is called "notepad++" and is vastly better than notepad
but it doesn't come with Windows so you need to install it yourself.

http://notepad-plus-plus.org/


* Actually I don't use cmd.exe unless I really have to since it's such
a frustratingly rubbish program. I always install a better terminal
emulator called "Console2" to replace the graphical part of cmd.exe
and "git-bash" which allows me to type bash-style commands instead of
DOS-style commands. At this point my experience is somewhat closer to
what you would get out of the box on most non-Windows operating
systems.


Oscar


More information about the Tutor mailing list