Re: Trying to use pyinstaller under python 3.11, and, recently started receiving error message about specific module/distribution

2024-04-04 Thread Jacob Kruger via Python-list
Ok, had received response on pyinstaller mailing list, but, also just 
related to trying clean uninstall/reinstall of modules, but, while 
checking that out, something else occurred to me, and, it now operates 
as it should.



Anyway, what seemed to be causing issue was actually that, since, while 
am working under windows 11, quite often you might need to work with 
case-sensitivity in file names, not by choice, but, since a lot of 
target platforms, like linux, etc. are case-sensitive, and, at times, 
when working with external modules, this might cause hassles, etc.



In other words, the folder/directory where all my python source code is 
stored is set to be case-sensitive - there are a couple of ways to 
implement this under windows 10 and windows 11, via some external 
utilities, or by running the following command from a 
terminal/power-shell window, running it as administrator:


fsutil.exe file SetCaseSensitiveInfo C:\folder\path enable


If you instead use disable argument at the end, it then disables 
case-sensitivity, and, what did now was, under current project/test 
code, I created an additional sub-folder, copied code files, etc. over 
into it, disabled case-sensitivity on it, recreated the virtual 
environment, and installed all required modules, including pyinstaller 
using pip, and, when I then run pyinstaller from there, it works fine, 
and, does what I want it to.



In other words, something to do with having case-sensitivity enabled 
recursively on the folder/directory containing the code and the virtual 
environment seemed to be causing these errors/issues, specific to 
altgraph, which doesn't really make sense to me, but, it's now working, 
so, will archive this to memory, for later reference.



Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


On 2024/04/02 17:11, Barry wrote:



On 1 Apr 2024, at 15:52, Jacob Kruger via Python-list  
wrote:

Found many, many mentions of errors, with some of the same keywords, but, no 
resolutions that match my exact issue at all.

Try asking the pyinstaller developers. I think there is a mailing list.

Barry


As in, most of them are mentioning older versions of python, and, mainly 
different platforms - mac and linux, but, various google searches have not 
mentioned much of using it on windows, and having it just stop working.


Now did even try shifting over to python 3.12, but, still no-go.


If launch pyinstaller under python 3.10 on this exact same machine, pyinstaller 
runs - just keep that older version hovering around for a couple of occasional 
tests, partly since some of my target environments are still running older 
versions of python, but anyway.


Also, not really relevant, but, cx_freeze is perfectly able to generate 
executables for this same code, but, then not combining all output into a 
single file - will stick to that for now, but, not always as convenient, and, 
still wondering what changed here.


Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."



On 2024/03/31 14:51, Barry wrote:


On 31 Mar 2024, at 13:24, Jacob Kruger via Python-list  
wrote:

pkg_resources.DistributionNotFound: The 'altgraph' distribution was not found 
and is required by the application

I think I have seen this error being discussed before…

A web search for pyinstaller and that error leads to people discussing why it 
happens it looks like.

Barry



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

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


Re: Trying to use pyinstaller under python 3.11, and, recently started receiving error message about specific module/distribution

2024-04-03 Thread Jacob Kruger via Python-list
Ok, last update for now - checked out the following page on 
pyinstaller.org, and, ended up posting to the mailing list, so, let's see:


https://pyinstaller.org/en/latest/when-things-go-wrong.html


Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


On 2024/04/02 17:11, Barry wrote:



On 1 Apr 2024, at 15:52, Jacob Kruger via Python-list  
wrote:

Found many, many mentions of errors, with some of the same keywords, but, no 
resolutions that match my exact issue at all.

Try asking the pyinstaller developers. I think there is a mailing list.

Barry


As in, most of them are mentioning older versions of python, and, mainly 
different platforms - mac and linux, but, various google searches have not 
mentioned much of using it on windows, and having it just stop working.


Now did even try shifting over to python 3.12, but, still no-go.


If launch pyinstaller under python 3.10 on this exact same machine, pyinstaller 
runs - just keep that older version hovering around for a couple of occasional 
tests, partly since some of my target environments are still running older 
versions of python, but anyway.


Also, not really relevant, but, cx_freeze is perfectly able to generate 
executables for this same code, but, then not combining all output into a 
single file - will stick to that for now, but, not always as convenient, and, 
still wondering what changed here.


Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."



On 2024/03/31 14:51, Barry wrote:


On 31 Mar 2024, at 13:24, Jacob Kruger via Python-list  
wrote:

pkg_resources.DistributionNotFound: The 'altgraph' distribution was not found 
and is required by the application

I think I have seen this error being discussed before…

