Re: Assistance Request - Issue with Installing 'pip' despite Python 3.10 Installation

2023-06-07 Thread Thomas Passin via Python-list

On 6/7/2023 10:54 AM, Florian Guilbault via Python-list wrote:

Dear Python Technical Team,

I hope this email finds you well. I am reaching out to you today to seek
assistance with an issue I am facing regarding the installation of 'pip'
despite my numerous attempts to resolve the problem.

Recently, I performed installation, uninstallation, and even repair
operations on Python 3.10 on my computer. However, I have noticed that
'pip' has never been installed successfully. When I check via the command
prompt, I receive the following error: "'pip' is not recognized as an
internal or external command, operable program, or batch file."

I have tried several approaches to resolve this issue. I have verified that
the PATH environment variable is correctly configured to include the path
to the Python Scripts directory. I have also attempted to run the
'get-pip.py' installation script from the command line, but it did not work
either.

I am aware that 'pip' is typically installed automatically with Python, but
I am encountering this persistent difficulty. Therefore, I would like to
request your assistance and expertise in resolving this 'pip' installation
issue. I would like to be able to use 'pip' to manage my Python packages
efficiently.

I am open to any suggestions and steps you can provide to help me resolve
this problem. Please note that I am a user on the Windows operating system.

Thank you sincerely for your attention and support. I eagerly await your
guidance to resolve this situation.


You have by now seen several responses, and the one most likely to be 
helpful is to run pip with


py -m pip

I would like to suggest some ways you can make it more likely that  you 
will get useful suggestions in the future.  Basically, please fill in 
details about your situation.


