Re: Best use of "open" context manager

2024-07-06 Thread Alan Gauld via Python-list
to mentally negotiate. The advantage of the original version is that you can ignore errors and read the code easily. You only need to find the except clause if you need to know how errors will be dealt with. But if comprehending the core functionality of the code you can just ignore all the error handling blocks.

Re: IDLE: clearing the screen

2024-06-09 Thread Alan Gauld via Python-list
. But that didn't work for me in IDLE either. I think this is one where the best bet is to go into the IDLE code and add a Shell submenu to clear screen! Apparently it's been on the workstack at idle-dev for a long time but is considered low priority... -- Alan G Author of the Learn to Program we

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

2024-05-19 Thread Alan Gauld via Python-list
> and all the rest cannot be resolved otherwise. I've honestly never experienced this "nightmare". I install stuff and it just works. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flick

Re: Terminal Emulator

2024-05-14 Thread Alan Gauld via Python-list
"batch" mode. So many options. Most of the specs are available online and there must be dozens of terminal emulators around written in C so you should have plenty of sample code to study. Good luck! -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://

Re: how to discover what values produced an exception?

2024-05-06 Thread Alan Bawden via Python-list
to mention the actual objects that caused the error has always annoyed me. I've always presumed that for some reason it just wasn't easy to do. And it's never been more than a minor annoyance to me. So the OP is not wrong for wishing for this. Other programming languages do it. Other Python programmers miss it. - Alan -- https://mail.python.org/mailman/listinfo/python-list

Re: Python Dialogs (Posting On Python-List Prohibited)

2024-05-03 Thread Alan Bawden via Python-list
in (dict(replacements),) for s in re.split("\\b(" + "|".join(re.escape(s[0]) for s in replacements) + ")\\b", text) ) How about just: repl = { "a" : "b", "c" : "d", "e" : "f", "g" : "h", } "".join(repl.get(s, s) for s in re.split(r"\b", text)) - Alan -- https://mail.python.org/mailman/listinfo/python-list

Re: How to Add ANSI Color to User Response

2024-04-10 Thread Alan Gauld via Python-list
# make it visible else: scr.addstr("Sorry, no colors available") curses.wrapper(main) HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos

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

2024-03-30 Thread Alan Gauld via Python-list
There seem to be several derivation sources including a fantasy world city suspended above a very thin, tall steeple Personally, I know SIGIL as an opensource EPUB editor! None of them seem to have any direct connection to the xkcd cartoon. -- Alan G Author of the Learn to Program web site http:

Re: Error in Module

2024-03-11 Thread Alan Gauld via Python-list
s a third party package that you need to install separately from Python. It does not come as standard. Have you installed Flask on the computer where you are running your project? If so, how did you download/install it? -- Alan G Author of the Learn to Program web site http://www.alan-g.me

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

2024-03-06 Thread Alan Gauld via Python-list
And not just Google, I just tried bing, yahoo and duckduckgo and they are all the same. Not a one listed anything from python.org on the first page... In fact it didn't even appear in the first 100 listings, although wikipedia did manage an entry, eventually. -- Alan G Author of the Learn to Prog

Re: RE: Problem resizing a window and button placement

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

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

2024-02-26 Thread Alan Gauld via Python-list
re) root.mainloop() print("Ww Outside = <" + str(Ww) + ">") #### Notice that the button callback picks up the latest value of Ww. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr

Re: RE: Problem resizing a window and button placement

