ANN: Wing Python IDE 7.2.8 has been released

2021-01-14 Thread Wingware
Wing 7.2.8 fixes reformatting selections for PEP8, corrects completion 
of code reformatting in remote files when code is unchanged, fixes 
problems analyzing incomplete 'def async' statements, correctly handles 
refactor module rename when the target name exists, adds a preference to 
control the delay before tooltips are shown, reduces the default 
tooltips delay, shows a warning when a file exceeds the configured 
maximum size for running external code checkers, and makes a number of 
other usability improvements.


Details:  https://wingware.com/news/2021-01-12
Downloads:   https://wingware.com/downloads

== About Wing ==

Wing is a light-weight but full-featured Python IDE designed 
specifically for Python, with powerful editing, code inspection, 
testing, and debugging capabilities. Wing's deep code analysis provides 
auto-completion, auto-editing, and refactoring that speed up 
development. Its top notch debugger works with any Python code, locally 
or on a remote host. Wing also supports test-driven development, version 
control, UI color and layout customization, and includes extensive 
documentation and support.


Wing is available in three product levels:  Wing Pro is the 
full-featured Python IDE for professional developers, Wing Personal is a 
free Python IDE for students and hobbyists (omits some features), and 
Wing 101 is a very simplified free Python IDE for beginners (omits many 
features).


Learn more at https://wingware.com/


--
https://mail.python.org/mailman/listinfo/python-list


Re: count consecutive elements

2021-01-14 Thread Dan Stromberg
On Wed, Jan 13, 2021 at 6:20 PM Dan Stromberg  wrote:

> On Wed, Jan 13, 2021 at 5:59 PM Tim Chase 
> wrote:
>
>> On 2021-01-13 21:20, Bischoop wrote:
>> > I want to  to display a number or an alphabet which appears mostly
>> > consecutive in a given string or numbers or both
>> > Examples
>> > s= ' aabskaaabad'
>> > output: c
>> > # c appears 4 consecutive times
>> >  8bbakebaoa
>> > output: b
>> > #b appears 2 consecutive times
>>
>
> I'm kind of partial to:
>
> import collections
> import typing
>
>
> def get_longest(string: str) -> typing.Tuple[int, str]:
>
I just realized this has a kinda big bug. Don't use!
-- 
https://mail.python.org/mailman/listinfo/python-list


[ANN] PyYAML-5.4b1: Linux and Mac users, please test wheels!

2021-01-14 Thread Matt Davis
===
Announcing PyYAML-5.4b1
===

A beta release of PyYAML is now available:
https://github.com/yaml/pyyaml/releases/tag/5.4b1

This release contains a security fix for CVE-2020-14343. It removes the
python/module, python/object, and python/object/new tags from the
FullLoader.
YAML that uses these tags must be loaded by UnsafeLoader, or a custom loader
that has explicitly enabled them.

This beta release also adds Python wheels for manylinux1 (x86_64) and
MacOS (x86_64) with the libyaml extension included (built on libyaml 0.2.5).
We believe these wheels to be stable, but please take the opportunity to
test
against your local Linux and MacOS environments, and file any issues at
https://github.com/yaml/pyyaml/issues.

PyYAML 5.4 will be the last release to support Python 2.7.


Changes
===

* https://github.com/yaml/pyyaml/pull/407 -- build modernization, remove
distutils, fix metadata, build wheels, CI to GHA
* https://github.com/yaml/pyyaml/pull/472 -- fix for CVE-2020-14343, moves
arbitrary python tags to UnsafeLoader
* https://github.com/yaml/pyyaml/pull/441 -- fix memory leak in implicit
resolver setup
* https://github.com/yaml/pyyaml/pull/392 -- fix py2 copy support for
timezone objects
* https://github.com/yaml/pyyaml/pull/378 -- fix compatibility with Jython


Resources
=

PyYAML IRC Channel: #pyyaml on irc.freenode.net
PyYAML homepage: https://github.com/yaml/pyyaml
PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation
Source and binary installers: https://pypi.org/project/PyYAML/
GitHub repository: https://github.com/yaml/pyyaml/
Bug tracking: https://github.com/yaml/pyyaml/issues

YAML homepage: http://yaml.org/
YAML-core mailing list:
http://lists.sourceforge.net/lists/listinfo/yaml-core


About PyYAML