A web search for pyinstaller and that error leads to people discussing why it 
happens it looks like.

Barry



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

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


Re: Trying to use pyinstaller under python 3.11, and, recently started receiving error message about specific module/distribution

2024-04-01 Thread Jacob Kruger via Python-list
Found many, many mentions of errors, with some of the same keywords, 
but, no resolutions that match my exact issue at all.



As in, most of them are mentioning older versions of python, and, mainly 
different platforms - mac and linux, but, various google searches have 
not mentioned much of using it on windows, and having it just stop working.



Now did even try shifting over to python 3.12, but, still no-go.


If launch pyinstaller under python 3.10 on this exact same machine, 
pyinstaller runs - just keep that older version hovering around for a 
couple of occasional tests, partly since some of my target environments 
are still running older versions of python, but anyway.



Also, not really relevant, but, cx_freeze is perfectly able to generate 
executables for this same code, but, then not combining all output into 
a single file - will stick to that for now, but, not always as 
convenient, and, still wondering what changed here.



Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


On 2024/03/31 14:51, Barry wrote:



On 31 Mar 2024, at 13:24, Jacob Kruger via Python-list  
wrote:

pkg_resources.DistributionNotFound: The 'altgraph' distribution was not found 
and is required by the application

I think I have seen this error being discussed before…

A web search for pyinstaller and that error leads to people discussing why it 
happens it looks like.

Barry



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


Trying to use pyinstaller under python 3.11, and, recently started receiving error message about specific module/distribution

2024-03-31 Thread Jacob Kruger via Python-list
This started happening this past week, and, while it's worked fine in 
the past, the moment I try to launch the pyinstaller process at all, to 
generate compiled output, or even if just launch it with no command line 
options, I receive the following error message:


pkg_resources.DistributionNotFound: The 'altgraph' distribution was not 
found and is required by the application



The full contents of the output string when I even try to just launch 
pyinstaller with no commands/arguments is the following:


Traceback (most recent call last):
  File "", line 198, in _run_module_as_main
  File "", line 88, in _run_code
  File 
"C:\pythonScripts\monitoring_nssm\venv\Scripts\pyinstaller.exe\__main__.py", 
line 7, in 
  File 
"C:\pythonScripts\monitoring_nssm\venv\Lib\site-packages\PyInstaller\__main__.py", 
line 228, in _console_script_run

run()
  File 
"C:\pythonScripts\monitoring_nssm\venv\Lib\site-packages\PyInstaller\__main__.py", 
line 170, in run

    parser = generate_parser()
^
  File 
"C:\pythonScripts\monitoring_nssm\venv\Lib\site-packages\PyInstaller\__main__.py", 
line 136, in generate_parser

    import PyInstaller.building.build_main
  File 
"C:\pythonScripts\monitoring_nssm\venv\Lib\site-packages\PyInstaller\building\build_main.py", 
line 28, in 

    from PyInstaller.building.api import COLLECT, EXE, MERGE, PYZ
  File 
"C:\pythonScripts\monitoring_nssm\venv\Lib\site-packages\PyInstaller\building\api.py", 
line 32, in 
    from PyInstaller.building.splash import Splash  # argument type 
validation in EXE

^^
  File 
"C:\pythonScripts\monitoring_nssm\venv\Lib\site-packages\PyInstaller\building\splash.py", 
line 23, in 

    from PyInstaller.depend import bindepend
  File 
"C:\pythonScripts\monitoring_nssm\venv\Lib\site-packages\PyInstaller\depend\bindepend.py", 
line 25, in 

    from PyInstaller.depend import dylib, utils
  File 
"C:\pythonScripts\monitoring_nssm\venv\Lib\site-packages\PyInstaller\depend\utils.py", 
line 31, in 

    from PyInstaller.lib.modulegraph import modulegraph
  File 
"C:\pythonScripts\monitoring_nssm\venv\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", 
line 34, in 

    from altgraph.ObjectGraph import ObjectGraph
  File 
"C:\pythonScripts\monitoring_nssm\venv\Lib\site-packages\altgraph\__init__.py", 
line 144, in 

    __version__ = pkg_resources.require("altgraph")[0].version
^
  File 
"C:\pythonScripts\monitoring_nssm\venv\Lib\site-packages\pkg_resources\__init__.py", 
line 952, in require

    needed = self.resolve(parse_requirements(requirements))
^^
  File 