2024-02-26 Thread Alan Gauld via Python-list
global Ww >> Ww = root.winfo_width() >> print("Ww Inside =<"+str(Ww)+">") >> >> root = tk.Tk() >> root.bind('',on_configure) >> root.mainloop() >> >> print("Ww Outside = <"+str(Ww)+">&

Re: RE: Problem resizing a window and button placement

2024-02-25 Thread Alan Gauld via Python-list
("Ww Outside = <" + str(Ww) > + ">") Produces: Ww Inside = <200> Ww Inside = <200> Ww Inside = <205> Ww Inside = <205> Ww Inside = <206> Ww Inside = <206> Ww Outside = <206> HTH -- Alan G Author of the Learn to Program web sit

Re: Is there a way to implement the ** operator on a custom object

2024-02-09 Thread Alan Bawden via Python-list
aking the object behave in a dict-like way. I can't remember how this is implemented, but you can create the necessary methods to have your object produce whatever it likes. All you need to do is subclass collections.abc.Mapping, and implement __len__, __iter__, and __getitem__. Pretty easy

PyTorch

2024-01-17 Thread Alan Zaharia via Python-list
Hello Python I Need help. it could not be found for PyTorch. It said in the Command Prompt ERROR: Could not find a version that satisfies the requirement torch (from versions: none) ERROR: No matching distribution found for torch, Can you help me? Thank You, Best, Alan. -- https

Re: Using my routines as functions AND methods

2024-01-04 Thread Alan Gauld via Python-list
gt;>> def g(obj, st): print(st, obj.v) ... >>> class D: ... def __init__(self,v): self.v = v ...m = g ... >>> d = D(66) >>> g(d,'val = ') val = 66 >>> d.m('v = ') v = 66 -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://

Re: Using my routines as functions AND methods

2024-01-03 Thread Alan Gauld via Python-list
ly a catch. But sometimes the simple things just work? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list

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

2023-12-30 Thread Alan Gauld via Python-list
e a GUI builder. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list

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

2023-12-25 Thread Alan Gauld via Python-list
e Python >> 3.4.4 Shell... Python names can't start with a % (its the modulo or string formatting operator). I know nothing of the innards of matplotlib so I can only suggest a closer examination of their tutorial information. -- Alan G Author of the Learn to Program web site http:

Re: on writing a number as 2^s * q, where q is odd

2023-12-05 Thread Alan Bawden via Python-list
tegers. Probably N is 56 or 48 or 32. And why 62 bits? Because the bit_count method is certainly written in C, where every step in bit_count_62 would use 64-bit integers. If you like this sort of stuff, check out the book "Hacker's Delight" by Henry Warren. See <https://en.wikiped

Re: on writing a number as 2^s * q, where q is odd

2023-11-29 Thread Alan Bawden via Python-list
jak writes: Alan Bawden ha scritto: > Julieta Shem writes: > > How would you write this procedure? > def powers_of_2_in(n): > ... > > def powers_of_2_in(n): > return (n ^ (n - 1)).bit_count() - 1 > Great solutio

Re: on writing a number as 2^s * q, where q is odd

2023-11-29 Thread Alan Bawden via Python-list
Julieta Shem writes: How would you write this procedure? def powers_of_2_in(n): ... def powers_of_2_in(n): return (n ^ (n - 1)).bit_count() - 1 -- https://mail.python.org/mailman/listinfo/python-list

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

2023-11-19 Thread Alan Gauld via Python-list
nd 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

Amy known issues with tkinter /ttk on latest MacOS?

2023-11-16 Thread Alan Gauld via Python-list
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

Re: Newline (NuBe Question)

2023-11-15 Thread Alan Gauld via Python-list
"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.ama

Re: xor operator

2023-11-13 Thread Alan Gauld via Python-list
sts (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: h

Re: Checking if email is valid

2023-11-02 Thread Alan Bawden via Python-list
uot;VRFY" command. And spammers _did_ abuse it in exactly this manner. And so pretty much every mail server in the world disabled VRFY sometime in the 90s. - Alan -- https://mail.python.org/mailman/listinfo/python-list

Re: Question(s)

2023-10-25 Thread Alan Gauld via Python-list
ave comprehensive Python support. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list

Re: Question(s)

2023-10-24 Thread Alan Gauld via Python-list
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 -- ht

Re: Question(s)

2023-10-24 Thread Alan Gauld via Python-list
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 th

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

2023-09-15 Thread Alan Gauld via Python-list
ome 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 on

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

2023-09-01 Thread Alan Gauld via Python-list
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

Re: Multiple inheritance and a broken super() chain

2023-07-05 Thread Alan Gauld via Python-list
ust 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 potent

Re: Multiple inheritance and a broken super() chain

2023-07-04 Thread Alan Gauld via Python-list
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:

Re: Fwd: AUTO EDITOR DIDN'T WORK

2023-06-15 Thread Alan Gauld via Python-list
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(as

Fwd: AUTO EDITOR DIDN'T WORK

2023-06-13 Thread Alan Gauld via Python-list
and reinstalled about twice and still no success hence I uninstalled it. On Mon, 12 Jun 2023, 23:33 Alan Gauld via Python-list, mailto:python-list@python.org>> wrote: On 12/06/2023 10:26, Real Live FootBall Tv via Python-list wrote: > I did it because I was going to use it with another ap

Fwd: Re: AUTO EDITOR DIDN'T WORK

2023-06-12 Thread Alan Gauld via Python-list
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 ru

Re: Silly (maybe) question re imported module(s)

2023-05-19 Thread Alan Gauld
ot callable Ah, now I understand. cubes is a literal list defined in the module. > But that was spot on, thanks > >>>> import cube >>>> cube.cubes > [0, 1, 8, 27, 64, 125, 216, 343, 512, 729] Glad to help. -- Alan G Author of the Learn to Program web site h

Re: Silly (maybe) question re imported module(s)

2023-05-19 Thread Alan Gauld
\Temp\cube.py >>>> cubes > [0, 1, 8, 27, 64, 125, 216, 343, 512, 729] cubes looks like it should be a function but in that case there should be parens after it. So I'm not sure how that is working! I'd expect that you need to do: import cube cube.cubes() -- Alan G Au

Re: Silly (maybe) question re imported module(s)

2023-05-19 Thread Alan Gauld
; the modules. are you typing >>> import mymodule at the interactive prompt or are you using the File->Open menu to load them into the editor? (It sounds like the latter) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_ga

Re: What to use instead of nntplib?

2023-05-16 Thread Alan Gauld
quired? > > See PEP 594: https://peps.python.org/pep-0594/ Thanks Cameron. A scary list; I must have a dozen projects from the late 90s still live that are using many of these! I'm glad I'm retired and won't be the one who has to fix 'em :-) -- Alan G Author of the Learn to Program we

Re: What to use instead of nntplib?

2023-05-16 Thread Alan Gauld
deprecated? Surely there are still a lot of nntp servers around, both inside and outside corporate firewalls? Is there a problem with the module or is it just perceived as no longer required? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/al

Re: [pygettext] --package-name and --package-version unknown

2023-05-04 Thread Alan Gauld
does create in each > po-file. Sorry, I've never used pygettext so can't help 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:

Re: Python curses missing form library?

2023-04-24 Thread Alan Gauld
building terminal based form-type apps the best bet seems to be urwid. I haven't used it in anger but the beginner docs I saw looked promising. -- 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

Re: PyCharm's strict PEP and not so strict?

2023-04-19 Thread Alan Gauld
ow to plumb it into your IDE). Personally I've never felt the need for any stricter error checking than the interpreter provides so I can't offer anything beyond the generic suggestion to use a linter. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.

Re: tksheet - Copy and Paste with headers

2023-04-16 Thread Alan Gauld
text editor in the first instance? And Excel in the second? If all else fails you can probably write handlers and bind to Ctrl-C and Ctrl-V to do something yourself that mimics cut/paste. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Fol

Re: RE: Weak Type Ability for Python

2023-04-13 Thread Alan Gauld
ll the operators (commands in Tcl-speak) in the language so redefining plus is easy. Doing it based on type is more tricky but doable. > Unfortunately, if they BOTH are flexible, how do you decide whether to add > them as numbers or concatenate them as strings? Yes, that's where it becomes a d

Re: Weak Type Ability for Python

2023-04-13 Thread Alan Gauld
e a rival to M$ OS/2 running NeXTstep now that would have been a platform for the 90s... both so near yet so far. -- 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.c

Re: Windows Gui Frontend

2023-04-01 Thread Alan Gauld
o real evidence of 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: Windows installer from python source code without access to source code

2023-03-31 Thread Alan Gauld
ython3 so ive no idea what it does today! But a quick check suggests it still exists and works with python3 code - last major release was in Nov 2022. -- 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

Re: Fwd: Friday finking: IDE 'macro expansions'

2023-03-18 Thread Alan Gauld
prices: $1000~3000 for the pro versions! (But there is still a free community version with just the basics.) See http://www.embarcadero.com And it's targeted at multi-platforms now: Windows, MacOS, Android, iOS although it only runs on Windows. -- Alan G Author of the Learn to Program

Re: Fwd: Friday finking: IDE 'macro expansions'

2023-03-18 Thread Alan Gauld
nitude more difficult. The Lazarus open source project is based on Delphi's IDE. -- 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://ma

Fwd: Friday finking: IDE 'macro expansions'

2023-03-17 Thread Alan Gauld
tricks but I don't always use them. In vim I use auto-indent and that's about 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.pyth

Re: Lambda returning tuple question, multi-expression

2023-03-09 Thread Alan Gauld
;normal") ) ) It's not a radical change from using a lamba as a callback but it does extend the use case to cover a common GUI scenario. I like it. I wish I'd thought of it years ago. Thanks for sharing. -- Alan G Author of the Learn to Program web site http:/

Re: RE: Which more Pythonic - self.__class__ or type(self)?

2023-03-04 Thread Alan Gauld
more loose term and the community less stressed about it than their C++ cousins where it has almost reached a religious fervour! -- 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

Re: Python list insert iterators

2023-03-03 Thread Alan Bawden
Guenther Sohler writes: Hi Python community, I have a got an example list like 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 T T and i eventually want to insert items in the given locations (A shall go between 2 and 3, B shall go between 6 and 7) Right now i just use

Re: Which more Pythonic - self.__class__ or type(self)?

2023-03-03 Thread Alan Gauld
types should rarely be necessary since Python uses duck typing and limiting things to a hard type seriously restricts your code. -- 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.flick

Re: Regular Expression bug?

2023-03-02 Thread Alan Bawden
) s0 = r0.match(s) >>> print(s0) None Assuming that you were expecting to match "pn=2017", then you probably don't want the 'match' method. Read its documentation. Then read the documentation for the _other_ methods that a Pattern supports. Then you will be enlighten

Re: TypeError: can only concatenate str (not "int") to str

2023-02-26 Thread Alan Gauld
as it exists. (We also cover beginner questions about programming in general.) So this thread is most definitely in the right place IMHO. -- Alan G Tutor list moderator -- https://mail.python.org/mailman/listinfo/python-list

Re: Usenet vs. Mailing-list (was: evaluation question)

2023-01-31 Thread Alan Gauld
stuff) is a now more complicated than before. So I have to be very highly motivated to jump through the hoops. -- 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/alangauld