YAML is a data serialization format designed for human readability and
interaction with scripting languages. PyYAML is a YAML parser and emitter
for
Python.

PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support,
capable extension API, and sensible error messages. PyYAML supports standard
YAML tags and provides Python-specific tags that allow to represent an
arbitrary Python object.

PyYAML is applicable for a broad range of tasks from complex configuration
files to object serialization and persistence.


Example
===

>>> import yaml

>>> yaml.full_load("""
... name: PyYAML
... description: YAML parser and emitter for Python
... homepage: https://github.com/yaml/pyyaml
... keywords: [YAML, serialization, configuration, persistence, pickle]
... """)
{'keywords': ['YAML', 'serialization', 'configuration', 'persistence',
'pickle'], 'homepage': 'https://github.com/yaml/pyyaml', 'description':
'YAML parser and emitter for Python', 'name': 'PyYAML'}

>>> print(yaml.dump(_))
name: PyYAML
homepage: https://github.com/yaml/pyyaml
description: YAML parser and emitter for Python
keywords: [YAML, serialization, configuration, persistence, pickle]


Maintainers
===

The following people are currently responsible for maintaining PyYAML:

* Ingy döt Net
* Matt Davis

and many thanks to all who have contribributed!
See: https://github.com/yaml/pyyaml/pulls


Copyright
=

Copyright (c) 2017-2020 Ingy döt Net 
Copyright (c) 2006-2016 Kirill Simonov 

The PyYAML module was written by Kirill Simonov .
It is currently maintained by the YAML and Python communities.

PyYAML is released under the MIT license.
See the file LICENSE for more details.
-- 
https://mail.python.org/mailman/listinfo/python-list


Exploring terminfo

2021-01-14 Thread Alan Gauld via Python-list
During lockdown I've been digging deeper into the curses module
and lately into the ti family of functions that reside there.

I've written a short program that is supposed to
- *clear the screen*,
- read some input
- display the result in a message *highlighted in bold*.
- get input to end the program

The parts marked with ** use terminfo, or they should.
My problem is that while the clear-screen part works the
bold bit only appears in the final input(), not in the
output message.

Here is the code:

#
import curses as cur
cur.setupterm()

bold = cur.tigetstr('bold')
cls = cur.tigetstr('clear')

cur.putp(cls)
name = input("Hello, what's your name? ")

cur.putp(bold)
print("Nice to meet you ", name)

input("\nHit enter to exit")
###

I've tried variations on flush both inside and outside
the print() - both before and after.
I've tried writing to stdout instead of print, but nothing is working.
The Hit enter... message is in bold but the Hello... line isn't.

Does anyone know what's going on and how to fix it.

I could, of course, jump into full curses but I wanted to
see if I could use the terminfo stuff directly to retain
use of regular input() and print() functions.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: count consecutive elements

2021-01-14 Thread Bischoop
On 2021-01-13, Bischoop  wrote:

I know what was wrong:

> m = s.index(i)

I forgot that m will return first index of i.

So tried that way but still getting out of index although I that that
I'm making sure not to get out of index.

s = 'aabskaaabadh'

c = 0
t = list(set(s)) # list of characters in s
li=[0,0,0,0,0,0]  # list for counted repeats
print(t)
for x in t:
h = t.index(x)
for index, i in enumerate(s):
maximus = len(s)
if i == x:
c += 1
if index < maximus:
if s[index +1] != x:  # if next element is not x
if c > li[h]:   #update c if bigger than existing
li[h] = c
c = 0
else:
if c > li[h]:
li[h] = c


for i in t:
n = t.index(i)
print(i,li[n])

print(f'{s[li.index(max(li))]} appears {max(li)} consecutive times')


-- 
https://mail.python.org/mailman/listinfo/python-list


Question - problem downloading Python

2021-01-14 Thread christine tiscareno
I installed in my lap-top your latest version of Python (3.9.1), yet when I
go to cmd.exe   to check,  I get that I have Python 22.7.17 ???

Why? What should I do to get the latest version?

  I tried going back to fix problems and it does not fix it, that is how I
got your email.

How can I get the latest Python version (3.9.1), instead of what I'm
getting (22.7.17)?

Thank you for your time.

-- 
Kind regards, Christine Tiscareno
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: conceptual problem

2021-01-14 Thread Alan Gauld via Python-list
On 13/01/2021 15:37, songbird wrote:

>   my momentary conceptual problem is that to me OOP means
> being able to encapsulate data structures and code from
> other parts of the program, 

That's true, but encapsulation simply means that the data
and functions are contained within a single
entity - ie a capsule. It says nothing about whether
you can access them directly or not.

When OOP started the basic concept of having functions
inside the same structure as the data that they operated
on was so radical that encapsulation became a big topic.
But over time it has gotten mixed up with data hiding
and abstraction (also big topics back in the 70/80s)
So the term encapsulation has tended to be used to
cover abstraction and data hiding as well as simple(pure)
encapsulation.

> that is how python is designed.  this is probably a complete
> aside to this whole thread and perhaps even this newsgroup

It is a long running(as in for decades!) sub-thread to
the whole Python language. :-)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list


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

2021-01-14 Thread Peter Pearson
On Wed, 13 Jan 2021 21:46:08 - (UTC), Grant Edwards wrote:
> On 2021-01-13, Peter Pearson  wrote:
[snip]
>> Browsergui is not widely popular (I don't think anybody but me has
>> mentioned it on this newsgroup), but it was written to be simple and
>> Pythonic, and has served me well.  Browsergui just uses your browser as
>> its user interface.  Grab it from
>>
>> https://github.com/speezepearson/browsergui
>
> I've been browsing through to documentation and examples, and I don't
> see any way to do any sort of modern flexible layout (e.g. nesting
> horizontal and vertical flexboxes) where you can control which
> elements grow/shrink when the window size changes.
>
> Is there a way to span columns/rows in a grid or control which columns
> grow/shrink?
>
> Have I missed something?

I doubt you've missed anything important, though I'm not sure because
I haven't done any of the things you mention.  Browsergui is minimalist.
If you've done the "python -m browsergui.examples" and don't see 
something like what you want, it's probably not there.

I like Browsergui for simple tools that require a little more
interaction than straight command-line utilities: exploring the effect
of various value-settings on some curve on a graph, or exploring the
ranges of values in a CSV file, or (most recently) rearranging the
order of image files in a list.

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


why sqrt is not a built-in function?

2021-01-14 Thread Denys Contant
I don't understand why sqrt is not a built-in function. 
Why do we have to first import the function from the math module?
I use it ALL THE TIME!

That felt good. Thank you.







-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why sqrt is not a built-in function?

2021-01-14 Thread jak

Il 14/01/2021 18:44, Denys Contant ha scritto:

I don't understand why sqrt is not a built-in function.
Why do we have to first import the function from the math module?
I use it ALL THE TIME!

That felt good. Thank you.








>>> val=16
>>> exp=2
>>> val ** (1/exp)
4.0
>>>
--
https://mail.python.org/mailman/listinfo/python-list


Re: why sqrt is not a built-in function?

2021-01-14 Thread Skip Montanaro
> I don't understand why sqrt is not a built-in function.
> Why do we have to first import the function from the math module?
> I use it ALL THE TIME!

For one, it's specific to numeric types. You might use it all the
time, but I (for example) almost never need to use it, or to import
the math module for my Python work/play. OTOH, I use stuff from the
sys and csv modules (and lately, pandas) all the time. I import those
modules when necessary. If you don't need them, I suspect you might
grumble that they are useless for you. Requiring explicit module
import gives programmers more control over the content of their module
namespaces if the builtins don't include the kitchen sink.

If you skim the output of

import builtins
dir(builtins)

you should see that the two largest classes of builtin identifiers are
exceptions (ZeroDivisionError, etc) and types (list, set, etc). Other
classes include singleton constants (True, False, None) and general
sequence operations (useful for loop control - reversed, iter,
zip...). math.sqrt doesn't fit into those object classes. The
remainder are a mixture of things, but generally aren't quite as
special purpose as that. Granted, there are a couple which might be
better left out (IMO), like round and pow, but I suspect their
presence might simply be more a matter of them being present since
Python's earliest days and reflect a tendency later to avoid
gratuitous breakage of existing code.

Finally, should have never considered it, I think you might want to
study the output of

import this

Think on the second and last lines in particular.

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why sqrt is not a built-in function?

2021-01-14 Thread Alan Gauld via Python-list
On 14/01/2021 17:44, Denys Contant wrote:
> I don't understand why sqrt is not a built-in function. 
> Why do we have to first import the function from the math module?
> I use it ALL THE TIME!

