Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Cameron Simpson

On 13Nov2022 10:08, Cameron Simpson  wrote:

On 13Nov2022 07:57, Cameron Simpson  wrote:

  # replace fctory with a function calling factory.__func__
  factory = lambda arg: factory.__func__(classmethod, arg)


It just occurred to me that you might need to grab the value of 
factory.__func__ first:


   factory0 = factory
   factory = lambda arg: factory0.__func__(classmethod, arg)

Otherwise the closure might introduce a recursion.


Or avoid the closure:

from functools import partial
..
factory = partial(factory.__func__, classmethod)

to produces a partially filled in function.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Cameron Simpson

On 13Nov2022 07:57, Cameron Simpson  wrote:

   # replace fctory with a function calling factory.__func__
   factory = lambda arg: factory.__func__(classmethod, arg)


It just occurred to me that you might need to grab the value of 
factory.__func__ first:


factory0 = factory
factory = lambda arg: factory0.__func__(classmethod, arg)

Otherwise the closure might introduce a recursion.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Ian Pilcher

On 11/12/22 14:57, Cameron Simpson wrote:
You shouldn't need a throwaway class, just use the name "classmethod" 
directly - it's the type!


     if not callable(factory):
     if type(factory) is classmethod:
     # replace fctory with a function calling factory.__func__
     factory = lambda arg: factory.__func__(classmethod, arg)
     else:
     raise TypeError("unhandled factory type %s:%r" % 
(type(factory), factory)

     value = factory(d[attr])


Or I could use the C++ version:

  face << palm;

Thanks!

--

Google  Where SkyNet meets Idiocracy


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


Re: Persisting functions typed into the shell

2022-11-12 Thread Chris Angelico
On Sun, 13 Nov 2022 at 05:48, Stefan Ram  wrote:
>   So much for the topic of "In Python, /everything/ is an
>   object"! There seem to be first and second-class objects:
>   Shelveable and non-shelveable objects.
>

That's a bit unfair. Everything IS an object, but not all objects can
be treated the same way. Complex numbers can't be compared for
greater-than/less-than, but they are still first-class objects.

Is it acceptable to you if the reconstituted function doesn't have
source code (which will affect tracebacks and such), as long as it
behaves the same way? If so, save the __code__.co_code attribute, and
build a new function from that.

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


Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Cameron Simpson

On 12Nov2022 10:34, Ian Pilcher  wrote:

So I've done this.

   class _HasUnboundClassMethod(object):
   @classmethod
   def _classmethod(cls):
   pass  # pragma: no cover
   _methods = [ _classmethod ]

   _ClassMethodType = type(_HasUnboundClassMethod._methods[0])

Which allows me to do this:

   def __init__(self, d):
   for attr, factory in self._attrs.items():
   if callable(factory):
   value = factory(d[attr])
   else:
   assert type(factory) is self._ClassMethodType
   value = factory.__func__(type(self), d[attr])
   setattr(self, attr, value)

It's a bit cleaner, although I'm not thrilled about having a throwaway
class, just to define a literal that ought to be provided by the
runtime.


Ah, nice again.

You shouldn't need a throwaway class, just use the name "classmethod" 
directly - it's the type!


if not callable(factory):
if type(factory) is classmethod:
# replace fctory with a function calling factory.__func__
factory = lambda arg: factory.__func__(classmethod, arg)
else:
raise TypeError("unhandled factory type %s:%r" % (type(factory), 
factory)
value = factory(d[attr])

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Cameron Simpson

On 12Nov2022 18:44, Weatherby,Gerard  wrote:

Use the inspect module as Cameron suggested.


My suggestions was not for the post-construction class attributes but 
for the comtents of the "_attrs" mapping. Post construction the class 
method is callable. But the classmethod object stashed in "_attrs" is 
not.


However, it _is_ of type "classmethod", which means it can be identified 
without using "inspect". Here's an alternative demo programme:


class Demo:

  @classmethod
  def us(cls):
print(cls.__name__)

  @staticmethod
  def double(x):
return x + x

  def triple(self, y):
return 3 * y

  _attrs = {
  "double": double,
  "triple": triple,
  "us": us,
  }

for name, attr in Demo._attrs.items():
  print(name, "->", attr, type(attr))
  print("  is class method =", type(attr) is classmethod)
  print("  is callable =", callable(attr))
  if inspect.ismethod(attr):
print("  ismethod")
  if inspect.isfunction(attr):
print("  isfunction")

breakpoint()

I stuck a breakpoint in so that I could inspect things after the run.  
The run looks like this:


py3 demo1.py
double ->  
  is class method = False
  is callable = False
triple ->  
  is class method = False
  is callable = True
  isfunction
us ->  
  is class method = True
  is callable = False

so just testing "type(attr) is classmethod" identifies the unpromoted 
class method.


I need to real Ian's other post to see what he did to turn that into a 
callable factory function.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Problems with IDLE in Windows 8.1 and installer x86 Version 3.10.8

2022-11-12 Thread Eryk Sun
On 11/12/22, darkst...@o2online.de  wrote:
>
 import _tkinter
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: DLL load failed while importing _tkinter: Das angegebene Modul
> wurd
> e nicht gefunden.

Loading the extension module "_tkinter.pyd" tries to load two TCL/Tk
DLL files that should be in the same directory: "tcl86t.dll" and
"tk86t.dll". Previously I asked you to look for these two files, and
you said they were there, but maybe one is corrupt.

Please try the following in the interactive shell:

import os, sys, ctypes
tcl86 = os.path.join(sys.prefix, 'DLLs', 'tcl86t.dll')
tk86 = os.path.join(sys.prefix, 'DLLs', 'tk86t.dll')

Run the following two statements one after the other in the shell:

ctypes.CDLL(tcl86)
ctypes.CDLL(tk86)

Either or both will fail if the DLL or one of its dependencies can't
be found or loaded.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need max values in list of tuples, based on position

2022-11-12 Thread Dennis Lee Bieber
On Sat, 12 Nov 2022 13:24:37 -0500, Dennis Lee Bieber
 declaimed the following:


>   Granted, this will NOT work with "select *" unless one does the select
>*/fetchall first, AND extracts the names from the cursor description --
>then run a loop to create the select max(length(col)), ... statement (which
>is why I state the fetchall step, as unless one creates a second cursor,
>the latter select will wipe out any unfetched data from the first).
>

Okay, a follow-up...


>>> import sqlite3 as db
>>> con = 
>>> db.connect("c:/users/wulfraed/documents/.localdatabases/solitaire-sqlite/solitaire.db")
>>> cur = con.cursor()
>>> cur.execute("select * from game")

>>> columns = [ "max(length(%s))" % col[0] for col in cur.description ]
>>> columns
['max(length(ID))', 'max(length(Variant))', 'max(length(Num_of_Decks))',
'max(length(Cards_in_Deck))', 'max(length(Num_Tableau_Cards))',
'max(length(Num_Reserve_Cards))', 'max(length(Foundation_Value))',
'max(length(Tableau_Value))', 'max(length(Reserve_Value))']
>>> sql = "select %s from game" % ", ".join(columns)
>>> data = cur.fetchall()
>>> cur.execute(sql)

>>> widths = cur.fetchone()
>>> widths
(1, 16, 1, 2, 2, 2, 1, 2, 2)
>>> pformat = [ f'%{w}s' for w in widths ]
>>> pformat
['%1s', '%16s', '%1s', '%2s', '%2s', '%2s', '%1s', '%2s', '%2s']
>>> pformat = " | ".join(pformat)
>>> for row in data:
... print(pformat % row)
... 
1 |  Klondike draw-3 | 1 | 52 | 28 | 24 | 1 | -1 | -2
2 | Perpetual Motion | 1 | 52 |  0 | 52 | 1 | -1 | -1
3 |  Klondike draw-1 | 1 | 52 | 28 | 24 | 1 | -1 | -2

I used " | " rather than "\t" as column separators. View with a fixed
width font.

It could be a tad shorter -- the list-comps for columns and widths
(pformat) could be embedded IN the .join() calls.


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


Re: Persisting functions typed into the shell

2022-11-12 Thread Weatherby,Gerard
Sounds like Jupyter Notebooks: https://jupyter.org


From: Python-list  on 
behalf of Stefan Ram 
Date: Saturday, November 12, 2022 at 1:48 PM
To: python-list@python.org 
Subject: Persisting functions typed into the shell
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

  Many readers here know interactive Python sessions with
  prompts like ">>>". But a "session" could be something else.
  One could imagine that when starting a new session, one
  still sees all the variables and constants defined in
  preceding sessions.

  I have implemented something like a "restore()" and a "save()"
  call. "restore()" will restore the names from the last "save()".
  "save()" will look for user-defined names (it excludes certain
  standard names and certain other names from my software) and
  save them using the "shelve" package from the standard library.

  I you know "shelve" or have read the subject line, you can
  guess what comes now:

  I cannot save user-defined functions this way!

  When a user types into the console:

|>>> def f():
|...print( "example" )
|...

  he gives source code to shell and hopes that the shell will
  cherish the memory of that function. But instead it acts as
  if from now on it does not know the source code of "f"!

  So, there seems to be no way now to persist this function
  to a file? as if by "save( f )" or something similar?
  If not the source code, then maybe some other form?

  So much for the topic of "In Python, /everything/ is an
  object"! There seem to be first and second-class objects:
  Shelveable and non-shelveable objects.


--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!kVssvGre00pk5iMVIWUbuGXUwcZ8veRBEuSiX-VLlkRVlJoQ96fl6CZG9zQ72Hky8qqofZhhhA5qZpkneyEz4-4$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Weatherby,Gerard
Use the inspect module as Cameron suggested.


import inspect


def analyze_class(clzz):
"""Analyze a class proof of concept"""
assert inspect.isclass(clzz)
for k, v in inspect.getmembers(clzz, lambda v: inspect.isfunction(v) or 
inspect.ismethod(v)):
if inspect.ismethod(v):
print(f"{v.__qualname__} -> class method ")
if inspect.isfunction(v):
sig = inspect.signature(v)
names = [n for n, _ in sig.parameters.items()]
if len(names) > 0 and str(names[0]) == 'self':
print(f"{v.__qualname__}->  probably a bound method ")
else:
print(f"{v.__qualname__}->  probably a static method ")


class Demo:

@classmethod
def us(cls):
print(cls.__name__)

@staticmethod
def double(x):
return x + x

def triple(self, y):
return 3 * y


analyze_class(Demo)

output:

Demo.double->  probably a static method
Demo.triple->  probably a bound method
Demo.us -> class method



From: Python-list  on 
behalf of Ian Pilcher 
Date: Saturday, November 12, 2022 at 11:36 AM
To: python-list@python.org 
Subject: Re: Dealing with non-callable classmethod objects
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

On 11/11/22 16:47, Cameron Simpson wrote:
> On 11Nov2022 15:29, Ian Pilcher  wrote:
>> * Can I improve the 'if callable(factory):' test above?  This treats
>>  all non-callable objects as classmethods, which is obviously not
>>  correct.  Ideally, I would check specifically for a classmethod, but
>>  there doesn't seem to be any literal against which I could check the
>>  factory's type.
>
> Yeah, it does feel a bit touchy feely.
>
> You could see if the `inspect` module tells you more precise things
> about the `factory`.
>
> The other suggestion I have is to put the method name in `_attrs`; if
> that's a `str` you could special case it as a well known type for the
> factory and look it up with `getattr(cls,factory)`.

So I've done this.

 class _HasUnboundClassMethod(object):
 @classmethod
 def _classmethod(cls):
 pass  # pragma: no cover
 _methods = [ _classmethod ]

 _ClassMethodType = type(_HasUnboundClassMethod._methods[0])

Which allows me to do this:

 def __init__(self, d):
 for attr, factory in self._attrs.items():
 if callable(factory):
 value = factory(d[attr])
 else:
 assert type(factory) is self._ClassMethodType
 value = factory.__func__(type(self), d[attr])
 setattr(self, attr, value)

It's a bit cleaner, although I'm not thrilled about having a throwaway
class, just to define a literal that ought to be provided by the
runtime.

--

Google  Where SkyNet meets Idiocracy


--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!nx6jxVGHt4Gj1WplLAV4uuhaMyS7Ry0qTCGvZm7jLCj9GbK4vto49sfmP12TTgcAT6Akjz5hJWw9JoylO_FrgQ$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Persisting functions typed into the shell

2022-11-12 Thread dn

On 13/11/2022 05.05, Stefan Ram wrote:

Wayne Harris  writes:

Wow.  Could the dis module help at all?


   Thank you for this idea! I think this should work, but only
   under CPython and not necessarily across different Python
   versions. Still, I might use dis.


Was constructing a two-part tutorial. When it came to the preparing for 
the second meeting, was surprised to discover that PyCharm retained code 
and values in its Python Console (its REPL tab/window) - I'm presuming, 
within its 'project' structure.


Was more interested in ensuring all-parties would be able to re-create 
the ending/re-starting position, regardless of IDE. Accordingly, never 
looked any further.


Depending upon the full range of criteria, may be worth a look...


Disclaimer: JetBrains sponsor our local PUG with a one-year 'pro' 
license, as a monthly 'door prize'. Apart from using the product, have 
no other connection!


Similarly, have not looked at such within VS-Codium or other editors/IDEs...
--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Need max values in list of tuples, based on position

2022-11-12 Thread Dennis Lee Bieber
On Fri, 11 Nov 2022 21:20:10 -0500, DFS  declaimed the
following:

>Yeah, I don't know why cursor.description doesn't work with SQLite; all 
>their columns are basically varchars.
>
If you read PEP 249 (the general DB-API), everything except column name
and data type code are optional. And the documentation for the sqlite3
module explicitly states that it only provides the column name, not even
type code.
 
>
>The query is literally any SELECT, any type of data, including SELECT *. 
>  The reason it works with SELECT * is the cursor.description against 
>SQLite DOES give the column names:
>
>select * from timezone;
>print(cur.description)
>(
>('TIMEZONE', None, None, None, None, None, None),
>('TIMEZONEDESC', None, None, None, None, None, None),
>('UTC_OFFSET',   None, None, None, None, None, None)
>)
>
>(I lined up the data)
>
>

Consider (table definition first)

CREATE TABLE Game (
ID INTEGER PRIMARY KEY NOT NULL,
Variant VARCHAR(64) NOT NULL,
Num_of_Decks INTEGER DEFAULT 1 NOT NULL,
Cards_in_Deck INTEGER DEFAULT 52 NOT NULL,
Num_Tableau_Cards INTEGER NOT NULL,
Num_Reserve_Cards INTEGER  
GENERATED ALWAYS 
AS ((Num_of_Decks * Cards_in_Deck) - Num_Tableau_Cards) STORED,
Foundation_Value INTEGER DEFAULT 1 NOT NULL,
Tableau_Value INTEGER DEFAULT -1 NOT NULL,
Reserve_Value INTEGER DEFAULT -2 NOT NULL
);
CREATE UNIQUE INDEX idx_Variant ON Game (Variant);

followed by a session retrieving three columns...

>>> import sqlite3 as db
>>> con = 
>>> db.connect("c:/users/wulfraed/documents/.localdatabases/solitaire-sqlite/solitaire.db")
>>> cur = con.cursor()
>>> cur.execute("""select max(length(variant)), max(length(cards_in_deck)),
... max(length(num_reserve_cards)) from Game""")

>>> widths = cur.fetchall()
>>> widths
[(16, 2, 2)]
>>> 
>>> widths[0]
(16, 2, 2)
>>> pformat = [f'%{w}s' for w in widths[0] ]
>>> pformat
['%16s', '%2s', '%2s']
>>> pformat = "\t".join(pformat)
>>> pformat
'%16s\t%2s\t%2s'
>>> for row in cur.fetchall():
... print(pformat % row)
... 
 Klondike draw-352  24
Perpetual Motion52  52
 Klondike draw-152  24
>>> 

Granted, this will NOT work with "select *" unless one does the select
*/fetchall first, AND extracts the names from the cursor description --
then run a loop to create the select max(length(col)), ... statement (which
is why I state the fetchall step, as unless one creates a second cursor,
the latter select will wipe out any unfetched data from the first).

It lets SQLite do the work of determining the max width occupied by
each column, rather than some complicated Python loop.



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


Re: Persisting functions typed into the shell

2022-11-12 Thread Wayne Harris via Python-list
On 12/11/2022 10:01, Stefan Ram wrote:
>   Many readers here know interactive Python sessions with
>   prompts like ">>>". But a "session" could be something else. 
>   One could imagine that when starting a new session, one
>   still sees all the variables and constants defined in 
>   preceding sessions.
> 
>   I have implemented something like a "restore()" and a "save()"
>   call. "restore()" will restore the names from the last "save()".
>   "save()" will look for user-defined names (it excludes certain
>   standard names and certain other names from my software) and
>   save them using the "shelve" package from the standard library.
> 
>   I you know "shelve" or have read the subject line, you can
>   guess what comes now:
> 
>   I cannot save user-defined functions this way!
> 
>   When a user types into the console:
> 
> |>>> def f():
> |...print( "example" )
> |...
> 
>   he gives source code to shell and hopes that the shell will
>   cherish the memory of that function. But instead it acts as
>   if from now on it does not know the source code of "f"!
> 
>   So, there seems to be no way now to persist this function
>   to a file? as if by "save( f )" or something similar?
>   If not the source code, then maybe some other form?
> 
>   So much for the topic of "In Python, /everything/ is an
>   object"! There seem to be first and second-class objects:
>   Shelveable and non-shelveable objects.

Wow.  Could the dis module help at all?  Say by getting the bytes of the
compiled function and then saving them to a file, then reading them off
later and rebuilding the function with dis again?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems with IDLE in Windows 8.1 and installer x86 Version 3.10.8

2022-11-12 Thread Thomas Passin

On 11/12/2022 11:48 AM, darkst...@o2online.de wrote:

Hello Thomas,

there is a “_tkinter.pyd” in the *.dll Directory. Is there something 
more, I can check?


Yes, look in the "Lib" (NOT "libs") subdirectory of the Python tree and 
see if it has a subdirectory named "tkinter". That's where it is in my 
own Python installations.  If it's there check to see if it actually has 
anything in it.


Probably it will be populated.  The next thing would to see if we can 
work out what's going wrong.


As long as you are in the LIB directory, check and see if it has a 
subdirectory named "idlelib".  If it does, try to run its self-tests**. 
In a console window, type the following command:


python -m idlelib.idle_test.htest

If it works, there it will put up a succession of little Tk dialogs and 
windows.  If you get any of them, you can cancel out of it, since you 
won't need to run dozens of little self-tests.


NOTE - on your system, the command "python" might run Python 2.7 instead 
of Python 3.x.  So use the right name for your version of Python - or 
use "py" (no quotes), which recent Python installers set up so you 
probably have it.  BTW, what version(s) of Python do you have installed? 
  If you said in a previous post, I don't recall.  You can check what 
version is running when you use the name "python" by using this command 
line (Note the upper-case "V"):


python -V


** I found out about this self-test command line because I noticed a 
file README.txt in the idlelib\idle_test subdirectory, and read it.  It 
pays to be curious and nosy when trying to work out computer problems.



*Von:* Thomas Passin 
*Gesendet:* ‎Samstag‎, ‎12‎. ‎November‎ ‎2022 ‎14‎:‎42
*An:* darkst...@o2online.de 
*Cc:* python-list@python.org 

All right, now let's verify that tk is not there (otherwise it might be
there but corrupted or not loadable for some reason).

Open Windows Explorer and navigate it to the Python directory as I
described in my last message. The navigate to the subdirectory named
"DLLs".  If tkinter is installed, there will be a file named
"_tkinter.pyd".  If that file is missing, then definitely tk isn't
there.  If it is, then it's been installed but something is wrong with
the install.

Probably it won't be there, but it's a good idea to check anyway.

If it's not there, I would suggest installing a different version of
Python.  There might be something wrong with the packaging of that
particular version, who knows?  And I would try a release with a lower
version if possible, just in case a later one accidentally used some
instruction not compatible with your version of Windows 8 (unlikely, but
just in case it could happen).  For example, if you currently have
Python 3.9.10, try Python 3.8.9.  The available releases are all here:

https://www.python.org/downloads/windows/

If this works, wonderful!  If it does not, I'm out of ideas for the moment.

On 11/11/2022 4:18 PM, darkst...@o2online.de wrote:
 > Hello,
 >
 > yes, its a Windows 8.1 with 32 bit. I have found my Installation ordner.
 >
 > If I type python
 >
 > ** IDLE can't import Tkinter.
 > Your Python may not configured for TK. **
 >
 > So I tried this:
 >
 >  >>> import _tkinter
 > Traceback (most recent call last):
 >    File "", line 1, in 
 > ImportError: DLL load failed while importing _tkinter: Das angegebene
 > Modul wurd
 > e nicht gefunden.
 >
 > So I it is a tkinter Problem and I tried this:
 >
 >  >>> import _tkinter
 > Traceback (most recent call last):
 >    File "", line 1, in 
 > ImportError: DLL load failed while importing _tkinter: Das angegebene
 > Modul wurd
 > e nicht gefunden.
 >
 > How can I go gon, to make it work?
 >
 >
 >
 >
 >
 > *Von:* Thomas Passin 
 > *Gesendet:* ‎Donnerstag‎, ‎10‎. ‎November‎ ‎2022 ‎03‎:‎00
 > *An:* python-list@python.org 
 >
 >
 > On 11/9/2022 7:02 PM, darkst...@o2online.de wrote:
 >  > Is there no one who can help?
 >
 > Is there a reason why you tried to install a 32-bit version?  Most
 > personal computers are 64-bit ones these days. Also, I don't remember if
 > you are running Windows or not.
 >
 > One problem for getting help from the list is that there have not been
 > many details given. "Doesn't start" is not helpful.  Are there error
 > messages displayed on the terminal?  How did you try to start it?  Does
 > Python run at all?
 >
 > A Python installation normally includes a batch file that launches idle.
 >    This batch file may not be on your path for one reason or another.  If
 > so, it would not run when you type "idle" at a command line.
 >
 > So the first thing to do is to figure out if you have either the Python
 > program idle.py or idle.pyw, or the batch file idle.bat (for Windows)
 > On Linux Mint, when I typed "idle" at a terminal, I got this message:
 >
 > "Command 'idle' not found, but can be installed with:
 >
 > sudo apt install 

Re: Dealing with non-callable classmethod objects

2022-11-12 Thread Ian Pilcher

On 11/11/22 16:47, Cameron Simpson wrote:

On 11Nov2022 15:29, Ian Pilcher  wrote:

* Can I improve the 'if callable(factory):' test above?  This treats
 all non-callable objects as classmethods, which is obviously not
 correct.  Ideally, I would check specifically for a classmethod, but
 there doesn't seem to be any literal against which I could check the
 factory's type.


Yeah, it does feel a bit touchy feely.

You could see if the `inspect` module tells you more precise things 
about the `factory`.


The other suggestion I have is to put the method name in `_attrs`; if 
that's a `str` you could special case it as a well known type for the 
factory and look it up with `getattr(cls,factory)`.


So I've done this.

class _HasUnboundClassMethod(object):
@classmethod
def _classmethod(cls):
pass  # pragma: no cover
_methods = [ _classmethod ]

_ClassMethodType = type(_HasUnboundClassMethod._methods[0])

Which allows me to do this:

def __init__(self, d):
for attr, factory in self._attrs.items():
if callable(factory):
value = factory(d[attr])
else:
assert type(factory) is self._ClassMethodType
value = factory.__func__(type(self), d[attr])
setattr(self, attr, value)

It's a bit cleaner, although I'm not thrilled about having a throwaway
class, just to define a literal that ought to be provided by the
runtime.

--

Google  Where SkyNet meets Idiocracy


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


Re: Need max values in list of tuples, based on position

2022-11-12 Thread 2QdxY4RzWzUUiLuE
On 2022-11-12 at 15:03:10 +,
"Weatherby,Gerard"  wrote:

> Types are available if you want to use
> them. https://www.pythontutorial.net/python-basics/python-type-hints/

Python has always been a strongly typed language.

Recent changes have given it some level of static type checking in
addition to the dyunamic typing.

> From: Python-list  on 
> behalf of Pancho via Python-list 
> Date: Friday, November 11, 2022 at 6:28 PM
> To: python-list@python.org 
> Subject: Re: Need max values in list of tuples, based on position
> 
> That was one of the things I didn't like about Python. Lack of types and
> subsequent loss of intellisense is the thing I find hardest to deal with.

-- 
I can eat glass, it does not hurt me.
Dan Sommers, http://www.tombstonezero.net/dan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Argument name should be lowercase

2022-11-12 Thread Weatherby,Gerard
RUN is a global constant, and the method is documented, explaining why the 
parameter is there:

# Copy globals as function locals to make sure that they are available
# during Python shutdown when the Pool is destroyed.
def __del__(self, _warn=warnings.warn, RUN=RUN):

From: Python-list  on 
behalf of Stefan Ram 
Date: Friday, November 11, 2022 at 2:42 PM
To: python-list@python.org 
Subject: Re: Argument name should be lowercase
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

"Weatherby,Gerard"  writes:
>I'd personally find it weird to see an all-cap parameter

  In the source code of the standard library, all-caps
  notation is used for a parameter name sometimes
  if that parameter name is "URL" or sometimes
  when it is being initialized from an all-caps name as in:

|def __del__(self, _warn=warnings.warn, RUN=RUN):
|if self._state == RUN:
...
from "pool.py".

  ("RUN=RUN" makes RUN have the value "RUN" had
  at the time of the definition of the function.)


--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!kI1c1EIpXCtnz0SBHvQmJokWXPBo0rCY9MQ-IwXOZU4RyHqqKho9wMu6Ekj6GMXA0EbReT8_4GOxvoldiOsL3W8$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Need max values in list of tuples, based on position

2022-11-12 Thread Weatherby,Gerard
Types are available if you want to use them. 
https://www.pythontutorial.net/python-basics/python-type-hints/

From: Python-list  on 
behalf of Pancho via Python-list 
Date: Friday, November 11, 2022 at 6:28 PM
To: python-list@python.org 
Subject: Re: Need max values in list of tuples, based on position

That was one of the things I didn't like about Python. Lack of types and
subsequent loss of intellisense is the thing I find hardest to deal with.

--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!jAUMq5gqI7J7UJIYw7lfpUMAy-BZPyyY8uWLJLVdVLWCaVMSBzVE6uX4RWQ-YZ0c3gvnIYn1u0r0BOmdCvEVAhyK6g$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems with IDLE in Windows 8.1 and installer x86 Version 3.10.8

2022-11-12 Thread Thomas Passin
All right, now let's verify that tk is not there (otherwise it might be 
there but corrupted or not loadable for some reason).