Re: RE: NoneType List

2023-01-02 Thread Alan Gauld
the ludicrously strict typing slightly. Turbo Pascal made Pascal a joy and I still use Delphi for Windows programming today. TP also introduced classes to Pascal (although Apple had already done so for the Mac and Borland basically ported the syntax to the PC). -- Alan G Author of the Learn to

Re: NoneType List

2022-12-31 Thread Alan Gauld
hain them. But sadly it doesn't. -- 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 to Float, without introducing errors

2022-12-17 Thread Alan Gauld
ecimal accuracy is your primary goal, it might suit you 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: Does one have to use curses to read single characters from keyboard?

2022-12-13 Thread Alan Gauld
On 12/12/2022 17:45, Alan Gauld wrote: Absolutely nothing apparently! But in practce I did pen some esponses to Davids post. However this list seems to strip out what I've written, its happened a few times now. Not every time but enough that I rarely post here. But I'll try once more

Re: Does one have to use curses to read single characters from keyboard?

2022-12-12 Thread Alan Gauld
r: have had it on my 'radar', but never actually employed. > (if you have considered, will be interested to hear conclusions...) -- 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: an oop question

2022-11-03 Thread Alan Gauld
On 03/11/2022 18:29, Chris Angelico wrote: > On Fri, 4 Nov 2022 at 05:21, Julieta Shem wrote: >> >> Chris Angelico writes: >> >>> On Thu, 3 Nov 2022 at 21:44, Alan Gauld wrote: >>>> Also Python is not a purely OOP language, in that you can write >

