Re: IDLE: clearing the screen

2024-06-09 Thread Alan Gauld via Python-list
On 08/06/2024 20:18, Rob Cliffe via Python-list wrote:
> OK, here is the advanced version:
> import os
> class _cls(object):
>      def __repr__(self):
>          os.system('cls')
>          return ''
> cls = _cls()
> 
> Now when you type
> cls
> it clears the screen.  

For me on a Mac it clears the terminal screen that I used
to launch IDLE and prints a single blank line on the IDLE
shell. (And I have to use "clear" instead of "cls" of course.

A quick Google suggests that printing Ctrl-L (formfeed?) might
be a platform agnostic solution. But that didn't work for me
in IDLE either. I think this is one where the best bet is to go
into the IDLE code and add a Shell submenu to clear screen!
Apparently it's been on the workstack at idle-dev for a long
time but is considered low priority...

-- 
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


Re: Terminal Emulator (Posting On Python-List Prohibited)

2024-05-19 Thread Alan Gauld via Python-list
On 18/05/2024 19:12, Piergiorgio Sartor via Python-list wrote:

>> So venvs make managing all that pretty convenient. Dunno why everybody's 
>> so down on venvs...

Not so much down on them, they are just one extra step that's
mostly not needed(in my use case)

> Only people which are *not* using python... :-)
> 
> In my experience, venvs is the only possible
> way to use python properly.

Well, I've been using Python since 1998 on Linux, Windows
and MacOS and have yet to find a use for a venv. I've
played with them when they first came out but haven't
actually found a scenario where I've thought "I need
a venv for that!"

But then I'm a sole user, I have 3 or 4 projects going
but only me working on them. I only have 2 Python versions
at any time and the OS handles that just fine without
any venvs.

> The dependency nightmare created by python, pip
> and all the rest cannot be resolved otherwise.

I've honestly never experienced this "nightmare".
I install stuff and it just works.

-- 
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


Re: Terminal Emulator

2024-05-14 Thread Alan Gauld via Python-list
On 14/05/2024 18:44, Gordinator via Python-list wrote:
> I wish to write a terminal emulator in Python. I am a fairly competent 
> Python user, and I wish to try a new project idea. What references can I 
> use when writing my terminal emulator? I wish for it to be a true 
> terminal emulator as well, not just a Tk text widget or something like that.

The first thing is to decide which terminal. A VT100 is very different
from a 3270. And even a VT330 is quite different from a VT100 although
sharing a common subset of control codes. And if you start looking at
graphical terminals things get even more interesting!

The other thing to consider is whether it will be a standalone app or
a GUI component. If the latter do you want to expose your own API or
clone the manufacturers? Or both?!
Or you could make it an object that can be used both in GUIs and in
"robotic" or "batch" mode. So many options.

Most of the specs are available online and there must be dozens of
terminal emulators around written in C so you should have plenty
of sample code to study. Good luck!

-- 
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


Re: How to Add ANSI Color to User Response

2024-04-10 Thread Alan Gauld via Python-list
On 10/04/2024 19:50, WordWeaver Evangelist via Python-list wrote:

> I have a simple question. I use the following textPrompt in some of my Jython 
> modules:
>  '\nYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, 
> forceUppercase=True)
> Is there a way to add an ANSI color code to the end

Normally, for any kind of fancy terminal work, I'd say use curses.
But I suspect Jython may not support curses?

On the offchance it does do curses it would look like:

import curses

def main(scr):
   if curses.has_colors():  # check the terminal supports color
  curses.start_color().  # init the color system
  curses.init_pair(1,curses.COLOR_YELLOW,curses.COLOR_BLUE)

  # Now start adding text coloring as desired...
  scr.addstr(0,0,"This string is yellow and blue",
 curses.color_pair(1))

  scr.refresh().  # make it visible
   else: scr.addstr("Sorry, no colors available")

curses.wrapper(main)

HTH
-- 
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


Re: xkcd.com/353 ( Flying with Python )

2024-03-30 Thread Alan Gauld via Python-list
On 30/03/2024 07:04, Greg Ewing via Python-list wrote:
> On 30/03/24 7:21 pm, HenHanna wrote:
>> https://xkcd.com/1306/
>>   what does  SIGIL   mean?
> 
> I think its' a Perl term, referring to the $/@/# symbols in front of
> identifiers.

There seem to be several derivation sources including a fantasy world
city suspended above a very thin, tall steeple

Personally, I know SIGIL as an opensource EPUB editor!

None of them seem to have any direct connection to the xkcd cartoon.

-- 
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


Re: Error in Module

2024-03-11 Thread Alan Gauld via Python-list
On 10/03/2024 18:08, Sanskar Mukeshbhai Joshi via Python-list wrote:

> I had made my project in BCA in Python. When I had complete my 
> project and run the program, at that time I got the error in 
> runnig my project. The error was ModuleNotFoundError: No module named 'flask'.

Flask is a third party package that you need to install separately
from Python. It does not come as standard. Have you installed Flask
on the computer where you are running your project? If so, how did you
download/install it?

-- 
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


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

2024-03-06 Thread Alan Gauld via Python-list
On 05/03/2024 22:46, Grant Edwards via Python-list wrote:
> Unfortunately (presumably thanks to SEO) the enshittification of
> Google has reached the point where searching for info on things like
> Python name scope, the first page of links are to worthless sites like
> geeksforgeeks.
And not just Google, I just tried bing, yahoo and duckduckgo
and they are all the same. Not a one listed anything from
python.org on the first page... In fact it didn't even appear
in the first 100 listings, although wikipedia did manage an
entry, eventually.

-- 
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


Re: RE: Problem resizing a window and button placement

2024-02-27 Thread Alan Gauld via Python-list
On 27/02/2024 07:13, Steve GS via Python-list wrote:

> Aside from using it to resized
> the window, is there no way to
> know the last value of the
> change for use in the program?

The last value would be the current width.
And you know how to get that as shown in
your configure function:

Ww = root.winfo_width()

> I could write the value to a
> label and read it back later

That's no different to writing it to
global Ww and accessing that as demonstrated
in my last code post (with button).

>>>  It's better just to ask tk
> for the values whenever you
> need them, as you do inside
> your handler.
> 
> How would that be done?

Ww = root.winfo_width()

Provided you can access the root widget
(which is (nearly?) always true) you
can get the width of the main window.

But can I ask if you have a particular use-case
in mind for this? We started out talking about
relocating some widgets when the window was
resized. We established that the best place
to do that was inside the configure event
handler, with no need to store the width.
(assuming you aren't using a dynamic layout
manager(grid/pack/form) which would be better
still!)

We've now moved on to the more general issue
of communicating values between event handlers
(although still using the width as our exemplar).
Is this just academic interest or do you have
a specific need for this? If we know the need
we might be able to suggest a specific (and
possibly better?)solution.

-- 
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


Re: RE: RE: Problem resizing a window and button placement

2024-02-26 Thread Alan Gauld via Python-list
On 26/02/2024 11:02, 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.

You have to use a function that operates inside the mainloop.
Thats the nature of event driven programs, all activity happens
inside the mainloop except initialisation and cleanup.

So you need to create an event handler as I described below.

Here is the complete program including the button:

###
import tkinter as tk

Ww=None

def on_configure(*args):
  global Ww
  Ww = root.winfo_width()
  print("Ww Inside = <" + str(Ww) + ">")

def printW(): print("Button Ww = ", Ww)


root = tk.Tk()
bw = tk.Button(root, text="Print Width", command=printW)
bw.pack()
root.bind('', on_configure)
root.mainloop()

print("Ww Outside = <" + str(Ww) + ">")


Notice that the button callback picks up the latest value of 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


Re: RE: Problem resizing a window and button placement

2024-02-26 Thread Alan Gauld via Python-list
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


Re: RE: Problem resizing a window and button placement

2024-02-25 Thread Alan Gauld via Python-list
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

-- 
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


Re: Using my routines as functions AND methods

2024-01-04 Thread Alan Gauld via Python-list
On 04/01/2024 04:17, Thomas Passin via Python-list wrote:

>> 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
> 
> 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

Yes but I did the assignment inside the class definition and
that seemed to work just fine:

>>> def g(obj, st): print(st, obj.v)
...
>>> class D:
...def __init__(self,v): self.v = v
...m = g
...
>>> d = D(66)
>>> g(d,'val = ')
val =  66
>>> d.m('v = ')
v =  66


-- 
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


Re: Using my routines as functions AND methods

2024-01-03 Thread Alan Gauld via Python-list
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?

-- 
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


Re: Are there any easy-to-use Visual Studio C# WinForms-like GUI designers in the Python world for Tk?

2023-12-30 Thread Alan Gauld via Python-list
On 29/12/2023 01:05, Félix An via Python-list wrote:
> I'm used to C# WinForms, which has an easy-to-use drag-and-drop GUI 
> designer in Visual Studio. Is there anything similar for Tk? How about 
> Qt? 

There are any number of them but few that work well. The best
I found was Dabo but it uses its own Framework (based, ISTR,
on wxPython?) so not much good for integrating with third
party widgets etc.

I also used a Python fork of SpecTcl but it died a death I think.

The Qt Designer tool works with Python but I never took to
Qt as a toolkit although once mastered it is very powerful.
Probably the best choice for professional class GUI
applications using a GUI builder.

And on a Mac the standard Apple XCode GUI builder works fine
with Python too, but is Mac specific.

> What do you recommend as the easiest way to create GUI programs in 
> Python, similar to the ease of use of C# WinForms?

Provided you aren't getting fancy the basic Tkinter toolset
and programming by hand works best for me. Once you get used
to it its quick, flexible and fairly easy to debug. I also
use wxPython if I need something more sophisticated, but again
I just type the code I don't use a GUI builder.

-- 
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


Re: >>> %matplotlib inline results in SyntaxError: invalid syntax

2023-12-25 Thread Alan Gauld via Python-list
On 25/12/2023 05:34, geetanajali homes via Python-list wrote:

>> import numpy as np 
>> import pandas as pd 
>> import random 
>> import matplotlib.pyplot as plt 
>> %matplotlib inline 
>>
>> I get an error on the last line. I am running this code in Idle Python 
>> 3.4.4 Shell... 

Python names can't start with a % (its the modulo or
string formatting operator).

I know nothing of the innards of matplotlib so I can only
suggest a closer examination of their tutorial information.

-- 
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


Re: Amy known issues with tkinter /ttk on latest MacOS?

2023-11-19 Thread Alan Gauld via Python-list



On 17/11/2023 03:38, Terry Reedy wrote:
> There have been other reports on the cpython issue tracker than Sonoma 
> broke bits of tk behavior.
> https://github.com/python/cpython/issues?q=is%3Aissue+label%3AOS-mac+is%3Aclosed
>  
> shows a couple

Thanks Terry, I had a browse and it seems I'm not alone. That's a relief.

I'll upgrade to 3.13 when it comes out and hopefully it will go
away. (Another suggestion was to use the homebrew python but I don't
like having any more homebrew stuff than is absolutely necessary!)

