A beginning beginner's question about input, output and . . .

Cameron Simpson cs at cskk.id.au
Mon Jan 11 17:11:37 EST 2021


On 11Jan2021 15:37, DonK <don81846 at comcast.net.REMOVEME> wrote:
>Hi, I'm thinking about learning Python but I'm 74 years old and will
>very likely not ever have a programming job again. I used to program
>in Visual Basic, C\C++, Delphi, etc. and some obscure "mainframe"
>languages.

Therefore you're happy with classes, and are presumably with a Windows 
background. (And, of course, the mainframe world.)

>I've installed Python 3.7, the PyCharm IDE and watched some Youtube
>tutorials but it's been stretched out over about 1.5 years so I'll
>probably need to go back to the beginning. My problem is that I don't
>understand how Python programs are used. (i.e user input and output)
>Is Python mainly used for backends?

My personal Python use is almost all backend, and on a personal basis I 
spend most of my time at a command prompt in a terminal window.

However, you can write fully fledged GUI applications in Python.

Without a GUI Python programmes tend to work off their input and write 
to their output (or other files) like any other command line programme.

Chris mentioned input() for reading input and print() for writing 
output. input() is an interactive function (it accepts a prompt string 
and reads a single line of text). If you're writing something batchy, 
which might be in a pipeline or reading from a text file, then the 
standard input is sys.stdin and can be read in various ways - when that 
is text the typical way is just to iterate over it in a for-loop, which 
gets your lines of text.

Trite example:

    import sys
    ........
    ........
    lineno = 0
    for line in sys.stdin:
        lineno += 1
        print("line number", lineno, "text =", line)

>I've seen some Python gui frameworks like Tkinter, PyQt, etc. but they
>look kinda like adding a family room onto a 1986 double wide mobile
>home, and they look even more complicated than creating a GUI from
>scratch in C++ with a message loop, raising events . . .

They aren't really. I've not use Tkinter, but I have used PyQt. You 
still have the usual framework:

- contruct widgets (windows and other GUI elements) with the associated 
  code which runs when you interact with them

- an event loop (usually simply entered after constructing the main GUI 
  component(s)) - it will run until told to stop

- raising events - in PyQt these are called "signals" - you issue a 
  signel/event with whatever information it uses and the event loop runs 
  its handler in due course

Part of the difficulty with PyQt (for me) is that it is a Python shim 
onto a quite large C++ widget library. Most of the actual doco seems to 
be the C++ side, and you need to infer some stuff to use it from Python.  
The shim is very one-to-one, so that works pretty well.

I gather that Tkinter is easier to get off the ground with.

>So, what do you folks use Python for?

Personally, almost entirely command line stuff, and making 
libraries/modules/packages which implement what I need.

>Nowdays I mainly just use programming for rather small utilities for
>my personal use.

Me too.

>Currently I'd like to write something to iterate
>through open windows and save them to different folders depending on
>if the titlebar contains certain strings. In the past I would probably
>have used Excel's VBA to do this but I no longer have Excel installed
>on my main computer. I'd like a bit of a challenge but I don't want to
>spin my wheels trying to learn something that will be a dead end for
>me.

This requires Windows specific knowledge, which I lack. Saving to 
folders etc is standard stuff, but the "iterate through open windows" 
and consulting their titlebar strings is platform, and maybe app, 
specific. I'm not a Windows person, alas.

>I know that this probably seems like a stupid post but your input will
>be useful.

No, it's entirely reasonable. Getting off the ground with a 
useful-to-you task is always the first hurdle with a new language.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list