1. Say what operating system your computer is running.  All the 
responses so far have assumed that it is some version of Windows.  This 
may or may not be correct.  We can infer it in this case from the 
message you reported ("'pip' is not recognized as an internal or 
external command, operable program, or batch file."), but you should say 
so that we don't need to guess.


2. Since this question is about your python installation, say how you 
installed it, since there are several possibilities.  For example, you 
may have used the installer from python.org, you may have installed it 
from the Microsoft store, etc.  These different installations are not 
always the same.


3.  When you wrote that you "verified that the PATH environment variable 
is correctly configured to include the path to the Python Scripts 
directory", tell us what that PATH actually is, not just that it is 
"correct".  We don't know if your idea of "correct" matches ours.


4.  Say how you tried to run programs that appeared to fail - running 
"python" in a console may launch a different version from the one you 
expect.  On Windows, running "py" will run the most recent one.


BTW, my own python.org installation of Python 3.11 on Windows 10 does 
not include a get-pip.exe or a get-pip.py in its Python311\Scripts 
directory (not that it was needed).


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


Re: Assistance Request - Issue with Installing 'pip' despite Python 3.10 Installation

2023-06-07 Thread Thomas Passin via Python-list

On 6/7/2023 6:28 PM, Eryk Sun wrote:

On 6/7/23, Thomas Passin via Python-list  wrote:


You have by now seen several responses, and the one most likely to be
helpful is to run pip with

py -m pip


That won't be of any help if pip isn't installed. By default, Python's
installer attempts to install pip by running the ensurepip package,
but sometimes it fails. It can help to try to manually run ensurepip
in the shell. For example:

 py -m ensurepip --default-pip --upgrade --verbose


Yes, but why should anyone besides the OP think pip isn't installed? Let 
him try py -m pip.  If pip isn't installed he will see something like


C:\Users\tom\AppData\Local\Programs\Python\Python311\python.exe: No 
module named pip


Then ensurepip should take care of it. Otherwise it's just that he 
hasn't tried the one thing that will certainly work as expected if pip 
is present.

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


Re: Assistance Request - Issue with Installing 'pip' despite Python 3.10 Installation

2023-06-08 Thread Thomas Passin via Python-list

On 6/8/2023 3:14 PM, Dennis Lee Bieber via Python-list wrote:

On Wed, 7 Jun 2023 10:36:22 -0600, Mats Wichmann 
declaimed the following:



I'm assuming you checked - say, with Explorer - that pip.exe really is
where you think it is?
Anyway,  if you ask a Windows shell (cmd) to locate it, and it doesn't,
then your PATH is not set up correctly after all.

where pip

should give you back a path that ends witn ...\Scripts\pip.exe



I'm having a suspicion that recent Windows installers are not including
a pip.exe...

-=-=-
C:\Users\Owner>echo %path%
C:\Python310\Scripts\;C:\Python310\;C:\Python310\Tools\Scripts;C:\Program
Files\PuTTY\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program
Files (x86)\Common Files\Acronis\VirtualFile\;C:\Program Files (x86)\Common
Files\Acronis\VirtualFile64\;C:\Program Files (x86)\Common
Files\Acronis\FileProtector\;C:\Program Files (x86)\Common
Files\Acronis\FileProtector64\;C:\Program Files (x86)\Common
Files\Acronis\SnapAPI\;C:\Program Files\ooRexx;C:\Program
Files\rexx.org\Regina;C:\Program Files\Microchip\xc8\v2.41\bin;C:\Program
Files\Microchip\xc8\v2.36\bin;C:\Program
Files\Microchip\xc16\v2.00\bin;C:\Program
Files\Microchip\xc32\v4.21\bin;C:\Program Files\Microsoft VS
Code\bin;C:\Program Files\dotnet\;C:\Program Files\TortoiseHg\;C:\Program
Files\Calibre2\;C:\Program Files\Microsoft SQL
Server\150\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client
SDK\ODBC\170\Tools\Binn\;C:\Program Files (x86)\IVI
Foundation\VISA\WinNT\Bin\;C:\Users\Owner\AppData\Local\Microsoft\WindowsApps;C:\Program
Files\JetBrains\PyCharm Community Edition
2021.1.2\bin;;C:\Users\Owner\.dotnet\tools

C:\Users\Owner>where pip.*
INFO: Could not find files for the given pattern(s).

C:\Users\Owner>
-=-=-
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\Owner> Get-ChildItem -Path C:\Python310\ -Recurse -Name -Filter
"pip.*"
Lib\site-packages\pip
Lib\site-packages\pipenv\patched\pip
Lib\site-packages\pipenv\utils\pip.py
Lib\site-packages\pipenv\utils\__pycache__\pip.cpython-310.pyc
PS C:\Users\Owner>
-=-=-

I've just run the installer -- python-3.10.11-amd64.exe -- as admin, in
"repair" mode! There is NO pip.exe under the Python install directory.


It's in the Scripts directory:

C:\Users\tom\AppData\Local\Programs\Python\Python311\Scripts\pip3.exe

Note that this installation was made for a single user, not "All Users" 
- this is an install-time option.  For an "All Users" location (I 
happened to install 3.9 for "All Users"), it does go into %PROGRAMFILES%:


C:\Program Files\Python39\Scripts\pip.exe

Whether this directory ends up on the PATH depends on a user option 
during installation. That's one among several reasons to invoke pip with 
py -m pip.


It always gets installed, though.


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


Re: Assistance Request - Issue with Installing 'pip' despite Python 3.10 Installation

2023-06-08 Thread Thomas Passin via Python-list

On 6/8/2023 6:23 PM, Eryk Sun wrote:

on 6/8/23, Thomas Passin via Python-list  wrote:


It always gets installed, though.


By default, the option to install pip is enabled. It's implemented by
executing ensurepip after the interpreter is installed. However,
ensurepip may silently fail during installation. As a CPython triager
I've come across this problem a couple of times, but it should be
rare. It can possibly be resolved by manually executing ensurepip via
the following command:

 py [-3[.X]] -m ensurepip --default-pip --upgrade --verbose

If Python is installed for all users, the latter should be executed
from a shell that has administrator access. Even if this command also
fails, the verbose output in the console may be helpful to further
diagnose the problem.


Hah! I *knew* someone would come up with an exceptional case.  It would 
be pretty hard for an ordinary user to know about this encantation or 
make progress if something does go wrong.   Lucky for me I've always had 
the python.org installer work smoothly.


"By default, the option to install pip is enabled" - Why would someone 
opt not to install pip, though?  Would that be an attempt to prevent 
users from installing packages on their own?



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


Re: Assistance Request - Issue with Installing 'pip' despite Python 3.10 Installation

2023-06-10 Thread Thomas Passin via Python-list

On 6/9/2023 1:43 PM, Dennis Lee Bieber via Python-list wrote:

On Thu, 8 Jun 2023 17:22:22 -0400, Thomas Passin 
declaimed the following:


On 6/8/2023 3:14 PM, Dennis Lee Bieber via Python-list wrote:
C:\Users\Owner>

-=-=-
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\Owner> Get-ChildItem -Path C:\Python310\ -Recurse -Name -Filter
"pip.*"
Lib\site-packages\pip
Lib\site-packages\pipenv\patched\pip
Lib\site-packages\pipenv\utils\pip.py
Lib\site-packages\pipenv\utils\__pycache__\pip.cpython-310.pyc
PS C:\Users\Owner>
-=-=-

I've just run the installer -- python-3.10.11-amd64.exe -- as admin, in
"repair" mode! There is NO pip.exe under the Python install directory.


It's in the Scripts directory:

C:\Users\tom\AppData\Local\Programs\Python\Python311\Scripts\pip3.exe


I copied the wrong line of my output - pip.exe is in the same place as 
pip3.exe.



Note that this installation was made for a single user, not "All Users"
- this is an install-time option.  For an "All Users" location (I
happened to install 3.9 for "All Users"), it does go into %PROGRAMFILES%:


I always install in "All Users" mode, but specify a directory that is
NOT under "Program Files" -- in this case, C:\Python310

The PowerShell command recurses into all subdirectories of the -path
argument. As it shows, the ONLY "pip" found is the actual library module.

PS C:\Users\Owner> Get-ChildItem -Path C:\P*\ -Recurse -Name -Filter
"pip.*"
R\R-4.2.3\library\climextRemes\pip
R\R-4.2.3\library\vICC\help\figures\pip.png
Package Cache\{5C3F818F-9EF5-444C-9386-77A0063A383A}v3.10.11150.0\pip.msi
Package Cache\{861EF849-90A5-4F4A-BAD4-479141466551}v3.10.10150.0\pip.msi
Lib\site-packages\pip
Lib\site-packages\pipenv\patched\pip
Lib\site-packages\pipenv\utils\pip.py
Lib\site-packages\pipenv\utils\__pycache__\pip.cpython-310.pyc
PS C:\Users\Owner> Get-ChildItem -Path C:\P*\ -Recurse -Name -Filter
"pip*.exe"
Common Files\Microsoft Shared\ink\pipanel.exe
{F87E77CE-BAA2-49E1-AAE3-1F6B2704ABAA}\OFFLINE\8AFA5EE\A9DCCED0\Pipe.exe
PS C:\Users\Owner>

Two variations, both now including "Program Files" (and x86),
"ProgramData", and the Python install; one looking for
"pip", the other "pipexe". Again, nothing
found except the library module.

"ensurepip" appears to only verify that the library module is installed
and does not seem to look for any .exe or other convenience access file.

PS C:\Users\Owner> python -m ensurepip
Looking in links: c:\Users\Owner\AppData\Local\Temp\tmp0cr7yu4s
Requirement already satisfied: setuptools in c:\python310\lib\site-packages
(67.6.1)
Requirement already satisfied: pip in c:\python310\lib\site-packages
(23.0.1)
PS C:\Users\Owner>


The standard python.org installs pip.exe in the Scripts directory and a 
pip folder in the Lib\site-packages directory. The pip directory does 
not include an actual file named "pip.py", but through Python invocation 
magic (involving __main__), py -m pip finds the right entry point and 
runs what you want.


We can find pip.exe using good old-fashioned dir (we don't need any 
new-fangled Powershell):


C:\Users\tom>dir AppData\Local\Programs\Python /Aa /S /W /B |find 
"pip"|find "Scripts"

C:\Users\tom\AppData\Local\Programs\Python\Python310\Scripts\pip.exe
C:\Users\tom\AppData\Local\Programs\Python\Python310\Scripts\pip3.10.exe
C:\Users\tom\AppData\Local\Programs\Python\Python310\Scripts\pip3.exe
C:\Users\tom\AppData\Local\Programs\Python\Python310\Scripts\pipx.exe
C:\Users\tom\AppData\Local\Programs\Python\Python311\Scripts\pip.exe
C:\Users\tom\AppData\Local\Programs\Python\Python311\Scripts\pip3.11.exe
C:\Users\tom\AppData\Local\Programs\Python\Python311\Scripts\pip3.exe
C:\Users\tom\AppData\Local\Programs\Python\Python37\Scripts\pip.exe
C:\Users\tom\AppData\Local\Programs\Python\Python37\Scripts\pip3.10.exe
C:\Users\tom\AppData\Local\Programs\Python\Python37\Scripts\pip3.7.exe
C:\Users\tom\AppData\Local\Programs\Python\Python37\Scripts\pip3.exe

Searching for a "pip" directory:

C:\Users\tom>dir AppData\Local\Programs\Python /Ad /S /W /B |find "pip" 
|find /V "_"

C:\Users\tom\AppData\Local\Programs\Python\Python310\Lib\ensurepip
C:\Users\tom\AppData\Local\Programs\Python\Python310\Lib\site-packages\pip
C:\Users\tom\AppData\Local\Programs\Python\Python310\Lib\site-packages\pip-23.1.dist-info
C:\Users\tom\AppData\Local\Programs\Python\Python310\Lib\site-packages\pipx
C:\Users\tom\AppData\Local\Programs\Python\Python310\Lib\site-packages\pipx-1.1.0.dist-info
C:\Users\tom\AppData\Local\Programs\Python\Python310\Lib\site-packages\mypy\typeshed\stdlib\ensurepip
C:\Users\tom\AppData\Local\Programs\Python\Python310\Lib\site-packages\mypy\typeshed\stdlib\@python2\ensurepip
C:\Users\tom\AppData\Local\Programs\Python\Python310\Lib\site-packages\pipx\commands
C:\Users\tom\AppData\Local\Programs\Python\Python310\Lib\site-packages\win32\Demos\pipes
C:\Users\tom\App

Re: Assistance Request - Issue with Installing 'pip' despite Python 3.10 Installation

2023-06-10 Thread Thomas Passin via Python-list

On 6/10/2023 12:32 PM, Eryk Sun wrote:

On 6/10/23, Thomas Passin via Python-list  wrote:


We can find pip.exe using good old-fashioned dir (we don't need any
new-fangled Powershell):

C:\Users\tom>dir AppData\Local\Programs\Python /Aa /S /W /B |find
"pip"|find "Scripts"


CMD's `dir` and `for` commands support simple wildcard matching. For
example, the following recursively searches for a file named
"pip*.exe" under "%ProgramFiles%\Python311":

 C:\>dir /b /s "%ProgramFiles%\Python311\pip*.exe"
 C:\Program Files\Python311\Scripts\pip.exe
 C:\Program Files\Python311\Scripts\pip3.11.exe
 C:\Program Files\Python311\Scripts\pip3.exe

 C:\>for /r "%ProgramFiles%\Python311" %f in (pip*.exe) do @(echo %f)
 C:\Program Files\Python311\Scripts\pip.exe
 C:\Program Files\Python311\Scripts\pip3.11.exe
 C:\Program Files\Python311\Scripts\pip3.exe

The following recursively searches for a directory named "pip" under
"%ProgramFiles%\Python311:

 C:\>dir /ad /b /s "%ProgramFiles%\Python311\pip"
 C:\Program Files\Python311\Lib\site-packages\pip

Or search for a directory name that starts with "pip":

 C:\>dir /ad /b /s "%ProgramFiles%\Python311\pip*"
 C:\Program Files\Python311\Lib\site-packages\pip
 C:\Program Files\Python311\Lib\site-packages\pip-22.3.1.dist-info
 C:\Program Files\Python311\Lib\site-packages\win32\Demos\pipes

With a recursive `for /r path [/d]` loop, the strings in the set have
to include wildcard characters to actually check for an existing file
or directory, else each string in the set simply gets appended to the
directory names in the recursive walk. For example, the following
recursively searches for a directory (i.e. /d) named "pip*" under
"%ProgramFiles%\Python311":

 C:\>for /r "%ProgramFiles%\Python311" /d %d in (pip*) do @(echo %d)
 C:\Program Files\Python311\Lib\site-packages\pip
 C:\Program Files\Python311\Lib\site-packages\pip-22.3.1.dist-info
 C:\Program Files\Python311\Lib\site-packages\win32\Demos\pipes

To match a specific name, you can filter the matches using an `if`
statement to compare the base filename of the loop variable (i.e.
[n]ame + e[x]tension) with the required name. For example:

 C:\>for /r "%ProgramFiles%\Python311" /d %d in (pip*) do @(
 More? if "%~nxd"=="pip" echo %d)
 C:\Program Files\Python311\Lib\site-packages\pip


Yes; I didn't want to get too esoteric with commands that are hard to 
figure out and remember, because then why not use Powershell, whose 
commands are hard to figure out and remember?


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


Re: Assistance Request - Issue with Installing 'pip' despite Python 3.10 Installation

2023-06-10 Thread Thomas Passin via Python-list

On 6/10/2023 3:20 PM, Eryk Sun wrote:

On 6/10/23, Thomas Passin via Python-list  wrote:


Yes; I didn't want to get too esoteric with commands that are hard to
figure out and remember, because then why not use Powershell, whose
commands are hard to figure out and remember?


Using `dir /s [/ad] [/b] "[path\]pattern"` with a wildcard pattern is
a simple way to recursively search for a filename or directory,
without needing to pipe the output to a findstr/grep/awk command. It's
also fast. Of course, CMD's wildcards aren't nearly as powerful as
regular expressions.


I used find to reduce the number of unwanted hits, which was helpful and 
easy to understand even if not very powerful.



The examples I included with `for` loops in CMD were for completeness
to show how to get the results in a loop variable for further
processing in a batch script. Personally, I use `for` loops a lot even
when working at the command prompt, but I'm a dinosaur in that regard.
Using PowerShell really should be preferred nowadays.


If one is doing them every day, and especially if it's for a script that 
will be reused, those loops expressions are valuable. For a one-shot 
use, and for the majority of users who (I'm sure) don't use them very 
often, they can be pretty obscure.


PowerShell has some kind of repulsive field effect on me. Plus it has an 
ugly console appearance and seems slow.  So I avoid it unless I find 
some particular case I really need it for, which is hardly ever.


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


Re: AUTO EDITOR DIDN'T WORK

2023-06-12 Thread Thomas Passin via Python-list

On 6/12/2023 5:26 AM, Real Live FootBall Tv via Python-list wrote:

  I recently Installed and Uninstalled Python, hence the system was trying
to get why I UNINSTALLED python.
I did it because I was going to use it with another application, A VIDEO
EDITING APP, Auto EDITOR but it didn't work for some reasons unknown to me.
Seeing, therefore, that the app didn't work, I thought it was of no use
keeping it occupying space within my system, hence I took it off by
UNINSTALLATION.
If there is anything I can do to make it work, I won't mind getting the
tips from you guys, thanks.



It will be hard to impossible to help without some specific information. 
 Like - what happened to cause you to say "it didn't work", what 
version of what operating system and Python you use, how you installed 
the Auto Editor package, and why you are asking for help after 
uninstalling Python.  You sure won't get it working by uninstalling Python.


The home page for the app is, according to PyPi, 
https://auto-editor.com.  Have you gone through everything there before 
giving up?

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


Re: Fwd: AUTO EDITOR DIDN'T WORK

2023-06-13 Thread Thomas Passin via Python-list

On 6/13/2023 5:32 PM, Alan Gauld via Python-list wrote:

Okay thanks. Meanwhile, I am not tech savvy so I may not say much here.
I followed all the commands as given on the website to install auto
editor standing it on python but after rendering the XML file, I
couldn't open it with my Davinci Resolve 18. I uninstalled and
reinstalled about twice and still no success hence I uninstalled it.


I don't understand when you talk about an "XML file". Auto-editor works 
on video files, or at least .mp4 files, which are not XML files. 
Davinci Resolve does have some ability to interoperate with other 
editors using XML in some way (according to Wikipedia, 
https://en.wikipedia.org/wiki/DaVinci_Resolve) but that's a different 
thing completely.


I also don't know what you mean by "after rendering the XML file" since 
from what I can see auto-edit doesn't render anything.


The simplest thing that auto-editor can do is to cut out long periods of 
dead space, e.g., from an mp4 file.  Their documentation shows how to do 
it.  If it were me, I would run the example command line on a sample mp4 
file, then see what it looked like in Davinci.  Is that what you did? 
It should be the same video but with some dead space removed.


(Note that I'm speaking from a place of no experience with either of 
these software packages; just looking at what auto-edit claims to do).




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


Re: Fwd: AUTO EDITOR DIDN'T WORK

2023-06-13 Thread Thomas Passin via Python-list

On 6/13/2023 9:43 PM, gene heskett via Python-list wrote:

On 6/13/23 19:10, Thomas Passin via Python-list wrote:

On 6/13/2023 5:32 PM, Alan Gauld via Python-list wrote:

Okay thanks. Meanwhile, I am not tech savvy so I may not say much here.
I followed all the commands as given on the website to install auto
editor standing it on python but after rendering the XML file, I
couldn't open it with my Davinci Resolve 18. I uninstalled and
reinstalled about twice and still no success hence I uninstalled it.


I don't understand when you talk about an "XML file". Auto-editor 
works on video files, or at least .mp4 files, which are not XML files. 
Davinci Resolve does have some ability to interoperate with other 
editors using XML in some way (according to Wikipedia, 
https://en.wikipedia.org/wiki/DaVinci_Resolve) but that's a different 
thing completely.


I also don't know what you mean by "after rendering the XML file" 
since from what I can see auto-edit doesn't render anything.


The simplest thing that auto-editor can do is to cut out long periods 
of dead space, e.g., from an mp4 file.  Their documentation shows how 
to do it.  If it were me, I would run the example command line on a 
sample mp4 file, then see what it looked like in Davinci.  Is that 
what you did? It should be the same video but with some dead space 
removed.


(Note that I'm speaking from a place of no experience with either of 
these software packages; just looking at what auto-edit claims to do).




auto-edit? Never heard of it. xml? I've written hundred of kilobytes of 
it in plain old geany. I didn't know there was a special editor for xml.


Oh, there are, there are - mostly intended for document authoring, I think.

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


Re: Enum + new in 3.11

2023-06-16 Thread Thomas Passin via Python-list

On 6/16/2023 1:40 AM, dn via Python-list wrote:
Have you figured-out a use for the @enum.member and @enum.nonmember 
decorators (new in Python 3.11)?



"What's New" says:
Added the member() and nonmember() decorators, to ensure the decorated 
object is/is not converted to an enum member.


The PSL docs say:
@enum.member
     A decorator for use in enums: its target will become a member.

also:
enum members have names and values (the name of Color.RED is RED, the 
value of Color.BLUE is 3, etc.)


Whereas the "Utilities and Decorators" section is slightly confusing 
because class decorators are mixed with others, so one has to read 
more-carefully.



"Curiosity killed the cat" and other cautionary tales/tails...

Have added the following decorated staticmethod to a basic enum. It is 
indeed recognised as a member of the enum, but its value is the 
method-object. To gain the value the method-object represents 
(property-like behavior) one has to call the method/enum-value as a 
function:-



from enum import Enum, member


class MenuOptions( Enum ):
     """ Legal menu-choices. """
     N = "NewGame"
     L = "LoadGame"
     # ...

     @member
     @staticmethod
     def extra_member()->str:
     return "QuitGame"


def print_demo( enum_chosen:MenuOptions )->None:
     """ Illustrative printing. """
     print( "Name:", enum_chosen, enum_chosen.name )
     if isinstance( enum_chosen, MenuOptions ):
     print( "Value:", enum_chosen.value )


print( MenuOptions.__members__ )
# {'N': , 'L': , 
'extra_member': MenuOptions.extra_member at 0x7f0802128860>)>>}


print_demo( MenuOptions[ "L" ] )
# Name: MenuOptions.L L
# Value: LoadGame

print_demo( MenuOptions.extra_member )
# Name: MenuOptions.extra_member extra_member
# Value: 0x7f0802128860>)>


print( MenuOptions.extra_member.value() )
# QuitGame


Therefore, like an @property decorator applied to a method in a 
custom-class, it could be used to only evaluate some 'expensive' 
computation if/when it is needed. Similarly, it could use the other 
values within the enum in order to present some 'combination'.


Weirdly (given that enums are considered immutable) I imagine that if 
the 'extra_member' were to call some external function with varying 
output, the value could be considered mutable when it is eventually called.


Other?better ideas...


mypy is having trouble with 3.11 enums:

"There are 83 open Enum mypy issues at the the time of this writing.

Getting the Enum datatype to work with mypy is becoming impossible as I 
find myself having to use cast() in at least every other line."


(see https://github.com/python/mypy/issues/12841)

There have also been other changes to enum  in 3.11 - here is a useful 
rundown:


https://www.andy-pearce.com/blog/posts/2023/Jan/whats-new-in-python-311-new-and-improved-modules/#enum

I had no idea

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


Re: Enum + new in 3.11

2023-06-16 Thread Thomas Passin via Python-list

On 6/16/2023 7:37 PM, dn via Python-list wrote:

On 16/06/2023 23.47, Thomas Passin via Python-list wrote:

On 6/16/2023 1:40 AM, dn via Python-list wrote:
Have you figured-out a use for the @enum.member and @enum.nonmember 
decorators (new in Python 3.11)?




mypy is having trouble with 3.11 enums:

"There are 83 open Enum mypy issues at the the time of this writing.

Getting the Enum datatype to work with mypy is becoming impossible as 
I find myself having to use cast() in at least every other line."


(see https://gi


thub.com/python/mypy/issues/12841)


There have also been other changes to enum  in 3.11 - here is a useful 
rundown:


https://www.andy-pearce.com/blog/posts/2023/Jan/whats-new-in-python-311-new-and-improved-modules/#enum

I had no idea



Sorry to hear about mypy. PyCharm has its own mechanism - if there's 
something like mypy underneath, I don't know [which].


TBH I haven't noticed any such difficulties, BUT haven't tried using 
more than a defined sub-class of Enum - and using such as a class. Thus:


class MenuOptions( Enum ):
     """ Legal menu-choices. """
     N = "NewGame"
     L = "LoadGame"
     


if __name__ == "__main__":
     n:MenuOptions = MenuOptions.N
     print( n, type( n ) )
     # MenuOptions.N 

works correctly, but strikes me as pedantry.
(any (mypy) problematic code you'd like me to try (in PyCharm) as a 
comparison? Perhaps off-list - could summarise any pertinent discoveries 
later...)



I tried messing with the enum-members, eg N:str; but realised that 
although this worked/was passed silently, the name of a member is not 
actually a string anyway. So, backed that out.



Had noted the first web.ref but deemed it unimportant (to me - as 
above). The second I had not found, and enjoyed reading (many thanks!).


«I’ll be honest, I struggled to think of concrete cases where this would 
be useful, since I don’t tend to pile additional functionality into my 
enumerations — they’re almost always just bare classes which are members 
of another class or module which provides the related functionality. But 
I think it’s good to broaden your horizons...»


The last being the same view as led me to this point, and the first, the 
motivation for this post! As said, I tend to only use enums in a fairly 
mechanistic fashion.


However, I have been playing-around with his "additional functionality". 
For example, adding the idea of a default-value if an enquiry attempts 
to use a 'key' which is not present (which seems 'natural', but equally 
goes against (my understanding of) the ethos of an enum). Next, (see 
earlier comment about having to invoke the @member-target as a function) 
was the idea that if one is using an enum as a collection of the correct 
choices/responses in a menu (per code snippet), making the member.value 
into a function* attempts to reproduce the idiom of using a dict[ionary] 
to simulate a case/select construct - which combines the idea of an 
API's constants with making a decision as to which functionality should 
be invoked.


* function here (cf "method") because unlikely to locate such 
functionality within the enum. However, am also experimenting with 
classes (cue OOP-mumblings, eg "polymorphism", "inversion", ...)


All the fun of the fair!

BTW when I reach the point of making comparisons, I expect the enum will 
be 'cheaper' in storage; but that the dict-construct will be 'faster' - 
pure speculation(!) Repeating: curious cats, etc...




From reading the references, especially the second one, it seems to me 
that these new features are mostly intended to handle weird cases 
involving subclasses of enums.  I plan to master these features by 
avoiding them - and hope I never need to understand someone else's code 
that uses them.


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


Re: File system path annotations

2023-06-19 Thread Thomas Passin via Python-list

On 6/19/2023 10:04 AM, Roel Schroeven via Python-list wrote:

Op 19/06/2023 om 11:44 schreef Peter Slížik:

Thank you, Roel. You've answered all my questions.

> [PEP 519]: ...as that can be represented with typing.Union[str, 
bytes, os.PathLike] easily enough and the hope is users

> will slowly gravitate to path objects only.

I read a lot on Python and, frankly, I don't see this happening. 
People on the Internet keep using /str/ as their path representation 
choice. Presumably, programmers don't feel the need to bother with a 
complex solution if the simplest option works just fine.
I agree, I don't see that happening either. I often find myself using 
str for paths: often simple filenames are all that's needed, and then I 
don't see much point in importing pathlib and wrapping the filenames in 
Path() constructors. I do tend to switch to path objects when I start 
needing to do operations on the paths, though.



If you are writing code that will run on both Windows and Linux/Mac, 
pathlib objects are very useful since the path separators will come out 
right with no extra effort. Also, the syntax for composing a path seems 
very natural (e.g., Path('a') / 'b' / 'c'), so that's a bonus.


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


Re: TKinter in Python - advanced notions

2023-06-23 Thread Thomas Passin via Python-list

On 6/23/2023 4:16 AM, Andreas Heckel via Python-list wrote:

Hi,

Apologies for potentially mis-using this thread. But I have been struggling 
recently making exactly this leap from simple GUI examples to a more elaborate 
MVVM concept. Mainly I have been struggling finding nice example python code 
bases, that allow some understanding to the beginner, which I certainly still 
am, but also show enough complexity to see the concept in action.
Any hints / links to github or similar highly welcome. If the list is not the 
appropriate place, I am happy if you email me directly.

Cheers,
Andreas


-Original Message-
From: Python-list
On Behalf Of Diego Souza via Python-list
Sent: Friday, June 23, 2023 4:14 AM
To: aapost
Cc: python-list
Subject: Re: TKinter in Python - advanced notions

Have you considered improving the architecture itself, not your GUI library
skills?

I recommend you look at the Model View ViewModel (MVVM) concept and
implement something similar (this is largely used in the Android framework
nowadays). This would separate your program logic from the rendering and
visualization. It would also make your program more reactive, decoupled,
and easier to maintain. When you mentioned threads I immediately thought of
this because it is much easier to implement parallel jobs and present
results back in the GUI, as everything becomes reactive. This is overkill
for a small project such as the code you showed, but I recommend it for
larger projects.


As a general comment (and I have not done anything tricky or complex 
with Tk), MVC or the other approaches in a similar vein, though good, 
can lead you into more complexity than you need, because of the extra 
abstractions involved.  Yes, for sure the GUI should not be doing domain 
or business logic. Yes, it's good to keep database access separate from 
the other parts of your program. But you may not need all the classes 
and layers that you think you might.  It all depends on what you need to 
do, of course.


Another useful design thought is to try to keep as much of the GUI logic 
separate from Tk itself as possible.  Basically, you would write a more 
abstract (and simpler) GUI API, and then write an adapter that knows how 
to make Tk do those things.  One advantage is that this approach makes 
it easier to change to another GUI toolkit later (say PyQt, for 
example).  Another is that it helps you avoid getting sucked into too 
many Tk details that aren't needed for the program concept.


Here is a simple (or simple-minded :) ) example:

class AbstractApi:
"""An abstract class for standardizing access to a display widget."""
def __init__(self, parent):
self.parent = parent
self.client = None

def registerClient(self, client):
self.client = client

def loadPanel(self, panel_name, html):
"""Load html into display panel."""
pass

def focusPanel(self, panel_name):
"""Select a named display panel."""
pass

def handleSearchText(self):
pass

def writeStatusBar(self, msg):
pass

def handleLinkClicked(self, uri, source):
"""Handle a link clicked in the "source" display panel."""
pass

These (let us say for the purposes of illustration) are the only things 
you need from the GUI.  You can write a Tk-specific version of this, and 
the rest of your program doesn't need to know that Tk is even involved. 
If you want to change to say GTK, this class is the only thing that 
would need to change.


Even if this approach turns out to be too simple for a really 
complicated UI, the closer you can come to realizing it the better.




On Wed, Jun 21, 2023 at 7:20 PM aapost via Python-list <
python-list@python.org> wrote:


On 6/21/23 09:47, Dan Kolis wrote:

I've write a huge biotech program ( an IDE for synthetic biology ), and

am slowly outgrowing TKINTER.


Has anybody out there merged a little bit of TCL direct calls from

Python 3.X to get more freedom then TKINTER for just some Windows ?


I wish it looked better, but its 'ok'. I believe X11 IO is considerably

superior for serious work the HTML.  I mean 'serious' work. with lots of
multi media windows. I am not talking about fb "Oh ! There is a window it
opened inthe corner !"... trivial functionality.


I don't know if it would help, but you can extend/add tcl/tk packages

I don't remember the full instructions right off, but quickly reverse
engineering my old stuff I think you just need to drop them in
/usr/share/tcltk/ or equivalent.

(I needed to do that to replace the terrible looking default file dialog
for unix/linux with fsdialog.)

then running something like the following from your Tk object

self.eval('package require fsdialog')

(reverse engineering the python tkinter source you can likely find other
ways of doing more tcl direct stuff)

I have not researched if there are some better, more featured
(non-buggy) Text widgets implemented in tcl that can be dropped in, (I
know 

Re: my excel file is not updated to add new data

2023-06-26 Thread Thomas Passin via Python-list

On 6/26/2023 1:46 PM, small marcc via Python-list wrote:

pandas.ExcelWriter

import pandas

This code creates the path to the Excel file where the data will be written. It 
checks if the file already exists, and if so, reads the existing data into a 
DataFrame. Otherwise, it creates a new empty DataFrame. Then it concatenates 
the existing data with the new data and writes the result to the Excel file. 
Finally, it displays a message that the backup was successful and closes the 
information window.

I do not understand why it does not work, the new data is not displayed in 
excel when I am in python tkinter, my data in python must be displayed in excel.
I use the following code to write data to an excel file using pandas:

please help meHowever, when I run this code, the new data is not showing in the 
excel file.


Do you meant the modified data is not displayed in a linked Excel 
window, or that the Excel file itself does not get changed?



I don't understand why this isn't working. Can you help me solve this problem?

data = {'Numero du client': [numero_du_client],
 'Prénom': [prenom],
 'Nom': [nom],
 'Adresse': [adresse],
 'Numero de téléphone': [numero_de_tel],
 'Longueur de cour': [longueur_de_cour],
 'Largeur de cour': [largeur_de_cour],
 "Unite(p ou m)":[boutonPieds, boutonMetres] #edit
 "Prix_coutant:[prix_coutant],   #new add  he asks me to define when I 
haven't done for others
 "Prix soumission":[prix_soumission], # new add  he asks me to define when 
I haven't done for others
 "MargeProfit":[marge_profit]} # new dd   he asks me to define when I 
haven't done for others


#my link with live excel valid for any move as long as the script and excel are 
in the same folder


chemin_script = os.path.abspath(__file__)
dossier_script = os.path.dirname(chemin_script)
nom_fichier_excel = "testpython.xlsx"
chemin_fichier_excel = os.path.join(dossier_script, nom_fichier_excel)
  df = pd.DataFrame(data)
 if os.path.exists(chemin_fichier_excel):
  df_existant = pd.read_excel(chemin_fichier_excel)
 else:
  df_existant = pd.DataFrame()
 df_concat = pd.concat([df_existant, df], ignore_index=True)
 df_concat.to_excel(chemin_fichier_excel, index=False)
 with pd.ExcelWriter(path, engine='xlsxwriter') as writer:
  df.to_excel(writer, index=False, sheet_name='Clients')
 print("sauvegarde reussi")
 fenetre_info.destroy()



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


Re: divmod with negative Decimal values

2023-08-22 Thread Thomas Passin via Python-list

On 8/18/2023 5:14 AM, Rob Cliffe via Python-list wrote:

divmod(Decimal("-1"), 60)


It's not divmod per se, but the modulus operation:

from decimal import Decimal
D1 = Decimal(-1)
D1 % 60  # Decimal(-1)

fmod() performs the same way:

from math import fmod
fmod(-1, 60)  # -1.0

From the Python docs on math.fmod:

"math.fmod(x, y)
Return fmod(x, y), as defined by the platform C library. Note that the 
Python expression x % y may not return the same result. The intent of 
the C standard is that fmod(x, y) be exactly (mathematically; to 
infinite precision) equal to x - n*y for some integer n such that the 
result has the same sign as x and magnitude less than abs(y). Python’s x 
% y returns a result with the sign of y instead, and may not be exactly 
computable for float arguments. For example, fmod(-1e-100, 1e100) is 
-1e-100, but the result of Python’s -1e-100 % 1e100 is 1e100-1e-100, 
which cannot be represented exactly as a float, and rounds to the 
surprising 1e100. For this reason, function fmod() is generally 
preferred when working with floats, while Python’s x % y is preferred 
when working with integers."


I'm not sure this is helpful in a practical way here ...




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


Re: iterations destroy reversed() results

2023-09-03 Thread Thomas Passin via Python-list

On 9/1/2023 12:15 PM, Pierre Fortin via Python-list wrote:

Hi,

reversed() results are fine until iterated over, after which the
results are no longer available. This was discovered after using
something like this:

rev = reversed( sorted( list ) )
sr = sum( 1 for _ in rev )
# rev is now destroyed

So reversed() results can only be iterated once unlike sorted(), etc...


reversed() is an iterator these days:

>>> l1 = [1, 2, 3]
>>> rev = reversed( sorted( l1 ) )
>>> type(rev)

>

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


Re: Passing info to function used in re.sub

2023-09-03 Thread Thomas Passin via Python-list

On 9/3/2023 12:10 PM, Jan Erik Moström via Python-list wrote:

I'm looking for some advice for how to write this in a clean way

I want to replace some text using a regex-pattern, but before creating 
replacement text I need to some file checking/copying etc. My code right now 
look something like this:

def fix_stuff(m):
# Do various things that involves for info
# that what's available in m
replacement_text = m.group(1) + global_var1 + global_var2
return replacement_text

and the call comes here

global_var1 = "bla bla"
global_var2 = "pff"

new_text = re.sub(im_pattern,fix_stuff,md_text)


The "problem" is that I've currently written some code that works but it uses 
global variables ... and I don't like global variables. I assume there is a better way to 
write this, but how?

= jem


There are two things to keep in mind here, I think.  First, in Python a 
"global" variable is really module-level, so variables specific to one 
module seem fine and are common practice.


Second, the way you have written this example, it looks like these 
module-level "variables" are in effect constants.  In other words, they 
are just shorthand for specific declared quantities.  If this is so, 
then it makes even more sense to define them as module-level objects in 
the module that needs to use them.


If you still don't want to use them as "global" in your module, then 
define them in a separate module and import them from that module.


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


Re: Python 3.11.5 Pip Issue

2023-09-14 Thread Thomas Passin via Python-list

On 9/13/2023 11:39 PM, Jacob Keeler via Python-list wrote:

I downloaded Python 3.11.5, and there was nothing in the “Scripts” file,
and there was no Pip. I would like to know why.


What do you mean by "downloaded"? And are you talking about Windows? 
Did you download the installer from python.org and run it, or did you 
download a zip file and unpack it?


The answers will make a difference.

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


Re: Python 3.11.5 Pip Issue

2023-09-14 Thread Thomas Passin via Python-list

On 9/13/2023 11:39 PM, Jacob Keeler via Python-list wrote:

I downloaded Python 3.11.5, and there was nothing in the “Scripts” file,
and there was no Pip. I would like to know why.


I just downloaded the 3.11.5 64-bit installer for Windows from 
python.org and ran it.  This was an upgrade since I already had 3.11.4 
installed.  I had installed for me as a user rather than for "everyone" 
so it installed into %USERPROFILE%\AppData\Local\Programs\Python\Python311\.


The Scripts folder is at

C:\Users\tom\AppData\Local\Programs\Python\Python311\Scripts

I checked and the installer did update the pip.exe and pip3.exe files. 
in this Scripts directory.


So ... presumably you downloaded and ran the Windows 64-bit installer, 
is that right?  Did you install it for "everyone" or just for you?  Did 
you notice any error messages during installation?  Did you do a 
standard install or did you customize it in some way? Exactly where is 
the "Scripts" directory in which you found "nothing"? Was the "py" 
launcher installed - that is, can you run Python 3.11.5 by typing "py"? 
If so, can you run pip by typing


py -m pip

(this is the most reliable way to run pip, by the way, because it always 
runs the version of pip that is installed for the latest install of Python).


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


Re: Postgresql equivalent of Python's timeit?

2023-09-17 Thread Thomas Passin via Python-list

On 9/17/2023 11:48 AM, AVI GROSS via Python-list wrote:

Timing things that are fairly simple is hard enough to do repeatedly, but when 
it involves access to slower media and especially to network connections to 
servers, the number of things that can change are enormous. There are all kinds 
of caching at various levels depending on your hardware and resource contention 
with other programs running here and there as well as on various network-like 
structures and busses or just hard disks. Asking for anything to be repeated 
multiple times in a row as a general rule can make your results seem slower or 
faster depending on too many factors including what else is running on your 
machine.

I am wondering if an approach to running something N times that may average things out a bit is to simply put in a pause. Have your program wait a few minutes between attempts and perhaps even do other things within your loop that make it likely some of the resources you want not to be in a queue have a chance to be flushed as other things take their place. 


One thing I have done for timing queries is to construct a series of 
test queries with the query parameters drawn randomly from a large set 
of values.  The hope is that random combinations will defeat caching and 
provide a reasonably realistic view of the times.



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


Re: Postgresql equivalent of Python's timeit?

2023-09-17 Thread Thomas Passin via Python-list

On 9/17/2023 5:01 AM, Albert-Jan Roskam via Python-list wrote:

On Sep 15, 2023 19:45, "Peter J. Holzer via Python-list"
 wrote:

  On 2023-09-15 17:42:06 +0200, Albert-Jan Roskam via Python-list wrote:
  >    This is more related to Postgresql than to Python, I hope this is
  ok.
  >    I want to measure Postgres queries N times, much like Python timeit
  >    (https://docs.python.org/3/library/timeit.html). I know about
  EXPLAIN
  >    ANALYZE and psql \timing, but there's quite a bit of variation in
  the
  >    times. Is there a timeit-like function in Postgresql?

  Why not simply call it n times from Python?

  (But be aware that calling the same query n times in a row is likely to
  be
  unrealistically fast because most of the data will already be in
  memory.)

=
Thanks, I'll give this a shot. Hopefully the caching is not an issue if I
don't re-use the same database connection.


Here is a stack overflow thread that gives a good rundown of ways to get 
timings from Postgres:


https://stackoverflow.com/questions/9063402/get-execution-time-of-postgresql-query

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


Re: PEP668 / pipx and "--editable" installs

2023-09-17 Thread Thomas Passin via Python-list

On 9/16/2023 7:57 PM, Rimu Atkinson via Python-list wrote:



It is nothing bad about using virtual environments but also not about
not using them. In my own work I haven't see a use case where I needed
them. And I expect that some day I'll encounter a use case for it. This
here is not about pro and cons of virtual environments.

You are in a use case where you need them, right now :) When you 
understand the benefits of virtual environments you will understand what 
I meant by that.



Please explain how the two problems I explained are influenced by not
using virtual environments.


The first problem can be avoided because virtual environments can use a 
different version of python than the system one. If you need an earlier 
version of python then you can use it instead.


I have multiple versions of Python on both Windows and Linux machines. 
I don't have to use the system version.  On Windows the "py" launcher 
can launch any Python version on your system.


The second problem can be avoided because virtual environments exist in 
a part of the file system that you have write access to, so you don't 
need to use sudo to install packages. Your main user account does not 
have write access to /usr/bin.


And therefore on Linux pip will install packages as --user even if the 
option isn't specified.  On Windows, one would just use --user routinely.


Also when a virtual environment is activated the path to it's packages 
is a part of that environment so your code will always be able to import 
the packages you want.


Whenever a version of Python is launched its system path is set up so 
that its own packages are used.  The one thing that can cause problems 
is programs in the Python Scripts directory, which may not be on the 
path for a particular version of Python.  A virtual environment will 
take case of that, but I almost never run scripts in that directory so 
it's not an issue for me.


I think there are situations where a venv is useful, but not because of 
the points you have asserted here.  For myself, I find that after a 
while, I tend to forget what I set up the various venvs for, and what 
state they are in.  So I have stopped using them.  I just put up with 
having more packages in /site-packages than a particular applications 
needs. If I want to, say, work on code in a git clone's directory tree, 
I launch Python using a batch file that sets the PYTHONPATH to point there.


It's much easier to understand if you try it for yourself. Google has 
many excellent resources, here is one 
https://www.freecodecamp.org/news/how-to-setup-virtual-environments-in-python/


Best of luck :)

R


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


Re: PEP668 / pipx and "--editable" installs

2023-09-18 Thread Thomas Passin via Python-list

On 9/18/2023 2:56 PM, c.buhtz--- via Python-list wrote:

On 2023-09-18 10:16 "Peter J. Holzer via Python-list"
 wrote:

On 2023-09-15 14:15:23 +, c.buhtz--- via Python-list wrote:

I tried to install it via "pipx install -e .[develop]". It's
pyproject.toml has a bug: A missing dependency "dateutil". But
"dateutil" is not available from PyPi for Python 3.11 (the default
in Debian 12). But thanks to great Debian they have a
"python3-dateutil" package. I installed it.


This can be installed via pip:


I'm aware of this. But this is not the question.

I would like to know and understand why my via "pipx" installed package
"hyperorg" is not able to see the systems packages installed via "apt
install python3-dateutils"?

Is this the usual behavior? Is this correct?
What is the design decision behind it?

Is it really the intention of PEP668 that pipx-installed packages are
not allowed to use system packages?


One way this could happen is if the hyperorg package got installed by a 
different version of Python than the system version.  I've lost track of 
just how your installation is set up so this may not apply.  But, for 
example, if the system is using Python 3.10.x and you installed hyperorg 
using Python 3.11, that would be such a situation.  The apt-installed 
packages will get installed into the system python directories, rather 
than to the Python 3.11 directories.


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


Re: Using generator expressions

2023-09-25 Thread Thomas Passin via Python-list

On 9/25/2023 10:15 AM, Jonathan Gossage via Python-list wrote:

I am having a problem using generator expressions to supply the arguments
for a class instance initialization. The following example shows the
problem:

class test1(object):
 def __init__(self, a, b):


 self.name = a


 self.value = b
st = 'Programming Renaissance, Any'.split(', ')
y = test1(a for a in st)
print(f'Object values are: {y._a}, {y._b}')

I would expect to get the values from the list generated by splitting the
string passed in as arguments to the new instance of test1, but instead
I get the generator expression by itself as a generator object. The
generator
expression is treated like a passive object instead of being run. If I had
wanted to pass the generator expression itself, I would have expected to
have
to use parentheses around the generator expression. Any suggestions on how
to
get the generator expression to run?
If I change the definition of the input arguments to *args I can capture the
arguments within __init__ but it is verbose and ugly. Also, I could accept
the
arguments from a Sequence and extract the Sequence members into the class
values. I would prefer my solution if I could get it to work.
Note that I tried generator expressions both inside parentheses and not,
without success.



You should get an error at the y assignment.  The argument of test1() is 
a generator, which would get assigned to the "a" argument, and there 
would be no "b" argument, which is an error.


In any event, even if this were to work as you want, it would only work 
for strings that contain one comma.  And you ask for values like y._a, 
but y._a is never created, only y.a.  If you did convert the generator 
to a list, and if you fix the underscored variable names, it still 
wouldn't work because the arguments don't expect a list.


Time to step back and figure out exactly what you actually want to do.

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


Re: upgrade of pip on my python 2.7 version

2023-09-27 Thread Thomas Passin via Python-list

On 9/27/2023 7:17 AM, Zuri Shaddai Kuchipudi via Python-list wrote:

hello everyone this the error that im getting while trying to install and 
upgrade pip on what is the solution for it?

C:\repository\pst-utils-pc-davinci-simulator>pip install
You are using pip version 7.0.1, however version 23.2.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
You must give at least one requirement to install (see "pip help install")

C:\repository\pst-utils-pc-davinci-simulator>pip install --upgrade pip
You are using pip version 7.0.1, however version 23.2.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting pip
   Using cached 
https://files.pythonhosted.org/packages/ba/19/e63fb4e0d20e48bd2167bb7e857abc0e21679e24805ba921a224df8977c0/pip-23.2.1.tar.gz
 Complete output from command python setup.py egg_info:
 Traceback (most recent call last):
   File "", line 20, in 
   File 
"c:\users\kuchipz\appdata\local\temp\pip-build-gc4ekm\pip\setup.py", line 7
 def read(rel_path: str) -> str:
  ^
 SyntaxError: invalid syntax

 
Command "python setup.py egg_info" failed with error code 1 in 
c:\users\kuchipz\appdata\local\temp\pip-build-gc4ekm\pip


Possibly this:

https://techglimpse.com/install-higher-version-pip-python27/


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


Re: path to python in venv

2023-09-27 Thread Thomas Passin via Python-list

On 9/27/2023 2:53 PM, Larry Martell via Python-list wrote:

I was under the impression that in a venv the python used would be in
the venv's bin dir. But in my venvs I see this in the bin dirs:

lrwxrwxrwx 1 larrymartell larrymartell7 Sep 27 11:21 python -> python3
lrwxrwxrwx 1 larrymartell larrymartell   16 Sep 27 11:21 python3 ->
/usr/bin/python3

Googling this I read:

The presence of symbolic links like python and python3 in the bin
directory of your virtual environment pointing to the system Python
executable (/usr/bin/python) suggests that the virtual environment was
created using the system Python interpreter rather than a standalone
Python installation.

This can happen if you create a virtual environment using a
system-wide Python interpreter, and the virtual environment inherits
some of the symbolic links or shortcuts from the system Python
installation. In this case, your virtual environment is not fully
isolated because it still relies on the system Python interpreter.

Not sure what this really means, nor how to get python to be in my venv.


You don't need to "get python to be in my venv".  The venv contains its 
own Python Lib directory, and whatever site-packages installs you want 
for that venv.  In essence, the script for launching the venv sets up 
the PYTHONPATH variable and some other paths so that Python finds its 
files in the venv directories instead of in the usual Python locations. 
Setting these paths may involve creating symbolic links and that is all 
done for you.


The thing you need to appreciate is that when you create a venv with a 
command like this:


 -m venv path/to/venv

this will all link back to whatever version of Python you used in place 
of .  If you invoked it with python3, on Linux you will get 
whatever your system runs when you type "python3", which would usually 
be the system's Python install.  If you want to use some other version 
of Python, say python3.10, then just run that one instead when you 
create the venv.


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


Re: upgrade of pip on my python 2.7 version

2023-09-28 Thread Thomas Passin via Python-list

On 9/28/2023 9:23 AM, Zuri Shaddai Kuchipudi via Python-list wrote:

On Wednesday, 27 September 2023 at 23:33:02 UTC+2, Chris Angelico wrote:

On Thu, 28 Sept 2023 at 07:27, Mats Wichmann via Python-list
 wrote:


Upgrading to Python 3 is the best answer... except when it isn't. If
you want to convert a small project it's usually not too hard; and using
a conversion tool can work well.

Just remember that Python 2.7.18, the very last version of Python 2,
was released in 2020 and has not changed since. There are not even
security patches being released (at least, not from python.org - but
if you're using a different distribution of Python, you are also quite
possibly using their package manager rather than pip). Staying on a
version of Python that hasn't had new features since 2010 and hasn't
had bug fixes since 2020 is going to become increasingly problematic.

Convert your code. Pay the price in development time now and then reap
the benefits, rather than paying the price when you run into a massive
issue somewhere down the track and there's no options left to you.

Convert while you still have the luxury of running the old code.

ChrisA

but how do i convert it chris just downloading the python version 3 will solve 
my issue? and what about the changes


You have to modify your existing Python code.  It's often easy to do. 
There is the tool that tries to convert from Python 2 to Python 3; you 
may need to do some extra work after that.  Depending on the code you 
may even be able to make it work with both Python 2.7 and 3.x.  Often 
the biggest change is to print statements:


Python 2:
print a, b, c

Python3:
print(a, b, c)

If you are very unlucky, your code will depend on some package that has 
never been ported to Python 3.  But that would be unusual.


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


Re: Where I do ask for a new feature

2023-10-20 Thread Thomas Passin via Python-list

On 10/19/2023 11:16 PM, Bongo Ferno via Python-list wrote:

On Thursday, October 19, 2023 at 11:26:52 PM UTC-3, avi.e...@gmail.com wrote:


There are many ways to make transient variables that disappear at some time
and do we need yet another? Yes, you can create one of those ways but what
is the big deal with deleting a variable when no longer used?


Assigning a variable to something can be anything else than a temporal alias.
A with statement makes clear that the alias is an alias and is local, and it 
automatically clears the variable after the block code is used.

Python clutters the variable space with vars that are needed only on certain 
places, and an alias doesn't has a scope.
Convenient alias are short names, and short names are limited in quantity. If 
the space is cluttered with short alias, it opens risks for wrong utilization.

Its like writing a "for i" in a list comprehension and having to worry if "i" 
was already used in another place..


If a name is temporarily needed in a certain place and in a certain 
scope then reusing the name shouldn't be a problem.


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


Re: Running a subprocess in a venv

2023-10-21 Thread Thomas Passin via Python-list

On 10/21/2023 11:32 AM, Larry Martell via Python-list wrote:

On Sat, Oct 21, 2023 at 9:49 AM Johannes Findeisen  wrote:


On Sat, 21 Oct 2023 09:01:18 -0400
Larry Martell via Python-list  wrote:


I have a python script, and from that I want to run another script in
a subprocess in a venv. What is the best way to do that? I could write
a file that activates the venv then runs the script, then run that
file, but that seems messy. Is there a better way?


How do you do that?


How? Open a file and write the commands I need then invoke that.


It sounds messy but not wrong...

I would activate the venv and then run my Python script. In the Python
script you can call another python script in a subprocess like this:

import sys
import subprocess

# https://docs.python.org/3/library/subprocess.html#popen-constructor
proc = subprocess.Popen([sys.executable, "/path/to/an/otherscript.py"])

# https://docs.python.org/3/library/subprocess.html#popen-objects
# Do your process communication/handling... proc.communicate(),
# proc.wait(), proc.terminate(), proc.kill() etc.

Is this the answer you are looking for?

Detailed docs: https://docs.python.org/3/library/subprocess.html


I know how to use Popen. What I was missing was running the script
using sys.executable. Thanks.


A nice feature of using sys.executable is that you automatically use the 
same Python installation as your invoking program is running with.  On a 
system that has several different Python installations, that's a very 
good thing.


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


Re: Question(s)

2023-10-24 Thread Thomas Passin via Python-list

On 10/24/2023 8:22 AM, o1bigtenor via Python-list wrote:

Greetings

(Sorry for a nebulous subject but dunno how to have a short title for
a complex question.)

I have been using computers for a long time but am only beginning my
foray into the
galaxy of programming. Have done little to this point besides
collection of information
on sensors and working on the logic of what I wish to accomplish. Have
been reading code that accompanies other's projects in the process of
self development.

Is there a way to verify that a program is going to do what it is
supposed to do even
before all the hardware has been assembled and installed and tested?

(Many years ago I remember an article (if not an issue) in Byte magazine about
mathematically proven constructs a.k.a. programs - - - this idea is
what I'm pursuing.
The concept is that in non-trivial programs there are plenty of places where a
poorly placed symbol or lack of a character will result in at best an inaccurate
result and at worst - - - no result. This is the kind of thing
(correct code) that I'm
hoping to accomplish - - - to rephrase the question - - - how do I
test for that?)

TIA


By now you have read many responses that basically say that you cannot 
prove that a given program has no errors, even apart from the hardware 
question.  Even if it could be done, the kind of specification that you 
would need would in itself be difficult to create, read, and understand, 
and would be subject to bugs itself.


Something less ambitious than a full proof of correctness of an 
arbitrary program can sometimes be achieved.  The programming team for 
the Apollo moon mission developed a system which, if you would write 
your requirements in a certain way, could generate correct C code for them.


You won't be doing that.

Here I want to point out something else.  You say you are just getting 
into programming.  You are going to be making many mistakes and errors, 
and there will be many things about programming you won't understand 
until you get some good solid experience.  That's not anything to do 
with you personally, that's just how it will play out.


So be prepared to learn from your mistakes and bugs.  They are how you 
learn the nuts and bolts of the business of programming.


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


Re: Question(s)

2023-10-24 Thread Thomas Passin via Python-list

On 10/24/2023 7:15 PM, o1bigtenor wrote:

On Tue, Oct 24, 2023 at 6:09 PM Thomas Passin via Python-list
 wrote:



snip


By now you have read many responses that basically say that you cannot
prove that a given program has no errors, even apart from the hardware
question.  Even if it could be done, the kind of specification that you
would need would in itself be difficult to create, read, and understand,
and would be subject to bugs itself.

Something less ambitious than a full proof of correctness of an
arbitrary program can sometimes be achieved.  The programming team for
the Apollo moon mission developed a system which, if you would write
your requirements in a certain way, could generate correct C code for them.

You won't be doing that.

Here I want to point out something else.  You say you are just getting
into programming.  You are going to be making many mistakes and errors,
and there will be many things about programming you won't understand
until you get some good solid experience.  That's not anything to do
with you personally, that's just how it will play out.

So be prepared to learn from your mistakes and bugs.  They are how you
learn the nuts and bolts of the business of programming.



I am fully expecting to make mistakes (grin!).
I have a couple trades tickets - - - I've done more than a touch of technical
learning so mistakes are not scary.

What is interesting about this is the absolute certainty that it is impossible
to program so that that program is provably correct.
Somehow - - - well - - to me that sounds that programming is illogical.

If I set up a set of mathematical problems (linked) I can prove that the
logic structure of my answer is correct.


In general, that's not the case - CF Godel's Theorem.  There are true 
arithmetical statements that cannot be proven to be true within the 
axioms of arithmetic.  There's a counterpart in programming called the 
halting problem. Can an arbitrary computer program be proven to ever 
finish - to come to a halt (meaning basically to spit out a computed 
result)?  Not in general.  If it will never halt you can never check its 
computation.


This doesn't mean that no program can ever be proven to halt, nor that 
no program can never be proven correct by formal means.  Will your 
program be one of those?  The answer may never come ...



That's what I'm looking to do with the programming.

(Is that different than the question(s) that I've asked - - - dunno.)

Stimulating interaction for sure (grin!).



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


Re: Question(s)

2023-10-24 Thread Thomas Passin via Python-list

On 10/24/2023 7:37 PM, Grant Edwards via Python-list wrote:

On 2023-10-24, Thomas Passin via Python-list  wrote:


Something less ambitious than a full proof of correctness of an
arbitrary program can sometimes be achieved.  The programming team
for the Apollo moon mission developed a system which, if you would
write your requirements in a certain way, could generate correct C
code for them.


Er, what?

C didnt' exist until after the Apollo program was done.

FORTRAN, perhaps?



Sorry, I mixed myself up.  The head of the team continued to develop the 
techniques and market them.  It's todays's version that can output C 
(going from memory a few years old here).  Sorry to have confused 
everyone and myself.


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


Re: Question(s)

2023-10-25 Thread Thomas Passin via Python-list

On 10/25/2023 9:21 AM, Thomas Passin wrote:

On 10/25/2023 8:50 AM, o1bigtenor via Python-list wrote:
On Wed, Oct 25, 2023 at 7:00 AM Dieter Maurer  
wrote:


o1bigtenor wrote at 2023-10-25 06:44 -0500:
On Wed, Oct 25, 2023 at 6:24?AM Dieter Maurer  
wrote:

...

There are different kinds of errors.

Some can be avoided by using an integrated development environment
(e.g. misspellings, type mismatches, ...).


Haven't heard of a python IDE - - - doesn't mean that there isn't 
such - -

just that I haven't heard of such. Is there a python IDE?


There are several.

Python comes with "IDLE".


Interesting - - - started looking into this.


There are several others,
e.g. "ECLIPSE" can be used for Python development.


Is 'Eclipse' a Windows oriented IDE?
(Having a hard time finding linux related  information on the
website.)


Search for other alternatices.


Will do.

Thanks for the assistance.


Pyzo is one possibility - https://pyzo.org


The Leo editor is excellent, as long as you are prepared for a steep 
learning curve - https://github.com/leo-editor/leo-editor


It's installable via pip (though there can be fixable install glitches 
on some Linux distros).




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


Re: Question(s)

2023-10-25 Thread Thomas Passin via Python-list

On 10/25/2023 8:50 AM, o1bigtenor via Python-list wrote:

On Wed, Oct 25, 2023 at 7:00 AM Dieter Maurer  wrote:


o1bigtenor wrote at 2023-10-25 06:44 -0500:

On Wed, Oct 25, 2023 at 6:24?AM Dieter Maurer  wrote:
...

There are different kinds of errors.

Some can be avoided by using an integrated development environment
(e.g. misspellings, type mismatches, ...).


Haven't heard of a python IDE - - - doesn't mean that there isn't such - -
just that I haven't heard of such. Is there a python IDE?


There are several.

Python comes with "IDLE".


Interesting - - - started looking into this.


There are several others,
e.g. "ECLIPSE" can be used for Python development.


Is 'Eclipse' a Windows oriented IDE?
(Having a hard time finding linux related  information on the
website.)


Search for other alternatices.


Will do.

Thanks for the assistance.


Pyzo is one possibility - https://pyzo.org

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


Re: Question(s)

2023-10-25 Thread Thomas Passin via Python-list

On 10/25/2023 9:20 AM, Michael F. Stemper via Python-list wrote:

On 24/10/2023 17.50, Thomas Passin wrote:


   The programming team for the Apollo moon mission developed a system 
which,> if you would write your requirements in a certain way, could 
generate correct

C code for them.
Since the last Apollo mission was in 1972, when C was first being 
developed, I

find this hard to believe.


Yes, sorry, see my previous post.  It's the current-day evolution of the 
tools that can output C.


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


Re: Too Broad of an exception

2023-10-25 Thread Thomas Passin via Python-list

On 10/25/2023 11:49 AM, rsutton via Python-list wrote:

On 10/25/2023 11:06 AM, Stefan Ram wrote:

r...@zedat.fu-berlin.de (Stefan Ram) writes:

outer quotation marks) prints some prominent exception types. After
manually removing those that do not seem to apply, I am left with:
"AssertionError",
"ChildProcessError",

...

   "Manually removing" above was meant to be a fast first pass,
   where I only excluded exception types that were obviously
   inappropriate. It is now to be followed by a search for the
   appropriate exception types among those exception types left.



@Rene & @Stefan,
I really appreciate the guidance provided.  By replacing Exception with 
RuntimeError, pylint seems happy!  More specificity, I guess.  I know 
that I could have ignored the pylint exceptions, but I want to use this 
as a learning experience.  I looks like I have a lot of reading to do on 
exception handling. IMO all of the try/except code looks quite clumsy to 
me.  It may be excellent for some tasks but to me, it looks quite 
inelegant.  Like I said, I have a lot to learn.


In this particular case you could probably just handle the return result 
from robocopy right there.  Of course, it depends on the rest of the 
code.  It probably doesn't really need an exception, and if you want to 
handle it in the calling function, you could just return the result as a 
boolean:


return p.returncode < 8  # Reversed the test since a return of "True"
 # would make more sense as a return code


Thank you both for your guidance.

Richard



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


Re: Question(s)

2023-10-26 Thread Thomas Passin via Python-list

On 10/26/2023 7:50 AM, o1bigtenor via Python-list wrote:

On Wed, Oct 25, 2023 at 9:10 AM Dieter Maurer  wrote:


o1bigtenor wrote at 2023-10-25 08:29 -0500:

...
It would appear that something has changed.

Went to the Eclipse download page, downloaded and verified (using sha-512).
Expanded software to # opt .
There is absolutely NO mention of anything python - - - java, c and
its permutations,
'scientific computing', and some others but nothing python.

I may be missing something due to an extreme lack of knowledge.

Please advise as to where I might find the 'python' environment in eclipse.


I entered "eclipse python download" in my favorite search engine
(=> "ecosia.org") and the second hit gave:
"https://marketplace.eclipse.org/content/pydev-python-ide-eclipse";.


Using Duckduckgo I had tried eclipse + python  which I would have
thought should have spit out something useful - - - but that just took
me to the general page and the download - - - well it did NOT offer
any python anything!

Thank you for the tip!


Eclipse is a huge complicated ecosystem.  I'd stay away from it and go 
with something smaller and simpler. (having said that, it's quite a few 
years since I gave up on Eclipse the last time).  Something like pyzo, 
for instance.

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


Re: Question(s)

2023-10-26 Thread Thomas Passin via Python-list

On 10/26/2023 4:25 PM, o1bigtenor via Python-list wrote:

On Thu, Oct 26, 2023 at 11:43 AM Michael Torrie via Python-list
 wrote:


On 10/26/23 06:34, o1bigtenor wrote:

Interesting - - - -  ". . . see if it runs." - - - that's the issue!
When the code is accessing sensors there isn't an easy way to
check that the code is working until one has done the all of the
physical construction. If I'm trying to control a pulsation system
using square waves with distinct needs for timing etc I hadn't
seen any way of 'stepping through the code' (phrase you use later).


Having dabbled in embedded electronics, all I can say is you will just
have to build it and try to get it working.  Failure is always an
option.  If I understand you correctly, this is for a hobby interest, so
go at it and have fun.

Stepping through code is a basic part of debugging in any language.
They all have tools for it. Google for python debugging.

"distinct needs for timing?"  Did you forget to tell us you need to use
MicroPython?  Certainly MicroPython running on a microcontroller with
help from hardware timers certainly can do it, but this mailing list is
not the place to ask about it.  Instead you'll have to visit a forum on
MicroPython or CircuitPython.  By the way you definitely can step
through MicroPython code one line at a time with a remote debugger, say
with Visual Studio Code.


Its one of the reasons to use micropython - - - it is a subset of python.
I didn't think I was asking about micropython here though. The project with
the square wave stuff has lots going on so its more likely that regular python
will be used. Part of the challenge is trying to figure out if I need to be
running a real time kernel or even a real time OS. Independent information
is quite hard to find - - - seems like most of the information is by someone
with skin in the game and then without a background its hard to figure out
if what they're saying tells enough so that I can make a good decision or
not.


[snip]

Maybe see -

pyvisa (https://pyvisa.readthedocs.io/en/latest/)
https://github.com/mick001/Instruments-Control
http://justinbois.github.io/bootcamp/2021/lessons/l40_serial.html
https://chaserhkj.gitbooks.io/ivi-book/content/

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


Re: Question(s)

2023-10-26 Thread Thomas Passin via Python-list

On 10/26/2023 6:36 PM, AVI GROSS via Python-list wrote:

I am not one for IDLE worship, Tenor. But if you have been getting a message 
here, it is that there are an amazing number of programs that support your use 
of python during the development phase and perhaps later. I actually often use 
an environment called RSTUDIO (now part of a new name of POSIT) because it has 
been expanded beyond supporting R and supports Python and a growing number of 
other languages or combos that combine word processing with inserts from 
multiple languages.


Excellent! I didn't know about this development.

[snip]


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


Re: Question(s)

2023-10-26 Thread Thomas Passin via Python-list

On 10/26/2023 10:52 PM, avi.e.gr...@gmail.com wrote:

Thomas,

It looks like much of our discussion and attempts at help are not going to
be that helpful to Tenor as we may be way off bass about what he wants to do
and certainly RSTUDIO and quite a few other suggestions may not be available
in his microcontroller.

As I see it, some of his objective involves sampling a sensor in real time.
I have not heard what he wants to do with the data gathered and this may be
an example of where code needs to be running fast enough to keep up. Proving
the code will work, especially if you add logging or print statements or run
it in a monitored mode so you can follow what it is doing, presents special
challenges.

Now if he ever wants to read in a .CSV file and analyze the data and make
graphs and so on, I might chime in. For now, I am dropping out.



Avi


I'm there.  It's like someone is insisting on being instructed how to 
drive a race car in a race when he's only got a learner's permit.  You 
just have to go through the experience of actually driving on streets 
and in traffic first.  There is no substitute.


TomP


-Original Message-
From: Python-list  On
Behalf Of Thomas Passin via Python-list
Sent: Thursday, October 26, 2023 6:50 PM
To: python-list@python.org
Subject: Re: Question(s)

On 10/26/2023 6:36 PM, AVI GROSS via Python-list wrote:

I am not one for IDLE worship, Tenor. But if you have been getting a

message here, it is that there are an amazing number of programs that
support your use of python during the development phase and perhaps later. I
actually often use an environment called RSTUDIO (now part of a new name of
POSIT) because it has been expanded beyond supporting R and supports Python
and a growing number of other languages or combos that combine word
processing with inserts from multiple languages.

Excellent! I didn't know about this development.

[snip]




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


Re: Checking if email is valid

2023-11-03 Thread Thomas Passin via Python-list

On 11/3/2023 6:51 AM, Jon Ribbens via Python-list wrote:

On 2023-11-03, Chris Angelico  wrote:

On Fri, 3 Nov 2023 at 12:21, AVI GROSS via Python-list
 wrote:

My guess is that a first test of an email address might be to see if
a decent module of that kind fills out the object to your
satisfaction. You can then perhaps test parts of the object, rather
than everything at once, to see if it is obviously invalid. As an
example, what does u...@alpha...com with what seems to be lots of
meaningless periods, get parsed into?


What do you mean by "obviously invalid"? Have you read the RFC?


What do you mean by 'What do you mean by "obviously invalid"?'
Have you read the RFC?


About reading the RFC, there's this ... but read the comments too ...

https://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/


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


Re: pip/pip3 confusion and keeping up to date

2023-11-06 Thread Thomas Passin via Python-list

On 11/6/2023 5:04 PM, Karsten Hilbert via Python-list wrote:

Am Mon, Nov 06, 2023 at 02:43:47PM -0700 schrieb Mats Wichmann via Python-list:


I had just hoped someone here might have a handy pointer for
how to deal with modules having to be installed from pip for
use with an apt-installed python-based application.


That just shouldn't happen - such packages are supposed to be 
dependency-complete within
the packaging universe in question.


Yep, that's the preferable ideal world.

Which doesn't happen (but that's not the fault of anyone
around here, no harm intended).

.From all the posts I gather the answer to my question is
"simply": unpackaged-but-needed modules need to be packaged.


I think there is one aspect that isn't getting consideration here.  And 
that is whether or not you want these packages installed in the default 
system Python install.  You might not.  Maybe you want to get the latest 
possible version of super-dooper-gui-helper, but one of its dependencies 
doesn't play well with the system Python libraries. Or ... but you get 
the point.  There are probably many cases where you want *not* to 
install into the system Python world.  So you would need to come up with 
an APT-based installer that doesn't do that.


Obviously it's not unthinkable; it is just one more thing to figure out.

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


Re: Detect naming typos (AttributeError) in function names

2023-11-07 Thread Thomas Passin via Python-list

On 11/7/2023 2:48 AM, Christian Buhtz via Python-list wrote:

Hello Dieter,

thanks for your reply.

Am 06.11.2023 19:11 schrieb Dieter Maurer:

One option is a test suite (--> Python's "unittest" package)
with a sufficiently high coverage (near 100 %).


Yes, that is the primary goal. But it is far away in the related project.

I got a hint that "pylint" is able to detect problems like this.


mypy can detect typos in names by noticing that they haven't been 
declared.  For example, if you have a class NewClass(BaseClass), and 
BaseClass has a method findme(), but you call it as findMe(), mypy will 
tell you findMe does not exist in BaseClass.  It can be annoying to get 
the options set right so you don't get too many undesired hits, but it's 
certainly doable.  mypy can be slow, depending on your code.


You could also simply run py_compile, which will try to compile the 
code.  It will stop at the first error it finds.


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


Re: Writing to clipboard in Python 3.11

2023-11-07 Thread Thomas Passin via Python-list

On 11/5/2023 7:51 PM, Rob Cliffe via Python-list wrote:
Recently I switched from Python 3.8.3 to Python 3.11.4.  A strange 
problem appeared which was not there before:
I am using the win32clipboard backage (part of pywin32), and when I use 
SetClipboardData() to write text which consists ENTIRELY OF DIGITS to 
the clipboard, I either get an error (not always the same error message) 
or a program crash.  The problem does not appear if I use 
SetClipboardText() instead.

Sample program:

from win32clipboard import *
OpenClipboard()
SetClipboardData(CF_UNICODETEXT, "A")
SetClipboardData(CF_UNICODETEXT, "A0")
SetClipboardData(CF_UNICODETEXT, "0A")
SetClipboardText("0", CF_UNICODETEXT)
print("OK so far")
SetClipboardData(CF_UNICODETEXT, "0")
CloseClipboard()

Sample output:

OK so far
Traceback (most recent call last):
   File "R:\W.PY", line 8, in 
     SetClipboardData(CF_UNICODETEXT, "0")
pywintypes.error: (0, 'SetClipboardData', 'No error message is available')

I can get round the problem by using SetClipboardText().  But can anyone 
shed light on this?


No, but I use pyperclip.  It's cross platform.  Maybe it doesn't have 
this problem, though I don't know for sure.


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


Re: fCONV_AUSRICHTG is not defined - Why?

2023-11-07 Thread Thomas Passin via Python-list

On 11/7/2023 12:47 PM, Egon Frerich via Python-list wrote:

I've no idea why this happens. In a module there are lists and definitions:

     Felder = [
     # Name   lg1  lg2 typ   Ausrichtung Holen Prüfen Prüfvorg
     ["Jahr", 4, 5, "u", "", "right", "center"],
     ["Monat", 2, 5, "u", "", "right", "center"],
     ["Tag", 2, 3, "u", "", "right", "center"],
     ["Belegnr", 5, 7, "s", "", "right", "center"],
     ["Bank", 2, 4, "u", "", "center", "center"],
     ["Art", 2, 3, "u", "", "center", "center"],
     ["Aufg", 2, 4, "u", "", "center", "center"],
     ["Text", 25, 25, "s", "-", "left", "left"],
     ["Ergänzung", 12, 12, "s", "-", "left", "left"],
     ["Betrag", 13, 13, "s", "", "right", "right"],
     ["W", 1, 2, "s", "", "center", "center"],
     ["WBetrag", 7, 7, "s", "", "right", "right"],
     ["Kurs", 6, 6, "s", "", "right", "right"],
     ]
     "Reihenfolge in der Dimension 1"
     (
     fJAHR,
     fMONAT,
     fTAG,
     fBELEGNR,
     fBANK,
     fART,
     fAUFGABE,
     fTEXT,
     fTEXTERG,
     fBETRAG,
     fWAEHRUNG,
     fBETRAGinWAEHRUNG,
     fUMRECHNUNGSKURS,
     ) = list(range(13))
     "Reihenfolge in der Dimension 2"
     (
     fNAME,
     fLG1,
     fLG2,
     fTYP,
     fCONV_AUSRICHTG,
     fENTRY_AUSRICHTG,
     fTEXT_AUSRICHTUNG,
     fHOLFUNKT,
     fPRUEFFUNKT,
     fPRUEF_ARG,
     ) = list(range(10))


Two lines with  test statements follow and the statement which produces 
an error:


     print(Felder)
     print(fJAHR, fNAME, fTYP, fCONV_AUSRICHTG)
     akette = "%" + "%".join(
     ["%s%s%s " % (i[fCONV_AUSRICHTG], i[fLG2], i[fTYP]) for i in 
Felder])


The traceback shows:

$ python3 testGeldspurGUI.py
[['Jahr', 4, 5, 'u', '', 'right', 'center'], ['Monat', 2, 5, 'u', '', 
'right', 'center'], ['Tag', 2, 3, 'u', '', 'right', 'center'], 
['Belegnr', 5, 7, 's', '', 'right', 'center'], ['Bank', 2, 4, 'u', '', 
'center', 'center'], ['Art', 2, 3, 'u', '', 'center', 'center'], 
['Aufg', 2, 4, 'u', '', 'center', 'center'], ['Text', 25, 25, 's', '-', 
'left', 'left'], ['Ergänzung', 12, 12, 's', '-', 'left', 'left'], 
['Betrag', 13, 13, 's', '', 'right', 'right'], ['W', 1, 2, 's', '', 
'center', 'center'], ['WBetrag', 7, 7, 's', '', 'right', 'right'], 
['Kurs', 6, 6, 's', '', 'right', 'right']]

0 0 3 4
Traceback (most recent call last):
   File "/home/egon/Entw/Geldspur/geldspur/testGeldspurGUI.py", line 15, 
in 

     from tests.testU2 import testU2
   File "/home/egon/Entw/Geldspur/geldspur/tests/testU2.py", line 9, in 


     from gui.GUI_Konfig import GUIcfg
   File "/home/egon/Entw/Geldspur/geldspur/gui/GUI_Konfig.py", line 11, 
in 

     class GUIcfg:
   File "/home/egon/Entw/Geldspur/geldspur/gui/GUI_Konfig.py", line 90, 
in GUIcfg

     ["%s%s%s " % (i[fCONV_AUSRICHTG], i[fLG2], i[fTYP]) for i in Felder])
   File "/home/egon/Entw/Geldspur/geldspur/gui/GUI_Konfig.py", line 90, 
in 

     ["%s%s%s " % (i[fCONV_AUSRICHTG], i[fLG2], i[fTYP]) for i in Felder])