Meantime I'll just have to continue nudging the mouse as I click!

Alan G.


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


Amy known issues with tkinter /ttk on latest MacOS?

2023-11-16 Thread Alan Gauld via Python-list
I have a little app that I wrote ages ago (2015) using tkinter/ttk
and it just works. Or it did, up until the latest MacOS version upgrade
and now it has become very sporadic in response to mouse clicks.

For example I have a drop-down list and I can drop the list but
then it won't let me select an item. Or sometimes, the selected
item is highlighted but the corresponding action doesn't get fired.
It is intermittent which makes debugging it difficult. And it's
not just lists it also affects regular buttons as well.
Right clicks seem to work ok, it's only the left mouse button.
Also, I've just noticed that if I move the mouse slightly while
clicking that seems to work. There are no error/warning
messages in the Console.

I'm just wondered if this is a known issue, or just my setup?
Any suggestions welcomed.

Python version - 3.10.4
OS version - Sonoma 14.1
M1 Mac Mini, 16GB Ram

I could upgrade my Python version but I was planning on waiting
for the 3.13 release to finalize first. And I doubt if that's
the cause anyway.

-- 
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


Re: Newline (NuBe Question)

2023-11-15 Thread Alan Gauld via Python-list
On 15/11/2023 07:25, Grizzy Adams via Python-list wrote:

> 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  ---

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

Firstly, it is usually a bad idea to mix formatting features(like
newline) with the data. You will need to remove them again if you want
to work with the data itself.

So, better to print the raw data and add the formatting during printing.

There are a couple of options here (well more than a couple actually!)
The simplest is to create another for loop and print each field with a
newline automatically added by print()

Another is to simply join everything in grades together separated by
newlines. Python has a method to do that called join():

print('\n'.join(grades))

Unfortunately it seems your data has a mix of strings and numbers so
that won't work without some tweaks:

print('\n'.join(str(f) for f in grades))


However, I wonder if this really what you want? You have created grades
as a long list containing all of the attributes of all of the students
plus their Pass/Fail status. But you have no (easy)way to access the
Pass/Fail value for each student. Do you really want to store the
Pass/Fail in the student? And then print the students? Like so:

for s in students
if s.finalGrade() > 82:
   s.result = "Pass"
else:
   s.result = "Fail"
print(s.school)
print(s.name)
...
print(s.result)

Just a thought...

PS. There are neater ways to do this but you may not have covered
those yet so I'll stick to basics.


-- 
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


Re: xor operator

2023-11-13 Thread Alan Gauld via Python-list
On 14/11/2023 00:33, Mats Wichmann via Python-list wrote:
> Hardware and software people may have somewhat different views of xor

I've come at it from both sides. I started life as a telecomms
technician and we learned about xor in the context of switching
and relays and xor was a wiring configuration for scenarios where
you wanted any single change of switch state to toggle the
entire system (think a stairwell with switches on every
landing).

Later, I got into software engineering and we studied Boolean
algebra and xor was an odd number of Truth values, used in
parity tests (and in encryption).

But from both perspectives xor is pretty clearly defined
in how it operates and not, I suspect, what the OP really
wants in this case.

-- 
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


Re: Question(s)

2023-10-25 Thread Alan Gauld via Python-list
On 25/10/2023 12:44, o1bigtenor via Python-list wrote:

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

There are literally dozens with varying degrees of smartness.
The big 4 all have Python plugins/environments:
Eclipse, Netbeans, VisualStudio, IntelliJ

And of course the Apple XCode toolset has a python environment.

There are also several Python specific IDEs around too.
Most of them are multi-platform:

https://www.simplilearn.com/tutorials/python-tutorial/python-ide

gives a small sample

And of course the old favourites vi/vim and emacs both have
comprehensive Python support.

-- 
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


Re: Question(s)

2023-10-24 Thread Alan Gauld via Python-list
On 25/10/2023 00:08, o1bigtenor via Python-list wrote:

> So how does one test software then?

Testing is very different to proving!
As an industry we do a lot of testing at many different levels.
On bigger projects you'll find:
- Unit tests - testing small fragments of a bigger program
- Integration tests - testing that sub modules of code work
  together (and code with hardware, if applicable)
- System testing - checking that the code(and hardware) as a
  whole does what it should based on the specs (often done
  by an independent team)
- Performance testing - checking the system runs as fast as it
  should, using only the memory it should, for as long as it should.
- User testing - Can a real user drive it?
- security testing - Does it stop the bad guys from messing it
  up or using it as a gateway?

And there are more levels if you are really keen.
Testing often(usually!) takes up more time than programming.
And there are many, many books written about how to do it.

-- 
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


Re: Question(s)

2023-10-24 Thread Alan Gauld via Python-list
On 24/10/2023 22:51, Grant Edwards via Python-list wrote:

>>> 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?
> And the specified customer requirements are usually wrong too. Sure,
> the customer said it is supposed to do X, but what they actually
> needed was Y.

And this is the hardest bit, specifying exactly what you want at
a level that can be formally verified. I worked on some safety
critical systems a while back(1990s) and we had to formally verify
the core (non UI) code. We did this, but it still failed in some
scenarios because we verified it against faulty specs which,
in turn, were based on the customer's incorrectly stated requirements.
Garbage-In-Garbage-Out still applies.

Was the 3 months of formal analysis a waste of time? No, we still
caught lots of subtle stuff that might have been missed, but it
wasn't 100%. The bugs we did have were caught and identified
during system tests. So far as I know, nobody has died as a
result of any bugs in that system.

But, to the OP, the effort in
a) Learning the math and gaining experience for formal analysis and
b) actually performing such an analysis of real design/code
is simply not worth the effort for 99% of the programs you will write.
It is much simpler and faster to just test. And test again. And again.
Especially if you use automated testing tools which is the norm nowadays.


-- 
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


Re: Why doc call `__init__` as a method rather than function?