Re: an oop question

2022-11-03 Thread Alan Gauld
really have to fight the system to do so. -- 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: [correction]an oop question

2022-11-02 Thread Alan Gauld
I'd implement the example hierarchy as > >>>> class Language: > ... def f(self): > ... print(self.greeting) And that would be perfectly valid too. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_g

Re: an oop question

2022-11-02 Thread Alan Gauld
n cellular automata theory. .. Unfortunately, there is a huge gap between pure OOP theory and practical OOP languages! And just as big a gap between OOP language potential and real-world OOP usage. Very few purely OOP programs exist (maybe excepting in Smalltalk - see Stefan's posts again). :-( -- Ala

Re: an oop question

2022-10-31 Thread Alan Gauld
Empty()" > def __repr__(self): > return self.__str__() > def __new__(clss): > if not hasattr(clss, "saved"): > clss.saved = super().__new__(clss) > return clss.saved > > class Stack(Pair): > def pop(self): > return self.first > def push(self, x): > return Stack(x, self) -- 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: random.SystemRandom().randint() inefficient

2022-07-27 Thread Alan Bawden
Cecil Westerhof writes: Alan Bawden writes: > Cecil Westerhof writes: > >Yes, I try to select a random element, but it has also to be removed, >because an element should not be used more as once. > > Instead of using pop to do that why

Re: random.SystemRandom().randint() inefficient

2022-07-27 Thread Alan Bawden
e willing to have it destroyed by this process: seq = list(seq) n = len(seq) while n: i = randrange(n) yield seq[i] n -= 1 if i < n: seq[i] = seq[n] -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: on a statement followed by an expression

2022-06-04 Thread Alan Bawden
time. Your original code that used a `for' loop is actually much clearer. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: min, max with position

2022-06-04 Thread Alan Bawden
looking for is usually called "argmax" and "argmin" (see ). These don't exist in the standard Python library as far as I can tell, but numpy does have "argmax" and "argmin" routines. -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: tail

2022-05-09 Thread Alan Bawden
Marco Sulla writes: On Mon, 9 May 2022 at 19:53, Chris Angelico wrote: ... Nevertheless, tail is a fundamental tool in *nix. It's fast and reliable. Also the tail command can't handle different encodings? It definitely can't. It works for UTF-8, and all the ASCII compatible single

Re: Python/New/Learn

2022-05-05 Thread Alan Gauld
here will be closer to your level than the more advanced topics that get addressed here. Finally, I have a tutorial aimed at complete beginners, see the link 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 p

Re: Python app on a Mac

2022-04-15 Thread Alan Gauld
so does a Terminal in the background. The SO answer does mention you can get the Terminal to close when the script terminates whhich would be better than now. However, another answer mentions something called Automator, which I'll need to Google... Thanks for the pointer though. -- Alan G Auth

Python app on a Mac

2022-04-15 Thread Alan Gauld
or somesuch? Alan G. -- https://mail.python.org/mailman/listinfo/python-list

Fwd: Re: Long running process - how to speed up?

2022-02-19 Thread Alan Gauld
re. But it might be possible to divide and conquer and get better speed. It all depends on what you are doing. We can't tell. We cannot answer such a vague question with any specific solution. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/ala

[issue28159] Deprecate isdst argument in email.utils.localtime

2022-02-08 Thread Alan WiIliams
Alan WiIliams added the comment: Hi, I'd like to work on this issue. Based on the discussion, the main thing to do here is to raise a deprecation warning when isdst is used? -- nosy: +Alan.Williams ___ Python tracker <https://bugs.python.

Re: Best way to check if there is internet?

2022-02-08 Thread Alan Bawden
And I missed one that was just published last month: https://datatracker.ietf.org/doc/html/rfc9171 Unlike RFC 5050, this version of the protocol actually claims to be a "Proposed Standard". -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Best way to check if there is internet?

2022-02-08 Thread Alan Bawden
g/wiki/Delay-tolerant_networking https://datatracker.ietf.org/doc/html/rfc4838 https://datatracker.ietf.org/doc/html/rfc5050 -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list

Re: Advanced ways to get object information from within python

2021-12-23 Thread Alan Gauld
nvenient way for me to know what > all of these are. help(scrapy.http) help(scrapy.spiders) etc... And if it turns out they are not functions or classes you can use [p]print to get the values. You can also use type() to clarify what kind of thing an attribute is. -- Alan G Author of the Learn to Progr

Re: Advantages of Default Factory in Dataclasses

2021-11-16 Thread Alan Bawden
David Lowry-Duda writes: ... For the same reason that the following code doesn't do what some people might expect it to: ```python def add_to(elem, inlist=[]): inlist.append(elem) return inlist list1 = add_to(1) list2 = add_to(2) print(list1) # prints

Re: New assignmens ...

2021-10-24 Thread Alan Bawden
the target to be as general as possible! I'm guessing that about 70% of you will think that this is a horrible idea, 10% of you will find it compelling, and the remaining 20% will find themselves conflicted. You can count me in that last category... -- Alan Bawden -- https://mail.python.org/mailman

Fwd: Re: sum() vs. loop

2021-10-12 Thread Alan Gauld
transit. Presumably, especially for large numbers, a single python loop is faster than 2 C loops? But that's purely my speculation. -- 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:

Re: Question again

2021-09-16 Thread Alan Gauld via Python-list
) > > #User answers > answer = input() > #If user says 'yes' again, reply 'fine! bye then!' > if answer == "yes" : > print("Fine! bye then!") Shouldn't those lines be indented as part of the if statement above? > #Other than that if user says 'no', reply