NameError: name 'fCONV_AUSRICHTG' is not defined

You see "Felder" and with "0 0 3 4" the correct value 4 for 
fCONV_AUSRICHTG. But there is the NameError.


What does  mean? Is there a change from python2 to python3?


You are using a syntax that I don't understand, but "listcomp" means a 
list comprehenson.


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


Re: fCONV_AUSRICHTG is not defined - Why?

2023-11-07 Thread Thomas Passin via Python-list

On 11/7/2023 3:29 PM, MRAB via Python-list wrote:

On 2023-11-07 19:20, Jim Schwartz via Python-list wrote:
Where do you define fCONV_AUSRICHTG? It must be initialized or defined 
somewhere. Did you leave out a statement from the python 2 version?



It's given its value here:

     (
     fNAME,
     fLG1,
     fLG2,
     fTYP,
     fCONV_AUSRICHTG,
     fENTRY_AUSRICHTG,
     fTEXT_AUSRICHTUNG,
     fHOLFUNKT,
     fPRUEFFUNKT,
     fPRUEF_ARG,
     ) = list(range(10))



This construction is a sneaky way to assign index numbers to list 
entries.  A simplified example:


>>> S1 = 'string 1'
>>> S2 = 'string 2'
>>> (fS1, fS2) = list(range(2))
>>> fS1
0
>>>
>>> fS2
1