2023-09-15 Thread Alan Gauld via Python-list
On 15/09/2023 11:49, scruel tao via Python-list wrote:
> ```python
 class A:
> ...   def __init__(self):
> ... pass

> On many books and even the official documents, it seems that 
> many authors prefer to call `__init__` as a "method" rather 
> than a "function".

That' because in OOP terminology methods are traditionally
implemented as functions defined inside a class (There are
other ways to define methods in other languages, but the
class/function duology is by far the most common.)

What is a method? It is the way that an object handles a
message. OOP is all about objects sending messages to each
other. Many different objects can receive the same message
but they each have their own method of handling that message.
(This is called polymorphism.)

Over time the most common way to implememt OOP in a language
is to invent a "class" structure and to allow functions to
either be defined within it or added to it later. In either
case these functions are what define how a class (and its
object instances) handle a given message. So the function
describes the method for that message. And over time that
has become shortened to the function inside a class *is*
its method.

In practice, the message looks like a function call. And
the method consists of the function body (and/or any
inherited function body). Thus every method is a function
(or set of functions) but not every function is a  method
(or part of one).

-- 
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


Re: Why do I always get an exception raised in this __init__()?

2023-09-01 Thread Alan Gauld via Python-list
On 31/08/2023 22:15, Chris Green via Python-list wrote:

> class Gpiopin:
> 
> def __init__(self, pin):
> # 
> #  
> # scan through the GPIO chips to find the line/pin we want 
> # 
> for c in ['gpiochip0', 'gpiochip1', 'gpiochip2', 'gpiochip3']:
>  
> chip = gpiod.Chip(c)
> for l in range(32):
> line = chip.get_line(l)
> if pin in line.name():
> print("Found: ", line.name())
> return
> else:
> raise ValueError("Can't find pin '" + pin + "'")

You don't store the line anywhere.
You need to use self.line
self.line = chip.get_line(l)
if pin...

> def print_name(self): 
> print (self.line.name()) 
>  
> def set(self): 
> self.line.set_value(1) 
>
> def clear(self): 
> self.line.set_value(0) 

As you do here.

-- 
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


Re: Multiple inheritance and a broken super() chain

2023-07-05 Thread Alan Gauld via Python-list
On 05/07/2023 01:27, Chris Angelico via Python-list wrote:

>> So I'm curious about how big this "big problem with MI" is in
> 
> Who said it's a big problem with MI? 

I think it's a very common perception, particularly with
newer programmers who have never used it in anger. Any
time anyone discusses MI it seems somebody will jump in
and warn about diamonds etc. As a result many steer clear
of MI, which is a shame.

My personal experience of MI is that used appropriately
it is a powerful and useful tool. But it must be used
in a true is-a type relationship and not just as a kind
of cheap reuse mechanism - that's when problems start.

Also, mixin style MI is particularly powerful but the
protocol between mixin and "subclass" needs to be carefully
designed and documented. Like any powerful tool you need
to understand the costs of use as well as the potential
benefits.

-- 
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


Re: Multiple inheritance and a broken super() chain

2023-07-04 Thread Alan Gauld via Python-list
On 03/07/2023 19:39, Chris Angelico via Python-list wrote:
> On Tue, 4 Jul 2023 at 03:39, Peter Slížik via Python-list
>> The legacy code I'm working with uses a classic diamond inheritance. 

> What happens when Top is initialized twice? This seems like a problem
> waiting to happen, and when you moved to using super(), you more than
> likely simplified things and fixed things.

Slightly off topic but I wonder how many real world problems
people have experienced having the top of a diamond initialized
twice? The reason I ask is that I ran a maintenance team for
about 5 years (early 1990s) working on various OOP projects using MI;
in Lisp Flavors, C++(*) and a homebrew variant of C that supported MI.
In that time I don't recall ever having problems with top objects
being initialized twice (apart from redundant execution of code
of course).

In most cases the top object was so abstract that its init()/constructor
was only doing generic type stuff or opening database sessions/networks
etc which got lost and tidied up by garbage collectors.

So I'm curious about how big this "big problem with MI" is in
practice. I'm sure there are scenarios where it has bitten folks
but it never (or very rarely) occurred in our projects. (Of
course, being maintenance programmers, the problems may have
been ironed out before the code ever reached us! But that
wasn't usually the case...)

(*) C++ is the odd one out because it doesn't have GC, but then
neither does it have an Object superclass so very often MI in C++
does not involve creating diamonds! And especially if the MI
style is mixin based.

-- 
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


Re: Fwd: AUTO EDITOR DIDN'T WORK

2023-06-15 Thread Alan Gauld via Python-list
On 15/06/2023 08:58, Real Live FootBall Tv via Python-list wrote:
> I have followed the instructions given on how to install the app. What I
> needed was an application to cut of silence from my video and I saw auto
> editor demonstrated as one of the applications that could do that. It does
> cut the silent areas of an MP4 format video for instance but would save it
> as a XML file which in turn would be exported to the video editor that
> supports the output from the auto editor app. The one who demonstrated it
> in a video used Davinci Resolve to import the XML file, I followed same
> process but I couldn't get same result.

It looks like you have three parts to this puzzle:
- auto-editor
- resolve
- Python

It's not clear which part isn't working but you can at
least test Python is working after you install it
by running the interpreter in a console/terminal
window by typing python at the command prompt.

If you get the Python prompt:

>>>

Then Python is installed OK.

After that it's back into auto-editor and resolve and this is
not the best place to get answers for those. Resolve at least
has an active support forum, so I'd start there(assuming
python works!)

-- 
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


Fwd: AUTO EDITOR DIDN'T WORK

2023-06-13 Thread Alan Gauld via Python-list
Forwarding to list

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.

On Mon, 12 Jun 2023, 23:33 Alan Gauld via Python-list,
mailto:python-list@python.org>> wrote:


On 12/06/2023 10:26, Real Live FootBall Tv via Python-list wrote:

> 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.

You need to define "didn't work"
Did it work as a python interpreter?
ie. Did you get a >>> prompt in a terminal?
and without involvement from your video editor?
If so, what did you do to link it to the video editor?
And what was the result?

Or did Python not even start? How did you try to use it?
What OS are you on? Did the installer run OK?


-- Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/ <http://www.alan-g.me.uk/>
http://www.amazon.com/author/alan_gauld
<http://www.amazon.com/author/alan_gauld>
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
<http://www.flickr.com/photos/alangauldphotos>



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

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


Fwd: Re: AUTO EDITOR DIDN'T WORK

2023-06-12 Thread Alan Gauld via Python-list


On 12/06/2023 10:26, Real Live FootBall Tv via Python-list wrote:

> 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.

You need to define "didn't work"
Did it work as a python interpreter?
ie. Did you get a >>> prompt in a terminal?
and without involvement from your video editor?
If so, what did you do to link it to the video editor?
And what was the result?

Or did Python not even start? How did you try to use it?
What OS are you on? Did the installer run OK?


-- 
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


Re: Question again

2021-09-16 Thread Alan Gauld via Python-list
On 16/09/2021 06:50, af kh wrote:
> Hello,
> I was doing some coding on a website called replit 

I have no idea what that is but...

> after answering 'no' or 'yes' after the last sentence I wrote, 
> the Python window shut off,

That's what you told it to do in the code.
Regardless of which answer the user gives the program
reaches the end and stops.

>  in replit I added one more sentence, but it isn't shown on Python, 

I dn;t know what this means.

> #Gives greetings to the user
> import random
...
> #Ask to pick between numbers 1~10 to see if you will get lucky today: Third 
> question
> number = input("Please pick between numbers 1~10 to see your luck for today: 
> ")
> 
> #From number 1~3 and an answer
> if number == "1" or number == "2" or number == "3" :
>   print("You're in grat luck today!")
> 
> #From number 4~7 and an answer
> elif number == "4" or number == "5" or number == "6" :
>   print("damn, bad luck is coming your way")

The cde and comment are not consistent.

> #From number 8~10 and an answer
> elif number == "7" or number == "8" or number == "9" or number == "10" :
>   print("I cannot sense any luck today, try again next time")

Same here.

> #Add a statement and question: Fourth question
> print("That will be all for today's chitchat, woohooo! would you like to exit 
> the chat?")
> #User says 'yes'
> reply = input()
> 
> #If user says 'yes' reply 'wait hold on! are you really leaving??': Fifth 
> question
> if reply == "yes" :
>   print("Wait hold on! are you really leaving??")
> 
> #User answers
> answer = input()
> #If user says 'yes' again, reply 'fine! bye then!'
> if answer == "yes" :
>   print("Fine! bye then!")


Shouldn't those lines be indented as part of the if statement above?

> #Other than that if user says 'no', reply 'just kidding we're done here haha'
> elif answer == "no" :
>   print("just kidding we're done here haha")

But the code always gets to the end, there is nothing
to stop it exiting.


-- 
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


Re: Friday Finking: Contorted loops

2021-09-12 Thread Alan Gauld via Python-list
On 12/09/2021 09:11, jak wrote:

> if the only way to terminate a 'while True' loop is by using the 'break' 
> statement, why is it allowed to add the 'else' statement which will only 
> contain dead code?
> 
> while True:
>  break
> else:
>  print('dead code')
> 
Because to the interpreter the condition is not part of the
language. It is syntactically correct.

An optimiser OTOH might welkl determine that the condition
will never fail and therefore the else clause never be reached,
in which case it would remove the dead code (possibly emitting
a warning in the process?).

A linter likewise might identify the redundant code.
I don't use any python linters, does anyone know if they do
detect such dead spots?

-- 
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


Re: Friday Finking: Contorted loops

2021-09-12 Thread Alan Gauld via Python-list
On 11/09/2021 15:41, Peter J. Holzer wrote:

> How is C's do/while loop more horrible than Pascal's repeat/until? 

Because it is very hard to spot or distinguish from a normal
while loop.

while condition ;

Is a valid (and fairly common) loop in C

so code that has

do{
code
}
while condition;

Looks, for non-trivial cases, like a lot of code followed
by an empty while loop.

The do is easy to miss  and the while loop disguised as
a repeat termination is confusing.

repeat
code
until condition

Is far clearer to comprehend since there is no ambiguity.

> In an old collection of small C programs of mine I find:
> 
> 35 regular for loops
> 28 while loops
> 2 infinite for loops
> 1 "infinite" for loop (i.e. it exits somewhere in the middle)
> 0 do/while loops.

That wouldn't surprise me, I've only used do/while in C
a handful of times. But in Pascal I use it regularly.

-- 
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


Re: Friday Finking: Contorted loops

2021-09-11 Thread Alan Gauld via Python-list
On 10/09/2021 19:49, Stefan Ram wrote:
> Alan Gauld  writes:
>> OK, That's a useful perspective that is at least consistent.
>> Unfortunately it's not how beginners perceive it
> ...
> 
>   Beginners perceive it the way it is explained to them by
>   their teacher.

I'm not sure that's true. Most  beginners, in my experience,
learn the syntax from their teachers and then go off and play.
What they observe happening is what sticks. And python loop
'else' constructs appear inconsistent to them.

As teachers we like to think we are passing on our wisdom
to our students but in reality everyone learns from their
own experience. The teachers advice is just the starting
point. Hopefully, that starting point sends them in the
right direction but that's the best we can hope for.

-- 
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


Re: Friday Finking: Contorted loops

2021-09-10 Thread Alan Gauld via Python-list
On 10/09/2021 16:36, MRAB wrote:

>> while...else...
>>
>> executes the else if the body of the loop does NOT get executed.
>>
>> for...else...
>>
>> executes the else iff ALL iterations of the for loop DO complete.
>>
> [snip]
> 
> In both cases, it executes the 'else' part if it didn't break out of the 
> loop. That's it.

OK, That's a useful perspective that is at least consistent.

Unfortunately it's not how beginners perceive it and it causes
regular confusion about how/when they should use else with a loop.

-- 
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


Re: Friday Finking: Contorted loops

2021-09-10 Thread Alan Gauld via Python-list
On 10/09/2021 00:47, Terry Reedy wrote:

> even one loop is guaranteed.)  "do-while" or "repeat-until is even rarer 
> since fractional-loop include this as a special case.

Is there any empirical evidence to support this?
Or is it just a case of using the tools that are available?
In my experience of using Pascal (and much later with Delphi)
that I used repeat loops at least as often as while loops,
possibly more.

But using Python and to a lesser extent C (which has a
rather horrible do/while) construct I use while loops
(often with an if-break) simply because that's what
the language offers.

So is it the case that the "need" for repeat loops is
rare, simply a result of there being no native repeat
loop available? After all we could have done without
a for loop too and just used a while loop for
everything (as was done in Oberon(?) ) Would we
then state that the use of for loops was rare?
But I would hope that any empirical research would
look at the wider function of the loop and its
purpose rather than merely analyzing the syntax
and keywords.


-- 
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


Re: Friday Finking: Contorted loops

2021-09-10 Thread Alan Gauld via Python-list
On 09/09/2021 22:36, dn via Python-list wrote:

> Even in fairly modest Python constructs, we quickly repeal the one-in,
> one-out philosophy because try...except operates by providing another
> exit-path.

Exceptions are exceptional by their nature (or should be!) As such
they can arguably be excused from the SP strictures.

But python complicates this tenet still further by adding an else
clause to its loops. And complicating this still more is that these
else clauses have almost exactly opposite effects.

while...else...

executes the else if the body of the loop does NOT get executed.

for...else...

executes the else iff ALL iterations of the for loop DO complete.

This confuses beginners immensely - and quite a few non
beginners too; which is probably why they are not often
seen "in the wild".

This adds to the question of where exactly does a Python loop
end? Is it after the code-suite following the loop construct?
Or is it after the else code-suite, where such exists?

Returning to the specific case of a repeat structure.
In the case of a while loop the else offers another option:

while condition
loop-body
else
loop-body

Now loop-body always gets executed at least once. But at
the cost of duplicating the loop-body code, thus violating DRY.

Just another thought...

-- 
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


Re: on writing a while loop for rolling two dice

2021-09-07 Thread Alan Gauld via Python-list
On 07/09/2021 15:53, Grant Edwards wrote:

> I remember engineering manager I worked with about 35 years ago who
> used a set of C macros to try to make his code look as much like BASIC
> as possible:
> 
>   #define IF if (
>   #define THEN ) {
>   #define ELSE } else {
>   #define ENDIF }
>   ...
> 
> IIRC he copied them out of a magazine article.

That was quite common in C before it became popular(early/mid 80s).
I've seen Pascal, Algol and Coral macro sets in use.
You could even download pre-written ones from various
bulletin boards (remember them?!) for a while.

-- 
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


Re: The sqlite3 timestamp conversion between unixepoch and localtime can't be done according to the timezone setting on the machine automatically.

2021-09-04 Thread Alan Gauld via Python-list
On 03/09/2021 18:37, Chris Angelico wrote:

 Without DST the schools opened in the dark so all the kids
 had to travel to school in the dark and the number of
 traffic accidents while crossing roads jumped.
> 
> Are you saying that you had DST in winter, or that, when summer *and*
> DST came into effect, there was more light at dawn? Because a *lot* of
> people confuse summer and DST, and credit DST with the natural effects
> of the season change.

OK, I see the confusion. What I should point out was that the
experiment involved us staying on DST and not reverting to UTC
in the winter - that unified us with most of the EU apparently...

So although I'm saying DST it was really the non-reversion from
DST to UTC that caused problems. Arguably, if we just stayed on
UTC and didn't have DST at all there would be no issue - except
we'd be an hour out of sync with the EU. (Post Brexit that may
not be seen as a problem!! :-)

-- 
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


Re: The sqlite3 timestamp conversion between unixepoch and localtime can't be done according to the timezone setting on the machine automatically.

2021-09-03 Thread Alan Gauld via Python-list
On 02/09/2021 19:30, Chris Angelico wrote:

>> Without DST the schools opened in the dark so all the kids
>> had to travel to school in the dark and the number of
>> traffic accidents while crossing roads jumped.
> 
> How do they manage in winter? 

That was the winter. Sunrise wasn't till 10:00 or so
and the schools open at 9. With DST sunrise became
9:00 and with pre-dawn light it is enough to see by.

Its a recurring theme. Every now and then some smart
young politician from the south of the UK suggests
doing away with DST and a large crowd of northerners
jump up and say no way!

> Can that be solved with better street> lighting?

They had street lighting but it casts dark shadows etc.
In fact modern LED based street lighting is worse in
that respect that the old yellow sodium lights were.
But where it doesn't exist the cost of installing
street lighting in small villages is too high compared
to just changing the clocks. And of course street
lighting has a real running cost that would be reflected
in the local council taxes, and nobody wants to
pay more of them! After all street lighting has
been available for over 150 years, if they haven't
installed it by now (I mean, nearly everywhere
has some lighting, at least on the main roads,
it's just the smaller back streets that tend to be dark.)

> That was fifty years ago now, and the negative consequences
> of DST are far stronger now.

But not apparent to most people. Most still see it
as a benefit because they get longer working daylight.

-- 
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


Re: The sqlite3 timestamp conversion between unixepoch and localtime can't be done according to the timezone setting on the machine automatically.

2021-09-02 Thread Alan Gauld via Python-list
On 02/09/2021 20:11, MRAB wrote:

>> In one of them (I can't recall which is which) they change on the 4th
>> weekend of October/March in the other they change on the last weekend.
>>
>>
> In the EU (and UK) it's the last Sunday in March/October.
> 
> In the US it's second Sunday in March and the first Sunday in November.
> 
> I know which one I find easier to remember!

Interesting. I remember it as closer than that. The bugs we found were
due to differences in the DST settings of the BIOS in the PCs. (They
were deliberately all sourced from DELL but the EU PCs had a slightly
different BIOS).

The differences you cite should have thrown up issues every year.
I must see if I can find my old log books...

-- 
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


Re: The sqlite3 timestamp conversion between unixepoch and localtime can't be done according to the timezone setting on the machine automatically.

2021-09-02 Thread Alan Gauld via Python-list
On 02/09/2021 19:28, Chris Angelico wrote:

>> Except for the places that don't follow the IANA scheme and/or
>> dynamically change their time settings on a whim. To be complete
>> you need the ability to manually override too.
>>
> 
> What places are those? 

Mainly small non-tech oriented places such as small pacific islands
or principalities with local governance - such as by a group of
tribal elders. I mentioned earlier the example of Andorra announcing
on the Friday night before a DST change that they were deferring
it for a week to preserve the skiing conditions. But we came across
several similar situations in dealing with multi-national service centres.

> IANA maintains the database by noticing changes
> and announcements, and updating the database. 

But don;t those have to be electronic in nature? How, for example
would it pick up the radio news announcement mentioned above?

> governments need to "opt in" or anything. Stuff happens because people
> do stuff, and people do stuff because they want to be able to depend
> on timezone conversions.

Umm, they do DST because it makes their lives easier - more daylight,
extra work time. etc. The needs of, or impact on, computers in these
kinds of small localities and communities are way down the pecking order.

> There ARE times when a government makes a change too quickly to get
> updates out to everyone, especially those who depend on an OS-provided
> copy of tzdata, so I agree with the "on a whim" part. Though,
> fortunately, that's rare.

I agree it is very rare and if you only operate in mainstream
localities you probably never see it as an issue, it's only
when you need to support "off grid" locations that manual
control becomes important. Also the problems we had were about
15 years ago, things may be better ordered nowadays. (I've been
retired for 7 years so can't speak of more recent events)

-- 
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


Re: The sqlite3 timestamp conversion between unixepoch and localtime can't be done according to the timezone setting on the machine automatically.

2021-09-02 Thread Alan Gauld via Python-list
On 31/08/2021 23:31, Chris Angelico wrote:

> Ah, good to know. I think that actually makes a lot of sense; in the
> US, they try to let everyone pretend that the rest of the world
> doesn't exist ("we always change at 2AM"), but in Europe, they try to
> synchronize for the convenience of commerce ("everyone changes at 1AM
> UTC").

There's another gotcha with DST changes. The EU and USA have different
dates on which they change to DST.

In one of them (I can't recall which is which) they change on the 4th
weekend of October/March in the other they change on the last weekend.

That means on some years (when there are 5 weekends) there is a
week when one has changed and the other hasn't. That caused us
a lot of head scratching the first time we encountered it because
our service centres in the US and EU were getting inconsistent
time reporting and some updates showing as having happened in
the future!

-- 
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


Re: The sqlite3 timestamp conversion between unixepoch and localtime can't be done according to the timezone setting on the machine automatically.

2021-09-02 Thread Alan Gauld via Python-list
On 31/08/2021 22:32, Chris Angelico wrote:

> If we could abolish DST world-wide, life would be far easier. All the
> rest of it would be easy enough to handle.
We tried that in the UK for 2 years back in the '70s and very
quickly reverted to DST when they realized that the number
of fatalities among young children going to school doubled
during those two years.

Without DST the schools opened in the dark so all the kids
had to travel to school in the dark and the number of
traffic accidents while crossing roads jumped.

In fact during WW2 they increased DST to 2 hours (that
was for the farmers!) because it meant that farm labourers
would start work at first light, effectively extending
the working day.

-- 
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


Re: The sqlite3 timestamp conversion between unixepoch and localtime can't be done according to the timezone setting on the machine automatically.

2021-09-02 Thread Alan Gauld via Python-list
On 31/08/2021 22:13, Chris Angelico wrote:

> But ultimately, it all just means that timezones are too hard for
> humans to handle, and we MUST handle them using IANA's database. It is
> the only way.

Except for the places that don't follow the IANA scheme and/or
dynamically change their time settings on a whim. To be complete
you need the ability to manually override too.

-- 
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


Re: The sqlite3 timestamp conversion between unixepoch and localtime can't be done according to the timezone setting on the machine automatically.

2021-08-31 Thread Alan Gauld via Python-list
On 31/08/2021 13:45, Chris Angelico wrote:

> (I find the Ireland situation particularly amusing. 

Time zones and daylight saving arrangements in particular are a
nightmare at the micro level. I once worked on a large customer
support application which required all dates/times to be viewable
in UTC plus any of:
- The local support centre's time (eg. Tokyo, Japan)
- The customer organization's local time(eg. Seoul, Korea)
- The local site time (some remote island in the pacific...)

The big problem was the last one since some small countries
have local arrangements for timezones that don't conform to
the official ones. One pacific island had dual "patrons" and to
avoid offending either they adopted a non-standard "timezone"
half-way between the two patron's zones!

In another case we had the principality of Andorra deciding
to put off switching to DST for an extra week because it
would make the snow melt faster and spoil the skiing!
This was decided by the council on the Friday before it
was due to happen and announced on the local radio...

I got more grey hairs on that project than any other.

-- 
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


Python UI (was Re: urgent)

2021-08-30 Thread Alan Gauld via Python-list
On 29/08/2021 11:28, Hari wrote:
> i was download ur python software but it is like boring user interface

I agree it is a boring user interface. Just 3 chevrons: >>>
You can change it a little if you want but ultimately its
just an invitation to type commands.

What kind of interface did you have in mind?

If you want a GUI to develop code there are literally
dozens of those. But ultimately programming is about
typing text into an editor.

> me like young student to learn ,can u have any updates?

There are many tools to help you work with python.
If you tell us what kind of things you want we can tell
you where to find them (if they exist!)

But the basic Python interpreter is primarily there
to run your programs, it's hard to see how you can make
that less boring without also making it very inefficient.
And professional users would hate that!

-- 
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


Re: on writing a while loop for rolling two dice

2021-08-28 Thread Alan Gauld via Python-list
On 28/08/2021 21:50, Hope Rouselle wrote:

>>> roll_count = 0
>>> while True:
>>> outcome = roll_two_dice()
>>> roll_count += 1
>>> if outcome[ 0 ]== outcome[ 1 ]: break
>>> return roll_count, outcome[ 0 ]
>>
> 
> Wait, I'm surprised ``outcome'' is still a valid name at the
> return-statement.  Wasn't it defined inside the while?  

If that really bugs you just replace the break with the return.


>>> if outcome[ 0 ]== outcome[ 1 ]:
>>>return roll_count, outcome[ 0 ]

Now its all inside the loop.

But remember readable code is better than  cute code every time.
And personally I'd just declare the x,y up front. Easier to
understand and debug IMHO.

-- 
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


Re: tkinter

2021-08-21 Thread Alan Gauld via Python-list
On 21/08/2021 19:37, Tony Genter wrote:
>Tkinter stopped working overnight from 8/20/2021 to 8/21/2021.  Last night
>I was working on tutorials to work on a GUI and this morning every file
>that uses tkinter is broken stating that no module `tkinter' exists.

