Re: Problems with running Python in Npp

2021-09-09 Thread Dennis Lee Bieber
On Wed, 8 Sep 2021 21:54:14 -0400, Ricardo 
declaimed the following:

>   Hey Python and crew I'm having difficulties installing and running Python
>   on my computer. I've seen plenty YouTube videos on how to set it up, but
>   none of them have worked. Any help or guidance will be greatly
>   appreciated.
>

INFORMATION... We want... information.

"None of them have worked" is as useful to us as "I went out to a
football field looking for baseballs" (actually, the latter is more
informative and useful for debugging).

What is "Npp" -- Wikipedia shows a dozen political parties, a weather
satellite, a number of chemical compounds, an Australian electronic payment
system, and a form of rocket propulsion.

What exactly is happening when you attempt to run Python? HOW are you
attempting to run it?

The most common problem is that people keep clicking on the INSTALLER
file -- once the installer has run, just stuff it some place safe should
you need to fix an install. Python is not some massive IDE like Visual
Studio. It is a language interpreter, commonly run from a command shell by
typing "Python some-script-file-name" (though newer Python's include a
so-called "launcher" invoked as just "py").


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/

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


Re: Change the display style of the text on the STACKLINE.

2021-09-09 Thread Roland Mueller via Python-list
Hello

to 9. syysk. 2021 klo 6.53 hongy...@gmail.com (hongyi.z...@gmail.com)
kirjoitti:

> I'm using the following code in my forked project [1]:
>
> percol.view.STACKLINE = 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s Dir:M-d
> Dircmd:M-b'
>
> I would like to change the display style of the text mentioned above, for
> example, to underline some characters in it, as shown below:
>
> _D_ir:M-d
>
>
You can use e.g. str.replace() or re.sub()

>>> percol.view.STACKLINE = percol.view.STACKLINE.replace('D', '_D_')
Result: 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s _D_ir:M-d _D_ircmd:M-b'

>>> import re

Replace D with _D_
>>> percol.view.STACKLINE = re.sub(r'([D])',
r'_\1_',  percol.view.STACKLINE)
Result: 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s _D_ir:M-d _D_ircmd:M-b'

Replace D and M with _D_, _M_
>>> percol.view.STACKLINE = re.sub(r'([DM])', r'_\1_',
percol.view.STACKLINE)
'Fold:F1,F2,F3 Push:C-p Pop:_M_-p Script:_M_-s _D_ir:_M_-d _D_ircmd:_M_-b'

Regards,
Roland



> How to achieve this purpose?
>
> [1]
> https://github.com/hongyi-zhao/ariadne/blob/838179bb4275ac85f5342d9e7d086d6ade3be1de/rc.py#L55
>
> Regards,
> HY
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Friday Finking: Contorted loops

2021-09-09 Thread dn via Python-list
Why does Python not have a repeat-until loop construct?
(or should that be 'modern programming languages'?)

This is a perennial question (one contributor calling it "immemorial"),
but there seem to be reasons why the Python Interpreter would find such
a construct awkward, or is otherwise unable to comply. If so, what does
one need to understand, in order to comprehend the (apparent) omission?

NB I'm not asking 'how to do this with while?'.


TLDR;
- wherein the historical background is explored, a possible 'gap in
knowledge' exposed, alternative implementations discussed, PEP-proposals
critiqued, and related-questions (re-)asked at the end...


If the question itself doesn't appeal to you, perhaps some of the
discussion and web.refs (below) will. Happy Friday. Happy thinking!


The term "Structured Programming" was coined by Edsger W Dijkstra. It
proposed a number of "control structures" (which were largely
unavailable in the programming languages of that time):

- sequence: a series of statements/routines to be executed in sequence
- selection: if...then, if...then...else..., case
- iteration: while, repeat (do...until), for
- recursion: a routine 'calling itself' as a cascade

The 'content' or 'process' of each structure was a block (or in Python
terminology: a "suite") consisting of any/all of the above (thus
"nesting"). Python's indentation practice, today likely descended from
this concept.


Much of the development of the ideas behind Structured Programming that
followed the crystallisation of this list of constructs, were attempts
to mathematically (logically) 'prove' code as "correct".