On Nov 7, 2023, at 1:06 PM, Thomas Passin via Python-list 
 wrote:


On 11/7/2023 12:47 PM, Egon Frerich via Python-list wrote:
I've no idea why this happens. In a module there are lists and 
definitions:

    Felder = [
    # Name   lg1  lg2 typ   Ausrichtung Holen Prüfen Prüfvorg
    ["Jahr", 4, 5, "u", "", "right", "center"],
    ["Monat", 2, 5, "u", "", "right", "center"],
    ["Tag", 2, 3, "u", "", "right", "center"],
    ["Belegnr", 5, 7, "s", "", "right", "center"],
    ["Bank", 2, 4, "u", "", "center", "center"],
    ["Art", 2, 3, "u", "", "center", "center"],
    ["Aufg", 2, 4, "u", "", "center", "center"],
    ["Text", 25, 25, "s", "-", "left", "left"],
    ["Ergänzung", 12, 12, "s", "-", "left", "left"],
    ["Betrag", 13, 13, "s", "", "right", "right"],
    ["W", 1, 2, "s", "", "center", "center"],
    ["WBetrag", 7, 7, "s", "", "right", "right"],
    ["Kurs", 6, 6, "s", "", "right", "right"],
    ]
    "Reihenfolge in der Dimension 1"
    (
    fJAHR,
    fMONAT,
    fTAG,
    fBELEGNR,
    fBANK,
    fART,
    fAUFGABE,
    fTEXT,
    fTEXTERG,
    fBETRAG,
    fWAEHRUNG,
    fBETRAGinWAEHRUNG,
    fUMRECHNUNGSKURS,
    ) = list(range(13))
    "Reihenfolge in der Dimension 2"
    (
    fNAME,
    fLG1,
    fLG2,
    fTYP,
    fCONV_AUSRICHTG,
    fENTRY_AUSRICHTG,
    fTEXT_AUSRICHTUNG,
    fHOLFUNKT,
    fPRUEFFUNKT,
    fPRUEF_ARG,
    ) = list(range(10))
Two lines with  test statements follow and the statement which 
produces an error:

    print(Felder)
    print(fJAHR, fNAME, fTYP, fCONV_AUSRICHTG)
    akette = "%" + "%".join(
    ["%s%s%s " % (i[fCONV_AUSRICHTG], i[fLG2], i[fTYP]) for i in 
Felder])

The traceback shows:
$ python3 testGeldspurGUI.py
[['Jahr', 4, 5, 'u', '', 'right', 'center'], ['Monat', 2, 5, 'u', 
'', 'right', 'center'], ['Tag', 2, 3, 'u', '', 'right', 'center'], 
['Belegnr', 5, 7, 's', '', 'right', 'center'], ['Bank', 2, 4, 'u', 
'', 'center', 'center'], ['Art', 2, 3, 'u', '', 'center', 'center'], 
['Aufg', 2, 4, 'u', '', 'center', 'center'], ['Text', 25, 25, 's', 
'-', 'left', 'left'], ['Ergänzung', 12, 12, 's', '-', 'left', 
'left'], ['Betrag', 13, 13, 's', '', 'right', 'right'], ['W', 1, 2, 
's', '', 'center', 'center'], ['WBetrag', 7, 7, 's', '', 'right', 
'right'], ['Kurs', 6, 6, 's', '', 'right', 'right']]

0 0 3 4
Traceback (most recent call last):
  File "/home/egon/Entw/Geldspur/geldspur/testGeldspurGUI.py", line 
15, in 

    from tests.testU2 import testU2
  File "/home/egon/Entw/Geldspur/geldspur/tests/testU2.py", line 9, 
in 

    from gui.GUI_Konfig import GUIcfg
  File "/home/egon/Entw/Geldspur/geldspur/gui/GUI_Konfig.py", line 
11, in 

    class GUIcfg:
  File "/home/egon/Entw/Geldspur/geldspur/gui/GUI_Konfig.py", line 
90, in GUIcfg
    ["%s%s%s " % (i[fCONV_AUSRICHTG], i[fLG2], i[fTYP]) for i in 
Felder])
  File "/home/egon/Entw/Geldspur/geldspur/gui/GUI_Konfig.py", line 
90, in 
    ["%s%s%s " % (i[fCONV_AUSRICHTG], i[fLG2], i[fTYP]) for i in 
Felder])

NameError: name 'fCONV_AUSRICHTG' is not defined
You see "Felder" and with "0 0 3 4" the correct value 4 for 
fCONV_AUSRICHTG. But there is the NameError.

What does  mean? Is there a change from python2 to python3?


You are using a syntax that I don't understand, but "listcomp" means 
a list comprehenson.






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


Re: xor operator (DEPRECATED)

2023-11-13 Thread Thomas Passin via Python-list

On 11/13/2023 11:44 PM, AVI GROSS via Python-list wrote:

Dom,

I hear you.

As you say, writing your own extension in something like C++ may not appeal to 
you even if it is faster.

I was wondering if using a generator or something similar in R might make sense.

I mean what happens if you write a function that includes a "yield" or two and 
does a part of what you want. It maintains some internal state between invocations. So 
you can call it once to setup things then call it repeatedly to keep processing the next 
item. You stop calling it when you get a result you want, such as that it has seen what 
you want N times.

Since the code stays in memory, it may effectively run faster than some other 
kinds of functions calls. It can keep things in internal storage such as not 
just how many N you want but how many it has seen.


I'm inclined to just turn the iterable into a set to get the values, 
then iterate through those values calling count() on a listified version 
of the iterable. If the count >= target, return.


It may not be the fastest one could do but it's simple and probably 
pretty fast for many uses.  I suppose that for some iterables it would 
be better not to turn them into lists, but one could figure out about 
that after working out more carefully what cases need to be covered.



Your outer function can maintain a list of the items you want to XOR or 
generate a new one dynamically as needed. It can use functional programming 
techniques to create a new customized version of the iterator, such as with a 
value of N built in. You would then call the outer function and let it use the 
inner function till the result is available or until the data in the iterator 
runs out or perhaps other tweaks involving two way communication of sorts 
between the functions.

I am NOT suggesting this approach is optimal or fast but merely wondering if 
something along these lines is worth trying that might speed things up even if 
not very fast. Such approaches can be even more effective if what you are 
working on need not all be instantiated up front but can be dynamically 
calculated or incrementally read from files. With care, you can make multiple 
instantiations that each iterate over their own sets of data without 
interference.

Just a thought. In a sense, this can be a slightly decent substitute for the 
non-standard evaluation in R where you can arrange for lots of your data to not 
be interpreted till absolutely needed.



-Original Message-
From: Dom Grigonis 
Sent: Monday, November 13, 2023 10:12 PM
To: avi.e.gr...@gmail.com
Cc: Grant Edwards ; Python 
Subject: Re: xor operator (DEPRECATED)

Fair point. However, I gave it a shot for the following reason:

I couldn’t find a way to make such performant function. Using python builtin 
components still ends up several times slower than builtin `all`. Cython or 
numba or similar is not an option as they do not support `truth` values. Or if 
they do, it ends up slower than pure python variant.

So all what is left is writing a proper extension. Which I would prefer not to 
do for 1 function. I thought maybe `xor`, as in logical XOR functionality in 
its vanilla case could be compelling. And after doing a bit of search I see 
that very very few languages have that and it seems for a good reason.

Some that do: R, thats all I could find. Although some (if not many) went 
through the proposal phase. And yes, none of them have a function that I am 
proposing.

So yes, you are right, not a good proposal.

But there still seems to be the need for short-circuiting performant 
implementations in python space. The issue is that there are many variants of 
what might be needed while there is no efficient solution to sourcing 
predicates from python to lower level implementations. Someone mentioned that 
numpy experimented with such implementations in C, but they did not get 
anywhere with it.

The best I could come up with is cached numba for numpy problems, which does 
perform very well and more than worth it if function is re-used. It even ends 
up faster than cython or cffi extensions, however can’t have many of those due 
to JIT and AOT is currently being deprecated (which wouldn’t solve anything 
anyway). However, as I mentioned earlier it does not apply to this case.

So it’s either:
a) Something very clever and flexible implemented that covers most of such 
needs and doesn’t require predicates.
b) I welcome any thoughts on this.

DG


On 14 Nov 2023, at 04:27, AVI GROSS via Python-list  
wrote:

I was going to ask a dumb question. Has any other language you know of made
something available that does what is being asked for and included it in the
main program environment rather than an add-on?

A secondary mention here has been whether short-circuiting functions like
"any" and "all" have been augmented with something like "has_n" that
evaluates arguments till it has found n or perhaps n+1 of what it wants then
skips the rest. Does any language

Re: Newline (NuBe Question)

2023-11-15 Thread Thomas Passin via Python-list

On 11/15/2023 2:25 AM, Grizzy Adams via Python-list wrote:

Hi & thanks for patience with what could be simple to you

Have this (from an online "classes" tutorial)

--- Start Code Snippit  ---

students = []
grades = []
for s in geographyClass:
students.append(geographyStudent(s))
for s in students:
 grades.append(s.school)
 grades.append(s.name)
 grades.append(s.finalGrade())
 if s.finalGrade()>82:
 grades.append("Pass")
 else:
 grades.append("Fail")
print(grades)

--- End Code Snippit  ---

I have extended (from tutorial) it a bit, I would really like to have a newline

at end of each record, I have searched (and tested) but cant get "\n" to give a

newline, I get "Mydata\n"

Do I need to replace "append" with "print", or is there a way to get the
newline in as I append to list?


First of all, if this is an accurate representation of the course 
material, you need a better course.  There's no sense in appending all 
those values one after another in a single list since later it will be 
very inconvenient to detect the end of one student's info and the start 
of the next one's.  And if you don't need to know that, but just want to 
print out the data, you don't need to a list at all, just print it out 
in the loop.


A list that contains lists of each student's data, one per interior 
list, would make more sense.


Second, it is usual to append data to a list without print formatting, 
and then add your formatting when you go to print the list.  That way 
you can use the list for other things beyond just printing, and the code 
is clearer and simpler as well.


You may see responses that suggest various code alternatives.  But you 
haven't shown us an example of what you want the output to look like, 
and you haven't said what else you plan to use the list for.  So anyone 
who responds has to fly blind, without knowing key information.


Asking for help is like writing code, with an added social element.  You 
have to be clear about the requirements, inputs, and desired outputs, 
and you have to organize your request in a way that's easy for others to 
understand and be willing to help.  Your original post is partway there 
already.


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


Re: Newline (NuBe Question)

2023-11-15 Thread Thomas Passin via Python-list

On 11/15/2023 2:04 PM, Grizzy Adams via Python-list wrote:

Wednesday, November 15, 2023  at 12:19, Pierre Fortin wrote:
Re: Newline (NuBe Question) (at least in part)


On Wed, 15 Nov 2023 16:51:09 - Grizzy Adams via Python-list wrote:

I don't give solutions; just a nudge...  you appear not to fully grok
"list"; your list is ONE list with no delineation between students. You
want a "list of lists"...



['Example High', 'Mary', 89.6, 'Pass', 'Example High', 'Matthew', 76.5, 'Fail', 
'Example High', 'Marie', 80.4, 'Fail', 'Example High', 'Manuel', 79.6, 'Fail', 
'Example High', 'Malala', 98.9, 'Pass']



Like this:



students = [
['Example High', 'Mary', 89.6, 'Pass'],
['Example High','Matthew', 76.5, 'Fail'],
['Example High', 'Marie', 80.4, 'Fail'],
['Example High', 'Manuel', 79.6, 'Fail'],
['Example High', 'Malala', 98.9, 'Pass']
]


for now I made a copt of code and altered to

students = []
grades = []


# In this design there is no point in the extra loop.
# also, the indentation is wrong.  Perhaps you inserted
# tabs?  Use only spaces in these posts.
# Also you don't need the students list

for student in geographyClass:
# students.append(geographyStudent(s))

s = geographyStudent(student)



 # for s in students:

  if s.finalGrade()>82: Result=("Pass")
  else: Result=("Fail")
  print(s.school, s.name, s.finalGrade(),Result)


This may help get you headed in the right direction:



for s in students:
print( s )



Hint: look forward to learning about f-strings...


I will look forward to them, may even go search ahead,


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


Re: Newline (NuBe Question)

2023-11-16 Thread Thomas Passin via Python-list

On 11/16/2023 1:19 AM, Grizzy Adams via Python-list wrote:

Wednesday, November 15, 2023  at 15:54, Thomas Passin via Python-list wrote:
Re: Newline (NuBe Question) (at least in part)


On 11/15/2023 2:04 PM, Grizzy Adams via Python-list wrote:

Wednesday, November 15, 2023  at 12:19, Pierre Fortin wrote:
Re: Newline (NuBe Question) (at least in part)
  

On Wed, 15 Nov 2023 16:51:09 - Grizzy Adams via Python-list wrote:



I don't give solutions; just a nudge...  you appear not to fully grok
"list"; your list is ONE list with no delineation between students. You
want a "list of lists"...
  

['Example High', 'Mary', 89.6, 'Pass', 'Example High', 'Matthew', 76.5, 'Fail', 
'Example High', 'Marie', 80.4, 'Fail', 'Example High', 'Manuel', 79.6, 'Fail', 
'Example High', 'Malala', 98.9, 'Pass']



Like this:
  

students = [
 ['Example High', 'Mary', 89.6, 'Pass'],
 ['Example High','Matthew', 76.5, 'Fail'],
 ['Example High', 'Marie', 80.4, 'Fail'],
 ['Example High', 'Manuel', 79.6, 'Fail'],
 ['Example High', 'Malala', 98.9, 'Pass']
]
  

for now I made a copt of code and altered to

students = []
grades = []



# In this design there is no point in the extra loop.
# also, the indentation is wrong.  Perhaps you inserted
# tabs?  Use only spaces in these posts.


I copy-pasted the code direct from IDLE, (to avoid any other typo's)


# Also you don't need the students list

for student in geographyClass:
# students.append(geographyStudent(s))

 s = geographyStudent(student)



  # for s in students:

   if s.finalGrade()>82: Result=("Pass")
   else: Result=("Fail")
   print(s.school, s.name, s.finalGrade(),Result)


I'll hive this a try (as a learning point)


I wrote that you don't need the "students" list, which is correct.  But 
there could be a use for a list.  It would let you change the order in 
which students appear in the printed output.  Knowing how to do that is 
a useful skill.  But that should be left for a later lesson, not mixed 
in here.


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


Re: Code improvement question

2023-11-17 Thread Thomas Passin via Python-list

On 11/17/2023 6:17 AM, Peter J. Holzer via Python-list wrote:

On 2023-11-16 11:34:16 +1300, Rimu Atkinson via Python-list wrote:

Why don't you use re.findall?

re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt)


I think I can see what you did there but it won't make sense to me - or
whoever looks at the code - in future.

That answers your specific question. However, I am in awe of people who
can just "do" regular expressions and I thank you very much for what
would have been a monumental effort had I tried it.


I feel the same way about regex. If I can find a way to write something
without regex I very much prefer to as regex usually adds complexity and
hurts readability.


I find "straight" regexps very easy to write. There are only a handful
of constructs which are all very simple and you just string them
together. But then I've used regexps for 30+ years, so of course they
feel natural to me.

(Reading regexps may be a bit harder, exactly because they are to
simple: There is no abstraction, so a complicated pattern results in a
long regexp.)

There are some extensions to regexps which are conceptually harder, like
lookahead and lookbehind or nested contexts in Perl. I may need the
manual for those (especially because they are new(ish) and every
language uses a different syntax for them) or avoid them altogether.

Oh, and Python (just like Perl) allows you to embed whitespace and
comments into Regexps, which helps readability a lot if you have to
write long regexps.



You might find https://regex101.com/ to be useful for testing your regex.
You can enter in sample data and see if it matches.

If I understood what your regex was trying to do I might be able to suggest
some python to do the same thing. Is it just removing numbers from text?


Not "removing" them (as I understood it), but extracting them (i.e. find
and collect them).


re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt)


\b - a word boundary.
[0-9]{2,7} - 2 to 7 digits
-  - a hyphen-minus
[0-9]{2}   - exactly 2 digits
-  - a hyphen-minus
[0-9]{2}   - exactly 2 digits
\b - a word boundary.

Seems quite straightforward to me. I'll be impressed if you can write
that in Python in a way which is easier to read.


And the re.VERBOSE (also re.X) flag can always be used so the entire 
expression can be written line-by-line with comments nearly the same as 
the example above


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


Re: Code improvement question

2023-11-17 Thread Thomas Passin via Python-list

On 11/17/2023 9:46 AM, Peter J. Holzer via Python-list wrote:

On 2023-11-17 07:48:41 -0500, Thomas Passin via Python-list wrote:

On 11/17/2023 6:17 AM, Peter J. Holzer via Python-list wrote:

Oh, and Python (just like Perl) allows you to embed whitespace and
comments into Regexps, which helps readability a lot if you have to
write long regexps.


[...]

re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt)


\b - a word boundary.
[0-9]{2,7} - 2 to 7 digits
-  - a hyphen-minus
[0-9]{2}   - exactly 2 digits
-  - a hyphen-minus
[0-9]{2}   - exactly 2 digits
\b - a word boundary.

Seems quite straightforward to me. I'll be impressed if you can write
that in Python in a way which is easier to read.


And the re.VERBOSE (also re.X) flag can always be used so the entire
expression can be written line-by-line with comments nearly the same
as the example above


Yes. That's what I alluded to above.


I know, and I just wanted to make it explicit for people who didn't know 
much about Python regexes.


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


Re: Silly/crazy problem with sqlite

2023-11-25 Thread Thomas Passin via Python-list

On 11/24/2023 4:49 PM, Rimu Atkinson via Python-list wrote:







I really can't think of a case
where the missing comma would make any sense at all.



That is pretty tricky, yes.

The comma means it's a tuple. Without the comma, it's just a string with 
parenthesis around it, which is a string.


PyDev console: starting.
Python 3.9.15 (main, Oct 28 2022, 17:28:38) [GCC] on linux
x = ('%' + "2023-11" + '%')
x
'%2023-11%'
x = ('%' +  x + '%',)
x
('%%2023-11%%',)
x.__class__.__name__
'tuple'


To make it very clear in your code so that you are reminded next time 
you want to re-use it, you could write


param = '%2023-11%'
cr.execute(sql, (param,))

Probably the param value will actually use a variable instead of the 
hard-coded value in the example. So use an f-string, because it's more 
readable and easier to get right:


date = ... # Where ever the actual date value comes from
param = f'%{date}%'
cr.execute(sql, (param,))

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


Re: How/where to store calibration values - written by program A, read by program B

2023-12-05 Thread Thomas Passin via Python-list

On 12/5/2023 11:50 AM, MRAB via Python-list wrote:

On 2023-12-05 14:37, Chris Green via Python-list wrote:

Is there a neat, pythonic way to store values which are 'sometimes'
changed?

My particular case at the moment is calibration values for ADC inputs
which are set by running a calibration program and used by lots of
programs which display the values or do calculations with them.

 From the program readability point of view it would be good to have a
Python module with the values in it but using a Python program to
write/update a Python module sounds a bit odd somehow.

I could simply write the values to a file (or a database) and I
suspect that this may be the best answer but it does make retrieving
the values different from getting all other (nearly) constant values.

Are there any Python modules aimed specifically at this sort of
requirement?

Some kind of key/value store sounds like the correct solution. I 
wouldn't go as far a database - that's overkill for a few calibration 
values.


I might suggest TOML, except that Python's tomllib (Python 3.11+) is 
read-only!


Personally, I'd go for lines of:

     key1: value1
     key2: value2

Simple to read, simple to write.


Just go with an .ini file. Simple, well-supported by the standard 
library. And it gives you key/value pairs.


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


Re: How/where to store calibration values - written by program A, read by program B

2023-12-06 Thread Thomas Passin via Python-list

On 12/6/2023 6:35 AM, Barry Scott via Python-list wrote:




On 6 Dec 2023, at 09:32, Chris Green via Python-list  
wrote:

My requirement is *slightly* more complex than just key value pairs,
it has one level of hierarchy, e.g.:-

KEY1:
  a: v1
  c: v3
  d: v4
KEY2:
  a: v7
  b: v5
  d: v6

Different numbers of value pairs under each KEY.


JSON will allow you to nest dictionaries.

{
 'KEY1': {
 'a': v1
 'c': v3
 'd': v4
 }
 'KEY2': {
  'a': v7
  'b': v5
  'd': v6
 }
}

Personally I would not use .ini style these days as the format does not include 
type of the data.


Neither does JSON.  Besides, JSON is more complicated than necessary 
here - in fact, your example isn't even legal JSON since lines are 
missing commas.


Fun fact - for at least some, maybe most, JSON files, using eval() on 
them is hugely faster than using Python's standard JSON library.  I 
learned this when I wanted to ingest a large browser bookmarks JSON 
file. It wouldn't matter for a much smaller file, of course.


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


Re: How/where to store calibration values - written by program A, read by program B

2023-12-06 Thread Thomas Passin via Python-list

On 12/6/2023 1:12 PM, MRAB via Python-list wrote:

On 2023-12-06 12:23, Thomas Passin via Python-list wrote:

On 12/6/2023 6:35 AM, Barry Scott via Python-list wrote:



On 6 Dec 2023, at 09:32, Chris Green via Python-list 
 wrote:


My requirement is *slightly* more complex than just key value pairs,
it has one level of hierarchy, e.g.:-

    KEY1:
  a: v1
  c: v3
  d: v4
    KEY2:
  a: v7
  b: v5
  d: v6

Different numbers of value pairs under each KEY.


JSON will allow you to nest dictionaries.

{
 'KEY1': {
 'a': v1
 'c': v3
 'd': v4
 }
 'KEY2': {
  'a': v7
  'b': v5
  'd': v6
 }
}

Personally I would not use .ini style these days as the format does 
not include type of the data.


Neither does JSON.  Besides, JSON is more complicated than necessary
here - in fact, your example isn't even legal JSON since lines are
missing commas.

Fun fact - for at least some, maybe most, JSON files, using eval() on
them is hugely faster than using Python's standard JSON library.  I
learned this when I wanted to ingest a large browser bookmarks JSON
file. It wouldn't matter for a much smaller file, of course.


It would be safer if you used literal_eval.


He's going to be writing his own calibration data files, though, so it 
should be safe for his purposes.


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


Re: A problem with str VS int.

2023-12-09 Thread Thomas Passin via Python-list

On 12/9/2023 9:42 PM, Steve GS via Python-list wrote:

  If I enter a one-digit input or a three-digit number, the code works but if I 
enter a two digit number, the if statement fails and the else condition 
prevails.

tsReading = input("   Enter the " + Brand + " test strip reading: ")
 if tsReading == "": tsReading = "0"
 print(tsReading)
 if ((tsReading < "400") and (tsReading >= "0")):
 tsDose = GetDose(sReading)
 print(tsReading + "-" + tsDose)
 ValueFailed = False
 else:
 print("Enter valid sensor test strip Reading.")

I converted the variable to int along with the if statement comparison and it 
works as expected.
See if it fails for you...


I don't have to try it to know it will fail.  You think you are 
comparing numbers but you are comparing strings instead, which won't 
work as you expect.


You would do better to convert the inputs and limits to numbers, as well 
as the GetDose() function.  In a more realistic version, you would also 
have to make sure the user input is legal, either an int or a float, 
whichever you want to work with.


And along those lines (a more realistic version), it would be preferable 
to change the limits to be named constants, which will make the code 
easier to understand and change when it's revisited later.  Something 
like this:


UPPER = 400
LOWER = 0
# ...
if LOWER < value < UPPER:
# .

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


Re: IDLE editor suggestion.

2023-12-12 Thread Thomas Passin via Python-list

On 2023-12-12 08:22, Steve GS via Python-list wrote:
> Maybe this already exists but
> I have never seen it in any
> editor that I have used.
>
> It would be nice to have a
> pull-down text box that lists
> all of the searches I have
> used during this session. It
> would make editing a lot
> easier if I could select the
> previous searches rather than
> having to enter it every time.
>
> If this is inappropriate to
> post this here, please tell me
> where to go.
> Life should be so
> complicated.
>
EditPad has this.

So do Notepad++, EditPlus (not free but low cost, Windows only, and very 
good), and I'm sure many others that are much simpler than Visual Studio 
Code, for example.

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


Re: Type hints - am I doing it right?

2023-12-13 Thread Thomas Passin via Python-list

On 12/13/2023 11:17 AM, Mats Wichmann via Python-list wrote:

On 12/13/23 00:19, Frank Millman via Python-list wrote:

I have to add 'import configparser' at the top of each of these 
modules in order to type hint the method.


This seems verbose. If it is the correct way of doing it I can live 
with it, but I wondered if there was an easier way.


Think of import as meaning "make this available in my current (module) 
namespace".


The actual import machinery only runs the first time, that is, if it's 
not already present in the sys.modules dict.


There's also the approach of importing the typing objects conditionally, 
as in this snippet from the Leo Editor 
(https://github.com/leo-editor/leo-editor)


if TYPE_CHECKING:  # pragma: no cover
from leo.core.leoCommands import Commands as Cmdr
from leo.core.leoGui import LeoKeyEvent as Event

Yes, it's more verbose but it makes clear what the intent is.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2023-12-22 Thread Thomas Passin via Python-list

On 12/22/2023 7:36 AM, Sibylle Koczian via Python-list wrote:

Hello,

I always install Python on Windows in the same manner:

- Python is not on the path,
- it is installed for all users,
- the Python Launcher is installed for all users,
- the file types .py, .pyw etc. are associated with Python.

My shebang line is usually "#!/usr/bin/env python3".

This has always worked well. I could run Python scripts in a console
window entering just the script name, by double clicking in the explorer
or using WIN+r; the two last variants for GUI or for scripts with
something like "input('Leave with Enter')" at the end.

Now I've got a new computer with Windows 11 and I've installed Python
3.12.1. On my older machine it's Windows 10 and Python 3.11.5. Reading
the Python documentation it seems my shebang lines should work as before
- but they don't. The error message:

"Unable to create process using 'C:\usr\bin\env\python
"C:\Eigen\Src\launcher_versuche.py" ': Das System kann die angegebene
Datei nicht finden."

Without the "env" in the shebang line and only without it everything
works as expected - but that's contrary to the documentation, isn't it?


How is a path for a linux location going to work on a Windows machine? 
On Windows, when you click on a script the OS tries to find the program 
that has been registered to run that script. Python would not have been 
installed to "C:\usr\bin\env\python".


On my Windows 10 machine, Python scripts run without a shebang line. 
Perhaps Windows 11 has added the ability to use one, but then you would 
need to use the actual location of your Python executable.


If you have several Python installations, it's better to run Python 
scripts using the "py" launcher, because Windows may have the wrong idea 
about which version to use.  The "where" command on my computer shows 
Python 3.9, but I'm actually using Python 12.


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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2023-12-22 Thread Thomas Passin via Python-list

On 12/22/2023 9:29 AM, Sibylle Koczian via Python-list wrote:

Am 22.12.2023 um 14:13 schrieb Barry:



On 22 Dec 2023, at 12:39, Sibylle Koczian via Python-list 
 wrote:


Hello,

I always install Python on Windows in the same manner:

- Python is not on the path,
- it is installed for all users,
- the Python Launcher is installed for all users,
- the file types .py, .pyw etc. are associated with Python.

My shebang line is usually "#!/usr/bin/env python3".

This has always worked well. I could run Python scripts in a console
window entering just the script name, by double clicking in the explorer
or using WIN+r; the two last variants for GUI or for scripts with
something like "input('Leave with Enter')" at the end.

Now I've got a new computer with Windows 11 and I've installed Python
3.12.1. On my older machine it's Windows 10 and Python 3.11.5. Reading
the Python documentation it seems my shebang lines should work as before
- but they don't. The error message:

"Unable to create process using 'C:\usr\bin\env\python
"C:\Eigen\Src\launcher_versuche.py" ': Das System kann die angegebene
Datei nicht finden."

Without the "env" in the shebang line and only without it everything
works as expected - but that's contrary to the documentation, isn't it?


This suggests a typo in the shebang line. Is there a space between env 
and python?


Barry



Tried several variants with the same script:

#!/usr/bin/env python3
# That's how I wrote it for Windows 10 / Python 3.11. It works there.

#!/usr/bin/env python
#!/usr/bin/env/python

The error messages vary a little. This is a German Windows installation,
the two variants with the space produce the same German error message,
the third produces the message I've put into my first description.

The working variant on Windows 11 / Python 3.12 is "#!/usr/bin python".


There is some important context that is missing here.  Python on Windows 
does not normally install to that location.  That is not even a Windows 
path, neither by directory name nor by path separators.


In addition, Powershell and cmd.exe do not use a shebang line, at least 
through Windows 10.  Instead, they use whatever executable has been 
registered for a file extension.  This may or may not be the version you 
think.  On my system, the OS will use Python 3.9, but actually the most 
recent Python version on my system is Python 3.12. I can demonstrate the 
difference:  here is a tiny Python file with a shebang line, called 
showme.py:


#! %USERPROFILE%\AppData\Local\Programs\Python\Python312\python.exe
import sys
print(sys.executable)

Run this with the "py" launcher:
py showme.py
# prints C:\Users\tom\AppData\Local\Programs\Python\Python312\python.exe

Run it by invoking just the script's name:
showme.py
# prints C:\Program Files\Python39\python.exe

In neither case is the shebang line used.

This makes me think that maybe the Linux subsystem for Windows is being 
used here. If so, possibly the syntax for a shebang line has been 
tightened up, or there's a typo.  Either way, I would not automatically 
assume that Windows (at least through Windows 10) ever used the shebang 
line for launching these scripts.




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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2023-12-22 Thread Thomas Passin via Python-list

On 12/22/2023 7:19 PM, Barry wrote:




On 23 Dec 2023, at 00:15, Thomas Passin via Python-list 
 wrote:

In neither case is the shebang line used.


As i understand it, not in front of my windows box to check.
The handler for .py file extension is set to be the py.exe
It is py.exe that understands shebang lines.


Not on my system. It may depend on whether Python gets installed to 
Program Files or to %USERPROFILE%/AppData/Local/Programs/Python.  Python 
3.9 is the last verson I installed to Program Files, and that's the 
version that Windows thinks it should use to run Python files.


Run the little test program I posted.  That will tell you which version 
of Python the system wants to use.

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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2023-12-22 Thread Thomas Passin via Python-list

On 12/22/2023 7:27 PM, Michael Torrie via Python-list wrote:

On 12/22/23 07:02, Thomas Passin via Python-list wrote:

On my Windows 10 machine, Python scripts run without a shebang line.
Perhaps Windows 11 has added the ability to use one, but then you would
need to use the actual location of your Python executable.


Yes if you associate .py or .pyw with python.exe (or pythonw.exe), then
things work as you describe.  However it's no longer recommended to do
that.

Instead---and I think this is the default now when you install
python---you should associate both .py and .pyw files with the py
launcher (py.exe) and it will examine the shebang line of the script and
determine which version of python to run. As I said this should work
regardless of the path listed in the shebang.  Note that the shebang is
meaningless to Windows itself, and Windows Explorer. It is only
meaningful to the py launcher.  So it's customary to just use a
unix-style shebang in your python scripts.  So either #!/usr/bin/python3
or #!/usr/bin/env python3 as you would in unix.

Using the py launcher as your Windows association with .py and.pyw files
you can have multiple versions of python installed and everything works
as it should, according to your shebang, just like on Unix.


I actually don't remember how to set up the association for Python 
files.  I just always type the "py" launcher anyway, as in


py -m pip instal ...

I think that the association with py.exe must only happen if you install 
to Program Files.  As I said in my previous post, Windows still sticks 
with launching Python files with Python 3.9 even though I'm three 
version beyond that.  3.9 is the only one I installed to Program Files.


In my experience one should always make sure to know what version of 
Python is being used, at least if there is more than one version 
installed on the computer.  Even on Linux using a shebang line can be 
tricky, because you are likely to get the system's version of Python, 
and that often is not what you want.  OTOH you don't want to go 
symlinking python3 to some other version of python because then the OS 
system may not work right.  So either you have to specify the Python 
version in the shebang, or just specify the right version on the command 
line.  In that case you might as well not have included the shebang line 
at all.


I may be more sensitive to this issue because I run many different Linux 
distros in VMs to check a few programs I support to make sure they can 
run on Linux as well as Windows.  What Linux, you ask?  Well, who knows 
what our users will use? So I'm always getting Python version 
mix-and-match problems.  The system will still be at Python 3.10 but I 
need Python 3.11.  The system uses Python 3.11 but we shouldn't (or 
cannot) install our dependencies so we need a parallel install.  Etc, etc.


It's just better not to make assumptions about which version of Python 
will be running. Just specify it yourself when you can, and then you can 
be sure.

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


Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list

On 12/29/2023 10:02 AM, Karsten Hilbert via Python-list wrote:

I agree that mypy's grasp of my intent from

queries:list[dict[str, str | list | dict[str, Any]]]=None,

into

"List[Dict[str, Union[str, List[Any], Dict[str, Any"

seems accurate. I just don't understand why list[dict[str,
str]] should not pass that construct.


I made a tiny test program with your type signature, and got this error 
message from mypy:


c:\temp\python\typing_test.py:3: error: X | Y syntax for unions requires 
Python 3.10  [syntax]


Aside from that, this variation causes no mypy error (you must use 
Sequence instead of List), and is also more clear about what you are 
trying to get:


from typing import Union, Sequence, Dict

DictType1 = Dict[str, str]
DictType2 = Dict[str, Sequence]
DictType3 = Dict[str, Dict]
QueryType = Sequence[Union[DictType1, DictType2, DictType3]]

def test_typing(queries:QueryType=None):
print(type(queries))

d1 = {'k1': 'v1', 'k2': 'v2'}
queries = [d1,]
test_typing(queries)

I'm not sure if this captures exactly what you want, but it avoids the 
problem where mypy does not regard str and Union[str, list] as 
equivalent types.  I tested this using Python 3.12.




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


Re: Aw: Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list

On 12/30/2023 10:08 AM, Karsten Hilbert via Python-list wrote:

Dear Thomas,

thanks for taking the time to look into my issue.

Maybe it helps if I explain what I want (sorry that my web mailer does not 
respect
indentation, I will insert dots).

I want a function to run SQL queries:

run_queries(conn, queries):
...for q in queries:
..conn.execute(q)

I now want to add type hints such that my large codebase can
be checked for silly doings. First, queries is to be a list
of the SQL to run:

run_queries(conn, queries:list):

Then, each list entry can be

...a string holding simple, complete SQL (say "SELECT 1")

run_queries(conn, queries:list[str]):

or

...a dict holding the SQL and arguments for parameters

run_queries(conn, queries:list[dict]):

So, taken together:

run_queries(conn, queries:list[str|dict]):

(yes, this is in Python 3.11/3.12)

Now, when it is a list of dicts I want to further constrain the
dicts. Each is to contain the keys "SQL" and "args". So the keys
are of type str. The values for the keys will be of various types,
such that I chose Any as pseudo-type, so that each list entry that
is of type dict should be dict[str, Any], hence:

queries = [{'SQL': 'SELECT %(value)s', 'args': {'value': 1}}]

and

run_queries(conn, queries:list[str|dict[str, Any]]):

If I now call this function with a simple SQL query:

SQL_query = 'SELECT 1'  # should be type str ?
queries = [SQL_query]   # should be type list[str] ?
run_queries(conn, queries = queries)

and run mypy over that (at least inside my complex codebase) I will
get a type mismatch being hinted at.