Are you sure you were running Python v3 and not python v2?
In v2 tkinter is spelled Tkinter.

If that is the issue then reinstalling python v3.x and ensuring
that it is the executable used should resolve the issue.

Another option might be that you are using virtual environments
which could result in all manner of chaos and confusion if you
inadvertently start the wrong one...

-- 
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


Re: Tkinter widgets for desktop database application

2021-07-14 Thread Alan Gauld via Python-list
On 13/07/2021 21:24, Rich Shepard wrote:

> What have other developers used for the UI on a stand-alone database
> application not using a web browser? 

Mostly I just use a scrolledlistbox and a set of functions for
formatting the data into columns for display. The big snag is
you can't do spreadsheet-like things such as select a single
field value or sort by a single column without writing a
fair bit of code. But for simple display, and selection
of a single record it works ok.

But a good grid control would be nice. I did try to use
the Tix.grid widget but failed. And now Tix is deprecated.
I'm sure there must be a third-party one somewhere but
I've never taken the time to hunt one down.

-- 
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


Re: tkinter: tksheet

2021-06-17 Thread Alan Gauld via Python-list
On 17/06/2021 00:15, Rich Shepard wrote:

> When I view my contacts table it needs to includes attributes from the
> company, people, and contacts tables so I can view all prior contacts with
> that person.

Sounds like a job for a database view.
Can you modify the database schema? Could you create a
view - even a temporary one just while your app is running?

Alternatively, and I've done this trick myself, create an
in-memory SqlLite database with a table that holds all the
columns you want then fetch the data from the master and
manipulate/view it from Sqlite - this makes sorting by
different columns fast and simple.

The downside is you have to refresh it periodically or
you will miss all changes in the master.

> Many years ago I used wxPython. For several reasons I decided to learn and
> use tkinter from now one. One reason is that the application for my clients
> will run mostly on windows hosts and I want to limit the software they need
> to install and maintain in order to run it.

Sure, that's the main reason I use tkinter too.


-- 
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


Re: tkinter: tksheet

2021-06-16 Thread Alan Gauld via Python-list
On 16/06/2021 21:45, Rich Shepard wrote:

> The two applications I'm building are both database applications. If
> tksheet() is not the most appropriate widget to display database tables what
> alternative would be better?

I've not used tksheet but it sounds like it might be worth investigating.