because pow() is a builtin function and

root = pow(x,0.5)

is the same as

root = math.sqrt(x)

As is

root = x ** 0.5

which is also builtin.

My question is: why do we even have a sqrt() in the
math module given that pow() and ** are already there?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why sqrt is not a built-in function?

2021-01-14 Thread Ethan Furman

On 1/14/21 9:44 AM, Denys Contant wrote:


I don't understand why sqrt is not a built-in function.
Why do we have to first import the function from the math module?
I use it ALL THE TIME!


And thousands, tens of thousands, and maybe hundreds of thousands don't.


That felt good. Thank you.


Any time.  ;-)

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: why sqrt is not a built-in function?

2021-01-14 Thread 2QdxY4RzWzUUiLuE
On 2021-01-14 at 17:54:55 +,
Alan Gauld via Python-list  wrote:

> My question is: why do we even have a sqrt() in the
> math module given that pow() and ** are already there?

Probably because the standard C math library has such a function, and
Python's math module is (or at least was) supposed be a thin wrapper
around that library.

For completeness, C doesn't have a exponentiation operator.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why sqrt is not a built-in function?

2021-01-14 Thread Chris Angelico
On Fri, Jan 15, 2021 at 5:56 AM <2qdxy4rzwzuui...@potatochowder.com> wrote:
>
> On 2021-01-14 at 17:54:55 +,
> Alan Gauld via Python-list  wrote:
>
> > My question is: why do we even have a sqrt() in the
> > math module given that pow() and ** are already there?
>
> Probably because the standard C math library has such a function, and
> Python's math module is (or at least was) supposed be a thin wrapper
> around that library.
>
> For completeness, C doesn't have a exponentiation operator.

Also, the math module works specifically with floats. Sometimes that's
what you want, other times it's not.

>>> pow(-2, 0.5)
(8.659560562354934e-17+1.4142135623730951j)
>>> (-2)**0.5
(8.659560562354934e-17+1.4142135623730951j)
>>> from math import sqrt; sqrt(-2)
Traceback (most recent call last):
  File "", line 1, in 
ValueError: math domain error
>>> from cmath import sqrt; sqrt(-2)
1.4142135623730951j

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why sqrt is not a built-in function?

2021-01-14 Thread Eli the Bearded
In comp.lang.python, Skip Montanaro   wrote:
> Finally, should have never considered it, I think you might want to
> study the output of
> 
> import this
> 
> Think on the second and last lines in particular.

   >>> import this
   The Zen of Python, by Tim Peters

   Beautiful is better than ugly.
   Explicit is better than implicit.
   Simple is better than complex.
   Complex is better than complicated.
   Flat is better than nested.
   Sparse is better than dense.
   Readability counts.
   Special cases aren't special enough to break the rules.
   Although practicality beats purity.
   Errors should never pass silently.
   Unless explicitly silenced.
   In the face of ambiguity, refuse the temptation to guess.
   There should be one-- and preferably only one --obvious way to do it.
   Although that way may not be obvious at first unless you're Dutch.
   Now is better than never.
   Although never is often better than *right* now.
   If the implementation is hard to explain, it's a bad idea.
   If the implementation is easy to explain, it may be a good idea.
   Namespaces are one honking great idea -- let's do more of those!
   >>> 

"There should be one-- and preferably only one --obvious way to do it."

Meanwhile, Alan Gauld pointed out:

  AG> because pow() is a builtin function and
  AG> root = pow(x,0.5)
  AG> is the same as
  AG> root = math.sqrt(x)

Plus the ** operation ("root = x ** 0.5"), that's now three ways.

Elijah
--
python user, not python advocate
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why sqrt is not a built-in function?