So far I don't grasp at which point my reasoning above is faulty.

Karsten


I am not very expert in Python type hints.  In working up the example 
program I just posted, I got an error message from mypy that remarked 
that "list" is invariant, and to try Sequence which is "covariant".  I 
don't know what that means (and I haven't looked into it yet), but when 
I changed from list to Sequence as suggested, mypy stopped complaining.


Here is the exact error message, and it has a reference you might want 
to follow up with:


c:\temp\python\typing_test.py:16: note: "List" is invariant -- see 
https://mypy.readthedocs.io/en/stable/common_issues.html#variance
c:\temp\python\typing_test.py:16: note: Consider using "Sequence" 
instead, which is covariant


Before that, mypy insisted that str and Union[str, list] were 
incompatible argument types, which is something you are seeing, too.


I suggest that you build up your types as in my example, so that it's 
very clear what they are and very easy to change them, and use Sequence 
instead of List (or list).  See if that will do the job.


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


Re: Aw: Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list

On 12/30/2023 10:08 AM, Karsten Hilbert via Python-list wrote:

Dear Thomas,

thanks for taking the time to look into my issue.

Maybe it helps if I explain what I want (sorry that my web mailer does not 
respect
indentation, I will insert dots).

I want a function to run SQL queries:

run_queries(conn, queries):
...for q in queries:
..conn.execute(q)

I now want to add type hints such that my large codebase can
be checked for silly doings. First, queries is to be a list
of the SQL to run:

run_queries(conn, queries:list):

Then, each list entry can be

...a string holding simple, complete SQL (say "SELECT 1")

run_queries(conn, queries:list[str]):


It occurs to me that you could simplify things if you converted those 
plain query strings to dicts:


'SELECT 1' --> {'SQL': 'SELECT 1'}

I'm fairly sure your database queries don't actually give you strings or 
dicts, right?  You probably get lists (or iterators) of tuples and 
somewhere you convert them to the arguments you are feeding to 
run_queries().  At least, that is how the standard Python db adapters 
work. If you change that conversion step, your arguments to 
run_queries() will all be lists of dicts, making your code simpler and 
reducing the complexity of the type hints.



or

...a dict holding the SQL and arguments for parameters

run_queries(conn, queries:list[dict]):

So, taken together:

run_queries(conn, queries:list[str|dict]):

(yes, this is in Python 3.11/3.12)

Now, when it is a list of dicts I want to further constrain the
dicts. Each is to contain the keys "SQL" and "args". So the keys
are of type str. The values for the keys will be of various types,
such that I chose Any as pseudo-type, so that each list entry that
is of type dict should be dict[str, Any], hence:

queries = [{'SQL': 'SELECT %(value)s', 'args': {'value': 1}}]

and

run_queries(conn, queries:list[str|dict[str, Any]]):

If I now call this function with a simple SQL query:

SQL_query = 'SELECT 1'  # should be type str ?
queries = [SQL_query]   # should be type list[str] ?
run_queries(conn, queries = queries)

and run mypy over that (at least inside my complex codebase) I will
get a type mismatch being hinted at.

So far I don't grasp at which point my reasoning above is faulty.

Karsten


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


Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list

On 12/29/2023 10:02 AM, Karsten Hilbert via Python-list wrote:

Am Fri, Dec 29, 2023 at 07:49:17AM -0700 schrieb Mats Wichmann via Python-list:


I am not sure why mypy thinks this

gmPG2.py:554: error: Argument "queries" to "run_rw_queries" has incompatible type 
"List[Dict[str, str]]"; expected
"List[Dict[str, Union[str, List[Any], Dict[str, Any"  [arg-type]
 rows, idx = run_rw_queries(link_obj = conn, queries = 
queries, return_data = True)
   
^~~

should be flagged. The intent is for "queries" to be

a list
of dicts
with keys of str
and values of
str OR
list of anything OR
dict with
keys of str
and values of anything

I'd have thunk list[dict[str,str]] matches that ?


Dict[str, str] means the key type and value type should both be strings,


Indeed, I know that much, list[dict[str, str]] is what is getting
passed in in this particular invocation of run_rw_queries().

For what it's worth here's the signature of that function:

def run_rw_queries (
link_obj:_TLnkObj=None,
queries:list[dict[str, str | list | dict[str, Any]]]=None,
end_tx:bool=False,
return_data:bool=None,
get_col_idx:bool=False,
verbose:bool=False
) -> tuple[list[dbapi.extras.DictRow], dict[str, int] | None]:

Given that I would have thought that passing in
list[dict[str, str]] for "queries" ought to be type safe.
Mypy indicates otherwise which I am not grokking as to why.


but in your
retelling above you indicate lots of possible value types... actually the mypy 
guess
seems to be a pretty good recreation of your psuedo-code description.


I agree that mypy's grasp of my intent from

queries:list[dict[str, str | list | dict[str, Any]]]=None,

into

"List[Dict[str, Union[str, List[Any], Dict[str, Any"

seems accurate. I just don't understand why list[dict[str,
str]] should not pass that construct.


Maybe better to ask the mypy people directly.


Karsten
--
GPG  40BE 5B0E C98E 1713 AFA6  5BC0 3BEA AC80 7D4F C89B


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


Re: mypy question

2023-12-30 Thread Thomas Passin via Python-list

On 12/30/2023 9:14 AM, Thomas Passin via Python-list wrote:

On 12/29/2023 10:02 AM, Karsten Hilbert via Python-list wrote:

I agree that mypy's grasp of my intent from

queries:list[dict[str, str | list | dict[str, Any]]]=None,

into

"List[Dict[str, Union[str, List[Any], Dict[str, Any"

seems accurate. I just don't understand why list[dict[str,
str]] should not pass that construct.


I made a tiny test program with your type signature, and got this error 
message from mypy:


c:\temp\python\typing_test.py:3: error: X | Y syntax for unions requires 
Python 3.10  [syntax]


Aside from that, this variation causes no mypy error (you must use 
Sequence instead of List), and is also more clear about what you are 
trying to get:


from typing import Union, Sequence, Dict

DictType1 = Dict[str, str]
DictType2 = Dict[str, Sequence]
DictType3 = Dict[str, Dict]
QueryType = Sequence[Union[DictType1, DictType2, DictType3]]

def test_typing(queries:QueryType=None):
     print(type(queries))

d1 = {'k1': 'v1', 'k2': 'v2'}
queries = [d1,]
test_typing(queries)

I'm not sure if this captures exactly what you want, but it avoids the 
problem where mypy does not regard str and Union[str, list] as 
equivalent types.  I tested this using Python 3.12.


In doing more testing, I have learned that my suggestion above does 
work, *except* that you cannot mix-and-match different DictTypex types 
within the same Sequence - meaning within the same query argument.  Any 
of the Union types is OK but they all have to be the same in any instance.


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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2024-01-01 Thread Thomas Passin via Python-list

On 1/1/2024 6:02 AM, Sibylle Koczian via Python-list wrote:

Am 30.12.2023 um 04:04 schrieb Mike Dewhirst via Python-list:


I had assumed the OP had installed Python from the Microsoft shop and 
that's where py.exe must have come from.




In fact I didn't say in my post that I always get Python from 
python.org. When I started to use the language there was no Python from 
any Microsoft shop (I'm not sure there was a Microsoft shop, it was in 
the last millenium, Python 1.5 or 1.6). So I tend to forget that 
possible download source.


But in all this thread I didn't see a single explanation for my current 
situation: one and the same shebang line works on Windows 10 / Python 
3.11 and doesn't work on Windows 11 / Python 3.12. I suspect Windows, 
because a change in the way Python 3.12 uses shebang lines should be 
visible in the documentation.


Happy new year to all!
Sibylle


Happy New Year!

I speculated that the shebang line didn't work on Windows 10 either, but 
you didn't realize it because the file associations were right to launch 
".py" programs with the right version of Python.  When the newer version 
of Python got installed, the default Python program to use, was not 
updated correctly, and the shebang line still has nothing to do with the 
launch failure.  This could happen if other the older install went into 
Program Files, while the newer one went into 
%USERPROFILE%\AppData\Local\Programs\Python.


This was backed up with all of 5 minutes of experimenting on my own 
computer, on which Windows launches ".py" programs with an old install 
of Python 3.9.9, but the py launcher launches Python 3.12 by default.


Since I am avoiding Windows 11, I can't try anything on it, so my 
thoughts above may not be relevant.


The Python docs for 3.12.1 cover shebang lines at

https://docs.python.org/3/using/windows.html

"If the first line of a script file starts with #!, it is known as a 
“shebang” line. Linux and other Unix like operating systems have native 
support for such lines and they are commonly used on such systems to 
indicate how a script should be executed. This launcher allows the same 
facilities to be used with Python scripts on Windows and the examples 
above demonstrate their use.


To allow shebang lines in Python scripts to be portable between Unix and 
Windows, this launcher supports a number of ‘virtual’ commands to 
specify which interpreter to use. The supported virtual commands are:


/usr/bin/env
/usr/bin/python
/usr/local/bin/python
python

For example, if the first line of your script starts with

#! /usr/bin/python
The default Python will be located and used. As many Python scripts 
written to work on Unix will already have this line, you should find 
these scripts can be used by the launcher without modification. If you 
are writing a new script on Windows which you hope will be useful on 
Unix, you should use one of the shebang lines starting with /usr."


But

"The /usr/bin/env form of shebang line has one further special property. 
Before looking for installed Python interpreters, this form will search 
the executable PATH for a Python executable matching the name provided 
as the first argument. This corresponds to the behaviour of the Unix env 
program, which performs a PATH search. If an executable matching the 
first argument after the env command cannot be found, but the argument 
starts with python, it will be handled as described for the other 
virtual commands. The environment variable PYLAUNCHER_NO_SEARCH_PATH may 
be set (to any value) to skip this search of PATH.


Shebang lines that do not match any of these patterns are looked up in 
the [commands] section of the launcher’s .INI file. This may be used to 
handle certain commands in a way that makes sense for your system. The 
name of the command must be a single argument (no spaces in the shebang 
executable), and the value substituted is the full path to the 
executable (additional arguments specified in the .INI will be quoted as 
part of the filename)."



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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2024-01-01 Thread Thomas Passin via Python-list

On 1/1/2024 8:19 AM, Thomas Passin via Python-list wrote:

On 1/1/2024 6:02 AM, Sibylle Koczian via Python-list wrote:

Am 30.12.2023 um 04:04 schrieb Mike Dewhirst via Python-list:


I had assumed the OP had installed Python from the Microsoft shop and 
that's where py.exe must have come from.




In fact I didn't say in my post that I always get Python from 
python.org. When I started to use the language there was no Python 
from any Microsoft shop (I'm not sure there was a Microsoft shop, it 
was in the last millenium, Python 1.5 or 1.6). So I tend to forget 
that possible download source.


But in all this thread I didn't see a single explanation for my 
current situation: one and the same shebang line works on Windows 10 / 
Python 3.11 and doesn't work on Windows 11 / Python 3.12. I suspect 
Windows, because a change in the way Python 3.12 uses shebang lines 
should be visible in the documentation.


Happy new year to all!
Sibylle


Happy New Year!

I speculated that the shebang line didn't work on Windows 10 either, but 
you didn't realize it because the file associations were right to launch 
".py" programs with the right version of Python.  When the newer version 
of Python got installed, the default Python program to use, was not 
updated correctly, and the shebang line still has nothing to do with the 
launch failure.  This could happen if other the older install went into 
Program Files, while the newer one went into 
%USERPROFILE%\AppData\Local\Programs\Python.


This was backed up with all of 5 minutes of experimenting on my own 
computer, on which Windows launches ".py" programs with an old install 
of Python 3.9.9, but the py launcher launches Python 3.12 by default.


Since I am avoiding Windows 11, I can't try anything on it, so my 
thoughts above may not be relevant.


The Python docs for 3.12.1 cover shebang lines at

https://docs.python.org/3/using/windows.html

"If the first line of a script file starts with #!, it is known as a 
“shebang” line. Linux and other Unix like operating systems have native 
support for such lines and they are commonly used on such systems to 
indicate how a script should be executed. This launcher allows the same 
facilities to be used with Python scripts on Windows and the examples 
above demonstrate their use.


To allow shebang lines in Python scripts to be portable between Unix and 
Windows, this launcher supports a number of ‘virtual’ commands to 
specify which interpreter to use. The supported virtual commands are:


/usr/bin/env
/usr/bin/python
/usr/local/bin/python
python

For example, if the first line of your script starts with

#! /usr/bin/python
The default Python will be located and used. As many Python scripts 
written to work on Unix will already have this line, you should find 
these scripts can be used by the launcher without modification. If you 
are writing a new script on Windows which you hope will be useful on 
Unix, you should use one of the shebang lines starting with /usr."


But

"The /usr/bin/env form of shebang line has one further special property. 
Before looking for installed Python interpreters, this form will search 
the executable PATH for a Python executable matching the name provided 
as the first argument. This corresponds to the behaviour of the Unix env 
program, which performs a PATH search. If an executable matching the 
first argument after the env command cannot be found, but the argument 
starts with python, it will be handled as described for the other 
virtual commands. The environment variable PYLAUNCHER_NO_SEARCH_PATH may 
be set (to any value) to skip this search of PATH.


Shebang lines that do not match any of these patterns are looked up in 
the [commands] section of the launcher’s .INI file. This may be used to 
handle certain commands in a way that makes sense for your system. The 
name of the command must be a single argument (no spaces in the shebang 
executable), and the value substituted is the full path to the 
executable (additional arguments specified in the .INI will be quoted as 
part of the filename)."




Here's how to find out what program Windows thinks it should use to run 
a ".py" file.  In a console:


C:\Users\tom>assoc .py
.py=Python.File

C:\Users\tom>ftype Python.file
Python.file="C:\Windows\py.exe" "%L" %*

If your ".py" files are associated to the py.exe launcher, as mine are, 
then the launcher may try to use your shebang line and you need to make 
sure there aren't any spaces where there shouldn't be.


If your ".py" files are not associated with py.exe, the shebang line 
probably won't be used for anything.



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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2024-01-01 Thread Thomas Passin via Python-list

On 1/1/2024 12:26 PM, Mats Wichmann via Python-list wrote:

On 1/1/24 07:11, Thomas Passin via Python-list wrote:

Here's how to find out what program Windows thinks it should use to 
run a ".py" file.  In a console:


C:\Users\tom>assoc .py
.py=Python.File

C:\Users\tom>ftype Python.file
Python.file="C:\Windows\py.exe" "%L" %*


That's not enough. There is now (has been for a while) a layered system, 
and this gives you just one layer, there may be other associations that 
win out.


Per somebody who actually knows:

 > The only way to determine the association without reimplmenting the 
shell's search is to simply ask the shell via AssocQueryString. Possibly 
PowerShell can provide this information. – Eryk Sun


"Possibly", eh?  In fact, on my system those layers must be in effect, 
since ftype claims that the "py" launcher will be used but in actual 
fact the old Python 3.9.9 is used instead, as I wrote earlier.  This is 
verified by this tiny Python script:


# Optional shebang line here
import sys
print(sys.executable)

Then run it with "py", a proposed shebang line, its plain name on the 
command line, whatever.  That will tell you for sure which Python 
executable gets launched by which technique.


On Windows 10, a shebang line gets ignored in favor of Python 3.9.9 (if 
invoked by the script name alone) or Python 3.12.1 (if invoked by the 
"py" launcher).


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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2024-01-02 Thread Thomas Passin via Python-list

On 1/2/2024 11:56 AM, Mats Wichmann via Python-list wrote:

On 1/1/24 12:53, Thomas Passin via Python-list wrote:

On Windows 10, a shebang line gets ignored in favor of Python 3.9.9 
(if invoked by the script name alone) or Python 3.12.1 (if invoked by 
the "py" launcher).


fwiw, you can also create an ini file to define to the launcher py which 
version should be the default, if no version is specified.


You might learn about this if you happen to read and remember the right 
part of the Python docs.  Otherwise you have no idea what py.exe is up 
to nor how it does it.  I would say that most people don't know there's 
an ini file, let alone what it can do.  Of course this situation isn't 
unique to py.exe!


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


Re: Using my routines as functions AND methods

2024-01-03 Thread Thomas Passin via Python-list

On 1/3/2024 11:17 PM, Thomas Passin wrote:

On 1/3/2024 8:00 PM, Alan Gauld via Python-list wrote:

On 03/01/2024 22:47, Guenther Sohler via Python-list wrote:

Hi,

In my cpython i have written quite some functions to modify "objects".
and their python syntax is e.g.\

translate(obj, vec). e.g whereas obj is ALWAYS first argument.


However, I also want to use these functions as class methods without 
having

to
write the function , twice. When using the SAME function as a methos, 
the

args tuple must insert/contain "self" in the first location, so i have
written a function to do that:


I'm probably missing something obvious here but can't you
just assign your function to a class member?

def myFunction(obj, ...): ...

class MyClass:
 myMethod = myFunction


Then you can call it as

myObject = MyClass()
myObject.myMethod()

A naive example seems to work but I haven't tried anything
complex so there is probably a catch. But sometimes the simple
things just work?


That works if you assign the function to a class instance, but not if 
you assign it to a class.


def f1(x):
     print(x)
f1('The plain function')

class Class1:
     pass

class Class2:
     pass

c1 = Class1()
c1.newfunc = f1
c1.newfunc('f1 assigned to instance') # Works as intended

Class2.newfunc = f1
c2 = Class2()
c2.newfunc('f1 assigned to class')  # Complains about extra argument


If your requirements are not very tricky, you can write a 
convert-to-method function yourself:


def f1(x):
print(x)
f1('The plain function')

class Class2:
pass

def convert_method(f):
"""Assign existing method without a "self" arg
   as a class's method.
"""
def fnew(instance, *args):
f(*args)
return fnew

Class2.newfunc = convert_method(f1)
c2 = Class2()
c2.newfunc('f1 assigned as method of Class2') # Prints the arg

This example does not make f1 aware of the self argument, but you asked 
to convert an existing function, and that function would not be aware of 
the self parameter. It's much like a decorator function, but is not here 
being used as a decorator. If you meant something else, please think out 
what you want and explain that.


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


Re: Using my routines as functions AND methods

2024-01-04 Thread Thomas Passin via Python-list

On 1/3/2024 8:00 PM, Alan Gauld via Python-list wrote:

On 03/01/2024 22:47, Guenther Sohler via Python-list wrote:

Hi,

In my cpython i have written quite some functions to modify "objects".
and their python syntax is e.g.\

translate(obj, vec). e.g whereas obj is ALWAYS first argument.



However, I also want to use these functions as class methods without having
to
write the function , twice. When using the SAME function as a methos, the
args tuple must insert/contain "self" in the first location, so i have
written a function to do that:


I'm probably missing something obvious here but can't you
just assign your function to a class member?

def myFunction(obj, ...): ...

class MyClass:
 myMethod = myFunction


Then you can call it as

myObject = MyClass()
myObject.myMethod()

A naive example seems to work but I haven't tried anything
complex so there is probably a catch. But sometimes the simple
things just work?


That works if you assign the function to a class instance, but not if 
you assign it to a class.


def f1(x):
print(x)
f1('The plain function')

class Class1:
pass

class Class2:
pass

c1 = Class1()
c1.newfunc = f1
c1.newfunc('f1 assigned to instance') # Works as intended

Class2.newfunc = f1
c2 = Class2()
c2.newfunc('f1 assigned to class')  # Complains about extra argument


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


Re: Extract lines from file, add to new files

2024-01-11 Thread Thomas Passin via Python-list

On 1/11/2024 1:27 PM, MRAB via Python-list wrote:

On 2024-01-11 18:08, Rich Shepard via Python-list wrote:

It's been several years since I've needed to write a python script so I'm
asking for advice to get me started with a brief script to separate names
and email addresses in one file into two separate files: 
salutation.txt and

emails.txt.

An example of the input file:

Calvin
cal...@example.com

Hobbs
ho...@some.com

Nancy
na...@herown.com

Sluggo
slu...@another.com

Having extracted salutations and addresses I'll write a bash script using
sed and mailx to associate a message file with each name and email 
address.


I'm unsure where to start given my lack of recent experience.


 From the look of it:

1. If the line is empty, ignore it.

2. If the line contains "@", it's an email address.

3. Otherwise, it's a name.


You could think about a single Python script that looks through your 
input file and constructs all the message files without ever writing 
separate salutation and address files at all.  Then you wouldn't need to 
write the sed and mailx scripts.  It shouldn't be much harder than 
peeling out the names and addresses into separate files.


If you haven't written any Python for some years, the preferred way to 
read and write files is using a "with" statement, like this:


with open('email_file.txt', encoding = 'utf-8') as f:
lines = f.readlines()
for line in lines:
if not line.strip():  # Skip blank lines
continue
# Do something with this line

You don't need to close the file because when the "with" block ends the 
file will be closed for you.


If the encoding is not utf-8 and you know what it will be, use that 
encoding instead.


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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2024-01-14 Thread Thomas Passin via Python-list

On 1/14/2024 7:48 AM, Sibylle Koczian via Python-list wrote:

Am 09.01.2024 um 12:36 schrieb Barry Scott via Python-list:



On 7 Jan 2024, at 15:09, Sibylle Koczian via Python-list 
 wrote:


Oh, and the two Windows and Python versions are on two different 
computers.


Will remove the "/env" from my shebang lines, even if I don't 
understand what's happening.


Thanks for the details.

Only thing I can think of is that "python" may be defaulting to mean 
python 2.

If you use "#!/usr/bin/env python3" it may work on both.


No, it doesn't. That's the form I started with. When it didn't work I 
thought "python3" might be too old, because Python 2 is dead for so long.


Did you creates a py.ini file to configure py.exe?

See if you have %userappdata%\py.ini on either windows 10 or windows 11.
If so what is its contents?


No to both.


I've tried with and without a py.ini and cannot duplicate what you see.



It really seems strange. Only thing I can think of - and I don't really 
believe in that idea: as far as I know in Windows 11 the handling of 
PATH has changed. My Python isn't on the path, perhaps that is it. A 
shebang line without "/env" doesn't check the path, right?


From what I've read recently, if you have a Python program that starts 
with a shebang line with any of four standard unix-like paths, then 
Python (not Windows) will look for a version of Python in standard 
locations - *NOT* in the shebang line locations:


"To allow shebang lines in Python scripts to be portable between Unix 
and Windows, this launcher supports a number of ‘virtual’ commands to 
specify which interpreter to use. The supported virtual commands are:


/usr/bin/env
/usr/bin/python
/usr/local/bin/python
python
"

Also -
"The /usr/bin/env form of shebang line has one further special property. 
Before looking for installed Python interpreters, this form will search 
the executable PATH for a Python executable matching the name provided 
as the first argument. This corresponds to the behaviour of the Unix env 
program, which performs a PATH search. If an executable matching the 
first argument after the env command cannot be found, but the argument 
starts with python, it will be handled as described for the other 
virtual commands.

"

There are some other complications, too, depending on whether you 
specify bare "python" or some specific version. The form with 
"/usr/bin/env" is the closest to the unix behavior, in that it searches 
the PATH.  And you write that your intended version of Python is not on 
the path.


