NZPUG: Smart Iterator Challenge

2022-09-22 Thread dn
A week-by-week Challenge series.
A new venture by the Auckland Branch of the New Zealand Python Users'
Group (AuckPUG)

Challenge-week 1: Implementing a monolithic solution, starts today!

All welcome!
- will suit Python-Apprentices ready to move-on from 'the basics' and
Python-Journeymen
- will welcome participation and coaching-contributions from
Python-Masters, with a special Challenge to be issued at that level

Kiwi accent optional (most people are no-good at it anyway).

With special thanks to our own Leam Hall, for feedback and advice
- that said, all errors and omissions are mine.


To avoid OT traffic on-list, please find all details, and file any
follow-up questions through the Meetup-site:
https://www.meetup.com/nzpug-auckland/ (or email myself directly).


Are you up for a challenge?
Regards =dn (for Pete and DJ)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get the current set LOG_MASK in Python's syslog module?

2022-09-22 Thread Chris Angelico
On Thu, 22 Sept 2022 at 23:46, Richard Moseley
 wrote:
>
> According to documentation syslog.setlogmask returns the current mask so
> save the value to reset later on.
>
> Oldval = syslog.setlogmask(newmask)
>
> This sets oldval to original mask.

This on its own suggests an odd technique that should work but won't be great:

oldval = syslog.setlogmask(1234)
syslog.setlogmask(oldval)

But the Python function just passes the value straight to the
underlying system call, and thus treats zero specially:

"""
The setlogmask() function sets this logmask for the calling
process, and returns the previous mask.  If the mask argument is
0, the current logmask is not modified.
"""

So you should be able to do:

current_mask = syslog.setlogmask(0)

The Python docs do say to refer to the man pages, but IMO it would be
worth mentioning this feature specifically in the docs.

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


Re: How to get the current set LOG_MASK in Python's syslog module?

2022-09-22 Thread Dennis Lee Bieber
On Thu, 22 Sep 2022 13:28:57 +, c.bu...@posteo.jp declaimed the
following:


>I would like to get the current `LOG_MASK`, which is kind of a logging 
>level. According to the docu it seems that `syslog` doesn't have a 
>mechanism for that.
>

There is a function .LOG_MASK() but it seems to just return 2^arg

>>> import syslog
>>> syslog.LOG_MASK(1)
2
>>> syslog.LOG_MASK(2)
4
>>> syslog.LOG_MASK(3)
8
>>> syslog.LOG_MASK(4)
16
>>> syslog.LOG_MASK(0)
1
>>> syslog.LOG_MASK(256)
1
>>> syslog.LOG_MASK(16)
65536
>>> syslog.__doc__
>>> syslog.LOG_MASK(17)
131072
>>> syslog.LOG_MASK(32)
1
>>> syslog.LOG_MASK(24)
16777216
>>>

That is in the Windows Linux (Debian) subsystem.


>Does someone has an idea?
>
>The docu also tells me that `syslog` does let pass all messages by 
>default.
>My point is I do manipulate via `syslog.setlogmask()` the current log 
>leve. At the end I would like to set it back to its previous value.
>
>Kind


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3.6 tkinter bug?