2021-01-14 Thread Chris Angelico
On Fri, Jan 15, 2021 at 6:11 AM Eli the Bearded <*@eli.users.panix.com> wrote:
>
> In comp.lang.python, Skip Montanaro   wrote:
> > Finally, should have never considered it, I think you might want to
> > study the output of
> >
> > import this
> >
> > Think on the second and last lines in particular.
>
>>>> import this
>The Zen of Python, by Tim Peters
>
>Beautiful is better than ugly.
>Explicit is better than implicit.
>Simple is better than complex.
>Complex is better than complicated.
>Flat is better than nested.
>Sparse is better than dense.
>Readability counts.
>Special cases aren't special enough to break the rules.
>Although practicality beats purity.
>Errors should never pass silently.
>Unless explicitly silenced.
>In the face of ambiguity, refuse the temptation to guess.
>There should be one-- and preferably only one --obvious way to do it.
>Although that way may not be obvious at first unless you're Dutch.
>Now is better than never.
>Although never is often better than *right* now.
>If the implementation is hard to explain, it's a bad idea.
>If the implementation is easy to explain, it may be a good idea.
>Namespaces are one honking great idea -- let's do more of those!
>>>>
>
> "There should be one-- and preferably only one --obvious way to do it."
>
> Meanwhile, Alan Gauld pointed out:
>
>   AG> because pow() is a builtin function and
>   AG> root = pow(x,0.5)
>   AG> is the same as
>   AG> root = math.sqrt(x)

They're not the same. The math module is the one obvious way to do
things that specifically involve floating point numbers and nothing
else.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why sqrt is not a built-in function?

2021-01-14 Thread Ethan Furman

On 1/14/21 11:06 AM, Eli the Bearded wrote:


"There should be one-- and preferably only one --obvious way to do it."

Meanwhile, Alan Gauld pointed out:

   AG> because pow() is a builtin function and
   AG> root = pow(x,0.5)
   AG> is the same as
   AG> root = math.sqrt(x)

Plus the ** operation ("root = x ** 0.5"), that's now three ways.


Yes, but which of those is obvious?

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: Question - problem downloading Python

2021-01-14 Thread vincent . vandevyvre
On 14/01/21 07:52, Christine Tiscareno wrote:
>I installed in my lap-top your latest version of Python (3.9.1), yet when I
>go to cmd.exe   to check,  I get that I have Python 22.7.17 ???
>
>Why? What should I do to get the latest version?

>  I tried going back to fix problems and it does not fix it, that is how I
>got your email.

>How can I get the latest Python version (3.9.1), instead of what I'm
>getting (22.7.17)?

>Thank you for your time.

Please, copy-paste all the content of your terminal (I presume this is wht you 
name cmd.exe).

Vincent
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exploring terminfo

2021-01-14 Thread Barry Scott



> On 14 Jan 2021, at 16:12, Alan Gauld via Python-list  
> wrote:
> 
> During lockdown I've been digging deeper into the curses module
> and lately into the ti family of functions that reside there.
> 
> I've written a short program that is supposed to
> - *clear the screen*,
> - read some input
> - display the result in a message *highlighted in bold*.
> - get input to end the program

It seems that curses does not allow you to mix raw stdin/stdout with its calls.
(got that idea from a quick web search).

If all you want is simple things like bold and clear I'd just use the
ANSI escape sequences directly.

Are there any terminals that do not understand ANSI escape sequences
these days?

Barry

> 
> The parts marked with ** use terminfo, or they should.
> My problem is that while the clear-screen part works the
> bold bit only appears in the final input(), not in the
> output message.
> 
> Here is the code:
> 
> #
> import curses as cur
> cur.setupterm()
> 
> bold = cur.tigetstr('bold')
> cls = cur.tigetstr('clear')
> 
> cur.putp(cls)
> name = input("Hello, what's your name? ")
> 
> cur.putp(bold)
> print("Nice to meet you ", name)
> 
> input("\nHit enter to exit")
> ###
> 
> I've tried variations on flush both inside and outside
> the print() - both before and after.
> I've tried writing to stdout instead of print, but nothing is working.
> The Hit enter... message is in bold but the Hello... line isn't.
> 
> Does anyone know what's going on and how to fix it.
> 
> I could, of course, jump into full curses but I wanted to
> see if I could use the terminfo stuff directly to retain
> use of regular input() and print() functions.
> 
> -- 
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question - problem downloading Python

2021-01-14 Thread Barry Scott



> On 14 Jan 2021, at 06:52, christine tiscareno  wrote:
> 
> I installed in my lap-top your latest version of Python (3.9.1), yet when I
> go to cmd.exe   to check,  I get that I have Python 22.7.17 ???
> 
> Why? What should I do to get the latest version?
> 
>  I tried going back to fix problems and it does not fix it, that is how I
> got your email.
> 
> How can I get the latest Python version (3.9.1), instead of what I'm
> getting (22.7.17)?