There is a grid in Tix but its quite hard to use and Tix is now
deprecated. It was also a bit unreliable when used from
Python (that's euphemistic for "I couldn't get it to work!" :-)

But there is nothing I know of for Tkinter that provides views
of database tables in the way that Delphi or VB or C# do, for
example. You have to extract the data using SQL and populate
the table and manage all changes (of both view and data) yourself.

A good grid component would be a huge boon for tkinter, its one
of the most commonly used widgets in VB/Delphi etc

A DB-API linked grid would be the height of luxury...

If you do a lot of that kind of desktop apps then you could
look at Dabo which is built on wxPython but has links to databases.
Unfortunately it looks like work ground to a halt about 5 years ago.

-- 
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


Re: Terminology: EU language skills, and Master to Main (or ...)

2021-06-14 Thread Alan Gauld via Python-list
On 13/06/2021 04:21, dn via Python-list wrote:

> What do you think a professionally-recognisable series of skill-levels
> for programmers?

This has been done or attempted many times, with perhaps the most
complete scheme being the British Computer Society's
"Industry Standard Model" which breaks jobs/skills in the industry
into many categories(30 or so?) and within each category there
are up to 6 levels of achievement. (Some skills don't have
the lowest levels(e.g. architect) while some only have lower
levels. The theory being a level 6 practitioner in and skill
is equally "good" as a level 6 in any other skill. One of
the skills is programming, and significantly, it is language independent.

I don't know if the ISM is still in use, it is many years
since I worked with the BCS as the training officer for our
office. But there used to be a comprehensive set of web pages
describing the requirements for each level for each skill.
A quick search for BCS ISM didn't throw up a link, sorry.

-- 
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


Re: Tkinter8.6: date picker

2021-06-14 Thread Alan Gauld via Python-list
On 11/06/2021 22:20, Rich Shepard wrote:
> I need a date picker 

+1


-- 
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


Re: fabric: fab command

2021-06-02 Thread Alan Gauld via Python-list
On 02/06/2021 14:35, jayshankar nair via Python-list wrote:

> import tools.fab.dev_utils as dev_utilsImportError: No module named 
> tools.fab.dev_utils
> Please let me know which package i have to install.

Work backwards.
Can you import tools.fab?
Can you import tools?

Once you know what you do have you can figure out
what you don't and why.

-- 
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


Re: Neither pdb or print() displays the bug

2021-06-01 Thread Alan Gauld via Python-list
On 01/06/2021 21:18, Rich Shepard wrote:
> On Sun, 30 May 2021, Cameron Simpson wrote:
> 
>> I've only just started with pdb. As of Python 3.7 there's a builtin
>> function named breakpoint() which drops you into the debugger.


> I'm stuck with neither approach (pdb, print()) working. 


> The activitytypes.py module:
> 

> class ATMainWindow(qtw.QMainWindow):
> 
>  def __init__(self):
>  super().__init__()
> 
>  # Model/View here.
>  self.model = qts.QSqlTableModel(db=db) # for single table
>  self.model.setTable('activitytypes')
>  self.model.select()
> 
>  self.table = qtw.QTableView()
>  self.table.setModel(self.model)
> 
>  self.setFixedSize(qtc.QSize(800, 600))

Assuming this is the line you want to examine set a beakpoint just above
it using the function that Cameron mentioned

(Or just set a breakpoint on the init() from pdb...

Trying to use step/next to debug an event driven application
is next to impossible. set breakpoints on the methods that
get triggered by events then generate the event to reach
the breakpoint.

Or, as in this case, on the init if you want to examine
objects as they are created.

As a general rule if you have to hit next/step more
than half a dozen times in a row you are probably making
extra work for yourself!


>> $/development/business_tracker/activitytypes.py(29)()
> -> window = ATMainWindow()
> (Pdb) n
> False
>> $/development/business_tracker/activitytypes.py(30)()
> -> window.show()
> (Pdb) n
>> $/development/business_tracker/activitytypes.py(32)()
> -> app.exec_()
> (Pdb) n
> n
>> $/development/business_tracker/activitytypes.py(32)()->None
> -> app.exec_()
> (Pdb) n

I'm not sure why you got that twice.
I'd expect you to only see it once.

> 
> and there it sits. No (Pdb) prompt, nothing. And no printed statements.

It's waiting while the app runs and for you to terminate it.

> I'd appreciate recommendations on the process to find where the bug lives
> since I can't seem to find it with print() or line-by-line in pdb.

Use breakpoints, don't try to step through the code from the
beginning - there lies madness!

And for event handlers that get called a lot use conditional
breakpoints so that you only stop when you want to.

-- 
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


Re: Definition of "property"

2021-06-01 Thread Alan Gauld via Python-list
On 31/05/2021 15:59, Dennis Lee Bieber wrote:
> On Sun, 30 May 2021 21:20:24 +0100, Alan Gauld via Python-list
>  declaimed the following:
> 
>> On 30/05/2021 17:57, Irv Kalb wrote:
>>> I am doing some writing (for an upcoming book on OOP), and I'm a little 
>>> stuck.  
>>
>> Oh dear, that's one of myt hot buttons I'm afraid!
>> I hope it really is about OOP and not about classes. Classes
>> are such a minor part of OOP that it is depressing how many

>   To me, OOP tends to be language specific... 

OOP is supposed to be a programming paradigm in the same way that
Functional or Logic programming are paradigms. Its all about
how you organise your code. It should be based on message
passing between autonomous agents(objects). Classes etc are
language constructs aimed at making OOP easier, but they
are not OOP. It's very easy to build a class/object based
program that is not in any way OOP (in fact I'd go as far
as to say the majority of such programs today come into
that category). It's also possible (but difficult!)
to build an OOP program without classes.

Incidentally, I'm not arguing that classes should not be used
in imperative programming, they can be very powerful there
too. Just that using classes is not necessarily OOP.

> Finding books on OOAD -- which should be language agnostic -- is 
> more difficult, and tend to turn into books about how to use 
> UML rather than how to analyze/design using OO.

That's a fairly modern phenomenon. Most of the early books about
OOAD were language agnostic - even when they used a language for
demonstration purposes.

Books like Grady Booch's classic OOAD, or Peter Coad's series
with Ed Yourdon. The so-called method wars. They all had their own
methodology, but mostly that was just diagrammatic variances. The
underlying techniques and resultant structures were the same.
(And hence the move to UML, which is just a notation - an
extremely useful one, although often abused through over
zealous application.)

Even Rumbaugh's OMT book was meant to be general OOD, although
IMHO it was the least OO of all of them being heavily based
on data modelling.

Sadly, there are very few books today that even attempt to
describe the difference between OOP and the more common
procedural programming paradigm. Discussions of OOP have
degenerated into discussions about OOPL features rather than
how to build worlds of objects passing messages to each other.

-- 
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


Re: How to debug python + curses? [was: RE: Applying winpdb_reborn]

2021-06-01 Thread Alan Gauld via Python-list
On 31/05/2021 16:16, Grant Edwards wrote:
> On 2021-05-30, Alan Gauld via Python-list  wrote:

>> You are not alone. debugging curses is one of the biggest obstacles to
>> its use.
> 
> Can't you just run the debugger in a different window and attach to
> the process you want to debug? That's how one uses a debugger with
> curses apps written in C/C++. 

That's how we did it when I used curses on VMS/Unix using C.

But I confess I didn't think you could attach any python
debugger to another python session?

> Or I add debugging printf calls which
> write to stderr and redirect stderr to a file.

I do use logging sometimes but its not as immediate
as seeing the messages in the application as you run it.

>> My approach is to define a status line at the bottom of my program and
>> write print statements into that window. Something like:
> 
> Why not just use the standard python logging facility and log to a
> file or another terminal window?

I find the immediacy of an in-window message much easier. Its like using
print() statements in a regular CLI application. Its there in front of
you, no other terminals to look at.


-- 
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


Re: Definition of "property"

2021-06-01 Thread Alan Gauld via Python-list
On 31/05/2021 01:24, Greg Ewing wrote:
> On 31/05/21 8:20 am, Alan Gauld wrote:
>>
>> That's a very Pythonic description.
> 
> If it's a book about Python, it needs to be. The word "property"
> has a very specialised meaning in Python.
> 
> In some other languages it's used the way we use "attribute" in
> Python. So a Python-specific definition is necessarily going
> to be very different from a generic one.

That was the point, the OP said it was a book about OOP.
Not a book about "OOP in Python". The two are not synonymous.

If we go back to the very beginnings of OOP, properties were
defined as the publicly available state variables of the object.
(Some others favoured using "properties" to describe the entire
set of messages to which an object could respond).

In classification theory they are defined as "the essential
characteristics of an object that identify it with a class"
Some theorists also insist that such properties be immutable
after instantiation of the object.

The first could be considered quite close to what Python
does(or allows you to do) but the second is quite different!
Although properties can be used to create a form of immutablity.

-- 
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


Re: Definition of "property"

2021-05-31 Thread Alan Gauld via Python-list
On 30/05/2021 23:57, Mike Dewhirst wrote:

> 
> A property is an object method masquerading as a cachable object attribute

Or a group of methods perhaps?

-- 
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


Re: How to debug python + curses? [was: RE: Applying winpdb_reborn]

2021-05-30 Thread Alan Gauld via Python-list
On 30/05/2021 18:26, pjfarl...@earthlink.net wrote:
> I tried winpdb-reborn some time last year on my Win10 system (python 3.8.3
> at that time), but could not figure out how to use it to debug a python
> script that uses the curses module.

You are not alone. debugging curses is one of the biggest obstacles to
its use.

My approach is to define a status line at the bottom of my program and
write print statements into that window. Something like:

def main(stdwin):
appwin = curses.newwin(...) # LINES-1 high
status = curses.newwin(...) # 1 line high positioned on bottom
# more code here
status.addstr(0,0, "Value of foo = %s" % foo)

curses.wrapper(main)

After debugging the status window can either be retained as an
application status bar or removed and the main window
enlarged by one line...

If anyone else has found a better way to debug curses code I'm
also keen to hear!

HTH
-- 
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


Re: Definition of "property"

2021-05-30 Thread Alan Gauld via Python-list
On 30/05/2021 17:57, Irv Kalb wrote:
> I am doing some writing (for an upcoming book on OOP), and I'm a little 
> stuck.  

Oh dear, that's one of myt hot buttons I'm afraid!
I hope it really is about OOP and not about classes. Classes
are such a minor part of OOP that it is depressing how many
books and articles focus on them to the exclusion of all
else that make up the OOP paradigm! Anyway, rant over...

> I understand what a "property" is, how it is used and the benefits, 

Do you? What is that based on? Is it how properties are used in OOP?
Or how they are used in Python? Is your book truly about OOP or
how Python does OOP (very different things!) How do python
properties compare to properties in other languages like
Object Pascal(aka Delphi) and Eiffel for example?
Which of these 3 options most closely models the pure OOP
concept of a property?

> definition of property.  

In OOP or in Python? Or both?

> A property object has getter, setter, and deleter methods 
> usable as decorators that create a copy of the property 
> with the corresponding accessor function set to the decorated function. 

That's a very Pythonic description.

> (I would like to avoid going through the whole derivation 
> with the property function, as that would distract from 
> the points that I am trying to make.) 

Which are?
Hopefully, about abstraction of data and function/methods
therby encouraging polymorphic representations of program structures,
which is the essence of OOP.

-- 
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


Re: Python doesn't work

2021-05-30 Thread Alan Gauld via Python-list
On 30/05/2021 12:23, Mr.Incognito wrote:
>Hello
> 
>I downloaded the latest versioon of Python and tried to open several .py
>files, but it doesn't open. It opens for a sec, then closes itself. I
>tried uninstalling and reinstalling, but it doesn't work.

Most likely it is working but faster than you can see.
Python is a program interpreter so if you simply execute
a .py file, the interpreter will execute it and terminate.
Any output will be displayed in a terminal window which
will close when the interpreter finishes.

The way round that is to launch the programs from inside
an existing command shell. assuming you are on Windows hit
Windows-R and type cmd to get a Windows> prompt. Then type

C:\WINDOWS> py \path\to\python\file.py

And you should see the program output.

-- 
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


Re: Applying winpdb_reborn

2021-05-30 Thread Alan Gauld via Python-list
On 30/05/2021 00:03, Cameron Simpson wrote:

> I'd imagine debugging is much like it is in C. Wait for the breakpoint 
> to trip, then inspect the programme variables.

That's a pretty crude form of debugging (although much better than just
single stepping from the beginning!).

Adding conditional breakpoints that stop only when variables are at
certain values, tracepoints that print out a set of values every time a
line is executed and watchpoints that keep a running display of a set of
variables all allow much faster location of errors.

I don't recall how many of those pdb supports but I'm pretty
sure watch points and conditional breaks are there.

-- 
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


Re: Applying winpdb_reborn

2021-05-29 Thread Alan Gauld via Python-list
On 29/05/2021 19:10, Dennis Lee Bieber wrote:
> On Sat, 29 May 2021 09:51:04 -0700 (PDT), Rich Shepard
>  declaimed the following:

>> What I find interesting is that every web page I find on 'using pdb' does no
>> more than explain the available commands; they don't explain the debugging
>> process. That's like showing someone what the word processor menus do; it
>> doesn't teach the user how to be a writer.

I would point out that my book on learning to program included a chapter
on using debugging, half of which was on pdb and how to use it. But that
book is now over 20 years old and based on Python 1.5.3! but
interestingly nearly all the reviewers specifically praised my
inclusion of a chapter on debugging.

>> I knew the debugging process with Fortran and C, but haven't learned how to
>> effectively use pdb to find bugs that don't issue a traceback or obvious
>> wrong answer such as my module displaying an empty window with no widgets.

Like most debuggers, set breakpoints, watchpoints and variable traces.

>   The only debugger I used to be familiar with was that of (Open)VMS.

My first job after graduating was writing white-box test scripts for a
PABX control system. It was done by writing VMS Debug scripts and then
running those scripts with  various input files to provide the different
initialization settings. I wrote around 100K lines of debug scripts to
test around 60K lines of C. It was an amazingly powerful debugger.

>   I don't even want to think of GDB...

I used gdb a few years after VMS DBG and thought it a dreadfully
primitive beast by comparison. The scripting and automation
features in particular were arcane by comparison.

But they are all more similar to pdb than to winpdb.

Maybe the OP could consider IDLE, it would at least be closer
to an IDE debugger than pdb! And in its latest incarnations Idle
is becoming a fairly useful tool once more.

-- 
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


Re: string storage [was: Re: imaplib: is this really so unwieldy?]

2021-05-26 Thread Alan Gauld via Python-list
On 26/05/2021 22:15, Tim Chase wrote:

> If you don't decode it upon reading it in, it should still be 100MB
> because it's a stream of encoded bytes.  

I usually convert them to utf8.

> You don't specify what you then do with this humongous string, 

Mainly I search for regex patterns which can span multiple lines.
I could chunk it up if memory was an issue but a single read is
just more convenient. Up until now it hasn't been an issue and
to be honest I don't often hit multi-byte characters so mostly
it will be single byte character strings.

They are mostly research papers and such from my university days
written on a Commodore PET and various early DOS computers with
weird long-lost word processors. Over the years they've been
exported/converted/reimported and then re-xported several times.
A very few have embedded text or "graphics"/equations which might
have some unicode characters but its not a big issue for me in practice.
I was more just thinking of the kinds of scenario where big strings
might become a problem if suddenly consuming 4x the storage
you expect.

-- 
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


Re: string storage [was: Re: imaplib: is this really so unwieldy?]

2021-05-26 Thread Alan Gauld via Python-list
On 26/05/2021 14:09, Tim Chase wrote:

>> If so, doesn't that introduce a pretty big storage overhead for
>> large strings?
> 
> Yes.  Though such large strings tend to be more rare, largely because
> they become unweildy for other reasons.

I do have some scripts that work on large strings - mainly produced by
reading an entire text file into a string using file.read(). Some of
these are several MB long so potentially now 4x bigger than I thought.
But you are right, even a 100MB string should still be OK on a
modern PC with 8GB+ RAM!...

-- 
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


string storage [was: Re: imaplib: is this really so unwieldy?]

2021-05-26 Thread Alan Gauld via Python-list
On 25/05/2021 23:23, Terry Reedy wrote:

> In CPython's Flexible String Representation all characters in a string 
> are stored with the same number of bytes, depending on the largest 
> codepoint.

I'm learning lots of new things in this thread!

Does that mean that if I give Python a UTF8 string that is mostly single
byte characters but contains one 4-byte character that Python will store
the string as all 4-byte characters?

If so, doesn't that introduce a pretty big storage overhead for
large strings?

> 
>  >>> sys.getsizeof('\U0001')
> 80
>  >>> sys.getsizeof('\U0001'*2)
> 84
>  >>> sys.getsizeof('a\U0001')
> 84

Which is what this seems to be saying.

I confess I had just assumed the unicode strings were stored
in native unicode UTF8 format.

-- 
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


Re: learning python ...

2021-05-25 Thread Alan Gauld via Python-list
On 25/05/2021 00:41, Jon Ribbens via Python-list wrote:

> What would you call the argument to a function that
> returns, say, an upper-cased version of its input?

Probably 'candidate' or 'original' or 'initial' or
somesuch.  Or even just 's'. Single character names
are OK when there is no significant meaning to convey!

But never a type name since the type could change or
be extended (like bytes or even a user defined string
subclass.)

The exception being where it's a teaching exercise
where the type is important, but even there I'd precede
it with an article: aString, the_string or similar.

-- 
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


Re: learning python ...

2021-05-24 Thread Alan Gauld via Python-list
On 24/05/2021 19:48, Grant Edwards wrote:

>> Traceback (  File "", line 1
>> if = 1.234
>>^
>> SyntaxError: invalid syntax
> 
> I must admit it might be nice if the compiler told you _why_ the
> syntax is invalid (e.g. "expected conditional expression while parsing
> 'if' statement").

Although wouldn't it be "expected boolean expression" rather than
conditional expression? Python doesn't care how the argument  to 'if'
is arrived at so long as it's a boolean. And with assignment
expressions, conditional expressions and literals all possible
unambiguous error messages get harder and harder to figure out.

But I do accept the general point that slightly more information
about syntax errors would be nice.

-- 
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


Re: learning python ...

2021-05-24 Thread Alan Gauld via Python-list
On 24/05/2021 16:54, Michael F. Stemper wrote:

> In my early days of writing python, I created lists named "list",
> dictionaries named "dict", and strings named "str". I mostly know better
> now, but sometimes still need to restrain my fingers.

I think most newbie programmers make that mistake. I certainly
did when learning Pascal back in the 80's.

But I was lucky, the tutorials were run by a guy who penalized
bad variable names severely and took a half-mark off for every
bad name. We very quickly learned to choose names that were
descriptive of the purpose rather than the type.

Its a lesson that I've never forgotten!

-- 
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


Re: learning python ...

2021-05-24 Thread Alan Gauld via Python-list
On 24/05/2021 07:21, hw wrote:

>> Inside the function f() the name 'x" shadows the global "x"; references
>> to "x" are to the function's local vairable. Which is very desireable.
> 
> If it works that way, I would consider it an entirely different 
> variable.  

Remember that in Python variables are just names.
They are literally keys to a dictionary and the value that is
associated with the name can change. It may be a literal value,
a function or a class or a type.

Names can be anything that is not a reserved word. (Provided
they keep within the naming grammar rules)

Also, unlike some other languages, type names are not reserved
words.

 by naming a variable like a variable type, I would think it is a bad
 idea for python to allow this without warning.

It does warn you, that's what the message it printed said:

 print(isinstance(int, float))
TypeError: isinstance() arg 2 must be a type or tuple of types


There is only on possible cause for that error. float is not
a type or a tuple of types. Therefore you must have changed
it somewhere.

Since this is the first place in the program that python can
identify an error, this is where the message gets printed.

You are working in a dynamic language that allows you to do
whatever you want to do.

-- 
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


Re: STARTUP FAILURE

2021-05-13 Thread Alan Gauld via Python-list
On 13/05/2021 14:49, Sumukh chakkirala wrote:
> Hello, I have been facing this " startup failure" for a while now, I can
> open the IDLE from the programs that I have saved but I'm not able to open
> the IDLE directly. Hope you can help me with this issue as soon as possible.
> 

Usual questions:

Which OS?
Which python version?

How exactly are you trying to open IDLE?
And what happens? Any errors?

How are you opening it "from the programs that I have saved"
What exactly does that meaN? Right click in a File explorer program maybe?

Have you tried other ways, such as from the command line?


-- 
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


Re: Start Python programming

2021-04-28 Thread Alan Gauld via Python-list
On 27/04/2021 18:32, Gazoo wrote:

> I'd like to start learning Python programming. What sites/tutorials
> could you recommend for beginner, please.

There is a getting started page on the python web site with
links to guide you to many listed suggestions - books,
web tutorials, video courses etc.

https://www.python.org/about/gettingstarted/

Which one suits you best depends on many factors both objective and
subjective.


-- 
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


Re: "py.ini" question

2021-04-25 Thread Alan Gauld via Python-list
On 24/04/2021 15:23, Gisle Vanem wrote:
> I have a question about the Python launcher;
>c:\Windows\py.exe and the py.ini file.
> 
> I have both Python 3.6 (32-bit) and Python 3.8 (64-bit)
> installed. And I have a 'c:\Users\Gisle\AppData\Local\py.ini'
> with this only:
>[defaults]
>python=3.6

I don't really use python on Windows so don't use this file.

However, based on some of the other responses, what happens
if you don't specify a version? ie. just type

py -c "...

And also what happens if you add an explicit python3 line as
in Barry's example:

[defaults]
python=3.6
python3=3.6

As I say, pure speculation on my part. But if it helps...


-- 
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


Re: Ad-hoc SQL query builder for Python3?

2021-04-25 Thread Alan Gauld via Python-list
On 24/04/2021 15:24, Rich Shepard wrote:
> My web searches are not finding what I need to include in an application I'm
> building: an ad-hoc sql query builder.
> 
> End users will want to query their data for reports not included in the
> built-in queries.

I assume you understand the huge risks involved in such a tool.
Letting users loose on their own data (and possibly other peoples)
allows for huge potential damage/data loss etc.

You can reduce the risk by finding ways to limit the access
to read-only and tightly controlling which tables etc can be
accessed. But many SQL builder tools don't do that and simply
provide a way to create queries, including drop table,
delete from etc. (Quite reasonably since they are usually
aimed at DBAs rather than ordinary users)

As a minimum ensure you have auto-backup processes in
place every time the tool is opened.

-- 
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


Re: do ya still use python?

2021-04-20 Thread Alan Gauld via Python-list
On 20/04/2021 04:47, Dan Stromberg wrote:

> Actually, this list is less busy than it was a decade or two ago, but
> that's probably because of things like stackoverflow, python-dev, pypy-dev,
> cython-devel, python-ideas, distutils-sig, issue trackers, code-quality,
> and probably others.
> 
> There was a time when most python-related discussion happened here on
> python-list/comp.lang.python.
> 

It's also a reflection of Python's maturity in the market. It is no
longer a cute language that folks stumble across and need lots of
support to get up and running. There are all sorts of formal and
informal training routes available. People are far more likely
to have a buddy at work using Python that they can ask stuff.

We see the same trend on the tutor list, traffic has dropped off
by a factor of 3-5 times what it was at its peak. And the questions
are changing too, fewer basic things about loops and writing
functions, more about specific library modules and such. (That's
why I now have time to regularly read this list instead of
dipping in once or twice a month! :-)

-- 
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


Re: Ann: New Python curses book

2021-04-15 Thread Alan Gauld via Python-list
On 14/04/2021 19:55, Rich Shepard wrote:
> On Wed, 14 Apr 2021, Alan Gauld via Python-list wrote:
> 
>> The paper version should be fine (apart from one error on p44 which has
>> now been fixed!).
> 
> Alan,
> 
> What's the error and correction so I can change it in my dead tree version?
> 
> Rich

In the main() function the block of code starting with the 'with'
statement should be indented to be part of main().
It has been left at the outermost indentation level.

The source code file is correct so check against that.

-- 
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


Re: port to PDOS (especially mainframe)

2021-04-14 Thread Alan Gauld via Python-list
On 14/04/2021 11:35, Paul Edwards wrote:
> I have succeeded in producing a Python 3.3 executable
...
> However, the executable doesn't work yet.
Late to this party but how big is the assembler?
It might be easier to translate the Python to C!
I've done that in the past and with the aid of a
few functions to mimic common Python constructs
(dicts, foreach() etc) it was verbose but not
too painful.

If its <5K? lines of Python it might be easier.

Just a thought.

-- 
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


Re: Ann: New Python curses book

2021-04-14 Thread Alan Gauld via Python-list
On 30/03/2021 12:12, Alan Gauld via Python-list wrote:
> I've just published, in Kindle and paperback formats,

I've just noticed that the kindle version has several indentation
problems in the code listings. I can't do anything to fix it
because it is all perfectly aligned in the Word file I submit,
it's caused somewhere in the Amazon conversion process. (In fact
it's possibly its OK on some Kindle devices/apps, just not
the web reader I was using!)

Hopefully the expected readership will be smart enough to:
a) figure it out from the context and
b) download the sample code which is correctly formatted.

The paper version should be fine (apart from one error
on p44 which has now been fixed!).

Apologies to anyone who got stung by this.

-- 
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


Re: UI design: combobox or radiobuttons?

2021-04-13 Thread Alan Gauld via Python-list
On 13/04/2021 22:53, Rich Shepard wrote:

> While a set of radiobuttons occupies more room on the parent widget than
> does a combobox are there any technical or user issues that would suggest
> using one over the other?

readability?
If the combo box puts the units immediately beside the value then
it will be more readable than if it is a row of radio buttons
above/below or beside the value.

But if the radio buttons represent a unit choice that applies
to all values on the screen then that is more noticeable and
thus more readable than a single small combobox choice
lurking in a corner somewhere.

-- 
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


Re: Ann: New Python curses book

2021-04-12 Thread Alan Gauld via Python-list
On 12/04/2021 00:53, Daniel Nelson wrote:

>> (It should be available in most other Amazon stores too)
> 
> This looks handy, I'd love to buy a copy but I don't do business with
> Amazon if I can avoid it.  Any chance this will be available from other
> locations?

I tried to publish it on several open-source web sites but none
of them responded to me so I went with Amazon as the commercial
site most people turn to first and with the widest reach.
Also the Amazon publishing tools are very easy to use.
However, one of their conditions for low cost books is
exclusivity, so no it won't appear anywhere else unless I
increase the price significantly which I don't want to do.

What I might do is host the original translation of the C
document as a PDF on my own web site. But that's not likely
to show up in many searches! If I get round to that I'll
announce it here.

-- 
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


Re: How to access a variable from one tab in another tab of a notebook?

2021-04-08 Thread Alan Gauld via Python-list
On 08/04/2021 06:01, Mohsen Owzar wrote:

>> But this is why GUIs are often(usually?) built as a class 
>> because you can store all the state variables within 
>> the instance and access them from all the methods. 
>>
>> You can do it with functions but you usually wind up 
>> with way too many globals to be comfortable.

> Because I'm a newbie in Python and write programs since 
> a couple of months, and I'm not so familiar with classes, 

OK, In that case you should probably read up on classes
and play around with them to get used to the ideas of
classes, objects and methods.

You can carry on using functions but you will need to
keep track of quite a lot of global variables which
can get messy in bigger programs. Classes just keep
things a bit more tidy.

> would be very nice to give me a code, how I have to 
> change my code into a class form.
> I tried without a class and I ran into problems that 
> the defined frame and entry are not defined.

One of the problems in your code is that you are not
storing references to the widgets you create. You are
relying on the containment tree to store the references
and keep them alive. But that makes it difficult to
access. As a general rule of thumb if you are creating
any widget that responds to events you should keep
a reference to it - ie. create a variable.

For example in your code you have a section like this:

def gen_t2(frame):
  def getValue(event):...

  lbl = Label(frame, text='Val').pack()

  ent = Entry(frame)
  ent.pack()
  ent.insert(0, '2')

  ent.bind('', getValue)

And you call it like this:

if firstTime2 == 1:if firstTime2 == 1:
  gen_t2(tab2)
  firstTime2 = 0

  gen_t2(tab2)
  firstTime2 = 0

Inside the function you store a reference to the Entry as ent.
but ent disappears as soon as the function ends, you cannot
use ent to access your entry outside the function.
You need to return the widget like so:

def gen_t2(frame):
  def getValue(event):...

  ...
  ent.bind('', getValue)
  return ent

And then call it like:

   if firstTime2:
  entry_field = gen_t2(tab2)
  firstTime2 = False

Now you can access your Entry field via the global
variable entry_field.

I suspect you should forget about the classes for now, focus
on getting the functions to work, especially returning values
and storing those in global variables that you can access from
elsewhere. These principles are just as important when you
get round to studying classes later.

And remember that global variables in one module can be
accessed from another module by importing the first module
into the second and using the module name as prefix.

import tab2

txt = tab2.entry_field.get()

HTH

You might also find the functions, namespaces and GUI sections
of my tutorial useful (see below).

-- 
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


Re: How to access a variable from one tab in another tab of a notebook?

2021-04-07 Thread Alan Gauld via Python-list
On 07/04/2021 09:35, Mohsen Owzar wrote:

> The problem is that I can't use the variable "val" from Tab2 in Tab 1, 

> # Filename: Tab1.py
> from tkinter import *
> 
> def gen_t1(frame):
>   f = LabelFrame(frame, text='f', bg='lightgreen')
>   f.pack(expand=True, fill='both')
> 
>   b1 = Button(f, text='B1').pack()
> 
> ##  if val > 5:


> # Filename: Tab2.py
> from tkinter import *
> 
> def gen_t2(frame):
>   def getValue(event):
> val = ent.get()
> print(val)

Note that val is a local variable within a nested function.
It only exists while the nested function is executing.
As soon as the function ends val is thrown away.

If you want the value of the entry you need to store it
in a variable that is visible after the function exits
(by returning it perhaps? or setting a global - ugly)

But you still have the problem of making that visible
to Tab1. You could import tab2 into tab1 and use Tab2.varName

But this is why GUIs are often(usually?) built as a class
because you can store all the state variables within
the instance and access them from all the methods.

You can do it with functions but you usually wind up
with way too many globals to be comfortable.

> from Tab1 import gen_t1
> from Tab2 import gen_t2
...
> def on_tab_change(event):
>   global firstTime1, firstTime2
>   
>   tab = event.widget.tab('current','text')
>   if tab == 'Tab 1':
> print('Tab 1')
> if firstTime1 == 1:
>   gen_t1(tab1)
>   firstTime1 = 0

Probably nicer to use boolean values for
firstTime1 and firstTime2, ie True and False
rather than their numeric equivalents.

HTH
-- 
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


Re: Horrible abuse of __init_subclass__, or elegant hack?

2021-04-02 Thread Alan Gauld via Python-list
On 02/04/2021 21:33, dn via Python-list wrote:

> Bournville was the only Cadbury chocolate I would
> consider. Today, even that seems to lack

Cadbury has always been a budget chocolate brand(*) here;
its a mass market option loaded with sugar and little
else. Certainly doesn't compare to Suchards, Lindt,
Nestle or Green & Black, or even Lidl's own brand:
Fin Carre (especially their "Rich Dark" milk choco!
).

(*)I'm guessing Hershey is the equivalent stateside?

> conversation) it is worth noting that the Cadbury brothers had some
> ideas about caring for workers/contributors in similar manner to PSF's
> interests in egalitarianism and diversity - certainly a quality-of-life
> beyond those of the often quoted 'advances' credited to Henry Ford.