One of the ideas to (help?) make things more prove-able, was that each
block and construct have only one way in (entry), and one way out
(exit), eg (from Wikipedia) "The conditional statement should have at
least one true condition and each condition should have one exit point
at max ... Often it is recommended that each loop should only have one
entry point (and in the original structural programming, also only one
exit point, and a few languages enforce this)" which as they say, was an
idea later dropped/felt to be somewhat impracticable (but to which theme
I shall return...)

Even in fairly modest Python constructs, we quickly repeal the one-in,
one-out philosophy because try...except operates by providing another
exit-path.


The 'structures' (or "constructs") of Structured Programming were
fore-runners of the Software Patterns and SOLID Principles
commonly-practised today. These ideas still hold the same goal of
trading a degree of abstraction for programming simplicity, possibly
testability, and improved quality.

Today, Python offers almost all of the SP constructs. A form of
case/select is expected in v3.10. The continuing omission is repeat-until.


If you have not met such a code-component before, the idea of a
repeat...until (or do...until) might look like this:

repeat:
code-suite
until condition

Thus, the code-suite will be executed as many times as necessary, until
the condition is met.


In Python, we are used to while-loops, which can be expressed in the
same style as:

while condition:
code-suite

What's the difference?

The answer is that the repeat's code-block MUST be executed at least
once. Whereas a while's code-suite could be totally ignored and not
executed at all!

An analogy is to RegEx and its * and + repetitions:

* means zero, one, or more matches
+ means (at least) one, or more matches


During the last weeks 'here', writing a while-loop was a topic of
conversation. A solution offered to the OP, can be described as:

loop-init-code
while True:#in other words, loop forever
code-suite
if condition:
break

Note three things:

1 the while condition has been bastardised - there is no meaningful
condition, it is designed to loop without thought or control*

2 the control condition within and ending the loop's suite exactly
replaces the until-condition of a repeat-until construct

3 the cyclomatic-complexity of the multi-faceted construct is much
higher than of a 'pure' while-loop (or for-loop)

NB "cyclomatic complexity" is an attempt to measure a program's
complexity based on the number of distinct paths or branches in the code
(please recall earlier comment about 'entry and exit').

* in one of the web.ref discussions, our own @Chris suggests taking
advantage of the 'truthiness' of data, and inserting some documentation:

while 'there is data to process':

Which is a considerable improvement over the bland 'loop forever' or
'loop until I tell you otherwise, according to criteria I won't reveal
until later' (an operating mode every?no teenager would accept,
on-principle! - including this one...)


