Re: unable to run the basic Embedded Python example

2023-06-24 Thread Fulian Wang via Python-list
Forgot to try it or not in an Apple computer, but there’s one or two apple 
computers in my home when I just began to learn computer science. I should try 
it. Because I remembered clearly, I tried it on others.

Get Outlook for iOS

From: Fulian Wang 
Sent: Saturday, June 24, 2023 7:43:56 PM
To: Dave Ohlsson ; python-list@python.org 

Subject: Re: unable to run the basic Embedded Python example

I study computer science in byu.edu, we choose the 3.4.3 vision. No matter 
which kind of computers or windows, I needed to download it from Microsoft 
store. Now I can download it directly from python.org

Get Outlook for iOS

From: Python-list  on 
behalf of Dave Ohlsson via Python-list 
Sent: Saturday, June 24, 2023 15:35
To: python-list@python.org 
Subject: unable to run the basic Embedded Python example

I cannot get the simple program
https://docs.python.org/3/extending/embedding.html#very-high-level-embedding
to work.

My environment:
* Windows 10
* Microsoft Visual Studio 2019
* Qt Creator 10.0.1 (only as an IDE)
* Python not installed

This is what I did:

1. I downloaded https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz

2. I extracted Python-3.11.4.tgz into C:\temp\Python-3.11.4

3. I opened the "x64 Native Tools Command Prompt for VS 2019" which comes
with Microsoft Visual Studio 2019

4. In "x64 Native Tools Command Prompt for VS 2019":

**
** Visual Studio 2019 Developer Command Prompt v16.11.26
** Copyright (c) 2021 Microsoft Corporation
**
[vcvarsall.bat] Environment initialized for: 'x64'

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>cd
C:\temp\Python-3.11.4\PCbuild

C:\temp\Python-3.11.4\PCbuild>build.bat -d // <= option '-d' means "debug"
Downloading nuget...
[many lines omitted]
Build succeeded.

C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(578,5): warning MSB3073:
The command ""C:\Program Files\Git\cmd\git.exe" name-rev --name-only HEAD >
"C:\temp\Python-3.11.4\PCbuild\obj\311amd64_Debug\pythoncore\gitbranch.txt""
exited with code 128.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(578,5): warning MSB4181:
The "Exec" task returned false but did not log an error.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(579,5): warning MSB3073:
The command ""C:\Program Files\Git\cmd\git.exe" rev-parse --short HEAD >
"C:\temp\Python-3.11.4\PCbuild\obj\311amd64_Debug\pythoncore\gitversion.txt""
exited with code 128.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(579,5): warning MSB4181:
The "Exec" task returned false but did not log an error.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(580,5): warning MSB3073:
The command ""C:\Program Files\Git\cmd\git.exe" describe --all --always
--dirty >
"C:\temp\Python-3.11.4\PCbuild\obj\311amd64_Debug\pythoncore\gittag.txt""
exited with code 128.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(580,5): warning MSB4181:
The "Exec" task returned false but did not log an error.
6 Warning(s)
0 Error(s)

Time Elapsed 00:00:34.87

C:\temp\Python-3.11.4\PCbuild>

5. I copied the example
https://docs.python.org/3/extending/embedding.html#very-high-level-embedding,
unchanged, to 'C:\temp\embedded_python\main.c'.

6. I created Qt Creator project file 'C:\temp\embedded_python\
embedded_python.pro':

TEMPLATE = app
TARGET = embedded_python
SOURCES += main.c
PYTHON_DIR = C:/temp/Python-3.11.4
INCLUDEPATH += $${PYTHON_DIR}/Include
INCLUDEPATH += $${PYTHON_DIR}/PC
LIBS += $${PYTHON_DIR}/PCbuild/amd64/python311_d.lib

7. I built the project:

20:02:38: Running steps for project embedded_python...
20:02:38: Starting: "C:\Qt\6.1.3\msvc2019_64\bin\qmake.exe"
C:\temp\embedded_python\embedded_python.pro -spec win32-msvc
"CONFIG+=debug" "CONFIG-=qml_debug" "CONFIG-=qtquickcompiler"
Info: creating stash file
C:\temp\build-embedded_python-Desktop_Qt_6_1_3_MSVC2019_64bit-Debug\.qmake.stash
20:02:38: The process "C:\Qt\6.1.3\msvc2019_64\bin\qmake.exe" exited
normally.
20:02:38: Starting: "C:\Qt\Tools\QtCreator\bin\jom\jom.exe" -f
C:/temp/build-embedded_python-Desktop_Qt_6_1_3_MSVC2019_64bit-Debug/Makefile
qmake_all

jom 1.1.3 - empower your cores

20:02:38: The process "C:\Qt\Tools\QtCreator\bin\jom\jom.exe" exited
normally.
20:02:38: Starting: "C:\Qt\Tools\QtCreator\bin\jom\jom.exe"
C:\Qt\Tools\QtCreator\bin\jom\jom.exe -f Makefile.Debug
cl -c -nologo -Zc:wchar_t -FS -Zc:strictStrings -Zi -MDd -utf-8 -W3 -w44456
-w44457 -w44458 /Fddebug\embedded_python.vc.pdb -DUNICODE -D_UNICODE
-DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DQT_GUI_LIB
-DQT_CORE_LIB -I..\embedded_python -I. -I..\Python-3.11.4\Include
-I..\Python-3.11.4\PC -I..\..\Qt\6.1.3\msvc2019_64\include
-I..\..\Qt\6.1.3\msvc2019_64\include\QtGui
-I..\..\Qt\6.1.3\msvc2019_64\include\QtCore -Idebug -IC:/VulkanSDK/
1.0.51.0/Include 

Re: unable to run the basic Embedded Python example

2023-06-24 Thread Fulian Wang via Python-list
I study computer science in byu.edu, we choose the 3.4.3 vision. No matter 
which kind of computers or windows, I needed to download it from Microsoft 
store. Now I can download it directly from python.org

Get Outlook for iOS

From: Python-list  on 
behalf of Dave Ohlsson via Python-list 
Sent: Saturday, June 24, 2023 15:35
To: python-list@python.org 
Subject: unable to run the basic Embedded Python example

I cannot get the simple program
https://docs.python.org/3/extending/embedding.html#very-high-level-embedding
to work.

My environment:
* Windows 10
* Microsoft Visual Studio 2019
* Qt Creator 10.0.1 (only as an IDE)
* Python not installed

This is what I did:

1. I downloaded https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz

2. I extracted Python-3.11.4.tgz into C:\temp\Python-3.11.4

3. I opened the "x64 Native Tools Command Prompt for VS 2019" which comes
with Microsoft Visual Studio 2019

4. In "x64 Native Tools Command Prompt for VS 2019":

**
** Visual Studio 2019 Developer Command Prompt v16.11.26
** Copyright (c) 2021 Microsoft Corporation
**
[vcvarsall.bat] Environment initialized for: 'x64'

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>cd
C:\temp\Python-3.11.4\PCbuild

C:\temp\Python-3.11.4\PCbuild>build.bat -d // <= option '-d' means "debug"
Downloading nuget...
[many lines omitted]
Build succeeded.

C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(578,5): warning MSB3073:
The command ""C:\Program Files\Git\cmd\git.exe" name-rev --name-only HEAD >
"C:\temp\Python-3.11.4\PCbuild\obj\311amd64_Debug\pythoncore\gitbranch.txt""
exited with code 128.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(578,5): warning MSB4181:
The "Exec" task returned false but did not log an error.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(579,5): warning MSB3073:
The command ""C:\Program Files\Git\cmd\git.exe" rev-parse --short HEAD >
"C:\temp\Python-3.11.4\PCbuild\obj\311amd64_Debug\pythoncore\gitversion.txt""
exited with code 128.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(579,5): warning MSB4181:
The "Exec" task returned false but did not log an error.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(580,5): warning MSB3073:
The command ""C:\Program Files\Git\cmd\git.exe" describe --all --always
--dirty >
"C:\temp\Python-3.11.4\PCbuild\obj\311amd64_Debug\pythoncore\gittag.txt""
exited with code 128.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(580,5): warning MSB4181:
The "Exec" task returned false but did not log an error.
6 Warning(s)
0 Error(s)