IOW, these shebang lines don't work the way you seem to think that they do.

See https://docs.python.org/3/using/windows.html for a more complete 
rundown.

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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2024-01-14 Thread Thomas Passin via Python-list

On 1/14/2024 8:54 AM, Thomas Passin via Python-list wrote:

On 1/14/2024 7:48 AM, Sibylle Koczian via Python-list wrote:

Am 09.01.2024 um 12:36 schrieb Barry Scott via Python-list:



On 7 Jan 2024, at 15:09, Sibylle Koczian via Python-list 
 wrote:


Oh, and the two Windows and Python versions are on two different 
computers.


Will remove the "/env" from my shebang lines, even if I don't 
understand what's happening.


Thanks for the details.

Only thing I can think of is that "python" may be defaulting to mean 
python 2.

If you use "#!/usr/bin/env python3" it may work on both.


No, it doesn't. That's the form I started with. When it didn't work I 
thought "python3" might be too old, because Python 2 is dead for so long.


Did you creates a py.ini file to configure py.exe?

See if you have %userappdata%\py.ini on either windows 10 or windows 11.
If so what is its contents?


No to both.


I've tried with and without a py.ini and cannot duplicate what you see.



It really seems strange. Only thing I can think of - and I don't 
really believe in that idea: as far as I know in Windows 11 the 
handling of PATH has changed. My Python isn't on the path, perhaps 
that is it. A shebang line without "/env" doesn't check the path, right?


 From what I've read recently, if you have a Python program that starts 
with a shebang line with any of four standard unix-like paths, then 
Python (not Windows) will look for a version of Python in standard 
locations - *NOT* in the shebang line locations:


I meant to write "the Python launcher", that is, the "py" program. 
Normal Python installs on Windows install the launcher and Windows will 
run it on ".py" files if no other program has been specified on the 
command line.


"To allow shebang lines in Python scripts to be portable between Unix 
and Windows, this launcher supports a number of ‘virtual’ commands to 
specify which interpreter to use. The supported virtual commands are:


/usr/bin/env
/usr/bin/python
/usr/local/bin/python
python
"

Also -
"The /usr/bin/env form of shebang line has one further special property. 
Before looking for installed Python interpreters, this form will search 
the executable PATH for a Python executable matching the name provided 
as the first argument. This corresponds to the behaviour of the Unix env 
program, which performs a PATH search. If an executable matching the 
first argument after the env command cannot be found, but the argument 
starts with python, it will be handled as described for the other 
virtual commands.

"

There are some other complications, too, depending on whether you 
specify bare "python" or some specific version. The form with 
"/usr/bin/env" is the closest to the unix behavior, in that it searches 
the PATH.  And you write that your intended version of Python is not on 
the path.


IOW, these shebang lines don't work the way you seem to think that they do.

See https://docs.python.org/3/using/windows.html for a more complete 
rundown.


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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2024-01-15 Thread Thomas Passin via Python-list

On 1/15/2024 1:26 PM, Mats Wichmann via Python-list wrote:

On 1/15/24 09:44, Sibylle Koczian via Python-list wrote:


First and foremost I want to understand why I'm seeing this:

- Python scripts with "/usr/bin/env python3" as shebang line work as 
expected on a computer with Windows 10 and Python 3.11.5. They have 
worked for years on this machine, using either the latest Python or 
one version before (depending on availability of some packages). There 
is a virtual machine with ArchLinux on the same machine and some of 
the scripts are copies from that.


- I've got a second computer with Windows 11 and I installed Python 
3.12.1 on it. After copying some scripts from my first computer I 
found that I couldn't start them: not by entering the script name in a 
console, not using py.exe, not double clicking in the explorer. 
Entering \python  probably worked 
- I think I tried that too, but I'm not really sure, because that's 
really not practical.


In the Python documentation for versions 3.11 and 3.12 I found no 
differences regarding py.exe and shebang lines.


Then I removed the "/env" from the shebang lines and could start the 
scripts from the second computer. That certainly is a solution, but 
why???


It's because of Windows itself.  The default nowadays is that irritating 
little stub that prompts you to go install Python from the WIndows 
store.  When you use the "env" form, it looks for python (or python3 in 
your case) in the PATH *first* and you'll get a hit.   Mine looks like:


C:\Users\mats\AppData\Local\Microsoft\WindwsApps\python.exe and python3.exe

you can check what it's doing for you by using the "where" command in a 
windows shell.


On your older Windows 10 machine you either never had that stub - I 
don't know when it was added, maybe someone from Microsoft listening 
here knows - or it's been superseded by changes to the PATH, or 
something.  On my fairly new Win 11 box the base of that path is early 
in the user portion of PATH, so that must be a default.


py.exe without the "/usr/bin/env" magic doesn't put PATH searching 
first, according to that snip from the docs that's been posted here 
several times., so you shouldn't fall down that particular rathole.


Python from the App Store is not the same as Python from python.org:

"The Microsoft Store package is a simple installation of Python that is 
suitable for running scripts and packages, and using IDLE or other 
development environments. It requires Windows 10 and above, but can be 
safely installed without corrupting other programs. It also provides 
many convenient commands for launching Python and its tools."


- https://docs.python.org/3/using/windows.html

Also:

"The Windows Store distribution of Python is a sandboxed application ... 
The internal components of Windows Store apps are protected from being 
accessed from other applications, and so the PyXLL add-in cannot use the 
Python DLLs and packages that are installed as part of the Windows Store 
Python app."


From the PyXLL support site -

https://support.pyxll.com/hc/en-gb/articles/4417634326675-Python-installed-via-the-Windows-Store-cannot-be-used-with-PyXLL

The "py" launcher is installed by the installer from python.org.




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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2024-01-15 Thread Thomas Passin via Python-list

On 1/15/2024 6:27 PM, Greg Ewing via Python-list wrote:

On 16/01/24 11:55 am, Mats Wichmann wrote:
Windows natively has something called python.exe and python3.exe which 
is interfering here


I'm wondering whether py.exe should be taught to recognise these stubs
and ignore them. This sounds like something that could trip a lot of
people up.


There are registry entries that say where all the python.org install 
locations are.  I suppose, but don't know, that py.exe checks them.  The 
registry entries are inComputer\HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore


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


Re: Question about garbage collection

2024-01-15 Thread Thomas Passin via Python-list

On 1/15/2024 9:47 PM, Akkana Peck via Python-list wrote:

I wrote:

Also be warned that some modules (particularly if they're based on libraries 
not written in Python) might not garbage collect, so you may need to use other 
methods of cleaning up after those objects.


Chris Angelico writes:

Got any examples of that?


The big one for me was gdk-pixbuf, part of GTK. When you do something like 
gtk.gdk.pixbuf_new_from_file(), there's a Python object that gets created, but 
there's also the underlying C code that allocates memory for the pixbuf. When 
the object went out of scope, the Python object was automatically garbage 
collected, but the pixbuf data leaked.


This kind of thing can happen with PyQt, also.  There are ways to 
minimize it but I don't know if you can ever be sure all Qt C++ objects 
will get deleted. It depends on the type of object and the circumstances.



Calling gc.collect() caused the pixbuf data to be garbage collected too.

There used to be a post explaining this on the pygtk mailing list: the link was
http://www.daa.com.au/pipermail/pygtk/2003-December/006499.html
but that page is gone now and I can't seem to find any other archives of that 
list (it's not on archive.org either). And this was from GTK2; I never checked 
whether the extra gc.collect() is still necessary in GTK3, but I figure leaving 
it in doesn't hurt anything. I use pixbufs in a tiled map application, so there 
are a lot of small pixbufs being repeatedly read and then deallocated.

 ...Akkana


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


Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more

2024-01-15 Thread Thomas Passin via Python-list

On 1/15/2024 7:24 PM, Thomas Passin wrote:

On 1/15/2024 6:27 PM, Greg Ewing via Python-list wrote:

On 16/01/24 11:55 am, Mats Wichmann wrote:
Windows natively has something called python.exe and python3.exe 
which is interfering here


I'm wondering whether py.exe should be taught to recognise these stubs
and ignore them. This sounds like something that could trip a lot of
people up.


There are registry entries that say where all the python.org install 
locations are.  I suppose, but don't know, that py.exe checks them.  The 
registry entries are 
in Computer\HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore


For python.org installs that are installed for all users, the entries are in

Computer\HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore

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


Re: Question about garbage collection

2024-01-16 Thread Thomas Passin via Python-list

On 1/16/2024 4:17 AM, Barry wrote:




On 16 Jan 2024, at 03:49, Thomas Passin via Python-list 
 wrote:

This kind of thing can happen with PyQt, also.  There are ways to minimize it 
but I don't know if you can ever be sure all Qt C++ objects will get deleted. 
It depends on the type of object and the circumstances.


When this has been seen in the past it has been promptly fixed by the 
maintainer.


The usual advice is to call deleteLater() on objects derived from PyQt 
classes.  I don't know enough about PyQt to know if this takes care of 
all dangling reference problems, though.


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


Re: How to replace a cell value with each of its contour cells and yield the corresponding datasets seperately in a list according to a Pandas-way?

2024-01-21 Thread Thomas Passin via Python-list

On 1/21/2024 7:37 AM, marc nicole via Python-list wrote:

Hello,

I have an initial dataframe with a random list of target cells (each cell
being identified with a couple (x,y)).
I want to yield four different dataframes each containing the value of one
of the contour (surrounding) cells of each specified target cell.

the surrounding cells to consider for a specific target cell are : (x-1,y),
(x,y-1),(x+1,y);(x,y+1), specifically I randomly choose 1 to 4 cells from
these and consider for replacement to the target cell.

I want to do that through a pandas-specific approach without having to
define the contour cells separately and then apply the changes on the
dataframe 


1. Why do you want a Pandas-specific approach?  Many people would rather 
keep code independent of special libraries if possible;


2. How big can these collections of target cells be, roughly speaking? 
The size could make a big difference in picking a design;


3. You really should work on formatting code for this list.  Your code 
below is very complex and would take a lot of work to reformat to the 
point where it is readable, especially with the nearly impenetrable 
arguments in some places.  Probably all that is needed is to replace all 
tabs by (say) three spaces, and to make sure you intentionally break 
lines well before they might get word-wrapped.  Here is one example I 
have reformatted (I hope I got this right):


list_tuples_idx_cells_all_datasets = list(filter(
   lambda x: utils_tuple_list_not_contain_nan(x),
   [list(tuples) for tuples in list(
 itertools.product(*target_cells_with_contour))
   ]))

4. As an aside, it doesn't look like you need to convert all those 
sequences and iterators to lists all over the place;




(but rather using an all in one approach):
for now I have written this example which I think is not Pandas specific:

[snip]

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


Re: How to replace a cell value with each of its contour cells and yield the corresponding datasets seperately in a list according to a Pandas-way?

2024-01-21 Thread Thomas Passin via Python-list

On 1/21/2024 11:54 AM, marc nicole wrote:

Thanks for the reply,

I think using a Pandas (or a Numpy) approach would optimize the 
execution of the program.


Target cells could be up to 10% the size of the dataset, a good example 
to start with would have from 10 to 100 values.


Thanks for the reformatted code.  It's much easier to read and think about.

For say 100 points, it doesn't seem that "optimization" would be much of 
an issue.  On my laptop machine and Python 3.12, your example takes 
around 5 seconds to run and print().  OTOH if you think you will go to 
much larger datasets, certainly execution time could become a factor.


I would think that NumPy arrays and/or matrices would have good potential.

Is this some kind of a cellular automaton, or an image filtering process?


Let me know your thoughts, here's a reproducible example which I formatted:



from numpy import random
import pandas as pd
import numpy as np
import operator
import math
from collections import deque
from queue import *
from queue import Queue
from itertools import product


def select_target_values(dataframe, number_of_target_values):
     target_cells = []
     for _ in range(number_of_target_values):
         row_x = random.randint(0, len(dataframe.columns) - 1)
         col_y = random.randint(0, len(dataframe) - 1)
         target_cells.append((row_x, col_y))
     return target_cells


def select_contours(target_cells):
     contour_coordinates = [(0, 1), (1, 0), (0, -1), (-1, 0)]
     contour_cells = []
     for target_cell in target_cells:
         # random contour count for each cell
         contour_cells_count = random.randint(1, 4)
         try:
             contour_cells.append(
                 [
                     tuple(
                         map(
                             lambda i, j: i + j,
                             (target_cell[0], target_cell[1]),
                             contour_coordinates[iteration_],
                         )
                     )
                     for iteration_ in range(contour_cells_count)
                 ]
             )
         except IndexError:
             continue
     return contour_cells


def create_zipf_distribution():
     zipf_dist = random.zipf(2, size=(50, 5)).reshape((50, 5))

     zipf_distribution_dataset = pd.DataFrame(zipf_dist).round(3)

     return zipf_distribution_dataset


def apply_contours(target_cells, contour_cells):
     target_cells_with_contour = []
     # create one single list of cells
     for idx, target_cell in enumerate(target_cells):
         target_cell_with_contour = [target_cell]
         target_cell_with_contour.extend(contour_cells[idx])
         target_cells_with_contour.append(target_cell_with_contour)
     return target_cells_with_contour


def create_possible_datasets(dataframe, target_cells_with_contour):
     all_datasets_final = []
     dataframe_original = dataframe.copy()

     list_tuples_idx_cells_all_datasets = list(
         filter(
             lambda x: x,
             [list(tuples) for tuples in 
list(product(*target_cells_with_contour))],

         )
     )
     target_original_cells_coordinates = list(
         map(
             lambda x: x[0],
             [
                 target_and_contour_cell
                 for target_and_contour_cell in target_cells_with_contour
             ],
         )
     )
     for dataset_index_values in list_tuples_idx_cells_all_datasets:
         all_datasets = []
         for idx_cell in range(len(dataset_index_values)):
             dataframe_cpy = dataframe.copy()
             dataframe_cpy.iat[
                 target_original_cells_coordinates[idx_cell][1],
                 target_original_cells_coordinates[idx_cell][0],
             ] = dataframe_original.iloc[
                 dataset_index_values[idx_cell][1], 
dataset_index_values[idx_cell][0]

             ]
             all_datasets.append(dataframe_cpy)
         all_datasets_final.append(all_datasets)
     return all_datasets_final


def main():
     zipf_dataset = create_zipf_distribution()

     target_cells = select_target_values(zipf_dataset, 5)
     print(target_cells)
     contour_cells = select_contours(target_cells)
     print(contour_cells)
     target_cells_with_contour = apply_contours(target_cells, contour_cells)
     datasets = create_possible_datasets(zipf_dataset, 
target_cells_with_contour)

     print(datasets)


main()

Le dim. 21 janv. 2024 à 16:33, Thomas Passin via Python-list 
mailto:python-list@python.org>> a écrit :


On 1/21/2024 7:37 AM, marc nicole via Python-list wrote:
 > Hello,
 >
 > I have an initial dataframe with a random list of target cells
(each cell
 > being identified with a couple (x,y)).
 > I want to yield four different dataframes each containing the
value of one
 > of the contour (surrounding) cells of each specified target cell.
 >
 > the surrounding cells 

Re: How to replace a cell value with each of its contour cells and yield the corresponding datasets seperately in a list according to a Pandas-way?

2024-01-21 Thread Thomas Passin via Python-list

On 1/21/2024 1:25 PM, marc nicole wrote:
It is part of a larger project aiming at processing data according to a 
given algorithm

Do you have any comments or any enhancing recommendations on the code?


I'm not knowledgeable enough about either pandas or numpy, I'm afraid, 
just very basic usage.  Someone else will probably pitch in.



Thanks.

Le dim. 21 janv. 2024 à 18:28, Thomas Passin via Python-list 
mailto:python-list@python.org>> a écrit :


On 1/21/2024 11:54 AM, marc nicole wrote:
 > Thanks for the reply,
 >
 > I think using a Pandas (or a Numpy) approach would optimize the
 > execution of the program.
 >
 > Target cells could be up to 10% the size of the dataset, a good
example
 > to start with would have from 10 to 100 values.

Thanks for the reformatted code.  It's much easier to read and think
about.

For say 100 points, it doesn't seem that "optimization" would be
much of
an issue.  On my laptop machine and Python 3.12, your example takes
around 5 seconds to run and print().  OTOH if you think you will go to
much larger datasets, certainly execution time could become a factor.

I would think that NumPy arrays and/or matrices would have good
potential.

Is this some kind of a cellular automaton, or an image filtering
process?

 > Let me know your thoughts, here's a reproducible example which I
formatted:
 >
 >
 >
 > from numpy import random
 > import pandas as pd
 > import numpy as np
 > import operator
 > import math
 > from collections import deque
 > from queue import *
 > from queue import Queue
 > from itertools import product
 >
 >
 > def select_target_values(dataframe, number_of_target_values):
 >      target_cells = []
 >      for _ in range(number_of_target_values):
 >          row_x = random.randint(0, len(dataframe.columns) - 1)
 >          col_y = random.randint(0, len(dataframe) - 1)
 >          target_cells.append((row_x, col_y))
 >      return target_cells
 >
 >
 > def select_contours(target_cells):
 >      contour_coordinates = [(0, 1), (1, 0), (0, -1), (-1, 0)]
 >      contour_cells = []
 >      for target_cell in target_cells:
 >          # random contour count for each cell
 >          contour_cells_count = random.randint(1, 4)
 >          try:
 >              contour_cells.append(
 >                  [
 >                      tuple(
 >                          map(
 >                              lambda i, j: i + j,
 >                              (target_cell[0], target_cell[1]),
 >                              contour_coordinates[iteration_],
 >                          )
 >                      )
 >                      for iteration_ in range(contour_cells_count)
 >                  ]
 >              )
 >          except IndexError:
 >              continue
 >      return contour_cells
 >
 >
 > def create_zipf_distribution():
 >      zipf_dist = random.zipf(2, size=(50, 5)).reshape((50, 5))
 >
 >      zipf_distribution_dataset = pd.DataFrame(zipf_dist).round(3)
 >
 >      return zipf_distribution_dataset
 >
 >
 > def apply_contours(target_cells, contour_cells):
 >      target_cells_with_contour = []
 >      # create one single list of cells
 >      for idx, target_cell in enumerate(target_cells):
 >          target_cell_with_contour = [target_cell]
 >          target_cell_with_contour.extend(contour_cells[idx])
 >          target_cells_with_contour.append(target_cell_with_contour)
 >      return target_cells_with_contour
 >
 >
 > def create_possible_datasets(dataframe, target_cells_with_contour):
 >      all_datasets_final = []
 >      dataframe_original = dataframe.copy()
 >
 >      list_tuples_idx_cells_all_datasets = list(
 >          filter(
 >              lambda x: x,
 >              [list(tuples) for tuples in
 > list(product(*target_cells_with_contour))],
 >          )
 >      )
 >      target_original_cells_coordinates = list(
 >          map(
 >              lambda x: x[0],
 >              [
 >                  target_and_contour_cell
 >                  for target_and_contour_cell in
target_cells_with_contour
 >              ],
 >          )
 >      )
 >      for dataset_index_values in list_tuples_idx_cells_all_datasets:
 >          all_datasets = []
 >          for 

Re: Extract lines from file, add to new files

2024-01-29 Thread Thomas Passin via Python-list

On 1/29/2024 11:15 AM, Rich Shepard via Python-list wrote:

For my use 1) the salutation and email address (always with an '@') are
sequential and 2) I'm developing the script to extract both from the same
file.


I've looked at my Python books "Python Crash Course," "Effective Python,"
and "Python Tricks The Book" as well as web pages in my searches without
finding the answer to what may be a simple question: how to specify a
variable in one file that has its values in another file.

Specifically, how to I designate the salutation holder in the message file
and pass it the name value from the name/email address file?

If this explanation is not sufficiently clear I'll re-write it. :-)

TIA,

Rich


I'm assuming this is a continuation of a previous thread about working 
with alternate lines with salutation and address, and I assume you've 
got that worked out.


If you aren't going to use one or another existing template system, 
perhaps the easiest is to use unique strings in the message file.  For 
example:


Dear __##so-and-so##__:
   Please don't write this message off as mere spam.
   Respectfully, Rich

Then you just do a replace of the unique string by the salutation. Don't 
change the original (i.e., template), make the changes to a copy that 
you will output.


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


Re: Extract lines from file, add to new files

2024-01-30 Thread Thomas Passin via Python-list

On 1/30/2024 8:37 AM, Rich Shepard via Python-list wrote:

On Mon, 29 Jan 2024, Thomas Passin via Python-list wrote:


If you aren't going to use one or another existing template system,
perhaps the easiest is to use unique strings in the message file. For
example:

Dear __##so-and-so##__:
  Please don't write this message off as mere spam.
  Respectfully, Rich

Then you just do a replace of the unique string by the salutation. Don't
change the original (i.e., template), make the changes to a copy that you
will output.


My script is not a web application, but an emailer that allows me to 
contact

clients and prospective clients. From the command line on a linux host.
Using the python smtplib and mail modules.

Rich


Fine, my toy example will still be applicable.  But, you know, you 
haven't told us enough to give you help.  Do you want to replace text 
from values in a file?  That's been covered. Do you want to send the 
messages using those libraries?  You haven't said what you don't know 
how to do.  Something else? What is it that you want to do that you 
don't know how?


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


Re: Extract lines from file, add to new files

2024-01-30 Thread Thomas Passin via Python-list

On 1/30/2024 12:21 PM, Rich Shepard via Python-list wrote:

On Tue, 30 Jan 2024, Thomas Passin via Python-list wrote:


Fine, my toy example will still be applicable. But, you know, you haven't
told us enough to give you help. Do you want to replace text from values
in a file? That's been covered. Do you want to send the messages using
those libraries? You haven't said what you don't know how to do. 
Something

else? What is it that you want to do that you don't know how?


Thomas,

For 30 years I've used a bash script using mailx to send messages to a list
of recipients. They have no salutation to personalize each one. Since I 
want

to add that personalized salutation I decided to write a python script to
replace the bash script.

I have collected 11 docs explaining the smtplib and email modules and
providing example scripts to apply them to send multiple individual 
messages

with salutations and attachments.


If I had a script that's been working for 30 years, I'd probably just 
use Python to do the personalizing and let the rest of the bash script 
do the rest, like it always has.  The Python program would pipe or send 
the personalized messages to the rest of the bash program. Something in 
that ballpark, anyway.



Today I'm going to be reading these. They each recommend using .csv input
files for names and addresses. My first search is learning whether I can
write a single .csv file such as:
"name1","address1"
"mane2","address2"
which I believe will work; and by inserting at the top of the message block
Hi, {yourname}
the name in the .csv file will replace the bracketed place holder
If the file contents are going to be people's names and email addresses, 
I would just tab separate them and split each line on the tab.  Names 
aren't going to include tabs so that would be safe.  Email addresses 
might theoretically include a tab inside a quoted name but that would be 
extremely obscure and unlikely.  No need for CSV, it would just add 
complexity.


data = f.readlines()
for d in data:
name, addr = line.split('\t') if line.strip() else ('', '')