Re: Friday Finking: Contorted loops

2021-09-12 Thread Alan Gauld via Python-list
in the process?). A linter likewise might identify the redundant code. I don't use any python linters, does anyone know if they do detect such dead spots? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flick

Re: Friday Finking: Contorted loops

2021-09-12 Thread Alan Gauld via Python-list
mall C programs of mine I find: > > 35 regular for loops > 28 while loops > 2 infinite for loops > 1 "infinite" for loop (i.e. it exits somewhere in the middle) > 0 do/while loops. That wouldn't surprise me, I've only used do/while in C a handful of times. But in Pasc

Re: Friday Finking: Contorted loops

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

Re: Friday Finking: Contorted loops

2021-09-10 Thread Alan Gauld via Python-list
cases, it executes the 'else' part if it didn't break out of the > loop. That's it. OK, That's a useful perspective that is at least consistent. Unfortunately it's not how beginners perceive it and it causes regular confusion about how/when they should use else with a loop. -- Alan G Aut

Re: Friday Finking: Contorted loops

2021-09-10 Thread Alan Gauld via Python-list
state that the use of for loops was rare? But I would hope that any empirical research would look at the wider function of the loop and its purpose rather than merely analyzing the syntax and keywords. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/au

Re: Friday Finking: Contorted loops