Time Elapsed 00:00:34.87

C:\temp\Python-3.11.4\PCbuild>

5. I copied the example
https://docs.python.org/3/extending/embedding.html#very-high-level-embedding,
unchanged, to 'C:\temp\embedded_python\main.c'.

6. I created Qt Creator project file 'C:\temp\embedded_python\
embedded_python.pro':

TEMPLATE = app
TARGET = embedded_python
SOURCES += main.c
PYTHON_DIR = C:/temp/Python-3.11.4
INCLUDEPATH += $${PYTHON_DIR}/Include
INCLUDEPATH += $${PYTHON_DIR}/PC
LIBS += $${PYTHON_DIR}/PCbuild/amd64/python311_d.lib

7. I built the project:

20:02:38: Running steps for project embedded_python...
20:02:38: Starting: "C:\Qt\6.1.3\msvc2019_64\bin\qmake.exe"
C:\temp\embedded_python\embedded_python.pro -spec win32-msvc
"CONFIG+=debug" "CONFIG-=qml_debug" "CONFIG-=qtquickcompiler"
Info: creating stash file
C:\temp\build-embedded_python-Desktop_Qt_6_1_3_MSVC2019_64bit-Debug\.qmake.stash
20:02:38: The process "C:\Qt\6.1.3\msvc2019_64\bin\qmake.exe" exited
normally.
20:02:38: Starting: "C:\Qt\Tools\QtCreator\bin\jom\jom.exe" -f
C:/temp/build-embedded_python-Desktop_Qt_6_1_3_MSVC2019_64bit-Debug/Makefile
qmake_all

jom 1.1.3 - empower your cores

20:02:38: The process "C:\Qt\Tools\QtCreator\bin\jom\jom.exe" exited
normally.
20:02:38: Starting: "C:\Qt\Tools\QtCreator\bin\jom\jom.exe"
C:\Qt\Tools\QtCreator\bin\jom\jom.exe -f Makefile.Debug
cl -c -nologo -Zc:wchar_t -FS -Zc:strictStrings -Zi -MDd -utf-8 -W3 -w44456
-w44457 -w44458 /Fddebug\embedded_python.vc.pdb -DUNICODE -D_UNICODE
-DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DQT_GUI_LIB
-DQT_CORE_LIB -I..\embedded_python -I. -I..\Python-3.11.4\Include
-I..\Python-3.11.4\PC -I..\..\Qt\6.1.3\msvc2019_64\include
-I..\..\Qt\6.1.3\msvc2019_64\include\QtGui
-I..\..\Qt\6.1.3\msvc2019_64\include\QtCore -Idebug -IC:/VulkanSDK/
1.0.51.0/Include -I..\..\Qt\6.1.3\msvc2019_64\mkspecs\win32-msvc -Fodebug\
@C:\Users\dave\AppData\Local\Temp\main.obj.21168.0.jom
main.c
..\embedded_python\main.c(12): warning C4996: 'Py_SetProgramName':
deprecated in 3.11
link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:WINDOWS
"/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls'
version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*'
processorArchitecture='*'" /MANIFEST:embed 

TKinter in Python - advanced notions - ok

2023-06-24 Thread Dan Kolis via Python-list
Well, its kind of obvious to make a skeleton, copy it in for some basic 
functionality and modularly ( is that a word ? ) manage each piece.

That ( like your example ) is fine stuff.  

As a side note, I am sure large, large highly generalised programs are pretty 
hard to make.

One thing I do is make each file have a null class like:

# Empty object maker ( M T ) ... get it say it !
class MT():
pass

# Hook point for this module generally
mod = MT()  