This form is a regularly recommended as a 'solution' (see first Answer
to SO question). However, it is likely to require some set-up (which is
technically preceding, and therefore outside of the construct, yet the
co

Re: Friday Finking: Contorted loops

2021-09-09 Thread Terry Reedy

On 9/9/2021 5:36 PM, dn via Python-list wrote:

Why does Python not have a repeat-until loop construct?


1. It is not needed.  You covered that.

2. It is rare useful.  For loops are common.  While loops are occasional 
(nearly an order of magnitude less common than for loops.  Fractional 
loop constructs are rare.  ("loop-and-a-half" is a mislabel since at not 
even one loop is guaranteed.)  "do-while" or "repeat-until is even rarer 
since fractional-loop include this as a special case.


3. Adding 'until' as a keyword *now*, rather than in 1.0 or at least 
several versions ago, has cost so far judged to outweigh the small 
benefit.  The PEP parser makes contextual keywords much more easily 
possible but there is a cost to having a context dependent grammar. 
Consider this 3.10.0 snippet:


>>> match, case = 1, 1
>>> match match:
... case case:
... print('matched')
...
...
matched
>>> match case:
... case match:
... print('matched')
...
...
matched

To me, having a word sometimes be a keyword and sometime not make code 
harder to read.  In IDLE, it is a bit easier as the keyword uses of 
'match' and 'case' above are correctly highlighted as keywords, and the 
non-keywords uses not highlighted.  But this is harder that for 
full-time keywords with sane code that works in an re-based highlighter.


Underscore, not used above, but also a new contextual keyword, is even 
harder.  Three of us could not get all the cases we tested correct and I 
suspect doing so without running the PEG parser may be impossible. 
Since highlighting is redone with each keystroke, I suspect doing the 
latter would add a noticeable and unacceptable lag between keystrokes 
and display.




--
Terry Jan Reedy

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


Re: Friday Finking: Contorted loops

2021-09-09 Thread Dennis Lee Bieber
On Fri, 10 Sep 2021 09:36:36 +1200, dn via Python-list
 declaimed the following:

>Why does Python not have a repeat-until loop construct?
>(or should that be 'modern programming languages'?)
>

I would suspect Python's indentation for block structure would be the
major hindrance. After all, all existing block constructs /open/ the block.

if ...:
block

else:
block

elif ...:
block

try:
block

except ...:
block

for ...:
block

while ...:
block

def ...:
block

class ...:
block

so how would

repeat:
block
until ...


fit the language. The alternative would be

repeat until ...:
block

putting the condition at the top, even though it is only tested at the
bottom (after processing  at least once). Granted, that IS the style
used in REXX, where DO/END are generic block boundary marks, with the DO
accepting all the loop constructs (FOR, WHILE, UNTIL) as optional parts.

>This is a perennial question (one contributor calling it "immemorial"),
>but there seem to be reasons why the Python Interpreter would find such
>a construct awkward, or is otherwise unable to comply. If so, what does
>one need to understand, in order to comprehend the (apparent) omission?
>
>NB I'm not asking 'how to do this with while?'.
>
>
>TLDR;
>- wherein the historical background is explored, a possible 'gap in
>knowledge' exposed, alternative implementations discussed, PEP-proposals
>critiqued, and related-questions (re-)asked at the end...
>
>
>If the question itself doesn't appeal to you, perhaps some of the
>discussion and web.refs (below) will. Happy Friday. Happy thinking!
>
>
>The term "Structured Programming" was coined by Edsger W Dijkstra. It
>proposed a number of "control structures" (which were largely
>unavailable in the programming languages of that time):
>
>- sequence: a series of statements/routines to be executed in sequence
>- selection: if...then, if...then...else..., case
>- iteration: while, repeat (do...until), for
>- recursion: a routine 'calling itself' as a cascade
>
>The 'content' or 'process' of each structure was a block (or in Python
>terminology: a "suite") consisting of any/all of the above (thus
>"nesting"). Python's indentation practice, today likely descended from
>this concept.
>
>
>Much of the development of the ideas behind Structured Programming that
>followed the crystallisation of this list of constructs, were attempts
>to mathematically (logically) 'prove' code as "correct".
>
>One of the ideas to (help?) make things more prove-able, was that each
>block and construct have only one way in (entry), and one way out
>(exit), eg (from Wikipedia) "The conditional statement should have at
>least one true condition and each condition should have one exit point
>at max ... Often it is recommended that each loop should only have one
>entry point (and in the original structural programming, also only one
>exit point, and a few languages enforce this)" which as they say, was an
>idea later dropped/felt to be somewhat impracticable (but to which theme
>I shall return...)
>
>Even in fairly modest Python constructs, we quickly repeal the one-in,
>one-out philosophy because try...except operates by providing another
>exit-path.
>
>
>The 'structures' (or "constructs") of Structured Programming were
>fore-runners of the Software Patterns and SOLID Principles
>commonly-practised today. These ideas still hold the same goal of
>trading a degree of abstraction for programming simplicity, possibly
>testability, and improved quality.
>
>Today, Python offers almost all of the SP constructs. A form of
>case/select is expected in v3.10. The continuing omission is repeat-until.
>
>
>If you have not met such a code-component before, the idea of a
>repeat...until (or do...until) might look like this:
>
>repeat:
>code-suite
>until condition
>
>Thus, the code-suite will be executed as many times as necessary, until
>the condition is met.
>
>
>In Python, we are used to while-loops, which can be expressed in the
>same style as:
>
>while condition:
>code-suite
>
>What's the difference?
>
>The answer is that the repeat's code-block MUST be executed at least
>once. Whereas a while's code-suite could be totally ignored and not
>executed at all!
>
>An analogy is to RegEx and its * and + repetitions:
>
>* means zero, one, or more matches
>+ means (at least) one, or more matches
>
>
>During the last weeks 'here', writing a while-loop was a topic of
>conversation. A solution offered to the OP, can be described as:
>
>loop-init-code
>while True:#in other words, loop forever
>code-suite
>if condition:
>break
>
>Note three things:
>
>1 the while condition has been bastar

Re: Friday Finking: Contorted loops

2021-09-09 Thread 2QdxY4RzWzUUiLuE
On 2021-09-09 at 22:33:16 +,
Stefan Ram  wrote:

>   One can think of a language where every loop is exited this
>   way, the only loop construct would be
> 
> loop
> ...
> 
>   and it would /always/ have to be exited via enclosed breaks.

I'm not quite sure what you mean by "one can," but that's how the simple
form of Common Lisp's loop macro works.  Friendlier looping constructs
are built with other macros on top of that one and/or its underlying
mechanism.¹

¹ The underlying mechanism is the moral equivalent of a Python suite
that can also contain tags and unconditional jumps to those tags, aka
"goto"s.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Finking: Contorted loops

2021-09-09 Thread Dennis Lee Bieber
On Thu, 09 Sep 2021 19:07:49 -0400, Dennis Lee Bieber
 declaimed the following:

>On Fri, 10 Sep 2021 09:36:36 +1200, dn via Python-list
> declaimed the following:

Someone, please shoot me now...

>>This is a perennial question (one contributor calling it "immemorial"),
>>but there seem to be reasons why the Python Interpreter would find such
>>a construct awkward, or is otherwise unable to comply. If so, what does
>>one need to understand, in order to comprehend the (apparent) omission?
>>

How did I ever let that whole quote pass through without trimming...


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/

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


Re: Change the display style of the text on the STACKLINE.

2021-09-09 Thread hongy...@gmail.com
On Thursday, September 9, 2021 at 8:57:37 PM UTC+8, Roland Mueller wrote:
> Hello 
> 
> to 9. syysk. 2021 klo 6.53 hongy...@gmail.com (hongy...@gmail.com) 
> kirjoitti:
> > I'm using the following code in my forked project [1]: 
> > 
> > percol.view.STACKLINE = 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s Dir:M-d 
> > Dircmd:M-b' 
> > 
> > I would like to change the display style of the text mentioned above, for 
> > example, to underline some characters in it, as shown below: 
> > 
> > _D_ir:M-d 
> > 
> >
> You can use e.g. str.replace() or re.sub() 
> 
> >>> percol.view.STACKLINE = percol.view.STACKLINE.replace('D', '_D_') 
> Result: 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s _D_ir:M-d _D_ircmd:M-b' 
> 
> >>> import re 
> 
> Replace D with _D_ 
> >>> percol.view.STACKLINE = re.sub(r'([D])', 
> r'_\1_', percol.view.STACKLINE) 
> Result: 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s _D_ir:M-d _D_ircmd:M-b' 
> 
> Replace D and M with _D_, _M_ 
> >>> percol.view.STACKLINE = re.sub(r'([DM])', r'_\1_', 
> percol.view.STACKLINE) 
> 'Fold:F1,F2,F3 Push:C-p Pop:_M_-p Script:_M_-s _D_ir:_M_-d _D_ircmd:_M_-b' 
> 
> Regards, 
> Roland

I tried with the following, but failed to achieve the expected effect:

class Term:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
LIGHTCYAN = '\033[1;36m'
LIGHTGRAY = '\033[0;37m'
YELLOW = '\033[0;33m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'

[...]

percol.view.STACKLINE = percol.view.STACKLINE.replace('D', Term.UNDERLINE + 'D' 
+ Term.ENDC)

The result will look like this:

Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s ?[4mD?[0mir:M-d ?[4mD?[0mircmd:M-b

Regards,
HY

> > How to achieve this purpose? 
> > 
> > [1] 
> > https://github.com/hongyi-zhao/ariadne/blob/838179bb4275ac85f5342d9e7d086d6ade3be1de/rc.py#L55
> >  
> > 
> > Regards, 
> > HY
> > -- 
> > https://mail.python.org/mailman/listinfo/python-list 
> >
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Change the display style of the text on the STACKLINE.

2021-09-09 Thread Roland Mueller via Python-list
pe 10. syysk. 2021 klo 8.53 hongy...@gmail.com (hongyi.z...@gmail.com)
kirjoitti:

> On Thursday, September 9, 2021 at 8:57:37 PM UTC+8, Roland Mueller wrote:
> > Hello
> >
> > to 9. syysk. 2021 klo 6.53 hongy...@gmail.com (hongy...@gmail.com)
> > kirjoitti:
> > > I'm using the following code in my forked project [1]:
> > >
> > > percol.view.STACKLINE = 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s
> Dir:M-d
> > > Dircmd:M-b'
> > >
> > > I would like to change the display style of the text mentioned above,
> for
> > > example, to underline some characters in it, as shown below:
> > >
> > > _D_ir:M-d
> > >
> > >
> > You can use e.g. str.replace() or re.sub()
> >
> > >>> percol.view.STACKLINE = percol.view.STACKLINE.replace('D', '_D_')
> > Result: 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s _D_ir:M-d
> _D_ircmd:M-b'
> >
> > >>> import re
> >
> > Replace D with _D_
> > >>> percol.view.STACKLINE = re.sub(r'([D])',
> > r'_\1_', percol.view.STACKLINE)
> > Result: 'Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s _D_ir:M-d
> _D_ircmd:M-b'
> >
> > Replace D and M with _D_, _M_
> > >>> percol.view.STACKLINE = re.sub(r'([DM])', r'_\1_',
> > percol.view.STACKLINE)
> > 'Fold:F1,F2,F3 Push:C-p Pop:_M_-p Script:_M_-s _D_ir:_M_-d
> _D_ircmd:_M_-b'
> >
> > Regards,
> > Roland
>
> I tried with the following, but failed to achieve the expected effect:
>
> class Term:
> HEADER = '\033[95m'
> OKBLUE = '\033[94m'
> OKGREEN = '\033[92m'
> WARNING = '\033[93m'
> FAIL = '\033[91m'
> ENDC = '\033[0m'
> LIGHTCYAN = '\033[1;36m'
> LIGHTGRAY = '\033[0;37m'
> YELLOW = '\033[0;33m'
> BOLD = '\033[1m'
> UNDERLINE = '\033[4m'
>
> [...]
>
> percol.view.STACKLINE = percol.view.STACKLINE.replace('D', Term.UNDERLINE
> + 'D' + Term.ENDC)
>
> The result will look like this:
>
> Fold:F1,F2,F3 Push:C-p Pop:M-p Script:M-s ?[4mD?[0mir:M-d
> ?[4mD?[0mircmd:M-b
>
> I cannot repeat that. Are you sure that the '?' shown in your output are
not due to your terminal settings that influence how strings printed by
Python or inside used terminal are shown?

Python 3.9.6 (default, Jul 16 2021, 00:00:00)
[GCC 11.1.1 20210531 (Red Hat 11.1.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> UL = '\033[4m'
>>> UL
'\x1b[4m'
>>> ENDC =  '\033[0m'
>>> ENDC
'\x1b[0m'

>>> s = UL + 'D' + ENDC
>>> s
'\x1b[4mD\x1b[0m'

>>> s = 'ABCDE'
>>> s = s.replace('D', UL + 'D' + ENDC)
>>> s
'ABC\x1b[4mD\x1b[0mE'

When I call  print(s) it even shows ABCD and D is underscored. But copying
the output to mail looses the underscore ...
[image: image.png]

BR,
Roland






> Regards,
> HY
>
>




> > > How to achieve this purpose?
> > >
> > > [1]
> > >
> https://github.com/hongyi-zhao/ariadne/blob/838179bb4275ac85f5342d9e7d086d6ade3be1de/rc.py#L55
> > >
> > > Regards,
> > > HY
> > > --
> > > https://mail.python.org/mailman/listinfo/python-list
> > >
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list