Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-19 Thread Chris Angelico
On Mon, Sep 20, 2021 at 3:19 AM Mostowski Collapse  wrote:
>
> I am refering to:
>
> Greg Ewing schrieb:
>  > where [w] is a weak reference object. Then you could periodically
>  > scan the trail looking for dead weakref objects and remove the
>  > corresponding [*] node from the list.
>  >
>  > You can also attach callbacks to weakref objects that are triggered
>  > when the referenced object dies. You might be able to make use of
>  > that to remove items from the trail instead of the periodic scanning.
>
> Question to Chris Angelico: If I stay with my
> sweep_trail(), which is the periodically scanning,
> I can use a single linked list.
>
> On the other hand if I would use the trigger
> from Python, I possibly would need a double linked
> list, to remove an element.
>
> Chris Angelico, is there a third option, that I have
> overlooked? Single linked list uses less space
> than double linked list, this why I go with scan.
>

I don't know. I don't understand your code well enough to offer advice
like that, because *your code is too complicated* and not nearly clear
enough.

But however it is that you're doing things, the best way is almost
always to directly refer to objects. Don't fiddle around with creating
your own concept of a doubly-linked list and a set of objects; just
refer directly to the objects. Let Python be Python, don't try to
build your own language on top of it.

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


Re: The code version of python -i

2021-09-19 Thread Abdur-Rahmaan Janhangeer
Oh thanks a lot, i was way from list this week

Just a note: it's pretty amazing to have at Chris Angelico at your local PUG

Else,

Well, let's say you have a lib that you need to provide users with a shell
for them to try
out functions, no need to translate functions to  cli args. Like Django
provides a shell
for users to use. The aim of injection is to allow code usage without
imports.

The presentation write-up is pretty new to me as I never approached clean
code
presentations. My presentations have always been hard text on screen
.

As all coders my natural instinct is to ... code a prez tool from scratch!

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius


On Fri, Sep 17, 2021 at 5:04 AM dn via Python-list 
wrote:

> Abdur-Rahmaan,
> Apologies for delay: several last-minute tasks were landed on me, so I
> haven't been able to 'read the list' since last week.
>
>
> > If i have a file name flower.py and i add x = 1 in it.
> > When i run python -i flower.py i get a shell
> 
> >
> > If type x i get 1
>  x
> > 1
> >
> > The values are auto injected.
> >
> > How do i start a shell by code with values already injected? Thanks
>
>
> What do you want to achieve with this?
>
>
> At this week's local PUG meeting, I was 'the warm-up act' for (our own)
> @Chris Angelico giving a talk about 'the walrus operator', his part in
> that PEP, and how anyone-and-everyone can contribute to the Python
> eco-system.
>
> My contribution was to start at the Python-Apprentice level, talking
> about different types of 'operators', and preparing the stage?beach for
> the more advanced 'walrus'. It culminated in a live-coding demo of
> Conditional expressions/the "ternary operator".
>
> Live-coding demos are always better (for the audience) than passively
> watching a progression of slides! However, that territory is labelled
> 'here be dragons', for presenters! (continuing the tradition of slide
> projectors which don't accept my cartridge/carousel, white boards
> lacking pens with ink, over-head projectors with blown lamps (and a used
> spare), RGB projectors which only/don't accept VGA cables, ...)
>
> Further: we've all suffered YouTube wannabes telling us how easy it is
> to do 'something', typing and mis-typing and re-typing, and generally
> wasting our time... (have they not heard of video-editing?) Those of us
> who present 'live' (unlike my video-lectures), can't rely upon a later
> 'cosmetic' stage to apply lip-stick on any 'pigs' in our typing!
>
> Rather than using a "script" document (as-in 'speaker's notes') to
> prompt me with what to type next, the remote presentation tool
> (BigBlueButton web-conferencing) allows the 'projection' of a (desktop)
> terminal window - whilst hiding my text-editor. Thus, at the appropriate
> moment, I was copy-pasting from my 'script' in xed, into the terminal's
> Python REPL. Worked very well - it appears as if I'm a very fast typist!
> Of course, sometimes I was copying one line of code at a time, and at
> others, multiple lines - thus (*still*) giving opportunity to 'fluff my
> lines'. Hah!
>
> For live-demos, I like to use pedagogical (teaching) 'patterns' of a
> structured narrative (as one would with a lecture) but trying to
> encourage involvement (if not "active learning"), using a "worked
> example" (learning through demonstration), and "discovery" (which
> because it is effectively a 'presentation', really means 'gradual
> revelation').
>
> (apologies for any non-obvious, non-Python, jargon - cognitive
> psychology (learning how we learn) is my research field)
>
> Thus, the demo proceeds on a step-by-step basis. At each step the
> process is:
> 1 present a problem/ask a question
> 2 ensure understanding/invite comments/accept suggestions
> 3 present code snippet*
> and (presumably) execute same to produce an 'answer'
> 4 comment/discuss/critique
>
> - which, unless 'the end', should lead us back to nr1 for the 'next
> step'...
>
> * in other scenarios, this might involve use of code suggested by the
> audience!
>
> Before reading this thread, I had been thinking that Jupyter might
> empower the combination of Python, 'steps', and 'live-coding'. However,
> a notebook will likely display future steps on-screen, before the
> current one has been completed (which defeats 'gradual revelation' -
> somewhat like jumping to 'the last page to find-out who dunnit') -
> unlike (say) presentation slides where no-one can see 'what comes
> next'/jump ahead, before the earlier 'lesson' has been learned.
>
> NB I'm not seeking 'information hiding' or encapsulation by its Java
> definition; but do want people to consider (only) one sub-problem at a
> time, and thus building-up to the whole solution! If one first
> understands the problem(s) and then contributes to generating a
> solution, you will learn far more effectively than i

Re: query

2021-09-19 Thread MRAB

On 2021-09-19 13:42, Shashwat Pandey wrote:

-- Forwarded message -
From: 
Date: Sun, Sep 19, 2021, 13:20
Subject: query
To: 


Hello!  I see you want to post a message to the Python List.  We would
be happy to help, but you must subscribe first:

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

After you have subscribed, please send your message to
python-list@python.org again.  Please do not include images as this is
a text-only forum -- instead, copy/paste or transcribe the information
from the image that you want us to know.

Alternatively, this list is mirrored both ways with the
comp.lang.python newsgroup (news:comp.lang.python).

Some people find it easier to follow this and other lists via gmane
(http://news.gmane.org/gmane.comp.python.general), a service which
offers a newsgroup interface to many online mailing lists.

*NB all posts to the mailing list are publicly archived at:*

   https://mail.python.org/pipermail/python-list





-- Forwarded message --
From: Shashwat Pandey 
To: python-list@python.org
Cc:
Bcc:
Date: Sun, 19 Sep 2021 13:19:31 +0530
Subject: query
Hello,
One thing I want to ask...

How to Fix Installation Error of PyAudio in VS Code ( Windows 32 Bit ) ??

Please Answer Me
It's very essential to complete my concept digitalization system project.

the error is given below please solve this problem


PS C:\Users\PRIYA> pip install pyaudio
Collecting pyaudio
   Using cached PyAudio-0.2.11.tar.gz (37 kB)
Using legacy 'setup.py install' for pyaudio, since package 'wheel' is not
installed.
Installing collected packages: pyaudio
 Running setup.py install for pyaudio ... error
 ERROR: Command errored out with exit status 1:
  command:
'C:\Users\PRIYA\AppData\Local\Programs\Python\Python39-32\python.exe' -u -c
'import io, os, sys, setuptools, tokenize; sys.argv[0] =
'"'"'C:\\Users\\PRIYA\\AppData\\Local\\Temp\\pip-install-v8hphebk\\pyaudio_4240cdb9492c47abb6d002cdb32aa86c\\setup.py'"'"';
__file__='"'"'C:\\Users\\PRIYA\\AppData\\Local\\Temp\\pip-install-v8hphebk\\pyaudio_4240cdb9492c47abb6d002cdb32aa86c\\setup.py'"'"';f
= getattr(tokenize, '"'"'open'"'"', open)(__file__) if
os.path.exists(__file__) else io.StringIO('"'"'from setuptools import
setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"',
'"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))'
install --record
'C:\Users\PRIYA\AppData\Local\Temp\pip-record-bdr6wfd9\install-record.txt'
--single-version-externally-managed --compile --install-headers
'C:\Users\PRIYA\AppData\Local\Programs\Python\Python39-32\Include\pyaudio'
  cwd:
C:\Users\PRIYA\AppData\Local\Temp\pip-install-v8hphebk\pyaudio_4240cdb9492c47abb6d002cdb32aa86c\
 Complete output (9 lines):
 running install
 running build
 running build_py
 creating build
 creating build\lib.win32-3.9
 copying src\pyaudio.py -> build\lib.win32-3.9
 running build_ext
 building '_portaudio' extension
 error: Microsoft Visual C++ 14.0 or greater is required. Get it with
"Microsoft C++ Build Tools":
https://visualstudio.microsoft.com/visual-cpp-build-tools/
 
ERROR: Command errored out with exit status 1:
'C:\Users\PRIYA\AppData\Local\Programs\Python\Python39-32\python.exe' -u -c
'import io, os, sys, setuptools, tokenize; sys.argv[0] =
'"'"'C:\\Users\\PRIYA\\AppData\\Local\\Temp\\pip-install-v8hphebk\\pyaudio_4240cdb9492c47abb6d002cdb32aa86c\\setup.py'"'"';
__file__='"'"'C:\\Users\\PRIYA\\AppData\\Local\\Temp\\pip-install-v8hphebk\\pyaudio_4240cdb9492c47abb6d002cdb32aa86c\\setup.py'"'"';f
= getattr(tokenize, '"'"'open'"'"', open)(__file__) if
os.path.exists(__file__) else io.StringIO('"'"'from setuptools import
setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"',
'"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))'
install --record
'C:\Users\PRIYA\AppData\Local\Temp\pip-record-bdr6wfd9\install-record.txt'
--single-version-externally-managed --compile --install-headers
'C:\Users\PRIYA\AppData\Local\Programs\Python\Python39-32\Include\pyaudio'
Check the logs for full command output.
WARNING: You are using pip version 21.2.3; however, version 21.2.4 is
available.
You should consider upgrading via the
'C:\Users\PRIYA\AppData\Local\Programs\Python\Python39-32\python.exe -m pip
install --upgrade pip' command.


By default, pip looks for packages on PyPI.

Unfortunately, it looks like PyAudio is not available on PyPI for that 
version of Python.


Fortunately, it _is_ available from Christoph Gohlke's site:

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio

The one you want is:

PyAudio‑0.2.11‑cp39‑cp39‑win32.whl
--
https://mail.python.org/mailman/listinfo/python-list


Re: query

2021-09-19 Thread Mats Wichmann

On 9/19/21 06:42, Shashwat Pandey wrote:


How to Fix Installation Error of PyAudio in VS Code ( Windows 32 Bit ) ??

Please Answer Me
It's very essential to complete my concept digitalization system project.


This comes up somewhat often - pyaudio has not released  new binary 
installer packages for some time.  When the system you install on 
doesn't find a matching binary package, it tries to build it from the 
from source. This doesn't work if you don't have a compiler:



 ERROR: Command errored out with exit status 1:
  command:
'C:\Users\PRIYA\AppData\Local\Programs\Python\Python39-32\python.exe' -u -c
'import io, os, sys, setuptools, tokenize; sys.argv[0] =
'"'"'C:\\Users\\PRIYA\\AppData\\Local\\Temp\\pip-install-v8hphebk\\pyaudio_4240cdb9492c47abb6d002cdb32aa86c\\setup.py'"'"';
__file__='"'"'C:\\Users\\PRIYA\\AppData\\Local\\Temp\\pip-install-v8hphebk\\pyaudio_4240cdb9492c47abb6d002cdb32aa86c\\setup.py'"'"';f
= getattr(tokenize, '"'"'open'"'"', open)(__file__) if
os.path.exists(__file__) else io.StringIO('"'"'from setuptools import
setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"',
'"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))'
install --record
'C:\Users\PRIYA\AppData\Local\Temp\pip-record-bdr6wfd9\install-record.txt'
--single-version-externally-managed --compile --install-headers
'C:\Users\PRIYA\AppData\Local\Programs\Python\Python39-32\Include\pyaudio'
  cwd:
C:\Users\PRIYA\AppData\Local\Temp\pip-install-v8hphebk\pyaudio_4240cdb9492c47abb6d002cdb32aa86c\
 Complete output (9 lines):
 running install
 running build
 running build_py
 creating build
 creating build\lib.win32-3.9
 copying src\pyaudio.py -> build\lib.win32-3.9
 running build_ext
 building '_portaudio' extension
 error: Microsoft Visual C++ 14.0 or greater is required. Get it with
"Microsoft C++ Build Tools":


quite honestly, even if you do install msvc on your Windows system, it 
will probably still fail to build as there are usually some addditional 
setup steps.


This kind of thing is fairly easy to prospect for - got to 
https://pypi.org, search for your package, and when found, click on 
Download Files and look at what's available.  In the case of the 
"official" pyaudio, there haven't been versions since Python 3.6.


In this case there's an alternate build you can download, if you look here:

https://pypi.org/project/pyaudio-wheels/

(in other words, instead of installing "pyaudio" try installing 
"pyaudio-wheels"). Hopefully that will work out for you.



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


Re: on writing a while loop for rolling two dice

2021-09-19 Thread Hope Rouselle
dn  writes:

[...]

> Further, if you look at the OP's original solution, it only publishes
> the last pair, ie the match, without mention of the list of non-matches.
> Was it perhaps only a means of testing the solution?

It was a means of showing the student that indeed they obtained a match.
If the exercise asked for returning a single die or no die at all, they
would make mistakes and there'd be no sign of them being wrong.  For
instance, one trouble a lot of them went through was to start counting
from zero and so their number of rolls was off by one.  (I didn't see
that coming!)  The reason they fall for this is that they also test
little --- for some it never occurred a match on the first roll, so they
never saw the zero counter coming out.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to support annotations for a custom type in a C extension?

2021-09-19 Thread Serhiy Storchaka
19.09.21 05:59, MRAB пише:
> On 2021-09-18 16:09, Serhiy Storchaka wrote:
>> "(PyCFunction)" is redundant, Py_GenericAlias already has the right
>> type. Overuse of casting to PyCFunction can hide actual bugs.
>>
> I borrowed that from listobject.c, which does have the cast.

Fixed. https://github.com/python/cpython/pull/28450

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


query

2021-09-19 Thread Shashwat Pandey
-- Forwarded message -
From: 
Date: Sun, Sep 19, 2021, 13:20
Subject: query
To: 


Hello!  I see you want to post a message to the Python List.  We would
be happy to help, but you must subscribe first:

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

After you have subscribed, please send your message to
python-list@python.org again.  Please do not include images as this is
a text-only forum -- instead, copy/paste or transcribe the information
from the image that you want us to know.

Alternatively, this list is mirrored both ways with the
comp.lang.python newsgroup (news:comp.lang.python).

Some people find it easier to follow this and other lists via gmane
(http://news.gmane.org/gmane.comp.python.general), a service which
offers a newsgroup interface to many online mailing lists.

*NB all posts to the mailing list are publicly archived at:*

  https://mail.python.org/pipermail/python-list





-- Forwarded message --
From: Shashwat Pandey 
To: python-list@python.org
Cc:
Bcc:
Date: Sun, 19 Sep 2021 13:19:31 +0530
Subject: query
Hello,
One thing I want to ask...

How to Fix Installation Error of PyAudio in VS Code ( Windows 32 Bit ) ??

Please Answer Me
It's very essential to complete my concept digitalization system project.

the error is given below please solve this problem


PS C:\Users\PRIYA> pip install pyaudio
Collecting pyaudio
  Using cached PyAudio-0.2.11.tar.gz (37 kB)
Using legacy 'setup.py install' for pyaudio, since package 'wheel' is not
installed.
Installing collected packages: pyaudio
Running setup.py install for pyaudio ... error
ERROR: Command errored out with exit status 1:
 command:
'C:\Users\PRIYA\AppData\Local\Programs\Python\Python39-32\python.exe' -u -c
'import io, os, sys, setuptools, tokenize; sys.argv[0] =
'"'"'C:\\Users\\PRIYA\\AppData\\Local\\Temp\\pip-install-v8hphebk\\pyaudio_4240cdb9492c47abb6d002cdb32aa86c\\setup.py'"'"';
__file__='"'"'C:\\Users\\PRIYA\\AppData\\Local\\Temp\\pip-install-v8hphebk\\pyaudio_4240cdb9492c47abb6d002cdb32aa86c\\setup.py'"'"';f
= getattr(tokenize, '"'"'open'"'"', open)(__file__) if
os.path.exists(__file__) else io.StringIO('"'"'from setuptools import
setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"',
'"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))'
install --record
'C:\Users\PRIYA\AppData\Local\Temp\pip-record-bdr6wfd9\install-record.txt'
--single-version-externally-managed --compile --install-headers
'C:\Users\PRIYA\AppData\Local\Programs\Python\Python39-32\Include\pyaudio'
 cwd:
C:\Users\PRIYA\AppData\Local\Temp\pip-install-v8hphebk\pyaudio_4240cdb9492c47abb6d002cdb32aa86c\
Complete output (9 lines):
running install
running build
running build_py
creating build
creating build\lib.win32-3.9
copying src\pyaudio.py -> build\lib.win32-3.9
running build_ext
building '_portaudio' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with
"Microsoft C++ Build Tools":
https://visualstudio.microsoft.com/visual-cpp-build-tools/

ERROR: Command errored out with exit status 1:
'C:\Users\PRIYA\AppData\Local\Programs\Python\Python39-32\python.exe' -u -c
'import io, os, sys, setuptools, tokenize; sys.argv[0] =
'"'"'C:\\Users\\PRIYA\\AppData\\Local\\Temp\\pip-install-v8hphebk\\pyaudio_4240cdb9492c47abb6d002cdb32aa86c\\setup.py'"'"';
__file__='"'"'C:\\Users\\PRIYA\\AppData\\Local\\Temp\\pip-install-v8hphebk\\pyaudio_4240cdb9492c47abb6d002cdb32aa86c\\setup.py'"'"';f
= getattr(tokenize, '"'"'open'"'"', open)(__file__) if
os.path.exists(__file__) else io.StringIO('"'"'from setuptools import
setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"',
'"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))'
install --record
'C:\Users\PRIYA\AppData\Local\Temp\pip-record-bdr6wfd9\install-record.txt'
--single-version-externally-managed --compile --install-headers
'C:\Users\PRIYA\AppData\Local\Programs\Python\Python39-32\Include\pyaudio'
Check the logs for full command output.
WARNING: You are using pip version 21.2.3; however, version 21.2.4 is
available.
You should consider upgrading via the
'C:\Users\PRIYA\AppData\Local\Programs\Python\Python39-32\python.exe -m pip
install --upgrade pip' command.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-19 Thread Mostowski Collapse
The trail itself can possibly not be eliminated. Its like a
database logfile. The trail is used during backtracking to
undo variable bindings. Which is like a database rollback.

Here is an example where a tail is used:

/* X equals 1 or X equals 2 */
?- X=1; X=2.
X = 1;
X = 2.

In the first answer the trail will have recorded that X
was bound to 1. When the second answer is requested,
the trail is used to unbind X, so that it can be bound to 2.

The Prolog garbage collection is a compactification
of the trail. Maybe databases can do the same with their
logfiles, for example if a logfile contains an insert and

then a delete of the same row, then these two logentries
can be merged. The only difference here is that Prolog
garbage collection primarily compactes towards trail

entries that have become irrelevant. This is part of 
intelligent bracktracking, and backjumping over multiple
goal invocations, that didn't record a choice point.

The Prolog garbage collection can compact the trail
before backjumping happens. So that Prolog search
has more space available.

Mostowski Collapse schrieb am Sonntag, 19. September 2021 um 10:51:03 UTC+2:
> I am refering to: 
> 
> Greg Ewing schrieb:
> > where [w] is a weak reference object. Then you could periodically 
> > scan the trail looking for dead weakref objects and remove the 
> > corresponding [*] node from the list. 
> > 
> > You can also attach callbacks to weakref objects that are triggered 
> > when the referenced object dies. You might be able to make use of 
> > that to remove items from the trail instead of the periodic scanning.
> Question to Chris Angelico: If I stay with my 
> sweep_trail(), which is the periodically scanning, 
> I can use a single linked list. 
> 
> On the other hand if I would use the trigger 
> from Python, I possibly would need a double linked 
> list, to remove an element. 
> 
> Chris Angelico, is there a third option, that I have 
> overlooked? Single linked list uses less space 
> than double linked list, this why I go with scan. 
> 
> Chris Angelico schrieb:
> > On Sun, Sep 19, 2021 at 11:46 AM Mostowski Collapse  
> > wrote: 
> >> 
> >> Yeah, it seems weak references could indeed spare 
> >> me mark_term(). But then I am stil left with sweep_trail(). 
> >> I did not yet measure what takes more time mark_term() 
> >> or sweep_trail(). The displayed "gc" is the sum of both. 
> >> 
> >> From what I have seen, very large trail practically reduced 
> >> to a zero trail during Prolog GC, I am assuming that 
> >> mark_term() is not the working horse. Usually mark_term() 
> >> only marks what is not-Garbage, and sweep_trail() 
> >> 
> >> has to deal with Garbage and not-Garbage. And there 
> >> is usually a lot of Garbage, much more than not-Garbage. 
> >> Finding the objects that survive, is like finding the needle 
> >> in the haystack, except we do not have to scan the 
> > 
> > If you stop referring to something, it is garbage. Python will dispose of 
> > it. 
> > 
> > You literally need to do nothing at all, and let the language take 
> > care of things. 
> > 
> > ChrisA 
> >
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-19 Thread Mostowski Collapse

I am refering to:

Greg Ewing schrieb:
> where [w] is a weak reference object. Then you could periodically
> scan the trail looking for dead weakref objects and remove the
> corresponding [*] node from the list.
>
> You can also attach callbacks to weakref objects that are triggered
> when the referenced object dies. You might be able to make use of
> that to remove items from the trail instead of the periodic scanning.

Question to Chris Angelico: If I stay with my
sweep_trail(), which is the periodically scanning,
I can use a single linked list.

On the other hand if I would use the trigger
from Python, I possibly would need a double linked
list, to remove an element.

Chris Angelico, is there a third option, that I have
overlooked? Single linked list uses less space
than double linked list, this why I go with scan.

Chris Angelico schrieb:

On Sun, Sep 19, 2021 at 11:46 AM Mostowski Collapse  wrote:


Yeah, it seems weak references could indeed spare
me mark_term(). But then I am stil left with sweep_trail().
I did not yet measure what takes more time mark_term()
or sweep_trail(). The displayed "gc" is the sum of both.

 From what I have seen, very large trail practically reduced
to a zero trail during Prolog GC, I am assuming that
mark_term() is not the working horse. Usually mark_term()
only marks what is not-Garbage, and sweep_trail()

has to deal with Garbage and not-Garbage. And there
is usually a lot of Garbage, much more than not-Garbage.
Finding the objects that survive, is like finding the needle
in the haystack, except we do not have to scan the


If you stop referring to something, it is garbage. Python will dispose of it.

You literally need to do nothing at all, and let the language take
care of things.

ChrisA



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


Re: How to "cast" an object to a derived class?

2021-09-19 Thread Dieter Maurer
Robert Latest wrote at 2021-9-18 13:03 GMT:
>Stefan Ram wrote:
>> Robert Latest  writes: But how can I "promote" a
>>>given Opaque instance to the derived class?
>>
>>   Sometimes, one can use containment instead of inheritance.
>
>Nah, doesn't work in my case. I'm trying to write a wrapper around
>xml.etree.ElemenTree and .Element  to circumvent its idiotic namespace
>handling. For that I need inheritance since I want to override the find..()
>functions to return my derived MyElement classes. I think it could work but I
>somehow need to convert the root Element to a MyElement.

If the class is a pure Python class, then the `__class__` attribute
of its instances is writable. You could try to assign the
derived class -- at your own risk.



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