Then, a category of symbols ( mostly 'variables ), grow under mod.(Whatever)

# This window gets to exist, and it's exit via op sys clicks
mod.ws = sb.make_Tk_Window( "seqdecodeshow" + str( a_Num ), gi.kCONFIGWIN ) 

This basic notion is that self.(stuff) is not quite multi class enough, yet 
'global' is unpopular as a notation, due to name pollution.


IN A BIG PROGRAM NOT A LITTLE WEENEY One YOU SCRATCH ON A BLACKBOARD SOMEPLACE 
!!

Generally, The way I proceed is to try to avoid CLASSes in each module, but 
only a little. If you need it, you sure do. So early on ( like < 100 lines, if 
you avoided a class, roll back and add it ).

Then, mod.(anything) is 'sort of' like self to class, but its politics is the 
filename that made it alone.

If mod. is not used exactly in a class, roll it back to self. If its way more 
abstractley used, upgrade it to your concept of really global, which generally 
should be somewhat sparely used.

All my TK calls are wrapped in a custom layer, it reduces the line count to 
1/3. like so:

   sb.checkableBoole(cFrmL, 0, 0, gi.us, e_Txt, 
 setting_ClickCb )
sb.textCmdLine( cFrmL, 1, 0, gi.us, 'Apply',
applyThoseSelects )
sb.textCmdLine( cFrmL, 1, 1, gi.us, 'Reset',
resetSelects )
sb.textCmdLine( cFrmL, 1, 2, gi.us, 'Select 
all',   cbSelectAll )

cFrmL is the TK thing that contains these few text lines, with all the bg 
colors, whitepace, fonts, managed inside


This calls 'grid' of course for placement. But all colors, and callbacks for 
changes are entirely in called pieces, which have been tested like 150% crazy. 
sb is 

import screenBuilder1 assb  # Screen maker for TKinter and TKinter ++ 
windows

If you want to use my 'screenbuilder'... talk to me, I suppose. this is a 
biology IDE, the screen part is just a little piece of a huge initiative. 
Obviously, the human being's ideas in there head matter so the TK stuff is 
important, to say the least

Regs,
Daniel B. Kolis

my ref: 24 Jun 2023, https://groups.google.com/g/comp.lang.python/

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


Re: Trouble with defaults and timeout decorator

2023-06-24 Thread Piergiorgio Sartor via Python-list

On 24/06/2023 18.18, Jason Friedman wrote:

I'm writing a database connectivity module to be used by other modules and
leveraging the jaydebeapi module.

From what I can tell jaydebeapi contains no built-in timeout capability, so

then I turned to https://pypi.org/project/timeout-decorator/.
My goal is to have a default timeout of, say, 10 seconds, which can be
overridden by the caller.


import jaydebeapi
from timeout_decorator import timeout

class Database:
 database_connection = None
 database_name, user_name, password, host, port = stuff
 timeout = None

 def __init__(self, timeout=10):
 self.timeout = timeout

 @timeout(self.timeout)
 def get_connection(self):
 if not self.database_connection:
 self.database_connection = jaydebeapi.connect(some_args)
 return self.database_connection


The trouble occurs on line 12 with:
NameError: name 'self' is not defined


A quick search would return that "self"
is not available in the class body, only
in the class methods.

There are workarounds, but I guess not
simple ones, expecially for "timeout".

bye,

--

piergiorgio

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


unable to run the basic Embedded Python example

2023-06-24 Thread Dave Ohlsson via Python-list
I cannot get the simple program
https://docs.python.org/3/extending/embedding.html#very-high-level-embedding
to work.

My environment:
* Windows 10
* Microsoft Visual Studio 2019
* Qt Creator 10.0.1 (only as an IDE)
* Python not installed

This is what I did:

1. I downloaded https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz

2. I extracted Python-3.11.4.tgz into C:\temp\Python-3.11.4

3. I opened the "x64 Native Tools Command Prompt for VS 2019" which comes
with Microsoft Visual Studio 2019

4. In "x64 Native Tools Command Prompt for VS 2019":

**
** Visual Studio 2019 Developer Command Prompt v16.11.26
** Copyright (c) 2021 Microsoft Corporation
**
[vcvarsall.bat] Environment initialized for: 'x64'

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>cd
C:\temp\Python-3.11.4\PCbuild

C:\temp\Python-3.11.4\PCbuild>build.bat -d // <= option '-d' means "debug"
Downloading nuget...
[many lines omitted]
Build succeeded.

C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(578,5): warning MSB3073:
The command ""C:\Program Files\Git\cmd\git.exe" name-rev --name-only HEAD >
"C:\temp\Python-3.11.4\PCbuild\obj\311amd64_Debug\pythoncore\gitbranch.txt""
exited with code 128.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(578,5): warning MSB4181:
The "Exec" task returned false but did not log an error.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(579,5): warning MSB3073:
The command ""C:\Program Files\Git\cmd\git.exe" rev-parse --short HEAD >
"C:\temp\Python-3.11.4\PCbuild\obj\311amd64_Debug\pythoncore\gitversion.txt""
exited with code 128.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(579,5): warning MSB4181:
The "Exec" task returned false but did not log an error.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(580,5): warning MSB3073:
The command ""C:\Program Files\Git\cmd\git.exe" describe --all --always
--dirty >
"C:\temp\Python-3.11.4\PCbuild\obj\311amd64_Debug\pythoncore\gittag.txt""
exited with code 128.
C:\temp\Python-3.11.4\PCbuild\pythoncore.vcxproj(580,5): warning MSB4181:
The "Exec" task returned false but did not log an error.
6 Warning(s)
0 Error(s)

Time Elapsed 00:00:34.87

C:\temp\Python-3.11.4\PCbuild>

5. I copied the example
https://docs.python.org/3/extending/embedding.html#very-high-level-embedding,
unchanged, to 'C:\temp\embedded_python\main.c'.

6. I created Qt Creator project file 'C:\temp\embedded_python\
embedded_python.pro':

TEMPLATE = app
TARGET = embedded_python
SOURCES += main.c
PYTHON_DIR = C:/temp/Python-3.11.4
INCLUDEPATH += $${PYTHON_DIR}/Include
INCLUDEPATH += $${PYTHON_DIR}/PC
LIBS += $${PYTHON_DIR}/PCbuild/amd64/python311_d.lib

7. I built the project:

20:02:38: Running steps for project embedded_python...
20:02:38: Starting: "C:\Qt\6.1.3\msvc2019_64\bin\qmake.exe"
C:\temp\embedded_python\embedded_python.pro -spec win32-msvc
"CONFIG+=debug" "CONFIG-=qml_debug" "CONFIG-=qtquickcompiler"
Info: creating stash file
C:\temp\build-embedded_python-Desktop_Qt_6_1_3_MSVC2019_64bit-Debug\.qmake.stash
20:02:38: The process "C:\Qt\6.1.3\msvc2019_64\bin\qmake.exe" exited
normally.
20:02:38: Starting: "C:\Qt\Tools\QtCreator\bin\jom\jom.exe" -f
C:/temp/build-embedded_python-Desktop_Qt_6_1_3_MSVC2019_64bit-Debug/Makefile
qmake_all

jom 1.1.3 - empower your cores

20:02:38: The process "C:\Qt\Tools\QtCreator\bin\jom\jom.exe" exited
normally.
20:02:38: Starting: "C:\Qt\Tools\QtCreator\bin\jom\jom.exe"
C:\Qt\Tools\QtCreator\bin\jom\jom.exe -f Makefile.Debug
cl -c -nologo -Zc:wchar_t -FS -Zc:strictStrings -Zi -MDd -utf-8 -W3 -w44456
-w44457 -w44458 /Fddebug\embedded_python.vc.pdb -DUNICODE -D_UNICODE
-DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DQT_GUI_LIB
-DQT_CORE_LIB -I..\embedded_python -I. -I..\Python-3.11.4\Include
-I..\Python-3.11.4\PC -I..\..\Qt\6.1.3\msvc2019_64\include
-I..\..\Qt\6.1.3\msvc2019_64\include\QtGui
-I..\..\Qt\6.1.3\msvc2019_64\include\QtCore -Idebug -IC:/VulkanSDK/
1.0.51.0/Include -I..\..\Qt\6.1.3\msvc2019_64\mkspecs\win32-msvc -Fodebug\
@C:\Users\dave\AppData\Local\Temp\main.obj.21168.0.jom
main.c
..\embedded_python\main.c(12): warning C4996: 'Py_SetProgramName':
deprecated in 3.11
link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:WINDOWS
"/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls'
version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*'
processorArchitecture='*'" /MANIFEST:embed /OUT:debug\embedded_python.exe
@C:\Users\dave\AppData\Local\Temp\embedded_python.exe.21168.484.jom
20:02:39: The process "C:\Qt\Tools\QtCreator\bin\jom\jom.exe" exited
normally.
20:02:39: Elapsed time: 00:01.

8. So far, so good. Next, I tried to run embedded_python.exe. In order for
the Python DLL to be available:
8a. I closed Qt Creator.
8b. In the Control Panel, "System", "Advanced system settings", tab
"Advanced", "Environment Variables...", I added

Re: Trouble with defaults and timeout decorator

2023-06-24 Thread MRAB via Python-list

On 2023-06-24 17:18, Jason Friedman via Python-list wrote:

I'm writing a database connectivity module to be used by other modules and
leveraging the jaydebeapi module.
  From what I can tell jaydebeapi contains no built-in timeout capability, so
then I turned to https://pypi.org/project/timeout-decorator/.
My goal is to have a default timeout of, say, 10 seconds, which can be
overridden by the caller.


import jaydebeapi
from timeout_decorator import timeout

class Database:
 database_connection = None
 database_name, user_name, password, host, port = stuff
 timeout = None

 def __init__(self, timeout=10):
 self.timeout = timeout

 @timeout(self.timeout)
 def get_connection(self):
 if not self.database_connection:
 self.database_connection = jaydebeapi.connect(some_args)
 return self.database_connection


The trouble occurs on line 12 with:
NameError: name 'self' is not defined


The decorator is applied when the class is defined, but 'self' exists 
only in 'Database.__init__' and 'Database.get_connection' when they are 
called.


Have you tried applying the decorator "manually" in 'Database.__init__'?

def __init__(self, timeout=10):
self.timeout = timeout
self.get_connection = timeout(self.timeout)(self.get_connection)

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


Trouble with defaults and timeout decorator

2023-06-24 Thread Jason Friedman via Python-list
I'm writing a database connectivity module to be used by other modules and
leveraging the jaydebeapi module.
>From what I can tell jaydebeapi contains no built-in timeout capability, so
then I turned to https://pypi.org/project/timeout-decorator/.
My goal is to have a default timeout of, say, 10 seconds, which can be
overridden by the caller.


import jaydebeapi
from timeout_decorator import timeout

class Database:
database_connection = None
database_name, user_name, password, host, port = stuff
timeout = None

def __init__(self, timeout=10):
self.timeout = timeout

@timeout(self.timeout)
def get_connection(self):
if not self.database_connection:
self.database_connection = jaydebeapi.connect(some_args)
return self.database_connection


The trouble occurs on line 12 with:
NameError: name 'self' is not defined
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TKinter in Python - advanced notions

2023-06-24 Thread Chris Angelico via Python-list
On Sat, 24 Jun 2023 at 15:57, Thomas Passin via Python-list
 wrote:
> 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.

I'd agree, although what I would call this is a GUI *skeleton*. It's
not usually worth trying to isolate that from the actual GUI once you
reach production, but it's a great first step as you're building.

MVC and other such design patterns are excellent tools for learning
and conceptualizing, but I agree, it's not something you have to feel
locked into. When talking with students, I'll ask them to show me
whether something is part of the model, the view, or the controller,
but only to make sure they know what their code is doing. It's not
like I would ask them to make three separate files (usually - maybe
I'd pitch that to a struggling student as a teaching tool, but not in
prod).

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