Indeed, social engineering that to some extent still
exists today.

-- 
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


Re: Friday Finking: initialising values and implied tuples

2021-04-02 Thread Alan Gauld via Python-list
On 02/04/2021 23:10, dn via Python-list wrote:
> When there are several items to be defined and initialised, how do you
> prefer to format the code, and why?

> (a) basic linear presentation:
> 
> resource = "Oil"
> time = 1
> crude = 2
> residue = 3
> my_list = "long"

In production code I'd almost always go with this one.
It's the only option that both keeps the variable and value
together and allows me to add an explanatory comment if
necessary.

> (e) implicit tuples:
> 
> resource, time, crude, residue, my_list = "Oil", 1, 2, 3, "long"
Occasionally, and in personal code, I'll  use this.
Although this would be about as many items I'd ever
have in one list.

But in production code, if items are related, I'd use it.
eg.
x,y = 42,50   # starting coordinates
hour,min,sec = 0,0,0  # default start time

But in both those cases I'd more likely define a variable
to be a tuple:
eg.
start = (42,50)  # starting coordinates

-- 
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


Re: Horrible abuse of __init_subclass__, or elegant hack?

2021-04-02 Thread Alan Gauld via Python-list
On 02/04/2021 00:42, dn via Python-list wrote:

> Contrarily "tuck" in (old) English slang represented "sweets" (or

Not that old. We still use it occasionally today. And we
certainly had a "tuck shop" at school. It was where you
bought lunch if not eating in the refectory. ie. sandwiches,
crisps, pop etc. But its main sales were sweets including
chocolate bars  (bringing us back to Cadbury :-)

Unusually, our tuck shop was run by the student body. The
school prefects were the operating committee and
responsible for finding volunteers to staff it and
order supplies and bank the proceeds 9with the school
secretary)

