Re: unable to run the basic Embedded Python example
Hi Dave, I can tell you where the error comes from, but I don't know how to fix it correctly: Am 24.06.23 um 19:29 schrieb Dave Ohlsson: 9. And now, when I ran embedded_python.exe: 20:14:06: Starting C:\temp\build-embedded_python-Desktop_Qt_6_1_3_MSVC2019_64bit-Debug\debug\embedded_python.exe... Could not find platform independent libraries Python path configuration: PYTHONHOME = (not set) PYTHONPATH = (not set) program name = Python consists of the DLL that you have lined it with plus a large number of files (standard library) which contain, e.g., the encoding data and builtin functions etc. It needs to find these in order to run. You could set PYTHONHOME as an environment variable to point to that folder. If you don't use the regular Pyton installer, then you need to install these files yourself. Maybe there is also a way to set it from the C code. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter docs?
Am 24.05.23 um 03:18 schrieb Rob Cliffe: I have recently started converting a large project to tkinter, starting with zero knowledge of tkinter. (You are free to think: BAD IDEA. ) Welcome to the awesome world of GUI development. I was writing a subclass of the Checkbutton class (tkinter's name for what I call a checkbox). I needed to be able to (1) set (2) clear (3) interrogate the checked state. This is easy to do if you associate a "variable" with each Checkbutton instance, as seems to be usual tkinter practice. ("variable" is not a variable in the usual sense, but an object provided by tkinter that is linked to a GUI object (such as a Checkbutton), so that when the GUI object changes, the value of the "variable" changes, and vice versa.) However, I decided that I wanted to dispense with the variable, if possible. As you found out the hard way, it is possible, but then you dive into the internals of how the widgets work - usually you don't want to know that. Also, this bit differs between Tk and Ttk widgets. [...] lengthe description of Checkbutton internals In GUI programming, you will meet a bag of concepts that you haven't seen in sequential programming before. To make it worse, every GUI toolkit brings its own new set of concepts to the table. Maybe it is helpful to work through a Tk tutorial first. This is a good one: http://tkdocs.com/tutorial/index.html Similarly to the tutorial I would suggest to stick with the ttk widgets. Those are an "update" (> 10 years ago) to the tk widgets and are supposed to provide sensible defaults matching the users experience with native GUI elements. There are only 3 widgets where you must use a Tk widget, this is Text (for multiline formatted text entry), Canvas (for 2D drawings), and Toplevel (for new windows/ popups etc.) Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: How to add clickable url links to 3D Matplotlib chart ?
Am 30.03.23 um 01:11 schrieb a a: On Wednesday, 29 March 2023 at 22:51:15 UTC+2, Greg Ewing wrote: On 30/03/23 8:39 am, a a wrote: How to add clickable url links to the following 3D Matplotlib chart to make it knowledge representation 3D chart, make of 1,000+ open Tabs in Firefox ? It seems that matplotlib can be made to generate SVG images with hyperlinks in them: https://matplotlib.org/stable/gallery/misc/hyperlinks_sgskip.html -- Greg thank you but I need mouse hover-on, mouse click events to be handled by a simple algorithm to calculate which ball/circle has been selected (in the Matplotlib 3D animated chart above) to make the selected ball to flash and have label opened made of url icon, name of url, followed by url (exactly what Firefox makes with Tabs) For knowledge representation, 1,000+ Tabs open in Firefox, earthquakes 3D live chart by Giuseppe is a nice tool. One axis can represent time (timeline), two other axis can represent features attributed to to opened Tabs, like frequency of visits, ranking. Ok, balls should overlayed with a respective url icon, as done in Firefox (Tabs row) : url icon + label's name abbreviated It doesn't sound as if there is a "one-line" solution to this problem. It sounds more like you want a video game engine to interact with a 3D world. There used to be a 3D version of HTML, called VRML, with the successor of X3D that could show such a thing in the browser, but I doubt that there is easy support for it any more in recent browsers. Therefore it would be difficult to post this to the internet, unless you invest in some JS programming. In case you want to run this on your local computer, as opposed to in the browser, you can check out Python game engines. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Cutting slices
Am 05.03.23 um 23:43 schrieb Stefan Ram: The following behaviour of Python strikes me as being a bit "irregular". A user tries to chop of sections from a string, but does not use "split" because the separator might become more complicated so that a regular expression will be required to find it. OK, so if you want to use an RE for splitting, can you not use re.split() ? It basically works like the built-in splitting in AWK >>> s='alphaAbetaBgamma' >>> import re >>> re.split(r'A|B|C', s) ['alpha', 'beta', 'gamma'] >>> Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Evaluation of variable as f-string
Am 28.01.23 um 02:56 schrieb Thomas Passin: On 1/27/2023 5:10 PM, Christian Gollwitzer wrote: Am 27.01.23 um 21:43 schrieb Johannes Bauer: I don't understand why you fully ignore literally the FIRST example I gave in my original post and angrily claim that you solution works when it does not: x = { "y": "z" } s = "-> {x['y']}" print(s.format(x = x)) Traceback (most recent call last): File "", line 1, in KeyError: "'y'" This. Does. Not. Work. It's because "you're holding it wrong!". Notice the error message; it says that the key 'y' does not exist. (base) Apfelkiste:Abschlussmeeting chris$ ipython Python 3.8.8 (default, Apr 13 2021, 12:59:45) Type 'copyright', 'credits' or 'license' for more information IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: x = { "y": "z" } In [2]: s = "-> {x[y]}" In [3]: print(s.format(x = x)) -> z In [4]: Christian Oops, that's not quite what he wrote. You: s = "-> {x[y]}" # Works Him: s = "-> {x['y']}" # Fails You might want to reconsider why I could have possibly written this message Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Evaluation of variable as f-string
Am 27.01.23 um 21:43 schrieb Johannes Bauer: I don't understand why you fully ignore literally the FIRST example I gave in my original post and angrily claim that you solution works when it does not: x = { "y": "z" } s = "-> {x['y']}" print(s.format(x = x)) Traceback (most recent call last): File "", line 1, in KeyError: "'y'" This. Does. Not. Work. It's because "you're holding it wrong!". Notice the error message; it says that the key 'y' does not exist. (base) Apfelkiste:Abschlussmeeting chris$ ipython Python 3.8.8 (default, Apr 13 2021, 12:59:45) Type 'copyright', 'credits' or 'license' for more information IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: x = { "y": "z" } In [2]: s = "-> {x[y]}" In [3]: print(s.format(x = x)) -> z In [4]: Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: How to turn this Matlab code into python
Am 08.11.22 um 09:01 schrieb Dioumacor FAYE: From datenum to data_mjja=precp(:,ind_mjja); I think the code filters data based on calendar dates. I'd guess that you can do that most easily with pandas. https://pandas.pydata.org/docs/user_guide/timeseries.html Christian Le lun. 7 nov. 2022 à 21:42, Christian Gollwitzer a écrit : Am 07.11.22 um 18:12 schrieb Dioumacor FAYE: hi everyone I wanted to transform this matlab code into python. If anyone can help me please let me know. load /media/lpaosf/Dioumss/maman/data/precip_chirps_SEN_1981-2018.mat prcp = reshape(precip,[140*100,13879]); dates = datenum(1981,1,1):datenum(2018,12,31); date = datevec(dates); ind_mjja=find(date(:,2)>=5 & date(:,2)<=8);% May to Aug (May(31)+ June(30)+ July(31)+ August(31)= 123 days) data_mjja=precp(:,ind_mjja); data_mjja_res=reshape(data_mjja,14000,123,38); which part do you have trouble with? Christian -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: How to turn this Matlab code into python
Am 07.11.22 um 18:12 schrieb Dioumacor FAYE: hi everyone I wanted to transform this matlab code into python. If anyone can help me please let me know. load /media/lpaosf/Dioumss/maman/data/precip_chirps_SEN_1981-2018.mat prcp = reshape(precip,[140*100,13879]); dates = datenum(1981,1,1):datenum(2018,12,31); date = datevec(dates); ind_mjja=find(date(:,2)>=5 & date(:,2)<=8);% May to Aug (May(31)+ June(30)+ July(31)+ August(31)= 123 days) data_mjja=precp(:,ind_mjja); data_mjja_res=reshape(data_mjja,14000,123,38); which part do you have trouble with? Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: How to manage python shebang on mixed systems?
Am 07.11.22 um 10:28 schrieb Chris Green: Chris Green wrote: 3: with your pseudo "python3" script in place, make all the scripts use the "#!/usr/bin/env python3" shebang suggested above. Yes, that sounds a good plan to me, thanks Cameron. Doesn't '#!/usr/bin/env python3' suffer from the same problem as '#!/usr/bin/python3' in the sense that the env executable might not be in /usr/bin? Wouldn't '#! env python3' be better? Does this even work? I thought that, since the #! is resolved by the kernel, an absolute path is required, and that the whole purpose of the /usr/bin/env thing is to search the path (because it is universally installed in /usr/bin) and to possibly set other environment variables Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: setup.py + cython == chicken and the egg problem
Am 16.08.22 um 23:03 schrieb Dan Stromberg: I'm attempting to package up a python package that uses Cython. Rather than build binaries for everything under the sun, I've been focusing on including the .pyx file and running cython on it at install time. This requires a C compiler, but I'm OK with that. However, when I try to install the package from test.pypi.org, I get: $ python3 -m pip install -i https://test.pypi.org/simple/ pyx-treap below cmd output started 2022 Tue Aug 16 01:55:16 PM PDT Looking in indexes: https://test.pypi.org/simple/ Collecting pyx-treap Downloading https://test-files.pythonhosted.org/packages/3a/41/af5360934adccfc086a39e1f720323895144b53454ff6dacc0f06267db55/pyx_treap-2.0.15.tar.gz (125 kB) 125.9/125.9 kB 1.9 MB/s eta 0:00:00 Installing build dependencies ... error error: subprocess-exited-with-error ×? pip subprocess to install build dependencies did not run successfully. ?? exit code: 1 > [3 lines of output] Looking in indexes: https://test.pypi.org/simple/ ERROR: Could not find a version that satisfies the requirement setuptools (from versions: none) ERROR: No matching distribution found for setuptools [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: subprocess-exited-with-error I looked at your code and I think you are trying too hard. As far as I understand, you need Cython to be installed before the build process begins. Your entry in pyproject.toml should take care of that. But you also have these lines in your setup.py subprocess.check_call('%s -m pip install cython' % (sys.executable, ), shell=True) subprocess.check_call('%s -m cython pyx_treap.pyx' % (sys.executable, ), shell=True) The first one calls out to pip while pip is already running, I'm not sure that this will work, but judging from the error message it is looking for the requirements also from test.pypi. Maybe this is the reason that it fails (the error message says that it can't find setuptools). So jut delete this line and it might already work The second line, which compiles the Cython code, also runs *at every invocation of setup.py*, even if you'd do just python3 setup.py --help It may still work, but the correct way to do it is to create a build extension for setuptools. In my project you can see this here: https://github.com/j-from-b/CDEF/blob/main/setup.py#L88 OTOH, I would be surprised if Cython did not have this already, indeed you imported cythonize from Cython.Build. So maybe just deleting these two lines and it might work? Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: "CPython"
Am 20.06.22 um 22:47 schrieb Roel Schroeven: indication that www.analyticsinsight.net is wrong on that point. Frankly that website seems very low quality in general. In that same article they say: "CPython is a descendant of Pyscript built on Pyodide, a port of CPython, or a Python distribution for the browser and Node.js that is based on Webassembly and Emscripten." CPython is definitely not a descendant of Pyscript! Looks like someone found something (semi-) interesting and tried to write something insightful about it, but without really understanding any of it. Other articles don't seem to be any better. To me, this sentence is so badly cobbled together that it could be the output of a KI of some sort (GPT-3) trying to summarize stuff from the web. It doesn't make any sense at all on a semantic level. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test characters of a string
Am 08.06.22 um 19:57 schrieb De ongekruisigde: On 2022-06-08, 2qdxy4rzwzuui...@potatochowder.com <2qdxy4rzwzuui...@potatochowder.com> wrote: On 2022-06-09 at 04:15:46 +1000, Chris Angelico wrote: If you insist: >>> s = 'nm-iodine:x:996:57::/var/empty:/run/current-system/sw/bin/nologin' >>> print(s.split(':')) ['nm-iodine', 'x', '996', '57', '', '/var/empty', '/run/current-system/sw/bin/nologin'] Hesitantly, because this is the Python mailing list, I claim (a) ':' is simpler than r'([^:]*):([^:]*):(\d+):(\d+):([^:]*):([^:]*):(.*)$', and (b) string.split covers pretty much the same edge cases as re.search. Ah, but you don't catch the be numeric of fields (0-based) 2 and 3! But agreed, it's not the best of examples. Yes, that is a simplistic example, since the : can't even be quoted to appear in that format (which would require higher-order parsing than a simple split) Fortunately, the OP has just given another requirement to recognise different patterns, and now it went into a direction where it will become quite ugly if you avoid REs or any other pattern matching tools. This is also the main reason I suggested REs initially - often if you see other patterns in the data, you can easily adapt a RE solution, whereas you'll have to write the thing from ground up anew if you do it manually. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test characters of a string
Am 09.06.22 um 07:50 schrieb Dave: Hi, I’ve found you also need to take care of multiple disk CD releases. These have a format of “1-01 Track Name” “2-02 Trackl Name" Meaning Disk 1 Track1, Disk 2, Track 2. Also A and B Sides (from Vinyl LPs) “A1-Track Name” “B2-Track Name” Side A, Track 1, etc. Now you're getting into the complexity that is better handled by REs than by individual character examination. The first of your formats matches the RE \d-\d{2} (one digit, - two digits). Anchor that to check for a match at the beginning. The second one matches (A|B)\d- As long as one digit is enough. What is your goal, to extract these numbers or to strip them? Regexes can do both relatively easily. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test characters of a string
Am 07.06.22 um 23:01 schrieb Christian Gollwitzer: In [3]: re.sub(r'^\d+\s*', '', s) Out[3]: 'Trinket' that RE does match what you intended to do, but not exactly what you wrote in the OP. that would be '^\d\d.' start with exactly two digits followed by any character. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: How to test characters of a string
Am 07.06.22 um 21:56 schrieb Dave: It depends on the language I’m using, in Objective C, I’d use isNumeric, just wanted to know what the equivalent is in Python. Your problem is also a typical case for regular expressions. You can create an expression for "starts with any number of digits plus optional whitespace" and then replace this with nothing: chris@linux-tb9f:~> ipython Python 3.6.15 (default, Sep 23 2021, 15:41:43) [GCC] Type 'copyright', 'credits' or 'license' for more information IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import re In [2]: s='05 Trinket' In [3]: re.sub(r'^\d+\s*', '', s) Out[3]: 'Trinket' If it doesn't match, it will do nothing: In [4]: s='Es geht los' In [5]: re.sub(r'^\d+\s*', '', s) Out[5]: 'Es geht los' Some people on this list don't like regexes but for tasks like this they are made and working well. ^ is "starts with" \d is any digit \s is any space + is at least one * is nothing or one of Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Automatic Gain Control in Python?
Am 29.05.22 um 00:45 schrieb Stefan Ram: "Steve GS" writes: Subject: Automatic Gain Control in Python? Automatic Gain Control in Python is trivial. You have a list of samples and normalize them, i.e., divide by max. Slightly simplified [ s/max( samples )for s in samples ] (where sample values are normalized to the range -1,+1.) No, that's not it. Loudness is perceived in a different way, the crudest approximation is the standard deviation averaged over small frames, better measures take into account that the ear has a strongly frequency dependent response. For similar sound files, like podcasts which are voice-heavy, the stddev works reasoably well. If the normalization only reduces the volume, then dividing by the max is sufficient. However if you also want to raise the volume, then you need dynamic range compression. If you have ever tried to record some music with a simple microphone and a computer, you would have noticed that the recording is very soft, when normalized to the max. Commercial music is incredibly loud, and you might have wondered, how they do that. Google for "Loudness war" and "dynamic range compression" if you want to understand it in detail. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Issue sending data from C++ to Python
Am 18.05.22 um 16:08 schrieb Pablo Martinez Ulloa: I have been using your C++ Python API, in order to establish a bridge from C++ to Python. We want to do this, as we have a tactile sensor, which only has a library developed in C++, but we want to obtain the data in real time in Python to perform tests with a robotic arm and gripper. The problem we are facing is with transmitting the data into Python. We are using the function Py_BuildValue, and it seems to be working, but only for sending one value at a time, and we want to transmit 54 numbers The usual way to pass an array of numbers into Python is by means of a Numpy Array. In order to do that, you need to include arrayobject.h and then use PyArray_SimpleNew to create an array of numbers as a Python object which you can return https://numpy.org/devdocs/reference/c-api/array.html#c.PyArray_SimpleNew Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: No shortcut Icon on Desktop
Am 15.04.22 um 02:49 schrieb Mats Wichmann: On 4/14/22 18:06, Grant Edwards wrote: On 2022-04-14, Richard Damon wrote: I think the issue is that the 'python' interpreter/compiler isn't the sort of program that makes sense to make a desktop icon for, as it is a command line utility. Yes, it is a command line utility. Why does that mean you shouldn't have a desktop shortcut for it? I start up a python REPL prompt in a terminal often enough that were I a windows users, I would probably want a desktop shortcut for it. It would at least let people know that something got installed and show them what a Python is. If they don't want/use that shortcut, it's trivial to delete it. easy to add - it's a windows thing, not a python thing. you can navigate to the install directory and create a shortcut and drag that out of that directiory in explorer and drop it on the desktop. or you can navigate through the start menu, and when you get to the thing you want, pick open folder and then you can create a shortcut and drag off to the desktop. Yes, you *can* do that of course and it is not a Python thing - but the point is, that typical Windows installers create these shortcuts during the installation process for you - typically there is a pre-selected checkbox "Create desktop icons" or similar. I agree with Grant that this is what users expect from the installer. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing sequences with range objects
Am 08.04.22 um 09:21 schrieb Antoon Pardon: The first is really hard. Not only may information be missing, no single single piece of information is unique or immutable. Two people may have the same name (I know about several other "Peter Holzer"s), a single person might change their name (when I was younger I went by my middle name - how would you know that "Peter Holzer" and "Hansi Holzer" are the same person?), they will move (= change their address), change jobs, etc. Unless you have a unique immutable identifier that's enforced by some authority (like a social security number[1]), I don't think there is a chance to do that reliably in a program (although with enough data, a heuristic may be good enough). Yes I know all that. That is why I keep a bucket of possible duplicates per "identifying" field that is examined and use some heuristics at the end of all the comparing instead of starting to weed out the duplicates at the moment something differs. The problem is, that when an identifying field is judged to be unusable, the bucket to be associated with it should conceptually contain all other records (which in this case are the indexes into the population list). But that will eat a lot of memory. So I want some object that behaves as if it is a (immutable) list of all these indexes without actually containing them. A range object almost works, with the only problem it is not comparable with a list. Then write your own comparator function? Also, if the only case where this actually works is the index of all other records, then a simple boolean flag "all" vs. "these items in the index list" would suffice - doesn't it? Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Exchange OWA using Python?
Am 01.04.22 um 01:26 schrieb Grant Edwards: On 2022-03-31, Christian Gollwitzer wrote: Davmail is written in Java, not Python, but basically this should not matter if you only use it. Have you used it with OWA as the protocol? At least I thought so - this was in 2016 - 2017 and there was external webmail access allowed to our mail server. I've used davmail to connect to it. I vaguely remember that there was one day a sudden change, webmail was disabled and davmail then connected using EWS. Maybe the OWA protocol also evolved, I now see it on the roadmap. Good that you found a solution now with owl! I'm having a similar issue at my current position, we're using Lotus Notes (yes! The package from the 90s, it's outright horrible). There is only one thing available, the iNotes exporter, which allows to read the mail using thunderbird, sending is not implemented. Always keeping fingers crossed that the IT department does not update the server protocol. Sometimes they do minor changes like internal redirection URL changes, which costs me half a day to fix then. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Exchange OWA using Python?
Am 31.03.22 um 16:41 schrieb Grant Edwards: Is anybody aware of any Python code for the Exchange OWA protocol/API? The OWA e-mail client I've been using has stopped working. It was a commerical Python application named Hiri, wich has been abandoned by the developer. So, for now, I'm stuck with the OWA web client. It's clumsy and everything takes 3X as long to accomplish as it would with a real e-mail client, but I can survive with it if I have to. I can recommend davmail as a workaround: http://davmail.sourceforge.net/ Davmail converts OWA into regular mail protocols like POP3, IMAP, SMTP. You can use any email/calender client (I've used thunderbird) and most of it worked well. Davmail is written in Java, not Python, but basically this should not matter if you only use it. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Set tkinter top-level window to "always on visible workspace"
Am 28.03.22 um 20:03 schrieb Chris Angelico: Would you accept a solution that involves a subprocess call? wmctrl -ir {id} -b add,sticky Now, the only problem is... figuring out your window ID. Worst case, parse wmctrl -lG to get that info, but it might be possible to get the window ID from Tkinter itself. Sure: Call "winfo_id()" on the toplevel. You might want to reformat in it in hex format, which is the usual way to pass these IDs around. Tk actually returns it in hex format, but Tkinter reformats it as an integer. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Set tkinter top-level window to "always on visible workspace"
Am 28.03.22 um 00:55 schrieb Skip Montanaro: So you might tell your window manager to keep that window on the main workspace. Thanks. I'd forgotten about the possibility of doing this sort of thing in the window manager config. That would certainly be fine in this case. (It's been ages since I messed with this sort of thing.) I might be misguided, but on modern desktops that should be possible with a few mouseclicks. E.g. in KDE, there is a little pin icon displayed in every title bar of a toplevel window on the left side. If you click it, the window is shown on every workspace. There is also a way to set properties for a window permanently, by right-clicking on the title bar and then "enhanced attributes" (or similar, don't have KDE to check it roght now here) which gives a menu with multiple options to force the geometry. I don't know for GNOME desktop, but suspect it should be similarly easy. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Compiling and Linking pre-built Windows Python libraries with C++ files on Linux for Windows
Am 19.03.22 um 01:08 schrieb Ankit Agarwal: This is a very specific question. I am trying to figure out whether or not I can use pre-built python libraries and headers on Windows in a MinGW build on Linux. With the mingw cross-compiler on Linux that should be possible, however I guess it might be difficult to set it up. Setuptools is not good for crosscompiling. The easiest way to build Python extensions across multiple OSes is cibuildwheel: https://github.com/pypa/cibuildwheel Especially if your code lives on Github, then you can simply add cibuildwheel to your workflow and it will build for multiple OSes and Python versions on every commit. For OpenSource projects, Githubs build servers are even for free! Otherwise, the prices are moderate as well. If you happen to have your own build server farm (as in a commercial setting) then you can also use other CI tools with cibuildwheel. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: strange problem building non-pure wheel for apple M1 arm64
Am 07.03.22 um 17:22 schrieb Robin Becker: I use brew to install freetype version 2.11.1. gcc -bundle -undefined dynamic_lookup -g -arch arm64 build/temp.macosx-11.0-arm64-3.9/src/rl_addons/renderPM/_renderPM.o build/temp.macosx-11.0-arm64-3.9/src/rl_addons/renderPM/gt1/gt1-dict.o build/temp.macosx-11.0-arm64-3.9/src/rl_addons/renderPM/gt1/gt1-namecontext.o '''other compiled code build/temp.macosx-11.0-arm64-3.9/src/rl_addons/renderPM/libart_lgpl/art_vpath_dash.o -L/usr/local/lib -L/usr/lib -L/Library/Frameworks/Python.framework/Versions/3.9/lib -lfreetype -o build/lib.macosx-11.0-arm64-3.9/reportlab/graphics/_renderPM.cpython-39-darwin.so ld: warning: ignoring file /usr/local/lib/libfreetype.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64 The above message seems bizarre; everything is compiled for arm64, but gcc doesn't want to use an arm64 dylib. I would interpret this as: the host is runnig in intel, by doing the "brew install" it installs the intel version of freetype into /usr/local/lib/ ; then you cross-compile the python extension for ARM, but -lfreetype picks up the host version. On macOS it is not mandatory that all symbols in a .dylib are resolved. I would guess that the resulting file will not work on M1 macs. YOu can check by otool -L /path/toyour.dylib which libraries are referenced. If you use freetype functions in your C code and do not see it referenced, then the lib will not work. Maybe you can install an ARM-version of freetype, or compile it from source during your build process? Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Why does not Python accept functions with no names?
Am 20.02.22 um 16:48 schrieb Python: Abdur-Rahmaan Janhangeer wrote: Greetings list. Out of curiosity, why doesn't Python accept def (): return '---' () Where the function name is ''? For the same reason an empty sequence of characters cannot be a variable name. Do you know any language (or formal theory) that allows that? Tcl allows that: Main console display active (Tcl8.6.9 / Tk8.6.9) (CDEF) 49 % set "" Hallo Hallo (CDEF) 50 % puts ${} Hallo (CDEF) 51 % proc "" {} { puts "I'm empty" } (CDEF) 52 % "" I'm empty (CDEF) 53 % Any string can be a variable or command name, only :: is special as a namespace separator. This only works because of the sparse syntax; to retrieve a variable's content, $ is used. For "strange" names quoting is required, therefore I had to use "" in the example. It's a different matter how useful this actually is. One of the object systems in Tcl uses the empty variable to represent "self" as an array, so that you can write $(prop) for self.prop as it is in Python. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'
Am 10.02.22 um 20:43 schrieb Chris Angelico: On Fri, 11 Feb 2022 at 06:41, Dennis Lee Bieber wrote: While not tested with Excel, I /have/ encountered cases where an application has locked the file for writing, but multiple readers are permitted. Those would fail then if one attempts to write. {The other view point is a library that does a complete open/read\write-all/close to memory -- such an application might open/read/close, then Excel opens/locks, with the application only learning of the change when it attempts the open/write/close cycle} Yeah, I doubt Excel is that sophisticated. It's built on an assumption of single-user operation. It guards against multiple user opening the same file over network drives. All MS applications create lock files with weird names like ~.original-name.xlsx etc. If you open a file on the network share, and a colleague tries to open it from a second machine, then he will get the message "File locked by user xy from machine z". See here for word: https://support.microsoft.com/en-us/topic/-the-document-is-locked-for-editing-by-another-user-error-message-when-you-try-to-open-a-document-in-word-10b92aeb-2e23-25e0-9110-370af6edb638 I believe (haven't tested) that this is cooperative locking only and it doesn't help if you alter the file from another program. On the same machine though, I think that Excel opens the file with a flag to lock it from other processes. At least that was my observation and also what the OP has described. Hence it is impossible to concurrently write from Python into an open Excel file. One might ask what the real problem is the user is trying to solve. Is Excel a requirement, can it be swapped by a database engine? Best regards, Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: How to solve the given problem?
Am 10.02.22 um 11:26 schrieb NArshad: -ChrisA: You don't reply if you have problems. When I don't find any solution elsewhere then only I place in this group -Christian: One problem of different type requires the same elaboration. No it doesn't Q. What technique of statistics or numerical computation or general mathematics to use to solve this problem. Can you tell one example Find the values of 푥subscript(푖) for i from 1 to n (n =100). WTF? Go study maths yourself instead of asking here (Offf-topic as well) Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: How to solve the given problem?
Am 10.02.22 um 07:40 schrieb NArshad: Assume that there is a pattern of feeding for a special fish in a day (10 hours a day) as below: 150100303030202010 55 Today, the fish is fed in the second hour 60 unit instead of 100 unit Accidently. Implement some methods to distribute the remaining 40 unit in the rest of the day and propose the new patterns. Try to keep the distribution similar to the current feeding pattern. Note: pay attention that the total feeding amounts should be fix in a day. This is not a Python problem, it's a math problem and most probably a homework problem. Actually the question already tells you how to solve it. There are 40 units of fish-food left and you should distribute them proportionally to the rest of the day. Sum up the numbers from 3rd to last, add 40, and then distribute this to proportionally to each day. You'll end up with fractinoal numbers in the general case, so you'll have to find a method to fairly distribute the units, if you wan to stick with integers. You can also check out the various algorithms for distributing seats in a parliament, it is almost the same problem. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'
Am 09.02.22 um 08:46 schrieb NArshad: When I enter data using Tkinter form in an Excel file when the excel file is closed there is no error but when I enter data using Tkinter form when the excel is already open following error comes: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx' What to do to correct this error? I have already searched on google search many times but no solution was found. It's impossible. Excel locks the file deliberately when it is open, so that you can't overwrite it from a different program. Otherwise, the file could become inconsistent. The correct way to handle it in the GUI is to tell the user via a message box that the file is open and can't be written. An alternative to writing the file directly would be that you remote control Excel; I think it provides a DDE API: https://support.microsoft.com/en-us/office/dde-function-79e8b21c-2054-4b48-9ceb-d2cf38dc17f9 Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Correct way to setup a package with both compiled C code and Python code?
Am 08.02.22 um 18:57 schrieb Dieter Maurer: Christian Gollwitzer wrote at 2022-2-7 20:33 +0100: we've developed a Python pacakge which consists of both a compiled extension module and some helper functions in Python. Is there a tutorial on how to package such an extension? Look at "https://package.python.org;, especially "https://packaging.python.org/en/latest/guides/packaging-binary-extensions/;. Thank you, but that page is more like a high-level description, it talks a lot about the differences between C code and Python and how it can be combined using SWIG etc, but I already have a working extension. My question was more targeted at how to write the setup.py file in this case such that both the compiled code and the Python code gets loaded. In the meantime, I found a similar example for C++ code with CMake and pybind11 here: https://github.com/benjaminjack/python_cpp_example That gave me enough to create a similar thing for a pure CPython extension: https://github.com/auriocus/python_setuptools_sandbox Now, I still have to figure out how to get this on PyPI and how to enable OpenMP during compilation. Christian -- https://mail.python.org/mailman/listinfo/python-list
Correct way to setup a package with both compiled C code and Python code?
Hi all, we've developed a Python pacakge which consists of both a compiled extension module and some helper functions in Python. Is there a tutorial on how to package such an extension? Most resources I found for distutils describe either building an extension or pure python modules. Currently I have a structure like this: ABCD/__init__.py ABCD/main.py ccode/some.c ccode/some.h ccode/Makefile The Makefile compiles the C code and creates ABCD/some.so, which "main.py" then imports. This works, but not e.g. on Windows and it's not integrated into pip, of course. We're soon going to publish the package as open source code and it would be great to do "pip install ABCD" ultimately. Is there a simple example out there how to achieve this? Additionally, we use OpenMP in the C code for parallelism. This is easy in the Makefile, one has to pass "-fopenmp" to gcc and "/openmp" to msvc. Is there a way to set this flag automatically depending on the compiler? Best regards, Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Failure to Display Top menu
Am 26.11.21 um 21:38 schrieb Peter Mwale: Hello, my python 3.10 shell is not displaying the top menu. What should I do? You should explain, what you do exactly. The Python interpreter does not have a menu. a) What platform are you on? Windows, macOS, Linux? b) How did ou start Python and what was the expectation? Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: One line sort
Am 15.11.21 um 14:10 schrieb ast: A curiosity: q = lambda x: x and q([i for i in x[1:] if i < x[0]]) + [x[0]] + q([i for i in x[1:] if i >= x[0]]) >>> q([7, 5, 9, 0]) [0, 5, 7, 9] That seems to be a translation of the classic Haskell quicksort example: qsort [] = [] qsort (x:xs) = qsort [a | a <- xs, a < x] ++ [x] ++ qsort [b | b <- xs, b >= x] The Haskell version is a bit clearer IMHO due to the pattern matching, but that results in a 2 liner :) Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Create a contact book
Am 26.10.21 um 07:40 schrieb anders Limpan: i would like to create a contact book were you can keep track of your friends. With this contact book you will both be able to add friends and view which friends that you have added. anyone interested in helping me out with this one ?=) Here is how to do it: https://facebook.com/ Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: sum() vs. loop
Am 12.10.21 um 05:41 schrieb Dan Stromberg: On Mon, Oct 11, 2021 at 2:54 PM Steve Keller wrote: I have found the sum() function to be much slower than to loop over the operands myself: def sum_products(seq1, seq2): return sum([a * b for a, b in zip(seq1, seq2)]) def sum_products2(seq1, seq2): sum = 0 for a, b in zip(seq1, seq2): sum += a * b return sum It seems like the generator expression should be the fastest to me. But writing for speed instead of writing for clarity is usually not a great idea. Maybe, unless this was just a test, it can be fastest AND clearest with numpy.dot(seq1, seq2) - in case that the sequence consists of floats and, in the best case, is already stored in a numpy array. Then you cannot beat this with Python code. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: sum() vs. loop
Am 10.10.21 um 10:49 schrieb Steve Keller: I have found the sum() function to be much slower than to loop over the operands myself: def sum_products(seq1, seq2): return sum([a * b for a, b in zip(seq1, seq2)]) def sum_products2(seq1, seq2): sum = 0 for a, b in zip(seq1, seq2): sum += a * b return sum In a program I generate about 14 million pairs of sequences of ints each of length 15 which need to be summed. The first version with sum() needs 44 seconds while the second version runs in 37 seconds. The first version constructs a list, sums it up and throws the list away, while the second version only keeps the running sum in memory. How about a generator expression instead, i.e. sum((a * b for a, b in zip(seq1, seq2))) (untested) ? Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: NUmpy
Am 29.09.21 um 18:16 schrieb Jorge Conforte: Hi, I have a netcdf file "uwnd_850_1981.nc" and I'm using the commands to read it: Your code is incomplete: from numpy import dtype fileu ='uwnd_850_1981.nc' ncu = Dataset(fileu,'r') Where is "Dataset" defined? uwnd=ncu.variables['uwnd'][:] and I had: :1: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations I didn't how I have this message. My numpy verison is 1.21.2. Please, how can I solve this. First, it is only a warning, therefore it should still work. Second, the problem is not in the code that you posted. POssibly in the definition of "Dataset". Maybe the netCDF-File contains boolean values and the package you use to read it should be updated? Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: XML Considered Harmful
Am 22.09.21 um 16:52 schrieb Michael F. Stemper: On 21/09/2021 19.30, Eli the Bearded wrote: Yes, CSV files can model that. But it would not be my first choice of data format. (Neither would JSON.) I'd probably use XML. Okay. 'Go not to the elves for counsel, for they will say both no and yes.' (I'm not actually surprised to find differences of opinion.) It is wrong, CSV has no model of hierarchical data. A CSV file is a 2d table, just like a database table or an Excel sheet. You can /layer/ high-dimensional data on top of a 2D table, there is the relational algebra theory behind this, but it is wrong (or misleading at best) to say that CSV can model hierarchical data. It's the same as saying "CSV supports images". Of course it doesn't, its a textfile, but you could encode a JPEG as base64 and then put this string into the cell of a CSV table. That definitely isn't what a sane person would understand as "support". Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: on floating-point numbers
Am 04.09.21 um 14:48 schrieb Hope Rouselle: Christian Gollwitzer writes: Am 02.09.21 um 15:51 schrieb Hope Rouselle: Just sharing a case of floating-point numbers. Nothing needed to be solved or to be figured out. Just bringing up conversation. (*) An introduction to me I don't understand floating-point numbers from the inside out, but I do know how to work with base 2 and scientific notation. So the idea of expressing a number as mantissa * base^{power} is not foreign to me. (If that helps you to perhaps instruct me on what's going on here.) (*) A presentation of the behavior import sys sys.version '3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]' ls = [7.23, 8.41, 6.15, 2.31, 7.73, 7.77] sum(ls) 39.594 ls = [8.41, 6.15, 2.31, 7.73, 7.77, 7.23] sum(ls) 39.61 All I did was to take the first number, 7.23, and move it to the last position in the list. (So we have a violation of the commutativity of addition.) I believe it is not commutativity, but associativity, that is violated. Shall we take this seriously? (I will disagree, but that doesn't mean I am not grateful for your post. Quite the contary.) It in general violates associativity too, but the example above couldn't be referring to associativity because the second sum above could not be obtained from associativity alone. Commutativity is required, applied to five pairs of numbers. How can I go from 7.23 + 8.41 + 6.15 + 2.31 + 7.73 + 7.77 to 8.41 + 6.15 + 2.31 + 7.73 + 7.77 + 7.23? Perhaps only through various application of commutativity, namely the ones below. (I omit the parentheses for less typing. I suppose that does not create much trouble. There is no use of associativity below, except for the intented omission of parentheses.) With the parens it will become more obvious. 7.23 + 8.41 + 6.15 + 2.31 + 7.73 + 7.77 = 8.41 + 7.23 + 6.15 + 2.31 + 7.73 + 7.77 The sum is evaluated as (((7.23 + 8.41) + 6.15 + ...) For the first shift, you are correct that commutativity will result in (((8.41 + 7.23) + 6.15 + ...) But you can't go in one step to (((8.41 + 6.15) + 7.23 + ...) with the commutativity law alone. Instead, a sequence of associativity and commutativity is required to move the 7.23 out of the first pair of parentheses. And what I was trying to say, the commutative steps *are* equal in floating point arithmetics, whereas the associative steps are not. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: on floating-point numbers
Am 02.09.21 um 21:02 schrieb Julio Di Egidio: On Thursday, 2 September 2021 at 20:43:36 UTC+2, Chris Angelico wrote: On Fri, Sep 3, 2021 at 4:29 AM Hope Rouselle wrote: All I did was to take the first number, 7.23, and move it to the last position in the list. (So we have a violation of the commutativity of addition.) It's not about the commutativity of any particular pair of operands - that's always guaranteed. Nope, that is rather *not* guaranteed, as I have quite explained up thread. No, you haven't explained that. You linked to the famous Goldberg paper. Where in the paper does it say that operations on floats are not commutative? I'd be surprised because it is generally wrong. Unless you have special numbers like NaN or signed zeros etc., a+b=b+a and a*b=b*a holds also for floats. Christiah -- https://mail.python.org/mailman/listinfo/python-list
Re: on floating-point numbers
Am 02.09.21 um 15:51 schrieb Hope Rouselle: Just sharing a case of floating-point numbers. Nothing needed to be solved or to be figured out. Just bringing up conversation. (*) An introduction to me I don't understand floating-point numbers from the inside out, but I do know how to work with base 2 and scientific notation. So the idea of expressing a number as mantissa * base^{power} is not foreign to me. (If that helps you to perhaps instruct me on what's going on here.) (*) A presentation of the behavior import sys sys.version '3.8.10 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]' ls = [7.23, 8.41, 6.15, 2.31, 7.73, 7.77] sum(ls) 39.594 ls = [8.41, 6.15, 2.31, 7.73, 7.77, 7.23] sum(ls) 39.61 All I did was to take the first number, 7.23, and move it to the last position in the list. (So we have a violation of the commutativity of addition.) I believe it is not commutativity, but associativity, that is violated. Even for floating point, a+b=b+a except for maybe some extreme cases like denormliazed numbers etc. But in general (a+b)+c != a+ (b+c) Consider decimal floating point with 2 digits. a=1 b=c=0.04 Then you get LHS; (1 + 0.04) + 0.04 = 1 + 0.04 = 1 RHS: 1 + (0.04 + 0.04) = 1 + 0.08 = 1.1 Your sum is evaluated like (((a + b) + c) + ) and hence, if you permute the numbers, it can be unequal. If you need better accuracy, there is the Kahan summation algorithm and other alternatives: https://en.wikipedia.org/wiki/Kahan_summation_algorithm Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: on floating-point numbers
Am 02.09.21 um 16:49 schrieb Julio Di Egidio: On Thursday, 2 September 2021 at 16:41:38 UTC+2, Peter Pearson wrote: On Thu, 02 Sep 2021 10:51:03 -0300, Hope Rouselle wrote: 39.61 Welcome to the exciting world of roundoff error: Welcome to the exiting world of Usenet. *Plonk* Pretty harsh, isn't it? He gave a concise example of the same inaccuracy right afterwards. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Create a real-time interactive TUI using Python.
Am 31.08.21 um 18:49 schrieb Chris Angelico: On Wed, Sep 1, 2021 at 1:59 AM hongy...@gmail.com wrote: I want to know whether python can be used to create real-time interactive TUI, as hstr [1] does. [1] https://github.com/dvorka/hstr Yes. I think he also would like to know, how to achieve this ;) This kind of interface is usually done with the "curses"-library. There is a Python version of it, see e.g. here https://docs.python.org/3/howto/curses.html Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Subpixel positioning on Tk canvas
Am 20.06.21 um 01:49 schrieb Terry Reedy: On 6/19/2021 12:42 AM, Christian Gollwitzer wrote: 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? Since ActiveState has pulled out the developers of Tcl a few years ago, I haven't used ActiveTcl anymore. I was surprised to see that they actually offer a fairly recent version, but it also cannot be simply downloaded, one has to register. It was unclear to me if it costs money. Other people have stepped in to provide Tcl distributions where tese extensions are included; notable exanples are BAWT by Paul Obermeier http://www.bawt.tcl3d.org/download.html which offers all of the mentioned packages (and many more), Androwish/Undroidwish by Christian Werner which was originally developed for Android, but now works on te major desktop platforms, http://androwish.org/home/wiki?name=undroidwish and even kbskit can be mentioned, started by Rene Zaumseil and now updated in irregular intervals by me https://github.com/auriocus/kbskit I haven't checked the major linux distros, but they also might ship with some of these extensions. Concerning installation, it differs. Tablelist (also part of tklib) and pdf4tcl are pure-Tcl packages and therefore easily installed. TkDnD, TkTable and tkTreeCtrl are compiled extensions and therefore more difficult - however, due to the stubs mechanism of Tcl, the version number of Tcl and C compiler do NOT need to match. Typically a binary downloaded for the right OS and bitness will work, and compilation from source works with an autoconf-based configure script. Due to ActiveState's failure with the teapot, the Tcl world does now not any longer have a central repository tool like "pip" which works for everyone. This has just recently been discussed on comp.lang.tcl, but it is unlikely to happen in the near future. It is of course unrealistic to expect that Tkinter supports every odd Tk extension fron the Tcl world, which might not even be maintained any longer. OTOH there are extensions that are well-maintained, that could as well be part of the core Tk, but aren't for political reasons. If Tkinter continues to be the shipped "first choice" GUI for Python, then a few could be included - or otherwise Tkinter will lack Drag'n'drop for ever and a reasonable Tree widget (the core one is vey basic). Best regards, Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter problem
Am 19.06.21 um 08:48 schrieb Jach Feng: Christian Gollwitzer 在 2021年6月19日 星期六下午1:54:46 [UTC+8] 的信中寫道: 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. 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. Ah! Now I get it, sorry, missed that earlier. 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
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 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
Am 18.06.21 um 08:28 schrieb Liya Ann Sunny: I am using Colab. How could solve this problem. TclError: couldn't connect to display ":0.0" You're either not running an X server, or having problems to connect to it. Are you sure that Google Colab supports X11 at all? This link doesn't seem to support that idea: https://stackoverflow.com/questions/61168210/is-there-any-way-to-use-tkinter-with-google-colaboratory Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to get the following result in Python?
Am 12.06.21 um 04:02 schrieb Jach Feng: def foo(): ... # do something ... a = [] for i in range(3): ... a.append(foo()) ... a [] How about having "foo" return a list of things? Then you can append that list and return an empty list if you want nothing added: In [1]: def foo(): ...: return [1,2,3] ...: In [2]: def bar(): ...: return [] ...: In [3]: a=[] In [4]: a += foo() In [5]: a Out[5]: [1, 2, 3] In [6]: a += bar() In [7]: a Out[7]: [1, 2, 3] Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: learning python ...
Am 25.05.21 um 06:08 schrieb hw: On 5/25/21 12:37 AM, Greg Ewing wrote: Python does have references to *objects*. All objects live on the heap and are kept alive as long as there is at least one reference to them. If you rebind a name, and it held the last reference to an object, there is no way to get that object back. Are all names references? When I pass a name as a parameter to a function, does the object the name is referring to, when altered by the function, still appear altered after the function has returned? I wouldn't expect that ... Yes, it does. It is a common pitfall for newbie Python programmers. def f(a): a.append(2) l=[1, 2, 3] f(l) print(l) ==> [1, 2, 3, 2] The strange thing, coming from a different language, is the apparent difference, if instead of a list, you pass an integer: def f(a): a=5 l=3 f(l) print(l) > 3 Here, the "l" is not changed. The reason is that the statement "a=5" does NOT modify the object in a, but instead creates a new one and binds it to a. l still points to the old one. Whereas a.append() tells the object pointed to by a to change. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Bloody rubbish
Am 06.05.21 um 19:54 schrieb Skip Montanaro: Machine language is so much simpler, and you can code with just a hexpad. Pshaa... All you need are front panel switches. ;-) (Yes, I had a professor who required is to 'key' in our programs on the front panel, of a rack mounted PDP-11 as I recall. Needless to say, we didn't use an assembler either. We just wrote raw opcodes and their arguments on paper. This was in the late 70s.) Pure luxury! https://xkcd.com/378/ Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Not found in the documentation
Am 29.04.21 um 08:54 schrieb elas tica: Le mercredi 28 avril 2021 à 17:36:32 UTC+2, Chris Angelico a écrit : In what sense of the word "token" are you asking? The parser? You can play around with the low-level tokenizer with the aptly-named tokenizer module. It was a good suggestion, and the PLR doesn't mention the tokeniser module. It should, this goes very well with the conversional style it has. # -- from tokenize import tokenize from io import BytesIO s="""42 not\ in [42]""" g = tokenize(BytesIO(s.encode('utf-8')).readline) print(*(g), sep='\n') # -- the docs are wrong when they say: .. using a backslash). A backslash is illegal elsewhere on a line outside a string literal. .. You're not passing a backslash. Try print(s). It would be different with a raw string s=r"""42 not\ in [42]""" Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: convert script awk in python
Am 25.03.21 um 00:30 schrieb Avi Gross: It [awk] is, as noted, a great tool and if you only had one or a few tools like it available, it can easily be bent and twisted to do much of what the others do as it is more programmable than most. But following that line of reasoning, fairly simple python scripts can be written with python -c "..." or by pointing to a script The thing with awk is that lots of useful text processing is directly built into the main syntax; whereas in Python, you can certainly do it as well, but it requires to load a library. The simple column summation mentioned before by Cameron would be awk ' {sum += $2 } END {print sum}' which can be easily typed into a command line, with the benefit that it skips every line where the 2nd col is not a valid number. This is important because often there are empty lines, often there is an empty line at the end, some ascii headers whatever. The closest equivalent I can come up with in Python is this: == import sys s=0 for line in sys.stdin: try: s += float(line.split()[1]) except: pass print(s) === I don't want to cram this into a python -c " " line, if it even is possible; how do you handle indentation levels and loops?? Of course, for big fancy programs Python is a much better choice than awk, no questions asked - but awk has a place for little things which fit the special programming model, and there are surprisingly many applications where this is just the easiest and fastest way to do the job. It's like regexes - a few simple characters can do the job which otherwise requires a bulky program, but once the parsing gets to certain complexity, a true parsing language, or even just handcoded Python is much more maintainable. Christian PS: Exercise - handle lines commented out with a '#', i.e. skip those. In awk: gawk '!/^\s*#/ {sum += $2 } END {print sum}' -- https://mail.python.org/mailman/listinfo/python-list
Re: .title() - annoying mistake
Am 22.03.21 um 16:03 schrieb Robert Latest: Chris Angelico wrote: Cool thing is, nobody in Python needs to maintain anything here. That's great because I'm actually having trouble with sending log messages over the socket conection you helped me with, would you mind having a look? You misunderstood the "here". (native German as well, but I think it means "for keeping .title() up to date) I agree with Chris that .title() can be useful for "title-casing" a single character, whatever that means. It should be documented, though, that it is not suitable to title-case a string, not even in English. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: neonumeric - C++ arbitrary precision arithmetic library
Am 07.03.21 um 20:42 schrieb Peter J. Holzer: The second part is converting a parse tree into code. I am quite sure that it is possible to devise a formal language to specify the semantics of any programming language and then to use this to generate the code. However, I strongly suspect that such a language would be comparable in expressiveness and ease of use to other programming languages - or in other worlds it would be just another programming language. As far as I understand the idea, Leigh (aka Mr Flibble) thinks that he can create a "library" of code translators that translate the individual pieces of the parse tree into some intermediate code, and by specifying these codelets within the grammar the semantics of a language can be fully described. My argument against this whole thing is that the library would be enormous. He seems to think that big chunks can be reused for different languages, but I don't believe this. A simple example: int a = -3 unsigned int b = 5; in C: a < b is false. This is insane but follows from the type casting rules in C. in Python or any other language with sane integers, -3 < 5 will always be true. For large enough values you must convert them to big integers. CPython simply uses big integers for everything, but that obviously slows down the whole thing. If you want to compile that to fast machine code, you need to do the computation in fixed integers and check for overflow *after every single step*. And there are myriads of differences. Introducing JavaScript again will bring myriads of differences and so on. The closest thing to such a project I can think of is LLVM. It still requires you to write the actual code generator, but features many intrinsics and libriaries that could be reused and therefore it is easy to add a new language. The approximate value of LLVM is estimated here: https://chriscummins.cc/2019/llvm-cost/ It's over 5000 man years of work. There is no way a single developer, regardless how brilliant he may be, can recreate this in his lifetime. Maybe focussed to a single language or two, but not "universal" in any sense. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter long-running window freezes
Am 26.02.21 um 06:15 schrieb John O'Hagan: On Thu, 25 Feb 2021 21:57:19 +0100 Christian Gollwitzer wrote: I think it is not yet clear, if this is a bug in Tkinter or in Tcl/Tk, the underlying scripting language. It might also be platform dependent. Are you on Windows? Here is an equivalent Tcl program: == package require Tk proc randint {} { expr {int(rand()*1000)} } proc display {label} { destroy $label set id [randint] set label [label .l$id -text [randint]] pack $label after 100 [list display $label] } display [label .l] Can you run this and check that the freeze also occurs? If you can't execute the Tcl that is used by Python directly, you may also do something like root = Tk() root.eval('Here comes the Tcl code') root.mainloop() Can you also find out what version of Tcl/Tk you are using? Try root.eval('info patchlevel') Christian I've followed your suggestions as per my last post, and can confirm the same freezing behaviour when running your code directly as a tclsh script on Debian Testing, Tcl 8.6.11. You might report this as a bug to the Tcl bugtracker https://core.tcl-lang.org/tk/ticket I guess the problem is with the steady creation of widgets. Tk was not meant to be used like that. Tkinter creates new widget names for each widget with random numbers, just like the Tcl code above does, whereas in a usual Tcl/Tk program the names are given by the programmer. Can you also check this program, which reuses the same widget path name, albeit does the creation/destruction in cycles: == package require Tk proc randint {} { expr {int(rand()*1000)} } proc display {label} { destroy $label set label [label .l -text [randint]] pack $label after 100 [list display $label] } display [label .l] As mentioned by others, typically you wouldn't continuously recreate new widgets, but either update the text of the widget (label['text']="New text") or attaching a StringVar() ) or, if you must rearrange the widgets, you pack_forget() them and then repack them. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: error of opening Python
Am 25.02.21 um 18:22 schrieb Botao Liu: Dear Python team, This is my first time using Python, I tried to launch Python and it showed "Python 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information." I don't know what this meant and how to fix this. Could you please help me? Thank you very much. This is as it should be. What have you expected, that you think this is wrong? Maybe you are looking for an IDE like IDLE (should be installed along with Python on Windows), or something very different? Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter long-running window freezes
Am 24.02.21 um 12:35 schrieb John O'Hagan: Hi list I have a 3.9 tkinter interface that displays data from an arbitrary number of threads, each of which runs for an arbitrary period of time. A frame opens in the root window when each thread starts and closes when it stops. Widgets in the frame and the root window control the thread and how the data is displayed. This works well for several hours, but over time the root window becomes unresponsive and eventually freezes and goes grey. No error messages are produced in the terminal. Here is some minimal, non-threaded code that reproduces the problem on my system (Xfce4 on Debian testing): from tkinter import * from random import randint root = Tk() def display(label): label.destroy() label = Label(text=randint(0, 9)) label.pack() root.after(100, display, label) display(Label()) mainloop() This opens a tiny window that displays a random digit on a new label every .1 second. (Obviously I could do this by updating the text rather than recreating the label, but my real application has to destroy widgets and create new ones). This works for 3-4 hours, but eventually the window freezes. I think it is not yet clear, if this is a bug in Tkinter or in Tcl/Tk, the underlying scripting language. It might also be platform dependent. Are you on Windows? Here is an equivalent Tcl program: == package require Tk proc randint {} { expr {int(rand()*1000)} } proc display {label} { destroy $label set id [randint] set label [label .l$id -text [randint]] pack $label after 100 [list display $label] } display [label .l] Can you run this and check that the freeze also occurs? If you can't execute the Tcl that is used by Python directly, you may also do something like root = Tk() root.eval('Here comes the Tcl code') root.mainloop() Can you also find out what version of Tcl/Tk you are using? Try root.eval('info patchlevel') Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 0.9.1
Am 16.02.21 um 22:57 schrieb Skip Montanaro: A note to webmas...@python.org from an astute user named Hiromi in Japan* referred us to Guido's shell archives for the 0.9.1 release from 1991. I then pushed the result to a Github repo: https://github.com/smontanaro/python-0.9.1 That's a nice find! Reading the README, it occured to me that it refers to the shell, awk and perl as contenders for Python[1], but not to Tcl. I would have thought that in 1991, Tcl was one of the obvious choices as an extension language. At that time, it had already progressed to version 6 [2] Was Guido not aware of Tcl, or did he not think that it is a contender in the same area? Christian [1] "Python, an extensible interpreted programming language [...] can be used instead of shell, Awk or Perl scripts, to write prototypes of real applications, or as an extension language of large systems, you name it." [2] https://wiki.tcl-lang.org/page/Tcl+chronology -- https://mail.python.org/mailman/listinfo/python-list
Re: New Python implementation
I agree to all the rest of your post, but this: Am 16.02.21 um 09:57 schrieb Tarjei Bærland: I am not sure I agree that a language like Scheme or Logo or Brainfuck, with their small number of building blocks, would be harder to learn. is strange. I'm not sure, have you actually looked at Brainfuck? Maybe there is also confusion what means "learning" a programming language. For me, learning a language does not mean to remember the rules and keywords, but to be able to write useful programs. Indeed, Brainfuck with its 8 commands is easy to remember, but it comes at a very high price: you can't do anything useful with it with reasonable effort. It is unusable even for pure computer science stuff. It is easy to see that BF is Turing complete, so please write a BF program to compute the ackermann function. Should be easy, just three rules ;) I'd definitely choose Python to do it here. In that sense, Scheme also appears to be the Brainfuck of functional programming to me. It is not much more than the pure untyped lambda calculus, and by definition this allows you to compute anything, just like Brainfuck is a Turing machine. Actually it is impressive that you can write actual useful code with such a minimalist language (infix math? Pure bloat!). OTOH it feels like "assembly" compared to more evolved functional languages like, e.g. Haskell. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: New Python implementation
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 (in contrast to PL/I's many 'bells and whistles'). 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, anything that's built into the interpreter if you leave out any standard function, is enormous. To name a few: List comprehension, format strings, iterator protocol, asynchronous programming, everything called __dunderland. A minimal language with only very few basic rules, that would be Scheme e.g. Of course, it doesn't mean that Scheme is easier to program, but it is easier to write a compiler for it than for Python. That is a misundestanding often presented - a language that is simple in the sense of having a few simple rules, is usually hard to use. (e.g. Brainfuck). A language which is easy to use, often comes with a large variety of building blocks, to give you the right tool to choose for the job at hands (e.g. Python), and therefore is "complex". Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: New Python implementation
Am 15.02.21 um 21:37 schrieb Roel Schroeven: So your claim is that your compiler is able to, or will be able to, compile any language just by specifying a small schema file. Great! Do you maybe have a proof-of-concept? A simple language with a simple schema file to test the basic workings of your compiler, Here is the git repo: https://github.com/i42output/neos under languages/ you'll find different schema files. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: New Python implementation
Am 14.02.21 um 11:12 schrieb Paul Rubin: Christian Gollwitzer writes: He wants that neoGFX is scriptable in Python, but instead of linking with CPython, he will write his own Python implementation instead, because CPython is slow/not clean/ whatever. He doesn't seem to understand that this is an enormous task on its own, because the interesting part of a scripting language is the standard library with many decade-years of work. I wonder how big an issue the stdlib really is. Lots of it is written in Python and can port to another interpreter. Lots more is CPython C API bindings to external C libraries (e.g. OpenSSL) so porting those would be a matter of rebinding those libraries to libffi in the cases where that hasn't been done already. I'm not saying that it is unfeasible or very difficult. I'm saying that it is a lot of work, and for a single developer who has this as a side project / support for his graphics engine and who wants to beat existing implementations wrt. speed, I'm saying it is going to take a lot of time. It'definitely impossible by "defining a few JSON schema files", as Leigh claims with his "universal compiler". There definitely IS a lot of stuff in a baseline CPython interpreter - a (seemingly) simple thing like "print" will have an implementation of 1000 lines in C with all the formatting library, file I/O etc. Arbitrary precision integers - another library, networking - yet another and so on. CPython really is pretty slow, maybe because it uses so much boxed data, derps around with refcounts all the time, suffers memory fragmentation from not having a relocating GC, etc. And that is before we even mention the GIL. I don't argue with that. CPython is slow. But I'm arguing that you can't make it faster by multiple orders of magnitude unless you change the language. For numerical code, straight-forward C is usually 100x to 1000x faster than Python, and you can reach the same performance by giving up dynamic typing - Cython demonstrates this quite convincingly. If you don't want static typing (with types close to the machine like fixed-width integers) than you'll have to resort to a LOT of black magic to even come close (PyPy, modern JS engines, ) Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: New Python implementation
Am 14.02.21 um 01:19 schrieb Chris Angelico: On Sun, Feb 14, 2021 at 11:14 AM Mr Flibble wrote: On 13/02/2021 23:30, Igor Korot wrote: Hi, But most importantly - what is the reason for this ? I mean - what problems the actual python compiler produce? Thank you. I am creating neos as I need a performant scripting engine for my other major project "neoGFX" and I want to be able to support multiple popular scripting languages including Python. Until you have actually produced a (mostly) compatible Python implementation, can you please stop making these repeated and baseless jabs at CPython's performance? You keep stating or hinting that CPython is somehow unnecessarily slow, but unless you have some code to back your claims, this is nothing but mudslinging. This is a message to all commentators on this list: Mr Flibble is known on comp.lang.c++ for making very confident claims and announcements of the greatest software product since the invention of the wheel. He is indeed a capable C++ programmer, but he frequently underestimates the work needed for such big projects so that you can easily count them as vaporware for now. For example, he created his own "cross-platform, modern" GUI toolkit neoGFX[*] just because he thinks that QT is bad (it uses non-standard C++). Of course, cross-platform for now means it runs on Windows and anything else is far into the future, also the optical design looks modern / OK right now, but will look outdated soon. There is no evidence that any other designer will join the project to keep the look up to date. He wants that neoGFX is scriptable in Python, but instead of linking with CPython, he will write his own Python implementation instead, because CPython is slow/not clean/ whatever. He doesn't seem to understand that this is an enormous task on its own, because the interesting part of a scripting language is the standard library with many decade-years of work. So my advice is to waste your time in this discussion if you find it entertaining, but don't expect to have a usable product soon. Best regards, Christian [*] https://github.com/i42output/neoGFX -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert MBOX thunderbird to PST outlook
Am 08.02.21 um 11:08 schrieb J.O. Aho: On 08/02/2021 10.22, Paul Rubin wrote: "J.O. Aho" writes: I think most migrated to use IMAP like 30 years ago That handles email but not calendar or the other stuff. I think there are starting to be standards for that, but no idea whether either Thunderbird or Outlook follows them. Yes, that is true that the IMAP don't handle the calendar, for those you need caldav/webcal and then maybe carddav for address books too and I do think those are well supported in Thunderbird, the question is more what the web based Outlook handles, For thatm you can run radicale: https://radicale.org/3.0.html A Python-based calendar server. Then upload your calendars there from Thunderbird and download them from Outlook. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: idlelib re-use
Am 28.01.21 um 20:57 schrieb Terry Reedy: On 1/28/2021 5:53 AM, Robin Becker wrote: I googled in vain for instances where parts of idlelib are re-used in a simplistic way. I would like to use the editor functionality in a tkinter window and also probably run code in a subprocess. Are there any examples around that do these sorts of things? turtledemo reuses IDLE's colorizer and read-only textviews. I have seen occasional hints on stackoverflow of other such uses. One barrier to reuse is that the parts are highly interconnected, with numerous import loops. (Changing the form of some imports from 'import x' to 'from x import y' can make IDLE startup fail.) Some objects, like EditorWindow, are too monolithic. You cannot put a toplevel inside another toplevel. Yes, you can. There are two possiblities, the one is converting the toplevel into a frame with wm_forget(), after which you can simply pack it into another frame. The second one is configuring a frame as a container, which allows to even embed a window from a foreign application. I'm not sure this works on all platforms, though. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: A beginning beginner's question about input, output and . . .
Am 13.01.21 um 06:24 schrieb Greg Ewing: On 13/01/21 4:18 am, Grant Edwards wrote: AFAIK, Python can't be used to write device drivers for any popular OS At least not until some crazy person embeds Python in the Linux kernel... What do you mean, "until" ? https://medium.com/@yon.goldschmidt/running-python-in-the-linux-kernel-7cbcbd44503c http://www.kplugs.org/ Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: dayofyear is not great when going into a new year
Am 05.01.21 um 23:56 schrieb Eli the Bearded: Elijah -- also finds "week starts on Monday" to be oddball about ISO-8601 In Europe, the week starts on Monday - hence, Saturday and Sunday are the last days of the week or the "weekend". Starting on Sunday is weird for us, because then the weekend is split into the first and last day of the week (?) - even if, historically, the week was the time from Sunday to Sunday. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: tkinter: creating/attaching menubar to top level window
Am 08.01.21 um 22:47 schrieb Rich Shepard: I'm using Chapter 9 in Mark Roseman's "Modern Tkinter for Busy Python Developers" to learn how to write a top level menu. MWE code is attached. Python3 tells me there's invalid syntax on line 42: self.['menu'] = menubar # attach it to the top level window ^ yet that's the syntax he prints on page 84 (and has in the book's code supplement). It is a simple typo, remove the dot. self['menu'] = menubar It will then stop at the add_cascade, fix it like this: menubar.add_cascade(menu=self.menu_file, label='File') and then it works, Why am I getting an invalid syntax error here? Because the dot would indicate the access of an attribute. but no name follows. What it does here, instead, is indexing - the correct line is similar to setting a dict entry. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Class and tkinter problem
Am 07.01.21 um 08:29 schrieb Paulo da Silva: Does anybody know why cmd method isn't called when I change the button state (clicking on it) in this example? I know that this seems a weird class use. But why doesn't it work? Thanks. class C: from tkinter import Checkbutton import tkinter @staticmethod ^^it works if you remove the staticmethod here def cmd(): print("Test") Maybe there is a bug in tkinter, that it doesn't work with static methods? Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: I'm finally disentangled from Python 2, thank you everyone
Am 30.12.20 um 11:58 schrieb Chris Green: Could I ask you to write up a post on what you did here? I've never used cx-freeze but it sounds like a useful thing for keeping legacy stuff functioning. A writeup from someone who's actually used it for that would be welcome. Of course, here is what I wrote in my 'self help' Dokuwiki wiki about it. It refers specifically to the OKI software I wanted to keep using but it should be fairly easy to apply a similar process to other software. I asked on the Python newsgroup and the one suggestion that seemed feasible was to package the OKI software with all its dependencies on a system which still has Gtk2 and Python 2 and then install the whole package on esprimo. After a bit of looking around at Snap, Appimage and such I found cx_freeze which is aimed specifically at Python. The latest version doesn't support Python 2 but 5.1.1 does, so this is how I've have done it * Install xubuntu 18.04 on my old Revo system (has to be 64-bit), 18.04 is still in support. (has to be 64-bit simply because the final target is 64-bit) * Install cx_freeze 5.1.1 on Revo * Install the Oki software on Revo, check that it works, pulls in lots of libraries and packages. * Run 'cxfreeze /usr/libexec/okimfputl/scantool.py' (scantool.py is the utility I want to run on systems without Python 2) * Copy the resulting 'dist' directory to the target system, name isn't critical Then the fun starts. There's quite a few more libraries and packages are required and the scan daemon needs to be runnable. (The scan daemon was, fortunately, just a compiled program so ran 'as is' without issues) Files needed in /usr/libexec/okimfputl and /usr/libexec/okimfpdrv " There are a lot of hard coded references to /usr/libexec/okimfputl and /usr/libexec/okimfpdrv, it **might** be possible to change all these but I decided it would be less painful to use a couple of symbolic links to locations in /usr/local/libexec and put the required files in /usr/local/libexec/okimfputl and /usr/local/libexec/okimfpdrv. I discovered what files are needed in these directories by simply running scantool on the target and fixing each error as it arose. Other Python package and library files " I have installed the "dist" created by cxfreeze in /usr/local/libexec/okicxfreeze. The executable to run is thus /usr/local/libexec/okicxfreeze/scantool. There are also a few .so libraries and Python packages needed, as above I just found these by running scantool and fixing each error as it appeared. The system library files are put in /usr/local/lib, you have to run ldconfig after each file is put there. The Python packages (including the dreaded pyscand.so) have to be put in the working directory when scantool is run, so I have put them in /usr/local/libexec/okicxfreeze where the scantool executable is. I hope the above is useful. As I said it refers specifically to the scantool.py that I needed for my Oki scanner but I think the description is general enough to be useful. The basic process is:- Find (or create) a system where the software you want to run works OK. Install cx-freeze 5.1.1 on that system and run 'cxfreeze ' Check that the executable created by cxfreeze works on the system you built it on Copy the executable (and its 'dist' environment) to the target where you want to run it Try and run it on the target Iteratively work through the errors it throws up when you run it, in my case these were:- Missing .so system library files, copy them from the build system to somewhere they will be found on the target. You could put them in a 'private to the package' directory and set LD_LIBRARY_PATH or do as I did and put them in a standard library location (and run ldconfig after adding each). I've used pyinstaller in the past, and it seems to do a better job with that. It usually copies all the sytem libraries, too, but would fail with /usr/libexec/okimfputl & friends Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Function returns old value
Am 17.12.20 um 21:22 schrieb Michael F. Stemper: On 17/12/2020 03.57, Peter J. Holzer wrote: On 2020-12-17 03:06:32 -, Bischoop wrote: pasting from my IDE to vim/slrn was messing syntax, You can :set paste in vim to prevent it from messing with pasted content (don't forget to set nopaste afterwards). What's the difference between that and :set ai and :set noai With newer vims that's rarely necessary though since they can distinguish between input that was pasted and input that was typed. I thought that I was going nuts when I encountered that. Any idea how to defeat such a so-called 'feature"? Use "gvim" instead of "vim" in a Terminal. The problems arises because vim in the terminal simply gets the input and "thinks" that you typed that stuff in, for which it does auto-indenting. gvim, OTOH, doe sthe pasting by itself. It also has other useful features like menus and popup-dialogs for searching etc. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: linear algebric equations
Am 07.12.20 um 17:59 schrieb Tito Sanò: Regarding the solution of linear algebraic equations I noticed a big difference in the computation time in Python compared to the old fortran language. I have compared both the linelg and lapack.dgesv-lapack.zgesv modules with the fortan: dgelg and f04adf. The difference in computation time is enormous: for example for 430 degrees of freedom it is about 24 min in Python versus about 1 sec in fortran. There must be something seriously wrong. If I understand correctly, you want to solve an 430x430 matrix with LU decompositino (that is what dgesv from LAPACK does). The following code takes less than a second on my machine: ==430.py== import numpy as np # create a 430x430 random matrix A = np.random.randn(430,430) # right hand side b = np.ones(430) # solve it x = np.linalg.solve(A, b) print(x) time python3 430.py real0m0.318s user0m0.292s sys 0m0.046s If it takes longer than 1s, there is something wrong with your system. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: how to plot the FFT of a list of values
Am 05.12.20 um 18:16 schrieb Boris Dorestand: I have 16 values of the period sequence 1, 2, 4, 8, 1, 2, 4, 8, ... I compute its fourier transform using from scipy import fft, ifft x = [1,2,4,8,1,2,4,8] fft(x) array([ 30. +0.j, 0. +0.j, -6.+12.j, 0. +0.j, -10. +0.j, 0. +0.j, -6.-12.j, 0. +0.j]) Now how can I plot these values? I would like to plot 16 values. What do I need to do here? Can you show an example? Usually, for the FFT of real input data, you plot only the magnitude or square of the complex array, and usually on a logscale. So: import pylab import numpy as np fx = fft(x) pylab.semilogy(np.abs(fx)) pylab.show() Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Why can't numpy array be restored to saved value?
Am 25.11.20 um 07:47 schrieb pjfarl...@earthlink.net: Why isn't the final value of the numpy array npary in the following code the same as the initial value before some but not all elements of the array were changed to a new value? I know I am missing something basic here. I thought I understood the concepts of immutable vs mutable values but obviously I missed something. My environment is Win10-64, Python 3.8.5, numpy 1.19.2. Code and output follows. TIA for any help you can provide to cure my ignorance. Peter --- nptest.py --- import numpy as np import sys if len(sys.argv) > 0: try: asz = int(sys.argv[1]) + 0 except: asz = 4 npary = np.full([asz, asz, asz], 0, dtype=np.int32) print("Array before change=\n{}".format(npary)) svary = npary[:, :, :] Because this does not copy the array, rather it creates a view into the original array. This is an optimization to avoid copying. If you want a copy, do svary = npary.copy() Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange terminal behavior after quitting Tkinter application
Am 03.11.20 um 23:34 schrieb Dennis Lee Bieber: Out of curiosity, does Python on Linux honor the .pyw extension? On Windows, .pyw indicates a Python program that implements a GUI and will NOT make use of console (stdin/stdout/stderr). On Linux, there is no such distinction. On Windows it is only needed because, if you connect stdin/out, a terminal window pops up. >For a true GUI program that is notr acceptable, the user will be puzzled what this ugly useless window wants to do, and therefore a flag in the EXE file format indicates to Windows if it should pop up the console or not. On Linux, stdin/out is always connected. You must run your program from a terminal window to see it, otherwise it is silently connected to some channel in the background by the desktop environment. It can happen that the standard channels are closed, if you run a program in the terminal and then close the terminal (which sends SIGHUP to the program). In this case the program might later on throw I/O errors, when printing to stdout. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI (tkinter) popularity and job prospects for
Am 22.10.20 um 23:52 schrieb Paul Rubin: Michael Torrie writes: I doubt you'll find any jobs connected a particular Python GUI toolkit. It would be really nice if there was a way to straightforwardly run Tkinter applications on Android. You'd install a single .apk and that would let you run your Tkinter apps and make launchers for them. It's not unrealistic - there is AndroWish to run Tcl/Tk on Android including GUI and connection to Android specific services (subcommand "borg"). Someone in the Python community would need to make the Tkinter bridge with a native Python for Android. https://www.androwish.org/home/home Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Covariance matrix syntax
Am 19.10.20 um 07:23 schrieb Meghna Karkera: I am unable to find the *formula for covariance* used in np.cov syntax in PYTHON given in link https://numpy.org/doc/stable/reference/generated/numpy.cov.html. Could you please help me out. As said, you should click on the link [source] just at the right hand side of the page, at the top. There is numpy.cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None, aweights=None) and just next to it there is the link. It takes you there: https://github.com/numpy/numpy/blob/v1.19.0/numpy/lib/function_base.py#L2270-L2481 Which is the source code of the function. Best regards, Christian Thanks Meghna On Tue, Oct 13, 2020 at 11:46 AM Christian Gollwitzer wrote: Am 13.10.20 um 06:52 schrieb Meghna Karkera: Could you let me know what is the back end calculation of this covariance matrix syntax np.cov You can look it up yourself: Go to the docs https://numpy.org/doc/stable/reference/generated/numpy.cov.html At the right hand side, just right of the function signature, there is a link [source]. Click there and it takes you to the implementation. Apparently it is done in straightforward Python. Christian PS: Snipped a lot of unrelated citation at the bottom On Tue, Oct 13, 2020, 10:14 Bruno P. Kinoshita < brunodepau...@yahoo.com.br> wrote: [...] I think the np.cov is from the numpy module (imported/aliased as np?). -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Covariance matrix syntax
Am 13.10.20 um 06:52 schrieb Meghna Karkera: Could you let me know what is the back end calculation of this covariance matrix syntax np.cov You can look it up yourself: Go to the docs https://numpy.org/doc/stable/reference/generated/numpy.cov.html At the right hand side, just right of the function signature, there is a link [source]. Click there and it takes you to the implementation. Apparently it is done in straightforward Python. Christian PS: Snipped a lot of unrelated citation at the bottom On Tue, Oct 13, 2020, 10:14 Bruno P. Kinoshita wrote: [...] I think the np.cov is from the numpy module (imported/aliased as np?). -- https://mail.python.org/mailman/listinfo/python-list
Re: ValueError: arrays must all be same length
Am 02.10.20 um 14:34 schrieb Shaozhong SHI: Hello, I got a json response from an API and tried to use pandas to put data into a dataframe. However, I kept getting this ValueError: arrays must all be same length. Can anyone help? The following is the json text. What do you expect the dataframe to look like? dataframes are 2D tables, JSON is a tree. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Interference tkinter and plot from matplotlib
Am 30.09.20 um 15:46 schrieb Pierre Bonville: Hi everybody, Interference tkinter and plot from matplotlib You are mixing different ways of control flow. In a GUI program, don't call input(). Use the mainloop() as the very last of your calls, and only work in the callbacks. That means you would integrate a "Next" button in your GUI which switches the plots - or even show them side by side. Concerning matplotlib, you'll need to tell it to integrate with Tk properly. https://matplotlib.org/3.3.1/gallery/user_interfaces/embedding_in_tk_sgskip.html If you want a simple solution instead of full-blown GUI programming, use IPython https://ipython.readthedocs.io/en/stable/config/eventloops.html or jupyter notebooks. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop
Am 28.09.20 um 07:38 schrieb Stephane Tougard: On 2020-09-28, MRAB wrote: It's used where the language requires a statement. In, say, C, you would use empty braces: while (process_next_item()) { /* Do nothing. */ } If I want to express nothing in C, I put nothing and it works fine. #include int main(int argc, char * argv[]) { if(1 == 1) ; No. You put ";", that's not nothing. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop
Am 26.09.20 um 06:43 schrieb Stephane Tougard: ===PYTHON=== #!/usr/local/bin/python if 4 == 4: name = "Stephane" print(name) pass print("Out {}".format(name)) The exact same code in Python works fine, the variable name is used outside of the if block even it has been declared inside. This does not look right to me. I'll try another way of explaining it. You seem to be confused that the scope of the variable assignment[*] continues after the if. However, look at this: def f(): a=3 f() a NameError Traceback (most recent call last) in () > 1 a NameError: name 'a' is not defined So the "def f()" obviously introduces local scope, but control structures like if and while do not. Christian [*] In Python it's called "name binding", but it mostly works like variable assignment -- https://mail.python.org/mailman/listinfo/python-list
Re: Video file to subtitles file
Am 30.08.20 um 21:43 schrieb MRAB: On 2020-08-30 18:10, Christian Gollwitzer wrote: Well, with enough effort it is possible to build a system that is more useful than "entertaining". Google did that, English youtube videos can be annotated with subtitles from speech recognition. For example, try this video: https://www.youtube.com/watch?v=lYVLpC_8SQE There's not much background noise there; it takes place in a quiet room. It becomes a bit worse once the background music sets in, but still is usable. Feel free to try any other video. I think, it works with any video in English. I think that for "Hollywood"-style movies you will always have a crisp sound of the speech. They want the viewers to listen effortlessly - background music is typical, "true" noise is rare. Maybe try with this video: https://www.youtube.com/watch?v=nHn4XpKA6vM As soon as they are up in the air you have the engine sound overlaying the speech, and still the transcription is quite good. It sometimes mistakes the flapping of the engine as "applause" and misses a word or a sentence, but still very good. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Video file to subtitles file
Am 30.08.20 um 17:25 schrieb MRAB: On 2020-08-30 07:23, Muskan Sanghai wrote: On Sunday, August 30, 2020 at 11:46:15 AM UTC+5:30, Chris Angelico wrote: I recommend looking into CMU Sphinx then. I've used that from Python. The results are highly entertaining. ChrisA Okay I will try it, thank you. Speech recognition works best when there's a single voice, speaking clearly, with little or no background noise. Movies tend not to be like that. Which is why the results are "highly entertaining"... Well, with enough effort it is possible to build a system that is more useful than "entertaining". Google did that, English youtube videos can be annotated with subtitles from speech recognition. For example, try this video: https://www.youtube.com/watch?v=lYVLpC_8SQE Go to the settings thing (the little gear icon in the nav bar) and switch on subtitles, English autogenerated. You'll see a word-by-word transcription of the text, and most of it is accurate. There are strong arguments that anything one can build with open source tools will be inferior. 1) They'll probably have a bunch of highly qualified KI experts working on this thing 2) They have an enormous corpus of training data. Many videos already have user-provided subtitles. They can feed all of this into the training. I'm waiting to be disproven on this point ;) Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Video file to subtitles file
Am 29.08.20 um 13:51 schrieb Muskan Sanghai: I want to extract subtitles from a MPEG video (which does not have any previous subtitles) I'm still not sure I get it. "Extract" subtitles, when they are NOT there? Can it be, by any chance, that you are talking about speech recognition? I.e., you want a software which understands the spoken word in the movie sound and turns that into text, which can be shown as subtitles? Like the "auto-generated" subtitles which youtube offers for some videos. If so, it is a complex task and will not work overly well. I defer to the experts if there are any usable speech recognitino engines for this task. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax?
Am 06.08.20 um 17:13 schrieb Christian Seberino: Python is my favorite language and the easiest to use in my opinion. Lisp has a far simpler grammar and syntax. A beginner I think could learn Lisp much faster than Python. Therefore, it seems like Lisp *should* be easier to work with and more readable. I don't feel like it is easier to use but I can't see *why* that is. My best guess. Lisp pros: simpler syntax Lisp cons: prefix notation, lots more parentheses My hypothesis is that the cons slightly outweigh the pros of Lisp which is why Python is easier to work with and is more readable in the end? I concur with Chris Angelico there. The word "simple" is ambiguous. "Simpler" for the human is not the same as "simpler" for the computer In Lisp, the grammar is "simpler", meaining that the definition of the grammar is shorter; this makes it simpler for the compiler to parse, and to write a compiler for Lisp. In Python, the grammar is very complicated, writing a compiler for Python is a big task - still it is "simpler" to translate your ideas into Python It is related to the old saying "if all you have is hammer, then everything looks like a nail". In Lisp, your hammer is the list. So you are forced to map your problems onto list processing. For some things that works well, for others not so well (infix math) . In, say, Java, your tool is classes and inheritance. There are big books on "design patterns" that teach you how to map your problem onto inheritance. For some things, that works well, for others not so well ("abstract factory", "visitor pattern", ) In Python, you have an awfully complex of syntax, so your toolset includes list processing, lambda, inheritance, string interpolation, decorators This makes it possible to use the tool which best matches the language of your problem. Many problem domains have their own language, e.g. matrix math for linear algebra, pipes for sequential stream processing etc. The easier it is to translate the algorithm on paper into the runnable version, the Lisp is still impressive, because it is very good at metaprogramming. It shows how far you can get with so little syntax. Another point to consider is the ecosystem of your language. If you install Python, then you get basic math, I/O, a GUI toolkit, network libraries, ... In more "traditional" languages like C or Lisp, you get math and I/O, period. For everything else you need to hunt down a library. Therefore, solve the task "download the gimp installer from github via https" requires 2,3 lines in Python and installing a (possibly complex) library for the same task in Lisp or C. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: How to diagnose import error when importing from .so file?
Am 29.07.20 um 23:01 schrieb Chris Green: Even more annoying is that most of what's in pyscand.so is constants, there's only a couple of functions in there, so there's very little to it really. If there are really only constants, you could import it into Python 2 and dump the content e.g. as a JSON file to read it in under Python 3. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Installing Python 3.8.3 with tkinter
Am 23.07.20 um 06:30 schrieb Klaus Jantzen: On 7/22/20 11:05 PM, Ned Deily wrote: On 2020-07-22 06:20, Klaus Jantzen wrote: Trying to install Python 3.8.3 with tkinter I run configure with the following options ./configure --enable-optimizations --with-ssl-default-suites=openssl --with-openssl=/usr/local --enable-loadable-sqlite-extensions --with-pydebug --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib/tcl8.6' --with-tcltk-includes='-I/opt/ActiveTcl-8.6/include' Running Python gives the following information [...] How do that correctly? Try --with-tcltk-libs='-L/opt/ActiveTcl-8.6/lib -ltcl8.6 -ltk8.6' Thank you for your suggestion; unfortunately it did not help. Does the configure process output something when checking for Tcl/Tk? Does it say "no"? THen you can analyse the config.log file what happened. In order to compile Tk extensions, you need X11 development headers. Maybe that is one problem. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Pycharm Won't Do Long Underscore
Am 23.06.20 um 22:49 schrieb Tony Kaloki: Alexander, Thank you so much! It worked! Thank you. One question: in your reply, are you saying that Python would have treated the two separate underscores the same way as a long underscore i.e. it's a stylistic choice rather than a functional necessity? Python only ever sees two separate underscores. There is no long underscore, its only the way it is printed to your screen that differs. The difference is the same as if you would choose Arial, Times, or Courier to print your source code. The characters look slightly different to your eye, but they are exactly the same for Python. The .py file doesn't have a difference, regardless how you set the font. As others have said, the underscore of some fonts is so long that they overlap, if you put more than on in a row. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: SaveAs on macOS Catalina.
Am 09.05.20 um 04:37 schrieb Bev In TX: On May 8, 2020, at 8:29 PM, Terry Reedy wrote: https://bugs.python.org/issue40553 On macOS The default Save/Save as dialogs are short, only displaying a few major folders along with Favorites and Recents. That dialog doesn’t display folder contents. However, you can get an expanded dialog by clicking on the little arrow to the right of the Where box. Using that dialog allows one to select any folder and displays folder contents. I tried using both Save and Save as, and was unable to duplicate the problem with either the short or the long dialog. Python 3.8.2 macOS Catalina 10.15.4 Can it be a problem with the underlying Tk version? If so, it would be helpful to isolate the Tk call and convert it to an equivalent Tcl script for the core developers to test. Fairly recently, Tk has got many bugfixes because of changes in OSX. Here is the file that implements the file dialogs: https://core.tcl-lang.org/tk/artifact/d72cdfbcbfaa717f and the history: https://core.tcl-lang.org/tk/finfo?name=macosx/tkMacOSXDialog.c=d72cdfbcbfaa717f As you can see, it has been touched two days ago (!) to restore some window behaviour, which was switched of because of Catalina last August (this commit) https://core.tcl-lang.org/tk/info/59b1d265c2444112 Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Function to avoid a global variable
Am 28.04.20 um 09:54 schrieb ast: funny ! So we found 4 different ways to handle a memory in a function 1- Use a function parameter with a mutable default value 2- Use a function attribute 3- Use a callable object, and store your stuff inside an object attr 4- Use a closure to emulate a static function variable Any more ? 5- Use a global variable, of course That's definitely the least recommendable solution. Global variable names pollute the global namespace, therefore they don't make sense to just store state within one function. They should be reserved to the case where multiple functions access a common state. Usually it is best to restrict the scope of a variable to the region of code where it necessarily needs to be available. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: print small DataFrame to STDOUT and read it back into dataframe
Am 06.04.20 um 17:17 schrieb Luca: On 4/6/2020 4:08 AM, Reto wrote: Does this help? Thank you, but not really. What I am trying to achieve is to have a way to copy and paste small yet complete dataframes (which may be the result of previous calculations) between a document (TXT, Word, GoogleDoc) and Jupiter/IPython. Did I make sense? CSV is the most sensible option here. It is widely supported by spreadsheets etc. and easily copy/pasteable. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Adding tkinter modules to notebook tabs
Am 04.04.20 um 22:31 schrieb Rich Shepard: On Sat, 4 Apr 2020, Christian Gollwitzer wrote: I'm not sure I fully understand it, because a "module" is not defined in the language of tkinter. Christian, True, but it is in Python: a file ending in .py which, in this case, contains a class of tkinter widgets. Is it correct, you want to know how to place more than one widget - a arrangement of widgets - onto a notebook tab? Yes, as they are defined and laid out in separate files/modules. This is achieved by a ttk.Frame() widget, which holds all the other stuff, and then you place the frame onto the notebook: n=ttk.Notebook() f1=ttk.Frame() # put all your stuff into f1 n.add(f1, text="Module1") # repeat for your other "modules" This looks to me like it's adding the text, "Module1" to the tab. Yes and no. It puts the empty frame in the notebook and labels it with "Module1" so that when you click the label, the frame is raised. Of course, not very interesting, because the frame is empty. Here: nb = ttk.Notebook(Main) ... page3 = ttk.Frame(nb) ... # add titles to tabs nb.add(page3, text='Biota') ... This puts the text on each notebook tab, correct? It adds an empty frame, as above. If so, how do I add class BiotaDataForm(Tk.Frame): which defines all the widgets in the module in views/biota.py into the body of the notebook's page3? Add that thing instead of the frame. blabla=BioDataForm() # whatever args it needs, maybe parent=nb nb.add(blabla, text="Biodata") Christian PS: I suggest to change all Tk widgets to ttk widgets for optical reasons, but that's a side note. -- https://mail.python.org/mailman/listinfo/python-list
Re: Adding tkinter modules to notebook tabs
Am 04.04.20 um 16:59 schrieb Rich Shepard: My Python3-3.8.2 application has 8 modules with subject-specific data entry/editing widgets and I want to display each module on a ttk.Notebook. Each notebook resource I've found in my reference books and on the web describe how to create a notebook and tabs and add labels to the tabs; a few describe how to place individual widgets on a tab. But I've not found how to place a widget-filled module on a notebook tab. I'm not sure I fully understand it, because a "module" is not defined in the language of tkinter. Is it correct, you want to know how to place more than one widget - a arrangement of widgets - onto a notebook tab? This is achieved by a ttk.Frame() widget, which holds all the other stuff, and then you place the frame onto the notebook: n=ttk.Notebook() f1=ttk.Frame() # put all your stuff into f1 n.add(f1, text="Module1") # repeat for your other "modules" Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Identifying tkinter version [ANSWERED]
Am 01.04.20 um 19:22 schrieb Rich Shepard: On Wed, 1 Apr 2020, Tony van der Hoff wrote: How do I determine the installed version? import tkinter tkinter.TkVersion 8.6 Thanks, Tony. I was close, but still too far away. This only shows you the major version. There have been many updates to Tcl/Tk in "minor" releases, including lots of rework on Tk internals. Therefore, you need the patchlevel. YOu can get this by root.eval('info patchlevel') Apfelkiste:Test chris$ python3 Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter >>> root=tkinter.Tk() >>> root.eval('info patchlevel') '8.5.9' >>> (urks, I'll have to upgrade. 8.5.9 on OSX is seriously broken) Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Converting program from shell to tkinter
Hi Randall, I assume you are asking about the Python programming language (tkinter??). This group discusses the Tcl programming language, from which Tk originates. See 2 answers below. Xpost and Fup2 c.l.p Christian Am 22.03.20 um 00:59 schrieb Randall Wert: I am trying to enhance a shell program -- you know, the kind that communicates with the user through simple lines of text, using print() and input() statements -- by adding a tkinter interface. I have successfully completed three projects using tkinter in the past, but this one is proving more difficult. The essence of the problem is, I want the program to still have the same control flow as in the "shell" program. It should issue messages to the user and receive their input. But tkinter seems to be purely designed for event-driven programs (responding to button clicks, for example). To be more specific: It is a hangman game. The user enters different types of input as the program runs (choice of difficulty level, letters (guesses), Y/N for playing another game, etc.). I would like to be able to use a single user entry field for all of those purposes, and accept input from it when the user presses Enter, instead of having a different button for each type of user input. I hope I am explaining it clearly. I would appreciate any tips on converting to a tkinter interface while maintaining the same program flow. You must convert the program into a state machine. Luckily, both Tcl and Python can help you with this, in the form of a coroutine. For Tcl, take a look to this page https://wiki.tcl-lang.org/page/Coroutines+for+event-based+programming For Python, look up generators and google "asyncio tkinter". Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter: which ttk widget for database table primary key?
Am 18.03.20 um 21:39 schrieb Rich Shepard: Subject might be confusing so I'll expand it here. My application uses a database backend in which each table has a unique and database-generated sequential numeric key. I want to display that key in the GUI for that class but it's not entered by the user or altered. It seems to me that the ttk.Entry and ttk.Spinbox widgets are inappropriate. As a newcomer to Tkinter I ask for advice on which widget to use. You can use an Entry and set it to readonly state. Or you can use a Label. The advantage of the readonly Entry is, that the user can still copy/paste the content, and that it can scroll if the string is very long. Christian -- https://mail.python.org/mailman/listinfo/python-list