I assume you typed "python".

And I assume that it is because you have python 2.7.17 installed and its on
your PATH.

To run python 3.9.1 do this in cmd.exe

py -3.9

It is also likely that just typing "py" will run python 3.9.1.
Typing "py -2" will run python 2.

Run this to find all the versions of python that you have available:

py -0

Barry

> 
> Thank you for your time.
> 
> -- 
> Kind regards, Christine Tiscareno
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: count consecutive elements

2021-01-14 Thread Wolfram Hinderer via Python-list



Am 13.01.2021 um 22:20 schrieb Bischoop:

I want to  to display a number or an alphabet which appears mostly
consecutive in a given string or numbers or both
Examples
s= ' aabskaaabad'
output: c
# c appears 4 consecutive times
  8bbakebaoa
output: b
#b appears 2 consecutive times



You can let itertools.groupy find the groups.

max((len(tuple(group)), key) for key, group in itertools.groupby(s))
# (4, 'c')
--
https://mail.python.org/mailman/listinfo/python-list


Re: Exploring terminfo

2021-01-14 Thread Eli the Bearded
In comp.lang.python, Barry Scott   wrote:
> Alan Gauld via Python-list  wrote:
>> I've written a short program that is supposed to
>> - *clear the screen*,
>> - read some input
>> - display the result in a message *highlighted in bold*.
>> - get input to end the program
> It seems that curses does not allow you to mix raw stdin/stdout with its 
> calls.

This sounds very plausable. In C, in curses one uses printw() not
printf().

> If all you want is simple things like bold and clear I'd just use the
> ANSI escape sequences directly.
> 
> Are there any terminals that do not understand ANSI escape sequences
> these days?

Probably, I hear tales of people using odd set-ups from time to time.
But that could just be the circles I hang out in.

When I've wanted to do simple things like bold and clear, I've used the
tput(1) tool. You can capture stdout from the tool and use the output
over and over. Typically I've done this in shell scripts:

#!/bin/sh
bold=$(tput smso)   # set mode stand out
nobold=$(tput rmso) # remove mode stand out
clear=$(tput clear) # clear screen
home=$(tput home)   # home, without clear

for word in Ten Nine Eight Seven Six Five Four Three Two One; do
   echo "${clear}${bold}${word}${nobold} ..."
   sleep 1
done
echo "${home}Nothing happens."
exit

Elijah
--
adapting to python left as an excercise for the reader
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exploring terminfo

2021-01-14 Thread Grant Edwards
On 2021-01-14, Barry Scott  wrote:

> It seems that curses does not allow you to mix raw stdin/stdout with
> its calls.  (got that idea from a quick web search).

That is definitely the case. Output in curses is done to an in-memory
virtual terminal screen. Optimized output is then sent (at some point
later) to update the physical terminal with any changes made in the
virtual terminal since the last update.  If you want to use ncurses,
you can't mess with the physical terminal behind its back and expect
anything to work.

> If all you want is simple things like bold and clear I'd just use the
> ANSI escape sequences directly.

Or use a terminfo library:

  https://github.com/DirectXMan12/py-terminfo

It _may_ be possible to use ncurses to get the terminfo strings
required for various functions without actually having ncurses to any
I/O, but I've never tried that...

--
Grant

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exploring terminfo

2021-01-14 Thread Grant Edwards
On 2021-01-14, Eli the Bearded <*@eli.users.panix.com> wrote:

> When I've wanted to do simple things like bold and clear, I've used the
> tput(1) tool. You can capture stdout from the tool and use the output
> over and over. Typically I've done this in shell scripts:
>
> #!/bin/sh
> bold=$(tput smso) # set mode stand out
> nobold=$(tput rmso)   # remove mode stand out
> [...]

I was about to suggest using tput.

https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x405.html
https://linuxcommand.org/lc3_adv_tput.php
https://martin-thoma.com/colorize-your-scripts-output/

>From python you could actually invoke the tput executable every time
you wanted to do something, or you could cache the output strings produced by
tput as demonstrated in the bash script above.