Open Windows Explorer and navigate it to the Python directory as I 
described in my last message. The navigate to the subdirectory named 
"DLLs".  If tkinter is installed, there will be a file named 
"_tkinter.pyd".  If that file is missing, then definitely tk isn't 
there.  If it is, then it's been installed but something is wrong with 
the install.


Probably it won't be there, but it's a good idea to check anyway.

If it's not there, I would suggest installing a different version of 
Python.  There might be something wrong with the packaging of that 
particular version, who knows?  And I would try a release with a lower 
version if possible, just in case a later one accidentally used some 
instruction not compatible with your version of Windows 8 (unlikely, but 
just in case it could happen).  For example, if you currently have 
Python 3.9.10, try Python 3.8.9.  The available releases are all here:


https://www.python.org/downloads/windows/

If this works, wonderful!  If it does not, I'm out of ideas for the moment.

On 11/11/2022 4:18 PM, darkst...@o2online.de wrote:

Hello,

yes, its a Windows 8.1 with 32 bit. I have found my Installation ordner.

If I type python

** IDLE can't import Tkinter.
Your Python may not configured for TK. **

So I tried this:

 >>> import _tkinter
Traceback (most recent call last):
   File "", line 1, in 
ImportError: DLL load failed while importing _tkinter: Das angegebene 
Modul wurd

