Re: How to turn a defaultdict into a normal dict.

2020-06-16 Thread Matt Wheeler
On Wed, 10 Jun 2020 at 23:02, Peter Otten <__pete...@web.de> wrote:
> > However later when I actually use it, accessing a key that is not
> > present, should raise KeyError.
> >
> > Is that somehow possible?
>
> It never occured to me to try that, but:
>
> >>> from collections import defaultdict
> >>> d = defaultdict(list)
> >>> d["x"]
> []
> >>> d.default_factory = None
> >>> d["y"]
> Traceback (most recent call last):
>   File "", line 1, in 
> KeyError: 'y'

An alternative approach to this would be to use a regular dict from the start...

d.setdefault("x", []).append("stuff")


-- 
Matt Wheeler
http://funkyh.at
-- 
https://mail.python.org/mailman/listinfo/python-list


Python Curses Programming HowTo -reviewers?

2020-06-16 Thread Alan Gauld via Python-list
While studying the curses module I was struck  by the paucity of
tutorial documentation for the Python version. Fortunately I
know C and used to write curses applications back in the 80s/90s
so I turned to the C tutorials. However, there are quite a lot
of differences between the Python wrapper implementation and
the C library.

I therefore took it on myself to do a translation of the Linux
Documentation Project's "Curses HowTo" by Pradeep Padala into Python.
It is mostly a translation of the code with minimal changes to the
explanatory text (deleting the stuff about how to compile etc plus
some libraries that are not available in Python). I have added a few
short sections that the C version does not cover but I thought were useful.

This is now available as a PDF and I'd be interested in review comments.
Ideally I'm looking for new curses users to review it as a tutorial and
for experienced curses users to check that what I've done is sane!

It is about 75 pages long and covers the core curses module, the panel
module and the textpad widget as well as a brief intro to the dialog module.

If anyone feels keen please reply and I'll forward a copy.
Eventually I'm aiming to put the finished document on my website.

It's amazing what a pandemic can produce...

-- 
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: Python Curses Programming HowTo -reviewers?

2020-06-16 Thread Bob Gailer
> If anyone feels keen please reply and I'll forward a copy.

I'm interested please forward me a copy.

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


Aw: Python Curses Programming HowTo -reviewers?

2020-06-16 Thread Karsten Hilbert
> I therefore took it on myself to do a translation of the Linux
> Documentation Project's "Curses HowTo" by Pradeep Padala into Python.
>
> This is now available as a PDF and I'd be interested in review comments.

I'd be interested in having a look, generally.

Will this be available somewhere ?

Thanks,
Karsten

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


Re: Python Curses Programming HowTo -reviewers?

2020-06-16 Thread Bev In TX


> On Jun 16, 2020, at 11:12 AM, Alan Gauld via Python-list 
>  wrote:
> 
> If anyone feels keen please reply and I'll forward a copy.
> Eventually I'm aiming to put the finished document on my website.

I am interested.
Thanks,
Bev in TX
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Finking: Beyond implementing Unicode

2020-06-16 Thread DL Neil via Python-list

On 13/06/20 4:47 AM, Terry Reedy wrote:

On 6/12/2020 2:03 AM, DL Neil via Python-list wrote:
Unicode has given us access to a wealth of mathematical and other 
symbols. Hardware and soft-/firm-ware flexibility enable us to move 
beyond and develop new 'standards'. Do we have opportunities to make 
computer programming more math-familiar and/or more 
logically-expressive, and thus easier to learn and practice? Could we 
develop Python to take advantage of these opportunities?


...

Could we then also 'update' Python, to accept the wider range of 
symbols instead/in-addition to those currently in-use?


Would such even constitute 'a good idea'?


There was a recent thread on python-ideas discussing this.  It started 
with arrow characters.  There have been others.



Am pleased to hear that it's neither 'new' nor 'way out there'...

Am not subscribed to that list. Went looking for its archives, but 
failed - there's no "ideas" on 
(https://mail.python.org/mailman/listinfo). Please send a pointer...

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Finking: Beyond implementing Unicode

2020-06-16 Thread DL Neil via Python-list

On 13/06/20 5:11 AM, Dennis Lee Bieber wrote:

On Fri, 12 Jun 2020 18:03:55 +1200, DL Neil via Python-list
 declaimed the following:



There is/was a language called "APL" (and yes the acronym means "A
Programming Language", and yes it started the craze, through "B" (and
BCPL), and yes, that brought us "C" - which you are more likely to have
heard about - and yes then there were DataSci folk, presumably more
numerate than literate, who thought the next letter to be "R". So, sad!?).


R was preceded by S http://www.unige.ch/ses/sococ/cl/r/srdiff.e.html
https://cran.r-project.org/doc/FAQ/R-FAQ.html#What-are-the-differences-between-R-and-S_003f
(which, with some scrolling, produces...


Oh dear, my sarcasm about being literately-challenged stands!



APL was hopelessly keyboard-unfriendly, requiring multiple key-presses
or 'over-typing' to produce those arithmetic-operator symbols -


Not with a Tektronix APL terminal, and Xerox CP/V APL 



Specific design-for-purpose - hardware/software integration!



remember, much of this was on mainframe 3270-style terminals, although
later PC-implementations have existed (I can't comment on how 'active'
any community might be). The over-typing was necessary to encode/produce
the APL symbols which don't exist on a standard typewriter keyboard. Ugh!


Many implementations also allowed for a spelled out version for special
characters... $RHO for example, for the greek letter rho.


To which my first reaction was "ugh!". However, I often prefer to have a 
named constant in my Python code - instead of "magic numbers", eg


LINE_WIDTH = 79 # PEP-8 source-code characters per line



I'm glad to have limited my APL-exposure to only reading about it during
a 'Programming Languages' topic! (If you are 'into' functional
programming you may like to explore further)


I used it as a 3-credit independent study in my senior year (1980). All
I was after was a passing grade to complete the credits for graduation. I'm
slightly ashamed to admit that my fanciest program turned that Tektronix
storage display tube terminal into a glorified Etch-a-Sketch (terminal had
X/Y scroll wheels that the APL implementation could read).


Hey, at least you gained access. I think my uni (when I was an u/grad) 
only had one graphic terminal which was kept in the computer room and 
thus only staff had access.


Our introduction to graphics (using FORTRAN) had to be shown using 80x24 
character-based terminals (DEC VT-52s, from memory). Drawing shapes was 
bad-enough, but demonstrations of rotation and translation became the 
very definition of ugly!


I've been somewhat re-living those days, teaching myself how to play 
with Pygame (not a 'work' activity!), and learning how to move entities 
around on the screen (quite similar to HTML5, but sufficiently different 
to give pause). That said, the learning of such basic "building-blocks", 
four-plus decades ago, under-pins working in both/either/each, today!

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Finking: Beyond implementing Unicode

2020-06-16 Thread DL Neil via Python-list
There was a recent thread on python-ideas discussing this.  It started 
with arrow characters.  There have been others.



Am pleased to hear that it's neither 'new' nor 'way out there'...

Am not subscribed to that list. Went looking for its archives, but 
failed - there's no "ideas" on 
(https://mail.python.org/mailman/listinfo). Please send a pointer...



Apologies!
Eventually remembered the second list of lists - the list of Python 
lists which are Python lists but not on the first list of Python 
lists... No wonder I'm dizzy!

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list