Still much to learn and the batch of downloaded PDF files should educate 
me.


Regards,

Rich


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


Re: Extract lines from file, add to new files

2024-01-31 Thread Thomas Passin via Python-list

On 1/30/2024 11:25 PM, avi.e.gr...@gmail.com wrote:

Thomas, on some points we may see it differently.


I'm mostly going by what the OP originally asked for back on Jan 11. 
He's been too stingy with information since then to be worth spending 
much time on, IMHO.



Some formats can be done simply but are maybe better done in somewhat
standard ways.

Some of what the OP has is already tables in a database and that can
trivially be exported into a CSV file or other formats like your TSV file
and more. They can also import from there. As I mentioned, many spreadsheets
and all kinds of statistical programs tend to support some formats making it
quite flexible.

Python has all kinds of functionality, such as in the pandas module, to read
in a CSV or write it out. And once you have the data structure in memory, al
kinds of queries and changes can be made fairly straightforwardly. As one
example, Rich has mentioned wanting finer control in selecting who gets some
version of the email based on concepts like market segmentation. He already
may have info like the STATE (as in Arizona) in his database. He might at
some point enlarge his schema so each entry is placed in one or more
categories and thus his CSV, once imported, can do the usual tasks of
selecting various rows and columns or doing joins or whatever.

Mind you, another architecture could place quite a bit of work completely on
the back end and he could send SQL queries to the database from python and
get back his results into python which would then make the email messages
and pass them on to other functionality to deliver. This would remove any
need for files and just rely on the DB.

There as as usual, too many choices and not necessarily one best answer. Of
course if this was a major product that would be heavily used, sure, you
could tweak and optimize. As it is, Rich is getting a chance to improve his
python skills no matter which way he goes.



-Original Message-
From: Python-list  On
Behalf Of Thomas Passin via Python-list
Sent: Tuesday, January 30, 2024 10:37 PM
To: python-list@python.org
Subject: Re: Extract lines from file, add to new files

On 1/30/2024 12:21 PM, Rich Shepard via Python-list wrote:

On Tue, 30 Jan 2024, Thomas Passin via Python-list wrote:


Fine, my toy example will still be applicable. But, you know, you haven't
told us enough to give you help. Do you want to replace text from values
in a file? That's been covered. Do you want to send the messages using
those libraries? You haven't said what you don't know how to do.
Something
else? What is it that you want to do that you don't know how?


Thomas,

For 30 years I've used a bash script using mailx to send messages to a

list

of recipients. They have no salutation to personalize each one. Since I
want
to add that personalized salutation I decided to write a python script to
replace the bash script.

I have collected 11 docs explaining the smtplib and email modules and
providing example scripts to apply them to send multiple individual
messages
with salutations and attachments.


If I had a script that's been working for 30 years, I'd probably just
use Python to do the personalizing and let the rest of the bash script
do the rest, like it always has.  The Python program would pipe or send
the personalized messages to the rest of the bash program. Something in
that ballpark, anyway.


Today I'm going to be reading these. They each recommend using .csv input
files for names and addresses. My first search is learning whether I can
write a single .csv file such as:
"name1","address1"
"mane2","address2"
which I believe will work; and by inserting at the top of the message

block

Hi, {yourname}
the name in the .csv file will replace the bracketed place holder

If the file contents are going to be people's names and email addresses,
I would just tab separate them and split each line on the tab.  Names
aren't going to include tabs so that would be safe.  Email addresses
might theoretically include a tab inside a quoted name but that would be
extremely obscure and unlikely.  No need for CSV, it would just add
complexity.

data = f.readlines()
for d in data:
  name, addr = line.split('\t') if line.strip() else ('', '')


Still much to learn and the batch of downloaded PDF files should educate
me.

Regards,

Rich




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


Re: Extract lines from file, add to new files

2024-01-31 Thread Thomas Passin via Python-list

On 1/31/2024 9:05 AM, Rich Shepard via Python-list wrote:

On Tue, 30 Jan 2024, Thomas Passin via Python-list wrote:


If I had a script that's been working for 30 years, I'd probably just use
Python to do the personalizing and let the rest of the bash script do the
rest, like it always has. The Python program would pipe or send the
personalized messages to the rest of the bash program. Something in that
ballpark, anyway.


Thomas,

A bash shell script looks easier for me and more promising. Using a while
loop (one for the name file the other for the address file), and sed for
putting the name at the head of the message replacing a generic placeholder
should work with the existing for loop script.


Sounds good.  I'd still be a bit worried about the two files getting out 
of sync, as others have mentioned.


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


Re: Extract lines from file, add to new files

2024-02-03 Thread Thomas Passin via Python-list
In my view this whole thread became murky and complicated because the OP 
did not write down the requirements for the program.  Requirements are 
needed to communicate with other people.  An individual may not need to 
actually write down the requirements - depending on their complexity - 
but they always exist even if only vaguely in a person's mind.  The 
requirements may include what tools or languages the person wants to use 
and why.


If you are asking for help, you need to communicate the requirements to 
the people you are asking for help from.


The OP may have thought the original post(s) contained enough of the 
requirements but as we know by now, they didn't.


The person asking for help may not realize they don't know enough to 
write down all the requirements; an effort to do so may bring that lack 
to visibility.


Mailing lists like these have a drawback that it's hard to impossible 
for someone not involved in a thread to learn anything general from it. 
We can write over and over again to please state clearly what you want 
to do and where the sticking points are, but newcomers post new 
questions without ever reading these pleas.  Then good-hearted people 
who want to be helpful end up spending a lot of time trying to guess 
what is actually being asked for, and maybe never find out with enough 
clarity.  Others take a guess and then spend time working up a solution 
that may or may not be on target.


So please! before posting a request for help, write down the 
requirements as best you can figure them out, and then make sure that 
they are expressed such that the readers can understand.


On 2/3/2024 11:33 AM, avi.e.gr...@gmail.com wrote:

Thomas,

I have been thinking about the concept of being stingy with information as
this is a fairly common occurrence when people ask for help. They often ask
for what they think they want while people like us keep asking why they want
that and perhaps offer guidance on how to get closer to what they NEED or a
better way.

In retrospect, Rich did give all the info he thought he needed. It boiled
down to saying that he wants to distribute data into two files in such a way
that finding an item in file A then lets him find the corresponding item in
file B. He was not worried about how to make the files or what to do with
the info afterward. He had those covered and was missing what he considered
a central piece. And, it seems he programs in multiple languages and
environments as needed and is not exactly a newbie. He just wanted a way to
implement his overall design.

We threw many solutions and ideas at him but some of us (like me) also got
frustrated as some ideas were not received due to one objection or another
that had not been mentioned earlier when it was not seen as important.

I particularly notice a disconnect some of us had. Was this supposed to be a
search that read only as much as needed to find something and stopped
reading, or a sort of filter that returned zero or more matches and went to
the end, or perhaps something that read entire files and swallowed them into
data structures in memory and then searched and found corresponding entries,
or maybe something else?

All the above approaches could work but some designs not so much. For
example, some files are too large. We, as programmers, often consciously or
unconsciously look at many factors to try to zoom in on what approaches me
might use. To be given minimal amounts of info can be frustrating. We worry
about making a silly design. But the OP may want something minimal and not
worry as long as it is fairly easy to program and works.

We could have suggested something very simple like:

Open both files A and B
In a loop get a line from each. If the line from A is a match, do something
with the current line from B.
If you are getting only one, exit the loop.

Or, if willing, we could have suggested any other file format, such as a
CSV, in which the algorithm is similar but different as in:

Open file A
Read a line in a loop
Split it in parts
If the party of the first part matches something, use the party of the
second part

Or, of course, suggest they read the entire file, into a list of lines or a
data.frame and use some tools that search all of it and produce results.

I find I personally now often lean toward the latter approach but ages ago
when memory and CPU were considerations and maybe garbage collection was not
automatic, ...


-Original Message-
From: Python-list  On
Behalf Of Thomas Passin via Python-list
Sent: Wednesday, January 31, 2024 7:25 AM
To: python-list@python.org
Subject: Re: Extract lines from file, add to new files

On 1/30/2024 11:25 PM, avi.e.gr...@gmail.com wrote:

Thomas, on some points we may see it differently.


I'm mostly going by what the OP originally asked for back on Jan 11.
He's been too stingy with information since then to be worth spending
much time on, IMHO.


Some formats can be done simply but are maybe be

Re: Extract lines from file, add to new files

2024-02-03 Thread Thomas Passin via Python-list

On 2/3/2024 5:02 PM, dn via Python-list wrote:
Every trainer, in any field, has to deal with these problems - all the 
time, and over-and-over.



On 4/02/24 06:58, Thomas Passin via Python-list wrote:
In my view this whole thread became murky and complicated because the 
OP did not write down the requirements for the program.  Requirements 
are needed to communicate with other people.  An individual may not 
need to actually write down the requirements - depending on their 
complexity - but they always exist even if only vaguely in a person's 
mind.  The requirements may include what tools or languages the person 
wants to use and why.


If you are asking for help, you need to communicate the requirements 
to the people you are asking for help from.


The OP may have thought the original post(s) contained enough of the 
requirements but as we know by now, they didn't.


There is another possible interpretation in such situations (not 
necessarily this one): that the person is fixated on a particular 
solution (and unable/unwilling to adjust his/her thinking to consider 
more widely).


Thus, the question is not: 'here's an entire problem, how can it be 
solved', but more: 'I have a solution, and want help to implement it 
(and only it) just-so'.



The latter is an interesting psychology:

1
an experienced person who is trying to translate from one tool to 
another (Python), but discovers that a word-for-word solution is 
difficult because of the artificial-constraints they've placed on the 
situation.


2
a beginner who doesn't know what (s)he doesn't know and comes-up with an 
idea, but fails to appreciate that there is likely more than one path to 
the goal.



The person asking for help may not realize they don't know enough to 
write down all the requirements; an effort to do so may bring that 
lack to visibility.


In the case of 'Beginners' this should probably be taken-as-read!

Which is why we will always find ourselves asking questions or 'please 
give more information'...



However, there are other reasons, eg corporate concerns or personality; 
why people don't want to give more information. The former is reasonable 
(have suffered from same myself). The latter may reveal that the person 
is 'difficult to deal with'...



Mailing lists like these have a drawback that it's hard to impossible 
for someone not involved in a thread to learn anything general from 
it. We can write over and over again to please state clearly what you 
want to do and where the sticking points are, but newcomers post new 
questions without ever reading these pleas.  Then good-hearted people 
who want to be helpful end up spending a lot of time trying to guess 
what is actually being asked for, and maybe never find out with enough 
clarity.  Others take a guess and then spend time working up a 
solution that may or may not be on target.


So please! before posting a request for help, write down the 
requirements as best you can figure them out, and then make sure that 
they are expressed such that the readers can understand.


Unfortunately, if the person doesn't understand the problem (leave-aside 
any ideas of solution), then (s)he will not be able to clearly 
communicate same to us, in any way, shape, or form...


Which brings one to the question: if a person cannot express the problem 
clearly and completely, is (s)he suited to development work? If the 
problem is not understood, could 'the solution' ever be more than an 
exercise in hope?

(prototyping and experimentation aside)


Pairs programming can be fun and productive, if you are lucky to have 
the right person to work with.  I've had one person like that over the 
years.


Yes, it is frustrating to invest time and effort in helping someone, 
only for same to disappear 'into a black hole'. The lack of response 
seems to indicate a lack of respect or appreciation. Is this perhaps 
part of today's "consumer" life-style, where so few are contributors or 
creators?



On the other side of that coin: do the people who make assumptions and 
(kindly) blaze-ahead with 'a solution', actually help the conversation? 
If the assumptions are correct, yes! What if they are not?



...and don't get me started on folk who want us to do their 
training-assignments or build some application, for them!



As a slight aside: on one training-course DiscussionList/BulletinBoard 
set-up, if a trainee asked a question without a descriptive 
title/SubjectLine, eg "Python not working" or "Urgent: please help"; I 
asked them to re-post with a title that would help others in a similar 
situation find the topic - and closed the original thread.


Some found it "brutal" - probably skewing towards those who felt 
"Urgent" because they'd left things too close to deadline. Others joi

Re: Testing (sorry)

2024-02-18 Thread Thomas Passin via Python-list

On 2/18/2024 6:09 PM, Grant Edwards via Python-list wrote:

On 2024-02-18, Peter J. Holzer via Python-list  wrote:

[Replying to the list *and* Grant]

On 2024-02-17 19:38:04 -0500, Grant Edwards via Python-list wrote:

Today I noticed that nothing I've posted to python-list in past 3
weeks has shown up on the list.


January 29th, AFAICS. And end of december before that.


I don't know how to troubleshoot this other than sending test
messages.  Obviously, if this shows up on the list, then I've gotten
it to work...


This did show up and 3 other test messages with very similar text
as well.

Also there was a whole flurry of almost but not quite identical messages
from you in the "nan" thread.


Sorry about that.

All of those were posted at various times throughout the day yesterday
using two different accounts, two different mail servers, and three
different methods for submitting the e-mails.  I finally gave up and
switched to using comp.lang.python via Usenet.

Then, about 24 hours later, all those messages finally showed up.

At one point about half way through that process yesterday, I
unsusbscribed and then re-subscribed both e-mail addresses.  I got
confirmation and welcome messages on both accounts.  Sending "help"
requests to the list server produced the expected results. I enabled
the sending of confirmation messages from the list server.

But posts to the list still seemed to vanish into the ether while
emails from both accounts reached other destinations without delay,

During this process a number of posts from other users did appear in
the list archive and at at _one_ of the two e-mail addresses which I
had subscribed.

But no sign of any of my posts.

About 24 hours later, all of my posts (and the confirmation e-mails)
all showed up in a burst at the same time on two different unrelated
e-mail accounts.

I still have no clue what was going on...


Sometimes a post of mine will not show up for hours or even half a day. 
They are all addressed directly to the list.  Sometimes my email 
provider sends me a notice that the message bounced.  Those notices say 
that the address wasn't available when the transmission was tried.


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


Re: Testing (sorry)

2024-02-19 Thread Thomas Passin via Python-list

On 2/19/2024 9:17 AM, Grant Edwards via Python-list wrote:

On 2024-02-19, Thomas Passin  wrote:


About 24 hours later, all of my posts (and the confirmation e-mails)
all showed up in a burst at the same time on two different unrelated
e-mail accounts.

I still have no clue what was going on...


Sometimes a post of mine will not show up for hours or even half a day.
They are all addressed directly to the list.  Sometimes my email
provider sends me a notice that the message bounced.  Those notices say
that the address wasn't available when the transmission was tried.


Here is a typical bounce message that I get:

: host mail.python.org[188.166.95.178] said: 
450-4.3.2

Service currently unavailable 450 4.3.2

Some time after I get one of these messages I re-send the post.  Usually 
it gets through then.



I guess that in future I'll wait a couple days before I assume
something is broken.

--
Grant



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


Re: Testing (sorry)

2024-02-19 Thread Thomas Passin via Python-list

On 2/19/2024 11:55 AM, Skip Montanaro wrote:

Here is a typical bounce message that I get:

mailto:python-list@python.org>>: host
mail.python.org [188.166.95.178] said:
450-4.3.2
      Service currently unavailable 450 4.3.2

Some time after I get one of these messages I re-send the post. 
Usually

it gets through then.


Looks kinda like greylisting to me. I'm pretty sure that's one of the 
tool in the mail.python.org  chain.


I don't see it as greylisting.  A repeat post will succeed, before there 
would be time for my email provider (Dreamhost) to do anything about it.


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


Re: Problem resizing a window and button placement

2024-02-24 Thread Thomas Passin via Python-list

On 2/24/2024 3:20 AM, Steve GS via Python-list wrote:

Yes, I ran that elegantly
simple code. The print
statement reports the X, Y,
Height and Width values.
However, I do not see how to
capture the width value.

  I experimented with the code
Vwidth = rootV.winfo_width()
and it also reports the width
as I resize the window.

However, I cannot seem to use
the variable Vwidth outside
the sub routine. It is acting
as if Vwidth is not global but
I added that.  It is reported
that Vwidth is not defined
when I try to use it in my
code.


Well, yes, in Python a variable created inside a function or method is 
local to that function unless you declare it global. That characteristic 
is called its "scope". But if you think you need it to be a global 
variable you should rethink your design. For one thing, before the next 
time you use your global variable the window size may have changed again.


Instead, it would be better to have the function that responds to the 
resize event perform the action that you want, or call another function 
that does, passing the new width to it.


Note that in most programming languages, variables have a scope.  The 
rules about those scopes vary between languages.




So close..
SGA

-Original Message-
From: Barry

Sent: Saturday, February 24,
2024 3:04 AM
To: Steve GS

Cc: MRAB
;
python-list@python.org
Subject: Re: Problem resizing
a window and button placement




On 24 Feb 2024, at 04:36,

Steve GS via Python-list

wrote:


How do I extract the values
from args?


You can look up the args in
documentation.
You can run the example code
MRAB provided and see what is
printed to learn what is in
the args.

Barry




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


Re: Problem resizing a window and button placement

2024-02-24 Thread Thomas Passin via Python-list

On 2/24/2024 9:51 PM, Steve GS via Python-list wrote:
First of all, please make sure that the formatting is readable and 
especially the indentation.  This is Python, after all.


Do not use tabs; use 3 or 4 spaces instead of each tab.

import tkinter as tk

#global Ww  Neither global
helps
def on_configure(*args):
# print(args)
  #global Ww  Neither
global helps
  Ww = root.winfo_width()
  print("WwInside = <" +
str(Ww) + ">")

root = tk.Tk()
root.bind('',
on_configure)
print("WwOutside = <" +
str(Ww) + ">")
#NameError: name 'Ww' is not
defined


The function that declares Ww hasn't run yet. As I wrote earlier, the 
function bound to the callback should do all the work for the callback, 
or it should call other functions that do.  That's if you don't let a 
layout do it all for you, as others have written.



root.mainloop()

SGA

-Original Message-
From: Python-list
 On
Behalf Of MRAB via Python-list
Sent: Saturday, February 24,
2024 7:49 PM
To: python-list@python.org
Subject: Re: Problem resizing
a window and button placement

On 2024-02-25 00:33, Steve GS
via Python-list wrote:

"Well, yes, in Python a
variable created inside a
function or method is local

to

that function unless you
declare it global."

Yes, I knew that. I tried to
global it both before the
function call and within it.
Same for when I created the
variable. If I try to use it
in the rest of the code, it
keeps coming up as not
declared.  In other

functions,

I can 'return' the variable
but that apparently would

not

work for this function.

Is this type of function any
different that that which I
have been using?


Please post a short example
that shows the problem.



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


Re: Problem resizing a window and button placement

2024-02-25 Thread Thomas Passin via Python-list

On 2/25/2024 4:19 PM, Steve GS via Python-list wrote:

SOLUTION FOUND!

The fix was to write the code that uses the width value and to place it into 
the function itself.
Kluge? Maybe but it works.


Right, just what I wrote earlier:

"have the function that responds to the resize event perform the action 
that you want"



Mischief Managed.


As for the most recent suggestion, it fails for me:

Traceback (most recent call last):
   File "F:/___zInsulin Code A 08-02-23/WinPic/IOWw.pyw", line 14, in 
 print("Ww Outside = <" + str(Ww) > + ">")
TypeError: bad operand type for unary +: 'str'

With the need to close the window, it adds an extra step and intervention to 
the program to use. I am not sure how this help[s.

As a curio, it would be interesting to see how to use the value of a variable, 
created in the function used here, and make it available to the code outside 
the function.



SGA

-Original Message-
From: Alan Gauld 
Sent: Sunday, February 25, 2024 12:44 PM
To: Steve GS ; python-list@python.org
Subject: Re: RE: Problem resizing a window and button placement

On 25/02/2024 03:58, Steve GS via Python-list wrote:
import tkinter as tk

Ww = None

def on_configure(*args):
global Ww
Ww = root.winfo_width()
print("Ww Inside = <" + str(Ww) + ">")

root = tk.Tk()
root.bind('', on_configure)
root.mainloop()

print("Ww Outside = <" + str(Ww) > + ">")

Produces:
Ww Inside = <200>
Ww Inside = <200>
Ww Inside = <205>
Ww Inside = <205>
Ww Inside = <206>
Ww Inside = <206>
Ww Outside = <206>

HTH



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


Re: Problem resizing a window and button placement

2024-02-26 Thread Thomas Passin via Python-list

On 2/26/2024 6:02 AM, Steve GS via Python-list wrote:

Although your code produces the value of Ww outside the function, I do not see 
how I can use the value of Ww unless I close the program.


The configuration event hasn't fired at the time you include the print 
statement in the handler's def block, and therefore the print function 
inside your handler hasn't invoked.  It won't be invoked until you 
resize the window.


There is no point to saving the width and height outside your 
on_configure() function, because outside that function you can't know if 
they have been changed.  There could even have been a race condition 
where you use one but the other changes before you get around to using 
it.  It's better just to ask tk for the values whenever you need them, 
as you do inside your handler.



import tkinter as tk

Ww = None  # What does this do? Why not Integer?
WwZ = None

# These could be integers, like 0, but that would not be the correct
# window sizes at that point. The window is either not constructed or it
# has some definite size that is not zero.


def on_configure(*args):
 global Ww
 global WwZ
 Ww = root.winfo_width()
 print("9  Ww Inside =<"+str(Ww)+">")  # works
 WwZ = Ww * 2
 print("11  WwZ Inside =<"+str(WwZ)+">")  # works
 return(Ww)  #Can I use this?
 
root = tk.Tk()

root.bind('',on_configure)
print("15  Ww Inside1 = <"+str(Ww)+">")
#Ww2 = int(Ww) * 2  # fails
print("17  WwZ Inside2 = <"+str(WwZ)+">")

root.mainloop()

Ww2 = int(Ww) * 2  #Works but only after the program stops
print("21  Ww Outside2 = <"+str(WwZ)+">")
# Can I have concentric loops?


SGA

-Original Message-
From: Alan Gauld 
Sent: Monday, February 26, 2024 4:04 AM
To: Steve GS ; python-list@python.org
Subject: Re: RE: Problem resizing a window and button placement

On 26/02/2024 07:56, Steve GS via Python-list wrote:


Then there is that discovery
element: Why is my original
idea not working? I still
cannot pass the value back
from the function.  What is
different about this function
that others would have given
me the value?


There is nothing different, see the code below.
print() is a function like any other.
In this case it is called after you close the window, ie after mainloop() exits.
But any other function called inside
mainloop - eg any other event handler can also access it.

For example, if you added a button:

def printW(): print("Button Ww = ", Ww)

bw = tk.Button(root, text="Print Width", command=printW)
bw.pack()

You would be able to print the value on demand.


import tkinter as tk

Ww = None

def on_configure(*args):
 global Ww
 Ww = root.winfo_width()
 print("Ww Inside =<"+str(Ww)+">")

root = tk.Tk()
root.bind('',on_configure)
root.mainloop()

print("Ww Outside = <"+str(Ww)+">")


--
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


  1   2   >