"C:\pythonScripts\monitoring_nssm\venv\Lib\site-packages\pkg_resources\__init__.py", 
line 813, in resolve

    dist = self._resolve_dist(
^^^
  File 
"C:\pythonScripts\monitoring_nssm\venv\Lib\site-packages\pkg_resources\__init__.py", 
line 854, in _resolve_dist

    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'altgraph' distribution was not 
found and is required by the application


# ---end of output---


I have tried completely removing python's installation, and, 
reinstalling it, but, same issue more or less immediately.



If I freeze pip's installed list within this specific virtual 
environment, it lists the following:


altgraph==0.17.4
packaging==24.0
pefile==2023.2.7
pyinstaller==6.5.0
pyinstaller-hooks-contrib==2024.3
pywin32-ctypes==0.2.2

# ---end of requirements.txt---


And, if, just for testing, I launch python interpreter, and, ask it to 
import altgraph, it provides the same last line of error output?



If relevant, running with python 3.11.8, under windows 11 64-bit, and, 
can't think of anything that specifically occurred/changed this past 
week, besides normal things like windows updates, etc., but, don't 
really think that's likely to be relevant, unless something to do with 
pywin32 has caused an issue?



Should I try installing python 3.12 version instead and see if it changes?


Also, if relevant, while running under latest up-to-date version of 
windows 11 64 bit, have in any case enabled case-sensitivity on the 
folder I store all my python code in, just in case.



TIA

--

Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


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


Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-07 Thread Jacob Kruger via Python-list

Thanks again, all.


I think the python -i scoping2.py would have given me a good beginning 
as well - will archive that one for use.



And, to maybe explain how I work - not an excuse at all - but, I am 
actually 100% blind, so a lot of the IDE's, or their common 
means/methods of interaction don't suit me all the time, which is why I 
generally work via programmer's text editor interfaces, or treat 
something like VS code as such, but then still prefer to run my code via 
command line, using pdb to then play around with forms of debugging, etc.



And, yes, also generally prefer to work via classes, modules, etc. at 
runtime, but this was more or less mostly testing, which then caused 
confusion/interference on my side...LOL!



Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


On 2024/03/07 03:55, Grant Edwards via Python-list wrote:

On 2024-03-07, dn via Python-list  wrote:


The idea of importing a module into the REPL and then (repeatedly)
manually entering the code to set-up and execute is unusual (surely type
such into a script (once), and run that (repeatedly). As you say, most
of us would be working from an IDE and hitting 'Run'. Am wondering why
you weren't - but it's not important.

Unless the code is intended to be used as a module, 'import'ing it into
the REPL doesn't make sense.

A simple example:

---testit.py--
x = 'x'
y = 'y'
def foo():
 global y
 print("hi")
 x = 'X'
 y = 'Y'
 print(x)
 print(y)
--

The usual method to play with that interactively is

 $ python -i testit.py
 >>> x
 'x'
 >>> y
 'y'
 >>> foo()
 hi
 X
 Y
 >>> x
 'x'
 >>> y
 'Y'
 >>>

As we've seen, doing a 'from testit.py import *' doesn't let you test
what the OP was trying to test. Doing 'import testit.py' gets you
closer, but it's a hassle to test code that way. The right thing to do
is 'python -i ' (or the equivalent button/option in an IDE).

   https://docs.python.org/3/tutorial/interpreter.html

If you intended to use testit.py as a module, and wanted to experiment
with its behavior as a module, then go ahead and import it. But, don't
do 'from testit.py import *' until

  1. you know how that differs from 'import testit.py'

and

  2. you want to use that difference



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


Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
Ok, Ethan, that makes sense - I generally work with modules in folders, 
etc., but, this was just test code, but, 'see' if I instead import 
scoping2 as sc2, and then refer to sc2.dt_expiry and sc2.do_it, then it 
does operate as it should - thanks, again.



Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


On 2024/03/06 18:57, Ethan Furman via Python-list wrote:

On 3/6/24 08:28, Jacob Kruger via Python-list wrote:

> C:\temp\py_try>python
> Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec  4 2023, 19:24:49) [MSC 
v.1937 64 bit (AMD64)] on win32

> Type "help", "copyright", "credits" or "license" for more information.
>  >>> from scoping2 import *

And it becomes clear:  only do `from ... import *` when the module has 
been specifically designed to support that.


If you were to also do `import scoping2` and, after calling `do_it()`, 
`print(scoping2.dt_expiry)`, you would see that it had changed.


I know there are good explanations for how variables and names work in 
Python, but I couldn't find any at the moment. Sorry.


--
~Ethan~

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


Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
You'll see more details in other mail, but, here I am firing up standard 
python interpreter from within windows terminal, and then executing 
following line:


from scoping2 import *


And, this is under windows 11 windows terminal, which is where I 
generally interact with my python code, via command line - generally 
working with flask, and/or other forms of command line interaction, most 
of the time.



Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


On 2024/03/06 17:39, Roel Schroeven via Python-list wrote:

Op 6/03/2024 om 13:55 schreef Jacob Kruger via Python-list:
If you import the contents of that file into the python interpreter, 
[...]


What exactly to you mean by "import the contents of that file into the 
python interpreter"? Other people have put your code in a script, 
executed it, and saw it working as expected. I pasted in IPython, and 
likewise saw it working as expected, and the same with IDLE. It seems 
to me you must be doing something different from us; maybe the way you 
execute that code might be the key to this whole confusion.



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


Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
Matt, other mail is more relevant - seems to maybe have more to do with 
different behavour if import code, or not - no, does not make sense to 
me - but, here's the command line contents including printing out id() 
results, but, only working via importing code:


#---start session---

C:\temp\py_try>type scoping2.py
from datetime import datetime, timezone, timedelta

dt_expiry = datetime.strptime("1970-01-01 00:00", "%Y-%m-%d 
%H:%M").replace(tzinfo=timezone.utc)


def do_it():
    global dt_expiry
    dt_expiry = datetime.now()+timedelta(minutes=5)
    print("date value", dt_expiry.strftime("%Y-%m-%d %H:%M"))
    print("ID", id(dt_expiry))
# end of do_it function


C:\temp\py_try>python
Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec  4 2023, 19:24:49) [MSC v.1937 
64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.
>>> from scoping2 import *
>>> print(dt_expiry)
1970-01-01 00:00:00+00:00
>>> print(id(dt_expiry))
1808577867152
>>> do_it()
date value 2024-03-06 18:39
ID 1808572660736
>>> print(dt_expiry)
1970-01-01 00:00:00+00:00
>>> print(id(dt_expiry))
1808577867152
>>>
---end session---

As in, the two different ID values are being returned outside and inside 
the function, whereas, if I included that bit inside the interpreter 
while typing code manually, chances are the same ID would be retained 
both inside and outside function.


Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


On 2024/03/06 15:57, Mats Wichmann via Python-list wrote:

On 3/6/24 05:55, Jacob Kruger via Python-list wrote:
Ok, simpler version - all the code in a simpler test file, and 
working with two separate variables to explain exactly what am 
talking about:


If you import the contents of that file into the python interpreter, 
dt_expiry will start off as "1970-01-01 00:00", and, if you execute 
do_it function, it will print out the new value assigned to the 
dt_expiry variable inside that function, but if you then again check 
the value of the dt_expiry variable afterwards, it's reverted to the 
1970... value?



If I take out the line that removes values from l_test # 
l_test.clear() # before appending new value to it, then it will also 
not retain it's new/additional child items after the function exits, 
and will just revert back to [1, 2, 3] each and every time.



In other words, with some of the variable/object types, if you use a 
function that manipulates the contents of a variable, before then 
re-assigning it a new value, it seems like it might then actually 
update/manipulate the global variable, but, either just calling 
purely content retrieval functions against said objects, or assigning 
them new values from scratch seems to then ignore the global scope 
specified in the first line inside the function?



Hope this makes more sense


No, it doesn't. Your code is working as one would expect. For example, 
adding prints for the l_test variable, and removing the .clear() which 
you claim makes it not work, shows me:


before: l_test=[1, 2, 3], id(l_test)=140153285385856
leaving do_it: l_test=[1, 2, 3, 1, 2, 3, 99], id(l_test)=140153285385856
after: l_test=[1, 2, 3, 1, 2, 3, 99], id(l_test)=140153285385856

It's the same list object, as you can see by the id values. And the 
list is updating as expected.


And... you don't need the global statement for l_test. As it's 
mutable, you can mutate it in the function; the global only acts on 
assignment. Using "global" for that may make your intent more clear to 
readers though, although static checkers will grumble at you.


You must be doing something additional that you're not telling us about.



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


Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
Thanks for all your input people, and, yes, I know that besides the 
scope oddities the rest of the code is not my normal style either - was 
partly due to forms of experimentation to try figure out what could be 
causing issues. For example, instead of [:] syntax, was specifically 
using copy() to make sure was not interacting with original variable 
values, etc.



This will be a bit longer - copying-pasting command line output here to 
show you what I truly mean - first session, where I am importing code 
into interpreter and second session where I retype exact same code 
behave differently:


#---first session---

C:\temp\py_try>type scoping2.py
from datetime import datetime, timezone, timedelta

dt_expiry = datetime.strptime("1970-01-01 00:00", "%Y-%m-%d 
%H:%M").replace(tzinfo=timezone.utc)


def do_it():
    global dt_expiry
    dt_expiry = datetime.now()+timedelta(minutes=5)
    print(dt_expiry.strftime("%Y-%m-%d %H:%M"))
# end of do_it function

C:\temp\py_try>python
Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec  4 2023, 19:24:49) [MSC v.1937 
64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.
>>> from scoping2 import *
>>> print(dt_expiry)
1970-01-01 00:00:00+00:00
>>> do_it()
2024-03-06 18:12
>>> print(dt_expiry)
1970-01-01 00:00:00+00:00
>>>

#---end first session---


And, if I now retype the contents of the file into the python 
interpreter instead:


#---start second session---

C:\temp\py_try>python
Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec  4 2023, 19:24:49) [MSC v.1937 
64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime, timezone, timedelta
>>> dt_expiry = datetime.strptime("1970-01-01 00:00", "%Y-%m-%d 
%H:%M").replace(tzinfo=timezone.utc)

>>> def do_it():
... global dt_expiry
... dt_expiry = datetime.now()+timedelta(minutes=5)
... print(dt_expiry.strftime("%Y-%m-%d %H:%M"))
...
>>> print(dt_expiry)
1970-01-01 00:00:00+00:00
>>> do_it()
2024-03-06 18:20
>>> print(dt_expiry)
2024-03-06 18:20:03.909825
>>>

#---end second session---


So, in the second session, where retyped everything, it behaves as I 
would expect it to, but, during first session, the variable is being 
treated as a local variable inside the function - no code differences 
since literally copied-pasted each and every line into console, but, a 
different behaviour nonetheless?



So, yes, know this comes across like some form of a scam/joke, or 
list-garbage, since it doesn't make any sense to me at all, but still 
just wondering if missing something, or should I shift over to 3.12 to 
see if if works differently, or just try reinstalling 3.11 from scratch, 
or should I retry the above in something like the VS code console, or a 
different python console, etc.?



Sorry


Jacob Kruger

Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


On 2024/03/06 16:01, Thomas Passin via Python-list wrote:

On 3/6/2024 7:55 AM, Jacob Kruger via Python-list wrote:
Ok, simpler version - all the code in a simpler test file, and 
working with two separate variables to explain exactly what am 
talking about:


# start code

from datetime import datetime, timezone, timedelta

from copy import copy


# initialise original values

dt_expiry = datetime.strptime("1970-01-01 00:00", "%Y-%m-%d 
%H:%M").replace(tzinfo=timezone.utc)


l_test = [1, 2, 3]


def do_it():
 global dt_expiry, l_test # asked python to refer to global 
variables for both


 # assign new value immediately

 dt_expiry = datetime.now()+timedelta(minutes=5)
 print(dt_expiry.strftime("%Y-%m-%d %H:%M")) # just to show new 
value has been assigned

 # grab copy of list for re-use of items
 l_temp = copy(l_test)
 # following line means l_test will later on retain value in 
global scope because it was manipulated inside function instead of 
just assigned new value

 l_test.clear()
 # replace original set of values
 for i in l_temp: l_test.append(i)
 # add new item
 l_test.append(99)
# end of do_it function

# end code


If you import the contents of that file into the python interpreter, 
dt_expiry will start off as "1970-01-01 00:00", and, if you execute 
do_it function, it will print out the new value assigned to the 
dt_expiry variable inside that function, but if you then again check 
the value of the dt_expiry variable afterwards, it's reverted to the 
1970... value?


Not when I run your code. With a little annotation added to the print 
statements I get (I added the import statements to make it run, and I 
used the same date-time formatting for all three pr

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
So, this does not make sense to me in terms of the following snippet 
from the official python docs page:


https://docs.python.org/3/faq/programming.html


"In Python, variables that are only referenced inside a function are 
implicitly global. If a variable is assigned a value anywhere within the 
function’s body, it’s assumed to be a local unless explicitly declared 
as global."



So, I would then assume that if I explicitly include a variable name 
inside the global statement, then even just assigning it a new value 
should update the variable in the global context, outside the function?



Unless this is something that changed from 3.11 to 3.12 - since that 
snippet is more or less referring to 3.12, but, don't think it was 
changed in any way?



Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


On 2024/03/06 14:55, Jacob Kruger wrote:
Ok, simpler version - all the code in a simpler test file, and working 
with two separate variables to explain exactly what am talking about:


# start code

from datetime import datetime, timezone, timedelta

from copy import copy


# initialise original values

dt_expiry = datetime.strptime("1970-01-01 00:00", "%Y-%m-%d 
%H:%M").replace(tzinfo=timezone.utc)


l_test = [1, 2, 3]


def do_it():
    global dt_expiry, l_test # asked python to refer to global 
variables for both


    # assign new value immediately

    dt_expiry = datetime.now()+timedelta(minutes=5)
    print(dt_expiry.strftime("%Y-%m-%d %H:%M")) # just to show new 
value has been assigned

    # grab copy of list for re-use of items
    l_temp = copy(l_test)
    # following line means l_test will later on retain value in global 
scope because it was manipulated inside function instead of just 
assigned new value

    l_test.clear()
    # replace original set of values
    for i in l_temp: l_test.append(i)
    # add new item
    l_test.append(99)
# end of do_it function

# end code


If you import the contents of that file into the python interpreter, 
dt_expiry will start off as "1970-01-01 00:00", and, if you execute 
do_it function, it will print out the new value assigned to the 
dt_expiry variable inside that function, but if you then again check 
the value of the dt_expiry variable afterwards, it's reverted to the 
1970... value?



If I take out the line that removes values from l_test # 
l_test.clear() # before appending new value to it, then it will also 
not retain it's new/additional child items after the function exits, 
and will just revert back to [1, 2, 3] each and every time.



In other words, with some of the variable/object types, if you use a 
function that manipulates the contents of a variable, before then 
re-assigning it a new value, it seems like it might then actually 
update/manipulate the global variable, but, either just calling purely 
content retrieval functions against said objects, or assigning them 
new values from scratch seems to then ignore the global scope 
specified in the first line inside the function?



Hope this makes more sense


Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


On 2024/03/05 20:23, dn via Python-list wrote:

Jacob,

Please reduce the problem to a small code-set which reproduces the 
problem. If we can reproduce same, then that tells us something. At 
the very least, we can experiment without having to expend amounts of 
time in a (likely faulty) bid to reproduce the same environment.


Also, code is the ultimate description!


Perhaps start with a small experiment:

- after l_servers is created, print its id()
- after the global statement, print its id()
- after the clear/reassignment, print its id()

Is Python always working with the same list?
Please advise...


On 6/03/24 07:13, Jacob Kruger via Python-list wrote:

Hi there


Working with python 3.11, and, issue that confused me for a little 
while, trying to figure out what was occurring - unless am 
completely confused, or missing something - was that, for example, 
when having pre-defined a variable, and then included it in the 
global statement inside a function, that function was still 
referring to a completely local instance, without manipulating 
outside variable object at all unless I first executed a form of 
referral to it, before then possibly assigning a new value to it.



Now, this does not seem to occur consistently if, for example, I 
just run bare-bones test code inside the python interpreter, but 
consistently occurs inside my actual testing script.



Basically, in a file with python code in that am using for a form of
testing at the moment, at the top of the file, under all the import
statements, I initiate the existence of a list variable to make use of

later:


# code snippet

l_servers = []

# end of first code snippet


Then, lower down, inside a couple of different functions, the first 
line

inside the functions includes 

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-06 Thread Jacob Kruger via Python-list
Ok, simpler version - all the code in a simpler test file, and working 
with two separate variables to explain exactly what am talking about:


# start code

from datetime import datetime, timezone, timedelta

from copy import copy


# initialise original values

dt_expiry = datetime.strptime("1970-01-01 00:00", "%Y-%m-%d 
%H:%M").replace(tzinfo=timezone.utc)


l_test = [1, 2, 3]


def do_it():
    global dt_expiry, l_test # asked python to refer to global 
variables for both


    # assign new value immediately

    dt_expiry = datetime.now()+timedelta(minutes=5)
    print(dt_expiry.strftime("%Y-%m-%d %H:%M")) # just to show new 
value has been assigned

    # grab copy of list for re-use of items
    l_temp = copy(l_test)
    # following line means l_test will later on retain value in global 
scope because it was manipulated inside function instead of just 
assigned new value

    l_test.clear()
    # replace original set of values
    for i in l_temp: l_test.append(i)
    # add new item
    l_test.append(99)
# end of do_it function

# end code


If you import the contents of that file into the python interpreter, 
dt_expiry will start off as "1970-01-01 00:00", and, if you execute 
do_it function, it will print out the new value assigned to the 
dt_expiry variable inside that function, but if you then again check the 
value of the dt_expiry variable afterwards, it's reverted to the 1970... 
value?



If I take out the line that removes values from l_test # l_test.clear() 
# before appending new value to it, then it will also not retain it's 
new/additional child items after the function exits, and will just 
revert back to [1, 2, 3] each and every time.



In other words, with some of the variable/object types, if you use a 
function that manipulates the contents of a variable, before then 
re-assigning it a new value, it seems like it might then actually 
update/manipulate the global variable, but, either just calling purely 
content retrieval functions against said objects, or assigning them new 
values from scratch seems to then ignore the global scope specified in 
the first line inside the function?



Hope this makes more sense


Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


On 2024/03/05 20:23, dn via Python-list wrote:

Jacob,

Please reduce the problem to a small code-set which reproduces the 
problem. If we can reproduce same, then that tells us something. At 
the very least, we can experiment without having to expend amounts of 
time in a (likely faulty) bid to reproduce the same environment.


Also, code is the ultimate description!


Perhaps start with a small experiment:

- after l_servers is created, print its id()
- after the global statement, print its id()
- after the clear/reassignment, print its id()

Is Python always working with the same list?
Please advise...


On 6/03/24 07:13, Jacob Kruger via Python-list wrote:

Hi there


Working with python 3.11, and, issue that confused me for a little 
while, trying to figure out what was occurring - unless am completely 
confused, or missing something - was that, for example, when having 
pre-defined a variable, and then included it in the global statement 
inside a function, that function was still referring to a completely 
local instance, without manipulating outside variable object at all 
unless I first executed a form of referral to it, before then 
possibly assigning a new value to it.



Now, this does not seem to occur consistently if, for example, I just 
run bare-bones test code inside the python interpreter, but 
consistently occurs inside my actual testing script.



Basically, in a file with python code in that am using for a form of
testing at the moment, at the top of the file, under all the import
statements, I initiate the existence of a list variable to make use of

later:


# code snippet

l_servers = []

# end of first code snippet


Then, lower down, inside a couple of different functions, the first line
inside the functions includes the following:
# code snippet
 global l_servers
# end code snippet

That should, in theory, mean that if I assign a value to that variable
inside one of the functions, it should reflect globally?

However, it seems like that, while inside those functions, it can be
assigned a new list of values, but if I then return to the scope outside

the functions, it has reverted back to being an empty list = []?


The issue seems to specifically (or not) occur when I make a call to 
one function, and, in the steps it's executing in one context, while 
it's not doing anything to the list directly, it's then making a call 
to the second function, which is then meant to repopulate the list 
with a brand new set of values.



Now, what almost seems to be occurring, is that while just 
manipulating the contents of a referenced variable is fine in this 
context, the moment I try to reassign it, that's where the i

Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread Jacob Kruger via Python-list

Hi there


Working with python 3.11, and, issue that confused me for a little 
while, trying to figure out what was occurring - unless am completely 
confused, or missing something - was that, for example, when having 
pre-defined a variable, and then included it in the global statement 
inside a function, that function was still referring to a completely 
local instance, without manipulating outside variable object at all 
unless I first executed a form of referral to it, before then possibly 
assigning a new value to it.



Now, this does not seem to occur consistently if, for example, I just 
run bare-bones test code inside the python interpreter, but consistently 
occurs inside my actual testing script.



Basically, in a file with python code in that am using for a form of
testing at the moment, at the top of the file, under all the import
statements, I initiate the existence of a list variable to make use of

later:


# code snippet

l_servers = []

# end of first code snippet


Then, lower down, inside a couple of different functions, the first line
inside the functions includes the following:
# code snippet
    global l_servers
# end code snippet

That should, in theory, mean that if I assign a value to that variable
inside one of the functions, it should reflect globally?

However, it seems like that, while inside those functions, it can be
assigned a new list of values, but if I then return to the scope outside

the functions, it has reverted back to being an empty list = []?


The issue seems to specifically (or not) occur when I make a call to one 
function, and, in the steps it's executing in one context, while it's 
not doing anything to the list directly, it's then making a call to the 
second function, which is then meant to repopulate the list with a brand 
new set of values.



Now, what almost seems to be occurring, is that while just manipulating 
the contents of a referenced variable is fine in this context, the 
moment I try to reassign it, that's where the issue is occurring .



Here are relevant excerpts from the file:-


# start code

# original assignation in main part of file

l_servers = []


# function wich is initially being executed

def interact():
    global l_servers
    # extra code inbetween choosing what to carry out

    # ...

    # end of other code

    bl_response, o_out = list_servers()

    if bl_response: # just make sure other function call was successful

    l_servers.clear() # first make reference to global variable

    for srv in o_out: l_servers.append(srv) # now re-populate items

    # end code snippet from inside interact function

# end of interact function

# end of code snippet


That other function being called from within, list_servers() was 
initially just trying to populate the values inside the global list 
variable itself, but was ending up in a similar fashion - reverting to 
initial empty value, but, the above now seems to work, as long as I 
first make reference to/manipulate/work with global variable instead of 
just trying to reassign it a brand new value/set of items?



So, am I missing something obvious, have I forgotten about something 
else - yes, know that if was working from within an embedded function, I 
might need/want to then use the nonlocal statement against that variable 
name, but, honestly, just not sure how this can be occurring, and, it's 
not just with this one list variable, etc.?



If I try simple test code from within the python interpreter, using 
different types of variables, this does also not seem to be the same all 
the time, but, don't think it can relate to an iterable like a list, or 
else, just in case, here is the code snippet with all the import 
statements from the top of that file, in case something could be 
overriding standard behaviour - not likely in this context, but, really 
not sure what's occurring:


# import code snippet

import requests, time
from requests.auth import HTTPBasicAuth
import psutil as psu
import pytz
import bcrypt
from copy import copy
from datetime import datetime, timedelta, timezone
from dateutil.parser import parse

# end of import snippet


Thanks if you have any ideas/thoughts on the matter


Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


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


Re: No current way to just compile flet code into truly native packages for smart phones, etc.?

2023-11-14 Thread Jacob Kruger via Python-list

Yup.


Also checked out beeware - which also offers cross-platform compilation 
of same code - but, one minor issue there first time tried it out was 
working with additional/external modules, and, packaging resources.



Plus, while it includes it's own form of LBC GUI interface - toga - the 
one included here in flet seemed 'nicer':


https://beeware.org/project/projects/libraries/toga/


But, haven't taken time to really take it much further than just a bit 
of playing around so far.



Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


On 2023/11/13 19:47, Barry wrote:



On 13 Nov 2023, at 17:21, Jacob Kruger via Python-list  
wrote:

Had a look at the following bit of introduction to using python and flet to 
build cross-platform flutter-based apps using same python code, and, while it 
seems to work alright if tell it to run as under GUI here on windows desktop, 
and, while can get it to fire up PWA version as well, that's not really 
stand-alone since will still require code to be running in background, and, in 
terms of, for example, android, it seems like it will need to then be running 
via the native android flet interpreter for it to work as such?


https://flet.dev/docs/


Flet PWA deployment 
<https://flet.dev/docs/guides/python/deploying-web-app/progressive-web-apps/>

flet looks interesting. It seems from the road map there is lots missing today.
Also the people that know flet are on discord. You may find someone here.

Barry


--

Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."

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


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


No current way to just compile flet code into truly native packages for smart phones, etc.?

2023-11-13 Thread Jacob Kruger via Python-list
Had a look at the following bit of introduction to using python and flet 
to build cross-platform flutter-based apps using same python code, and, 
while it seems to work alright if tell it to run as under GUI here on 
windows desktop, and, while can get it to fire up PWA version as well, 
that's not really stand-alone since will still require code to be 
running in background, and, in terms of, for example, android, it seems 
like it will need to then be running via the native android flet 
interpreter for it to work as such?



https://flet.dev/docs/


Flet PWA deployment 



--

Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."

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


Re: SQL rollback of multiple inserts involving constraints

2023-11-10 Thread Jacob Kruger via Python-list
Think performing a session/transaction flush after the first two inserts 
should offer the workaround before you've committed all transaction 
actions to the database finally:


https://medium.com/@oba2311/sqlalchemy-whats-the-difference-between-a-flush-and-commit-baec6c2410a9


HTH


Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."


On 2023/11/10 11:15, Loris Bennett via Python-list wrote:

Hi,

In my MariaDB database I have a table 'people' with 'uid' as the primary
key and a table 'groups' with 'gid' as the primary key.  I have a third
table 'memberships' with 'uid' and 'gid' being the primary key and the
constraint that values for 'uid' and 'gid' exist in the tables 'people'
and 'groups', respectively.  I am using SQLAlchemy and writing a method
to setup a membership for a new person in a new group.

I had assumed that I should be able to perform all three inserts
(person, group, membership) with a single transaction and then rollback
if there is a problem.  However, the problem is that if the both the
insert into 'people' and that into 'groups' are not first committed, the
constraint on the insertion of the membership fails.

What am I doing wrong?

Apologies if this is actually an SQL question rather than something
related to SQLAlchemy.

Cheers,

Loris


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