Alternatively, I think you can use the ncurses library to retrieve the control
strings (just don't use any ncurses input/output calls), like this example from
https://stackoverflow.com/questions/6199285/tput-cup-in-python-on-the-commandline:

from curses import *
setupterm()

cols = tigetnum("cols")
lines = tigetnum("lines")
print str(cols) + "x" + str(lines)

place_begin = tparm(tigetstr("cup"), 15, 14)
place_end = tparm(tigetstr("cup"), 50, 0)

print place_begin + "-- some text --" + place_end


-- 
https://mail.python.org/mailman/listinfo/python-list


RE: why sqrt is not a built-in function?

2021-01-14 Thread Avi Gross via Python-list
Ethan, if it is not obvious, then should we add the following functions just
in case?

cube_root()
fourth_root()
nth(root)
two_thirds_root()
e_th_root()
pi_th_root()
x_over_y_root()

And so on.

It is true that square roots are probably more commonly taken than many
others above (I have never taken the pi_th root but you never know) and you
can make a fourth root by taking the square root twice. There is nothing
wrong with creating a convenience function but it needs to stop somewhere.
The purpose of modules or packages and other add-ons is to supplement the
base language that is loaded whether you want it or not. Some have argued to
remove many current things from the base that THEY never use (or compiled
their own such version) to make it smaller and faster.

Given that, you can either import the sqrt function or make your own that
just turns around and uses one of the methods that is built-in. But if you
use all kinds of things regularly, consider importing them all at once by
having your own module with some name that imports all of them and importing
that and waiting as they all load.



-Original Message-
From: Python-list  On
Behalf Of Ethan Furman
Sent: Thursday, January 14, 2021 2:36 PM
To: python-list@python.org
Subject: Re: why sqrt is not a built-in function?

On 1/14/21 11:06 AM, Eli the Bearded wrote:

> "There should be one-- and preferably only one --obvious way to do it."
> 
> Meanwhile, Alan Gauld pointed out:
> 
>AG> because pow() is a builtin function and
>AG> root = pow(x,0.5)
>AG> is the same as
>AG> root = math.sqrt(x)
> 
> Plus the ** operation ("root = x ** 0.5"), that's now three ways.

Yes, but which of those is obvious?

--
~Ethan~
-- 
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Friday Finking: Abstract Base Classes - love or hate

2021-01-14 Thread dn via Python-list
Do you make frequent use of Abstract Base Classes (ABCs), prefer to use
an ordinary super-class for the same purpose, or steer-clear? Are they
more-usually employed when the project includes an extensive design
stage, and the meta-class integral to some hierarchy of entities?


Previous Friday Finkings have arisen from in-house discussions within a
Python dev.team which deserved a wider airing or debate. This contains
(with due apologies) excessive personal reflection and comments
abstracted from posts to this Discussion List.


Many of us have used Python for years but never touched ABCs. Apparently
then, we don't need to be aware of them! Colleagues 'here' have said
"never used it" and/or "never seen the need", and similar.

Often pythonista learn how to define class(es), and then to inherit or
compose further classes. Everything works swimmingly. If it ain't broke,
don't fix it! So, we have no reason to advance our programming
capabilities/knowledge. Indeed an earlier post voiced the suggestion
that we could get on quite happily without knowing about/using ABCs.


Aside: Certainly the earliest iteration of Python meta-classes/ABCs
(related, but confusingly different - am not going there!) 'arrived' at
about the same time as did I - back at Python 1.n - but I've only
ever/started using ABCs, since circa 3.5. Thus, from personal
learning-experience: one can only understand and use abstract-classes
after gaining a thorough understanding and facility with using
(ordinary) class-es. (perhaps?)


Conducting (what some people call) extensive research*, we will be told
that an ABC is: "a way to overload isinstance() and issubclass()". When
would we use those two functions which introspect a class-hierarchy?

isinstance(object, classinfo)
= is the object argument an instance of the classinfo argument

issubclass(class, classinfo)
= is the class argument a subclass of the classinfo argument
(etc)

Luv-a-duck! How does this fit with duck-typing and EAFP? (sorry,
terrible attempt at a joke) Aren't we supposed to *presume* that we our
sub-class/instance is just that, and we should just presume to use its
data and methods (wrapped in a try...except in case 'forgiveness' might
be necessary)?


Perhaps with the increasing number of DataScience folk using Python (?),
we do seem to be finding a reasonable proportion of Python
improvements/updates seemingly heading in the LBYL direction... OK,
let's go-with-the-flow.

There are two 'problems' with the isinstance()/issubclass() approach:
- it's not very duck-y
- when it 'happens'.

So, let's say we want to *execute* a particular method against the
current data-structure. We can only do this if the class (or its
hierarchy) includes said method. Thus:

data.method( arguments... )

However, we are concerned that the instance may not be part of a
hierarchy offering this method. What can we do?

- EAFP: wrap in try...except
- LBYL: check for method by assuring the hierarchy, eg isinstance()

Each incurring the consequential-problem: but what then?


The problem is not 'discovered' until execution-time - worst-case
scenario: it is discovered by some user (who is no-longer our friend).

If we are really going LBYL, surely we want to discover the problem as
early as possible, ie preferably whilst coding+testing?

Using an ABC we can do just that, because the presence/absence of
methods is checked when the sub-class is defined. If it does not
implement all of the required methods, the sub-class will fail. Yes, we
could do that by coding a super-class with methods that contain only:

raise NotImplementedError()

but when would a sub-class's error in not implementing the method then
be 'discovered'?


Personal aside/illustration/confession: I implemented an application
which used "plug-ins" - effectively filters/actions. The first couple of
use-cases were easy - they were integral to the application-design. As
is the way of these things, few months later a request arrived for
another plug-in. Of course, I was very happy with the plug-in which I
coded oh-so-quickly. Trouble is, I *forgot* to implement one of the
required methods, and mis-spelled another. Yes, if I had a scrap of
humility, I should have re-read my original code. Sigh!

Forget the apocryphal "will your future self remember in six months'
time", as I have aged (and most of us do!), I've moved my philosophy to
one of trying to avoid having to remember - firstly in six *weeks'*
time, and more recently: six *days'*!

All was greatly improved by implementing an ABC as a guide, or a
check-list, even, a template - as proven by later requests for yet more
'plug-ins'...

Please remember that 'umble scribe is not an "OOP-native", starting this
career way-back when mainframes were powered by dinosaurs in
tread-mills. I am told this is what other languages refer to as an
"interface". In some ways I visualise the ABC as a "mixin" - perhaps
better-understood when the ABC does include an inheritable method.
(feel free to add/d

Re: why sqrt is not a built-in function?

2021-01-14 Thread Eli the Bearded
In comp.lang.python, Ethan Furman   wrote:
> On 1/14/21 11:06 AM, Eli the Bearded wrote:
>> "There should be one-- and preferably only one --obvious way to do it."
>> Plus the ** operation ("root = x ** 0.5"), that's now three ways.
> Yes, but which of those is obvious?

If it's up to me, the ** one.

Elijah
--
using a syntax with "^" instead of "**" would be okay, too
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why sqrt is not a built-in function?

2021-01-14 Thread Greg Ewing

Aother thing to consider is that math.sqrt is not the only
sqrt function in Python. There is also one in cmath, and
in the wider ecosystem, another one in numpy. Being explicit
about which one you're using is a good thing.

Concerning exponentiation, it can be used to achieve the same
thing as sqrt, but the sqrt function probably uses a more
efficient algorithm.

Also, exponentiation assumes you're okay with getting a
complex result:

>>> (-27)**0.5
(3.181725716174721e-16+5.196152422706632j)

So it's not quite the same thing as math.sqrt().

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: conceptual problem (was: A beginning beginner's question about input, output and . . .

2021-01-14 Thread Greg Ewing

On 14/01/21 11:49 am, Cameron Simpson wrote:

The "pure" OOP approach, where method calls are used as messages to set
or fetch aspects of the object, is usually does with getter and setter
methods like:

 x = o.getX()
 o.setX(9)


People use get and set methods, not because it's somehow morally
wrong to expose attributes directly, but as a workaround for the
lack of a language feature.

In C++ and Java, different calling syntax is required for direct
access and access mediated by methods, so if you start out exposing
something directly and then change your mind, all the code using it
has to be changed. For this reason, people got into the habit of
wrapping everything in get and set methods from the beginning,
"just in case".

Python doesn't have this problem -- you can turn an attribute
into a property at any time, and nothing else needs to change.
So get and set methods are unnecessary and actively discouraged
in Python.

(C#, if I understand correctly, gets this sort of half-right.
You can turn an attribute into a property, and the calling *source*
doesn't change, but it all has to be recompiled -- which kind of
defeats the purpose.)

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list