Re: Strange disassembly
On 19/06/2021 07:50, Chris Angelico wrote: On Sat, Jun 19, 2021 at 4:16 PM Rob Cliffe via Python-list wrote: On 18/06/2021 11:04, Chris Angelico wrote: sys.version '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' def chk(x): ... if not(0 < x < 10): raise Exception ... dis.dis(chk) 2 0 LOAD_CONST 1 (0) 2 LOAD_FAST0 (x) 4 DUP_TOP 6 ROT_THREE 8 COMPARE_OP 0 (<) 10 POP_JUMP_IF_FALSE 11 (to 22) 12 LOAD_CONST 2 (10) 14 COMPARE_OP 0 (<) 16 POP_JUMP_IF_TRUE14 (to 28) 18 LOAD_GLOBAL 0 (Exception) 20 RAISE_VARARGS1 >> 22 POP_TOP 24 LOAD_GLOBAL 0 (Exception) 26 RAISE_VARARGS1 >> 28 LOAD_CONST 0 (None) 30 RETURN_VALUE Why are there two separate bytecode blocks for the "raise Exception"? I'd have thought that the double condition would still be evaluated as one thing, or at least that the jump destinations for both the early-abort and the main evaluation should be the same. ChrisA As an ornery human I could refactor this to avoid the code duplication as 2 0 LOAD_CONST 1 (0) 2 LOAD_FAST0 (x) 4 DUP_TOP 6 ROT_THREE 8 COMPARE_OP 0 (<) 10 POP_JUMP_IF_TRUE10 (to 18) 12 POP_TOP >> 14 LOAD_GLOBAL 0 (Exception) 16 RAISE_VARARGS1 >> 18 LOAD_CONST 2 (10) 20 COMPARE_OP 0 (<) 22 POP_JUMP_IF_FALSE 21 (to 14) 24 LOAD_CONST 0 (None) 26 RETURN_VALUE >>> (there may be mistakes in this) but this is probably too much to expect of the compiler. Hmm, I think that depends too much on knowing that the raise won't return. That might be a neat optimization (effectively a form of dead code removal), but otherwise, the best you could do would be to also have it jump out after the raise. ChrisA Er, doesn't your original dis output make the same assumption? Otherwise, after this line 20 RAISE_VARARGS1 it would attempt to do an extra pop, then raise a second time. Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange disassembly
On Sat, Jun 19, 2021 at 5:13 PM Rob Cliffe via Python-list wrote: > > > > On 19/06/2021 07:50, Chris Angelico wrote: > > On Sat, Jun 19, 2021 at 4:16 PM Rob Cliffe via Python-list > > wrote: > >> > >> > >> On 18/06/2021 11:04, Chris Angelico wrote: > >> sys.version > >>> '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' > >> def chk(x): > >>> ... if not(0 < x < 10): raise Exception > >>> ... > >> dis.dis(chk) > >>> 2 0 LOAD_CONST 1 (0) > >>> 2 LOAD_FAST0 (x) > >>> 4 DUP_TOP > >>> 6 ROT_THREE > >>> 8 COMPARE_OP 0 (<) > >>>10 POP_JUMP_IF_FALSE 11 (to 22) > >>>12 LOAD_CONST 2 (10) > >>>14 COMPARE_OP 0 (<) > >>>16 POP_JUMP_IF_TRUE14 (to 28) > >>>18 LOAD_GLOBAL 0 (Exception) > >>>20 RAISE_VARARGS1 > >>> >> 22 POP_TOP > >>>24 LOAD_GLOBAL 0 (Exception) > >>>26 RAISE_VARARGS1 > >>> >> 28 LOAD_CONST 0 (None) > >>>30 RETURN_VALUE > >>> Why are there two separate bytecode blocks for the "raise Exception"? > >>> I'd have thought that the double condition would still be evaluated as > >>> one thing, or at least that the jump destinations for both the > >>> early-abort and the main evaluation should be the same. > >>> > >>> ChrisA > >> As an ornery human I could refactor this to avoid the code duplication as > >> > >> 2 0 LOAD_CONST 1 (0) > >> 2 LOAD_FAST0 (x) > >> 4 DUP_TOP > >> 6 ROT_THREE > >> 8 COMPARE_OP 0 (<) > >>10 POP_JUMP_IF_TRUE10 (to 18) > >>12 POP_TOP > >> >> 14 LOAD_GLOBAL 0 (Exception) > >>16 RAISE_VARARGS1 > >> >> 18 LOAD_CONST 2 (10) > >>20 COMPARE_OP 0 (<) > >>22 POP_JUMP_IF_FALSE 21 (to 14) > >>24 LOAD_CONST 0 (None) > >>26 RETURN_VALUE > >> >>> > >> > >> (there may be mistakes in this) but this is probably too much to expect > >> of the compiler. > > Hmm, I think that depends too much on knowing that the raise won't > > return. That might be a neat optimization (effectively a form of dead > > code removal), but otherwise, the best you could do would be to also > > have it jump out after the raise. > > > > ChrisA > Er, doesn't your original dis output make the same assumption? > Otherwise, after this line > >20 RAISE_VARARGS1 > > it would attempt to do an extra pop, then raise a second time. In my original, I expected to see a single RAISE, with a jump over the POP. The thing that surprised me was duplicating the RAISE to avoid the jump. Either way, the behaviour would be the same, though. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Faker package [RESOLVED]
On Sat, 19 Jun 2021, MRAB wrote: It looks like you're mixing some Python usage ("faker.names()") in with command line usage. MRAB, You are correct. That was my problem. Judging from the docs, I'd say you need something more like: $ faker -o temp.out name for 1 fake name or: $ faker -r=10 -o temp.out name for 10 fake names. Thank you. I didn't pick that up when I read the document. Much appreciated, Rich -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter problem
liyaanns...@gmail.com 在 2021年6月18日 星期五下午2:28:35 [UTC+8] 的信中寫道: > I am using Colab. How could solve this problem. > import tkinter as Tk > from tkinter import * > import sys > import os > #create main window > master = Tk() > master.title("tester") > master.geometry("300x100") > > > #make a label for the window > label1 = tkinter.Label(master, text='Hello') > # Lay out label > label1.pack() > > # Run forever! > master.mainloop() > The error shows that : > in () > 9 > 10 #create main window > ---> 11 master = Tk() > 12 master.title("tester") > 13 master.geometry("300x100") > > /usr/lib/python3.7/tkinter/__init__.py in __init__(self, screenName, > baseName, className, useTk, sync, use) > 2021 baseName = baseName + ext > 2022 interactive = 0 > -> 2023 self.tk = _tkinter.create(screenName, baseName, className, > interactive, wantobjects, useTk, sync, use) > 2024 if useTk: > 2025 self._loadtk() > > TclError: couldn't connect to display ":0.0" >>> import tkinter as Tk >>> Tk >>> from tkinter import * >>> Tk >>> tkinter Traceback (most recent call last): File "", line 1, in NameError: name 'tkinter' is not defined >>> --Jach -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter problem
Christian Gollwitzer 在 2021年6月19日 星期六下午12:27:54 [UTC+8] 的信中寫道: > Am 19.06.21 um 05:59 schrieb Jach Feng: > import tkinter as Tk > Tk > > > 'C:\\Users\\jfong\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\tkinter\\__init__.py'> > > > from tkinter import * > Tk > > > tkinter > > Traceback (most recent call last): > > File "", line 1, in > > NameError: name 'tkinter' is not defined > > What's the point? That has no relation to the question. > > "import A as B" does not define A. That's a feature, not a bug. > > Christian No, it's not. It's only because this line triggers my response:-) > label1 = tkinter.Label(master, text='Hello') --Jach -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter problem
Christian Gollwitzer 在 2021年6月19日 星期六下午1:54:46 [UTC+8] 的信中寫道: > Am 19.06.21 um 07:16 schrieb Jach Feng: > > Christian Gollwitzer 在 2021年6月19日 星期六下午12:27:54 [UTC+8] 的信中寫道: > >> Am 19.06.21 um 05:59 schrieb Jach Feng: > >> import tkinter as Tk > >> Tk > >>> >>> 'C:\\Users\\jfong\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\tkinter\\__init__.py'> > >>> > >> from tkinter import * > >> Tk > >>> > >> tkinter > >>> Traceback (most recent call last): > >>> File "", line 1, in > >>> NameError: name 'tkinter' is not defined > >> > >> What's the point? That has no relation to the question. > >> > >> "import A as B" does not define A. That's a feature, not a bug. > >> > >> Christian > > No, it's not. It's only because this line triggers my response:-) > >> label1 = tkinter.Label(master, text='Hello') > You have posted this as an answer to Liya's question about Google Colab. > What you wrote has nothing to do with it and does not help with Liya's > problem. > > I guess you wanted to post another question? Then please open a new > thread. In addition, the question is unclear, you just posted a > transcript of three lines of Python. > > Christian I posted to point out there is an error in Liya's script. It's not related to Colab, but it may relate to his problem. --Jach -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange disassembly
On 6/18/2021 8:13 PM, Chris Angelico wrote: On Sat, Jun 19, 2021 at 9:50 AM Terry Reedy wrote: Why are there two separate bytecode blocks for the "raise Exception"? Because one block must POP_TOP and other must not. I'd have thought that the double condition would still be evaluated as one thing, or at least that the jump destinations for both the early-abort and the main evaluation should be the same. To reuse the exception block with POP_TOP, could jump over it after the 2nd compare. Hmm, fair enough I guess. The compiler figured that it'd be faster to duplicate the executable code rather than have the jump. I would not assume that any alternative was considered. It made for a somewhat confusing disassembly, but I presume it's faster to run. For the simplest and fasted bytecode, write normal logic and let x be reloaded instead of duplicated and rotated. >>> import dis >>> def f(x): ... if x <= 0 or 10 <= x: raise Exception ... ... >>> dis.dis(f) 2 0 LOAD_FAST0 (x) 2 LOAD_CONST 1 (0) 4 COMPARE_OP 1 (<=) 6 POP_JUMP_IF_TRUE 8 (to 16) 8 LOAD_CONST 2 (10) 10 LOAD_FAST0 (x) 12 COMPARE_OP 1 (<=) 14 POP_JUMP_IF_FALSE 10 (to 20) >> 16 LOAD_GLOBAL 0 (Exception) 18 RAISE_VARARGS1 >> 20 LOAD_CONST 0 (None) 22 RETURN_VALUE >>> Makes sense. I'm not sure if this would actually run faster, but I can't really justify warping my code around the disassembly :) Thanks for the explanation. I guess I just assumed the interpreter would prefer a jump to the duplication, but that's a decision it's free to take! -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter problem
Am 19.06.21 um 05:59 schrieb Jach Feng: import tkinter as Tk Tk from tkinter import * Tk tkinter Traceback (most recent call last): File "", line 1, in NameError: name 'tkinter' is not defined What's the point? That has no relation to the question. "import A as B" does not define A. That's a feature, not a bug. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter problem
On 6/18/2021 2:28 AM, Liya Ann Sunny wrote: I am using Colab. How could solve this problem. import tkinter as Tk If you do this, import 'as tk'. from tkinter import * The second import overwrites the first since it imports tkinter.Tk as 'Tk'. Don't try to do both. import sys import os #create main window master = Tk() master.title("tester") master.geometry("300x100") #make a label for the window label1 = tkinter.Label(master, text='Hello') # Lay out label label1.pack() # Run forever! master.mainloop() The error shows that : in () 9 10 #create main window ---> 11 master = Tk() 12 master.title("tester") 13 master.geometry("300x100") /usr/lib/python3.7/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use) 2021 baseName = baseName + ext 2022 interactive = 0 -> 2023 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) 2024 if useTk: 2025 self._loadtk() TclError: couldn't connect to display ":0.0" -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Subpixel positioning on Tk canvas
Am 19.06.21 um 06:26 schrieb George Furbish: On Saturday, June 19, 2021 at 12:22:31 AM UTC-4, Christian Gollwitzer wrote: Am 19.06.21 um 02:03 schrieb George Furbish: Does Tk support interpolation/subpixel positioning of canvas elements? (e.g. images, text.) I have moving elements on my canvas, but the movement isn't very smooth and it's especially obvious when I have text moving alongside an image, since the two elements tend to jump to the next pixel at different times, creating a little judder between the two. There is an "improved canvas" available, tkpath, which supports antialiasing on all platforms. It is part of, e.g. undroidwish, if you want to experiment with it. Last time I tested it had problems on macOS though. How can I enable or access the improved canvas via Tkinter? Probably by writing the wrapper for it ;) Sorry for that answer, but Tkinter does not support many of the most useful extensions for Tcl/Tk, because someone has to write the wrappers. It only supports what is provided by base Tk. Among those I consider useful and use in almost any application are: * TkDnD for native drag'n'drop support (there is an inferior python package of the same name which implements local DnD only) * tablelist - complete widget for displaying trees and tables like ttk::treeview, but with almost every feature one could imagine * pdf4tcl - create a PDF from a canvas content, e.g. for printing Basically you call Tcl via the eval() method of tkinter; in principle you could do import tkinter as tk root=tk() root.eval('package require tkpath') root.eval('...here comes your tkpath code...') root.call('.tkp', 'create', 'oval', ) tkpath is described here: https://wiki.tcl-lang.org/page/tkpath For the wrapping, look at the implementation files of Tkinter, for say, the original canvas, and modify accordingly. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter problem
Am 19.06.21 um 07:16 schrieb Jach Feng: Christian Gollwitzer 在 2021年6月19日 星期六下午12:27:54 [UTC+8] 的信中寫道: Am 19.06.21 um 05:59 schrieb Jach Feng: import tkinter as Tk Tk from tkinter import * Tk tkinter Traceback (most recent call last): File "", line 1, in NameError: name 'tkinter' is not defined What's the point? That has no relation to the question. "import A as B" does not define A. That's a feature, not a bug. Christian No, it's not. It's only because this line triggers my response:-) label1 = tkinter.Label(master, text='Hello') You have posted this as an answer to Liya's question about Google Colab. What you wrote has nothing to do with it and does not help with Liya's problem. I guess you wanted to post another question? Then please open a new thread. In addition, the question is unclear, you just posted a transcript of three lines of Python. Christian -- https://mail.python.org/mailman/listinfo/python-list
Unable to remove setup of 3.9.5 from Windows 10
Hello Team, I have installed the Python 3.9.5 and trying to remove from the PC through the Uninstall Program (All Possible ways - Through Control Panel or Uninstall Python executable) It just outputs saying Uninstall Successfully but nothing happening (Still listed in Programs List) and even not allowing me to install again. Please let me know if there is any alternate resolution Thanks, Manish -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to remove setup of 3.9.5 from Windows 10
On 6/19/21 10:14 AM, Manish Jain wrote: Hello Team, I have installed the Python 3.9.5 and trying to remove from the PC through the Uninstall Program (All Possible ways - Through Control Panel or Uninstall Python executable) It just outputs saying Uninstall Successfully but nothing happening (Still listed in Programs List) and even not allowing me to install again. Please let me know if there is any alternate resolution Thanks, Manish You could try this: https://support.microsoft.com/en-us/topic/fix-problems-that-block-programs-from-being-installed-or-removed-cca7d1b6-65a9-3d98-426b-e9f927e1eb4d -- https://mail.python.org/mailman/listinfo/python-list
Re: Subpixel positioning on Tk canvas
On 6/19/2021 12:42 AM, Christian Gollwitzer wrote: Am 19.06.21 um 06:26 schrieb George Furbish: On Saturday, June 19, 2021 at 12:22:31 AM UTC-4, Christian Gollwitzer wrote: Am 19.06.21 um 02:03 schrieb George Furbish: Does Tk support interpolation/subpixel positioning of canvas elements? (e.g. images, text.) I have moving elements on my canvas, but the movement isn't very smooth and it's especially obvious when I have text moving alongside an image, since the two elements tend to jump to the next pixel at different times, creating a little judder between the two. There is an "improved canvas" available, tkpath, which supports antialiasing on all platforms. It is part of, e.g. undroidwish, if you want to experiment with it. Last time I tested it had problems on macOS though. How can I enable or access the improved canvas via Tkinter? Probably by writing the wrapper for it ;) Sorry for that answer, but Tkinter does not support many of the most useful extensions for Tcl/Tk, because someone has to write the wrappers. It only supports what is provided by base Tk. Among those I consider useful and use in almost any application are: Are these extensions included with the tcl/tk distribution, or otherwise available from active state? Are this extensions included with Linux installations of tcl/tk? Or easily installed? * TkDnD for native drag'n'drop support (there is an inferior python package of the same name which implements local DnD only) * tablelist - complete widget for displaying trees and tables like ttk::treeview, but with almost every feature one could imagine * pdf4tcl - create a PDF from a canvas content, e.g. for printing Basically you call Tcl via the eval() method of tkinter; in principle you could do import tkinter as tk root=tk() root.eval('package require tkpath') root.eval('...here comes your tkpath code...') root.call('.tkp', 'create', 'oval', ) tkpath is described here: https://wiki.tcl-lang.org/page/tkpath For the wrapping, look at the implementation files of Tkinter, for say, the original canvas, and modify accordingly. Christian -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange disassembly
Chris Angelico writes: >>> sys.version '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' >>> def chk(x): ... if not(0 < x < 10): raise Exception ... >>> dis.dis(chk) 2 0 LOAD_CONST 1 (0) 2 LOAD_FAST0 (x) 4 DUP_TOP 6 ROT_THREE 8 COMPARE_OP 0 (<) 10 POP_JUMP_IF_FALSE 11 (to 22) 12 LOAD_CONST 2 (10) 14 COMPARE_OP 0 (<) 16 POP_JUMP_IF_TRUE14 (to 28) 18 LOAD_GLOBAL 0 (Exception) 20 RAISE_VARARGS1 >> 22 POP_TOP 24 LOAD_GLOBAL 0 (Exception) 26 RAISE_VARARGS1 >> 28 LOAD_CONST 0 (None) 30 RETURN_VALUE >>> Why are there two separate bytecode blocks for the "raise Exception"? I'd have thought that the double condition would still be evaluated as one thing, or at least that the jump destinations for both the early-abort and the main evaluation should be the same. Looks like in 3.8 it compiles more like the way you expected. I didn't try 3.9, but it looks like a recent change to te compiler. -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to remove setup of 3.9.5 from Windows 10
Unrelated topic, but i thought Windows 10 will be retired anytime soon. On Sun, Jun 20, 2021 at 5:58 AM Mats Wichmann wrote: > On 6/19/21 10:14 AM, Manish Jain wrote: > > Hello Team, > > > > I have installed the Python 3.9.5 and trying to remove from the PC > through > > the Uninstall Program (All Possible ways - Through Control Panel or > > Uninstall Python executable) > > > > It just outputs saying Uninstall Successfully but nothing happening > (Still > > listed in Programs List) and even not allowing me to install again. > > > > Please let me know if there is any alternate resolution > > > > Thanks, > > Manish > > > > You could try this: > > > https://support.microsoft.com/en-us/topic/fix-problems-that-block-programs-from-being-installed-or-removed-cca7d1b6-65a9-3d98-426b-e9f927e1eb4d > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list