e nicht gefunden.

So I it is a tkinter Problem and I tried this:

 >>> import _tkinter
Traceback (most recent call last):
   File "", line 1, in 
ImportError: DLL load failed while importing _tkinter: Das angegebene 
Modul wurd

e nicht gefunden.

How can I go gon, to make it work?





*Von:* Thomas Passin 
*Gesendet:* ‎Donnerstag‎, ‎10‎. ‎November‎ ‎2022 ‎03‎:‎00
*An:* python-list@python.org 


On 11/9/2022 7:02 PM, darkst...@o2online.de wrote:
 > Is there no one who can help?

Is there a reason why you tried to install a 32-bit version?  Most
personal computers are 64-bit ones these days. Also, I don't remember if
you are running Windows or not.

One problem for getting help from the list is that there have not been
many details given. "Doesn't start" is not helpful.  Are there error
messages displayed on the terminal?  How did you try to start it?  Does
Python run at all?

A Python installation normally includes a batch file that launches idle.
   This batch file may not be on your path for one reason or another.  If
so, it would not run when you type "idle" at a command line.

So the first thing to do is to figure out if you have either the Python
program idle.py or idle.pyw, or the batch file idle.bat (for Windows)
On Linux Mint, when I typed "idle" at a terminal, I got this message:

"Command 'idle' not found, but can be installed with:

sudo apt install idle"

So that's how you would get it with that flavor of Linux.

I'm going to walk through what I would probably do if I had the same
problem on Windows (I'm going to assume that you are running Windows).
It's a little long to write out, but not really that hard.  Basically,
there are only a few steps:

1. Find your Python installation;
2. Look in the installation location to see if the idle program is there;
3.  If it is, try to run it and note any error messages.

First you need to find out where your Python installation is located on
your system disk. If you don't know, one way to find out is to run the
following command in a console window:

where /R %USERPROFILE% python.exe

You may be surprised that there more several ones that you didn't
expect, such as (on my computer):

C:\Users\tom\AppData\Local\Microsoft\WindowsApps\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\python.exe

It seems that Windows has its own Python installation; that's not the
one you want.  You are looking for one that looks like this (with your
own user name, of course, instead of mine):

C:\Users\tom\AppData\Local\Programs\Python\Python310\python.exe

Appdata\Local\Programs is where Python3 usually gets installed.  Now we
know that I have Python 3.10 at
C:\Users\tom\AppData\Local\Programs\Python.  You may be using a
different version of Python; if so, just use that version instead.

Idle is normally installed in the directory tree under python.  Let's
call the top of that tree %PYTH0N%.  On my system, as we see above, that
is C:\Users\tom\AppData\Local\Programs\Python\Python310.  Idle should be at

%PYTHON%\Lib\idlelib

Open Windows explorer, and navigate to that directory. If you have that
directory, then you should be able to run idle.  If it doesn't exist,
That's a problem and needs to be fixed, probably by a fresh install of
Python.  If it does, you will see the batch file idle.bat.  Double-click
it, and idle should run.  If it does not, see below.

That's not a conv