2021-09-10 Thread Alan Gauld via Python-list
lways gets executed at least once. But at the cost of duplicating the loop-body code, thus violating DRY. Just another thought... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://ww

Re: on writing a while loop for rolling two dice

2021-09-07 Thread Alan Gauld via Python-list
e { > #define ENDIF } > ... > > IIRC he copied them out of a magazine article. That was quite common in C before it became popular(early/mid 80s). I've seen Pascal, Algol and Coral macro sets in use. You could even download pre-written ones from various bulletin boards (remember them?!

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

2021-09-04 Thread Alan Gauld via Python-list
cept we'd be an hour out of sync with the EU. (Post Brexit that may not be seen as a problem!! :-) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list

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

2021-09-03 Thread Alan Gauld via Python-list
see it as a benefit because they get longer working daylight. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list

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

2021-09-02 Thread Alan Gauld via Python-list
he EU PCs had a slightly different BIOS). The differences you cite should have thrown up issues every year. I must see if I can find my old log books... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on

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

2021-09-02 Thread Alan Gauld via Python-list
control becomes important. Also the problems we had were about 15 years ago, things may be better ordered nowadays. (I've been retired for 7 years so can't speak of more recent events) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Foll

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

2021-09-02 Thread Alan Gauld via Python-list
updates showing as having happened in the future! -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list

  1   2   3   4   5   6   7   8   9   10   >