Re: Unable to save any files

2020-08-11 Thread Terry Reedy

On 8/11/2020 5:27 AM, Lim Clayton wrote:


I am a relatively new Python User. I recently downloaded Python on my
desktop and I am unable to save anything when I use IDLE. I can run codes
on the shell without any issue but running anything on the window which
requires saving causes nothing to happen. I still get the prompt which says
you need to save before the code can be run but nothing happens when I
press Ok. I am using Windows 10 and I have tried uninstalling and
reinstalling. Any advice?


There are two possible reasons in 3.8.4 and 3.9.0b4 - non-ascii 
characters and files created outside of IDLE.  Non-ascii chars was fixed 
in 3.8.5 and 3.9.0b5.  Files created outside of IDLE work in 3.8.6, due 
in September and 3.9.0rc1, released today.  If you do not need 3rd party 
modules, use the latter.  If you do, create new files within IDLE with 
File=> New.



--
Terry Jan Reedy

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


Re: Unable to save any files

2020-08-11 Thread dn via Python-list

On 11/08/2020 21:27, Lim Clayton wrote:

Hi,

I am a relatively new Python User. I recently downloaded Python on my
desktop and I am unable to save anything when I use IDLE. I can run codes
on the shell without any issue but running anything on the window which
requires saving causes nothing to happen. I still get the prompt which says
you need to save before the code can be run but nothing happens when I
press Ok. I am using Windows 10 and I have tried uninstalling and
reinstalling. Any advice?


When saving the code, which folder is being used?
What does the File Explorer show?
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Strange namespace issue

2020-08-11 Thread Chris Angelico
On Wed, Aug 12, 2020 at 12:03 PM Lele Gaifax  wrote:
> But I see this is somewhat fragile, and wonder about a proper fix, but isn't
> that a reasonable usage of the "locals" argument to exec()?
>

I'm not sure. Passing a locals argument to eval() I have sometimes
done, but never exec(). I've always exec'd code at top level and then
extracted something from globals - it seems the easiest.

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


Re: IDLE: New Feature?

2020-08-11 Thread Terry Reedy

On 8/11/2020 4:26 AM, Steve wrote:

<< Simplest specification:
<< one list for all 3 search boxes;
<< start fresh each session

I do not understand what this means...


A proposed feature needs a specification with sufficient details to code 
and review.  Your proposal "a pull-down history list for Find' is too 
general."  This is typical of proposals, especially for IDLE it seems.


Should there be a list only for Find and not for Find/Replace and Find 
in Files?  Makes no sense.  A separate list for each?  What if you start 
with Find and then realize you want to replace?  Or find in the current 
file and realize that you want to find in multiple files.  I would want 
one list so I could transfer search terms.  (Another solution would be 
to link the boxes so one can transfer directly.)


How long is history kept?  Forever across sessions, or just for one 
session?  The latter is much easier.


--
Terry Jan Reedy

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


Unable to save any files

2020-08-11 Thread Lim Clayton
Hi,

I am a relatively new Python User. I recently downloaded Python on my
desktop and I am unable to save anything when I use IDLE. I can run codes
on the shell without any issue but running anything on the window which
requires saving causes nothing to happen. I still get the prompt which says
you need to save before the code can be run but nothing happens when I
press Ok. I am using Windows 10 and I have tried uninstalling and
reinstalling. Any advice?



Yours Sincerely, Clay
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Strange namespace issue

2020-08-11 Thread Lele Gaifax
Chris Angelico  writes:

> Interesting. You're passing an empty globals and a non-empty locals
> (the second and third arguments to exec, respectively). Is that
> deliberate? By the look of this code, it's meant to be at global scope
> (as if it's the top level code in a module), which is best done by
> passing just a single dict to exec (it'll be both globals and locals).
>
> The reason your first block works but the comprehensions don't is that
> comprehensions act in a nested scope. I think you've hit on a curious
> edge case where empty globals results in strange behaviour.
>
> I tried your code with the empty dict removed and it appears to work,
> but if you had a good reason for having separate dicts, that might
> break.

Thank you Chris,

yes, you are right and indeed passing the external context in the "globals"
argument *AND* omitting the "locals" one I get the expected outcome, and yes,
I'm surprised, the snake still bites sometime, after several dozens of years :)

However, I'm still unclear on *when* it is safe & useful to pass the third
argument to exec(): while in the particular case I was working it does not
make any difference (passing the context in the second "globals" argument,
that is), in at least one other case I am relying on the fact that passing the
third argument the script "stores" there whatever it defines, and the caller
examines that to make some further decision. In other words, something like
this:

script = """\
def function_a():
  return ['a' * repetitions]

def function_b():
  return [['a'] * repetitions]

precomputed = repetitions ** 10

def function_c():
  return precomputed
"""

code = compile(script, 'script', 'exec')
globs = {'repetitions': 3}
locs = {}
exec(code, globs, locs)

for n in locs:
print(f"Oh, you defined {n!r}...")
v = locs[n]
if callable(v):
print("  a callable, returning", v())
else:
print("  a value,", v)

In this case, it would be less practical to determine what the script defined:
by any chance this case is the first I wrote, and here the choice to pass the
third argument was surely "deliberate".

But I see this is somewhat fragile, and wonder about a proper fix, but isn't
that a reasonable usage of the "locals" argument to exec()?

Ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


[RELEASE] Python 3.9.0rc1 is now available

2020-08-11 Thread Łukasz Langa
Python 3.9.0 is *almost* ready. This release, *3.9.0rc1*, is the penultimate 
release preview. You can get it here:

https://www.python.org/downloads/release/python-390rc1/
Entering the release candidate phase, only reviewed code changes which are 
clear bug fixes are allowed between this release candidate and the final 
release. The second candidate and the last planned release preview is currently 
planned for 2020-09-14.

Please keep in mind that this is a preview release and its use is *not* 
recommended for production environments.

Calls to action

Core developers: all eyes on the docs now

 * Are all *your* changes properly documented?
 * Did you notice *other* changes you know of to have insufficient 
documentation?
Community members

We *strongly encourage* maintainers of third-party Python projects to prepare 
their projects for 3.9 compatibility during this phase. As always, report any 
issues to the Python bug tracker .

Installer news

This is the first version of Python to default to the 64-bit installer on 
Windows. The installer now also actively disallows installation on Windows 7. 
Python 3.9 is incompatible with this unsupported version of Windows.

Major new features of the 3.9 series, compared to 3.8

Some of the new major new features and changes in Python 3.9 are:

 * PEP 584 , Union Operators in  
`dict`
 * PEP 585 , Type Hinting Generics 
In Standard Collections
 * PEP 593 , Flexible function and 
variable annotations
 * PEP 602 , Python adopts a stable 
annual release cadence
 * PEP 615 , Support for the IANA 
Time Zone Database in the Standard Library
 * PEP 616 , String methods to 
remove prefixes and suffixes
 * PEP 617 , New PEG parser for 
CPython
 * BPO 38379 , garbage collection does not 
block on resurrected objects;
 * BPO 38692 , os.pidfd_open added that 
allows process management without races and signals;
 * BPO 39926 , Unicode support updated to 
version 13.0.0;
 * BPO 1635741 , when Python is 
initialized multiple times in the same process, it does not leak memory anymore;
 * A number of Python builtins (range, tuple, set, frozenset, list, dict) are 
now sped up using PEP 590  vectorcall;
 * A number of Python modules (_abc, audioop, _bz2, _codecs, _contextvars, 
_crypt, _functools, _json, _locale, operator, resource, time, _weakref) now use 
multiphase initialization as defined by PEP 489 
;
 * A number of standard library modules (audioop, ast, grp, _hashlib, pwd, 
_posixsubprocess, random, select, struct, termios, zlib) are now using the 
stable ABI defined by PEP 384 .
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove "" from starting of a string if provided by the user

2020-08-11 Thread Bill Campbell
On Tue, Aug 11, 2020, Ganesh Pal wrote:
>The possible value of stat['server2'] can be either (a)
>"'/fileno_100.txt'" or (b) '/fileno_100.txt' .

def stripquotes(s):
'''Strip leading single or double quotes to any depth'''
import re
pat = re.compile(r'^([\'"])(.*)(\1)$')
slast = None
while slast != s:
slast = s
s = pat.cub(r'\2', s)
return s
# end stripquotes(s)

Bill
-- 
INTERNET:   b...@celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www2.celestial.com/ 6641 E. Mercer Way
Mobile: (206) 947-5591  PO Box 820
Fax:(206) 232-9186  Mercer Island, WA 98040-0820

Democracy is the theory that the common people know what they
want and deserve to get it good and hard. == H.L. Mencken
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove "" from starting of a string if provided by the user

2020-08-11 Thread Akkana Peck
> > On 2020-08-11 02:20, Ganesh Pal wrote:
> > > How do I check if it the value was  (a) i.e string started and ended
> > > with a quote

Of course the original question was simple and there have been lots
of solutions given.

But I find this comes up periodically, and I'm always leery of using
something like line.replace("'", "").replace('"', '') because it
gets not only quote pairs, but things like "unmatched quotes'
or "it's a contraction".

I was thinking shlex had something like this, but it doesn't (it
can do the opposite, add quotation marks with appropriate escaping).
So I did a little playing around with re.sub.

At first I tried:
line = re.sub('"([^"]*)"', "\\1", line)
line = re.sub("'([^']*)'", "\\1", line)
which works for simple cases, but it can't detect apostrophes
properly, so it didn't work for one of my test strings,
"This one's apostrophe is in a more 'difficult' place."
(it sees the apostrophe as an open single quote, closes it
before difficult, leaving the one after difficult as an apostrophe).

Then I tried to use \b:
line = re.sub('\\b"([^"]*)"\\b', "\\1", line)
line = re.sub("\\b'([^']*)'\\b", "\\1", line)
but punctuation isn't considered part of a word, so it didn't work
right for strings like "some word."

I decided that really, the important thing was that the open quote
can't have an alphanumeric before it, and the end quote can't have
an alphanumeric after it:
line = re.sub('\W"([^"]*)"\W', "\\1", line)
line = re.sub("\W'([^']*)'\W", "\\1", line)
but no, that wasn't quite right since it didn't pick up quotes at
the beginning or end, and it loses some spaces too.

After some fiddling I ended up with
line = re.sub('(^|\W)"([^"]*)"(\W|$)', "\\1\\2\\3", line)
line = re.sub("(^|\W)'([^']*)'(\W|$)", "\\1\\2\\3", line)
which seems to work pretty well.

Any suggested improvements? I find this comes up now and then, so I'm
going to keep this around in my library for times when I need it,
and I'm sure there are cases I didn't think of. (And yes, I know
this is overkill for the original poster's question, but when I
need this I usually want something a little smarter.)

I've appended my test program below.

...Akkana

import re

s = '''Here are some strings.
"This string is quoted with double-quotes."
"Same, except this time the end quote is inside the period".
'This one is quoted with singles.'
"This has one of each and so shouldn't be changed.
"This has 'single quotes' inside double quotes, and it's got an apostrophe too."
"This one's apostrophe is in a more 'difficult' place."
'This has "double quotes" inside single quotes.'
'''

def remquotes(line):
"""Remove pairs of single and/or double quotes from the string passed in.
   Try to preserve things that aren't quotes, like parentheses.
"""
line = re.sub('(^|\W)"([^"]*)"(\W|$)', "\\1\\2\\3", line)
line = re.sub("(^|\W)'([^']*)'(\W|$)", "\\1\\2\\3", line)

return line

if __name__ == '__main__':
for line in s.split('\n'):
print(remquotes(line))

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


Re: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax?

2020-08-11 Thread bryan . gene . olson
Christian Seberino wrote:
> A beginner I think could learn Lisp much faster than Python.

For talented beginners, Lisp rocks much like Python, in that easy assignments 
are easy enough to implement. On the high end, Lisp rocks again: Lisp masters 
are astonishingly productive. In between, beyond pedagogical exercises but 
short of our Turing Award masterwork, Lisp's extreme flexibility has a 
significant down-side in violating the middle third of Python Zen (PEP 20) 
guiding principle: "There should be one -- and preferably only one -- obvious 
way to do it."

Flexibility is good. In a programming language it's great, and Python is super 
flexible. Lisp is beyond. There are many Lisps, the big two of which are Common 
Lisp (CL) and Scheme. Common Lisp has been more industrially important, but 
Scheme out-Lisps CL. As we deal with Python's recent additions, such as "enum", 
the walrus operator, type hints, and async/await, I remain in awe of [call with 
current current 
continuation](https://en.wikipedia.org/wiki/Call-with-current-continuation), 
which in Scheme is abbreviated "call/cc".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove "" from starting of a string if provided by the user

2020-08-11 Thread Joel Goldstick
On Tue, Aug 11, 2020 at 12:26 PM MRAB  wrote:
>
> On 2020-08-11 02:20, Ganesh Pal wrote:
>  > The possible value of stat['server2'] can be either (a)
> "'/fileno_100.txt'" or (b) '/fileno_100.txt' .
>  > How do I check if it the value was  (a) i.e string started and ended
> with a quote , so that I can use ast.literal_eval()
>  > >>> import ast
>  > >>> stat = {}
>  > >>> stat['server2']  = "'/fileno_100.txt'"
>  > >>> stat['server2'] = ast.literal_eval(stat['server2'])
>  > >>> print  stat['server2']
>  > /fileno_100.txt
>  > >>>
>  > >>> if stat['server2'].startswith("\"") and
> stat['server2'].endswith("\""):
>  > ...stat['server2'] = ast.literal_eval(stat['server2'])
>  > ...
>  > >>>
>  > I tried startswith() and endswith(), doesn't seem to work ?. Is there
> a simpler way ?
>  >
>
> I gave 2 possible solutions. Try the first one, which was to use the
> .strip method to remove the quotes.
>
> The reason that startswith and endwith don't seem to work is that you're
> checking for the presence of " (double quote) characters, but, according
> to what you've posted, the strings contain ' (single quote) characters.
>
> [snip]
>
> --
> https://mail.python.org/mailman/listinfo/python-list

I'm assuming that you don't want the string to start with single
quote, doublequote, or the other way around.  If you have that
situation, strip the first and last characters:

>>> s = "'Starts with double quote'"
>>> s1 = '"Starts with single quote"'
>>> if s[:1] == "'" or s[:1] == '"':
...   s_stripped = s[1:-1]
...
>>> s_stripped
'Starts with double quote'
>>> if s1[:1] == "'" or s1[:1] == '"':
...   s_stripped = s1[1:-1]
...
>>> s_stripped
'Starts with single quote'
>>>

This assumes the quotes match at both ends of the string
-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove "" from starting of a string if provided by the user

2020-08-11 Thread MRAB

On 2020-08-11 02:20, Ganesh Pal wrote:
> The possible value of stat['server2'] can be either (a) 
"'/fileno_100.txt'" or (b) '/fileno_100.txt' .
> How do I check if it the value was  (a) i.e string started and ended 
with a quote , so that I can use ast.literal_eval()

> >>> import ast
> >>> stat = {}
> >>> stat['server2']  = "'/fileno_100.txt'"
> >>> stat['server2'] = ast.literal_eval(stat['server2'])
> >>> print  stat['server2']
> /fileno_100.txt
> >>>
> >>> if stat['server2'].startswith("\"") and 
stat['server2'].endswith("\""):

> ...    stat['server2'] = ast.literal_eval(stat['server2'])
> ...
> >>>
> I tried startswith() and endswith(), doesn't seem to work ?. Is there 
a simpler way ?

>

I gave 2 possible solutions. Try the first one, which was to use the 
.strip method to remove the quotes.


The reason that startswith and endwith don't seem to work is that you're 
checking for the presence of " (double quote) characters, but, according 
to what you've posted, the strings contain ' (single quote) characters.


[snip]

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


RE: IDLE: New Feature?

2020-08-11 Thread Steve
<< Simplest specification:
<< one list for all 3 search boxes;
<< start fresh each session

I do not understand what this means...



Footnote:
The only time "incorrectly" is spelled incorrectly 
is when it is spelled "incorrectly".

-Original Message-
From: Python-list  On
Behalf Of Terry Reedy
Sent: Sunday, August 9, 2020 9:51 PM
To: python-list@python.org
Subject: Re: IDLE: New Feature?

On 8/9/2020 7:39 PM, Steve wrote:
> Where would the conversation have to happen to get the forces-that-be 
> to install a pull-down/history menu for the Find option in IDLE?  To 
> have to retype the search option over and over when I am toggling 
> between two or more searches gets tiresome.  I would rather spend my 
> brain cells and bandwidth thinking about coding.
The IDLE-dev mail list
https://mail.python.org/mailman/listinfo/idle-dev
may or may not be active at any time.

Simplest specification:
one list for all 3 search boxes;
start fresh each session

If search boxes were non-modal, it might work to have two open for same
editor (not sure).

> Footnote:
> There's 99 bugs in the code, in the code.
> 99 bugs in the code.
> Take one down and patch it all around.
> Now there's 117 bugs in the code.

Argh!  I sometimes find a bug fixing a bug, but more often think of multiple
possible improvement when implementing one.

--
Terry Jan Reedy

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

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