-- 
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


Re: Horrible abuse of __init_subclass__, or elegant hack?

2021-04-01 Thread Alan Gauld via Python-list
On 01/04/2021 00:14, Chris Angelico wrote:

> On a scale of 1 to "submit this to The Daily WTF immediately", how bad
> is this code? :)

The only worthwhile test of code quality is whether a new member
of the team, competent in the language but not an expert can
understand the code in two readings or less. If they can it's
good enough. Maintenance is always the highest cost in any
significant project so good code must be maintainable.

In this case I'd venture they'd encounter init_sublass() for the
first time, do some research and on the second reading make sense
of it. So, it's good to go.

Whether it's an optimal design or not is a different matter.
There's always more than one way to do it.

-- 
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


Source code link was: Re: Ann: New Python curses book

2021-03-31 Thread Alan Gauld via Python-list
On 31/03/2021 00:09, Alan Gauld via Python-list wrote:

> Watch this space. Hopefully tomorrow.

The source code is now available in a zip file at:

http://www.alan-g.me.uk/hills/PythonCursesCode.zip

Or via a link on the programming section of my
home page

http://www.alan-g.me.uk/

It is licensed using a Creative Commons license.

-- 
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


Re: New Python curses book

2021-03-30 Thread Alan Gauld via Python-list
On 30/03/2021 20:05, Brian Oney via Python-list wrote:
> Congratulations!
> 
> Indeed, I was wondering for a moment if this was a guide to al dente 
> spaghetti code. With each curse being a funny way to mess with the colleagues 
> performing the code review ;)

