Fwd: Re: AUTO EDITOR DIDN'T WORK
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
Fwd: AUTO EDITOR DIDN'T WORK
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:[email protected]>> 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
Re: Fwd: AUTO EDITOR DIDN'T WORK
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
Re: Multiple inheritance and a broken super() chain
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: Multiple inheritance and a broken super() chain
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: Why do I always get an exception raised in this __init__()?
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: Why doc call `__init__` as a method rather than function?
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: Question(s)
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: Question(s)
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)
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: xor operator
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: Newline (NuBe Question)
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
Amy known issues with tkinter /ttk on latest MacOS?
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: Amy known issues with tkinter /ttk on latest MacOS?
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
Exploring terminfo
During lockdown I've been digging deeper into the curses module
and lately into the ti family of functions that reside there.
I've written a short program that is supposed to
- *clear the screen*,
- read some input
- display the result in a message *highlighted in bold*.
- get input to end the program
The parts marked with ** use terminfo, or they should.
My problem is that while the clear-screen part works the
bold bit only appears in the final input(), not in the
output message.
Here is the code:
#
import curses as cur
cur.setupterm()
bold = cur.tigetstr('bold')
cls = cur.tigetstr('clear')
cur.putp(cls)
name = input("Hello, what's your name? ")
cur.putp(bold)
print("Nice to meet you ", name)
input("\nHit enter to exit")
###
I've tried variations on flush both inside and outside
the print() - both before and after.
I've tried writing to stdout instead of print, but nothing is working.
The Hit enter... message is in bold but the Hello... line isn't.
Does anyone know what's going on and how to fix it.
I could, of course, jump into full curses but I wanted to
see if I could use the terminfo stuff directly to retain
use of regular input() and print() functions.
--
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: conceptual problem
On 13/01/2021 15:37, songbird wrote: > my momentary conceptual problem is that to me OOP means > being able to encapsulate data structures and code from > other parts of the program, That's true, but encapsulation simply means that the data and functions are contained within a single entity - ie a capsule. It says nothing about whether you can access them directly or not. When OOP started the basic concept of having functions inside the same structure as the data that they operated on was so radical that encapsulation became a big topic. But over time it has gotten mixed up with data hiding and abstraction (also big topics back in the 70/80s) So the term encapsulation has tended to be used to cover abstraction and data hiding as well as simple(pure) encapsulation. > that is how python is designed. this is probably a complete > aside to this whole thread and perhaps even this newsgroup It is a long running(as in for decades!) sub-thread to the whole Python language. :-) -- 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 sqrt is not a built-in function?
On 14/01/2021 17:44, Denys Contant wrote: > I don't understand why sqrt is not a built-in function. > Why do we have to first import the function from the math module? > I use it ALL THE TIME! because pow() is a builtin function and root = pow(x,0.5) is the same as root = math.sqrt(x) As is root = x ** 0.5 which is also builtin. My question is: why do we even have a sqrt() in the math module given that pow() and ** are already 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: Exploring terminfo
On 14/01/2021 21:30, Barry Scott wrote: >> During lockdown I've been digging deeper into the curses module >> and lately into the ti family of functions that reside there. > It seems that curses does not allow you to mix raw stdin/stdout with its > calls. That's true of curses after you call initscr() But the while point of using the tiXXX terminfo functions is that you don't need to call initscr to use them, just setupterm() which does no take control in the same way. The problem is the tiXXX functions are not well documented and there are very few tutorials, even in C! > If all you want is simple things like bold and clear I'd just use the > ANSI escape sequences directly. The whole point of terminfo is to avoid having to use terminal specific control codes. > Are there any terminals that do not understand ANSI escape sequences Lots, most significantly the x3270 IBM mainframe terminals. Now, whether you can run curses and terminfo on a 3270 I don't know... But I suspect the Wyse family are non ANSI compliant too and there are still some of them around. And of course the standard xterm emulator supports the Tektronic graphics terminal emulation so there would definitely be a use there. But to be honest if I was doing this in anger I'd just use curses. This is more about exploring the module. The functions are there and so we should be able to use them and demonstrate them. But for that we need tutorials/HowTos etc that cover them. I've already written a curses HowTo, I'd like to extend it to cover the terminfo bits too. But for now I'm drawing a blank. -- 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: Exploring terminfo
On 14/01/2021 23:08, Grant Edwards wrote:
> Alternatively, I think you can use the ncurses library to retrieve the control
> strings (just don't use any ncurses input/output calls), like this example
> from
> https://stackoverflow.com/questions/6199285/tput-cup-in-python-on-the-commandline:
>
> from curses import *
> setupterm()
>
> cols = tigetnum("cols")
> lines = tigetnum("lines")
> print str(cols) + "x" + str(lines)
>
> place_begin = tparm(tigetstr("cup"), 15, 14)
> place_end = tparm(tigetstr("cup"), 50, 0)
>
> print place_begin + "-- some text --" + place_end
That's exactly what I'm trying to do but with the character
attributes rather than cursor positioning. I can retrieve values and I
can clear the scrn. But the bold(and inverse and underline etc)
strings don;yt seem to affect print() or stdout.write(). But they do
affect the input() prompt strings.
What is different about the input() prompts? Why are they affected
when print isn't?
I've discovered that I can (sort of) get my code to work if I insert
blank input statements between the various prints. But then I need to
keep hitting return to get the display to show up - not exactly useful.
But the point is that after an input() the subsequent print statements
use the set attributes as desired. What can I insert to get the same
effect without requiring the user to type input between prints?
Or what parameter should I be setting where?
--
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: Exploring terminfo
On 14/01/2021 22:11, Grant Edwards wrote: > Or use a terminfo library: > > https://github.com/DirectXMan12/py-terminfo > > It _may_ be possible to use ncurses to get the terminfo strings > required for various functions without actually having ncurses to any > I/O, but I've never tried that... That is precisely what the tiXXX family of functions in the curses module is supposed to enable. I'm just struggling to get anything other than very basic stuff working! -- 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: Exploring terminfo
On 14/01/2021 16:12, Alan Gauld via Python-list wrote:
> #
> import curses as cur
> cur.setupterm()
>
> bold = cur.tigetstr('bold')
> cls = cur.tigetstr('clear')
>
> cur.putp(cls)
> name = input("Hello, what's your name? ")
>
> cur.putp(bold)
> print("Nice to meet you ", name)
>
> input("\nHit enter to exit")
> ###
>
> I've tried variations on flush both inside and outside
> the print() - both before and after.
> I've tried writing to stdout instead of print, but nothing is working.
> The "Hit enter..." message is in bold but the "Nice..." line isn't.
A bit more exploration and I've got a C version of the same program
to work (I'll spare you the #includes!):
int main(void){
char line[20];
int err = 0;
char *clr;
char *bold;
setupterm("xterm",1, &err);
clr = tigetstr("clear");
bold = tigetstr("bold");
putp(clr);
putp(bold);
printf("Enter a name: ");
fgets(line, sizeof(line),stdin);
printf("Hello %s\n", line);
exit(0);
}
So the native C functions work as expected.
Why does the Python wrapper not?
--
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: Exploring terminfo
On 15/01/2021 17:31, Grant Edwards wrote:
>>> cur.putp(cls)
>>> name = input("Hello, what's your name? ")
>>>
>>> cur.putp(bold)
>>> print("Nice to meet you ", name)
>> putp(clr);
>> putp(bold);
>> printf("Enter a name: ");
>> fgets(line, sizeof(line),stdin);
>>
>> printf("Hello %s\n", line);
>> exit(0);
> One difference is that the name prompt is being written to stdout in
> the C version and stderr in the Python version. But I don't see why
> that would matter.
That could make a big difference, the putp() function specifically
states that it writes to stdout.
> I suspect that the problem is that putp is writing to the libc
> "stdout" FILE stream that's declaredin . That stream
> layer/object has buffering that is invisible to Python.
That would indeed explain it.
> Now the question: is there a way to tell the curses module to flush
> its stdout FILE stream?
Indeed. But unless it's trivial it rather defeats the concept of
using the terminfo functions to create text effects without
diving into full curses screen control! And that was what I
was hoping to uncover.
I wonder if I can use the os module to mess with the
file descriptors hmmm.
Thanks for that snippet, I had no idea that input() wrote
to stderr nor that Python added a stdout layer on top of libc.
Do you know where that is documented? I'd be interested in
reading 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: Exploring terminfo
On 15/01/2021 21:41, Dennis Lee Bieber wrote: > On Fri, 15 Jan 2021 13:19:26 +0000, Alan Gauld via Python-list > declaimed the following: > >> So the native C functions work as expected. >> Why does the Python wrapper not? > > Are you running Python from a plain command shell, or from some sort of > IDE? Heh Dennis, you should know I'm strictly a vim and bash man ;-) -- 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: Exploring terminfo
On 17/01/2021 00:02, Greg Ewing wrote: > On 17/01/21 12:40 pm, Chris Angelico wrote: >> This is true. However, at some point, the boundary is crossed from >> Python into the C library. Something, at that point, knows. It's very >> common to have a flush option available, so it should be used. > > I'm wondering whether the problem in this particular case stems > from trying to use parts of curses without initialising it > properly. The problem is terminfo is not really part of curses. Curses is built on top of terminfo. > I expect that initialising curses would put stdout > into some kind of unbuffered mode, You can choose the mode, but once in curses all the standard input/output options cease to be usable, you have to use the curses functions such as addstr(), getch() etc. Its precisely because curses is such an all or nothing option that I wanted to see if I could create some kind of text attribute control outside of curses - which it seems is what Cameron has been up to independently! For example, it is difficult to call a Python function that has print statements in it (bad practice though it may be!) from within curses. You need to temporarily turn cures off, call he function then reinstate curses. It's doable but messy! If you don't need to create windows and move the cursor around and respond to mouse clicks etc then curses is a bit of overkill to just turn some text bold or inverse. That's where the terminfo functions come in and, as you saw from the C code, are fairly trivial to use in C. -- 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: Exploring terminfo
On 18/01/2021 22:14, Random832 wrote: > On Fri, Jan 15, 2021, at 13:36, Alan Gauld via Python-list wrote: >> That could make a big difference, the putp() function specifically >> states that it writes to stdout. > > I think there is a reasonable argument that this is a deficiency of the > curses module. > > I think that the curses module should ..> B) expose a version of putp that > uses pthon's stdout[.buffer].write rather than C's putchar. To be fair that's a limitation of the C curses library. putp() is a wrapper around tputs() even there, and you can't change what it does. The gap in the curses module is that it doesn't offer the tputs() option as an alternative. But there are quite a lot of gaps in the curses module it's just that most folks don't use them so nobody complains or takes action to add them. I've been using curses (C and python) for nearly 30 years and this is the first time I've ever used the tiXXX functions, and it was mainly just out of curiosity rather than real need. -- 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 you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.
On 27/01/2021 18:42, C W wrote: > I'd like to know how the experts on here are approaching and debugging > this. > > Bonus if no debugger or breakpoint. Just the good ol' run the function and > evaluate/print output for problems. One option you may like and nobody seems to have mentioned yet is to use the interactive prompt. Simply run the program with the -i flag and the program will stay in the interpreter at the >>> prompt. Similar to what you seem to be used to doing in R... >From there you can print the current value of variables, inspect objects etc. I find it useful sometimes when I'm not on my desktop PC, although usually I jump into winpdb or similar if I need that kind of support. dubuggers and breakpoints combined with watchpoints are very powerful tools and easy to learn. (Although I may be pre-disposed since my first job after uni' was to white-box test 500K lines of C using a VAX command line debugger in batch mode. I wrote over 100K lines of debugger commands!) -- 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: IDE tools to debug in Python?
On 27/01/2021 19:27, Dietmar Schwertberger wrote: > Python is an interactive language. You can develop a lot while working > on a Python console. Then copy and paste into a program. Absolutely, the humble interactive prompt is often overlooked as a development tool. It's not as good as the "evaluate expression" tool in the Smalltalk workspace, say, but it's close. I habitually use 3 windows: - an editor, a shell command line (to execute the code) and an interactive Python prompt. -- 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 you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.
On 27/01/2021 23:04, [email protected] wrote: > systems are more painful than others, but yes, some debugging > environments are more painful than others, too. Very true! but a good debugger is a godsend. Howevder... > A well placed call to print (they're not "print statements" anymore!) > can be much more enlightening and much faster than single stepping > through code in a debugger, If you are single stepping more than 2 or 3 lines then you aren't using the debugger properly! Use breakpoints(selected by brain power!) and watches. The watches are like print statements but don;t modify the source code (nothing to remove later!) Anytime I find myself hitting the step button more that a few times I know I'm not using the debugger effectively and rethink. > and seeing the output from the same print > statement inside a loop can be much better than manually examining > variables iteration after iteration and trying to remember what the > value was before. So don't do that, use the debugger. Most of them have conditional breakpoints that will stop only when you need to. > The best debugging tool, however, remains your brain. Amen to that, regardless of any software tool used. -- 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: IDE tools to debug in Python?
On 27/01/2021 18:32, flaskee via Python-list wrote: > > While print() is groovy and all, > if anyone runs across a non-pdb python debugger (standalone or IDE-based) > please let me know. > There are many. But why must it be non-pdb? That seems rather arbitrary. Or do you really mean you want a non-command-line debugger? One standalone option is winpdb But most Python IDEs have basic debugging tools built in. -- 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: Files can only be modified in IDLE, but not via Powershell
On 08/02/2021 21:33, Stefan Ritter wrote: > I have a Windows 10 ADM64 desktop and a Windows 10 AMD64 Laptop. So notionally identical. > I wrote some code to insert text in a .txt-file. It works perfectly on > my laptop. > > On my desktop it works only if i run it in IDLE, the text appears > afterwards in the file . However it does not work if run it in > Powershell (or anything else), there are no changes made in the file. You only mention powershell in the context of the desktop. How are you running the code. Can you show us the command line for both laptop and desktop? Or describe exactly what you are doing if using a GUI tool. Showing us the code may help 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: New Python implementation
On 11/02/2021 12:30, Mr Flibble wrote: > I am starting work on creating a new Python implementation > from scratch using "neos" my universal compiler that can > compile any programming language. Can i clarify that? Are you saying that you are going to recompile the existing C code for pyhton using yoour universal compiler and the resulting binary file will be a new implementation of the interpreter that you expect to be faster? That's what it sounds like to me. In which case the question is not whether you can write a better interpreter than CPython but whether you can write a better compiler than GNU/MING/VC etc While a universal compiler is certainly an interesting and challenging project I'm not sure how much it tells us about existing Python implementations. On the other hand, if you are planning on rewriting the existing interpreter in something other than C, what is that something? > Sample neos session (parsing a fibonacci program, > neoscript rather than Python in this case): I'm not sure what relevance this has unless you want to rewrite Python in neoscript? Or are you translating the C into neoscript and then compiling it? But in a later response you seem to say neoscript was not involved? Slightly confused... -- 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: super() in injected methods
On 12/02/2021 02:39, Andras Tantos wrote: > 1. Ports, which are the connection points on the various netlist > entities. These would be the inputs and outputs of an AND gate for example > > 2. NetTypes, which describe the type of data that can travel through a > net (and thus through a Port). One such type would be an 8-bit signed > integer, or a simple logic signal. > 2. A (derived) Port instance has a member of a (derived) NetType instance Sounds like the right solution. > Now, when a Port gets assigned a NetType, it needs to gain all sorts of > new features. It for example should have a 'length' attribute that tells > how many bits are needed to represent its possible values. The list of > these new features (attributes, methods, properties) are known to the > NetType and should be injected into the Port when the NetType is > assigned to the Port. So aren't these operations of the type rather than the port. If you expose the type the users can message it directly. n = myport.type.length() Keep the responsibility with the object that owns them. Creating a facade over another object is sometimes useful but a dynamic facade sounds like trouble. Client code is going to have to know which methods exist and when. Can you ever change the type? What happens to the injected methods, do you need to remove them and replace them with others? -- 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 implementation
On 12/02/2021 21:46, Mr Flibble wrote: > The neos Python implementation will consist of a schema file > which describes the language plus any Python-specific semantic concepts So the schema file is some kind of formal grammar definition of the language? And you "compile" this directly into machine code? Is that the idea? So when you say you have a universal compiler for any language what you mean is that you can produce a compiler/interpreter for any language from a language definition/schema. Is that it? I'm still not sure I understand what exactly you are proposing to do. What the final output looks like? I'm assuming it's a new executable interpreter that can run any valid python code. Is that correct? -- 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 implementation
On 13/02/2021 16:09, Mr Flibble wrote: > On 13/02/2021 00:01, Alan Gauld wrote: >> I'm assuming it's a new executable interpreter that can run any >> valid python code. Is that correct? > > It is a universal *compiler* so it compiles the python code to byte code > and then optionally to machine code via a JIT which is then executed. OK, sorry for being dense, but just to be absolutely clear. You are going to create a Python compiler that will take existing Python code and output a byte code file. (I assume the byte code is not standard Python byte code?) And I assume the execution environment for the bytecode is part of your neos system? If that's correct, then how do you propose to deal with regular Python byte code? And what would the Python disassembler produce - Python assembler instructions or neos? -- 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 implementation
On 14/02/2021 00:07, Mr Flibble wrote: > On 13/02/2021 18:11, Alan Gauld wrote: >> You are going to create a Python compiler that will take existing >> Python code and output a byte code file. > > No neos is not a Python compiler: it is a *universal* compiler that > can compile any programming language describable by a schema file Yes, I understand that, but from the perspective of this list what you are doing is providing a tool (a combination of neos and a schema) that will take in Python source code and spit out neos byte code. So, to all intents and purposes it is a Python compiler (albeit capable of more when needed). >> If that's correct, then how do you propose to deal with >> regular Python byte code? And what would the Python disassembler >> produce - Python assembler instructions or neos? > > The neos Python implementation will not be dealing > with Python byte code in any form whatsoever. Ok but what do you do with the disassembler module? Will it read neos byte code instead of the Python codes? Also what about tools that work at the byte code level, I assume they will not work with neos either? That might include the profiler and debugger for example? Also what would happen with the interactive prompt (>>>) I'm assuming you'd expect users to continue using the CPython interpreter and only compile the source after it was working there? Like turning on the optimiser in a traditional compiled language like C. -- 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: Efficiency debates
On 15/02/2021 02:26, Avi Gross via Python-list wrote: > I think we have discussed this a few times. Indeed, many times! And there is a natural tendency for a group focused on a programming language to fixate on language improvements. But it's worth while to back up and look at real world scenarios too where choice of programming language is such a minor influence on performance that it is rarely even considered significant. Much more important are things like network speeds, database speeds, disk access speeds and overall architecture and design. These are the areas that give orders of magnitude performance improvement. Next comes algorithm design, caching models and the like. These give multiple factors of improvement. Finally, we come to language tweaks and choice of language where a doubling of performance might be attainable. (Language X being "10 times faster" than language Y rarely translates to a non-trivial application being 10 times faster!) Of course, it depends on the type of project and if its a high computational scenario things will likely be different. But for the big projects that run our lives - air traffic control, taxation, payroll, billing, banking and so on, choice of language comes way down the pecking order. What's that quote about premature optimization?... -- 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 implementation
On 15/02/2021 22:24, Roel Schroeven wrote: > Grant Edwards schreef op 15/02/2021 om 21:59: >> On 2021-02-15, Roel Schroeven wrote: >> >>> Is it your intention to not only compile procedural and object-oriented >>> languages, or also functional languages such as Haskell, Ocaml, Scheme? >> >> And Prolog! > > Ha, yes, that one was the next one I thought about, but in the I decided > to leave it out. Yes, Prolog is definitely different. When I was at Uni' in the mid 80s we all got taught Prolog because the Japanese had promised to produce a 5th generation computer by 1990 and it would be based on Prolog. We're still waiting, but in the meantime we got the internet and GUIs. Looks like Sun got it right - "the network is the computer"... -- 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 implementation
On 16/02/2021 07:35, Christian Gollwitzer wrote: > Am 16.02.21 um 06:36 schrieb dn: >> Pascal's value as a teaching language was that it embodied many aspects >> of structured programming, and like Python, consisted of a limited range >> of items which could be learned very quickly > > ROFL. Maybe that was true for Python when it was first invented. Today > it is not "a few simple things". Even just the core language, Python v1 was a good teaching language. v2 complicated it a bit but it was still usable. v3 is no longer a good teaching language (unless maybe you are teaching CompSci at university.) In fact in v3 things are so complex that I seriously considered dropping Python as the core language for my programming tutorial. Until I started looking for an alternative, and there really isn't anything much better. At least not that can also be used for real projects once you've learned it. But the sort of change that has made it complicated for beginners is range(). range() used to be simple - it returned a list of numbers in the range specified. The hardest thing to explain was why it stopped one short of the upper limit. Now range returns a "range object". Say what? How do explain a range object to a beginner? And you can't avoid it because the name pops up in the interpreter. And that's just one example, the language is now full of meta goodness that makes it incomprehensible to beginners. In a teaching environment, with a teacher present to answer questions, it's probably usable, but for a self guided course it's increasingly inscrutable. -- 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 implementation
On 16/02/2021 22:23, boB Stepp wrote: >> And that's just one example, the language is now full of meta goodness >> that makes it incomprehensible to beginners. > > Hmm. I'm not sure I can agree, Alan. My son took to Python 3 like a duck to > water. That's interesting. I knew you were teaching him but not how he got on. Good for him. My comments stem from the feedback emails I get from my tutorial. People get messages like "foo is not an iterable" or references to range objects and such and it confuses them. I never got those kinds of messages for the v.1 tutorial... > Yes, there is a ton of meta-goodness in Python, but most of it can be ignored > to be able to *just use it*. But the problem I see is that you can't ignore it because it bubbles to the surface in error messages. And if you don't know what it means you don't know that you can ignore it! That's where a teacher/mentor comes in, they can say "Oh that's OK just ignore it!" but if you are on your own you think "Oh no! What do I do now?" But as I say, I can't find anything better so I'll stick with it for now. -- 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 implementation
On 16/02/2021 21:22, Tarjei Bærland via Python-list wrote: > To me, it depends on what you want out of including programming in > mathematics education. That's a really important subclass distinction. If programming is seen as an adjunct to math then the aims can be simplified considerably since you are only interested in pure computation. Things like networking, interfacing to peripherals and the like can be ignored. Likewise you probably don't care about creating large projects wit multiple files etc. With those constraints there are probably better languages than python. You mention Logo and I had fun with that back in the 80s and early 90s. But ultimately it wasn't suitable for the kind of real-world programming I needed. That's why I chose python for my tutorial. Its not only teachable at a basic level but it is actually usable on larger, real-world type projects once you've learned it. You never need to throw away your skills. > If the aim is to quickly get the students to "be creative" with > programming by themselves, my feeling is that Python is too unwieldy for > a beginner. Don't underestimate the interactive prompt. It gives instant feedback and is moire usable for beginners than most Lisp-style REPLs. Logo works too of course. But almost anything you can do in Logo you can do almost as easily in Python. Be it list handling or turtle graphics. > minutes. They get the feeling of designing their own computational > procedure much quicker than in Python. (Yes, of course, the introductory > excercises in Python are a bit more advanced than "add two numbers".) But they don't need to be. My tutor starts off with precisely that... > I am honestly not sure what quite what my feelings are regarding this, > perhaps Python is the best of all possible options. Its a good compromise. Its got faults (see my other post!) but I haven't found anything clearly better. -- 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 implementation
On 19/02/2021 03:51, Dennis Lee Bieber wrote: > They chose Pascal as being more modern, and something taught in schools > (yeah, like TurboPascal is going to be a good introduction to writing > software for real-time ground control of satellites). Funnily enough it was. Or at least for real-time telecomms control. We wrote all our real-time stuff on VAX and later PC using Pascal from the mid 80s through to early 1990s when we switched to C++. But TurboPascal was not much like Pascal, it had all the theoretical bits by-passed or removed. I still use Pascal in the shape of Delphi for building windows GUI apps today... But Delphi bears even less resemblance to Wirth's Pascal, in fact its quite similar to Python in many ways. -- 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
On 19/02/2021 06:27, Smit Patel wrote: > I recently downloaded python from your website and when I started using it, > it worked correctly but when I installed the random2 module it showed > startup failure and won't work again. > So, I uninstalled it and downloaded it again but it is showing the same > problem of startup failure. Can you send us more details about what exactly happens. How are you running it? What OS? What error messages are you getting (in full please) -- 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 implementation
On 19/02/2021 18:14, Michael F. Stemper wrote: >> and cons. LISP only had cons. :-) LOL -- 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: name for a mutually inclusive relationship
On 24/02/2021 16:12, Ethan Furman wrote: > I'm looking for a name for a group of options that, when one is specified, > all of them must be specified. > > For contrast, > > - radio buttons: a group of options where only one can be specified (mutually > exclusive) > - check boxes: a group of options that are independent of each other (any > number of > them may be specified) > > - ???: a group of options where, if one is specified, all must be specified > (mutually > inclusive) Given that radio buttons and check boxes are all effectively using boolean states, doesn't this mean none of the group or all of the group? In which case it's a single boolean value - a check box that controls all options. I suspect I'm missing something... -- 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 of opening Python
On 25/02/2021 17:22, Botao Liu wrote: > Type "help", "copyright", "credits" or "license" for more information." Follow the instructions and type "help" at the >>> prompt. Then follow the instructions which it displays. -- 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: name for a mutually inclusive relationship
On 26/02/2021 04:30, Ethan Furman wrote: >> Do you have a specific problem you're trying to solve? > > No, I just came across the concept in my browsing and > was wondering if there was a name for it. If we stick with boolean values (like radio buttons and checkboxes) then I think the name is "equality" A BResult -- 0 0 1 0 1 0 1 0 0 1 1 1 So you determine "success" by whether all inputs are equal. (Or as somebody else said "not xor") -- 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 needed as a legacy version 2.7 imports the module...
On 26/02/2021 22:23, Kevin M. Wilson via Python-list wrote: > Hey Community, Is there a site where I might/can download a version of > Tkinter for Python 2.7? Which OS? If it's Linux you may need to fetch the tkinter package for your distro. In Windoze it should come as standard In MacOS (or any other OS) ... Ask someone who knows... -- 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
yield from () Was: Re: weirdness with list()
On 28/02/2021 00:17, Cameron Simpson wrote: > BUT... It also has a __iter__ value, which like any Box iterates over > the subboxes. For MDAT that is implemented like this: > > def __iter__(self): > yield from () Sorry, a bit OT but I'm curious. I haven't seen this before: yield from () What is it doing? What do the () represent in this context? -- 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: yield from () Was: Re: weirdness with list()
On 28/02/2021 23:47, Alan Gauld via Python-list wrote: > On 28/02/2021 00:17, Cameron Simpson wrote: > >> BUT... It also has a __iter__ value, which like any Box iterates over >> the subboxes. For MDAT that is implemented like this: >> >> def __iter__(self): >> yield from () > > Sorry, a bit OT but I'm curious. I haven't seen > this before: > > yield from () > > What is it doing? > What do the () represent in this context? > Thanks for the replies. I should have known better but I was thinking some cleverness with callables and completely forgot the empty tuple syntax. Oops! -- 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?
On 07/03/2021 07:16, [email protected] wrote: > Where can I find any documentation of the correct curses constant name(s) to > use for detecting a "wheel down" action? Or do I just have to manually > define my own BUTTON5 constant name for the wheel-down event? I suspect you need to look in the ncurses documentation or even the C code. And that is no guarantee that the Python curses module will expose any values you do find other than as numeric codes. I would have expected the mouse wheel down/click to appear as a BUTTON2 event to be honest. I didn't even realize there was a BUTTON4 event defined let alone BUTTON5. Incidentally, when you talk about wheel up/down are you talking about wheel rotation events rather than actual button down/up events? In that case 4 and 5 might make sense. If you find the answer please post back, I'm very interested since I'm in the middle of writing a book on the Python curses module and was unaware of this behaviour. A whole new area to explore I'm also interested in any documentation you have already found on it - where did you get this understanding? -- 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?
On 09/03/2021 01:05, [email protected] 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
Re: REPL peculiarity
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: How do I read .csv files
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: .title() - annoying mistake
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: convert script awk in python
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: convert script awk in python
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: memory consumption
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
Ann: New Python curses book
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: Ann: New Python curses book
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
Re: memory consumption
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
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: New Python curses book
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
Source code link was: Re: Ann: New Python curses book
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: Horrible abuse of __init_subclass__, or elegant hack?
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
Re: Horrible abuse of __init_subclass__, or elegant hack?
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?
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
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: How to access a variable from one tab in another tab of a notebook?
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: How to access a variable from one tab in another tab of a notebook?
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: Ann: New Python curses book
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: UI design: combobox or radiobuttons?
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
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: port to PDOS (especially mainframe)
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
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: do ya still use python?
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: Ad-hoc SQL query builder for Python3?
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: "py.ini" question
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: Start Python programming
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: STARTUP FAILURE
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: learning python ...
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: learning python ...
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 ...
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 ...
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
string storage [was: Re: imaplib: is this really so unwieldy?]
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: string storage [was: Re: imaplib: is this really so unwieldy?]
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
Re: string storage [was: Re: imaplib: is this really so unwieldy?]
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: Applying winpdb_reborn
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: Applying winpdb_reborn
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: Definition of "property"
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
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: How to debug python + curses? [was: RE: Applying winpdb_reborn]
On 30/05/2021 18:26, [email protected] 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"
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: Definition of "property"
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: How to debug python + curses? [was: RE: Applying winpdb_reborn]
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"
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: Neither pdb or print() displays the bug
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: fabric: fab command
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: Tkinter8.6: date picker
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: Terminology: EU language skills, and Master to Main (or ...)
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: tkinter: tksheet
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