2022-09-22 Thread Peter Smith
On Wednesday, February 1, 2017 at 11:55:35 AM UTC, Terry Reedy wrote:
> On 2/1/2017 1:37 AM, Christian Gollwitzer wrote: 
> > Am 01.02.17 um 00:02 schrieb MRAB: 
> >> On 2017-01-31 22:34, Christian Gollwitzer wrote: 
>  .!frame.!checkbutton 
>  .!frame.!checkbutton2 
>  .!frame2.!checkbutton 
>  .!frame2.!checkbutton2 
> >>> 
> >>> 
> >> Perhaps someone who knows Tcl and tk can tell me, but I notice that in 
> >> the first example, the second part of the widget names are unique, 
> >> whereas in the second example, the second part of the widget names are 
> >> the reused (both "!checkbutton" and "!checkbutton2" occur twice). 
> > 
> > It is indeed the reason, but it has some strange legacy cause: the 
> > default name for the checkbutton-linked variable is the name of the 
> > button inside the parent. Therefore creating a checkbutton has the side 
> > effect of creating a variable with the button's name. 
> > 
> > In this case, the first buttons in the frames are linked to a variable 
> > called "!checkbutton" and the other two are linked to "!checkbutton2". 
> > (a variable name in Tcl can be anything apart from the empty string). 
> > This can also be demonstrated by this Tcl script: 
> > 
> > package require Tk 
> > 
> > pack [frame .f1] 
> > pack [frame .f2] 
> > 
> > pack [checkbutton .f1.c1 -text "A" ] 
> > pack [checkbutton .f1.c2 -text "B" ] 
> > 
> > pack [checkbutton .f2.c1 -text "C" ] 
> > pack [checkbutton .f2.c2 -text "D" ] 
> > 
> > which is equivalent to the Python code above. 
> > 
> > Note that this surprising behaviour was corrected for the (modern) ttk 
> > widgets, so if "checkbutton" is replaced by "ttk::checkbutton", they are 
> > not any longer linked. In Python, that would be 
> > 
> > from tkinter import ttk 
> > ... 
> > w = ttk.Checkbutton() 
> > 
> > (Personally, I'm not using the legacy widgets any longer)
> Christian, could you repeat any relevant parts of your comments on the 
> tracker, especially any ideas on how we might fix tkinter? 
> https://bugs.python.org/issue29402
> >> Do the names need to be: 
> >> 
> >> .!frame.!checkbutton 
> >> .!frame.!checkbutton2 
> >> .!frame2.!checkbutton3 
> >> .!frame2.!checkbutton4
> Serhiy considered that but, not knowing that this would cause a 
> regression, we both liked numbering within parent better. 
> 
> There is a similar issue with radiobuttons on ttk.OptionMenus that 
> existed *before* the 3.6 name changes. 
> https://bugs.python.org/issue25684 
> So there seems to be a systematic issue with tk or how we are (mis)using it.
> > Good question. Maybe there should be unique variable names? I.e., if the 
> > script is changed into package require Tk 
> > 
> > pack [frame .f1] 
> > pack [frame .f2] 
> > 
> > pack [checkbutton .f1.c1 -text "A" -variable v1] 
> > pack [checkbutton .f1.c2 -text "B" -variable v2] 
> > 
> > pack [checkbutton .f2.c1 -text "C" -variable v3] 
> > pack [checkbutton .f2.c2 -text "D" -variable v4] 
> > 
> > then they are also not linked.
> -- 
> Terry Jan Reedy

It looks as if the issue is indeed that the expression to the right of 
CheckButton(... variable= must be an expression.

This works for me
   global checkbix, checkbuttons
   checkbix += 1
   b = tk.Checkbutton(frame, text=text, variable=checkbuttons[checkbix], ...)

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


Re: Problem when scraping the 100 Movie titles.

2022-09-22 Thread Fabian Joseph
#Try using, it's save in json format of the website: 
import json
import requests
from bs4 import BeautifulSoup


url = "https://www.empireonline.com/movies/features/best-movies-2/;

soup = BeautifulSoup(requests.get(url).content, "html.parser")
data = json.loads(soup.select_one("#__NEXT_DATA__").contents[0])

# uncomment this to print all data:
#print(json.dumps(data, indent=4))


def find_articles(data):
if isinstance(data, dict):
for k, v in data.items():
if k.startswith("ImageMeta:"):
yield v['image']['name']
else:
yield from find_articles(v)
elif isinstance(data, list):
for i in data:
yield from find_articles(i)


for a in find_articles(data):
print(a)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python3.6 tkinter bug?

2022-09-22 Thread Peter Smith
On Wednesday, February 1, 2017 at 11:55:35 AM UTC, Terry Reedy wrote:
> On 2/1/2017 1:37 AM, Christian Gollwitzer wrote: 
> > Am 01.02.17 um 00:02 schrieb MRAB: 
> >> On 2017-01-31 22:34, Christian Gollwitzer wrote: 
>  .!frame.!checkbutton 
>  .!frame.!checkbutton2 
>  .!frame2.!checkbutton 
>  .!frame2.!checkbutton2 
> >>> 
> >>> 
> >> Perhaps someone who knows Tcl and tk can tell me, but I notice that in 
> >> the first example, the second part of the widget names are unique, 
> >> whereas in the second example, the second part of the widget names are 
> >> the reused (both "!checkbutton" and "!checkbutton2" occur twice). 
> > 
> > It is indeed the reason, but it has some strange legacy cause: the 
> > default name for the checkbutton-linked variable is the name of the 
> > button inside the parent. Therefore creating a checkbutton has the side 
> > effect of creating a variable with the button's name. 
> > 
> > In this case, the first buttons in the frames are linked to a variable 
> > called "!checkbutton" and the other two are linked to "!checkbutton2". 
> > (a variable name in Tcl can be anything apart from the empty string). 
> > This can also be demonstrated by this Tcl script: 
> > 
> > package require Tk 
> > 
> > pack [frame .f1] 
> > pack [frame .f2] 
> > 
> > pack [checkbutton .f1.c1 -text "A" ] 
> > pack [checkbutton .f1.c2 -text "B" ] 
> > 
> > pack [checkbutton .f2.c1 -text "C" ] 
> > pack [checkbutton .f2.c2 -text "D" ] 
> > 
> > which is equivalent to the Python code above. 
> > 
> > Note that this surprising behaviour was corrected for the (modern) ttk 
> > widgets, so if "checkbutton" is replaced by "ttk::checkbutton", they are 
> > not any longer linked. In Python, that would be 
> > 
> > from tkinter import ttk 
> > ... 
> > w = ttk.Checkbutton() 
> > 
> > (Personally, I'm not using the legacy widgets any longer)
> Christian, could you repeat any relevant parts of your comments on the 
> tracker, especially any ideas on how we might fix tkinter? 
> https://bugs.python.org/issue29402
> >> Do the names need to be: 
> >> 
> >> .!frame.!checkbutton 
> >> .!frame.!checkbutton2 
> >> .!frame2.!checkbutton3 
> >> .!frame2.!checkbutton4
> Serhiy considered that but, not knowing that this would cause a 
> regression, we both liked numbering within parent better. 
> 
> There is a similar issue with radiobuttons on ttk.OptionMenus that 
> existed *before* the 3.6 name changes. 
> https://bugs.python.org/issue25684 
> So there seems to be a systematic issue with tk or how we are (mis)using it.
> > Good question. Maybe there should be unique variable names? I.e., if the 
> > script is changed into package require Tk 
> > 
> > pack [frame .f1] 
> > pack [frame .f2] 
> > 
> > pack [checkbutton .f1.c1 -text "A" -variable v1] 
> > pack [checkbutton .f1.c2 -text "B" -variable v2] 
> > 
> > pack [checkbutton .f2.c1 -text "C" -variable v3] 
> > pack [checkbutton .f2.c2 -text "D" -variable v4] 
> > 
> > then they are also not linked.
> -- 
> Terry Jan Reedy
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get the current set LOG_MASK in Python's syslog module?

2022-09-22 Thread Richard Moseley
According to documentation syslog.setlogmask returns the current mask so
save the value to reset later on.

Oldval = syslog.setlogmask(newmask)

This sets oldval to original mask.

On Thu, 22 Sep 2022, 14:32 ,  wrote:

> X-Post: https://stackoverflow.com/q/73814924/4865723
>
> Hello,
>
> I'm aware that there is a `logging` package that is more _modern_ then
> [`syslog`](https://docs.python.org/3/library/syslog.html). But I have
> old code here to deal with that does use `syslog`. So that question is
> specific to `syslog` and not to `logging`.
>
> I would like to get the current `LOG_MASK`, which is kind of a logging
> level. According to the docu it seems that `syslog` doesn't have a
> mechanism for that.
>
> Does someone has an idea?
>
> The docu also tells me that `syslog` does let pass all messages by
> default.
> My point is I do manipulate via `syslog.setlogmask()` the current log
> leve. At the end I would like to set it back to its previous value.
>
> Kind
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


How to get the current set LOG_MASK in Python's syslog module?

2022-09-22 Thread c . buhtz

X-Post: https://stackoverflow.com/q/73814924/4865723

Hello,

I'm aware that there is a `logging` package that is more _modern_ then 
[`syslog`](https://docs.python.org/3/library/syslog.html). But I have 
old code here to deal with that does use `syslog`. So that question is 
specific to `syslog` and not to `logging`.


I would like to get the current `LOG_MASK`, which is kind of a logging 
level. According to the docu it seems that `syslog` doesn't have a 
mechanism for that.


Does someone has an idea?

The docu also tells me that `syslog` does let pass all messages by 
default.
My point is I do manipulate via `syslog.setlogmask()` the current log 
leve. At the end I would like to set it back to its previous value.


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