From dncarachiola at gmail.com Mon Jun 1 00:06:17 2020 From: dncarachiola at gmail.com (Dennis Carachiola) Date: Sun, 31 May 2020 21:06:17 -0700 (PDT) Subject: why no camelCase in PEP 8? In-Reply-To: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> Message-ID: <97c6935d-ce01-4589-adca-b842589f04d6@googlegroups.com> >From PEP8-- "The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Python code. As PEP 20 says, "Readability counts". A style guide is about consistency. Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is the most important. However, know when to be inconsistent -- sometimes style guide recommendations just aren't applicable. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask! In particular: do not break backwards compatibility just to comply with this PEP!" From dncarachiola at gmail.com Mon Jun 1 00:14:52 2020 From: dncarachiola at gmail.com (Dennis Carachiola) Date: Sun, 31 May 2020 21:14:52 -0700 (PDT) Subject: OT: ALGOL 60 at 60 In-Reply-To: References: Message-ID: Ah, but I have used it. Admittedly it was during a programming languages survey course at RPI in 1971-3. From rosuav at gmail.com Mon Jun 1 01:03:18 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Jun 2020 15:03:18 +1000 Subject: Spotify Playlist In-Reply-To: References: <6ef738dc-c0fc-49d0-8545-c3fe4f3ec5d6@googlegroups.com> Message-ID: On Mon, Jun 1, 2020 at 2:55 PM Terry Reedy wrote: > > On 5/31/2020 7:10 PM, Chris Angelico wrote: > > Automation would be a bit harder, as you'd have to periodically query > > the API for each playlist's description, and then update them. > > https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/ > > > > The reason this would be harder is that you'd risk running up against > > the rate limits: > > https://developer.spotify.com/documentation/web-api/#rate-limiting > > Their recommendation is to query infomation about multiple items at > once, as their API allows. I suspect that one can also add or update > multiple items at once. I'm not sure, but that doesn't even matter. The question is more about how frequently you can query to see if it's been wiped. But that might be irrelevant, depending on exactly how high the rate limits are - I didn't check. (If you're allowed, say, 1500 calls per day, then you could poll every minute and still be fine.) But I only did a very cursory examination. A feasibility test, the results of which are that I'd be confident putting this project in the hands of a competent novice programmer. ChrisA From giansofficial at gmail.com Mon Jun 1 03:55:07 2020 From: giansofficial at gmail.com (giansofficial at gmail.com) Date: Mon, 1 Jun 2020 00:55:07 -0700 (PDT) Subject: Spotify Playlist In-Reply-To: References: <6ef738dc-c0fc-49d0-8545-c3fe4f3ec5d6@googlegroups.com> Message-ID: <1d47ac14-af97-477c-a141-8782e93f49d1@googlegroups.com> Il giorno luned? 1 giugno 2020 07:03:45 UTC+2, Chris Angelico ha scritto: > On Mon, Jun 1, 2020 at 2:55 PM Terry Reedy wrote: > > > > On 5/31/2020 7:10 PM, Chris Angelico wrote: > > > Automation would be a bit harder, as you'd have to periodically query > > > the API for each playlist's description, and then update them. > > > https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/ > > > > > > The reason this would be harder is that you'd risk running up against > > > the rate limits: > > > https://developer.spotify.com/documentation/web-api/#rate-limiting > > > > Their recommendation is to query infomation about multiple items at > > once, as their API allows. I suspect that one can also add or update > > multiple items at once. > > I'm not sure, but that doesn't even matter. The question is more about > how frequently you can query to see if it's been wiped. But that might > be irrelevant, depending on exactly how high the rate limits are - I > didn't check. (If you're allowed, say, 1500 calls per day, then you > could poll every minute and still be fine.) > > But I only did a very cursory examination. A feasibility test, the > results of which are that I'd be confident putting this project in the > hands of a competent novice programmer. > > ChrisA I received other 6 reports tonight, i'm desperate, don't know what to do. Please guys, can you help me? PLEASE. Do you know someone who can code something like this? PLEASE. From rhodri at kynesim.co.uk Mon Jun 1 05:59:38 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 1 Jun 2020 10:59:38 +0100 Subject: Binary Sort on Python List __xor__ In-Reply-To: References: <0c2a145b-bd6c-4bd1-9eba-655a168312ae@googlegroups.com> Message-ID: <9a6a345c-05ff-4659-ed20-c5c49d453230@kynesim.co.uk> On 31/05/2020 18:01, Evan Schalton wrote: > I think you're arguing both sides of the argument -- numpy arrays do > have a lot of similar, related operations (because numpy uses them > internally -- since they're more efficient) which means they're not > fringe. > > I'm advocating that the built-in list class add the efficient, > convenience methods -- especially since it wouldn't be overriding > other methods, it would be leveraging standard methods that are > currently unimplemented > Those methods make perfect sense in the bit-twiddling lists that you are using. They make no sense whatsoever for lists like ["The", "quick", "brown", "fox"]. There's a decent purpose for a class implementing the features you want, but I honestly don't think the generic list class is it. -- Rhodri James *-* Kynesim Ltd From tavn1992 at gmail.com Mon Jun 1 04:20:12 2020 From: tavn1992 at gmail.com (Trent N) Date: Mon, 1 Jun 2020 01:20:12 -0700 Subject: Spotify Playlist In-Reply-To: <1d47ac14-af97-477c-a141-8782e93f49d1@googlegroups.com> References: <6ef738dc-c0fc-49d0-8545-c3fe4f3ec5d6@googlegroups.com> <1d47ac14-af97-477c-a141-8782e93f49d1@googlegroups.com> Message-ID: I could probably do this for you. Just need to know how many playlists it would need to be to decide how hard it would be. I have some experience with this type of stuff. Also if they are able to file so many reports so fast. I worry that any program to try and combat this would be rate limited pretty fast,, and not able to keep up with the report. It would just have to be looked into. Please email me privately and we can discuss. On Mon, Jun 1, 2020 at 1:02 AM wrote: > > Il giorno luned? 1 giugno 2020 07:03:45 UTC+2, Chris Angelico ha scritto: > > On Mon, Jun 1, 2020 at 2:55 PM Terry Reedy wrote: > > > > > > On 5/31/2020 7:10 PM, Chris Angelico wrote: > > > > Automation would be a bit harder, as you'd have to periodically query > > > > the API for each playlist's description, and then update them. > > > > https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/ > > > > > > > > The reason this would be harder is that you'd risk running up against > > > > the rate limits: > > > > https://developer.spotify.com/documentation/web-api/#rate-limiting > > > > > > Their recommendation is to query infomation about multiple items at > > > once, as their API allows. I suspect that one can also add or update > > > multiple items at once. > > > > I'm not sure, but that doesn't even matter. The question is more about > > how frequently you can query to see if it's been wiped. But that might > > be irrelevant, depending on exactly how high the rate limits are - I > > didn't check. (If you're allowed, say, 1500 calls per day, then you > > could poll every minute and still be fine.) > > > > But I only did a very cursory examination. A feasibility test, the > > results of which are that I'd be confident putting this project in the > > hands of a competent novice programmer. > > > > ChrisA > > I received other 6 reports tonight, i'm desperate, don't know what to do. > > Please guys, can you help me? PLEASE. Do you know someone who can code something like this? PLEASE. > -- > https://mail.python.org/mailman/listinfo/python-list From jjenne025 at go.tahomasd.us Mon Jun 1 13:31:34 2020 From: jjenne025 at go.tahomasd.us (Joseph Jenne) Date: Mon, 1 Jun 2020 10:31:34 -0700 Subject: [RELEASE] Python 3.9.0b1 is now available for testing In-Reply-To: References: Message-ID: <064f836d-3d60-2c1d-668c-9bc4378dc90d@go.tahomasd.us> > > I used https://github.com/python/pyperformance pyperformance to > compare Arch linux latest > >> Python 3.8.3 (default, May 17 2020, 18:15:42) [GCC 10.1.0] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> > > against a vanilla build (configure make makeinstall) of python 3.9b1 > >> Python 3.9.0b1 (default, May 19 2020, 21:09:14) [GCC 10.1.0] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> > > I find all the bench marks seem to be slower in python 3.9b1. > >> 38.json >> ======= >> >> Performance version: 1.0.1 >> Report on Linux-5.6.14-arch1-1-x86_64-with-glibc2.2.5 >> Number of logical CPUs: 4 >> Start date: 2020-05-31 04:00:24.503704 >> End date: 2020-05-31 04:22:44.961331 >> >> 39.json >> ======= >> >> Performance version: 1.0.1 >> Report on Linux-5.6.14-arch1-1-x86_64-with-glibc2.31 >> Number of logical CPUs: 4 >> Start date: 2020-05-31 04:23:21.247268 >> End date: 2020-05-31 04:49:09.891889 >> >> ### 2to3 ### >> Mean +- std dev: 437 ms +- 5 ms -> 548 ms +- 7 ms: 1.25x slower >> Significant (t=-96.22) >> >> ### chameleon ### >> Mean +- std dev: 12.5 ms +- 0.1 ms -> 16.2 ms +- 0.2 ms: 1.30x slower >> Significant (t=-111.53) > > ....... > > Is this because I haven't built in the same way as Arch or are there > real slowdowns in this beta? Or even dumber have I got the results the > wrong way round? > -- > Robin Becker Most builds of python included with distribution packages are built with various levels of optimization. I have experienced slowdowns from source built python of the same version as the distribution python even when using some optimization flags with the configure script. This appears to be normal behavior and is not cause for concern about the performance of python 3.9.0b1 -- Joseph Jenne From jimandkimparinisi at yahoo.com Mon Jun 1 16:54:45 2020 From: jimandkimparinisi at yahoo.com (Jim Parinisi) Date: Mon, 1 Jun 2020 20:54:45 +0000 (UTC) Subject: Trouble with version 3.8 In-Reply-To: <543511102.742822.1591044506846@mail.yahoo.com> References: <543511102.742822.1591044506846.ref@mail.yahoo.com> <543511102.742822.1591044506846@mail.yahoo.com> Message-ID: <1860277305.750923.1591044885800@mail.yahoo.com> I had been using python 3.6 on two computers with windows 7 and windows 10.? We bought a windows 10 machine and I installed python 3.8 on it.? Many of my python apps failed with an error similar to this: ?File "C:\Python38\lib\os.py", line 818, in fsdecode? ? filename = fspath(filename)? # Does type-checking of `filename`.TypeError: expected str, bytes or os.PathLike object, not list I looked online and could not find any solutions to my problem.? So, I uninstalled v3.8 and installed v3.6. Version 3.6 worked. Any advice on how to fix version 3.8 would be appreciated. From python at mrabarnett.plus.com Mon Jun 1 18:53:06 2020 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 1 Jun 2020 23:53:06 +0100 Subject: Trouble with version 3.8 In-Reply-To: <1860277305.750923.1591044885800@mail.yahoo.com> References: <543511102.742822.1591044506846.ref@mail.yahoo.com> <543511102.742822.1591044506846@mail.yahoo.com> <1860277305.750923.1591044885800@mail.yahoo.com> Message-ID: <60f39d8c-c322-f9a2-92d1-57c54a024286@mrabarnett.plus.com> On 2020-06-01 21:54, Jim Parinisi via Python-list wrote: > > I had been using python 3.6 on two computers with windows 7 and windows 10.? We bought a windows 10 machine and I installed python 3.8 on it.? Many of my python apps failed with an error similar to this: > ?File "C:\Python38\lib\os.py", line 818, in fsdecode? ? filename = fspath(filename)? # Does type-checking of `filename`.TypeError: expected str, bytes or os.PathLike object, not list > I looked online and could not find any solutions to my problem.? So, I uninstalled v3.8 and installed v3.6. Version 3.6 worked. > Any advice on how to fix version 3.8 would be appreciated. > "an error similar to this"? Please post the actual traceback. It would also help if you looked at the traceback for where your code calls the function from the stdlib and then added some debugging, such as to a log file, to see what you're passing to the function. From what you've provided above, it would appear to be a list, which appears to be the problem. Where does that list come from? From tjreedy at udel.edu Tue Jun 2 00:04:19 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 2 Jun 2020 00:04:19 -0400 Subject: Trouble with version 3.8 In-Reply-To: <1860277305.750923.1591044885800@mail.yahoo.com> References: <543511102.742822.1591044506846.ref@mail.yahoo.com> <543511102.742822.1591044506846@mail.yahoo.com> <1860277305.750923.1591044885800@mail.yahoo.com> Message-ID: On 6/1/2020 4:54 PM, Jim Parinisi via Python-list wrote: > > I had been using python 3.6 on two computers with windows 7 and windows 10.? We bought a windows 10 machine and I installed python 3.8 on it.? Many of my python apps failed with an error similar to this > ?File "C:\Python38\lib\os.py", line 818, in fsdecode? ? filename = fspath(filename)? # Does type-checking of `filename`.TypeError: expected str, bytes or os.PathLike object, not list When posting tracebacks, *copy* and paste the full traceback *with hard returns* so lines are not joined together as above. With them inserted, the above is: File "C:\Python38\lib\os.py", line 818, in fsdecode filename = fspath(filename) # Does type-checking of `filename`. TypeError: expected str, bytes or os.PathLike object, not list fsdecode is being passed a list as a filename. Look at the full traceback to see if that comes from you or something internal. > Any advice on how to fix version 3.8 would be appreciated. Don't assume that 3.8 is the problem and in need of a fix. Maybe your code depends on a bug in 3.6 fixed in the 3.8 you installed. fsdecode itself is the same in 3.6 and 3.8. On Windows, fspath is supplied by the C-coded nt module. You could search the change logs in What's New 3.7 and 3.8 for mention of fspath. -- Terry Jan Reedy From tjreedy at udel.edu Tue Jun 2 00:06:33 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 2 Jun 2020 00:06:33 -0400 Subject: Trouble with version 3.8 In-Reply-To: <1860277305.750923.1591044885800@mail.yahoo.com> References: <543511102.742822.1591044506846.ref@mail.yahoo.com> <543511102.742822.1591044506846@mail.yahoo.com> <1860277305.750923.1591044885800@mail.yahoo.com> Message-ID: On 6/1/2020 4:54 PM, Jim Parinisi via Python-list wrote: > So, I uninstalled v3.8 and installed v3.6. You can have both installed on Windows. Without 3.8, you cannot follow any suggestions about things to try with 3.8 ;-). -- Terry Jan Reedy From keller at no.invalid Wed Jun 3 08:57:19 2020 From: keller at no.invalid (Steve Keller) Date: Wed, 3 Jun 2020 14:57:19 +0200 Subject: Animated functions with matplotlib Message-ID: I am trying to plot a live signal using matplotlib and it really drives me crazy. I have tried dozens of variants, with and without interactive (plt.ion()), with animation.FuncAnimation and doing things by hand, calling plt.show() and/or plt.draw() but nothing works as expected. One problem is that running commands in the interactive python shell behaves differently from the behavior when using the same commands in a script, so trying out different versions is very confusing. I'd like to do something like this: fig, ax = plt.subplots() ival = .1 now = 0 t = list(numpy.linspace(now, now, 500)) y = [0] * len(t) while True: time.sleep(ival) now += ival val = get_sample_from_some_signal() t = t[1:] + [now] y = y[1:] + [val] ax.clear() ax.plot(t, y) plt.pause(1e-9) This works but is *very* slow and it seems the plot window is closed and opened again or raised for each new value to plot. I have tried to call plt.show(block=False) only once and then repeatedly only change data with ax.lines[0].set_xdata(), ax.lines[0].set_ydata(), and ax.set_xlim() and then calling plt.draw(). That works in the interactive python shell but not in a script. When calling set[xy]_data() and set_xlim() in an amimate() function passed to animation.FuncAnimation, but I haven't managed to redraw the x scale values (although ax.xlim() is called). Also, with animation.FuncAnimation() I loose control of the main thread of execution. When calling plt.show() the function doesn't return. I may want to change the loop so that instead of time.sleep(ival) val = get_sample_from_some_signal() I would have val = wait_for_next_same_from_some_signal() and I think this doesn't work with FuncAnimation since that calls the passed function with a fixed time interval. I am completely lost, can someone help? Steve From python-list at mlists.thewrittenword.com Tue Jun 2 13:26:16 2020 From: python-list at mlists.thewrittenword.com (Albert Chin) Date: Tue, 2 Jun 2020 12:26:16 -0500 Subject: Division issue with 3.8.2 on AIX 7.1 Message-ID: <20200602172615.GA27264@thewrittenword.com> I've built Python 3.8.2 on AIX 5.2, 5.3, 6.1, and 7.1. I am seeing different results for the following Python program: $ python3 -c "eps = 2.0 ** -53.0; tiny = 2.0 ** -1022.0; \ print ((1.0 - eps) / tiny * 4.0)" I get the correct result, 1.7976931348623157e+308, on AIX 5.2, 5.3, and 6.1. But, on 7.1, I get "inf". Anyone know where can I look in the Python source code to investigate this? -- albert chin (china at thewrittenword.com) From aaron.christensen at gmail.com Tue Jun 2 13:47:34 2020 From: aaron.christensen at gmail.com (Aaron) Date: Tue, 2 Jun 2020 13:47:34 -0400 Subject: From an existing Pandas DataFrame, how can I create a summary DataFrame based on the union of overlapping date ranges (given a start and an end date) and an additional column? Message-ID: Hello, Given a dateframe with trips made by employees of different companies, I am trying to generate a new dataframe with only the company names. I am looking to combine the overlapping travel times from employees of the SAME company into a single row. If there are no overlapping travel times, then that row just transfers over as-is. When there are overlapping travel times, then the following will happen: --The name field is removed b/c that is no longer relevant (company name stays), the Depart date will be the earliest date of any of the trip dates regardless of the employee, the Return date will be the latest date of any of the trip dates regardless of the employee, the charges for the trip will be summed For example, if trips had dates 01/01/20 - 01/31/20, 01/15/20 - 02/15/20, 02/01-20 - 02/28/20, then all three would be combined. The starting date will be 1/1/20 and ending as of 2/28/20. Basically, the company was on that trip from start to finish? kinda like a relay run handing off the baton. Also, the charges will be summed for each of those trips and transferred over to the single row. Here is the starting dataframe code/output (note: the row order is typically not already sorted by company name as in this example): import pandas as pd emp_trips = {'Name': ['Bob','Joe','Sue','Jack', 'Henry', 'Frank', 'Lee', 'Jack'], 'Company': ['ABC', 'ABC', 'ABC', 'HIJ', 'HIJ', 'DEF', 'DEF', 'DEF'], 'Depart' : ['01/01/2020', '01/01/2020', '01/06/2020', '01/01/2020', '05/01/2020', '01/13/2020', '01/12/2020', '01/14/2020'], 'Return' : ['01/31/2020', '02/15/2020', '02/20/2020', '03/01/2020', '05/05/2020', '01/15/2020', '01/30/2020', '02/02/2020'], 'Charges': [10.10, 20.25, 30.32, 40.00, 50.01, 60.32, 70.99, 80.87] } df = pd.DataFrame(emp_trips, columns = ['Name', 'Company', 'Depart', 'Return', 'Charges']) # Convert to date format df['Return']= pd.to_datetime(df['Return']) df['Depart']= pd.to_datetime(df['Depart']) Name Company Depart Return Charges0 Bob ABC 2020-01-01 2020-01-31 10.101 Joe ABC 2020-01-01 2020-02-15 20.252 Sue ABC 2020-01-06 2020-02-20 30.323 Jack HIJ 2020-01-01 2020-03-01 40.004 Henry HIJ 2020-05-01 2020-05-05 50.015 Frank DEF 2020-01-13 2020-01-15 60.326 Lee DEF 2020-01-12 2020-01-30 70.997 Jack DEF 2020-01-14 2020-02-02 80.87 And, here is the desired/generated dataframe: Company Depart Return Charges0 ABC 01/01/2020 02/20/2020 60.671 HIJ 01/01/2020 03/01/2020 40.002 HIJ 05/01/2020 05/05/2020 50.013 DEF 01/12/2020 02/02/2020 212.18 I have been trying to use a combination of sorting and grouping but the best I've achieved is reordering the dataframe. Even though I am able to sort/group based on values, I still run into the issues of finding overlapping date ranges and pulling out all trips based on a single company per aggregate/overlapping date range. Thank you in advance for any help! Aaron From miki.tebeka at gmail.com Wed Jun 3 23:44:47 2020 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Wed, 3 Jun 2020 20:44:47 -0700 (PDT) Subject: Division issue with 3.8.2 on AIX 7.1 In-Reply-To: References: <20200602172615.GA27264@thewrittenword.com> Message-ID: <6d68a6c4-9fac-4768-9697-03bd769abaeb@googlegroups.com> > Anyone know where can I look in the Python source code to investigate > this? Probably around https://github.com/python/cpython/blob/master/Objects/floatobject.c From pythonfm at gmail.com Wed Jun 3 23:48:20 2020 From: pythonfm at gmail.com (pythonfm at gmail.com) Date: Wed, 3 Jun 2020 20:48:20 -0700 (PDT) Subject: Trouble with making modules 'global' Message-ID: <76a5b723-1cc2-46b6-b6d8-0c3a665f024f@googlegroups.com> Hi, I am struggling with making modules global for all definitions in my code. I faced the problem with the pyomo modules but can generate the error with pandas too. The model structure looks as follow: I have 3 '.py' files each of them containing definitions. The first controls inputs and outputs and starts an optimization.py file ( optimization.py). Within optimization.py I call a third .py file (model.py) that includes a series of definitions, representing mathematical equations of a optimization model. (1) Main.py import pandas as pd def main_part() ... Result = optimization_def(x,y,z) ... (2) Optimization.py def optimization(x_l,y_l,z_l) ... O = obejctive(x_l,y_l) ... (3) Model.py def objctive(x_a,x_b) ... def constraint(x_a,z_a) .... I do not understand why pd is not known in def optimization() as well as in objctive(). I tried to make it global by adding global pd in Main.py I would appreciate any support. Thanks in advance Frank From python-list at mlists.thewrittenword.com Thu Jun 4 00:28:12 2020 From: python-list at mlists.thewrittenword.com (Albert Chin) Date: Wed, 3 Jun 2020 23:28:12 -0500 Subject: Division issue with 3.8.2 on AIX 7.1 In-Reply-To: <6d68a6c4-9fac-4768-9697-03bd769abaeb@googlegroups.com> <1tegdf9trvqrk2eltfhc1jf3oap5te4sbp@4ax.com> Message-ID: <20200604042812.GD27264@thewrittenword.com> On Wed, Jun 03, 2020 at 08:11:17PM -0400, Dennis Lee Bieber wrote: > On Tue, 2 Jun 2020 12:26:16 -0500, Albert Chin > declaimed the following: > > >I've built Python 3.8.2 on AIX 5.2, 5.3, 6.1, and 7.1. I am seeing > >different results for the following Python program: > > $ python3 -c "eps = 2.0 ** -53.0; tiny = 2.0 ** -1022.0; \ > >print ((1.0 - eps) / tiny * 4.0)" > > > >I get the correct result, 1.7976931348623157e+308, on AIX 5.2, 5.3, > >and 6.1. But, on 7.1, I get "inf". > > > >Anyone know where can I look in the Python source code to investigate > >this? > > Have you considered that it might be something in an underlying C > library (especially for the double-precision exponentiation)? On Wed, Jun 03, 2020 at 08:44:47PM -0700, Miki Tebeka wrote: > > Anyone know where can I look in the Python source code to investigate > > this? > > Probably around > https://github.com/python/cpython/blob/master/Objects/floatobject.c Thanks to both of you. I applied some updated OS patches and the problem went away. -- albert chin (china at thewrittenword.com) From pythonfm at gmail.com Thu Jun 4 00:31:31 2020 From: pythonfm at gmail.com (pythonfm at gmail.com) Date: Wed, 3 Jun 2020 21:31:31 -0700 (PDT) Subject: Trouble with making modules 'global' In-Reply-To: <76a5b723-1cc2-46b6-b6d8-0c3a665f024f@googlegroups.com> References: <76a5b723-1cc2-46b6-b6d8-0c3a665f024f@googlegroups.com> Message-ID: <1e5f6c4d-df11-4ea4-a456-40cc78e160a1@googlegroups.com> I just realized that the problem is related to python 3.8 and not to 3.7. Am Donnerstag, 4. Juni 2020 05:48:31 UTC+2 schrieb pyth... at gmail.com: > Hi, > > I am struggling with making modules global for all definitions in my code. > I faced the problem with the pyomo modules but can generate the error with pandas too. > > The model structure looks as follow: > > I have 3 '.py' files each of them containing definitions. The first controls inputs and outputs and starts an optimization.py file ( optimization.py). Within optimization.py I call a third .py file (model.py) that includes a series of definitions, representing mathematical equations of a optimization model. > > > > (1) Main.py > import pandas as pd > > def main_part() > ... Result = optimization_def(x,y,z) > ... > > (2) Optimization.py > def optimization(x_l,y_l,z_l) > ... O = obejctive(x_l,y_l) > ... > > (3) Model.py > def objctive(x_a,x_b) > ... > def constraint(x_a,z_a) > .... > > > I do not understand why pd is not known in def optimization() as well as in objctive(). > I tried to make it global by adding global pd in Main.py > > > I would appreciate any support. Thanks in advance > Frank From hudsonkelley05 at gmail.com Wed Jun 3 22:22:38 2020 From: hudsonkelley05 at gmail.com (Kelley Hudson) Date: Wed, 3 Jun 2020 21:22:38 -0500 Subject: Issues with Python Message-ID: <09A8637C-7D15-4FC0-A499-E7BC6CC60600@hxcore.ol> Keep getting an error when trying to us Python with Pycharm. I uninstalled it but this was the error I received. ? Sent from [1]Mail for Windows 10 ? References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From swest at mcssk12.org Thu Jun 4 00:37:03 2020 From: swest at mcssk12.org (Sherry L. West) Date: Wed, 3 Jun 2020 23:37:03 -0500 Subject: Division issue with 3.8.2 on AIX 7.1 In-Reply-To: <20200604042812.GD27264@thewrittenword.com> References: <6d68a6c4-9fac-4768-9697-03bd769abaeb@googlegroups.com> <1tegdf9trvqrk2eltfhc1jf3oap5te4sbp@4ax.com> <20200604042812.GD27264@thewrittenword.com> Message-ID: I need off this list please. I don?t even have this. On Wed, Jun 3, 2020 at 11:30 PM Albert Chin < python-list at mlists.thewrittenword.com> wrote: > On Wed, Jun 03, 2020 at 08:11:17PM -0400, Dennis Lee Bieber wrote: > > On Tue, 2 Jun 2020 12:26:16 -0500, Albert Chin > > declaimed the following: > > > > >I've built Python 3.8.2 on AIX 5.2, 5.3, 6.1, and 7.1. I am seeing > > >different results for the following Python program: > > > $ python3 -c "eps = 2.0 ** -53.0; tiny = 2.0 ** -1022.0; \ > > >print ((1.0 - eps) / tiny * 4.0)" > > > > > >I get the correct result, 1.7976931348623157e+308, on AIX 5.2, 5.3, > > >and 6.1. But, on 7.1, I get "inf". > > > > > >Anyone know where can I look in the Python source code to investigate > > >this? > > > > Have you considered that it might be something in an underlying C > > library (especially for the double-precision exponentiation)? > > On Wed, Jun 03, 2020 at 08:44:47PM -0700, Miki Tebeka wrote: > > > Anyone know where can I look in the Python source code to investigate > > > this? > > > > Probably around > > https://github.com/python/cpython/blob/master/Objects/floatobject.c > > Thanks to both of you. I applied some updated OS patches and the > problem went away. > > -- > albert chin (china at thewrittenword.com) > -- > https://mail.python.org/mailman/listinfo/python-list > -- Mrs. Sherry West Owens Cross Roads Elementary From meetsai2004 at gmail.com Thu Jun 4 00:59:35 2020 From: meetsai2004 at gmail.com (Meet Agrawal) Date: Thu, 4 Jun 2020 10:29:35 +0530 Subject: Unsubscribe to python list Message-ID: I want to unsubscribe from python list and would like to stop recieving mails from the same. From PythonList at DancesWithMice.info Thu Jun 4 01:12:19 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 4 Jun 2020 17:12:19 +1200 Subject: Unsubscribe to python list In-Reply-To: References: Message-ID: <8e4916e6-4029-1353-ba0e-90583f52a18f@DancesWithMice.info> On 4/06/20 4:59 PM, Meet Agrawal wrote: > I want to unsubscribe from python list and would like to stop recieving > mails from the same. At the bottom of your request (as reflected), this, and all over messages to the list is an administration link. At the foot of that web-page you will find a space to unsubscribe your email address (admittedly, I've not tried it). -- Regards =dn From PythonList at DancesWithMice.info Thu Jun 4 01:19:13 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 4 Jun 2020 17:19:13 +1200 Subject: Issues with Python In-Reply-To: <09A8637C-7D15-4FC0-A499-E7BC6CC60600@hxcore.ol> References: <09A8637C-7D15-4FC0-A499-E7BC6CC60600@hxcore.ol> Message-ID: <63a4fe47-eb0e-767a-0d3c-cd04f2384e0b@DancesWithMice.info> On 4/06/20 2:22 PM, Kelley Hudson wrote: > Keep getting an error when trying to us Python with Pycharm. I uninstalled > it but this was the error I received. > > > > Sent from [1]Mail for Windows 10 > > > > References > > Visible links > 1. https://go.microsoft.com/fwlink/?LinkId=550986 Many folk are security-conscious and will not click on links provided by unknown people (apologies for sounding unfriendly). Recommend you copy-paste the exact message into an email (also request a descriptive Subject: which will help anyone with a similar problem to search the archives). Also, it may help to know the OpSys (assuming MS-Windows), the version of Python, and that of the Pycharm IDE... Meantime, the Pycharm folk have invested considerable time and effort in their on-line manual. Is there an answer there about how to link particular (versions) Python interpreters to the current project? -- Regards =dn From __peter__ at web.de Thu Jun 4 04:28:16 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 04 Jun 2020 10:28:16 +0200 Subject: Trouble with making modules 'global' References: <76a5b723-1cc2-46b6-b6d8-0c3a665f024f@googlegroups.com> Message-ID: pythonfm at gmail.com wrote: > Hi, > > I am struggling with making modules global for all definitions in my code. Don't. Global names in Python are global to a single module, not your entire application. > I faced the problem with the pyomo modules but can generate the error with > pandas too. > > The model structure looks as follow: > > I have 3 '.py' files each of them containing definitions. The first > controls inputs and outputs and starts an optimization.py file ( > optimization.py). Within optimization.py I call a third .py file > (model.py) that includes a series of definitions, representing > mathematical equations of a optimization model. > > > > (1) Main.py > import pandas as pd If you want to use Optimization in Main.py you have to import the module just like you did with pandas. > > def main_part() > ... Result = optimization_def(x,y,z) > ... > > (2) Optimization.py If you want to use pandas in Optimization.py you have to import it. Note that only the first time a module is imported in an application the import may take a noticeable time. Subsequent imports result in a lookup in the sys.modules cache. > def optimization(x_l,y_l,z_l) > ... O = obejctive(x_l,y_l) > ... > > (3) Model.py > def objctive(x_a,x_b) > ... > def constraint(x_a,z_a) > .... > > > I do not understand why pd is not known in def optimization() as well as > in objctive(). I tried to make it global by adding global pd in Main.py > > > I would appreciate any support. Thanks in advance > Frank From barry at barrys-emacs.org Thu Jun 4 04:14:01 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 4 Jun 2020 09:14:01 +0100 Subject: Trouble with making modules 'global' In-Reply-To: <76a5b723-1cc2-46b6-b6d8-0c3a665f024f@googlegroups.com> References: <76a5b723-1cc2-46b6-b6d8-0c3a665f024f@googlegroups.com> Message-ID: > On 4 Jun 2020, at 04:48, pythonfm at gmail.com wrote: > > Hi, > > I am struggling with making modules global for all definitions in my code. Each python module has to import all the modules it needs. Importing on one module does not make the imported names usable from another module. What python does do is only run the code of an imported module once. The seconds module to do an import will find that its already imported and just setup the names to be usable. > I faced the problem with the pyomo modules but can generate the error with pandas too. > > The model structure looks as follow: > > I have 3 '.py' files each of them containing definitions. The first controls inputs and outputs and starts an optimization.py file ( optimization.py). Within optimization.py I call a third .py file (model.py) that includes a series of definitions, representing mathematical equations of a optimization model. > > > > (1) Main.py > import pandas as pd > > def main_part() > ... Result = optimization_def(x,y,z) > ... > > (2) Optimization.py You also need to import pandas in each module that uses it. > def optimization(x_l,y_l,z_l) > ... O = obejctive(x_l,y_l) > ... > > (3) Model.py And here. > def objctive(x_a,x_b) > ... > def constraint(x_a,z_a) > .... > > > I do not understand why pd is not known in def optimization() as well as in objctive(). > I tried to make it global by adding global pd in Main.py > > > I would appreciate any support. Thanks in advance > Frank Barry > -- > https://mail.python.org/mailman/listinfo/python-list > From o1bigtenor at gmail.com Thu Jun 4 08:09:08 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Thu, 4 Jun 2020 07:09:08 -0500 Subject: Unsubscribe to python list In-Reply-To: <8e4916e6-4029-1353-ba0e-90583f52a18f@DancesWithMice.info> References: <8e4916e6-4029-1353-ba0e-90583f52a18f@DancesWithMice.info> Message-ID: On Thu, Jun 4, 2020 at 12:14 AM DL Neil via Python-list wrote: > > On 4/06/20 4:59 PM, Meet Agrawal wrote: > > I want to unsubscribe from python list and would like to stop recieving > > mails from the same. > > > At the bottom of your request (as reflected), this, and all over > messages to the list is an administration link. At the foot of that > web-page you will find a space to unsubscribe your email address > (admittedly, I've not tried it). > -- Not that I have any wish to but wanting to 'know' I did check. The very last lines are where you enter your email address with the idea (didn't try that but ISTR) that you would get an automated response which would detail your options for account changes, which would include removing one's subscription. HTH From tjreedy at udel.edu Thu Jun 4 04:18:31 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 4 Jun 2020 04:18:31 -0400 Subject: Trouble with making modules 'global' In-Reply-To: <76a5b723-1cc2-46b6-b6d8-0c3a665f024f@googlegroups.com> References: <76a5b723-1cc2-46b6-b6d8-0c3a665f024f@googlegroups.com> Message-ID: On 6/3/2020 11:48 PM, pythonfm at gmail.com wrote: > I am struggling with making modules global for all definitions in my code. You cannot. You must import every module either directly or indirectly into every module that uses it. > I faced the problem with the pyomo modules but can generate the error with pandas too. > > The model structure looks as follow: > > I have 3 '.py' files each of them containing definitions. The first controls inputs and outputs and starts an optimization.py file ( optimization.py). Within optimization.py I call a third .py file (model.py) that includes a series of definitions, representing mathematical equations of a optimization model. > > > > (1) Main.py The PEP8 standard is all lower case for modules, leaving TitleCase for classes, so, for instance, file/module 'editor' contains the definition of class 'Editor' as its main class. > import pandas as pd Do you use 'pd' in Main? If not, delete. > def main_part() > ... Result = optimization_def(x,y,z) > ... > > (2) Optimization.py To use pd here, import it here. > def optimization(x_l,y_l,z_l) > ... O = obejctive(x_l,y_l) > ... > > (3) Model.py Ditto. > def objctive(x_a,x_b) > ... > def constraint(x_a,z_a) > .... > > > I do not understand why pd is not known in def optimization() as well as in objctive(). Because of missing imports. > I tried to make it global by adding global pd in Main.py Where it is likely irrelevant. -- Terry Jan Reedy From tjreedy at udel.edu Thu Jun 4 04:22:53 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 4 Jun 2020 04:22:53 -0400 Subject: Division issue with 3.8.2 on AIX 7.1 In-Reply-To: <1tegdf9trvqrk2eltfhc1jf3oap5te4sbp@4ax.com> References: <20200602172615.GA27264@thewrittenword.com> <1tegdf9trvqrk2eltfhc1jf3oap5te4sbp@4ax.com> Message-ID: On 6/3/2020 8:11 PM, Dennis Lee Bieber wrote: > On Tue, 2 Jun 2020 12:26:16 -0500, Albert Chin > declaimed the following: > >> I've built Python 3.8.2 on AIX 5.2, 5.3, 6.1, and 7.1. I am seeing >> different results for the following Python program: >> $ python3 -c "eps = 2.0 ** -53.0; tiny = 2.0 ** -1022.0; \ >> print ((1.0 - eps) / tiny * 4.0)" >> >> I get the correct result, 1.7976931348623157e+308, on AIX 5.2, 5.3, >> and 6.1. But, on 7.1, I get "inf". Execute "print(1.0-eps, tiny)" and see if they differ. >> Anyone know where can I look in the Python source code to investigate >> this? > > Have you considered that it might be something in an underlying C > library (especially for the double-precision exponentiation)? This is a more likely source of the change than our code. -- Terry Jan Reedy From filipbascarevic at gmail.com Thu Jun 4 04:47:29 2020 From: filipbascarevic at gmail.com (Filip Bascarevic) Date: Thu, 4 Jun 2020 10:47:29 +0200 Subject: Fwd: How can I build embeddable zip python on Linux In-Reply-To: References: Message-ID: Dear Python team, I have tried to build the GDB with Python support for windows. Because I didn?t want to have any Python dependence on building system, I decided to embed python in GDB using Windows x86_64 embeddable zip file and with it I had success. When I tried to build GDB with Python support on Linux, I realized I couldn?t find embeddable python for Linux. I have tried to find some article how can I build embeddable Python from source in Linux and only what I have found is this: https://stackoverflow.com/questions/42280553/how-to-build-embeddable-python but again it is only for Windows. Please, can you give me some instructions how can I build embeddable Python from source in Linux? Is it possible in the Linux environment? Please let me know if I can assist any further. With best regards, M.Eng. Filip Bascarevic From torriem at gmail.com Thu Jun 4 09:40:34 2020 From: torriem at gmail.com (Michael Torrie) Date: Thu, 4 Jun 2020 07:40:34 -0600 Subject: Division issue with 3.8.2 on AIX 7.1 In-Reply-To: References: <6d68a6c4-9fac-4768-9697-03bd769abaeb@googlegroups.com> <1tegdf9trvqrk2eltfhc1jf3oap5te4sbp@4ax.com> <20200604042812.GD27264@thewrittenword.com> Message-ID: <807670e6-3453-5adf-0af5-0b500e3c4801@gmail.com> On 6/3/20 10:37 PM, Sherry L. West wrote: > I need off this list please. I don?t even have this. Unsubscribe here: https://mail.python.org/mailman/listinfo/python-list From mats at python.org Thu Jun 4 11:55:11 2020 From: mats at python.org (Mats Wichmann) Date: Thu, 4 Jun 2020 09:55:11 -0600 Subject: Python with text editor In-Reply-To: References: Message-ID: On 5/30/20 1:42 AM, Preetha M wrote: > Hello. Thank you for responding to my previous mail. Can someone tell me > how to connect python to sublime text 3. Whenever I select python and type > the code, it does not work when I press ctrl+B. Please tell. > Try Corey Schaefer's video on setup: (search on youtube for "Setting up a Python Development Environment in Sublime Text" if you don't want to follow an obfuscated link in email, which is probably a good idea!) https://www.youtube.com/watch?v=xFciV6Ew5r4 From PythonList at DancesWithMice.info Thu Jun 4 20:15:27 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Fri, 5 Jun 2020 12:15:27 +1200 Subject: Friday Finking: Imports, Namespaces, Poisoning, Readability Message-ID: <6aa1aba8-2715-f410-0087-d4fca95bfd1e@etelligence.info> How do you prefer to balance all of the above when import-ing? Python offers a number of options for importing modules, eg import module, ... from importable import object, ... most of which can be augmented with the "as preferred_name" syntax. (ignoring the much-reviled "*" (import everything, not private) variation) The basic application of the as-clause, is a means of avoiding conflict within the namespace. Thus, if the name "vector" is already used within the module, we can: from importable import vector as direction ... go( direction ) Another common use is abbreviation - despite modern editors offering look-ahead guesses and superceding the typing-saver it once was; eg: import numpy as np from importable import vector as v The "np" is not as good an example (for this discussion) because it is very commonly-used and therefore well-understood (at least amongst the Stats and DataSc communities). However, the "v" suffers the same fate as abbreviated object-names everywhere - after a while, one starts to forget exactly what the opaque name actually means. In between the intense COVID-19 busy-ness, I have been attempting a contEd course (and perversely choosing to use Python instead of their chosen language) and thus am 'discovering' (PSL's) pygame library. Accordingly: import pygame as pg So, after employing that, every time I encountered the abbreviation I had to stop and think: 'what is this "pg" thing?'. Agreed, that's part of the "learning process" - and in-time, even my sluggish grey-matter managed to reach the point of readability (but can I assume the same of my reader/colleagues/course-tutor?). However, as I started building helper functions and my own objects 'around' the pygame library, without much thought, I followed the pattern: import pygame as pg # this is from PSL import pygame_utilities as pgu # this is from my own work ... if pgu.has_alpha( ink_color_tuple ): ... It didn't take long before I was being stopped, to think: "where did "pgu" come-from?" (remember, being a good, little, boy*, all of my import statements are parked way-up at the top of the code-listing). The opposite approach - specifically avoiding abbreviations and the readability issues they may carry, and bravely facing the challenge of avoiding name-clashes, might involve something like: from pygame_plane_geometry import ( CartesianError, GeometricNtuple, CartesianCoordinate, Vector, Polygon, ... ) ... position = CartesianCoordinate( 1, 2 ) Now, we will enjoy much-improved readability - but will have to rely upon the IDE's 'pop-up', to see an object's init/signature (for example). Thus, we face an extra concern of 'where do I find this module?' to be able to clarify or examine any detail. The final 'crunch' then - to enjoy full readability AND avoid naming conflict AND offer full source-location information: import pygame_plane_geometry ... position = pygame_plane_geometry.CartesianCoordinate( 1, 2 ) Lovely stuff! Except that we're either 'banging on the door' of column-79, or our eyes are tiring from 'all that reading'. Maybe? Finking/discussion: - how do you like to balance these three (and any other criteria)? - is your preference (or selection) influenced by the facilities offered by your favorite editor/IDE? - does your decision differ according to whether the 'target module' is one of yours, from the PSL, from some third party, corporate, ...? - do you prefer PSL's importlib over Python's native import-s, for one of these (or any other) reason? - AOB? WebRefs: https://docs.python.org/3/tutorial/modules.html https://docs.python.org/3/reference/import.html * if you believe that, I have a bridge from Brooklyn available at an absolute bargain price... (https://nycwalks.com/blog/the-brooklyn-bridge-if-you-believe-that-i-have-a-bridge-in-brooklyn-to-sell-to-you/) -- Regards, =dn From python.list at tim.thechases.com Thu Jun 4 21:02:13 2020 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 4 Jun 2020 20:02:13 -0500 Subject: Friday Finking: Imports, Namespaces, Poisoning, Readability In-Reply-To: <6aa1aba8-2715-f410-0087-d4fca95bfd1e@etelligence.info> References: <6aa1aba8-2715-f410-0087-d4fca95bfd1e@etelligence.info> Message-ID: <20200604200213.4e819536@bigbox.attlocal.net> On 2020-06-05 12:15, DL Neil via Python-list wrote: > Finking/discussion: > > - how do you like to balance these three (and any other criteria)? For most of what I do, I only ever have one such module so I'm not trying keep multiple short-names in my head concurrently. For me, it's usually tkinter which I import as either "tk" or just "t". It's usually cases where the whole content would dump a lot of junk in my module's namespace (like tkinter or pygame), so I like to keep the namespacing; but I also don't want to clutter my code with long references to it. > - is your preference (or selection) influenced by the facilities > offered by your favorite editor/IDE? Not really. I'm a vi/vim/ed guy. While vim has some nice "go to the definition of the thing under the cursor" (gd/gD/tags/etc), regardless of my $EDITOR, it's not overly taxing to see "tk.thing" and if I had any question about it, jump to the top of the file where all the import-statements are, and see that tkinter is being imported as tk. It's there explicitly, unlike those abominable "from tkinter import *" tutorials. > - does your decision differ according to whether the 'target > module' is one of yours, from the PSL, from some third party, > corporate, ...? I've not given it much thought, but I tend to use the above method with PSL/3rd-party libraries where there's a lot of things in that namespace; but for my own code, they're usually pretty svelte, so I stick to "from mymodule import a, b, c" if there are lots or just an "import mymodule" without aliasing it shorter. If the imported names were to grow to an unweildy size, I'd go the same route as above ("import myutils as u"). My largely irrelevant $0.02 USD, adjusted for tax and inflation, -tkc From torriem at gmail.com Fri Jun 5 00:12:45 2020 From: torriem at gmail.com (Michael Torrie) Date: Thu, 4 Jun 2020 22:12:45 -0600 Subject: Fwd: How can I build embeddable zip python on Linux In-Reply-To: References: Message-ID: <430a8ca4-fea5-8431-ce27-46ecb3cc8f1d@gmail.com> On 6/4/20 2:47 AM, Filip Bascarevic wrote: > When I tried to build GDB with Python support on Linux, I realized I > couldn?t find embeddable python for Linux. > > Please, can you give me some instructions how can I build embeddable Python > from source in Linux? Is it possible in the Linux environment? What does "embeddable python" mean? Do you mean the libpython shared library and C API? If so it's just a matter of installing the correct -devel or -dev package on your distro. On Debian this would likely be libpython#.#-dev where # is the version. For example, libpython3.8-dev. On Fedora that might be python-devel (or on CentOS, python36-devel). From luuk at invalid.lan Fri Jun 5 02:49:38 2020 From: luuk at invalid.lan (Luuk) Date: Fri, 5 Jun 2020 08:49:38 +0200 Subject: Fwd: How can I build embeddable zip python on Linux In-Reply-To: References: <430a8ca4-fea5-8431-ce27-46ecb3cc8f1d@gmail.com> Message-ID: <5ed9eb02$0$13634$e4fe514c@newszilla.xs4all.nl> On 5-6-2020 06:12, Michael Torrie wrote: > On 6/4/20 2:47 AM, Filip Bascarevic wrote: >> When I tried to build GDB with Python support on Linux, I realized I >> couldn?t find embeddable python for Linux. >> >> Please, can you give me some instructions how can I build embeddable Python >> from source in Linux? Is it possible in the Linux environment? > > What does "embeddable python" mean? Do you mean the libpython shared > library and C API? If so it's just a matter of installing the correct > -devel or -dev package on your distro. On Debian this would likely be > libpython#.#-dev where # is the version. For example, libpython3.8-dev. > On Fedora that might be python-devel (or on CentOS, python36-devel). > probably the same as asked here (with no answer (yet)): https://stackoverflow.com/questions/49425397/building-an-embeddable-minimal-python-distribution-on-linux -- Luuk From luuk at invalid.lan Fri Jun 5 02:52:28 2020 From: luuk at invalid.lan (Luuk) Date: Fri, 5 Jun 2020 08:52:28 +0200 Subject: Fwd: How can I build embeddable zip python on Linux In-Reply-To: <5ed9eb02$0$13634$e4fe514c@newszilla.xs4all.nl> References: <430a8ca4-fea5-8431-ce27-46ecb3cc8f1d@gmail.com> <5ed9eb02$0$13634$e4fe514c@newszilla.xs4all.nl> Message-ID: <5ed9ebac$0$13634$e4fe514c@newszilla.xs4all.nl> On 5-6-2020 08:49, Luuk wrote: > On 5-6-2020 06:12, Michael Torrie wrote: >> On 6/4/20 2:47 AM, Filip Bascarevic wrote: >>> When I tried to build GDB with Python support on Linux, I realized I >>> couldn?t find embeddable python for Linux. >>> >>> Please, can you give me some instructions how can I build embeddable Python >>> from source in Linux? Is it possible in the Linux environment? >> >> What does "embeddable python" mean?? Do you mean the libpython shared >> library and C API?? If so it's just a matter of installing the correct >> -devel or -dev package on your distro. On Debian this would likely be >> libpython#.#-dev where # is the version. For example, libpython3.8-dev. >> On Fedora that might be python-devel (or on CentOS, python36-devel). >> > > probably the same as asked here (with no answer (yet)): > https://stackoverflow.com/questions/49425397/building-an-embeddable-minimal-python-distribution-on-linux > > https://docs.python.org/3.5/using/windows.html#embedded-distribution 3.8. Embedded Distribution New in version 3.5. The embedded distribution is a ZIP file containing a minimal Python environment. It is intended for acting as part of another application, rather than being directly accessed by end-users. When extracted, the embedded distribution is (almost) fully isolated from the user?s system, including environment variables, system registry settings, and installed packages. The standard library is included as pre-compiled and optimized .pyc files in a ZIP, and python3.dll, python35.dll, python.exe and pythonw.exe are all provided. Tcl/tk (including all dependants, such as Idle), pip and the Python documentation are not included. Note The embedded distribution does not include the Microsoft C Runtime and it is the responsibility of the application installer to provide this. The runtime may have already been installed on a user?s system previously or automatically via Windows Update, and can be detected by finding ucrtbase.dll in the system directory. Third-party packages should be installed by the application installer alongside the embedded distribution. Using pip to manage dependencies as for a regular Python installation is not supported with this distribution, though with some care it may be possible to include and use pip for automatic updates. In general, third-party packages should be treated as part of the application (?vendoring?) so that the developer can ensure compatibility with newer versions before providing updates to users. The two recommended use cases for this distribution are described below -- Luuk From rhodri at kynesim.co.uk Fri Jun 5 07:36:50 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 5 Jun 2020 12:36:50 +0100 Subject: Friday Finking: Imports, Namespaces, Poisoning, Readability In-Reply-To: <6aa1aba8-2715-f410-0087-d4fca95bfd1e@etelligence.info> References: <6aa1aba8-2715-f410-0087-d4fca95bfd1e@etelligence.info> Message-ID: AFAIKT the "three" are readability, naming conflicts and source location. On 05/06/2020 01:15, DL Neil via Python-list wrote: > - how do you like to balance these three (and any other criteria)? Readability is king. Or queen, if you prefer. Anything that damages readability drops dramatically in its desirability. One consequence of that is that I rarely use "import ... as", since as you mentioned, renamed libraries are a rich source of WTF moments. I would use "import numpy as np" (if I ever used numpy) because it seems to be standard, but I wouldn't type "import pygame as pg" despite having used PyGame extensively in the past. I tend to use "from xxx import yy_yy, zzzz" when I'm not importing many things from a library and their names are sufficiently obvious. The definitions of "not many" and "sufficiently obvious" are pretty flexible. In particular, I'll list more items as the qualified names get longer, as you noted. Source location is a non-issue; it's trivial to jump to the imports at the top of the file, look it up and jump back again. Or have two buffers viewing the same file; that's a technique I use quite a lot anyway. If I need to know the signature, that's what documentation is for. I would never rename an object I've imported using "as". It's just not worth the inevitable heartache. If that means I have namespace collisions, that's either a vote to use the qualified name or to change the name of whatever I wrote that clashes with it. > - is your preference (or selection) influenced by the facilities offered > by your favorite editor/IDE? Not really. I'm an EMACS user, so any of the "fancy" IDE handiwork is immediately out. The only reason you need an IDE is if your support tools suck (sorry, Windows users). > - does your decision differ according to whether the 'target module' is > one of yours, from the PSL, from some third party, corporate, ...? I'm more likely to change my own module to fit :-) > - do you prefer PSL's importlib over Python's native import-s, for one > of these (or any other) reason? Um, why would I? -- Rhodri James *-* Kynesim Ltd From lily_sararat at yahoo.com Fri Jun 5 06:54:04 2020 From: lily_sararat at yahoo.com (Lily Sararat) Date: Fri, 5 Jun 2020 10:54:04 +0000 (UTC) Subject: Can't download Pygame and Pgzero In-Reply-To: <1279232174.1285211.1591353594586@mail.yahoo.com> References: <1279232174.1285211.1591353594586.ref@mail.yahoo.com> <1279232174.1285211.1591353594586@mail.yahoo.com> Message-ID: <2128511764.2197366.1591354444857@mail.yahoo.com> To whom it may concern, I have trouble installing the?Pygame and Pgzero on Window.? I based on the instruction on the "Computer Coding Python Games for Kids" by Carol Vorderman.? Nothing works.?? I tried Python 3.6.2 as describe in the book and the latest version 3.8.3 still encounter on the same problem.? I really need to get this sorted so my kid can spend his summer break mastering the coding. Brgs, From agnese.camellini at gmail.com Fri Jun 5 09:38:50 2020 From: agnese.camellini at gmail.com (Agnese Camellini) Date: Fri, 5 Jun 2020 15:38:50 +0200 Subject: Strange use of Lambda arrow Message-ID: Hello to everyone, lately i building up an open source project, with some collaborator, but one of them cannot contribute any more. He is a solution architect so he is very skilled (much more than me!). I am now analysing his code to finish the job but i don't get this use of the lambda arrow, it's like he is deplaring the returned tipe in the function signature (as you would do in Java). I have never seen something like this in python.. Can someone please explain to me this usage (the part regarding the question is highlighted in yellow): @classmethod def extract_document_data(cls, file_path : str) -> DocumentData: """ Entry point of the module, it extracts the data from the document whose path is passed as input. The extraction strategy is automatically chosen based on the MIME type of the file. @type file_path: str @param file_path: The path of the document to be parsed. @rtype: DocumentData @returns: An object containing the data of the parsed document. """ mime = magic.Magic(mime=True) mime_type = mime.from_file(file_path) document_type = DocumentType.get_instance(mime_type) strategy = cls.strategies[document_type] return strategy.extract_document_data(file_path) To be more verbose, this is the whole script: from enum import Enum import json import magic import docx from pdfminer.converter import PDFPageAggregator from pdfminer.layout import LAParams, LTContainer, LTTextContainer from pdfminer.pdfdocument import PDFDocument, PDFNoOutlines from pdfminer.pdfinterp import PDFPageInterpreter from pdfminer.pdfinterp import PDFResourceManager from pdfminer.pdfpage import PDFPage from pdfminer.pdfparser import PDFParser class DocumentType(Enum): """ Defines the handled document types. Each value is associated to a MIME type. """ def __init__(self, mime_type): self.mime_type = mime_type @classmethod def get_instance(cls, mime_type : str): values = [e for e in cls] for value in values: if value.mime_type == mime_type: return value raise MimeNotValidError(mime_type) PDF = 'application/pdf' DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' class MimeNotValidError(Exception): """ Exception to be raised when a not valid MIME type is processed. """ pass class DocumentData: """ Wrapper for the extracted document data (TOC and contents). """ def __init__(self, toc : list = [], pages : list = [], document_text : str = None): self.toc = toc self.pages = pages if document_text is not None: self.document_text = document_text else: self.document_text = ' '.join([page.replace('\n', ' ') for page in pages]) def toc_as_json(self) -> str: return json.dumps(self.toc) class ExtractionStrategy: """ Base class for the extraction strategies. """ @staticmethod def extract_document_data(file_path : str) -> DocumentData: pass class DOCXExtractionStrategy(ExtractionStrategy): """ It implements the TOC and contents extraction from a DOCX document. """ @staticmethod def extract_document_data(file_path : str) -> DocumentData: document = docx.Document(file_path) body_elements = document._body._body # Selecting only the elements from DOCX XML, # as they're the only to contain some text. text_elems = body_elements.xpath('.//w:t') return DocumentData(document_text = ' '.join([elem.text for elem in text_elems])) class PDFExtractionStrategy(ExtractionStrategy): """ It implements the TOC and contents extraction from a PDF document. """ @staticmethod def parse_toc(doc : PDFDocument) -> list: raw_toc = [] try: outlines = doc.get_outlines() for (level, title, dest, a, se) in outlines: raw_toc.append((level, title)) except PDFNoOutlines: pass return PDFExtractionStrategy.build_toc_tree(raw_toc) @staticmethod def build_toc_tree(items : list) -> list: """ Builds the TOC tree from a list of TOC items. @type items: list @param items: The TOC items. Each item must have the following format: (, ). E.g: [(1, 'Contents'), (2, 'Chapter 1'), (2, 'Chapter 2')] @rtype: list @returns: The TOC tree. The tree hasn't a root element, therefore it actually is a list. """ toc = [] if items is None or len(items) == 0: return toc current_toc_level = toc # Using an explicit stack containing the lists corresponding to # the various levels of the TOC, to simulate the recursive building # of the TOC tree in a more efficient way toc_levels_stack = [] toc_levels_stack.append(current_toc_level) # Each TOC item can be inserted into the current TOC level as # string (just the item description) or as dict, where the key is # the item description and the value is a list containing the # children TOC items. # To correctly determine how to insert the current item into # the current level, a kind of look-ahead is needed, that is # the depth of the next item has to be considered. # Initializing the variables related to the previous item. prev_item_depth, prev_item_desc = items[0] # Adding a fake final item in order to handle all the TOC items # inside the cycle. items.append((-1, '')) for i in range(1, len(items)): # In fact each iteration handles the item of the previous # one, using the current item to determine how to insert # the previous item into the current TOC level, # as explained before. curr_item = items[i] curr_item_depth = curr_item[0] if curr_item_depth == prev_item_depth: # The depth of the current item is the same # as the previous one. # Inserting the previous item into the current TOC level # as string. current_toc_level.append(prev_item_desc) elif curr_item_depth == prev_item_depth + 1: # The depth of the current item is increased by 1 compared to # the previous one. # Inserting the previous item into the current TOC level # as dict. prev_item_dict = { prev_item_desc : [] } current_toc_level.append(prev_item_dict) # Updating the current TOC level with the newly created one # which contains the children of the previous item. current_toc_level = prev_item_dict[prev_item_desc] toc_levels_stack.append(current_toc_level) elif curr_item_depth < prev_item_depth: # The depth of the current item is lesser than # the previous one. # Inserting the previous item into the current TOC level # as string. current_toc_level.append(prev_item_desc) if i < len(items)-1: # Executing these steps for all the items except the last one depth_diff = prev_item_depth - curr_item_depth # Removing from the stack as many TOC levels as the difference # between the depth of the previous item and the depth of the # current one. for i in range(0, depth_diff): toc_levels_stack.pop() # Updating the current TOC level with the one contained in # the head of the stack. current_toc_level = toc_levels_stack[-1] # Updating the previous item with the current one prev_item_depth, prev_item_desc = curr_item return toc @staticmethod def from_bytestring(s) -> str: """ If the input string is a byte-string, converts it to a string using UTF-8 as encoding. @param s: A string or a byte-string. @rtype: str @returns: The potentially converted string. """ if s: if isinstance(s, str): return s else: return s.encode('utf-8') @staticmethod def parse_layout_nodes(container : LTContainer) -> str: """ Recursively extracts the text from all the nodes contained in the input PDF layout tree/sub-tree. @type container: LTContainer @param container: The PDF layout tree/sub-tree from which to extract the text. @rtype: str @returns: A string containing the extracted text. """ text_content = [] # The iterator returns the children nodes. for node in container: if isinstance(node, LTTextContainer): # Only nodes of type LTTextContainer contain text. text_content.append(PDFExtractionStrategy.from_bytestring(node.get_text())) elif isinstance(node, LTContainer): # Recursively calling the method on the current node, which is a container itself. text_content.append(PDFExtractionStrategy.parse_layout_nodes(node)) else: # Ignoring all the other node types. pass # Joining all the extracted text chunks with a new line character. return "\n".join(text_content) @staticmethod def parse_pages(doc : PDFDocument) -> list: rsrcmgr = PDFResourceManager() laparams = LAParams() device = PDFPageAggregator(rsrcmgr, laparams=laparams) interpreter = PDFPageInterpreter(rsrcmgr, device) text_content = [] for i, page in enumerate(PDFPage.create_pages(doc)): interpreter.process_page(page) layout = device.get_result() # Extracts the text from all the nodes of the PDF layout tree of each page text_content.append(PDFExtractionStrategy.parse_layout_nodes(layout)) return text_content @staticmethod def parse_pdf(file_path : str) -> (list, list): toc = [] pages = [] try: fp = open(file_path, 'rb') parser = PDFParser(fp) doc = PDFDocument(parser) parser.set_document(doc) if doc.is_extractable: toc = PDFExtractionStrategy.parse_toc(doc) pages = PDFExtractionStrategy.parse_pages(doc) fp.close() except IOError: pass return (toc, pages) @staticmethod def extract_document_data(file_path : str) -> DocumentData: toc, pages = PDFExtractionStrategy.parse_pdf(file_path) return DocumentData(toc, pages = pages) class DocumentDataExtractor: """ Main class of the module. It's responsible for actually executing the text extraction. The output is constituted by the following items: -table of contents (TOC); -pages contents. """ # Dictionary containing the extraction strategies for the different # document types, indexed by the corresponding DocumentType enum values. strategies = { DocumentType.DOCX : DOCXExtractionStrategy(), DocumentType.PDF : PDFExtractionStrategy() } @classmethod def extract_document_data(cls, file_path : str) -> DocumentData: """ Entry point of the module, it extracts the data from the document whose path is passed as input. The extraction strategy is automatically chosen based on the MIME type of the file. @type file_path: str @param file_path: The path of the document to be parsed. @rtype: DocumentData @returns: An object containing the data of the parsed document. """ mime = magic.Magic(mime=True) mime_type = mime.from_file(file_path) document_type = DocumentType.get_instance(mime_type) strategy = cls.strategies[document_type] return strategy.extract_document_data(file_path) From rosuav at gmail.com Fri Jun 5 12:40:08 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Jun 2020 02:40:08 +1000 Subject: Strange use of Lambda arrow In-Reply-To: References: Message-ID: On Sat, Jun 6, 2020 at 2:36 AM Agnese Camellini wrote: > > Hello to everyone, lately i building up an open source project, with some > collaborator, but one of them cannot contribute any more. He is a solution > architect so he is very skilled (much more than me!). I am now analysing > his code to finish the job but i don't get this use of the lambda arrow, > it's like he is deplaring the returned tipe in the function signature (as > you would do in Java). I have never seen something like this in python.. > > Can someone please explain to me this usage (the part regarding the > question is highlighted in yellow): > > @classmethod > def extract_document_data(cls, file_path : str) -> DocumentData: I don't know what you highlighted in yellow, as that part didn't come through. But in Python, that arrow has nothing to do with lambda functions; it is exactly as you describe, annotating a function with the type of its return value. ChrisA From rhodri at kynesim.co.uk Fri Jun 5 12:53:09 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 5 Jun 2020 17:53:09 +0100 Subject: Can't download Pygame and Pgzero In-Reply-To: <2128511764.2197366.1591354444857@mail.yahoo.com> References: <1279232174.1285211.1591353594586.ref@mail.yahoo.com> <1279232174.1285211.1591353594586@mail.yahoo.com> <2128511764.2197366.1591354444857@mail.yahoo.com> Message-ID: <190278c1-57f7-796f-2455-bc2aba053b78@kynesim.co.uk> On 05/06/2020 11:54, Lily Sararat via Python-list wrote: > I have trouble installing the Pygame and Pgzero on Window. I based > on the instruction on the "Computer Coding Python Games for Kids" by > Carol Vorderman. Nothing works. > I tried Python 3.6.2 as describe in the book and the latest version > 3.8.3 still encounter on the same problem. I really need to get this > sorted so my kid can spend his summer break mastering the coding. Hi there Lily. We aren't Pygame specialists, but we can give it a go. However to do that you're going to need to give us some details. Which version of Windows are you using? What exactly did you do to install Pygame and Pgzero, in order, and what exactly went wrong. Please copy and paste any error messages, don't send screenshots because the mailing list will strip them off and we won't see them. -- Rhodri James *-* Kynesim Ltd From zljubisic at gmail.com Fri Jun 5 17:36:38 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Fri, 5 Jun 2020 14:36:38 -0700 (PDT) Subject: Can I have a class with property named "from" Message-ID: <1353363c-116b-48b1-b85a-a7e9d1c5a946o@googlegroups.com> Hi, if I define class like this one: class abc: def __init__(self): self._from = None @property def from(self): return self._from @from.setter def from(self, value): self._from = value I get the error SyntaxError: invalid syntax because of the property named from. Looks like in python from is a keyword that cannot be used as a property name. I have to create a python object from a complex (nested) json object that has many keys with name "from" and value of date in string format. As I would like to keep property names as they are in the json file... is there a workaround? Regards. From ethan at stoneleaf.us Fri Jun 5 17:50:45 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 5 Jun 2020 14:50:45 -0700 Subject: Can I have a class with property named "from" In-Reply-To: <1353363c-116b-48b1-b85a-a7e9d1c5a946o@googlegroups.com> References: <1353363c-116b-48b1-b85a-a7e9d1c5a946o@googlegroups.com> Message-ID: On 06/05/2020 02:36 PM, zljubisic at gmail.com wrote: > class abc: > > def __init__(self): > self._from = None > > @property > def from(self): > return self._from > > @from.setter > def from(self, value): > self._from = value > > > I get the error SyntaxError: invalid syntax because of the property named from. > Looks like in python from is a keyword that cannot be used as a property name. > > I have to create a python object from a complex (nested) json object that has many keys with name "from" and value of date in string format. > > As I would like to keep property names as they are in the json file... is there a workaround? There is no workaround that allows a keyword to be used except as a keyword, other than making it a string. When faced with this kind of situation myself I use a synonym, like "since", or a translation, like "desde". -- ~Ethan~ From python at mrabarnett.plus.com Fri Jun 5 18:15:36 2020 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 5 Jun 2020 23:15:36 +0100 Subject: Can I have a class with property named "from" In-Reply-To: References: <1353363c-116b-48b1-b85a-a7e9d1c5a946o@googlegroups.com> Message-ID: On 2020-06-05 22:50, Ethan Furman wrote: > On 06/05/2020 02:36 PM, zljubisic at gmail.com wrote: > >> class abc: >> >> def __init__(self): >> self._from = None >> >> @property >> def from(self): >> return self._from >> >> @from.setter >> def from(self, value): >> self._from = value >> >> >> I get the error SyntaxError: invalid syntax because of the property named from. >> Looks like in python from is a keyword that cannot be used as a property name. >> >> I have to create a python object from a complex (nested) json object that has many keys with name "from" and value of date in string format. >> >> As I would like to keep property names as they are in the json file... is there a workaround? > > There is no workaround that allows a keyword to be used except as a keyword, other than making it a string. When faced with this kind of situation myself I use a synonym, like "since", or a translation, like "desde". > The usual workaround is to append an underscore: 'from_'. From cs at cskk.id.au Fri Jun 5 18:23:10 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 6 Jun 2020 08:23:10 +1000 Subject: Strange use of Lambda arrow In-Reply-To: References: Message-ID: <20200605222310.GA54707@cskk.homeip.net> On 06Jun2020 02:40, Chris Angelico wrote: >On Sat, Jun 6, 2020 at 2:36 AM Agnese Camellini > wrote: >> >> Hello to everyone, lately i building up an open source project, with some >> collaborator, but one of them cannot contribute any more. He is a solution >> architect so he is very skilled (much more than me!). I am now analysing >> his code to finish the job but i don't get this use of the lambda arrow, >> it's like he is deplaring the returned tipe in the function signature (as >> you would do in Java). I have never seen something like this in python.. >> >> Can someone please explain to me this usage (the part regarding the >> question is highlighted in yellow): >> >> @classmethod >> def extract_document_data(cls, file_path : str) -> DocumentData: > >I don't know what you highlighted in yellow, as that part didn't come >through. But in Python, that arrow has nothing to do with lambda >functions; it is exactly as you describe, annotating a function with >the type of its return value. The OP may be being confused by JavaScript, where they have "arrow functions", which are what Python calls lambda: anonymous functions. It uses an arrow in the syntax: (x,y) -> x+y To reiterate what Chris said: in Python the -> is just a type annotation, indicating the expected return type(s) for a function. Cheers, Cameron Simpson From ethan at stoneleaf.us Fri Jun 5 18:59:45 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 5 Jun 2020 15:59:45 -0700 Subject: Can I have a class with property named "from" In-Reply-To: References: <1353363c-116b-48b1-b85a-a7e9d1c5a946o@googlegroups.com> Message-ID: <85704289-778e-48ed-58d0-8b06fa011dd1@stoneleaf.us> On 06/05/2020 03:15 PM, MRAB wrote: > On 2020-06-05 22:50, Ethan Furman wrote: >> There is no workaround that allows a keyword to be used except as a keyword, other than making it a string.? When faced with this kind of situation myself I use a synonym, like "since", or a translation, like "desde". >> > The usual workaround is to append an underscore: 'from_'. True, but ick. ;-) It's like a dangling preposition. -- ~Ethan~ From rosuav at gmail.com Fri Jun 5 20:01:00 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Jun 2020 10:01:00 +1000 Subject: Strange use of Lambda arrow In-Reply-To: <20200605222310.GA54707@cskk.homeip.net> References: <20200605222310.GA54707@cskk.homeip.net> Message-ID: On Sat, Jun 6, 2020 at 8:24 AM Cameron Simpson wrote: > The OP may be being confused by JavaScript, where they have "arrow > functions", which are what Python calls lambda: anonymous functions. It > uses an arrow in the syntax: > > (x,y) -> x+y > In JS, they're sometimes called "fat arrow" functions, because they are spelled "=>". Maybe there's some other language where they're spelled "->"? ChrisA From python at mrabarnett.plus.com Fri Jun 5 21:48:36 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 6 Jun 2020 02:48:36 +0100 Subject: Strange use of Lambda arrow In-Reply-To: References: <20200605222310.GA54707@cskk.homeip.net> Message-ID: <4d6997ad-f8ad-717b-5d79-84ece0ac8bc4@mrabarnett.plus.com> On 2020-06-06 01:01, Chris Angelico wrote: > On Sat, Jun 6, 2020 at 8:24 AM Cameron Simpson wrote: >> The OP may be being confused by JavaScript, where they have "arrow >> functions", which are what Python calls lambda: anonymous functions. It >> uses an arrow in the syntax: >> >> (x,y) -> x+y >> > > In JS, they're sometimes called "fat arrow" functions, because they > are spelled "=>". Maybe there's some other language where they're > spelled "->"? > I think it's Cameron who's confused. :-) The OP said "Java". Java has "->"; JavaScript has "=>". From cs at cskk.id.au Sat Jun 6 00:35:30 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 6 Jun 2020 14:35:30 +1000 Subject: Strange use of Lambda arrow In-Reply-To: <4d6997ad-f8ad-717b-5d79-84ece0ac8bc4@mrabarnett.plus.com> References: <4d6997ad-f8ad-717b-5d79-84ece0ac8bc4@mrabarnett.plus.com> Message-ID: <20200606043530.GA31150@cskk.homeip.net> On 06Jun2020 02:48, MRAB wrote: >On 2020-06-06 01:01, Chris Angelico wrote: >>On Sat, Jun 6, 2020 at 8:24 AM Cameron Simpson wrote: >>>The OP may be being confused by JavaScript, where they have "arrow >>>functions", which are what Python calls lambda: anonymous functions. It >>>uses an arrow in the syntax: >>> >>> (x,y) -> x+y >>> >> >>In JS, they're sometimes called "fat arrow" functions, because they >>are spelled "=>". Maybe there's some other language where they're >>spelled "->"? >> >I think it's Cameron who's confused. :-) Likely. It is months since I wrote any JavaScript, and I've never enjoyed it. It is a hellscape of callbacks and closures, and an object model as thin as Perl's. >The OP said "Java". Java has "->"; JavaScript has "=>". Hah. Are there not languages where "=>" is an alternate spelling of greater-than-or-equal? Cheers, Cameron Simpson From PythonList at DancesWithMice.info Sat Jun 6 02:29:47 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 6 Jun 2020 18:29:47 +1200 Subject: Can I have a class with property named "from" In-Reply-To: <1353363c-116b-48b1-b85a-a7e9d1c5a946o@googlegroups.com> References: <1353363c-116b-48b1-b85a-a7e9d1c5a946o@googlegroups.com> Message-ID: <359e590e-5e06-6f6c-d91b-11436fc9b8c9@DancesWithMice.info> On 6/06/20 9:36 AM, zljubisic at gmail.com wrote: > Hi, > > if I define class like this one: > > class abc: > > def __init__(self): > self._from = None > > @property > def from(self): > return self._from > > @from.setter > def from(self, value): > self._from = value > > > I get the error SyntaxError: invalid syntax because of the property named from. > Looks like in python from is a keyword that cannot be used as a property name. > > I have to create a python object from a complex (nested) json object that has many keys with name "from" and value of date in string format. > > As I would like to keep property names as they are in the json file... is there a workaround? The from moduleNM import object/can't use a keyword issue has been discussed. When a JSON object is load-ed into a Python program, its native form is a dict. Thus, "from" will be one of the dict's keys, cf a Python identifier. Why have you chosen to go to the trouble of creating a separate data-attribute (with the from/_from/from_ name)? (I realise the above class is likely 'cut-down' to suit publication) Does the answer include terms such as 'understanding', 'control', 'easier to use', 'better suited to existing code'? Assuming a good reason (why wouldn't we?), then it is necessary for the Python object to include (or be able to access) 'serialise' and/or 'deserialise' routines - because Python objects will not do this, in and of themselves. This is the opportunity to rename the value between its JSON version and its internal (code) use. If there are <> then they can't all be called "from" anyway. Plus, a term such as "from", likely fails to convey its full meaning, eg a student might be enrolled_since, or "zljubisic" has been paid an higher salary rate_from. As such, 'expanding' its name would likely improve readability, comprehension, and thus code-quality! (I'm with the "ick" when it comes to 'artificial' name-mangling) -- Regards =dn From caledonian209 at gmail.com Sat Jun 6 05:20:45 2020 From: caledonian209 at gmail.com (Caledonian26) Date: Sat, 6 Jun 2020 02:20:45 -0700 (PDT) Subject: Applied Data Science with Python - Assignment 2.3: clicking on chart to select Y values Message-ID: Hey all, I have the following code below: import pandas as pd import numpy as np from scipy import stats np.random.seed(12345) scores = [np.random.normal(32000,200000,3650).mean(), np.random.normal(43000,100000,3650).mean(),np.random.normal(43500,140000,3650).mean(), np.random.normal(48000,70000,3650).mean()] standarderrors1992 = stats.sem(np.random.normal(32000,200000,3650)) standarderrors1993 = stats.sem(np.random.normal(43000,100000,3650)) standarderrors1994 = stats.sem(np.random.normal(43500,140000,3650)) standarderrors1995 = stats.sem(np.random.normal(48000,70000,3650)) add1992 = 1.96*standarderrors1992 add1993 = 1.96*standarderrors1993 add1994 = 1.96*standarderrors1994 add1995 = 1.96*standarderrors1995 mean1992 = np.random.normal(32000,200000,3650).mean() mean1993 = np.random.normal(43000,100000,3650).mean() mean1994 = np.random.normal(43500,140000,3650).mean() mean1995 = np.random.normal(48000,70000,3650).mean() labels = [1992,1993,1994,1995] add = [add1992,add1992,add1994,add1995] 1. This first part organises the raw data. limits = [] def onclick(event): plt.cla() plt.bar(df["index"].values,df["values"].values,align='center', alpha=0.5,yerr=add) plt.xticks(labels) limit = event.ydata limits.append(limit) if len(limits) >= 1: plt.gcf().canvas.mpl_disconnect(plt.gcf().canvas.mpl_connect('button_press_event', onclick)) plt.gcf().canvas.mpl_connect('button_press_event', onclick) 2. This next part allows the user to press on the graph to select a Y value. This should be assigned to the variable 'limits' dict = {mean1992:add1992,mean1993:add1993,mean1994:add1994,mean1995:add1995} colourofbars = [] for key,value in dict.items(): if limits[0] > (key+(value)): colour = 1 colourofbars.append(colour) elif limits[0] < (key-(value)): colour = 0 colourofbars.append(colour) elif (limits[0] < (key+(value))) & (limits[0] > (key-(value))): colour = ((key+(value))-limits[0])/((key+value)-(key-value)) colourofbars.append(colour) df["colourofbars"] = colourofbars 3. Here, the list 'colourofbars' is appended based on the data above, and added as a column to the dataframe 'df'. cmap = plt.cm.rainbow norm = matplotlib.colors.Normalize(vmin=1.5, vmax=4.5) plt.bar(df.index,df.values,color=cmap(norm(df.colourofbars.values)),align='center', alpha=0.5,yerr=add) plt.xticks(labels) sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm) plt.gcf().colorbar(sm) plt.show() 4. Here, a different colour is assigned to each bar in the bar chart depending on the values in the column 'colourofbars'. I then try to plot a legend showing this colour gradient scale. *However,* I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? Am I on the right lines? From rosuav at gmail.com Sat Jun 6 05:29:19 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 6 Jun 2020 19:29:19 +1000 Subject: Applied Data Science with Python - Assignment 2.3: clicking on chart to select Y values In-Reply-To: References: Message-ID: On Sat, Jun 6, 2020 at 7:26 PM Caledonian26 wrote: > *However,* I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? Am I on the right lines? > Python always gives you a wealth of information with an exception. Most notably, you get a traceback, which tells you where the error happened, where that was called from, where THAT was called from, etc, all the way to the start of the program. In order to track down this error, you'll need the traceback. I would recommend copying and pasting it in its entirety; even if you don't (yet) understand how to interpret it, we can help you with that. All the best! ChrisA From caledonian209 at gmail.com Sat Jun 6 05:34:59 2020 From: caledonian209 at gmail.com (Caledonian26) Date: Sat, 6 Jun 2020 02:34:59 -0700 (PDT) Subject: Applied Data Science with Python - Assignment 2.3: clicking on chart to select Y values In-Reply-To: References: Message-ID: <10234a6b-12b5-4dbe-984b-e2623b5b0738o@googlegroups.com> On Saturday, June 6, 2020 at 10:29:46 AM UTC+1, Chris Angelico wrote: > On Sat, Jun 6, 2020 at 7:26 PM Caledonian26 wrote: > > *However,* I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? Am I on the right lines? > > > > Python always gives you a wealth of information with an exception. > Most notably, you get a traceback, which tells you where the error > happened, where that was called from, where THAT was called from, etc, > all the way to the start of the program. In order to track down this > error, you'll need the traceback. I would recommend copying and > pasting it in its entirety; even if you don't (yet) understand how to > interpret it, we can help you with that. > > All the best! > > ChrisA Hey, Here is the full error message: Traceback (most recent call last): File "", line 45, in IndexError: list index out of range From miki.tebeka at gmail.com Sat Jun 6 05:42:40 2020 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 6 Jun 2020 02:42:40 -0700 (PDT) Subject: Shared library missing from wheel (custom build) Message-ID: <3e393747-2872-426e-a41b-5d0fbfccfc27o@googlegroups.com> Hi, I'm playing around with generating extension moudle to Python in Go. This is for a blog post - not production ready. The Go code is compiled to a shared library and the Python module is using ctypes to call the Go code in the shared library. I know it's know a classic extension module with PyModule_Create and friends, but that's for later... maybe. The setup.py is defined as --- from subprocess import call from setuptools import Extension, setup from setuptools.command.build_ext import build_ext class build_go_ext(build_ext): def build_extension(self, ext): ext_path = self.get_ext_filename(ext.name) cmd = ['go', 'build', '-buildmode=c-shared', '-o', ext_path] cmd += ext.sources out = call(cmd) if out != 0: raise RuntimeError('Go build failed') setup( name='checksig', version='0.1.0', py_modules=['checksig'], ext_modules=[ Extension('_checksig', ['checksig.go', 'export.go']) ], cmdclass={'build_ext': build_go_ext}, ) --- When I run "python setup.py bdist_wheel", I see that that _checksig.cpython-38-x86_64-linux-gnu.so is being built. But when I look at the content of dist/checksig-0.1.0-cp38-cp38-linux_x86_64.whl it's not there. What am I missing? You can view the whole (WIP) project at https://github.com/ardanlabs/python-go/tree/master/pyext Thanks, Miki From miki.tebeka at gmail.com Sat Jun 6 06:03:56 2020 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sat, 6 Jun 2020 03:03:56 -0700 (PDT) Subject: Shared library missing from wheel (custom build) In-Reply-To: <3e393747-2872-426e-a41b-5d0fbfccfc27o@googlegroups.com> References: <3e393747-2872-426e-a41b-5d0fbfccfc27o@googlegroups.com> Message-ID: <51e9175c-542e-4ad4-b24e-2423020c8348o@googlegroups.com> Changed to self.get_ext_full_path(ext.name) and it works now. From edmondo.giovannozzi at gmail.com Sat Jun 6 06:52:51 2020 From: edmondo.giovannozzi at gmail.com (edmondo.giovannozzi at gmail.com) Date: Sat, 6 Jun 2020 03:52:51 -0700 (PDT) Subject: Strange use of Lambda arrow In-Reply-To: References: Message-ID: Have a look at: https://docs.python.org/3/library/typing.html Il giorno venerd? 5 giugno 2020 18:35:10 UTC+2, Agnese Camellini ha scritto: > Hello to everyone, lately i building up an open source project, with some > collaborator, but one of them cannot contribute any more. He is a solution > architect so he is very skilled (much more than me!). I am now analysing > his code to finish the job but i don't get this use of the lambda arrow, > it's like he is deplaring the returned tipe in the function signature (as > you would do in Java). I have never seen something like this in python.. > > Can someone please explain to me this usage (the part regarding the > question is highlighted in yellow): > > @classmethod > def extract_document_data(cls, file_path : str) -> DocumentData: > """ > Entry point of the module, it extracts the data from the document > whose path is passed as input. > The extraction strategy is automatically chosen based on the MIME > type > of the file. > > @type file_path: str > @param file_path: The path of the document to be parsed. > @rtype: DocumentData > @returns: An object containing the data of the parsed document. > """ > > mime = magic.Magic(mime=True) > mime_type = mime.from_file(file_path) > document_type = DocumentType.get_instance(mime_type) > strategy = cls.strategies[document_type] > return strategy.extract_document_data(file_path) > > > To be more verbose, this is the whole script: > > from enum import Enum > import json > import magic > > import docx > from pdfminer.converter import PDFPageAggregator > from pdfminer.layout import LAParams, LTContainer, LTTextContainer > from pdfminer.pdfdocument import PDFDocument, PDFNoOutlines > from pdfminer.pdfinterp import PDFPageInterpreter > from pdfminer.pdfinterp import PDFResourceManager > from pdfminer.pdfpage import PDFPage > from pdfminer.pdfparser import PDFParser > > > class DocumentType(Enum): > """ > Defines the handled document types. > Each value is associated to a MIME type. > """ > > def __init__(self, mime_type): > self.mime_type = mime_type > > @classmethod > def get_instance(cls, mime_type : str): > values = [e for e in cls] > for value in values: > if value.mime_type == mime_type: > return value > raise MimeNotValidError(mime_type) > > PDF = 'application/pdf' > DOCX = > 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' > > > class MimeNotValidError(Exception): > """ > Exception to be raised when a not valid MIME type is processed. > """ > > pass > > > class DocumentData: > """ > Wrapper for the extracted document data (TOC and contents). > """ > > def __init__(self, toc : list = [], pages : list = [], document_text : > str = None): > self.toc = toc > self.pages = pages > if document_text is not None: > self.document_text = document_text > else: > self.document_text = ' '.join([page.replace('\n', ' ') for page > in pages]) > > def toc_as_json(self) -> str: > return json.dumps(self.toc) > > > class ExtractionStrategy: > """ > Base class for the extraction strategies. > """ > > @staticmethod > def extract_document_data(file_path : str) -> DocumentData: > pass > > > class DOCXExtractionStrategy(ExtractionStrategy): > """ > It implements the TOC and contents extraction from a DOCX document. > """ > > @staticmethod > def extract_document_data(file_path : str) -> DocumentData: > document = docx.Document(file_path) > body_elements = document._body._body > # Selecting only the elements from DOCX XML, > # as they're the only to contain some text. > text_elems = body_elements.xpath('.//w:t') > return DocumentData(document_text = ' '.join([elem.text for elem in > text_elems])) > > > class PDFExtractionStrategy(ExtractionStrategy): > """ > It implements the TOC and contents extraction from a PDF document. > """ > > @staticmethod > def parse_toc(doc : PDFDocument) -> list: > raw_toc = [] > try: > outlines = doc.get_outlines() > for (level, title, dest, a, se) in outlines: > raw_toc.append((level, title)) > except PDFNoOutlines: > pass > return PDFExtractionStrategy.build_toc_tree(raw_toc) > > @staticmethod > def build_toc_tree(items : list) -> list: > """ > Builds the TOC tree from a list of TOC items. > > @type items: list > @param items: The TOC items. > Each item must have the following format: (, description>). > E.g: [(1, 'Contents'), (2, 'Chapter 1'), (2, 'Chapter 2')] > @rtype: list > @returns: The TOC tree. The tree hasn't a root element, therefore it > actually is a list. > """ > > toc = [] > if items is None or len(items) == 0: > return toc > current_toc_level = toc > # Using an explicit stack containing the lists corresponding to > # the various levels of the TOC, to simulate the recursive building > # of the TOC tree in a more efficient way > toc_levels_stack = [] > toc_levels_stack.append(current_toc_level) > > # Each TOC item can be inserted into the current TOC level as > # string (just the item description) or as dict, where the key is > # the item description and the value is a list containing the > # children TOC items. > # To correctly determine how to insert the current item into > # the current level, a kind of look-ahead is needed, that is > # the depth of the next item has to be considered. > > # Initializing the variables related to the previous item. > prev_item_depth, prev_item_desc = items[0] > # Adding a fake final item in order to handle all the TOC items > # inside the cycle. > items.append((-1, '')) > > for i in range(1, len(items)): > # In fact each iteration handles the item of the previous > # one, using the current item to determine how to insert > # the previous item into the current TOC level, > # as explained before. > curr_item = items[i] > curr_item_depth = curr_item[0] > > if curr_item_depth == prev_item_depth: > # The depth of the current item is the same > # as the previous one. > # Inserting the previous item into the current TOC level > # as string. > current_toc_level.append(prev_item_desc) > elif curr_item_depth == prev_item_depth + 1: > # The depth of the current item is increased by 1 compared > to > # the previous one. > # Inserting the previous item into the current TOC level > # as dict. > prev_item_dict = { prev_item_desc : [] } > current_toc_level.append(prev_item_dict) > # Updating the current TOC level with the newly created one > # which contains the children of the previous item. > current_toc_level = prev_item_dict[prev_item_desc] > toc_levels_stack.append(current_toc_level) > elif curr_item_depth < prev_item_depth: > # The depth of the current item is lesser than > # the previous one. > # Inserting the previous item into the current TOC level > # as string. > current_toc_level.append(prev_item_desc) > if i < len(items)-1: > # Executing these steps for all the items except the > last one > depth_diff = prev_item_depth - curr_item_depth > # Removing from the stack as many TOC levels as the > difference > # between the depth of the previous item and the depth > of the > # current one. > for i in range(0, depth_diff): > toc_levels_stack.pop() > # Updating the current TOC level with the one contained > in > # the head of the stack. > current_toc_level = toc_levels_stack[-1] > # Updating the previous item with the current one > prev_item_depth, prev_item_desc = curr_item > > return toc > > @staticmethod > def from_bytestring(s) -> str: > """ > If the input string is a byte-string, converts it to a string using > UTF-8 as encoding. > > @param s: A string or a byte-string. > @rtype: str > @returns: The potentially converted string. > """ > > if s: > if isinstance(s, str): > return s > else: > return s.encode('utf-8') > > @staticmethod > def parse_layout_nodes(container : LTContainer) -> str: > """ > Recursively extracts the text from all the nodes contained in the > input PDF layout tree/sub-tree. > > @type container: LTContainer > @param container: The PDF layout tree/sub-tree from which to > extract the text. > @rtype: str > @returns: A string containing the extracted text. > """ > > text_content = [] > > # The iterator returns the children nodes. > for node in container: > if isinstance(node, LTTextContainer): > # Only nodes of type LTTextContainer contain text. > > text_content.append(PDFExtractionStrategy.from_bytestring(node.get_text())) > elif isinstance(node, LTContainer): > # Recursively calling the method on the current node, which > is a container itself. > > text_content.append(PDFExtractionStrategy.parse_layout_nodes(node)) > else: > # Ignoring all the other node types. > pass > > # Joining all the extracted text chunks with a new line character. > return "\n".join(text_content) > > @staticmethod > def parse_pages(doc : PDFDocument) -> list: > rsrcmgr = PDFResourceManager() > laparams = LAParams() > device = PDFPageAggregator(rsrcmgr, laparams=laparams) > interpreter = PDFPageInterpreter(rsrcmgr, device) > > text_content = [] > for i, page in enumerate(PDFPage.create_pages(doc)): > interpreter.process_page(page) > layout = device.get_result() > # Extracts the text from all the nodes of the PDF layout tree > of each page > > text_content.append(PDFExtractionStrategy.parse_layout_nodes(layout)) > > return text_content > > @staticmethod > def parse_pdf(file_path : str) -> (list, list): > toc = [] > pages = [] > try: > fp = open(file_path, 'rb') > parser = PDFParser(fp) > doc = PDFDocument(parser) > parser.set_document(doc) > > if doc.is_extractable: > toc = PDFExtractionStrategy.parse_toc(doc) > pages = PDFExtractionStrategy.parse_pages(doc) > > fp.close() > except IOError: > pass > return (toc, pages) > > @staticmethod > def extract_document_data(file_path : str) -> DocumentData: > toc, pages = PDFExtractionStrategy.parse_pdf(file_path) > return DocumentData(toc, pages = pages) > > > class DocumentDataExtractor: > """ > Main class of the module. > It's responsible for actually executing the text extraction. > The output is constituted by the following items: > -table of contents (TOC); > -pages contents. > """ > > # Dictionary containing the extraction strategies for the different > # document types, indexed by the corresponding DocumentType enum values. > strategies = { > DocumentType.DOCX : DOCXExtractionStrategy(), > DocumentType.PDF : PDFExtractionStrategy() > } > > @classmethod > def extract_document_data(cls, file_path : str) -> DocumentData: > """ > Entry point of the module, it extracts the data from the document > whose path is passed as input. > The extraction strategy is automatically chosen based on the MIME > type > of the file. > > @type file_path: str > @param file_path: The path of the document to be parsed. > @rtype: DocumentData > @returns: An object containing the data of the parsed document. > """ > > mime = magic.Magic(mime=True) > mime_type = mime.from_file(file_path) > document_type = DocumentType.get_instance(mime_type) > strategy = cls.strategies[document_type] > return strategy.extract_document_data(file_path) From edmondo.giovannozzi at gmail.com Sat Jun 6 08:28:55 2020 From: edmondo.giovannozzi at gmail.com (edmondo.giovannozzi at gmail.com) Date: Sat, 6 Jun 2020 05:28:55 -0700 (PDT) Subject: Can't download Pygame and Pgzero In-Reply-To: References: <1279232174.1285211.1591353594586.ref@mail.yahoo.com> <1279232174.1285211.1591353594586@mail.yahoo.com> <2128511764.2197366.1591354444857@mail.yahoo.com> Message-ID: <584319c4-dda2-4217-a1dd-dbefbbb94bb7o@googlegroups.com> Il giorno venerd? 5 giugno 2020 18:35:10 UTC+2, Lily Sararat ha scritto: > To whom it may concern, > I have trouble installing the?Pygame and Pgzero on Window.? I based on the instruction on the "Computer Coding Python Games for Kids" by Carol Vorderman.? Nothing works.?? > I tried Python 3.6.2 as describe in the book and the latest version 3.8.3 still encounter on the same problem.? I really need to get this sorted so my kid can spend his summer break mastering the coding. > Brgs, Hi Lily, on windows I prefer to start from a complete python distribution where most of the packages are already installed. One possibility is WinPython http://winpython.github.io/ You can install that in a directory without a full system installation. you can find there a "WinPython command Prompt" if you open it you can issue there the command: pip install pgzero pygame should be already installed. Cheers From vinodupadhyay900 at gmail.com Sat Jun 6 10:41:23 2020 From: vinodupadhyay900 at gmail.com (Tushar Upadhyay) Date: Sat, 6 Jun 2020 20:11:23 +0530 Subject: Can't download Pygame and Pgzero In-Reply-To: <584319c4-dda2-4217-a1dd-dbefbbb94bb7o@googlegroups.com> References: <1279232174.1285211.1591353594586.ref@mail.yahoo.com> <1279232174.1285211.1591353594586@mail.yahoo.com> <2128511764.2197366.1591354444857@mail.yahoo.com> <584319c4-dda2-4217-a1dd-dbefbbb94bb7o@googlegroups.com> Message-ID: Stop all the message and mails On Sat, 6 Jun 2020, 6:03 pm , wrote: > Il giorno venerd? 5 giugno 2020 18:35:10 UTC+2, Lily Sararat ha scritto: > > To whom it may concern, > > I have trouble installing the Pygame and Pgzero on Window. I based on > the instruction on the "Computer Coding Python Games for Kids" by Carol > Vorderman. Nothing works. > > I tried Python 3.6.2 as describe in the book and the latest version > 3.8.3 still encounter on the same problem. I really need to get this > sorted so my kid can spend his summer break mastering the coding. > > Brgs, > > Hi Lily, > on windows I prefer to start from a complete python distribution where > most of the packages are already installed. > One possibility is WinPython > > http://winpython.github.io/ > > You can install that in a directory without a full system installation. > you can find there a "WinPython command Prompt" if you open it you can > issue there the command: > > pip install pgzero > > pygame should be already installed. > > Cheers > > -- > https://mail.python.org/mailman/listinfo/python-list > From souvik.viksou at gmail.com Sat Jun 6 11:01:07 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sat, 6 Jun 2020 20:31:07 +0530 Subject: Can't download Pygame and Pgzero In-Reply-To: References: <1279232174.1285211.1591353594586.ref@mail.yahoo.com> <1279232174.1285211.1591353594586@mail.yahoo.com> <2128511764.2197366.1591354444857@mail.yahoo.com> <584319c4-dda2-4217-a1dd-dbefbbb94bb7o@googlegroups.com> Message-ID: What? Souvik flutter dev On Sat, Jun 6, 2020, 8:11 PM Tushar Upadhyay wrote: > Stop all the message and mails > > On Sat, 6 Jun 2020, 6:03 pm , wrote: > > > Il giorno venerd? 5 giugno 2020 18:35:10 UTC+2, Lily Sararat ha scritto: > > > To whom it may concern, > > > I have trouble installing the Pygame and Pgzero on Window. I based on > > the instruction on the "Computer Coding Python Games for Kids" by Carol > > Vorderman. Nothing works. > > > I tried Python 3.6.2 as describe in the book and the latest version > > 3.8.3 still encounter on the same problem. I really need to get this > > sorted so my kid can spend his summer break mastering the coding. > > > Brgs, > > > > Hi Lily, > > on windows I prefer to start from a complete python distribution where > > most of the packages are already installed. > > One possibility is WinPython > > > > http://winpython.github.io/ > > > > You can install that in a directory without a full system installation. > > you can find there a "WinPython command Prompt" if you open it you can > > issue there the command: > > > > pip install pgzero > > > > pygame should be already installed. > > > > Cheers > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Sat Jun 6 11:40:44 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 6 Jun 2020 16:40:44 +0100 Subject: Applied Data Science with Python - Assignment 2.3: clicking on chart to select Y values In-Reply-To: <10234a6b-12b5-4dbe-984b-e2623b5b0738o@googlegroups.com> References: <10234a6b-12b5-4dbe-984b-e2623b5b0738o@googlegroups.com> Message-ID: On 2020-06-06 10:34, Caledonian26 wrote: > On Saturday, June 6, 2020 at 10:29:46 AM UTC+1, Chris Angelico wrote: >> On Sat, Jun 6, 2020 at 7:26 PM Caledonian26 wrote: >> > *However,* I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? Am I on the right lines? >> > >> >> Python always gives you a wealth of information with an exception. >> Most notably, you get a traceback, which tells you where the error >> happened, where that was called from, where THAT was called from, etc, >> all the way to the start of the program. In order to track down this >> error, you'll need the traceback. I would recommend copying and >> pasting it in its entirety; even if you don't (yet) understand how to >> interpret it, we can help you with that. >> >> All the best! >> >> ChrisA > > Hey, > > Here is the full error message: > > Traceback (most recent call last): > File "", line 45, in > IndexError: list index out of range > Which is line 45? Are you entering the code at the Python prompt? From soorajspadmanabhan at gmail.com Sat Jun 6 13:21:41 2020 From: soorajspadmanabhan at gmail.com (emagnun) Date: Sat, 6 Jun 2020 10:21:41 -0700 (PDT) Subject: ElementNotInteracable Exception for Selenium Chrome webdriver Message-ID: I'm using latest python and latest Selenium chrome webdriver. I'm trying to have a simple code to search in youtube but I'm getting the below error. Can anyone help me? File "search.py", line 8, in searchBox.click() Selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable #MyCodeStartsHere from selenium import webdriver driver = webdriver.Chrome() driver.get('https://youtube.com') searchBox = driver.find_element_by_xpath('//*[@id="search"]') if searchBox.is_enabled(): searchBox.click() searchBox.send_keys("youtube test") searchButton = driver.find_element_by_xpath('//*[@id="search-icon-legacy"]/yt-icon') searchButton.click() else: print("What the heck") #MyCodeEndsHere From codemouse92 at outlook.com Sat Jun 6 12:46:26 2020 From: codemouse92 at outlook.com (Jason C. McDonald) Date: Sat, 06 Jun 2020 09:46:26 -0700 Subject: I was really uncomfort with any programming... Message-ID: > I was really uncomfort with any programming,but I need to become efficient in python coding please give any tips to make interest in programming.hope your words will helpful to me.thank you Often the best way to make programming interesting is to use it to build something you care about! There are a number of books that can help with this, such as "Invent Your Own Computer Games with Python" by Al Sweigart (through No Starch Press, or free on his website). In the end, programming isn't "for everyone". Anyone may theoretically learn how to do it, even do it well, but that doesn't mean they'll necessarily enjoy it. I'm actually rather curious why you *need* to become "efficient" (proficient?) in Python? Work requirement? By the way, you should put your message the the BODY of the email, not in the subject line. Keep subject lines short. -- Jason C. McDonald (CodeMouse92) Author | Speaker | Hacker | Time Lord Contact info at: https://indeliblebluepen.com PGP key: https://keyserver.pgp.com id="-x-evo-selection-start-marker"> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: This is a digitally signed message part URL: From tjreedy at udel.edu Sat Jun 6 10:48:34 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 6 Jun 2020 10:48:34 -0400 Subject: Can I have a class with property named "from" In-Reply-To: <85704289-778e-48ed-58d0-8b06fa011dd1@stoneleaf.us> References: <1353363c-116b-48b1-b85a-a7e9d1c5a946o@googlegroups.com> <85704289-778e-48ed-58d0-8b06fa011dd1@stoneleaf.us> Message-ID: On 6/5/2020 6:59 PM, Ethan Furman wrote: > On 06/05/2020 03:15 PM, MRAB wrote: >> On 2020-06-05 22:50, Ethan Furman wrote: > >>> There is no workaround that allows a keyword to be used except as a >>> keyword, other than making it a string.? When faced with this kind of >>> situation myself I use a synonym, like "since", or a translation, >>> like "desde". >>> >> The usual workaround is to append an underscore: 'from_'. > > True, but ick.? ;-)? It's like a dangling preposition. It is, in a sense, standard practice. It is used, for instance, for tcl/tk names that are python keywords. The option / argument name 'in' is written 'in_' when written without quotes in a call. f(in_='.') and f(**{'in':'.'}) have the same effect. -- Terry Jan Reedy From aaron.christensen at gmail.com Sat Jun 6 17:08:02 2020 From: aaron.christensen at gmail.com (Aaron) Date: Sat, 6 Jun 2020 17:08:02 -0400 Subject: When creating a nested dictionary of dataframes, how can I name a dictionary based on a list name of the dataframe? Message-ID: When creating a nested dictionary of dataframes, how can I name a dictionary based on a list name of the dataframe? Given the following: # START CODE import pandas as pd cars = {'Brand': ['Honda Civic','Toyota Corolla'], 'Price': [22000,25000] } df_cars = pd.DataFrame(cars, columns = ['Brand','Price']) trucks = {'Brand': ['GMC Sierra','Ford F-150'], 'Price': [50000,48000] } df_trucks = pd.DataFrame(trucks, columns = ['Brand','Price']) list_of_dfs = [df_cars, df_trucks] # Not exactly sure how this code should be: dict_of_dfs = {} for df in list_of_dfs: dict_of_dfs[name_of_df] = {} # Not sure here dict_of_dfs[name_of_df]['results'] = df # Not sure here # END CODE I am trying to use a for loop that performs the following: # START CODE dict_of_dfs['df_cars'] = {} dict_of_dfs['df_cars']['results'] = df_cars dict_of_dfs['df_trucks'] = {} dict_of_dfs['df_trucks']['results'] = df_trucks # END CODE The above code should produce the following desired output: { 'df_cars': { 'results': Brand Price 0 Honda Civic 22000 1 Toyota Corolla 25000}, 'df_trucks': { 'results': Brand Price 0 GMC Sierra 50000 1 Ford F-150 48000} } I've read multiple threads, used the module varname, and tried using enumerate() but have been unsuccessful. Thank you! From kushal at locationd.net Sat Jun 6 21:20:10 2020 From: kushal at locationd.net (Kushal Kumaran) Date: Sat, 06 Jun 2020 18:20:10 -0700 Subject: ElementNotInteracable Exception for Selenium Chrome webdriver In-Reply-To: (emagnun's message of "Sat, 6 Jun 2020 10:21:41 -0700 (PDT)") References: Message-ID: <87ftb7pt85.fsf@copper.locationd.net> emagnun writes: > I'm using latest python and latest Selenium chrome webdriver. I'm > trying to have a simple code to search in youtube but I'm getting the > below error. Can anyone help me? > > File "search.py", line 8, in searchBox.click() > Selenium.common.exceptions.ElementNotInteractableException: Message: > element not interactable > Try checking what kind of element it finds for you (perhaps by logging searchBox.tag_name). There might be multiple elements matching the search criteria. > #MyCodeStartsHere > from selenium import webdriver > > driver = webdriver.Chrome() > driver.get('https://youtube.com') > > searchBox = driver.find_element_by_xpath('//*[@id="search"]') > if searchBox.is_enabled(): > searchBox.click() > searchBox.send_keys("youtube test") > searchButton = > driver.find_element_by_xpath('//*[@id="search-icon-legacy"]/yt-icon') > searchButton.click() > else: > print("What the heck") > #MyCodeEndsHere -- regards, kushal From __peter__ at web.de Sun Jun 7 04:38:47 2020 From: __peter__ at web.de (Peter Otten) Date: Sun, 07 Jun 2020 10:38:47 +0200 Subject: When creating a nested dictionary of dataframes, how can I name a dictionary based on a list name of the dataframe? References: Message-ID: Aaron wrote: > When creating a nested dictionary of dataframes, how can I name a > dictionary based on a list name of the dataframe? > > Given the following: > > # START CODE > import pandas as pd > > cars = {'Brand': ['Honda Civic','Toyota Corolla'], > 'Price': [22000,25000] > } > df_cars = pd.DataFrame(cars, columns = ['Brand','Price']) > > trucks = {'Brand': ['GMC Sierra','Ford F-150'], > 'Price': [50000,48000] > } > df_trucks = pd.DataFrame(trucks, columns = ['Brand','Price']) > > list_of_dfs = [df_cars, df_trucks] > > # Not exactly sure how this code should be: > dict_of_dfs = {} > for df in list_of_dfs: > dict_of_dfs[name_of_df] = {} # Not sure here > dict_of_dfs[name_of_df]['results'] = df # Not sure here > # END CODE In the general case you can't find the name of a value, so you may start with the names and look up the dataframes in the global namespace: list_of_df_names = ["df_cars", "df_trucks"] dict_of_dfs = { name: {"results": globals()[name]} for name in list_of_df_names } Personally I would probably reorganize your code a bit and avoid the df_... names: import pandas as pd vehicles = dict( cars={ 'Brand': ['Honda Civic','Toyota Corolla'], 'Price': [22000,25000] }, trucks={ 'Brand': ['GMC Sierra','Ford F-150'], 'Price': [50000,48000] } ) dict_of_dfs = { name: {"results": pd.DataFrame(val)} for name, val in vehicles.items() } From miki.tebeka at gmail.com Sun Jun 7 09:15:33 2020 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 7 Jun 2020 06:15:33 -0700 (PDT) Subject: ctypes & allocated memory Message-ID: Hi, Does ctypes, when using restype, frees allocated memory? For example, will the memory allocated by "strdup" be freed after the "del" statement? If not, how can I free it? --- import ctypes libc = ctypes.cdll.LoadLibrary('libc.so.6') strdup = libc.strdup strdup.argtypes = [ctypes.c_char_p] strdup.restype = ctypes.c_char_p out = strdup(b'hello').decode('utf-8') print(out) # hello del out --- Thanks, Miki From miki.tebeka at gmail.com Sun Jun 7 09:39:21 2020 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 7 Jun 2020 06:39:21 -0700 (PDT) Subject: ctypes & allocated memory In-Reply-To: References: Message-ID: <2130a145-406a-46f8-a0f3-763b692f0660o@googlegroups.com> > Does ctypes, when using restype, frees allocated memory? > > For example, will the memory allocated by "strdup" be freed after the "del" statement? If not, how can I free it? I've tried the following program and I'm more confused now :) Can anyone explain the output? --- import ctypes import gc import resource def mem_usage(): return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss libc = ctypes.cdll.LoadLibrary('libc.so.6') strdup = libc.strdup strdup.argtypes = [ctypes.c_char_p] strdup.restype = ctypes.c_char_p size = 1 << 20 print(f'size: {size:,}') data = b'x' * size # 1MB mb = mem_usage() print(f'memory before: {mb:,}') n = 1000 print(f'n: {n:,}') for _ in range(n): strdup(data) gc.collect() ma = mem_usage() diff = ma - mb print(f'memory after: {ma:,}') print(f'diff: {diff:,}') print(f'diff/size: {diff/size:.2f}') --- Which prints --- size: 1,048,576 memory before: 21,556 n: 1,000 memory after: 1,035,180 diff: 1,013,624 diff/size: 0.97 --- From torriem at gmail.com Sun Jun 7 11:32:33 2020 From: torriem at gmail.com (Michael Torrie) Date: Sun, 7 Jun 2020 09:32:33 -0600 Subject: ctypes & allocated memory In-Reply-To: References: Message-ID: <5e30d2c9-d553-6fdf-e3e7-218b7f98ee59@gmail.com> On 6/7/20 7:15 AM, Miki Tebeka wrote: > Hi, > > Does ctypes, when using restype, frees allocated memory? > > For example, will the memory allocated by "strdup" be freed after the "del" statement? If not, how can I free it? I don't think so. I did a quick google search and came up with this discussion, which may be relevant: https://stackoverflow.com/questions/13445568/python-ctypes-how-to-free-memory-getting-invalid-pointer-error > > --- > import ctypes > > libc = ctypes.cdll.LoadLibrary('libc.so.6') > strdup = libc.strdup > strdup.argtypes = [ctypes.c_char_p] > strdup.restype = ctypes.c_char_p > > out = strdup(b'hello').decode('utf-8') > print(out) # hello > del out > --- > > Thanks, > Miki > From hjp-python at hjp.at Sun Jun 7 12:39:51 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 7 Jun 2020 18:39:51 +0200 Subject: Trouble with making modules 'global' In-Reply-To: References: <76a5b723-1cc2-46b6-b6d8-0c3a665f024f@googlegroups.com> Message-ID: <20200607163951.GB8191@hjp.at> On 2020-06-04 04:18:31 -0400, Terry Reedy wrote: > On 6/3/2020 11:48 PM, pythonfm at gmail.com wrote: > > (1) Main.py > > The PEP8 standard is all lower case for modules, leaving TitleCase for > classes, so, for instance, file/module 'editor' contains the definition of > class 'Editor' as its main class. And nobody swoops in to point out that he isn't required to follow PEP 8? I'm disappointed. SCNR. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From hjp-python at hjp.at Sun Jun 7 12:37:02 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 7 Jun 2020 18:37:02 +0200 Subject: Is there some reason that recent Windows 3.6 releases don't included executable nor msi installers? In-Reply-To: References: <4986af9e-0c1e-97d3-e830-268a1cc57684@python.org> <20200528212044.GD17383@hjp.at> Message-ID: <20200607163702.GA8191@hjp.at> On 2020-05-28 20:51:59 -0400, Terry Reedy wrote: > On 5/28/2020 5:20 PM, Peter J. Holzer wrote: [The final "security-only" releases are source-only] > > This seems a rather odd policy to me. > > Not if one considers the intended users. > Do you prefer we not make these releases? No, of couse not (also, as a Linux user I'm not terribly inconvenienced by the lack of Windows binaries). I would prefer that security fixes are distributed in the same form as the original release so that people can apply them without encountering additional hurdles. I assume (perhaps naively) that those releases are tested on the supported platforms. After building and testing them, is that much additional work to put the artifacts on the web site? (I admit that the Windows developers I know aren't very fond of automation, is that a general trait?) hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From caledonian209 at gmail.com Sun Jun 7 15:06:05 2020 From: caledonian209 at gmail.com (Caledonian26) Date: Sun, 7 Jun 2020 12:06:05 -0700 (PDT) Subject: Button press event - event handling and picking: IndexError: list index out of range Message-ID: I have the following command below. The overall aim is to allow the user to select a Y-value by pressing on the bar graph. The colour of each bar should then change depending on what this Y-value is. import pandas as pd import numpy as np from scipy import stats import matplotlib.pyplot as plt import matplotlib.colors np.random.seed(12345) df = pd.DataFrame({"values":[np.random.normal(32000,200000,3650).mean(), np.random.normal(43000,100000,3650).mean(), np.random.normal(43500,140000,3650).mean(), np.random.normal(48000,70000,3650).mean()], "index":[1992,1993,1994,1995]}) standarderrors1992 = stats.sem(np.random.normal(32000,200000,3650)) standarderrors1993 = stats.sem(np.random.normal(43000,100000,3650)) standarderrors1994 = stats.sem(np.random.normal(43500,140000,3650)) standarderrors1995 = stats.sem(np.random.normal(48000,70000,3650)) add1992 = 1.96*standarderrors1992 add1993 = 1.96*standarderrors1993 add1994 = 1.96*standarderrors1994 add1995 = 1.96*standarderrors1995 mean1992 = np.random.normal(32000,200000,3650).mean() mean1993 = np.random.normal(43000,100000,3650).mean() mean1994 = np.random.normal(43500,140000,3650).mean() mean1995 = np.random.normal(48000,70000,3650).mean() labels = [1992,1993,1994,1995] add = [add1992,add1992,add1994,add1995] 1. This first part organises the raw data. limits = [] def onclick(event): plt.cla() plt.bar(df["index"].values,df["values"].values,align='center', alpha=0.5,yerr=add) plt.xticks(labels) limit = event.ydata limits.append(limit) if len(limits) >= 1: plt.gcf().canvas.mpl_disconnect(plt.gcf().canvas.mpl_connect('button_press_event', onclick)) plt.gcf().canvas.mpl_connect('button_press_event', onclick) 2. This next part allows the user to press on the graph to select a Y value. This should be assigned to the variable 'limits' dict = {mean1992:add1992,mean1993:add1993,mean1994:add1994,mean1995:add1995} colourofbars = [] for key,value in dict.items(): if limits[0] > (key+(value)): colour = 1 colourofbars.append(colour) elif limits[0] < (key-(value)): colour = 0 colourofbars.append(colour) elif (limits[0] < (key+(value))) & (limits[0] > (key-(value))): colour = ((key+(value))-limits[0])/((key+value)-(key-value)) colourofbars.append(colour) df["colourofbars"] = colourofbars 3. Here, the list 'colourofbars' is appended based on the data above, and added as a column to the dataframe 'df'. cmap = plt.cm.rainbow norm = matplotlib.colors.Normalize(vmin=1.5, vmax=4.5) plt.bar(df["index"].values,df["values"].values,color=cmap(norm(df["colourofbars"].values)),align='center', alpha=0.5,yerr=add) plt.xticks(labels) sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm) plt.gcf().colorbar(sm) plt.show() 4. Here, a different colour is assigned to each bar in the bar chart depending on the values in the column 'colourofbars'. I then try to plot a legend showing this colour gradient scale. However, I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? From barry at barrys-emacs.org Sun Jun 7 16:25:27 2020 From: barry at barrys-emacs.org (Barry) Date: Sun, 7 Jun 2020 21:25:27 +0100 Subject: ctypes & allocated memory In-Reply-To: References: Message-ID: <0CFA68D8-6E92-4EDB-A4F2-027547D6ABC9@barrys-emacs.org> > On 7 Jun 2020, at 14:23, Miki Tebeka wrote: > > ?Hi, > > Does ctypes, when using restype, frees allocated memory? > > For example, will the memory allocated by "strdup" be freed after the "del" statement? If not, how can I free it? See https://linux.die.net/man/3/strdup that tells you to use free() to delete memory allocated by strdup. You must remember the result of strdup and free it at an appropriate time. Barry > > --- > import ctypes > > libc = ctypes.cdll.LoadLibrary('libc.so.6') > strdup = libc.strdup > strdup.argtypes = [ctypes.c_char_p] > strdup.restype = ctypes.c_char_p > > out = strdup(b'hello').decode('utf-8') > print(out) # hello > del out > --- > > Thanks, > Miki > -- > https://mail.python.org/mailman/listinfo/python-list > From aaron.christensen at gmail.com Sun Jun 7 17:48:48 2020 From: aaron.christensen at gmail.com (Aaron) Date: Sun, 7 Jun 2020 17:48:48 -0400 Subject: When creating a nested dictionary of dataframes, how can I name a dictionary based on a list name of the dataframe? In-Reply-To: References: Message-ID: Thank you for the help! Based on your response/recommendation, I am thinking that my entire approach to solving my problem is very poor. I am trying to pull slices from a dataframe, store them in a nested dictionary, retrieve them, perform calculations, store the results in the same nested dictionary (hence why I need to know the actual name of each nested dictionary), retrieve the results, then format the results. LOL that looks so bad when I think about it out loud. What I think I should be doing is pull my first slice from a dataframe, perform my calculations, then format those results in my desired final output; take my second, third, fourth, etc. slices and then just repeat that same pattern instead of what I initially thought I should do. Is there a standard approach for evaluating particular slices of dataframes or does it always depend on the situation? On Sun, Jun 7, 2020 at 4:39 AM Peter Otten <__peter__ at web.de> wrote: > Aaron wrote: > > > When creating a nested dictionary of dataframes, how can I name a > > dictionary based on a list name of the dataframe? > > > > Given the following: > > > > # START CODE > > import pandas as pd > > > > cars = {'Brand': ['Honda Civic','Toyota Corolla'], > > 'Price': [22000,25000] > > } > > df_cars = pd.DataFrame(cars, columns = ['Brand','Price']) > > > > trucks = {'Brand': ['GMC Sierra','Ford F-150'], > > 'Price': [50000,48000] > > } > > df_trucks = pd.DataFrame(trucks, columns = ['Brand','Price']) > > > > list_of_dfs = [df_cars, df_trucks] > > > > # Not exactly sure how this code should be: > > dict_of_dfs = {} > > for df in list_of_dfs: > > dict_of_dfs[name_of_df] = {} # Not sure here > > dict_of_dfs[name_of_df]['results'] = df # Not sure here > > # END CODE > > In the general case you can't find the name of a value, so you may start > with the names and look up the dataframes in the global namespace: > > list_of_df_names = ["df_cars", "df_trucks"] > dict_of_dfs = { > name: {"results": globals()[name]} > for name in list_of_df_names > } > > Personally I would probably reorganize your code a bit and avoid the > df_... > names: > > import pandas as pd > > vehicles = dict( > cars={ > 'Brand': ['Honda Civic','Toyota Corolla'], > 'Price': [22000,25000] > }, > trucks={ > 'Brand': ['GMC Sierra','Ford F-150'], > 'Price': [50000,48000] > } > ) > > dict_of_dfs = { > name: {"results": pd.DataFrame(val)} > for name, val in vehicles.items() > } > > > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Sun Jun 7 18:24:22 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 8 Jun 2020 10:24:22 +1200 Subject: Button press event - event handling and picking: IndexError: list index out of range In-Reply-To: References: Message-ID: <7a0d18a1-1e77-1ca8-b5a0-4665915ad2f3@DancesWithMice.info> On 8/06/20 7:06 AM, Caledonian26 wrote: ... > However, I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? When things go wrong, Python tries to be helpful by providing a "traceback". Please copy-paste the entire traceback, to help us help you. The error-message says that (somewhere) a list is being used *but* the index is pointing to an element that does not exist, eg the fifth element of a list that contains only three members. Short answer: What you could do, is add a temporary print() to show you the exact value of the list index. Thus, giving you a pointer/where to back-track, to find the source of the problem... The longer answer: learning to use a debugger or a 'visual' IDE/web-tool. -- Regards =dn From python at mrabarnett.plus.com Sun Jun 7 18:38:02 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 7 Jun 2020 23:38:02 +0100 Subject: Button press event - event handling and picking: IndexError: list index out of range In-Reply-To: <7a0d18a1-1e77-1ca8-b5a0-4665915ad2f3@DancesWithMice.info> References: <7a0d18a1-1e77-1ca8-b5a0-4665915ad2f3@DancesWithMice.info> Message-ID: <39a1f860-a6d5-c700-98f3-1a0c97519f32@mrabarnett.plus.com> On 2020-06-07 23:24, DL Neil via Python-list wrote: > On 8/06/20 7:06 AM, Caledonian26 wrote: > ... > >> However, I keep getting the error: IndexError: list index out of range. Could anyone give me a helping hand as to where I am going wrong? > > > When things go wrong, Python tries to be helpful by providing a > "traceback". Please copy-paste the entire traceback, to help us help you. > > The error-message says that (somewhere) a list is being used *but* the > index is pointing to an element that does not exist, eg the fifth > element of a list that contains only three members. > > Short answer: What you could do, is add a temporary print() to show you > the exact value of the list index. Thus, giving you a pointer/where to > back-track, to find the source of the problem... > > The longer answer: learning to use a debugger or a 'visual' IDE/web-tool. > FYI, that's the same good advice that ChrisA gave yesterday in reply to the same post. See the thread "Applied Data Science with Python - Assignment 2.3: clicking on chart to select Y values". From PythonList at DancesWithMice.info Sun Jun 7 18:43:04 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 8 Jun 2020 10:43:04 +1200 Subject: Button press event - event handling and picking: IndexError: list index out of range In-Reply-To: <39a1f860-a6d5-c700-98f3-1a0c97519f32@mrabarnett.plus.com> References: <7a0d18a1-1e77-1ca8-b5a0-4665915ad2f3@DancesWithMice.info> <39a1f860-a6d5-c700-98f3-1a0c97519f32@mrabarnett.plus.com> Message-ID: <69229c83-9452-5e16-3551-5478d9dd2390@DancesWithMice.info> On 8/06/20 10:38 AM, MRAB wrote: > On 2020-06-07 23:24, DL Neil via Python-list wrote: >> On 8/06/20 7:06 AM, Caledonian26 wrote: >> ... >> >>> However, I keep getting the error: IndexError: list index out of >>> range. Could anyone give me a helping hand as to where I am going wrong? >> >> >> When things go wrong, Python tries to be helpful by providing a >> "traceback". Please copy-paste the entire traceback, to help us help you. >> >> The error-message says that (somewhere) a list is being used *but* the >> index is pointing to an element that does not exist, eg the fifth >> element of a list that contains only three members. >> >> Short answer: What you could do, is add a temporary print() to show you >> the exact value of the list index. Thus, giving you a pointer/where to >> back-track, to find the source of the problem... >> >> The longer answer: learning to use a debugger or a 'visual' IDE/web-tool. >> > FYI, that's the same good advice that ChrisA gave yesterday in reply to > the same post. See the thread "Applied Data Science with Python - > Assignment 2.3: clicking on chart to select Y values". Apologies @MRAB, didn't realise the duplication. I think I came to that thread late, noticed @Chris (and yourself?) had responded, deleted, and moved-on. -- Regards =dn From torriem at gmail.com Sun Jun 7 23:30:30 2020 From: torriem at gmail.com (Michael Torrie) Date: Sun, 7 Jun 2020 21:30:30 -0600 Subject: ctypes & allocated memory In-Reply-To: <0CFA68D8-6E92-4EDB-A4F2-027547D6ABC9@barrys-emacs.org> References: <0CFA68D8-6E92-4EDB-A4F2-027547D6ABC9@barrys-emacs.org> Message-ID: <27759667-28ee-fe29-e495-4ed52256cba4@gmail.com> On 6/7/20 2:25 PM, Barry wrote: >> Does ctypes, when using restype, frees allocated memory? >> >> For example, will the memory allocated by "strdup" be freed after the "del" statement? If not, how can I free it? > > See https://linux.die.net/man/3/strdup that tells you to use free() to delete memory allocated by strdup. > > You must remember the result of strdup and free it at an appropriate time. But the problem is that by specifying the type as ctypes.c_char_p, ctypes will hide that pointer from you and return a Python object instead. I'm not sure how ctypes is doing it under the hood, but I suspect ctypes is doing it's own strdup of the string on conversion, and managing that memory, but the original pointer ends up being lost and leaking memory. The stack exchange link I posted suggests that have ctypes give you a void * pointer, and then cast that to give you a python string while still having the original pointer to free. Is this correct? From miki.tebeka at gmail.com Mon Jun 8 01:34:05 2020 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Sun, 7 Jun 2020 22:34:05 -0700 (PDT) Subject: ctypes & allocated memory In-Reply-To: References: <0CFA68D8-6E92-4EDB-A4F2-027547D6ABC9@barrys-emacs.org> <27759667-28ee-fe29-e495-4ed52256cba4@gmail.com> Message-ID: <3c960145-3028-4c7c-b024-aab82b80a897o@googlegroups.com> Hi, > But the problem is that by specifying the type as ctypes.c_char_p, > ctypes will hide that pointer from you and return a Python object > instead. I'm not sure how ctypes is doing it under the hood, but I > suspect ctypes is doing it's own strdup of the string on conversion, and > managing that memory, but the original pointer ends up being lost and > leaking memory. Yes, the problem with my code I posted is that resource.getrusage report the Python allocated memory. Once I've changed to psutil.Process().memory_info().rss I see the memory leak. The code now looks like: --- ... strdup.restype = ctypes.c_void_p free = libc.free free.argtypes = [ctypes.c_void_p] ... for _ in range(n): o = strdup(data) s = ctypes.string_at(o).decode('utf-8') free(o) --- This seems to fix the leak. Thanks From devendrardhond at gmail.com Sat Jun 6 23:45:19 2020 From: devendrardhond at gmail.com (Devendra Dhond) Date: Sun, 7 Jun 2020 09:15:19 +0530 Subject: Error in PIP install packages Message-ID: R/sir, I am facing too much errors during pip installing. Deserialization error And much more in red errors. Pip upgrading error Please help me out.. I want to uninstall complete python all pip and freshly download python and install various packages. Suggest me which version I need to download And sequence of package installing. I want to install all necessary packages.. I.e. playsound Pygame Face_recogntion Wheel Numpy Dlib Regards, Devendra Dhond From purelyconstructive at gmail.com Sun Jun 7 20:13:49 2020 From: purelyconstructive at gmail.com (purelyconstructive .) Date: Sun, 7 Jun 2020 18:13:49 -0600 Subject: Installation Problems Message-ID: Hello, I'm sorry if this isn't the correct email to send this to, but I am new to Python and I am having a very hard time getting it installed correctly no matter what version I try. My computer specs are: Toshiba Satellite C55t-B Laptop Intel Celeron CPU N2830 @ 2.16GHz 4 GB RAM 64-bit Windows 8 First, I tried installing the 64-bit version of Python 3.8.3, but anytime I try to open it, whether by clicking on its shortcut or running it in a command line, a dialog box pops up with the following error: "The application was unable to start correctly (0xc000007b). Click OK to close the application." After searching for a solution, I came across this Stack Overflow post that covers what seems to be a similar problem: https://stackoverflow.com/questions/20650596/cannot-open-python-error-0xc000007b I tried all of the solutions offered there to no avail (e.g.: uninstalling and reinstalling it several times with various settings, changing the PATH in Environmental Variables to point to Python38, updating the Microsoft Visual C++ Redistributable Package, etc.). None of it worked, so I eventually decided to try the 32-bit version instead. This generally seems to work as Python will now open just fine when I click on its shortcut or run it in a command line. However, IDLE won't open. Nothing comes up when I click on its shortcut... I searched for a solution again and came across this Stack Overflow post with what seems to be a similar problem: https://stackoverflow.com/questions/7509579/python-idle-won%C2%B4t-start I've tried all of these solutions too, but none of them worked (e.g.: uninstalling and reinstalling several times with different settings, checking PATH in Environmental Variables, adding a TCL_LIBRARY entry to Environmental Variables that points to tcl8.6, "repairing" the installation under Uninstall Programs in Windows, etc.). After looking at the section on IDLE within the Python Documentation, I came across the command: "python -m idlelib" When I try it I get the error: "** IDLE can't import Tkinter. Your Python may not be configured for Tk. **" More searches on how to fix this problem have led me to try out all sorts of different things similar to what I have described above, but I feel like something on my computer is not allowing Python to install correctly (even when it seems to) and I can't pin-point what exactly it is. Any help in this matter would be greatly appreciated. Sincerely, Sage From zljubisic at gmail.com Mon Jun 8 15:53:08 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Mon, 8 Jun 2020 12:53:08 -0700 (PDT) Subject: Can I have a class with property named "from" In-Reply-To: References: <1353363c-116b-48b1-b85a-a7e9d1c5a946o@googlegroups.com> <85704289-778e-48ed-58d0-8b06fa011dd1@stoneleaf.us> Message-ID: <9e1c1bee-f523-440c-a055-1121c10f0940o@googlegroups.com> Well the problem that I am facing with is, that I have to establish interface between python and outer system. Original question was about creation of input object (data that I have received from outer system). If I accept recommendation to use "from_" instead of "from", it could work, for processing input, because processing is under my control. However, my process will create output object that I should json serialize and return back to outer system as a response to the input. If I will have "from_" object property instead of "from", I believe that I should write a custom object to json serializer in order to support changing names from "from_" to "from". From zljubisic at gmail.com Mon Jun 8 16:10:57 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Mon, 8 Jun 2020 13:10:57 -0700 (PDT) Subject: Do I need setters/getters in python? Message-ID: Consider this code: class SetGet: _x = 1 @property def x(self): return self._x @x.setter def x(self, value): self._x = value class Dynamic: x = 1 if __name__ == '__main__': a = SetGet() print(f'x = {a.x}') a.x = 2 print(f'x = {a.x}') a = Dynamic() print(f'x = {a.x}') a.x = 2 print(f'x = {a.x}') Output is the same: x = 1 x = 2 x = 1 x = 2 If I have public property and I am not doing any transformation with data that is used to sat variable value... do I need a setter/getter at all? Is there any difference if property "_x" is defined as class property as in the case in SetGet class, or if I have put it in the SetGet inite like: class SetGet: def __init__(): self._x = 1 (the rest is the same). When I said "difference", I mean except the fact that in init I can change "_x"'s value at the time of class construction. Regards From tjreedy at udel.edu Mon Jun 8 16:27:14 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 8 Jun 2020 16:27:14 -0400 Subject: Do I need setters/getters in python? In-Reply-To: References: Message-ID: On 6/8/2020 4:10 PM, zljubisic at gmail.com wrote: > Consider this code: > > > class SetGet: > > _x = 1 > > @property > def x(self): > return self._x > > @x.setter > def x(self, value): > self._x = value > > > class Dynamic: > > x = 1 > > if __name__ == '__main__': > > a = SetGet() > > print(f'x = {a.x}') > a.x = 2 > print(f'x = {a.x}') > > a = Dynamic() > print(f'x = {a.x}') > a.x = 2 > print(f'x = {a.x}') > > > Output is the same: > > x = 1 > x = 2 > x = 1 > x = 2 > > If I have public property and I am not doing any transformation with data that is used to sat variable value... do I need a setter/getter at all? No! -- Terry Jan Reedy From souvik.viksou at gmail.com Mon Jun 8 20:50:28 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Tue, 9 Jun 2020 06:20:28 +0530 Subject: Error in PIP install packages In-Reply-To: References: Message-ID: Can you paste the complete error message that you got on running pip? Souvik flutter dev On Mon, Jun 8, 2020, 10:10 PM Devendra Dhond wrote: > R/sir, > > > > I am facing too much errors during pip installing. > > Deserialization error > > And much more in red errors. > > Pip upgrading error > > > > Please help me out.. > > > > I want to uninstall complete python all pip and freshly download python and > install various packages. > > > > Suggest me which version I need to download > > And sequence of package installing. > > I want to install all necessary packages.. > > I.e. playsound > > Pygame > > Face_recogntion > > Wheel > > Numpy > > Dlib > > > > Regards, > > Devendra Dhond > -- > https://mail.python.org/mailman/listinfo/python-list > From adam.preble at gmail.com Tue Jun 9 03:26:43 2020 From: adam.preble at gmail.com (Adam Preble) Date: Tue, 9 Jun 2020 00:26:43 -0700 (PDT) Subject: Is CONTINUE_LOOP still a thing? Message-ID: <472493e2-0062-4a1b-8f6f-92a269031403o@googlegroups.com> I got to the point of trying to implement continue in my own interpreter project and was surprised when my for-loop just used some jumps to manage its control flow. Actually, I hoped for something else; I don't have logic in my code generation to track jump positions. I kind of hoped there was some CONTINUE opcode with some extra logic I could add at run time to just kind of do it. (that is my own problem and I know there is no such thing as a free lunch, but it's 2AM and I want to hope!) Well, I found CONTINUE_LOOP, which applies for for-loops, but 3.6.8 sure doesn't emit it for pretty basic stuff: >>> def for_continue(): ... a = 0 ... for i in range(0, 3, 1): ... if i == 2: ... continue ... a += i ... else: ... a += 10 ... return a ... >>> for_continue() 11 >>> dis(for_continue) 2 0 LOAD_CONST 1 (0) 2 STORE_FAST 0 (a) 3 4 SETUP_LOOP 46 (to 52) 6 LOAD_GLOBAL 0 (range) 8 LOAD_CONST 1 (0) 10 LOAD_CONST 2 (3) 12 LOAD_CONST 3 (1) 14 CALL_FUNCTION 3 16 GET_ITER >> 18 FOR_ITER 22 (to 42) 20 STORE_FAST 1 (i) 4 22 LOAD_FAST 1 (i) 24 LOAD_CONST 4 (2) 26 COMPARE_OP 2 (==) 28 POP_JUMP_IF_FALSE 32 5 30 JUMP_ABSOLUTE 18 6 >> 32 LOAD_FAST 0 (a) 34 LOAD_FAST 1 (i) 36 INPLACE_ADD 38 STORE_FAST 0 (a) 40 JUMP_ABSOLUTE 18 >> 42 POP_BLOCK 8 44 LOAD_FAST 0 (a) 46 LOAD_CONST 5 (10) 48 INPLACE_ADD 50 STORE_FAST 0 (a) 9 >> 52 LOAD_FAST 0 (a) 54 RETURN_VALUE The place where a CONTINUE_LOOP could have made sense would be at address 30 for that JUMP_ABSOLUTE. That'll go back to a FOR_ITER, as CONTINUE_LOOP implies it *must* do. I'm just guessing that at some point, somebody concluded there wasn't anything special about having that opcode over absolute jumps and it got abandoned. I wanted to check if my notions were correct or if there's some gotcha where having that over other things makes sense. From joepareti54 at gmail.com Tue Jun 9 05:44:46 2020 From: joepareti54 at gmail.com (joseph pareti) Date: Tue, 9 Jun 2020 11:44:46 +0200 Subject: From an existing Pandas DataFrame, how can I create a summary DataFrame based on the union of overlapping date ranges (given a start and an end date) and an additional column? In-Reply-To: References: Message-ID: i gave it a shot, see attached Am Mi., 3. Juni 2020 um 23:38 Uhr schrieb Aaron : > Hello, > > Given a dateframe with trips made by employees of different companies, I am > trying to generate a new dataframe with only the company names. I am > looking to combine the overlapping travel times from employees of the SAME > company into a single row. If there are no overlapping travel times, then > that row just transfers over as-is. When there are overlapping travel > times, then the following will happen: > > --The name field is removed b/c that is no longer relevant (company name > stays), the Depart date will be the earliest date of any of the trip dates > regardless of the employee, the Return date will be the latest date of any > of the trip dates regardless of the employee, the charges for the trip will > be summed > > For example, if trips had dates 01/01/20 - 01/31/20, 01/15/20 - 02/15/20, > 02/01-20 - 02/28/20, then all three would be combined. The starting date > will be 1/1/20 and ending as of 2/28/20. Basically, the company was on > that trip from start to finish? kinda like a relay run handing off the > baton. Also, the charges will be summed for each of those trips and > transferred over to the single row. > > Here is the starting dataframe code/output (note: the row order is > typically not already sorted by company name as in this example): > > import pandas as pd > > > emp_trips = {'Name': ['Bob','Joe','Sue','Jack', 'Henry', 'Frank', > 'Lee', 'Jack'], > 'Company': ['ABC', 'ABC', 'ABC', 'HIJ', 'HIJ', 'DEF', 'DEF', > 'DEF'], > 'Depart' : ['01/01/2020', '01/01/2020', '01/06/2020', > '01/01/2020', '05/01/2020', '01/13/2020', '01/12/2020', '01/14/2020'], > 'Return' : ['01/31/2020', '02/15/2020', '02/20/2020', > '03/01/2020', '05/05/2020', '01/15/2020', '01/30/2020', '02/02/2020'], > 'Charges': [10.10, 20.25, 30.32, 40.00, 50.01, 60.32, 70.99, 80.87] > } > > df = pd.DataFrame(emp_trips, columns = ['Name', 'Company', 'Depart', > 'Return', 'Charges']) > # Convert to date format > df['Return']= pd.to_datetime(df['Return']) > df['Depart']= pd.to_datetime(df['Depart']) > > Name Company Depart Return Charges0 Bob ABC > 2020-01-01 2020-01-31 10.101 Joe ABC 2020-01-01 2020-02-15 > 20.252 Sue ABC 2020-01-06 2020-02-20 30.323 Jack HIJ > 2020-01-01 2020-03-01 40.004 Henry HIJ 2020-05-01 2020-05-05 > 50.015 Frank DEF 2020-01-13 2020-01-15 60.326 Lee DEF > 2020-01-12 2020-01-30 70.997 Jack DEF 2020-01-14 2020-02-02 > 80.87 > > And, here is the desired/generated dataframe: > > Company Depart Return Charges0 ABC 01/01/2020 > 02/20/2020 60.671 HIJ 01/01/2020 03/01/2020 40.002 HIJ > 05/01/2020 05/05/2020 50.013 DEF 01/12/2020 02/02/2020 > 212.18 > > I have been trying to use a combination of sorting and grouping but > the best I've achieved is reordering the dataframe. Even though I am > able to sort/group based on values, I still run into the issues of > finding overlapping date ranges and pulling out all trips based on a > single company per aggregate/overlapping date range. > > Thank you in advance for any help! > > Aaron > -- > https://mail.python.org/mailman/listinfo/python-list > -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 From tjreedy at udel.edu Tue Jun 9 10:10:58 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 9 Jun 2020 10:10:58 -0400 Subject: Is CONTINUE_LOOP still a thing? In-Reply-To: <472493e2-0062-4a1b-8f6f-92a269031403o@googlegroups.com> References: <472493e2-0062-4a1b-8f6f-92a269031403o@googlegroups.com> Message-ID: On 6/9/2020 3:26 AM, Adam Preble wrote: > Well, I found CONTINUE_LOOP In opcode.py for 3.6.8 with value 119, annotated as an absolute jump. Everything in this file is use-at-your-own-risk internal cpython detail, subject to change with any release. > 3.6.8 sure doesn't emit it for pretty basic stuff: It is gone in 3.8.3, along with others. I believe a core developer who added new opcodes removed unused opcodes after counting emissions of opcodes in compiler code. As with Python, deletion of unused items is not guaranteed to be immediate. SETUP_LOOP, which was used in 3.6, is gone also. -- Terry Jan Reedy From cousinstanley at gmail.com Tue Jun 9 11:00:43 2020 From: cousinstanley at gmail.com (Cousin Stanley) Date: Tue, 09 Jun 2020 08:00:43 -0700 Subject: Button press event - event handling and picking: IndexError: list index out of range References: Message-ID: Caledonian26 wrote: .... > However, I keep getting the error: > > IndexError: list index out of range. > > Could anyone give me a helping hand > as to where I am going wrong? > I appended a single arbitrary value for limits since the limits list had not been previously initialized .... .... colourofbars = [ ] for key , value in dict_means.items() : limits.append( 3000 ) if limits[ 0 ] > ( key + ( value ) ) : .... This fix gets past the index out of range error and produces a plot which might let you proceed to the next problem you might encounter .... -- Stanley C. Kitching Human Being Phoenix, Arizona From jjenne025 at go.tahomasd.us Tue Jun 9 13:31:36 2020 From: jjenne025 at go.tahomasd.us (Joseph Jenne) Date: Tue, 9 Jun 2020 10:31:36 -0700 Subject: Python-list Digest, Vol 201, Issue 9 In-Reply-To: References: Message-ID: <32e66964-a05c-7513-0ca6-856e4ad30d50@go.tahomasd.us> On 2020-06-09 09:00, zljubisic at gmail.com wrote: > Well the problem that I am facing with is, that I have to establish interface between python and outer system. > > Original question was about creation of input object (data that I have received from outer system). If I accept recommendation to use "from_" instead of "from", it could work, for processing input, because processing is under my control. > > However, my process will create output object that I should json serialize and return back to outer system as a response to the input. If I will have "from_" object property instead of "from", I believe that I should write a custom object to json serializer in order to support changing names from "from_" to "from". It should be possible to name it from_ and then insert it into the __dict__ as 'from', although a custom serializer would probably be preferable from a design standpoint. From rhodri at kynesim.co.uk Tue Jun 9 14:56:36 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 9 Jun 2020 19:56:36 +0100 Subject: Python-list Digest, Vol 201, Issue 9 In-Reply-To: <32e66964-a05c-7513-0ca6-856e4ad30d50@go.tahomasd.us> References: <32e66964-a05c-7513-0ca6-856e4ad30d50@go.tahomasd.us> Message-ID: <6a166b44-8422-7c21-5071-2545a3cc0769@kynesim.co.uk> On 09/06/2020 18:31, Joseph Jenne via Python-list wrote: > On 2020-06-09 09:00, zljubisic at gmail.com wrote: > >> Well the problem that I am facing with is, that I have to establish >> interface between python and outer system. >> >> Original question was about creation of input object (data that I have >> received from outer system). If I accept recommendation to use "from_" >> instead of "from", it could work, for processing input, because >> processing is under my control. >> >> However, my process will create output object that I should json >> serialize and return back to outer system as a response to the input. >> If I will have "from_" object property instead of "from", I believe >> that I should write a custom object to json serializer in order to >> support changing names from "from_" to "from". > > It should be possible to name it from_ and then insert it into the > __dict__ as 'from', although a custom serializer > would probably be preferable from a design standpoint. Might it be simpler to use a dict from the start? You could have a dictionary key of "from" without any problems. -- Rhodri James *-* Kynesim Ltd From lukasz at langa.pl Tue Jun 9 17:59:21 2020 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Tue, 9 Jun 2020 23:59:21 +0200 Subject: [RELEASE] Python 3.9.0b3 is now available for testing Message-ID: On behalf of the entire Python development community, and the currently serving Python release team in particular, I?m pleased to announce the release of Python 3.9.0b3. Get it here: https://www.python.org/downloads/release/python-390b3/ Wait, Beta 3? What happened to Beta 2? Beta 2? Speak of him no more. We disappeared him. He was a bad release. Truly awful. I get shivers just thinking about it. Never mention that name again in this house. I mean, long story short, in Beta 2 you couldn?t do urllib.request.urlopen("https://www.python.org").read() because it wouldn?t find root certificates due to a bug . Since this was a problem only apparent on an installed Python, it wasn?t identified by unit tests and was only found by Ned while he was testing his Mac installer. By the time we learned of the severity of the bug I already tagged and published the release on python.org . That?s why we couldn?t just re-do the release under the same version. Sorry for the trouble. We?re tweaking our release process to catch this problem sooner in future releases. Now, back to regular programming? This is a beta preview of Python 3.9 Python 3.9 is still in development. This release, 3.9.0b3, is the third of five planned beta release previews. Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their projects to support the new feature release. Call to action We strongly encourage maintainers of third-party Python projects to test with 3.9 during the beta phase and report issues found to the Python bug tracker as soon as possible. While the release is planned to be feature complete entering the beta phase, it is possible that features may be modified or, in rare cases, deleted up until the start of the release candidate phase (2020-08-10). Our goal is have no ABI changes after beta 5 and as few code changes as possible after 3.9.0rc1, the first release candidate. To achieve that, it will be extremely important to get as much exposure for 3.9 as possible during the beta phase. Please keep in mind that this is a preview release and its use is not recommended for production environments. Major new features of the 3.9 series, compared to 3.8 Some of the new major new features and changes in Python 3.9 are: PEP 584 , Union Operators in dict PEP 585 , Type Hinting Generics In Standard Collections PEP 593 , Flexible function and variable annotations PEP 602 , Python adopts a stable annual release cadence PEP 616 , String methods to remove prefixes and suffixes PEP 617 , New PEG parser for CPython BPO 38379 , garbage collection does not block on resurrected objects; BPO 38692 , os.pidfd_open added that allows process management without races and signals; BPO 39926 , Unicode support updated to version 13.0.0; BPO 1635741 , when Python is initialized multiple times in the same process, it does not leak memory anymore; A number of Python builtins (range, tuple, set, frozenset, list, dict) are now sped up using PEP 590 vectorcall; A number of Python modules (_abc, audioop, _bz2, _codecs, _contextvars, _crypt, _functools, _json, _locale, operator, resource, time, _weakref) now use multiphase initialization as defined by PEP 489 ; A number of standard library modules (audioop, ast, grp, _hashlib, pwd, _posixsubprocess, random, select, struct, termios, zlib) are now using the stable ABI defined by PEP 384 . (Hey, fellow core developer, if a feature you find important is missing from this list, let ?ukasz know .) The next pre-release, the fourth beta release of Python 3.9, will be 3.9.0b4. It is currently scheduled for 2020-06-29. More resources Online Documentation PEP 596 , 3.9 Release Schedule Report bugs at https://bugs.python.org . Help fund Python and its community . Your friendly release team, Ned Deily @nad Steve Dower @steve.dower ?ukasz Langa @ambv From urs at isnogud.escape.de Wed Jun 10 06:01:43 2020 From: urs at isnogud.escape.de (Urs Thuermann) Date: 10 Jun 2020 12:01:43 +0200 Subject: Appending to and removing from numpy arrays Message-ID: Hi, is it possible to append data to or remove data from numpy arrays like Python lists? I have some code where I currently use lists and often do things like a.append(elem) a += b del a[:-n] I am thinking of changing to numpy arrays but it seems I cannot modify numpy arrays like this in-place, but instead I need to create a new array and assign that: a = np.append(a, elem) a = np.append(a, b) a = a[-n:] Or do I miss something here? urs From just4now666666 at gmail.com Wed Jun 10 09:32:30 2020 From: just4now666666 at gmail.com (elisha hollander) Date: Wed, 10 Jun 2020 16:32:30 +0300 Subject: Turning pygame apps into add-ons Message-ID: I have a folder with my pygame apps, I want to build a program to have a nice interface to access those apps from, I want it to be like an actual computer, so, I need it to open the apps as rect of something not as external apps. Is there a way to do it without changing all the codes? (I can import the app from the app file, but it won't open in the interface) From robin at reportlab.com Wed Jun 10 09:46:59 2020 From: robin at reportlab.com (Robin Becker) Date: Wed, 10 Jun 2020 14:46:59 +0100 Subject: pyinstaller Message-ID: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> I'm sure this has come up before, but a tiny pyinstaller created exe is being seen as malware by windows 10. Is there any way to create simple single file applications which don't get this treatment? The intended users are unlikely to understand how to adjust the scanner to whitelist the application. -- Robin Becker From rosuav at gmail.com Wed Jun 10 10:02:58 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Jun 2020 00:02:58 +1000 Subject: pyinstaller In-Reply-To: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> Message-ID: On Wed, Jun 10, 2020 at 11:49 PM Robin Becker wrote: > > I'm sure this has come up before, but a tiny pyinstaller created exe is being seen as malware by windows 10. > > Is there any way to create simple single file applications which don't get this treatment? > > The intended users are unlikely to understand how to adjust the scanner to whitelist the application. Tell them to install Python from an official source, and then distribute your application as a single .py (or .pyw) file. Problem solved. ChrisA From souvik.viksou at gmail.com Wed Jun 10 10:18:27 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Wed, 10 Jun 2020 19:48:27 +0530 Subject: pyinstaller In-Reply-To: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> Message-ID: You might also try py2exe, in that way the user doesn't need to install python in her/his computer. Souvik flutter dev On Wed, Jun 10, 2020, 7:18 PM Robin Becker wrote: > I'm sure this has come up before, but a tiny pyinstaller created exe is > being seen as malware by windows 10. > > Is there any way to create simple single file applications which don't get > this treatment? > > The intended users are unlikely to understand how to adjust the scanner to > whitelist the application. > -- > Robin Becker > -- > https://mail.python.org/mailman/listinfo/python-list > From robin at reportlab.com Wed Jun 10 10:37:13 2020 From: robin at reportlab.com (Robin Becker) Date: Wed, 10 Jun 2020 15:37:13 +0100 Subject: pyinstaller In-Reply-To: References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> Message-ID: <5aa459a1-d8a1-44f1-4622-1cafcbce1c6c@everest.reportlab.co.uk> On 10/06/2020 15:18, Souvik Dutta wrote: > You might also try py2exe, in that way the user doesn't need to install > python in her/his computer. > > Souvik flutter dev > > On Wed, Jun 10, 2020, 7:18 PM Robin Becker wrote: > >> I'm sure this has come up before, but a tiny pyinstaller created exe is >> being seen as malware by windows 10. ........I think we used py2exe previously and I guess that will have the same problems as pyinstaller. -- Robin Becker From cspealma at redhat.com Wed Jun 10 10:50:42 2020 From: cspealma at redhat.com (Calvin Spealman) Date: Wed, 10 Jun 2020 10:50:42 -0400 Subject: pyinstaller In-Reply-To: References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> Message-ID: On Wed, Jun 10, 2020 at 10:06 AM Chris Angelico wrote: > On Wed, Jun 10, 2020 at 11:49 PM Robin Becker wrote: > > > > I'm sure this has come up before, but a tiny pyinstaller created exe is > being seen as malware by windows 10. > > > > Is there any way to create simple single file applications which don't > get this treatment? > > > > The intended users are unlikely to understand how to adjust the scanner > to whitelist the application. > > Tell them to install Python from an official source, and then > distribute your application as a single .py (or .pyw) file. Problem > solved. > This is in no way a solution or a reasonable way to distribute software to end-users. Please don't give non-answers. ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] TRIED. TESTED. TRUSTED. From rosuav at gmail.com Wed Jun 10 10:59:09 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Jun 2020 00:59:09 +1000 Subject: pyinstaller In-Reply-To: References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> Message-ID: On Thu, Jun 11, 2020 at 12:51 AM Calvin Spealman wrote: > > > > On Wed, Jun 10, 2020 at 10:06 AM Chris Angelico wrote: >> >> On Wed, Jun 10, 2020 at 11:49 PM Robin Becker wrote: >> > >> > I'm sure this has come up before, but a tiny pyinstaller created exe is being seen as malware by windows 10. >> > >> > Is there any way to create simple single file applications which don't get this treatment? >> > >> > The intended users are unlikely to understand how to adjust the scanner to whitelist the application. >> >> Tell them to install Python from an official source, and then >> distribute your application as a single .py (or .pyw) file. Problem >> solved. > > > This is in no way a solution or a reasonable way to distribute software to end-users. Please don't give non-answers. > I'm sorry to have used this non-answer myself in the past. I must have been hallucinating; all those end users that double-click on .py files and successfully run applications must actually have been figments of my imagination. This IS a viable way to distribute software. Yes, it means you have to package everything up into a single .py file, which restricts you a bit; I'm not sure if it's viable to distribute a .zip file for importing, but it wasn't last time I did this. But if you can manage to make a single file out of it, it becomes - effectively - an application. Maybe this answer isn't applicable to everyone, but it's unfair to call it a non-answer. ChrisA From souvik.viksou at gmail.com Wed Jun 10 11:11:06 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Wed, 10 Jun 2020 20:41:06 +0530 Subject: pyinstaller In-Reply-To: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> Message-ID: I found this... https://stackoverflow.com/questions/43777106/program-made-with-pyinstaller-now-seen-as-a-trojan-horse-by-avg Might be usefull, might be useless. Souvik flutter dev On Wed, Jun 10, 2020, 7:18 PM Robin Becker wrote: > I'm sure this has come up before, but a tiny pyinstaller created exe is > being seen as malware by windows 10. > > Is there any way to create simple single file applications which don't get > this treatment? > > The intended users are unlikely to understand how to adjust the scanner to > whitelist the application. > -- > Robin Becker > -- > https://mail.python.org/mailman/listinfo/python-list > From robin at reportlab.com Wed Jun 10 11:29:25 2020 From: robin at reportlab.com (Robin Becker) Date: Wed, 10 Jun 2020 16:29:25 +0100 Subject: pyinstaller In-Reply-To: References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> Message-ID: On 10/06/2020 16:11, Souvik Dutta wrote: > I found this... > https://stackoverflow.com/questions/43777106/program-made-with-pyinstaller-now-seen-as-a-trojan-horse-by-avg > Might be usefull, might be useless. > > Souvik flutter dev > > On Wed, Jun 10, 2020, 7:18 PM Robin Becker wrote: ..... thanks for the above. I might try to do a downgrade as that is suggested as one of the ways forward. I don't want to start compiling my own versions of the boostrap exe bits. Clearly most virus scanners only look at the obvious behaviour ie we execute a lot of python code which is probably impenetrable to the scanner and hence suspicious. I submitted my exe to the web based scanner in that answer and it came out clean, but windows 10 barks :( -- Robin Becker From mats at python.org Wed Jun 10 12:52:52 2020 From: mats at python.org (Mats Wichmann) Date: Wed, 10 Jun 2020 10:52:52 -0600 Subject: pyinstaller In-Reply-To: References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> Message-ID: <91425689-55f4-9e2a-5474-ca684bb83125@python.org> On 6/10/20 8:50 AM, Calvin Spealman wrote: > On Wed, Jun 10, 2020 at 10:06 AM Chris Angelico wrote: > >> On Wed, Jun 10, 2020 at 11:49 PM Robin Becker wrote: >>> >>> I'm sure this has come up before, but a tiny pyinstaller created exe is >> being seen as malware by windows 10. >>> >>> Is there any way to create simple single file applications which don't >> get this treatment? >>> >>> The intended users are unlikely to understand how to adjust the scanner >> to whitelist the application. >> >> Tell them to install Python from an official source, and then >> distribute your application as a single .py (or .pyw) file. Problem >> solved. >> > > This is in no way a solution or a reasonable way to distribute software to > end-users. Please don't give non-answers. It's perfectly reasonable. Now that Python is available as an install from the Microsoft Store, telling people to install that is a far simpler solution than trying to fight with various bundlers, or with a virus/malware scanner. The bundlers have, as far as I can tell, always been a bit problematic. If they work for you, great, if not... oh, well. Just look at the history of "[insert bundler name] not working for me" type questions over the last decade+ on the internet. Virus/malware checkers on the hand are their own thing: they decide, based on collected evidence, that certain attributes/bit patterns/etc. indicate something nefarious. If you're unlucky enough, always a chance with binary exe files, data files, etc, to match their heuristics, you're (potentially) evil, and all you can do is argue with them that your item is legitimate and they ought update their descriptions. Microsoft is generally heading in the direction (along the lines of mobile phone app stores, though it's still a configurable option at the moment) to consider any installation that doesn't come from an approved source as doubtful and/or forbidden, and in a corporate setting if they decide to configure managed systems that way, you're unlikely to win an argument to allow your little installer. From antoon.pardon at vub.be Wed Jun 10 04:05:14 2020 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 10 Jun 2020 10:05:14 +0200 Subject: How to turn a defaultdict into a normal dict. Message-ID: <296747fe-d12e-5d0e-0749-1ff7fb0d4de1@vub.be> The problem I face is that at the building face, I need a defaultdict because the values are lists that are appended too. So a defaultdict(list) is convenient in that new entries are treated as if the value is an empty list. However later when I actually use it, accessing a key that is not present, should raise KeyError. Is that somehow possible? -- Antoon Pardon. From robin at reportlab.com Wed Jun 10 10:14:53 2020 From: robin at reportlab.com (Robin Becker) Date: Wed, 10 Jun 2020 15:14:53 +0100 Subject: pyinstaller In-Reply-To: References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> Message-ID: <29588d52-22ea-9f4d-d356-7c547a500c2d@everest.reportlab.co.uk> On 10/06/2020 15:02, Chris Angelico wrote: ........ >> >> The intended users are unlikely to understand how to adjust the scanner to whitelist the application. > > Tell them to install Python from an official source, and then > distribute your application as a single .py (or .pyw) file. Problem > solved. > > ChrisA > Thanks for the obvious suggestion, but if they have difficulty whitelisting the app then installing python is also probably beyond their abilities :( and I think it ought to be easier for the pyinstaller created executables to 'just work'. The current exe works on very old versions of windows as well. Some people are reluctant to change old win 95/xp machines just to run a single app. I had supposed there might be a simple mechanism to get these applications validated in some way, but it seems not. MS seems uninterested. -- Robin Becker From silviaaminul25aprile at gmail.com Wed Jun 10 07:26:17 2020 From: silviaaminul25aprile at gmail.com (Silvia Aminul) Date: Wed, 10 Jun 2020 12:26:17 +0100 Subject: repair modify uninstall Message-ID: <534381AF-B361-4AE2-9EB5-DCB3F00047DF@hxcore.ol> Hello ? I tried installing Python for windows 10 (the latest version of python for windows ) And after downloading and trying to launch it keeps saying repair modify uninstall I tried looking for solution and it was suggested I might have downloaded python twice so I uninstalled python from the core (control panel ) And tried installing python again however the same problems keep coming up (repair modify uninstall) Could you help me I?m not sure what I?m doing wrong Thank you in advance Silvia ? ? Sent from [1]Mail for Windows 10 ? References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From grant.b.edwards at gmail.com Wed Jun 10 11:42:26 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 10 Jun 2020 15:42:26 -0000 (UTC) Subject: pyinstaller References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> Message-ID: On 2020-06-10, Souvik Dutta wrote: > You might also try py2exe, in that way the user doesn't need to > install python in her/his computer. I used to use py2exe for Windows apps, and it worked well for 2.x. A couple years ago had to switch to cx_freeze due to issues with 3.x support in py2exe (those issues may have been resolved since). -- Grant From grant.b.edwards at gmail.com Wed Jun 10 11:42:59 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 10 Jun 2020 15:42:59 -0000 (UTC) Subject: pyinstaller References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> <5aa459a1-d8a1-44f1-4622-1cafcbce1c6c@everest.reportlab.co.uk> Message-ID: On 2020-06-10, Robin Becker wrote: > ........I think we used py2exe previously and I guess that will have > the same problems as pyinstaller. Why do you guess that? -- Grant From john at johnweller.co.uk Wed Jun 10 12:56:11 2020 From: john at johnweller.co.uk (John Weller) Date: Wed, 10 Jun 2020 17:56:11 +0100 Subject: Syntax Help Message-ID: <00e901d63f48$0c56ab10$25040130$@johnweller.co.uk> Hi I am trying to learn python. Looking at an example on the web I found this line: def plot(*args, **kwargs): What do the stars mean? TIA John Weller 01380 723235 07976 393631 From rosuav at gmail.com Wed Jun 10 15:41:33 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Jun 2020 05:41:33 +1000 Subject: pyinstaller In-Reply-To: <29588d52-22ea-9f4d-d356-7c547a500c2d@everest.reportlab.co.uk> References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> <29588d52-22ea-9f4d-d356-7c547a500c2d@everest.reportlab.co.uk> Message-ID: On Thu, Jun 11, 2020 at 5:26 AM Robin Becker wrote: > > On 10/06/2020 15:02, Chris Angelico wrote: > ........ > >> > >> The intended users are unlikely to understand how to adjust the scanner to whitelist the application. > > > > Tell them to install Python from an official source, and then > > distribute your application as a single .py (or .pyw) file. Problem > > solved. > > > > ChrisA > > > Thanks for the obvious suggestion, but if they have difficulty whitelisting the app then installing python is also > probably beyond their abilities :( and I think it ought to be easier for the pyinstaller created executables to 'just work'. Python can be installed from the app store, or from a python.org downloader. If that's too much hassle for them, then they're going to need help *whatever* you do. > The current exe works on very old versions of windows as well. Some people are reluctant to change old win 95/xp > machines just to run a single app. And a lot of us are reluctant to try to support XP. It's an operating system that was released the same year as Python 2.2 - do you try to support that? If not, why support an ancient OS? > I had supposed there might be a simple mechanism to get these applications validated in some way, but it seems not. MS > seems uninterested. And I can't blame them. How is MS going to know that you haven't tampered with the Python binary before you packaged it up? How can end users be expected to trust it? ChrisA From python at mrabarnett.plus.com Wed Jun 10 16:05:20 2020 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 10 Jun 2020 21:05:20 +0100 Subject: How to turn a defaultdict into a normal dict. In-Reply-To: <296747fe-d12e-5d0e-0749-1ff7fb0d4de1@vub.be> References: <296747fe-d12e-5d0e-0749-1ff7fb0d4de1@vub.be> Message-ID: On 2020-06-10 09:05, Antoon Pardon wrote: > The problem I face is that at the building face, I need a defaultdict > because the values are lists that are appended too. So a > defaultdict(list) is convenient in that new entries are treated as if > the value is an empty list. > > However later when I actually use it, accessing a key that is not > present, should raise KeyError. > > Is that somehow possible? > Pass the defaultdict to dict: my_dict = defaultdict(list) ... my_dict = dict(my_dict) From PythonList at DancesWithMice.info Wed Jun 10 16:09:47 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 11 Jun 2020 08:09:47 +1200 Subject: repair modify uninstall In-Reply-To: <534381AF-B361-4AE2-9EB5-DCB3F00047DF@hxcore.ol> References: <534381AF-B361-4AE2-9EB5-DCB3F00047DF@hxcore.ol> Message-ID: On 10/06/20 11:26 PM, Silvia Aminul wrote: > I tried installing Python for windows 10 (the latest version of python for > windows ) > > And after downloading and trying to launch it keeps saying repair modify > uninstall I tried looking for solution and it was suggested I might have > downloaded python twice so I uninstalled python from the core (control > panel ) Please refer to the (extensive) Python documentation and advise if this page answers your question, or is insufficient for your purposes: https://docs.python.org/3/using/windows.html -- Regards =dn From PythonList at DancesWithMice.info Wed Jun 10 16:20:22 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 11 Jun 2020 08:20:22 +1200 Subject: Turning pygame apps into add-ons In-Reply-To: References: Message-ID: On 11/06/20 1:32 AM, elisha hollander wrote: > I have a folder with my pygame apps, I want to build a program to have a > nice interface to access those apps from, I want it to be like an actual > computer, so, I need it to open the apps as rect of something not as > external apps. > Is there a way to do it without changing all the codes? > (I can import the app from the app file, but it won't open in the interface) Exactly what you want is not clear - maybe a language-translation problem, and if so, please don't feel the need to apologise! What do you mean by "actual computer"? A rect[angle] is a basic shape for display in Pygame. Do you want the name of each app to appear inside a box? Perhaps if you show us a portion of the code illustrating the import (and a portion of the code to be imported) - and then talk about what happened, and what you would prefer to be the result? (remember that this list will only accept text-format attachments (no graphic screen-dumps!), so best to copy-paste code/results directly into the email message) -- Regards =dn From PythonList at DancesWithMice.info Wed Jun 10 17:13:16 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 11 Jun 2020 09:13:16 +1200 Subject: Syntax Help In-Reply-To: <00e901d63f48$0c56ab10$25040130$@johnweller.co.uk> References: <00e901d63f48$0c56ab10$25040130$@johnweller.co.uk> Message-ID: On 11/06/20 4:56 AM, John Weller wrote: > I am trying to learn python. Looking at an example on the web I found this > line: > def plot(*args, **kwargs): > What do the stars mean? The Python "docs" are (surprisingly, for this day-and-age) comprehensive. Try https://docs.python.org/3/tutorial/controlflow.html and its several discussions about def[ining] functions and parameters. Please also be aware that there is also a Python-Tutor Discussion List which has the specific objective of supporting learners (follow link, below). -- Regards =dn From __peter__ at web.de Wed Jun 10 18:02:48 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 11 Jun 2020 00:02:48 +0200 Subject: How to turn a defaultdict into a normal dict. References: <296747fe-d12e-5d0e-0749-1ff7fb0d4de1@vub.be> Message-ID: Antoon Pardon wrote: > The problem I face is that at the building face, I need a defaultdict > because the values are lists that are appended too. So a > defaultdict(list) is convenient in that new entries are treated as if > the value is an empty list. > > However later when I actually use it, accessing a key that is not > present, should raise KeyError. > > Is that somehow possible? It never occured to me to try that, but: >>> from collections import defaultdict >>> d = defaultdict(list) >>> d["x"] [] >>> d.default_factory = None >>> d["y"] Traceback (most recent call last): File "", line 1, in KeyError: 'y' From tjreedy at udel.edu Wed Jun 10 17:38:25 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 10 Jun 2020 17:38:25 -0400 Subject: Syntax Help In-Reply-To: <00e901d63f48$0c56ab10$25040130$@johnweller.co.uk> References: <00e901d63f48$0c56ab10$25040130$@johnweller.co.uk> Message-ID: On 6/10/2020 12:56 PM, John Weller wrote: > I am trying to learn python. Looking at an example on the web I found this > line: > def plot(*args, **kwargs): This is function definition. > What do the stars mean? The python docs have an index that has a Symbols page. https://docs.python.org/3/genindex-Symbols.html * and ** both have entries for 'function definition' which point to https://docs.python.org/3/reference/compound_stmts.html#index-22 As a beginner, you might get more help from the tutorial, but the Symbols index is a way to find concise reminders for the different uses of different symbols. -- Terry Jan Reedy From torriem at gmail.com Wed Jun 10 22:38:53 2020 From: torriem at gmail.com (Michael Torrie) Date: Wed, 10 Jun 2020 20:38:53 -0600 Subject: repair modify uninstall In-Reply-To: References: <534381AF-B361-4AE2-9EB5-DCB3F00047DF@hxcore.ol> Message-ID: On 6/10/20 2:09 PM, DL Neil via Python-list wrote: > On 10/06/20 11:26 PM, Silvia Aminul wrote: >> I tried installing Python for windows 10 (the latest version of python for >> windows ) >> >> And after downloading and trying to launch it keeps saying repair modify >> uninstall I tried looking for solution and it was suggested I might have >> downloaded python twice so I uninstalled python from the core (control >> panel ) > > Please refer to the (extensive) Python documentation and advise if this > page answers your question, or is insufficient for your purposes: > https://docs.python.org/3/using/windows.html Since this comes up on a weekly basis, perhaps the installer should open that web page to section 3.8.1 after a successful installation. Maybe users would read that short section and not try to run the installer over and over again. Or since that can be annoying, a prominent "how to get started" link to click on. I dunno. I'm not sure why users think the installer is the python interpreter after running it the first time, but apparently many do. From grant.b.edwards at gmail.com Wed Jun 10 23:30:00 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 11 Jun 2020 03:30:00 -0000 (UTC) Subject: repair modify uninstall References: <534381AF-B361-4AE2-9EB5-DCB3F00047DF@hxcore.ol> Message-ID: On 2020-06-11, Michael Torrie wrote: > Since this comes up on a weekly basis, perhaps the installer should open > that web page to section 3.8.1 after a successful installation. Maybe > users would read that short section and not try to run the installer > over and over again. Or since that can be annoying, a prominent "how to > get started" link to click on. I dunno. Suggestions like this also get made regularly. I'm baffled why the Python installer doesn't display an initial screen that says something like. This is the Python INSTALLER. If you have installed Python, here's what you do to run it: Click the buttons below only if you want to INSTALL, UNINSTALL, or REPAIR Python. See the above instruction to use/run Python. > I'm not sure why users think the installer is the python interpreter > after running it the first time, but apparently many do. Indeed. Is the file name not clear that it's an installer? -- Grant From python at python.invalid Wed Jun 10 16:48:56 2020 From: python at python.invalid (Python) Date: Wed, 10 Jun 2020 22:48:56 +0200 Subject: Syntax Help In-Reply-To: References: <00e901d63f48$0c56ab10$25040130$@johnweller.co.uk> Message-ID: <5ee14716$0$16200$426a74cc@news.free.fr> Le 10/06/2020 ? 18:56, John Weller a ?crit?: > Hi > > > > I am trying to learn python. Looking at an example on the web I found this > line: > > > > def plot(*args, **kwargs): > > > > What do the stars mean? That, respectively, positional arguments will be packed into a sequence of references called args and that keywords argument will be packed into a dictionary called kwargs. From robin at reportlab.com Thu Jun 11 04:17:23 2020 From: robin at reportlab.com (Robin Becker) Date: Thu, 11 Jun 2020 09:17:23 +0100 Subject: pyinstaller In-Reply-To: References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> <29588d52-22ea-9f4d-d356-7c547a500c2d@everest.reportlab.co.uk> Message-ID: <6b9e6a9c-6f3a-2403-cb70-d47a408f34c9@everest.reportlab.co.uk> On 10/06/2020 20:41, Chris Angelico wrote: ......... > Python can be installed from the app store, or from a python.org > downloader. If that's too much hassle for them, then they're going to > need help *whatever* you do. > works for windows 10, but probably not on older machines. >> The current exe works on very old versions of windows as well. Some people are reluctant to change old win 95/xp >> machines just to run a single app. > > And a lot of us are reluctant to try to support XP. It's an operating > system that was released the same year as Python 2.2 - do you try to > support that? If not, why support an ancient OS? unfortunately we don't get to choose the users' hardware or what OS they use. > >> I had supposed there might be a simple mechanism to get these applications validated in some way, but it seems not. MS >> seems uninterested. > > And I can't blame them. How is MS going to know that you haven't > tampered with the Python binary before you packaged it up? How can end > users be expected to trust it? no disagreement here > ChrisA > From rosuav at gmail.com Thu Jun 11 04:24:26 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Jun 2020 18:24:26 +1000 Subject: pyinstaller In-Reply-To: <6b9e6a9c-6f3a-2403-cb70-d47a408f34c9@everest.reportlab.co.uk> References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> <29588d52-22ea-9f4d-d356-7c547a500c2d@everest.reportlab.co.uk> <6b9e6a9c-6f3a-2403-cb70-d47a408f34c9@everest.reportlab.co.uk> Message-ID: On Thu, Jun 11, 2020 at 6:18 PM Robin Becker wrote: > > On 10/06/2020 20:41, Chris Angelico wrote: > ......... > > Python can be installed from the app store, or from a python.org > > downloader. If that's too much hassle for them, then they're going to > > need help *whatever* you do. > > > works for windows 10, but probably not on older machines. > > >> The current exe works on very old versions of windows as well. Some people are reluctant to change old win 95/xp > >> machines just to run a single app. > > > > And a lot of us are reluctant to try to support XP. It's an operating > > system that was released the same year as Python 2.2 - do you try to > > support that? If not, why support an ancient OS? > unfortunately we don't get to choose the users' hardware or what OS they use. > But you DO get to choose what you support. If they want to use Windows 98 on an 80386, that's their (stupid) choice, and they can't guarantee that your program will work on it. ChrisA From barry at barrys-emacs.org Thu Jun 11 05:16:52 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 11 Jun 2020 10:16:52 +0100 Subject: pyinstaller In-Reply-To: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> Message-ID: <10846AAE-8747-4625-886B-13E7E4AA533B@barrys-emacs.org> > On 10 Jun 2020, at 14:46, Robin Becker wrote: > > I'm sure this has come up before, but a tiny pyinstaller created exe is being seen as malware by windows 10. > > Is there any way to create simple single file applications which don't get this treatment? Submit the .exe to Microsoft so they can update the virus definitions to remove your false positive. https://www.microsoft.com/en-us/wdsi/filesubmission I did this for one of my open source projects and Microsoft fixed the false problem in a few days for me. Barry > > The intended users are unlikely to understand how to adjust the scanner to whitelist the application. > -- > Robin Becker > -- > https://mail.python.org/mailman/listinfo/python-list > From robin at reportlab.com Thu Jun 11 05:27:19 2020 From: robin at reportlab.com (Robin Becker) Date: Thu, 11 Jun 2020 10:27:19 +0100 Subject: pyinstaller In-Reply-To: References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> <29588d52-22ea-9f4d-d356-7c547a500c2d@everest.reportlab.co.uk> <6b9e6a9c-6f3a-2403-cb70-d47a408f34c9@everest.reportlab.co.uk> Message-ID: <9957252c-4e50-8c7c-8e2b-518daad2400a@everest.reportlab.co.uk> On 11/06/2020 09:24, Chris Angelico wrote: ........ > > But you DO get to choose what you support. If they want to use Windows > 98 on an 80386, that's their (stupid) choice, and they can't guarantee > that your program will work on it. sadly this isn't really true since this is only part of the process and we are trying to capture data (sports results) which they create on their hardware for other reasons; some machines are 20 years old and some this year. Some of the capture devices are using serial ports :( which luckily I don't get near :) Regarding the users as stupid because they won't follow us on the upgrade tread wheel seems a bit arrogant. > > ChrisA > -- Robin Becker From robin at reportlab.com Thu Jun 11 05:30:26 2020 From: robin at reportlab.com (Robin Becker) Date: Thu, 11 Jun 2020 10:30:26 +0100 Subject: pyinstaller In-Reply-To: <10846AAE-8747-4625-886B-13E7E4AA533B@barrys-emacs.org> References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> <10846AAE-8747-4625-886B-13E7E4AA533B@barrys-emacs.org> Message-ID: .......... > Submit the .exe to Microsoft so they can update the virus definitions to remove your false positive. > > https://www.microsoft.com/en-us/wdsi/filesubmission > > I did this for one of my open source projects and Microsoft fixed the false problem in a few days for me. > I think my boss actually tried this, but I will check. Thanks > Barry ........ >> -- >> Robin Becker From rosuav at gmail.com Thu Jun 11 05:32:24 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 11 Jun 2020 19:32:24 +1000 Subject: pyinstaller In-Reply-To: <9957252c-4e50-8c7c-8e2b-518daad2400a@everest.reportlab.co.uk> References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> <29588d52-22ea-9f4d-d356-7c547a500c2d@everest.reportlab.co.uk> <6b9e6a9c-6f3a-2403-cb70-d47a408f34c9@everest.reportlab.co.uk> <9957252c-4e50-8c7c-8e2b-518daad2400a@everest.reportlab.co.uk> Message-ID: On Thu, Jun 11, 2020 at 7:27 PM Robin Becker wrote: > > On 11/06/2020 09:24, Chris Angelico wrote: > ........ > > > > But you DO get to choose what you support. If they want to use Windows > > 98 on an 80386, that's their (stupid) choice, and they can't guarantee > > that your program will work on it. > sadly this isn't really true since this is only part of the process and we are trying to capture data (sports results) > which they create on their hardware for other reasons; some machines are 20 years old and some this year. Some of the > capture devices are using serial ports :( which luckily I don't get near :) > > Regarding the users as stupid because they won't follow us on the upgrade tread wheel seems a bit arrogant. > What about regarding the users as so stupid that they can't handle "go to python.org and install Python, then double-click this .py file"? Are they smart enough to handle a two-step installation process? Because that's what I suggested at the start, and you were the one who said they wouldn't be able to handle it. I'm judging your users based on your descriptions of them and nothing else. I'd much rather assume that they're intelligent and can accept the consequences of their choices. ChrisA From john at johnweller.co.uk Thu Jun 11 06:03:37 2020 From: john at johnweller.co.uk (John Weller) Date: Thu, 11 Jun 2020 11:03:37 +0100 Subject: Syntax Help In-Reply-To: References: <00e901d63f48$0c56ab10$25040130$@johnweller.co.uk> Message-ID: <000101d63fd7$93e0a560$bba1f020$@johnweller.co.uk> Many thanks to all who responded. I was an experienced programmer until I retired nearly 20 years ago, mainly in the military weapons area then XBase when I left the military. I decided I had to learn Python when my grandson started learning it at school if I wanted to retain my position as the family IT guru ? I have been able to find answers to most problems by Googling but couldn't work out a suitable query for this one. I have signed up for the tutors list. Thanks again John Weller 01380 723235 07976 393631 -----Original Message----- From: Python-list On Behalf Of DL Neil via Python-list Sent: 10 June 2020 22:13 To: python-list at python.org Subject: Re: Syntax Help On 11/06/20 4:56 AM, John Weller wrote: > I am trying to learn python. Looking at an example on the web I found > this > line: > def plot(*args, **kwargs): > What do the stars mean? The Python "docs" are (surprisingly, for this day-and-age) comprehensive. Try https://docs.python.org/3/tutorial/controlflow.html and its several discussions about def[ining] functions and parameters. Please also be aware that there is also a Python-Tutor Discussion List which has the specific objective of supporting learners (follow link, below). -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list From fabiofz at gmail.com Thu Jun 11 07:34:59 2020 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 11 Jun 2020 08:34:59 -0300 Subject: PyDev 7.6.0 Released Message-ID: PyDev 7.6.0 Release Highlights - *Debugger improvements* (updated to pydevd 1.9.1). - *Variables are now grouped* (special/class/function/protected) -- note: it's possible to hide groups in the variables view menu dropdown. - When a launching a subprocess does not target a python executable, the original args are kept (so, quotes are no longer trimmed). - A step in which would skip code won't be reported in the return if it'd reach the same location. - The disassembled version of a frame may be shown if the sources are not available. - PySide2 is supported to recognize QThreads/event loop in interactive console. - *Python 3.8 parsing fixes* - Properly parsing f-strings with named unicode character. i.e.: *f"\N{BULLET}"*. - Properly parsing f-strings formats using colon. i.e.: *f"{datetime.datetime.now():%Y-%m-%d %H:%M:%S}"*. - Properly parsing f-strings with vars ending in equals. i.e.: *f'{y=}'*. - Properly parsing raw f-strings such as *rf"str"*. - Properly parsing iterable unpacking syntax. i.e.: *return lastname.upper(), *members*. - Support for the latest version of PyTest (which may resolve symlinks and changed the TerminalWriter import location). - PyDev package explorer is a bit faster (cache source project paths for a project). - Recognizing type comments for *self* attributes. i.e.: *#: :type self.var: MyClass*. - Trailing commas properly recognized in automatic import. About PyDev PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development, now also available for Python on Visual Studio Code. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. It is also available as a standalone through LiClipse with goodies such as multiple cursors, theming and support for many other languages, such as Django Templates, Jinja2, Html, JavaScript, etc. Links: PyDev: http://pydev.org PyDev Blog: http://pydev.blogspot.com PyDev on VSCode: http://pydev.org/vscode LiClipse: http://www.liclipse.com PyVmMonitor - Python Profiler: http://www.pyvmmonitor.com/ Cheers, Fabio Zadrozny From vincent at vincentdavis.net Thu Jun 11 09:44:25 2020 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 11 Jun 2020 07:44:25 -0600 Subject: Convert and analyze image data in a spreadsheet. Message-ID: Looking for a little advise. I have 6x6 color (CIELAB ) data in a spreadsheet (color samples of clothing). I would like to visualize this as an image on a per channel (l,a,b) and as a color image. I can read the data from the spreadsheet. I am not sure the path a should choose from there. I think the path is to read this data into a numpy array and use scikit-image. Questions: 1. I am not sure how to get the 3 color measurements into a color image pixel. 2. I only kinda understand color spaces, this data is in CIELAB, do I want to keep it in that color format? I think yes. 3. How can I visualize this data as a 6x6 color image and visualize each color on a gray scale. 4. General hints or link of how to proceed would be helpful. Thanks Vincent Davis From robin at reportlab.com Thu Jun 11 05:27:19 2020 From: robin at reportlab.com (Robin Becker) Date: Thu, 11 Jun 2020 10:27:19 +0100 Subject: pyinstaller In-Reply-To: References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> <29588d52-22ea-9f4d-d356-7c547a500c2d@everest.reportlab.co.uk> <6b9e6a9c-6f3a-2403-cb70-d47a408f34c9@everest.reportlab.co.uk> Message-ID: <9957252c-4e50-8c7c-8e2b-518daad2400a@everest.reportlab.co.uk> On 11/06/2020 09:24, Chris Angelico wrote: ........ > > But you DO get to choose what you support. If they want to use Windows > 98 on an 80386, that's their (stupid) choice, and they can't guarantee > that your program will work on it. sadly this isn't really true since this is only part of the process and we are trying to capture data (sports results) which they create on their hardware for other reasons; some machines are 20 years old and some this year. Some of the capture devices are using serial ports :( which luckily I don't get near :) Regarding the users as stupid because they won't follow us on the upgrade tread wheel seems a bit arrogant. > > ChrisA > -- Robin Becker From tjreedy at udel.edu Thu Jun 11 08:06:47 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Jun 2020 08:06:47 -0400 Subject: repair modify uninstall In-Reply-To: References: <534381AF-B361-4AE2-9EB5-DCB3F00047DF@hxcore.ol> Message-ID: On 6/10/2020 11:30 PM, Grant Edwards wrote: > On 2020-06-11, Michael Torrie wrote: > >> Since this comes up on a weekly basis, perhaps the installer should open >> that web page to section 3.8.1 after a successful installation. Maybe >> users would read that short section and not try to run the installer >> over and over again. Or since that can be annoying, a prominent "how to >> get started" link to click on. I dunno. > > Suggestions like this also get made regularly. I'm baffled why the > Python installer doesn't display an initial screen that says something > like. > > This is the Python INSTALLER. If you have installed Python, > here's what you do to run it: > > > > Click the buttons below only if you want to INSTALL, UNINSTALL, > or REPAIR Python. See the above instruction to use/run Python. > >> I'm not sure why users think the installer is the python interpreter >> after running it the first time, but apparently many do. > > Indeed. Is the file name not clear that it's an installer? No. python-3.8.3-amd64.exe, which is typical naming for install files. I opened https://bugs.python.org/issue40948 and suggested adding '-setup' or '-install', as well as instructions on the initial screen for existing installs, and, if not present, the final screen for new installs. -- Terry Jan Reedy From tjreedy at udel.edu Thu Jun 11 08:13:06 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 11 Jun 2020 08:13:06 -0400 Subject: Syntax Help In-Reply-To: <000101d63fd7$93e0a560$bba1f020$@johnweller.co.uk> References: <00e901d63f48$0c56ab10$25040130$@johnweller.co.uk> <000101d63fd7$93e0a560$bba1f020$@johnweller.co.uk> Message-ID: On 6/11/2020 6:03 AM, John Weller wrote: >I have been able to find answers to most problems by Googling but couldn't work out a suitable query for this one. That is why I and others have made the Symbols index as complete as possible. If anything thinks something is missing, say so here. -- Terry Jan Reedy From papaabramg at gmail.com Thu Jun 11 10:58:07 2020 From: papaabramg at gmail.com (Avraham Markov) Date: Thu, 11 Jun 2020 17:58:07 +0300 Subject: Fwd: python 3.8.3 fails In-Reply-To: References: Message-ID: Please suggest something to fix ---------- Forwarded message --------- From: Avraham Markov Date: Thu, Jun 11, 2020 at 5:50 PM Subject: python 3.8.3 fails To: Hello, I successfully installed Python 3.8.3 (64-bit) at Windows 10 LTSC 64 bit by python-3.8.3-amd64 installer from https://www.python.org/downloads/windows/ Also by python-3.8.3 installer, but lastly by python-3.8.3-amd64 installer. Then when I open powershell, PS C:\Users\AlexJer> python python : Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32 At line:1 char:1 + python + ~~~~~~ + CategoryInfo : NotSpecified: (Python 3.8.3 (t...MD64)] on win32:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError Type "help", "copyright", "credits" or "license" for more information. > >> Thanks, Avraham From grant.b.edwards at gmail.com Thu Jun 11 11:39:08 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 11 Jun 2020 15:39:08 -0000 (UTC) Subject: pyinstaller References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> <29588d52-22ea-9f4d-d356-7c547a500c2d@everest.reportlab.co.uk> <6b9e6a9c-6f3a-2403-cb70-d47a408f34c9@everest.reportlab.co.uk> Message-ID: On 2020-06-11, Chris Angelico wrote: > But you DO get to choose what you support. True, for a certain value of "you". The requirement to support certains OSes and versions is often a business decision that is out of the hands of the developer. I suppose the OP could quit and stand on the street corner with a cardboard sign: Please Help Didn't want to support Windows 7 From arj.python at gmail.com Thu Jun 11 14:00:54 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 11 Jun 2020 22:00:54 +0400 Subject: The FaQ project - Single or Double quotes Message-ID: Since the single vs double quote thread i decided to reactivate the FaQ project. You can view it here https://abdur-rahmaanj.github.io/pyfaq/[list]_Single_or_double_quotes.html The index has some some more summaries: https://abdur-rahmaanj.github.io/pyfaq/ I auto pull the messages with some manual edits like filtering empty mails etc Mr Christopher maintains one for python-ideas https://github.com/PythonCHB/PythonListsSummaries This one is intended to have even some common questions like where do i start etc Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy | blog github Mauritius From arj.python at gmail.com Thu Jun 11 14:03:44 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 11 Jun 2020 22:03:44 +0400 Subject: The FaQ project - Single or Double quotes In-Reply-To: References: Message-ID: I'm still unsure whether or not to have a summary instead of just listing the texts Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy | blog github Mauritius On Thu, Jun 11, 2020 at 10:00 PM Abdur-Rahmaan Janhangeer < arj.python at gmail.com> wrote: > Since the single vs double quote thread > i decided to reactivate the FaQ project. > > You can view it here > > https://abdur-rahmaanj.github.io/pyfaq/[list]_Single_or_double_quotes.html > > The index has some some more summaries: > > https://abdur-rahmaanj.github.io/pyfaq/ > > > I auto pull the messages with some manual edits like > filtering empty mails etc > > Mr Christopher maintains one for python-ideas > https://github.com/PythonCHB/PythonListsSummaries > > This one is intended to have even some common questions > like where do i start etc > > Kind Regards, > > Abdur-Rahmaan Janhangeer > compileralchemy | blog > > github > Mauritius > From python at mrabarnett.plus.com Thu Jun 11 14:59:00 2020 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 11 Jun 2020 19:59:00 +0100 Subject: Fwd: python 3.8.3 fails In-Reply-To: References: Message-ID: On 2020-06-11 15:58, Avraham Markov wrote: > Please suggest something to fix > > ---------- Forwarded message --------- > From: Avraham Markov > Date: Thu, Jun 11, 2020 at 5:50 PM > Subject: python 3.8.3 fails > To: > > > Hello, I successfully installed Python 3.8.3 (64-bit) > at Windows 10 LTSC 64 bit by python-3.8.3-amd64 installer > from https://www.python.org/downloads/windows/ > Also by python-3.8.3 installer, > but lastly by python-3.8.3-amd64 installer. > Then when I open powershell, > > PS C:\Users\AlexJer> python > python : Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC > v.1924 64 bit (AMD64)] on win32 > At line:1 char:1 > + python > + ~~~~~~ > + CategoryInfo : NotSpecified: (Python 3.8.3 (t...MD64)] on > win32:String) [], RemoteException > + FullyQualifiedErrorId : NativeCommandError > > Type "help", "copyright", "credits" or "license" for more information. >> >>> After typing "python", you have "python : " at the start of the next line. That's what it doesn't like. Where does that come from? From grant.b.edwards at gmail.com Thu Jun 11 13:58:03 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 11 Jun 2020 17:58:03 -0000 (UTC) Subject: repair modify uninstall References: <534381AF-B361-4AE2-9EB5-DCB3F00047DF@hxcore.ol> Message-ID: On 2020-06-11, Terry Reedy wrote: > >> Indeed. Is the file name not clear that it's an installer? > > No. python-3.8.3-amd64.exe, which is typical naming for install files. > > I opened https://bugs.python.org/issue40948 and suggested adding > '-setup' or '-install', An excellent suggestion. When I build .exe installers, I always end the name in '-setup'. Everybody seems to understand that, but my audience is probably smaller and a bit more tech-savvy that that of the Python audience. > as well as instructions on the initial screen for existing installs, > and, if not present, the final screen for new installs. Thanks for filing that bug. -- Grant From zljubisic at gmail.com Thu Jun 11 16:51:25 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Thu, 11 Jun 2020 13:51:25 -0700 (PDT) Subject: Typing, how come that :int is not ensuring int parameter? Message-ID: Hi, If I run this code: class Property: def __init__(self, var: int): self.a: int = var @property def a(self): return self.__a @a.setter def a(self, var: int): if var > 0 and var % 2 == 0: self.__a = var else: self.__a = 2 if __name__ == '__main__': x = Property(1.5) print(x.a) I am getting 2. How come, if I have created a class with :int in order to ensure that "a" property must be an integer, that I can create an instance with float (1.5)? Regards. From PythonList at DancesWithMice.info Thu Jun 11 16:58:02 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Fri, 12 Jun 2020 08:58:02 +1200 Subject: Syntax Help In-Reply-To: References: <00e901d63f48$0c56ab10$25040130$@johnweller.co.uk> <000101d63fd7$93e0a560$bba1f020$@johnweller.co.uk> Message-ID: On 12/06/20 12:13 AM, Terry Reedy wrote: > On 6/11/2020 6:03 AM, John Weller wrote: >> I have been able to find answers to most problems by Googling but >> couldn't work out a suitable query for this one. > > That is why I and others have made the Symbols index as complete as > possible.? If anything thinks something is missing, say so here. It is a solid contribution to the community. Thanks! -- Regards =dn From barry at barrys-emacs.org Thu Jun 11 17:06:04 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 11 Jun 2020 22:06:04 +0100 Subject: Typing, how come that :int is not ensuring int parameter? In-Reply-To: References: Message-ID: <869F6A96-4794-47BC-9FE0-905DA462F1E6@barrys-emacs.org> > On 11 Jun 2020, at 21:51, zljubisic at gmail.com wrote: > > Hi, > > If I run this code: > class Property: > > def __init__(self, var: int): > self.a: int = var > > @property > def a(self): > return self.__a > > @a.setter > def a(self, var: int): > if var > 0 and var % 2 == 0: > self.__a = var > else: > self.__a = 2 > > if __name__ == '__main__': > x = Property(1.5) > print(x.a) > > I am getting 2. > How come, if I have created a class with :int in order to ensure that "a" property must be an integer, that I can create an instance with float (1.5)? The : int is a type *hint* that isn not enforced by python. If you use a checker program like mypy it will use the type hints and report problems to your. You can install myy with pip. $ python3 -m pip install mypy I put your code in a.py and then checked it: $ /Library/Frameworks/Python.framework/Versions/3.8/bin/mypy a.py a.py:18: error: Argument 1 to "Property" has incompatible type "float"; expected "int" Found 1 error in 1 file (checked 1 source file) As you can see it found the problem. Barry > > Regards. > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Thu Jun 11 17:13:52 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Fri, 12 Jun 2020 09:13:52 +1200 Subject: Typing, how come that :int is not ensuring int parameter? In-Reply-To: References: Message-ID: <7255444e-81b2-d7a6-3b2e-681af5fc15ff@DancesWithMice.info> On 12/06/20 8:51 AM, zljubisic at gmail.com wrote: > Hi, > > If I run this code: > class Property: > > def __init__(self, var: int): > self.a: int = var > > @property > def a(self): > return self.__a > > @a.setter > def a(self, var: int): > if var > 0 and var % 2 == 0: > self.__a = var > else: > self.__a = 2 > > if __name__ == '__main__': > x = Property(1.5) > print(x.a) > > I am getting 2. > How come, if I have created a class with :int in order to ensure that "a" property must be an integer, that I can create an instance with float (1.5)? You may be confusing Python with some other programming language previously-learned. We need to 're-wire' the way your mind is working because whilst you are not-wrong for that-language, you are not-right for Python. So, I'm not going to answer your question directly, but to offer you a learning-path:- What did mypy (or...) say, when you ran tests against the source-code? (Typing is no use without such a testing regime!) Have you read the docs for Typing? - and for extra bonus-points, the numerous PEPs (proposals and accepted) related to how Python implements Typing? (that done, you will likely answer your own question, and accumulate some useful learning about Python - at both the practical and philosophical/idiomatic levels) -- Regards =dn From zljubisic at gmail.com Thu Jun 11 17:32:42 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Thu, 11 Jun 2020 14:32:42 -0700 (PDT) Subject: Typing, how come that :int is not ensuring int parameter? In-Reply-To: References: <7255444e-81b2-d7a6-3b2e-681af5fc15ff@DancesWithMice.info> Message-ID: OK, as I can see nothing is enforced but I can use mypy and tests for the purpose. As I am using pycharm, looks like I need a plugin for mypy. There are two of them out there: non official: https://plugins.jetbrains.com/plugin/11086-mypy and official: https://plugins.jetbrains.com/plugin/13348-mypy-official- Do you have any experience with any of these plugins? Please share your opinion. Best regards. From PythonList at DancesWithMice.info Thu Jun 11 18:03:48 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Fri, 12 Jun 2020 10:03:48 +1200 Subject: Typing, how come that :int is not ensuring int parameter? In-Reply-To: References: <7255444e-81b2-d7a6-3b2e-681af5fc15ff@DancesWithMice.info> Message-ID: <71aae9f4-5d2c-cd0d-8ca3-903ab32b703d@DancesWithMice.info> On 12/06/20 9:32 AM, zljubisic at gmail.com wrote: > OK, as I can see nothing is enforced but I can use mypy and tests for the purpose. Exactly! Well done - Python uses 'duck typing' and thus when the Typing module was added, it became an option. As mentioned elsewhere, it provides "hints" at 'compile time'. > As I am using pycharm, looks like I need a plugin for mypy. > There are two of them out there: > non official: https://plugins.jetbrains.com/plugin/11086-mypy > and official: https://plugins.jetbrains.com/plugin/13348-mypy-official- > > Do you have any experience with any of these plugins? > Please share your opinion. I don't have a competent opinion for the current Pycharm, but hope that others will answer. TBH I'd be surprised if it doesn't come 'baked in'. -- Regards =dn From PythonList at DancesWithMice.info Fri Jun 12 02:03:55 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Fri, 12 Jun 2020 18:03:55 +1200 Subject: Friday Finking: Beyond implementing Unicode Message-ID: <016811bb-4dea-11d6-27bf-a66192fdd61f@etelligence.info> Unicode has given us access to a wealth of mathematical and other symbols. Hardware and soft-/firm-ware flexibility enable us to move beyond and develop new 'standards'. Do we have opportunities to make computer programming more math-familiar and/or more logically-expressive, and thus easier to learn and practice? Could we develop Python to take advantage of these opportunities? TLDR;? Skip to the last paragraphs/block... Back in the ?good, old days, small eight-bit computers advanced beyond many of their predecessors, because we could begin to encode characters and "string" them together - as well as computing with numbers. Initially, we used 7-bit ASCII code (on smaller machines - whereas IBM mainframes used EBCDIC, etc). ASCII gave us both upper- and lower-case letters, digits, special characters, and control codes. Later this was extended to 8-bits as "Code Page 1252", whereby MSFT added more special characters, superscripts, fractions, currency symbols, and many ordinary and combinatorial letters used in other "Romance languages" (European). Latterly, we have implemented Unicode, which seeks to include all of the world's scripts and languages and may employ multiple bytes per 'character'. (simplification) A massive effort went into Python (well done PyDevs!), and the adoption of Unicode in-particular, made Python 3 a less-than seamless upgrade from Python 2. However, 'standing upon the shoulders of giants', we can now take advantage of Unicode both as an encoding for data files, and within the code of our own Python applications. We don't often see examples of the latter, eg >>> ? = 3.14159 >>> r = 1 >>> circumference = 2 * ? * r >>> print( circumference ) 6.28318 >>> Empf?nger = "dn" # Addressee/recipient >>> Stra?enname = "Lansstra?e" # Street name >>> Immobilien_Hausnummer = "42" # Building/house number (whilst the above is valid German, I have 'cheated' in order to add suitable characters - for the purposes of illustration to EN-monolinguals - apologies for any upset to your sense of "ordnung" - please consider the meaning of "42" to restore yourself...) However, we are still shackled to an history where an asterisk (*) is used as the multiplication symbol, because "x" was an ASCII letter. Similarly, we have the ** for an exponential operator, because we didn't have superscripts (per algebraic expression). Worse, we made "=" mean: 'use the identifier to the left to represent the right-hand-side value-result', ie "Let" or "Set" - this despite left-to-right expression making it more logical to say: 'transfer this (left-side) value to the part on the right', ie 'give all of the chocolate cake to me', as well as 'robbing' us of the symbol's usual meaning of "equality" (in Python that had to become the "==" symbol). Don't let me get started on "!" (exclamation/surprise!) meaning "not"! There is/was a language called "APL" (and yes the acronym means "A Programming Language", and yes it started the craze, through "B" (and BCPL), and yes, that brought us "C" - which you are more likely to have heard about - and yes then there were DataSci folk, presumably more numerate than literate, who thought the next letter to be "R". So, sad!?). The point of mentioning APL? It allowed the likes of: AREA?PI?RADIUS?2 APL was hopelessly keyboard-unfriendly, requiring multiple key-presses or 'over-typing' to produce those arithmetic-operator symbols - remember, much of this was on mainframe 3270-style terminals, although later PC-implementations have existed (I can't comment on how 'active' any community might be). The over-typing was necessary to encode/produce the APL symbols which don't exist on a standard typewriter keyboard. Ugh! I'm glad to have limited my APL-exposure to only reading about it during a 'Programming Languages' topic! (If you are 'into' functional programming you may like to explore further) Turning now to "hardware" and the subtle 'limitations' it imposes upon us. PC-users (see also Apple, and glass-keyboard users) have become wedded to the 'standard' 101~105-key "QWERTY"/"AZERTY"/etc keyboards (again, restricting myself to European languages - with due apologies). Yet, there exists a variety of ways to implement the 'standard', as well as a range of other keyboard layouts. Plus we have folk experimenting with SBCs, eg Raspberry Pi; learning how to interpret low-level hardware, ie key-presses and keyboard "arrays", and developing/innovating all-manner of special interfaces and other tools. Back to Python, or is it 'forward to Python': In the same way that we often add a "numeric key-pad" to the standard 'typing' alphanumeric keyboard, could we add another key-pad or row of keys? Might such give us the opportunity to start employing other, and more logical symbols for programming, eg directional arrows, a modifier key to enable subscripts and another for superscripts, Greek/Math symbols to release us from the approximations/alternatives such as asterisk-means-multiply, and so-on...? Could we then also 'update' Python, to accept the wider range of symbols instead/in-addition to those currently in-use? Would such even constitute 'a good idea'? Web.Refs on hardware: https://imgur.com/a/AalpV1r https://github.com/mattdibi/redox-keyboard https://github.com/BenRoe/awesome-mechanical-keyboard https://github.com/help-14/mechanical-keyboard https://github.com/makerdiary/python-keyboard?mc_cid=fc3464732f&mc_eid=cd74eeaf09 Web.Refs on the rest: https://www.ascii-code.com/ https://en.wikipedia.org/wiki/APL_syntax_and_symbols https://en.wikipedia.org/wiki/Digital_encoding_of_APL_symbols https://en.wikipedia.org/wiki/IBM_PC_keyboard -- Regards, =dn From nospam at yrl.co.uk Fri Jun 12 07:05:31 2020 From: nospam at yrl.co.uk (Elliott Roper) Date: Fri, 12 Jun 2020 06:05:31 -0500 Subject: Friday Finking: Beyond implementing Unicode References: <016811bb-4dea-11d6-27bf-a66192fdd61f@etelligence.info> <8f1522b5-b678-48d9-9fa9-3299b910f521o@googlegroups.com> Message-ID: On 12 Jun 2020 at 09:47:04 BST, "moi" wrote: > i) Today there people, who are still not understanding this: > >>>> '?'.encode('utf-8') > b'\xc3\x85' >>>> '?'.encode('utf-16-le') > b'\xc5\x00' >>>> '?'.encode('utf-32-le') > b'\xc5\x00\x00\x00' > > ii) On a Western Europen Windows, Py 3 is not even working > correctly with the *characters* of the Windows-1252 coding > scheme. (As I understand this issue, you may have the same > problem on let say an iso-8859-2 platform). > > iii) When it works, I mean when it *by chance* works, the > result is all by satisfying: > >>>> import timeit >>>> timeit.timeit("s.encode('utf-8')", "s = 'Universit?t Z?rich' * 1000") > 50.96167644299999 >>>> timeit.timeit("s.encode('utf-8')", "s = 'Universitat Zurich' * 1000") > 2.4885878450000973 >>>> > > > iv) ... > v) ... > vi) ... i) Who cares? ii) Breaking News. Windows is mired in backward compatibility. iii) My 3 year old Mac is 5 times faster than that. Get over it. Maths always made its greatest advances after notation improved. Terseness and unambiguity are king. You are looking backward. DL Neil is looking forward. A long way forward. It won't be our generation, our brains are already mis-wired. -- To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 3CF7 637F 896B C810 E199 7E5C A9E4 8E59 E248 From rosuav at gmail.com Fri Jun 12 08:33:34 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 12 Jun 2020 22:33:34 +1000 Subject: Friday Finking: Beyond implementing Unicode In-Reply-To: References: <016811bb-4dea-11d6-27bf-a66192fdd61f@etelligence.info> <8f1522b5-b678-48d9-9fa9-3299b910f521o@googlegroups.com> Message-ID: On Fri, Jun 12, 2020 at 9:11 PM Elliott Roper wrote: > > On 12 Jun 2020 at 09:47:04 BST, "moi" wrote: > i) Who cares? Don't bother responding to him. He's somehow gotten the idea that Python's Unicode support is broken, and he spews his vomit out onto the newsgroup periodically. He's blocked from the mailing list, and for good reason. Ignore him and save yourself the hassle. ChrisA From robin at reportlab.com Fri Jun 12 11:09:52 2020 From: robin at reportlab.com (Robin Becker) Date: Fri, 12 Jun 2020 16:09:52 +0100 Subject: pyinstaller In-Reply-To: References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> <29588d52-22ea-9f4d-d356-7c547a500c2d@everest.reportlab.co.uk> <6b9e6a9c-6f3a-2403-cb70-d47a408f34c9@everest.reportlab.co.uk> Message-ID: On 11/06/2020 16:39, Grant Edwards wrote: > the hands of the developer. I suppose the OP could quit and stand on > the street corner with a cardboard sign: I would love to do that :) From tjreedy at udel.edu Fri Jun 12 12:47:57 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 12 Jun 2020 12:47:57 -0400 Subject: Friday Finking: Beyond implementing Unicode In-Reply-To: <016811bb-4dea-11d6-27bf-a66192fdd61f@etelligence.info> References: <016811bb-4dea-11d6-27bf-a66192fdd61f@etelligence.info> Message-ID: On 6/12/2020 2:03 AM, DL Neil via Python-list wrote: > Unicode has given us access to a wealth of mathematical and other > symbols. Hardware and soft-/firm-ware flexibility enable us to move > beyond and develop new 'standards'. Do we have opportunities to make > computer programming more math-familiar and/or more > logically-expressive, and thus easier to learn and practice? Could we > develop Python to take advantage of these opportunities? ... > Could we then also 'update' Python, to accept the wider range of symbols > instead/in-addition to those currently in-use? > > Would such even constitute 'a good idea'? There was a recent thread on python-ideas discussing this. It started with arrow characters. There have been others. -- Terry Jan Reedy From jsid2387 at gmail.com Fri Jun 12 16:49:45 2020 From: jsid2387 at gmail.com (Siddharth Joshi) Date: Fri, 12 Jun 2020 21:49:45 +0100 Subject: Python database compatibility Message-ID: All, I am new in Python world and would like to use it for one of the our purpose . Before that, I would like to ask if Python has compatibility with ENSCRIBE database . Enscribe database (file structured) is the native database of HP NonStop (Tandem) server, mainly used in applications running on nonStop Tandem . Almost all the applications which runs on Tandem using enscribe are Tier 0 applications (often critical once). Would be good if anyone let me know on Python and Enscribe compatibility. Many thanks Sid From larry.martell at gmail.com Fri Jun 12 17:12:05 2020 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 12 Jun 2020 17:12:05 -0400 Subject: Python database compatibility In-Reply-To: References: Message-ID: On Fri, Jun 12, 2020 at 5:03 PM Siddharth Joshi wrote: > > All, > > I am new in Python world and would like to use it for one of the our > purpose . Before that, I would like to ask if Python has compatibility with > ENSCRIBE database . > > Enscribe database (file structured) is the native database of HP NonStop > (Tandem) server, mainly used in applications running on nonStop Tandem . > Almost all the applications which runs on Tandem using enscribe are Tier 0 > applications (often critical once). > > Would be good if anyone let me know on Python and Enscribe compatibility. If you can use ODBC with it then you can use python with it. From PythonList at DancesWithMice.info Fri Jun 12 18:29:39 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 13 Jun 2020 10:29:39 +1200 Subject: pyinstaller In-Reply-To: References: <4804ac0a-02cd-097f-d3e1-af964383bf8d@everest.reportlab.co.uk> <29588d52-22ea-9f4d-d356-7c547a500c2d@everest.reportlab.co.uk> <6b9e6a9c-6f3a-2403-cb70-d47a408f34c9@everest.reportlab.co.uk> Message-ID: On 13/06/20 3:09 AM, Robin Becker wrote: > On 11/06/2020 16:39, Grant Edwards wrote: >> the hands of the developer.? I suppose the OP could quit and stand on >> the street corner with a cardboard sign: > I would love to do that :) Of possible interest to folk interested in this thread: Recently came across this article: https://www.activestate.com/blog/how-to-convert-py-to-exe/ NB have no assessment/advice to report -- Regards =dn From PythonList at DancesWithMice.info Fri Jun 12 19:26:26 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 13 Jun 2020 11:26:26 +1200 Subject: Python database compatibility In-Reply-To: References: Message-ID: On 13/06/20 8:49 AM, Siddharth Joshi wrote: > I am new in Python world and would like to use it for one of the our > purpose . Before that, I would like to ask if Python has compatibility with > ENSCRIBE database . > > Enscribe database (file structured) is the native database of HP NonStop > (Tandem) server, mainly used in applications running on nonStop Tandem . > Almost all the applications which runs on Tandem using enscribe are Tier 0 > applications (often critical once). Wow, a 'blast from the past'! I worked on HP3000s (from which Tandem originally developed) forty years ago. My first foray into 'non-stop' computing, supporting banking systems and the like, involved jumping-ship to Stratus (or more precisely, the re-badged IBM System/88). Others were also involved in that project, so happily/sadly I ended-up consulting for a project that no-one else wanted: figuring out how to network those new-fangled IBM PC/XTs and integrate office systems with aforementioned DBs and similar. After all that, please excuse me whilst I take a grandpa-snooze... The question is broad. What do you want to do once an interface can be found, eg do you merely want a one-off use to transcribe the old data to a new system, do you want to build a front-end interface and data-collection application, or is perhaps a back-end MIS analysis your goal? The quality of the interface, its speed, its data-handling capabilities, etc, etc, will all influence... I haven't heard about Enscribe in recent years. My recollection is that their direct interfaces were Java-based. Python offers a JDBC "connector" which may be worth investigating. There are also other new/improved/faster/super libraries, eg JayDeBeAPI - see PyPi. See also Attunity (if still available, eg http://whp-aus2.cold.extweb.hp.com/pub/nonstop/ccc/apr0110.pdf). HP pursued various 'modernisation' proposals, which may be worth review, eg using SOAP/micro-services and XML/interchange. The comp.sys.tandem forum discussed ideas (five years ago): https://groups.google.com/forum/#!topic/comp.sys.tandem/dG2t9faPzWg The lingua-franca of DB inter-connection is probably ODBC, and thus the Python ODBC connector. Trusting these give some food-for-thought... -- Regards =dn From barry at barrys-emacs.org Sat Jun 13 06:35:33 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Sat, 13 Jun 2020 11:35:33 +0100 Subject: Announcing Scm Workbench 0.9.4 for Git, Mercurial and Subversion Message-ID: SCM Workbench features * Support Subversion (svn), Mercurial (hg) and Git projects. * Experimental support for Perforce (P4) * Easy to learn and use * Builtin User Guide describes the operation and features of the application. * Add project wizard can scan for all your existing projects. * All subversion client operations in a GUI * Many Git client operations in a GUI * GUI git rebase * Some mercurial (hg) client operations in a GUI * Enhanced operations (subversion rename of modified files etc) * Support for Dark mode * Support software development workflow * Builtin GUI diff showing line and character diffs * Ability to diff between revisions in a files history * Runs on Windows, Mac OS X and Unix platforms Please visit http://scm-workbench.barrys-emacs.org/ for downloads, git source, user guide and further information on SCM Workbench. New in 0.9.4 * Feature to show all commits since a tag (great for writing release notes) * Update to Python 3.8 for built kits * Build tools for macOS and Windows use venv * Fix problem with creating editor and shell process on macOS 10.15 * Fix traceback with changing SVN properties * Fix styles for light mode diff * Support favourites that start with "Config". Barry From Bischoop at vimuster.net Sat Jun 13 06:40:12 2020 From: Bischoop at vimuster.net (Bischoop) Date: Sat, 13 Jun 2020 10:40:12 -0000 (UTC) Subject: change surface Message-ID: I'm playing with pygame, https://bpa.st/6GOQ Not sure what is wrong here that object moves but draws another surface. From mats at wichmann.us Sat Jun 13 10:41:22 2020 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 13 Jun 2020 08:41:22 -0600 Subject: Fwd: python 3.8.3 fails In-Reply-To: References: Message-ID: <09fdf90c-39eb-5a2f-a49c-780b879546b5@wichmann.us> On 6/11/20 8:58 AM, Avraham Markov wrote: > Please suggest something to fix > > ---------- Forwarded message --------- > From: Avraham Markov > Date: Thu, Jun 11, 2020 at 5:50 PM > Subject: python 3.8.3 fails > To: > > > Hello, I successfully installed Python 3.8.3 (64-bit) > at Windows 10 LTSC 64 bit by python-3.8.3-amd64 installer > from https://www.python.org/downloads/windows/ > Also by python-3.8.3 installer, > but lastly by python-3.8.3-amd64 installer. > Then when I open powershell, > > PS C:\Users\AlexJer> python > python : Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC > v.1924 64 bit (AMD64)] on win32 > At line:1 char:1 > + python > + ~~~~~~ > + CategoryInfo : NotSpecified: (Python 3.8.3 (t...MD64)] on > win32:String) [], RemoteException > + FullyQualifiedErrorId : NativeCommandError > > Type "help", "copyright", "credits" or "license" for more information. >> For reasons which someone wiser in the ways of Powershell will have to describe, you have to run some programs programs with a more qualified name. That is, try running: python.exe Alternatives: the Python launcher doesn't have this limitation. Try running: py If you used the python.org installer, the Python Launcher is recommended anyway. The Python install from the Microsoft Store also doesn't have that limitation, if you install that you should be able to run by typing just python There's probably some simple setup to make it work as we might expect/wish in Powershell... but the point is: there's nothing *wrong* with your setup. From python at mrabarnett.plus.com Sat Jun 13 12:10:46 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 13 Jun 2020 17:10:46 +0100 Subject: Fwd: python 3.8.3 fails In-Reply-To: <09fdf90c-39eb-5a2f-a49c-780b879546b5@wichmann.us> References: <09fdf90c-39eb-5a2f-a49c-780b879546b5@wichmann.us> Message-ID: <112ca10b-78f4-507b-5d76-537d6e5240bf@mrabarnett.plus.com> On 2020-06-13 15:41, Mats Wichmann wrote: > On 6/11/20 8:58 AM, Avraham Markov wrote: >> Please suggest something to fix >> >> ---------- Forwarded message --------- >> From: Avraham Markov >> Date: Thu, Jun 11, 2020 at 5:50 PM >> Subject: python 3.8.3 fails >> To: >> >> >> Hello, I successfully installed Python 3.8.3 (64-bit) >> at Windows 10 LTSC 64 bit by python-3.8.3-amd64 installer >> from https://www.python.org/downloads/windows/ >> Also by python-3.8.3 installer, >> but lastly by python-3.8.3-amd64 installer. >> Then when I open powershell, >> >> PS C:\Users\AlexJer> python >> python : Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC >> v.1924 64 bit (AMD64)] on win32 >> At line:1 char:1 >> + python >> + ~~~~~~ >> + CategoryInfo : NotSpecified: (Python 3.8.3 (t...MD64)] on >> win32:String) [], RemoteException >> + FullyQualifiedErrorId : NativeCommandError >> >> Type "help", "copyright", "credits" or "license" for more information. >>> > > For reasons which someone wiser in the ways of Powershell will have to > describe, you have to run some programs programs with a more qualified > name. That is, try running: > > python.exe > > Alternatives: the Python launcher doesn't have this limitation. Try > running: > > py > > If you used the python.org installer, the Python Launcher is recommended > anyway. > > The Python install from the Microsoft Store also doesn't have that > limitation, if you install that you should be able to run by typing just > > python > > There's probably some simple setup to make it work as we might > expect/wish in Powershell... but the point is: there's nothing *wrong* > with your setup. > I have Windows 10 Home and the stock Python from python.org. Typing just "python" at the Powershell prompt starts Python without a problem. From PythonList at DancesWithMice.info Sat Jun 13 17:25:59 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 14 Jun 2020 09:25:59 +1200 Subject: change surface In-Reply-To: References: Message-ID: <460464da-f4d0-ccdf-7625-178c500a130c@DancesWithMice.info> On 13/06/20 10:40 PM, Bischoop wrote: > I'm playing with pygame, https://bpa.st/6GOQ > Not sure what is wrong here that object moves but draws another > surface. (not sure how many will click on a link like that - best to copy-paste code into (text) email message) The most usual reason for 'leaving' an old version of a surface visible, when a new frame is drawn by the game-loop, is that there is no code to 'wipe' the old before painting the new 'on top'. Either: 1 keep track of the position of each moving surface and before calculating its new position (and adding it to the background), execute appropriate code to wipe it (and restore whatever was 'underneath'). 2 clear the entire display, and build it again from 'background' to 'foreground'. (takes longer but is 'guaranteed') -- Regards =dn From Bischoop at vimuster.net Sun Jun 14 06:12:26 2020 From: Bischoop at vimuster.net (Bischoop) Date: Sun, 14 Jun 2020 10:12:26 -0000 (UTC) Subject: close() the file when opening "with"? Message-ID: So far I learnt "with" closes the file opened therefore "Generally" no need to close() file. I'm worry about this "Generally", then close() or not? From rosuav at gmail.com Sun Jun 14 06:27:02 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 14 Jun 2020 20:27:02 +1000 Subject: close() the file when opening "with"? In-Reply-To: References: Message-ID: On Sun, Jun 14, 2020 at 8:16 PM Bischoop wrote: > > > So far I learnt "with" closes the file opened therefore "Generally" no > need to close() file. I'm worry about this "Generally", then close() or > not? Where did you learn that? Can you cite a reference? If you use a with block, the file is guaranteed to be closed as you exit that block. It's that simple. ChrisA From Bischoop at vimuster.net Sun Jun 14 06:36:06 2020 From: Bischoop at vimuster.net (Bischoop) Date: Sun, 14 Jun 2020 10:36:06 -0000 (UTC) Subject: close() the file when opening "with"? References: Message-ID: On 2020-06-14, Chris Angelico wrote: > On Sun, Jun 14, 2020 at 8:16 PM Bischoop wrote: >> >> >> So far I learnt "with" closes the file opened therefore "Generally" no >> need to close() file. I'm worry about this "Generally", then close() or >> not? > > Where did you learn that? Can you cite a reference? > > If you use a with block, the file is guaranteed to be closed as you > exit that block. It's that simple. > > ChrisA Where I learnt what that "with" closes the file or that "Generally" no need to close() file when using "with"? From vincent at vincentdavis.net Sun Jun 14 10:35:27 2020 From: vincent at vincentdavis.net (Vincent Davis) Date: Sun, 14 Jun 2020 08:35:27 -0600 Subject: Convert and analyze image data in a spreadsheet. In-Reply-To: References: Message-ID: Dennis, Thanks for your ideas. The researcher I am working with just told me the data is wrong and needs to send me new data and there are other problems with exactly what their research questions is. So this goes nowhere for now. Thanks Vincent Davis 720-301-3003 *Want to get a hold of me?* *SMS: awesome.phone: ok...* *email: bad!* On Thu, Jun 11, 2020 at 1:17 PM Dennis Lee Bieber wrote: > > My previous response hasn't made it through the > gmane<>list<>usenet<>back cycle so I can't "talk to myself"... > > On Thu, 11 Jun 2020 07:44:25 -0600, Vincent Davis > declaimed the following: > > >Looking for a little advise. > >I have 6x6 color (CIELAB < > https://en.wikipedia.org/wiki/CIELAB_color_space>) > >data in a spreadsheet (color samples of clothing). I would like to > >visualize this as an image on a per channel (l,a,b) and as a color image. > I > >can read the data from the spreadsheet. I am not sure the path a should > >choose from there. I think the path is to read this data into a numpy > array > >and use scikit-image. > > > > I'm going to speak blasphemy and mention the R statistics package. > It > has > > https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/convertColor.html > which includes L*a*b* as a color space. Though it does not seem to have > Adobe RGB... > """ > "XYZ", "sRGB", "Apple RGB", "CIE RGB", "Lab", "Luv". > """ > > Also links to the main page of a source of the math used in > converting > > It also mentions something that wasn't obvious in other references: > """ > The Lab and Luv spaces describe colors of objects, and so require the > specification of a reference ?white light? color. Illuminant D65 is a > standard indirect daylight, Illuminant D50 is close to direct sunlight, and > Illuminant A is the light from a standard incandescent bulb. Other standard > CIE illuminants supported are B, C, E and D55. RGB colour spaces are > defined relative to a particular reference white, and can be only > approximately translated to other reference whites. > """ > > ... hence conversions from L*a*b* to, say, sRGB, will differ based upon > what illumination reference is used! > > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com > http://wlfraed.microdiversity.freeddns.org/ > > -- > https://mail.python.org/mailman/listinfo/python-list > From jsid2387 at gmail.com Sun Jun 14 11:21:49 2020 From: jsid2387 at gmail.com (Siddharth Joshi) Date: Sun, 14 Jun 2020 16:21:49 +0100 Subject: Python database compatibility In-Reply-To: References: Message-ID: Thanks Neil for your input . I am looking for opportunities to connect to the Tandem DB ( enscribe) via using Payton programs to analyse the data /patterns of the txns. I am very new in Python world so don,t know how these can be achieved ! In our setup , Tandem DB is not connected via any other 3rd party system therefore don?t know if JDBC/ODBC works here or not. But will go through the link you have given and see if there are any!! Thanks Sid On Sat, 13 Jun 2020 at 00:27, DL Neil via Python-list < python-list at python.org> wrote: > On 13/06/20 8:49 AM, Siddharth Joshi wrote: > > I am new in Python world and would like to use it for one of the our > > purpose . Before that, I would like to ask if Python has compatibility > with > > ENSCRIBE database . > > > > Enscribe database (file structured) is the native database of HP NonStop > > (Tandem) server, mainly used in applications running on nonStop Tandem . > > Almost all the applications which runs on Tandem using enscribe are Tier > 0 > > applications (often critical once). > > Wow, a 'blast from the past'! > > I worked on HP3000s (from which Tandem originally developed) forty years > ago. My first foray into 'non-stop' computing, supporting banking > systems and the like, involved jumping-ship to Stratus (or more > precisely, the re-badged IBM System/88). Others were also involved in > that project, so happily/sadly I ended-up consulting for a project that > no-one else wanted: figuring out how to network those new-fangled IBM > PC/XTs and integrate office systems with aforementioned DBs and similar. > After all that, please excuse me whilst I take a grandpa-snooze... > > > The question is broad. What do you want to do once an interface can be > found, eg do you merely want a one-off use to transcribe the old data to > a new system, do you want to build a front-end interface and > data-collection application, or is perhaps a back-end MIS analysis your > goal? The quality of the interface, its speed, its data-handling > capabilities, etc, etc, will all influence... > > > I haven't heard about Enscribe in recent years. My recollection is that > their direct interfaces were Java-based. Python offers a JDBC > "connector" which may be worth investigating. There are also other > new/improved/faster/super libraries, eg JayDeBeAPI - see PyPi. See also > Attunity (if still available, eg > http://whp-aus2.cold.extweb.hp.com/pub/nonstop/ccc/apr0110.pdf). > > HP pursued various 'modernisation' proposals, which may be worth review, > eg using SOAP/micro-services and XML/interchange. > > The comp.sys.tandem forum discussed ideas (five years ago): > https://groups.google.com/forum/#!topic/comp.sys.tandem/dG2t9faPzWg > > The lingua-franca of DB inter-connection is probably ODBC, and thus the > Python ODBC connector. > > > Trusting these give some food-for-thought... > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From zljubisic at gmail.com Sun Jun 14 11:20:46 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Sun, 14 Jun 2020 08:20:46 -0700 (PDT) Subject: How to keep Dict[str, List] default method parameter as local to the method? Message-ID: Hi, consider this example: from typing import Dict, List class chk_params: def execute(self, params: Dict[str, List] = None): if params is None: params = {} for k, v in params.items(): params[k] = [val + 10 for val in v] return params.values() params = { 'A' : [1], 'B': [2], 'C': [3], 'D': [4], 'E': [5] } print(params) params_obj = chk_params() print(params_obj.execute(params = params)) print(params) Output is: {'A': [1], 'B': [2], 'C': [3], 'D': [4], 'E': [5]} dict_values([[11], [12], [13], [14], [15]]) {'A': [11], 'B': [12], 'C': [13], 'D': [14], 'E': [15]} I expected that last print statement will show original parameters A=1, B=2... but this is not the case. How to construct the method parameters, with params parameter as type of Dict[str, List], but at the same time keep params as local dictionary to the chk_params.execute() method? From kushal at locationd.net Sun Jun 14 12:02:46 2020 From: kushal at locationd.net (Kushal Kumaran) Date: Sun, 14 Jun 2020 09:02:46 -0700 Subject: How to keep Dict[str, List] default method parameter as local to the method? In-Reply-To: (zljubisic's message of "Sun, 14 Jun 2020 08:20:46 -0700 (PDT)") References: Message-ID: <87v9jt4oux.fsf@copper.locationd.net> zljubisic at gmail.com writes: > Hi, > > consider this example: > > from typing import Dict, List > > > class chk_params: > def execute(self, params: Dict[str, List] = None): > if params is None: > params = {} > > for k, v in params.items(): > params[k] = [val + 10 for val in v] > > return params.values() > > params = { > 'A' : [1], > 'B': [2], > 'C': [3], > 'D': [4], > 'E': [5] > } > print(params) > params_obj = chk_params() > > print(params_obj.execute(params = params)) > print(params) > > Output is: > {'A': [1], 'B': [2], 'C': [3], 'D': [4], 'E': [5]} > dict_values([[11], [12], [13], [14], [15]]) > {'A': [11], 'B': [12], 'C': [13], 'D': [14], 'E': [15]} > > I expected that last print statement will show original parameters A=1, B=2... but this is not the case. > > How to construct the method parameters, with params parameter as type of Dict[str, List], but at the same time keep params as local dictionary to the chk_params.execute() method? The execute method modifies the dict being passed into it. If you don't want that behaviour, you can pass in a copy of your params object. dict(params) will make a shallow copy, which will work in this particular case. If the execute method were to do in-place modification operation on the values (perhaps using v.append or v.extend in its loop), you'd need a deep copy provided by the standard library's copy.deepcopy function. -- regards, kushal From dieter at handshake.de Sun Jun 14 12:21:52 2020 From: dieter at handshake.de (Dieter Maurer) Date: Sun, 14 Jun 2020 18:21:52 +0200 Subject: How to keep Dict[str, List] default method parameter as local to the method? In-Reply-To: References: Message-ID: <24294.20128.456567.41958@ixdm.fritz.box> zljubisic at gmail.com wrote at 2020-6-14 08:20 -0700: >Hi, > >consider this example: > >from typing import Dict, List > > >class chk_params: > def execute(self, params: Dict[str, List] = None): > if params is None: > params = {} > > for k, v in params.items(): > params[k] = [val + 10 for val in v] > > return params.values() > >params = { > 'A' : [1], > 'B': [2], > 'C': [3], > 'D': [4], > 'E': [5] >} >print(params) >params_obj = chk_params() > >print(params_obj.execute(params = params)) >print(params) > >Output is: >{'A': [1], 'B': [2], 'C': [3], 'D': [4], 'E': [5]} >dict_values([[11], [12], [13], [14], [15]]) >{'A': [11], 'B': [12], 'C': [13], 'D': [14], 'E': [15]} > >I expected that last print statement will show original parameters A=1, B=2... but this is not the case. You must distinquish between the "name -> object" binding of function arguments and modifications of the object. You change the binding via assignments to the name (in your case of the form "params = ..."). Those assignments affect only the local name (i.e. in the function), not bindings of the name name elsewhere. If you change the object itself ("params" is bound to) (in your case via "params[k] = ..."), then the object changes - and this change can be seen at other places where this object is accessible. If you want object modifications made in your function not be seen elsewhere, you must work on a local object (not accessible elsewhere: e.g. def execute(self, params: Dict[str, List] = None): params = {} if params is None else params.copy() # copies ... From hjp-python at hjp.at Sun Jun 14 13:21:23 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 14 Jun 2020 19:21:23 +0200 Subject: close() the file when opening "with"? In-Reply-To: References: Message-ID: <20200614172123.GA24728@hjp.at> On 2020-06-14 10:12:26 -0000, Bischoop wrote: > So far I learnt "with" closes the file opened therefore "Generally" no > need to close() file. I'm worry about this "Generally", then close() or > not? In some cases you don't want the file to be automatically closed when you leave the context where you opened it (for example, you might want to write a function which opens a file, does some checks on it and then returns the file handle to the caller so that it can read or write the file). In those cases you can't use "with open ..." and you will have to close the file in some other fashion (for example, the caller could be responsible for calling close, or you could write your function as a context manager and the caller could call it as "with my_open ...") So, "generally" you want to use open together with "with" (and then the file will be automatically closed), but sometimes you want to do soemthing else. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From __peter__ at web.de Sun Jun 14 13:43:34 2020 From: __peter__ at web.de (Peter Otten) Date: Sun, 14 Jun 2020 19:43:34 +0200 Subject: How to keep Dict[str, List] default method parameter as local to the method? References: Message-ID: zljubisic at gmail.com wrote: > Hi, > > consider this example: > > from typing import Dict, List > > > class chk_params: > def execute(self, params: Dict[str, List] = None): > if params is None: > params = {} > > for k, v in params.items(): > params[k] = [val + 10 for val in v] > > return params.values() > > params = { > 'A' : [1], > 'B': [2], > 'C': [3], > 'D': [4], > 'E': [5] > } > print(params) > params_obj = chk_params() > > print(params_obj.execute(params = params)) > print(params) > > Output is: > {'A': [1], 'B': [2], 'C': [3], 'D': [4], 'E': [5]} > dict_values([[11], [12], [13], [14], [15]]) > {'A': [11], 'B': [12], 'C': [13], 'D': [14], 'E': [15]} > > I expected that last print statement will show original parameters A=1, > B=2... but this is not the case. > > How to construct the method parameters, with params parameter as type of > Dict[str, List], but at the same time keep params as local dictionary to > the chk_params.execute() method? The type annotations are only a distraction here; let's give classical Python a chance with - no type annotations - no class - dangerous default, for the thrill of it;) def execute(params={}): return [[val + 10 for val in v] for v in params.values()] Clean and simple. If you insist on getting dict_values(): def execute(params={}): return {k: [val + 10 for val in v] for k, v in params.items()}.values() The relevant takeaway is: if you don't want to modify a value, don't modify it. Do not wait for a const modifier to save you. From hjp-python at hjp.at Sun Jun 14 13:44:32 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 14 Jun 2020 19:44:32 +0200 Subject: How to keep Dict[str, List] default method parameter as local to the method? In-Reply-To: References: Message-ID: <20200614174432.GB24728@hjp.at> On 2020-06-14 08:20:46 -0700, zljubisic at gmail.com wrote: > consider this example: > > from typing import Dict, List > > > class chk_params: > def execute(self, params: Dict[str, List] = None): > if params is None: > params = {} > > for k, v in params.items(): > params[k] = [val + 10 for val in v] > > return params.values() > > params = { > 'A' : [1], > 'B': [2], > 'C': [3], > 'D': [4], > 'E': [5] > } > print(params) > params_obj = chk_params() > > print(params_obj.execute(params = params)) > print(params) > > Output is: > {'A': [1], 'B': [2], 'C': [3], 'D': [4], 'E': [5]} > dict_values([[11], [12], [13], [14], [15]]) > {'A': [11], 'B': [12], 'C': [13], 'D': [14], 'E': [15]} > > I expected that last print statement will show original parameters > A=1, B=2... but this is not the case. Others have already explained that. > How to construct the method parameters, with params parameter as type > of Dict[str, List], but at the same time keep params as local > dictionary to the chk_params.execute() method? Take one step back. What you really want is for chk_params.execute to return the new values and not to modify the old dict. Whether or not params is a "local dictionary" (that doesn't really make much sense in Python[1]) is an irrelevant implementation detail. So lets do that: class chk_params: def execute(self, params: Dict[str, List] = None): if params is None: params = {} result = {} for k, v in params.items(): result[k] = [val + 10 for val in v] return result.values() Of course at this point I notice that you are building a dict which you don't need, so I would simplify that further: class chk_params: def execute(self, params: Dict[str, List] = None): if params is None: params = {} result = [] for k, v in params.items(): result.append([val + 10 for val in v]) return result hp [1] There is a very good talk by Raymond Hettinger on how variables and objects in Python work. Unfortunately I can't find it at the moment. -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From hjp-python at hjp.at Sun Jun 14 13:48:48 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 14 Jun 2020 19:48:48 +0200 Subject: How to keep Dict[str, List] default method parameter as local to the method? In-Reply-To: <20200614174432.GB24728@hjp.at> References: <20200614174432.GB24728@hjp.at> Message-ID: <20200614174848.GC24728@hjp.at> On 2020-06-14 19:44:32 +0200, Peter J. Holzer wrote: > [1] There is a very good talk by Raymond Hettinger on how variables and > objects in Python work. Unfortunately I can't find it at the moment. Sorry, that talk was by Ned Batchelder (that's why I couldn't find it): https://www.youtube.com/watch?v=_AEJHKGk9ns hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From zljubisic at gmail.com Sun Jun 14 13:55:02 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Sun, 14 Jun 2020 10:55:02 -0700 (PDT) Subject: How to keep Dict[str, List] default method parameter as local to the method? In-Reply-To: References: <24294.20128.456567.41958@ixdm.fritz.box> Message-ID: params = {} if params is None else params.copy() has solved the problem. I have provided just a toy example here. Execute method actually takes dict[str, List]. List contains objects. Each object has two properties, so I have a logic that analyzes these properties and returns None or List as a dict[k] value. Now when I have dict prepared with proper key/values pairs, I am proceeding to execution of the jinjasql query. What I have to ensure is that I will get dic[str, List] (I could go further and ensure that list contains only object of certain class, by the way, how to do that?). Than I must ensure that I am working on local copy of parameters. Anyway, copy that Dieter Maurer suggested works as it should. Thanks. From zljubisic at gmail.com Sun Jun 14 14:24:23 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Sun, 14 Jun 2020 11:24:23 -0700 (PDT) Subject: How to keep Dict[str, List] default method parameter as local to the method? In-Reply-To: References: <20200614174432.GB24728@hjp.at> <20200614174848.GC24728@hjp.at> Message-ID: Thanks for the video. Now it is clear to me what has happened and why copy solves the problem. From tjreedy at udel.edu Sun Jun 14 09:05:06 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Jun 2020 09:05:06 -0400 Subject: Fwd: python 3.8.3 fails In-Reply-To: <5l6aef5k4o6pndl8h0mfi5lccl5ob05jfa@4ax.com> References: <09fdf90c-39eb-5a2f-a49c-780b879546b5@wichmann.us> <112ca10b-78f4-507b-5d76-537d6e5240bf@mrabarnett.plus.com> <5l6aef5k4o6pndl8h0mfi5lccl5ob05jfa@4ax.com> Message-ID: On 6/13/2020 2:38 PM, Dennis Lee Bieber wrote: > On Sat, 13 Jun 2020 17:10:46 +0100, MRAB > declaimed the following: > >> I have Windows 10 Home and the stock Python from python.org. Typing just >> "python" at the Powershell prompt starts Python without a problem. > > 99 44/100% sure what the OP called "PowerShell" is "PowerShell ISE", > not a PowerShell console. In my testing ISE intercepts STDIN and STDERR -- > Interactive Python dumps its banner message on STDERR. ISE intercepts that > banner and tries to interpret it as a PowerShell error object, which fails, > causing a PowerShell error dump to be shown. The interception of STDIN > prevents the Python >>> prompt from receiving any input. Buffering of > STDOUT is also in play... > > -=-=-=- ISE (using to abort hanging commands) > PS C:\Users\Wulfraed> python -c "print(input('type something'))" > > PS C:\Users\Wulfraed> python -c "x = input('Enter something '); print(x)" > > PS C:\Users\Wulfraed> python -c "x = input('Enter something\n '); print(x)" > Enter something > > PS C:\Users\Wulfraed> > > > -=-=-=- PS console window > PS C:\Users\Wulfraed> python -c "print(input('type something'))" > type somethingabc > abc > PS C:\Users\Wulfraed> python -c "x = input('Enter something '); print(x)" > Enter something abcd > abcd > PS C:\Users\Wulfraed> python -c "x = input('Enter something\n '); print(x)" > Enter something > something > something > PS C:\Users\Wulfraed> Could you open a tracker issue to put 'Do not use PowerShell IDE' is the Windows chapter of 'Using Python'? This is obviously not common knowledge? Or open as a possible bug issue. Maybe the install can be done a big differently. -- Terry Jan Reedy From tjreedy at udel.edu Sun Jun 14 09:06:32 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 14 Jun 2020 09:06:32 -0400 Subject: close() the file when opening "with"? In-Reply-To: References: Message-ID: On 6/14/2020 6:36 AM, Bischoop wrote: > On 2020-06-14, Chris Angelico wrote: >> On Sun, Jun 14, 2020 at 8:16 PM Bischoop wrote: >>> >>> >>> So far I learnt "with" closes the file opened therefore "Generally" no >>> need to close() file. I'm worry about this "Generally", then close() or >>> not? >> >> Where did you learn that? Can you cite a reference? >> >> If you use a with block, the file is guaranteed to be closed as you >> exit that block. It's that simple. >> >> ChrisA > > Where I learnt what that "with" closes the file or that "Generally" no > need to close() file when using "with"? The latter. Chris said that the former is true. The qualification in the latter should not be. -- Terry Jan Reedy From jpic at yourlabs.org Sun Jun 14 09:21:01 2020 From: jpic at yourlabs.org (J. Pic) Date: Sun, 14 Jun 2020 15:21:01 +0200 Subject: Multiple event loops within the same thread ? Message-ID: Hi all, It's possible to create several event loops in the same thread by calling asyncio.new_event_loop() Question: is there any use case where that could be useful ? Thank you in advance -- ? From sjkelleyjr at gmail.com Sun Jun 14 10:58:22 2020 From: sjkelleyjr at gmail.com (sjkelleyjr at gmail.com) Date: Sun, 14 Jun 2020 07:58:22 -0700 (PDT) Subject: In this episode we write a full-text search engine using bloom filters! What other packages are you aware of that can act as search engines? Message-ID: <8006d6f2-0b92-4844-ad8d-5503f6a8d602o@googlegroups.com> https://youtu.be/MHatF6Hpm1U From soorajspadmanabhan at gmail.com Mon Jun 15 04:47:44 2020 From: soorajspadmanabhan at gmail.com (emagnun) Date: Mon, 15 Jun 2020 01:47:44 -0700 (PDT) Subject: python object is NoneType even after declaring as global: ttk textbox Message-ID: <57d89ff9-2396-4cfa-b997-67accd4bf4eao@googlegroups.com> I have a very simple script that retrieves the value from a text box upon click of a checkButton. But in click event, I'm receiving text box object as NoneType even after setting it as global. Pls help. Output: !!ERROR!! Tag is None ########### Source Code ########### from tkinter import * from tkinter import ttk import os def submitData(): global tag global tagBox if (tagBox is not None): tag = tagBox.get("1.0","end-1c") print ("!!SUCESS!! tag -->", tag) else: print ("!!ERROR!! Tag is None") gui = Tk() gui.title("GUI") gui.geometry('250x300') tag = "NA" tagBoxLabel = Label(gui, text = "Tag: ").grid(column=0, row=5, pady=30, sticky="EN") tagBox = Text(gui, height=1, width=20).grid(column=1, row=5, pady=30, sticky="WN") submitButton = ttk.Button(gui, text="Submit", command=lambda: submitData()).grid(column=1, row=7) gui.mainloop() From __peter__ at web.de Mon Jun 15 06:17:55 2020 From: __peter__ at web.de (Peter Otten) Date: Mon, 15 Jun 2020 12:17:55 +0200 Subject: python object is NoneType even after declaring as global: ttk textbox References: <57d89ff9-2396-4cfa-b997-67accd4bf4eao@googlegroups.com> Message-ID: emagnun wrote: > I have a very simple script that retrieves the value from a text box upon > click of a checkButton. But in click event, I'm receiving text box object > as NoneType even after setting it as global. Pls help. > > Output: !!ERROR!! Tag is None > > ########### Source Code ########### > from tkinter import * > from tkinter import ttk > import os > > def submitData(): > global tag > global tagBox You do not need the global declaration for tagBox as you do not rebind that name. > if (tagBox is not None): > tag = tagBox.get("1.0","end-1c") > print ("!!SUCESS!! tag -->", tag) > else: > print ("!!ERROR!! Tag is None") > > gui = Tk() > gui.title("GUI") > gui.geometry('250x300') > > tag = "NA" > tagBoxLabel = Label(gui, text = "Tag: ").grid(column=0, row=5, pady=30, > sticky="EN") > tagBox = Text(gui, height=1, width=20).grid(column=1, row=5, > pady=30, sticky="WN") The grid() method always returns None. So tagBoxLabel, tagBox, and submitButton are all bound to None. To get a reference of the widget you need two steps: # bind tagBox tagBox = Text(...) # define layout tagBox.grid(...) > submitButton = ttk.Button(gui, text="Submit", command=lambda: > submitData()).grid(column=1, row=7) > gui.mainloop() Superfluous lambda alert: instead of lambda: submitData() just write submitData , i. e.: ttk.Button(..., command=submitData).grid() From m at funkyhat.org Tue Jun 16 09:35:53 2020 From: m at funkyhat.org (Matt Wheeler) Date: Tue, 16 Jun 2020 13:35:53 +0000 (UTC) Subject: How to turn a defaultdict into a normal dict. In-Reply-To: References: <296747fe-d12e-5d0e-0749-1ff7fb0d4de1@vub.be> Message-ID: On Wed, 10 Jun 2020 at 23:02, Peter Otten <__peter__ at web.de> wrote: > > However later when I actually use it, accessing a key that is not > > present, should raise KeyError. > > > > Is that somehow possible? > > It never occured to me to try that, but: > > >>> from collections import defaultdict > >>> d = defaultdict(list) > >>> d["x"] > [] > >>> d.default_factory = None > >>> d["y"] > Traceback (most recent call last): > File "", line 1, in > KeyError: 'y' An alternative approach to this would be to use a regular dict from the start... d.setdefault("x", []).append("stuff") -- Matt Wheeler http://funkyh.at From alan.gauld at yahoo.co.uk Tue Jun 16 11:38:46 2020 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 16 Jun 2020 16:38:46 +0100 Subject: Python Curses Programming HowTo -reviewers? Message-ID: While studying the curses module I was struck by the paucity of tutorial documentation for the Python version. Fortunately I know C and used to write curses applications back in the 80s/90s so I turned to the C tutorials. However, there are quite a lot of differences between the Python wrapper implementation and the C library. I therefore took it on myself to do a translation of the Linux Documentation Project's "Curses HowTo" by Pradeep Padala into Python. It is mostly a translation of the code with minimal changes to the explanatory text (deleting the stuff about how to compile etc plus some libraries that are not available in Python). I have added a few short sections that the C version does not cover but I thought were useful. This is now available as a PDF and I'd be interested in review comments. Ideally I'm looking for new curses users to review it as a tutorial and for experienced curses users to check that what I've done is sane! It is about 75 pages long and covers the core curses module, the panel module and the textpad widget as well as a brief intro to the dialog module. If anyone feels keen please reply and I'll forward a copy. Eventually I'm aiming to put the finished document on my website. It's amazing what a pandemic can produce... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From bgailer at gmail.com Tue Jun 16 13:57:48 2020 From: bgailer at gmail.com (Bob Gailer) Date: Tue, 16 Jun 2020 13:57:48 -0400 Subject: Python Curses Programming HowTo -reviewers? In-Reply-To: References: Message-ID: > If anyone feels keen please reply and I'll forward a copy. I'm interested please forward me a copy. Bob Gailer From Karsten.Hilbert at gmx.net Tue Jun 16 14:34:31 2020 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Tue, 16 Jun 2020 20:34:31 +0200 Subject: Aw: Python Curses Programming HowTo -reviewers? In-Reply-To: References: Message-ID: > I therefore took it on myself to do a translation of the Linux > Documentation Project's "Curses HowTo" by Pradeep Padala into Python. > > This is now available as a PDF and I'd be interested in review comments. I'd be interested in having a look, generally. Will this be available somewhere ? Thanks, Karsten From countryone77 at gmail.com Tue Jun 16 16:56:01 2020 From: countryone77 at gmail.com (Bev In TX) Date: Tue, 16 Jun 2020 15:56:01 -0500 Subject: Python Curses Programming HowTo -reviewers? In-Reply-To: References: Message-ID: <26E702FA-9148-412F-9A7D-334A356F20FC@gmail.com> > On Jun 16, 2020, at 11:12 AM, Alan Gauld via Python-list wrote: > > If anyone feels keen please reply and I'll forward a copy. > Eventually I'm aiming to put the finished document on my website. I am interested. Thanks, Bev in TX From PythonList at DancesWithMice.info Tue Jun 16 19:45:17 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 17 Jun 2020 11:45:17 +1200 Subject: Friday Finking: Beyond implementing Unicode In-Reply-To: References: <016811bb-4dea-11d6-27bf-a66192fdd61f@etelligence.info> Message-ID: On 13/06/20 4:47 AM, Terry Reedy wrote: > On 6/12/2020 2:03 AM, DL Neil via Python-list wrote: >> Unicode has given us access to a wealth of mathematical and other >> symbols. Hardware and soft-/firm-ware flexibility enable us to move >> beyond and develop new 'standards'. Do we have opportunities to make >> computer programming more math-familiar and/or more >> logically-expressive, and thus easier to learn and practice? Could we >> develop Python to take advantage of these opportunities? > > ... > >> Could we then also 'update' Python, to accept the wider range of >> symbols instead/in-addition to those currently in-use? >> >> Would such even constitute 'a good idea'? > > There was a recent thread on python-ideas discussing this.? It started > with arrow characters.? There have been others. Am pleased to hear that it's neither 'new' nor 'way out there'... Am not subscribed to that list. Went looking for its archives, but failed - there's no "ideas" on (https://mail.python.org/mailman/listinfo). Please send a pointer... -- Regards =dn From PythonList at DancesWithMice.info Tue Jun 16 19:57:52 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 17 Jun 2020 11:57:52 +1200 Subject: Friday Finking: Beyond implementing Unicode In-Reply-To: <16d7efh0nks26h3j0k9r9gplimu21bg9a6@4ax.com> References: <016811bb-4dea-11d6-27bf-a66192fdd61f@etelligence.info> <16d7efh0nks26h3j0k9r9gplimu21bg9a6@4ax.com> Message-ID: On 13/06/20 5:11 AM, Dennis Lee Bieber wrote: > On Fri, 12 Jun 2020 18:03:55 +1200, DL Neil via Python-list > declaimed the following: > >> >> There is/was a language called "APL" (and yes the acronym means "A >> Programming Language", and yes it started the craze, through "B" (and >> BCPL), and yes, that brought us "C" - which you are more likely to have >> heard about - and yes then there were DataSci folk, presumably more >> numerate than literate, who thought the next letter to be "R". So, sad!?). > > R was preceded by S http://www.unige.ch/ses/sococ/cl/r/srdiff.e.html > https://cran.r-project.org/doc/FAQ/R-FAQ.html#What-are-the-differences-between-R-and-S_003f > (which, with some scrolling, produces... Oh dear, my sarcasm about being literately-challenged stands! >> APL was hopelessly keyboard-unfriendly, requiring multiple key-presses >> or 'over-typing' to produce those arithmetic-operator symbols - > > Not with a Tektronix APL terminal, and Xerox CP/V APL Specific design-for-purpose - hardware/software integration! >> remember, much of this was on mainframe 3270-style terminals, although >> later PC-implementations have existed (I can't comment on how 'active' >> any community might be). The over-typing was necessary to encode/produce >> the APL symbols which don't exist on a standard typewriter keyboard. Ugh! > > Many implementations also allowed for a spelled out version for special > characters... $RHO for example, for the greek letter rho. To which my first reaction was "ugh!". However, I often prefer to have a named constant in my Python code - instead of "magic numbers", eg LINE_WIDTH = 79 # PEP-8 source-code characters per line >> I'm glad to have limited my APL-exposure to only reading about it during >> a 'Programming Languages' topic! (If you are 'into' functional >> programming you may like to explore further) > > I used it as a 3-credit independent study in my senior year (1980). All > I was after was a passing grade to complete the credits for graduation. I'm > slightly ashamed to admit that my fanciest program turned that Tektronix > storage display tube terminal into a glorified Etch-a-Sketch (terminal had > X/Y scroll wheels that the APL implementation could read). Hey, at least you gained access. I think my uni (when I was an u/grad) only had one graphic terminal which was kept in the computer room and thus only staff had access. Our introduction to graphics (using FORTRAN) had to be shown using 80x24 character-based terminals (DEC VT-52s, from memory). Drawing shapes was bad-enough, but demonstrations of rotation and translation became the very definition of ugly! I've been somewhat re-living those days, teaching myself how to play with Pygame (not a 'work' activity!), and learning how to move entities around on the screen (quite similar to HTML5, but sufficiently different to give pause). That said, the learning of such basic "building-blocks", four-plus decades ago, under-pins working in both/either/each, today! -- Regards =dn From PythonList at DancesWithMice.info Tue Jun 16 20:13:07 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 17 Jun 2020 12:13:07 +1200 Subject: Friday Finking: Beyond implementing Unicode In-Reply-To: References: <016811bb-4dea-11d6-27bf-a66192fdd61f@etelligence.info> Message-ID: <2d5c4c03-f3e8-ce7d-535e-d5f0a48ccb7d@DancesWithMice.info> >> There was a recent thread on python-ideas discussing this.? It started >> with arrow characters.? There have been others. > > > Am pleased to hear that it's neither 'new' nor 'way out there'... > > Am not subscribed to that list. Went looking for its archives, but > failed - there's no "ideas" on > (https://mail.python.org/mailman/listinfo). Please send a pointer... Apologies! Eventually remembered the second list of lists - the list of Python lists which are Python lists but not on the first list of Python lists... No wonder I'm dizzy! -- Regards =dn From palashbauri1 at gmail.com Wed Jun 17 02:59:03 2020 From: palashbauri1 at gmail.com (Palash Bauri) Date: Wed, 17 Jun 2020 12:29:03 +0530 Subject: Application Distribution using Embeddable Zip on Windows Message-ID: I am developing a parser with PLY and was hoping to distribute it to users. Ofcourse there're plenty of Ways to build a executable of an Python script such as PyInstaller , Py2Exe and some others, but they have their problems , one of them which is their output distribution size is huge, a simple "hello world" program would even cost user 30 to 50+ megabytes of storage. Distributing on Linux is not that much of hassle with snap packages or even Appimages. But on windows it's a mess. But Python Embeddable Zip seems promising to me, it's very lightweight. But the thing is I couldn't figure out how to build a "launcher" (As mentioned here -> https://docs.python.org/3/using/windows.html) for my application? Any help or suggestions would be very much appreciated. ~Palash Bauri From rosuav at gmail.com Wed Jun 17 03:09:12 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Jun 2020 17:09:12 +1000 Subject: Application Distribution using Embeddable Zip on Windows In-Reply-To: References: Message-ID: On Wed, Jun 17, 2020 at 5:00 PM Palash Bauri wrote: > > I am developing a parser with PLY and was hoping to distribute it to users. > Ofcourse there're plenty of Ways to build a executable of an Python script > such as PyInstaller , Py2Exe and some others, but they have their problems > , one of them which is their output distribution size is huge, a simple > "hello world" program would even cost user 30 to 50+ megabytes of storage. > Distributing on Linux is not that much of hassle with snap packages or even > Appimages. But on windows it's a mess. > > But Python Embeddable Zip seems promising to me, it's very lightweight. > > But the thing is I couldn't figure out how to build a "launcher" (As > mentioned here -> https://docs.python.org/3/using/windows.html) for my > application? > > Any help or suggestions would be very much appreciated. > Try creating a .pyz file using the zipapp module: https://docs.python.org/3/library/zipapp.html It should 'just work', out of the box. ChrisA From palashbauri1 at gmail.com Wed Jun 17 07:08:07 2020 From: palashbauri1 at gmail.com (Palash Bauri) Date: Wed, 17 Jun 2020 16:38:07 +0530 Subject: Application Distribution using Embeddable Zip on Windows In-Reply-To: References: Message-ID: > Try creating a .pyz file using the zipapp module: > https://docs.python.org/3/library/zipapp.html > It should 'just work', out of the box. > ChrisA But I will still need to build a launcher or put a Python Interpreter at users' path in order to run .pyz files. From rosuav at gmail.com Wed Jun 17 07:13:56 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 17 Jun 2020 21:13:56 +1000 Subject: Application Distribution using Embeddable Zip on Windows In-Reply-To: References: Message-ID: On Wed, Jun 17, 2020 at 9:09 PM Palash Bauri wrote: > > > Try creating a .pyz file using the zipapp module: > > > https://docs.python.org/3/library/zipapp.html > > > It should 'just work', out of the box. > > > ChrisA > > But I will still need to build a launcher or put a Python Interpreter > at users' path in order to run .pyz files. Putting a Python interpreter onto the users' systems is the job of python.org and/or the Windows app store. You should just have to worry about your own app. ChrisA From palashbauri1 at gmail.com Wed Jun 17 09:44:17 2020 From: palashbauri1 at gmail.com (Palash Bauri) Date: Wed, 17 Jun 2020 19:14:17 +0530 Subject: Application Distribution using Embeddable Zip on Windows In-Reply-To: References: Message-ID: Well , in some cases that is true, but in my program's case that's not true as it's targetting not-so-much tech savvy users. I would like to make an compact plug-and-play solution. And , I think using Python Embeddable zip and a custom launcher will be more suitable for my program. On 6/17/20, Chris Angelico wrote: > On Wed, Jun 17, 2020 at 9:09 PM Palash Bauri > wrote: >> >> > Try creating a .pyz file using the zipapp module: >> >> > https://docs.python.org/3/library/zipapp.html >> >> > It should 'just work', out of the box. >> >> > ChrisA >> >> But I will still need to build a launcher or put a Python Interpreter >> at users' path in order to run .pyz files. > > Putting a Python interpreter onto the users' systems is the job of > python.org and/or the Windows app store. You should just have to worry > about your own app. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From palashbauri1 at gmail.com Wed Jun 17 10:48:30 2020 From: palashbauri1 at gmail.com (Palash Bauri) Date: Wed, 17 Jun 2020 20:18:30 +0530 Subject: Application Distribution using Embeddable Zip on Windows In-Reply-To: References: Message-ID: Well, that crossed my mind earlier, but as my program is a text parser and has it's own input & output source filetype, it should have those filetypes associated with the program. Just using an MSI installer will not do that trick. ~Palash Bauri On Wed, 17 Jun 2020, 7:18 pm Shakil Khan, wrote: > How about writing a windows MSI installer and wrapping Python and your > script together in the MSI. > > $hakil > > > On Jun 17, 2020, at 6:44 AM, Palash Bauri > wrote: > > > > Well , in some cases that is true, but in my program's case that's not > > true as it's targetting not-so-much tech savvy users. I would like to > > make an compact plug-and-play solution. > > > > And , I think using Python Embeddable zip and a custom launcher will > > be more suitable for my program. > > > > On 6/17/20, Chris Angelico wrote: > >> On Wed, Jun 17, 2020 at 9:09 PM Palash Bauri > >> wrote: > >>> > >>>> Try creating a .pyz file using the zipapp module: > >>> > >>>> https://docs.python.org/3/library/zipapp.html > >>> > >>>> It should 'just work', out of the box. > >>> > >>>> ChrisA > >>> > >>> But I will still need to build a launcher or put a Python Interpreter > >>> at users' path in order to run .pyz files. > >> > >> Putting a Python interpreter onto the users' systems is the job of > >> python.org and/or the Windows app store. You should just have to worry > >> about your own app. > >> > >> ChrisA > >> -- > >> https://mail.python.org/mailman/listinfo/python-list > >> > > -- > > https://mail.python.org/mailman/listinfo/python-list > > From palashbauri1 at gmail.com Wed Jun 17 11:16:53 2020 From: palashbauri1 at gmail.com (Palash Bauri) Date: Wed, 17 Jun 2020 20:46:53 +0530 Subject: Application Distribution using Embeddable Zip on Windows In-Reply-To: <2A228D3E-1EF3-452E-B06F-10AA1782BBBE@gmail.com> References: <2A228D3E-1EF3-452E-B06F-10AA1782BBBE@gmail.com> Message-ID: Well , I didn't know that single scripts can be used to associate filetypes. I will test it out. Currently I'm doing an experiment with Embeddable distribution , Writing a launcher with rust. I have no idea what's the efficient or correct way to do it. Let's hope for the best. I think they should've explained how to write an Launcher or even an example code in the docs. I will have your solution as an backup option. ~Palash Bauri On Wed, 17 Jun 2020, 8:30 pm Shakil Khan, wrote: > May be I have not understood your requirement. > But let me put what I understood and how can it be achieved. > > Requirement:- > There is a file in system called as abc.pal, this file when double > clicked produces a file called as abc.parsed > > Solution: > 1) Pack the MSI and Python Binary in MSI > 2) Unpack and install the MSI and as part of it install the Python in > standard Path and update the PATH > 3) Associate the file type *.pal to open with your application say > Palash_parser.py > 4) When the file abc.pal is double-clicked the associated application is > Palash_parser.py. > The application Palash_parser.py can run without any issues as the Python > is already installed and in Path and produces abc.parsed > > Sorry if this is not what you intended. > Good luck then. > > $hakil > > On Jun 17, 2020, at 7:48 AM, Palash Bauri wrote: > > Well, that crossed my mind earlier, but as my program is a text parser and > has it's own input & output source filetype, it should have those filetypes > associated with the program. Just using an MSI installer will not do that > trick. > > > ~Palash Bauri > > On Wed, 17 Jun 2020, 7:18 pm Shakil Khan, wrote: > >> How about writing a windows MSI installer and wrapping Python and your >> script together in the MSI. >> >> $hakil >> >> > On Jun 17, 2020, at 6:44 AM, Palash Bauri >> wrote: >> > >> > Well , in some cases that is true, but in my program's case that's not >> > true as it's targetting not-so-much tech savvy users. I would like to >> > make an compact plug-and-play solution. >> > >> > And , I think using Python Embeddable zip and a custom launcher will >> > be more suitable for my program. >> > >> > On 6/17/20, Chris Angelico wrote: >> >> On Wed, Jun 17, 2020 at 9:09 PM Palash Bauri >> >> wrote: >> >>> >> >>>> Try creating a .pyz file using the zipapp module: >> >>> >> >>>> https://docs.python.org/3/library/zipapp.html >> >>> >> >>>> It should 'just work', out of the box. >> >>> >> >>>> ChrisA >> >>> >> >>> But I will still need to build a launcher or put a Python Interpreter >> >>> at users' path in order to run .pyz files. >> >> >> >> Putting a Python interpreter onto the users' systems is the job of >> >> python.org and/or the Windows app store. You should just have to worry >> >> about your own app. >> >> >> >> ChrisA >> >> -- >> >> https://mail.python.org/mailman/listinfo/python-list >> >> >> > -- >> > https://mail.python.org/mailman/listinfo/python-list >> >> > From tjreedy at udel.edu Tue Jun 16 23:00:03 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 16 Jun 2020 23:00:03 -0400 Subject: Friday Finking: Beyond implementing Unicode In-Reply-To: References: <016811bb-4dea-11d6-27bf-a66192fdd61f@etelligence.info> Message-ID: On 6/16/2020 7:45 PM, DL Neil via Python-list wrote: > On 13/06/20 4:47 AM, Terry Reedy wrote: >> There was a recent thread on python-ideas discussing this.? It started >> with arrow characters.? There have been others. > > Am pleased to hear that it's neither 'new' nor 'way out there'... The idea has been rejected multiple times, which puts you in good company (in a sense). > Am not subscribed to that list. Went looking for its archives, but > failed - there's no "ideas" on > (https://mail.python.org/mailman/listinfo). Please send a pointer... Try mailman3. https://mail.python.org/mailman3/lists/python-ideas.python.org/ Archive link on page. -- Terry Jan Reedy From alan.gauld at yahoo.co.uk Tue Jun 16 13:08:29 2020 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 16 Jun 2020 18:08:29 +0100 Subject: Python Curses Programming HowTo -reviewers? In-Reply-To: References: Message-ID: On 16/06/2020 16:38, Alan Gauld via Python-list wrote: > This is now available as a PDF and I'd be interested in review comments. Just to add that I can send a zip of the code files too. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From manuel.fernandez at unisalento.it Tue Jun 16 13:18:15 2020 From: manuel.fernandez at unisalento.it (=?UTF-8?Q?Manuel_Fernandez_-_Universit=c3=a0?=) Date: Tue, 16 Jun 2020 19:18:15 +0200 Subject: Problems with python383.dll Message-ID: <3a520d90-5ee3-e2bc-822e-4ce622e8e531@unisalento.it> Dear Sirs, I tried to install the software Python 3.8.3 (32 bit), but after it finished and I tried to start it, there appeared a message in which it was written that it couldn't find the file python383.dll and stopped. What can I do? Do you have this file so that I can insert it manually. I thank you for your help. Best wishes, Manuel Fernandez -- From gauravsinghrathore17 at gmail.com Tue Jun 16 16:02:36 2020 From: gauravsinghrathore17 at gmail.com (gauravsinghrathore17 at gmail.com) Date: Wed, 17 Jun 2020 01:32:36 +0530 Subject: uninstallation issue Message-ID: <78E26376-BCF4-4C49-B28F-9D6EB6DCC47A@hxcore.ol> My python 3.8 version is not getting uninstall in my system. Please solve this problem. ? Thanks for you concern. ? Sent from [1]Mail for Windows 10 ? References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From alan.gauld at yahoo.co.uk Tue Jun 16 17:31:46 2020 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 16 Jun 2020 22:31:46 +0100 Subject: Aw: Python Curses Programming HowTo -reviewers? In-Reply-To: References: Message-ID: On 16/06/2020 19:34, Karsten Hilbert wrote: >> I therefore took it on myself to do a translation of the Linux >> Documentation Project's "Curses HowTo" by Pradeep Padala into Python. >> >> This is now available as a PDF and I'd be interested in review comments. > > I'd be interested in having a look, generally. > > Will this be available somewhere ? Eventually, on my web site. After the next round of corrections. I'll send the PDF and zip via direct mail. BTW I have enough reviewers now, Thanks everyone! -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From ivan.ivanyuk at gmail.com Wed Jun 17 09:21:30 2020 From: ivan.ivanyuk at gmail.com (Ivan Ivanyuk) Date: Wed, 17 Jun 2020 15:21:30 +0200 Subject: Property for dataclass field with default value Message-ID: Hello All, I have some trouble using @dataclass together with @property decorator or property() function. >From the documentation and PEP is seems that the intended behaviour of @dataclass is to be the same as normal __init__() that sets instance variables. But it seems that when using @property decorator some parts work differently when relying on default values. I'm using Pyhton 3.8.3 for this. Using the code: from dataclasses import dataclass @dataclass class Container: x: int = 30 @property def x(self) -> int: return self._x @x.setter def x(self, z: int): if z > 1: self._x = z else: raise ValueError c= Container(x=10) print(c) c= Container() print(c) output is: Container(x=10) Traceback (most recent call last): File "/Users/ivanivanyuk/Documents/Shared/repos/bitbucket/evbox/g5plus-automated-testing/dataclass_example.py", line 18, in c= Container() File "", line 3, in __init__ File "/Users/ivanivanyuk/Documents/Shared/repos/bitbucket/evbox/g5plus-automated-testing/dataclass_example.py", line 13, in x if z > 1: TypeError: '>' not supported between instances of 'property' and 'int' Code with __init__() being inserted that should be roughly the same as generated by the @dataclass decorator: @dataclass class Container: x: int = 30 def __init__(self, x:int = 30): self.x = x @property def x(self) -> int: return self._x @x.setter def x(self, z: int): if z > 1: self._x = z else: raise ValueError c= Container(x=10) print(c) c= Container() print(c) output is: Container(x=10) Container(x=30) As far as I can see, this happens because actual __init__() generated by the @dataclass decorator looks like: def __init__(self, x:int = ): self.x = x I came up with a really convoluted way to work around it (just for fun, as this clearly defies the idea of dataclasses as a way to decrease boilerplate code): from dataclasses import dataclass, field def set_property(): Container.x = property(Container.get_x, Container.set_x) return 30 @dataclass class Container: x: int = field(default_factory=set_property) def get_x(self) -> int: return self._x def set_x(self, z: int): if z > 1: self._x = z else: raise ValueError c= Container(x=10) print(c) c= Container() print(c) output is: Container(x=10) Container(x=30) So, what I'm missing here? Is there some way to use field() or decorators to make property just work the same as in non-decorated class? Best regards, Ivan Ivanyuk From souvik.viksou at gmail.com Wed Jun 17 20:59:44 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Thu, 18 Jun 2020 06:29:44 +0530 Subject: uninstallation issue In-Reply-To: <78E26376-BCF4-4C49-B28F-9D6EB6DCC47A@hxcore.ol> References: <78E26376-BCF4-4C49-B28F-9D6EB6DCC47A@hxcore.ol> Message-ID: Before you uninstall right click on idle and find the location where python is installed. Probably it would be under C:\\Programe files\\python. And then uninstall python. After that you will see that some folders where deleted but others where not. Delete the others and you will have uninstalled python. On Thu, Jun 18, 2020, 4:06 AM gauravsinghrathore17 at gmail.com < gauravsinghrathore17 at gmail.com> wrote: > My python 3.8 version is not getting uninstall in my system. > > Please solve this problem. > > > > Thanks for you concern. > > > > Sent from [1]Mail for Windows 10 > > > > References > > Visible links > 1. https://go.microsoft.com/fwlink/?LinkId=550986 > -- > https://mail.python.org/mailman/listinfo/python-list > From torriem at gmail.com Wed Jun 17 21:19:46 2020 From: torriem at gmail.com (Michael Torrie) Date: Wed, 17 Jun 2020 19:19:46 -0600 Subject: Problems with python383.dll In-Reply-To: <3a520d90-5ee3-e2bc-822e-4ce622e8e531@unisalento.it> References: <3a520d90-5ee3-e2bc-822e-4ce622e8e531@unisalento.it> Message-ID: On 6/16/20 11:18 AM, Manuel Fernandez - Universit? wrote: > Dear Sirs, > I tried to install the software Python 3.8.3 (32 bit), but after it > finished and I tried to start it, there appeared a message in which it > was written that it couldn't find the file python383.dll and stopped. > What can I do? Do you have this file so that I can insert it manually. > I thank you for your help. > Best wishes, > Manuel Fernandez Which version of Windows? 32-bit or 64-bit? Where did you download the installer from? How did you try to start it? Normally python is a command-line tool, so you run it from a command prompt, not from the start menu. Read through this page and see if it helps at all: https://docs.python.org/3/using/windows.html From nad at python.org Wed Jun 17 23:33:15 2020 From: nad at python.org (Ned Deily) Date: Wed, 17 Jun 2020 23:33:15 -0400 Subject: [RELEASE] Python 3.7.8rc1 and 3.6.11rc1 are now available for testing Message-ID: <4433F30E-012A-4807-9472-C6710223BFC3@python.org> Details here: https://discuss.python.org/t/python-3-7-8rc1-and-3-6-11rc1-are-now-available-for-testing/4467 https://www.python.org/downloads/release/python-378rc1/ https://www.python.org/downloads/release/python-3611rc1/ -- Ned Deily nad at python.org -- [] From __peter__ at web.de Thu Jun 18 05:22:22 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 18 Jun 2020 11:22:22 +0200 Subject: Property for dataclass field with default value References: Message-ID: Ivan Ivanyuk wrote: > Hello All, > > I have some trouble using @dataclass together with @property decorator > or property() function. > > From the documentation and PEP is seems that the intended behaviour of > @dataclass is to be the same as normal __init__() that sets instance > variables. > > But it seems that when using @property decorator some parts work > differently when relying on default values. I'm using Pyhton 3.8.3 for > this. > > Using the code: > > from dataclasses import dataclass > > @dataclass > class Container: > x: int = 30 > > @property > def x(self) -> int: > return self._x > > @x.setter > def x(self, z: int): > if z > 1: > self._x = z > else: > raise ValueError > c= Container(x=10) > print(c) > c= Container() > print(c) > > output is: > > Container(x=10) > Traceback (most recent call last): > File > "/Users/ivanivanyuk/Documents/Shared/repos/bitbucket/evbox/g5plus- automated-testing/dataclass_example.py", > line 18, in > c= Container() > File "", line 3, in __init__ > File > "/Users/ivanivanyuk/Documents/Shared/repos/bitbucket/evbox/g5plus- automated-testing/dataclass_example.py", > line 13, in x > if z > 1: > TypeError: '>' not supported between instances of 'property' and 'int' > > Code with __init__() being inserted that should be roughly the same as > generated by the @dataclass decorator: > > @dataclass > class Container: > x: int = 30 > > def __init__(self, x:int = 30): > self.x = x > > @property > def x(self) -> int: > return self._x > > @x.setter > def x(self, z: int): > if z > 1: > self._x = z > else: > raise ValueError > > c= Container(x=10) > print(c) > c= Container() > print(c) > > output is: > Container(x=10) > Container(x=30) > > As far as I can see, this happens because actual __init__() generated > by the @dataclass decorator looks like: > > def __init__(self, x:int = ): > self.x = x > > I came up with a really convoluted way to work around it (just for > fun, as this clearly defies the idea of dataclasses as a way to > decrease boilerplate code): > > from dataclasses import dataclass, field > > def set_property(): > Container.x = property(Container.get_x, Container.set_x) > return 30 > > @dataclass > class Container: > x: int = field(default_factory=set_property) > > def get_x(self) -> int: > return self._x > > def set_x(self, z: int): > if z > 1: > self._x = z > else: > raise ValueError > > c= Container(x=10) > print(c) > c= Container() > print(c) > > output is: > Container(x=10) > Container(x=30) > > So, what I'm missing here? Is there some way to use field() or > decorators to make property just work the same as in non-decorated > class? Your class definition is basically class Container: x = default_value x = property_x i. e. you use the same name twice. A possible workaround might be to define the property in a subclass. That way you get distinct namespaces for the default value and the property: @dataclass class ContainerBase: x: int = 42 class Container(ContainerBase): @property def x(self): return self._x @x.setter def x(self, value): if value <= 1: raise ValueError self._x = value From ivan.ivanyuk at gmail.com Thu Jun 18 09:23:21 2020 From: ivan.ivanyuk at gmail.com (Ivan Ivanyuk) Date: Thu, 18 Jun 2020 15:23:21 +0200 Subject: Property for dataclass field with default value In-Reply-To: References: Message-ID: On Thu, 18 Jun 2020 at 11:26, Peter Otten <__peter__ at web.de> wrote: > > Ivan Ivanyuk wrote: > > > Hello All, > > > > I have some trouble using @dataclass together with @property decorator > > or property() function. > > > > From the documentation and PEP is seems that the intended behaviour of > > @dataclass is to be the same as normal __init__() that sets instance > > variables. > > > > But it seems that when using @property decorator some parts work > > differently when relying on default values. I'm using Pyhton 3.8.3 for > > this. > > > > Using the code: > > > > from dataclasses import dataclass > > > > @dataclass > > class Container: > > x: int = 30 > > > > @property > > def x(self) -> int: > > return self._x > > > > @x.setter > > def x(self, z: int): > > if z > 1: > > self._x = z > > else: > > raise ValueError > > c= Container(x=10) > > print(c) > > c= Container() > > print(c) > > > > output is: > > > > Container(x=10) > > Traceback (most recent call last): > > File > > "/Users/ivanivanyuk/Documents/Shared/repos/bitbucket/evbox/g5plus- > automated-testing/dataclass_example.py", > > line 18, in > > c= Container() > > File "", line 3, in __init__ > > File > > "/Users/ivanivanyuk/Documents/Shared/repos/bitbucket/evbox/g5plus- > automated-testing/dataclass_example.py", > > line 13, in x > > if z > 1: > > TypeError: '>' not supported between instances of 'property' and 'int' > > > > Code with __init__() being inserted that should be roughly the same as > > generated by the @dataclass decorator: > > > > @dataclass > > class Container: > > x: int = 30 > > > > def __init__(self, x:int = 30): > > self.x = x > > > > @property > > def x(self) -> int: > > return self._x > > > > @x.setter > > def x(self, z: int): > > if z > 1: > > self._x = z > > else: > > raise ValueError > > > > c= Container(x=10) > > print(c) > > c= Container() > > print(c) > > > > output is: > > Container(x=10) > > Container(x=30) > > > > As far as I can see, this happens because actual __init__() generated > > by the @dataclass decorator looks like: > > > > def __init__(self, x:int = ): > > self.x = x > > > > I came up with a really convoluted way to work around it (just for > > fun, as this clearly defies the idea of dataclasses as a way to > > decrease boilerplate code): > > > > from dataclasses import dataclass, field > > > > def set_property(): > > Container.x = property(Container.get_x, Container.set_x) > > return 30 > > > > @dataclass > > class Container: > > x: int = field(default_factory=set_property) > > > > def get_x(self) -> int: > > return self._x > > > > def set_x(self, z: int): > > if z > 1: > > self._x = z > > else: > > raise ValueError > > > > c= Container(x=10) > > print(c) > > c= Container() > > print(c) > > > > output is: > > Container(x=10) > > Container(x=30) > > > > So, what I'm missing here? Is there some way to use field() or > > decorators to make property just work the same as in non-decorated > > class? > > Your class definition is basically > > class Container: > x = default_value > x = property_x > > i. e. you use the same name twice. A possible workaround might be to define > the property in a subclass. That way you get distinct namespaces for the > default value and the property: > > @dataclass > class ContainerBase: > x: int = 42 > > class Container(ContainerBase): > @property > def x(self): > return self._x > > @x.setter > def x(self, value): > if value <= 1: > raise ValueError > self._x = value > > > -- > https://mail.python.org/mailman/listinfo/python-list Didn't think about it in such a way! But now that it was pointed, I see no obvious way to resolve this in dataclass decorator given the way it's implemented now. And while adding another class looks easy it somewhat detracts from the dataclasses' purpose of removing boilerplate. Does it seems like a good idea to ask for documenting that behaviour in dataclasses documentation or it's not popular enough use case? Regards, Ivan From bluesourav141 at gmail.com Thu Jun 18 06:20:14 2020 From: bluesourav141 at gmail.com (Sourav Kundu) Date: Thu, 18 Jun 2020 15:50:14 +0530 Subject: problem at the time of using editor Message-ID: when I am using the editor to write a long program and trying to run it the python command line showing it syntax error From mats at python.org Thu Jun 18 11:22:19 2020 From: mats at python.org (Mats Wichmann) Date: Thu, 18 Jun 2020 09:22:19 -0600 Subject: problem at the time of using editor In-Reply-To: References: Message-ID: On 6/18/20 4:20 AM, Sourav Kundu wrote: > when I am using the editor to write a long program and trying to run it the > python command line showing it syntax error > That almost certainly means there is a syntax error in your code. Please provide some details - like the actual error text. Note: for certain syntax errors, the error began previously, and the line where the error is reported is the first time you can be sure there actually was an error. Consider: print("This is a problem" x = 12 The closing paren on the function call print() was omitted. This will give this result: x = 12 ^ SyntaxError: invalid syntax Clearly, "x = 12" does not contain a syntax error. But paired parens are allowed to span multiple lines, so Python keeps looking for the closing one, and only when the syntax can't possibly be right any longer does it give up and report an error. A good Python-aware editor/IDE will do work to help show you where the actual problem is. From tjreedy at udel.edu Thu Jun 18 10:33:40 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 18 Jun 2020 10:33:40 -0400 Subject: problem at the time of using editor In-Reply-To: References: Message-ID: On 6/18/2020 6:20 AM, Sourav Kundu wrote: > when I am using the editor to write a long program and trying to run it the > python command line showing it syntax error That happens to all of us, even for short programs. -- Terry Jan Reedy From grant.b.edwards at gmail.com Thu Jun 18 10:57:05 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 18 Jun 2020 14:57:05 -0000 (UTC) Subject: problem at the time of using editor References: Message-ID: On 2020-06-18, Sourav Kundu wrote: > when I am using the editor to write a long program and trying to run > it the python command line showing it syntax error Fix the syntax error using the editor, then run the program again. From PythonList at DancesWithMice.info Thu Jun 18 16:54:05 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Fri, 19 Jun 2020 08:54:05 +1200 Subject: problem at the time of using editor In-Reply-To: References: Message-ID: <9615a0d4-4658-f5f9-653f-449d062c31ca@DancesWithMice.info> On 18/06/20 10:20 PM, Sourav Kundu wrote: > when I am using the editor to write a long program and trying to run it the > python command line showing it syntax error Of possible interest:- Why SuperHELP for Python? | pssst Search domain p-s.co.nz/wordpress/why-superhelp-for-python/p-s.co.nz/wordpress/why-superhelp-for-python/ SuperHELP reads a snippet of Python and provides advice, warnings, and basic information based on what it finds. For example, it might notice a function docstring is missing and show a template for adding one. Or identify the use of a named tuple and explain how to add docstrings to individual fields or the named tuple as a whole. As mentioned, at this stage in your learning process, you may find it helpful to use a basic Python editor which has a built-in terminal console. -- Regards =dn From lepto.python at gmail.com Fri Jun 19 04:30:54 2020 From: lepto.python at gmail.com (oyster) Date: Fri, 19 Jun 2020 16:30:54 +0800 Subject: why same ctypes code runs on win7, but not on win10? Message-ID: The attachment is a very simple code that uses the DLL from https://github.com/ying32/govcl to create a GUI application. The code runs on my python 3.6.10 64 bits with win7 64 bits, but failed on my python 3.6.10 64 bits and python 3.7.5 with win10 64 bits, by saying following message. What is the problem? Thanks. ``` vcl.Application_Initialize(Application) OSError: exception: access violation reading 0xFFFFFFFF9BCEE490 ``` ```python import ctypes def main(): vcl = ctypes.CDLL('liblcl.dll') Application = vcl.Application_Instance() vcl.Application_Initialize(Application) form = vcl.Application_CreateForm(Application, False); vcl.Application_Run(Application); main() ``` From eryksun at gmail.com Fri Jun 19 06:22:52 2020 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 19 Jun 2020 05:22:52 -0500 Subject: why same ctypes code runs on win7, but not on win10? In-Reply-To: References: Message-ID: On 6/19/20, oyster wrote: > The attachment is a very simple code that uses the DLL from > https://github.com/ying32/govcl to create a GUI application. The code > runs on my python 3.6.10 64 bits with win7 64 bits, but failed on my > python 3.6.10 64 bits and python 3.7.5 with win10 64 bits, by saying > following message. What is the problem? Thanks. > ``` > vcl.Application_Initialize(Application) > OSError: exception: access violation reading 0xFFFFFFFF9BCEE490 > ``` The default return type is a 32-bit signed integer, and apparently Application_Instance returns a memory address (i.e. a pointer). You can't rely on a 64-bit process loading DLLs and allocating memory only in the lower 32-bit address space. The following should fix the problem: import ctypes # In Python 3.8+, ctypes no longer searches PATH or the # current working directory when loading DLLs. liblcl_path = 'path/to/liblcl.dll' vcl = ctypes.CDLL(liblcl_path) # Use a c_void_p subclass, which, unlike c_void_p itself, # will not be automatically converted to a Python integer. class vclapp_p(ctypes.c_void_p): """VCL Application Instance""" # Override the default c_int result type. vcl.Application_Instance.restype = vclapp_p def main(): app = vcl.Application_Instance() vcl.Application_Initialize(app) form = vcl.Application_CreateForm(app, False) vcl.Application_Run(app) From tony.flury at btinternet.com Wed Jun 17 12:34:55 2020 From: tony.flury at btinternet.com (Tony Flury) Date: Wed, 17 Jun 2020 17:34:55 +0100 Subject: How to test? In-Reply-To: <20200424204032.73b0e5e1@arcor.com> References: <20200424204032.73b0e5e1@arcor.com> Message-ID: <75abbbef-b3a2-6dd8-9df3-e73ef81f57d2@btinternet.com> On 24/04/2020 19:40, Manfred Lotz wrote: > I have a command like application which checks a directory tree for > certain things. If there are errors then messages will be written to > stdout. > > How to test this in the best way? > > One idea was for the error situations to write messages to files and > then later when running the tests to compare the error messages output > to the previously saved output. > > Is there anything better? > In a recent application that I wrote (where output to the console was important), I tested it using the 'unittest' framework, and by patching sys.stderr to be a StringIO - that way my test case could inspect what was being output. with patch('sys.stderr', StringIO()) as stderr:application.do_stuff()self.assertTrue(stderr.getvalue(), 'Woops - that didn\'t work') I am not sure of the structure of your application, and whether you have a callable API that you can invoke. From __peter__ at web.de Fri Jun 19 14:06:56 2020 From: __peter__ at web.de (Peter Otten) Date: Fri, 19 Jun 2020 20:06:56 +0200 Subject: Property for dataclass field with default value References: Message-ID: Ivan Ivanyuk wrote: > On Thu, 18 Jun 2020 at 11:26, Peter Otten <__peter__ at web.de> wrote: >> >> Ivan Ivanyuk wrote: >> >> > Hello All, >> > >> > I have some trouble using @dataclass together with @property decorator >> > or property() function. >> > >> > From the documentation and PEP is seems that the intended behaviour of >> > @dataclass is to be the same as normal __init__() that sets instance >> > variables. >> > >> > But it seems that when using @property decorator some parts work >> > differently when relying on default values. I'm using Pyhton 3.8.3 for >> > this. >> > >> > Using the code: >> > >> > from dataclasses import dataclass >> > >> > @dataclass >> > class Container: >> > x: int = 30 >> > >> > @property >> > def x(self) -> int: >> > return self._x >> > >> > @x.setter >> > def x(self, z: int): >> > if z > 1: >> > self._x = z >> > else: >> > raise ValueError [...] >> Your class definition is basically >> >> class Container: >> x = default_value >> x = property_x >> >> i. e. you use the same name twice. A possible workaround might be to >> define the property in a subclass. That way you get distinct namespaces >> for the default value and the property: [...] > Didn't think about it in such a way! But now that it was pointed, I > see no obvious way to resolve this in dataclass decorator given the > way it's implemented now. And while adding another class looks easy it > somewhat detracts from the dataclasses' purpose of removing > boilerplate. > > Does it seems like a good idea to ask for documenting that behaviour > in dataclasses documentation or it's not popular enough use case? I don't know. From what I've seen runtime value checking has not even been considered even though it is part of attrs which seems to be a source of inspiration for dataclasses. https://www.attrs.org/en/stable/examples.html#validators If you make a feature request on python-ideas or the bugtracker you may at least find out why this part was not copied. From tjreedy at udel.edu Fri Jun 19 12:23:16 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 19 Jun 2020 12:23:16 -0400 Subject: How to test? In-Reply-To: <75abbbef-b3a2-6dd8-9df3-e73ef81f57d2@btinternet.com> References: <20200424204032.73b0e5e1@arcor.com> <75abbbef-b3a2-6dd8-9df3-e73ef81f57d2@btinternet.com> Message-ID: On 6/17/2020 12:34 PM, Tony Flury via Python-list wrote: > In a recent application that I wrote (where output to the console was > important), I tested it using the 'unittest' framework, and by patching > sys.stderr to be a StringIO - that way my test case could inspect what > was being output. Tony's code with hard returns added so that code lines remain separated instead of wrapping. with patch('sys.stderr', StringIO()) as stderr: application.do_stuff() self.assertTrue(stderr.getvalue(), 'Woops - that didn\'t work') This doc, worth reading more than once, is https://docs.python.org/3/library/unittest.mock.html#the-patchers -- Terry Jan Reedy From sirosen at uchicago.edu Fri Jun 19 15:35:48 2020 From: sirosen at uchicago.edu (Stephen Rosen) Date: Fri, 19 Jun 2020 15:35:48 -0400 Subject: How to test? In-Reply-To: References: <20200424204032.73b0e5e1@arcor.com> <75abbbef-b3a2-6dd8-9df3-e73ef81f57d2@btinternet.com> Message-ID: Worth noting: by assertTrue he probably meant assertEqual. But I'd recommend using assertIn [1] if you're using unittest to check output written to stdout/stderr. That way, your tests are slightly more robust to changes in the exact output. pytest may also be helpful for this (or any!) type of testing. Disclaimer/warning: pytest can be confusing even for experienced python programmers because it does some fancy things. But if you put in the time to learn it, it's very popular because of the way it structures testsuites and code reuse (i.e. fixtures). It can do a lot to help you, and provides output capturing out of the box [2] as well as some handy tools for building temporary testing directories [3]. [1] https://docs.python.org/3.6/library/unittest.html#unittest.TestCase.assertIn [2] https://docs.pytest.org/en/stable/capture.html [3] https://docs.pytest.org/en/stable/tmpdir.html On Fri, Jun 19, 2020 at 2:18 PM Terry Reedy wrote: > On 6/17/2020 12:34 PM, Tony Flury via Python-list wrote: > > > In a recent application that I wrote (where output to the console was > > important), I tested it using the 'unittest' framework, and by patching > > sys.stderr to be a StringIO - that way my test case could inspect what > > was being output. > > Tony's code with hard returns added so that code lines remain separated > instead of wrapping. > > with patch('sys.stderr', StringIO()) as stderr: > application.do_stuff() self.assertTrue(stderr.getvalue(), > 'Woops - that didn\'t work') > This doc, worth reading more than once, is > https://docs.python.org/3/library/unittest.mock.html#the-patchers > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list > From mats at python.org Sat Jun 20 11:56:50 2020 From: mats at python.org (Mats Wichmann) Date: Sat, 20 Jun 2020 09:56:50 -0600 Subject: How to test? In-Reply-To: <33292aa6-98e1-6b0b-ab34-6ca057941db0@DancesWithMice.info> References: <20200424204032.73b0e5e1@arcor.com> <20200425071636.529a9575@arcor.com> <20200425095354.0fa6e6f4@arcor.com> <6690ffb2-6c57-7d60-47e1-fd0d8f761aab@DancesWithMice.info> <20200426124601.520f7559@arcor.com> <7fc1e98d-f83d-961a-03c6-79de7d4807f0@DancesWithMice.info> <20200430192541.1594f9b1@arcor.com> <33292aa6-98e1-6b0b-ab34-6ca057941db0@DancesWithMice.info> Message-ID: On 5/1/20 2:34 PM, DL Neil via Python-list wrote: >>> Given your replies, 'now' might be a good time to take a look at >>> Pytest, and see how you could use it to help build better code - by >>> building tested units/functions which are assembled into ever-larger >>> tested-units... (there is a range of choice/other testing aids if >>> Pytest doesn't take your fancy) >> >> I have to admit I chose unittest. Simply because it is in the standard >> lbrary. As so many people seem to prefer pytest I should take a look at >> it. > > Not at all! This is a personal bias - I happen to have been using Pytest. it doesn't have to be either-or; pytest can deal with unittest tests, with some limitations. See here for some notes: https://docs.pytest.org/en/stable/unittest.html so you can try out what you have under pytest, and if liking it, can begin to transition to more native pytest - or just keep it as the test runner, or just stick with unittest. From bdorestand at example.com Sat Jun 20 11:59:16 2020 From: bdorestand at example.com (Boris Dorestand) Date: Sat, 20 Jun 2020 12:59:16 -0300 Subject: how to let argument be optional falling back to certain integer Message-ID: <86v9jlpw2z.fsf@example.com> I just wrote def f(y, N, k = None): k = k or (N - 1) return k I was surprised to find out that 0 == False, so f(7, 31, 0) produces 31. I'd like 0 to be a valid choice for k. How do you guys let k be an optional argument such that it defaults to N - 1? Thank you. From rosuav at gmail.com Sat Jun 20 12:06:05 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Jun 2020 02:06:05 +1000 Subject: how to let argument be optional falling back to certain integer In-Reply-To: <86v9jlpw2z.fsf@example.com> References: <86v9jlpw2z.fsf@example.com> Message-ID: On Sun, Jun 21, 2020 at 2:02 AM Boris Dorestand wrote: > > I just wrote > > def f(y, N, k = None): > k = k or (N - 1) > return k > > I was surprised to find out that 0 == False, so f(7, 31, 0) produces 31. > > I'd like 0 to be a valid choice for k. > > How do you guys let k be an optional argument such that it defaults to > N - 1? > The easiest way is to explicitly check for None. if k is None: k = N - 1 Zero being false shouldn't be a surprise. If None can count as false, then so should other "emptiness" values. (Remember, the canonical falseness value is False, not None.) ChrisA From python at python.invalid Sat Jun 20 13:30:13 2020 From: python at python.invalid (Python) Date: Sat, 20 Jun 2020 19:30:13 +0200 Subject: how to let argument be optional falling back to certain integer In-Reply-To: References: <86v9jlpw2z.fsf@example.com> Message-ID: <5eee476b$0$4699$426a74cc@news.free.fr> Le 20/06/2020 ? 18:23, Stefan Ram a ?crit?: > Boris Dorestand writes: >> def f(y, N, k = None): >> k = k or (N - 1) >> return k >> I was surprised to find out that 0 == False, so f(7, 31, 0) produces 31. > > bool is a subtype of int. > >> I'd like 0 to be a valid choice for k. > > k = N-1 if k==None else k When comparing wih None "is" is preferred to == k = N - 1 if k is None else k From bdorestand at example.com Sat Jun 20 19:59:58 2020 From: bdorestand at example.com (Boris Dorestand) Date: Sat, 20 Jun 2020 20:59:58 -0300 Subject: how to let argument be optional falling back to certain integer References: <86v9jlpw2z.fsf@example.com> Message-ID: <86r1u9nv9d.fsf@example.com> Chris Angelico writes: > On Sun, Jun 21, 2020 at 2:02 AM Boris Dorestand wrote: >> >> I just wrote >> >> def f(y, N, k = None): >> k = k or (N - 1) >> return k >> >> I was surprised to find out that 0 == False, so f(7, 31, 0) produces 31. >> >> I'd like 0 to be a valid choice for k. >> >> How do you guys let k be an optional argument such that it defaults to >> N - 1? >> > > The easiest way is to explicitly check for None. > > if k is None: k = N - 1 Got it. That's clear code. > Zero being false shouldn't be a surprise. If None can count as false, > then so should other "emptiness" values. (Remember, the canonical > falseness value is False, not None.) This is true. I have written 0 as false in C so many times. But clearly for me times have changed... I now look at numbers as a thing in their own special class not to be confused as truth-values. (So much so that I fell for this.) But I confess I still think of numbers as all TRUE. (Even zero!) Anyway, I kind of replied just to thank you all for the great group this is. ChrisA, I don't know how can keep up with this newsgroup, but you do. This is crazy. Years go by and when I come back, there you are still. You're priceless. From rosuav at gmail.com Sat Jun 20 20:33:52 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 21 Jun 2020 10:33:52 +1000 Subject: how to let argument be optional falling back to certain integer In-Reply-To: <86r1u9nv9d.fsf@example.com> References: <86v9jlpw2z.fsf@example.com> <86r1u9nv9d.fsf@example.com> Message-ID: On Sun, Jun 21, 2020 at 10:06 AM Boris Dorestand wrote: > > Chris Angelico writes: > > Zero being false shouldn't be a surprise. If None can count as false, > > then so should other "emptiness" values. (Remember, the canonical > > falseness value is False, not None.) > > This is true. I have written 0 as false in C so many times. But > clearly for me times have changed... I now look at numbers as a thing > in their own special class not to be confused as truth-values. (So much > so that I fell for this.) But I confess I still think of numbers as all > TRUE. (Even zero!) That's an interesting view. But fortunately you can have that too - just have to treat None as its own thing, instead of using a falsiness test. :) > Anyway, I kind of replied just to thank you all for the great group this > is. ChrisA, I don't know how can keep up with this newsgroup, but you > do. This is crazy. Years go by and when I come back, there you are > still. You're priceless. You're most welcome! I hang out here a lot because the people here are awesome. I've learned a lot, helped a lot of people, the language has shifted, it's been great. I like to think of myself as an empowerer - I help YOU to be able to do amazing things. It's you who are the awesome creative person who's making code do magic, and I'm just removing barriers from your way :) ChrisA From lepto.python at gmail.com Sun Jun 21 01:08:14 2020 From: lepto.python at gmail.com (oyster) Date: Sun, 21 Jun 2020 13:08:14 +0800 Subject: question on callback functions with ctypes Message-ID: question on callback functions with ctypes I try to use GoVCL( https://github.com/ying32/govcl ) in python via ctypes. GoVCL supplies C header and simple C demo under https://github.com/ying32/govcl/tree/master/Tools/makeCHeader/test Now the simple python code can run on both win7 and win10 according to Eryk Sun's suggestion - thank you Eryk Sun. But I am still puzzled by 2 questions 1. the callback function does not been invoked, so there must be something wrong when I deal with it. However, I can't figure it out. 2. in the original main.c, there is no need to call `vcl.SetEventCallback(doEventCallbackProc)`. But I learn this in a python code that uses cffi to call GoVCL. How can I make the python code as simple as the C code? Thanks The following python code is a simplified version of the C code ```python import sys, os import ctypes # In Python 3.8+, ctypes no longer searches PATH or the # current working directory when loading DLLs. liblcl_path = os.path.join(os.path.split(os.path.realpath(__file__))[0], 'liblcl.dll') vcl = ctypes.CDLL(liblcl_path) def _doEventCallbackProc(f, args, argcount): print(f, args, argcount) if f == ctypes.addressof(onButton1Click): vcl.DShowMessage("Hello world!".encode('utf8')) elif f == ctypes.addressof(onFormKeyDown): fnOnFormKeyDown(f, args, argcount) elif f == ctypes.addressof(onFormKeyDown): fnOnFormKeyDown(f, args, argcount) doEventCallbackProc = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_long)(_doEventCallbackProc) def _onButton1Click(sender): vcl.ShowMessage("Hello world!"); onButton1Click = ctypes.CFUNCTYPE(None, ctypes.c_void_p)(_onButton1Click) print(ctypes.addressof(onButton1Click)) Char = ctypes.c_uint16 TShiftState = ctypes.c_uint32 def _onFormKeyDown(sender, key, shift): print(key, shift); onFormKeyDown = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(Char), TShiftState)(_onFormKeyDown) print(ctypes.addressof(onFormKeyDown)) def _onEditChange(sender): print("%s\n", vcl.Edit_GetText(sender)); onEditChange = ctypes.CFUNCTYPE(None, ctypes.c_void_p)(_onEditChange) print(ctypes.addressof(onEditChange)) def main(): vcl.SetEventCallback(doEventCallbackProc) vcl.Application_Instance.restype = ctypes.c_void_p Application = vcl.Application_Instance() vcl.Application_Initialize.argtypes = ctypes.c_void_p, vcl.Application_Initialize(Application) vcl.Application_CreateForm.argtypes = ctypes.c_void_p, ctypes.c_bool vcl.Application_CreateForm.restype = ctypes.c_void_p form = vcl.Application_CreateForm(Application, False); vcl.Form_SetCaption.argtypes = ctypes.c_void_p, ctypes.c_char_p vcl.Form_SetCaption(form, "LCL Form".encode('utf8')); vcl.Form_SetKeyPreview.argtypes = ctypes.c_void_p, ctypes.c_bool vcl.Form_SetKeyPreview(form, True); vcl.Form_SetOnKeyDown.argtypes = ctypes.c_void_p, ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(Char), TShiftState) vcl.Form_SetOnKeyDown(form, onFormKeyDown); vcl.Button_Create.argtypes = ctypes.c_void_p, vcl.Button_Create.restype = ctypes.c_void_p btn = vcl.Button_Create(form); vcl.Button_SetParent.argtypes = ctypes.c_void_p, ctypes.c_void_p vcl.Button_SetParent(btn, form); vcl.Button_SetOnClick.argtypes = ctypes.c_void_p, ctypes.CFUNCTYPE(None, ctypes.c_void_p) vcl.Button_SetOnClick(btn, onButton1Click); vcl.Button_SetCaption.argtypes = ctypes.c_void_p, ctypes.c_char_p vcl.Button_SetCaption(btn, "button1".encode('utf8')); vcl.Button_SetLeft.argtypes = ctypes.c_void_p, ctypes.c_uint32 vcl.Button_SetLeft(btn, 100); vcl.Button_SetTop.argtypes = ctypes.c_void_p, ctypes.c_uint32 vcl.Button_SetTop(btn, 100); vcl.Edit_Create.argtypes = ctypes.c_void_p, vcl.Edit_Create.restype = ctypes.c_void_p edit = vcl.Edit_Create(form); vcl.Edit_SetParent.argtypes = ctypes.c_void_p, ctypes.c_void_p vcl.Edit_SetParent(edit, form); vcl.Edit_SetOnChange.argtypes = ctypes.c_void_p, ctypes.CFUNCTYPE(None, ctypes.c_void_p) vcl.Edit_SetOnChange(edit, onEditChange); vcl.Application_Run.argtypes = ctypes.c_void_p, vcl.Application_Run(Application); main() ``` the C code ```C #include "liblcl.h" #ifdef _WIN32 char *UTF8Decode(char* str) { int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, 0, 0); wchar_t* wCharBuffer = (wchar_t*)malloc(len * sizeof(wchar_t) + 1); MultiByteToWideChar(CP_UTF8, 0, str, -1, wCharBuffer, len); len = WideCharToMultiByte(CP_ACP, 0, wCharBuffer, -1, 0, 0, 0, NULL); char* aCharBuffer = (char*)malloc(len * sizeof(char) + 1); WideCharToMultiByte(CP_ACP, 0, wCharBuffer, -1, aCharBuffer, len, 0, NULL); free((void*)wCharBuffer); return aCharBuffer; } #endif void onButton1Click(TObject sender) { ShowMessage("Hello world!"); } void onOnDropFiles(TObject sender, void* aFileNames, intptr_t len) { printf("aFileNames: %p, len=%d\n", aFileNames, len); intptr_t i; for (i = 0; i < len; i++) { #ifdef _WIN32 char *filename = UTF8Decode(GetStringArrOf(aFileNames, i)); #else char *filename = GetStringArrOf(aFileNames, i); #endif printf("file[%d]=%s\n", i+1, filename); #ifdef _WIN32 free((void*)filename); #endif } } void onFormKeyDown(TObject sender, Char* key, TShiftState shift) { printf("key=%d, shift=%d\n", *key, shift); if (*key == vkReturn) { ShowMessage("press Enter!"); } TShiftState s = Include(0, ssAlt); if (InSet(s, ssAlt)) { printf("ssAlt1\n"); } s = Exclude(s, ssAlt); if (!InSet(s, ssAlt)) { printf("ssAlt2\n"); } } void onEditChange(TObject sender) { printf("%s\n", Edit_GetText(sender)); } int main() { #ifdef _WIN32 if (load_liblcl("liblcl.dll")) { #endif #ifdef __linux__ if (load_liblcl("liblcl.so")) { #endif #ifdef __APPLE__ if (load_liblcl("liblcl.dylib")) { #endif Application_Initialize(Application); TForm form = Application_CreateForm(Application, FALSE); Form_SetCaption(form, "LCL Form"); Form_SetPosition(form, poScreenCenter); Form_SetAllowDropFiles(form, TRUE); Form_SetOnDropFiles(form, onOnDropFiles); Form_SetKeyPreview(form, TRUE); Form_SetOnKeyDown(form, onFormKeyDown); TButton btn = Button_Create(form); Button_SetParent(btn, form); Button_SetOnClick(btn, onButton1Click); Button_SetCaption(btn, "button1"); Button_SetLeft(btn, 100); Button_SetTop(btn, 100); TEdit edit = Edit_Create(form); Edit_SetParent(edit, form); Edit_SetLeft(edit, 10); Edit_SetTop(edit, 10); Edit_SetOnChange(edit, onEditChange); Application_Run(Application); close_liblcl(); } return 0; } ``` From phoenix1987 at gmail.com Sun Jun 21 17:57:07 2020 From: phoenix1987 at gmail.com (Gabriele) Date: Sun, 21 Jun 2020 21:57:07 GMT Subject: [ANN] Austin -- Python frame stack sampler for CPython v1.0.1 is now available Message-ID: I am delighted to announce the release 1.0.1 of Austin. If you haven't heard of Austin before, it is a frame stack sampler for CPython. It can be used to obtain statistical profiling data out of a running Python application without a single line of instrumentation. This means that you can start profiling a Python application straightaway, even while it's running on a production environment, with minimal impact on performance. The simplest way of using Austin is by piping its output to FlameGraph for a quick and detailed representation of the collected samples. The latest release introduces a memory profiling mode which allows you to profile memory usage. Austin is a pure C application that has no other dependencies other than the C standard library. Its source code is hosted on GitHub at https://github.com/P403n1x87/austin The README contains installation and usage details, as well as some examples of Austin in action. Details on how to contribute to Austin's development can be found at the bottom of the page. Austin v1.0.1 is also the first version of Austin to be available from Homebrew for easy installation on MacOS. These are the other places where Austin can be downloaded Linux: - Snap Store - Debian repositories Windows: - Chocolatey Furthermore, you can stay up-to-date with the project's development by following Austin on Twitter (https://twitter.com/AustinSampler). All the best, Gabriele Bugfixes ======== - Fixed Python 3.8 support on MacOS. From bdorestand at example.com Sun Jun 21 19:54:52 2020 From: bdorestand at example.com (Boris Dorestand) Date: Sun, 21 Jun 2020 20:54:52 -0300 Subject: how to let argument be optional falling back to certain integer References: <86v9jlpw2z.fsf@example.com> <86r1u9nv9d.fsf@example.com> Message-ID: <86ftaonfeb.fsf@example.com> Chris Angelico writes: [...] >> Anyway, I kind of replied just to thank you all for the great group this >> is. ChrisA, I don't know how can keep up with this newsgroup, but you >> do. This is crazy. Years go by and when I come back, there you are >> still. You're priceless. > > You're most welcome! I hang out here a lot because the people here are > awesome. I've learned a lot, helped a lot of people, the language has > shifted, it's been great. > > I like to think of myself as an empowerer - I help YOU to be able to > do amazing things. It's you who are the awesome creative person who's > making code do magic, and I'm just removing barriers from your way :) I appreciate that a lot! But of course if that's your view of things, then you are the great one here. No doubt about it. Have a great day! From ml_news at posteo.de Mon Jun 22 01:14:56 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Mon, 22 Jun 2020 07:14:56 +0200 Subject: How to test? References: <20200424204032.73b0e5e1@arcor.com> <75abbbef-b3a2-6dd8-9df3-e73ef81f57d2@btinternet.com> Message-ID: <20200622071456.24292635@arcor.com> On Wed, 17 Jun 2020 17:34:55 +0100 Tony Flury wrote: > On 24/04/2020 19:40, Manfred Lotz wrote: > > I have a command like application which checks a directory tree for > > certain things. If there are errors then messages will be written to > > stdout. > > > > How to test this in the best way? > > > > One idea was for the error situations to write messages to files and > > then later when running the tests to compare the error messages > > output to the previously saved output. > > > > Is there anything better? > > > > In a recent application that I wrote (where output to the console was > important), I tested it using the 'unittest' framework, and by > patching sys.stderr to be a StringIO - that way my test case could > inspect what was being output. > > with patch('sys.stderr', StringIO()) as > stderr:application.do_stuff()self.assertTrue(stderr.getvalue(), > 'Woops - that didn\'t work') > > I am not sure of the structure of your application, and whether you > have a callable API that you can invoke. > Thanks a lot. That's really great. In the meantime I switched to pytest because things are so much more convenient to setup. So, also thanks to the others who gave the links to how this can be done with pytest. -- Manfred From sundrambajaj8 at gmail.com Sun Jun 21 05:37:00 2020 From: sundrambajaj8 at gmail.com (Sundram Bajaj) Date: Sun, 21 Jun 2020 15:07:00 +0530 Subject: Fwd: regarding issues faced while running python in the command prompt In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Date: Sun, 21 Jun 2020, 14:06 Subject: regarding issues faced while running python in the command prompt To: Hello! I see you want to post a message to the Python List. We would be happy to help, but you must subscribe first: https://mail.python.org/mailman/listinfo/python-list After you have subscribed, please send your message again. Alternatively, this list is mirrored both ways with the comp.lang.python newsgroup (news:comp.lang.python). Some people find it easier to follow this and other lists via gmane (http://news.gmane.org/gmane.comp.python.general), a service which offers a newsgroup interface to many online mailing lists. *NB all posts to the mailing list are publicly archived at:* https://mail.python.org/pipermail/python-list ---------- Forwarded message ---------- From: Sundram Bajaj To: "python-list at python.org" Cc: Bcc: Date: Sun, 21 Jun 2020 14:06:09 +0530 Subject: regarding issues faced while running python in the command prompt Respected sir/ madam Every time I try to run program written in Atom text editor on command prompt in my windows 10 a message pops up that file is not recognised as internal file. Please go through the screenshot of the same attached herewith and help me asap. I also tried uninstalling python and reinstall it but am also unable to do it. Every time I try reinstalling through the setup the inly option that I get is of repairing the software. I am really facing a lot of issues and request you to please resolve my problems ASAP. Thank you Sent from Mail for Windows 10 From merinoisbest at gmail.com Sun Jun 21 05:47:09 2020 From: merinoisbest at gmail.com (Merino Isbest) Date: Sun, 21 Jun 2020 11:47:09 +0200 Subject: mdo_import_help python code Message-ID: Hi, I'm a new user, also a python newbie, hoping to learn here from the wisdom and experience of other members. Now, anyone is familiar with mdo_import_help ? I'm trying to run some python code code but it keeps failing because mdo_import_ help is missing. Thanks, guys Mirabelle la Terreur Virus-free. www.avast.com <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> From akintolaaisham at gmail.com Sun Jun 21 13:31:30 2020 From: akintolaaisham at gmail.com (Aisha Akintola) Date: Sun, 21 Jun 2020 18:31:30 +0100 Subject: Problem installing Python Message-ID: Good day, I downloaded python(python3.8.3) on my system (windows 8) to enable me use PyCharm. However, I realised the python wasn't well installed. I get message "the program can't start because api-ms-win-crt-runtime-I1-1-0.dll is missing from your computer. Try reinstalling the program to fix this problem'. I have reinstalled but got the same error message; what should I do? Thank you From souvik.viksou at gmail.com Mon Jun 22 02:55:06 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Mon, 22 Jun 2020 12:25:06 +0530 Subject: regarding issues faced while running python in the command prompt In-Reply-To: References: Message-ID: You cannot attach any screenshots because the list strips them. You will have to provide your errors and your tries as an inline text in the email (copy and paste the error). Souvik flutter dev On Mon, Jun 22, 2020, 12:02 PM Sundram Bajaj wrote: > ---------- Forwarded message --------- > From: > Date: Sun, 21 Jun 2020, 14:06 > Subject: regarding issues faced while running python in the command prompt > To: > > > Hello! I see you want to post a message to the Python List. We would > be happy to help, but you must subscribe first: > > https://mail.python.org/mailman/listinfo/python-list > > After you have subscribed, please send your message again. > > Alternatively, this list is mirrored both ways with the > comp.lang.python newsgroup (news:comp.lang.python). > > Some people find it easier to follow this and other lists via gmane > (http://news.gmane.org/gmane.comp.python.general), a service which > offers a newsgroup interface to many online mailing lists. > > *NB all posts to the mailing list are publicly archived at:* > > https://mail.python.org/pipermail/python-list > > > > > > ---------- Forwarded message ---------- > From: Sundram Bajaj > To: "python-list at python.org" > Cc: > Bcc: > Date: Sun, 21 Jun 2020 14:06:09 +0530 > Subject: regarding issues faced while running python in the command prompt > > Respected sir/ madam > > Every time I try to run program written in Atom text editor on command > prompt in my windows 10 a message pops up that file is not recognised as > internal file. Please go through the screenshot of the same attached > herewith and help me asap. I also tried uninstalling python and reinstall > it but am also unable to do it. Every time I try reinstalling through the > setup the inly option that I get is of repairing the software. I am really > facing a lot of issues and request you to please resolve my problems ASAP. > > Thank you > > > > Sent from Mail for > Windows > 10 > -- > https://mail.python.org/mailman/listinfo/python-list > From David.Raymond at tomtom.com Mon Jun 22 07:15:14 2020 From: David.Raymond at tomtom.com (David Raymond) Date: Mon, 22 Jun 2020 11:15:14 +0000 Subject: how to let argument be optional falling back to certain integer In-Reply-To: <86r1u9nv9d.fsf@example.com> References: <86v9jlpw2z.fsf@example.com> <86r1u9nv9d.fsf@example.com> Message-ID: > This is true. I have written 0 as false in C so many times. But > clearly for me times have changed... I now look at numbers as a thing > in their own special class not to be confused as truth-values. (So much > so that I fell for this.) But I confess I still think of numbers as all > TRUE. (Even zero!) Also remember that in Python bool is a subclass of int: >>> isinstance(False, int) True >>> 0 == False True >>> 1 == True True >>> ["A", "B"][False] 'A' >>> ["A", "B"][True] 'B' So if you're trying to do something slightly different based on the type of the input you might fall into this trap if isinstance(foo, float): do float stuff elif isinstance(foo, int): do int stuff elif isinstance(foo, bool): this line will never run because it would have triggered the int line From bdorestand at example.com Mon Jun 22 08:52:18 2020 From: bdorestand at example.com (Boris Dorestand) Date: Mon, 22 Jun 2020 09:52:18 -0300 Subject: how to let argument be optional falling back to certain integer References: <86v9jlpw2z.fsf@example.com> <86r1u9nv9d.fsf@example.com> Message-ID: <86sgen6z5p.fsf@example.com> David Raymond writes: >> This is true. I have written 0 as false in C so many times. But >> clearly for me times have changed... I now look at numbers as a thing >> in their own special class not to be confused as truth-values. (So much >> so that I fell for this.) But I confess I still think of numbers as all >> TRUE. (Even zero!) > > Also remember that in Python bool is a subclass of int: >>>> isinstance(False, int) > True >>>> 0 == False > True >>>> 1 == True > True >>>> ["A", "B"][False] > 'A' >>>> ["A", "B"][True] > 'B' > > So if you're trying to do something slightly different based on the > type of the input you might fall into this trap > > if isinstance(foo, float): > do float stuff > elif isinstance(foo, int): > do int stuff > elif isinstance(foo, bool): > this line will never run because it would have triggered the int line In my case I was only interested in ints, so I actually did try isinstance(k, int) and it seemed to work because I didn't try k = False I settled for the explicit check done by Chris Angelico. From python at mrabarnett.plus.com Mon Jun 22 10:39:13 2020 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 22 Jun 2020 15:39:13 +0100 Subject: Problem installing Python In-Reply-To: References: Message-ID: <2afbe631-9976-e339-423e-799fe88126ae@mrabarnett.plus.com> On 2020-06-21 18:31, Aisha Akintola wrote: > Good day, > I downloaded python(python3.8.3) on my system (windows 8) to enable me use > PyCharm. However, I realised the python wasn't well installed. I get > message "the program can't start because api-ms-win-crt-runtime-I1-1-0.dll > is missing from your computer. Try reinstalling the program to fix > this problem'. > I have reinstalled but got the same error message; what should I do? > Thank you > You need the Windows Universal C Runtime: http://www.microsoft.com/en-us/download/details.aspx?id=48234 From spluque at gmail.com Mon Jun 22 18:38:52 2020 From: spluque at gmail.com (Seb) Date: Mon, 22 Jun 2020 17:38:52 -0500 Subject: parsing encrypted netrc file Message-ID: <87tuz2d8ub.fsf@otaria.sebmel.org> Hello, What's the pythonic way to do this without polluting the user's directory with the decrypted file? I wrongly thought this should do it: import os.path as osp import gnupg import netrc import tempfile gpg = gnupg.GPG() with open(osp.expanduser("~/.authinfo.gpg"), "rb") as f: with tempfile.NamedTemporaryFile("w+") as tf: status = gpg.decrypt_file(f, output=tf.name) info = netrc.netrc(tf.name) which fails as the temporary file doesn't even get created. -- Seb From python at mrabarnett.plus.com Mon Jun 22 19:40:28 2020 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Jun 2020 00:40:28 +0100 Subject: parsing encrypted netrc file In-Reply-To: <87tuz2d8ub.fsf@otaria.sebmel.org> References: <87tuz2d8ub.fsf@otaria.sebmel.org> Message-ID: <6c602e30-81ad-b645-f276-12c8a787fdfa@mrabarnett.plus.com> On 2020-06-22 23:38, Seb wrote: > Hello, > > What's the pythonic way to do this without polluting the user's > directory with the decrypted file? I wrongly thought this should do it: > > import os.path as osp > import gnupg > import netrc > import tempfile > > gpg = gnupg.GPG() > > with open(osp.expanduser("~/.authinfo.gpg"), "rb") as f: > with tempfile.NamedTemporaryFile("w+") as tf: > status = gpg.decrypt_file(f, output=tf.name) > info = netrc.netrc(tf.name) > > which fails as the temporary file doesn't even get created. > Are you sure it doesn't get created? I'm wondering whether you need to flush the file before passing it to netrc to ensure that all of the decrypted data is there on disk for reader. I'm also wondering whether the file is shareable. From spluque at gmail.com Mon Jun 22 20:47:04 2020 From: spluque at gmail.com (Seb) Date: Mon, 22 Jun 2020 19:47:04 -0500 Subject: parsing encrypted netrc file In-Reply-To: <6c602e30-81ad-b645-f276-12c8a787fdfa@mrabarnett.plus.com> (MRAB's message of "Tue, 23 Jun 2020 00:40:28 +0100") References: <87tuz2d8ub.fsf@otaria.sebmel.org> <6c602e30-81ad-b645-f276-12c8a787fdfa@mrabarnett.plus.com> Message-ID: <87mu4ud2wn.fsf@otaria.sebmel.org> On Tue, 23 Jun 2020 00:40:28 +0100, MRAB wrote: > On 2020-06-22 23:38, Seb wrote: >> Hello, >> What's the pythonic way to do this without polluting the user's >> directory with the decrypted file? I wrongly thought this should do >> it: >> import os.path as osp import gnupg import netrc import tempfile >> gpg = gnupg.GPG() >> with open(osp.expanduser("~/.authinfo.gpg"), "rb") as f: with >> tempfile.NamedTemporaryFile("w+") as tf: status = gpg.decrypt_file(f, >> output=tf.name) info = netrc.netrc(tf.name) >> which fails as the temporary file doesn't even get created. > Are you sure it doesn't get created? Without using tempfile: with open(osp.expanduser("~/.authinfo.gpg"), "rb") as f: status = gpg.decrypt_file(f, output=".authinfo.txt") info = netrc.netrc(".authinfo.txt") I get the error: NetrcParseError: bad follower token 'port' (.authinfo.txt, line 1) which is interesting. The structure of ~/.authinfo.gpg is: machine my.server.com login user at foo.com password mypasswd port 587 so it seems this is not what netrc.netrc expects. -- Seb From python at mrabarnett.plus.com Mon Jun 22 21:08:19 2020 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Jun 2020 02:08:19 +0100 Subject: parsing encrypted netrc file In-Reply-To: <87mu4ud2wn.fsf@otaria.sebmel.org> References: <87tuz2d8ub.fsf@otaria.sebmel.org> <6c602e30-81ad-b645-f276-12c8a787fdfa@mrabarnett.plus.com> <87mu4ud2wn.fsf@otaria.sebmel.org> Message-ID: <608b8d77-d58a-7d30-0480-e65501e5fe3f@mrabarnett.plus.com> On 2020-06-23 01:47, Seb wrote: > On Tue, 23 Jun 2020 00:40:28 +0100, > MRAB wrote: > >> On 2020-06-22 23:38, Seb wrote: >>> Hello, > >>> What's the pythonic way to do this without polluting the user's >>> directory with the decrypted file? I wrongly thought this should do >>> it: > >>> import os.path as osp import gnupg import netrc import tempfile > >>> gpg = gnupg.GPG() > >>> with open(osp.expanduser("~/.authinfo.gpg"), "rb") as f: with >>> tempfile.NamedTemporaryFile("w+") as tf: status = gpg.decrypt_file(f, >>> output=tf.name) info = netrc.netrc(tf.name) > >>> which fails as the temporary file doesn't even get created. > >> Are you sure it doesn't get created? > > Without using tempfile: > > with open(osp.expanduser("~/.authinfo.gpg"), "rb") as f: > status = gpg.decrypt_file(f, output=".authinfo.txt") > info = netrc.netrc(".authinfo.txt") > > I get the error: > > NetrcParseError: bad follower token 'port' (.authinfo.txt, line 1) > > which is interesting. The structure of ~/.authinfo.gpg is: > > machine my.server.com login user at foo.com password mypasswd port 587 > > so it seems this is not what netrc.netrc expects. > Here's a page I found about ".netrc": https://ec.haxx.se/usingcurl/usingcurl-netrc and here's a page I found about ".authinfo.gpg": https://www.emacswiki.org/emacs/GnusAuthinfo Can you see the subtle difference? From mal at europython.eu Tue Jun 23 09:08:54 2020 From: mal at europython.eu (M.-A. Lemburg) Date: Tue, 23 Jun 2020 15:08:54 +0200 Subject: EuroPython 2020: Opening our Merchandise Shop Message-ID: <2a3d6846-ec79-c3bc-dc86-28c83bcab455@europython.eu> We?re very happy to announce our very own EuroPython merchandise shop: * EuroPython Merch Shop * https://shop.spreadshirt.ie/europython/ Customize your conference t-shirt for EP2020 -------------------------------------------- The shop is run on the Spreadshirt platform and so Spreadshirt will handle all payments, invoicing and shipping. Since we?re running EuroPython 2020 as an online event, we will not be giving out conference bags or t-shirts this year, as we do for the in-person event. Instead, we give you the opportunity to choose among the many products we have put up in the shop, and order the color and size completely individually. Any profit this creates will go towards the EuroPython 2021 financial aid budget, so will be put to good use. Save 15% until July 5 --------------------- Spreadshirt is giving a 15% discount on the prices until July 5, 23:59 UTC, so if you?re ordering in the next few days, you can still get your shirt in time for the conference. Shipping worldwide ------------------ Spreadshirt is shipping to a lot of destinations worldwide. Unfortunately, they don?t support shipping to the US, Australia, Brasil and a few other countries on their European shop system. Since the US taxation system is too complex for us to handle at the moment, we have not created a corresponding US shop yet. We will look into this later this year. Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/post/621715858139594752/europython-2020-opening-our-merchandise-shop Tweet: https://twitter.com/europython/status/1275402520488222727 Thanks, -- EuroPython 2020 Team https://ep2020.europython.eu/ https://www.europython-society.org/ From spluque at gmail.com Mon Jun 22 21:18:22 2020 From: spluque at gmail.com (Seb) Date: Mon, 22 Jun 2020 20:18:22 -0500 Subject: parsing encrypted netrc file In-Reply-To: <608b8d77-d58a-7d30-0480-e65501e5fe3f@mrabarnett.plus.com> (MRAB's message of "Tue, 23 Jun 2020 02:08:19 +0100") References: <87tuz2d8ub.fsf@otaria.sebmel.org> <6c602e30-81ad-b645-f276-12c8a787fdfa@mrabarnett.plus.com> <87mu4ud2wn.fsf@otaria.sebmel.org> <608b8d77-d58a-7d30-0480-e65501e5fe3f@mrabarnett.plus.com> Message-ID: <87imfid1gh.fsf@otaria.sebmel.org> On Tue, 23 Jun 2020 02:08:19 +0100, MRAB wrote: [...] > Here's a page I found about ".netrc": > https://ec.haxx.se/usingcurl/usingcurl-netrc > and here's a page I found about ".authinfo.gpg": > https://www.emacswiki.org/emacs/GnusAuthinfo > Can you see the subtle difference? Awww nuts, I do! What a pain, wouldn't it be nice if there was a standard on such things. Thanks for the pointer! -- Seb From pabloalcain at gmail.com Tue Jun 23 10:35:26 2020 From: pabloalcain at gmail.com (Pablo Alcain) Date: Tue, 23 Jun 2020 11:35:26 -0300 Subject: [Python-ideas] asyncio: return from multiple coroutines In-Reply-To: References: Message-ID: Thank you very much Kyle for your answer, I am moving this conversation to the more proper python-list for whoever wants to chime in. I summarize here the key points of my original question (full question on the quoted email): I have an application that listens on two websockets through the async library https://websockets.readthedocs.io/ and I have to perform the same function on the result, no matter where the message came from. I have implemented a rather cumbersome solution with async Queues: https://pastebin.com/BzaxRbtF, but i think there has to be a more async-friendly option I am missing. Now I move on to the comments that Kyle made On Tue, Jun 23, 2020 at 12:32 AM Kyle Stanley wrote: > I believe asyncio.wait() with "return_when=FIRST_COMPLETED" would > perform the functionality you're looking for with the > "asyncio.on_first_return()". For details on the functionality of > asyncio.wait(), see > https://docs.python.org/3/library/asyncio-task.html#asyncio.wait. > > I understand that I can create two coroutines that call the same > function, but it would be much cleaner (because of implementation issues) > if I can simply create a coroutine that yields the result of whichever > connection arrives first. > > You can use an asynchronous generator that will continuously yield the > result of the first recv() that finishes (I'm assuming you mean > "yields" literally and want multiple results from a generator, but I > might be misinterpreting that part). > Yes, I want to have multiple results: the connections listening forever, returning a result for each message received. > > Here's a brief example, using the recv() coroutine function from the > pastebin linked: > > ``` > import asyncio > import random > > async def recv(message: str, max_sleep: int): > sleep_time = max_sleep * random.random() > await asyncio.sleep(sleep_time) > return f'{message} awaited for {sleep_time:.2f}s' > > async def _start(): > while True: > msgs = [ > asyncio.create_task(recv("Messager 1", max_sleep=1)), > asyncio.create_task(recv("Messager 2", max_sleep=1)) > ] > done, _ = await asyncio.wait(msgs, > return_when=asyncio.FIRST_COMPLETED) > result = done.pop() > yield await result > > async def main(): > async for result in _start(): > print(result) > > asyncio.run(main()) > ``` I forgot to mention thatI did try to use asyncio.wait with `FIRST_COMPLETED`; however, the problem is that it seems to evict the not-completed coroutines, so the messenger that arrives second does not send the message. To check it, I have run that script without the random sleep. just msgr1 waits 1s and msgr2 waits 2s, so msgr1 always ends first. I expect a result like this (which I am currently getting with queues): Messenger 1 waits for 1.0s Messenger 1 waits for 1.0s Messenger 2 waits for 2.0s Messenger 1 waits for 1.0s Messenger 1 waits for 1.0s Messenger 2 waits for 2.0s Messenger 1 waits for 1.0s ... but instead I got this: Messenger 1 waits for 1.0s Messenger 1 waits for 1.0s Messenger 1 waits for 1.0s Messenger 1 waits for 1.0s Messenger 1 waits for 1.0s ... > Note that in the above example, in "msgs", you can technically pass > the coroutine objects directly to asyncio.wait(), as they will be > implicitly converted to tasks. However, we decided to deprecate that > functionality in Python 3.8 since it can be rather confusing. So > creating and passing the tasks is a better practice. > Thanks for that info, I am still trying to grasp the best practices surrounding mostly the explicitness in async. > > Again, it's quite likely I am not seeing something obvious, but I didn't > know where else to ask. > > If you're not mostly certain or relatively inexperienced with the > specific area that the question pertains to, I'd recommend asking on > python-list first (or another Python user community). python-ideas is > primarily intended for new feature proposals/suggestions. Although if > you've tried other resources and haven't found an answer, it's > perfectly fine to ask a question as part of the suggestion post. > > > Original question, as posted in python-ideas: > On Mon, Jun 22, 2020 at 6:24 PM Pablo Alcain > wrote: > > > > Hey everyone. I have been looking into asyncio lately, and even though I > have had my fair share of work, I still have some of it very shaky, so > first of all forgive me if what I am saying here is already implemented and > I totally missed it (so far, it looks *really* likely). > > > > Basically this is the situation: I have an application that listens on > two websockets through the async library > https://websockets.readthedocs.io/ and I have to perform the same > function on the result, no matter where the message came from. I understand > that I can create two coroutines that call the same function, but it would > be much cleaner (because of implementation issues) if I can simply create a > coroutine that yields the result of whichever connection arrives first. > > > > I have implemented a rather cumbersome solution with async Queues (as I > would do in threading), in which each connection puts its message in a > queue and an adapter class awaits the first element of the queue on > "receive". Here I attach a pastebin with the minimal working example: > https://pastebin.com/BzaxRbtF > > > > However, it looks like a more async-friendly solution should exist, > something like > > > > ``` > > async def _start(): > > msg1 = recv("Messager 1", sleep_time=1) > > msg2 = recv("Messager 2", sleep_time=2) > > while True: > > result = await asyncio.on_first_return(msg1, msg2) > > print(result) > > ``` > > > > (I understand that this implementation would not work because the event > loop doesn't know that it is "the same task repeated", but it's just to > tell you the general idea) > > > > Again, it's quite likely I am not seeing something obvious, but I didn't > know where else to ask. > > > > Thank you very much, > > Pablo > > > > _______________________________________________ > > Python-ideas mailing list -- python-ideas at python.org > > To unsubscribe send an email to python-ideas-leave at python.org > > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > > Message archived at > https://mail.python.org/archives/list/python-ideas at python.org/message/XBR5QPXRBCCJELDVEWMKRBPTNG4SJM64/ > > Code of Conduct: http://python.org/psf/codeofconduct/ > From tony.flury at btinternet.com Tue Jun 23 10:32:32 2020 From: tony.flury at btinternet.com (Tony Flury) Date: Tue, 23 Jun 2020 15:32:32 +0100 Subject: Floating point problem In-Reply-To: References: <5e99a696$0$6454$426a74cc@news.free.fr> <643a4577-9fbc-f2f4-ffb8-a780e02a9ea1@DancesWithMice.info> Message-ID: <594fc325-6420-c468-802b-e793bdde38df@btinternet.com> On 18/04/2020 15:29, Grant Edwards wrote: > On 2020-04-18, Souvik Dutta wrote: >> I literally tried it!!! And it did not stop because I did not get any 1.0 >> rather I got 0.99999999999 But why does this happen. This is a simple math >> which according to normal human logic should give perfect numbers which are >> not endless. Then why does a computer behave so differently? > Because computers _don't_do_math_. That is a very important thing to > remember. > > Computer do something that _approximates_ math... in some > situations... if you know what you're doing. > > In you're case you're doing IEEE floating point operations. Before you > use floating point, you should read the article by Goldman that has been > suggested: > > https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html > https://dl.acm.org/doi/10.1145/103162.103163 There is also https://docs.python.org/3/tutorial/floatingpoint.html In the official Python documentation, well worth reading. > > -- > Grant > From barry at barrys-emacs.org Tue Jun 23 15:18:33 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Tue, 23 Jun 2020 20:18:33 +0100 Subject: parsing encrypted netrc file In-Reply-To: <87tuz2d8ub.fsf@otaria.sebmel.org> References: <87tuz2d8ub.fsf@otaria.sebmel.org> Message-ID: <5A265AB4-7970-4A32-B33D-3CD36DE51600@barrys-emacs.org> > On 22 Jun 2020, at 23:38, Seb wrote: > > Hello, > > What's the pythonic way to do this without polluting the user's > directory with the decrypted file? I wrongly thought this should do it: > > import os.path as osp > import gnupg > import netrc > import tempfile > > gpg = gnupg.GPG() > > with open(osp.expanduser("~/.authinfo.gpg"), "rb") as f: > with tempfile.NamedTemporaryFile("w+") as tf: > status = gpg.decrypt_file(f, output=tf.name) > info = netrc.netrc(tf.name) > > which fails as the temporary file doesn't even get created. I do not how to do this. But I would decrypt into a string in memory. Then have netrc parse from the string. There is no point in having an encrypted file if you are going to decrypt in to a temp file. A deleted files leaves it in the contents on the disk to be grab by bad actors. Barry > > -- > Seb > -- > https://mail.python.org/mailman/listinfo/python-list > From jgossage at gmail.com Tue Jun 23 14:04:42 2020 From: jgossage at gmail.com (Jonathan Gossage) Date: Tue, 23 Jun 2020 14:04:42 -0400 Subject: Asynchronous generators Message-ID: -- I am attempting to learn how to use asyncio and I have been unable to find any documentation or Internet posts that give information on the principles underlying asyncio, let alone any examples showing how asynchronous generators should be used. I have built a toy program to test trying to read a text file, line by line, and process each line asynchronously. I wind up with a message complaining that my asynchronous generator is not a coroutine. I am posting a copy of my program here along with the results from trying to run it. I am hoping for some suggestions about how to fix it. I am using Python 3.8.3 on Ubuntu 20.04 import asyncio > from pathlib import Path > import timeit > > async def _read_password() -> str: > with Path('/etc/passwd').open() as f: > line: str = f.readline() > yield line > print('read_password has read everything') > > async def main(_rp) -> int: > line = '' > async for line in _rp: > try: > print(f'Got line {line}') > except StopAsyncIteration: > line = None > _rp.aclose() > return 0 > > if __name__ == '__main__': > _loop = asyncio.get_event_loop() > _rp = _read_password() > _m = main(_rp) > _loop.create_task(_m) > _loop.create_task(_rp) > timeit.Timer(_loop.run_until_complete()).timeit() > _loop.close() Here is the output: Traceback (most recent call last): File "/usr/local/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/home/jgossage/EclipseWorkspaces/GlobalVillage/Infrastructure/Play/Async/passwd.py", line 34, in _loop.create_task(_rp) File "/usr/local/lib/python3.8/asyncio/base_events.py", line 431, in create_task task = tasks.Task(coro, loop=self, name=name) TypeError: a coroutine was expected, got From tkaloki at live.co.uk Tue Jun 23 15:18:18 2020 From: tkaloki at live.co.uk (Tony Kaloki) Date: Tue, 23 Jun 2020 19:18:18 +0000 Subject: FW: Pycharm Won't Do Long Underscore In-Reply-To: References: Message-ID: Sent from Mail for Windows 10 From: Tony Kaloki Sent: 23 June 2020 19:45 To: python-list at python.org Subject: Pycharm Won't Do Long Underscore Hi Guys, I?ve just begun to learn basic computer programming by downloading Python and Pycharm and following Youtube tutorials. But I?ve come across a problem that?s stopped me in my tracks. When I try to do a long underscore __ for classes in Pycharm, it only gives me two separate single underscores _ _. This is only in Pycharm, no problems anywhere else. Could you tell me how to fix this, because I can?t find any answers on the web and I?m not sure if I can go any further in my learning without being able to get long underscores. Sorry if I?m just being really dense, but like I said I?m an absolute beginner. Thanks for your time, Tony Sent from Mail for Windows 10 From python at mrabarnett.plus.com Tue Jun 23 16:44:24 2020 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 23 Jun 2020 21:44:24 +0100 Subject: FW: Pycharm Won't Do Long Underscore In-Reply-To: References: Message-ID: <1ba5e69e-f916-f96d-a67b-44a3df638228@mrabarnett.plus.com> On 2020-06-23 20:18, Tony Kaloki wrote: > > > Sent from Mail for Windows 10 > > From: Tony Kaloki > Sent: 23 June 2020 19:45 > To: python-list at python.org > Subject: Pycharm Won't Do Long Underscore > > > Hi Guys, > I?ve just begun to learn basic computer programming by downloading Python and Pycharm and following Youtube tutorials. But I?ve come across a problem that?s stopped me in my tracks. > When I try to do a long underscore __ for classes in Pycharm, it only gives me two separate single underscores _ _. This is only in Pycharm, no problems anywhere else. Could you tell me how to fix this, because I can?t find any answers on the web and I?m not sure if I can go any further in my learning without being able to get long underscores. > Sorry if I?m just being really dense, but like I said I?m an absolute beginner. Thanks for your time, > The "__" is 2 underscores; it's just that they usually appear joined together in many fonts. If you try: print('_' * 2) do they appear joined together or separate? If they appear separate, then you can see that that's just how they're displayed in that funt. From tkaloki at live.co.uk Tue Jun 23 16:49:36 2020 From: tkaloki at live.co.uk (Tony Kaloki) Date: Tue, 23 Jun 2020 20:49:36 +0000 Subject: Pycharm Won't Do Long Underscore In-Reply-To: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> References: , <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> Message-ID: 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? In any case, thanks again for your quick and easy to follow - even for me - reply. Tony Get Outlook for Android ________________________________ From: Alexander Neilson Sent: Tuesday, June 23, 2020 9:28:37 PM To: Tony Kaloki Cc: python-list at python.org Subject: Re: Pycharm Won't Do Long Underscore Hi Tony The ?long underscore? (often called Dunder as ?double underscore?) is actually two underscores as you are seeing shown in PyCharm. However the display of it as one long underscore is a ligature (special font display to communicate clearer) and to enable these in PyCharm go to the settings dialog (depending on windows or Mac this could be in different locations) and select Editor > Font In that screen select ?enable font ligatures? and if your font supports it (like the default JetBrains Mono does) that will start to display the double underscores as a single long underscore. Regards Alexander Alexander Neilson Neilson Productions Limited 021 329 681 alexander at neilson.net.nz > On 24/06/2020, at 07:57, Tony Kaloki wrote: > > ? > > Sent from Mail for Windows 10 > > From: Tony Kaloki > Sent: 23 June 2020 19:45 > To: python-list at python.org > Subject: Pycharm Won't Do Long Underscore > > > Hi Guys, > I?ve just begun to learn basic computer programming by downloading Python and Pycharm and following Youtube tutorials. But I?ve come across a problem that?s stopped me in my tracks. > When I try to do a long underscore __ for classes in Pycharm, it only gives me two separate single underscores _ _. This is only in Pycharm, no problems anywhere else. Could you tell me how to fix this, because I can?t find any answers on the web and I?m not sure if I can go any further in my learning without being able to get long underscores. > Sorry if I?m just being really dense, but like I said I?m an absolute beginner. Thanks for your time, > Tony > Sent from Mail for Windows 10 > > > -- > https://mail.python.org/mailman/listinfo/python-list From inhahe at gmail.com Tue Jun 23 17:10:09 2020 From: inhahe at gmail.com (inhahe) Date: Tue, 23 Jun 2020 17:10:09 -0400 Subject: Asynchronous generators In-Reply-To: References: Message-ID: I know of a URL that explains asyncio: https://hackernoon.com/a-simple-introduction-to-pythons-asyncio-595d9c9ecf8c. As to your specific problem, I can't help and don't know if the URL helps. I haven't studied asyncio much. On Tue, Jun 23, 2020 at 3:53 PM Jonathan Gossage wrote: > -- > I am attempting to learn how to use asyncio and I have been unable to find > any documentation or Internet posts that give information on the principles > underlying asyncio, let alone any examples showing how asynchronous > generators should be used. I have built a toy program to test trying to > read a text file, line by line, and process each line asynchronously. I > wind up with a message complaining that my asynchronous generator is not a > coroutine. I am posting a copy of my program here along with the results > from trying to run it. I am hoping for some suggestions about how to fix > it. I am using Python 3.8.3 on Ubuntu 20.04 > > import asyncio > > from pathlib import Path > > import timeit > > > > async def _read_password() -> str: > > with Path('/etc/passwd').open() as f: > > line: str = f.readline() > > yield line > > print('read_password has read everything') > > > > async def main(_rp) -> int: > > line = '' > > async for line in _rp: > > try: > > print(f'Got line {line}') > > except StopAsyncIteration: > > line = None > > _rp.aclose() > > return 0 > > > > if __name__ == '__main__': > > _loop = asyncio.get_event_loop() > > _rp = _read_password() > > _m = main(_rp) > > _loop.create_task(_m) > > _loop.create_task(_rp) > > timeit.Timer(_loop.run_until_complete()).timeit() > > _loop.close() > > > Here is the output: > > Traceback (most recent call last): > File "/usr/local/lib/python3.8/runpy.py", line 194, in > _run_module_as_main > return _run_code(code, main_globals, None, > File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code > exec(code, run_globals) > File > > "/home/jgossage/EclipseWorkspaces/GlobalVillage/Infrastructure/Play/Async/passwd.py", > line 34, in > _loop.create_task(_rp) > File "/usr/local/lib/python3.8/asyncio/base_events.py", line 431, in > create_task > task = tasks.Task(coro, loop=self, name=name) > TypeError: a coroutine was expected, got _read_password at 0x7f1f2454b8b0> > -- > https://mail.python.org/mailman/listinfo/python-list > From alexander at neilson.net.nz Tue Jun 23 16:28:37 2020 From: alexander at neilson.net.nz (Alexander Neilson) Date: Wed, 24 Jun 2020 08:28:37 +1200 Subject: Pycharm Won't Do Long Underscore In-Reply-To: References: Message-ID: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> Hi Tony The ?long underscore? (often called Dunder as ?double underscore?) is actually two underscores as you are seeing shown in PyCharm. However the display of it as one long underscore is a ligature (special font display to communicate clearer) and to enable these in PyCharm go to the settings dialog (depending on windows or Mac this could be in different locations) and select Editor > Font In that screen select ?enable font ligatures? and if your font supports it (like the default JetBrains Mono does) that will start to display the double underscores as a single long underscore. Regards Alexander Alexander Neilson Neilson Productions Limited 021 329 681 alexander at neilson.net.nz > On 24/06/2020, at 07:57, Tony Kaloki wrote: > > ? > > Sent from Mail for Windows 10 > > From: Tony Kaloki > Sent: 23 June 2020 19:45 > To: python-list at python.org > Subject: Pycharm Won't Do Long Underscore > > > Hi Guys, > I?ve just begun to learn basic computer programming by downloading Python and Pycharm and following Youtube tutorials. But I?ve come across a problem that?s stopped me in my tracks. > When I try to do a long underscore __ for classes in Pycharm, it only gives me two separate single underscores _ _. This is only in Pycharm, no problems anywhere else. Could you tell me how to fix this, because I can?t find any answers on the web and I?m not sure if I can go any further in my learning without being able to get long underscores. > Sorry if I?m just being really dense, but like I said I?m an absolute beginner. Thanks for your time, > Tony > Sent from Mail for Windows 10 > > > -- > https://mail.python.org/mailman/listinfo/python-list From grant.b.edwards at gmail.com Tue Jun 23 17:02:12 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 23 Jun 2020 21:02:12 -0000 (UTC) Subject: Pycharm Won't Do Long Underscore References: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> Message-ID: On 2020-06-23, Tony Kaloki wrote: > in your reply, are you saying that Python would have treated the > two separate underscores the same way as a long underscore No. There is no long underscore in Python. In Python, it's always two underscores. In some fonts, two underscores just _looks_ like a single long underscore. -- Grant From alexander at neilson.net.nz Tue Jun 23 17:12:48 2020 From: alexander at neilson.net.nz (Alexander Neilson) Date: Wed, 24 Jun 2020 09:12:48 +1200 Subject: Pycharm Won't Do Long Underscore In-Reply-To: References: Message-ID: <09C587B6-7A4F-40AB-95D7-6421FB52A6AA@neilson.net.nz> Hi Tony Absolutely. The ?long underscore? is just a display thing. Underneath it is always two underscores. The only difference is what your editor is showing (or how the underscore is drawn in the display font - as some fonts make the underscore the full width or slightly over the edge of where the character will be displayed so that many underscores look all joined up like a line) These links may provide you with some useful reading around this and what underscores signal in Python. https://dbader.org/blog/meaning-of-underscores-in-python https://dbader.org/blog/python-dunder-methods Happy to have helped and good luck with your Python journey. Regards Alexander Alexander Neilson Neilson Productions Limited 021 329 681 alexander at neilson.net.nz > On 24/06/2020, at 08:49, Tony Kaloki wrote: > > ? > 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? > In any case, thanks again for your quick and easy to follow - even for me - reply. > Tony > > Get Outlook for Android > > From: Alexander Neilson > Sent: Tuesday, June 23, 2020 9:28:37 PM > To: Tony Kaloki > Cc: python-list at python.org > Subject: Re: Pycharm Won't Do Long Underscore > > Hi Tony > > The ?long underscore? (often called Dunder as ?double underscore?) is actually two underscores as you are seeing shown in PyCharm. > > However the display of it as one long underscore is a ligature (special font display to communicate clearer) and to enable these in PyCharm go to the settings dialog (depending on windows or Mac this could be in different locations) and select Editor > Font > > In that screen select ?enable font ligatures? and if your font supports it (like the default JetBrains Mono does) that will start to display the double underscores as a single long underscore. > > Regards > Alexander > > Alexander Neilson > Neilson Productions Limited > 021 329 681 > alexander at neilson.net.nz > > > On 24/06/2020, at 07:57, Tony Kaloki wrote: > > > > ? > > > > Sent from Mail for Windows 10 > > > > From: Tony Kaloki > > Sent: 23 June 2020 19:45 > > To: python-list at python.org > > Subject: Pycharm Won't Do Long Underscore > > > > > > Hi Guys, > > I?ve just begun to learn basic computer programming by downloading Python and Pycharm and following Youtube tutorials. But I?ve come across a problem that?s stopped me in my tracks. > > When I try to do a long underscore __ for classes in Pycharm, it only gives me two separate single underscores _ _. This is only in Pycharm, no problems anywhere else. Could you tell me how to fix this, because I can?t find any answers on the web and I?m not sure if I can go any further in my learning without being able to get long underscores. > > Sorry if I?m just being really dense, but like I said I?m an absolute beginner. Thanks for your time, > > Tony > > Sent from Mail for Windows 10 > > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Tue Jun 23 23:34:57 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 23 Jun 2020 23:34:57 -0400 Subject: FW: Pycharm Won't Do Long Underscore In-Reply-To: <1ba5e69e-f916-f96d-a67b-44a3df638228@mrabarnett.plus.com> References: <1ba5e69e-f916-f96d-a67b-44a3df638228@mrabarnett.plus.com> Message-ID: On 6/23/2020 4:44 PM, MRAB wrote: > On 2020-06-23 20:18, Tony Kaloki wrote: >> ????? When I try to do a long underscore __? for classes in Pycharm, >> it only gives me two separate single underscores _ _. > The "__" is 2 underscores; it's just that they usually appear joined > together in many fonts. To really see this, start IDLE either from an icon or 'python -m idlelib' (use 'python3' on *nix) on a command line. Open the settings dialog with Options => Configure IDLE. On the Font tab there is a Font Sample box. Go to the bottom and enter several _____s. In the Windows Courier font, and several others, this looks like one line. On the left, try other fonts. On Windows, switching to Source Code Pro (and some others) results in separate underscores. Source Code Pro, as the name suggests, is aimed at programmers, and we need to be able to count underscores. Or maybe you can switch fonts in your mail reader and see what happens to the underscores above. -- Terry Jan Reedy From auriocus at gmx.de Wed Jun 24 01:15:36 2020 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 24 Jun 2020 07:15:36 +0200 Subject: Pycharm Won't Do Long Underscore In-Reply-To: References: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> Message-ID: 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 From dieter at handshake.de Wed Jun 24 12:21:46 2020 From: dieter at handshake.de (Dieter Maurer) Date: Wed, 24 Jun 2020 18:21:46 +0200 Subject: Asynchronous generators In-Reply-To: References: Message-ID: <24307.32154.854496.910400@ixdm.fritz.box> Jonathan Gossage wrote at 2020-6-23 14:04 -0400: >-- >I am attempting to learn how to use asyncio and I have been unable to find >any documentation or Internet posts that give information on the principles >underlying asyncio ... I am almost sure to have read an asyncio tutorial found via "python.org". From rosuav at gmail.com Wed Jun 24 13:59:00 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 25 Jun 2020 03:59:00 +1000 Subject: Pycharm Won't Do Long Underscore In-Reply-To: References: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> Message-ID: On Thu, Jun 25, 2020 at 3:51 AM Dennis Lee Bieber wrote: > > On Tue, 23 Jun 2020 20:49:36 +0000, Tony Kaloki > declaimed the following: > > >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? > > There is no "long underscore" in the character set. If there were, > Python would not know what to do with it as it was created back when ASCII > and ISO-Latin-1 were the common character sets. (Interesting: Windows > Character Map utility calls the underscore character "low line"). That's what Unicode calls it - charmap is probably using that name. > Many word processors are configured to change sequences of hyphens: > - -- --- into - ? ? (hyphen, en-dash, em-dash)... But in this case, those > are each single characters in the character map (using Windows-Western, > similar to ISO-Latin-1): hyphen is x2D, en-dash is x96, em-dash is x97 > (note that en-/em-dash are >127, hence would not be in pure ASCII) Hyphen is U+002D, en dash is U+2013, em dash is 2014. :) ChrisA From python at mrabarnett.plus.com Wed Jun 24 14:28:52 2020 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 24 Jun 2020 19:28:52 +0100 Subject: Pycharm Won't Do Long Underscore In-Reply-To: References: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> Message-ID: On 2020-06-24 18:59, Chris Angelico wrote: > On Thu, Jun 25, 2020 at 3:51 AM Dennis Lee Bieber wrote: >> >> On Tue, 23 Jun 2020 20:49:36 +0000, Tony Kaloki >> declaimed the following: >> >> >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? >> >> There is no "long underscore" in the character set. If there were, >> Python would not know what to do with it as it was created back when ASCII >> and ISO-Latin-1 were the common character sets. (Interesting: Windows >> Character Map utility calls the underscore character "low line"). > > That's what Unicode calls it - charmap is probably using that name. > >> Many word processors are configured to change sequences of hyphens: >> - -- --- into - ? ? (hyphen, en-dash, em-dash)... But in this case, those >> are each single characters in the character map (using Windows-Western, >> similar to ISO-Latin-1): hyphen is x2D, en-dash is x96, em-dash is x97 >> (note that en-/em-dash are >127, hence would not be in pure ASCII) > > Hyphen is U+002D, en dash is U+2013, em dash is 2014. :) > Not quite. :-) Hyphen is U+2010. U+002D is hyphen-minus; it's does double-duty, for historical reasons. From tkaloki at live.co.uk Wed Jun 24 14:51:46 2020 From: tkaloki at live.co.uk (Tony Kaloki) Date: Wed, 24 Jun 2020 18:51:46 +0000 Subject: Pycharm Won't Do Long Underscore In-Reply-To: References: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> , Message-ID: Thanks for all your explanations, everyone. Hopefully, I'll know better next time I come across a similar case. Now, to try and understand the rest of Python... Get Outlook for Android ________________________________ From: Python-list on behalf of MRAB Sent: Wednesday, June 24, 2020 7:28:52 PM To: python-list at python.org Subject: Re: Pycharm Won't Do Long Underscore On 2020-06-24 18:59, Chris Angelico wrote: > On Thu, Jun 25, 2020 at 3:51 AM Dennis Lee Bieber wrote: >> >> On Tue, 23 Jun 2020 20:49:36 +0000, Tony Kaloki >> declaimed the following: >> >> >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? >> >> There is no "long underscore" in the character set. If there were, >> Python would not know what to do with it as it was created back when ASCII >> and ISO-Latin-1 were the common character sets. (Interesting: Windows >> Character Map utility calls the underscore character "low line"). > > That's what Unicode calls it - charmap is probably using that name. > >> Many word processors are configured to change sequences of hyphens: >> - -- --- into - ? ? (hyphen, en-dash, em-dash)... But in this case, those >> are each single characters in the character map (using Windows-Western, >> similar to ISO-Latin-1): hyphen is x2D, en-dash is x96, em-dash is x97 >> (note that en-/em-dash are >127, hence would not be in pure ASCII) > > Hyphen is U+002D, en dash is U+2013, em dash is 2014. :) > Not quite. :-) Hyphen is U+2010. U+002D is hyphen-minus; it's does double-duty, for historical reasons. -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Jun 24 14:55:26 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 25 Jun 2020 04:55:26 +1000 Subject: Pycharm Won't Do Long Underscore In-Reply-To: References: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> Message-ID: On Thu, Jun 25, 2020 at 4:40 AM MRAB wrote: > > On 2020-06-24 18:59, Chris Angelico wrote: > > On Thu, Jun 25, 2020 at 3:51 AM Dennis Lee Bieber wrote: > >> > >> On Tue, 23 Jun 2020 20:49:36 +0000, Tony Kaloki > >> declaimed the following: > >> > >> >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? > >> > >> There is no "long underscore" in the character set. If there were, > >> Python would not know what to do with it as it was created back when ASCII > >> and ISO-Latin-1 were the common character sets. (Interesting: Windows > >> Character Map utility calls the underscore character "low line"). > > > > That's what Unicode calls it - charmap is probably using that name. > > > >> Many word processors are configured to change sequences of hyphens: > >> - -- --- into - ? ? (hyphen, en-dash, em-dash)... But in this case, those > >> are each single characters in the character map (using Windows-Western, > >> similar to ISO-Latin-1): hyphen is x2D, en-dash is x96, em-dash is x97 > >> (note that en-/em-dash are >127, hence would not be in pure ASCII) > > > > Hyphen is U+002D, en dash is U+2013, em dash is 2014. :) > > > Not quite. :-) > > Hyphen is U+2010. > > U+002D is hyphen-minus; it's does double-duty, for historical reasons. True true, I should have corrected that name. But the point is, "Windows-Western" is not a good way to describe characters (I think that probably means "code page 1252"?). Use the Unicode codepoints for reliability :) ChrisA From hjp-python at hjp.at Wed Jun 24 17:10:16 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 24 Jun 2020 23:10:16 +0200 Subject: Pycharm Won't Do Long Underscore In-Reply-To: References: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> Message-ID: <20200624211016.GB24048@hjp.at> On 2020-06-24 13:48:18 -0400, Dennis Lee Bieber wrote: > On Tue, 23 Jun 2020 20:49:36 +0000, Tony Kaloki > declaimed the following: > > 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? > > There is no "long underscore" in the character set. There is U+FF3F Fullwidth Low Line. > If there were, Python would not know what to do with it You can use it in variable names, but not at the beginning, and it isn't equivalent to two underscores, of course: Python 3.9.0b3 (default, Jun 13 2020, 10:49:29) [GCC 7.5.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ? = 12 File "", line 1 ? = 12 ^ SyntaxError: invalid character '?' (U+FF3F) >>> a? = 12 >>> a? 12 >>> a__ Traceback (most recent call last): File "", line 1, in NameError: name 'a__' is not defined >>> hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From pfeiffer at cs.nmsu.edu Wed Jun 24 17:33:16 2020 From: pfeiffer at cs.nmsu.edu (Joe Pfeiffer) Date: Wed, 24 Jun 2020 15:33:16 -0600 Subject: FW: Pycharm Won't Do Long Underscore References: <1ba5e69e-f916-f96d-a67b-44a3df638228@mrabarnett.plus.com> Message-ID: <1ba70sdu8z.fsf@pfeifferfamily.net> One other note -- while you may want various good-looking fonts with ligatures in other domains, for writing code a monospace font with no ligatures lets you see exactly what's there and saves a host of problems. My personal favorite for these purposes is called "Terminus Regular", but which specific one you pick is much less important than that you use one. From zljubisic at gmail.com Wed Jun 24 17:46:35 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 24 Jun 2020 14:46:35 -0700 (PDT) Subject: Pycharm offers only implementation of an abstract getter but not an abstract setter Message-ID: <5a05d878-3a67-4d79-a23e-fbab8de304b6o@googlegroups.com> I would like to have an abstract class in which I will have an abstract property. So I used Pycharm in order to create an abstract (base) class: import abc class BaseSomeAbstract(abc.ABC): _abs_prop = None @property @abc.abstractmethod def abs_prop(self): return self._abs_prop @abs_prop.setter @abc.abstractmethod def abs_prop(self, value): self._abs_prop = value Now I have created a new file and a new class: from subclassing.abstract.BaseSomeAbstract import BaseSomeAbstract class ChildSomeAbstract(BaseSomeAbstract): Now I pressed alt+enter, implement abstract methods. I got only a single choice abs_prop(self: BaseSomeAbstract). If I choose this option, my subclass looks like this: from subclassing.abstract.BaseSomeAbstract import BaseSomeAbstract class ChildSomeAbstract(BaseSomeAbstract): @property def abs_prop(self): pass Why Pycharm didn't offer a setter as well as getter? What is the propper way to define an abstract property, and how to force subclass to define setter and getter for the abstract property? From zljubisic at gmail.com Wed Jun 24 18:13:07 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 24 Jun 2020 15:13:07 -0700 (PDT) Subject: Pycharm offers only implementation of an abstract getter but not an abstract setter In-Reply-To: <5a05d878-3a67-4d79-a23e-fbab8de304b6o@googlegroups.com> References: <5a05d878-3a67-4d79-a23e-fbab8de304b6o@googlegroups.com> Message-ID: <0d94833f-7d1e-458b-8e7d-5b93d91f40f7o@googlegroups.com> If my subclass is as this: from subclassing.abstract.BaseSomeAbstract import BaseSomeAbstract class ChildSomeAbstract(BaseSomeAbstract): @property def abs_prop(self): return self._abs_prop I can create an instance of it with no errors. So x = ChildSomeAbstract() works with no problem. It looks like setter @abstractmethod decorator is not respected. From o1bigtenor at gmail.com Wed Jun 24 18:27:08 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Wed, 24 Jun 2020 17:27:08 -0500 Subject: Pycharm Won't Do Long Underscore In-Reply-To: References: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> Message-ID: On Wed, Jun 24, 2020 at 1:54 PM Tony Kaloki wrote: > > Thanks for all your explanations, everyone. Hopefully, I'll know better next time I come across a similar case. Now, to try and understand the rest of Python... > Your last sentence - - - - I'm right there with you! (Reading it made me chuckle!) I've been a tool maker in so many areas and never really wanted to fall into the rabbit hole called computer programming (wry grin!). Here I am working on Python, R, SQL and that's just for starters! Oh well - - - helps keep life interesting!! Regards From grant.b.edwards at gmail.com Wed Jun 24 21:38:00 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 25 Jun 2020 01:38:00 -0000 (UTC) Subject: Pycharm Won't Do Long Underscore References: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> <20200624211016.GB24048@hjp.at> Message-ID: On 2020-06-24, Peter J. Holzer wrote: > There is U+FF3F Fullwidth Low Line. > >> If there were, Python would not know what to do with it > > You can use it in variable names, but not at the beginning, and it isn't > equivalent to two underscores, of course: Ouch. Anybody caught using that should be fed to a large snake. -- Grant From zljubisic at gmail.com Thu Jun 25 02:02:31 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 24 Jun 2020 23:02:31 -0700 (PDT) Subject: Pycharm offers only implementation of an abstract getter but not an abstract setter In-Reply-To: <0d94833f-7d1e-458b-8e7d-5b93d91f40f7o@googlegroups.com> References: <5a05d878-3a67-4d79-a23e-fbab8de304b6o@googlegroups.com> <0d94833f-7d1e-458b-8e7d-5b93d91f40f7o@googlegroups.com> Message-ID: This also works with no errors: from abc import ABC, abstractmethod class C(ABC): @property @abstractmethod def my_abstract_property(self): pass @my_abstract_property.setter @abstractmethod def my_abstract_property(self, val): pass class D(C): my_abstract_property = 1 if __name__ == '__main__': x = D() print(x.my_abstract_property) x.my_abstract_property = 5 print(x.my_abstract_property) Output: 1 5 I expected to get an error that setter is not implemented. If I try to instante C class directly as: x = C(), I will get an error: TypeError: Can't instantiate abstract class C with abstract methods my_abstract_property Can someone please explain to me how it works i python? From Bischoop at vimuster.net Thu Jun 25 07:50:36 2020 From: Bischoop at vimuster.net (Bischoop) Date: Thu, 25 Jun 2020 11:50:36 -0000 (UTC) Subject: [Beginner] Spliting input Message-ID: I try to split input numbers, for example: 12 so I cant add them, I tried separated split(' ') but it's not working. Any ideas how to do this? * numb1,numb2=input("enter 1st and 2nd no ").split() Avg=(int(numb1) + int(numb2)) / 2 print(Avg) * -- Thanks From andrew.bell.ia at gmail.com Thu Jun 25 08:06:58 2020 From: andrew.bell.ia at gmail.com (Andrew Bell) Date: Thu, 25 Jun 2020 08:06:58 -0400 Subject: [Beginner] Spliting input In-Reply-To: References: Message-ID: Without knowing the problem you're having, it's hard to answer. This seems generally correct. On Thu, Jun 25, 2020 at 7:57 AM Bischoop wrote: > I try to split input numbers, for example: 12 so I cant add them, I > tried separated split(' ') but it's not working. > Any ideas how to do this? > > * > numb1,numb2=input("enter 1st and 2nd no ").split() > Avg=(int(numb1) + int(numb2)) / 2 > print(Avg) > -- Andrew Bell andrew.bell.ia at gmail.com From Bischoop at vimuster.net Thu Jun 25 08:13:46 2020 From: Bischoop at vimuster.net (Bischoop) Date: Thu, 25 Jun 2020 12:13:46 -0000 (UTC) Subject: [Beginner] Spliting input References: Message-ID: On 2020-06-25, Andrew Bell wrote: > Without knowing the problem you're having, it's hard to answer. > This seems generally correct. > > Error track: Traceback (most recent call last): File "splitting.py", line 1, in numb1,numb2=input("enter 1st and 2nd no ").split() ValueError: not enough values to unpack (expected 2, got 1) From frank at chagford.com Thu Jun 25 08:28:06 2020 From: frank at chagford.com (Frank Millman) Date: Thu, 25 Jun 2020 14:28:06 +0200 Subject: [Beginner] Spliting input In-Reply-To: References: Message-ID: On 2020-06-25 2:13 PM, Bischoop wrote: > On 2020-06-25, Andrew Bell wrote: >> Without knowing the problem you're having, it's hard to answer. >> This seems generally correct. >> >> > Error track: > Traceback (most recent call last): > File "splitting.py", line 1, in > numb1,numb2=input("enter 1st and 2nd no ").split() > ValueError: not enough values to unpack (expected 2, got 1) > Without arguments, split() splits on whitespace. If you entered 2 numbers separated by a comma, but no spaces, there is no split. Maybe you meant split(',') which will split on a comma. Frank Millman From frank at chagford.com Thu Jun 25 08:28:06 2020 From: frank at chagford.com (Frank Millman) Date: Thu, 25 Jun 2020 14:28:06 +0200 Subject: [Beginner] Spliting input In-Reply-To: References: Message-ID: On 2020-06-25 2:13 PM, Bischoop wrote: > On 2020-06-25, Andrew Bell wrote: >> Without knowing the problem you're having, it's hard to answer. >> This seems generally correct. >> >> > Error track: > Traceback (most recent call last): > File "splitting.py", line 1, in > numb1,numb2=input("enter 1st and 2nd no ").split() > ValueError: not enough values to unpack (expected 2, got 1) > Without arguments, split() splits on whitespace. If you entered 2 numbers separated by a comma, but no spaces, there is no split. Maybe you meant split(',') which will split on a comma. Frank Millman From __peter__ at web.de Thu Jun 25 08:48:03 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 25 Jun 2020 14:48:03 +0200 Subject: [Beginner] Spliting input References: Message-ID: Bischoop wrote: > I try to split input numbers, for example: 12 so I cant add them, I > tried separated split(' ') but it's not working. > Any ideas how to do this? > > * > numb1,numb2=input("enter 1st and 2nd no ").split() > Avg=(int(numb1) + int(numb2)) / 2 > print(Avg) > * > > -- > Thanks To split the string "12" into its characters (i. e. the digits "1" and "2") you don't need the split() method which only works with separators. Instead you can unpack the digits directly: >>> a, b = input("enter two digits> ") enter two digits> 12 >>> a '1' >>> b '2' >>> (int(a) + int(b)) / 2 1.5 From rhodri at kynesim.co.uk Thu Jun 25 09:27:06 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 25 Jun 2020 14:27:06 +0100 Subject: Pycharm offers only implementation of an abstract getter but not an abstract setter In-Reply-To: <5a05d878-3a67-4d79-a23e-fbab8de304b6o@googlegroups.com> References: <5a05d878-3a67-4d79-a23e-fbab8de304b6o@googlegroups.com> Message-ID: On 24/06/2020 22:46, zljubisic at gmail.com wrote: > Why Pycharm didn't offer a setter as well as getter? This is a general Python mailing list. If you have specific questions/complaints about PyCharm, they are probably better addressed directly to the makers of PyCharm. -- Rhodri James *-* Kynesim Ltd From zljubisic at gmail.com Thu Jun 25 10:18:11 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Thu, 25 Jun 2020 07:18:11 -0700 (PDT) Subject: Pycharm offers only implementation of an abstract getter but not an abstract setter In-Reply-To: References: <5a05d878-3a67-4d79-a23e-fbab8de304b6o@googlegroups.com> Message-ID: <977e5805-499d-4d37-8480-b234f0fd2532o@googlegroups.com> You can freely leave Pycharm out of equation. In that case, there is a question how to force subclass to implement setter method? From torriem at gmail.com Thu Jun 25 13:56:47 2020 From: torriem at gmail.com (Michael Torrie) Date: Thu, 25 Jun 2020 11:56:47 -0600 Subject: Pycharm Won't Do Long Underscore In-Reply-To: References: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> <20200624211016.GB24048@hjp.at> Message-ID: <57bcc6ac-7446-6da8-bd1b-ca0002951265@gmail.com> On 6/24/20 7:38 PM, Grant Edwards wrote: > On 2020-06-24, Peter J. Holzer wrote: > >> There is U+FF3F Fullwidth Low Line. >> >>> If there were, Python would not know what to do with it >> >> You can use it in variable names, but not at the beginning, and it isn't >> equivalent to two underscores, of course: > > Ouch. Anybody caught using that should be fed to a large snake. Even allowing unicode letters in variable names period is questionable, but that loud debate was over years ago. Fortunately I have never seen any python code in the wild with non-latin characters for variable names. Would make editing code very painful for developers from different locales and keyboards. Even if it might seem novel at first to have ? be a variable name. From aeros167 at gmail.com Thu Jun 25 01:35:56 2020 From: aeros167 at gmail.com (Kyle Stanley) Date: Thu, 25 Jun 2020 01:35:56 -0400 Subject: [Python-ideas] asyncio: return from multiple coroutines In-Reply-To: References: Message-ID: (Resending this email since it didn't originally go through to python-list, sorry for the duplicate Pablo) > Yes, I want to have multiple results: the connections listening forever, returning a result for each message received. > I forgot to mention thatI did try to use asyncio.wait with `FIRST_COMPLETED`; however, the problem is that it seems to evict the not-completed coroutines, so the messenger that arrives second does not send the message. To check it, I have run that script without the random sleep. just msgr1 waits 1s and msgr2 waits 2s, so msgr1 always ends first. I expect a result like this (which I am currently getting with queues): FYI, the other coroutines are not evicted or cancelled, they are simply in the "pending" set of the "done, pending" tuple returned by `asyncio.wait()` and were not returned. I misunderstood what you were actually looking for, but I think that I understand now. Since it seems like you want to be able to receive the results out of order from both "messengers" and have them continuously listen to their respective socket (without affecting the other), a queue is likely going to be the best approach. I think you had the right general idea with your example, but here's a way to make it significantly less cumbersome and easy to expand upon (such as expanding the number of websockets to listen to): ``` import asyncio class MessengerQueue: def __init__(self): self._queue = asyncio.Queue() async def get(self): return await self._queue.get() async def start_messengers(self): # Could be easily modified to create any number of "messengers" set to # listen on specific websockets, by passing a list and creating a task for # each one. asyncio.create_task(self._messenger("Messenger 1", 1)) asyncio.create_task(self._messender("Messenger 2", 2)) async def _messenger(self, message: str, sleep_time: int): while True: await asyncio.sleep(sleep_time) await self._queue.put(f'{message} awaited for {sleep_time:.2f}s') async def main(): mqueue = MessengerQueue() asyncio.create_task(mqueue.start_messengers()) while True: result = await mqueue.get() print(result) asyncio.run(main()) ``` This results in your desired output: Messenger 1 awaited for 1.00s Messenger 2 awaited for 2.00s Messenger 1 awaited for 1.00s Messenger 1 awaited for 1.00s Messenger 2 awaited for 2.00s Messenger 1 awaited for 1.00s Messenger 1 awaited for 1.00s Messenger 2 awaited for 2.00s Note: it would probably be more idiomatic to call these "consumers" or "listeners" rather than "messengers"/"messagers" (the websocket docs refer to them as "consumer handlers"), but I used "messengers" to make it a bit more easily comparable to the original queue example from the OP: https://pastebin.com/BzaxRbtF. I hope the above example is of some use. :-) Regards, Kyle Stanley On Thu, Jun 25, 2020 at 1:28 AM Kyle Stanley wrote: > > > Yes, I want to have multiple results: the connections listening forever, returning a result for each message received. > > > I forgot to mention thatI did try to use asyncio.wait with `FIRST_COMPLETED`; however, the problem is that it seems to evict the not-completed coroutines, so the messenger that arrives second does not send the message. To check it, I have run that script without the random sleep. just msgr1 waits 1s and msgr2 waits 2s, so msgr1 always ends first. I expect a result like this (which I am currently getting with queues): > > FYI, the other coroutines are not evicted or cancelled, they are > simply in the "pending" set of the "done, pending" tuple returned by > `asyncio.wait()` and were not returned. I misunderstood what you were > actually looking for, but I think that I understand now. > > Since it seems like you want to be able to receive the results out of > order from both "messengers" and have them continuously listen to > their respective socket (without affecting the other), a queue is > likely going to be the best approach. I think you had the right > general idea with your example, but here's a way to make it > significantly less cumbersome and easy to expand upon (such as > expanding the number of websockets to listen to): > > ``` > import asyncio > > class MessengerQueue: > def __init__(self): > self._queue = asyncio.Queue() > > async def get(self): > return await self._queue.get() > > async def start_messengers(self): > # Could be easily modified to create any number of > "messengers" set to > # listen on specific websockets, by passing a list and > creating a task for > # each one. > asyncio.create_task(self._messenger("Messenger 1", 1)) > asyncio.create_task(self._messender("Messenger 2", 2)) > > async def _messenger(self, message: str, sleep_time: int): > while True: > await asyncio.sleep(sleep_time) > await self._queue.put(f'{message} awaited for {sleep_time:.2f}s') > > > async def main(): > mqueue = MessengerQueue() > asyncio.create_task(mqueue.start_messengers()) > while True: > result = await mqueue.get() > print(result) > > asyncio.run(main()) > ``` > > This results in your desired output: > Messenger 1 awaited for 1.00s > Messenger 2 awaited for 2.00s > Messenger 1 awaited for 1.00s > Messenger 1 awaited for 1.00s > Messenger 2 awaited for 2.00s > Messenger 1 awaited for 1.00s > Messenger 1 awaited for 1.00s > Messenger 2 awaited for 2.00s > > Note: it would probably be more idiomatic to call these "consumers" or > "listeners" rather than "messengers"/"messagers" (the websocket docs > refer to them as "consumer handlers"), but I used "messengers" to make > it a bit more easily comparable to the original queue example from the > OP: https://pastebin.com/BzaxRbtF. > > I hope the above example is of some use. :-) > > Regards, > Kyle Stanley > > > > > On Tue, Jun 23, 2020 at 10:36 AM Pablo Alcain wrote: > > > > Thank you very much Kyle for your answer, I am moving this conversation to the more proper python-list for whoever wants to chime in. I summarize here the key points of my original question (full question on the quoted email): > > > > I have an application that listens on two websockets through the async library https://websockets.readthedocs.io/ and I have to perform the same function on the result, no matter where the message came from. I have implemented a rather cumbersome solution with async Queues: https://pastebin.com/BzaxRbtF, but i think there has to be a more async-friendly option I am missing. > > > > Now I move on to the comments that Kyle made > > > > On Tue, Jun 23, 2020 at 12:32 AM Kyle Stanley wrote: > >> > >> I believe asyncio.wait() with "return_when=FIRST_COMPLETED" would > >> perform the functionality you're looking for with the > >> "asyncio.on_first_return()". For details on the functionality of > >> asyncio.wait(), see > >> https://docs.python.org/3/library/asyncio-task.html#asyncio.wait. > >> > >> > I understand that I can create two coroutines that call the same function, but it would be much cleaner (because of implementation issues) if I can simply create a coroutine that yields the result of whichever connection arrives first. > >> > >> You can use an asynchronous generator that will continuously yield the > >> result of the first recv() that finishes (I'm assuming you mean > >> "yields" literally and want multiple results from a generator, but I > >> might be misinterpreting that part). > > > > > > Yes, I want to have multiple results: the connections listening forever, returning a result for each message received. > > > >> > >> > >> Here's a brief example, using the recv() coroutine function from the > >> pastebin linked: > >> > >> ``` > >> import asyncio > >> import random > >> > >> async def recv(message: str, max_sleep: int): > >> sleep_time = max_sleep * random.random() > >> await asyncio.sleep(sleep_time) > >> return f'{message} awaited for {sleep_time:.2f}s' > >> > >> async def _start(): > >> while True: > >> msgs = [ > >> asyncio.create_task(recv("Messager 1", max_sleep=1)), > >> asyncio.create_task(recv("Messager 2", max_sleep=1)) > >> ] > >> done, _ = await asyncio.wait(msgs, > >> return_when=asyncio.FIRST_COMPLETED) > >> result = done.pop() > >> yield await result > >> > >> async def main(): > >> async for result in _start(): > >> print(result) > >> > >> asyncio.run(main()) > >> ``` > > > > > > I forgot to mention thatI did try to use asyncio.wait with `FIRST_COMPLETED`; however, the problem is that it seems to evict the not-completed coroutines, so the messenger that arrives second does not send the message. To check it, I have run that script without the random sleep. just msgr1 waits 1s and msgr2 waits 2s, so msgr1 always ends first. I expect a result like this (which I am currently getting with queues): > > > > Messenger 1 waits for 1.0s > > Messenger 1 waits for 1.0s > > Messenger 2 waits for 2.0s > > Messenger 1 waits for 1.0s > > Messenger 1 waits for 1.0s > > Messenger 2 waits for 2.0s > > Messenger 1 waits for 1.0s > > ... > > > > but instead I got this: > > > > Messenger 1 waits for 1.0s > > Messenger 1 waits for 1.0s > > Messenger 1 waits for 1.0s > > Messenger 1 waits for 1.0s > > Messenger 1 waits for 1.0s > > ... > > > > > >> > >> > >> > >> Note that in the above example, in "msgs", you can technically pass > >> the coroutine objects directly to asyncio.wait(), as they will be > >> implicitly converted to tasks. However, we decided to deprecate that > >> functionality in Python 3.8 since it can be rather confusing. So > >> creating and passing the tasks is a better practice. > > > > > > Thanks for that info, I am still trying to grasp the best practices surrounding mostly the explicitness in async. > > > >> > >> > Again, it's quite likely I am not seeing something obvious, but I didn't know where else to ask. > >> > >> If you're not mostly certain or relatively inexperienced with the > >> specific area that the question pertains to, I'd recommend asking on > >> python-list first (or another Python user community). python-ideas is > >> primarily intended for new feature proposals/suggestions. Although if > >> you've tried other resources and haven't found an answer, it's > >> perfectly fine to ask a question as part of the suggestion post. > >> > >> > > > > Original question, as posted in python-ideas: > > > >> > >> On Mon, Jun 22, 2020 at 6:24 PM Pablo Alcain wrote: > >> > > >> > Hey everyone. I have been looking into asyncio lately, and even though I have had my fair share of work, I still have some of it very shaky, so first of all forgive me if what I am saying here is already implemented and I totally missed it (so far, it looks *really* likely). > >> > > >> > Basically this is the situation: I have an application that listens on two websockets through the async library https://websockets.readthedocs.io/ and I have to perform the same function on the result, no matter where the message came from. I understand that I can create two coroutines that call the same function, but it would be much cleaner (because of implementation issues) if I can simply create a coroutine that yields the result of whichever connection arrives first. > >> > > >> > I have implemented a rather cumbersome solution with async Queues (as I would do in threading), in which each connection puts its message in a queue and an adapter class awaits the first element of the queue on "receive". Here I attach a pastebin with the minimal working example: https://pastebin.com/BzaxRbtF > >> > > >> > However, it looks like a more async-friendly solution should exist, something like > >> > > >> > ``` > >> > async def _start(): > >> > msg1 = recv("Messager 1", sleep_time=1) > >> > msg2 = recv("Messager 2", sleep_time=2) > >> > while True: > >> > result = await asyncio.on_first_return(msg1, msg2) > >> > print(result) > >> > ``` > >> > > >> > (I understand that this implementation would not work because the event loop doesn't know that it is "the same task repeated", but it's just to tell you the general idea) > >> > > >> > Again, it's quite likely I am not seeing something obvious, but I didn't know where else to ask. > >> > > >> > Thank you very much, > >> > Pablo > >> > > >> > _______________________________________________ > >> > Python-ideas mailing list -- python-ideas at python.org > >> > To unsubscribe send an email to python-ideas-leave at python.org > >> > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > >> > Message archived at https://mail.python.org/archives/list/python-ideas at python.org/message/XBR5QPXRBCCJELDVEWMKRBPTNG4SJM64/ > >> > Code of Conduct: http://python.org/psf/codeofconduct/ From a.h.jaffe at gmail.com Thu Jun 25 08:56:11 2020 From: a.h.jaffe at gmail.com (Andrew Jaffe) Date: Thu, 25 Jun 2020 13:56:11 +0100 Subject: [Beginner] Spliting input In-Reply-To: References: Message-ID: <4bd504b0-e71e-a080-19a5-def24babdd9d@gmail.com> Hi, On 25/06/2020 12:50, Bischoop wrote: > I try to split input numbers, for example: 12 so I cant add them, I > tried separated split(' ') but it's not working. > Any ideas how to do this? > > * > numb1,numb2=input("enter 1st and 2nd no ").split() > Avg=(int(numb1) + int(numb2)) / 2 > print(Avg) So, this is an opportunity to do (and learn) some debugging! One problem is that the first line does two things at once -- it reads the input and tries to split it into numb1 and numb2. Similarly for the "average" line. You could instead try: input_string = input("enter 1st and 2nd no ") print(input_string) numb1_as_string, numb2_as_string = input_string.split() print(numb1_as_string, numb2_as_string) numb1 = int(numb1) numb2 = int(numb2) print(numb1, numb2) avg = (numb1 + numb2) / 2 print(avg) Now, when if fails on input_string.split() (which I think is what happens) you can then be sure that you know what the input is. Let's say it's "17,3". Since you know that, you can experiment: "17, 3".split() -> "17,", "3" (note extra space) "17 3".split() -> "17" "3" (aha, getting somewhere) ... and same results for both of these with split(' '), which should indicate that it's splitting on the space, and you didn't supply a space. So now maybe try "17,3".split(',') -> "17", "3" (bingo!) Bonus question: what happens with "17, 3".split(',')? > * > > -- > Thanks > From sinanpv22 at gmail.com Thu Jun 25 19:02:40 2020 From: sinanpv22 at gmail.com (sinanpv22 at gmail.com) Date: Thu, 25 Jun 2020 16:02:40 -0700 (PDT) Subject: I need to study Python Message-ID: Hey, I'm a completely noob. I want to learn python, how can i or where can i study python? From ikorot01 at gmail.com Thu Jun 25 20:16:53 2020 From: ikorot01 at gmail.com (Igor Korot) Date: Thu, 25 Jun 2020 19:16:53 -0500 Subject: I need to study Python In-Reply-To: References: Message-ID: Hi, Just sign-up for a local community college. Will be easier and u will keep motivation... Thank you. On Thu, Jun 25, 2020, 6:49 PM wrote: > Hey, I'm a completely noob. > I want to learn python, how can i or where can i study python? > -- > https://mail.python.org/mailman/listinfo/python-list > From manisettu99s at gmail.com Fri Jun 26 02:08:51 2020 From: manisettu99s at gmail.com (Manikandan S) Date: Fri, 26 Jun 2020 11:38:51 +0530 Subject: Regarding error code 9 Message-ID: Sir/Mam; While installing matplotlib in python i face this issue that it shows error : erro no 9 please reply with some solution for this error i am beginner so please explain in detail about this error and guide me to fix this error. Thank you From ast at invalid Fri Jun 26 03:02:12 2020 From: ast at invalid (ast) Date: Fri, 26 Jun 2020 09:02:12 +0200 Subject: property Message-ID: <5ef59d74$0$9530$426a74cc@news.free.fr> Hello, I am wondering why this code is OK: class Temperature: def __init__(self): self.celsius = 0 fahrenheit = property() @fahrenheit.getter def fahrenheit(self): return 9/5*self.celsius +32 @fahrenheit.setter def fahrenheit(self, value): self.celsius = (value-32)*5/9 and this one is not: class Temperature: def __init__(self): self.celsius = 0 fahrenheit = property() @fahrenheit.getter def f(self): return 9/5*self.celsius +32 @fahrenheit.setter def f(self, value): self.celsius = (value-32)*5/9 In the second code, I just changed the names of the decorated functions Unforunately I was not able to find "property" source code to understand how it works exactly I wrote a my_property which makes the two previous codes to work fine. This is why I don't understand why the genuine property does't work when decorated functions are named f rather than fahrenheit Here it is: class my_property: def __init__(self, fget=None, fset=None, fdel=None): self.fget = fget self.fset = fset self.fdel = fdel def __get__(self, instance, owner): if instance is None: return self return self.fget(instance) def __set__(self, instance, value): self.fset(instance, value) def __delete__(self, instance): self.fdel(instance) def getter(self, fget): self.fget = fget return self def setter(self, fset): self.fset = fset return self def deleter(self, fdel): self.fdel = fdel return self From ikorot01 at gmail.com Fri Jun 26 08:42:26 2020 From: ikorot01 at gmail.com (Igor Korot) Date: Fri, 26 Jun 2020 07:42:26 -0500 Subject: Regarding error code 9 In-Reply-To: References: Message-ID: Hi, On Fri, Jun 26, 2020, 1:17 AM Manikandan S wrote: > Sir/Mam; > While installing matplotlib in python i face this issue that it shows > error : erro no 9 please reply with some solution for this error i am > beginner so please explain in detail about this error and guide me to fix > this error. > What OS? What python version? Are you using pip to install? Thank you. > Thank you > -- > https://mail.python.org/mailman/listinfo/python-list > From barry at barrys-emacs.org Fri Jun 26 08:56:25 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Fri, 26 Jun 2020 13:56:25 +0100 Subject: property In-Reply-To: <5ef59d74$0$9530$426a74cc@news.free.fr> References: <5ef59d74$0$9530$426a74cc@news.free.fr> Message-ID: <7C8DA9DB-5DB7-4D8A-AB37-A7748EFD95CC@barrys-emacs.org> > On 26 Jun 2020, at 08:02, ast wrote: > > Hello, > > I am wondering why this code is OK: > > class Temperature: > def __init__(self): > self.celsius = 0 > > fahrenheit = property() > > @fahrenheit.getter > def fahrenheit(self): > return 9/5*self.celsius +32 > > @fahrenheit.setter > def fahrenheit(self, value): > self.celsius = (value-32)*5/9 > > > and this one is not: > > > class Temperature: > def __init__(self): > self.celsius = 0 > > fahrenheit = property() > > @fahrenheit.getter > def f(self): > return 9/5*self.celsius +32 > > @fahrenheit.setter > def f(self, value): > self.celsius = (value-32)*5/9 > > In the second code, I just changed the names of the > decorated functions It seems you have to change all the fahenheit to f for this to work. You left 3. > > Unforunately I was not able to find "property" source > code to understand how it works exactly I see these docs: https://docs.python.org/3/library/functions.html?highlight=property#property which do not show your usage. The code is here: https://github.com/python/cpython/blob/master/Objects/descrobject.c It defines the PyProperty_Type that is the builtin property class. Barry > > I wrote a my_property which makes the two previous codes > to work fine. This is why I don't understand why the > genuine property does't work when decorated functions > are named f rather than fahrenheit > > Here it is: > > class my_property: > > def __init__(self, fget=None, fset=None, fdel=None): > self.fget = fget > self.fset = fset > self.fdel = fdel > > def __get__(self, instance, owner): > if instance is None: > return self > return self.fget(instance) > > def __set__(self, instance, value): > self.fset(instance, value) > > def __delete__(self, instance): > self.fdel(instance) > > def getter(self, fget): > self.fget = fget > return self > > def setter(self, fset): > self.fset = fset > return self > > def deleter(self, fdel): > self.fdel = fdel > return self > -- > https://mail.python.org/mailman/listinfo/python-list From joel.goldstick at gmail.com Fri Jun 26 09:00:23 2020 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 26 Jun 2020 09:00:23 -0400 Subject: I need to study Python In-Reply-To: References: Message-ID: On Thu, Jun 25, 2020 at 8:18 PM Igor Korot wrote: > > Hi, > Just sign-up for a local community college. > Will be easier and u will keep motivation... > > Thank you. > > > On Thu, Jun 25, 2020, 6:49 PM wrote: > > > Hey, I'm a completely noob. > > I want to learn python, how can i or where can i study python? > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list start with python.org -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From jpic at yourlabs.org Fri Jun 26 09:07:18 2020 From: jpic at yourlabs.org (J. Pic) Date: Fri, 26 Jun 2020 15:07:18 +0200 Subject: I need to study Python In-Reply-To: References: Message-ID: What happens when people want to start a music instrument and start with pure theory, scales and modes, it's that the instrument ends up in a forgotten corner of the room because they are not having real fun with it. I would like to suggest that you start with a pet project, you can even start with a website for example in which case start with Django official tutorial for example. Have fun ! From __peter__ at web.de Fri Jun 26 09:12:50 2020 From: __peter__ at web.de (Peter Otten) Date: Fri, 26 Jun 2020 15:12:50 +0200 Subject: property References: <5ef59d74$0$9530$426a74cc@news.free.fr> Message-ID: Unknown wrote: > Hello, > > I am wondering why this code is OK: > > class Temperature: > def __init__(self): > self.celsius = 0 > > fahrenheit = property() > > @fahrenheit.getter > def fahrenheit(self): > return 9/5*self.celsius +32 > > @fahrenheit.setter > def fahrenheit(self, value): > self.celsius = (value-32)*5/9 > > > and this one is not: > > > class Temperature: > def __init__(self): > self.celsius = 0 > > fahrenheit = property() > > @fahrenheit.getter > def f(self): > return 9/5*self.celsius +32 > > @fahrenheit.setter > def f(self, value): > self.celsius = (value-32)*5/9 > > In the second code, I just changed the names of the > decorated functions > @fahrenheit.getter > def f(self): is syntactic sugar for def f(self): ... f = fahrenheit.getter(f) > Unforunately I was not able to find "property" source > code to understand how it works exactly The getter/setter of the property builtin return a new property >>> p = property() >>> q = p.getter(None) >>> p is q False where you > def getter(self, fget): > self.fget = fget > return self modify the existing one. > I wrote a my_property which makes the two previous codes > to work fine. This is why I don't understand why the > genuine property does't work when decorated functions > are named f rather than fahrenheit > > Here it is: > > class my_property: > > def __init__(self, fget=None, fset=None, fdel=None): > self.fget = fget > self.fset = fset > self.fdel = fdel > > def __get__(self, instance, owner): > if instance is None: > return self > return self.fget(instance) > > def __set__(self, instance, value): > self.fset(instance, value) > > def __delete__(self, instance): > self.fdel(instance) > > def getter(self, fget): > self.fget = fget > return self > > def setter(self, fset): > self.fset = fset > return self > > def deleter(self, fdel): > self.fdel = fdel > return self From wesley at freenetMail.de Fri Jun 26 03:05:04 2020 From: wesley at freenetMail.de (Wesley Peng) Date: Fri, 26 Jun 2020 15:05:04 +0800 Subject: I need to study Python In-Reply-To: References: Message-ID: Pick a book like Core Python Programming, read it and do coding follow it. regards. sinanpv22 at gmail.com wrote: > Hey, I'm a completely noob. > I want to learn python, how can i or where can i study python? > From dieter at handshake.de Fri Jun 26 13:57:58 2020 From: dieter at handshake.de (Dieter Maurer) Date: Fri, 26 Jun 2020 19:57:58 +0200 Subject: property In-Reply-To: <5ef59d74$0$9530$426a74cc@news.free.fr> References: <5ef59d74$0$9530$426a74cc@news.free.fr> Message-ID: <24310.14118.822172.267573@ixdm.fritz.box> ast wrote at 2020-6-26 09:02 +0200: >Hello, > >I am wondering why this code is OK: > >class Temperature: > def __init__(self): > self.celsius = 0 > > fahrenheit = property() > > @fahrenheit.getter > def fahrenheit(self): > return 9/5*self.celsius +32 > > @fahrenheit.setter > def fahrenheit(self, value): > self.celsius = (value-32)*5/9 > > >and this one is not: > > >class Temperature: > def __init__(self): > self.celsius = 0 > > fahrenheit = property() > > @fahrenheit.getter > def f(self): > return 9/5*self.celsius +32 > > @fahrenheit.setter > def f(self, value): > self.celsius = (value-32)*5/9 A decoration @dec... def f(...): ... is a shorthand notation for def f(...): ... f = dec...(f) In your first example, "fahrenheit" is defined as you expect. In the second example, some property functions are bound to `f`. It depends on implementation details, whether the final `f` and/or `fahrenheit` has both getter/setter definitions. Always use the same name for function and property (as you do in your first class). From vinay_sajip at yahoo.co.uk Sun Jun 28 01:13:55 2020 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Sun, 28 Jun 2020 05:13:55 +0000 (UTC) Subject: ANN: distlib 0.3.1 released on PyPI References: <2106468845.8220262.1593321235656.ref@mail.yahoo.com> Message-ID: <2106468845.8220262.1593321235656@mail.yahoo.com> I've recently released version 0.3.1 of distlib on PyPI [1]. For newcomers, distlib is a library of packaging functionality which is intended to be usable as the basis for third-party packaging tools. The main changes in this release are as follows: * Fixed #132: Added documentation to help with relative interpreter paths. Thanks ? to Paul Kienzle for the patch. * Fixed #134: Allowed specifying a different target Python version when generating ? scripts. * Fixed #135: Exposed the ``enquote_executable`` function previously implemented ? as an internal function. * Addressed #138: Improved metadata support for newer metadata versions. Thanks to ? James Tocknell for the patch. * Changed the output of flags in entry point definitions in wheels. Thanks to ? frostming (??) for the patch. * Stopped writing JSON metadata. Only old-style metadata is written now. A more detailed change log is available at [2]. Please try it out, and if you find any problems or have any suggestions for improvements, please give some feedback using the issue tracker! [3] Note: Mailman3 might mishandle some of the links below. In that case, just copy and paste the links into your browser address bar - that should work. Regards, Vinay Sajip [1] https://pypi.org/project/distlib/0.3.1/ [2] https://distlib.readthedocs.io/en/0.3.1/ [3] https://bitbucket.org/pypa/distlib/issues/new From bdorestand at example.com Sun Jun 28 08:49:35 2020 From: bdorestand at example.com (Boris Dorestand) Date: Sun, 28 Jun 2020 09:49:35 -0300 Subject: on generating combinations among a variable list of lists Message-ID: <867dvrjqxs.fsf@example.com> Say we have [1,3,5,7], [2,3], [1,10]. I'd like to generate [1,2,1] [1,2,10] [1,3,1] [1,3,10] [3,2,1] [3,2,10] [3,3,1] [3,3,10] [5, ...] ... [7,3,10] The number of input lists is variable. The example shows three lists, but there could be only one or ten lists or any other number of lists. I looked at itertools. There doesn't seem to be any procedure ready for this. I might have to combine some of them but I'm not yet sure how. From nad at python.org Sun Jun 28 08:57:10 2020 From: nad at python.org (Ned Deily) Date: Sun, 28 Jun 2020 08:57:10 -0400 Subject: [RELEASE] Python 3.7.8 and 3.6.11 now available - last 3.7.x bugfix release Message-ID: <36E5B71C-7D67-412B-8F16-2589C07A4D8B@python.org> https://discuss.python.org/t/python-3-7-8-and-3-6-11-now-available-last-3-7-x-bugfix-release/4583 -- Ned Deily nad at python.org -- [] From __peter__ at web.de Sun Jun 28 09:07:31 2020 From: __peter__ at web.de (Peter Otten) Date: Sun, 28 Jun 2020 15:07:31 +0200 Subject: on generating combinations among a variable list of lists References: <867dvrjqxs.fsf@example.com> Message-ID: Boris Dorestand wrote: > Say we have [1,3,5,7], [2,3], [1,10]. I'd like to generate > > [1,2,1] > [1,2,10] > [1,3,1] > [1,3,10] > [3,2,1] > [3,2,10] > [3,3,1] > [3,3,10] > [5, ...] > ... > [7,3,10] > > The number of input lists is variable. The example shows three lists, > but there could be only one or ten lists or any other number of lists. > > I looked at itertools. There doesn't seem to be any procedure ready for > this. I might have to combine some of them but I'm not yet sure how. itertools.product() seems to do what you want: >>> for t in itertools.product([1,3,5,7], [2,3], [1,10]): ... print(t) ... (1, 2, 1) (1, 2, 10) (1, 3, 1) (1, 3, 10) (3, 2, 1) (3, 2, 10) (3, 3, 1) (3, 3, 10) (5, 2, 1) (5, 2, 10) (5, 3, 1) (5, 3, 10) (7, 2, 1) (7, 2, 10) (7, 3, 1) (7, 3, 10) If you need lists instead of tuples convert them >>> list(t) [7, 3, 10] To pass a varying number of lists use a list of lists and a star argument: >>> lists = [[[1, 2], [3, 4]], [[10, 20, 30], [40, 50]]] >>> for item in lists: ... print(list(itertools.product(*item))) ... [(1, 3), (1, 4), (2, 3), (2, 4)] [(10, 40), (10, 50), (20, 40), (20, 50), (30, 40), (30, 50)] From narenchunduri at gmail.com Sun Jun 28 11:04:04 2020 From: narenchunduri at gmail.com (narenchunduri at gmail.com) Date: Sun, 28 Jun 2020 08:04:04 -0700 (PDT) Subject: Assign Excel cell value from Datepicker widget Selection using Python Message-ID: <972e5d78-b594-43a1-88ef-43bf61e580a0o@googlegroups.com> When I run the python code I should be able to open my Excel and when I click on one Excel cell I should have my datepicker widget popped up and I should be able to select any date from my datepicker widget as my Excel cell value Tried below code but in vain: (Used jupyter Notebook) from ipywidgets import widgets from openpyxl import * wb = load_workbook('My_Excel.xlsx') worksheet = wb.active worksheet['B1'] = 'Datepicker' worksheet['B2'] = widgets.DatePicker() wb.save('My_Excel.xlsx') wb.close() Error Occured: ValueError: Cannot convert DatePicker(value=None) to Excel From bdorestand at example.com Sun Jun 28 12:59:01 2020 From: bdorestand at example.com (Boris Dorestand) Date: Sun, 28 Jun 2020 13:59:01 -0300 Subject: on generating combinations among a variable list of lists References: <867dvrjqxs.fsf@example.com> Message-ID: <861rlzjfe2.fsf@example.com> Peter Otten <__peter__ at web.de> writes: > Boris Dorestand wrote: > >> Say we have [1,3,5,7], [2,3], [1,10]. I'd like to generate >> >> [1,2,1] >> [1,2,10] >> [1,3,1] >> [1,3,10] >> [3,2,1] >> [3,2,10] >> [3,3,1] >> [3,3,10] >> [5, ...] >> ... >> [7,3,10] >> >> The number of input lists is variable. The example shows three lists, >> but there could be only one or ten lists or any other number of lists. >> >> I looked at itertools. There doesn't seem to be any procedure ready for >> this. I might have to combine some of them but I'm not yet sure how. > > itertools.product() seems to do what you want: > >>>> for t in itertools.product([1,3,5,7], [2,3], [1,10]): > ... print(t) > ... > (1, 2, 1) > (1, 2, 10) > (1, 3, 1) > (1, 3, 10) > (3, 2, 1) > (3, 2, 10) > (3, 3, 1) > (3, 3, 10) > (5, 2, 1) > (5, 2, 10) > (5, 3, 1) > (5, 3, 10) > (7, 2, 1) > (7, 2, 10) > (7, 3, 1) > (7, 3, 10) That's precisely it. I missed product. Thanks! > If you need lists instead of tuples convert them > >>>> list(t) > [7, 3, 10] > > To pass a varying number of lists use a list of lists and a star argument: > >>>> lists = [[[1, 2], [3, 4]], [[10, 20, 30], [40, 50]]] >>>> for item in lists: > ... print(list(itertools.product(*item))) > ... > [(1, 3), (1, 4), (2, 3), (2, 4)] > [(10, 40), (10, 50), (20, 40), (20, 50), (30, 40), (30, 50)] The star-syntax I didn't even know. And it was very useful. Thank you! From PythonList at DancesWithMice.info Sun Jun 28 13:31:01 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 29 Jun 2020 05:31:01 +1200 Subject: Assign Excel cell value from Datepicker widget Selection using Python In-Reply-To: <972e5d78-b594-43a1-88ef-43bf61e580a0o@googlegroups.com> References: <972e5d78-b594-43a1-88ef-43bf61e580a0o@googlegroups.com> Message-ID: <4b0b54b3-7d73-3619-fbc9-51e605025eb4@DancesWithMice.info> On 29/06/20 3:04 AM, narenchunduri at gmail.com wrote: > When I run the python code I should be able to open my Excel and when I click on one Excel cell I should have my datepicker widget popped up and I should be able to select any date from my datepicker widget as my Excel cell value > > Tried below code but in vain: (Used jupyter Notebook) > > from ipywidgets import widgets > from openpyxl import * > > wb = load_workbook('My_Excel.xlsx') > worksheet = wb.active > worksheet['B1'] = 'Datepicker' > worksheet['B2'] = widgets.DatePicker() > wb.save('My_Excel.xlsx') > wb.close() > Error Occured: ValueError: Cannot convert DatePicker(value=None) to Excel Do you know what comes back from the DatePicker() and is it suitable for this purpose? Recommend capturing it to a variable, and then printing its value (and type(), if necessary) to be sure of the facts... Let us know how you get on... -- Regards =dn From narenchunduri at gmail.com Sun Jun 28 14:01:56 2020 From: narenchunduri at gmail.com (narenchunduri at gmail.com) Date: Sun, 28 Jun 2020 11:01:56 -0700 (PDT) Subject: Assign Excel cell value from Datepicker widget Selection using Python In-Reply-To: References: <972e5d78-b594-43a1-88ef-43bf61e580a0o@googlegroups.com> <4b0b54b3-7d73-3619-fbc9-51e605025eb4@DancesWithMice.info> Message-ID: Datepicker is returning two different types. before date change its and after change its From narenchunduri at gmail.com Sun Jun 28 14:10:24 2020 From: narenchunduri at gmail.com (narenchunduri at gmail.com) Date: Sun, 28 Jun 2020 11:10:24 -0700 (PDT) Subject: Assign Excel cell value from Datepicker widget Selection using Python In-Reply-To: References: <972e5d78-b594-43a1-88ef-43bf61e580a0o@googlegroups.com> <4b0b54b3-7d73-3619-fbc9-51e605025eb4@DancesWithMice.info> Message-ID: <9196ca1e-3478-4bc5-b117-4d131aa946c7o@googlegroups.com> Do we have any other to achive my query From narenchunduri at gmail.com Sun Jun 28 14:19:06 2020 From: narenchunduri at gmail.com (narenchunduri at gmail.com) Date: Sun, 28 Jun 2020 11:19:06 -0700 (PDT) Subject: Assign Excel cell value from Datepicker widget Selection using Python In-Reply-To: References: <972e5d78-b594-43a1-88ef-43bf61e580a0o@googlegroups.com> <4b0b54b3-7d73-3619-fbc9-51e605025eb4@DancesWithMice.info> Message-ID: <480733f2-6487-4707-b4d5-25e3044e3412o@googlegroups.com> Is there any other way to achieve my query? From kushal at locationd.net Sun Jun 28 14:34:35 2020 From: kushal at locationd.net (Kushal Kumaran) Date: Sun, 28 Jun 2020 11:34:35 -0700 Subject: Assign Excel cell value from Datepicker widget Selection using Python In-Reply-To: <972e5d78-b594-43a1-88ef-43bf61e580a0o@googlegroups.com> (narenchunduri's message of "Sun, 28 Jun 2020 08:04:04 -0700 (PDT)") References: <972e5d78-b594-43a1-88ef-43bf61e580a0o@googlegroups.com> Message-ID: <875zbbt4xw.fsf@copper.locationd.net> narenchunduri at gmail.com writes: > When I run the python code I should be able to open my Excel and when > I click on one Excel cell I should have my datepicker widget popped up > and I should be able to select any date from my datepicker widget as > my Excel cell value > > Tried below code but in vain: (Used jupyter Notebook) > > from ipywidgets import widgets > from openpyxl import * > > wb = load_workbook('My_Excel.xlsx') > worksheet = wb.active > worksheet['B1'] = 'Datepicker' > worksheet['B2'] = widgets.DatePicker() > wb.save('My_Excel.xlsx') > wb.close() > Error Occured: ValueError: Cannot convert DatePicker(value=None) to Excel You might be asking too much from the tools. Unless openpyxl has some special knowledge of ipywidgets, what you're looking for won't work. ipywidgets has web-based components, that work from web browsers. You can use the cell data validation features to restrict the B2 cell to a valid date value, and the cell formatting ability to set the visual representation to a date, but that will not be sufficient to turn it into a date picker. You will have to deal with VBA or form components to do that. I'm not aware of such capabilities in the various xlsx writing libraries. -- regards, kushal From PythonList at DancesWithMice.info Sun Jun 28 18:07:30 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 29 Jun 2020 10:07:30 +1200 Subject: Assign Excel cell value from Datepicker widget Selection using Python In-Reply-To: References: <972e5d78-b594-43a1-88ef-43bf61e580a0o@googlegroups.com> <4b0b54b3-7d73-3619-fbc9-51e605025eb4@DancesWithMice.info> Message-ID: On 29/06/20 6:01 AM, narenchunduri at gmail.com wrote: > Datepicker is returning two different types. before date change its and after change its Well done! When it is printed, the date probably makes sense (to us), and the debug-print has given you the opportunity to make sure the data is exactly what is required! Now consider the 'second half' of the process: which data-type the Excel interface requires. Given the original err.msg, a conversion function may be helpful, eg str() https://docs.python.org/3/library/string.html Successful? -- Regards =dn From npropadovic at gmail.com Sun Jun 28 08:56:01 2020 From: npropadovic at gmail.com (Propadovic Nenad) Date: Sun, 28 Jun 2020 14:56:01 +0200 Subject: I need to study Python In-Reply-To: References: Message-ID: While there are a number of answers here which have a point, I'd first ask why do you want/need to study Python? Because, if you need it for something specific, you might want to focus on learning exactly what you need. In lack of an answer to that question, I'd recommend this: - as a newbie you need the basics first. There is a free interactive course here: https://www.codecademy.com/learn/learn-python-3 they'll give you the basic programming experience, without you having to set up any kind of programming environment, which is the first task with potential to scare away a beginner (depending on how ambitiously the environment is built up) - After that I'd give a plus one for the project based approach mentioned by J.Pic. If you however want to get a hands-on overview of what you can do with Python, go with a course that encompases a number of projects, if possible non-trivial ones. On Udemy you can find a number of such, I like this one: https://www.udemy.com/course/the-python-mega-course/ (make sure to purchase it for around 10$, when they are giving a discount, which is almost every week) - Finally, if you want to add some academic rigor and good programming practices, here's a free course by MIT: https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-0001-introduction-to-computer-science-and-programming-in-python-fall-2016/lecture-videos/index.htm >From there on, things to learn are infinite, I'm afraid, but you'd definitely not be a noob any more. Or, at least, the best educated noob on the planet! Am Fr., 26. Juni 2020 um 01:49 Uhr schrieb : > Hey, I'm a completely noob. > I want to learn python, how can i or where can i study python? > -- > https://mail.python.org/mailman/listinfo/python-list > From jf_byrnes at comcast.net Sun Jun 28 18:11:24 2020 From: jf_byrnes at comcast.net (Jim) Date: Sun, 28 Jun 2020 17:11:24 -0500 Subject: Does this dataframe look correct? Message-ID: linux mint 19.3, python 3.6 I wrote a program to download stock info from yahoo using yfinance. I have been running it unchanged for the past 3 months, today it gave an error. When looping through a list of stocks the error is random, never the same position in the list. I wrote the following little test script to show the error: import yfinance as yf import pandas as pd day = '2020-06-25' aapl = yf.Ticker('AAPL') hist = aapl.history(start=day) print(hist) close = hist.loc[day]['Close'] I ran it 10 times 8 times I got a dataframe and 2 times I got the error shown below: (env36) jfb at jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3 /home/jfb/Dev/Python/test_yfinance.py Open High Low Close Volume Date 2020-06-25 360.70 365.00 357.57 364.84 34380600 2020-06-26 364.41 365.32 353.02 353.63 51270100 (env36) jfb at jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3 /home/jfb/Dev/Python/test_yfinance.py Traceback (most recent call last): File "/home/jfb/Dev/Python/test_yfinance.py", line 13, in hist = aapl.history(start=day) File "/home/jfb/EVs/env36/lib/python3.6/site-packages/yfinance/base.py", line 155, in history data = data.json() File "/home/jfb/EVs/env36/lib/python3.6/site-packages/requests/models.py", line 897, in json return complexjson.loads(self.text, **kwargs) File "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/__init__.py", line 518, in loads return _default_decoder.decode(s) File "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py", line 370, in decode obj, end = self.raw_decode(s) File "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py", line 400, in raw_decode return self.scan_once(s, idx=_w(s, idx).end()) simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0) I don't know pandas that well. My only contact with it is when a module I am using depends on it. So does the dataframe look correct? The error complains of line 1, column 1. Just looking at the dataframe it looks like Date is on a different line from the rest of the headers or is that just the result of being printed in the terminal? On the yfinance github issues page there were a few people reporting this error. A couple of people reported a work around using try/except. It worked for some people and not others. It didn't work for me. I'd appreciate any advice you could give. Thanks, Jim From python at mrabarnett.plus.com Sun Jun 28 21:53:25 2020 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 29 Jun 2020 02:53:25 +0100 Subject: Does this dataframe look correct? In-Reply-To: References: Message-ID: <6db0115e-a3f6-abeb-a15b-5047113068ce@mrabarnett.plus.com> On 2020-06-28 23:11, Jim wrote: > linux mint 19.3, python 3.6 > > I wrote a program to download stock info from yahoo using yfinance. I > have been running it unchanged for the past 3 months, today it gave an > error. When looping through a list of stocks the error is random, never > the same position in the list. > > I wrote the following little test script to show the error: > > import yfinance as yf > import pandas as pd > day = '2020-06-25' > aapl = yf.Ticker('AAPL') > hist = aapl.history(start=day) > print(hist) > close = hist.loc[day]['Close'] > > I ran it 10 times 8 times I got a dataframe and 2 times I got the error > shown below: > > (env36) jfb at jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3 > /home/jfb/Dev/Python/test_yfinance.py > Open High Low Close Volume > Date > > 2020-06-25 360.70 365.00 357.57 364.84 34380600 > 2020-06-26 364.41 365.32 353.02 353.63 51270100 > > (env36) jfb at jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3 > /home/jfb/Dev/Python/test_yfinance.py > Traceback (most recent call last): > File "/home/jfb/Dev/Python/test_yfinance.py", line 13, in > hist = aapl.history(start=day) > File > "/home/jfb/EVs/env36/lib/python3.6/site-packages/yfinance/base.py", line > 155, in history > data = data.json() > File > "/home/jfb/EVs/env36/lib/python3.6/site-packages/requests/models.py", > line 897, in json > return complexjson.loads(self.text, **kwargs) > File > "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/__init__.py", > line 518, in loads > return _default_decoder.decode(s) > File > "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py", > line 370, in decode > obj, end = self.raw_decode(s) > File > "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py", > line 400, in raw_decode > return self.scan_once(s, idx=_w(s, idx).end()) > simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0) > > I don't know pandas that well. My only contact with it is when a module > I am using depends on it. So does the dataframe look correct? > > The error complains of line 1, column 1. Just looking at the dataframe > it looks like Date is on a different line from the rest of the headers > or is that just the result of being printed in the terminal? > > On the yfinance github issues page there were a few people reporting > this error. A couple of people reported a work around using try/except. > It worked for some people and not others. It didn't work for me. > > I'd appreciate any advice you could give. > It's complaining about the JSON data that it's getting. What does that data look like when it complains? It might be that there's some kind of limit to how often you can get the data and it's trying to tell you that, but you're not expecting anything back except the data. You could add some temporary code at line 897 of "/home/jfb/EVs/env36/lib/python3.6/site-packages/requests/models.py" to save the data to a file just before the decoding. Remember to make a backup copy of any source file that you modify! From jf_byrnes at comcast.net Sun Jun 28 23:07:34 2020 From: jf_byrnes at comcast.net (Jim) Date: Sun, 28 Jun 2020 22:07:34 -0500 Subject: Does this dataframe look correct? In-Reply-To: <6db0115e-a3f6-abeb-a15b-5047113068ce@mrabarnett.plus.com> References: <6db0115e-a3f6-abeb-a15b-5047113068ce@mrabarnett.plus.com> Message-ID: On 6/28/20 8:53 PM, MRAB wrote: > On 2020-06-28 23:11, Jim wrote: >> linux mint 19.3, python 3.6 >> >> I wrote a program to download stock info from yahoo using yfinance. I >> have been running it unchanged for the past 3 months, today it gave an >> error. When looping through a list of stocks the error is random, never >> the same position in the list. >> >> I wrote the following little test script to show the error: >> >> import yfinance as yf >> import pandas as pd >> day = '2020-06-25' >> aapl = yf.Ticker('AAPL') >> hist = aapl.history(start=day) >> print(hist) >> close = hist.loc[day]['Close'] >> >> I ran it 10 times 8 times I got a dataframe and 2 times I got the error >> shown below: >> >> (env36) jfb at jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3 >> /home/jfb/Dev/Python/test_yfinance.py >> ??????????????? Open??? High???? Low?? Close??? Volume >> Date >> >> 2020-06-25? 360.70? 365.00? 357.57? 364.84? 34380600 >> 2020-06-26? 364.41? 365.32? 353.02? 353.63? 51270100 >> >> (env36) jfb at jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3 >> /home/jfb/Dev/Python/test_yfinance.py >> Traceback (most recent call last): >> ??? File "/home/jfb/Dev/Python/test_yfinance.py", line 13, in >> ????? hist = aapl.history(start=day) >> ??? File >> "/home/jfb/EVs/env36/lib/python3.6/site-packages/yfinance/base.py", line >> 155, in history >> ????? data = data.json() >> ??? File >> "/home/jfb/EVs/env36/lib/python3.6/site-packages/requests/models.py", >> line 897, in json >> ????? return complexjson.loads(self.text, **kwargs) >> ??? File >> "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/__init__.py", >> line 518, in loads >> ????? return _default_decoder.decode(s) >> ??? File >> "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py", >> line 370, in decode >> ????? obj, end = self.raw_decode(s) >> ??? File >> "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py", >> line 400, in raw_decode >> ????? return self.scan_once(s, idx=_w(s, idx).end()) >> simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 >> (char 0) >> >> I don't know pandas that well. My only contact with it is when a module >> I am using depends on it. So does the dataframe look correct? >> >> The error complains of line 1, column 1. Just looking at the dataframe >> it looks like Date is on a different line from the rest of the headers >> or is that just the result of being printed in the terminal? >> >> On the yfinance github issues page there were a few people reporting >> this error. A couple of people reported a work around using try/except. >> It worked for some people and not others. It didn't work for me. >> >> I'd appreciate any advice you could give. >> > It's complaining about the JSON data that it's getting. What does that > data look like when it complains? > > It might be that there's some kind of limit to how often you can get the > data and it's trying to tell you that, but you're not expecting anything > back except the data. > > You could add some temporary code at line 897 of > "/home/jfb/EVs/env36/lib/python3.6/site-packages/requests/models.py" to > save the data to a file just before the decoding. Remember to make a > backup copy of any source file that you modify! I don't think it is a limit problem. It happened the first time I ran the script after a week of not using it. I am only geting info on 33 stocks and I know that people use this module to get info on 100's of stocks. Anyway I was wrong about the try/except not solving the problem. I made a mistake in the try/except and when I corrected it, like a dummy, I never saved the change before running it again. I will use your suggestions to see if I can figure out the root cause of the problem. as before today it ran for months with no errors. Sorry for taking up the lists time with my mistake and thanks for your help. Regards, Jim From __peter__ at web.de Mon Jun 29 03:16:59 2020 From: __peter__ at web.de (Peter Otten) Date: Mon, 29 Jun 2020 09:16:59 +0200 Subject: Does this dataframe look correct? References: Message-ID: Jim wrote: > linux mint 19.3, python 3.6 > > I wrote a program to download stock info from yahoo using yfinance. I > have been running it unchanged for the past 3 months, today it gave an > error. When looping through a list of stocks the error is random, never > the same position in the list. > > I wrote the following little test script to show the error: > > import yfinance as yf > import pandas as pd > day = '2020-06-25' > aapl = yf.Ticker('AAPL') > hist = aapl.history(start=day) > print(hist) > close = hist.loc[day]['Close'] > > I ran it 10 times 8 times I got a dataframe and 2 times I got the error > shown below: > > (env36) jfb at jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3 > /home/jfb/Dev/Python/test_yfinance.py > Open High Low Close Volume > Date > > 2020-06-25 360.70 365.00 357.57 364.84 34380600 > 2020-06-26 364.41 365.32 353.02 353.63 51270100 > > (env36) jfb at jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3 > /home/jfb/Dev/Python/test_yfinance.py > Traceback (most recent call last): > File "/home/jfb/Dev/Python/test_yfinance.py", line 13, in > hist = aapl.history(start=day) > File > "/home/jfb/EVs/env36/lib/python3.6/site-packages/yfinance/base.py", line > 155, in history > data = data.json() > File > "/home/jfb/EVs/env36/lib/python3.6/site-packages/requests/models.py", > line 897, in json > return complexjson.loads(self.text, **kwargs) > File > "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/__init__.py", > line 518, in loads > return _default_decoder.decode(s) > File > "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py", > line 370, in decode > obj, end = self.raw_decode(s) > File > "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py", > line 400, in raw_decode > return self.scan_once(s, idx=_w(s, idx).end()) > simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char > 0) > > I don't know pandas that well. My only contact with it is when a module > I am using depends on it. So does the dataframe look correct? > > The error complains of line 1, column 1. Just looking at the dataframe > it looks like Date is on a different line from the rest of the headers > or is that just the result of being printed in the terminal? > > On the yfinance github issues page there were a few people reporting > this error. A couple of people reported a work around using try/except. > It worked for some people and not others. It didn't work for me. > > I'd appreciate any advice you could give. My guess is that pandas is not the source of the problem. The error occurs when simplejson tries to parse an empty string: >>> import simplejson >>> simplejson.loads("") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 488, in loads return _default_decoder.decode(s) File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in decode obj, end = self.raw_decode(s) File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 389, in raw_decode return self.scan_once(s, idx=_w(s, idx).end()) simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char 0) This probably means that yahoo returns an empty string instead of the expected JSON. If the error occurs only sporadically and you can identify the downloading code in the API source you can try and replace (pseudo-code) json_data = download_from_yahoo() df = dataframe_from_json(json_data) with while True: json_data = download_from_yahoo() if json_data: break time.sleep(1) # wait a moment, then retry download df = dataframe_from_json(json_data) From tony.flury at btinternet.com Tue Jun 23 19:54:38 2020 From: tony.flury at btinternet.com (Tony Flury) Date: Wed, 24 Jun 2020 00:54:38 +0100 Subject: Solved: Re: Missing python curses functions? In-Reply-To: References: Message-ID: Maybe you should raise a bug (bugs.python.org) and flag that this function is missing. It could be that it can be introduced by whoever is maintaining the existing code. On 20/05/2020 08:31, Alan Gauld via Python-list wrote: > On 19/05/2020 20:53, Alan Gauld via Python-list wrote: > >> One of the functions discussed that does not appear to have >> a Python equivalent is attr_get() which gets the current >> attributes. > OK, Using inch() I've written the following function: > > > def attr_get(win): > """ return current window attributes. > If a character exists at the bottom right position it will be lost! > """ > y,x = win.getmaxyx() # how many lines in the window? > win.insch(y-1,0,' ') # insert a space at bottom left > ch = win.inch(y-1,0) # now read the char (including attributes) > win.delch(y-1,0) # remove the char from window > return ch > > And it can be used like: > > import curses > scr = curses.initscr() > # uncomment next line to test > # scr.attrset(curses.A_UNDERLINE) > > atts = attr_get(scr) > if atts & cur.A_UNDERLINE: > scr.addstr("Underline is on") > else: > scr.addstr("Underline is off") > > scr.refresh() > scr.getch() > curses.endwin() > > Just in case its useful to anyone else... From joepareti54 at gmail.com Mon Jun 29 13:14:19 2020 From: joepareti54 at gmail.com (joseph pareti) Date: Mon, 29 Jun 2020 19:14:19 +0200 Subject: i don't understand this python class Message-ID: I have piece of code with constructs as follows: *class* *SentimentNetwork**:* *def* __init__*(*self*,* reviews*,* labels*,* hidden_nodes *=* 10*,* learning_rate *=* 0.1*):* np*.*random*.*seed*(*1*)* self*.*init_network*(**len**(*self*.*review_vocab*),*hidden_nodes*,* 1*,* learning_rate*)* *def* init_network*(*self*,* input_nodes*,* hidden_nodes*,* output_nodes *,* learning_rate*):* # Store the number of nodes in input, hidden, and output layers. self*.*input_nodes *=* input_nodes self*.*hidden_nodes *=* hidden_nodes self*.*output_nodes *=* output_nodes which makes me think about the redundant usage of* init_network:* 1. as a method, AND 2. as a property So far I have only seen codes where the 2 things are separated, e.g. : *import* insurance *as* ins *class* *Vehicle**:* *def* __init__*(*self*,* speed*,* make*):* self*.*speed *=* speed self*.*make *=* make *class* *car**(*Vehicle*):* *def* __init__*(*self*,* speed*,* make*):* Vehicle*.*__init__*(*self*,* speed*,* make*)* self*.*insurance *=* ins*.*calc*(*make*)* *def* show_out*(*self*):* *print**(*'vehicle is '*,*self*.*make*,*' insurance premium '*,*self *.*insurance*)* *def* claim*(*self*,* discount*):* X *=* self*.*insurance *+* discount *return* X And hence I am not sure about the behavior of the first code in this email. -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 From cspealma at redhat.com Mon Jun 29 13:29:37 2020 From: cspealma at redhat.com (Calvin Spealman) Date: Mon, 29 Jun 2020 13:29:37 -0400 Subject: i don't understand this python class In-Reply-To: References: Message-ID: You are misreading the original example. `init_network` is defined as a method on the class, and called in its initializer. There is no property named "init_network". On Mon, Jun 29, 2020 at 1:18 PM joseph pareti wrote: > I have piece of code with constructs as follows: > > *class* *SentimentNetwork**:* > > *def* __init__*(*self*,* reviews*,* labels*,* hidden_nodes *=* 10*,* > learning_rate *=* 0.1*):* > > > > np*.*random*.*seed*(*1*)* > > > > self*.*init_network*(**len**(*self*.*review_vocab*),*hidden_nodes*,* > 1*,* learning_rate*)* > > > > > > > > *def* init_network*(*self*,* input_nodes*,* hidden_nodes*,* > output_nodes > *,* learning_rate*):* > > # Store the number of nodes in input, hidden, and output layers. > > self*.*input_nodes *=* input_nodes > > self*.*hidden_nodes *=* hidden_nodes > > self*.*output_nodes *=* output_nodes > > which makes me think about the redundant usage of* init_network:* > > 1. as a method, AND > 2. as a property > > So far I have only seen codes where the 2 things are separated, e.g. : > > *import* insurance *as* ins > > *class* *Vehicle**:* > > *def* __init__*(*self*,* speed*,* make*):* > > self*.*speed *=* speed > > self*.*make *=* make > > *class* *car**(*Vehicle*):* > > *def* __init__*(*self*,* speed*,* make*):* > > Vehicle*.*__init__*(*self*,* speed*,* make*)* > > self*.*insurance *=* ins*.*calc*(*make*)* > > *def* show_out*(*self*):* > > *print**(*'vehicle is '*,*self*.*make*,*' insurance premium > '*,*self > *.*insurance*)* > > *def* claim*(*self*,* discount*):* > > X *=* self*.*insurance *+* discount > > *return* X > > > And hence I am not sure about the behavior of the first code in this email. > -- > Regards, > Joseph Pareti - Artificial Intelligence consultant > Joseph Pareti's AI Consulting Services > https://www.joepareti54-ai.com/ > cell +49 1520 1600 209 > cell +39 339 797 0644 > -- > https://mail.python.org/mailman/listinfo/python-list > > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] TRIED. TESTED. TRUSTED. From jf_byrnes at comcast.net Mon Jun 29 14:03:50 2020 From: jf_byrnes at comcast.net (Jim) Date: Mon, 29 Jun 2020 13:03:50 -0500 Subject: Does this dataframe look correct? In-Reply-To: References: Message-ID: On 6/29/20 2:16 AM, Peter Otten wrote: > Jim wrote: > >> linux mint 19.3, python 3.6 >> >> I wrote a program to download stock info from yahoo using yfinance. I >> have been running it unchanged for the past 3 months, today it gave an >> error. When looping through a list of stocks the error is random, never >> the same position in the list. >> >> I wrote the following little test script to show the error: >> >> import yfinance as yf >> import pandas as pd >> day = '2020-06-25' >> aapl = yf.Ticker('AAPL') >> hist = aapl.history(start=day) >> print(hist) >> close = hist.loc[day]['Close'] >> >> I ran it 10 times 8 times I got a dataframe and 2 times I got the error >> shown below: >> >> (env36) jfb at jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3 >> /home/jfb/Dev/Python/test_yfinance.py >> Open High Low Close Volume >> Date >> >> 2020-06-25 360.70 365.00 357.57 364.84 34380600 >> 2020-06-26 364.41 365.32 353.02 353.63 51270100 >> >> (env36) jfb at jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3 >> /home/jfb/Dev/Python/test_yfinance.py >> Traceback (most recent call last): >> File "/home/jfb/Dev/Python/test_yfinance.py", line 13, in >> hist = aapl.history(start=day) >> File >> "/home/jfb/EVs/env36/lib/python3.6/site-packages/yfinance/base.py", line >> 155, in history >> data = data.json() >> File >> "/home/jfb/EVs/env36/lib/python3.6/site-packages/requests/models.py", >> line 897, in json >> return complexjson.loads(self.text, **kwargs) >> File >> "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/__init__.py", >> line 518, in loads >> return _default_decoder.decode(s) >> File >> "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py", >> line 370, in decode >> obj, end = self.raw_decode(s) >> File >> "/home/jfb/EVs/env36/lib/python3.6/site-packages/simplejson/decoder.py", >> line 400, in raw_decode >> return self.scan_once(s, idx=_w(s, idx).end()) >> simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char >> 0) >> >> I don't know pandas that well. My only contact with it is when a module >> I am using depends on it. So does the dataframe look correct? >> >> The error complains of line 1, column 1. Just looking at the dataframe >> it looks like Date is on a different line from the rest of the headers >> or is that just the result of being printed in the terminal? >> >> On the yfinance github issues page there were a few people reporting >> this error. A couple of people reported a work around using try/except. >> It worked for some people and not others. It didn't work for me. >> >> I'd appreciate any advice you could give. > > My guess is that pandas is not the source of the problem. The error occurs > when simplejson tries to parse an empty string: > >>>> import simplejson >>>> simplejson.loads("") > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python3/dist-packages/simplejson/__init__.py", line 488, in > loads > return _default_decoder.decode(s) > File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 370, in > decode > obj, end = self.raw_decode(s) > File "/usr/lib/python3/dist-packages/simplejson/decoder.py", line 389, in > raw_decode > return self.scan_once(s, idx=_w(s, idx).end()) > simplejson.scanner.JSONDecodeError: Expecting value: line 1 column 1 (char > 0) > > This probably means that yahoo returns an empty string instead of the > expected JSON. If the error occurs only sporadically and you can identify > the downloading code in the API source you can try and replace (pseudo-code) > > json_data = download_from_yahoo() > df = dataframe_from_json(json_data) > > with > > while True: > json_data = download_from_yahoo() > if json_data: break > time.sleep(1) # wait a moment, then retry download > df = dataframe_from_json(json_data) > Thanks, I have it working now by wrapping a for loop in a try/except. When I get a chance I will use yours and MRAB's suggestions to try to figure out just what caused the problem. Regards, Jim From solipsis at pitrou.net Mon Jun 29 16:25:13 2020 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 29 Jun 2020 22:25:13 +0200 Subject: [RELEASE] mpdecimal-2.5.0 References: <20200629132701.GA4734@bytereef.org> Message-ID: <20200629222513.1f254b6d@fsol> Hi Stefan On Mon, 29 Jun 2020 15:27:01 +0200 Stefan Krah wrote: > Hi, > > I've released mpdecimal-2.5.0: > > http://www.bytereef.org/mpdecimal/index.html > > 15417edc8e12a57d1d9d75fa7e3f22b158a3b98f44db9d694cfd2acde8dfa0ca mpdecimal-2.5.0.tar.gz > > Starting with Python 3.9, this version should be used for an external libmpdec. > > Python versions 3.7 and 3.8 should use the previous version mpdecimal-2.4.2. Speaking of which, is there a plan to incorporate a C API to the _decimal module? Currently, there's no reliable way AFAIK, from C or C++, to take a PyObject* and acccess the underlying `mpd_t*` directly, for fast conversions. Regards Antoine. From PythonList at DancesWithMice.info Mon Jun 29 17:08:16 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 30 Jun 2020 09:08:16 +1200 Subject: i don't understand this python class In-Reply-To: References: Message-ID: <59c12ba1-7143-044b-023e-9ebe26ecf1f1@DancesWithMice.info> On 30/06/20 5:14 AM, joseph pareti wrote: > I have piece of code with constructs as follows: > > *class* *SentimentNetwork**:* > > *def* __init__*(*self*,* reviews*,* labels*,* hidden_nodes *=* 10*,* > learning_rate *=* 0.1*):* > np*.*random*.*seed*(*1*)* > self*.*init_network*(**len**(*self*.*review_vocab*),*hidden_nodes*,* > 1*,* learning_rate*)* > > *def* init_network*(*self*,* input_nodes*,* hidden_nodes*,* output_nodes > *,* learning_rate*):* > # Store the number of nodes in input, hidden, and output layers. > self*.*input_nodes *=* input_nodes > self*.*hidden_nodes *=* hidden_nodes > self*.*output_nodes *=* output_nodes > > which makes me think about the redundant usage of* init_network:* > > 1. as a method, AND > 2. as a property Let's imagine this code-functionality, but where all of the initialisation is performed in the single __init__ method:- - there would be four lines of code instead of eight, saving typing-time and reading-time - when reading the code, we would not have to 'jump' our eyes from __init__() to init_network, just to see what happens at instantiation So, why bother? (is that the nub of your question?) Consider now the pertinent four lines: - seed the PRNG (Pseudo-Random Number Generator) - set number of input_nodes - set number of hidden_nodes - set number of output_notes per my favorite (hi-brown and highly-technical) TV program(me): "which of these is not like the others?" Add to such thinking, that there is apparently much more in the initialiser than illustrated (presumably for brevity - thanks!), and you can comprehend that there are several *different* functions that all have to happen upon instantiation. So, although init_network() as a separate method is *functionally* unnecessary, by separating those tasks from 'everything else that has to happen' (and presumably also bunching groups of those tasks together under applicable headings!) is a very helpful *documentation* technique - in fact, I put it to you, that the name of the method is more helpful to a reader, than is the explanatory comment! Your thoughts? (which #comment 'should' be a docstring, BTW) The word "property" may have a slightly different definition in Python than in other programming languages you have used. If that part of the question hasn't been adequately-covered (albeit en-passant) please explain further... Finally, please be aware that there is a Python-Tutor Discussion List for the pleasure of both learners and tutors. -- Regards =dn From satyaprasad at mail.g Tue Jun 30 06:52:58 2020 From: satyaprasad at mail.g (satyaprasad) Date: Tue, 30 Jun 2020 10:52:58 -0000 (UTC) Subject: Data structures and Algorithms Message-ID: Hi, I am currently in learning process of python have been worked on some desktop application using pyqt . I want improve my DSA area but i searched so many videos mot sure how to start . 1.Do i really need learn datastructures in c or c++ to get complete logical details. 2 .or shall i start learn using python itself then where to start . Can some one give me a road map for DSA with python. I am Beginner.... From ast at invalid Tue Jun 30 08:14:55 2020 From: ast at invalid (ast) Date: Tue, 30 Jun 2020 14:14:55 +0200 Subject: property In-Reply-To: References: <5ef59d74$0$9530$426a74cc@news.free.fr> Message-ID: <5efb2cc0$0$6456$426a74cc@news.free.fr> Le 26/06/2020 ? 10:16, R.Wieser a ?crit?: > ast, > > I have absolutily /no idea/ about how that "fahrenheit = property()" comes > into play though. > It just creates an empty property object. You can then fill this object with the read/write/delete functions with the methods getter, setter, deleter From cs at cskk.id.au Tue Jun 30 08:26:19 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 30 Jun 2020 22:26:19 +1000 Subject: Data structures and Algorithms In-Reply-To: References: Message-ID: <20200630122619.GA51148@cskk.homeip.net> On 30Jun2020 10:52, satyaprasad wrote: >Hi, I am currently in learning process of python have been worked on >some desktop application using pyqt . I want improve my DSA area but i >searched so many videos mot sure how to start . 1.Do i really need learn >datastructures in c or c++ to get complete logical details. 2 .or shall >i start learn using python itself then where to start . Can some one >give me a road map for DSA with python. In my opinion you are better off using Python. In C and (less so) in C++ there is a lot of cruft around managing memory and allocating sizes, not to mention additional verbiage. In Python you are far freer to concentrate on the data structures and algorithms themselves. Maybe start here: https://duckduckgo.com/html?q=python%20data%20structures%20and%20algorithms%20tutorials Cheers, Cameron Simpson From ast at invalid Tue Jun 30 08:29:10 2020 From: ast at invalid (ast) Date: Tue, 30 Jun 2020 14:29:10 +0200 Subject: property In-Reply-To: References: <5ef59d74$0$9530$426a74cc@news.free.fr> Message-ID: <5efb3017$0$4030$426a74cc@news.free.fr> Le 26/06/2020 ? 15:12, Peter Otten a ?crit?: > Unknown wrote: > The getter/setter of the property builtin return a new property >>>> p = property() >>>> q = p.getter(None) >>>> p is q > False > > where you > >> def getter(self, fget): >> self.fget = fget >> return self > > modify the existing one. > > Yes you are right. Thank you for noticing that. My property seems better since you can choose any names for the functions to be used for fget, fset and fdel. From Richard at Damon-Family.org Tue Jun 30 09:18:48 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Tue, 30 Jun 2020 09:18:48 -0400 Subject: Data structures and Algorithms In-Reply-To: <20200630122619.GA51148@cskk.homeip.net> References: <20200630122619.GA51148@cskk.homeip.net> Message-ID: On 6/30/20 8:26 AM, Cameron Simpson wrote: > On 30Jun2020 10:52, satyaprasad wrote: >> Hi, I am currently in learning process of python have been worked on >> some desktop application using pyqt . I want improve my DSA area but i >> searched so many videos mot sure how to start . 1.Do i really need learn >> datastructures in c or c++ to get complete logical details. 2 .or shall >> i start learn using python itself then where to start . Can some one >> give me a road map for DSA with python. > In my opinion you are better off using Python. In C and (less so) in C++ > there is a lot of cruft around managing memory and allocating sizes, not > to mention additional verbiage. In Python you are far freer to > concentrate on the data structures and algorithms themselves. > > Maybe start here: > > https://duckduckgo.com/html?q=python%20data%20structures%20and%20algorithms%20tutorials > > Cheers, > Cameron Simpson I would disagree a bit here, a lot depends on WHY and WHAT you want to learn about Data Structures and Algorithms. A lot of learning Data Structures is learning to understand the actual typical structure of the Data Structure, and seeing the explicit pointers can be helpful here. Python may be better for the Algorithms side, where hiding some of the gritty detail can be more useful, though that hiding might obscure some details if you want to think about what is the complexity of an operation. -- Richard Damon From narenchunduri at gmail.com Tue Jun 30 10:17:05 2020 From: narenchunduri at gmail.com (narenchunduri at gmail.com) Date: Tue, 30 Jun 2020 07:17:05 -0700 (PDT) Subject: Assign Excel cell value from Datepicker widget Selection using Python In-Reply-To: References: <972e5d78-b594-43a1-88ef-43bf61e580a0o@googlegroups.com> <875zbbt4xw.fsf@copper.locationd.net> Message-ID: <41e3b0dd-c283-46f1-b4c9-977562adb8a5o@googlegroups.com> Thx kushal for your valuable points From rhodri at kynesim.co.uk Tue Jun 30 10:25:25 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 30 Jun 2020 15:25:25 +0100 Subject: Code of Conduct address "hold message" Message-ID: <5601f105-cfb5-3345-f470-0b5ec7930aee@kynesim.co.uk> Having just had occasion to use the code of conduct link (conduct-wg at python.org), I got back the message: Your mail to 'conduct-wg at python.org' with the subject Is being held until the list moderator can review it for approval. etc. I know this is the standard moderation message, but it seems rather out of place for the CoC address. It's not the least bit reassuring if you feel uncomfortable about making such reports, as some people (myself included) are. If I were emailing a commercial company's complaints line I would expect something more in the nature of Thank you for your email about "". We will deal with it as soon as we can." Plus the usual platitudes about valuing my input and appreciating my custom which don't necessarily apply here ;-/ Any chance of getting the message altered to something a bit more friendly? -- Rhodri James *-* Kynesim Ltd From sirosen at uchicago.edu Tue Jun 30 11:59:11 2020 From: sirosen at uchicago.edu (Stephen Rosen) Date: Tue, 30 Jun 2020 11:59:11 -0400 Subject: How to handle async and inheritance? Message-ID: Hi all, I'm looking at a conflict between code sharing via inheritance and async usage. I would greatly appreciate any guidance, ideas, or best practices which might help. I'll speak here in terms of a toy example, but, if anyone wants to look at the real code, I'm working on webargs. [1] Specifically, we have a `Parser` class and an `AsyncParser` subclass, and the two have a lot of code duplication to handle async/await. [2] I've got an inheritance structure like this: class MyAbstractType: ... class ConcreteType(MyAbstractType): ... class AsyncConcreteType(MyAbstractType): ... One of my goals, of course, is to share code between ConcreteType and AsyncConcreteType via their parent. But the trouble is that there are functions defined like this: class MyAbstractType: def foo(self): x = self.bar() y = self.baz(x) ... # some code here, let's say 20 lines class AsyncConcreteType(MyAbstractType): async def foo(self): x = await self.bar() y = self.baz(x) ... # the same 20 lines as above, but with an `await` added every-other line I'm aware that I'm looking at "function color" and that my scenario is pitting two language features -- inheritance and async -- against one another. But I don't see a clean way out if we want to support an "async-aware" version of a class with synchronous methods. What I tried already, which I couldn't get to work, was to either fiddle with things like `inspect` to see if the current function is async or to use a class variable to indicate that the current class is the async version. The idea was to write something like class MyAbstractType: _use_async_calls = False def foo(self): x = self._await_if_i_am_async(self.bar) y = self.baz(x) ... and that way, the async subclass just needs to change signatures to be async with little stubs and set the flag, class AsyncConcreteType(MyAbstractType): _use_async_calls = True async def foo(self): return super().foo() async def bar(self): return super().bar() but this (some of you are ahead of me on this, I'm sure!) did not work at all. I couldn't find any way to write `_await_if_i_am_async`, other than possibly doing some weird things with `exec`. Once I concluded that the python wouldn't let me decide whether or not to use await at runtime, at least with tools of which I'm aware, I basically gave up on that route. However, it seems like there should be some clever technique for defining `MyAbstractType.foo` such that it awaits on certain calls *if* there's some indication that it should do so. It's obviously possible with `exec`, but I don't want to convert all of the core codepaths into giant `exec` blocks. Perhaps there's a way which is safer and more maintainable though? If anyone has experience in this space and can offer up a good solution, I would love to hear about it. And if someone wants to go above-and-beyond and look at webargs, and suggest a better way for us to support aiohttp, I'd obviously welcome that kind of help as well! Thanks in advance, and best regards, -Stephen [1] https://github.com/marshmallow-code/webargs [2] https://github.com/marshmallow-code/webargs/blob/6668d267fa4135cf3f653e422bd168298f2213a8/src/webargs/asyncparser.py#L24 From lukasz at langa.pl Tue Jun 30 12:25:59 2020 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Tue, 30 Jun 2020 18:25:59 +0200 Subject: [RELEASE] Python 3.8.4rc1 is now ready for testing Message-ID: <168A62C8-E1C6-4B6B-B136-DCCD4BFD4A49@langa.pl> Python 3.8.4rc1 is the release candidate of the fourth maintenance release of Python 3.8. Go get it here: https://www.python.org/downloads/release/python-384rc1/ Assuming no critical problems are found prior to 2020-07-13, the scheduled release date for 3.8.4, no code changes are planned between this release candidate and the final release. That being said, please keep in mind that this is a pre-release and as such its main purpose is testing. Maintenance releases for the 3.8 series will continue at regular bi-monthly intervals, with 3.8.5 planned for mid-September 2020. What?s new? The Python 3.8 series is the newest feature release of the Python language, and it contains many new features and optimizations. See the ?What?s New in Python 3.8 ? document for more information about features included in the 3.8 series. This is the first bugfix release that is considerably smaller than the previous three. There?s 20% less changes at 130 commits than the average of previous three releases. Detailed information about all changes made in version 3.8.4 specifically can be found in its change log . We hope you enjoy Python 3.8! Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. Your friendly release team, Ned Deily @nad Steve Dower @steve.dower ?ukasz Langa @ambv From PythonList at DancesWithMice.info Tue Jun 30 13:34:58 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 1 Jul 2020 05:34:58 +1200 Subject: Data structures and Algorithms In-Reply-To: References: <20200630122619.GA51148@cskk.homeip.net> Message-ID: <360e3745-9f9b-f15c-2945-b259019fa983@DancesWithMice.info> On 1/07/20 1:18 AM, Richard Damon wrote: > On 6/30/20 8:26 AM, Cameron Simpson wrote: >> On 30Jun2020 10:52, satyaprasad wrote: >>> Hi, I am currently in learning process of python have been worked on >>> some desktop application using pyqt . I want improve my DSA area but i >>> searched so many videos mot sure how to start . 1.Do i really need learn >>> datastructures in c or c++ to get complete logical details. 2 .or shall >>> i start learn using python itself then where to start . Can some one >>> give me a road map for DSA with python. >> In my opinion you are better off using Python. In C and (less so) in C++ >> there is a lot of cruft around managing memory and allocating sizes, not >> to mention additional verbiage. In Python you are far freer to >> concentrate on the data structures and algorithms themselves. >> >> Maybe start here: >> >> https://duckduckgo.com/html?q=python%20data%20structures%20and%20algorithms%20tutorials >> >> Cheers, >> Cameron Simpson > > I would disagree a bit here, a lot depends on WHY and WHAT you want to > learn about Data Structures and Algorithms. A lot of learning Data > Structures is learning to understand the actual typical structure of the > Data Structure, and seeing the explicit pointers can be helpful here. > > Python may be better for the Algorithms side, where hiding some of the > gritty detail can be more useful, though that hiding might obscure some > details if you want to think about what is the complexity of an operation. Yes, there's quite a bit of room for discussing what to learn and why one might want to learn such; expanding into 'what is ComSc' and why/how might learning such topics benefit a professional programmer (or specialist in one particular arena); and the list goes on... For decades I have lusted (well, almost) for a copy of Knuth's library (but it is NOT a training resource). However, I also reflect that a lot of our study as u/grads, eg learning and comparing multiple sorting algorithms; is almost irrelevant these days, and with Python - sort() is at-least 'good enough' for 99% of (my) in-RAM applications. (and Knuth started his collection of algorithms in the 1960s, IIRC) To the OP: recommending you view both Coursera.org and edX.org. The likes of Georgia Tech and U.Mich[igan] offer series of courses using Python as their illustration language. In combination with increasing your Python skills, you will thus be able to follow a structured series, or to pick-and-choose from their syllabi to suit your particular needs/interests. Courses are usually chargeable, but most can be "audited" for $free (you might have to wind through the dialog-boxes, and will likely not be able to submit exams/assignments for consideration) (Disclosure: I train using edX - but not in Python) -- Regards =dn From rhodri at kynesim.co.uk Tue Jun 30 14:51:07 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 30 Jun 2020 19:51:07 +0100 Subject: Code of Conduct address "hold message" In-Reply-To: <5601f105-cfb5-3345-f470-0b5ec7930aee@kynesim.co.uk> References: <5601f105-cfb5-3345-f470-0b5ec7930aee@kynesim.co.uk> Message-ID: <53d4ea54-d029-7ea2-3b39-91733c54b2f9@kynesim.co.uk> On 30/06/2020 15:25, Rhodri James wrote: > Having just had occasion to use the code of conduct link > (conduct-wg at python.org), I got back the message: > > ? Your mail to 'conduct-wg at python.org' with the subject > > ??? > > ? Is being held until the list moderator can review it for approval. Ah, it looks like the message I was expecting is generated when the moderator actually picks up the complaint, so that's OK. The generic moderation message is still rather off-putting, though. -- Rhodri James *-* Kynesim Ltd From hjp-python at hjp.at Tue Jun 30 15:47:35 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 30 Jun 2020 21:47:35 +0200 Subject: Pycharm Won't Do Long Underscore In-Reply-To: <57bcc6ac-7446-6da8-bd1b-ca0002951265@gmail.com> References: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> <20200624211016.GB24048@hjp.at> <57bcc6ac-7446-6da8-bd1b-ca0002951265@gmail.com> Message-ID: <20200630194735.GA13992@hjp.at> On 2020-06-25 11:56:47 -0600, Michael Torrie wrote: > On 6/24/20 7:38 PM, Grant Edwards wrote: > > On 2020-06-24, Peter J. Holzer wrote: > >> There is U+FF3F Fullwidth Low Line. > >> > >>> If there were, Python would not know what to do with it > >> > >> You can use it in variable names, but not at the beginning, and it isn't > >> equivalent to two underscores, of course: > > > > Ouch. Anybody caught using that should be fed to a large snake. > > Even allowing unicode letters in variable names period is questionable, > but that loud debate was over years ago. Fortunately I have never seen > any python code in the wild with non-latin characters for variable > names. When I use German words as identifiers (I try to avoid this, but sometimes translating to English would just confuse everybody), I do use umlauts. I have also used Greek letters for physical quantities (e.g., ? for angular velocity). > Would make editing code very painful for developers from different > locales and keyboards. Yeah, editor support is a problem[1]. For my code with German identifiers it is very unlikely that anybody who doesn't use German daily (and hence already has the need to type umlauts) will ever have to edit it. The Greek characters are in private code only. hp [1] I use vim. Digraphs are a bit awkward but good enough for medium rare[2] characters. I don't know how to type characters not on the keyboard[3] in VS code or PyCharm or Emacs or whatever others are using. "I can't edit your code because I can't type that variable name" is certainly not something I want to hear from my colleagues. [2] Pun not intended. [3] Includes compose-sequences, if the keyboard has a compose key. -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From hjp-python at hjp.at Tue Jun 30 16:00:00 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 30 Jun 2020 22:00:00 +0200 Subject: FW: Pycharm Won't Do Long Underscore In-Reply-To: <1ba70sdu8z.fsf@pfeifferfamily.net> References: <1ba5e69e-f916-f96d-a67b-44a3df638228@mrabarnett.plus.com> <1ba70sdu8z.fsf@pfeifferfamily.net> Message-ID: <20200630200000.GB13992@hjp.at> On 2020-06-24 15:33:16 -0600, Joe Pfeiffer wrote: > One other note -- while you may want various good-looking fonts with > ligatures in other domains, for writing code a monospace font with no > ligatures lets you see exactly what's there and saves a host of > problems. My personal favorite for these purposes is called "Terminus > Regular", but which specific one you pick is much less important than > that you use one. I agree. Although there are some fonts with special ligatures for programming. I have never used one, but that seems like an interesting concept. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From pfeiffer at cs.nmsu.edu Tue Jun 30 17:46:40 2020 From: pfeiffer at cs.nmsu.edu (Joe Pfeiffer) Date: Tue, 30 Jun 2020 15:46:40 -0600 Subject: FW: Pycharm Won't Do Long Underscore References: <1ba5e69e-f916-f96d-a67b-44a3df638228@mrabarnett.plus.com> <1ba70sdu8z.fsf@pfeifferfamily.net> <20200630200000.GB13992@hjp.at> Message-ID: <1bpn9g5irj.fsf@pfeifferfamily.net> "Peter J. Holzer" writes: > On 2020-06-24 15:33:16 -0600, Joe Pfeiffer wrote: >> One other note -- while you may want various good-looking fonts with >> ligatures in other domains, for writing code a monospace font with no >> ligatures lets you see exactly what's there and saves a host of >> problems. My personal favorite for these purposes is called "Terminus >> Regular", but which specific one you pick is much less important than >> that you use one. > > I agree. Although there are some fonts with special ligatures for > programming. I have never used one, but that seems like an interesting > concept. I've never heard of that before. I'd be curious to try one. From david at lowryduda.com Tue Jun 30 19:36:11 2020 From: david at lowryduda.com (David Lowry-Duda) Date: Tue, 30 Jun 2020 19:36:11 -0400 Subject: Understanding interoperability Message-ID: <20200630233611.GA20142@icerm-dld> I have quite a bit of experience with various programming languages, including python, C, C++, and lisp. But I very rarely work on projects that use interoperability. This is something that I'd like to learn more about. Sometimes, for numerical computing, I use cython as a binding layer between C++ and python, but that's the extent of my experience. I'm under the impression that if one were to want to use something like lisp (like say ecl embeddable common lisp), C, and python together, the process boils down to writing a lot of wrappers in C. And more generally, C is a frequent lowest-common-denominator language. Is my understanding right? - DLD -- David Lowry-Duda From rosuav at gmail.com Tue Jun 30 21:11:15 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jul 2020 11:11:15 +1000 Subject: Understanding interoperability In-Reply-To: <20200630233611.GA20142@icerm-dld> References: <20200630233611.GA20142@icerm-dld> Message-ID: On Wed, Jul 1, 2020 at 9:37 AM David Lowry-Duda wrote: > > I have quite a bit of experience with various programming languages, > including python, C, C++, and lisp. But I very rarely work on projects > that use interoperability. This is something that I'd like to learn more > about. > > Sometimes, for numerical computing, I use cython as a binding layer > between C++ and python, but that's the extent of my experience. I'm > under the impression that if one were to want to use something like lisp > (like say ecl embeddable common lisp), C, and python together, the > process boils down to writing a lot of wrappers in C. And more > generally, C is a frequent lowest-common-denominator language. Is my > understanding right? > On most operating systems, there's some kind of binary executable format that is compatible with basically any language, but is most often described in C, so yes, C becomes the de facto language of these kinds of things. But you also have another very good option, and that is to keep all the binaries entirely separate, and use interprocess communication between them. For example, you could have a Python program that starts a Lisp interpreter as a subprocess, and communicates with it via stdin/stdout; or a TCP or Unix socket can be used for negotiating between groups of languages; or you can have everything push stuff into a PostgreSQL database. There are many options, depending on what kind of interaction you need. I'm a big fan of using networking to communicate (ie TCP sockets, or higher level constructs such as HTTP or WebSockets) as they can be used by all manner of programs, even those running in restricted environments such as inside a web browser. For instance, I have a Pike program that manages my Twitch channel bot, and it can signal a web page (JavaScript running in a web browser) using a WebSocket to have it do things, and a Python program can talk to it via the same sort of websocket to send it a message. Meanwhile a shell script can trigger things by invoking Python, etc, etc. Easy to change different parts out, because the communication lines are defined in simple terms like "HTTP with JSON payload", which can be understood easily by all languages. If you actually need real function calls (like you say with Cython being between C++ and Python), the hardest part is managing different data types. Python code running in CPython already has a rich API for this, but once you bring some other language into the mix, now you have to think about the differences between different integer types, or different string types. Unless your code is very carefully crafted, you will probably find that it's just as much trouble - and just as much of a performance hit - as it would be if you were using external communication. It takes a lot of planning to properly take advantage of polyglot intra-process communication :) ChrisA From random832 at fastmail.com Tue Jun 30 22:00:17 2020 From: random832 at fastmail.com (Random832) Date: Tue, 30 Jun 2020 22:00:17 -0400 Subject: Pycharm Won't Do Long Underscore In-Reply-To: References: <52C88F94-12A6-4835-9D92-808C8BBBC272@neilson.net.nz> <20200624211016.GB24048@hjp.at> Message-ID: <043ec527-3d70-4e96-b18f-068bc559da1c@www.fastmail.com> On Wed, Jun 24, 2020, at 21:38, Grant Edwards wrote: > On 2020-06-24, Peter J. Holzer wrote: > > > There is U+FF3F Fullwidth Low Line. > > > >> If there were, Python would not know what to do with it > > > > You can use it in variable names, but not at the beginning, and it isn't > > equivalent to two underscores, of course: It is, in fact, equivalent to a single underscore. This is reasonable, given the unicode rules [I assume identifier lookup uses NFKC] and how these characters function for East Asian users. > Ouch. Anybody caught using that should be fed to a large snake. Honestly, if I were to suggest any change it'd be to fix it so it's allowed at the beginning of an identifier. Let each (human) language's community worry about coding conventions for code intended for speakers of that language instead of trying to impose things on the world as english-speakers. >>> a=1 >>> a_b=2 >>> ? 1 >>> ??? 2 >>> ? File "", line 1 ? ^ SyntaxError: invalid character in identifier