Welcome, guest | Sign In | My Account | Store | Cart

A simple example of having a pseudo-echo using sys.stdout.write...

This gives exactly the same results from Python Versions, 1.4.0, 2.0.1, 2.5.6, 2.6.9, 3.4.3 and 3.5.2 on various platforms including the classic AMIGA A1200.

Enjoy finding simple solutions to often very difficult problems...

Bazza.

Python, 14 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Issued as CC0, 2017, Public Domain, B.Walker, G0LCU.
import sys

echo=sys.stdout.write

newline="\n"
char="!"
num=1
strng1="Python Version "
strng2=".4.0 for the AMIGA to 3.5.x"

echo("This works from %s%u%s on any platform%c%c" %(strng1, num, strng2, char, newline))

# sys.stdout.flush()

This snippet is useful for making simple Python code version independent.

I used, 'echo', but just change to 'printf' if that is your preference.

There will be some limitations, but hey, most 'echo' commands/statements/functions usually do have limitations.

3 comments

Barry Walker (author) 7 years, 3 months ago  # | flag

Now checked on Python Versions 2.2.1 and 2.7.10. (Version 2.2.1 on Windows and 2.7.10 on OSX 10.12.2, Sierra.)

Barry Walker (author) 7 years, 2 months ago  # | flag

Well I knew this guy would pass a comment, BUT on another site that I actually follow, here:-

https://mail.python.org/pipermail/python-list/2017-February/719378.html

And Another guy to whom I wall say THANK YOU to for a nice reply.

https://mail.python.org/pipermail/python-list/2017-February/719381.html

Thank you Antoon for that succinct answer, I don't know you but I left the Python ML some years ago because of Mr D'Aprano...

One of my very first posts some years ago when I was on the Python ML, he ridiculed. I left a few months after that.

Oh yes Mr D'Aprano I remember you well... Remember this one which is mine, you SHOULD do? http://code.activestate.com/recipes/578662-a-demo-to-show-how-to-write-text-into-the-python-t/?in=user-4177147

How about this one:- http://code.activestate.com/recipes/577836-raw_input-for-all-versions-of-python/?in=user-4177147

I must NOT forget this one too:- code.activestate.com/recipes/578662-a-demo-to-show-how-to-write-text-into-the-python-t/?in=user-4177147 I am a pure amateur coder BUT........ I expect a PROFESSIONAL to know how to RESET and return a *NIX style terminal back to normal using terminal escape codes ALONE from the command line.

And finally let's face it you were not clever enough to give a reply to this one eh! I set it as a challenge! http://code.activestate.com/recipes/578013-amplitude-modulation-tremolo-was-an-audiosound-sni/?in=user-4177147

So again Antoon Pardon, THANK YOU; so you can hear me... ;oD

Barry Walker (author) 7 years, 2 months ago  # | flag

Somehow the last upload got corrupted, the correct URL is:

http://code.activestate.com/recipes/578079-pure-fun-for-text-mode-python/?in=user-4177147

Bazza.