You may jest but I originally titled it "Programming Python with curses"

And changed it precisely because I thought it might be misunderstood :-)

-- 
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


Re: Ann: New Python curses book

2021-03-30 Thread Alan Gauld via Python-list
On 30/03/2021 19:52, Grant Edwards wrote:

> It is. I just bought the kindle version on the US site, and it renders
> fine in the cloud reader. It would be cool if you could cut/paste code
> examples from the book into IDLE or a text editor, but I've never been
> able to get the cloud reader to allow that sort of thing.

Blast! You just reminded me I meant to add a link to where
the source code zip lives! (Or will live once I put it there)
I'll do an update of the kindle book but I don't know
if you can get the update for free...

I'll also post the zip file url here once I've put it up.
Thanks for that reminder.

As for cut n paste, the requirement to write in MS Word
and convert to PDF/Kindle means that quotes etc get
all messed up. And as for Python indentation I shudder
to think. That's why I intended to put the source code up.

Watch this space. Hopefully tomorrow.

-- 
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


Re: memory consumption

2021-03-30 Thread Alan Gauld via Python-list
On 30/03/2021 16:50, Chris Angelico wrote:

>> A 1GB process on modern computers is hardly a big problem?
>> Most machines have 4G and many have 16G or even 32G
>> nowadays.
>>
> 
> Desktop systems maybe, but if you rent yourself a worker box, it might
> not have anything like that much. Especially if you need to have
> multiple of them.

Rental servers on the cloud. Now that's after my time.
The last server I used had 128GB and anything less than
32GB wasn't worthy of the name.

I forget you can rent virtual servers for pennies
these days! :-)

-- 
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


Re: Ann: New Python curses book

2021-03-30 Thread Alan Gauld via Python-list
On 30/03/2021 17:14, Grant Edwards wrote:

> Is the kindle format readable via a web browser pointed at
> read.amazon.com (AKA "Kindle Cloud Reader)?

It seems to be, I downloaded the free sample and could
read the first 2 chapters on the web reader.

-- 
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


Ann: New Python curses book

2021-03-30 Thread Alan Gauld via Python-list
I've just published, in Kindle and paperback formats,
my book on "Programming curses with Python".

https://www.amazon.co.uk/dp/B091B85B77/

(It should be available in most other Amazon stores too)

It is a complete rewrite of the Linux Documentation
Project's HowTo for the C ncurses library. It has the
same structure but all-new text and several new
chapters. All specific to the Python curses package.

I've kept the prices as low as Amazon permits (and
allowing for fluctuations in their costs). As such,
I will therefore make a few cents profit per book
from sales (full disclosure). However, I felt this
was the easiest and most effective way to get it
"out there" where it could be found.

I hope it's useful to somebody.

Special thanks to all who provided me with feedback
on its various iterations, especially Alex Kleider
and Bob Stepp who stuck with it right to the end.
Thanks guys.

-- 
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


Re: memory consumption

2021-03-30 Thread Alan Gauld via Python-list
On 29/03/2021 11:12, Alexey wrote:
> Hello everyone!
> I'm experiencing problems with memory consumption.
> 

The first thing you really need to tell us is which
OS you are using? Memory management varies wildly
depending on OS. Even different flavours of *nix
do it differently.

However, most do it effectively, so you as a programmer
shouldn't have to worry too much provided you aren't
leaking, which you don't think you are.

> and after second run it weighs 1Gb. If I will continue 
> to run this class, memory wont increase, so I think
> it's not a memory leak, but rather Python wont release 
> allocated memory back to OS. Maybe I'm wrong.

A 1GB process on modern computers is hardly a big problem?
Most machines have 4G and many have 16G or even 32G
nowadays.


-- 
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


Re: convert script awk in python

2021-03-24 Thread Alan Gauld via Python-list
On 24/03/2021 16:00, Avi Gross via Python-list wrote:

> But I wonder how much languages like AWK are still used to make new programs
> as compared to a time they were really useful.

True. I first discovered awk from a Byte article around 1988/9
and it became my goto tool for text munching right up until
I found Python in 1998.

I still use it as part of a unix command pipeline but I rarely
write awk scripts in a file anymore - if it's that complex I
reach for Python.

But at one time I had a dozen or more awk scripts in my ~/bin folder.

I also used awk on a real-world project to process csv files from an
Excel spreadsheet and create site-specific config files for some shiny
new WindowsNT(v3.1) boxes we were using. They had twin network
connections and hard coded IP settings(for resilience) and the network
designers delivered the site settings by Excel. We turned them into .BAT
files using awk.

Eventually, we figured out how to write Excel macros and converted
it all to VBA. Happy days. :-)

-- 
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


Re: convert script awk in python

2021-03-24 Thread Alan Gauld via Python-list
On 23/03/2021 14:40, Avi Gross via Python-list wrote:

> $1 == 113 {
> if (x || y || z)
> print "More than one type $8 atom.";
> else {
> x = $2; y = $3; z = $4;
> istep++;
> }
> }
> 
> I am a tod concerned as to where any of the variables x, y or z have been
> defined at this point. 

They haven't been, they are using awk's auto-initialization feature.
The variables are defined in this bit of code. The first time we see $1
== 113 we define the variables. On subsequent appearances we print the
warning.

> far as I know has not been called. Weird. Maybe awk is allowing an
> uninitialized variable to be tested for in your code but if so, you need to
> be cautious how you do this in python.

It's standard behaviour in any POSIX compliant awk, variables are
initialised to empty strings/arrays or zero as appropriate to first use.

The original AWK book has already been mentioned, which covers nawk.
I'll add the O'Reilly book "sed & awk" which covers the POSIX version
and includes several extensions not covered in the original book. (It
also covers sed but that's irrelevant here)

-- 
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


Re: .title() - annoying mistake

2021-03-19 Thread Alan Gauld via Python-list
On 19/03/2021 19:58, Dan Stromberg wrote:

> In high school, I was taught that English has multiple capitalization
> rulesets to choose among for titles.
> 

And, of course, there are multiple forms of English.
English English is very different from US English.

And even in the UK there are (a few, minor) differences between
usage in Scotland compared to England, for example.

Trying to write programming languages to follow natural
language semantics and grammar is an exercise in frustration.

-- 
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


Re: How do I read .csv files

2021-03-16 Thread Alan Gauld via Python-list
On 16/03/2021 16:15, The Cool Life wrote:
> Try importing the CSV module. That might help!
And for the removal of doubt it is spelled csv 9lower case)

And it looks like you want to read about the DictReader
class within it.

The csv module docs include several examples.

-- 
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


Re: REPL peculiarity

2021-03-11 Thread Alan Gauld via Python-list
On 11/03/2021 11:01, Rob Cliffe via Python-list wrote:
> This is a valid Python program:
> 
> def f(): pass
> print(f)
> 
> But at the REPL:
> 
>  >>> def f(): pass
> ... print(f)
>    File "", line 2
>      print(f)
>      ^
> SyntaxError: invalid syntax
> 
> It doesn't seem to matter what the second line is.  In the REPL you have 
> to leave a blank line after the "def" line.  Why?

I guess just because that's how the interpreter is written. It looks for
a blank line to terminate the function definition. It does the same with
multi-line definitions too. I agree it would be possible in the case of
single line definitions to forego the blank line but it doesn't.
It does remind you that you need another line since it shows the
secondary prompt ... instead of the primary >>>

-- 
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


Re: python curses constant names for mouse wheel movements?

2021-03-09 Thread Alan Gauld via Python-list
On 09/03/2021 01:05, pjfarl...@earthlink.net wrote:
> I am replying to my own message due to the digest not appearing in my inbox
> yet today.  I will add Alan Gould's responses and my reply to him manually.

> Yes, when I talk about wheel up/down I do mean wheel rotation events, not
> wheel-button-down or up click events.  The latter are correctly reported by
> the PDCurses implementation used by windows-curses V2.2.0 as BUTTON2 events.
> 
> Christoph Gohlke gave me this link to the current-version PDCurses
> implementation definitions for the mouse state constants, which I found very
> helpful:
> 
> https://github.com/wmcbrine/PDCurses/blob/master/curses.h#L199
> 
> The PDCurses names defined there are exactly what I needed to see, even if
> the current cpython and windows-curses implementations do not support them
> quite yet.  I can safely define them myself and adjust my code as later
> releases of cpython and windows-curses are updated to support them natively.

Thanks, I've done some tests and I see the events as

WHEEL FORWARD - 0x1  or curses.BUTTON4_PRESSED
WHEEL BACK- 0x20   but not defined in the curses module

That's using ncurses on Linux.
Do you get the same mask value under PDcurses on Windows?

I suspect in the real world I'd probably create my own
definitions as WHEEL_FORWARD and WHEEL_BACKWARD just for
readability.

> This link to an ncurses man page concerning mouse events is also
> instructive:
> 
> https://invisible-island.net/ncurses/man/curs_mouse.3x.html

Thanks for that, I hadn't spotted that there was a mouse man
page before...

-- 
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   >