From dieter at handshake.de Fri May 1 00:42:25 2020 From: dieter at handshake.de (Dieter Maurer) Date: Fri, 1 May 2020 06:42:25 +0200 Subject: SSL Certificate Verify Failed (_ssl.c:600) using Windows Server 2019 In-Reply-To: References: <24235.4673.14122.18088@ixdm.fritz.box> Message-ID: <24235.43185.176654.240830@ixdm.fritz.box> separated wrote at 2020-5-1 02:51 +0000: > ... >but I still dont know why when I running a command 'youtube-dl -U' then got a message 'ERROR: can't find the current version. Please try again later' maybe it needs a sudo password. This looks like a log message (the "ERROR" likely comes from this). I would search the source code (recursively) for "find the current version" to locate the piece of code responsible for the message and then look around to find out why it is generated. From cseberino at gmail.com Fri May 1 09:58:09 2020 From: cseberino at gmail.com (Christian Seberino) Date: Fri, 1 May 2020 06:58:09 -0700 (PDT) Subject: Techniques to extend code without modifying it? (besides modules and decorators) In-Reply-To: <874kt2f0d5.fsf@nightsong.com> References: <874kt2f0d5.fsf@nightsong.com> Message-ID: Paul Thanks! I'm glad there is theory about my concern. I knew I wasn't the only one with that question. cs > > https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle > > Also: > > https://en.wikipedia.org/wiki/Expression_problem From PythonList at DancesWithMice.info Fri May 1 16:34:00 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 2 May 2020 08:34:00 +1200 Subject: How to test? In-Reply-To: <20200430192541.1594f9b1@arcor.com> 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> Message-ID: <33292aa6-98e1-6b0b-ab34-6ca057941db0@DancesWithMice.info> >> 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. Your objective is learning to program in Python. 'Chopping and changing' between ancillary tools would be a distraction and time-sink. If you have already started learning unittest, keep going. We all have to start 'somewhere'! At the learning stage, any one of these tools will help you with testing, and testing should improve your overall programming skills. Once your expertise, in both Python and the testing tool, matures; you will be better placed to survey the opportunities and to choose the best alternative for you and your applications... -- Regards =dn From PythonList at DancesWithMice.info Fri May 1 19:12:39 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 2 May 2020 11:12:39 +1200 Subject: Function to avoid a global variable In-Reply-To: References: <5ea7d268$0$5889$426a74cc@news.free.fr> <5ea7da2d$0$15172$426a74cc@news.free.fr> Message-ID: On 28/04/20 7:36 PM, Chris Angelico wrote: >>> "Best"? Not sure about that. Functions are first-class objects in >>> Python, so a function *is* a callable object. You don't have to create >>> a custom class with a call method just to be able to attach attributes >>> to your function. >>> >>> ChrisA >>> >> >> Using a mutable object as a function default parameter value >> and changing it inside the function looks like a "trick" >> according to me. > > Sure. But you're contrasting this to a suggestion to literally just > attach attributes to a function. Python lets you actually do that. You > don't have to simulate the feature by creating a custom class and > making it callable - you just straight-up add attributes to a > function. Sure, what you suggested works, but there's no reason to. Functions are objects too! I regularly point-out this powerful facility, and its affordances, but... Yes, it's perfectly reasonable and even sensible to attach an attribute; BUT do many people expect to find such? If we were to collectively survey our own application code, how many examples would we find - as a percentage of such a corpus? Expectation: it would be v.v.low. Accordingly, whilst perfectly-implemented Python, and thus not a "trick", at least it is something that is easy for 'an ordinary person' to 'miss' (or misunderstand). The same cognitive logic applies to function parameters. Use of these is laced with 'gotchas', because people assume a different logic to/fail to properly understand Python. Hence such style decisions as 'use None, or not at all'. Personal opinion: I've never really liked closures, and have tended to associate them with other languages that actually need them in order to accomplish common-constructs or have them as a tenet/pillar of their language-design philosophy. Python does not, so... The choice of global variable should not be completely discounted - we have been given the global statement for a reason! However, its use in this case has been rightly-criticised (elsewhere) as an unnecessary 'pollution'. Which leaves us (or me!) with the overly-wordy wrapping-in-a-class option. The use of a class-attribute seems natural and is a well-worn pattern often used for counting instances, totalling a value across instances, or indeed limiting (usually to one, single) instantiations. Opinion: The function attribute is most efficient, in terms of programmer time or LoC. However the class-construct seems more-readily recognisable. That said, the OP's stated specification is to limit the depth of a stack. Many would have implemented the stack as a (derived) class, and thus adding a class-attribute control-variable would become only part of a wider whole - rather than the class being created merely to replace a simpler and more-concise function. Contrarily, if we (all) use function-attributes and enjoy the simplicity and power justifying the reasons they were given to us, they would become second-nature to code AND to read! -- Regards =dn From rosuav at gmail.com Fri May 1 19:30:59 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 May 2020 09:30:59 +1000 Subject: Function to avoid a global variable In-Reply-To: References: <5ea7d268$0$5889$426a74cc@news.free.fr> <5ea7da2d$0$15172$426a74cc@news.free.fr> Message-ID: On Sat, May 2, 2020 at 9:14 AM DL Neil via Python-list wrote: > > On 28/04/20 7:36 PM, Chris Angelico wrote: > >>> "Best"? Not sure about that. Functions are first-class objects in > >>> Python, so a function *is* a callable object. You don't have to create > >>> a custom class with a call method just to be able to attach attributes > >>> to your function. > >>> > >>> ChrisA > >>> > >> > >> Using a mutable object as a function default parameter value > >> and changing it inside the function looks like a "trick" > >> according to me. > > > > Sure. But you're contrasting this to a suggestion to literally just > > attach attributes to a function. Python lets you actually do that. You > > don't have to simulate the feature by creating a custom class and > > making it callable - you just straight-up add attributes to a > > function. Sure, what you suggested works, but there's no reason to. > > > Functions are objects too! I regularly point-out this powerful facility, > and its affordances, but... > > > Yes, it's perfectly reasonable and even sensible to attach an attribute; > BUT do many people expect to find such? If we were to collectively > survey our own application code, how many examples would we find - as a > percentage of such a corpus? > > Expectation: it would be v.v.low. Accordingly, whilst > perfectly-implemented Python, and thus not a "trick", at least it is > something that is easy for 'an ordinary person' to 'miss' (or > misunderstand). > One of the problems with the use of function attributes is that there's no way to say "this function". You have to use its name. Otherwise, it would be easy to write self-contained idioms such as static variables or omitted arg detection without the risk of polluting the namespace: def some_function(x, y, z=object()): if z is me.__defaults__[0]: z = x + y ... def static(**kw): def deco(f): for name, initial in kw.items(): setattr(f, name, initial) return f return deco @static(called=0) def other_function(): me.called += 1 ... Obviously the name "me" can't be used, as it'd break a bunch of code, but conceptually this would be incredibly helpful. It'd also be a reliable idiom for recursion optimization - any "me()" is guaranteed to be recursion and may potentially give info to an optimizer. Perhaps, if Python had a way to identify the current function, it would feel less odd to attach attributes to it. ChrisA From bob at mellowood.ca Fri May 1 20:00:47 2020 From: bob at mellowood.ca (Bob van der Poel) Date: Fri, 1 May 2020 17:00:47 -0700 Subject: Function to avoid a global variable In-Reply-To: References: <5ea7d268$0$5889$426a74cc@news.free.fr> <5ea7da2d$0$15172$426a74cc@news.free.fr> Message-ID: I still think that the use of a keyword like "static" would be easiest. def foo(arg): static counter = 0 counter += 1 if counter ... And in this case static just means that it's a variable only readable inside foo() and it should maintain it's value between calls. A "global" without the name pollution. Or is this too simple .... ??? On Fri, May 1, 2020 at 4:30 PM Chris Angelico wrote: > On Sat, May 2, 2020 at 9:14 AM DL Neil via Python-list > wrote: > > > > On 28/04/20 7:36 PM, Chris Angelico wrote: > > >>> "Best"? Not sure about that. Functions are first-class objects in > > >>> Python, so a function *is* a callable object. You don't have to > create > > >>> a custom class with a call method just to be able to attach > attributes > > >>> to your function. > > >>> > > >>> ChrisA > > >>> > > >> > > >> Using a mutable object as a function default parameter value > > >> and changing it inside the function looks like a "trick" > > >> according to me. > > > > > > Sure. But you're contrasting this to a suggestion to literally just > > > attach attributes to a function. Python lets you actually do that. You > > > don't have to simulate the feature by creating a custom class and > > > making it callable - you just straight-up add attributes to a > > > function. Sure, what you suggested works, but there's no reason to. > > > > > > Functions are objects too! I regularly point-out this powerful facility, > > and its affordances, but... > > > > > > Yes, it's perfectly reasonable and even sensible to attach an attribute; > > BUT do many people expect to find such? If we were to collectively > > survey our own application code, how many examples would we find - as a > > percentage of such a corpus? > > > > Expectation: it would be v.v.low. Accordingly, whilst > > perfectly-implemented Python, and thus not a "trick", at least it is > > something that is easy for 'an ordinary person' to 'miss' (or > > misunderstand). > > > > One of the problems with the use of function attributes is that > there's no way to say "this function". You have to use its name. > Otherwise, it would be easy to write self-contained idioms such as > static variables or omitted arg detection without the risk of > polluting the namespace: > > def some_function(x, y, z=object()): > if z is me.__defaults__[0]: > z = x + y > ... > > def static(**kw): > def deco(f): > for name, initial in kw.items(): > setattr(f, name, initial) > return f > return deco > > @static(called=0) > def other_function(): > me.called += 1 > ... > > Obviously the name "me" can't be used, as it'd break a bunch of code, > but conceptually this would be incredibly helpful. It'd also be a > reliable idiom for recursion optimization - any "me()" is guaranteed > to be recursion and may potentially give info to an optimizer. > > Perhaps, if Python had a way to identify the current function, it > would feel less odd to attach attributes to it. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From PythonList at DancesWithMice.info Fri May 1 20:50:11 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 2 May 2020 12:50:11 +1200 Subject: Function to avoid a global variable In-Reply-To: References: <5ea7d268$0$5889$426a74cc@news.free.fr> <5ea7da2d$0$15172$426a74cc@news.free.fr> Message-ID: <435a3d47-419a-718b-b9e2-29994357d36b@DancesWithMice.info> On 2/05/20 11:30 AM, Chris Angelico wrote: > On Sat, May 2, 2020 at 9:14 AM DL Neil via Python-list > wrote: >> >> On 28/04/20 7:36 PM, Chris Angelico wrote: >>>>> "Best"? Not sure about that. Functions are first-class objects in >>>>> Python, so a function *is* a callable object. You don't have to create >>>>> a custom class with a call method just to be able to attach attributes >>>>> to your function. >>>>> >>>>> ChrisA >>>>> >>>> >>>> Using a mutable object as a function default parameter value >>>> and changing it inside the function looks like a "trick" >>>> according to me. >>> >>> Sure. But you're contrasting this to a suggestion to literally just >>> attach attributes to a function. Python lets you actually do that. You >>> don't have to simulate the feature by creating a custom class and >>> making it callable - you just straight-up add attributes to a >>> function. Sure, what you suggested works, but there's no reason to. >> >> >> Functions are objects too! I regularly point-out this powerful facility, >> and its affordances, but... >> >> >> Yes, it's perfectly reasonable and even sensible to attach an attribute; >> BUT do many people expect to find such? If we were to collectively >> survey our own application code, how many examples would we find - as a >> percentage of such a corpus? >> >> Expectation: it would be v.v.low. Accordingly, whilst >> perfectly-implemented Python, and thus not a "trick", at least it is >> something that is easy for 'an ordinary person' to 'miss' (or >> misunderstand). >> > > One of the problems with the use of function attributes is that > there's no way to say "this function". You have to use its name. > Otherwise, it would be easy to write self-contained idioms such as > static variables or omitted arg detection without the risk of > polluting the namespace: > > def some_function(x, y, z=object()): > if z is me.__defaults__[0]: > z = x + y > ... > > def static(**kw): > def deco(f): > for name, initial in kw.items(): > setattr(f, name, initial) > return f > return deco > > @static(called=0) > def other_function(): > me.called += 1 > ... > > Obviously the name "me" can't be used, as it'd break a bunch of code, > but conceptually this would be incredibly helpful. It'd also be a > reliable idiom for recursion optimization - any "me()" is guaranteed > to be recursion and may potentially give info to an optimizer. > > Perhaps, if Python had a way to identify the current function, it > would feel less odd to attach attributes to it. The trouble is, functions seem to have an existential crisis: they know their own __name__ but have no sense of self! However, all is not lost because they are still very __func__-y. (apologies to anyone reading this whilst drinking) Unfortunately, Shakespeare is not the only one to ask: what's in a name, Rosie? >>> def double( x ): ... return x + x ... >>> double( 2 ) 4 >>> double.__name__ 'double' ### so-far, so-good - but let's pick-up the pace: >>> pasodoble = double >>> pasodoble( 2 ) 4 >>> pasodoble.__name__ 'double' ### You're so tired (from working quickly, perhaps) that you can't even remember your own __name__? (by extrapolation, I estimate; but you (@Chris) will no doubt, educate) I'm assuming this has something to do with "decorators"? In relation to the wider part of the problem-mentioned, a class is instantiated to become a second, and separate-but-linked, object. Whereas the two function-names are merely multiple labels to the same object (and id()): >>> pasodoble >>> double ### Whereas:- >>> class C(): ... '''Docstring that says nothing about a class that does just as much.''' ... >>> c = C() >>> C.__name__ 'C' >>> c.__name__ Traceback (most recent call last): File "", line 1, in AttributeError: 'C' object has no attribute '__name__' ### Wait a minute! Have you forgotten your own name? ### What else don't you know? >>> c.self Traceback (most recent call last): File "", line 1, in AttributeError: 'C' object has no attribute 'self' >>> c.__doc__ 'Docstring that says nothing about a class that does nothing.' ### (yes, I know, *I* caused the first of these two!) ### However, they are separate entities. Proof: >>> id( C ) 94619010560432 >>> id(c) 140014684436880 Hence, being empowered to accomplish a lot more with instantiated classes. Although methods are merely functions, a method enjoys 'extra' by virtue of being an attribute of a class's instance and being able to call-upon further attributes within the same namespace. -- Regards =dn From PythonList at DancesWithMice.info Fri May 1 21:06:50 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 2 May 2020 13:06:50 +1200 Subject: Function to avoid a global variable In-Reply-To: References: <5ea7d268$0$5889$426a74cc@news.free.fr> <5ea7da2d$0$15172$426a74cc@news.free.fr> Message-ID: On 2/05/20 12:00 PM, Bob van der Poel wrote: > I still think that the use of a keyword like "static" would be easiest. > > def foo(arg): > static counter = 0 > counter += 1 > if counter ... > > And in this case static just means that it's a variable only readable > inside foo() and it should maintain it's value between calls. A "global" > without the name pollution. Or is this too simple .... ??? No, it's not "too simple" an example/request. Although they are often considered more complex than materials suitable for 'beginner' (?simple) training, generator functions (and async-gen-func-s) already offer this (without the static-statement) def gen( args ): counter = 0 while counter < max_depth: yield counter counter will retain its value ("maintain state") between iterations. -- Regards =dn From rahulgupta100689 at gmail.com Sat May 2 00:03:38 2020 From: rahulgupta100689 at gmail.com (Rahul Gupta) Date: Fri, 1 May 2020 21:03:38 -0700 (PDT) Subject: error in CSV resetting with seek(0) Message-ID: <423cfbe8-a338-43ba-a3a0-e7692960fc41@googlegroups.com> consider the following code import csv import numpy as np with open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file1, open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file2: csv_reader1 = csv.DictReader(csv_file1) csv_reader2 = csv.DictReader(csv_file2) filename = "cell_split_demo.csv" with open("D:\PHD\obranking\\cell_split_demo.csv", 'w') as csvfilew1: fields = (range(0, 300)) csvwriter1 = csv.DictWriter(csvfilew1, fieldnames=fields) csvwriter1.writeheader() for i, row in enumerate(csv_reader1): print(f"value_i({i}) label({row['label']})") for j, line in enumerate(csv_reader2): if j <= i: matrixrows[j] = [] if row['label'] != line['label']: print(f"value_j({j})Unequal label({line['label']})") else: print(f"value_j({j}) equal label({line['label']})") pass else: break csv_file2.seek(0) Here is some of the out_put samples value_i(0) label(BW) value_j(0) equal label(BW) value_i(1) label(BW) value_j(0) Unequal label(label) value_j(1) equal label(BW) value_i(2) label(BW) value_j(0) Unequal label(label) value_j(1) equal label(BW) value_j(2) equal label(BW) You can see for j=0 while i goes from 1 to n it is not able to acess line['label'] value. Kindly help what is wrong with this? From __peter__ at web.de Sat May 2 00:52:25 2020 From: __peter__ at web.de (Peter Otten) Date: Sat, 02 May 2020 06:52:25 +0200 Subject: error in CSV resetting with seek(0) References: <423cfbe8-a338-43ba-a3a0-e7692960fc41@googlegroups.com> Message-ID: Rahul Gupta wrote: > consider the following code > import csv > import numpy as np > > with open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file1, > open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file2: > csv_reader1 = csv.DictReader(csv_file1) > csv_reader2 = csv.DictReader(csv_file2) > > > filename = "cell_split_demo.csv" > with open("D:\PHD\obranking\\cell_split_demo.csv", 'w') as csvfilew1: > fields = (range(0, 300)) > csvwriter1 = csv.DictWriter(csvfilew1, fieldnames=fields) > csvwriter1.writeheader() > > for i, row in enumerate(csv_reader1): > print(f"value_i({i}) label({row['label']})") > for j, line in enumerate(csv_reader2): > if j <= i: > matrixrows[j] = [] > if row['label'] != line['label']: > print(f"value_j({j})Unequal > label({line['label']})") > else: > print(f"value_j({j}) equal > label({line['label']})") pass > else: > break > csv_file2.seek(0) > Here is some of the out_put samples > value_i(0) label(BW) > value_j(0) equal label(BW) > value_i(1) label(BW) > value_j(0) Unequal label(label) > value_j(1) equal label(BW) > value_i(2) label(BW) > value_j(0) Unequal label(label) > value_j(1) equal label(BW) > value_j(2) equal label(BW) > You can see for j=0 while i goes from 1 to n it is not able to acess > line['label'] value. Kindly help what is wrong with this? Without looking closely I would guess that seek(0) causes the reader to mistake the header for a data row. If your data fits into memory you can do rows = list(csv_reader1) for i, outer_row in enumerate(rows): ... for j, inner_row in enumerate(rows): ... With this aproach csv_reader2 is not needed at all. If that fails for lack of memory build a new csv_reader2 on every iteration csv_reader1 = csv.DictReader(csv_file1) for i, outer_row in enumerate(csv_reader1): csv_reader2 = csv.DictReader(csv_file2) ... for j, inner_row in enumerate(csv_reader2) ... csv_file2.seek(0) From PythonList at DancesWithMice.info Sat May 2 16:32:08 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 3 May 2020 08:32:08 +1200 Subject: OT-Comic: Tabs vs Spaces Message-ID: Is this the way to write Python Enhancement Proposals (PEPs)? eg https://www.python.org/dev/peps/pep-0008/#indentation TabError: inconsistent use of tabs and spaces in indentation https://www.geeksaresexy.net/2020/05/01/the-tab-club-comic/ -- Regards, =dn From rosuav at gmail.com Sat May 2 17:07:23 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 May 2020 07:07:23 +1000 Subject: OT-Comic: Tabs vs Spaces In-Reply-To: References: Message-ID: On Sun, May 3, 2020 at 6:33 AM DL Neil via Python-list wrote: > > Is this the way to write Python Enhancement Proposals (PEPs)? > eg https://www.python.org/dev/peps/pep-0008/#indentation > > TabError: inconsistent use of tabs and spaces in indentation > https://www.geeksaresexy.net/2020/05/01/the-tab-club-comic/ Well OBVIOUSLY the problem is that just four spaces tried to masquerade as a tab! ChrisA From PythonList at DancesWithMice.info Sat May 2 17:50:05 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 3 May 2020 09:50:05 +1200 Subject: Docs - beyond tabs, spaces, PEPs... Message-ID: <3f34a63a-4948-599d-b02a-b1706a9f152a@etelligence.info> To make-up to those people who frowned at the earlier OT-Comic post... There are changes in-the-wind, in the way Python should/could be documented. Currently, there is a difficulty in 'scaling' the documentation to cope with the growing range of language user-types, as well as keeping-up with new developments in the language, and providing documentation for different purposes. Possibilities for wider community involvement? https://pyfound.blogspot.com/2020/04/cpython-documentation-next-5-years.html -- Regards, =dn From PythonList at DancesWithMice.info Sat May 2 17:50:59 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 3 May 2020 09:50:59 +1200 Subject: OT-Comic: Tabs vs Spaces In-Reply-To: References: Message-ID: On 3/05/20 9:07 AM, Chris Angelico wrote: > On Sun, May 3, 2020 at 6:33 AM DL Neil via Python-list > wrote: >> >> Is this the way to write Python Enhancement Proposals (PEPs)? >> eg https://www.python.org/dev/peps/pep-0008/#indentation >> >> TabError: inconsistent use of tabs and spaces in indentation >> https://www.geeksaresexy.net/2020/05/01/the-tab-club-comic/ > > Well OBVIOUSLY the problem is that just four spaces tried to > masquerade as a tab! I suppose over-achievers like you want eight spaces? -- Regards =dn From rosuav at gmail.com Sat May 2 17:58:14 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 May 2020 07:58:14 +1000 Subject: OT-Comic: Tabs vs Spaces In-Reply-To: References: Message-ID: On Sun, May 3, 2020 at 7:55 AM DL Neil via Python-list wrote: > > On 3/05/20 9:07 AM, Chris Angelico wrote: > > On Sun, May 3, 2020 at 6:33 AM DL Neil via Python-list > > wrote: > >> > >> Is this the way to write Python Enhancement Proposals (PEPs)? > >> eg https://www.python.org/dev/peps/pep-0008/#indentation > >> > >> TabError: inconsistent use of tabs and spaces in indentation > >> https://www.geeksaresexy.net/2020/05/01/the-tab-club-comic/ > > > > Well OBVIOUSLY the problem is that just four spaces tried to > > masquerade as a tab! > > I suppose over-achievers like you want eight spaces? > Of course! Except when working with files created by Valve, where apparently the norm is four-space tabs and they use tabs to align the middles of lines. Although they get indentation wrong sometimes too, so I honestly don't know :) ChrisA From rahulgupta100689 at gmail.com Sat May 2 01:29:46 2020 From: rahulgupta100689 at gmail.com (Rahul Gupta) Date: Fri, 1 May 2020 22:29:46 -0700 (PDT) Subject: error in CSV resetting with seek(0) In-Reply-To: <423cfbe8-a338-43ba-a3a0-e7692960fc41@googlegroups.com> References: <423cfbe8-a338-43ba-a3a0-e7692960fc41@googlegroups.com> Message-ID: <4a91116c-e5f0-46af-8cf6-9da8599754c5@googlegroups.com> @peter Otten thanks From dycrulah2006 at gmail.com Sun May 3 00:32:01 2020 From: dycrulah2006 at gmail.com (Ajisekola Adeyemi) Date: Sun, 3 May 2020 05:32:01 +0100 Subject: Error 0x80070570 while installing Python. In-Reply-To: References: Message-ID: Good day sir. I tried several times to install the latest version of Python which I downloaded from python.org but I keep getting error 0x80070570. I have done Window Update. And I also downloaded lower version but the same error keep popping up. I am using Compaq mini laptop with Window 7(32bit). I will appreciate if you can assist me in solving this problem. Thanks. On Sun, May 3, 2020, 12:09 AM Ajisekola Adeyemi wrote: > Good day sir. I tried several times to install the latest version of > Python which I downloaded from python.org but I keep getting > error 0x80070570. I have done Window Update. And I also downloaded lower > version but the same error keep popping up. I am using Compaq mini laptop > with Window 7(32bit). > I will appreciate if you can assist me in solving this problem. Thanks. > From souvik.viksou at gmail.com Sun May 3 01:55:01 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sun, 3 May 2020 11:25:01 +0530 Subject: Error 0x80070570 while installing Python. In-Reply-To: References: Message-ID: This is a windows error not a python one. Check this article. https://www.lifewire.com/fix-error-0x80070570-4687271 Souvik flutter dev On Sun, May 3, 2020, 10:38 AM Ajisekola Adeyemi wrote: > Good day sir. I tried several times to install the latest version of Python > which I downloaded from python.org but I keep getting error 0x80070570. I > have done Window Update. And I also downloaded lower version but the same > error keep popping up. I am using Compaq mini laptop with Window 7(32bit). > I will appreciate if you can assist me in solving this problem. Thanks. > > On Sun, May 3, 2020, 12:09 AM Ajisekola Adeyemi > wrote: > > > Good day sir. I tried several times to install the latest version of > > Python which I downloaded from python.org but I keep getting > > error 0x80070570. I have done Window Update. And I also downloaded lower > > version but the same error keep popping up. I am using Compaq mini > laptop > > with Window 7(32bit). > > I will appreciate if you can assist me in solving this problem. Thanks. > > > -- > https://mail.python.org/mailman/listinfo/python-list > From aakashjana2002 at gmail.com Sun May 3 10:44:12 2020 From: aakashjana2002 at gmail.com (Aakash Jana) Date: Sun, 3 May 2020 20:14:12 +0530 Subject: Pip not working on windows Message-ID: I recently upgraded pip to version 20.1 and now whenever I try pup install on my PC I get the following error :- Fatal error in launcher : unable to create process using '"c:\python38\python.exe ' "c:\Python38\Scripts\pip.exe" : The system cannot find the file specified. But when I manually inspected the folder ? the files were there I even tried upgrading it by python -m pip install --upgrade pip which worked but I still can not use pip. From joepareti54 at gmail.com Sun May 3 12:08:58 2020 From: joepareti54 at gmail.com (joseph pareti) Date: Sun, 3 May 2020 18:08:58 +0200 Subject: Pip not working on windows In-Reply-To: References: Message-ID: are you doing *pip** install* from Windows cmd of from Anaconda prompt? I used the latter and it works Am So., 3. Mai 2020 um 16:48 Uhr schrieb Aakash Jana < aakashjana2002 at gmail.com>: > I recently upgraded pip to version 20.1 and now whenever I try pup install > on my PC I get the following error :- Fatal error in launcher : unable to > create process using '"c:\python38\python.exe ' > "c:\Python38\Scripts\pip.exe" : The system cannot find the file specified. > But when I manually inspected the folder ? the files were there I even > tried upgrading it by python -m pip install --upgrade pip which worked but > I still can not use pip. > -- > 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 aakashjana2002 at gmail.com Sun May 3 13:06:28 2020 From: aakashjana2002 at gmail.com (Aakash Jana) Date: Sun, 3 May 2020 22:36:28 +0530 Subject: Pip not working on windows In-Reply-To: References: Message-ID: Yes, I am! On Sun, 3 May 2020, 9:39 pm joseph pareti are you doing *pip** install* from Windows cmd of from Anaconda prompt? I > used the latter and it works > > Am So., 3. Mai 2020 um 16:48 Uhr schrieb Aakash Jana < > aakashjana2002 at gmail.com>: > >> I recently upgraded pip to version 20.1 and now whenever I try pup install >> on my PC I get the following error :- Fatal error in launcher : unable to >> create process using '"c:\python38\python.exe ' >> "c:\Python38\Scripts\pip.exe" : The system cannot find the file specified. >> But when I manually inspected the folder ? the files were there I even >> tried upgrading it by python -m pip install --upgrade pip which worked but >> I still can not use pip. >> -- >> 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 julianawaltermann11 at gmail.com Sun May 3 12:11:24 2020 From: julianawaltermann11 at gmail.com (julianawaltermann11 at gmail.com) Date: Sun, 3 May 2020 09:11:24 -0700 (PDT) Subject: Consumer trait recognition Message-ID: <04f15248-27d5-43bb-bb64-821c87a6dc35@googlegroups.com> Dear Community, I constructed a lexicon for words that show how different words are linked to consumer traits and motivations (e.g. Achievement and Power Motivation). Now I have collected a large amount of online customer reviews and want to match each review with the word definitions of the consumer traits and motivations in order to identify whether they influence the consumer preferences. How do I that? Both the lexicons and the customer reviews are csv files. Thank you in advance! Best regards, JW From ozstar1 at gmail.com Sun May 3 21:33:17 2020 From: ozstar1 at gmail.com (ozstar1 at gmail.com) Date: Sun, 3 May 2020 18:33:17 -0700 (PDT) Subject: Is there anything in the script which could cause it to not run its full course please? Message-ID: Hi, A nooby here and I could do with some help in finding out what, if anything, is wrong with the script Is there anything in this script that could cause the stream to stop before the allocated time? For example the time.txt file which gives the times to the script, shows the time to start and run, like this.. 04-05-2020 09:30:00 40 04-05-2020 12:30:00 40 04-05-2020 15:30:00 40 04-05-2020 22:30:00 40 When I run the the stream manually not using the script, it runs the full 40 mins length however as soon as I use the script, it stops the stream a few minutes in. It is not any specific time, just a random time. I see my two options are.. something in the script or something going on in the PC background, although it doesn't do it when I don't use the script. Please help and I am not sure where else to go as it does seem like a script or python event. Thank you --------------------- import time import datetime import sys from pynput.mouse import Button, Controller class Autostreaming(object): def __init__(self): self.mouse = Controller() pass def startstreaming(self): #load text file time_file = open("time.txt", "r") for date_time_duration in time_file.readlines(): input_date,input_time,input_duration=date_time_duration.split(' ') current_datetime = datetime.datetime.now() current_date = current_datetime.strftime('%d-%m-%Y') if(input_date>=current_date): while(True): _time = datetime.datetime.now() current_time= _time.strftime('%H:%M:%S') if(input_time==current_time): #self.mouse.position = (1912,594) #self.mouse.click(Button.left,1) #time.sleep(2) self.mouse.position = (1250,710) self.mouse.click(Button.left,1) time.sleep(2) self.mouse.position = (1824,1136) self.mouse.click(Button.left,1) time.sleep(2) self.mouse.position = (1587,37) self.mouse.click(Button.left,1) time.sleep(2) self.mouse.position = (1250,710) self.mouse.click(Button.left,1) time.sleep(2) #self.mouse.position = (1202, 806) #self.mouse.click(Button.left,1) print("streaming........") time.sleep(int(input_duration)*60)#please put your streaming function self.mouse.position = (1824,1136) self.mouse.click(Button.left,1) break elif(input_time>current_time): print('Waiting for the next stream to start at {}'.format(input_time)+" hrs on {}".format(input_date)) time.sleep(1) continue elif(input_date>current_date and input_time References: Message-ID: <6935f8dc-38aa-68d5-ba5d-1429fa8d10b4@dewhirst.com.au> On 4/05/2020 12:44 am, Aakash Jana wrote: > I recently upgraded pip to version 20.1 and now whenever I try pup install > on my PC I get the following error :- Fatal error in launcher : unable to > create process using '"c:\python38\python.exe ' > "c:\Python38\Scripts\pip.exe" : The system cannot find the file specified. > But when I manually inspected the folder ? the files were there I even > tried upgrading it by python -m pip install --upgrade pip which worked but > I still can not use pip. Just thoughtI'd try it on my Windows PC ... (xxex3) D:\Users\mike\envs\xxex3>pip install --upgrade -r requirements/test.txt Collecting bleach ? Downloading bleach-3.1.5-py2.py3-none-any.whl (151 kB) ???? |????????????????????????????????| 151 kB 2.2 MB/s Collecting pytz ? Downloading pytz-2020.1-py2.py3-none-any.whl (510 kB) ???? |????????????????????????????????| 510 kB 3.3 MB/s Collecting requests ? Using cached requests-2.23.0-py2.py3-none-any.whl (58 kB) Requirement already up-to-date: cirpy in d:\users\mike\envs\xxex3\lib\site-packages (from -r requirements\../ssds/requirements/base.txt (line 4)) (1.0.2) Collecting docutils ? Using cached docutils-0.16-py2.py3-none-any.whl (548 kB) Collecting django==2.2.12 ? Using cached Django-2.2.12-py3-none-any.whl (7.5 MB) Collecting pwned-passwords-django ? Using cached pwned_passwords_django-1.4-py3-none-any.whl (5.8 kB) Collecting django-csp ? Downloading django_csp-3.6-py2.py3-none-any.whl (17 kB) Collecting django-referrer-policy ? Downloading django-referrer-policy-1.0.tar.gz (3.6 kB) Collecting stripe ? Downloading stripe-2.47.0-py2.py3-none-any.whl (203 kB) ???? |????????????????????????????????| 203 kB 6.8 MB/s Collecting coverage ? Downloading coverage-5.1-cp37-cp37m-win_amd64.whl (205 kB) ???? |????????????????????????????????| 205 kB 6.4 MB/s Processing d:\users\mike\downloads\psycopg2-2.7.7-cp37-cp37m-win_amd64.whl Processing d:\users\mike\downloads\pillow-6.0.0-cp37-cp37m-win_amd64.whl Collecting django-debug-toolbar ? Using cached django_debug_toolbar-2.2-py3-none-any.whl (198 kB) Collecting packaging ? Downloading packaging-20.3-py2.py3-none-any.whl (37 kB) Requirement already satisfied, skipping upgrade: webencodings in d:\users\mike\envs\xxex3\lib\site-packages (from bleach->-r requirements\../ssds/requirements/base.txt (line 1)) (0.5.1) Requirement already satisfied, skipping upgrade: six>=1.9.0 in d:\users\mike\envs\xxex3\lib\site-packages (from bleach->-r requirements\../ssds/requirements/base.txt (line 1)) (1.12.0) Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in d:\users\mike\envs\xxex3\lib\site-packages (from requests->-r requirements\../ssds/requirements/base.txt (line 3)) (2019.3.9) Requirement already satisfied, skipping upgrade: chardet<4,>=3.0.2 in d:\users\mike\envs\xxex3\lib\site-packages (from requests->-r requirements\../ssds/requirements/base.txt (line 3)) (3.0.4) Requirement already satisfied, skipping upgrade: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in d:\users\mike\envs\xxex3\lib\site-packages (from requests->-r requirements\../ssds/requirements/base.txt (line 3)) (1.24.2) Requirement already satisfied, skipping upgrade: idna<3,>=2.5 in d:\users\mike\envs\xxex3\lib\site-packages (from requests->-r requirements\../ssds/requirements/base.txt (line 3)) (2.8) Requirement already satisfied, skipping upgrade: sqlparse in d:\users\mike\envs\xxex3\lib\site-packages (from django==2.2.12->-r requirements\../ssds/requirements/base.txt (line 6)) (0.3.0) Collecting pyparsing>=2.0.2 ? Downloading pyparsing-2.4.7-py2.py3-none-any.whl (67 kB) ???? |????????????????????????????????| 67 kB 4.5 MB/s Installing collected packages: pyparsing, packaging, bleach, pytz, requests, docutils, django, pwned-passwords-django, django-csp, django-referrer-policy, stripe, coverage, psycopg2, Pillow, django-debug-toolbar ? Attempting uninstall: bleach ??? Found existing installation: bleach 3.1.0 ??? Uninstalling bleach-3.1.0: ????? Successfully uninstalled bleach-3.1.0 ? Attempting uninstall: pytz ??? Found existing installation: pytz 2019.1 ??? Uninstalling pytz-2019.1: ????? Successfully uninstalled pytz-2019.1 ? Attempting uninstall: requests ??? Found existing installation: requests 2.21.0 ??? Uninstalling requests-2.21.0: ????? Successfully uninstalled requests-2.21.0 ? Attempting uninstall: docutils ??? Found existing installation: docutils 0.14 ??? Uninstalling docutils-0.14: ????? Successfully uninstalled docutils-0.14 ? Attempting uninstall: django ??? Found existing installation: Django 2.2.10 ??? Uninstalling Django-2.2.10: ????? Successfully uninstalled Django-2.2.10 ? Attempting uninstall: pwned-passwords-django ??? Found existing installation: pwned-passwords-django 1.3.1 ??? Uninstalling pwned-passwords-django-1.3.1: ????? Successfully uninstalled pwned-passwords-django-1.3.1 ??? Running setup.py install for django-referrer-policy ... done ? Attempting uninstall: stripe ??? Found existing installation: stripe 2.29.0 ??? Uninstalling stripe-2.29.0: ????? Successfully uninstalled stripe-2.29.0 ? Attempting uninstall: coverage ??? Found existing installation: coverage 4.5.3 ??? Uninstalling coverage-4.5.3: ????? Successfully uninstalled coverage-4.5.3 ? Attempting uninstall: psycopg2 ??? Found existing installation: psycopg2 2.8.4 ??? Uninstalling psycopg2-2.8.4: ????? Successfully uninstalled psycopg2-2.8.4 ? Attempting uninstall: Pillow ??? Found existing installation: Pillow 6.0.0 ??? Uninstalling Pillow-6.0.0: ????? Successfully uninstalled Pillow-6.0.0 Successfully installed Pillow-6.0.0 bleach-3.1.5 coverage-5.1 django-2.2.12 django-csp-3.6 django-debug-toolbar-2.2 django-referrer-policy-1.0 docutils-0.16 packaging-20.3 psycopg2-2.7.7 pwned-passwords-django-1.4 pyparsing-2.4.7 pytz-2020.1 requests-2.23.0 stripe-2.47.0 WARNING: You are using pip version 20.0.2; however, version 20.1 is available. You should consider upgrading via the 'd:\users\mike\envs\xxex3\scripts\python.exe -m pip install --upgrade pip' command. (xxex3) D:\Users\mike\envs\xxex3>pip install --upgrade pip Collecting pip ? Downloading pip-20.1-py2.py3-none-any.whl (1.5 MB) ???? |????????????????????????????????| 1.5 MB 1.7 MB/s Installing collected packages: pip ? Attempting uninstall: pip ??? Found existing installation: pip 20.0.2 ??? Uninstalling pip-20.0.2: ????? Successfully uninstalled pip-20.0.2 ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'D:\\users\\mike\\temp\\pip-uninstall-b1k082p9\\pip.exe' Consider using the `--user` option or check the permissions. # so I tried again using the advice a few lines above in the WARNING and ... (xxex3) D:\Users\mike\envs\xxex3>d:\users\mike\envs\xxex3\scripts\python.exe -m pip install --upgrade pip Requirement already up-to-date: pip in d:\users\mike\envs\xxex3\lib\site-packages (20.1) Could not build wheels for pip, since package 'wheel' is not installed. (xxex3) D:\Users\mike\envs\xxex3> Which all means there are problems with pip on Windows if you don't follow the documented advice very carefully. The reason is that Windows is not designed for developers and pip has to turn itself inside out for Windows compared with Linux pip. Just in case you didn't notice, I did all the above in a virtualenv. Here is the base Python pip ... C:\Python36>python.exe -m pip install --upgrade pip Collecting pip ? Using cached https://files.pythonhosted.org/packages/54/2e/df11ea7e23e7e761d484ed3740285a34e38548cf2bad2bed3dd5768ec8b9/pip-20.1-py2.py3-none-any.whl packaging 19.0 requires six, which is not installed. mike 0.3.5 requires six, which is not installed. livereload 2.6.0 requires six, which is not installed. Installing collected packages: pip ? Found existing installation: pip 10.0.1 ??? Uninstalling pip-10.0.1: ????? Successfully uninstalled pip-10.0.1 Successfully installed pip-20.1 So I had better install six ... but to use the correct pip and python I need to be specific ... C:\Python36>dir scripts ?Volume in drive C is OS ?Volume Serial Number is 1CCB-177E ?Directory of C:\Python36\scripts 04/05/2020? 11:16 AM??? ????????? . 04/05/2020? 11:16 AM??? ????????? .. 04/12/2019? 05:16 PM?????????? 102,761 easy_install-3.6.exe 04/12/2019? 05:16 PM?????????? 102,761 easy_install.exe 04/05/2020? 11:16 AM?????????? 106,336 pip.exe 04/05/2020? 11:16 AM?????????? 106,336 pip3.6.exe 04/05/2020? 11:16 AM?????????? 106,336 pip3.exe ?????????????? 5 File(s)??????? 524,530 bytes ?????????????? 2 Dir(s)? 69,478,674,432 bytes free C:\Python36>cd .. C:\>python36\scripts\pip install six Collecting six ? Using cached six-1.14.0-py2.py3-none-any.whl (10 kB) Installing collected packages: six Successfully installed six-1.14.0 C:\> I have to use Python36 because that is the version supplied in Ubuntu 18.04 which I use for our production server. It does work and you should understand that Microsoft does not go out of its way to make things easy for anyone who doesn't do things their way. Cheers Mike From bjlockie021 at gmail.com Sun May 3 22:38:06 2020 From: bjlockie021 at gmail.com (James Smith) Date: Sun, 3 May 2020 19:38:06 -0700 (PDT) Subject: =+ for strings Message-ID: <331e6e38-f404-42d3-82cc-a4d94ff4f8cf@googlegroups.com> I tried: dt=+"{:02d}".format(day) but I got: dt=+"{:02d}".format(day) TypeError: bad operand type for unary +: 'str' This works: dt=dt+"{:02d}".format(day) Why can't I do the shortcut on strings? From rosuav at gmail.com Sun May 3 22:43:25 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 May 2020 12:43:25 +1000 Subject: =+ for strings In-Reply-To: <331e6e38-f404-42d3-82cc-a4d94ff4f8cf@googlegroups.com> References: <331e6e38-f404-42d3-82cc-a4d94ff4f8cf@googlegroups.com> Message-ID: On Mon, May 4, 2020 at 12:41 PM James Smith wrote: > > I tried: > dt=+"{:02d}".format(day) > but I got: > dt=+"{:02d}".format(day) > TypeError: bad operand type for unary +: 'str' > > This works: > dt=dt+"{:02d}".format(day) > > Why can't I do the shortcut on strings? The shortcut is += not =+ :) ChrisA From 2QdxY4RzWzUUiLuE at potatochowder.com Sun May 3 22:49:23 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Sun, 3 May 2020 22:49:23 -0400 Subject: =+ for strings In-Reply-To: <331e6e38-f404-42d3-82cc-a4d94ff4f8cf@googlegroups.com> References: <331e6e38-f404-42d3-82cc-a4d94ff4f8cf@googlegroups.com> Message-ID: <20200503224923.e27bdd0ccbd19c0ac9b60fb6@potatochowder.com> On Sun, 3 May 2020 19:38:06 -0700 (PDT) James Smith wrote: > I tried: > dt=+"{:02d}".format(day) > but I got: > dt=+"{:02d}".format(day) > TypeError: bad operand type for unary +: 'str' > > This works: > dt=dt+"{:02d}".format(day) > > Why can't I do the shortcut on strings? ITYM: dt += "{:02d}".format(day) Note += rather than =+ (which is parsed as an assignment operator followed by a unary plus operator). -- ?Atoms are not things.? ? Werner Heisenberg Dan Sommers, http://www.tombstonezero.net/dan From adam.preble at gmail.com Mon May 4 02:00:22 2020 From: adam.preble at gmail.com (Adam Preble) Date: Sun, 3 May 2020 23:00:22 -0700 (PDT) Subject: Import machinery for extracting non-modules from modules (not using import-from) Message-ID: <25f483b4-54ee-4c31-86e0-bf1cd6a38fb9@googlegroups.com> The (rightful) obsession with modules in PEP-451 and the import machinery hit me with a gotcha when I was trying to implement importing .NET stuff that mimicked IronPython and Python.NET in my interpreter project. The meat of the question: Is it important that the spec loader actually return a module? Can it just return... stuff? I know a from X import Y is the normal means for this, but if the loader knows better, can it just do it? A normal process is something like: import X A bunch of finders line up to see if they know anything about X. If they don't, they return None. Assume it's found. That finder will return a module spec for how to load it. A little later, that spec is instructed to load the module. If X wasn't a module, you can expect to see something like: ModuleNotFoundError: No module named 'X'; 'X' is not a package ...you were supposed to do 'from something import X'. I'm actually trying to figure out if there's a way with normal Python modules where I can even be in a situation to just blandly trying to import X without a package in front of it. With IronPython--and I'm pretty sure Python.NET, there are situations where you CAN do this. The paths for .NET 'packages' are the .NET namespaces (a slightly different usage of the term). Say I want the machine name. It would be typical to get that with System.Environment.MachineName. MachineName is a static field in Environment. System.Environment is a namespace in mscorlib (in classic .NET framework). The .NET namespace can be null. In that case it's just in the root namespace or something. Let's say I have a .dll I've made known to IronPython or Python.NET using its clr.AddReference, and I want to toy with some class defined without a namespace called "Crazy." This is totally fine: import Crazy I really can't follow what either one is doing here, and I don't know how well they're even latching on the PEP-451. So there's the main question: is it important that the spec loader actually return a module? Can it just return... stuff? I know a from X import Y is the normal means for this, but if the loader knows better, can it just do it? From ast at invalid Mon May 4 09:20:37 2020 From: ast at invalid (ast) Date: Mon, 4 May 2020 15:20:37 +0200 Subject: Problem with doctest Message-ID: <5eb016a6$0$5894$426a34cc@news.free.fr> Hello doctest of the sample function funct() doesn't works because flag used by funct() is the one defined in first line "flag = True" and not the one in the doctest code ">>> flag = False". Any work around known ? flag = True # <- funct() always use this one def funct(): """ Code for doctest: >>> flag = True >>> funct() 'Yes' >>> flag = False # <- Ignored unfortunalely >>> funct() 'No' """ if flag: return "Yes" else: return "No" if __name__ == "__main__": import doctest doctest.testmod() Failed example: funct() Expected: 'No' Got: 'Yes' ********************************************************************** 1 items had failures: 1 of 4 in __main__.funct ***Test Failed*** 1 failures. From __peter__ at web.de Mon May 4 11:33:46 2020 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 May 2020 17:33:46 +0200 Subject: Problem with doctest References: <5eb016a6$0$5894$426a34cc@news.free.fr> Message-ID: Unknown wrote: > Hello > > doctest of the sample function funct() doesn't works > because flag used by funct() is the one defined in > first line "flag = True" and not the one in the > doctest code ">>> flag = False". > > Any work around known ? You can import the module where funct() is defined: def funct() """ >>> import module >>> module.flag = False >>> funct() 'No' """ ... > flag = True # <- funct() always use this one > > def funct(): > """ > Code for doctest: > > >>> flag = True > >>> funct() > 'Yes' > >>> flag = False # <- Ignored unfortunalely > >>> funct() > 'No' > """ > > if flag: > return "Yes" > else: > return "No" > > if __name__ == "__main__": > import doctest > doctest.testmod() > > > > Failed example: > funct() > Expected: > 'No' > Got: > 'Yes' > ********************************************************************** > 1 items had failures: > 1 of 4 in __main__.funct > ***Test Failed*** 1 failures. From David.Raymond at tomtom.com Mon May 4 11:35:26 2020 From: David.Raymond at tomtom.com (David Raymond) Date: Mon, 4 May 2020 15:35:26 +0000 Subject: Is there anything in the script which could cause it to not run its full course please? In-Reply-To: References: Message-ID: Not necessarily the cause of your problem, but if you're going to compare dates it should be as objects, or as text as year-month-day. Here you're comparing dates as text in day-month-year format. So January first 9999 comes before May 4th 2020 "01-01-9999" < "04-05-2020" ... 04-05-2020 09:30:00 40 04-05-2020 12:30:00 40 04-05-2020 15:30:00 40 04-05-2020 22:30:00 40 ... input_date,input_time,input_duration=date_time_duration.split(' ') current_datetime = datetime.datetime.now() current_date = current_datetime.strftime('%d-%m-%Y') if(input_date>=current_date): while(True): ... From dieter at handshake.de Mon May 4 12:41:01 2020 From: dieter at handshake.de (Dieter Maurer) Date: Mon, 4 May 2020 18:41:01 +0200 Subject: Problem with doctest In-Reply-To: <5eb016a6$0$5894$426a34cc@news.free.fr> References: <5eb016a6$0$5894$426a34cc@news.free.fr> Message-ID: <24240.17821.33640.423517@ixdm.fritz.box> ast wrote at 2020-5-4 15:20 +0200: >doctest of the sample function funct() doesn't works >because flag used by funct() is the one defined in >first line "flag = True" and not the one in the >doctest code ">>> flag = False". > >Any work around known ? > > >flag = True # <- funct() always use this one > >def funct(): > """ > Code for doctest: > > >>> flag = True > >>> funct() > 'Yes' > >>> flag = False # <- Ignored unfortunalely > >>> funct() > 'No' > """ > > if flag: > return "Yes" > else: > return "No" > >if __name__ == "__main__": > import doctest > doctest.testmod() > > > >Failed example: > funct() >Expected: > 'No' >Got: > 'Yes' >********************************************************************** >1 items had failures: > 1 of 4 in __main__.funct >***Test Failed*** 1 failures. The "flag" used inside "funct" refers to the definition in "funct.__globals__" (i.e. the module where "funct" is defined in). As your observation shows, this is not the "flag" changed by the doctest. The doctest behavior reflects the use in a function or a foreign module (rather than a use at the top level of the module defining "funct"). From john_ladasky at sbcglobal.net Mon May 4 15:26:35 2020 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Mon, 4 May 2020 12:26:35 -0700 (PDT) Subject: Multiprocessing vs. concurrent.futures, Linux vs. Windows Message-ID: Several years ago I built an application using multiprocessing. It only needed to work in Linux. I got it working fine. At the time, concurrent.futures did not exist. My current project is an application which includes a PyQt5 GUI, and a live video feed with some real-time image processing. Running all this in one process resulted in unacceptable performance, so I'm trying to move all of the heavy video work into its own process. I only need to define one child process. I don't need a Pool. The child Process can run indefinitely, and it will communicate multiple messages to the main process using a Pipe. I built a working example in Linux, but it hangs in Windows. I built a minimum example. My problem has nothing to do with PyQt. In Windows, my example hangs when I try to create the child Process. Code: import os from multiprocessing import Pipe, Process def child_app(): inlet.send("Child process id = {}".format(os.getpid())) if __name__ == "__main__": outlet, inlet = Pipe() print("Parent process id =", os.getpid()) child_process = Process(target=child_app) # Windows hangs here child_process.start() print(outlet.recv()) child_process.join() child_process.close() print("Program complete.") I'm working in Python 3.7.6 on Windows 10, and 3.7.5 on Ubuntu Linux 19.10. I am reading through the multiprocessing documentation, and I'm guessing that I've run into a problem with spawning vs. forking a new Process. The former is the Windows default, and the latter is the Posix default. Before I dig too deeply, I am wondering whether this cross-platform problem is something that concurrent.futures might handle automatically. The concurrent API looks foreign to me. But if it is meant to replace multiprocessing, I suppose this would be a good time for me to learn it. Thanks for any advice and suggestions! From genc061907 at hotmail.com Mon May 4 06:15:37 2020 From: genc061907 at hotmail.com (=?iso-8859-3?Q?H=DCSEY=A9N_KO=C7?=) Date: Mon, 4 May 2020 10:15:37 +0000 Subject: phyton hata Message-ID: Phyton 3.8.2 versiyonu bilgisayar?ma indirdim fakat sorunlar ile kar??la?t?n?z diyerek hata veriyor Windows 10 i?in Posta ile g?nderildi From jorge.conforte at inpe.br Mon May 4 14:14:14 2020 From: jorge.conforte at inpe.br (J Conrado) Date: Mon, 4 May 2020 15:14:14 -0300 Subject: naN values Message-ID: <8076250f-f1d0-5b91-e214-f6befc2b2fad@inpe.br> Hi, I have a 2d array and I would? how can I replace NaN values for example with -9999 value or other value. Thank, Conrado From __peter__ at web.de Mon May 4 17:45:33 2020 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 May 2020 23:45:33 +0200 Subject: naN values References: <8076250f-f1d0-5b91-e214-f6befc2b2fad@inpe.br> Message-ID: J Conrado wrote: > I have a 2d array and I would how can I replace NaN values for example > with -9999 value or other value. >>> a array([[ nan, 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., nan]]) >>> a[numpy.isnan(a)] = 42 >>> a array([[ 42., 1., 2., 3.], [ 4., 5., 6., 7.], [ 8., 9., 10., 42.]]) From ozstar1 at gmail.com Mon May 4 18:02:09 2020 From: ozstar1 at gmail.com (ozstar1 at gmail.com) Date: Mon, 4 May 2020 15:02:09 -0700 (PDT) Subject: Is there anything in the script which could cause it to not run its full course please? In-Reply-To: References: Message-ID: Many thanks for your help. It is really appreciated. I see both your points and maybe this is where my problems lays. If for example it starts (and it does) at 9.30am then the print is.. streaming.... It is supposed to wait for the 40 minutes, stop then print this.. Waiting for the next stream to start at 12:30 however I get this same message maybe 4 minutes in, not 40. I have checked for admin 'events' in Win10 1909 however there is nothing there, and the start menu has only 3 items, none that would effect this. The box doesn't have anything else running, as it is virtually dedicated to this streaming. It has two displays, one for the stream program and the other for the dos box, so nothing is on the streamer screen where the mouse clicks. Once again many thanks and let me digest your info. From tjreedy at udel.edu Mon May 4 16:43:56 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 4 May 2020 16:43:56 -0400 Subject: Multiprocessing vs. concurrent.futures, Linux vs. Windows In-Reply-To: References: Message-ID: On 5/4/2020 3:26 PM, John Ladasky wrote: > Several years ago I built an application using multiprocessing. It only needed to work in Linux. I got it working fine. At the time, concurrent.futures did not exist. > > My current project is an application which includes a PyQt5 GUI, and a live video feed with some real-time image processing. Running all this in one process resulted in unacceptable performance, so I'm trying to move all of the heavy video work into its own process. I only need to define one child process. I don't need a Pool. The child Process can run indefinitely, and it will communicate multiple messages to the main process using a Pipe. > > I built a working example in Linux, but it hangs in Windows. I built a minimum example. My problem has nothing to do with PyQt. In Windows, my example hangs when I try to create the child Process. Code: > > > import os > from multiprocessing import Pipe, Process > > def child_app(): > inlet.send("Child process id = {}".format(os.getpid())) > > if __name__ == "__main__": > outlet, inlet = Pipe() > print("Parent process id =", os.getpid()) > child_process = Process(target=child_app) # Windows hangs here > child_process.start() > print(outlet.recv()) > child_process.join() > child_process.close() > print("Program complete.") > > > I'm working in Python 3.7.6 on Windows 10, and 3.7.5 on Ubuntu Linux 19.10. Does the minimal example in the doc work for you? (IE, do you only have a problem with Pipe?) from multiprocessing import Process def f(name): print('hello', name) if __name__ == '__main__': p = Process(target=f, args=('bob',)) p.start() p.join() How about the Pipe example? from multiprocessing import Process, Pipe def f(conn): conn.send([42, None, 'hello']) conn.close() if __name__ == '__main__': parent_conn, child_conn = Pipe() p = Process(target=f, args=(child_conn,)) p.start() print(parent_conn.recv()) # prints "[42, None, 'hello']" p.join() If this does not work on Windows, the example or doc should be changed. But I believe I tested it once. Note that unlike your code, the child_conn is sent as argument. The relation between the module code and child processes is different on Windows than *nix. From ozstar1 at gmail.com Mon May 4 20:17:02 2020 From: ozstar1 at gmail.com (ozstar1 at gmail.com) Date: Mon, 4 May 2020 17:17:02 -0700 (PDT) Subject: Is there anything in the script which could cause it to not run its full course please? In-Reply-To: References: Message-ID: <6a83a756-20d3-48f6-b506-b15d37f13870@googlegroups.com> On Tuesday, 5 May 2020 01:35:42 UTC+10, David Raymond wrote: > Not necessarily the cause of your problem, but if you're going to compare dates it should be as objects, or as text as year-month-day. Here you're comparing dates as text in day-month-year format. So January first 9999 comes before May 4th 2020 > > "01-01-9999" < "04-05-2020" > > ... > 04-05-2020 09:30:00 40 > 04-05-2020 12:30:00 40 > 04-05-2020 15:30:00 40 > 04-05-2020 22:30:00 40 > ... > input_date,input_time,input_duration=date_time_duration.split(' ') > current_datetime = datetime.datetime.now() > current_date = current_datetime.strftime('%d-%m-%Y') > if(input_date>=current_date): > while(True): > ... Thank you, see what you mean. I have corrected this now. From souvik.viksou at gmail.com Mon May 4 20:41:04 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Tue, 5 May 2020 06:11:04 +0530 Subject: phyton hata In-Reply-To: References: Message-ID: ne hatas? al?yorsun Souvik flutter dev On Tue, May 5, 2020, 1:28 AM H?SEY?N KO? wrote: > Phyton 3.8.2 versiyonu bilgisayar?ma indirdim fakat sorunlar ile > kar??la?t?n?z diyerek hata veriyor > > > Windows 10 i?in Posta ile > g?nderildi > > -- > https://mail.python.org/mailman/listinfo/python-list > From john_ladasky at sbcglobal.net Mon May 4 21:05:44 2020 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Mon, 4 May 2020 18:05:44 -0700 (PDT) Subject: Multiprocessing vs. concurrent.futures, Linux vs. Windows In-Reply-To: References: Message-ID: On Monday, May 4, 2020 at 4:09:53 PM UTC-7, Terry Reedy wrote: > On 5/4/2020 3:26 PM, John Ladasky wrote: > > Several years ago I built an application using multiprocessing. It only needed to work in Linux. I got it working fine. At the time, concurrent.futures did not exist. > > > > My current project is an application which includes a PyQt5 GUI, and a live video feed with some real-time image processing. Running all this in one process resulted in unacceptable performance, so I'm trying to move all of the heavy video work into its own process. I only need to define one child process. I don't need a Pool. The child Process can run indefinitely, and it will communicate multiple messages to the main process using a Pipe. > > > > I built a working example in Linux, but it hangs in Windows. I built a minimum example. My problem has nothing to do with PyQt. In Windows, my example hangs when I try to create the child Process. Code: > > > > > > import os > > from multiprocessing import Pipe, Process > > > > def child_app(): > > inlet.send("Child process id = {}".format(os.getpid())) > > > > if __name__ == "__main__": > > outlet, inlet = Pipe() > > print("Parent process id =", os.getpid()) > > child_process = Process(target=child_app) # Windows hangs here > > child_process.start() > > print(outlet.recv()) > > child_process.join() > > child_process.close() > > print("Program complete.") > > > > > > I'm working in Python 3.7.6 on Windows 10, and 3.7.5 on Ubuntu Linux 19.10. > > Does the minimal example in the doc work for you? > (IE, do you only have a problem with Pipe?) > > from multiprocessing import Process > > def f(name): > print('hello', name) > > if __name__ == '__main__': > p = Process(target=f, args=('bob',)) > p.start() > p.join() > > How about the Pipe example? > > from multiprocessing import Process, Pipe > > def f(conn): > conn.send([42, None, 'hello']) > conn.close() > > if __name__ == '__main__': > parent_conn, child_conn = Pipe() > p = Process(target=f, args=(child_conn,)) > p.start() > print(parent_conn.recv()) # prints "[42, None, 'hello']" > p.join() > > If this does not work on Windows, the example or doc should be changed. > But I believe I tested it once. Note that unlike your code, the > child_conn is sent as argument. The relation between the module code > and child processes is different on Windows than *nix. Hi Terry, Thanks for your reply. I have been hacking at this for a few hours. I have learned two things: 1. Windows hangs unless you explicitly pass any references you want to use in the subprocess through args. That would include the Pipe connection. Using multiprocessing in Linux requires the reference names to be global, however the use of args is not required. Finally, Linux does not appear to cause any problems if args are specified. 2. Even if you fix problem 1, the parent process must be distinguished by creating the subprocess inside an "if __name__ == '__main__'" block. Again, Linux just pushes on through, but Windows will hang if you don't do this. The example code you posted shows exactly these two changes. They are OS-specific, and my multiprocessing code has been (up to now) only required to run on Linux. These recommendations can be found in the official Python docs, e.g.: https://docs.python.org/3.7/library/multiprocessing.html#programming-guidelines From torriem at gmail.com Mon May 4 22:09:10 2020 From: torriem at gmail.com (Michael Torrie) Date: Mon, 4 May 2020 20:09:10 -0600 Subject: phyton hata In-Reply-To: References: Message-ID: <36bf9517-be23-0afe-b755-6421c4dec0b2@gmail.com> On 5/4/20 4:15 AM, H?SEY?N KO? wrote: > Phyton 3.8.2 versiyonu bilgisayar?ma indirdim fakat sorunlar ile kar??la?t?n?z diyerek hata veriyor > > > Windows 10 i?in Posta ile g?nderildi > Please ensure Windows is up to date using Windows Update. That will solve most installation problems. From jsf80238 at gmail.com Mon May 4 23:28:46 2020 From: jsf80238 at gmail.com (Jason Friedman) Date: Mon, 4 May 2020 21:28:46 -0600 Subject: Consumer trait recognition In-Reply-To: <04f15248-27d5-43bb-bb64-821c87a6dc35@googlegroups.com> References: <04f15248-27d5-43bb-bb64-821c87a6dc35@googlegroups.com> Message-ID: > > I constructed a lexicon for words that show how different words are linked > to consumer traits and motivations (e.g. Achievement and Power Motivation). > Now I have collected a large amount of online customer reviews and want to > match each review with the word definitions of the consumer traits and > motivations in order to identify whether they influence the consumer > preferences. > > How do I that? Both the lexicons and the customer reviews are csv files. > > I was going to reply that you should consider the https://www.nltk.org/ mailing list, but I see you have already done so ( https://groups.google.com/forum/#!topic/nltk-users/LWllpEiW65k). Someone replied asking for what you have so far, "preferably in code". You might also show on that forum the first 5-or-so lines of your two files, along with what you expect the first 5-or-so lines of output to look like. From miki.tebeka at gmail.com Tue May 5 00:36:43 2020 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Mon, 4 May 2020 21:36:43 -0700 (PDT) Subject: [ANN] Python Brain Teasers Book is Out Message-ID: <7f63bc98-82f1-4f46-80e1-22a7a90fa18e@googlegroups.com> Hi All, I'm excited that my book "Python Brain Teasers: 30 brain teasers to tickle your mind and help become a better developer." is out. You can grab is from https://gum.co/iIQT (PDF & ePUB). Let me know how many teasers did you get right. If you're curious, a sample of the book, including the forward by Raymond Hettinger is at https://www.353solutions.com/python-brain-teasers Stay curious, keep hacking, Miki From arj.python at gmail.com Tue May 5 01:23:22 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 5 May 2020 09:23:22 +0400 Subject: [ANN] Python Brain Teasers Book is Out In-Reply-To: <7f63bc98-82f1-4f46-80e1-22a7a90fa18e@googlegroups.com> References: <7f63bc98-82f1-4f46-80e1-22a7a90fa18e@googlegroups.com> Message-ID: Greetings, Would be grateful if you could post it to python-authors also: https://mail.python.org/mailman/listinfo/python-authors Thanks! Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy.com | github Mauritius On Tue, May 5, 2020 at 8:40 AM Miki Tebeka wrote: > Hi All, > > I'm excited that my book "Python Brain Teasers: 30 brain teasers to tickle > your mind and help become a better developer." is out. > > You can grab is from https://gum.co/iIQT (PDF & ePUB). Let me know how > many teasers did you get right. > > If you're curious, a sample of the book, including the forward by Raymond > Hettinger is at https://www.353solutions.com/python-brain-teasers > > Stay curious, keep hacking, > Miki > -- > https://mail.python.org/mailman/listinfo/python-list > From cs at cskk.id.au Tue May 5 04:43:18 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 5 May 2020 18:43:18 +1000 Subject: Is there anything in the script which could cause it to not run its full course please? In-Reply-To: <6a83a756-20d3-48f6-b506-b15d37f13870@googlegroups.com> References: <6a83a756-20d3-48f6-b506-b15d37f13870@googlegroups.com> Message-ID: <20200505084318.GA5073@cskk.homeip.net> On 04May2020 17:17, ozstar1 at gmail.com wrote: >On Tuesday, 5 May 2020 01:35:42 UTC+10, David Raymond wrote: >> Not necessarily the cause of your problem, but if you're going to compare dates it should be as objects, or as text as year-month-day. Here you're comparing dates as text in day-month-year format. So January first 9999 comes before May 4th 2020 >> >> "01-01-9999" < "04-05-2020" [...] > >Thank you, see what you mean. I have corrected this now. It seem worth pointing out that this is why many of us like ISO8601 dates, which are written from largest component to smallest component. For example: 2020-05-04 They have the convenient property of sorting lexically as they would sort numerically. But David's right on in saying that if you're comparing numbers, do it numerically. Comparing text when the underlying thing isn't text is the wrong approach. Cheers, Cameron Simpson From sabri.pllana at gmail.com Tue May 5 08:10:24 2020 From: sabri.pllana at gmail.com (SP) Date: Tue, 5 May 2020 05:10:24 -0700 (PDT) Subject: Special issue on Recent Advances in Autonomous Vehicle Solutions in the Digital Continuum Message-ID: <17cee61a-bf7f-4839-ac03-ed09adc1b392@googlegroups.com> Special issue on Recent Advances in Autonomous Vehicle Solutions in the Digital Continuum Computing Journal, Springer Nature https://www.springer.com/journal/607/updates/17917580 SCOPE The domain of autonomous vehicle computing systems is changing rapidly under the pressure of an intense competition, the continuous emergence of new markets and players. Research and development in autonomous vehicles poses many challenges and opportunities both in hardware and software across the Digital Continuum: from sensors at the Edge to HPC resources in the Cloud. Hardware requirements range from specific processor architectures, efficient SIMD processing on graphics processors, and efficient memory hierarchy. Similarly, software requirements range from operating system support and specialized image processing kernels, to efficient deep learning algorithms for scene and object detection. Special attention is paid to power limitations, cost for mass production, and safety. This special issue of Computing addresses recent advances for autonomous vehicles in the Digital Continuum encompassing the Edge, Fog, and Cloud Computing. Topics of interest include, but are not limited to: - Workload characterization and benchmarks for autonomous vehicles to be used in heterogeneous platforms. - Special accelerator architectures and microarchitectures to be used on the Edge. - Resource allocation approaches for autonomous vehicle computation needs. - Scheduling heuristics and run time environment solutions to achieve better throughput in computing systems with different constraints. - Framework and prototype experiences with integration of specialized components. - Testbed implementations with heterogeneous computing resources for autonomous vehicles. - Memory system design for specialized hardware. - System impact of offloading computation including interconnect technology, bandwidth, and data processing. - Programmability of heterogeneous hardware resources with variable distances. - Techniques to facilitate configurability or configurable solutions. - System evaluation and analysis of specialized platforms. GUEST EDITORS - Ozcan Ozturk (Lead Guest Editor), Bilkent University (TR), - Sabri Pllana, Linnaeus University (SE), - Sma?l Niar, Universit? Polytechnique Hauts-de-France (FR), - Kaoutar El Maghraoui, IBM Thomas J. Watson Research Center (US). TENTATIVE SCHEDULE - Submission Due: 1st Sep 2020 - First Review Notification: 1st Nov 2020 - Revision Due: 1st Dec 2020 - Final Review Notification: 1st Feb 2021 SUBMISSION GUIDELINES Formatting: All submitted manuscripts must be formatted according to Computing's Submission Guidelines/Instructions for Authors which are available at https://www.springer.com/journal/607. We will accept both LaTeX manuscripts (Springer templates to be found under Submission Guidelines/Instructions for Authors/Text) and word manuscripts (for which no templates are available). Manuscript length: Please note that the page limit for Special Issue submissions differs from that of regular Computing submissions. Manuscripts submitted to the Special Issue should not exceed 20 pages. Submission that do not comply with this requirement are likely to be desk rejected without being reviewed. Submission instruction: Manuscripts should be submitted using the online submission system at https://www.editorialmanager.com/comp/default.aspx. When submitting a manuscript for this special issue, authors should select ?SI: Autonomous Vehicle Solutions in the Digital Continuum? during the submission step 'Additional Information'. Submissions of ?extended versions? of already published works (e.g., conference/workshop papers) should be significantly extended with a relevant part of novel contribution (at least 30% new work). A ?Summary of Differences? between the submitted paper to this special issue and the former one must be included. From tjreedy at udel.edu Tue May 5 00:02:44 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 5 May 2020 00:02:44 -0400 Subject: Multiprocessing vs. concurrent.futures, Linux vs. Windows In-Reply-To: References: Message-ID: On 5/4/2020 9:05 PM, John Ladasky wrote: > On Monday, May 4, 2020 at 4:09:53 PM UTC-7, Terry Reedy wrote: [snip] > Hi Terry, > > Thanks for your reply. I have been hacking at this for a few hours. I have learned two things: > > 1. Windows hangs unless you explicitly pass any references you want to use in the subprocess through args. That would include the Pipe connection. > Using multiprocessing in Linux requires the reference names to be global, however the use of args is not required. Finally, Linux does not appear to cause any problems if args are specified. > 2. Even if you fix problem 1, the parent process must be distinguished by creating the subprocess inside an "if __name__ == '__main__'" block. Again, Linux just pushes on through, but Windows will hang if you don't do this. > > The example code you posted shows exactly these two changes. They are OS-specific, and my multiprocessing code has been (up to now) only required to run on Linux. These recommendations can be found in the official Python docs, e.g.: > > https://docs.python.org/3.7/library/multiprocessing.html#programming-guidelines I was aware of point 2 (use __name__ clause) because there was a time when some of the examples in the doc did not do that, and they failed when run on Windows. So there was a patch to fix the examples and add the explicit advice. I must have read point 1 (pass resources in args) but forgot. But knowing that the examples are, I believe, now tested on Windows, I looked for the one closest to your code and then saw the difference. Good luck with moving forward. From adolfbordeaux99 at gmail.com Tue May 5 00:34:19 2020 From: adolfbordeaux99 at gmail.com (Adolf Yoshua Marbun) Date: Tue, 5 May 2020 11:34:19 +0700 Subject: Python Installation Problem Message-ID: Dear Python, I am currently learning about Python. First thing first, I need to install the interpreter Python 3.8.2 before I get to the IDE. But, I have problem during running command. The installation was successful. When I try to run the command prompt, typing "python --version", it always shows me an error message as attached below this message. I tried to follow the message (reinstalling the program), but didn't work. I don't know what it is and I have tried few times to solve the problem from the internet. I wish Python could help me find a solution. Thank you very much. -- *Regards,* *Adolf Yoshua Marbun* From sparr0 at gmail.com Tue May 5 18:07:58 2020 From: sparr0 at gmail.com (Sparr Risher) Date: Tue, 5 May 2020 15:07:58 -0700 (PDT) Subject: Feature request: method to cancel or bail out from fileinput.input(inplace=True) Message-ID: <094f374d-091b-4198-81be-1c3af2232bed@googlegroups.com> After using https://docs.python.org/3/library/fileinput.html to open a file for inplace filtering, a backup is created before output is redirected to the new file. It is possible, but non-trivial and non-obvious, to bail out of this situation, putting the backed up file back in place and ending the output redirection. My request is for a .cancel() or similar method that will automate this bail out process, leaving the filesystem and streams in the state they were in before fileinput.input() was called. The primary use case for this functionality would be upon encountering an exception in the middle of file processing. While on the subject, I also believe the following additional functionality would be worthwhile, even without fulfillment of the main request: A method to return the extension provided for the backup file, and/or to return the full name of the backup file. A parameter to disallow silent overwrite of the backup file. From sforman at hushmail.com Tue May 5 17:23:09 2020 From: sforman at hushmail.com (Simon Forman) Date: Tue, 05 May 2020 14:23:09 -0700 Subject: The '-c' CLI option removes just the command str. Message-ID: <20200505212309.E0C41406E2@smtp.hushmail.com> Is this anything? When you run a python command from the shell to just print the command line args you get this: $ python -c "import sys; print(sys.argv)" ['-c'] But I would expect one of these: Either the '-c' option consumes both args: $ python -c "import sys; print(sys.argv)" [] Or it leaves them both in: $ python -c "import sys; print(sys.argv)" ['-c', 'import sys; print(sys.argv)'] What do you think? Warm regards, ~Simon From rhodri at kynesim.co.uk Tue May 5 18:20:23 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 5 May 2020 23:20:23 +0100 Subject: Python Installation Problem In-Reply-To: References: Message-ID: On 05/05/2020 05:34, Adolf Yoshua Marbun wrote: > Dear Python, > > I am currently learning about Python. First thing first, I need to install > the interpreter Python 3.8.2 before I get to the IDE. But, I have problem > during running command. > > The installation was successful. When I try to run the command prompt, > typing "python --version", it always shows me an error message as attached > below this message. I tried to follow the message (reinstalling the > program), but didn't work. I don't know what it is and I have tried few > times to solve the problem from the internet. Unfortunately this is a text-only mailing list, and your attachment was stripped off before any of us had the chance to see it. Could you copy and paste the error message into a message, please? Also if you could let us know what operating system you are using, some people may be able to offer more detailed advice. -- Rhodri James *-* Kynesim Ltd From python at mrabarnett.plus.com Tue May 5 18:39:56 2020 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 5 May 2020 23:39:56 +0100 Subject: Python Installation Problem In-Reply-To: References: Message-ID: On 2020-05-05 23:20, Rhodri James wrote: > On 05/05/2020 05:34, Adolf Yoshua Marbun wrote: >> Dear Python, >> >> I am currently learning about Python. First thing first, I need to install >> the interpreter Python 3.8.2 before I get to the IDE. But, I have problem >> during running command. >> >> The installation was successful. When I try to run the command prompt, >> typing "python --version", it always shows me an error message as attached >> below this message. I tried to follow the message (reinstalling the >> program), but didn't work. I don't know what it is and I have tried few >> times to solve the problem from the internet. > > Unfortunately this is a text-only mailing list, and your attachment was > stripped off before any of us had the chance to see it. Could you copy > and paste the error message into a message, please? Also if you could > let us know what operating system you are using, some people may be able > to offer more detailed advice. > If you're using Windows and it's complaining that it can't find "python", try the Python launcher instead: py --version From greg.ewing at canterbury.ac.nz Tue May 5 21:07:10 2020 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 6 May 2020 13:07:10 +1200 Subject: print() ignores context ? In-Reply-To: References: Message-ID: On 1/05/20 8:33 pm, R.Wieser wrote: > > getcontext().rounding=ROUND_HALF_UP > > print(round(1.5)) > print(round(2.5)) If you're talking about getcontext() from the decimal module, that only affects operations with Decimals, not regular floats. Python doesn't provide a way to change the rounding mode for floats. -- Greg From souvik.viksou at gmail.com Tue May 5 22:17:34 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Wed, 6 May 2020 07:47:34 +0530 Subject: Python Installation Problem In-Reply-To: References: Message-ID: Have you added python to path? If not then you will have to do it. Souvik flutter dev On Wed, May 6, 2020, 1:28 AM Adolf Yoshua Marbun wrote: > Dear Python, > > I am currently learning about Python. First thing first, I need to install > the interpreter Python 3.8.2 before I get to the IDE. But, I have problem > during running command. > > The installation was successful. When I try to run the command prompt, > typing "python --version", it always shows me an error message as attached > below this message. I tried to follow the message (reinstalling the > program), but didn't work. I don't know what it is and I have tried few > times to solve the problem from the internet. > > I wish Python could help me find a solution. Thank you very much. > > > -- > *Regards,* > *Adolf Yoshua Marbun* > -- > https://mail.python.org/mailman/listinfo/python-list > From adolfbordeaux99 at gmail.com Tue May 5 22:19:16 2020 From: adolfbordeaux99 at gmail.com (Adolf Yoshua Marbun) Date: Wed, 6 May 2020 09:19:16 +0700 Subject: Python Installation Problem In-Reply-To: References: Message-ID: Yes, I did. I did this before the installation began, checked the "add to PATH" option. On Wed, May 6, 2020 at 9:17 AM Souvik Dutta wrote: > Have you added python to path? If not then you will have to do it. > > Souvik flutter dev > > On Wed, May 6, 2020, 1:28 AM Adolf Yoshua Marbun < > adolfbordeaux99 at gmail.com> wrote: > >> Dear Python, >> >> I am currently learning about Python. First thing first, I need to install >> the interpreter Python 3.8.2 before I get to the IDE. But, I have problem >> during running command. >> >> The installation was successful. When I try to run the command prompt, >> typing "python --version", it always shows me an error message as attached >> below this message. I tried to follow the message (reinstalling the >> program), but didn't work. I don't know what it is and I have tried few >> times to solve the problem from the internet. >> >> I wish Python could help me find a solution. Thank you very much. >> >> >> -- >> *Regards,* >> *Adolf Yoshua Marbun* >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- *Regards,* *Adolf Yoshua Marbun* From souvik.viksou at gmail.com Tue May 5 22:55:45 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Wed, 6 May 2020 08:25:45 +0530 Subject: Python Installation Problem In-Reply-To: References: Message-ID: What is the error can you copy and paste? Because this list does not support attachment. Souvik flutter dev On Wed, May 6, 2020, 7:49 AM Adolf Yoshua Marbun wrote: > Yes, I did. I did this before the installation began, checked the "add to > PATH" option. > > On Wed, May 6, 2020 at 9:17 AM Souvik Dutta > wrote: > >> Have you added python to path? If not then you will have to do it. >> >> Souvik flutter dev >> >> On Wed, May 6, 2020, 1:28 AM Adolf Yoshua Marbun < >> adolfbordeaux99 at gmail.com> wrote: >> >>> Dear Python, >>> >>> I am currently learning about Python. First thing first, I need to >>> install >>> the interpreter Python 3.8.2 before I get to the IDE. But, I have problem >>> during running command. >>> >>> The installation was successful. When I try to run the command prompt, >>> typing "python --version", it always shows me an error message as >>> attached >>> below this message. I tried to follow the message (reinstalling the >>> program), but didn't work. I don't know what it is and I have tried few >>> times to solve the problem from the internet. >>> >>> I wish Python could help me find a solution. Thank you very much. >>> >>> >>> -- >>> *Regards,* >>> *Adolf Yoshua Marbun* >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> > > -- > *Regards,* > *Adolf Yoshua Marbun* > From miki.tebeka at gmail.com Wed May 6 00:03:35 2020 From: miki.tebeka at gmail.com (Miki Tebeka) Date: Tue, 5 May 2020 21:03:35 -0700 (PDT) Subject: [ANN] Python Brain Teasers Book is Out In-Reply-To: References: <7f63bc98-82f1-4f46-80e1-22a7a90fa18e@googlegroups.com> Message-ID: <961740cd-4807-48c7-9e84-900c4006cce2@googlegroups.com> Hi, > Would be grateful if you could post it to python-authors also: > https://mail.python.org/mailman/listinfo/python-authors Done. Though list seems very dormant. Thanks, Miki From arj.python at gmail.com Wed May 6 01:36:27 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 6 May 2020 09:36:27 +0400 Subject: [ANN] Python Brain Teasers Book is Out In-Reply-To: <961740cd-4807-48c7-9e84-900c4006cce2@googlegroups.com> References: <7f63bc98-82f1-4f46-80e1-22a7a90fa18e@googlegroups.com> <961740cd-4807-48c7-9e84-900c4006cce2@googlegroups.com> Message-ID: Thanks a lot! The list is very dormant and we have begun working to make the list beneficial for the community. It is supposed to be a resource place for Python literature advice, from blog posts to books writing. I have also removed your moderate flag so that your future messages won't be held. _disclaimer: a python-authors admin_ Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy.com | github Mauritius On Wed, May 6, 2020 at 8:05 AM Miki Tebeka wrote: > Hi, > > > Would be grateful if you could post it to python-authors also: > > https://mail.python.org/mailman/listinfo/python-authors > Done. Though list seems very dormant. > > Thanks, > Miki > -- > https://mail.python.org/mailman/listinfo/python-list > From yuri.yudhaswana at gmail.com Wed May 6 02:03:33 2020 From: yuri.yudhaswana at gmail.com (yuri.yudhaswana at gmail.com) Date: Tue, 5 May 2020 23:03:33 -0700 (PDT) Subject: compiling 3.7.0 from source with custom libffi path In-Reply-To: <8181788f-19b5-4192-b3ca-de3d57f2a178@googlegroups.com> References: <8181788f-19b5-4192-b3ca-de3d57f2a178@googlegroups.com> Message-ID: Hi, I dont have "lib64" in libffi, are you sure it is "lib64" or just "lib"? On Monday, 1 July 2019 21:32:46 UTC+9, tom... at gmail.com wrote: > On Monday, September 24, 2018 at 11:48:59 AM UTC+3, Fetchinson . wrote: > > I'm trying to compile python 3.7.0 from source with a custom libffi > > path and the compiler/linker doesn't seem to pick up the right > > version. The system libffi doesn't have the development files so I've > > installed the latest libffi (also from source) to /opt/custom but > > still I get > > > > INFO: Could not locate ffi libs and/or headers > > > > Failed to build these modules: > > _ctypes > > > > Although I compile python with --prefix=/opt/custom because that's the > > location I'd like to install it too. So how do I tell the build system > > where to find my custom libffi? > > > > Cheers, > > Daniel > > > > > > > > -- > > Psss, psss, put it down! - http://www.cafepress.com/putitdown > > After some messing around with the build scripts, I figured it out. This works for me: > > 0. Choose installation path for FFI -> $LIBFFI_PATH > 1. Configure, build, install libffi: > 1a. Download libffi from https://sourceware.org/libffi/ and untar it > 1b. ./configure --prefix $LIBFFI_PATH > 1c. make > 1d. make install > 2. Configure CPython: (I'm using tcsh syntax, it is slightly different with bash) > 2a. setenv PKG_CONFIG_PATH $LIBFFI_PATH/lib/pkgconfig/ > 2b. setenv LDFLAGS "-L $LIBFFI_PATH/lib64/" > 2c. /configure --with-pydebug > 3. Build > 3a. setenv LD_LIBRARY_PATH "${LIBFFI_PATH}/lib64/" > 3b. make -s -j2 > > Good luck! From mal at europython.eu Wed May 6 07:47:52 2020 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 6 May 2020 13:47:52 +0200 Subject: EuroPython 2020: Call for Sponsors Message-ID: Reach out to enthusiastic Python developers, users and professionals worldwide by presenting your company at the first online EuroPython conference ever, from July 23-26! * EuroPython 2020 Sponsor Packages * https://ep2020.europython.eu/sponsor/packages/ Sponsoring EuroPython guarantees you highly targeted visibility and the opportunity to present yourself and your company in a professional and innovative environment. We have updated our in-person conference sponsor packages to the new online format and lowered the prices, giving you an excellent opportunity to reach out to attendees and even run your own virtual rooms, text channels, talks and training sessions throughout the conference and sprint days. You will also be able to post job ads on our website and the conference chat system, as well as get a mention and opportunity to give away digital swag via our virtual exhibit page. In addition, as a sponsor of EuroPython 2020, you will directly help promote the work of a great open-source community which has become a powerhouse of technological development and innovation. Want to know more ? ------------------- Head over to the sponsor packages page and feel free to contact us directly with any questions at sponsoring at europython.eu Special offer for early bird sponsors ------------------------------------- Sponsors who sign up before or on May 15, will receive a special 10% discount on the sponsor package price. Become a sponsor and support EuroPython 2020 today ! You can sign up on the sponsor packages page: https://ep2020.europython.eu/sponsor/packages/#Sponsor-Signup 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/617365129666920448/europython-2020-call-for-sponsors Tweet: https://twitter.com/europython/status/1257999190476697600 Thanks, -- EuroPython 2020 Team https://ep2020.europython.eu/ https://www.europython-society.org/ From vicrance711 at gmail.com Wed May 6 09:46:56 2020 From: vicrance711 at gmail.com (Rance Victor) Date: Wed, 6 May 2020 14:46:56 +0100 Subject: Idle not opening In-Reply-To: References: Message-ID: Hey there, After successfully installing Python 3.8.2(64 bit) on my system(windows 10 64 bit OS), my idle is not opening. I've tried uninstalling and reinstalling it again but still the same result. Looking forward to a fix please. Thanks From arj.python at gmail.com Wed May 6 13:55:27 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 6 May 2020 21:55:27 +0400 Subject: FlaskCon is round the corner! Message-ID: Greetings list, FlaskCon is coming soon. It will be a 100% remote event with paper reviews by the Pallets team. It is a collaborative event and a first attempt of it's kind. In an attempt to include as much people as we can from the community we prepared a form to gather some ideas. https://forms.gle/yB64uY9QkXV4k74u5 Participating UGs include: - PythonIreland - PythonNigeria - PyAmsterdam - BangPypers - PyConChina - PythonMoscow - PyMUG (UG of Mauritius) Call for papers will start soon. We'd be happy to have some graphics volunteering ^^ You can reach out to myself or any chair of the participating UGs. Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy.com | github Mauritius From souvik.viksou at gmail.com Wed May 6 23:10:24 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Thu, 7 May 2020 08:40:24 +0530 Subject: Idle not opening In-Reply-To: References: Message-ID: What exactly are you seeing when you try to open idle? Don't attach any file or photo. Just say verbally. Souvik flutter dev On Wed, May 6, 2020, 7:40 PM Rance Victor wrote: > Hey there, > After successfully installing Python 3.8.2(64 bit) on my system(windows 10 > 64 bit OS), my idle is not opening. I've tried uninstalling and > reinstalling it again but still the same result. > Looking forward to a fix please. > Thanks > -- > https://mail.python.org/mailman/listinfo/python-list > From rackflot at gmail.com Thu May 7 07:30:26 2020 From: rackflot at gmail.com (rackflot at gmail.com) Date: Thu, 7 May 2020 04:30:26 -0700 (PDT) Subject: Debian Buster: ModuleNotFoundError: No module named 'mysql' In-Reply-To: References: <3cbcc7bc-3414-7b64-969d-e79a859e6017@gmail.com> Message-ID: <5dda0b2c-e2f7-4209-a4ce-c4c7b0f9d66d@googlegroups.com> I have the same issue. I use visual code from Ms and the remote debugging over an ssh. I am able to do all mysql while in the debugger but running on command line does not work. The DB is logged in as root as this was the only way I could make it work. pi at raspberrypi:~/blescan/iBeacon-Scanner-$ pip search mysql-connector | grep --color mysql-connector-python mysql-connector-python (8.0.20) - MySQL driver written in Python mysql-connector-python-dd (2.0.2) - MySQL driver written in Python mysql-connector-python-rf (2.2.2) - MySQL driver written in Python pi at raspberrypi:~/blescan/iBeacon-Scanner-$ pip install mysql-connector-python-rf Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Requirement already satisfied: mysql-connector-python-rf in /home/pi/.local/lib/python3.7/site-packages (2.2.2) pi at raspberrypi:~/blescan/iBeacon-Scanner-$ sudo python3 BeaconClass.py Traceback (most recent call last): File "BeaconClass.py", line 7, in import mysql.connector as mariadb ModuleNotFoundError: No module named 'mysql' pi at raspberrypi:~/blescan/iBeacon-Scanner-$ From python at mrabarnett.plus.com Thu May 7 07:53:18 2020 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 7 May 2020 12:53:18 +0100 Subject: Debian Buster: ModuleNotFoundError: No module named 'mysql' In-Reply-To: <5dda0b2c-e2f7-4209-a4ce-c4c7b0f9d66d@googlegroups.com> References: <3cbcc7bc-3414-7b64-969d-e79a859e6017@gmail.com> <5dda0b2c-e2f7-4209-a4ce-c4c7b0f9d66d@googlegroups.com> Message-ID: On 2020-05-07 12:30, rackflot at gmail.com wrote: > I have the same issue. I use visual code from Ms and the remote debugging over an ssh. > I am able to do all mysql while in the debugger but running on command line does not work. > The DB is logged in as root as this was the only way I could make it work. > > pi at raspberrypi:~/blescan/iBeacon-Scanner-$ pip search mysql-connector | grep --color mysql-connector-python > mysql-connector-python (8.0.20) - MySQL driver written in Python > mysql-connector-python-dd (2.0.2) - MySQL driver written in Python > mysql-connector-python-rf (2.2.2) - MySQL driver written in Python > pi at raspberrypi:~/blescan/iBeacon-Scanner-$ pip install mysql-connector-python-rf > Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple > Requirement already satisfied: mysql-connector-python-rf in /home/pi/.local/lib/python3.7/site-packages (2.2.2) > pi at raspberrypi:~/blescan/iBeacon-Scanner-$ sudo python3 BeaconClass.py > Traceback (most recent call last): File "BeaconClass.py", line 7, in > import mysql.connector as mariadb ModuleNotFoundError: No module named 'mysql' > pi at raspberrypi:~/blescan/iBeacon-Scanner-$ > I believe that it's "pip" for "python" (Python 2) and "pip3" for "python3" (Python 3). Personally, I'd use: python3 -m pip ... or: sudo python3 -m pip ... instead. From mal at europython.eu Thu May 7 15:00:44 2020 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 7 May 2020 21:00:44 +0200 Subject: Sharing our research and licenses for going online with Python events Message-ID: In March 2020, we had to make a tough decision on whether to cancel EuroPython 2020 or run it online. Since we did not want to lose continuity and all the work we had already put into the in-person event, we decided to go for an online version. Now, just as many other in-person events, running the online version required a lot of research, experimentation, gaining knowledge in using online conference tools and finding a concept which would allow us to carry over as much of the in-person conference experience to the online version as possible. * EuroPython 2020 Online * https://ep2020.europython.eu/ This is an on-going effort, but we believe that our existing research will help other Python events go online as well and want to share this knowledge with you. Running Online Conferences -------------------------- The two central documents we have are: - EuroPython 2020 - Online Conference Tools This covers research on a lot of different tools available out there, our experience with them, hints and tips on how to use them effectively (esp. for Zoom and Discord). https://docs.google.com/document/d/1OAVtZnxVgmkDGvSV1vEzra7m5Nfjr-81kCrustzxAek/edit# - EuroPython 2020 - Virtual Conference Concept Since we had to start afresh with the conference concept, we ran and still are running a brainstorming phase to come up with ideas and are now starting to materialize these into a concept, which we?ll use as basis for running EuroPython this year. https://docs.google.com/document/d/1aGnYM3RlyLFUmdhnykGfgD6gNXJYo8zateu9Re_fdNg/edit# If you have questions around these documents and their content, feel free to contact us at helpdesk at europython.eu. Sharing our Zoom Webinar and Pro licenses ----------------------------------------- In addition to sharing our research, we?d also like to share the Zoom Webinar and Pro licenses we have with other events, where possible. We have already shared them with: - PyAmsterdam - Remote Python Pizza The only thing we ask is that some of our work group members can participate in the event as co-host to observe and help, since we need to train and gain more experience in using these tools. As a bonus, we can also help with the configuration and share our existing experience. If you?re interested in this, please get in contact with us at helpdesk at europython.eu. 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://www.europython-society.org/post/617463429296472064/sharing-our-research-and-licenses-for-going-online Tweet: https://twitter.com/europythons/status/1258392513863397378 Thanks, -- EuroPython 2020 Team https://ep2020.europython.eu/ https://www.europython-society.org/ From rackflot at gmail.com Thu May 7 15:22:53 2020 From: rackflot at gmail.com (rackflot at gmail.com) Date: Thu, 7 May 2020 12:22:53 -0700 (PDT) Subject: Debian Buster: ModuleNotFoundError: No module named 'mysql' In-Reply-To: References: <3cbcc7bc-3414-7b64-969d-e79a859e6017@gmail.com> <5dda0b2c-e2f7-4209-a4ce-c4c7b0f9d66d@googlegroups.com> Message-ID: <7207f3b3-fb58-461f-a322-86d77b870b5f@googlegroups.com> On Thursday, May 7, 2020 at 7:57:14 AM UTC-4, MRAB wrote: > On 2020-05-07 12:30, rackflot at gmail.com wrote: > > I have the same issue. I use visual code from Ms and the remote debugging over an ssh. > > I am able to do all mysql while in the debugger but running on command line does not work. > > The DB is logged in as root as this was the only way I could make it work. > > > > pi at raspberrypi:~/blescan/iBeacon-Scanner-$ pip search mysql-connector | grep --color mysql-connector-python > > mysql-connector-python (8.0.20) - MySQL driver written in Python > > mysql-connector-python-dd (2.0.2) - MySQL driver written in Python > > mysql-connector-python-rf (2.2.2) - MySQL driver written in Python > > pi at raspberrypi:~/blescan/iBeacon-Scanner-$ pip install mysql-connector-python-rf > > Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple > > Requirement already satisfied: mysql-connector-python-rf in /home/pi/.local/lib/python3.7/site-packages (2.2.2) > > pi at raspberrypi:~/blescan/iBeacon-Scanner-$ sudo python3 BeaconClass.py > > Traceback (most recent call last): File "BeaconClass.py", line 7, in > > import mysql.connector as mariadb ModuleNotFoundError: No module named 'mysql' > > pi at raspberrypi:~/blescan/iBeacon-Scanner-$ > > > I believe that it's "pip" for "python" (Python 2) and "pip3" for > "python3" (Python 3). > > Personally, I'd use: > > python3 -m pip ... > > or: > > sudo python3 -m pip ... > > instead. This only happens when on the command line trying to run the python script. it works fine in visual studio code. Resinstalled all of the packages mentioned above, it keeps saying it is all fine. What is different in MS debugger? From emirhangunec77 at gmail.com Thu May 7 17:06:21 2020 From: emirhangunec77 at gmail.com (=?UTF-8?B?RW1pcmhhbiBHw7xuZcOn?=) Date: Thu, 7 May 2020 14:06:21 -0700 (PDT) Subject: Automatic Minecraft Server Creator & Manager Message-ID: <8fe656ff-de7c-4138-b1ba-e256db8dd27d@googlegroups.com> This mini-program/script helps you to creating self-hosted minecraft servers. Just open 25565 port on your router or use Hamachi and run this script. Then follow the instructions in terminal correctly and don't forget to edit server.properties. This python3 script for linux works correctly and windows. https://github.com/emirhangunec/minecraftservermanagement From emirhangunec77 at gmail.com Thu May 7 17:08:50 2020 From: emirhangunec77 at gmail.com (=?UTF-8?B?RW1pcmhhbiBHw7xuZcOn?=) Date: Thu, 7 May 2020 14:08:50 -0700 (PDT) Subject: Automatic Minecraft Server Creator & Manager In-Reply-To: <8fe656ff-de7c-4138-b1ba-e256db8dd27d@googlegroups.com> References: <8fe656ff-de7c-4138-b1ba-e256db8dd27d@googlegroups.com> Message-ID: 8 May?s 2020 Cuma 00:06:37 UTC+3 tarihinde Emirhan G?ne? yazd?: > This mini-program/script helps you to creating self-hosted minecraft servers. Just open 25565 port on your router or use Hamachi and run this script. Then follow the instructions in terminal correctly and don't forget to edit server.properties. This python3 script for linux works correctly and windows. > > https://github.com/emirhangunec/minecraftservermanagement This python3 script works correctly with windows too. From kumarsagar9635 at gmail.com Thu May 7 00:15:04 2020 From: kumarsagar9635 at gmail.com (Music lover) Date: Thu, 7 May 2020 09:45:04 +0530 Subject: Not able use installed modules Message-ID: Hello python team, I have installed the latest version of python from your site. Then I successfully installed some modules like :- numpy , pandas, matplotlib from command prompt. But I am not able to use them while programing in python Idle. It's saying " no module named 'matplotlib' ." Please help me as soon as possible. Thanks and regards From tjreedy at udel.edu Wed May 6 20:35:31 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 May 2020 20:35:31 -0400 Subject: Idle not opening In-Reply-To: References: Message-ID: On 5/6/2020 9:46 AM, Rance Victor wrote: > Hey there, > After successfully installing Python 3.8.2(64 bit) on my system(windows 10 > 64 bit OS), my idle is not opening. I've tried uninstalling and > reinstalling it again but still the same result. Was the box for installing tkinter and IDLE checked? How did you try to run IDLE? Can you run Python itself -- from the start menu or command prompt, the latter either with > py or > python Is so, does 'import tkinter' work? Does 'dir(tkinter)' has a couple hundred entries? If the above, what does 'import idlelib.idle' do, or at command line, 'py -m idlelib'? From souvik.viksou at gmail.com Thu May 7 20:29:44 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Fri, 8 May 2020 05:59:44 +0530 Subject: Not able use installed modules In-Reply-To: References: Message-ID: What is your os? If you are on windows then check out app execution aliases. There will be two different python versions. Uncheck one and try installing again. If that doesn't work then uncheck the other and try installing again. Have you ever downloaded any other version of python but didn't uninstall it? If so then you will have to use pip3 install Souvik flutter dev On Fri, May 8, 2020, 2:49 AM Music lover wrote: > Hello python team, > I have installed the latest version of python from your site. > Then I successfully installed some modules like :- numpy , pandas, > matplotlib from command prompt. But I am not able to use them while > programing in python Idle. It's saying " no module named 'matplotlib' ." > > > Please help me as soon as possible. > > Thanks and regards > -- > https://mail.python.org/mailman/listinfo/python-list > From rackflot at gmail.com Thu May 7 20:59:28 2020 From: rackflot at gmail.com (rackflot at gmail.com) Date: Thu, 7 May 2020 17:59:28 -0700 (PDT) Subject: Debian Buster: ModuleNotFoundError: No module named 'mysql' In-Reply-To: <7207f3b3-fb58-461f-a322-86d77b870b5f@googlegroups.com> References: <3cbcc7bc-3414-7b64-969d-e79a859e6017@gmail.com> <5dda0b2c-e2f7-4209-a4ce-c4c7b0f9d66d@googlegroups.com> <7207f3b3-fb58-461f-a322-86d77b870b5f@googlegroups.com> Message-ID: i have figured it out. When i made the database, i made it with root access. I think i had to do that to make it accessable for a webpage. i changed to SU and installed this. pip install mysql-connector-python-rf and the other listed above. dumped out of su then tried it again. it worked. So, the package installed under my normal login it seems did not have the access that mysql needed for root. hmm. From souravsusari311 at gmail.com Thu May 7 22:56:47 2020 From: souravsusari311 at gmail.com (sourav susari) Date: Fri, 8 May 2020 08:26:47 +0530 Subject: There is some problem in the python software it was not installing in my laptop Message-ID: <5eb4cbb1.1c69fb81.e213e.0ff1@mx.google.com> ? ? Sent from [1]Mail for Windows 10 ? References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From souvik.viksou at gmail.com Thu May 7 23:37:25 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Fri, 8 May 2020 09:07:25 +0530 Subject: There is some problem in the python software it was not installing in my laptop In-Reply-To: <5eb4cbb1.1c69fb81.e213e.0ff1@mx.google.com> References: <5eb4cbb1.1c69fb81.e213e.0ff1@mx.google.com> Message-ID: What is the problem? You cannot attach images or any file. You will have to say in words. This list does not support attachments. Souvik flutter dev On Fri, May 8, 2020, 8:51 AM sourav susari wrote: > > > > > 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 lmfp.forums at gmail.com Fri May 8 04:37:54 2020 From: lmfp.forums at gmail.com (LM FP) Date: Fri, 8 May 2020 01:37:54 -0700 (PDT) Subject: Pyinstaller resources.DistributionNotFound 'workalendar' Message-ID: Hi! I have imported workalendar package -together with others packages- to my python script, and It works fine. I compile it with Pyinstaller without errors, but when I run the exe file appears a warning: pkg_resources.DistributionNotFound: The 'workalendar' distribution was not found and is required by the application. I execute this: C:\Python\Python38\Scripts\pyinstaller.exe --onefile .\main.spec And when I execute the exe file returns: pkg_resources.DistributionNotFound: The 'workalendar' distribution was not found and is required by the application [5716] Failed to execute script main My spec file: # -*- mode: python ; coding: utf-8 -*- block_cipher = None a = Analysis(['main.py'], pathex=['C:\\Users\\user\\Downloads\\MyScript', 'C:\\Python\\Python38\\Lib\\site-packages\\workalendar'], binaries=[], datas=[], hiddenimports=['pkg_resources.py2_warn', 'workalendar-9.0.0.dist-info/*', 'workalendar-9.0.0.dist-info'], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, [], name='main', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude=[], runtime_tmpdir=None, console=True ) Whats is the problem? From souvik.viksou at gmail.com Fri May 8 04:49:44 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Fri, 8 May 2020 14:19:44 +0530 Subject: Pyinstaller resources.DistributionNotFound 'workalendar' In-Reply-To: References: Message-ID: Have you installed the package listed in the error in a virtual environment? On Fri, 8 May, 2020, 2:10 pm LM FP, wrote: > Hi! > I have imported workalendar package -together with others packages- to my > python script, and It works fine. I compile it with Pyinstaller without > errors, but when I run the exe file appears a warning: > pkg_resources.DistributionNotFound: The 'workalendar' distribution was not > found and is required by the application. > > I execute this: C:\Python\Python38\Scripts\pyinstaller.exe --onefile > .\main.spec > > And when I execute the exe file returns: > pkg_resources.DistributionNotFound: The 'workalendar' distribution was not > found and is required by the application > [5716] Failed to execute script main > > > My spec file: > > # -*- mode: python ; coding: utf-8 -*- > > block_cipher = None > > > a = Analysis(['main.py'], > pathex=['C:\\Users\\user\\Downloads\\MyScript', > 'C:\\Python\\Python38\\Lib\\site-packages\\workalendar'], > binaries=[], > datas=[], > hiddenimports=['pkg_resources.py2_warn', > 'workalendar-9.0.0.dist-info/*', 'workalendar-9.0.0.dist-info'], > hookspath=[], > runtime_hooks=[], > excludes=[], > win_no_prefer_redirects=False, > win_private_assemblies=False, > cipher=block_cipher, > noarchive=False) > pyz = PYZ(a.pure, a.zipped_data, > cipher=block_cipher) > exe = EXE(pyz, > a.scripts, > a.binaries, > a.zipfiles, > a.datas, > [], > name='main', > debug=False, > bootloader_ignore_signals=False, > strip=False, > upx=True, > upx_exclude=[], > runtime_tmpdir=None, > console=True ) > > Whats is the problem? > > -- > https://mail.python.org/mailman/listinfo/python-list > From lmfp.forums at gmail.com Fri May 8 05:02:20 2020 From: lmfp.forums at gmail.com (LM FP) Date: Fri, 8 May 2020 02:02:20 -0700 (PDT) Subject: Pyinstaller resources.DistributionNotFound 'workalendar' In-Reply-To: References: Message-ID: <8a70d092-0d17-4300-bdf0-c24e9e4ad21f@googlegroups.com> Hi, I followed pypi instructions: pip install workalendar, and I also have not installed any virtual python environment on my computer. El viernes, 8 de mayo de 2020, 10:51:24 (UTC+2), Souvik Dutta escribi?: > Have you installed the package listed in the error in a virtual environment? > > On Fri, 8 May, 2020, 2:10 pm LM FP, wrote: > > > Hi! > > I have imported workalendar package -together with others packages- to my > > python script, and It works fine. I compile it with Pyinstaller without > > errors, but when I run the exe file appears a warning: > > pkg_resources.DistributionNotFound: The 'workalendar' distribution was not > > found and is required by the application. > > > > I execute this: C:\Python\Python38\Scripts\pyinstaller.exe --onefile > > .\main.spec > > > > And when I execute the exe file returns: > > pkg_resources.DistributionNotFound: The 'workalendar' distribution was not > > found and is required by the application > > [5716] Failed to execute script main > > > > > > My spec file: > > > > # -*- mode: python ; coding: utf-8 -*- > > > > block_cipher = None > > > > > > a = Analysis(['main.py'], > > pathex=['C:\\Users\\user\\Downloads\\MyScript', > > 'C:\\Python\\Python38\\Lib\\site-packages\\workalendar'], > > binaries=[], > > datas=[], > > hiddenimports=['pkg_resources.py2_warn', > > 'workalendar-9.0.0.dist-info/*', 'workalendar-9.0.0.dist-info'], > > hookspath=[], > > runtime_hooks=[], > > excludes=[], > > win_no_prefer_redirects=False, > > win_private_assemblies=False, > > cipher=block_cipher, > > noarchive=False) > > pyz = PYZ(a.pure, a.zipped_data, > > cipher=block_cipher) > > exe = EXE(pyz, > > a.scripts, > > a.binaries, > > a.zipfiles, > > a.datas, > > [], > > name='main', > > debug=False, > > bootloader_ignore_signals=False, > > strip=False, > > upx=True, > > upx_exclude=[], > > runtime_tmpdir=None, > > console=True ) > > > > Whats is the problem? > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > From nomail at adres.net Fri May 8 10:36:22 2020 From: nomail at adres.net (Sir Real) Date: Fri, 08 May 2020 09:36:22 -0500 Subject: Can a print overwrite a previous print ? References: <5eb56bf0$0$21597$426a74cc@news.free.fr> Message-ID: On Fri, 8 May 2020 16:25:52 +0200, ast wrote: >Hello > > >Suppose we want that: > >print("abcdef"); print("ghi") > >produces: > >ghidef > >The 2nd print overwrites the first one. >Is it feasible ? > >It should since the progress bar tdqh seems to do that > >try: > >from tkdm import tkdm > >for i in tqdm(range(100_000_000)): > pass > >It produces a progress bar like this: >100%|???????????????????????????????????????????????????????????????| >100000000/100000000 [00:56<00:00, 1781611.52it/s] print('abcdef', end='\r'); print('ghi', end='') From ast at invalid Fri May 8 10:25:52 2020 From: ast at invalid (ast) Date: Fri, 8 May 2020 16:25:52 +0200 Subject: Can a print overwrite a previous print ? Message-ID: <5eb56bf0$0$21597$426a74cc@news.free.fr> Hello Suppose we want that: print("abcdef"); print("ghi") produces: ghidef The 2nd print overwrites the first one. Is it feasible ? It should since the progress bar tdqh seems to do that try: from tkdm import tkdm for i in tqdm(range(100_000_000)): pass It produces a progress bar like this: 100%|???????????????????????????????????????????????????????????????| 100000000/100000000 [00:56<00:00, 1781611.52it/s] From mal at europython.eu Fri May 8 10:57:05 2020 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 8 May 2020 16:57:05 +0200 Subject: EuroPython 2020: Second call for proposals (CFP) - Going global Message-ID: <04e67efc-5ce8-837f-4ebb-e6d321adb121@europython.eu> After participating in several other online events in Europe, we found that there is a lot of interest in these events from other time zones as well. This is a real advantage of running an online event: without the need to travel, joining an event becomes much easier. * EuroPython 2020 Online 2nd CFP * https://ep2020.europython.eu/call-for-proposals/ To make it possible for speakers from the Americas and India/Asia/Pacific regions to give talks at EuroPython 2020 as well, we have decided to extend the schedule and provide extra slots in the CEST morning and the evening hours, so that we can have almost 80 talk slots available, and run a second CFP with specific emphasis on submissions from outside the central European time zones. Submitting a talk ----------------- We will run this second CFP from May 11 until May 24. To submit a talk, please visit our CFP page on the website. This has all the necessary details on how to submit a talk. We would also welcome submissions for helpdesks and posters, regardless of time zone, since we haven?t received any in the first CFP. Results from the first CFP -------------------------- The results from the first CFP will be announced on Sunday (May 10). 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/617552560206872576/europython-2020-second-call-for-proposals-cfp Tweet: https://twitter.com/europython/status/1258749100431990787 Thanks, -- EuroPython 2020 Team https://ep2020.europython.eu/ https://www.europython-society.org/ From mats at python.org Fri May 8 11:31:55 2020 From: mats at python.org (Mats Wichmann) Date: Fri, 8 May 2020 09:31:55 -0600 Subject: Not able use installed modules In-Reply-To: References: Message-ID: On 5/6/20 10:15 PM, Music lover wrote: > Hello python team, > I have installed the latest version of python from your site. > Then I successfully installed some modules like :- numpy , pandas, > matplotlib from command prompt. But I am not able to use them while > programing in python Idle. It's saying " no module named 'matplotlib' ." > > > Please help me as soon as possible. > > Thanks and regards > As a general answer, this is *always* a problem with paths. Your installation of modules went somewhere your Python doesn't know where to look, which is that Python's value of sys.path. It probably went into a version-specific location in the sys.path of a different Python as Souvik has suggested. Usually if you ran "pip install something" and then can't find "something" that means pip does not map to the Python you're going to use. As a result, it's better to use the following, with MYPYTHON being code for the way you expect to invoke Python - that could be "python" or "python3" or "py" or "py -3.8" or whatever it happens to be: MYPYTHON -m pip install something calling it as a module means things will be right for whatever MYPYTHON is, rather than picking up the first executable called pip, which might not be for that one. FWIW, many people who are after the set of numpy, pandas, etc. opt to use Anaconda which specifically aims to make the unified installation of Python with matching scientific, numeric, data science, etc. modules in a way that won't give you the kind of headache you are encountering. From robertvstepp at gmail.com Fri May 8 14:15:03 2020 From: robertvstepp at gmail.com (boB Stepp) Date: Fri, 8 May 2020 13:15:03 -0500 Subject: Not able use installed modules In-Reply-To: References: Message-ID: <20200508181502.GB5589@Dream-Machine1> On Fri, May 08, 2020 at 09:31:55AM -0600, Mats Wichmann wrote: > On 5/6/20 10:15 PM, Music lover wrote: > > Hello python team, > > I have installed the latest version of python from your site. > > Then I successfully installed some modules like :- numpy , pandas, > > matplotlib from command prompt. But I am not able to use them while > > programing in python Idle. It's saying " no module named 'matplotlib' ." > As a general answer, this is *always* a problem with paths. Your > installation of modules went somewhere your Python doesn't know where to > look, which is that Python's value of sys.path. It probably went into a > version-specific location in the sys.path of a different Python as > Souvik has suggested. > > Usually if you ran "pip install something" and then can't find > "something" that means pip does not map to the Python you're going to > use. As a result, it's better to use the following, with MYPYTHON being > code for the way you expect to invoke Python - that could be "python" or > "python3" or "py" or "py -3.8" or whatever it happens to be: > > MYPYTHON -m pip install something > > calling it as a module means things will be right for whatever MYPYTHON > is, rather than picking up the first executable called pip, which might > not be for that one. This may be a naive question on my part, but, as far as I can tell, most instructions that I have encountered for installing Python packages state the installation instructions as "pip install ...", which seems to repeatedly lead to these type of OP questions. Has there ever been given thought to changing these "standard" installation instructions to something less error fraught for the newcomer/novice? -- Wishing you only the best, boB Stepp From joepareti54 at gmail.com Fri May 8 15:02:00 2020 From: joepareti54 at gmail.com (joseph pareti) Date: Fri, 8 May 2020 21:02:00 +0200 Subject: basic Python question Message-ID: In general I prefer doing: X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42) clf = RandomForestClassifier(n_estimators = 100, max_depth= None) *clf_f = clf.fit(X_train, y_train)* predicted_labels = clf_f.predict( X_test) score = clf.score(X_test, y_test) score1 = metrics.accuracy_score( y_test, predicted_labels) rather than: X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42) clf0=RandomForestClassifier(n_estimators=100, max_depth= None) *clf0.fit(X_train, y_train)* y_pred =clf0.predict(X_test) score= metrics.accuracy_score(y_test, y_pred) Are the two codes really equivalent? -- 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 python at mrabarnett.plus.com Fri May 8 15:46:24 2020 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 8 May 2020 20:46:24 +0100 Subject: basic Python question In-Reply-To: References: Message-ID: On 2020-05-08 20:02, joseph pareti wrote: > In general I prefer doing: > > > X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42) >clf = RandomForestClassifier(n_estimators = 100, max_depth= > None) *clf_f = clf.fit(X_train, y_train)* predicted_labels = clf_f.predict( > X_test) score = clf.score(X_test, y_test) score1 = metrics.accuracy_score( > y_test, predicted_labels) > > > rather than: > > X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, > random_state=42) clf0=RandomForestClassifier(n_estimators=100, max_depth= > None) *clf0.fit(X_train, y_train)* y_pred =clf0.predict(X_test) score= > metrics.accuracy_score(y_test, y_pred) > > > Are the two codes really equivalent? > You didn't give any context and say what package you're using! After searching for "RandomForestClassifier", I'm guessing that you're using scikit. From the documentation here: https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html#sklearn.ensemble.RandomForestClassifier.fit it says: Returns: self : object so it looks like clf.fit(...) returns clf. That being the case, then, yes, they're equivalent. From joepareti54 at gmail.com Fri May 8 15:52:06 2020 From: joepareti54 at gmail.com (joseph pareti) Date: Fri, 8 May 2020 21:52:06 +0200 Subject: basic Python question In-Reply-To: References: Message-ID: yes, it is random forest classifier from scikit learn. Thank you. Am Fr., 8. Mai 2020 um 21:50 Uhr schrieb MRAB : > On 2020-05-08 20:02, joseph pareti wrote: > > In general I prefer doing: > > > > > > X_train, X_test, y_train, y_test = train_test_split(X, y, > test_size=0.33, random_state=42) > >clf = RandomForestClassifier(n_estimators = 100, max_depth= > > None) *clf_f = clf.fit(X_train, y_train)* predicted_labels = > clf_f.predict( > > X_test) score = clf.score(X_test, y_test) score1 = > metrics.accuracy_score( > > y_test, predicted_labels) > > > > > > rather than: > > > > X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, > > random_state=42) clf0=RandomForestClassifier(n_estimators=100, max_depth= > > None) *clf0.fit(X_train, y_train)* y_pred =clf0.predict(X_test) score= > > metrics.accuracy_score(y_test, y_pred) > > > > > > Are the two codes really equivalent? > > > You didn't give any context and say what package you're using! > > After searching for "RandomForestClassifier", I'm guessing that you're > using scikit. > > From the documentation here: > > > https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html#sklearn.ensemble.RandomForestClassifier.fit > > it says: > > Returns: self : object > > so it looks like clf.fit(...) returns clf. > > That being the case, then, yes, they're equivalent. > -- > 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 joepareti54 at gmail.com Fri May 8 16:19:34 2020 From: joepareti54 at gmail.com (joseph pareti) Date: Fri, 8 May 2020 22:19:34 +0200 Subject: basic Python question In-Reply-To: References: Message-ID: yet, something is still unclear; in Python you can do things like: *clf0.fit(X_train, y_train)* which is not the way I programmed in other languages where a left-hand side and a right hand side is required. Am Fr., 8. Mai 2020 um 21:52 Uhr schrieb joseph pareti < joepareti54 at gmail.com>: > yes, it is random forest classifier from scikit learn. Thank you. > > Am Fr., 8. Mai 2020 um 21:50 Uhr schrieb MRAB >: > >> On 2020-05-08 20:02, joseph pareti wrote: >> > In general I prefer doing: >> > >> > >> > X_train, X_test, y_train, y_test = train_test_split(X, y, >> test_size=0.33, random_state=42) >> >clf = RandomForestClassifier(n_estimators = 100, max_depth= >> > None) *clf_f = clf.fit(X_train, y_train)* predicted_labels = >> clf_f.predict( >> > X_test) score = clf.score(X_test, y_test) score1 = >> metrics.accuracy_score( >> > y_test, predicted_labels) >> > >> > >> > rather than: >> > >> > X_train, X_test, y_train, y_test = train_test_split(X, y, >> test_size=0.33, >> > random_state=42) clf0=RandomForestClassifier(n_estimators=100, >> max_depth= >> > None) *clf0.fit(X_train, y_train)* y_pred =clf0.predict(X_test) score= >> > metrics.accuracy_score(y_test, y_pred) >> > >> > >> > Are the two codes really equivalent? >> > >> You didn't give any context and say what package you're using! >> >> After searching for "RandomForestClassifier", I'm guessing that you're >> using scikit. >> >> From the documentation here: >> >> >> https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html#sklearn.ensemble.RandomForestClassifier.fit >> >> it says: >> >> Returns: self : object >> >> so it looks like clf.fit(...) returns clf. >> >> That being the case, then, yes, they're equivalent. >> -- >> 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 > -- 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 python at mrabarnett.plus.com Fri May 8 16:50:14 2020 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 8 May 2020 21:50:14 +0100 Subject: basic Python question In-Reply-To: References: Message-ID: <83af8aac-4865-045b-4c47-580c3bd945f3@mrabarnett.plus.com> On 2020-05-08 21:19, joseph pareti wrote: > yet, something is still unclear; in Python you can do things like: > > *clf0.fit(X_train,y_train)* > > which is not the way I programmed in other languages where a left-hand > side and a right hand side is required. > All it's doing is performing the calculation and then storing the result in the object itself. Most other languages can do that too. > Am Fr., 8. Mai 2020 um 21:52?Uhr schrieb joseph pareti > >: > > yes, it is random?forest classifier from scikit learn. Thank you. > > Am Fr., 8. Mai 2020 um 21:50?Uhr schrieb MRAB > >: > > On 2020-05-08 20:02, joseph pareti wrote: > > In general I prefer doing: > > > > > > X_train, X_test, y_train, y_test = train_test_split(X, y, > test_size=0.33, random_state=42) > ?>clf = RandomForestClassifier(n_estimators = 100, max_depth= > > None) *clf_f = clf.fit(X_train, y_train)* predicted_labels = > clf_f.predict( > > X_test) score = clf.score(X_test, y_test) score1 = > metrics.accuracy_score( > > y_test, predicted_labels) > > > > > > rather than: > > > > X_train, X_test, y_train, y_test = train_test_split(X, y, > test_size=0.33, > > random_state=42) > clf0=RandomForestClassifier(n_estimators=100, max_depth= > > None) *clf0.fit(X_train, y_train)* y_pred > =clf0.predict(X_test) score= > > metrics.accuracy_score(y_test, y_pred) > > > > > > Are the two codes really equivalent? > > > You didn't give any context and say what package you're using! > > After searching for "RandomForestClassifier", I'm guessing > that you're > using scikit. > > ?From the documentation here: > > https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html#sklearn.ensemble.RandomForestClassifier.fit > > it says: > > ? ? ?Returns: self : object > > so it looks like clf.fit(...) returns clf. > > That being the case, then, yes, they're equivalent. > > From cs at cskk.id.au Fri May 8 20:02:36 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 9 May 2020 10:02:36 +1000 Subject: Can a print overwrite a previous print ? In-Reply-To: References: Message-ID: <20200509000236.GA57139@cskk.homeip.net> On 08May2020 09:36, Sir Real wrote: >On Fri, 8 May 2020 16:25:52 +0200, ast wrote: >>Suppose we want that: >> >>print("abcdef"); print("ghi") >> >>produces: >> >>ghidef >> >>The 2nd print overwrites the first one. >>Is it feasible ? On a terminal, yes. This is a display issue. >>It should since the progress bar tdqh seems to do that >> >>try: >>from tkdm import tkdm >>for i in tqdm(range(100_000_000)): >> pass >>It produces a progress bar like this: >>100%|???????????????????????????????????????????????????????????????| >>100000000/100000000 [00:56<00:00, 1781611.52it/s] > > >print('abcdef', end='\r'); print('ghi', end='') Aye, though that is the (hated by me) rewrite-the-whole-line brute force approach. I've got a module "cs.upd" on PyPI which does this with minimal overwrites if you want something eaier on the eyes. Doubtless there are others. Cheers, Cameron Simpson From john_ladasky at sbcglobal.net Fri May 8 21:07:18 2020 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 8 May 2020 18:07:18 -0700 (PDT) Subject: Should setuptools version propagate to a module's __version__? If so, how? Message-ID: <48420bd4-5ebc-47ad-93fa-c7b6e05a315c@googlegroups.com> I just came across a package in PyPI which is in a state of neglect. The official version on the PyPI page is 1.3.1 -- but the installed module reports its version as 1.2.0. This is confusing. There are several bugs in this package besides the mismatched version number. I've forked a copy of the package on GitHub, and I will attempt a cleanup. In another private package of my own, I performed an unsavory hack in setup.py. There is a "version" argument to the setup() call. I define "version" as a global variable in setup.py. Before I call setup with this version number, I also modify the line of package code which defines its __version__. This works for me, but it feels wrong. Is there a recommended way to keep the internal reference and the setup.py reference in sync? Is there any reason someone would NOT want these numbers to match? Thanks for your input. From john_ladasky at sbcglobal.net Fri May 8 21:16:27 2020 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 8 May 2020 18:16:27 -0700 (PDT) Subject: Should setuptools version propagate to a module's __version__? If so, how? In-Reply-To: <48420bd4-5ebc-47ad-93fa-c7b6e05a315c@googlegroups.com> References: <48420bd4-5ebc-47ad-93fa-c7b6e05a315c@googlegroups.com> Message-ID: On Friday, May 8, 2020 at 6:07:33 PM UTC-7, John Ladasky wrote: > Is there a recommended way to keep the internal reference and the setup.py reference in sync? Is there any reason someone would NOT want these numbers to match? Replying to myself... I just found this: https://packaging.python.org/guides/single-sourcing-package-version/ From al.alexiev at gmail.com Fri May 8 20:19:20 2020 From: al.alexiev at gmail.com (al.alexiev at gmail.com) Date: Fri, 8 May 2020 17:19:20 -0700 (PDT) Subject: IP address to binary conversion In-Reply-To: References: Message-ID: <0783881a-989b-4bf1-9972-5d8573706ede@googlegroups.com> Just for the records and to have a fully working bidirectional solution: >>> ip '10.44.32.0' >>> struct.unpack('L', socket.inet_aton(ip))[0] 2108426 >>> socket.inet_ntoa(struct.pack('>> Good luck ;-) From tjreedy at udel.edu Fri May 8 21:08:39 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 8 May 2020 21:08:39 -0400 Subject: SaveAs on macOS Catalina. Message-ID: https://bugs.python.org/issue40553 At least a couple of people have had problems using SaveAs from IDLE when running on macOS Catalina. But Ned Deily cannot reproduce the issue. I cannot because I have refused the buggy 'upgrade'. We could use more data. What do other Catalina Python users experience? If not an IDLE user, the experiment is easy. In terminal: $ python3 -m idlelib In IDLE: File => New File => SaveAs In the macOS saveas dialog: Enter a minimal name that does not match an existing .py name in Documents. Hit [Save] button. Does the dialog save and close, or does it clear the Document content list and freeze? The three Apple apps I looked at, Safari, Maps, and Keynote do not display folder contents. This might be the problem. What do other Mac apps do? -- Terry Jan Reedy From countryone77 at gmail.com Fri May 8 22:37:52 2020 From: countryone77 at gmail.com (Bev In TX) Date: Fri, 8 May 2020 21:37:52 -0500 Subject: SaveAs on macOS Catalina. Message-ID: <9B78B085-089B-49AE-9FAF-E1DCFDC15773@gmail.com> ? > On May 8, 2020, at 8:29 PM, Terry Reedy wrote: > > https://bugs.python.org/issue40553 > > At least a couple of people have had problems using SaveAs from IDLE when running on macOS Catalina. But Ned Deily cannot reproduce the issue. I cannot because I have refused the buggy 'upgrade'. We could use more data. What do other Catalina Python users experience? > > If not an IDLE user, the experiment is easy. > > In terminal: > $ python3 -m idlelib > > In IDLE: > File => New > File => SaveAs > > In the macOS saveas dialog: > Enter a minimal name that does not match an existing .py name in Documents. Hit [Save] button. Does the dialog save and close, or does it clear the Document content list and freeze? > > The three Apple apps I looked at, Safari, Maps, and Keynote do not display folder contents. This might be the problem. What do other Mac apps do? That is not the problem. On macOS The default Save/Save as dialogs are short, only displaying a few major folders along with Favorites and Recents. That dialog doesn?t display folder contents. However, you can get an expanded dialog by clicking on the little arrow to the right of the Where box. Using that dialog allows one to select any folder and displays folder contents. I tried using both Save and Save as, and was unable to duplicate the problem with either the short or the long dialog. Python 3.8.2 macOS Catalina 10.15.4 Bev in TX From alan at csail.mit.edu Sat May 9 01:07:15 2020 From: alan at csail.mit.edu (Alan Bawden) Date: 09 May 2020 01:07:15 -0400 Subject: IP address to binary conversion References: <0783881a-989b-4bf1-9972-5d8573706ede@googlegroups.com> Message-ID: <86imh5lmrg.fsf@richard.bawden.org> al.alexiev at gmail.com writes: > Just for the records and to have a fully working bidirectional solution: > > >>> ip > '10.44.32.0' > >>> struct.unpack('L', socket.inet_aton(ip))[0] > 2108426 > >>> socket.inet_ntoa(struct.pack(' '10.44.32.0' > >>> > > Good luck ;-) This will not work as expected on a big-endian machine, because 'L' means _native_ byte order, but ' References: Message-ID: On 7/05/20 4:15 PM, Music lover wrote: > Hello python team, > I have installed the latest version of python from your site. > Then I successfully installed some modules like :- numpy , pandas, > matplotlib from command prompt. But I am not able to use them while > programing in python Idle. It's saying " no module named 'matplotlib' ." What do you mean by "It's saying..."? Please help us (volunteers) to help you... by copy-pasting the actual code and the actual error message into a reply to this message. The answers given already attempt to solve different possible problems, to which I can add - Are you using an import statement? - Does the error occur after the import? -- Regards =dn From auriocus at gmx.de Sat May 9 02:46:45 2020 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 9 May 2020 08:46:45 +0200 Subject: SaveAs on macOS Catalina. In-Reply-To: References: <9B78B085-089B-49AE-9FAF-E1DCFDC15773@gmail.com> Message-ID: Am 09.05.20 um 04:37 schrieb Bev In TX: > ? >> On May 8, 2020, at 8:29 PM, Terry Reedy wrote: >> >> https://bugs.python.org/issue40553 >> > On macOS The default Save/Save as dialogs are short, only displaying a few major folders along with Favorites and Recents. That dialog doesn?t display folder contents. However, you can get an expanded dialog by clicking on the little arrow to the right of the Where box. Using that dialog allows one to select any folder and displays folder contents. > > I tried using both Save and Save as, and was unable to duplicate the problem with either the short or the long dialog. > > Python 3.8.2 > macOS Catalina 10.15.4 Can it be a problem with the underlying Tk version? If so, it would be helpful to isolate the Tk call and convert it to an equivalent Tcl script for the core developers to test. Fairly recently, Tk has got many bugfixes because of changes in OSX. Here is the file that implements the file dialogs: https://core.tcl-lang.org/tk/artifact/d72cdfbcbfaa717f and the history: https://core.tcl-lang.org/tk/finfo?name=macosx/tkMacOSXDialog.c&m=d72cdfbcbfaa717f As you can see, it has been touched two days ago (!) to restore some window behaviour, which was switched of because of Catalina last August (this commit) https://core.tcl-lang.org/tk/info/59b1d265c2444112 Christian From bgailer at gmail.com Sat May 9 07:59:44 2020 From: bgailer at gmail.com (Bob Gailer) Date: Sat, 9 May 2020 07:59:44 -0400 Subject: Not able use installed modules In-Reply-To: <20200508181502.GB5589@Dream-Machine1> References: <20200508181502.GB5589@Dream-Machine1> Message-ID: On May 8, 2020 2:15 PM, "boB Stepp" wrote: [snip] > This may be a naive question on my part, but, as far as I can tell, most > instructions that I have encountered for installing Python packages state the > installation instructions as "pip install ...", which seems to repeatedly > lead to these type of OP questions. Has there ever been given thought to > changing these "standard" installation instructions to something less error > fraught for the newcomer/novice? > -- > Wishing you only the best, > > boB Stepp I agree. I've been using python for many many years and have been repeatedly frustrated with pip. Bob Gailer From chalao.adda at gmail.com Sat May 9 08:37:39 2020 From: chalao.adda at gmail.com (Joydeep C) Date: Sat, 9 May 2020 12:37:39 -0000 (UTC) Subject: Pandas Dataframe Numbers Comma Formatted Message-ID: I have a Pandas dataframe like below. X Y 0 12345 67890 1 54321 N/A 2 67890 123456 I need to make these numbers comma formatted. For example, 12345 => 12,345. Please help. Thanks. From chalao.adda at gmail.com Sat May 9 09:11:33 2020 From: chalao.adda at gmail.com (Joydeep C) Date: Sat, 9 May 2020 13:11:33 -0000 (UTC) Subject: Pandas Dataframe Numbers Comma Formatted References: <5eb6a51e$0$6464$426a74cc@news.free.fr> Message-ID: On Sat, 09 May 2020 14:42:43 +0200, Python wrote: > Joydeep wrote: >> I have a Pandas dataframe like below. >> >> X Y >> 0 12345 67890 1 54321 N/A 2 67890 123456 >> >> I need to make these numbers comma formatted. For example, 12345 => >> 12,345. > > >>> value = 12345 f'{value:,}' # >= 3.6 > '12,345' > >>> '{:,}'.format(value) # >= 2.7 > '12,345' I need all the numbers in the whole dataframe to be formatted like that, not one value. From __peter__ at web.de Sat May 9 09:50:55 2020 From: __peter__ at web.de (Peter Otten) Date: Sat, 09 May 2020 15:50:55 +0200 Subject: Pandas Dataframe Numbers Comma Formatted References: <5eb6a51e$0$6464$426a74cc@news.free.fr> Message-ID: Joydeep C wrote: > On Sat, 09 May 2020 14:42:43 +0200, Python wrote: > >> Joydeep wrote: >>> I have a Pandas dataframe like below. >>> >>> X Y >>> 0 12345 67890 1 54321 N/A 2 67890 123456 >>> >>> I need to make these numbers comma formatted. For example, 12345 => >>> 12,345. >> >> >>> value = 12345 f'{value:,}' # >= 3.6 >> '12,345' >> >>> '{:,}'.format(value) # >= 2.7 >> '12,345' > > I need all the numbers in the whole dataframe to be formatted like that, > not one value. >>> import pandas as pd >>> df = pd.DataFrame([[12345., 67890.], [54321, "N/A"]], columns=["X","Y"]) >>> df X Y 0 12345 67890 1 54321 N/A [2 rows x 2 columns] Reading the docstring for you: >>> help(df) | | to_string(self, buf=None, columns=None, col_space=None, colSpace=None, header=True, index=True, na_rep='NaN', formatters=None, float_format=None, sparsify=None, nanRep=None, index_names=True, justify=None, force_unicode=None, line_width=None, max_rows=None, max_cols=None, show_dimensions=False) | Render a DataFrame to a console-friendly tabular output. | | Parameters | ---------- | frame : DataFrame | object to render ... | float_format : one-parameter function, optional | formatter function to apply to columns' elements if they are floats | default None So: >>> print(df.to_string(float_format="{:,.0f}".format)) X Y 0 12,345 67,890 1 54,321 N/A From chalao.adda at gmail.com Sat May 9 10:26:50 2020 From: chalao.adda at gmail.com (Joydeep C) Date: Sat, 9 May 2020 14:26:50 -0000 (UTC) Subject: Pandas Dataframe Numbers Comma Formatted References: <5eb6a51e$0$6464$426a74cc@news.free.fr> <5eb6b40f$0$3869$426a74cc@news.free.fr> Message-ID: On Sat, 09 May 2020 15:46:27 +0200, Python wrote: > Joydeep C wrote: >> On Sat, 09 May 2020 14:42:43 +0200, Python wrote: >> >>> Joydeep wrote: >>>> I have a Pandas dataframe like below. >>>> >>>> X Y >>>> 0 12345 67890 1 54321 N/A 2 67890 123456 >>>> >>>> I need to make these numbers comma formatted. For example, 12345 => >>>> 12,345. >>> >>> >>> value = 12345 f'{value:,}' # >= 3.6 >>> '12,345' >>> >>> '{:,}'.format(value) # >= 2.7 >>> '12,345' >> >> I need all the numbers in the whole dataframe to be formatted like >> that, >> not one value. > > >>> data.applymap((lambda x: f"{x:,}") ) > X Y > 0 12,345 67,890.0 1 54,321 nan 2 67,890 12,345.0 > >>> data.apply(np.vectorize((lambda x: f"{x:,}"))) > X Y > 0 12,345 67,890.0 1 54,321 nan 2 67,890 12,345.0 It's giving error - "Cannot specify ',' with 's'." From chalao.adda at gmail.com Sat May 9 11:32:17 2020 From: chalao.adda at gmail.com (Joydeep C) Date: Sat, 9 May 2020 15:32:17 -0000 (UTC) Subject: Pandas Dataframe Numbers Comma Formatted References: <5eb6a51e$0$6464$426a74cc@news.free.fr> <5eb6b40f$0$3869$426a74cc@news.free.fr> <5eb6cb15$0$5889$426a74cc@news.free.fr> Message-ID: On Sat, 09 May 2020 17:24:41 +0200, Python wrote: > Joydeep C wrote: >> On Sat, 09 May 2020 15:46:27 +0200, Python wrote: >> >>> Joydeep C wrote: >>>> On Sat, 09 May 2020 14:42:43 +0200, Python wrote: >>>> >>>>> Joydeep wrote: >>>>>> I have a Pandas dataframe like below. >>>>>> >>>>>> X Y >>>>>> 0 12345 67890 1 54321 N/A 2 67890 123456 >>>>>> >>>>>> I need to make these numbers comma formatted. For example, 12345 => >>>>>> 12,345. >>>>> >>>>> >>> value = 12345 f'{value:,}' # >= 3.6 >>>>> '12,345' >>>>> >>> '{:,}'.format(value) # >= 2.7 >>>>> '12,345' >>>> >>>> I need all the numbers in the whole dataframe to be formatted like >>>> that, >>>> not one value. >>> >>> >>> data.applymap((lambda x: f"{x:,}") ) >>> X Y >>> 0 12,345 67,890.0 1 54,321 nan 2 67,890 12,345.0 >>> >>> data.apply(np.vectorize((lambda x: f"{x:,}"))) >>> X Y >>> 0 12,345 67,890.0 1 54,321 nan 2 67,890 12,345.0 >> >> It's giving error - "Cannot specify ',' with 's'." > > It means that you're not storing numbers in your dataframe but strings, > which is likely not what you want here. Fix that first. Of course, they are strings. It's "N/A", not nan. From justrock.akki at gmail.com Sat May 9 12:36:01 2020 From: justrock.akki at gmail.com (Akshay Ghodake) Date: Sat, 9 May 2020 22:06:01 +0530 Subject: Concatenation of multiple video files in single file Message-ID: Hello, I want a help to concatenation of multiple video files into a single file in python. Any help will be greatly appreciated. Best regards, Akshay Ghodake From python at python.invalid Sat May 9 08:42:43 2020 From: python at python.invalid (Python) Date: Sat, 9 May 2020 14:42:43 +0200 Subject: Pandas Dataframe Numbers Comma Formatted In-Reply-To: References: Message-ID: <5eb6a51e$0$6464$426a74cc@news.free.fr> Joydeep wrote: > I have a Pandas dataframe like below. > > X Y > 0 12345 67890 > 1 54321 N/A > 2 67890 123456 > > I need to make these numbers comma formatted. For example, 12345 => > 12,345. >>> value = 12345 >>> f'{value:,}' # >= 3.6 '12,345' >>> '{:,}'.format(value) # >= 2.7 '12,345' From python at python.invalid Sat May 9 09:46:27 2020 From: python at python.invalid (Python) Date: Sat, 9 May 2020 15:46:27 +0200 Subject: Pandas Dataframe Numbers Comma Formatted In-Reply-To: References: <5eb6a51e$0$6464$426a74cc@news.free.fr> Message-ID: <5eb6b40f$0$3869$426a74cc@news.free.fr> Joydeep C wrote: > On Sat, 09 May 2020 14:42:43 +0200, Python wrote: > >> Joydeep wrote: >>> I have a Pandas dataframe like below. >>> >>> X Y >>> 0 12345 67890 1 54321 N/A 2 67890 123456 >>> >>> I need to make these numbers comma formatted. For example, 12345 => >>> 12,345. >> >> >>> value = 12345 f'{value:,}' # >= 3.6 >> '12,345' >> >>> '{:,}'.format(value) # >= 2.7 >> '12,345' > > I need all the numbers in the whole dataframe to be formatted like that, > not one value. >>> data.applymap((lambda x: f"{x:,}") ) X Y 0 12,345 67,890.0 1 54,321 nan 2 67,890 12,345.0 >>> data.apply(np.vectorize((lambda x: f"{x:,}"))) X Y 0 12,345 67,890.0 1 54,321 nan 2 67,890 12,345.0 From python at python.invalid Sat May 9 11:24:41 2020 From: python at python.invalid (Python) Date: Sat, 9 May 2020 17:24:41 +0200 Subject: Pandas Dataframe Numbers Comma Formatted In-Reply-To: References: <5eb6a51e$0$6464$426a74cc@news.free.fr> <5eb6b40f$0$3869$426a74cc@news.free.fr> Message-ID: <5eb6cb15$0$5889$426a74cc@news.free.fr> Joydeep C wrote: > On Sat, 09 May 2020 15:46:27 +0200, Python wrote: > >> Joydeep C wrote: >>> On Sat, 09 May 2020 14:42:43 +0200, Python wrote: >>> >>>> Joydeep wrote: >>>>> I have a Pandas dataframe like below. >>>>> >>>>> X Y >>>>> 0 12345 67890 1 54321 N/A 2 67890 123456 >>>>> >>>>> I need to make these numbers comma formatted. For example, 12345 => >>>>> 12,345. >>>> >>>> >>> value = 12345 f'{value:,}' # >= 3.6 >>>> '12,345' >>>> >>> '{:,}'.format(value) # >= 2.7 >>>> '12,345' >>> >>> I need all the numbers in the whole dataframe to be formatted like >>> that, >>> not one value. >> >> >>> data.applymap((lambda x: f"{x:,}") ) >> X Y >> 0 12,345 67,890.0 1 54,321 nan 2 67,890 12,345.0 >> >>> data.apply(np.vectorize((lambda x: f"{x:,}"))) >> X Y >> 0 12,345 67,890.0 1 54,321 nan 2 67,890 12,345.0 > > It's giving error - "Cannot specify ',' with 's'." It means that you're not storing numbers in your dataframe but strings, which is likely not what you want here. Fix that first. From python at python.invalid Sat May 9 11:38:34 2020 From: python at python.invalid (Python) Date: Sat, 9 May 2020 17:38:34 +0200 Subject: Pandas Dataframe Numbers Comma Formatted In-Reply-To: References: <5eb6a51e$0$6464$426a74cc@news.free.fr> <5eb6b40f$0$3869$426a74cc@news.free.fr> <5eb6cb15$0$5889$426a74cc@news.free.fr> Message-ID: <5eb6ce56$0$21617$426a74cc@news.free.fr> Joydeep C wrote: > On Sat, 09 May 2020 17:24:41 +0200, Python wrote: > >> Joydeep C wrote: >>> On Sat, 09 May 2020 15:46:27 +0200, Python wrote: >>> >>>> Joydeep C wrote: >>>>> On Sat, 09 May 2020 14:42:43 +0200, Python wrote: >>>>> >>>>>> Joydeep wrote: >>>>>>> I have a Pandas dataframe like below. >>>>>>> >>>>>>> X Y >>>>>>> 0 12345 67890 1 54321 N/A 2 67890 123456 >>>>>>> >>>>>>> I need to make these numbers comma formatted. For example, 12345 => >>>>>>> 12,345. >>>>>> >>>>>> >>> value = 12345 f'{value:,}' # >= 3.6 >>>>>> '12,345' >>>>>> >>> '{:,}'.format(value) # >= 2.7 >>>>>> '12,345' >>>>> >>>>> I need all the numbers in the whole dataframe to be formatted like >>>>> that, >>>>> not one value. >>>> >>>> >>> data.applymap((lambda x: f"{x:,}") ) >>>> X Y >>>> 0 12,345 67,890.0 1 54,321 nan 2 67,890 12,345.0 >>>> >>> data.apply(np.vectorize((lambda x: f"{x:,}"))) >>>> X Y >>>> 0 12,345 67,890.0 1 54,321 nan 2 67,890 12,345.0 >>> >>> It's giving error - "Cannot specify ',' with 's'." >> >> It means that you're not storing numbers in your dataframe but strings, >> which is likely not what you want here. Fix that first. > > Of course, they are strings. It's "N/A", not nan. So convert back to float in the lambda, when appropriate, then use the format string. From al.alexiev at gmail.com Sat May 9 12:23:08 2020 From: al.alexiev at gmail.com (al.alexiev at gmail.com) Date: Sat, 9 May 2020 09:23:08 -0700 (PDT) Subject: IP address to binary conversion In-Reply-To: <86imh5lmrg.fsf@richard.bawden.org> References: <0783881a-989b-4bf1-9972-5d8573706ede@googlegroups.com> <86imh5lmrg.fsf@richard.bawden.org> Message-ID: <88d47760-580b-40ef-887b-e8dec340c012@googlegroups.com> Hi Alan, Yes, agreed that any '!I' or '!L' combination will work on different type of platforms in a consistent manner, when applied in both directions. I was referring to Alex Martelli's output, where the conversion back to IP seems to be reversed, even with '!L', which means that he's already with a little-endian byte order and using 'L' or '>> ip = '1.2.168.0' >>> struct.unpack('L', socket.inet_aton(ip))[0] 11010561 >>> struct.unpack('>> struct.unpack('!L', socket.inet_aton(ip))[0] 16951296 >>> >>> socket.inet_ntoa(struct.pack('!L',11010561)) '0.168.2.1' >>> socket.inet_ntoa(struct.pack('>> socket.inet_ntoa(struct.pack('!L',16951296)) '1.2.168.0' >>> Greets, Alex From rosuav at gmail.com Sat May 9 18:51:17 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 May 2020 08:51:17 +1000 Subject: Concatenation of multiple video files in single file In-Reply-To: References: Message-ID: On Sun, May 10, 2020 at 8:50 AM Akshay Ghodake wrote: > > Hello, > > I want a help to concatenation of multiple video files into a single file > in python. > > Any help will be greatly appreciated. Step 1: import subprocess Step 2: Run ffmpeg ChrisA From cs at cskk.id.au Sat May 9 23:16:56 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 10 May 2020 13:16:56 +1000 Subject: Should setuptools version propagate to a module's __version__? If so, how? In-Reply-To: <48420bd4-5ebc-47ad-93fa-c7b6e05a315c@googlegroups.com> References: <48420bd4-5ebc-47ad-93fa-c7b6e05a315c@googlegroups.com> Message-ID: <20200510031656.GA23447@cskk.homeip.net> On 08May2020 18:07, John Ladasky wrote: >I just came across a package in PyPI which is in a state of neglect. The official version on the PyPI page is 1.3.1 -- but the installed module reports its version as 1.2.0. This is confusing. > >There are several bugs in this package besides the mismatched version number. I've forked a copy of the package on GitHub, and I will attempt a cleanup. > >In another private package of my own, I performed an unsavory hack in setup.py. There is a "version" argument to the setup() call. I define "version" as a global variable in setup.py. Before I call setup with this version number, I also modify the line of package code which defines its __version__. This works for me, but it feels wrong. > >Is there a recommended way to keep the internal reference and the >setup.py reference in sync? Is there any reason someone would NOT want >these numbers to match? My release script writes the setup.py on the fly, so it gets the version number from the release tag I use. I also autopatch the module itself to set __version__ to match when I make that release tag. Cheers, Cameron Simpson From best_lay at yahoo.com Sun May 10 00:52:11 2020 From: best_lay at yahoo.com (Wildman) Date: Sat, 09 May 2020 23:52:11 -0500 Subject: Concatenation of multiple video files in single file References: Message-ID: On Sat, 09 May 2020 22:06:01 +0530, Akshay Ghodake wrote: > Hello, > > I want a help to concatenation of multiple video files into a single file > in python. > > Any help will be greatly appreciated. > > Best regards, > Akshay Ghodake This might help... https://kkroening.github.io/ffmpeg-python/ -- GNU/Linux user #557453 The cow died so I don't need your bull! From mal at europython.eu Sun May 10 11:16:26 2020 From: mal at europython.eu (M.-A. Lemburg) Date: Sun, 10 May 2020 17:16:26 +0200 Subject: EuroPython 2020: First part of the program available Message-ID: <861a92da-144f-6605-0e6e-3a7fffe6896a@europython.eu> Our program work group (WG) has been working hard over the last week to select the first batch of sessions for EuroPython 2020, based on your talk voting and our diversity criteria. We?re now happy to announce the first 60 talks, brought to you by 61 speakers. * EuroPython 2020 Session List * https://ep2020.europython.eu/events/sessions/ We will have over 80 sessions for EP2020 ---------------------------------------- Tomorrow, we will open the second CFP to fill the additional slots we have added for the Americas, India/Asian/Pacific time zones. This will then complete the program for EP2020, with over 80 sessions by more than 80 speakers waiting for you ? from all over the world ! https://blog.europython.eu/post/617552560206872576/europython-2020-second-call-for-proposals-cfp Waiting List ------------ Some talks are still in the waiting list. We will inform all speakers who have submitted talks about the selection status by email. Full Schedule ------------- The full schedule will be available shortly after we have completed the second CFP, later in May. Conference Tickets ------------------ Conference tickets are available on our registration page. We have simplified and greatly reduced the prices for the EP2020 online edition. As always, all proceeds from the conference will go into our grants budget, which we use to fund financial aid for the next EuroPython edition, special workshops and other European conferences and projects: * EuroPython Society Grants Program * https://www.europython-society.org/grants We hope to see lots of you at the conference in July. Rest assured that we?ll make this a great event again ? even within the limitations of running the conference online. 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/617740494311718912/europython-2020-first-part-of-the-program Tweet: https://twitter.com/europython/status/1259500793096527872 Thanks, -- EuroPython 2020 Team https://ep2020.europython.eu/ https://www.europython-society.org/ From grant.b.edwards at gmail.com Sat May 9 21:37:39 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 10 May 2020 01:37:39 -0000 (UTC) Subject: Concatenation of multiple video files in single file References: Message-ID: On 2020-05-09, Chris Angelico wrote: > On Sun, May 10, 2020 at 8:50 AM Akshay Ghodake wrote: > >> I want a help to concatenation of multiple video files into a single file >> in python. >> >> Any help will be greatly appreciated. > > Step 1: > import subprocess > > Step 2: > Run ffmpeg Definitely. Mencoder does a nice job with some containers (particularly AVI), but ffmpeg is probably more actively maintained and more widely applicable. If you would rather spend weeks instead of minutes, you could try using Python ffmpeg bindings: https://github.com/kkroening/ffmpeg-python That will take a lot longer to develop and work and won't as well. If you would rather spend years instead of weeks, you start with this: import sys infile = open(sys.argv[1],'rb') outfile = open(sys.argv[2],'wb') print("Converting %s to %s" % (sys.argv[1],sys.argv[2])) # some stuff goes here infile.close() outfile.close() Then you study the specifications for the container formats you want to support, the audio and video codecs you want to support, and fill in 'some stuff'. This will take, much, much longer to develop and mostly just won't work, period. You will learn a lot more, though. :) -- Grant From john_ladasky at sbcglobal.net Sun May 10 16:00:03 2020 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sun, 10 May 2020 13:00:03 -0700 (PDT) Subject: Should setuptools version propagate to a module's __version__? If so, how? In-Reply-To: References: <48420bd4-5ebc-47ad-93fa-c7b6e05a315c@googlegroups.com> <20200510031656.GA23447@cskk.homeip.net> Message-ID: On Saturday, May 9, 2020 at 8:17:19 PM UTC-7, Cameron Simpson wrote: > I also autopatch the module itself to > set __version__ to match when I make that release tag. Yes, that's exactly what the module I wrote for my company's internal use does. The official version number is hard-coded into setup.py. My setup.py opens my module's __init__.py, and patches the line that starts with "__version__ = ". I can see that this approach is one of several suggested approaches described in the Python packaging guide. If I'm going to work with a package that eventually ends up on PyPI, I want to make sure that I don't do something unexpected or fragile. From facerias at gmail.com Sun May 10 16:27:48 2020 From: facerias at gmail.com (facerias at gmail.com) Date: Sun, 10 May 2020 13:27:48 -0700 (PDT) Subject: How to translate this SQL query to Pandas query Message-ID: I need to translate this SQL query to Pandas: SELECT * FROM df_dicodes AS di LEFT OUTER JOIN df_2 AS h2 ON di.Dicode = h2.NM_code AND (datetime(julianday(datetime(di.LastResolDate))) - datetime(julianday(datetime(h2.FechaLectura))) < 180) AND ((di.Oficina=h2.Centro AND di.Incidencia=h2.`Num Ticket`) OR (di.Incidencia=h2.`Num Ticket` AND (di.Oficina=h2.Centro OR h2.Centro BETWEEN '22015' AND '22025') OR (di.Incidencia=h2.`Num Ticket` AND (di.Oficina <> h2.Centro OR h2.Centro BETWEEN '22015' AND '22025'))) OR (di.Oficina=h2.Centro)) ORDER BY di.Oficina; df_result = pd.merge(df_dicodes, df_2, how='left', left_on=['Dicode'], right_on=['NM_Code']) How could I continue this merge? Thanks! From cs at cskk.id.au Sun May 10 21:38:45 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 11 May 2020 11:38:45 +1000 Subject: Should setuptools version propagate to a module's __version__? If so, how? In-Reply-To: References: Message-ID: <20200511013845.GA24216@cskk.homeip.net> On 10May2020 13:00, John Ladasky wrote: >On Saturday, May 9, 2020 at 8:17:19 PM UTC-7, Cameron Simpson wrote: >> I also autopatch the module itself to >> set __version__ to match when I make that release tag. > >Yes, that's exactly what the module I wrote for my company's internal use does. The official version number is hard-coded into setup.py. My setup.py opens my module's __init__.py, and patches the line that starts with "__version__ = ". > >I can see that this approach is one of several suggested approaches >described in the Python packaging guide. If I'm going to work with a >package that eventually ends up on PyPI, I want to make sure that I >don't do something unexpected or fragile. Yah. In my case the VCS tag is the reference from which I make the setup.py and patch the source file. Cheers, Cameron Simpson From s.faruna at futminna.edu.ng Sun May 10 17:31:52 2020 From: s.faruna at futminna.edu.ng (Solomon Onuche Faruna) Date: Sun, 10 May 2020 22:31:52 +0100 Subject: Installation problem Message-ID: I install python 3.8 and pycharm community edition on window 8 but when I try to install matplotlib in pycharm I discovered I got "error loading package list pypi.python.org" so I updated the pycharm to version 2020.1. The packages loaded but when I try to install matplotlib I was told "No matching distribution found for matplotlib". I am confused right now. I need urgent help. Thanks From scooky2000 at gmail.com Sun May 10 20:30:18 2020 From: scooky2000 at gmail.com (Del Mervine) Date: Sun, 10 May 2020 17:30:18 -0700 Subject: Concatenation of multiple video files in single file In-Reply-To: References: Message-ID: On 5/9/20 9:36 AM, Akshay Ghodake wrote: > Hello, > > I want a help to concatenation of multiple video files into a single file > in python. > > Any help will be greatly appreciated. > > Best regards, > Akshay Ghodake As others have said, ffmpeg. If you need more processing features, Vapoursynth might be an option. You have the ability to build complex processing graphs that run in optimized C/ASM. Vapoursynth is built with Cython so scripts run faster than pure python. From cdarlint at gmail.com Mon May 11 03:17:14 2020 From: cdarlint at gmail.com (cdarlint at gmail.com) Date: Mon, 11 May 2020 00:17:14 -0700 (PDT) Subject: Error: thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable t In-Reply-To: <36ed0fc8-508c-4a4a-8424-0b5e5916c0cb@googlegroups.com> References: <36ed0fc8-508c-4a4a-8424-0b5e5916c0cb@googlegroups.com> Message-ID: <842475f8-4960-4c5b-8978-3a4194915bd5@googlegroups.com> On Friday, October 11, 2019 at 6:27:40 PM UTC+8, prabakar... at gmail.com wrote: > python> conn = hive.Connection(host="xx.xx.xxx.xxx",port=8889,username='hadoop') > > C:\Users\Nova15>python > Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> from pyhive import hive > >>> conn = hive.Connection(host="54.169.219.144",port=8889,username='hadoop') > Traceback (most recent call last): > File "", line 1, in > File "c:\users\nova15\appdata\local\programs\python\python37\lib\site-packages\pyhive\hive.py", line 192, in __init__ > self._transport.open() > File "c:\users\nova15\appdata\local\programs\python\python37\lib\site-packages\thrift_sasl\__init__.py", line 79, in open > message=("Could not start SASL: %s" % self.sasl.getError())) > thrift.transport.TTransport.TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2' > > > I am trying to connect from windows 10 local to Prestodb in AWS. I've worked out some steps to make it work basically it needs to find sasl2 folder, which located site-library/sasl(pip) or Library/bin(conda) method 1: put sasl2 folder into C:\CMU\bin\ method 2: add an entry in registry, to the sasl2 folder, e.g. HKEY_LOCAL_MACHINE\SOFTWARE\Carnegie Mellon\Project Cyrus\SASL Library\SearchPath C:\Users\cdarling\Miniconda3\envs\hive\Library\bin\sasl2 I've replied related github issue too https://github.com/dropbox/PyHive/issues/161 From cdarlint at gmail.com Mon May 11 03:19:22 2020 From: cdarlint at gmail.com (cdarlint at gmail.com) Date: Mon, 11 May 2020 00:19:22 -0700 (PDT) Subject: Installation problem In-Reply-To: References: Message-ID: <26823510-63db-4c41-8f02-a44831978a59@googlegroups.com> On Monday, May 11, 2020 at 9:56:17 AM UTC+8, Solomon Onuche Faruna wrote: > I install python 3.8 and pycharm community edition on window 8 but when I > try to install matplotlib in pycharm I discovered I got "error loading > package list pypi.python.org" so I updated the pycharm to version 2020.1. > The packages loaded but when I try to install matplotlib I was told "No > matching distribution found for matplotlib". I am confused right now. I > need urgent help. Thanks I would suggest you to install Anaconda which include python/numpy and possibly matplotlib altogether if not included, just run in cmd: conda install matplotlib and it will be installed From pariisaap at gmail.com Mon May 11 10:41:42 2020 From: pariisaap at gmail.com (pariisaap at gmail.com) Date: Mon, 11 May 2020 07:41:42 -0700 (PDT) Subject: scikit learn problem Message-ID: <69cd19cf-5e39-497b-bf47-569cd6ff82fe@googlegroups.com> Hello I tried to run a pickle and after that i couldn't to run any program containing sklearn I uninstall python and install again but i still have problem with scikit learn can anybody help me . thank you. From pariisaap at gmail.com Mon May 11 10:49:04 2020 From: pariisaap at gmail.com (pariisaap at gmail.com) Date: Mon, 11 May 2020 07:49:04 -0700 (PDT) Subject: scikit learn problem In-Reply-To: <69cd19cf-5e39-497b-bf47-569cd6ff82fe@googlegroups.com> References: <69cd19cf-5e39-497b-bf47-569cd6ff82fe@googlegroups.com> Message-ID: On Monday, 11 May 2020 19:11:59 UTC+4:30, pari... at gmail.com wrote: > Hello > I tried to run a pickle code and after that i couldn't run any program containing sklearn > I uninstall python and install again but i still have problem with scikit learn can anybody help me . thank you. the error is something like that "Traceback (most recent call last): File "C:/Users/Rahaaaa/Desktop/python/sckitlearn/6.py", line 1, in from sklearn.linear_model import LogisticRegression File "C:\Users\Rahaaaa\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\__init__.py", line 76, in from .base import clone" From pariisaap at gmail.com Mon May 11 10:50:14 2020 From: pariisaap at gmail.com (pariisaap at gmail.com) Date: Mon, 11 May 2020 07:50:14 -0700 (PDT) Subject: scikit learn problem In-Reply-To: <69cd19cf-5e39-497b-bf47-569cd6ff82fe@googlegroups.com> References: <69cd19cf-5e39-497b-bf47-569cd6ff82fe@googlegroups.com> Message-ID: On Monday, 11 May 2020 19:11:59 UTC+4:30, pari... at gmail.com wrote: > Hello > I tried to run a pickle and after that i couldn't run any program containing sklearn > I uninstall python and install again but i still have problem with scikit learn can anybody help me . thank you. the error is something like that "Traceback (most recent call last): File "C:/Users/Rahaaaa/Desktop/python/sckitlearn/6.py", line 1, in from sklearn.linear_model import LogisticRegression File "C:\Users\Rahaaaa\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\__init__.py", line 76, in from .base import clone" From souvik.viksou at gmail.com Mon May 11 11:23:51 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Mon, 11 May 2020 20:53:51 +0530 Subject: scikit learn problem In-Reply-To: References: <69cd19cf-5e39-497b-bf47-569cd6ff82fe@googlegroups.com> Message-ID: Is that the complete error message? On Mon, 11 May, 2020, 8:25 pm , wrote: > On Monday, 11 May 2020 19:11:59 UTC+4:30, pari... at gmail.com wrote: > > Hello > > I tried to run a pickle and after that i couldn't run any program > containing sklearn > > I uninstall python and install again but i still have problem with > scikit learn can anybody help me . thank you. > the error is something like that > > > "Traceback (most recent call last): > File "C:/Users/Rahaaaa/Desktop/python/sckitlearn/6.py", line 1, in > > from sklearn.linear_model import LogisticRegression > File > "C:\Users\Rahaaaa\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\__init__.py", > line 76, in > from .base import clone" > > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Mon May 11 13:16:24 2020 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 11 May 2020 18:16:24 +0100 Subject: scikit learn problem In-Reply-To: References: <69cd19cf-5e39-497b-bf47-569cd6ff82fe@googlegroups.com> Message-ID: <82972e2b-a723-1bc3-0daa-44f37bf93ef4@mrabarnett.plus.com> On 2020-05-11 16:23, Souvik Dutta wrote: > Is that the complete error message? > It's a strange traceback because it shows a path with slashes (on Windows?) and a path with backslashes. > On Mon, 11 May, 2020, 8:25 pm , wrote: > >> On Monday, 11 May 2020 19:11:59 UTC+4:30, pari... at gmail.com wrote: >> > Hello >> > I tried to run a pickle and after that i couldn't run any program >> containing sklearn >> > I uninstall python and install again but i still have problem with >> scikit learn can anybody help me . thank you. >> the error is something like that >> >> >> "Traceback (most recent call last): >> File "C:/Users/Rahaaaa/Desktop/python/sckitlearn/6.py", line 1, in >> >> from sklearn.linear_model import LogisticRegression >> File >> "C:\Users\Rahaaaa\AppData\Local\Programs\Python\Python37\lib\site-packages\sklearn\__init__.py", >> line 76, in >> from .base import clone" >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From mats at python.org Mon May 11 13:33:05 2020 From: mats at python.org (Mats Wichmann) Date: Mon, 11 May 2020 11:33:05 -0600 Subject: Installation problem In-Reply-To: References: Message-ID: <212ea04f-125d-efbc-acf1-8b7582e25ac2@python.org> On 5/10/20 3:31 PM, Solomon Onuche Faruna wrote: > I install python 3.8 and pycharm community edition on window 8 but when I > try to install matplotlib in pycharm I discovered I got "error loading > package list pypi.python.org" so I updated the pycharm to version 2020.1. > The packages loaded but when I try to install matplotlib I was told "No > matching distribution found for matplotlib". I am confused right now. I > need urgent help. Thanks > The message normally means either the architecture or the python version is not available in a package uploaded to pypi. It doesn't sound like the version is the problem at least - you're trying 3.8 and matplotlib now has 3.8 packages. pypi access, meanwhile, may have some problems if you're having to go through a proxy for your network connection - it doesn't use the one set up for your web browser. https://pip.pypa.io/en/stable/user_guide/ Just a couple of things to think about... The advice you've already received to get a unified environment through Anaconda is a good one. It was created largely for that reason - getting numpy, scipy, matplotlib, etc. all installed can be a daunting task if you're new to the Python package world. From defenastrator at gmail.com Mon May 11 15:58:47 2020 From: defenastrator at gmail.com (Will Bradshaw) Date: Mon, 11 May 2020 12:58:47 -0700 (PDT) Subject: proposal for slice hashing Message-ID: <82778d45-0cf6-4959-a0b0-f6fe3ebb2f30@googlegroups.com> I recently ran into a situation where I needed to hash a slice and found this to be unsupported. This seems silly as there is little benefit of slices not supporting hashing and large downsides. This coupled with the fact that one cannot subclass slices is a significant and needless annoyance. It seems to me a hash of a slices would simply be a hash of a slice would (in python) be: def __hash__(self): return hash((self.start, self.stop, self.step)) I can see no reason why this is not the case Context: I have an object that presents itself as a multidimensional array in the numpy style but is computes it's values on __getitem__ calls as it represents an infinite field of numbers. However this operation is expensive. In many cases the same slice of the field will be needed repeatedly. This lends itself to using an lru cache on __getitem__() however this does not work as slices cannot be stored in the dictionary key used for the lru_cache.* The only options as of now are: 1. use 3 layers of wrappers to pack the slices into a custom type that supports hashing pass this mangled version of the arguments through lru_cache wrapper into a function that reverses the process of the first wrapper and passes through to the underlying implementation. (see below "code for workaround" as example) - This is kinda jank and arguably slow. Though in my case the cost of the calculation operation dwarfs this cost by an several orders of magnitude. - mapping may be unreliable and is a rather long and impenetrable mess. 2. implementing my own custom caching for this situation which does not scale well and is a heck of a lot of work. 3. implement a special case for slices in the lru_cache function. However, this is just moving the problem into the functools library. * While I do realize that further efficiency gains would be found by caching results in a sparse and tracking what is and is not filled in the field thus keeping what is essentially a by cell cache that would be significantly more work and unlikely to yield much better results in my case and still doesn't solve the general use case. Code for Workaround: from functools import lru_cache class _hashable_slice(object): __slots__ = ['slice'] def __init__(self, s: slice): self.slice = s def __hash__(self): return hash((self.slice.start, self.slice.stop, self.slice.step)) def __eq__(self, other): return other == self.slice def slice_lru_cache(*lru_args, **lru_kwargs): lru_wrapper = lru_cache(*lru_args, **lru_kwargs) def decorator(f): @lru_wrapper def inner(*args, **kwargs): def unpack(x): if isinstance(x, _hashable_slice): return x.slice if isinstance(x, (tuple, list)): return type(x)(unpack(v) for v in x) else: return x return f(*(unpack(v) for v in args), **{k: unpack(v) for k, v in kwargs.items()}) def wrapper(*args, **kwargs): def pack(x): if isinstance(x, slice): return _hashable_slice(x) if isinstance(x, (tuple, list)): return type(x)(pack(v) for v in x) else: return x return inner(*(pack(v) for v in args), **{k: pack(v) for k, v in kwargs.items()}) wrapper.__getattr__ = lambda name: getattr(inner, name) return wrapper return decorator From rosuav at gmail.com Mon May 11 16:10:28 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 May 2020 06:10:28 +1000 Subject: proposal for slice hashing In-Reply-To: <82778d45-0cf6-4959-a0b0-f6fe3ebb2f30@googlegroups.com> References: <82778d45-0cf6-4959-a0b0-f6fe3ebb2f30@googlegroups.com> Message-ID: On Tue, May 12, 2020 at 6:01 AM Will Bradshaw wrote: > The only options as of now are: > 1. use 3 layers of wrappers to pack the slices into a custom type that supports hashing pass this mangled version of the arguments through lru_cache wrapper into a function that reverses the process of the first wrapper and passes through to the underlying implementation. (see below "code for workaround" as example) > - This is kinda jank and arguably slow. Though in my case the cost of the calculation operation dwarfs this cost by an several orders of magnitude. > - mapping may be unreliable and is a rather long and impenetrable mess. > 2. implementing my own custom caching for this situation which does not scale well and is a heck of a lot of work. > 3. implement a special case for slices in the lru_cache function. However, this is just moving the problem into the functools library. > 4. Implement __getitem__ as a wrapper around a caching lookup function that simply takes the three arguments. def __getitem__(self, slice): return generate_values(slice.start, slice.stop, slice.step) @lru_cache def generate_values(start, stop, step): ... Not sure if this makes it easy enough to not worry about the hashability. ChrisA From defenastrator at gmail.com Mon May 11 16:26:50 2020 From: defenastrator at gmail.com (Will Bradshaw) Date: Mon, 11 May 2020 13:26:50 -0700 (PDT) Subject: proposal for slice hashing In-Reply-To: References: <82778d45-0cf6-4959-a0b0-f6fe3ebb2f30@googlegroups.com> Message-ID: On Monday, May 11, 2020 at 4:10:56 PM UTC-4, Chris Angelico wrote: > On Tue, May 12, 2020 at 6:01 AM Will Bradshaw wrote: > > The only options as of now are: > > 1. use 3 layers of wrappers to pack the slices into a custom type that supports hashing pass this mangled version of the arguments through lru_cache wrapper into a function that reverses the process of the first wrapper and passes through to the underlying implementation. (see below "code for workaround" as example) > > - This is kinda jank and arguably slow. Though in my case the cost of the calculation operation dwarfs this cost by an several orders of magnitude. > > - mapping may be unreliable and is a rather long and impenetrable mess. > > 2. implementing my own custom caching for this situation which does not scale well and is a heck of a lot of work. > > 3. implement a special case for slices in the lru_cache function. However, this is just moving the problem into the functools library. > > > > 4. Implement __getitem__ as a wrapper around a caching lookup function > that simply takes the three arguments. > > def __getitem__(self, slice): > return generate_values(slice.start, slice.stop, slice.step) > > @lru_cache > def generate_values(start, stop, step): > ... > > Not sure if this makes it easy enough to not worry about the hashability. > > ChrisA does not work in the case of multi dimensional __getitem__ calls in the numpy style which happens to be my case as the number of dimensions in the indexes changes by case and all of the following are supported for each axis: slice, array of indexes, int index, and other custom index object types which I am hesitant to disclose) From rosuav at gmail.com Mon May 11 16:45:28 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 May 2020 06:45:28 +1000 Subject: proposal for slice hashing In-Reply-To: References: <82778d45-0cf6-4959-a0b0-f6fe3ebb2f30@googlegroups.com> Message-ID: On Tue, May 12, 2020 at 6:31 AM Will Bradshaw wrote: > > On Monday, May 11, 2020 at 4:10:56 PM UTC-4, Chris Angelico wrote: > > On Tue, May 12, 2020 at 6:01 AM Will Bradshaw wrote: > > > The only options as of now are: > > > 1. use 3 layers of wrappers to pack the slices into a custom type that supports hashing pass this mangled version of the arguments through lru_cache wrapper into a function that reverses the process of the first wrapper and passes through to the underlying implementation. (see below "code for workaround" as example) > > > - This is kinda jank and arguably slow. Though in my case the cost of the calculation operation dwarfs this cost by an several orders of magnitude. > > > - mapping may be unreliable and is a rather long and impenetrable mess. > > > 2. implementing my own custom caching for this situation which does not scale well and is a heck of a lot of work. > > > 3. implement a special case for slices in the lru_cache function. However, this is just moving the problem into the functools library. > > > > > > > 4. Implement __getitem__ as a wrapper around a caching lookup function > > that simply takes the three arguments. > > > > def __getitem__(self, slice): > > return generate_values(slice.start, slice.stop, slice.step) > > > > @lru_cache > > def generate_values(start, stop, step): > > ... > > > > Not sure if this makes it easy enough to not worry about the hashability. > > > > ChrisA > > does not work in the case of multi dimensional __getitem__ calls in the numpy style which happens to be my case as the number of dimensions in the indexes changes by case and all of the following are supported for each axis: slice, array of indexes, int index, and other custom index object types which I am hesitant to disclose) > Ah, fair enough. Was just looking for a solution that would work on existing Python versions rather than demanding an upgrade to 3.10 :) Your use-case isn't common, but on the other hand, making slice objects hashable doesn't seem like it'd break anything. Obviously they'd only be hashable if start/stop/step are all hashable, but that's no different from tuples. +0.5. BTW, your third option (moving the problem to functools) might actually be easier than you think. You'd ultimately just be changing the behaviour of _make_key. Unfortunately there's no easy way to replace that function for a specific lru_cache, but that might itself be a useful feature. Imagine this: @lru_cache(make_key=hashable_slices) def __getitem__(self, item): ... Current implementation has a single global _make_key function that then gets snapshotted into the closure, so you could do something hacky as a proof of concept: old = functools._make_key functools._make_key = hashable_slices @lru_cache def __getitem__(self, item): ... functools._make_key = old Obviously that's bad code, but it's a great low-effort proof of concept :) ChrisA From defenastrator at gmail.com Mon May 11 18:09:17 2020 From: defenastrator at gmail.com (Will Bradshaw) Date: Mon, 11 May 2020 15:09:17 -0700 (PDT) Subject: proposal for slice hashing In-Reply-To: References: <82778d45-0cf6-4959-a0b0-f6fe3ebb2f30@googlegroups.com> Message-ID: <0bac516c-6a51-41ad-80b6-b7f9477af8ad@googlegroups.com> On Monday, May 11, 2020 at 4:45:55 PM UTC-4, Chris Angelico wrote: > On Tue, May 12, 2020 at 6:31 AM Will Bradshaw wrote: > > > > On Monday, May 11, 2020 at 4:10:56 PM UTC-4, Chris Angelico wrote: > > > On Tue, May 12, 2020 at 6:01 AM Will Bradshaw wrote: > > > > The only options as of now are: > > > > 1. use 3 layers of wrappers to pack the slices into a custom type that supports hashing pass this mangled version of the arguments through lru_cache wrapper into a function that reverses the process of the first wrapper and passes through to the underlying implementation. (see below "code for workaround" as example) > > > > - This is kinda jank and arguably slow. Though in my case the cost of the calculation operation dwarfs this cost by an several orders of magnitude. > > > > - mapping may be unreliable and is a rather long and impenetrable mess. > > > > 2. implementing my own custom caching for this situation which does not scale well and is a heck of a lot of work. > > > > 3. implement a special case for slices in the lru_cache function. However, this is just moving the problem into the functools library. > > > > > > > > > > 4. Implement __getitem__ as a wrapper around a caching lookup function > > > that simply takes the three arguments. > > > > > > def __getitem__(self, slice): > > > return generate_values(slice.start, slice.stop, slice.step) > > > > > > @lru_cache > > > def generate_values(start, stop, step): > > > ... > > > > > > Not sure if this makes it easy enough to not worry about the hashability. > > > > > > ChrisA > > > > does not work in the case of multi dimensional __getitem__ calls in the numpy style which happens to be my case as the number of dimensions in the indexes changes by case and all of the following are supported for each axis: slice, array of indexes, int index, and other custom index object types which I am hesitant to disclose) > > > > Ah, fair enough. Was just looking for a solution that would work on > existing Python versions rather than demanding an upgrade to 3.10 :) I have a solution to the issue in current python, it was given in my first post at the bottom. I implemented a variant of it for my work. Just because there is a hack does not mean a fix should not be implemented. > Your use-case isn't common, but on the other hand, making slice > objects hashable doesn't seem like it'd break anything. Obviously > they'd only be hashable if start/stop/step are all hashable, but > that's no different from tuples. +0.5. I'm certain that my use case is not common. However, there are certainly many uncommon use cases in which being able to have a slice in a dictionary key or otherwise hashing a slice could be useful. > > BTW, your third option (moving the problem to functools) might > actually be easier than you think. You'd ultimately just be changing > the behaviour of _make_key. Unfortunately there's no easy way to > replace that function for a specific lru_cache, but that might itself > be a useful feature. Imagine this: > > @lru_cache(make_key=hashable_slices) > def __getitem__(self, item): > ... This is a good idea as it would allow for quite a bit of tuning by the user and allow trade offs to be made between cache lookup complexity and potentially unnecessary re-computes. From buddy.peacock at gmail.com Mon May 11 22:33:14 2020 From: buddy.peacock at gmail.com (Buddy Peacock) Date: Mon, 11 May 2020 22:33:14 -0400 Subject: Help Problem with python : python-3.8.3rc1-amd64 Message-ID: I am trying to install python on my surface with windows 10, version 1903, build 18362.778. The installer seems to think everything worked. But there is no Python folder anywhere on the system. I looked in the root directory as well as "Program Files" and "Program Files (x86)" and not in any users folders either. I have uninstalled and re-installed twice. Once after shutting down and restarting. Your help would be appreciated as I am taking an on-line programming class. Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC (920) 740-3411 linkedin.com/in/buddypeacock From torriem at gmail.com Mon May 11 23:25:13 2020 From: torriem at gmail.com (Michael Torrie) Date: Mon, 11 May 2020 21:25:13 -0600 Subject: Help Problem with python : python-3.8.3rc1-amd64 In-Reply-To: References: Message-ID: <4d14d024-ce8b-3594-263e-9e1ee1fbcd7e@gmail.com> On 5/11/20 8:33 PM, Buddy Peacock wrote: > I am trying to install python on my surface with windows 10, version 1903, > build 18362.778. The installer seems to think everything worked. But there > is no Python folder anywhere on the system. I looked in the root directory > as well as "Program Files" and "Program Files (x86)" and not in any users > folders either. I have uninstalled and re-installed twice. Once after > shutting down and restarting. Your help would be appreciated as I am > taking an on-line programming class. Unless you specifically selected "install for all users" it's probably going to be installed to your home directory under the hidden folder "AppData," specially "AppData\Local\Programs\Python." Be sure to tell the installer to put python in your path--that way no matter where it is, from the command prompt you can just run "python" and it will fire up the interpreter. Additionally, "Idle" (the integrated development environment) will probably be in your start menu. From torriem at gmail.com Mon May 11 23:34:41 2020 From: torriem at gmail.com (Michael Torrie) Date: Mon, 11 May 2020 21:34:41 -0600 Subject: Help Problem with python : python-3.8.3rc1-amd64 In-Reply-To: <4d14d024-ce8b-3594-263e-9e1ee1fbcd7e@gmail.com> References: <4d14d024-ce8b-3594-263e-9e1ee1fbcd7e@gmail.com> Message-ID: <9255d427-9e35-9abf-6663-43cb4dcef0ae@gmail.com> On 5/11/20 9:25 PM, Michael Torrie wrote: > On 5/11/20 8:33 PM, Buddy Peacock wrote: >> I am trying to install python on my surface with windows 10, version 1903, >> build 18362.778. The installer seems to think everything worked. But there >> is no Python folder anywhere on the system. I looked in the root directory >> as well as "Program Files" and "Program Files (x86)" and not in any users >> folders either. I have uninstalled and re-installed twice. Once after >> shutting down and restarting. Your help would be appreciated as I am >> taking an on-line programming class. > > Unless you specifically selected "install for all users" it's probably > going to be installed to your home directory under the hidden folder > "AppData," specially "AppData\Local\Programs\Python." Be sure to tell > the installer to put python in your path--that way no matter where it > is, from the command prompt you can just run "python" and it will fire > up the interpreter. Additionally, "Idle" (the integrated development > environment) will probably be in your start menu. Hmm, actually I think the AppData install path is if you install from the Microsoft Store, which you could try. From tjreedy at udel.edu Mon May 11 23:09:21 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 May 2020 23:09:21 -0400 Subject: proposal for slice hashing In-Reply-To: <82778d45-0cf6-4959-a0b0-f6fe3ebb2f30@googlegroups.com> References: <82778d45-0cf6-4959-a0b0-f6fe3ebb2f30@googlegroups.com> Message-ID: On 5/11/2020 3:58 PM, Will Bradshaw wrote: > I recently ran into a situation where I needed to hash a slice and found this to be unsupported. Slice objects, as opposed to slices of objects, have no explicit use in Python itself. They were added for use by "NumericalPython and other 3rd party extensions". https://docs.python.org/3/library/functions.html#slice They have the functionality needed for that use. If this does not meet your needs, don't use them. Slice objects are similar to named tuples in having a fixed number of immutable fields accessed by name. https://docs.python.org/3/glossary.html#term-named-tuple They were added before collections.namedtuple but if added today *for general use*, probably would be nametuples, with hashing and anything that comes from subclassing tuple. So either use the namedtuple factory or roll your own to make something that works for you. -- Terry Jan Reedy From tjreedy at udel.edu Tue May 12 05:42:46 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 May 2020 05:42:46 -0400 Subject: Help Problem with python : python-3.8.3rc1-amd64 In-Reply-To: <9255d427-9e35-9abf-6663-43cb4dcef0ae@gmail.com> References: <4d14d024-ce8b-3594-263e-9e1ee1fbcd7e@gmail.com> <9255d427-9e35-9abf-6663-43cb4dcef0ae@gmail.com> Message-ID: On 5/11/2020 11:34 PM, Michael Torrie wrote: > On 5/11/20 9:25 PM, Michael Torrie wrote: >> On 5/11/20 8:33 PM, Buddy Peacock wrote: >>> I am trying to install python on my surface with windows 10, version 1903, >>> build 18362.778. The installer seems to think everything worked. But there >>> is no Python folder anywhere on the system. I looked in the root directory >>> as well as "Program Files" and "Program Files (x86)" and not in any users >>> folders either. I have uninstalled and re-installed twice. Once after >>> shutting down and restarting. Your help would be appreciated as I am >>> taking an on-line programming class. >> >> Unless you specifically selected "install for all users" it's probably >> going to be installed to your home directory under the hidden folder >> "AppData," specially "AppData\Local\Programs\Python." Be sure to tell In particular, C:\Users\Yourname\AppDate.... >> the installer to put python in your path--that way no matter where it >> is, from the command prompt you can just run "python" and it will fire >> up the interpreter. Additionally, "Idle" (the integrated development >> environment) will probably be in your start menu. There should also be a plain python icon in the Python3.8 group. In any case, >>> import sys; sys.executable will give the path to the current python.exe. > Hmm, actually I think the AppData install path is if you install from > the Microsoft Store, which you could try. That is the default for the python.org installer. -- Terry Jan Reedy From jorge.conforte at inpe.br Tue May 12 12:05:05 2020 From: jorge.conforte at inpe.br (J Conrado) Date: Tue, 12 May 2020 13:05:05 -0300 Subject: Cartopy error Message-ID: <52d76fdc-9f89-6dd4-537f-dbe89ada4332@inpe.br> Hi, Please, what can I do to solve this error: import cartopy, cartopy.crs as ccrs? # Plot maps ? File "/home/conrado/anaconda3/envs/myenv/lib/python3.8/site-packages/cartopy/__init__.py", line 96, in ??? import cartopy.crs ? File "/home/conrado/anaconda3/envs/myenv/lib/python3.8/site-packages/cartopy/crs.py", line 36, in ??? from cartopy._crs import (CRS, Geodetic, Globe, PROJ4_VERSION, ImportError: libproj.so.19: cannot open shared object file: No such file or directory Thank you, Conrado From joel.goldstick at gmail.com Tue May 12 12:27:37 2020 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 12 May 2020 12:27:37 -0400 Subject: Cartopy error In-Reply-To: <52d76fdc-9f89-6dd4-537f-dbe89ada4332@inpe.br> References: <52d76fdc-9f89-6dd4-537f-dbe89ada4332@inpe.br> Message-ID: On Tue, May 12, 2020 at 12:13 PM J Conrado wrote: > > > > Hi, > > > Please, what can I do to solve this error: > > > import cartopy, cartopy.crs as ccrs # Plot maps # check your spelling. Did you mean cartopy.ccrs? > File > "/home/conrado/anaconda3/envs/myenv/lib/python3.8/site-packages/cartopy/__init__.py", > line 96, in > import cartopy.crs > File > "/home/conrado/anaconda3/envs/myenv/lib/python3.8/site-packages/cartopy/crs.py", > line 36, in > from cartopy._crs import (CRS, Geodetic, Globe, PROJ4_VERSION, > ImportError: libproj.so.19: cannot open shared object file: No such file > or directory > > > Thank you, > > > Conrado > > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From anjulakshmi894 at gmail.com Wed May 13 11:31:31 2020 From: anjulakshmi894 at gmail.com (anjulakshmi894 at gmail.com) Date: Wed, 13 May 2020 08:31:31 -0700 (PDT) Subject: php to python code converter In-Reply-To: References: Message-ID: <3e5cd703-1ee3-4e83-82da-80259b1fc56b@googlegroups.com> On Friday, 8 May 2009 16:08:25 UTC+5:30, bvidinli wrote: > if anybody needs: > http://code.google.com/p/phppython/ $username = "username"; $password = "password"; $hostname = "localhost"; $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("dropdownvalues", $dbhandle) or die("Could not select examples"); $choice = mysql_real_escape_string($_GET['choice']); $query = "SELECT * FROM dd_vals WHERE category='$choice'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo ""; } From mats at wichmann.us Wed May 13 15:38:53 2020 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 13 May 2020 13:38:53 -0600 Subject: Help Problem with python : python-3.8.3rc1-amd64 In-Reply-To: <4d14d024-ce8b-3594-263e-9e1ee1fbcd7e@gmail.com> References: <4d14d024-ce8b-3594-263e-9e1ee1fbcd7e@gmail.com> Message-ID: <46994d5f-0066-5aa4-c3d9-b28ac07483af@wichmann.us> On 5/11/20 9:25 PM, Michael Torrie wrote: > On 5/11/20 8:33 PM, Buddy Peacock wrote: >> I am trying to install python on my surface with windows 10, version 1903, >> build 18362.778. The installer seems to think everything worked. But there >> is no Python folder anywhere on the system. I looked in the root directory >> as well as "Program Files" and "Program Files (x86)" and not in any users >> folders either. I have uninstalled and re-installed twice. Once after >> shutting down and restarting. Your help would be appreciated as I am >> taking an on-line programming class. > > Unless you specifically selected "install for all users" it's probably > going to be installed to your home directory under the hidden folder > "AppData," specially "AppData\Local\Programs\Python." Be sure to tell > the installer to put python in your path--that way no matter where it > is, from the command prompt you can just run "python" and it will fire > up the interpreter. That's what the Python Launcher is for... instead of always having to get the path to python itself into the Windows path - and change it each time the version bumps, since the path includes the version number - "py" goes in your path in a place it's always found, so "py" from a command prompt works, with options to select a specific Python if you have several installed. Bonus: "py" works from PowerShell as well ("python" tends not to). From matheusdalmago10 at gmail.com Wed May 13 15:51:51 2020 From: matheusdalmago10 at gmail.com (matheusdalmago10 at gmail.com) Date: Wed, 13 May 2020 12:51:51 -0700 (PDT) Subject: Python 3.6 Embedded In-Reply-To: <5be30e1e-873c-4ae9-ab33-33884b8316af@googlegroups.com> References: <5be30e1e-873c-4ae9-ab33-33884b8316af@googlegroups.com> Message-ID: On Monday, December 26, 2016 at 5:27:33 AM UTC-2, jumppan... at gmail.com wrote: > I'm using the python3.6 DLL to embed Python 3 inside a Windows application. > > Here is some background into how Python is being used. > > 1. Firstly the same basic code worked fine with the earlier Python 2.7 version. > > 2. The code is structured as follows: > > Windows Executable > + > | > + Scripting DLL > + > | > + Pthyhon 3.6 DLL > > In other words the executable talks to the Scripting DLL and the scripting DLL then talks to the Python DLL. > > 3. To run a script the following flow control is used: > > a. Application loads the Scripting DLL > i. The Scripting DLL calls Py_Initialize found in the Python DLL > > b. Application run the script file using the Scripting DLL > i. The Scripting DLL calls PyRun_SimpleFileEx in the Python DLL to run the script > > c. Unload the scripting DLL > i. The Scripting DLL calls Py_FinalizeEx in the Python DLL clean up > > Symptoms of the Problem > ----------------------- > The problem can be replicated by a script that contains nothing but a single import statement. > > Using this test script the script can be run and re-run any number of times: > > import sys > > Using this test script the script will run the first time but fail every subsequent time: > > import socket > > The difference in the two import statements is the former is a built-in module while the later is using a dynamically loaded module. > > The Cause of the Problem > ------------------------ > I tracked down the cause of the problem to the fact the python36.dll unloads just fine for the first case but fails to unloaded for the second case. > > So when the application loads and unloads the Scripting DLL the python36.dll remains loaded. > > Then when the python36.dll is used the second time it now contains pointers to stale data and crashes on the second run. > > The Py_FinalizeEx document found here suggests it should stop all interpreters: https://docs.python.org/dev/c-api/init.html > > Anyone have an idea know what might be going wrong? > > What code is holding on to the Python DLL? Three and a half year later and I have the exact same problem. Curios world. From encore1 at cox.net Wed May 13 23:13:57 2020 From: encore1 at cox.net (Dick Holmes) Date: Wed, 13 May 2020 20:13:57 -0700 Subject: Subprocess Popen confusion Message-ID: https://occovid19.ochealthinfo.com/coronavirus-in-oc I'm trying to communicate using a continuing dialog between two processes on the same system. I've looked at various mechanisms and the class that seems to fit my needs is Popen in the subprocess module, but I can't seem to get more than a single round-trip message through Popen. I first call Popen then poll using the identifier returned from the call and the poll seems to work. I then call the communicate function passing None as the value to send to the companion process stdin. I get the expected result, but I also get "Exception condition detected on fd 0 \\n" and "error detected on stdin\\n". Subsequent attempts to read/write/communicate with the subprocess fail because the file (stdxx PIPE) is closed. I can't tell from the documentation if the communicate function is a one-time operation. I have tried using read but the read call doesn't return (I'm using winpdb-reborn to monitor the operations). I'm using Python 3.7, Windows 10, winpdb-reborn 2.0.0, rpdb2 1.5.0. If it makes any difference, I'm trying to communicate with GDB using the MI interpreter. Thoughts and advice appreciated! Dick From palashbauri1 at gmail.com Wed May 13 12:53:00 2020 From: palashbauri1 at gmail.com (Palash Bauri) Date: Wed, 13 May 2020 22:23:00 +0530 Subject: php to python code converter In-Reply-To: <3e5cd703-1ee3-4e83-82da-80259b1fc56b@googlegroups.com> References: <3e5cd703-1ee3-4e83-82da-80259b1fc56b@googlegroups.com> Message-ID: That gives a 404 ????, you sure , you pasted the right link ? ~Palash Bauri On Wed, 13 May 2020, 9:07 pm , wrote: > On Friday, 8 May 2009 16:08:25 UTC+5:30, bvidinli wrote: > > if anybody needs: > > http://code.google.com/p/phppython/ > > $username = "username"; > $password = "password"; > $hostname = "localhost"; > > $dbhandle = mysql_connect($hostname, $username, $password) or > die("Unable to connect to MySQL"); > $selected = mysql_select_db("dropdownvalues", $dbhandle) or > die("Could not select examples"); > $choice = mysql_real_escape_string($_GET['choice']); > > $query = "SELECT * FROM dd_vals WHERE category='$choice'"; > > $result = mysql_query($query); > > while ($row = mysql_fetch_array($result)) { > echo ""; > } > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Thu May 14 03:45:05 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 14 May 2020 09:45:05 +0200 Subject: Subprocess Popen confusion References: Message-ID: Dick Holmes wrote: > https://occovid19.ochealthinfo.com/coronavirus-in-oc > I'm trying to > communicate using a continuing dialog between two > processes on the same system. I think pexpect https://pexpect.readthedocs.io/en/stable/index.html does this naturally, but I don't know if Windows support is sufficient for your needs. > I've looked at various mechanisms and the > class that seems to fit my needs is Popen in the subprocess module, but > I can't seem to get more than a single round-trip message through Popen. > I first call Popen then poll using the identifier returned from the call > and the poll seems to work. I then call the communicate function passing > None as the value to send to the companion process stdin. I get the > expected result, but I also get "Exception condition detected on fd 0 > \\n" and "error detected on stdin\\n". Subsequent attempts to > read/write/communicate with the subprocess fail because the file (stdxx > PIPE) is closed. > > I can't tell from the documentation if the communicate function is a > one-time operation. Yes, communicate() is one-off, """Interact with process: Send data to stdin and close it. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. ... """ seems pretty clear. What would you improve? > I have tried using read but the read call doesn't > return (I'm using winpdb-reborn to monitor the operations). Try readline(). Deadlocks may happen ;) > I'm using Python 3.7, Windows 10, winpdb-reborn 2.0.0, rpdb2 1.5.0. If > it makes any difference, I'm trying to communicate with GDB using the MI > interpreter. > > Thoughts and advice appreciated! > > Dick From lukasz at langa.pl Thu May 14 04:47:10 2020 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Thu, 14 May 2020 10:47:10 +0200 Subject: [RELEASE] Python 3.8.3 is now available Message-ID: <509B65E2-6516-4042-924D-E5D06D4C744D@langa.pl> 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.8.3, the third maintenance release of Python 3.8. You can find it here: https://www.python.org/downloads/release/python-383/ It contains two months worth of bug fixes. Detailed information about all changes made in 3.8.3 can be found in its change log . Note that compared to 3.8.2, version 3.8.3 also contains the changes introduced in 3.8.3rc1. 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. Maintenance releases for the 3.8 series will continue at regular bi-monthly intervals, with 3.8.4 planned for mid-July 2020. One more thing Unless blocked on any critical issue, Monday May 18th will be the release date of Python 3.9.0 beta 1. It?s a special release for us because this is when we lock the feature set for Python 3.9. If you can help testing the current available alpha release, that would be very helpful: https://www.python.org/downloads/release/python-390a6/ We hope you enjoy the new Python release! 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. https://www.python.org/psf/ Your friendly release team, Ned Deily @nad Steve Dower @steve.dower ?ukasz Langa @ambv From tjreedy at udel.edu Thu May 14 03:53:55 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 May 2020 03:53:55 -0400 Subject: Subprocess Popen confusion In-Reply-To: References: Message-ID: On 5/13/2020 11:13 PM, Dick Holmes wrote: > https://occovid19.ochealthinfo.com/coronavirus-in-oc I'm trying to > communicate using a continuing dialog between two > processes on the same system Try multiprocessing and pipes. -- Terry Jan Reedy From aduojosam at gmail.com Thu May 14 07:15:11 2020 From: aduojosam at gmail.com (aduojo samson) Date: Thu, 14 May 2020 12:15:11 +0100 Subject: PROBLEM WITH PYTHON IDLE Message-ID: Hello, my name is Samson Haruna and I am from Nigeria.I have a problem with my python 3.8, any time I click on it to write my python code I get this error message "IDLE subprocess didn't make connection". I have uninstalled and reinstalled several times, I have even deleted and downloaded a new one, it works for some time then it stops giving me the above mentioned error message. what can I do. Samson.A.Haruna 08106587039 From python at mrabarnett.plus.com Thu May 14 08:00:13 2020 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 14 May 2020 13:00:13 +0100 Subject: php to python code converter In-Reply-To: References: <3e5cd703-1ee3-4e83-82da-80259b1fc56b@googlegroups.com> Message-ID: <92289c7f-8f45-2818-4559-b9e91356d458@mrabarnett.plus.com> On 2020-05-13 17:53, Palash Bauri wrote: > That gives a 404 ????, you sure , you pasted the right link ? > > ~Palash Bauri > > On Wed, 13 May 2020, 9:07 pm , wrote: > >> On Friday, 8 May 2009 16:08:25 UTC+5:30, bvidinli wrote: >> > if anybody needs: >> > http://code.google.com/p/phppython/ >> >> $username = "username"; >> $password = "password"; >> $hostname = "localhost"; >> >> $dbhandle = mysql_connect($hostname, $username, $password) or >> die("Unable to connect to MySQL"); >> $selected = mysql_select_db("dropdownvalues", $dbhandle) or >> die("Could not select examples"); >> $choice = mysql_real_escape_string($_GET['choice']); >> >> $query = "SELECT * FROM dd_vals WHERE category='$choice'"; >> >> $result = mysql_query($query); >> >> while ($row = mysql_fetch_array($result)) { >> echo ""; >> } Look at the date of the original post. It says "8 May 2009". That's over 11 years ago! Since then, Google Code has ceased to exist. From souvik.viksou at gmail.com Thu May 14 08:16:04 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Thu, 14 May 2020 17:46:04 +0530 Subject: PROBLEM WITH PYTHON IDLE In-Reply-To: References: Message-ID: What is your os? Where have you downloaded it from? What type of package did you download? Souvik flutter dev On Thu, May 14, 2020, 5:36 PM aduojo samson wrote: > Hello, my name is Samson Haruna and I am from Nigeria.I have a problem with > my python 3.8, any time I click on it to write my python code I get this > error message "IDLE subprocess didn't make connection". I have uninstalled > and reinstalled several times, I have even deleted and downloaded a new > one, it works for some time then it stops giving me the above mentioned > error message. what can I do. > > Samson.A.Haruna > 08106587039 > -- > https://mail.python.org/mailman/listinfo/python-list > From mats at python.org Thu May 14 08:16:52 2020 From: mats at python.org (Mats Wichmann) Date: Thu, 14 May 2020 06:16:52 -0600 Subject: PROBLEM WITH PYTHON IDLE In-Reply-To: References: Message-ID: <9d45a8dd-e470-f490-5bbb-380bc168ab4b@python.org> On 5/14/20 5:15 AM, aduojo samson wrote: > Hello, my name is Samson Haruna and I am from Nigeria.I have a problem with > my python 3.8, any time I click on it to write my python code I get this > error message "IDLE subprocess didn't make connection". I have uninstalled > and reinstalled several times, I have even deleted and downloaded a new > one, it works for some time then it stops giving me the above mentioned > error message. what can I do. Did you read the instructions in the link presented when it gives you that error? https://docs.python.org/3/library/idle.html#startup-failure Does this help? From jon+usenet at unequivocal.eu Thu May 14 08:58:39 2020 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 14 May 2020 12:58:39 -0000 (UTC) Subject: php to python code converter References: <3e5cd703-1ee3-4e83-82da-80259b1fc56b@googlegroups.com> <92289c7f-8f45-2818-4559-b9e91356d458@mrabarnett.plus.com> Message-ID: On 2020-05-14, MRAB wrote: > Look at the date of the original post. It says "8 May 2009". That's over > 11 years ago! > > Since then, Google Code has ceased to exist. Disgraceful, all URLs should continue to work for at least as long as this one has: http://info.cern.ch/hypertext/WWW/TheProject.html ;-) From encore1 at cox.net Thu May 14 14:06:38 2020 From: encore1 at cox.net (Dick Holmes) Date: Thu, 14 May 2020 11:06:38 -0700 Subject: Subprocess Popen confusion References: Message-ID: In article , __peter__ at web.de says... > > Dick Holmes wrote: > > > https://occovid19.ochealthinfo.com/coronavirus-in-oc > > > I'm trying to > > communicate using a continuing dialog between two > > processes on the same system. > > I think pexpect > > https://pexpect.readthedocs.io/en/stable/index.html > > does this naturally, but I don't know if Windows support is sufficient for > your needs. > > > I've looked at various mechanisms and the > > class that seems to fit my needs is Popen in the subprocess module, but > > I can't seem to get more than a single round-trip message through Popen. > > I first call Popen then poll using the identifier returned from the call > > and the poll seems to work. I then call the communicate function passing > > None as the value to send to the companion process stdin. I get the > > expected result, but I also get "Exception condition detected on fd 0 > > \\n" and "error detected on stdin\\n". Subsequent attempts to > > read/write/communicate with the subprocess fail because the file (stdxx > > PIPE) is closed. > > > > I can't tell from the documentation if the communicate function is a > > one-time operation. > > Yes, communicate() is one-off, > > > """Interact with process: Send data to stdin and close it. > Read data from stdout and stderr, until end-of-file is > reached. Wait for process to terminate. > ... > """ > > seems pretty clear. What would you improve? Peter - thanks for the clarification. I'm using the 3.6.5 CHM documentation and it doesn't mention the phrase "and close it". > > > I have tried using read but the read call doesn't > > return (I'm using winpdb-reborn to monitor the operations). > > Try readline(). Deadlocks may happen ;) > > > I'm using Python 3.7, Windows 10, winpdb-reborn 2.0.0, rpdb2 1.5.0. If > > it makes any difference, I'm trying to communicate with GDB using the MI > > interpreter. > > From cbdevidal.jk1 at gmail.com Thu May 14 08:28:23 2020 From: cbdevidal.jk1 at gmail.com (Christopher de Vidal) Date: Thu, 14 May 2020 08:28:23 -0400 Subject: Decorators with arguments? Message-ID: Help please? Creating an MQTT-to-Firestore bridge and I know a decorator would help but I'm stumped how to create one. I've used decorators before but not with arguments. The Firestore collection.on_snapshot() method invokes a callback and sends it three parameters (collection_snapshot, changes, and read_time). I need the callback to also know the name of the collection so that I can publish to the equivalent MQTT topic name. I had thought to add a fourth parameter and I believe a decorator is the right approach but am stumped how to add that fourth parameter. How would I do this with the code below? #!/usr/bin/env python3 from google.cloud import firestore import firebase_admin from firebase_admin import credentials import json import mqtt firebase_admin.initialize_app(credentials.Certificate("certs/firebase.json")) db = firestore.Client() mqtt.connect() def load_json(contents): try: return json.loads(contents) except (json.decoder.JSONDecodeError, TypeError): return contents def on_snapshot(col_name, col_snapshot, changes, read_time): data = dict() for doc in col_snapshot: serial = doc.id contents = load_json(doc.to_dict()['value']) data[serial] = contents for change in changes: serial = change.document.id mqtt_topic = col_name + '/' + serial contents = data[serial] if change.type.name in ['ADDED', 'MODIFIED']: mqtt.publish(mqtt_topic, contents) elif change.type.name == 'REMOVED': mqtt.publish(mqtt_topic, None) # Start repeated code section # TODO Better to use decorators but I was stumped on how to pass arguments def door_status_on_snapshot(col_snapshot, changes, read_time): on_snapshot('door_status', col_snapshot, changes, read_time) door_status_col_ref = db.collection('door_status') door_status_col_watch = door_status_col_ref.on_snapshot(door_status_on_snapshot) # Repetition... def cpu_temp_on_snapshot(col_snapshot, changes, read_time): on_snapshot('cpu_temp', col_snapshot, changes, read_time) cpu_temp_col_ref = db.collection('cpu_temp') cpu_temp_col_watch = cpu_temp_col_ref.on_snapshot(cpu_temp_on_snapshot) # End repeated code section # Start repeated code section door_status_col_watch.unsubscribe() cpu_temp_col_watch.unsubscribe() # Repetition... # End repeated code section Christopher de Vidal Would you consider yourself a good person? Have you ever taken the 'Good Person' test? It's a fascinating five minute quiz. Google it. From godisgovernment at gmail.com Thu May 14 15:01:55 2020 From: godisgovernment at gmail.com (Shawn Hoffman) Date: Thu, 14 May 2020 12:01:55 -0700 Subject: Fwd: Removing python installation In-Reply-To: References: Message-ID: I've somehow wound up in a situation where I have both 3.7.5 and 3.7.6 installed, and the py.exe launcher can find both of them, and defaults to the older one: >py -0p Installed Pythons found by py Launcher for Windows -3.7-64 "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe" * -3.7-64 C:\Users\shawn\AppData\Local\Programs\Python\Python37\python.exe As you can see, the 3.7.5 install is from Visual Studio. I want to remove this python installation, however while uninstalling it via the VS Installer GUI appears to work, none of the files are removed. Only the json file VS Installer uses to track the package is removed. In the VS Installer logs, I see: Skipping uninstall of 'CPython3.Exe.x64,version=3.7.5,chip=x64' because it is permanent. which seems suspicious. Additionally, in the aforementioned json file I can see the installer being used is "python-3.7.5-amd64.exe" from https://go.microsoft.com/fwlink/?linkid=2109129 , with args: "/quiet /log \"[LogFile]\" InstallAllUsers=1 CompileAll=1 Include_symbols=1 TargetDir=\"[SharedInstallDir]\\Python37_64\"" So, I've downloaded this installer and tried to run it with the /uninstall option. Again, the uninstall appears to complete OK, but the files are not removed. The uninstall log is here: https://gist.github.com/shuffle2/3c3aa736f5cf9579e6e4a4a33b1ad81d Is there some "clean" way to remove this VS-installed 3.7.5 (and not break the 3.7.6 install)? Thanks, -Shawn From stephane at sdf.org Thu May 14 18:36:34 2020 From: stephane at sdf.org (Stephane Tougard) Date: Thu, 14 May 2020 22:36:34 +0000 (UTC) Subject: Multithread and locking issue Message-ID: Hello, A multithreaded software written in Python is connected with a Postgres database. To avoid concurrent access issue with the database, it starts a thread who receive all SQL request via queue.put and queue.get (it makes only insert, so no issue with the return of the SQL request). As long as it runs with 10 threads, no issues. At 100 threads, the software is blocked by what I think is a locking issue. I guess Python multithreading and queue are working good enough that it can handle 100 threads with no issue (give me wrong here), so I guess the problem is in my code. The function (thread) who handles SQL requests. def execute_sql(q): print("Start SQL Thread") while True: try: data = q.get(True,5) except: print("No data") continue print("RECEIVED SQL ORDER") print(data) print("END") if data == "EXIT": return try: request = data['request'] arg = data['arg'] ref.execute(request,arg) except: print("Can not execute SQL request") print(data) The code to send the SQL request. sql = dict() sql['request'] = "update b2_user set credit = credit -%s where id = %s" sql['arg'] = (i,username,) try: q.put(sql,True,5) except: print("Can not insert data") The launch of the SQL thread (nothing fancy here). q = qu.Queue() t = th.Thread(target = execute_sql, args = (q,)) t.start() Any idea ? From cs at cskk.id.au Thu May 14 19:02:39 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 15 May 2020 09:02:39 +1000 Subject: Decorators with arguments? In-Reply-To: References: Message-ID: <20200514230239.GA6327@cskk.homeip.net> On 14May2020 08:28, Christopher de Vidal wrote: >Help please? Creating an MQTT-to-Firestore bridge and I know a decorator >would help but I'm stumped how to create one. I've used decorators before >but not with arguments. > >The Firestore collection.on_snapshot() method invokes a callback and sends >it three parameters (collection_snapshot, changes, and read_time). I need >the callback to also know the name of the collection so that I can publish >to the equivalent MQTT topic name. I had thought to add a fourth parameter >and I believe a decorator is the right approach but am stumped how to add >that fourth parameter. How would I do this with the code below? To start with, I'm not convinced a decorator is a good approach here. I'd use a small class. Maybe you could provide an example of how you think the code would look _with_ a decorator (ignoring the implementation of the decorator itself) so that we can see what you'd like to use? The thing about a decorator is that in normal use you use it to define a new named function; each function would tend to be different in what it does, otherwise you'd only have one function. It sounds like you want a named function per collection name, but with the _same_ inner code (on_snapshot). But decorators, being applied to multiple functions, are usually for situations where the inner code varies and the decorator is just making a shim to call it in a particular way. You've got _one_ function and just want to attach it to multiple collection names, kind of the inverse. To clear my mind, I'll lay out the class approach (untested). Then if I think you can do this with a decorator I'll try to sketch one. class MQTTAdaptor: def __init__(self, fbdb, collection_name): self.fbdb = fbdb self.collection_name = collection_name self.fbref = None self.subscribe() def subscribe(self): assert self.fbref is None self.fbref = db.collection(collection_name) self.fbref.on_snapshot(self.on_snapshot) def unsubscribe(self): self.fbref.unsubscribe() self.fbref = None def on_snapshot(self, col_snapshot, changes, read_time): col_name = self.collection_name data = {} for doc in col_snapshot: serial = doc.id contents = load_json(doc.to_dict()['value']) data[serial] = contents for change in changes: serial = change.document.id mqtt_topic = col_name + '/' + serial contents = data[serial] if change.type.name in ['ADDED', 'MODIFIED']: mqtt.publish(mqtt_topic, contents) elif change.type.name == 'REMOVED': mqtt.publish(mqtt_topic, None) else: warning("unhandled change type: %r" % change.type.name) adaptors = [] for collection_name in 'cpu_temp', 'door_status': adaptors.append(MQTTAdaptor, db, collection_name) .... run for a while ... for adaptor in adaptors: adaptor.unsubscribe() I've broken out the subscribe/unsubscribe as standalone methods just in case you want to resubscribe an adaptor later (eg turn them on and off). So here we've got a little class that keeps the state (the subscription ref and the collection name) and has its own FB style on_snapshot which passes stuff on to MQTT. If you want to do this with a decorator you've got a small problem: it is easy to make a shim like your on_snapshot callback, but if you want to do a nice unsubscribe at the end thend you need to keep the ref around somewhere. The class above provides a place to keep that. With a decorator you need it to know where to store that ref. You can use a global registry (ugh) or you could make one (just a dict) and pass it to the decorator as well. We'll use a global and just use it in the decorator directly, since we'll use "db" the same way. # the registry adaptors = {} @adapt('cpu_temp') def cpu_temp_on_snapshot(collection_name, col_snapshot, changes, read_time): ... your existing code here ... and then to subscribe: cpu_temp_col_ref = db.collection('cpu_temp') cpu_temp_col_watch = cpu_temp_col_ref.on_snapshot(cpu_temp_on_snapshot) but then for the door_status you want the same function repeated: @adapt('door_status') def door_on_snapshot(collection_name, col_snapshot, changes, read_time): ... your existing code here ... and the same longhand subscription. You can see this isn't any better - you're writing out on_snapshot longhand every time. Now, a decorator just accepts a function as its argument and returns a new function to be used in its place. So we could define on_snapshot once and decorate it: def named_snapshot(collection_name, col_snapshot, changes, read_time): ... the egneral function code here again ... cpu_temp_on_snapshot = adapt('cpu_temp')(named_snapshot) door_on_snapshot = adapt('door_status')(named_snapshot) but (a) it doesn't look so much like a decorator any more and (b) you still have to to the explicit subscription. However we could have the decorator do the subscription _and_ record the fbref for the unsubscription later. So not quite so bad. So, how do you do the decorator-with-an-argument? A decorator takes _one_ argument, a function, and returns a new function. The syntax: @foo def bah(...): ... is just a pretty shorthand for: # original "bah" def bah(...): .... # switch out "bah" for a new function using the original "bah" bah = foo(bah) However, you're allowed to write: @foo2(some-arguments...) def bah(...): ... What's going on there? The expression: foo2(some-arguments...) _itself_ returns a decorator. Which then decorates "bah". So, making an @adapt decorator for your purpose... [... hack hack ...] Well I can't write one of any use. I just wrote an @adapt decorator, but it never calls the function it is passed when I do that (because the mqtt "on_snapshot()" function already exists and it calls that instead). So there's no use for a decorator :-( Cheers, Cameron Simpson From cs at cskk.id.au Thu May 14 19:18:27 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 15 May 2020 09:18:27 +1000 Subject: Multithread and locking issue In-Reply-To: References: Message-ID: <20200514231827.GA88703@cskk.homeip.net> On 14May2020 22:36, Stephane Tougard wrote: >A multithreaded software written in Python is connected with a Postgres >database. To avoid concurrent access issue with the database, it starts >a thread who receive all SQL request via queue.put and queue.get (it >makes only insert, so no issue with the return of the SQL request). Just a remark that PostgreSQL ets callers work in parallel, just make multiple connections. But if you're coming from just one connection, yes serialising the SQL queries is good. >As long as it runs with 10 threads, no issues. At 100 threads, the >software is blocked by what I think is a locking issue. Or a timeout or busy loop. More print statements will help you. >I guess Python multithreading and queue are working good enough that it >can handle 100 threads with no issue (give me wrong here), Yep, that is just fine. >so I guess >the problem is in my code. > >The function (thread) who handles SQL requests. > >def execute_sql(q): > print("Start SQL Thread") > while True: > try: > data = q.get(True,5) > except: 2 problems here: 1: a "bare except" catches _any_ exception instead of just the one you want (Empty). Don't do that - catch _only_ what you expect to handle. 2: since you're catching anything you never know why an exception occurred - at least report it: except Exception as e: print("No data: %s" % e) continue > print("No data") > continue The first thing I would do is get rid of the timeout (5) parameter. And since block=True is the default, also that parameter: data = q.get() This never times out, so there's no need to test for a timeout. I would also put a print() _immediately_ before _and_ after the q.get() so that you know it was called and that it completed, and what it got. To indicate no more SQL, send a sentinel such as None, and test for that: data = q.get() if data is None: break > print("RECEIVED SQL ORDER") > print(data) > print("END") > if data == "EXIT": > return Ah, here's your sentinel. I prefer None or some other special value rather than a magic string ("EXIT"). Partly because some other queue you use might be processing arbitrary strings, so a string won't do. > try: > request = data['request'] > arg = data['arg'] > ref.execute(request,arg) > except: Another bare except. Catch specific exceptions and report the exception! > print("Can not execute SQL request") > print(data) > >The code to send the SQL request. > > sql = dict() > sql['request'] = "update b2_user set credit = credit -%s where id = %s" > sql['arg'] = (i,username,) > try: > q.put(sql,True,5) > except: Again the bare except. But just drop the timeout and go: q.put(sql) and forget the try/except. > print("Can not insert data") > >The launch of the SQL thread (nothing fancy here). > >q = qu.Queue() >t = th.Thread(target = execute_sql, args = (q,)) >t.start() That looks superficially good. Take out the timeouts, put in more print()s, and see what happens. You also need to send the end-of-SQL sentinel: q.put(None) or: q.put("EXIT") depending on what you decide to use. My problem with the timeouts is that they make your code far less predictable. If you get rid of them then your code must complete or deadlock, there's no fuzzy timeouts-may-occur middle ground. Timeouts are also difficult to choose correctly (if "correct" is even a term which is meaningful), and it is often then better to not try to choose them at all. Cheers, Cameron Simpson From python at mrabarnett.plus.com Thu May 14 19:32:17 2020 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 15 May 2020 00:32:17 +0100 Subject: Multithread and locking issue In-Reply-To: References: Message-ID: On 2020-05-14 23:36, Stephane Tougard wrote: > > > Hello, > > A multithreaded software written in Python is connected with a Postgres > database. To avoid concurrent access issue with the database, it starts > a thread who receive all SQL request via queue.put and queue.get (it > makes only insert, so no issue with the return of the SQL request). > > As long as it runs with 10 threads, no issues. At 100 threads, the > software is blocked by what I think is a locking issue. > > I guess Python multithreading and queue are working good enough that it > can handle 100 threads with no issue (give me wrong here), so I guess > the problem is in my code. > > The function (thread) who handles SQL requests. > > def execute_sql(q): > print("Start SQL Thread") > while True: > try: > data = q.get(True,5) > except: > print("No data") > continue > > print("RECEIVED SQL ORDER") > print(data) > print("END") > if data == "EXIT": > return > try: > request = data['request'] > arg = data['arg'] > ref.execute(request,arg) > except: > print("Can not execute SQL request") > print(data) > > > The code to send the SQL request. > > sql = dict() > sql['request'] = "update b2_user set credit = credit -%s where id = %s" > sql['arg'] = (i,username,) > try: > q.put(sql,True,5) > except: > print("Can not insert data") > > The launch of the SQL thread (nothing fancy here). > > q = qu.Queue() > t = th.Thread(target = execute_sql, args = (q,)) > t.start() > > > Any idea ? > Are there 100 threads running execute_sql? Do you put 100 "EXIT" messages into the queue, one for each thread? The "bare excepts" are a bad idea because they catch _all_ exceptions, even the ones that might occur due to bugs, such as NameError (misspelled variable or function). From stephane at sdf.org Thu May 14 20:40:06 2020 From: stephane at sdf.org (Stephane Tougard) Date: Fri, 15 May 2020 00:40:06 +0000 (UTC) Subject: Multithread and locking issue References: Message-ID: On 2020-05-14, MRAB wrote: > On 2020-05-14 23:36, Stephane Tougard wrote: >> > Are there 100 threads running execute_sql? Do you put 100 "EXIT" > messages into the queue, one for each thread? Nope, the EXIT comes from the main thread at the very end, once all other threads are dead already and the programm is good to die. It's just to ensure that the SQL thread dies as well. > The "bare excepts" are a bad idea because they catch _all_ exceptions, > even the ones that might occur due to bugs, such as NameError > (misspelled variable or function). At first, I did not use timeout nor try/except. The thing is that I never catch any except anyway. The program just stuck. If I CTRL-C on it, it shows a "acquire_lock()" status. So I added the timeout to ensure that it does not stuck on the get/put and the except to see if the problem comes from here. It does not come from here. I can remove all that, the programm is still going to stuck between 150/200 threads have been launched and have died. From rosuav at gmail.com Fri May 15 00:02:14 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 May 2020 14:02:14 +1000 Subject: Multithread and locking issue In-Reply-To: <20200514231827.GA88703@cskk.homeip.net> References: <20200514231827.GA88703@cskk.homeip.net> Message-ID: On Fri, May 15, 2020 at 9:20 AM Cameron Simpson wrote: > > On 14May2020 22:36, Stephane Tougard wrote: > >A multithreaded software written in Python is connected with a Postgres > >database. To avoid concurrent access issue with the database, it starts > >a thread who receive all SQL request via queue.put and queue.get (it > >makes only insert, so no issue with the return of the SQL request). > > Just a remark that PostgreSQL ets callers work in parallel, just make > multiple connections. Seconded. If you know how many threads you're going to have, just open that many connections. If not, there's a connection-pooling feature as part of psycopg2 (if I'm not mistaken). This would be far far easier to work with than a fragile queueing setup. Chrisa From stephane at sdf.org Fri May 15 01:57:03 2020 From: stephane at sdf.org (Stephane Tougard) Date: Fri, 15 May 2020 05:57:03 +0000 (UTC) Subject: Multithread and locking issue References: <20200514231827.GA88703@cskk.homeip.net> Message-ID: On 2020-05-15, Chris Angelico wrote: > Seconded. If you know how many threads you're going to have, just open > that many connections. If not, there's a connection-pooling feature as > part of psycopg2 (if I'm not mistaken). This would be far far easier > to work with than a fragile queueing setup. I've done like that (more or less), it works fine. I note that que queuing module or Python is "fragile". From antoon.pardon at vub.be Fri May 15 03:53:51 2020 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 15 May 2020 09:53:51 +0200 Subject: Multithread and locking issue In-Reply-To: References: Message-ID: Op 15/05/20 om 00:36 schreef Stephane Tougard: > > > Hello, > > A multithreaded software written in Python is connected with a Postgres > database. To avoid concurrent access issue with the database, it starts > a thread who receive all SQL request via queue.put and queue.get (it > makes only insert, so no issue with the return of the SQL request). > > As long as it runs with 10 threads, no issues. At 100 threads, the > software is blocked by what I think is a locking issue. > > I guess Python multithreading and queue are working good enough that it > can handle 100 threads with no issue (give me wrong here), so I guess > the problem is in my code. It is not the number of threads in itself that can cause problems. But my experience is that if you have an unbounded queue and your producers out pace the consumers, that can cause problems. And if you have 100 times more producers as you have consumers that can easily be the case. So my advice it to never use an unbounded queue. If the number of producers is small I go for a size of 10. If the number of producers gets larger, I go for a size between the number of producerers and the double of that. -- Antoon. From cs at cskk.id.au Fri May 15 04:24:12 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 15 May 2020 18:24:12 +1000 Subject: Multithread and locking issue In-Reply-To: References: Message-ID: <20200515082412.GA32471@cskk.homeip.net> On 15May2020 05:57, Stephane Tougard wrote: >On 2020-05-15, Chris Angelico wrote: >> Seconded. If you know how many threads you're going to have, just >> open >> that many connections. If not, there's a connection-pooling feature as >> part of psycopg2 (if I'm not mistaken). This would be far far easier >> to work with than a fragile queueing setup. > >I've done like that (more or less), it works fine. > >I note that que queuing module or Python is "fragile". It isn't fragile, it is very robust. Chris' statement (to my mind) means either that it is an additional layer of complexity to your programme (which you need to debug) or the pervasive fear of threaded programming, which has its pitfalls but is very rewarding and not hard to do safely and easily unless you do something agressive and complex. Cheers, Cameron Simpson From rosuav at gmail.com Fri May 15 04:31:11 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 May 2020 18:31:11 +1000 Subject: Multithread and locking issue In-Reply-To: <20200515082412.GA32471@cskk.homeip.net> References: <20200515082412.GA32471@cskk.homeip.net> Message-ID: On Fri, May 15, 2020 at 6:25 PM Cameron Simpson wrote: > > On 15May2020 05:57, Stephane Tougard wrote: > >On 2020-05-15, Chris Angelico wrote: > >> Seconded. If you know how many threads you're going to have, just > >> open > >> that many connections. If not, there's a connection-pooling feature as > >> part of psycopg2 (if I'm not mistaken). This would be far far easier > >> to work with than a fragile queueing setup. > > > >I've done like that (more or less), it works fine. > > > >I note that que queuing module or Python is "fragile". > > It isn't fragile, it is very robust. Chris' statement (to my mind) means > either that it is an additional layer of complexity to your programme > (which you need to debug) or the pervasive fear of threaded programming, > which has its pitfalls but is very rewarding and not hard to do safely > and easily unless you do something agressive and complex. > Correct. The complexity caused by not simply embracing threaded programming is what's fragile. ChrisA From __peter__ at web.de Fri May 15 09:51:16 2020 From: __peter__ at web.de (Peter Otten) Date: Fri, 15 May 2020 15:51:16 +0200 Subject: Decorators with arguments? References: Message-ID: Christopher de Vidal wrote: > Help please? Creating an MQTT-to-Firestore bridge and I know a decorator > would help but I'm stumped how to create one. I've used decorators before > but not with arguments. > > The Firestore collection.on_snapshot() method invokes a callback and sends > it three parameters (collection_snapshot, changes, and read_time). I need > the callback to also know the name of the collection so that I can publish > to the equivalent MQTT topic name. I had thought to add a fourth parameter > and I believe a decorator is the right approach but am stumped how to add > that fourth parameter. How would I do this with the code below? > > #!/usr/bin/env python3 > from google.cloud import firestore > import firebase_admin > from firebase_admin import credentials > import json > import mqtt > > firebase_admin.initialize_app(credentials.Certificate("certs/firebase.json")) > db = firestore.Client() > mqtt.connect() > > > def load_json(contents): > try: > return json.loads(contents) > except (json.decoder.JSONDecodeError, TypeError): > return contents > > > def on_snapshot(col_name, col_snapshot, changes, read_time): > data = dict() > for doc in col_snapshot: > serial = doc.id > contents = load_json(doc.to_dict()['value']) > data[serial] = contents > for change in changes: > serial = change.document.id > mqtt_topic = col_name + '/' + serial > contents = data[serial] > if change.type.name in ['ADDED', 'MODIFIED']: > mqtt.publish(mqtt_topic, contents) > elif change.type.name == 'REMOVED': > mqtt.publish(mqtt_topic, None) > > > # Start repeated code section > # TODO Better to use decorators but I was stumped on how to pass arguments > def door_status_on_snapshot(col_snapshot, changes, read_time): > on_snapshot('door_status', col_snapshot, changes, read_time) > > > door_status_col_ref = db.collection('door_status') > door_status_col_watch = > door_status_col_ref.on_snapshot(door_status_on_snapshot) > > # Repetition... > def cpu_temp_on_snapshot(col_snapshot, changes, read_time): > on_snapshot('cpu_temp', col_snapshot, changes, read_time) > > > cpu_temp_col_ref = db.collection('cpu_temp') > cpu_temp_col_watch = cpu_temp_col_ref.on_snapshot(cpu_temp_on_snapshot) > # End repeated code section > > # Start repeated code section > door_status_col_watch.unsubscribe() > cpu_temp_col_watch.unsubscribe() > # Repetition... > # End repeated code section > > Christopher de Vidal You might also consider a contextmanager: https://docs.python.org/3/library/contextlib.html # untested @contextmanager def subscribe(name, col_snapshot, changes, read_time): def status_on_snapshot(col_snapshot, changes, read_time): on_snapshot(name, col_snapshot, changes, read_time) status_col_ref = db.collection(name) status_col_watch = status_col_ref.on_snapshot(door_status_on_snapshot) try: yield status_col_ref finally: status_col_watch.unsubscribe() with subscribe("door_status", ...) as door_status_col_ref: with subscribe("cpu_temp", ...) as cpu_temp_col_ref: ... If there are many uniform ones the nested with statements can be generalized: NAMES = "door_status", "cpu_temp", ... with ExitStack() as stack: col_refs = [ stack.enter_context(subscribe(name)) for name in NAMES ] And if you like Camoron's suggestion or the subscribe() generator above just gets too unwieldy: a custom class can act as a contextmanager, too. https://docs.python.org/3/reference/compound_stmts.html#with From kacheva97 at gmail.com Fri May 15 00:18:23 2020 From: kacheva97 at gmail.com (Jhoana Kacheva Melissa Joseph) Date: Fri, 15 May 2020 00:18:23 -0400 Subject: Help with installation please Message-ID: Hello, I downloaded python 3.8 in my windows, I selected the box for the path but when I try to run it in powershell it brought me to app store to get it again. Please let me know Thanks Melissa From bryan5810 at gmail.com Fri May 15 13:53:02 2020 From: bryan5810 at gmail.com (=?utf-8?Q?Bryan_Cabrera_Ram=C3=ADrez?=) Date: Fri, 15 May 2020 19:53:02 +0200 Subject: RV: CodecRegistryError problem for an IDE. Message-ID: <5ebed700.1c69fb81.e291a.2356@mx.google.com> Hi, ? I'm trying to insall an INET package for an IDE called OMNeT++ and when I try to build the INET the following happens in the command window: ? ? Fatal Python error: Py_Initialize: unable to load the file system codec ? File "C:\Python27\Lib\encodings\__init__.py", line 123 ??? raise CodecRegistryError,\ ??????????????????????????? ^ SyntaxError: invalid syntax ? ? I did python repair from the setup installer but it still doesn't work. ? Do you know what should I do in order to solve the problem ? ? ? Best regards, ? Thank you, ? Bryan Cabrera Ramirez ? ? From PythonList at DancesWithMice.info Fri May 15 15:14:11 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 16 May 2020 07:14:11 +1200 Subject: php to python code converter In-Reply-To: References: <3e5cd703-1ee3-4e83-82da-80259b1fc56b@googlegroups.com> <92289c7f-8f45-2818-4559-b9e91356d458@mrabarnett.plus.com> Message-ID: <90c361fd-39f4-2c69-e0c0-3829b623b61e@DancesWithMice.info> On 15/05/20 12:58 AM, Jon Ribbens via Python-list wrote: > On 2020-05-14, MRAB wrote: >> Look at the date of the original post. It says "8 May 2009". That's over >> 11 years ago! >> >> Since then, Google Code has ceased to exist. > > Disgraceful, all URLs should continue to work for at least as long as > this one has: http://info.cern.ch/hypertext/WWW/TheProject.html ;-) Is there then a lesson to be learned here? Should you place trust in a company that (repeatedly) behaves in such a fashion, yet feels entitled to lecture others about 'what is good for the web'? -- Regards =dn From python at mrabarnett.plus.com Fri May 15 15:23:38 2020 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 15 May 2020 20:23:38 +0100 Subject: RV: CodecRegistryError problem for an IDE. In-Reply-To: <5ebed700.1c69fb81.e291a.2356@mx.google.com> References: <5ebed700.1c69fb81.e291a.2356@mx.google.com> Message-ID: <93ec33a4-1310-00a6-0fa7-7ead42e74a5d@mrabarnett.plus.com> On 2020-05-15 18:53, Bryan Cabrera Ram?rez wrote: > Hi, > > > > I'm trying to insall an INET package for an IDE called OMNeT++ and when > > I try to build the INET the following happens in the command window: > > > > > > Fatal Python error: Py_Initialize: unable to load the file system codec > > ? File "C:\Python27\Lib\encodings\__init__.py", line 123 > > ??? raise CodecRegistryError,\ > > ??????????????????????????? ^ > > SyntaxError: invalid syntax > > > > > > I did python repair from the setup installer but it still doesn't work. > > > > Do you know what should I do in order to solve the problem ? > > That syntax is valid for Python 2.7. (Python 2 has reached end-of-life.) I'm wondering if it's due to a confusion between Python 2 and Python 3, with Python 3 trying to run code intended for Python 2. From python at mrabarnett.plus.com Fri May 15 15:28:53 2020 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 15 May 2020 20:28:53 +0100 Subject: Help with installation please In-Reply-To: References: Message-ID: <724436fb-a37d-016c-bac3-18e81e6b7fd0@mrabarnett.plus.com> On 2020-05-15 05:18, Jhoana Kacheva Melissa Joseph wrote: > Hello, > > I downloaded python 3.8 in my windows, I selected the box for the path but > when I try to run it in powershell it brought me to app store to get it > again. > How are you running Python? What are you putting on the command line? When I try: python3 it takes me to the store. The recommended way these days is to use the Python launcher. py That starts the default one for me. From souvik.viksou at gmail.com Fri May 15 19:59:33 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sat, 16 May 2020 05:29:33 +0530 Subject: Help with installation please In-Reply-To: References: Message-ID: Windows has a default python 3. that is not installed but registered (which is as wierd as Microsoft). That is why you are redirected everytime to the store. You might want to check app execution aliases in the search bar an scroll down to find the two pythons and then uncheck one of them to avoid future confusions. On Sat, 16 May, 2020, 12:01 am Jhoana Kacheva Melissa Joseph, < kacheva97 at gmail.com> wrote: > Hello, > > I downloaded python 3.8 in my windows, I selected the box for the path but > when I try to run it in powershell it brought me to app store to get it > again. > > Please let me know > > Thanks > Melissa > -- > https://mail.python.org/mailman/listinfo/python-list > From souvik.viksou at gmail.com Fri May 15 21:10:24 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sat, 16 May 2020 06:40:24 +0530 Subject: Help with installation please In-Reply-To: References: Message-ID: App execution aliases is not on store. Search it in the start menu. On Sat, 16 May, 2020, 6:27 am Jhoana Kacheva Melissa Joseph, < kacheva97 at gmail.com> wrote: > Thanks for the tip! But there is nothing to unchecked. > > I typed python on powershell, once redirected to the app store I type app > execution aliases in search bar, hit enter and I see this picture attached. > Am I missing something please ? > > > > On Fri, May 15, 2020, 7:59 PM Souvik Dutta > wrote: > >> Windows has a default python 3. that is not installed but >> registered (which is as wierd as Microsoft). That is why you are redirected >> everytime to the store. You might want to check app execution aliases in >> the search bar an scroll down to find the two pythons and then uncheck one >> of them to avoid future confusions. >> >> On Sat, 16 May, 2020, 12:01 am Jhoana Kacheva Melissa Joseph, < >> kacheva97 at gmail.com> wrote: >> >>> Hello, >>> >>> I downloaded python 3.8 in my windows, I selected the box for the path >>> but >>> when I try to run it in powershell it brought me to app store to get it >>> again. >>> >>> Please let me know >>> >>> Thanks >>> Melissa >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> From souvik.viksou at gmail.com Fri May 15 22:59:02 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sat, 16 May 2020 08:29:02 +0530 Subject: Help with installation please In-Reply-To: References: Message-ID: Have you added python into path? On Sat, 16 May, 2020, 8:15 am Jhoana Kacheva Melissa Joseph, < kacheva97 at gmail.com> wrote: > Thanks for the tip! Now that I turned it off. This is what it says. > > Please see attached > > > > On Fri, May 15, 2020, 9:10 PM Souvik Dutta > wrote: > >> App execution aliases is not on store. Search it in the start menu. >> >> On Sat, 16 May, 2020, 6:27 am Jhoana Kacheva Melissa Joseph, < >> kacheva97 at gmail.com> wrote: >> >>> Thanks for the tip! But there is nothing to unchecked. >>> >>> I typed python on powershell, once redirected to the app store I type >>> app execution aliases in search bar, hit enter and I see this picture >>> attached. Am I missing something please ? >>> >>> >>> >>> On Fri, May 15, 2020, 7:59 PM Souvik Dutta >>> wrote: >>> >>>> Windows has a default python 3. that is not installed but >>>> registered (which is as wierd as Microsoft). That is why you are redirected >>>> everytime to the store. You might want to check app execution aliases in >>>> the search bar an scroll down to find the two pythons and then uncheck one >>>> of them to avoid future confusions. >>>> >>>> On Sat, 16 May, 2020, 12:01 am Jhoana Kacheva Melissa Joseph, < >>>> kacheva97 at gmail.com> wrote: >>>> >>>>> Hello, >>>>> >>>>> I downloaded python 3.8 in my windows, I selected the box for the path >>>>> but >>>>> when I try to run it in powershell it brought me to app store to get it >>>>> again. >>>>> >>>>> Please let me know >>>>> >>>>> Thanks >>>>> Melissa >>>>> -- >>>>> https://mail.python.org/mailman/listinfo/python-list >>>>> >>>> From henrik.milan at hotmail.com Fri May 15 21:44:09 2020 From: henrik.milan at hotmail.com (Henrik Milan) Date: Sat, 16 May 2020 04:44:09 +0300 Subject: Fwd: Uninstall was succesful - but actually nothing happened In-Reply-To: References: Message-ID: Hey, I noticed that the uninstaller says that the installation completed, but actually nothing really happened and all of my Python 3.6.8 installation was still completely installed on my machine and all files were located inside Python/Python36 folder still. See the picture attached. My computer is Windows 10, version 1909, build 10.0.18363. From souvik.viksou at gmail.com Fri May 15 23:01:46 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sat, 16 May 2020 08:31:46 +0530 Subject: Help with installation please In-Reply-To: References: Message-ID: Have you switched off both the pythons? If so then switch on one off them and try. If it still doesn't work then switch on the previous one and off the other and try again. On Sat, 16 May, 2020, 8:29 am Souvik Dutta, wrote: > Have you added python into path? > > On Sat, 16 May, 2020, 8:15 am Jhoana Kacheva Melissa Joseph, < > kacheva97 at gmail.com> wrote: > >> Thanks for the tip! Now that I turned it off. This is what it says. >> >> Please see attached >> >> >> >> On Fri, May 15, 2020, 9:10 PM Souvik Dutta >> wrote: >> >>> App execution aliases is not on store. Search it in the start menu. >>> >>> On Sat, 16 May, 2020, 6:27 am Jhoana Kacheva Melissa Joseph, < >>> kacheva97 at gmail.com> wrote: >>> >>>> Thanks for the tip! But there is nothing to unchecked. >>>> >>>> I typed python on powershell, once redirected to the app store I type >>>> app execution aliases in search bar, hit enter and I see this picture >>>> attached. Am I missing something please ? >>>> >>>> >>>> >>>> On Fri, May 15, 2020, 7:59 PM Souvik Dutta >>>> wrote: >>>> >>>>> Windows has a default python 3. that is not installed but >>>>> registered (which is as wierd as Microsoft). That is why you are redirected >>>>> everytime to the store. You might want to check app execution aliases in >>>>> the search bar an scroll down to find the two pythons and then uncheck one >>>>> of them to avoid future confusions. >>>>> >>>>> On Sat, 16 May, 2020, 12:01 am Jhoana Kacheva Melissa Joseph, < >>>>> kacheva97 at gmail.com> wrote: >>>>> >>>>>> Hello, >>>>>> >>>>>> I downloaded python 3.8 in my windows, I selected the box for the >>>>>> path but >>>>>> when I try to run it in powershell it brought me to app store to get >>>>>> it >>>>>> again. >>>>>> >>>>>> Please let me know >>>>>> >>>>>> Thanks >>>>>> Melissa >>>>>> -- >>>>>> https://mail.python.org/mailman/listinfo/python-list >>>>>> >>>>> From kacheva97 at gmail.com Fri May 15 23:12:45 2020 From: kacheva97 at gmail.com (Jhoana Kacheva Melissa Joseph) Date: Fri, 15 May 2020 23:12:45 -0400 Subject: Help with installation please In-Reply-To: References: Message-ID: When I turn off the other one, it brought me to the store. Yes, I did the path On Fri, May 15, 2020, 11:01 PM Souvik Dutta wrote: > Have you switched off both the pythons? If so then switch on one off them > and try. If it still doesn't work then switch on the previous one and off > the other and try again. > > On Sat, 16 May, 2020, 8:29 am Souvik Dutta, > wrote: > >> Have you added python into path? >> >> On Sat, 16 May, 2020, 8:15 am Jhoana Kacheva Melissa Joseph, < >> kacheva97 at gmail.com> wrote: >> >>> Thanks for the tip! Now that I turned it off. This is what it says. >>> >>> Please see attached >>> >>> >>> >>> On Fri, May 15, 2020, 9:10 PM Souvik Dutta >>> wrote: >>> >>>> App execution aliases is not on store. Search it in the start menu. >>>> >>>> On Sat, 16 May, 2020, 6:27 am Jhoana Kacheva Melissa Joseph, < >>>> kacheva97 at gmail.com> wrote: >>>> >>>>> Thanks for the tip! But there is nothing to unchecked. >>>>> >>>>> I typed python on powershell, once redirected to the app store I type >>>>> app execution aliases in search bar, hit enter and I see this picture >>>>> attached. Am I missing something please ? >>>>> >>>>> >>>>> >>>>> On Fri, May 15, 2020, 7:59 PM Souvik Dutta >>>>> wrote: >>>>> >>>>>> Windows has a default python 3. that is not installed but >>>>>> registered (which is as wierd as Microsoft). That is why you are redirected >>>>>> everytime to the store. You might want to check app execution aliases in >>>>>> the search bar an scroll down to find the two pythons and then uncheck one >>>>>> of them to avoid future confusions. >>>>>> >>>>>> On Sat, 16 May, 2020, 12:01 am Jhoana Kacheva Melissa Joseph, < >>>>>> kacheva97 at gmail.com> wrote: >>>>>> >>>>>>> Hello, >>>>>>> >>>>>>> I downloaded python 3.8 in my windows, I selected the box for the >>>>>>> path but >>>>>>> when I try to run it in powershell it brought me to app store to get >>>>>>> it >>>>>>> again. >>>>>>> >>>>>>> Please let me know >>>>>>> >>>>>>> Thanks >>>>>>> Melissa >>>>>>> -- >>>>>>> https://mail.python.org/mailman/listinfo/python-list >>>>>>> >>>>>> From souvik.viksou at gmail.com Fri May 15 23:20:37 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sat, 16 May 2020 08:50:37 +0530 Subject: Help with installation please In-Reply-To: References: Message-ID: Then you will have to use python3 forever in your life (atleast as long as you don't change your os... ??). On Sat, 16 May, 2020, 8:42 am Jhoana Kacheva Melissa Joseph, < kacheva97 at gmail.com> wrote: > When I turn off the other one, it brought me to the store. > > Yes, I did the path > > On Fri, May 15, 2020, 11:01 PM Souvik Dutta > wrote: > >> Have you switched off both the pythons? If so then switch on one off them >> and try. If it still doesn't work then switch on the previous one and off >> the other and try again. >> >> On Sat, 16 May, 2020, 8:29 am Souvik Dutta, >> wrote: >> >>> Have you added python into path? >>> >>> On Sat, 16 May, 2020, 8:15 am Jhoana Kacheva Melissa Joseph, < >>> kacheva97 at gmail.com> wrote: >>> >>>> Thanks for the tip! Now that I turned it off. This is what it says. >>>> >>>> Please see attached >>>> >>>> >>>> >>>> On Fri, May 15, 2020, 9:10 PM Souvik Dutta >>>> wrote: >>>> >>>>> App execution aliases is not on store. Search it in the start menu. >>>>> >>>>> On Sat, 16 May, 2020, 6:27 am Jhoana Kacheva Melissa Joseph, < >>>>> kacheva97 at gmail.com> wrote: >>>>> >>>>>> Thanks for the tip! But there is nothing to unchecked. >>>>>> >>>>>> I typed python on powershell, once redirected to the app store I type >>>>>> app execution aliases in search bar, hit enter and I see this picture >>>>>> attached. Am I missing something please ? >>>>>> >>>>>> >>>>>> >>>>>> On Fri, May 15, 2020, 7:59 PM Souvik Dutta >>>>>> wrote: >>>>>> >>>>>>> Windows has a default python 3. that is not installed but >>>>>>> registered (which is as wierd as Microsoft). That is why you are redirected >>>>>>> everytime to the store. You might want to check app execution aliases in >>>>>>> the search bar an scroll down to find the two pythons and then uncheck one >>>>>>> of them to avoid future confusions. >>>>>>> >>>>>>> On Sat, 16 May, 2020, 12:01 am Jhoana Kacheva Melissa Joseph, < >>>>>>> kacheva97 at gmail.com> wrote: >>>>>>> >>>>>>>> Hello, >>>>>>>> >>>>>>>> I downloaded python 3.8 in my windows, I selected the box for the >>>>>>>> path but >>>>>>>> when I try to run it in powershell it brought me to app store to >>>>>>>> get it >>>>>>>> again. >>>>>>>> >>>>>>>> Please let me know >>>>>>>> >>>>>>>> Thanks >>>>>>>> Melissa >>>>>>>> -- >>>>>>>> https://mail.python.org/mailman/listinfo/python-list >>>>>>>> >>>>>>> From kacheva97 at gmail.com Fri May 15 23:23:55 2020 From: kacheva97 at gmail.com (Jhoana Kacheva Melissa Joseph) Date: Fri, 15 May 2020 23:23:55 -0400 Subject: Help with installation please In-Reply-To: References: Message-ID: ?? but I still get the error in powershell. What should I do Souvik? On Fri, May 15, 2020, 11:20 PM Souvik Dutta wrote: > Then you will have to use python3 forever in your life (atleast as long as > you don't change your os... ??). > > On Sat, 16 May, 2020, 8:42 am Jhoana Kacheva Melissa Joseph, < > kacheva97 at gmail.com> wrote: > >> When I turn off the other one, it brought me to the store. >> >> Yes, I did the path >> >> On Fri, May 15, 2020, 11:01 PM Souvik Dutta >> wrote: >> >>> Have you switched off both the pythons? If so then switch on one off >>> them and try. If it still doesn't work then switch on the previous one and >>> off the other and try again. >>> >>> On Sat, 16 May, 2020, 8:29 am Souvik Dutta, >>> wrote: >>> >>>> Have you added python into path? >>>> >>>> On Sat, 16 May, 2020, 8:15 am Jhoana Kacheva Melissa Joseph, < >>>> kacheva97 at gmail.com> wrote: >>>> >>>>> Thanks for the tip! Now that I turned it off. This is what it says. >>>>> >>>>> Please see attached >>>>> >>>>> >>>>> >>>>> On Fri, May 15, 2020, 9:10 PM Souvik Dutta >>>>> wrote: >>>>> >>>>>> App execution aliases is not on store. Search it in the start menu. >>>>>> >>>>>> On Sat, 16 May, 2020, 6:27 am Jhoana Kacheva Melissa Joseph, < >>>>>> kacheva97 at gmail.com> wrote: >>>>>> >>>>>>> Thanks for the tip! But there is nothing to unchecked. >>>>>>> >>>>>>> I typed python on powershell, once redirected to the app store I >>>>>>> type app execution aliases in search bar, hit enter and I see this picture >>>>>>> attached. Am I missing something please ? >>>>>>> >>>>>>> >>>>>>> >>>>>>> On Fri, May 15, 2020, 7:59 PM Souvik Dutta >>>>>>> wrote: >>>>>>> >>>>>>>> Windows has a default python 3. that is not installed >>>>>>>> but registered (which is as wierd as Microsoft). That is why you are >>>>>>>> redirected everytime to the store. You might want to check app execution >>>>>>>> aliases in the search bar an scroll down to find the two pythons and then >>>>>>>> uncheck one of them to avoid future confusions. >>>>>>>> >>>>>>>> On Sat, 16 May, 2020, 12:01 am Jhoana Kacheva Melissa Joseph, < >>>>>>>> kacheva97 at gmail.com> wrote: >>>>>>>> >>>>>>>>> Hello, >>>>>>>>> >>>>>>>>> I downloaded python 3.8 in my windows, I selected the box for the >>>>>>>>> path but >>>>>>>>> when I try to run it in powershell it brought me to app store to >>>>>>>>> get it >>>>>>>>> again. >>>>>>>>> >>>>>>>>> Please let me know >>>>>>>>> >>>>>>>>> Thanks >>>>>>>>> Melissa >>>>>>>>> -- >>>>>>>>> https://mail.python.org/mailman/listinfo/python-list >>>>>>>>> >>>>>>>> From souvik.viksou at gmail.com Fri May 15 23:46:23 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sat, 16 May 2020 09:16:23 +0530 Subject: Help with installation please In-Reply-To: References: Message-ID: Try it. It's all about experiments... Souvik flutter dev On Sat, May 16, 2020, 8:56 AM Jhoana Kacheva Melissa Joseph < kacheva97 at gmail.com> wrote: > Soovik, should I disable the path length limit? > > I am just saying. Attached the picture. > > On Fri, May 15, 2020, 11:23 PM Jhoana Kacheva Melissa Joseph < > kacheva97 at gmail.com> wrote: > >> ?? but I still get the error in powershell. What should I do Souvik? >> >> On Fri, May 15, 2020, 11:20 PM Souvik Dutta >> wrote: >> >>> Then you will have to use python3 forever in your life (atleast as long >>> as you don't change your os... ??). >>> >>> On Sat, 16 May, 2020, 8:42 am Jhoana Kacheva Melissa Joseph, < >>> kacheva97 at gmail.com> wrote: >>> >>>> When I turn off the other one, it brought me to the store. >>>> >>>> Yes, I did the path >>>> >>>> On Fri, May 15, 2020, 11:01 PM Souvik Dutta >>>> wrote: >>>> >>>>> Have you switched off both the pythons? If so then switch on one off >>>>> them and try. If it still doesn't work then switch on the previous one and >>>>> off the other and try again. >>>>> >>>>> On Sat, 16 May, 2020, 8:29 am Souvik Dutta, >>>>> wrote: >>>>> >>>>>> Have you added python into path? >>>>>> >>>>>> On Sat, 16 May, 2020, 8:15 am Jhoana Kacheva Melissa Joseph, < >>>>>> kacheva97 at gmail.com> wrote: >>>>>> >>>>>>> Thanks for the tip! Now that I turned it off. This is what it says. >>>>>>> >>>>>>> Please see attached >>>>>>> >>>>>>> >>>>>>> >>>>>>> On Fri, May 15, 2020, 9:10 PM Souvik Dutta >>>>>>> wrote: >>>>>>> >>>>>>>> App execution aliases is not on store. Search it in the start menu. >>>>>>>> >>>>>>>> On Sat, 16 May, 2020, 6:27 am Jhoana Kacheva Melissa Joseph, < >>>>>>>> kacheva97 at gmail.com> wrote: >>>>>>>> >>>>>>>>> Thanks for the tip! But there is nothing to unchecked. >>>>>>>>> >>>>>>>>> I typed python on powershell, once redirected to the app store I >>>>>>>>> type app execution aliases in search bar, hit enter and I see this picture >>>>>>>>> attached. Am I missing something please ? >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> On Fri, May 15, 2020, 7:59 PM Souvik Dutta < >>>>>>>>> souvik.viksou at gmail.com> wrote: >>>>>>>>> >>>>>>>>>> Windows has a default python 3. that is not installed >>>>>>>>>> but registered (which is as wierd as Microsoft). That is why you are >>>>>>>>>> redirected everytime to the store. You might want to check app execution >>>>>>>>>> aliases in the search bar an scroll down to find the two pythons and then >>>>>>>>>> uncheck one of them to avoid future confusions. >>>>>>>>>> >>>>>>>>>> On Sat, 16 May, 2020, 12:01 am Jhoana Kacheva Melissa Joseph, < >>>>>>>>>> kacheva97 at gmail.com> wrote: >>>>>>>>>> >>>>>>>>>>> Hello, >>>>>>>>>>> >>>>>>>>>>> I downloaded python 3.8 in my windows, I selected the box for >>>>>>>>>>> the path but >>>>>>>>>>> when I try to run it in powershell it brought me to app store to >>>>>>>>>>> get it >>>>>>>>>>> again. >>>>>>>>>>> >>>>>>>>>>> Please let me know >>>>>>>>>>> >>>>>>>>>>> Thanks >>>>>>>>>>> Melissa >>>>>>>>>>> -- >>>>>>>>>>> https://mail.python.org/mailman/listinfo/python-list >>>>>>>>>>> >>>>>>>>>> From souvik.viksou at gmail.com Fri May 15 23:47:39 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sat, 16 May 2020 09:17:39 +0530 Subject: Help with installation please In-Reply-To: References: Message-ID: I dont know if you should shift from powershell to cmd. Python kinda does not work in powershell. Souvik flutter dev On Sat, May 16, 2020, 8:54 AM Jhoana Kacheva Melissa Joseph < kacheva97 at gmail.com> wrote: > ?? but I still get the error in powershell. What should I do Souvik? > > On Fri, May 15, 2020, 11:20 PM Souvik Dutta > wrote: > >> Then you will have to use python3 forever in your life (atleast as long >> as you don't change your os... ??). >> >> On Sat, 16 May, 2020, 8:42 am Jhoana Kacheva Melissa Joseph, < >> kacheva97 at gmail.com> wrote: >> >>> When I turn off the other one, it brought me to the store. >>> >>> Yes, I did the path >>> >>> On Fri, May 15, 2020, 11:01 PM Souvik Dutta >>> wrote: >>> >>>> Have you switched off both the pythons? If so then switch on one off >>>> them and try. If it still doesn't work then switch on the previous one and >>>> off the other and try again. >>>> >>>> On Sat, 16 May, 2020, 8:29 am Souvik Dutta, >>>> wrote: >>>> >>>>> Have you added python into path? >>>>> >>>>> On Sat, 16 May, 2020, 8:15 am Jhoana Kacheva Melissa Joseph, < >>>>> kacheva97 at gmail.com> wrote: >>>>> >>>>>> Thanks for the tip! Now that I turned it off. This is what it says. >>>>>> >>>>>> Please see attached >>>>>> >>>>>> >>>>>> >>>>>> On Fri, May 15, 2020, 9:10 PM Souvik Dutta >>>>>> wrote: >>>>>> >>>>>>> App execution aliases is not on store. Search it in the start menu. >>>>>>> >>>>>>> On Sat, 16 May, 2020, 6:27 am Jhoana Kacheva Melissa Joseph, < >>>>>>> kacheva97 at gmail.com> wrote: >>>>>>> >>>>>>>> Thanks for the tip! But there is nothing to unchecked. >>>>>>>> >>>>>>>> I typed python on powershell, once redirected to the app store I >>>>>>>> type app execution aliases in search bar, hit enter and I see this picture >>>>>>>> attached. Am I missing something please ? >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On Fri, May 15, 2020, 7:59 PM Souvik Dutta >>>>>>>> wrote: >>>>>>>> >>>>>>>>> Windows has a default python 3. that is not installed >>>>>>>>> but registered (which is as wierd as Microsoft). That is why you are >>>>>>>>> redirected everytime to the store. You might want to check app execution >>>>>>>>> aliases in the search bar an scroll down to find the two pythons and then >>>>>>>>> uncheck one of them to avoid future confusions. >>>>>>>>> >>>>>>>>> On Sat, 16 May, 2020, 12:01 am Jhoana Kacheva Melissa Joseph, < >>>>>>>>> kacheva97 at gmail.com> wrote: >>>>>>>>> >>>>>>>>>> Hello, >>>>>>>>>> >>>>>>>>>> I downloaded python 3.8 in my windows, I selected the box for the >>>>>>>>>> path but >>>>>>>>>> when I try to run it in powershell it brought me to app store to >>>>>>>>>> get it >>>>>>>>>> again. >>>>>>>>>> >>>>>>>>>> Please let me know >>>>>>>>>> >>>>>>>>>> Thanks >>>>>>>>>> Melissa >>>>>>>>>> -- >>>>>>>>>> https://mail.python.org/mailman/listinfo/python-list >>>>>>>>>> >>>>>>>>> From kacheva97 at gmail.com Fri May 15 23:53:53 2020 From: kacheva97 at gmail.com (Jhoana Kacheva Melissa Joseph) Date: Fri, 15 May 2020 23:53:53 -0400 Subject: Help with installation please In-Reply-To: References: Message-ID: Ok, thanks Souvik. Appreciate your help. On Fri, May 15, 2020, 11:47 PM Souvik Dutta wrote: > I dont know if you should shift from powershell to cmd. Python kinda does > not work in powershell. > > Souvik flutter dev > > On Sat, May 16, 2020, 8:54 AM Jhoana Kacheva Melissa Joseph < > kacheva97 at gmail.com> wrote: > >> ?? but I still get the error in powershell. What should I do Souvik? >> >> On Fri, May 15, 2020, 11:20 PM Souvik Dutta >> wrote: >> >>> Then you will have to use python3 forever in your life (atleast as long >>> as you don't change your os... ??). >>> >>> On Sat, 16 May, 2020, 8:42 am Jhoana Kacheva Melissa Joseph, < >>> kacheva97 at gmail.com> wrote: >>> >>>> When I turn off the other one, it brought me to the store. >>>> >>>> Yes, I did the path >>>> >>>> On Fri, May 15, 2020, 11:01 PM Souvik Dutta >>>> wrote: >>>> >>>>> Have you switched off both the pythons? If so then switch on one off >>>>> them and try. If it still doesn't work then switch on the previous one and >>>>> off the other and try again. >>>>> >>>>> On Sat, 16 May, 2020, 8:29 am Souvik Dutta, >>>>> wrote: >>>>> >>>>>> Have you added python into path? >>>>>> >>>>>> On Sat, 16 May, 2020, 8:15 am Jhoana Kacheva Melissa Joseph, < >>>>>> kacheva97 at gmail.com> wrote: >>>>>> >>>>>>> Thanks for the tip! Now that I turned it off. This is what it says. >>>>>>> >>>>>>> Please see attached >>>>>>> >>>>>>> >>>>>>> >>>>>>> On Fri, May 15, 2020, 9:10 PM Souvik Dutta >>>>>>> wrote: >>>>>>> >>>>>>>> App execution aliases is not on store. Search it in the start menu. >>>>>>>> >>>>>>>> On Sat, 16 May, 2020, 6:27 am Jhoana Kacheva Melissa Joseph, < >>>>>>>> kacheva97 at gmail.com> wrote: >>>>>>>> >>>>>>>>> Thanks for the tip! But there is nothing to unchecked. >>>>>>>>> >>>>>>>>> I typed python on powershell, once redirected to the app store I >>>>>>>>> type app execution aliases in search bar, hit enter and I see this picture >>>>>>>>> attached. Am I missing something please ? >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> On Fri, May 15, 2020, 7:59 PM Souvik Dutta < >>>>>>>>> souvik.viksou at gmail.com> wrote: >>>>>>>>> >>>>>>>>>> Windows has a default python 3. that is not installed >>>>>>>>>> but registered (which is as wierd as Microsoft). That is why you are >>>>>>>>>> redirected everytime to the store. You might want to check app execution >>>>>>>>>> aliases in the search bar an scroll down to find the two pythons and then >>>>>>>>>> uncheck one of them to avoid future confusions. >>>>>>>>>> >>>>>>>>>> On Sat, 16 May, 2020, 12:01 am Jhoana Kacheva Melissa Joseph, < >>>>>>>>>> kacheva97 at gmail.com> wrote: >>>>>>>>>> >>>>>>>>>>> Hello, >>>>>>>>>>> >>>>>>>>>>> I downloaded python 3.8 in my windows, I selected the box for >>>>>>>>>>> the path but >>>>>>>>>>> when I try to run it in powershell it brought me to app store to >>>>>>>>>>> get it >>>>>>>>>>> again. >>>>>>>>>>> >>>>>>>>>>> Please let me know >>>>>>>>>>> >>>>>>>>>>> Thanks >>>>>>>>>>> Melissa >>>>>>>>>>> -- >>>>>>>>>>> https://mail.python.org/mailman/listinfo/python-list >>>>>>>>>>> >>>>>>>>>> From PythonList at DancesWithMice.info Sat May 16 00:33:48 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 16 May 2020 16:33:48 +1200 Subject: Help with installation please In-Reply-To: References: Message-ID: <96293d91-31c4-b95a-d2e9-38404bfd823c@DancesWithMice.info> On 15/05/20 4:18 PM, Jhoana Kacheva Melissa Joseph wrote: > Hello, > > I downloaded python 3.8 in my windows, I selected the box for the path but > when I try to run it in powershell it brought me to app store to get it > again. Please advise if the following reference is accurate, and works for you: https://docs.python.org/3/using/windows.html -- Regards =dn From nasserhamed758 at gmail.com Sat May 16 08:58:22 2020 From: nasserhamed758 at gmail.com (KINGHAMED io) Date: Sat, 16 May 2020 16:58:22 +0400 Subject: Having trouble importing the python turtle on idle In-Reply-To: References: Message-ID: On Sat, 16 May 2020 at 4:38 PM KINGHAMED io wrote: > Hello my name is Hamed > I have purchased python for kids. > I have installed idle and Python launcher 3.8.3 with my 11 inch MacBook > Air (Mac OS Sierra)version 10.12.6 > I have followed all the instructions all the way through for installation > I even downloaded activetcl and had no issues with instructions until > chapter 4 page 45 > which is importing the python turtle on to my screen. > However I have troubleshooted every possible way to get this right even > uninstalling and reinstalling Python several times. > Can you please advise me on how to import the python turtle. > From Bischoop at vimuster.net Sat May 16 11:27:41 2020 From: Bischoop at vimuster.net (Bischoop) Date: Sat, 16 May 2020 15:27:41 -0000 (UTC) Subject: Having trouble importing the python turtle on idle References: Message-ID: On 2020-05-16, KINGHAMED io wrote: > On Sat, 16 May 2020 at 4:38 PM KINGHAMED io > wrote: > >> Hello my name is Hamed >> I have purchased python for kids. >> I have installed idle and Python launcher 3.8.3 with my 11 inch MacBook >> Air (Mac OS Sierra)version 10.12.6 >> I have followed all the instructions all the way through for installation >> I even downloaded activetcl and had no issues with instructions until >> chapter 4 page 45 >> which is importing the python turtle on to my screen. >> However I have troubleshooted every possible way to get this right even >> uninstalling and reinstalling Python several times. >> Can you please advise me on how to import the python turtle. >> From souvik.viksou at gmail.com Sat May 16 11:43:00 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sat, 16 May 2020 21:13:00 +0530 Subject: Having trouble importing the python turtle on idle In-Reply-To: References: Message-ID: What is the error? Souvik flutter dev On Sat, May 16, 2020, 8:27 PM KINGHAMED io wrote: > On Sat, 16 May 2020 at 4:38 PM KINGHAMED io > wrote: > > > Hello my name is Hamed > > I have purchased python for kids. > > I have installed idle and Python launcher 3.8.3 with my 11 inch MacBook > > Air (Mac OS Sierra)version 10.12.6 > > I have followed all the instructions all the way through for installation > > I even downloaded activetcl and had no issues with instructions until > > chapter 4 page 45 > > which is importing the python turtle on to my screen. > > However I have troubleshooted every possible way to get this right even > > uninstalling and reinstalling Python several times. > > Can you please advise me on how to import the python turtle. > > > -- > https://mail.python.org/mailman/listinfo/python-list > From dieter at handshake.de Sat May 16 12:56:36 2020 From: dieter at handshake.de (Dieter Maurer) Date: Sat, 16 May 2020 18:56:36 +0200 Subject: RV: CodecRegistryError problem for an IDE. In-Reply-To: <5ebed700.1c69fb81.e291a.2356@mx.google.com> References: <5ebed700.1c69fb81.e291a.2356@mx.google.com> Message-ID: <24256.6980.592868.784653@ixdm.fritz.box> Bryan Cabrera Ram?rez wrote at 2020-5-15 19:53 +0200: > I'm trying to insall an INET package for an IDE called OMNeT++ and when > I try to build the INET the following happens in the command window: > > Fatal Python error: Py_Initialize: unable to load the file system codec > ? File "C:\Python27\Lib\encodings\__init__.py", line 123 > ??? raise CodecRegistryError,\ > ??????????????????????????? ^ > SyntaxError: invalid syntax > > I did python repair from the setup installer but it still doesn't work. > > Do you know what should I do in order to solve the problem ? Apparently, a Python version 3 interpreter is used but it finds a Python version 2 library. Those versions cannot mix. I cannot tell you how this mix came into being. I would try to uninstall Python and then reinstall freshly Python 3. From phd at phdru.name Sat May 16 14:05:57 2020 From: phd at phdru.name (Oleg Broytman) Date: Sat, 16 May 2020 20:05:57 +0200 Subject: CheetahTemplate 3.2.5 Message-ID: <20200516180557.ltxjej4wuxcbkgrj@phdru.name> Hello! I'm pleased to announce version 3.2.5, a minor feature release of branch 3.2 of CheetahTemplate3. What's new in CheetahTemplate3 ============================== The contributor for this release is Yegor Yefremov. Build: - Install ``Cheetah3`` + ``markdown`` (used in ``Cheetah.Filters``) using ``pip install cheetah3[filters]`` (or ``cheetah3[markdown]``). CI: - Run tests with Python 3.8 at Travis CI. What is CheetahTemplate3 ======================== Cheetah3 is a free and open source template engine. It's a fork of the original CheetahTemplate library. Python 2.7 or 3.4+ is required. Where is CheetahTemplate3 ========================= Site: https://cheetahtemplate.org/ Development: https://github.com/CheetahTemplate3 Download: https://pypi.org/project/Cheetah3/3.2.5 News and changes: https://cheetahtemplate.org/news.html StackOverflow: https://stackoverflow.com/questions/tagged/cheetah Example ======= Below is a simple example of some Cheetah code, as you can see it's practically Python. You can import, inherit and define methods just like in a regular Python module, since that's what your Cheetah templates are compiled to :) :: #from Cheetah.Template import Template #extends Template #set $people = [{'name' : 'Tom', 'mood' : 'Happy'}, {'name' : 'Dick', 'mood' : 'Sad'}, {'name' : 'Harry', 'mood' : 'Hairy'}] How are you feeling?
    #for $person in $people
  • $person['name'] is $person['mood']
  • #end for
Oleg. -- Oleg Broytman https://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From defenastrator at gmail.com Sat May 16 18:11:54 2020 From: defenastrator at gmail.com (Will Bradshaw) Date: Sat, 16 May 2020 15:11:54 -0700 (PDT) Subject: proposal for slice hashing In-Reply-To: <878shwvn36.fsf@nightsong.com> References: <82778d45-0cf6-4959-a0b0-f6fe3ebb2f30@googlegroups.com> <878shwvn36.fsf@nightsong.com> Message-ID: <111aa964-05dd-4d55-bb82-7cac6cba0f96@googlegroups.com> On Tuesday, May 12, 2020 at 5:51:37 PM UTC-4, Paul Rubin wrote: > Terry Reedy writes: > > Slice objects are similar to named tuples > > In that case making them hashable sounds like good sense. I mean I've already made and tested a patch it wasn't hard. I did same day as I made the post. I've also done a bit of work on the proposal to make the key function changeable in functools.lru_cache though that is a bit more complex and will take a bit of refactoring to do right. From PythonList at DancesWithMice.info Sat May 16 19:26:57 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 17 May 2020 11:26:57 +1200 Subject: OT: ALGOL 60 at 60 Message-ID: ALGOL 60 at 60: The greatest computer language you've never used and grandaddy of the programming family tree Back to the time when tape was king By Richard Speed 15 May 2020 at 09:47 https://www.theregister.co.uk/2020/05/15/algol_60_at_60/ NB 'El Reg' is known for its irreverent and cynical views of computing, poking-fun at every opportunity and using British-slang (which may challenge some - one way or another). I've often surmised reminders of ALGOL in Python. However, I had not previously remembered the ALGOL Bulletins and their similarity to Python's PEPs. ALGOL was almost 'the machine language' for the Burroughs B6700 series (and similar) but concurring with the article, we regarded it as somewhat academic and majored in FORTRAN, COBOL, or both. (as distinct from those who defined ComSc as compiler writing, for whom ALGOL was a brilliant tool!) The article also managed to elicit an "oh wow" from me, with its picture of a drum-plotter - few today will have seen a plotter that moves the paper as well as the pen (even if that's still the way most 'character-printers' work). Silver-surfers of the world unite! -- Regards, =dn From bill at celestial.net Sat May 16 20:48:19 2020 From: bill at celestial.net (Bill Campbell) Date: Sat, 16 May 2020 17:48:19 -0700 Subject: OT: ALGOL 60 at 60 In-Reply-To: References: Message-ID: <20200517004818.GA8244@hazlitt.celestial.com> On Sun, May 17, 2020, DL Neil via Python-list wrote: >ALGOL 60 at 60: The greatest computer language you've never used and >grandaddy of the programming family tree >Back to the time when tape was king >By Richard Speed 15 May 2020 at 09:47 >https://www.theregister.co.uk/2020/05/15/algol_60_at_60/ Boy does that bring back some memories :-). ALGOL was the third programming language I learned after FORTRAN and Assembly on the Bendix G-20 in early 1966. I first learned ALGOL on G.E. time sharing, where input was paper tape, although it didn't require loading the compilers from tape so I never hat that pleasure. I loved the block structure of ALGOL, and started indenting FORTRAN so that the program logic stood out even if FORTRAN didn't understand it. ... >ALGOL was almost 'the machine language' for the Burroughs B6700 series (and >similar) but concurring with the article, we regarded it as somewhat academic >and majored in FORTRAN, COBOL, or both. (as distinct from those who defined >ComSc as compiler writing, for whom ALGOL was a brilliant tool!) I really got into ALGOL on a time sharing system using the Burroughs B-5500 where ALGOL was the system's native language, there was no Assembly Language per-se. The OS MCP, (Master Control Progam) was written entirely in ALGOL. The FORTRAN compiler generated ALGOL source, and I learned a lot looking at the ALGOL output of the FORTRAN program. Many of the programming methods I use today have their roots in doing a lot of scientific programming in ALGOL on the B-5500, then in BPL (Burroughs Programming Language) on Burroughs Medium Systems, B-2500->B-4500. Bill -- INTERNET: bill at celestial.com Bill Campbell; Celestial Software LLC URL: http://www2.celestial.com/ 6641 E. Mercer Way Mobile: (206) 947-5591 PO Box 820 Fax: (206) 232-9186 Mercer Island, WA 98040-0820 In free governments the rulers are the servants, and the people their superiors & sovereigns." -- Benjamin Franklin From mats at wichmann.us Sun May 17 10:18:22 2020 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 17 May 2020 08:18:22 -0600 Subject: Help with installation please In-Reply-To: References: Message-ID: <50f5f169-868d-f773-cbe1-1d8b186afe0f@wichmann.us> On 5/15/20 9:47 PM, Souvik Dutta wrote: > I dont know if you should shift from powershell to cmd. Python kinda does > not work in powershell. Powershell has a funky way of looking up programs, with the result that you have to type the full name for many. python.exe - should work, probably. maybe. Using the Python Launcher helps: it works without extra games py If you install the Python from the Microsoft Store it will work more "predicatably" - python, and python3, will work from both a cmd and a powershell commandline. on the other hand, you will have no Python Launcher on such a setup. From tjreedy at udel.edu Sat May 16 19:43:21 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 16 May 2020 19:43:21 -0400 Subject: Having trouble importing the python turtle on idle In-Reply-To: References: Message-ID: On 5/16/2020 8:58 AM, KINGHAMED io wrote: >> Hello my name is Hamed >> I have purchased python for kids. >> I have installed idle and Python launcher 3.8.3 with my 11 inch MacBook >> Air (Mac OS Sierra)version 10.12.6 >> I have followed all the instructions all the way through for installation >> I even downloaded activetcl and had no issues with instructions until >> chapter 4 page 45 The activetcl instructions in the book are obsolete. The 3.8 python.org macOS installer comes with a recent version of tcl/tk (8.6.8) compiled to work with the 3.8 that it installs. Another tcl/tk binary may not work. First, when running IDLE, select on the menu IDLE and About IDLE. What is the tk version? It should be 8.6.8. Second, start Terminal and enter ... $ python3.8 -m turtle This should start a turtle demo that draws and erases two patterns. >> which is importing the python turtle on to my screen. >> However I have troubleshooted every possible way to get this right even What is wrong? >> uninstalling and reinstalling Python several times. >> Can you please advise me on how to import the python turtle. Any of the following. import turtle import turtle as t from turtle import * -- Terry Jan Reedy From gorumara at gmail.com Sun May 17 03:06:40 2020 From: gorumara at gmail.com (Tarun Pathak) Date: Sun, 17 May 2020 12:36:40 +0530 Subject: Fwd: Unable to Install Python (3.5.0) Properly In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Tarun Pathak Date: Sun, May 17, 2020, 12:07 PM Subject: Unable to Install Python (3.5.0) Properly To: Dear Sir/Madam, I am trying to install Python for a while. But failed to do so. Tried with different files as well. Requesting your suggestion to solve this issue. Attached the log file in this email. [image: image.png] Thanking you, Tarun From PythonList at DancesWithMice.info Sun May 17 15:16:47 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 18 May 2020 07:16:47 +1200 Subject: Fwd: Unable to Install Python (3.5.0) Properly In-Reply-To: References: Message-ID: <39ade157-3381-6e5b-a9c0-858f36460482@DancesWithMice.info> On 17/05/20 7:06 PM, Tarun Pathak wrote: > ---------- Forwarded message --------- > From: Tarun Pathak > Date: Sun, May 17, 2020, 12:07 PM > Subject: Unable to Install Python (3.5.0) Properly > To: > > > > Dear Sir/Madam, > > I am trying to install Python for a while. But failed to do so. Tried > with different files as well. > Requesting your suggestion to solve this issue. > > Attached the log file in this email. > > [image: image.png] > > Thanking you, > Tarun Unfortunately this list does not accept images as attachments. Also, did you notice that there is a Python-Tutor Discussion List. It's a good place for Python-learners to ask questions. You do not state the Operating System in-use. So, presuming MS-Windows, please advise if the following reference is accurate, and works for you: https://docs.python.org/3/using/windows.html -- Regards =dn From gorumara at gmail.com Sun May 17 15:27:57 2020 From: gorumara at gmail.com (Tarun Pathak) Date: Mon, 18 May 2020 00:57:57 +0530 Subject: Fwd: Unable to Install Python (3.5.0) Properly In-Reply-To: <39ade157-3381-6e5b-a9c0-858f36460482@DancesWithMice.info> References: <39ade157-3381-6e5b-a9c0-858f36460482@DancesWithMice.info> Message-ID: Oh, My apology ! I should have mentioned the system stats in mail. Windows 7 , 64 bit Intel Core 2 duo C drive free space : 23 GB Initially, during installation system is asking for service pack 1 I did that. Later, it's asking for core.msi, dev.msi etc. Because system is not able to fetch from the web. The log file contains all these errors. On Mon, May 18, 2020, 12:50 AM DL Neil via Python-list < python-list at python.org> wrote: > On 17/05/20 7:06 PM, Tarun Pathak wrote: > > ---------- Forwarded message --------- > > From: Tarun Pathak > > Date: Sun, May 17, 2020, 12:07 PM > > Subject: Unable to Install Python (3.5.0) Properly > > To: > > > > > > > > Dear Sir/Madam, > > > > I am trying to install Python for a while. But failed to do so. Tried > > with different files as well. > > Requesting your suggestion to solve this issue. > > > > Attached the log file in this email. > > > > [image: image.png] > > > > Thanking you, > > Tarun > > > Unfortunately this list does not accept images as attachments. Also, did > you notice that there is a Python-Tutor Discussion List. It's a good > place for Python-learners to ask questions. > > You do not state the Operating System in-use. So, presuming MS-Windows, > please advise if the following reference is accurate, and works for you: > https://docs.python.org/3/using/windows.html > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From mats at python.org Sun May 17 15:47:47 2020 From: mats at python.org (Mats Wichmann) Date: Sun, 17 May 2020 13:47:47 -0600 Subject: Fwd: Unable to Install Python (3.5.0) Properly In-Reply-To: References: <39ade157-3381-6e5b-a9c0-858f36460482@DancesWithMice.info> Message-ID: <1b5057c1-5bfd-9bfc-deae-8b66168bacfe@python.org> On 5/17/20 1:27 PM, Tarun Pathak wrote: > Oh, My apology ! I should have mentioned the system stats in mail. > > Windows 7 , 64 bit > Intel Core 2 duo > C drive free space : 23 GB > > Initially, during installation system is asking for service pack 1 > I did that. > > Later, it's asking for core.msi, dev.msi etc. Because system is not able to > fetch from the web. The log file contains all these errors. 1. Why are you installing 3.5.0? Don't do that. If you *must* install 3.5, which is unlikely (but you haven't explained why), at least make sure to install the latest bugfix version of 3.5, which is 3.5.4 (that's the last with an installer provided). Better is to install 3.7 or 3.8, which are in active support. 2. The installer needs to talk to the Internet in some circumstances. If you have a machine without Internet access, use a different machine and follow the instructions here: https://docs.python.org/3/using/windows.html#installing-without-downloading and then transfer the files to your target machine and install from that. From oscar.j.benjamin at gmail.com Sun May 17 18:52:29 2020 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 17 May 2020 23:52:29 +0100 Subject: Help with installation please In-Reply-To: <50f5f169-868d-f773-cbe1-1d8b186afe0f@wichmann.us> References: <50f5f169-868d-f773-cbe1-1d8b186afe0f@wichmann.us> Message-ID: On Sun, 17 May 2020 at 15:21, Mats Wichmann wrote: > > On 5/15/20 9:47 PM, Souvik Dutta wrote: > > I dont know if you should shift from powershell to cmd. Python kinda does > > not work in powershell. > > Powershell has a funky way of looking up programs, with the result that > you have to type the full name for many. > > python.exe - should work, probably. maybe. > > Using the Python Launcher helps: it works without extra games > > py > > > If you install the Python from the Microsoft Store it will work more > "predicatably" - python, and python3, will work from both a cmd and a > powershell commandline. on the other hand, you will have no Python > Launcher on such a setup. I find the inconsistencies when it comes to "running Python" in a terminal in different operating systems or environments very frustrating. When teaching a class of 200 students who are new to programming it is really important that you can give a simple instruction that works. I'm yet to find that simple instruction for the basic task of starting a Python interpreter. I hope that one day we can get to a situation where once Python is installed it can be run by typing "python" in whatever terminal you want. -- Oscar From robertvstepp at gmail.com Sun May 17 19:13:13 2020 From: robertvstepp at gmail.com (boB Stepp) Date: Sun, 17 May 2020 18:13:13 -0500 Subject: Help with installation please In-Reply-To: References: <50f5f169-868d-f773-cbe1-1d8b186afe0f@wichmann.us> Message-ID: <20200517231313.GD12623@Dream-Machine1> On Sun, May 17, 2020 at 11:52:29PM +0100, Oscar Benjamin wrote: >I find the inconsistencies when it comes to "running Python" in a >terminal in different operating systems or environments very >frustrating. When teaching a class of 200 students who are new to >programming it is really important that you can give a simple >instruction that works. I'm yet to find that simple instruction for >the basic task of starting a Python interpreter. > >I hope that one day we can get to a situation where once Python is >installed it can be run by typing "python" in whatever terminal you >want. Amen!!! -- Wishing you only the best, boB Stepp From PythonList at DancesWithMice.info Sun May 17 20:26:57 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 18 May 2020 12:26:57 +1200 Subject: Help with installation please In-Reply-To: References: <50f5f169-868d-f773-cbe1-1d8b186afe0f@wichmann.us> Message-ID: <8a6a977c-ca96-8d7c-3257-bf5e13e3336c@DancesWithMice.info> On 18/05/20 10:52 AM, Oscar Benjamin wrote: > On Sun, 17 May 2020 at 15:21, Mats Wichmann wrote: >> >> On 5/15/20 9:47 PM, Souvik Dutta wrote: >>> I dont know if you should shift from powershell to cmd. Python kinda does >>> not work in powershell. >> >> Powershell has a funky way of looking up programs, with the result that >> you have to type the full name for many. >> >> python.exe - should work, probably. maybe. >> >> Using the Python Launcher helps: it works without extra games >> >> py >> >> >> If you install the Python from the Microsoft Store it will work more >> "predicatably" - python, and python3, will work from both a cmd and a >> powershell commandline. on the other hand, you will have no Python >> Launcher on such a setup. > > I find the inconsistencies when it comes to "running Python" in a > terminal in different operating systems or environments very > frustrating. When teaching a class of 200 students who are new to > programming it is really important that you can give a simple > instruction that works. I'm yet to find that simple instruction for > the basic task of starting a Python interpreter. > > I hope that one day we can get to a situation where once Python is > installed it can be run by typing "python" in whatever terminal you > want. At last, someone who understands the problem when it is bigger than one person! To be fair, the issue is caused by the likes of Microsoft and Apple deciding that they have 'the one true way'. However, wishing ain't going to make the problem go-away! This question (and its predecessor: "how do I install") is asked so frequently it is obviously a major bug-bear. Yet, it is something I (and most others with Python experience) do from 'muscle-memory' and without thinking... In the spirit of F/LOSS, if the previously-mentioned web-ref is not sufficient, and you are able to outline simple instructions to start a DOS-box (or whatever they call it these days) and the equivalent on Apple (as relevant to your environment), that's probably the best we can do at the applications level - and we should use that to update/improve the docs... -- Regards =dn From cl at isbd.net Mon May 18 06:50:03 2020 From: cl at isbd.net (Chris Green) Date: Mon, 18 May 2020 11:50:03 +0100 Subject: Can one make 'in' ungreedy? Message-ID: I have a strange/minor problem in a Python program I use for mail filtering. One of the ways it classifies messages is by searching for a specific string in square brackets [] in the Subject:, the section of code that does this is:- # # # copy the fields from the filter configuration file into better named variables # nm = fld[0] # name/alias dd = fld[1] + "/" # destination directory tocc = fld[2].lower() # list address sbstrip = '[' + fld[3] + ']' # string to match in and/or strip out of subject # # # see if the filter To/CC column matches the message To: or Cc: or if sbstrip is in Subject: # if (tocc in msgcc or tocc in msgto or sbstrip in msgsb): # # # set the destination directory # dest = mldir + dd + nm # # # Strip out list name (4th field) from subject if it's there # if sbstrip in msgsb: msg.replace_header("Subject", msgsb.replace(sbstrip, '')) # # # we've found a match so assume we won't get another # break So in the particular case where I have a problem sbstrip is "[Ipswich Recycle]" and the Subject: is "[SPAM] [Ipswich Recycle] OFFER: Lawnmower (IP11)". The match isn't found, presumably because 'in' is greedy and sees "[SPAM] [Ipswich Recycle]" which isn't a match for "[Ipswich Recycle]". Other messages with "[Ipswich Recycle]" in the Subject: are being found and filtered correctly, it seems that it's the presence of the "[SPAM]" in the Subject: that's breaking things. Is this how 'in' should work, it seems a little strange if so, not intuitively how one would expect 'in' to work. ... and is there any way round the issue except by recoding a separate test for the particular string search where this can happen? -- Chris Green ? From larry.martell at gmail.com Mon May 18 07:11:29 2020 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 18 May 2020 07:11:29 -0400 Subject: Can one make 'in' ungreedy? In-Reply-To: References: Message-ID: On Mon, May 18, 2020 at 7:05 AM Chris Green wrote: > > I have a strange/minor problem in a Python program I use for mail > filtering. > > One of the ways it classifies messages is by searching for a specific > string in square brackets [] in the Subject:, the section of code that > does this is:- > > # > # > # copy the fields from the filter configuration file into better named variables > # > nm = fld[0] # name/alias > dd = fld[1] + "/" # destination directory > tocc = fld[2].lower() # list address > sbstrip = '[' + fld[3] + ']' # string to match in and/or strip out of subject > # > # > # see if the filter To/CC column matches the message To: or Cc: or if sbstrip is in Subject: > # > if (tocc in msgcc or tocc in msgto or sbstrip in msgsb): > # > # > # set the destination directory > # > dest = mldir + dd + nm > # > # > # Strip out list name (4th field) from subject if it's there > # > if sbstrip in msgsb: > msg.replace_header("Subject", msgsb.replace(sbstrip, '')) > # > # > # we've found a match so assume we won't get another > # > break > > > So in the particular case where I have a problem sbstrip is "[Ipswich > Recycle]" and the Subject: is "[SPAM] [Ipswich Recycle] OFFER: > Lawnmower (IP11)". The match isn't found, presumably because 'in' is > greedy and sees "[SPAM] [Ipswich Recycle]" which isn't a match for > "[Ipswich Recycle]". > > Other messages with "[Ipswich Recycle]" in the Subject: are being > found and filtered correctly, it seems that it's the presence of the > "[SPAM]" in the Subject: that's breaking things. > > Is this how 'in' should work, it seems a little strange if so, not > intuitively how one would expect 'in' to work. ... and is there any > way round the issue except by recoding a separate test for the > particular string search where this can happen? >>> sbstrip = "[Ipswich Recycle]" >>> subject = "[SPAM] [Ipswich Recycle] OFFER:Lawnmower (IP11)" >>> sbstrip in subject True Clearly something else is going on in your program. I would run it in the debugger and look at the values of the variables in the case when it fails when you think it should succeed. I think you will see the variables do not hold what you think they do. From cl at isbd.net Mon May 18 08:39:18 2020 From: cl at isbd.net (Chris Green) Date: Mon, 18 May 2020 13:39:18 +0100 Subject: Can one make 'in' ungreedy? References: Message-ID: Larry Martell wrote: > On Mon, May 18, 2020 at 7:05 AM Chris Green wrote: > > > > I have a strange/minor problem in a Python program I use for mail > > filtering. > > > > One of the ways it classifies messages is by searching for a specific > > string in square brackets [] in the Subject:, the section of code that > > does this is:- > > > > # > > # > > # copy the fields from the filter configuration file into better named variables > > # > > nm = fld[0] # name/alias > > dd = fld[1] + "/" # destination directory > > tocc = fld[2].lower() # list address > > sbstrip = '[' + fld[3] + ']' # string to match in and/or strip out of subject > > # > > # > > # see if the filter To/CC column matches the message To: or Cc: or if sbstrip is in Subject: > > # > > if (tocc in msgcc or tocc in msgto or sbstrip in msgsb): > > # > > # > > # set the destination directory > > # > > dest = mldir + dd + nm > > # > > # > > # Strip out list name (4th field) from subject if it's there > > # > > if sbstrip in msgsb: > > msg.replace_header("Subject", msgsb.replace(sbstrip, '')) > > # > > # > > # we've found a match so assume we won't get another > > # > > break > > > > > > So in the particular case where I have a problem sbstrip is "[Ipswich > > Recycle]" and the Subject: is "[SPAM] [Ipswich Recycle] OFFER: > > Lawnmower (IP11)". The match isn't found, presumably because 'in' is > > greedy and sees "[SPAM] [Ipswich Recycle]" which isn't a match for > > "[Ipswich Recycle]". > > > > Other messages with "[Ipswich Recycle]" in the Subject: are being > > found and filtered correctly, it seems that it's the presence of the > > "[SPAM]" in the Subject: that's breaking things. > > > > Is this how 'in' should work, it seems a little strange if so, not > > intuitively how one would expect 'in' to work. ... and is there any > > way round the issue except by recoding a separate test for the > > particular string search where this can happen? > > >>> sbstrip = "[Ipswich Recycle]" > >>> subject = "[SPAM] [Ipswich Recycle] OFFER:Lawnmower (IP11)" > >>> sbstrip in subject > True > > Clearly something else is going on in your program. I would run it in > the debugger and look at the values of the variables in the case when > it fails when you think it should succeed. I think you will see the > variables do not hold what you think they do. Thanks for taking the trouble to look. It's a *bit* difficult to run in the debugger as the program is a filter triggered by incoming E-Mail messages. However I think I can fire stuff at it via stdin so I'll see what I can fathon out doing that. -- Chris Green ? From skip.montanaro at gmail.com Mon May 18 09:21:00 2020 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 18 May 2020 08:21:00 -0500 Subject: Can one make 'in' ungreedy? In-Reply-To: References: Message-ID: > > Thanks for taking the trouble to look. It's a *bit* difficult to run > in the debugger as the program is a filter triggered by incoming > E-Mail messages. However I think I can fire stuff at it via stdin so > I'll see what I can fathon out doing that. > Cheapo debug trick: When your filter starts, have it open a file in /tmp (or similar) with "a" mode, leaving that file object as a global variable. Then at points of interest, print out useful values to that open file object. Once you've got your logic sorted, either remove the code, comment it out, or predicate its action based on some debug flag. Briefly, using Larry's example: DBG_FP = open("/tmp/ipswich", "a") You might also want to print the message's message-id to DBG_FP at this point. It will serve as a useful separator between debug output for different messages. Sometime later: print("subject:", subject, file=DBG_FP) print("ipswich?", ipswich in subject, file=DBG_FP) And so on. If there is some conditional nesting/looping going on, it can be useful to also include a unique number in each print call in case it's not immediately apparent where a particular record in your file came from. print(1, "subject:", subject, file=DBG_FP) print(2, "ipswich?", ipswich in subject, file=DBG_FP) I started using Python long before there were any fancy debuggers available (never cottoned to pdb for some reason), so print statements were a very common way to debug logic errors. I must confess to continuing to rely on them instead of figuring out how to use modern IDEs (I'm still an Emacs guy anyway, so IDEs seem to suck as a way to edit code). Skip From shivani.shinde at alefedge.com Mon May 18 09:41:11 2020 From: shivani.shinde at alefedge.com (shivani.shinde at alefedge.com) Date: Mon, 18 May 2020 06:41:11 -0700 (PDT) Subject: python3 - Import python file as module Message-ID: <1dd9e5c2-4805-44e4-bee4-d89b8c92ea9c@googlegroups.com> Hi, I am a beginner to Python. I want to achieve the following: My directory structure: a ??? b ??? c ??? p ??? ??? q ??? ??? test.py ??? x ??? y ??? run.py In my run.py file, I want to import everything from test.py(contains methods). I have found relative path for test.py as "....p.q". I tried with exec() to import as : exec("from ....p.q import *"), but this gives me >> "list out of index" error. Then I tried with importlib.import_module with various combinations such as: 1. importlib.import_module('.test', package="....p.q") 2. importlib.import_module('test', package="....p.q") 3. importlib.import_module('....p.q.test', package=None) But I end up getting error as >> No module found "". Can anyone help me with this situation? Any help will be appreciated! Thank you. -- CONFIDENTIALITY. This email and any attachments?are?confidential?to Alef Edge Inc., and may also be privileged,?except?where the?email?states it can be disclosed.?If this email?is received in?error, please?do not disclose the contents?to anyone, notify?the sender by return?email, and delete?this email (and any?attachments) from your system. From cl at isbd.net Mon May 18 09:43:48 2020 From: cl at isbd.net (Chris Green) Date: Mon, 18 May 2020 14:43:48 +0100 Subject: Can one make 'in' ungreedy? References: Message-ID: Larry Martell wrote: > On Mon, May 18, 2020 at 7:05 AM Chris Green wrote: > > > > I have a strange/minor problem in a Python program I use for mail > > filtering. > > > > One of the ways it classifies messages is by searching for a specific > > string in square brackets [] in the Subject:, the section of code that > > does this is:- > > > > # > > # > > # copy the fields from the filter configuration file into better named variables > > # > > nm = fld[0] # name/alias > > dd = fld[1] + "/" # destination directory > > tocc = fld[2].lower() # list address > > sbstrip = '[' + fld[3] + ']' # string to match in and/or strip out of subject > > # > > # > > # see if the filter To/CC column matches the message To: or Cc: or if sbstrip is in Subject: > > # > > if (tocc in msgcc or tocc in msgto or sbstrip in msgsb): > > # > > # > > # set the destination directory > > # > > dest = mldir + dd + nm > > # > > # > > # Strip out list name (4th field) from subject if it's there > > # > > if sbstrip in msgsb: > > msg.replace_header("Subject", msgsb.replace(sbstrip, '')) > > # > > # > > # we've found a match so assume we won't get another > > # > > break > > > > > > So in the particular case where I have a problem sbstrip is "[Ipswich > > Recycle]" and the Subject: is "[SPAM] [Ipswich Recycle] OFFER: > > Lawnmower (IP11)". The match isn't found, presumably because 'in' is > > greedy and sees "[SPAM] [Ipswich Recycle]" which isn't a match for > > "[Ipswich Recycle]". > > > > Other messages with "[Ipswich Recycle]" in the Subject: are being > > found and filtered correctly, it seems that it's the presence of the > > "[SPAM]" in the Subject: that's breaking things. > > > > Is this how 'in' should work, it seems a little strange if so, not > > intuitively how one would expect 'in' to work. ... and is there any > > way round the issue except by recoding a separate test for the > > particular string search where this can happen? > > >>> sbstrip = "[Ipswich Recycle]" > >>> subject = "[SPAM] [Ipswich Recycle] OFFER:Lawnmower (IP11)" > >>> sbstrip in subject > True > > Clearly something else is going on in your program. I would run it in > the debugger and look at the values of the variables in the case when > it fails when you think it should succeed. I think you will see the > variables do not hold what you think they do. Absolutely right! It wasn't even this program had the problem, the odd messages in the wrong place were arriving via my 'catchall' mail filter which deposited stuff by an entirely different route into my inbox! Typical - looking for the bug in the wrong program. :-) -- Chris Green ? From __peter__ at web.de Mon May 18 10:57:29 2020 From: __peter__ at web.de (Peter Otten) Date: Mon, 18 May 2020 16:57:29 +0200 Subject: python3 - Import python file as module References: <1dd9e5c2-4805-44e4-bee4-d89b8c92ea9c@googlegroups.com> Message-ID: shivani.shinde at alefedge.com wrote: > Hi, > I am a beginner to Python. I want to achieve the following: > > My directory structure: > > a > ??? b > ??? c > ??? p > ? ??? q > ? ??? test.py > ??? x > ??? y > ??? run.py > > In my run.py file, I want to import everything from test.py(contains > methods). > > I have found relative path for test.py as "....p.q". > I tried with exec() to import as : exec("from ....p.q import *"), > but this gives me >> "list out of index" error. I do not recognize that error. Is this cut-and-paste? > Then I tried with importlib.import_module with various combinations such > as: 1. importlib.import_module('.test', package="....p.q") > 2. importlib.import_module('test', package="....p.q") > 3. importlib.import_module('....p.q.test', package=None) Why are you trying import_module() or exec() when you know the location of the module you want to import? > But I end up getting error as >> No module found "". > > Can anyone help me with this situation? You need to make sure that a is in your sys.path and that the importing module is itself imported using the complete path. For example: Given $ tree . ??? a ??? b ??? c ??? p ? ??? q ? ??? test.py ??? x ??? y ??? run.py 7 directories, 2 files $ cat a/b/c/p/q/test.pydef hello(): print("Hello, world!") $ cat a/b/c/x/y/run.py from ...p.q.test import hello hello() you can run your run.py with $ python3 -m a.b.c.x.y.run Hello, world! but not with $ python3 a/b/c/x/y/run.py Traceback (most recent call last): File "a/b/c/x/y/run.py", line 1, in from ...p.q.test import hello SystemError: Parent module '' not loaded, cannot perform relative import because here run.py is a standalone script from Python's point of view rather than part of a package hierarchy. In general you can never go higher than the toplevel package, so this also fails: $ cd a/b/c $ python3 -m x.y.run Traceback (most recent call last): File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main "__main__", mod_spec) File "/usr/lib/python3.4/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/petto/srcx/clpy/shivani/a/b/c/x/y/run.py", line 1, in from ...p.q.test import hello ValueError: attempted relative import beyond top-level package While this works $ cd .. $ python3 -m c.x.y.run Hello, world! it is a good idea to decide on the root package once and for all, and then only import starting from that. From dieter at handshake.de Mon May 18 12:08:56 2020 From: dieter at handshake.de (Dieter Maurer) Date: Mon, 18 May 2020 18:08:56 +0200 Subject: Can one make 'in' ungreedy? In-Reply-To: References: Message-ID: <24258.45848.157443.125218@ixdm.fritz.box> Chris Green wrote at 2020-5-18 11:50 +0100: > ... >So in the particular case where I have a problem sbstrip is "[Ipswich >Recycle]" and the Subject: is "[SPAM] [Ipswich Recycle] OFFER: >Lawnmower (IP11)". The match isn't found, presumably because 'in' is >greedy and sees "[SPAM] [Ipswich Recycle]" which isn't a match for >"[Ipswich Recycle]". `in` directly matches substrings; it is not greedy. From kale at thekunderts.net Mon May 18 12:46:59 2020 From: kale at thekunderts.net (Kale Kundert) Date: Mon, 18 May 2020 12:46:59 -0400 Subject: Sphinx plugin to make easier-to-navigate class documentation Message-ID: I'm writing to share a Sphinx plugin I wrote, which I think makes the documentation for large classes much easier to navigate and understand.? The plugin is called `autoclasstoc` and you can find the documentation here: https://autoclasstoc.readthedocs.io/en/latest/ I wrote this plugin because, while restructured text and Sphinx are great in a lot of ways, I've always been disappointed by the options for documenting classes.? `autoclass` is easy to use, but hard to read because all of the methods are just documented one after another with no index at the top. `autosummary` and `autogen` can be used together to create such an index, but they're more difficult to setup, and the index doesn't distinguish nicely between inherited and non-inherited methods. My plugin is modeled after the way `doxygen` (a popular documentation tool for C++ projects) works.? The documentation for each class starts with an index of all it's methods/attributes. Inherited methods are organized by the class they inherit from, and collapsed so they don't distract too much from the methods actually defined in the class itself. I'm pretty happy with how the plugin turned out, and I hope that other people might find it useful, too.? If you decide to give it a try, let me know (either here or, preferably, on Github) if there's anything you'd change. I'm happy to get feedback, because I threw this together pretty quickly and I'm sure there are use-cases I haven't fully considered yet. -Kale From ethan at stoneleaf.us Mon May 18 13:13:21 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 18 May 2020 10:13:21 -0700 Subject: Sphinx plugin to make easier-to-navigate class documentation In-Reply-To: References: Message-ID: <1caa22df-cc4d-e312-a9fe-0f95f352d58f@stoneleaf.us> On 05/18/2020 09:46 AM, Kale Kundert wrote: > I'm writing to share a Sphinx plugin I wrote, which I think makes the > documentation for large classes much easier to navigate and understand.? The > plugin is called `autoclasstoc` and you can find the documentation here: > > https://autoclasstoc.readthedocs.io/en/latest/ This sounds pretty cool! You should also post this on python-announce-list at python.org to reach a wider audience. -- ~Ethan~ From swaroop.sahoo769 at gmail.com Mon May 18 14:40:59 2020 From: swaroop.sahoo769 at gmail.com (swaroop.sahoo769 at gmail.com) Date: Mon, 18 May 2020 11:40:59 -0700 (PDT) Subject: Determining index of range of values in a matrix Message-ID: <04f37122-4347-4914-ad5f-22106275b60e@googlegroups.com> Hi All, I am using python for doing the following: I have a matrix which has dimension of 174*993. Each row of the matrix has some numbers in the range of 30-30.5. I would like to determine the index of the numbers in the range of 30-30.5 in each row. I can determine the index of the numbers in each row by using result1=np.where(np.logical_and(R[i,:]>= 30, R[i,:]<= 30.3)) But I would like to put the indexes in a matrix. That is difficult because the number of indexes in each row will be different. Can anyone help. Regards, Swaroop From sloanlance at gmail.com Mon May 18 15:47:22 2020 From: sloanlance at gmail.com (Lance E Sloan) Date: Mon, 18 May 2020 12:47:22 -0700 (PDT) Subject: why no camelCase in PEP 8? Message-ID: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> I've been using Python for about 18 years. Several things have changed in the language in those years. I don't disagree with most of it, but one of the things that annoys me is the disapproval of using camelCase to name symbols such as variables, functions, etc. I think PEP 8, the "Style Guide for Python Code" (https://www.python.org/dev/peps/pep-0008/), came out shortly after I began using Python. I think the old habits of the people I worked with and the relative lack of tools like Flake8 and Pylint led to the standard being ignored. However, now I see many developers really want to adhere to the standard. My preference for using camelCase (in PEP 8, AKA mixedCase) is putting me at odds with my colleagues, who point to PEP 8 as "the rules". I have reasons for my preferring camelCase. I suspect the reasons the PEP 8 authors have for not using it are probably as strong as my reasons. So our reasons probably nullify each other and what's left is simple preference. So, I'd like to know what was the reason behind favoring snake_case (AKA lower_case_with_underscores) in PEP 8 instead of camelCase. Does anyone in this group know? From rosuav at gmail.com Mon May 18 15:59:30 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 May 2020 05:59:30 +1000 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: On Tue, May 19, 2020 at 5:51 AM Lance E Sloan wrote: > > I've been using Python for about 18 years. Several things have changed in the language in those years. I don't disagree with most of it, but one of the things that annoys me is the disapproval of using camelCase to name symbols such as variables, functions, etc. > > I think PEP 8, the "Style Guide for Python Code" (https://www.python.org/dev/peps/pep-0008/), came out shortly after I began using Python. I think the old habits of the people I worked with and the relative lack of tools like Flake8 and Pylint led to the standard being ignored. However, now I see many developers really want to adhere to the standard. > > My preference for using camelCase (in PEP 8, AKA mixedCase) is putting me at odds with my colleagues, who point to PEP 8 as "the rules". I have reasons for my preferring camelCase. I suspect the reasons the PEP 8 authors have for not using it are probably as strong as my reasons. So our reasons probably nullify each other and what's left is simple preference. > > So, I'd like to know what was the reason behind favoring snake_case (AKA lower_case_with_underscores) in PEP 8 instead of camelCase. > > Does anyone in this group know? PEP 8 is a style guide for the Python standard library. It is the rules you must comply with if you are submitting a patch *to Python itself*. Nobody ever requires you to comply with it for any other code. ChrisA From encore1 at cox.net Mon May 18 16:50:15 2020 From: encore1 at cox.net (Dick Holmes) Date: Mon, 18 May 2020 13:50:15 -0700 Subject: Subprocess Popen confusion References: Message-ID: In article , __peter__ at web.de says... > > Dick Holmes wrote: > > > https://occovid19.ochealthinfo.com/coronavirus-in-oc > > > I'm trying to > > communicate using a continuing dialog between two > > processes on the same system. > > I think pexpect > > https://pexpect.readthedocs.io/en/stable/index.html > > does this naturally, but I don't know if Windows support is sufficient for > your needs. > > > I've looked at various mechanisms and the > > class that seems to fit my needs is Popen in the subprocess module, but > > I can't seem to get more than a single round-trip message through Popen. > > I first call Popen then poll using the identifier returned from the call > > and the poll seems to work. I then call the communicate function passing > > None as the value to send to the companion process stdin. I get the > > expected result, but I also get "Exception condition detected on fd 0 > > \\n" and "error detected on stdin\\n". Subsequent attempts to > > read/write/communicate with the subprocess fail because the file (stdxx > > PIPE) is closed. > > > > I can't tell from the documentation if the communicate function is a > > one-time operation. > > Yes, communicate() is one-off, > > > """Interact with process: Send data to stdin and close it. > Read data from stdout and stderr, until end-of-file is > reached. Wait for process to terminate. > ... > """ > > seems pretty clear. What would you improve? > > > I have tried using read but the read call doesn't > > return (I'm using winpdb-reborn to monitor the operations). > > Try readline(). Deadlocks may happen ;) > > > I'm using Python 3.7, Windows 10, winpdb-reborn 2.0.0, rpdb2 1.5.0. If > > it makes any difference, I'm trying to communicate with GDB using the MI > > interpreter. > > Per Peter's suggestion I tried readline and it works "as expected". I also discovered that the reason the read operations were stalling was that they followed a write and the write doesn't actually occur until "flush" is called even though the function call returns. There are undoubtedly some subtleties lurking about, but at least I'm making good progress. Thanks for the help! Dick From * at eli.users.panix.com Mon May 18 17:07:30 2020 From: * at eli.users.panix.com (Eli the Bearded) Date: Mon, 18 May 2020 21:07:30 +0000 (UTC) Subject: why no camelCase in PEP 8? References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <871rnh802d.fsf@nightsong.com> Message-ID: In comp.lang.python, Paul Rubin wrote: > I don't know if this was the explicit motivation for PEP 8, but it > has always seemed valid to me: > > https://en.wikipedia.org/wiki/Camel_case#Readability_studies There are three things cited there. One is a NYTimes story from 2009 "Against Camel Case" starting out with criticism of "iPhone" which the author describes but won't use as it it too difiguring. That's not a programmer talking about program identifiers. The other two are more relevant, two studies one from 2009 and one from 2010, each of which seems to reach a conclusion at odds with the other. The 2009 one finds camelCase easier to read than snake_case, and the 2010 one finds people recognize snake_case identifiers faster than camelCase ones. I don't think that Wikipedia page helps your case. I personally abhor the use of inappropriate mid-word caps in English, which fits the NYT piece, but am only mildly against them in code. I had some bad expierences with code that forced use of capital letters in college and that has tainted me against excess capitals ever since. This is a highly personal reason that I don't expect anyone else to share. Here's a simple argument against camel case: when it becomes necessary to join identifiers, camel case requires modification of the original unit while snake case just adds stuff to beginning and/or end. One noteworthy example is when a negated version is needed. camelCase -> noCamelCase snake_case -> no_snake_case One of those is easier to "grep" for than the other. Elijah ------ grep-ability of code should on everyone's mond From rosuav at gmail.com Mon May 18 17:19:20 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 May 2020 07:19:20 +1000 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <871rnh802d.fsf@nightsong.com> Message-ID: On Tue, May 19, 2020 at 7:11 AM Eli the Bearded <*@eli.users.panix.com> wrote: > Here's a simple argument against camel case Here's an even simpler argument. XMLHttpRequest ChrisA From juergen at brendel.com Mon May 18 17:55:04 2020 From: juergen at brendel.com (Juergen Brendel) Date: Tue, 19 May 2020 09:55:04 +1200 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <871rnh802d.fsf@nightsong.com> Message-ID: <9567e0da6056cbb2b03f83e603392342eca00b1d.camel@brendel.com> Hello! We have now moved into a pros/cons discussion of snake vs camel-case, which wasn't the original question. But discussions about coding styles are always fun, so why not... :-) I agree with Eli's reasoning about the grep-ability. It's something that people don't often pay attention to, but that is actually really important. One more note about the readability: A good friend of mine is a great developer, but has incredibly poor eye-sight. For him it's very important that the code has easily recognizable patterns. Imagine you'd have to try to make sense of code when you could only squint at the screen and see everything fuzzy and you get the idea. For what are now immediately obvious reasons he prefers snake-case. His concerns about reading code and recognizable patterns have been a guide in the development of my own coding style for more than 20 years now and it has served me well. Juergen On Mon, 2020-05-18 at 21:07 +0000, Eli the Bearded wrote: > In comp.lang.python, Paul Rubin wrote: > > I don't know if this was the explicit motivation for PEP 8, but it > > has always seemed valid to me: > > > > https://en.wikipedia.org/wiki/Camel_case#Readability_studies > > There are three things cited there. One is a NYTimes story from 2009 > "Against Camel Case" starting out with criticism of "iPhone" which > the author describes but won't use as it it too difiguring. That's > not a > programmer talking about program identifiers. > > The other two are more relevant, two studies one from 2009 and one > from > 2010, each of which seems to reach a conclusion at odds with the > other. > The 2009 one finds camelCase easier to read than snake_case, and the > 2010 one finds people recognize snake_case identifiers faster than > camelCase ones. I don't think that Wikipedia page helps your case. > > I personally abhor the use of inappropriate mid-word caps in English, > which fits the NYT piece, but am only mildly against them in code. I > had > some bad expierences with code that forced use of capital letters in > college and that has tainted me against excess capitals ever since. > This > is a highly personal reason that I don't expect anyone else to share. > > Here's a simple argument against camel case: when it becomes > necessary > to join identifiers, camel case requires modification of the original > unit while snake case just adds stuff to beginning and/or end. One > noteworthy example is when a negated version is needed. > > camelCase -> noCamelCase > snake_case -> no_snake_case > > One of those is easier to "grep" for than the other. > > Elijah > ------ > grep-ability of code should on everyone's mond From 2QdxY4RzWzUUiLuE at potatochowder.com Mon May 18 19:28:56 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Mon, 18 May 2020 19:28:56 -0400 Subject: why no camelCase in PEP 8? In-Reply-To: <9567e0da6056cbb2b03f83e603392342eca00b1d.camel@brendel.com> References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <871rnh802d.fsf@nightsong.com> <9567e0da6056cbb2b03f83e603392342eca00b1d.camel@brendel.com> Message-ID: <20200518192856.18e80d53ae34df226e1b7c7c@potatochowder.com> On Tue, 19 May 2020 09:55:04 +1200 Juergen Brendel wrote: > ... he prefers snake-case. That's not snake_case. That's kebab-case.? ? https://wiki.c2.com/?KebabCase From juergen at brendel.com Mon May 18 20:58:56 2020 From: juergen at brendel.com (Juergen Brendel) Date: Tue, 19 May 2020 12:58:56 +1200 Subject: why no camelCase in PEP 8? In-Reply-To: <20200518192856.18e80d53ae34df226e1b7c7c@potatochowder.com> References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <871rnh802d.fsf@nightsong.com> <9567e0da6056cbb2b03f83e603392342eca00b1d.camel@brendel.com> <20200518192856.18e80d53ae34df226e1b7c7c@potatochowder.com> Message-ID: <0c96c4be1e0f7b9dc8006b3cbe7fb901755b8f94.camel@brendel.com> On Mon, 2020-05-18 at 19:28 -0400, Dan Sommers wrote: > On Tue, 19 May 2020 09:55:04 +1200 > Juergen Brendel wrote: > > > ... he prefers snake-case. > > That's not snake_case. That's kebab-case.? > > ? https://wiki.c2.com/?KebabCase :-) From * at eli.users.panix.com Mon May 18 23:02:58 2020 From: * at eli.users.panix.com (Eli the Bearded) Date: Tue, 19 May 2020 03:02:58 +0000 (UTC) Subject: why no camelCase in PEP 8? References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <871rnh802d.fsf@nightsong.com> <87sgfw7lfy.fsf@nightsong.com> Message-ID: In comp.lang.python, Paul Rubin wrote: > Eli the Bearded <*@eli.users.panix.com> writes: >> One of those is easier to "grep" for than the other. > grep -i might help. Or might not, if I want case sensitivity in the rest of my RE. Elijah ------ can, but doesn't want to, build REs that are flexible about partial sensitivity From barry at barrys-emacs.org Tue May 19 04:02:35 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Tue, 19 May 2020 09:02:35 +0100 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <871rnh802d.fsf@nightsong.com> Message-ID: <38745FAF-BAB0-4802-9313-684013C0908B@barrys-emacs.org> > On 18 May 2020, at 22:07, Eli the Bearded <*@eli.users.panix.com> wrote: > > camelCase -> noCamelCase > snake_case -> no_snake_case > > One of those is easier to "grep" for than the other. I guess you mean that a case-sensitive grep can tell camelCase from noCamelCase. In all cases you need to use a \b to mark the boundary of the word. Otherwise the RE will match more than you expect, assuming a large set of identifiers. grep '\bsnake_case\b *.py Barry From rhodri at kynesim.co.uk Tue May 19 04:53:01 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 19 May 2020 09:53:01 +0100 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <871rnh802d.fsf@nightsong.com> Message-ID: On 18/05/2020 22:07, Eli the Bearded wrote: > camelCase -> noCamelCase > snake_case -> no_snake_case > > One of those is easier to "grep" for than the other. Eh. A changed case in the one, an extra character in the other; that's pretty much the same difficulty really. I certainly don't find it "hard" to grep for _snake_case. -- Rhodri James *-* Kynesim Ltd From barry at barrys-emacs.org Tue May 19 04:27:54 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Tue, 19 May 2020 09:27:54 +0100 Subject: Subprocess Popen confusion In-Reply-To: References: Message-ID: <15267DA3-45FC-4153-9271-4466400B5523@barrys-emacs.org> > On 18 May 2020, at 21:50, Dick Holmes wrote: snip > Per Peter's suggestion I tried readline and it works "as expected". I > also discovered that the reason the read operations were stalling was > that they followed a write and the write doesn't actually occur until > "flush" is called even though the function call returns. There are > undoubtedly some subtleties lurking about, but at least I'm making good > progress. You need the flush() because the stream is using buffered I/O. Each write adds to the buffer inside python and when then buffer if full it is written out of Python into the OS. As you found you can force a partial buffer to be written by calling flush(). Barry > > Thanks for the help! > > Dick > > > -- > https://mail.python.org/mailman/listinfo/python-list From lukasz at langa.pl Tue May 19 05:49:41 2020 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Tue, 19 May 2020 11:49:41 +0200 Subject: [RELEASE] Python 3.9.0b1 is now available for testing Message-ID: <026F8D50-BEEF-4814-A984-08B7B41FF392@langa.pl> 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.0b1. Get it here: https://www.python.org/downloads/release/python-390b1/ This is a beta preview of Python 3.9 Python 3.9 is still in development. This release, 3.9.0b1, is the first of four 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 4 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 second beta release of Python 3.9, will be 3.9.0b2. It is currently scheduled for 2020-06-08. 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 Richard at Damon-Family.org Tue May 19 06:52:46 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Tue, 19 May 2020 06:52:46 -0400 Subject: why no camelCase in PEP 8? In-Reply-To: <38745FAF-BAB0-4802-9313-684013C0908B@barrys-emacs.org> References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <871rnh802d.fsf@nightsong.com> <38745FAF-BAB0-4802-9313-684013C0908B@barrys-emacs.org> Message-ID: <98e90463-d999-7ab0-58f7-fc03549bd0ae@Damon-Family.org> On 5/19/20 4:02 AM, Barry Scott wrote: > >> On 18 May 2020, at 22:07, Eli the Bearded <*@eli.users.panix.com> wrote: >> >> camelCase -> noCamelCase >> snake_case -> no_snake_case >> >> One of those is easier to "grep" for than the other. > I guess you mean that a case-sensitive grep can tell > camelCase from noCamelCase. > > In all cases you need to use a \b to mark the boundary of the word. > Otherwise the RE will match more than you expect, assuming a > large set of identifiers. > > grep '\bsnake_case\b *.py > > Barry > I think the issue is that you can easy search for all 'snake_case' and get them, but you have more difficulty searching for all 'camelCase', needing to go case insensitive, but if leading case matters (like there is a type CamelCase that you don't want) you get unwanted hits. -- Richard Damon From Joseph.Schachner at Teledyne.com Tue May 19 14:00:59 2020 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Tue, 19 May 2020 18:00:59 +0000 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: I don't actually know, but I can take a guess. CamelCase can be problematic with terms that are abbreviations and always upper case. For example FIRFilter or USBPLL The first violated camelCase because it has no lower case letters before Filter, and the second completely violates camelCase because both USB and PLL are well known always capitalized abbreviations so that name has no lower case letters. On the other hand FIR_filter and USB_PLL have no problem showing where the split should be. And, because '_' looks sort of like a space, the individual words are more easily readable. notEveyoneThinksReadingCamelCaseIsEasy. -- Joseph S. -----Original Message----- From: Lance E Sloan Sent: Monday, May 18, 2020 3:47 PM To: python-list at python.org Subject: why no camelCase in PEP 8? I've been using Python for about 18 years. Several things have changed in the language in those years. I don't disagree with most of it, but one of the things that annoys me is the disapproval of using camelCase to name symbols such as variables, functions, etc. I think PEP 8, the "Style Guide for Python Code" (https://www.python.org/dev/peps/pep-0008/), came out shortly after I began using Python. I think the old habits of the people I worked with and the relative lack of tools like Flake8 and Pylint led to the standard being ignored. However, now I see many developers really want to adhere to the standard. My preference for using camelCase (in PEP 8, AKA mixedCase) is putting me at odds with my colleagues, who point to PEP 8 as "the rules". I have reasons for my preferring camelCase. I suspect the reasons the PEP 8 authors have for not using it are probably as strong as my reasons. So our reasons probably nullify each other and what's left is simple preference. So, I'd like to know what was the reason behind favoring snake_case (AKA lower_case_with_underscores) in PEP 8 instead of camelCase. Does anyone in this group know? From ml_news at posteo.de Tue May 19 14:10:43 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Tue, 19 May 2020 20:10:43 +0200 Subject: Strings: double versus single quotes Message-ID: <20200519201043.368b6157@arcor.com> Hi there, I am asking myself if I should preferably use single or double quotes for strings? If I need a single quote in a string I would use double quotes for the whole string and vice versa. For f-strings I mostly see double quotes but single quotes would work as well I think. Is there a recommendation? -- Manfred From rosuav at gmail.com Tue May 19 14:24:31 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 May 2020 04:24:31 +1000 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> Message-ID: On Wed, May 20, 2020 at 4:03 AM Schachner, Joseph wrote: > > And, because '_' looks sort of like a space, the individual words are more easily readable. notEveyoneThinksReadingCamelCaseIsEasy. > Me: "What does casels mean?" *beat* Me: "Well, I guess that's the point then, isn't it." ChrisA From rosuav at gmail.com Tue May 19 14:26:01 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 May 2020 04:26:01 +1000 Subject: Strings: double versus single quotes In-Reply-To: <20200519201043.368b6157@arcor.com> References: <20200519201043.368b6157@arcor.com> Message-ID: On Wed, May 20, 2020 at 4:21 AM Manfred Lotz wrote: > > Hi there, > I am asking myself if I should preferably use single or double quotes > for strings? > > If I need a single quote in a string I would use double quotes for the > whole string and vice versa. For f-strings I mostly see double > quotes but single quotes would work as well I think. > > Is there a recommendation? > Nothing strong. I tend to use double quotes because I have a background in C (where double quotes are for strings, single quotes for characters), and double quotes are the recommendation for docstrings (see PEP 258). If you tend to work a lot with SQL, you might prefer single quotes. Use whatever makes you happy. ChrisA From joel.goldstick at gmail.com Tue May 19 14:40:30 2020 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 19 May 2020 14:40:30 -0400 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> Message-ID: On Tue, May 19, 2020 at 2:27 PM Chris Angelico wrote: > > On Wed, May 20, 2020 at 4:21 AM Manfred Lotz wrote: > > > > Hi there, > > I am asking myself if I should preferably use single or double quotes > > for strings? > > > > If I need a single quote in a string I would use double quotes for the > > whole string and vice versa. For f-strings I mostly see double > > quotes but single quotes would work as well I think. > > > > Is there a recommendation? > > > > Nothing strong. I tend to use double quotes because I have a > background in C (where double quotes are for strings, single quotes > for characters), and double quotes are the recommendation for > docstrings (see PEP 258). If you tend to work a lot with SQL, you > might prefer single quotes. Use whatever makes you happy. > I thought triple quotes are for docstrings? > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From PythonList at DancesWithMice.info Tue May 19 14:33:46 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 20 May 2020 06:33:46 +1200 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> Message-ID: <2c62b18b-fa05-8488-ef9c-537543f28d1e@DancesWithMice.info> On 20/05/20 6:26 AM, Chris Angelico wrote: > On Wed, May 20, 2020 at 4:21 AM Manfred Lotz wrote: >> >> Hi there, >> I am asking myself if I should preferably use single or double quotes >> for strings? >> >> If I need a single quote in a string I would use double quotes for the >> whole string and vice versa. For f-strings I mostly see double >> quotes but single quotes would work as well I think. >> >> Is there a recommendation? >> > > Nothing strong. I tend to use double quotes because I have a > background in C (where double quotes are for strings, single quotes > for characters), and double quotes are the recommendation for > docstrings (see PEP 258). If you tend to work a lot with SQL, you > might prefer single quotes. Use whatever makes you happy. Have been finding myself doing somewhat the opposite: "a literal string" f'a string featuring computation of { result }' (never managed to make it as far as C in my alphabet skills, but yes, maybe SQL influences) @Chris: are you on the night-shift? -- Regards =dn From PythonList at DancesWithMice.info Tue May 19 14:44:15 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 20 May 2020 06:44:15 +1200 Subject: Determining index of range of values in a matrix In-Reply-To: <04f37122-4347-4914-ad5f-22106275b60e@googlegroups.com> References: <04f37122-4347-4914-ad5f-22106275b60e@googlegroups.com> Message-ID: On 19/05/20 6:40 AM, swaroop.sahoo769 at gmail.com wrote: > Hi All, > I am using python for doing the following: > I have a matrix which has dimension of 174*993. > Each row of the matrix has some numbers in the range of 30-30.5. > I would like to determine the index of the numbers in the range of 30-30.5 in each row. > I can determine the index of the numbers in each row by using result1=np.where(np.logical_and(R[i,:]>= 30, R[i,:]<= 30.3)) > But I would like to put the indexes in a matrix. > That is difficult because the number of indexes in each row will be different. > Can anyone help. I'm probably less than sure that I've understood the problem. How will the indexes be used once the second 'matrix' is built? Might it help to include some examples of data-rows, plus the expected index-row? Are we to assume that you are using np? As you allude, the usual structure of a "matrix" is that the number of 'columns' in each 'row' is the same. However, the indexes might constitute a "sparse matrix". Python however, has no 'matrix' data-structure, but does allow lists to contain lists (or dict[ionaries] to contain dicts) as a 2D data-structure. A list has no constraint, and no expectation that each 'row' has the same number of columns. -- Regards =dn From python.list at tim.thechases.com Tue May 19 14:36:54 2020 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 19 May 2020 13:36:54 -0500 Subject: Strings: double versus single quotes In-Reply-To: <20200519201043.368b6157@arcor.com> References: <20200519201043.368b6157@arcor.com> Message-ID: <20200519133654.71679e25@bigbox.attlocal.net> On 2020-05-19 20:10, Manfred Lotz wrote: > Hi there, > I am asking myself if I should preferably use single or double > quotes for strings? I'd say your consistency matters more than which one you choose. According to a recent observation by Raymond H. """ Over time, the #python world has shown increasing preference for double quotes: "hello" versus 'hello'. Perhaps, this is due to the persistent influence of JSON, PyCharm, Black, and plain English. In contrast, the interpreter itself prefers single quotes: >>> "hello" 'hello' """ https://twitter.com/raymondh/status/1259209765072154624 I think the worst choice is to be haphazard in your usage with a hodgepodge of single/double quotes. I personally use habits from my C days: double-quotes for everything except single characters for which I use a single-quote: if 'e' in "hello": as in indicator that I'm using it as a single character rather than as a string. I don't have a firm rule for myself if a string contains double-quotes. It doesn't happen often for me in a case where I couldn't use a triple-quoted string or that I am refering to it as a single character. -tkc From rosuav at gmail.com Tue May 19 15:35:48 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 May 2020 05:35:48 +1000 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> Message-ID: On Wed, May 20, 2020 at 4:42 AM Joel Goldstick wrote: > > On Tue, May 19, 2020 at 2:27 PM Chris Angelico wrote: > > > > On Wed, May 20, 2020 at 4:21 AM Manfred Lotz wrote: > > > > > > Hi there, > > > I am asking myself if I should preferably use single or double quotes > > > for strings? > > > > > > If I need a single quote in a string I would use double quotes for the > > > whole string and vice versa. For f-strings I mostly see double > > > quotes but single quotes would work as well I think. > > > > > > Is there a recommendation? > > > > > > > Nothing strong. I tend to use double quotes because I have a > > background in C (where double quotes are for strings, single quotes > > for characters), and double quotes are the recommendation for > > docstrings (see PEP 258). If you tend to work a lot with SQL, you > > might prefer single quotes. Use whatever makes you happy. > > > I thought triple quotes are for docstrings? Yes, but triple double quotes ==> """ <== not triple single quotes ==> ''' <== is what PEP 258 recommends. The description is awkward but it's still a place where the double-quote character (U+0022 QUOTATION MARK) is the recommendation. On Wed, May 20, 2020 at 4:46 AM DL Neil via Python-list wrote: > @Chris: are you on the night-shift? Yes? :) ChrisA From robin at reportlab.com Tue May 19 12:17:36 2020 From: robin at reportlab.com (Robin Becker) Date: Tue, 19 May 2020 17:17:36 +0100 Subject: [RELEASE] Python 3.9.0b1 is now available for testing In-Reply-To: <026F8D50-BEEF-4814-A984-08B7B41FF392@langa.pl> References: <026F8D50-BEEF-4814-A984-08B7B41FF392@langa.pl> Message-ID: On 19/05/2020 10:49, ?ukasz Langa wrote: > 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.0b1. Get it here: > > https://www.python.org/downloads/release/python-390b1/ > > This is a beta preview of Python 3.9 > > Python 3.9 is still in development. This release, 3.9.0b1, is the first of four 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 > ......... I built python3.9.0b1 from source using the standard configure make dance eg ./configure --prefix=$HOME/LOCAL/3.9b1 make && make install that appeared to work fine and I seem to get a working python. However, I seem to have an issue with the distutils package > robin at minikat:~/devel/reportlab > $ $HOME/LOCAL/3.9b1/bin/python3.9 > Python 3.9.0b1 (default, May 19 2020, 12:50:30) > [GCC 10.1.0] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import distutils > /home/robin/LOCAL/3.9b1/lib/python3.9/distutils/__init__.py:15: UserWarning: The virtualenv distutils package at %s appears to be in the same location as the system distutils? > warnings.warn("The virtualenv distutils package at %s appears to be in the same location as the system distutils?") >>>> distutils.__path__ > ['/home/robin/LOCAL/3.9b1/lib/python3.9/distutils'] >>>> distutils.__file__ > '/home/robin/LOCAL/3.9b1/lib/python3.9/distutils/__init__.py' >>>> is this a bug or have I built python 3.9.0b1 wrongly? -- Robin Becker From jf_byrnes at comcast.net Tue May 19 15:51:45 2020 From: jf_byrnes at comcast.net (Jim) Date: Tue, 19 May 2020 14:51:45 -0500 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> Message-ID: On 5/19/20 1:24 PM, Chris Angelico wrote: > On Wed, May 20, 2020 at 4:03 AM Schachner, Joseph > wrote: >> >> And, because '_' looks sort of like a space, the individual words are more easily readable. notEveyoneThinksReadingCamelCaseIsEasy. >> > > Me: "What does casels mean?" > > *beat* > > Me: "Well, I guess that's the point then, isn't it." > > ChrisA > Couldn't resist: Why not Chris_A :) Jim From alan.gauld at yahoo.co.uk Tue May 19 15:53:09 2020 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 19 May 2020 20:53:09 +0100 Subject: Missing python curses functions? Message-ID: During my Covid19 lock-down I thought I'd spend my time translating the "Linux Curses Programming HOWTO" document into Pythonic curses. One of the functions discussed that does not appear to have a Python equivalent is attr_get() which gets the current attributes. There are functions aplenty for setting/unsetting attributes but not for querying them. Or am I missing something....? I understand why we don't implement the print family of functions - we can use string formatting combined with addstr(). But I can't see equivalent python functionality in the attr_get() case? Is anyone other than me still even using Python curses? :-) -- 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 ethan at stoneleaf.us Tue May 19 16:41:33 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 19 May 2020 13:41:33 -0700 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> Message-ID: On 05/19/2020 11:40 AM, Joel Goldstick wrote: > I thought triple quotes are for docstrings? It's the recommendation, but double and single quotes work just fine, too -- at least for docstrings that fit an one line. -- ~Ethan~ From rosuav at gmail.com Tue May 19 16:49:59 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 May 2020 06:49:59 +1000 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> Message-ID: On Wed, May 20, 2020 at 6:38 AM Jim wrote: > > On 5/19/20 1:24 PM, Chris Angelico wrote: > > On Wed, May 20, 2020 at 4:03 AM Schachner, Joseph > > wrote: > >> > >> And, because '_' looks sort of like a space, the individual words are more easily readable. notEveyoneThinksReadingCamelCaseIsEasy. > >> > > > > Me: "What does casels mean?" > > > > *beat* > > > > Me: "Well, I guess that's the point then, isn't it." > > > > ChrisA > > > > Couldn't resist: Why not Chris_A :) Heh. Actually a fair question! It's actually been my shorthand name for many many years, and originally I used the username "chrisa" since that was the email convention at the company. I later started uppercasing it to avoid being thought of as a "Christa" or somesuch, and wanted to remain compatible with the existing address, so case changes were all I'd do. But if I were to identify myself in a more Pythonic way, it would be Chris_Angelico. Backward compatibility trumps PEP 8. ChrisA From PythonList at DancesWithMice.info Tue May 19 17:03:54 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 20 May 2020 09:03:54 +1200 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> Message-ID: <81e1f117-5066-3646-22d2-b1ebe57c915d@DancesWithMice.info> On 20/05/20 8:49 AM, Chris Angelico wrote: > On Wed, May 20, 2020 at 6:38 AM Jim wrote: >> >> On 5/19/20 1:24 PM, Chris Angelico wrote: >>> On Wed, May 20, 2020 at 4:03 AM Schachner, Joseph >>> wrote: >>>> >>>> And, because '_' looks sort of like a space, the individual words are more easily readable. notEveyoneThinksReadingCamelCaseIsEasy. >>>> >>> >>> Me: "What does casels mean?" Chris Angelico Shortens Every Long-name Savagely ? Significantly ? -- Regards =dn From ml_news at posteo.de Tue May 19 16:04:05 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Tue, 19 May 2020 22:04:05 +0200 Subject: Strings: double versus single quotes References: <20200519201043.368b6157@arcor.com> <20200519133654.71679e25@bigbox.attlocal.net> Message-ID: <20200519220405.3a60b807@arcor.com> On Tue, 19 May 2020 13:36:54 -0500 Tim Chase wrote: > On 2020-05-19 20:10, Manfred Lotz wrote: > > Hi there, > > I am asking myself if I should preferably use single or double > > quotes for strings? > > I'd say your consistency matters more than which one you choose. > > According to a recent observation by Raymond H. > > """ > Over time, the #python world has shown increasing preference > for double quotes: "hello" versus 'hello'. > > Perhaps, this is due to the persistent influence of JSON, > PyCharm, Black, and plain English. > > In contrast, the interpreter itself prefers single quotes: > > >>> "hello" > 'hello' > """ > > https://twitter.com/raymondh/status/1259209765072154624 > > I think the worst choice is to be haphazard in your usage with a > hodgepodge of single/double quotes. > > I personally use habits from my C days: double-quotes for everything > except single characters for which I use a single-quote: > > if 'e' in "hello": > > as in indicator that I'm using it as a single character rather than > as a string. > > I don't have a firm rule for myself if a string contains > double-quotes. It doesn't happen often for me in a case where I > couldn't use a triple-quoted string or that I am refering to it as a > single character. > > -tkc > > I am influenced by Perl which I used before. In Perl I used double quoted strings when I wanted interpolation. Otherwise single quoted strings. In Rust (or C) it is double quotes for strings and single quotes for characters. You may be right. Consistency is a good thing. So, I have to decide for what I use and be consistent thereafter. -- Manfred From barry at barrys-emacs.org Tue May 19 16:44:46 2020 From: barry at barrys-emacs.org (Barry) Date: Tue, 19 May 2020 21:44:46 +0100 Subject: [RELEASE] Python 3.9.0b1 is now available for testing In-Reply-To: References: Message-ID: > On 19 May 2020, at 21:36, Robin Becker wrote: > > ?On 19/05/2020 10:49, ?ukasz Langa wrote: >> 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.0b1. Get it here: >> https://www.python.org/downloads/release/python-390b1/ >> This is a beta preview of Python 3.9 >> Python 3.9 is still in development. This release, 3.9.0b1, is the first of four 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 > ......... > > I built python3.9.0b1 from source using the standard configure make dance eg > > ./configure --prefix=$HOME/LOCAL/3.9b1 > make && make install > > that appeared to work fine and I seem to get a working python. However, I seem to have an issue with the distutils package > > >> robin at minikat:~/devel/reportlab >> $ $HOME/LOCAL/3.9b1/bin/python3.9 >> Python 3.9.0b1 (default, May 19 2020, 12:50:30) [GCC 10.1.0] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import distutils >> /home/robin/LOCAL/3.9b1/lib/python3.9/distutils/__init__.py:15: UserWarning: The virtualenv distutils package at %s appears to be in the same location as the system distutils? >> warnings.warn("The virtualenv distutils package at %s appears to be in the same location as the system distutils?") >>>>> distutils.__path__ >> ['/home/robin/LOCAL/3.9b1/lib/python3.9/distutils'] >>>>> distutils.__file__ >> '/home/robin/LOCAL/3.9b1/lib/python3.9/distutils/__init__.py' > > is this a bug or have I built python 3.9.0b1 wrongly? I think that is correct __file__ value. What are you expecting to see? Barry > -- > Robin Becker > > -- > https://mail.python.org/mailman/listinfo/python-list From bill at celestial.net Tue May 19 16:54:56 2020 From: bill at celestial.net (Bill Campbell) Date: Tue, 19 May 2020 13:54:56 -0700 Subject: Missing python curses functions? In-Reply-To: References: Message-ID: <20200519205456.GA16168@hazlitt.celestial.com> On Tue, May 19, 2020, Alan Gauld via Python-list wrote: >During my Covid19 lock-down I thought I'd spend my time translating >the "Linux Curses Programming HOWTO" document into Pythonic curses. > >One of the functions discussed that does not appear to have >a Python equivalent is attr_get() which gets the current >attributes. I haven't looked for it. ... >Is anyone other than me still even using Python curses? :-) Raises hand. Bill -- INTERNET: bill at celestial.com Bill Campbell; Celestial Software LLC URL: http://www2.celestial.com/ 6641 E. Mercer Way Mobile: (206) 947-5591 PO Box 820 Fax: (206) 232-9186 Mercer Island, WA 98040-0820 Democracy Is Mob Rule with Income Taxes From robin at reportlab.com Tue May 19 18:41:31 2020 From: robin at reportlab.com (Robin Becker) Date: Tue, 19 May 2020 23:41:31 +0100 Subject: [RELEASE] Python 3.9.0b1 is now available for testing In-Reply-To: References: Message-ID: .......... >>> robin at minikat:~/devel/reportlab >>> $ $HOME/LOCAL/3.9b1/bin/python3.9 >>> Python 3.9.0b1 (default, May 19 2020, 12:50:30) [GCC 10.1.0] on linux >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> import distutils >>> /home/robin/LOCAL/3.9b1/lib/python3.9/distutils/__init__.py:15: UserWarning: The virtualenv distutils package at %s appears to be in the same location as the system distutils? >>> warnings.warn("The virtualenv distutils package at %s appears to be in the same location as the system distutils?") >>>>>> distutils.__path__ >>> ['/home/robin/LOCAL/3.9b1/lib/python3.9/distutils'] >>>>>> distutils.__file__ >>> '/home/robin/LOCAL/3.9b1/lib/python3.9/distutils/__init__.py' >> >> is this a bug or have I built python 3.9.0b1 wrongly? > > I think that is correct __file__ value. What are you expecting to see? I wasn't expecting the warning at all, but in fact this appears to be an interaction caused by installing virualenv==16.2.0 into my home built python3.9.0b1 and then using it to create a virtual environment. For some reason that creates a problem in the base python which I haven't yet fully explained. I can build python3.9.9b1 virtualenvs using archlinux python 3.8.2 with /bin/python -mvirtualenv -p /home/robin/LOCAL/3.9b1/bin/python3.9 myenv I prefer the older virtualenv because it makes python executables which I can link to rather than always using an explicit path. Sorry for the noise. > > Barry > >> -- >> Robin Becker >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > O From cs at cskk.id.au Tue May 19 20:48:57 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 20 May 2020 10:48:57 +1000 Subject: Missing python curses functions? In-Reply-To: References: Message-ID: <20200520004857.GA64494@cskk.homeip.net> On 19May2020 20:53, Alan Gauld wrote: >Is anyone other than me still even using Python curses? :-) Well, not curses full on (due to lack of time) but my cs.upd module uses the ti_getstr() et al functions for cursor motions and insert/delete line, etc. It may be that the person who wrote the curses module simply got tired. Or it predates the get_attr calls (not sure now old they are). Cheers, Cameron Simpson From cs at cskk.id.au Tue May 19 20:54:14 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 20 May 2020 10:54:14 +1000 Subject: Strings: double versus single quotes In-Reply-To: <20200519220405.3a60b807@arcor.com> References: <20200519220405.3a60b807@arcor.com> Message-ID: <20200520005414.GA74583@cskk.homeip.net> On 19May2020 22:04, Manfred Lotz wrote: >On Tue, 19 May 2020 13:36:54 -0500 >Tim Chase wrote: >> On 2020-05-19 20:10, Manfred Lotz wrote: >> > I am asking myself if I should preferably use single or double >> > quotes for strings? >> >> I'd say your consistency matters more than which one you choose. [...] >> I personally use habits from my C days: double-quotes for everything >> except single characters for which I use a single-quote: >> >> if 'e' in "hello": >> >> as in indicator that I'm using it as a single character rather than >> as a string. >> >> I don't have a firm rule for myself if a string contains >> double-quotes. It doesn't happen often for me in a case where I >> couldn't use a triple-quoted string or that I am refering to it as a >> single character. [...] > >I am influenced by Perl which I used before. In Perl I used double >quoted strings when I wanted interpolation. Otherwise single quoted >strings. In Rust (or C) it is double quotes for strings and single >quotes for characters. And I, the shell (where single quotes are "raw" and double quotes allow parameter substitution). So I use single quotes for plain old strings and double quotes when I'm going to be formatting the string with % (therefore, in most logging calls). Personally I find double quotes visually noisy, and prefer single quotes. Most of the time. This is one of the reasons I autoformat with yapf (which doesn't change my quoting) rather than black (which is very opinionated and also untunable, and _does_ change my quotes). Cheers, Cameron Simpson From alan.gauld at yahoo.co.uk Tue May 19 20:15:24 2020 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 20 May 2020 01:15:24 +0100 Subject: Strings: double versus single quotes In-Reply-To: <20200519201043.368b6157@arcor.com> References: <20200519201043.368b6157@arcor.com> Message-ID: On 19/05/2020 19:10, Manfred Lotz wrote: > Hi there, > I am asking myself if I should preferably use single or double quotes > for strings? Personally laziness wins every time. Single quotes only require one finger from the home position using my right hand, double quotes require two and a big movement of my left hand from home. So I use single quotes most of the time (ie unless it contains a single quote) -- 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 ryan.harrington at whitesourcesoftware.com Tue May 19 20:31:28 2020 From: ryan.harrington at whitesourcesoftware.com (Ryan Harrington) Date: Tue, 19 May 2020 20:31:28 -0400 Subject: Can't run program Message-ID: Hi - I'm not the least bit technical. Trying to learn through YouTube. I've gotten exit code 1, 2, 106. Tried setting up the project interpreter and can't figure it out. Tried uninstalling and reinstalling everything and still having problems. Any feedback appreciated. Thank you, -- Ryan Harrington Director of Sales M - 860-303-2265 WhiteSourceSoftware.com Boston, MA, USA From tjreedy at udel.edu Tue May 19 20:47:48 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 19 May 2020 20:47:48 -0400 Subject: Strings: double versus single quotes In-Reply-To: <20200519201043.368b6157@arcor.com> References: <20200519201043.368b6157@arcor.com> Message-ID: On 5/19/2020 2:10 PM, Manfred Lotz wrote: > Hi there, > I am asking myself if I should preferably use single or double quotes > for strings? > > If I need a single quote in a string I would use double quotes for the > whole string and vice versa. For f-strings I mostly see double > quotes but single quotes would work as well I think. > > Is there a recommendation? I personally like to use "This is a phrase or sentence" while '0', '\n', and 'work' are items or words. # And this is a comment 'quoted' by '#' and '\n'. -- Terry Jan Reedy From yong at riseup.net Tue May 19 21:11:06 2020 From: yong at riseup.net (Yong Pang) Date: Wed, 20 May 2020 09:11:06 +0800 Subject: Can't run program In-Reply-To: References: Message-ID: <0fb0e47a-b515-3a96-fe1d-2aa916717d1c@riseup.net> Hi Ryan Harrington wrote: > Hi - I'm not the least bit technical. Trying to learn through YouTube. I've > gotten exit code 1, 2, 106. Tried setting up the project interpreter and > can't figure it out. Tried uninstalling and reinstalling everything and > still having problems. Any feedback appreciated. You should be able to paste the code here before anyone others can help you. Regards. From souvik.viksou at gmail.com Tue May 19 22:09:28 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Wed, 20 May 2020 07:39:28 +0530 Subject: Strings: double versus single quotes In-Reply-To: <20200519201043.368b6157@arcor.com> References: <20200519201043.368b6157@arcor.com> Message-ID: I love and use only singel quotes. I think that looks clean... Nothing else. Souvik flutter dev On Tue, May 19, 2020, 11:50 PM Manfred Lotz wrote: > Hi there, > I am asking myself if I should preferably use single or double quotes > for strings? > > If I need a single quote in a string I would use double quotes for the > whole string and vice versa. For f-strings I mostly see double > quotes but single quotes would work as well I think. > > Is there a recommendation? > > > -- > Manfred > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From jf_byrnes at comcast.net Tue May 19 22:09:50 2020 From: jf_byrnes at comcast.net (Jim) Date: Tue, 19 May 2020 21:09:50 -0500 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> Message-ID: On 5/19/20 3:49 PM, Chris Angelico wrote: > On Wed, May 20, 2020 at 6:38 AM Jim wrote: >> >> On 5/19/20 1:24 PM, Chris Angelico wrote: >>> On Wed, May 20, 2020 at 4:03 AM Schachner, Joseph >>> wrote: >>>> >>>> And, because '_' looks sort of like a space, the individual words are more easily readable. notEveyoneThinksReadingCamelCaseIsEasy. >>>> >>> >>> Me: "What does casels mean?" >>> >>> *beat* >>> >>> Me: "Well, I guess that's the point then, isn't it." >>> >>> ChrisA >>> >> >> Couldn't resist: Why not Chris_A :) > > Heh. Actually a fair question! It's actually been my shorthand name > for many many years, and originally I used the username "chrisa" since > that was the email convention at the company. I later started > uppercasing it to avoid being thought of as a "Christa" or somesuch, > and wanted to remain compatible with the existing address, so case > changes were all I'd do. But if I were to identify myself in a more > Pythonic way, it would be Chris_Angelico. > > Backward compatibility trumps PEP 8. > > ChrisA > Fair point. Jim From bgailer at gmail.com Tue May 19 23:13:24 2020 From: bgailer at gmail.com (Bob Gailer) Date: Tue, 19 May 2020 23:13:24 -0400 Subject: Can't run program In-Reply-To: References: Message-ID: On May 19, 2020 9:02 PM, "Ryan Harrington" < ryan.harrington at whitesourcesoftware.com> wrote: > > Hi - I'm not the least bit technical. Trying to learn through YouTube. I've > gotten exit code 1, 2, 106. Tried setting up the project interpreter and > can't figure it out. Tried uninstalling and reinstalling everything and > still having problems. Any feedback appreciated. We need a lot more information in order to help you. Operating system? Where did you get the installation file? what does "everything" mean? Show us the steps you took and whatever error messages you got, or whatever "still having problems" means. I'm pretty sure this list does not take attachments, so you either need to copy and paste what you might have typed and any results from that, or put images in a place like pastebin and give us the link. Bob Gailer From robin at reportlab.com Wed May 20 04:03:16 2020 From: robin at reportlab.com (Robin Becker) Date: Wed, 20 May 2020 09:03:16 +0100 Subject: [RELEASE] Python 3.9.0b1 is now available for testing In-Reply-To: References: Message-ID: On 19/05/2020 23:41, Robin Becker wrote: > .......... >>>> robin at minikat:~/devel/reportlab >>>> $?$HOME/LOCAL/3.9b1/bin/python3.9 >>>> Python?3.9.0b1?(default,?May?19?2020,?12:50:30)?[GCC?10.1.0]?on?linux >>>> Type?"help",?"copyright",?"credits"?or?"license"?for?more?information. >>>>>>> import?distutils >>>> /home/robin/LOCAL/3.9b1/lib/python3.9/distutils/__init__.py:15:?UserWarning:?The?virtualenv?distutils?package?at?%s?appears?to?be?in?the?same?location?as?the?system?distutils? >>>> >>>> ??warnings.warn("The?virtualenv?distutils?package?at?%s?appears?to?be?in?the?same?location?as?the?system?distutils?") >>>>>>> distutils.__path__ >>>> ['/home/robin/LOCAL/3.9b1/lib/python3.9/distutils'] >>>>>>> distutils.__file__ >>>> '/home/robin/LOCAL/3.9b1/lib/python3.9/distutils/__init__.py' it seems installing virtualenv 16.2.0 into my python3.9 and then using it to create a venv modifies the base distutils/__init__.py so the problem seems to lie with virtualenv (or at least the older version). -- Robin Becker From souvik.viksou at gmail.com Wed May 20 00:41:09 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Wed, 20 May 2020 10:11:09 +0530 Subject: A python meme... Message-ID: Hi, If you guys see an attachment, then probably this list now supports attachment. And I am the successful founder of it. If you don't see then okay I am wrong and please ignore it. Note:- I already know that the list does not support attachments. This experiment was funded by a glitch... From shivani.shinde at alefedge.com Wed May 20 01:13:25 2020 From: shivani.shinde at alefedge.com (Shivani Shinde) Date: Tue, 19 May 2020 22:13:25 -0700 (PDT) Subject: python3 - Import python file as module In-Reply-To: References: <1dd9e5c2-4805-44e4-bee4-d89b8c92ea9c@googlegroups.com> Message-ID: <611cc273-6d66-4515-9631-9c2acf5d2742@googlegroups.com> Hi Peter, Thank you for your inputs. This really helped me. Thanks! -- CONFIDENTIALITY. This email and any attachments?are?confidential?to Alef Edge Inc., and may also be privileged,?except?where the?email?states it can be disclosed.?If this email?is received in?error, please?do not disclose the contents?to anyone, notify?the sender by return?email, and delete?this email (and any?attachments) from your system. From alan.gauld at yahoo.co.uk Wed May 20 02:58:55 2020 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 20 May 2020 07:58:55 +0100 Subject: Missing python curses functions? In-Reply-To: <20200520004857.GA64494@cskk.homeip.net> References: <20200520004857.GA64494@cskk.homeip.net> Message-ID: On 20/05/2020 01:48, Cameron Simpson wrote: > It may be that the person who wrote the curses module simply got tired. That was my assumption. Although the implementation includes some functions that are a lot more obscure. Usually when one is missing there is an alternative with the same effect, but in this case I can't find any way of finding out the attributes of a piece of text. You can read the text with instr() but it does not include the attributes. I confess I've never needed this functionality and only realized it was missing by working through the HOWO document. But I can see where it might be useful, say to toggle from bold to dim or somesuch. > Or it predates the get_attr calls (not sure now old they are). >From the man page it looks like its been there since SVR3 at least. But in browsing the man pages I came across another function that returns the attributes for a single character - inch(). That is supported in Python. To get the current settings you would need to write a character to the window(addch), fetch its attributes using inch() then delete the character just written (delch). Clunky but it should work. I'll try it and see if I can create an attr_get(win)->int function in Python... -- 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 alan.gauld at yahoo.co.uk Wed May 20 03:31:32 2020 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 20 May 2020 08:31:32 +0100 Subject: Solved: Re: Missing python curses functions? In-Reply-To: References: Message-ID: 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... -- 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 vinodupadhyay900 at gmail.com Wed May 20 13:37:25 2020 From: vinodupadhyay900 at gmail.com (Tushar Upadhyay) Date: Wed, 20 May 2020 23:07:25 +0530 Subject: Fwd: Python not uninstalling In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Tushar Upadhyay Date: Wed, 20 May 2020 at 22:57 Subject: Python not uninstalling To: Sir I had uninstalled my python from control pannel but it shows again and again.I tried multiple times but it does not uninstalling Please help me asap. From roysupriyo10 at gmail.com Wed May 20 10:22:53 2020 From: roysupriyo10 at gmail.com (Supriyo Roy) Date: Wed, 20 May 2020 19:52:53 +0530 Subject: Python not running Message-ID: I have installed the latest version of python which is 3.8.3. However, when I try to run a sample program, a small python icon appears on my taskbar for a split second and then disappears. Nothing else happens. Please advise me on how to get python up and running. Thank you in advance. Regards. -- Supriyo Roy From info at cmcc.it Wed May 20 11:24:34 2020 From: info at cmcc.it (CMCC Info) Date: Wed, 20 May 2020 17:24:34 +0200 Subject: Software Developer for the Digital Ocean Applications | Job position at CMCC Foundation, Italy Message-ID: <35738868-ee0a-a97d-68bf-a892b3953f95@cmcc.it> /Please, feel free to circulate //to anyone you think may be interested./// -- Software Developer for the Digital Ocean Applications (Code: 10822) *Deadline**31/05/2020* The CMCC is taking into consideration the possibility to hire a talented, motivated and proactive Software Developer to support research and development activities. This job announcement is a public invitation to express interest for the above mentioned CMCC Position. The location is CMCC Headquarters in*Lecce, Italy*. The primary purposes for this position is to support the Applications Research Unit of the OPA Division of CMCC , in activities based on both observed and model maritime data. Candidates will be engaged in: * supporting VISIR model (visir-model.net ) developments * porting/recoding/re-engineering/developing new numerical procedures based on heterogeneous maritime data * developing/maintaining and improving operational chains components. The desired qualifications are: * M.Sc. degree in Computer Science, Engineering, Physics, or Mathematics * Good knowledge of scientific programming languages (preferably Python, Matlab, R) * knowledge of version control systems (e.g., git) * Knowledge of UNIX/Linux operating systems * fluency in the English language * knowledge of workflow management platforms * experience in managing/manipulating NetCDF data// Belonging to legally protected categories (ex Italian Law 68/99) will constitute a preferential condition. The initial appointment is for 24 months starting from July 2020 at an annual salary ranging from 22 K to 38K Euros for junior research associates and from 32K to 48K Euros for senior research associates*, comprehensive of benefits*, depending on qualification and experience. *How to Apply* Applicants should register to CMCC JAM (Job Application Manager) website. For further information on CMCC Job Opportunities, please visit our website https://www.cmcc.it/work-with-us. -- Fondazione Centro Euro-Mediterraneo sui Cambiamenti Climatici Web: www.cmcc.it - Contact us: info at cmcc.it From PythonList at DancesWithMice.info Wed May 20 16:10:36 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 21 May 2020 08:10:36 +1200 Subject: Python not running In-Reply-To: References: Message-ID: On 21/05/20 2:22 AM, Supriyo Roy wrote: > I have installed the latest version of python which is 3.8.3. However, when > I try to run a sample program, a small python icon appears on my taskbar > for a split second and then disappears. Nothing else happens. Please advise > me on how to get python up and running. > Thank you in advance. Regards. Please advise if the following reference is accurate, and works for you: https://docs.python.org/3/using/windows.html -- Regards =dn From PythonList at DancesWithMice.info Wed May 20 16:15:10 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 21 May 2020 08:15:10 +1200 Subject: Can't run program In-Reply-To: References: Message-ID: <4bc45684-4a26-c573-eafb-7dd500ed0fd3@DancesWithMice.info> On 21/05/20 7:16 AM, Dennis Lee Bieber wrote: > On Tue, 19 May 2020 20:31:28 -0400, Ryan Harrington > declaimed the following: > >> Hi - I'm not the least bit technical. Trying to learn through YouTube. I've >> gotten exit code 1, 2, 106. Tried setting up the project interpreter and >> can't figure it out. Tried uninstalling and reinstalling everything and >> still having problems. Any feedback appreciated. >> > > Information... We want... Information > > What OS? > > What installer package (and where did you obtain it)? Assuming MS-Windows: Please advise if the following reference is accurate, and works for you: https://docs.python.org/3/using/windows.html -- Regards =dn From torriem at gmail.com Wed May 20 18:08:17 2020 From: torriem at gmail.com (Michael Torrie) Date: Wed, 20 May 2020 16:08:17 -0600 Subject: Python not running In-Reply-To: References: Message-ID: On 2020-05-20 8:22 a.m., Supriyo Roy wrote: > I have installed the latest version of python which is 3.8.3. However, when > I try to run a sample program, a small python icon appears on my taskbar > for a split second and then disappears. Nothing else happens. Please advise > me on how to get python up and running. > Thank you in advance. Regards. Always state your operating system! Python is simply an interpreter, not a graphical application, and is normally run from the command prompt. Your program is in fact running, but after it finishes, the window goes away, as it does for all console programs. If you run it from a command prompt you will see the complete output from your program. Please read the link that DL Neil helpfully provided to get you up and running on Windows. From larry.martell at gmail.com Wed May 20 18:24:40 2020 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 20 May 2020 18:24:40 -0400 Subject: Display, EasyProcess Message-ID: I have some code that uses the pyvirtualdisplay package and it works fine. pyvirtualdisplay,Display calls EasyProcess like this: @classmethod def check_installed(cls): EasyProcess([PROGRAM, '-help'], url=URL, ubuntu_package=PACKAGE).check_installed() I made a branch and made some changes. In the branch, when I instantiate Display and it gets to this point it fails with: TypeError: __init__() got an unexpected keyword argument 'url' There are no changes in my branch related to using Display. What's very odd is that the __init__() function for EasyProcess has this signature, and the call to it from Display is the same in my master branch and it works: def __init__( self, cmd, cwd=None, use_temp_files=True, env=None, ): So that url param must be getting passed to something else. I did some googling and found a post on SO where someone was having the same issue, and the answer was that they overrode the EasyProcess __init__ with their own init. If I am doing that I have no clue how that could be. I did inspect EasyProcess just before the call and it was the correct code. Here is the end of the stack trace: -> display = Display(visible=0, size=(800, 600)) > /usr/local/lib/python3.7/site-packages/pyvirtualdisplay/display.py(33)__init__() -> self._obj = self.display_class( /usr/local/lib/python3.7/site-packages/pyvirtualdisplay/display.py(51)display_class() -> cls.check_installed() /usr/local/lib/python3.7/site-packages/pyvirtualdisplay/xvfb.py(38)check_installed() -> ubuntu_package=PACKAGE).check_installed() Anyone have any thoughts on what could be causing this or how I can debug it further? From __peter__ at web.de Thu May 21 03:43:23 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 21 May 2020 09:43:23 +0200 Subject: Display, EasyProcess References: Message-ID: Larry Martell wrote: > I have some code that uses the pyvirtualdisplay package and it works fine. > > pyvirtualdisplay,Display calls EasyProcess like this: > > @classmethod > def check_installed(cls): > EasyProcess([PROGRAM, '-help'], url=URL, > ubuntu_package=PACKAGE).check_installed() > > I made a branch and made some changes. In the branch, when I > instantiate Display and it gets to this point it fails with: > > TypeError: __init__() got an unexpected keyword argument 'url' I took a look at the source, and the code causing the error was removed back in december: https://github.com/ponty/PyVirtualDisplay/commit/37613e36cf311bf855ac0af7850ffc85ac0635c6#diff-cdb8c67ac0a9554cd28f4f4bfc06fcf4 I suggest that you update your version of the pyvirtualdisplay package. From bernard+work at ei8fdb.org Thu May 21 04:55:16 2020 From: bernard+work at ei8fdb.org (Bernard Tyers - Sane UX Design) Date: Thu, 21 May 2020 09:55:16 +0100 Subject: pip UX studies: Test pip's new resolver and help us document dependency conflicts Message-ID: <30d0ea73-8c93-7331-0f38-f2b8958d8ce5@ei8fdb.org> Hi there, It's Bernard and Nicole from the pip Team. The team is working on the improving the way that pip resolves package dependency conflicts. We're asking for your help to test pip's new resolver. We're especially interested in hearing from people who have projects with complex dependencies. By complex dependencies we mean projects that look like this: - have at least 10 package dependencies - some package are pinned to specific versions - that you always have a dependency issue when installing it - you have to put in hacks, workarounds, or fixes Currently, we?re trying to discover all the ways in which pip?s dependency resolver fails, so that we can work out what error messages and/or debugging information we should display. You can find out what we'd like you to do on this blog post: http://www.ei8fdb.org/thoughts/2020/05/test-pips-alpha-resolver-and-help-us-document-dependency-conflicts/ If you're into social media, we'd appreciate if you'd boost these messages too: https://twitter.com/nlhkabu/status/1263132447971172352 https://social.ei8fdb.org/@bernard/104205537250874117 You can sign-up for other UX Studies also: http://www.ei8fdb.org/thoughts/2020/03/pip-ux-study-recruitment/ If you've got any questions, reply here off or on-list. Thanks, Bernard & Nicole pip Team UX -- Bernard Tyers, User research & Interaction Design Sane UX Design Twitter: @bernardtyers PGP Key: keybase.io/ei8fdb I am currently working with the Python Software Foundation, and Open Technology Fund From ansari.aafaq1994 at gmail.com Thu May 21 05:56:38 2020 From: ansari.aafaq1994 at gmail.com (ansari.aafaq1994 at gmail.com) Date: Thu, 21 May 2020 02:56:38 -0700 (PDT) Subject: Getting value of a variable without changing the expression in Python Message-ID: <67d93015-5cc5-4e8f-b970-57b69be263bf@googlegroups.com> Lets say i have a expression: flowrate=(veloctiy*area) i can find the flowrate with this expression but if i dont wanna change the expression and want to find the velocity by giving it value of area and flowrate ,how do i do this in python? is there any library or package or module for this? From Richard at Damon-Family.org Thu May 21 07:31:06 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 21 May 2020 07:31:06 -0400 Subject: Getting value of a variable without changing the expression in Python In-Reply-To: <67d93015-5cc5-4e8f-b970-57b69be263bf@googlegroups.com> References: <67d93015-5cc5-4e8f-b970-57b69be263bf@googlegroups.com> Message-ID: <95f60474-e676-5d17-a295-5b755416e520@Damon-Family.org> On 5/21/20 5:56 AM, ansari.aafaq1994 at gmail.com wrote: > Lets say i have a expression: > flowrate=(veloctiy*area) > i can find the flowrate with this expression > but if i dont wanna change the expression and want to find the velocity by giving it value of area and flowrate ,how do i do this in python? > is there any library or package or module for this? Python, like most computer languages doesn't directly support that sort of operation, one key point here is that in that context = means assign, or change to, and implies that the name on the left takes on the value to the right. There may be a library somewhere that allows you to pass "flowrate=veloctiy*area" (note, changed to a string) and the values for flowrate and area and it solves for veloctiy. Or a library where you do something like def flowrate_fun(veloctiy): ??? return veloctiy*area ?veloctiy = solve(flowrate_fun, flowrate) i.e. you pass a function and it finds what input make the function have a give value. -- Richard Damon From __peter__ at web.de Thu May 21 08:57:11 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 21 May 2020 14:57:11 +0200 Subject: Getting value of a variable without changing the expression in Python References: <67d93015-5cc5-4e8f-b970-57b69be263bf@googlegroups.com> Message-ID: ansari.aafaq1994 at gmail.com wrote: > Lets say i have a expression: > flowrate=(veloctiy*area) > i can find the flowrate with this expression > but if i dont wanna change the expression and want to find the velocity by > giving it value of area and flowrate ,how do i do this in python? is there > any library or package or module for this? With sympy ttps://docs.sympy.org/latest/tutorial/intro.html you can write: >>> import sympy >>> f, v, a = sympy.symbols("flowrate velocity area") >>> sympy.solve(v*a - f, a) [flowrate/velocity] >>> sympy.solve(v*a - f, f) [area*velocity] From chasea3rd at gmail.com Wed May 20 15:28:25 2020 From: chasea3rd at gmail.com (Charles Seagraves) Date: Wed, 20 May 2020 14:28:25 -0500 Subject: Installation Error Message-ID: Hi, I have been learning and using Python to create a program to play Mah Jongg and it was going well until my windows 10 computer started receiving an update. My computer restarted and Python was gone. I have attempted to reinstall with a message that the install was successful. When I started to use it I got the following message. pythonw.exe - System Error The code execution cannot proceed because python38.dll was not found. Reinstalling the program may fix this problem. I have reinstalled python several times. Repaired it several times but continue to get the same error. I uninstalled the bad Windows update but still had the same problem trying to get python running. Please help, Charlie Seagraves From larry.martell at gmail.com Thu May 21 17:17:00 2020 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 21 May 2020 17:17:00 -0400 Subject: Display, EasyProcess In-Reply-To: References: Message-ID: On Thu, May 21, 2020 at 3:44 AM Peter Otten <__peter__ at web.de> wrote: > > Larry Martell wrote: > > > I have some code that uses the pyvirtualdisplay package and it works fine. > > > > pyvirtualdisplay,Display calls EasyProcess like this: > > > > @classmethod > > def check_installed(cls): > > EasyProcess([PROGRAM, '-help'], url=URL, > > ubuntu_package=PACKAGE).check_installed() > > > > I made a branch and made some changes. In the branch, when I > > instantiate Display and it gets to this point it fails with: > > > > TypeError: __init__() got an unexpected keyword argument 'url' > > I took a look at the source, and the code causing the error was removed back > in december: > > https://github.com/ponty/PyVirtualDisplay/commit/37613e36cf311bf855ac0af7850ffc85ac0635c6#diff-cdb8c67ac0a9554cd28f4f4bfc06fcf4 > > I suggest that you update your version of the pyvirtualdisplay package. Thanks. That did the trick! From miked at dewhirst.com.au Thu May 21 19:08:01 2020 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Fri, 22 May 2020 09:08:01 +1000 Subject: Installation Error In-Reply-To: References: Message-ID: <4404d903-161a-39bf-5b37-83044846bab8@dewhirst.com.au> On 21/05/2020 5:28 am, Charles Seagraves wrote: > Hi, > I have been learning and using Python to create a program to play Mah Jongg > and it was going well until my windows 10 computer started receiving an > update. My computer restarted and Python was gone. I have attempted to > reinstall with a message that the install was successful. When I started to > use it I got the following message. > > pythonw.exe - System Error > The code execution cannot proceed because python38.dll was not found. > Reinstalling the program may fix this problem. > > I have reinstalled python several times. Repaired it several times but > continue to get the same error. > I uninstalled the bad Windows update but still had the same problem trying > to get python running. That sounds horrible. Have you tried installing Python 3.7 or 3.9? 32bit? 64bit? Also, I would try doing a custom install to a better location than the Windows standard place. My favourite is C:\Python36, C:\Python37, C:\Python38 etc. All the best Mike > > Please help, > Charlie Seagraves From souvik.viksou at gmail.com Thu May 21 20:18:51 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Fri, 22 May 2020 05:48:51 +0530 Subject: Installation Error In-Reply-To: References: Message-ID: Do you have DirectX latest version? It should have solved the problem. If not already installed then you might try to install it. On Thu, 21 May, 2020, 10:29 pm Charles Seagraves, wrote: > Hi, > I have been learning and using Python to create a program to play Mah Jongg > and it was going well until my windows 10 computer started receiving an > update. My computer restarted and Python was gone. I have attempted to > reinstall with a message that the install was successful. When I started to > use it I got the following message. > > pythonw.exe - System Error > The code execution cannot proceed because python38.dll was not found. > Reinstalling the program may fix this problem. > > I have reinstalled python several times. Repaired it several times but > continue to get the same error. > I uninstalled the bad Windows update but still had the same problem trying > to get python running. > > Please help, > Charlie Seagraves > -- > https://mail.python.org/mailman/listinfo/python-list > From zljubisic at gmail.com Thu May 21 21:41:49 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Thu, 21 May 2020 18:41:49 -0700 (PDT) Subject: PyCharm, how to setup self contained subprojects Message-ID: <134dc2c8-6f29-453a-842a-543fee10b121@googlegroups.com> Hi, I should provide python code for (Spring) microservice patform. In microservice paradigm, each microservice should do a simple task, so python code beneath it should be very small. As a PyCharm (community) user, I don't know how to set up such development environment. Each microservice could be a separate PyCharm project, but these projects should share some common classes. For example, let's say that you have a class for communication with outer world. Each PyCharm project (microservice) should use instance of this class, and do the different things with its data. I would like to avoid coping this common object to each PyCharm project (and prevent refactoring). Another, requirement is deployment of PyCharm project to the microservice platform. At the moment, my each microservice code is in separate project. I am coping each project files on separate folder on deployment server. So, each PyCharm project has its own main.py (the name of main.py can be different for each microservice). On deployment servers I cannot install anything. Another approach would be to have single PyCharm project with many root directories for microservices and multiple main.py files. In this case, when I deploy a single microservice, I will have trouble finding out what files I should copy (common classes), or to copy everything from PyCharm project, but specify main.py for specific microservice (root). If anyone is in the same situation, please share how you have set up PyCharm for such purpose, and how you are doing development. Regards From ciaran.hudson at gmail.com Thu May 21 17:04:58 2020 From: ciaran.hudson at gmail.com (=?UTF-8?Q?Ciar=C3=A1n_Hudson?=) Date: Thu, 21 May 2020 14:04:58 -0700 (PDT) Subject: creating a csv from information I have printed to screen Message-ID: How do I edit the code below to create a csv file which includes the information I have printed at the bottom? I'm pulling arrival data from an airport website and printing out only the flight info. I want to save that flight info to a CSV file. import requests from bs4 import BeautifulSoup cookies = { 'ApplicationGatewayAffinity': '1d2ad8ab214d1293a4e31bcd161589fa82a54a39bb7b3be80b503996092d4296', 'ApplicationGatewayAffinityCORS': '1d2ad8ab214d1293a4e31bcd161589fa82a54a39bb7b3be80b503996092d4296', } headers = { 'Connection': 'keep-alive', 'Cache-Control': 'max-age=0', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Sec-Fetch-Site': 'cross-site', 'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-User': '?1', 'Sec-Fetch-Dest': 'document', 'Referer': 'https://www.google.com/', 'Accept-Language': 'en-GB,en;q=0.9,en-US;q=0.8,fr;q=0.7,nl;q=0.6', } response = requests.get('https://www.corkairport.com/arrivals-departures', headers=headers, cookies=cookies) #print(response.content) soup = BeautifulSoup(response.content, 'html.parser') #print(soup.prettify()) ## commented out as it did not print as expected # headers = soup.find_all('th') # for header in headers: # for content in header.contents: # value = str(header).strip().replace('\n', '') # if len(value) == 0: # print('"0"', end=',') # elif value[0].lower() in 'abcdefghijklmnopqrstuvwxyz<': # print('\n' + value, end=',') # else: # print('"' + value + '"', end=',') print('Arriving From', 'Airline', 'Scheduled to arrive','Latest Update','Status') cells = soup.find_all('td') #print(cells) for cell in cells: for content in cell.contents: value = str(content).strip().replace('\n', '') if len(value) == 0: print('"0"', end=',') elif value[0].lower() in 'abcdefghijklmnopqrstuvwxyz<': print('\n' + value, end=',') else: print('"' + value + '"', end=',') From __peter__ at web.de Fri May 22 03:26:25 2020 From: __peter__ at web.de (Peter Otten) Date: Fri, 22 May 2020 09:26:25 +0200 Subject: creating a csv from information I have printed to screen References: Message-ID: Ciar?n Hudson wrote: > How do I edit the code below to create a csv file which includes the > information I have printed at the bottom? > > I'm pulling arrival data from an airport website and printing out only the > flight info. I want to save that flight info to a CSV file. First of all the data in the html is already structured as a table. You really want to keep that structure instead of reconstructing it from the individual cells: for row in table: write cells in row Then you have to decide on the columns > print('Arriving From', 'Airline', 'Scheduled to arrive','Latest > Update','Status') and I guess they are what you print above. Once you have the data creating the csv is easy, Python includes a module for it. So: import csv, sys [...] writer = csv.writer(sys.stdout) writer.writerow([ 'Arriving From', 'Airline', 'Scheduled to arrive', 'Latest Update', 'Status' ]) [table] = soup.find_all("table") for row in table.find_all("tr"): writer.writerow( [td.string.strip() for td in row.find_all("td")] ) To write to a file instead of stdout pass the writer a file with open("flight.csv", "w") as f: writer = csv.writer(f) ... > cells = soup.find_all('td') > #print(cells) > > for cell in cells: > for content in cell.contents: > value = str(content).strip().replace('\n', '') > if len(value) == 0: > print('"0"', end=',') > elif value[0].lower() in 'abcdefghijklmnopqrstuvwxyz<': > print('\n' + value, end=',') > else: > print('"' + value + '"', end=',') From checksum at virginmedia.com Fri May 22 07:49:35 2020 From: checksum at virginmedia.com (John Yeadon) Date: Fri, 22 May 2020 12:49:35 +0100 Subject: exiting a while loop Message-ID: Am I unreasonable in expecting this code to exit when required? # Add up the powers of 2 starting with 2**0 until 2 million is met. n = 1 target = 2000000 sum = 0 while True: x = 2 ** (n - 1) sum += x print(n, sum) if sum >= target: print("Target met.") exit n += 1 print("\n", n, "terms are required.") From larry.martell at gmail.com Fri May 22 07:55:00 2020 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 22 May 2020 07:55:00 -0400 Subject: exiting a while loop In-Reply-To: References: Message-ID: On Fri, May 22, 2020 at 7:51 AM John Yeadon via Python-list wrote: > > Am I unreasonable in expecting this code to exit when required? > > > # Add up the powers of 2 starting with 2**0 until 2 million is met. > n = 1 > target = 2000000 > sum = 0 > > while True: > x = 2 ** (n - 1) > sum += x > print(n, sum) > if sum >= target: > print("Target met.") > exit > n += 1 > > print("\n", n, "terms are required.") exit() From souvik.viksou at gmail.com Fri May 22 07:56:57 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Fri, 22 May 2020 17:26:57 +0530 Subject: exiting a while loop In-Reply-To: References: Message-ID: No not really. If you use a breakpoint and a debugger you will find out that your code continues till 2 M is met and then stops printing numbers continuously. On Fri, 22 May, 2020, 5:20 pm John Yeadon via Python-list, < python-list at python.org> wrote: > Am I unreasonable in expecting this code to exit when required? > > > # Add up the powers of 2 starting with 2**0 until 2 million is met. > n = 1 > target = 2000000 > sum = 0 > > while True: > x = 2 ** (n - 1) > sum += x > print(n, sum) > if sum >= target: > print("Target met.") > exit > n += 1 > > print("\n", n, "terms are required.") > > -- > https://mail.python.org/mailman/listinfo/python-list > From 2QdxY4RzWzUUiLuE at potatochowder.com Fri May 22 07:57:36 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Fri, 22 May 2020 07:57:36 -0400 Subject: exiting a while loop In-Reply-To: References: Message-ID: <87pnawqj0v.fsf@unique.fqdn> On Friday, May 22, 2020, at 7:49, John Yeadon via Python-list wrote: > Am I unreasonable in expecting this code to exit when required? Yes. :-) > # Add up the powers of 2 starting with 2**0 until 2 million is met. > n = 1 > target = 2000000 > sum = 0 > > while True: > x = 2 ** (n - 1) > sum += x > print(n, sum) > if sum >= target: > print("Target met.") > exit Try break instead of exit. See https://docs.python.org/3/reference/compound_stmts.html#the-for-statement for more information. > n += 1 > > print("\n", n, "terms are required.") -- ?Atoms are not things.? ? Werner Heisenberg Dan Sommers, http://www.tombstonezero.net/dan From __peter__ at web.de Fri May 22 07:58:06 2020 From: __peter__ at web.de (Peter Otten) Date: Fri, 22 May 2020 13:58:06 +0200 Subject: exiting a while loop References: Message-ID: John Yeadon via Python-list wrote: > Am I unreasonable in expecting this code to exit when required? It is unreasonable to expect something that doesn't match what you read in the tutorial ;) If you want to terminate the script you can use exit. However exit is a function, and you have to call it exit() to actually do anything. If you want to terminate just the loop, which is more likely because there is a print() following it, you can do this with break (which is a statement, so no trailing ()): > # Add up the powers of 2 starting with 2**0 until 2 million is met. > n = 1 > target = 2000000 > sum = 0 > > while True: > x = 2 ** (n - 1) > sum += x > print(n, sum) > if sum >= target: > print("Target met.") break > n += 1 > > print("\n", n, "terms are required.") From buddy.peacock at gmail.com Fri May 22 08:00:00 2020 From: buddy.peacock at gmail.com (Buddy Peacock) Date: Fri, 22 May 2020 08:00:00 -0400 Subject: creating a table within python code Message-ID: I'm working on my first python project in CS50W and I am trying to create 2 tables. I am getting the following error when trying to run it: I have included my code below the error message. flask.cli.NoAppException: Failed to find Flask application or factory in module "create_db". Use "FLASK_APP=create_db:name to specify one. Traceback (most recent call last) File "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", line 39, in reraise raise value File "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", line 97, in find_best_app raise NoAppException( flask.cli.NoAppException: Failed to find Flask application or factory in module "create_db". Use "FLASK_APP=create_db:name to specify one. I used: FLASK_APP=create_db.py at the command line and this is my code: import os from flask import Flask, session from flask_session import Session from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker engine = create_engine(os.getenv("DATABASE_URL")) db = scoped_session(sessionmaker(bind=engine)) def main(): db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY, isbn VARCHAR NOT NULL, title VARCHAR NOT NULL, author INTEGER NOT NULL, year INTEGER NOT NULL,)") db.execute("CREATE TABLE authors (id SERIAL PRIMARY KEY, name VARCHAR NOT NULL,)") db.commit() if __name__ == "__main__": main() Does anyone have any ideas? Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC (920) 740-3411 linkedin.com/in/buddypeacock From darcy at VybeNetworks.com Fri May 22 08:02:22 2020 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Fri, 22 May 2020 08:02:22 -0400 Subject: exiting a while loop In-Reply-To: References: Message-ID: <35320fa4-e091-86ba-18ea-4c40bb404dc5@VybeNetworks.com> On 2020-05-22 7:49 a.m., John Yeadon via Python-list wrote: > Am I unreasonable in expecting this code to exit when required? Yes. > # Add up the powers of 2 starting with 2**0 until 2 million is met. > n = 1 > target = 2000000 > sum = 0 > > while True: > ??? x = 2 ** (n - 1) > ??? sum += x > ??? print(n, sum) > ??? if sum >= target: > ??????? print("Target met.") > ??????? exit > ??? n += 1 > > print("\n", n, "terms are required.") I think that you meant "break", not "exit". -- D'Arcy J.M. Cain Vybe Networks Inc. A unit of Excelsior Solutions Corporation - Propelling Business Forward http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From __peter__ at web.de Fri May 22 08:19:05 2020 From: __peter__ at web.de (Peter Otten) Date: Fri, 22 May 2020 14:19:05 +0200 Subject: creating a csv from information I have printed to screen References: Message-ID: Ciar?n Hudson wrote: > This has helped a lot; cleaner output, keeping tbl format and creating a > csv but the csv is not being populated. Any idea what I am doing wrong? > writer = csv.writer(sys.stdout) > writer.writerow([ > 'Arriving From' > 'Airline', > 'Scheduled to arrive', 'Latest Update', 'Status' > ]) > > #cells = soup.find_all('td') > #print(cells) > > [table] = soup.find_all("table") > for row in table.find_all("tr"): > writer.writerow( > [td.string.strip() for td in row.find_all("td")] > ) > > > # for cell in cells: > > # for content in cell.contents: > # value = str(content).strip().replace('\n', '') > # if len(value) == 0: > # print('"0"', end=',') > # elif value[0].lower() in 'abcdefghijklmnopqrstuvwxyz<': > # print('\n' + value, end=',') > # else: > # print('"' + value + '"', end=',') > > > > > with open('flight.csv','w') as f: > writer = csv.writer(f) Well you open the file and create a writer but you don't write anything. You need this part [table] = soup.find_all("table") for row in table.find_all("tr"): writer.writerow( [td.string.strip() for td in row.find_all("td")] ) inside the with-suite, too. If you are interested in learning Python, you may put it into a function and invoke it twice, with the writer writing to stdout and the writer writing to the file. From souvik.viksou at gmail.com Fri May 22 09:42:31 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Fri, 22 May 2020 19:12:31 +0530 Subject: creating a table within python code In-Reply-To: References: Message-ID: There will be quotes when doing FLASK_APP="" I think that should solve the problem. On Fri, 22 May, 2020, 5:35 pm Buddy Peacock, wrote: > I'm working on my first python project in CS50W and I am trying to create > 2 tables. > I am getting the following error when trying to run it: I have included my > code below the error message. > > flask.cli.NoAppException: Failed to find Flask application or factory in > module "create_db". Use "FLASK_APP=create_db:name to specify one. > Traceback (most recent call last) > File > > "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", > line 39, in reraise > raise value > File > > "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", > line 97, in find_best_app > raise NoAppException( > flask.cli.NoAppException: Failed to find Flask application or factory in > module "create_db". Use "FLASK_APP=create_db:name to specify one. > > I used: > FLASK_APP=create_db.py at the command line > > and this is my code: > > import os > from flask import Flask, session > from flask_session import Session > from sqlalchemy import create_engine > from sqlalchemy.orm import scoped_session, sessionmaker > engine = create_engine(os.getenv("DATABASE_URL")) > db = scoped_session(sessionmaker(bind=engine)) > def main(): > db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY, isbn VARCHAR NOT > NULL, title VARCHAR NOT NULL, author INTEGER NOT NULL, year INTEGER NOT > NULL,)") > db.execute("CREATE TABLE authors (id SERIAL PRIMARY KEY, name VARCHAR > NOT NULL,)") > db.commit() > if __name__ == "__main__": > main() > > Does anyone have any ideas? > > Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC > (920) 740-3411 > linkedin.com/in/buddypeacock > -- > https://mail.python.org/mailman/listinfo/python-list > From python at python.invalid Fri May 22 01:00:13 2020 From: python at python.invalid (Python) Date: Fri, 22 May 2020 07:00:13 +0200 Subject: PyCharm, how to setup self contained subprojects In-Reply-To: <134dc2c8-6f29-453a-842a-543fee10b121@googlegroups.com> References: <134dc2c8-6f29-453a-842a-543fee10b121@googlegroups.com> Message-ID: <5ec75c23$0$5863$426a74cc@news.free.fr> Le 22/05/2020 ? 03:41, zljubisic at gmail.com a ?crit?: > Hi, > > I should provide python code for (Spring) microservice patform. > In microservice paradigm, each microservice should do a simple task, so python code beneath it should be very small. > > As a PyCharm (community) user, I don't know how to set up such development environment. > > Each microservice could be a separate PyCharm project, but these projects should share some common classes. For example, let's say that you have a class for communication with outer world. > Each PyCharm project (microservice) should use instance of this class, and do the different things with its data. > > I would like to avoid coping this common object to each PyCharm project (and prevent refactoring). > > Another, requirement is deployment of PyCharm project to the microservice platform. > At the moment, my each microservice code is in separate project. > I am coping each project files on separate folder on deployment server. > So, each PyCharm project has its own main.py (the name of main.py can be different for each microservice). > > On deployment servers I cannot install anything. > > Another approach would be to have single PyCharm project with many root directories for microservices and multiple main.py files. > > In this case, when I deploy a single microservice, I will have trouble finding out what files I should copy (common classes), or to copy everything from PyCharm project, but specify main.py for specific microservice (root). > > If anyone is in the same situation, please share how you have set up PyCharm for such purpose, and how you are doing development. > > Regards You shouldn't rely any software project on any IDE feature. You're taking the problem from the wrong end. You'd better have a look on the way cvs systems such as git can hangle it. As a matter of fact, imo, any software project based on a given IDE is doomed ot failed. From ciaran.hudson at gmail.com Fri May 22 07:07:40 2020 From: ciaran.hudson at gmail.com (=?UTF-8?Q?Ciar=C3=A1n_Hudson?=) Date: Fri, 22 May 2020 04:07:40 -0700 (PDT) Subject: creating a csv from information I have printed to screen In-Reply-To: References: Message-ID: This has helped a lot; cleaner output, keeping tbl format and creating a csv but the csv is not being populated. Any idea what I am doing wrong? import requests import csv, sys from bs4 import BeautifulSoup cookies = { 'ApplicationGatewayAffinity': '1d2ad8ab214d1293a4e31bcd161589fa82a54a39bb7b3be80b503996092d4296', 'ApplicationGatewayAffinityCORS': '1d2ad8ab214d1293a4e31bcd161589fa82a54a39bb7b3be80b503996092d4296', } headers = { 'Connection': 'keep-alive', 'Cache-Control': 'max-age=0', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Sec-Fetch-Site': 'cross-site', 'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-User': '?1', 'Sec-Fetch-Dest': 'document', 'Referer': 'https://www.google.com/', 'Accept-Language': 'en-GB,en;q=0.9,en-US;q=0.8,fr;q=0.7,nl;q=0.6', } response = requests.get('https://www.corkairport.com/arrivals-departures', headers=headers, cookies=cookies) #print(response.content) soup = BeautifulSoup(response.content, 'html.parser') #print(soup.prettify()) ## commented out as it did not print as expected # headers = soup.find_all('th') # for header in headers: # for content in header.contents: # value = str(header).strip().replace('\n', '') # if len(value) == 0: # print('"0"', end=',') # elif value[0].lower() in 'abcdefghijklmnopqrstuvwxyz<': # print('\n' + value, end=',') # else: # print('"' + value + '"', end=',') #print('Arriving From', 'Airline', 'Scheduled to arrive','Latest Update','Status') writer = csv.writer(sys.stdout) writer.writerow([ 'Arriving From' 'Airline', 'Scheduled to arrive', 'Latest Update', 'Status' ]) #cells = soup.find_all('td') #print(cells) [table] = soup.find_all("table") for row in table.find_all("tr"): writer.writerow( [td.string.strip() for td in row.find_all("td")] ) # for cell in cells: # for content in cell.contents: # value = str(content).strip().replace('\n', '') # if len(value) == 0: # print('"0"', end=',') # elif value[0].lower() in 'abcdefghijklmnopqrstuvwxyz<': # print('\n' + value, end=',') # else: # print('"' + value + '"', end=',') with open('flight.csv','w') as f: writer = csv.writer(f) From buddy.peacock at gmail.com Fri May 22 10:22:40 2020 From: buddy.peacock at gmail.com (Buddy Peacock) Date: Fri, 22 May 2020 10:22:40 -0400 Subject: creating a table within python code In-Reply-To: References: Message-ID: Thank you Souvik, but still having issues. I have pasted the command line interaction this time. My prior message is what appeared in the browser. ================================================================================================================ c:\Harvard\project1>SET FLASK_APP="create_db.py" c:\Harvard\project1>set DATABASE_URL=postgres:// guaqyugfujbudc:79ae65a6d8966991694906e4b96f20ebcfde5b80fb334e99d79d9300dd6ef95f at ec2-34-200-72-77.compute-1.amazonaws.com:5432/dep18tfh5g2eme c:\Harvard\project1>flask run * Serving Flask app ""create_db.py"" (lazy loading) * Environment: development * Debug mode: on * Restarting with stat * Debugger is active! * Debugger PIN: 124-607-194 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) 127.0.0.1 - - [22/May/2020 10:16:46] " [35m [1mGET / HTTP/1.1 [0m" 500 - Traceback (most recent call last): File "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", line 240, in locate_app __import__(module_name) ModuleNotFoundError: No module named '"create_db' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", line 338, in __call__ self._flush_bg_loading_exception() File "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", line 326, in _flush_bg_loading_exception reraise(*exc_info) File "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", line 39, in reraise raise value File "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", line 314, in _load_app self._load_unlocked() File "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", line 330, in _load_unlocked self._app = rv = self.loader() File "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", line 388, in load_app app = locate_app(self, import_name, name) File "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", line 250, in locate_app raise NoAppException('Could not import "{name}".'.format(name=module_name)) flask.cli.NoAppException: Could not import ""create_db.py"". 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET /?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1 [0m" 200 - 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET /?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1 [0m" 200 - 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET /?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1 [0m" 200 - 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 - 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET /?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1 [0m" 200 - 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 - Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC (920) 740-3411 linkedin.com/in/buddypeacock On Fri, May 22, 2020 at 9:42 AM Souvik Dutta wrote: > There will be quotes when doing FLASK_APP="" I think that > should solve the problem. > > On Fri, 22 May, 2020, 5:35 pm Buddy Peacock, > wrote: > >> I'm working on my first python project in CS50W and I am trying to create >> 2 tables. >> I am getting the following error when trying to run it: I have included >> my >> code below the error message. >> >> flask.cli.NoAppException: Failed to find Flask application or factory in >> module "create_db". Use "FLASK_APP=create_db:name to specify one. >> Traceback (most recent call last) >> File >> >> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", >> line 39, in reraise >> raise value >> File >> >> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >> line 97, in find_best_app >> raise NoAppException( >> flask.cli.NoAppException: Failed to find Flask application or factory in >> module "create_db". Use "FLASK_APP=create_db:name to specify one. >> >> I used: >> FLASK_APP=create_db.py at the command line >> >> and this is my code: >> >> import os >> from flask import Flask, session >> from flask_session import Session >> from sqlalchemy import create_engine >> from sqlalchemy.orm import scoped_session, sessionmaker >> engine = create_engine(os.getenv("DATABASE_URL")) >> db = scoped_session(sessionmaker(bind=engine)) >> def main(): >> db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY, isbn VARCHAR >> NOT >> NULL, title VARCHAR NOT NULL, author INTEGER NOT NULL, year INTEGER NOT >> NULL,)") >> db.execute("CREATE TABLE authors (id SERIAL PRIMARY KEY, name VARCHAR >> NOT NULL,)") >> db.commit() >> if __name__ == "__main__": >> main() >> >> Does anyone have any ideas? >> >> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >> (920) 740-3411 >> linkedin.com/in/buddypeacock >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From souvik.viksou at gmail.com Fri May 22 11:01:22 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Fri, 22 May 2020 20:31:22 +0530 Subject: creating a table within python code In-Reply-To: References: Message-ID: You might have to add @app.route("/") before the main method. On Fri, 22 May, 2020, 7:53 pm Buddy Peacock, wrote: > Thank you Souvik, but still having issues. I have pasted the command line > interaction this time. My prior message is what appeared in the browser. > > ================================================================================================================ > c:\Harvard\project1>SET FLASK_APP="create_db.py" > > c:\Harvard\project1>set DATABASE_URL=postgres:// > guaqyugfujbudc:79ae65a6d8966991694906e4b96f20ebcfde5b80fb334e99d79d9300dd6ef95f at ec2-34-200-72-77.compute-1.amazonaws.com:5432/dep18tfh5g2eme > > c:\Harvard\project1>flask run > * Serving Flask app ""create_db.py"" (lazy loading) > * Environment: development > * Debug mode: on > * Restarting with stat > * Debugger is active! > * Debugger PIN: 124-607-194 > * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) > 127.0.0.1 - - [22/May/2020 10:16:46] " [35m [1mGET / HTTP/1.1 [0m" 500 - > Traceback (most recent call last): > File > "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", > line 240, in locate_app > __import__(module_name) > ModuleNotFoundError: No module named '"create_db' > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File > "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", > line 338, in __call__ > self._flush_bg_loading_exception() > File > "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", > line 326, in _flush_bg_loading_exception > reraise(*exc_info) > File > "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", > line 39, in reraise > raise value > File > "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", > line 314, in _load_app > self._load_unlocked() > File > "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", > line 330, in _load_unlocked > self._app = rv = self.loader() > File > "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", > line 388, in load_app > app = locate_app(self, import_name, name) > File > "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", > line 250, in locate_app > raise NoAppException('Could not import > "{name}".'.format(name=module_name)) > flask.cli.NoAppException: Could not import ""create_db.py"". > 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET > /?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1 [0m" 200 - > 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET > /?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1 [0m" 200 - > 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET > /?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1 [0m" 200 - > 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET > /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 - > 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET > /?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1 [0m" 200 - > 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET > /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 - > > Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC > (920) 740-3411 > linkedin.com/in/buddypeacock > > > > > On Fri, May 22, 2020 at 9:42 AM Souvik Dutta > wrote: > >> There will be quotes when doing FLASK_APP="" I think that >> should solve the problem. >> >> On Fri, 22 May, 2020, 5:35 pm Buddy Peacock, >> wrote: >> >>> I'm working on my first python project in CS50W and I am trying to >>> create >>> 2 tables. >>> I am getting the following error when trying to run it: I have included >>> my >>> code below the error message. >>> >>> flask.cli.NoAppException: Failed to find Flask application or factory in >>> module "create_db". Use "FLASK_APP=create_db:name to specify one. >>> Traceback (most recent call last) >>> File >>> >>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", >>> line 39, in reraise >>> raise value >>> File >>> >>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >>> line 97, in find_best_app >>> raise NoAppException( >>> flask.cli.NoAppException: Failed to find Flask application or factory in >>> module "create_db". Use "FLASK_APP=create_db:name to specify one. >>> >>> I used: >>> FLASK_APP=create_db.py at the command line >>> >>> and this is my code: >>> >>> import os >>> from flask import Flask, session >>> from flask_session import Session >>> from sqlalchemy import create_engine >>> from sqlalchemy.orm import scoped_session, sessionmaker >>> engine = create_engine(os.getenv("DATABASE_URL")) >>> db = scoped_session(sessionmaker(bind=engine)) >>> def main(): >>> db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY, isbn VARCHAR >>> NOT >>> NULL, title VARCHAR NOT NULL, author INTEGER NOT NULL, year INTEGER NOT >>> NULL,)") >>> db.execute("CREATE TABLE authors (id SERIAL PRIMARY KEY, name VARCHAR >>> NOT NULL,)") >>> db.commit() >>> if __name__ == "__main__": >>> main() >>> >>> Does anyone have any ideas? >>> >>> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >>> (920) 740-3411 >>> linkedin.com/in/buddypeacock >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> From souvik.viksou at gmail.com Fri May 22 11:03:53 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Fri, 22 May 2020 20:33:53 +0530 Subject: creating a table within python code In-Reply-To: References: Message-ID: And also you might have to add after the import statements app= Flask(__name__) and app.run() inside the main function On Fri, 22 May, 2020, 8:31 pm Souvik Dutta, wrote: > You might have to add @app.route("/") before the main method. > > On Fri, 22 May, 2020, 7:53 pm Buddy Peacock, > wrote: > >> Thank you Souvik, but still having issues. I have pasted the command >> line interaction this time. My prior message is what appeared in the >> browser. >> >> ================================================================================================================ >> c:\Harvard\project1>SET FLASK_APP="create_db.py" >> >> c:\Harvard\project1>set DATABASE_URL=postgres:// >> guaqyugfujbudc:79ae65a6d8966991694906e4b96f20ebcfde5b80fb334e99d79d9300dd6ef95f at ec2-34-200-72-77.compute-1.amazonaws.com:5432/dep18tfh5g2eme >> >> c:\Harvard\project1>flask run >> * Serving Flask app ""create_db.py"" (lazy loading) >> * Environment: development >> * Debug mode: on >> * Restarting with stat >> * Debugger is active! >> * Debugger PIN: 124-607-194 >> * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) >> 127.0.0.1 - - [22/May/2020 10:16:46] " [35m [1mGET / HTTP/1.1 [0m" 500 - >> Traceback (most recent call last): >> File >> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >> line 240, in locate_app >> __import__(module_name) >> ModuleNotFoundError: No module named '"create_db' >> >> During handling of the above exception, another exception occurred: >> >> Traceback (most recent call last): >> File >> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >> line 338, in __call__ >> self._flush_bg_loading_exception() >> File >> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >> line 326, in _flush_bg_loading_exception >> reraise(*exc_info) >> File >> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", >> line 39, in reraise >> raise value >> File >> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >> line 314, in _load_app >> self._load_unlocked() >> File >> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >> line 330, in _load_unlocked >> self._app = rv = self.loader() >> File >> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >> line 388, in load_app >> app = locate_app(self, import_name, name) >> File >> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >> line 250, in locate_app >> raise NoAppException('Could not import >> "{name}".'.format(name=module_name)) >> flask.cli.NoAppException: Could not import ""create_db.py"". >> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET >> /?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1 [0m" 200 - >> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET >> /?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1 [0m" 200 - >> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET >> /?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1 [0m" 200 - >> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET >> /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 - >> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET >> /?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1 [0m" 200 - >> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET >> /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 - >> >> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >> (920) 740-3411 >> linkedin.com/in/buddypeacock >> >> >> >> >> On Fri, May 22, 2020 at 9:42 AM Souvik Dutta >> wrote: >> >>> There will be quotes when doing FLASK_APP="" I think that >>> should solve the problem. >>> >>> On Fri, 22 May, 2020, 5:35 pm Buddy Peacock, >>> wrote: >>> >>>> I'm working on my first python project in CS50W and I am trying to >>>> create >>>> 2 tables. >>>> I am getting the following error when trying to run it: I have >>>> included my >>>> code below the error message. >>>> >>>> flask.cli.NoAppException: Failed to find Flask application or factory in >>>> module "create_db". Use "FLASK_APP=create_db:name to specify one. >>>> Traceback (most recent call last) >>>> File >>>> >>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", >>>> line 39, in reraise >>>> raise value >>>> File >>>> >>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >>>> line 97, in find_best_app >>>> raise NoAppException( >>>> flask.cli.NoAppException: Failed to find Flask application or factory in >>>> module "create_db". Use "FLASK_APP=create_db:name to specify one. >>>> >>>> I used: >>>> FLASK_APP=create_db.py at the command line >>>> >>>> and this is my code: >>>> >>>> import os >>>> from flask import Flask, session >>>> from flask_session import Session >>>> from sqlalchemy import create_engine >>>> from sqlalchemy.orm import scoped_session, sessionmaker >>>> engine = create_engine(os.getenv("DATABASE_URL")) >>>> db = scoped_session(sessionmaker(bind=engine)) >>>> def main(): >>>> db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY, isbn VARCHAR >>>> NOT >>>> NULL, title VARCHAR NOT NULL, author INTEGER NOT NULL, year INTEGER NOT >>>> NULL,)") >>>> db.execute("CREATE TABLE authors (id SERIAL PRIMARY KEY, name >>>> VARCHAR >>>> NOT NULL,)") >>>> db.commit() >>>> if __name__ == "__main__": >>>> main() >>>> >>>> Does anyone have any ideas? >>>> >>>> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >>>> (920) 740-3411 >>>> linkedin.com/in/buddypeacock >>> > >>>> -- >>>> https://mail.python.org/mailman/listinfo/python-list >>>> >>> From ml_news at posteo.de Fri May 22 15:57:23 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Fri, 22 May 2020 21:57:23 +0200 Subject: Strings: double versus single quotes References: <20200519201043.368b6157@arcor.com> <20200519133654.71679e25@bigbox.attlocal.net> Message-ID: <20200522215723.4923720b@arcor.com> On Tue, 19 May 2020 13:36:54 -0500 Tim Chase wrote: > On 2020-05-19 20:10, Manfred Lotz wrote: > > Hi there, > > I am asking myself if I should preferably use single or double > > quotes for strings? > > I'd say your consistency matters more than which one you choose. > First, thanks to all for your opinions and judgements. I agree to the following: 1. Consistency is important. 2. Single quotes are less noisy. 3. Triple double quotes are to be preferred over triple single quotes. I also believe that transferring habits from C, Rust or whatever to Python doesn't make much sense as Python does not distinguish between a character and string from a type perspective. Of course, this is my subjective result, and others (may) have different opinions. -- Manfred From buddy.peacock at gmail.com Fri May 22 12:19:10 2020 From: buddy.peacock at gmail.com (Buddy Peacock) Date: Fri, 22 May 2020 12:19:10 -0400 Subject: creating a table within python code In-Reply-To: References: Message-ID: Still no go. I even tried using the entire path of the py ap in the SET FLASK_APP command.... This is my code now after trying your suggestions. =========================================================================== import os from flask import Flask, session from flask_session import Session from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker app= Flask(__name__) engine = create_engine(os.getenv("DATABASE_URL")) db = scoped_session(sessionmaker(bind=engine)) @app.route("/") def main(): app.run() db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY, isbn VARCHAR NOT NULL, title VARCHAR NOT NULL, author INTEGER NOT NULL, year INTEGER NOT NULL,)") db.execute("CREATE TABLE authors (id SERIAL PRIMARY KEY, name VARCHAR NOT NULL,)") db.commit() if __name__ == "__main__": main() ================================================================================= Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC (920) 740-3411 linkedin.com/in/buddypeacock On Fri, May 22, 2020 at 11:04 AM Souvik Dutta wrote: > And also you might have to add after the import statements app= > Flask(__name__) > and app.run() inside the main function > > On Fri, 22 May, 2020, 8:31 pm Souvik Dutta, > wrote: > >> You might have to add @app.route("/") before the main method. >> >> On Fri, 22 May, 2020, 7:53 pm Buddy Peacock, >> wrote: >> >>> Thank you Souvik, but still having issues. I have pasted the command >>> line interaction this time. My prior message is what appeared in the >>> browser. >>> >>> ================================================================================================================ >>> c:\Harvard\project1>SET FLASK_APP="create_db.py" >>> >>> c:\Harvard\project1>set DATABASE_URL=postgres:// >>> guaqyugfujbudc:79ae65a6d8966991694906e4b96f20ebcfde5b80fb334e99d79d9300dd6ef95f at ec2-34-200-72-77.compute-1.amazonaws.com:5432/dep18tfh5g2eme >>> >>> c:\Harvard\project1>flask run >>> * Serving Flask app ""create_db.py"" (lazy loading) >>> * Environment: development >>> * Debug mode: on >>> * Restarting with stat >>> * Debugger is active! >>> * Debugger PIN: 124-607-194 >>> * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) >>> 127.0.0.1 - - [22/May/2020 10:16:46] " [35m [1mGET / HTTP/1.1 [0m" 500 - >>> Traceback (most recent call last): >>> File >>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >>> line 240, in locate_app >>> __import__(module_name) >>> ModuleNotFoundError: No module named '"create_db' >>> >>> During handling of the above exception, another exception occurred: >>> >>> Traceback (most recent call last): >>> File >>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >>> line 338, in __call__ >>> self._flush_bg_loading_exception() >>> File >>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >>> line 326, in _flush_bg_loading_exception >>> reraise(*exc_info) >>> File >>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", >>> line 39, in reraise >>> raise value >>> File >>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >>> line 314, in _load_app >>> self._load_unlocked() >>> File >>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >>> line 330, in _load_unlocked >>> self._app = rv = self.loader() >>> File >>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >>> line 388, in load_app >>> app = locate_app(self, import_name, name) >>> File >>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >>> line 250, in locate_app >>> raise NoAppException('Could not import >>> "{name}".'.format(name=module_name)) >>> flask.cli.NoAppException: Could not import ""create_db.py"". >>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET >>> /?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1 [0m" 200 - >>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET >>> /?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1 [0m" 200 - >>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET >>> /?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1 [0m" 200 - >>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET >>> /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 - >>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET >>> /?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1 [0m" 200 - >>> 127.0.0.1 - - [22/May/2020 10:16:46] " [37mGET >>> /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1 [0m" 200 - >>> >>> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >>> (920) 740-3411 >>> linkedin.com/in/buddypeacock >>> >>> >>> >>> >>> On Fri, May 22, 2020 at 9:42 AM Souvik Dutta >>> wrote: >>> >>>> There will be quotes when doing FLASK_APP="" I think >>>> that should solve the problem. >>>> >>>> On Fri, 22 May, 2020, 5:35 pm Buddy Peacock, >>>> wrote: >>>> >>>>> I'm working on my first python project in CS50W and I am trying to >>>>> create >>>>> 2 tables. >>>>> I am getting the following error when trying to run it: I have >>>>> included my >>>>> code below the error message. >>>>> >>>>> flask.cli.NoAppException: Failed to find Flask application or factory >>>>> in >>>>> module "create_db". Use "FLASK_APP=create_db:name to specify one. >>>>> Traceback (most recent call last) >>>>> File >>>>> >>>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\_compat.py", >>>>> line 39, in reraise >>>>> raise value >>>>> File >>>>> >>>>> "C:\Users\buddy\AppData\Local\Programs\Python\Python38\Lib\site-packages\flask\cli.py", >>>>> line 97, in find_best_app >>>>> raise NoAppException( >>>>> flask.cli.NoAppException: Failed to find Flask application or factory >>>>> in >>>>> module "create_db". Use "FLASK_APP=create_db:name to specify one. >>>>> >>>>> I used: >>>>> FLASK_APP=create_db.py at the command line >>>>> >>>>> and this is my code: >>>>> >>>>> import os >>>>> from flask import Flask, session >>>>> from flask_session import Session >>>>> from sqlalchemy import create_engine >>>>> from sqlalchemy.orm import scoped_session, sessionmaker >>>>> engine = create_engine(os.getenv("DATABASE_URL")) >>>>> db = scoped_session(sessionmaker(bind=engine)) >>>>> def main(): >>>>> db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY, isbn >>>>> VARCHAR NOT >>>>> NULL, title VARCHAR NOT NULL, author INTEGER NOT NULL, year INTEGER NOT >>>>> NULL,)") >>>>> db.execute("CREATE TABLE authors (id SERIAL PRIMARY KEY, name >>>>> VARCHAR >>>>> NOT NULL,)") >>>>> db.commit() >>>>> if __name__ == "__main__": >>>>> main() >>>>> >>>>> Does anyone have any ideas? >>>>> >>>>> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >>>>> (920) 740-3411 >>>>> linkedin.com/in/buddypeacock < >>>>> https://www.linkedin.com/in/buddypeacock/> >>>>> -- >>>>> https://mail.python.org/mailman/listinfo/python-list >>>>> >>>> From grant.b.edwards at gmail.com Fri May 22 12:31:39 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 22 May 2020 16:31:39 -0000 (UTC) Subject: exiting a while loop References: Message-ID: On 2020-05-22, Peter Otten <__peter__ at web.de> wrote: > If you want to terminate the script you can use exit. However exit > is a function, and you have to call it > > exit() Actually it's an instance of _sitebuiltins.Quitter not a function. You still have to call it. ;) -- Grant From PythonList at DancesWithMice.info Fri May 22 17:24:40 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 23 May 2020 09:24:40 +1200 Subject: Online training June 11, 12: Docker packaging best practices for Python in production In-Reply-To: <6c513f22-04e3-42a7-8d88-8b24b0cdd19f@www.fastmail.com> References: <6c513f22-04e3-42a7-8d88-8b24b0cdd19f@www.fastmail.com> Message-ID: <415c0c2c-12a0-2f1b-8f74-efe99c7d3798@DancesWithMice.info> On 23/05/20 3:40 AM, Itamar Turner-Trauring wrote: > You?re about to ship your Python application into production using Docker: your images are going to be critical infrastructure. ... > *The class will take place on two mornings (US East Coast) on June 11th and 12th. You can **learn more about the class on the event page* * (*https://bit.ly/36kBhhN). Requested/suggested improvements to this 'advert': 1 internationalisation/localisation Please include the exact times because for many of us, "morning" begins a lot sooner than is typical elsewhere, and "EST" is a local-definition. (preferably use/add international standards for expressing times/dates) 2 community/commercial Please mention any costs. This list is populated by volunteers. - if you are volunteering your time, I have almost-insulted you by asking (apologies) - if you are charging for attendance, I shouldn't have to 'click here' to ascertain such a basic fact/significant-factor for many. The topic is a good one; both pertinent and current for Pythonista. Wishing it goes well... -- Regards =dn From PythonList at DancesWithMice.info Fri May 22 17:32:28 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 23 May 2020 09:32:28 +1200 Subject: exiting a while loop In-Reply-To: References: Message-ID: On 23/05/20 4:31 AM, Grant Edwards wrote: > On 2020-05-22, Peter Otten <__peter__ at web.de> wrote: > >> If you want to terminate the script you can use exit. However exit >> is a function, and you have to call it >> >> exit() > > > > Actually it's an instance of _sitebuiltins.Quitter not a function. > > You still have to call it. ;) > > Which definition (may) make it 'worse' (when compared with "break"): doesn't exit() also close the application-window under some OpSys (if not all) - which would 'disappear' the output before it could be read? -- Regards =dn From PythonList at DancesWithMice.info Fri May 22 17:36:13 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sat, 23 May 2020 09:36:13 +1200 Subject: Strings: double versus single quotes In-Reply-To: <20200522215723.4923720b@arcor.com> References: <20200519201043.368b6157@arcor.com> <20200519133654.71679e25@bigbox.attlocal.net> <20200522215723.4923720b@arcor.com> Message-ID: <0094b471-4a2d-a75b-7562-2caf953196b6@DancesWithMice.info> >>> I am asking myself if I should preferably use single or double >>> quotes for strings? ... > I agree to the following: > > 1. Consistency is important. > 2. Single quotes are less noisy. > 3. Triple double quotes are to be preferred over triple single quotes. ... > Of course, this is my subjective result, and others (may) have > different opinions. 4. unless a specific objective of a re-factoring exercise, maintain the conventions used within the code. 5, adhere to the conventions/standards/requirements of the dev.team or organisation. -- Regards =dn From ml_news at posteo.de Sat May 23 00:12:53 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Sat, 23 May 2020 06:12:53 +0200 Subject: Strings: double versus single quotes References: <20200519201043.368b6157@arcor.com> <20200519133654.71679e25@bigbox.attlocal.net> <20200522215723.4923720b@arcor.com> <0094b471-4a2d-a75b-7562-2caf953196b6@DancesWithMice.info> Message-ID: <20200523061253.384951f6@arcor.com> On Sat, 23 May 2020 09:36:13 +1200 DL Neil wrote: > >>> I am asking myself if I should preferably use single or double > >>> quotes for strings? > ... > > > I agree to the following: > > > > 1. Consistency is important. > > 2. Single quotes are less noisy. > > 3. Triple double quotes are to be preferred over triple single > > quotes. > ... > > > Of course, this is my subjective result, and others (may) have > > different opinions. > > 4. unless a specific objective of a re-factoring exercise, maintain > the conventions used within the code. > > 5, adhere to the conventions/standards/requirements of the dev.team > or organisation. > Yes, agree. -- Manfred From adam.preble at gmail.com Sat May 23 02:23:07 2020 From: adam.preble at gmail.com (Adam Preble) Date: Fri, 22 May 2020 23:23:07 -0700 (PDT) Subject: Is there some reason that recent Windows 3.6 releases don't included executable nor msi installers? Message-ID: I wanted to update from 3.6.8 on Windows without necessarily moving on to 3.7+ (yet), so I thought I'd try 3.6.9 or 3.6.10. All I see for both are source archives: https://www.python.org/downloads/release/python-369/ https://www.python.org/downloads/release/python-3610/ So, uh, I theoretically did build a 3.6.10 .exe installer, but I don't really trust I did everything right. Is there an officially sourced installation? From souvik.viksou at gmail.com Sat May 23 06:34:51 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sat, 23 May 2020 16:04:51 +0530 Subject: Is there some reason that recent Windows 3.6 releases don't included executable nor msi installers? In-Reply-To: References: Message-ID: If you take a look at this page then you will find out that 3.6.10 was not intended to be used in windows... https://www.python.org/downloads/windows/ Souvik flutter dev On Sat, May 23, 2020, 11:55 AM Adam Preble wrote: > I wanted to update from 3.6.8 on Windows without necessarily moving on to > 3.7+ (yet), so I thought I'd try 3.6.9 or 3.6.10. > > All I see for both are source archives: > > https://www.python.org/downloads/release/python-369/ > https://www.python.org/downloads/release/python-3610/ > > So, uh, I theoretically did build a 3.6.10 .exe installer, but I don't > really trust I did everything right. Is there an officially sourced > installation? > -- > https://mail.python.org/mailman/listinfo/python-list > From souvik.viksou at gmail.com Sat May 23 06:36:02 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sat, 23 May 2020 16:06:02 +0530 Subject: Is there some reason that recent Windows 3.6 releases don't included executable nor msi installers? In-Reply-To: References: Message-ID: And that there are no files for an installer. Souvik flutter dev On Sat, May 23, 2020, 4:04 PM Souvik Dutta wrote: > If you take a look at this page then you will find out that 3.6.10 was not > intended to be used in windows... > https://www.python.org/downloads/windows/ > > Souvik flutter dev > > On Sat, May 23, 2020, 11:55 AM Adam Preble wrote: > >> I wanted to update from 3.6.8 on Windows without necessarily moving on to >> 3.7+ (yet), so I thought I'd try 3.6.9 or 3.6.10. >> >> All I see for both are source archives: >> >> https://www.python.org/downloads/release/python-369/ >> https://www.python.org/downloads/release/python-3610/ >> >> So, uh, I theoretically did build a 3.6.10 .exe installer, but I don't >> really trust I did everything right. Is there an officially sourced >> installation? >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From skip.montanaro at gmail.com Sat May 23 07:03:54 2020 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 23 May 2020 06:03:54 -0500 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> Message-ID: > Nothing strong. I tend to use double quotes because I have a > background in C (where double quotes are for strings, single quotes > for characters), and double quotes are the recommendation for > docstrings (see PEP 258). If you tend to work a lot with SQL, you > might prefer single quotes. Use whatever makes you happy. I also came to Python from C and tend to make the same mental distinction, though that has softened with time. Given that I have four different choices, I consider: a) If it's preexisting code (especially written by someone else) I try to maintain that style (if discernable) for consistency, subject to b) Minimizing the need to use backslashes I also agree about SQL. I found that something like this: stmt = ( """select foo from bar""" """ where a = 'bag'""" """ and c = 'dog'""" ) worked pretty well, served to both satisfy my brain's desire for semantic indentation (you should see some of the SQL I inherited - yikes!) and maintain a visual distinction between Python and SQL quoting. (Consistently using triple quotes minimizes the chance of needing a stray Python backslash inside the SQL code.) I'm now retired, so can't double check, but I believe SQLite and MSSQL are unusual in their Pythonesque treatment of single and double quotes being synonymous. I believe most other dialects (Oracle, MySQL, Sybase, PostgreSQL that I checked) only recognize single quotes as string delimiters. Skip From zljubisic at gmail.com Sat May 23 07:21:08 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Sat, 23 May 2020 04:21:08 -0700 (PDT) Subject: PyCharm, how to setup self contained subprojects In-Reply-To: <5ec75c23$0$5863$426a74cc@news.free.fr> References: <134dc2c8-6f29-453a-842a-543fee10b121@googlegroups.com> <5ec75c23$0$5863$426a74cc@news.free.fr> Message-ID: <837a5980-d5cf-4f72-b716-f86a22162ee3@googlegroups.com> You are probably right. From rhodri at kynesim.co.uk Sat May 23 08:19:42 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Sat, 23 May 2020 13:19:42 +0100 Subject: Strings: double versus single quotes In-Reply-To: <20200522215723.4923720b@arcor.com> References: <20200519201043.368b6157@arcor.com> <20200519133654.71679e25@bigbox.attlocal.net> <20200522215723.4923720b@arcor.com> Message-ID: On 22/05/2020 20:57, Manfred Lotz wrote: > I also believe that transferring habits from C, Rust or whatever to > Python doesn't make much sense as Python does not distinguish between a > character and string from a type perspective. From a logical perspective, you are correct. From the point of view of someone who writes more C code than Python, not having to remember a new set of habits for Python makes life a lot simpler. Chacun ? son go?t and all that. -- Rhodri James *-* Kynesim Ltd From arj.python at gmail.com Sat May 23 08:51:14 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sat, 23 May 2020 16:51:14 +0400 Subject: Strings: double versus single quotes In-Reply-To: <20200519201043.368b6157@arcor.com> References: <20200519201043.368b6157@arcor.com> Message-ID: The interpreter prefers single-quotes >>> "single or double" 'single or double' I read a recent quote from Raymond Hettinger saying that the Python world prefers double ones. If Mr Hettinger is around i'd like to ask him where he pulled the theory from https://twitter.com/raymondh/status/1259209765072154624?s=20 Guess a personal choice thing ~ Kind Regards, Abdur-Rahmaan Janhangeer Mauritius On Tue, May 19, 2020 at 10:20 PM Manfred Lotz wrote: > Hi there, > I am asking myself if I should preferably use single or double quotes > for strings? > > If I need a single quote in a string I would use double quotes for the > whole string and vice versa. For f-strings I mostly see double > quotes but single quotes would work as well I think. > > Is there a recommendation? > > > -- > Manfred > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sat May 23 11:40:34 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 May 2020 01:40:34 +1000 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> Message-ID: On Sat, May 23, 2020 at 10:52 PM Abdur-Rahmaan Janhangeer wrote: > > The interpreter prefers single-quotes > > >>> "single or double" > 'single or double' > >>> 'not all that strongly, it doesn\'t' "not all that strongly, it doesn't" ChrisA From tjreedy at udel.edu Fri May 22 18:19:10 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 22 May 2020 18:19:10 -0400 Subject: exiting a while loop In-Reply-To: References: Message-ID: On 5/22/2020 12:31 PM, Grant Edwards wrote: > On 2020-05-22, Peter Otten <__peter__ at web.de> wrote: > >> If you want to terminate the script you can use exit. However exit >> is a function, and you have to call it >> >> exit() > > > > Actually it's an instance of _sitebuiltins.Quitter not a function. Which means that it is not part of the language and is not guaranteed to exist and will not if the local site module does not inject it. quit() and exit() are only meant for interactive use at the >>> prompt as a cross-platform alternative to ^D or ^Z on non-Windows or Windows. They should not be used in programs unless explicitly defined or imported. The reason both exist, violating the 'one obvious rule' is because both are (were) used used in various other REPLs and interactive text programs. -- Terry Jan Reedy From zljubisic at gmail.com Sat May 23 07:24:09 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Sat, 23 May 2020 04:24:09 -0700 (PDT) Subject: How to design a class that will listen on stdin? Message-ID: <6f482099-3f70-4204-a0ef-c698de5d81f9@googlegroups.com> Hi, I have to talk to outer system by stdin/stdout. Each line that comes to stdin should be processed and its result returned back to stdout. Logging should go to stderr. How to design a class that will listed to stdin and call required methods in order to process the data? Regards From arj.python at gmail.com Sat May 23 09:41:03 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sat, 23 May 2020 17:41:03 +0400 Subject: FlaskCon Call For Papers Message-ID: Greetings list, The call for papers for FlaskCon is open: https://flaskcon.com/ It is a community-run event, 100% free and remote with reviewers from the Pallets, Flask maintainers and more Feel free to pass the word around! Kind Regards, Abdur-Rahmaan Janhangeer Mauritius From grant.b.edwards at gmail.com Sat May 23 11:10:29 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 23 May 2020 15:10:29 -0000 (UTC) Subject: exiting a while loop References: Message-ID: On 2020-05-22, DL Neil via Python-list wrote: > On 23/05/20 4:31 AM, Grant Edwards wrote: >> On 2020-05-22, Peter Otten <__peter__ at web.de> wrote: >> >>> If you want to terminate the script you can use exit. However exit >>> is a function, and you have to call it >>> >>> exit() >> >> >> >> Actually it's an instance of _sitebuiltins.Quitter not a function. >> >> You still have to call it. ;) >> >> > Which definition (may) make it 'worse' (when compared with "break"): Oh, he definitely wanted break instead of exit(), and I assume the OP had already taken that advice. That's why I'm claiming extra pedant points: clarifying a pointless detail about something the OP didn't want to be using in first place and which had already been replaced by something else. -- Grant From dieter at handshake.de Sat May 23 12:14:57 2020 From: dieter at handshake.de (Dieter Maurer) Date: Sat, 23 May 2020 18:14:57 +0200 Subject: How to design a class that will listen on stdin? In-Reply-To: <6f482099-3f70-4204-a0ef-c698de5d81f9@googlegroups.com> References: <6f482099-3f70-4204-a0ef-c698de5d81f9@googlegroups.com> Message-ID: <24265.19457.147147.441108@ixdm.fritz.box> zljubisic at gmail.com wrote at 2020-5-23 04:24 -0700: >I have to talk to outer system by stdin/stdout. >Each line that comes to stdin should be processed and its result returned back to stdout. Logging should go to stderr. > >How to design a class that will listed to stdin and call required methods in order to process the data? Start by reading the Python tutorial ("https://docs.python.org/3/tutorial/index.html#tutorial-index"), especially section 7. From 2QdxY4RzWzUUiLuE at potatochowder.com Sat May 23 12:20:10 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (Dan Sommers) Date: Sat, 23 May 2020 12:20:10 -0400 Subject: How to design a class that will listen on stdin? In-Reply-To: <6f482099-3f70-4204-a0ef-c698de5d81f9@googlegroups.com> References: <6f482099-3f70-4204-a0ef-c698de5d81f9@googlegroups.com> Message-ID: <87a71ypqrp.fsf@unique.fqdn> On Saturday, May 23, 2020, at 07:24 -0400, zljubisic at gmail.com wrote: > I have to talk to outer system by stdin/stdout. > Each line that comes to stdin should be processed and its result returned back to stdout. Logging should go to stderr. > > How to design a class that will listed to stdin and call required methods in order to process the data? I wouldn't put it into a class, but the core of it looks something like this: for line in sys.stdin: result = process(line) print(result) if some_condition(): break The details may be different, and there's likely more error handling in production code, but that's the general idea. From python.list at tim.thechases.com Sat May 23 12:03:09 2020 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 23 May 2020 11:03:09 -0500 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> Message-ID: <20200523110309.79c401f9@bigbox.attlocal.net> On 2020-05-24 01:40, Chris Angelico wrote: > On Sat, May 23, 2020 at 10:52 PM Abdur-Rahmaan Janhangeer > wrote: > > > > The interpreter prefers single-quotes > > > > >>> "single or double" > > 'single or double' > > > >>> 'not all that strongly, it doesn\'t' > "not all that strongly, it doesn't" But when a string contains both, it biases towards single quotes: >>> "You said \"No it doesn't\"" 'You said "No it doesn\'t"' ;-) -tkc From arj.python at gmail.com Sat May 23 13:08:55 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sat, 23 May 2020 21:08:55 +0400 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> Message-ID: Nice one, Was requoting: <>> "hello" 'hello'>> from R Hettinger Kind Regards, Abdur-Rahmaan Janhangeer https://www.github.com/Abdur-RahmaanJ Mauritius sent from gmail client on Android, that's why the signature is so ugly. From Ralf_M at t-online.de Sat May 23 14:21:41 2020 From: Ralf_M at t-online.de (Ralf M.) Date: Sat, 23 May 2020 20:21:41 +0200 Subject: Enums are Singletons - but not always? Message-ID: <9d850c0b-38fd-008c-60ca-c0f78ffe87a7@t-online.de> Hello, recently I wrote a small library that uses an Enum. That worked as expected. Then I added a main() and if __name__ == "__main__" to make it runable as script. Now Enum members that should be the same aren't identical any more, there seem to be two instances of the same Enum. I think I know what's going on, but cannot find a good and elegant way to avoid the problem. I hope someone here can help me there. Below are a simplified code sample, the results when I run it and my thoughts. ##### Code of mod1.py ##### import enum, mod2 class En(enum.Enum): A = 1 B = 2 def main(): a = mod2.getA() print("a is En.A:", a is En.A) print("a:", repr(a), " En.A:", repr(En.A)) print("id(a), id(a.__class__)", id(a), id(a.__class__)) print("id(En.A), id(En) ", id(En.A), id(En)) if __name__ == "__main__": main() ##### End of mod1.py ##### ##### Code of mod2.py ##### import mod1 def getA(): return mod1.En.A ##### End of mod2.py ##### ##### Results when run: ##### C:\tmp>py mod1.py a is En.A: False a: En.A: id(a), id(a.__class__) 33305864 7182808 id(En.A), id(En) 33180552 7183752 C:\tmp>py Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import mod1 >>> mod1.main() a is En.A: True a: En.A: id(a), id(a.__class__) 49566792 44574280 id(En.A), id(En) 49566792 44574280 >>> So: When run as script there are two instances of En (different ids), but when mod1 is imported and mod1.main() is run it works as expected (just one instance of En, same ids). BTW: py -m mod1 doesn't work either. What I thing is happening: When the script is run, mod1.py is executed and an instance of En and its members is created. During the same run mod1 is also imported (via mod2), the file mod1.py is executed again as part of the import and another, different instance of En and its members is created. How do I have to change mod1.py to avoid the problem? Currently I have moved main() into a new file script.py. That works, but is not what I wanted. I doubt it's a bug in the enum module, but should that be the case, I'm willing to open an issue on the bug tracker. Or can nothing be done about it? Looking forward to any ideas Ralf M. P.S.: As I was about to send this post the following modification occured to me (see below). It works, but it doesn't feel right to import a module directly from inside itself. ##### Modified code of mod1.py (one line added) ##### import enum, mod2 class En(enum.Enum): A = 1 B = 2 from mod1 import En # NEW LINE, overwrite just defined En def main(): a = mod2.getA() print("a is En.A:", a is En.A) print("a:", repr(a), " En.A:", repr(En.A)) print("id(a), id(a.__class__)", id(a), id(a.__class__)) print("id(En.A), id(En) ", id(En.A), id(En)) if __name__ == "__main__": main() From Richard at Damon-Family.org Sat May 23 14:57:50 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 23 May 2020 14:57:50 -0400 Subject: Enums are Singletons - but not always? In-Reply-To: <9d850c0b-38fd-008c-60ca-c0f78ffe87a7@t-online.de> References: <9d850c0b-38fd-008c-60ca-c0f78ffe87a7@t-online.de> Message-ID: <03840414-5b9f-3bb0-5615-8ee3b460da6d@Damon-Family.org> On 5/23/20 2:21 PM, Ralf M. wrote: > Hello, > > recently I wrote a small library that uses an Enum. That worked as > expected. Then I added a main() and if __name__ == "__main__" to make > it runable as script. Now Enum members that should be the same aren't > identical any more, there seem to be two instances of the same Enum. > > I think I know what's going on, but cannot find a good and elegant way > to avoid the problem. I hope someone here can help me there. I don;'t think Python anywhere defines that a enum will be a singleton, and you should be checking for equality (==) not identity (is) -- Richard Damon From mats at python.org Sat May 23 15:22:26 2020 From: mats at python.org (Mats Wichmann) Date: Sat, 23 May 2020 13:22:26 -0600 Subject: Is there some reason that recent Windows 3.6 releases don't included executable nor msi installers? In-Reply-To: References: Message-ID: <4986af9e-0c1e-97d3-e830-268a1cc57684@python.org> On 5/23/20 12:23 AM, Adam Preble wrote: > I wanted to update from 3.6.8 on Windows without necessarily moving on to 3.7+ (yet), so I thought I'd try 3.6.9 or 3.6.10. > > All I see for both are source archives: > > https://www.python.org/downloads/release/python-369/ > https://www.python.org/downloads/release/python-3610/ > > So, uh, I theoretically did build a 3.6.10 .exe installer, but I don't really trust I did everything right. Is there an officially sourced installation? > During the early part of a release cycle, installers are built. Once the cycle moves into security fix-only mode, installers are not built. That's all you are seeing. From __peter__ at web.de Sat May 23 15:42:24 2020 From: __peter__ at web.de (Peter Otten) Date: Sat, 23 May 2020 21:42:24 +0200 Subject: Enums are Singletons - but not always? References: <9d850c0b-38fd-008c-60ca-c0f78ffe87a7@t-online.de> Message-ID: Ralf M. wrote: > Hello, > > recently I wrote a small library that uses an Enum. That worked as > expected. Then I added a main() and if __name__ == "__main__" to make it > runable as script. Now Enum members that should be the same aren't > identical any more, there seem to be two instances of the same Enum. > > I think I know what's going on, but cannot find a good and elegant way > to avoid the problem. I hope someone here can help me there. > > Below are a simplified code sample, the results when I run it and my > thoughts. > > ##### Code of mod1.py ##### > import enum, mod2 > class En(enum.Enum): > A = 1 > B = 2 > def main(): > a = mod2.getA() > print("a is En.A:", a is En.A) > print("a:", repr(a), " En.A:", repr(En.A)) > print("id(a), id(a.__class__)", id(a), id(a.__class__)) > print("id(En.A), id(En) ", id(En.A), id(En)) > if __name__ == "__main__": > main() > ##### End of mod1.py ##### > > ##### Code of mod2.py ##### > import mod1 > def getA(): > return mod1.En.A > ##### End of mod2.py ##### > > ##### Results when run: ##### > C:\tmp>py mod1.py > a is En.A: False > a: En.A: > id(a), id(a.__class__) 33305864 7182808 > id(En.A), id(En) 33180552 7183752 > > C:\tmp>py > Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 > 64 bit > (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import mod1 > >>> mod1.main() > a is En.A: True > a: En.A: > id(a), id(a.__class__) 49566792 44574280 > id(En.A), id(En) 49566792 44574280 > >>> > > So: When run as script there are two instances of En (different ids), > but when mod1 is imported and mod1.main() is run it works as expected > (just one instance of En, same ids). > BTW: py -m mod1 doesn't work either. > > What I thing is happening: > When the script is run, mod1.py is executed and an instance of En and > its members is created. During the same run mod1 is also imported (via > mod2), the file mod1.py is executed again as part of the import and > another, different instance of En and its members is created. > > How do I have to change mod1.py to avoid the problem? > Currently I have moved main() into a new file script.py. That works, but > is not what I wanted. But that is exactly the right approach. Avoid importing the main script under its name because that will run all code that is not guarded by if __name__ == "__main__": ... twice. In your case it's enum, but the same goes for every class, function or object and the module itself. In Python they are all created rather than declared. > I doubt it's a bug in the enum module, but should that be the case, I'm > willing to open an issue on the bug tracker. > > Or can nothing be done about it? mod2 could import the __main__ module, e. g. > ##### Code of mod2.py ##### import __main__ as mod1 > def getA(): > return mod1.En.A > ##### End of mod2.py ##### but that would hardcode the assumption that __main__ is always mod1.py. The only sane option is to not put anything in the main script that needs to be imported by other modules. > Looking forward to any ideas > Ralf M. > > P.S.: > As I was about to send this post the following modification occured to > me (see below). It works, but it doesn't feel right to import a module > directly from inside itself. > ##### Modified code of mod1.py (one line added) ##### > import enum, mod2 > class En(enum.Enum): > A = 1 > B = 2 > from mod1 import En # NEW LINE, overwrite just defined En > def main(): > a = mod2.getA() > print("a is En.A:", a is En.A) > print("a:", repr(a), " En.A:", repr(En.A)) > print("id(a), id(a.__class__)", id(a), id(a.__class__)) > print("id(En.A), id(En) ", id(En.A), id(En)) > if __name__ == "__main__": > main() From PythonList at DancesWithMice.info Sat May 23 15:45:28 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 24 May 2020 07:45:28 +1200 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> Message-ID: <3067f41d-43f1-1446-08b8-c4a468251782@DancesWithMice.info> On 23/05/20 11:03 PM, Skip Montanaro wrote: > I also agree about SQL. I found that something like this: > > stmt = ( > """select foo from bar""" > """ where a = 'bag'""" > """ and c = 'dog'""" > ) > > worked pretty well, served to both satisfy my brain's desire for semantic > indentation (you should see some of the SQL I inherited - yikes!) and > maintain a visual distinction between Python and SQL quoting. (Consistently > using triple quotes minimizes the chance of needing a stray Python > backslash inside the SQL code.) I'm now retired, so can't double check, but > I believe SQLite and MSSQL are unusual in their Pythonesque treatment of > single and double quotes being synonymous. I believe most other dialects > (Oracle, MySQL, Sybase, PostgreSQL that I checked) only recognize single > quotes as string delimiters. The older (and more professional?) RDBMS accept either/both as variable delimiters, per Python strings. My habit with SQL queries is to separate them from other code, cf the usual illustration of having them 'buried' within the code, immediately before, or even part of, the query call. This partly because (a) some dev.teams have a specific person handling DBA-tasks, and partly (b) in order to make it easy to find/correct/re-factor SQL code without it being mixed-in with the Python. (a) using a separate and specific module for SQL constants (which may include queries as text, or prepared queries), means that the 'DBA' may develop independently of the Python devs; that integration of code happens in the VCS; that the Python code may separate (stub) or integrate during unit-testing, according to progress and choice. (b) physical 'extraction' and separation make it easier to develop and test each component (SQL, Python, ...) separately - either work in SQL *or* in Python, and not have the extra 'load' of having to flip one's brain between the two; and by using a separate module, makes it easy to locate a 'class' of code dealing with particular data and/or carrying-out particular functions - much as you might for classes and/or libraries. Oh, and a further benefit: (further to "inherited", above) it becomes easier to avoid the massive tangles caused by trying to mix the conventions for indenting multi-line SQL code, with those for Python! -- Regards =dn From kushal at locationd.net Sat May 23 15:49:52 2020 From: kushal at locationd.net (Kushal Kumaran) Date: Sat, 23 May 2020 12:49:52 -0700 Subject: Enums are Singletons - but not always? In-Reply-To: <03840414-5b9f-3bb0-5615-8ee3b460da6d@Damon-Family.org> (Richard Damon's message of "Sat, 23 May 2020 14:57:50 -0400") References: <9d850c0b-38fd-008c-60ca-c0f78ffe87a7@t-online.de> <03840414-5b9f-3bb0-5615-8ee3b460da6d@Damon-Family.org> Message-ID: <87367qfn33.fsf@copper.locationd.net> Richard Damon writes: > On 5/23/20 2:21 PM, Ralf M. wrote: >> Hello, >> >> recently I wrote a small library that uses an Enum. That worked as >> expected. Then I added a main() and if __name__ == "__main__" to make >> it runable as script. Now Enum members that should be the same aren't >> identical any more, there seem to be two instances of the same Enum. >> >> I think I know what's going on, but cannot find a good and elegant way >> to avoid the problem. I hope someone here can help me there. > > I don;'t think Python anywhere defines that a enum will be a singleton, > and you should be checking for equality (==) not identity (is) > https://docs.python.org/3/library/enum.html#enum-members-aka-instances -- regards, kushal From __peter__ at web.de Sat May 23 15:50:33 2020 From: __peter__ at web.de (Peter Otten) Date: Sat, 23 May 2020 21:50:33 +0200 Subject: Enums are Singletons - but not always? References: <9d850c0b-38fd-008c-60ca-c0f78ffe87a7@t-online.de> Message-ID: Peter Otten wrote: >> ##### Code of mod2.py ##### > import __main__ as mod1 >> def getA(): >>return mod1.En.A >> ##### End of mod2.py ##### > > but that would hardcode the assumption that __main__ is always mod1.py. I should have mentioned the cyclic dependency -- if two modules import each other one may not be completely set up when the other tries to access it. From kushal at locationd.net Sat May 23 15:49:21 2020 From: kushal at locationd.net (Kushal Kumaran) Date: Sat, 23 May 2020 12:49:21 -0700 Subject: Enums are Singletons - but not always? In-Reply-To: <9d850c0b-38fd-008c-60ca-c0f78ffe87a7@t-online.de> (Ralf M.'s message of "Sat, 23 May 2020 20:21:41 +0200") References: <9d850c0b-38fd-008c-60ca-c0f78ffe87a7@t-online.de> Message-ID: <877dx2fn3y.fsf@copper.locationd.net> "Ralf M." writes: > Hello, > > recently I wrote a small library that uses an Enum. That worked as > expected. Then I added a main() and if __name__ == "__main__" to make > it runable as script. Now Enum members that should be the same aren't > identical any more, there seem to be two instances of the same Enum. > > I think I know what's going on, but cannot find a good and elegant way > to avoid the problem. I hope someone here can help me there. > > Below are a simplified code sample, the results when I run it and my > thoughts. > > ##### Code of mod1.py ##### > import enum, mod2 > class En(enum.Enum): > A = 1 > B = 2 > def main(): > a = mod2.getA() > print("a is En.A:", a is En.A) > print("a:", repr(a), " En.A:", repr(En.A)) > print("id(a), id(a.__class__)", id(a), id(a.__class__)) > print("id(En.A), id(En) ", id(En.A), id(En)) > if __name__ == "__main__": > main() > ##### End of mod1.py ##### > > ##### Code of mod2.py ##### > import mod1 > def getA(): > return mod1.En.A > ##### End of mod2.py ##### > > ##### Results when run: ##### > C:\tmp>py mod1.py > a is En.A: False > a: En.A: > id(a), id(a.__class__) 33305864 7182808 > id(En.A), id(En) 33180552 7183752 > > C:\tmp>py > Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC > v.1916 64 bit > (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> import mod1 >>>> mod1.main() > a is En.A: True > a: En.A: > id(a), id(a.__class__) 49566792 44574280 > id(En.A), id(En) 49566792 44574280 >>>> > > So: When run as script there are two instances of En (different ids), > but when mod1 is imported and mod1.main() is run it works as expected > (just one instance of En, same ids). > BTW: py -m mod1 doesn't work either. > > What I thing is happening: > When the script is run, mod1.py is executed and an instance of En and > its members is created. During the same run mod1 is also imported (via > mod2), the file mod1.py is executed again as part of the import and > another, different instance of En and its members is created. > > How do I have to change mod1.py to avoid the problem? > Currently I have moved main() into a new file script.py. That works, > but is not what I wanted. > I think of circular dependencies as a code smell. You can move the enum definition into a separate module, and have both mod1 and mod2 import that, or like you say, by moving the main function into its own module. Maybe you can explain why you don't want this. The note in the documentation about enum members being singletons only applies to the members. It does not apply to the enum class itself. In your case, __main__.En is not the same as mod1.En. The members being singleton means that, for the same enum class En, En.A will refer to the same object as En(1), or, perhaps an unpickled object that has the same value. > I doubt it's a bug in the enum module, but should that be the case, > I'm willing to open an issue on the bug tracker. > > Or can nothing be done about it? > It is not specific to the Enum class. You'll see the same behaviour with any class that gets imported under two different module names. > Looking forward to any ideas > Ralf M. > > P.S.: > As I was about to send this post the following modification occured to > me (see below). It works, but it doesn't feel right to import a module > directly from inside itself. > ##### Modified code of mod1.py (one line added) ##### > import enum, mod2 > class En(enum.Enum): > A = 1 > B = 2 > from mod1 import En # NEW LINE, overwrite just defined En > def main(): > a = mod2.getA() > print("a is En.A:", a is En.A) > print("a:", repr(a), " En.A:", repr(En.A)) > print("id(a), id(a.__class__)", id(a), id(a.__class__)) > print("id(En.A), id(En) ", id(En.A), id(En)) > if __name__ == "__main__": > main() I agree this is unpleasant to read. -- regards, kushal From PythonList at DancesWithMice.info Sat May 23 16:03:41 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 24 May 2020 08:03:41 +1200 Subject: Strings: double versus single quotes In-Reply-To: <20200523110309.79c401f9@bigbox.attlocal.net> References: <20200519201043.368b6157@arcor.com> <20200523110309.79c401f9@bigbox.attlocal.net> Message-ID: On 24/05/20 4:03 AM, Tim Chase wrote: > On 2020-05-24 01:40, Chris Angelico wrote: >> On Sat, May 23, 2020 at 10:52 PM Abdur-Rahmaan Janhangeer >> wrote: >>> >>> The interpreter prefers single-quotes >>> >>>>>> "single or double" >>> 'single or double' >>> >>>>> 'not all that strongly, it doesn\'t' >> "not all that strongly, it doesn't" > > But when a string contains both, it biases towards single quotes: > > >>> "You said \"No it doesn't\"" > 'You said "No it doesn\'t"' > > ;-) I'm highly amused by this interchange - for two reasons: that you'd noticed these details, and that I hadn't! Yes, I'd noted that the REPL responds with single-quotes, even if I used double-quotes in the definition (per "single of double", above) - for whatever that's worth (it's not as if the delimiters are stored along with other variable detail!) That the REPL is 'intelligent' about its choice to vary the delimiter to suit the content is good (design) sense - the best presentation (UX), ie doesn't is a better presentation than doesn\'t! Which brings me to my own, humble, and quite often non-PEP-8-respecting habits: that I (basically) apply the ?rules of English grammar to Python (which I write (mostly) in English). Thus a "quotation", eg someone's name, but any piece of data, will be enclosed in double-quotes: name = "Abdur-Rahman" whereas, when something will be 'calculated', I use singles, eg f'{ name } is top of the class' Never learning a language which distinguishes single character literals from strings, eg the C examples quoted earlier, such thoughts/distinctions don't 'exist'. (which makes me wonder why code reviews have never queried the point, or registered that I might seem to be behaving inconsistently...) -- Regards =dn From rosuav at gmail.com Sat May 23 16:15:07 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 May 2020 06:15:07 +1000 Subject: Enums are Singletons - but not always? In-Reply-To: <877dx2fn3y.fsf@copper.locationd.net> References: <9d850c0b-38fd-008c-60ca-c0f78ffe87a7@t-online.de> <877dx2fn3y.fsf@copper.locationd.net> Message-ID: On Sun, May 24, 2020 at 5:58 AM Kushal Kumaran wrote: > > "Ralf M." writes: > > > Below are a simplified code sample, the results when I run it and my > > thoughts. > > > > ##### Code of mod1.py ##### > > import enum, mod2 > > def main(): > > a = mod2.getA() > > ##### End of mod1.py ##### > > > > ##### Code of mod2.py ##### > > import mod1 > > def getA(): > > return mod1.En.A > > ##### End of mod2.py ##### > > > I think of circular dependencies as a code smell. You can move the enum > definition into a separate module, and have both mod1 and mod2 import > that, or like you say, by moving the main function into its own module. > Maybe you can explain why you don't want this. Correct - and especially since you're using the main module also as a module. Currently, that is something you just plain shouldn't do. You end up with one copy of the module called __main__ and another one called mod1, and they're completely independent. Just don't do that. However, there HAVE been some proposals to make this sort of thing work. In general, they'd end up doing something like having the module inserted into sys.modules twice, once as __main__ and once as mod1, so you end up getting the same module in both cases. That would work, since (with only one module) there'd only be one En class. I don't think any such proposal has gotten fully serious yet, but if this is something you're interested in (or feel strongly about), dig through the python-ideas archives to see some of the arguments for and against. ChrisA From ethan at stoneleaf.us Sat May 23 16:15:51 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 23 May 2020 13:15:51 -0700 Subject: Enums are Singletons - but not always? In-Reply-To: <03840414-5b9f-3bb0-5615-8ee3b460da6d@Damon-Family.org> References: <9d850c0b-38fd-008c-60ca-c0f78ffe87a7@t-online.de> <03840414-5b9f-3bb0-5615-8ee3b460da6d@Damon-Family.org> Message-ID: On 05/23/2020 11:57 AM, Richard Damon wrote: > I don't think Python anywhere defines that a enum will be a singleton, > and you should be checking for equality (==) not identity (is) If you're not sure, please do a little research first. We have enough bad information on the 'nets already. According to Kushal's link: > The most interesting thing about Enum members is that they are singletons. The only time using `==` is necessary is for mixed-Enums, such as IntEnum, and you need to compare what could be an IntEnum member in code that could be using actual `int`s. -- ~Ethan~ From benhansen1945 at gmail.com Sat May 23 12:55:36 2020 From: benhansen1945 at gmail.com (Ben Hansen) Date: Sat, 23 May 2020 11:55:36 -0500 Subject: Fwd: installed but doesn't boot In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Ben Hansen Date: Sat, May 23, 2020 at 11:44 AM Subject: Fwd: installed but doesn't boot To: ---------- Forwarded message --------- From: Ben Hansen Date: Fri, May 22, 2020 at 3:18 PM Subject: installed but doesn't boot To: I have installed python after getting the book "Coding for Kids/Python, and it won't boot. HELP1111 From aswin at pythonninja.xyz Sat May 23 13:45:30 2020 From: aswin at pythonninja.xyz (Aswin K) Date: Sat, 23 May 2020 13:45:30 -0400 Subject: Subject: Python Open-Source Snippets Newsletter Message-ID: Hi, I am creating a Python newsletter showcasing useful code snippets from popular open-source libraries. I will also be providing a runnable demo link to better understand the working. Newsletter subscription link: https://www.pythonninja.xyz/subscribe A sample snippet from the newsletter: HTTP Request retrying with Backoffs - Technique for retrying failed HTTP requests. From Google Maps Services Python (https://github.com/googlemaps/google-maps-services-python) Demo link: https://repl.it/@PythonNinja/requestretries """ first_request_time: The time of the first request (None if no retries have occurred). retry_counter: The count of retries, or zero for the first attempt. """ if not first_request_time: first_request_time = datetime.now() elapsed = datetime.now() - first_request_time if elapsed > self.retry_timeout: raise googlemaps.exceptions.Timeout() if retry_counter > 0: # 0.5 * (1.5 ^ i) is an increased sleep time of 1.5x per iteration, # starting at 0.5s when retry_counter=0. The first retry will occur # at 1, so subtract that first. delay_seconds = 0.5 * 1.5 ** (retry_counter - 1) # Jitter this value by 50% and pause. time.sleep(delay_seconds * (random.random() + 0.5)) Subscribe here: https://www.pythonninja.xyz/subscribe Feedbacks and criticism are welcome. From roel at roelschroeven.net Sat May 23 14:52:02 2020 From: roel at roelschroeven.net (Roel Schroeven) Date: Sat, 23 May 2020 20:52:02 +0200 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> Message-ID: Skip Montanaro schreef op 23/05/2020 om 13:03: > I also agree about SQL. I found that something like this: > > stmt = ( > """select foo from bar""" > """ where a = 'bag'""" > """ and c = 'dog'""" > ) > > worked pretty well, served to both satisfy my brain's desire for semantic > indentation (you should see some of the SQL I inherited - yikes!) and > maintain a visual distinction between Python and SQL quoting. (Consistently > using triple quotes minimizes the chance of needing a stray Python > backslash inside the SQL code.) May I ask why not simply like this: stmt = """ select foo from bar where a = 'bag' and c = 'dog' """ This introduces more newlines and spaces in the query, but that shouldn't really matter. I think it's more readable, and easier to edit the query. > I'm now retired, so can't double check, but > I believe SQLite and MSSQL are unusual in their Pythonesque treatment of > single and double quotes being synonymous. I believe most other dialects > (Oracle, MySQL, Sybase, PostgreSQL that I checked) only recognize single > quotes as string delimiters. Right. The SQLite developers did it that way in an effort to be compatible with MySQL, and since have come to the realisation that that was a mistake. In recent versions you can turn it off, in which cases single quotes are for string literals and double quotes are for identifiers (such as column names), as in standard SQL. See https://sqlite.org/quirks.html#double_quoted_string_literals_are_accepted -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From roel at roelschroeven.net Sat May 23 15:11:07 2020 From: roel at roelschroeven.net (Roel Schroeven) Date: Sat, 23 May 2020 21:11:07 +0200 Subject: Enums are Singletons - but not always? In-Reply-To: <03840414-5b9f-3bb0-5615-8ee3b460da6d@Damon-Family.org> References: <9d850c0b-38fd-008c-60ca-c0f78ffe87a7@t-online.de> <03840414-5b9f-3bb0-5615-8ee3b460da6d@Damon-Family.org> Message-ID: Richard Damon schreef op 23/05/2020 om 20:57: > On 5/23/20 2:21 PM, Ralf M. wrote: >> Hello, >> >> recently I wrote a small library that uses an Enum. That worked as >> expected. Then I added a main() and if __name__ == "__main__" to make >> it runable as script. Now Enum members that should be the same aren't >> identical any more, there seem to be two instances of the same Enum. >> >> I think I know what's going on, but cannot find a good and elegant way >> to avoid the problem. I hope someone here can help me there. > > I don;'t think Python anywhere defines that a enum will be a singleton, > and you should be checking for equality (==) not identity (is) So much this. Always check for equality instead of identity, unless you know what you're doing and you have a very good reason to use identity. Everywhere I see questions all the time from people new to Python, confused about stuff that happens when comparing using identity. I would like to know where that comes from ... are there tutorials that encourage using identity checks? -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From PythonList at DancesWithMice.info Sat May 23 16:39:05 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 24 May 2020 08:39:05 +1200 Subject: Fwd: installed but doesn't boot In-Reply-To: References: Message-ID: <7aea02c0-83bf-aa16-b14d-92e0fee99bc0@DancesWithMice.info> On 24/05/20 4:55 AM, Ben Hansen wrote: > ---------- Forwarded message --------- > From: Ben Hansen > Date: Sat, May 23, 2020 at 11:44 AM > Subject: Fwd: installed but doesn't boot > To: > > > > > ---------- Forwarded message --------- > From: Ben Hansen > Date: Fri, May 22, 2020 at 3:18 PM > Subject: installed but doesn't boot > To: > > > I have installed python after getting the book "Coding for Kids/Python, and > it won't boot. HELP1111 Assuming MS-Windows: Please advise if the following reference is accurate, and works for you: https://docs.python.org/3/using/windows.html -- Regards =dn From skip.montanaro at gmail.com Sat May 23 16:39:11 2020 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 23 May 2020 15:39:11 -0500 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> Message-ID: > > > May I ask why not simply like this: > > stmt = """ > select foo from bar > where a = 'bag' > and c = 'dog' > """ > Sorry, I don't recall. I wouldn't be at all surprised that it has something to do with Emacs's Python mode behavior. Emacs wouldn't know what to do with spaces in the string, but knows where to put string literals within the open parens. I'm pretty sure I was doing this before triple quoted strings existed. Thankfully, I don't need to mess around with SQL anymore. :-) Skip > From PythonList at DancesWithMice.info Sat May 23 16:50:06 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 24 May 2020 08:50:06 +1200 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> Message-ID: On 24/05/20 8:39 AM, Skip Montanaro wrote: >> >> >> May I ask why not simply like this: >> >> stmt = """ >> select foo from bar >> where a = 'bag' >> and c = 'dog' >> """ > > Sorry, I don't recall. I wouldn't be at all surprised that it has something > to do with Emacs's Python mode behavior. Emacs wouldn't know what to do > with spaces in the string, but knows where to put string literals within > the open parens. I'm pretty sure I was doing this before triple quoted > strings existed. > > Thankfully, I don't need to mess around with SQL anymore. :-) Awwww. don't be like that - send it all to me, and I'll fix it for you (at exorbitant rates, of course)... The above is valid - the editor has a file in one format/language, and is therefore applying 'the wrong rules' when it attempts to make SQL look like Python! The inconvenience (cf "issue") that arises, is that many SQL debuggers and error-handlers (etc) will repeat-back the source-code/query as-provided. Consequently, those messages are all messed-up with extraneous tabs and new-lines, making them difficult to read and debug. (see also: earlier post mentioning separation of languages/code) -- Regards =dn From python.list at tim.thechases.com Sat May 23 19:00:18 2020 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 23 May 2020 18:00:18 -0500 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> <20200523110309.79c401f9@bigbox.attlocal.net> Message-ID: <20200523180018.09ae72d3@bigbox.attlocal.net> On 2020-05-23 14:46, Dennis Lee Bieber wrote: > On Sat, 23 May 2020 11:03:09 -0500, Tim Chase > >But when a string contains both, it biases towards single quotes: > > > > >>> "You said \"No it doesn't\"" > > 'You said "No it doesn\'t"' > > This is where using triple quotes (or triple apostrophes) > around the entire thing simplifies it all... (except for a need to > separate the four ending quotes) Unless you're pathological. ;-) >>> """I said "This contain every type of \"""Python\""" '''triple-quoted''' string, doesn't it?\"""" 'I said "This contains every type of """Python""" \'\'\'triple-quoted\'\'\' string, doesn\'t it."' And-you-can-quote-me-on-that'ly yers, -tkc From souvik.viksou at gmail.com Sat May 23 22:56:17 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sun, 24 May 2020 08:26:17 +0530 Subject: Strings: double versus single quotes In-Reply-To: <20200523180018.09ae72d3@bigbox.attlocal.net> References: <20200519201043.368b6157@arcor.com> <20200523110309.79c401f9@bigbox.attlocal.net> <20200523180018.09ae72d3@bigbox.attlocal.net> Message-ID: This seems to be a life long debate... On Sun, 24 May, 2020, 5:25 am Tim Chase, wrote: > On 2020-05-23 14:46, Dennis Lee Bieber wrote: > > On Sat, 23 May 2020 11:03:09 -0500, Tim Chase > > >But when a string contains both, it biases towards single quotes: > > > > > > >>> "You said \"No it doesn't\"" > > > 'You said "No it doesn\'t"' > > > > This is where using triple quotes (or triple apostrophes) > > around the entire thing simplifies it all... (except for a need to > > separate the four ending quotes) > > Unless you're pathological. ;-) > > >>> """I said "This contain every type of \"""Python\""" > '''triple-quoted''' string, doesn't it?\"""" > 'I said "This contains every type of """Python""" > \'\'\'triple-quoted\'\'\' string, doesn\'t it."' > > And-you-can-quote-me-on-that'ly yers, > > -tkc > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Sat May 23 21:07:43 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 23 May 2020 21:07:43 -0400 Subject: Enums are Singletons - but not always? In-Reply-To: <9d850c0b-38fd-008c-60ca-c0f78ffe87a7@t-online.de> References: <9d850c0b-38fd-008c-60ca-c0f78ffe87a7@t-online.de> Message-ID: On 5/23/2020 2:21 PM, Ralf M. wrote: > ##### Code of mod1.py ##### > import enum, mod2 > class En(enum.Enum): > ??? A = 1 > ??? B = 2 > def main(): > ??? a = mod2.getA() > ??? print("a is En.A:", a is En.A) > ??? print("a:", repr(a), "??? En.A:", repr(En.A)) > ??? print("id(a), id(a.__class__)", id(a), id(a.__class__)) > ??? print("id(En.A), id(En)????? ", id(En.A), id(En)) > if __name__ == "__main__": > ??? main() > ##### Code of mod2.py ##### > import mod1 > def getA(): > return mod1.En.A As a couple of people mentioned, the issue is the circular import. When you run mod1 from a command line, its name is __main__. Its execution of mod1 code stops to execute enum code and then mod2 code. Execution of mod2 stops to execute mod1 code in a new module named 'mod1'. When the second execution of mod1 code does the import of enum and mod2, sys.modules['enum'] and sys.modules['mod2'] exist, are found, and used to satify the import. So enum and mod2 code are not executed again. In the 'mod1' module, 'mod2' is linked to the *incomplete* mod2. This 'works' in your code because the reference to mod2 within def main is not used because the name is 'mod1', not '__main__'. But if in mod1, you had written import enum from mod2 import getA the second execution of mod1 would fail because mod2.getA does not exist because execution of mod2 is paused to import mod1 When the mod1 import in mod2 finishes, the execution of mod2 code for 'mod2' finishes without issue. Then the execution of 'mod1' code in '__main__' finishes with the call to main. When you instead interactively import mod1, it is executed just once and you have to explicitly call main. In idlelib, pyshell currently has the IDLE Shell code, the main() function, and a couple of classes used elsewhere. (An atrocious design that I inherited and have only partly fixed.) As a *temporary* fix to an issue due to there being duplicate '__main__' and 'pyshell' modules, I added the following to the top of pyshell. import sys if __name__ == "__main__": sys.modules['idlelib.pyshell']=sys.modules['__main__'] But doing what others suggested, limiting the main or start module to one-time code, is better. -- Terry Jan Reedy From souvik.viksou at gmail.com Sun May 24 00:34:15 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sun, 24 May 2020 10:04:15 +0530 Subject: stderr writting before stdout In-Reply-To: References: Message-ID: Also this code maintains order i.e. writting is displayed before no errors. Why is that? import sys sys.stdout.write("Writting \n") sys.stderr.write("No errors \n") On Sun, 24 May, 2020, 9:57 am Souvik Dutta, wrote: > Hi, > Is there any precedence or priority order by which sys.stderr.write() and > sys.stdout.write() works. Because when running the below code... > > import sys > sys.stdout.write("Writting") > sys.stderr.write("No errors \n") > > No errors is written (displayed) first and writting is written later. Why > does this happen? > > From ml_news at posteo.de Sun May 24 00:41:19 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Sun, 24 May 2020 06:41:19 +0200 Subject: Strings: double versus single quotes References: <20200519201043.368b6157@arcor.com> <20200523110309.79c401f9@bigbox.attlocal.net> Message-ID: <20200524064119.7e146f1d@arcor.com> On Sat, 23 May 2020 14:46:04 -0400 Dennis Lee Bieber wrote: > On Sat, 23 May 2020 11:03:09 -0500, Tim Chase > declaimed the following: > > > > > >But when a string contains both, it biases towards single quotes: > > > > >>> "You said \"No it doesn't\"" > > 'You said "No it doesn\'t"' > > This is where using triple quotes (or triple apostrophes) > around the entire thing simplifies it all... (except for a need to > separate the four ending quotes) Exactly, I also would opt for triple quotes in this case. > > >>> """You said "No it doesn't" """ > 'You said "No it doesn\'t" ' > >>> '''You said "No it doesn't"''' > 'You said "No it doesn\'t"' > >>> > > NO \ escapes needed on the input strings. > > >>> print("""You said "No it doesn't" """) > You said "No it doesn't" > >>> print('''You said "No it doesn't"''') > You said "No it doesn't" > >>> > > -- Manfred From arj.python at gmail.com Sun May 24 01:20:04 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 24 May 2020 09:20:04 +0400 Subject: Strings: double versus single quotes In-Reply-To: <20200524064119.7e146f1d@arcor.com> References: <20200519201043.368b6157@arcor.com> <20200523110309.79c401f9@bigbox.attlocal.net> <20200524064119.7e146f1d@arcor.com> Message-ID: Greetings, Nice idea >>> '''You said "No it doesn't"''' 'You said "No it doesn\'t"' Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy | blog github Mauritius On Sun, May 24, 2020 at 9:05 AM Manfred Lotz wrote: > On Sat, 23 May 2020 14:46:04 -0400 > Dennis Lee Bieber wrote: > > > On Sat, 23 May 2020 11:03:09 -0500, Tim Chase > > declaimed the following: > > > > > > > > > >But when a string contains both, it biases towards single quotes: > > > > > > >>> "You said \"No it doesn't\"" > > > 'You said "No it doesn\'t"' > > > > This is where using triple quotes (or triple apostrophes) > > around the entire thing simplifies it all... (except for a need to > > separate the four ending quotes) > > Exactly, I also would opt for triple quotes in this case. > > > > > >>> """You said "No it doesn't" """ > > 'You said "No it doesn\'t" ' > > >>> '''You said "No it doesn't"''' > > 'You said "No it doesn\'t"' > > >>> > > > > NO \ escapes needed on the input strings. > > > > >>> print("""You said "No it doesn't" """) > > You said "No it doesn't" > > >>> print('''You said "No it doesn't"''') > > You said "No it doesn't" > > >>> > > > > > > > -- > Manfred > > -- > https://mail.python.org/mailman/listinfo/python-list > From arj.python at gmail.com Sun May 24 01:25:28 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 24 May 2020 09:25:28 +0400 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> <20200523110309.79c401f9@bigbox.attlocal.net> Message-ID: Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy | blog github Mauritius On Sun, May 24, 2020 at 12:03 AM DL Neil via Python-list < python-list at python.org> wrote: > > I'm highly amused by this interchange - for two reasons: that you'd > noticed these details, and that I hadn't! > Yes Mr Chris is good for coming on with these kind of points ^^_ > > Yes, I'd noted that the REPL responds with single-quotes, even if I used > double-quotes in the definition (per "single of double", above) - for > whatever that's worth (it's not as if the delimiters are stored along > with other variable detail!) > > That the REPL is 'intelligent' about its choice to vary the delimiter to > suit the content is good (design) sense - the best presentation (UX), ie > doesn't is a better presentation than doesn\'t! > > Which brings me to my own, humble, and quite often non-PEP-8-respecting > habits: that I (basically) apply the ?rules of English grammar to Python > (which I write (mostly) in English). Thus a "quotation", eg someone's > name, but any piece of data, will be enclosed in double-quotes: > > name = "Abdur-Rahman" > > whereas, when something will be 'calculated', I use singles, eg > > f'{ name } is top of the class' > This discussion dives a bit further into the philosophy of Python. Must reactivate the FaQ repo project. Mr Barker is doing it for python-ideas. From frank at chagford.com Sun May 24 01:43:08 2020 From: frank at chagford.com (Frank Millman) Date: Sun, 24 May 2020 07:43:08 +0200 Subject: Strings: double versus single quotes In-Reply-To: <3067f41d-43f1-1446-08b8-c4a468251782@DancesWithMice.info> References: <20200519201043.368b6157@arcor.com> <3067f41d-43f1-1446-08b8-c4a468251782@DancesWithMice.info> Message-ID: On 2020-05-23 9:45 PM, DL Neil via Python-list wrote: > > My habit with SQL queries is to separate them from other code, cf the > usual illustration of having them 'buried' within the code, immediately > before, or even part of, the query call. > I like that idea, as I find that I am embedding more and more SQL in my code. How do you handle parameters? Do you leave placeholders ('?' or '%s') in the query, and leave it to the 'importer' of the query to figure out what is required? Frank Millman From frank at chagford.com Sun May 24 01:43:08 2020 From: frank at chagford.com (Frank Millman) Date: Sun, 24 May 2020 07:43:08 +0200 Subject: Strings: double versus single quotes In-Reply-To: <3067f41d-43f1-1446-08b8-c4a468251782@DancesWithMice.info> References: <20200519201043.368b6157@arcor.com> <3067f41d-43f1-1446-08b8-c4a468251782@DancesWithMice.info> Message-ID: On 2020-05-23 9:45 PM, DL Neil via Python-list wrote: > > My habit with SQL queries is to separate them from other code, cf the > usual illustration of having them 'buried' within the code, immediately > before, or even part of, the query call. > I like that idea, as I find that I am embedding more and more SQL in my code. How do you handle parameters? Do you leave placeholders ('?' or '%s') in the query, and leave it to the 'importer' of the query to figure out what is required? Frank Millman From cs at cskk.id.au Sun May 24 02:03:34 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 24 May 2020 16:03:34 +1000 Subject: stderr writting before stdout In-Reply-To: References: Message-ID: <20200524060334.GA91516@cskk.homeip.net> Please don't top post; I have rearranged your message so that the discussion reads from top to bottom. Reponse below. On 24May2020 10:04, Souvik Dutta wrote: >On Sun, 24 May, 2020, 9:57 am Souvik Dutta, >wrote: >> Is there any precedence or priority order by which sys.stderr.write() >> and >> sys.stdout.write() works. Because when running the below code... >> >> import sys >> sys.stdout.write("Writting") >> sys.stderr.write("No errors \n") >> >> No errors is written (displayed) first and writting is written later. Why >> does this happen? > >Also this code maintains order i.e. writting is displayed before no >errors. >Why is that? > >import sys >sys.stdout.write("Writting \n") >sys.stderr.write("No errors \n") This is all to do with buffering. Output streams are buffered (unless you go out of your way to avoid it). This means that for throughput performance reasons, when you go f.write(...) the daa are written into an in memory buffer, and not yet to the file itself. The buffer is conventionally of fixe size. A fully buffered stream tries to minimise the OS-write calls (which copy from the pogramme to the operating system) because they are comparitively expensive. For thorughtput, writing a lot of data in bulk, this is a win because the OS-write calls are as few as possibly. An unbuffered stream calls the OS-write as soon as any data are received; there wouldn't even be an in memory beffer at all. This presents data to the OS as soon as possible, at the cost of more frequnt OS-write calls. In between these 2 extremes are onther policies. One such is line buffering: the contents of the buffer are written to the OS when there is a complete line in the bufeer (i.e. when a newline character arrives in the data). This is common on terminals, and writes complete lines to the terminal. This is common for writing "text" to a terminal, and makes more OS-writes that full buffeing and fewer than unbuffered as a comprimise to present timely display to a human. You can force an OS-write of a buffered stream by calling its flush() method. Conventionally, on UNIX systems, an output stream connected to a regular file is fully buffered, to maximise bulk data writing throughput. An output stream connected to a terminal is line buffered. Except for stderr, which is _unbuffered_ because it is felt that error messages should always show up as soon as possible. These different policies explain the behaviour you see. By inserting: sys.stdout.flush() calls at various points for can force OS-write calls and see data immediately, which will make this more clear to you. Cheers, Cameron Simpson From souvik.viksou at gmail.com Sun May 24 02:15:30 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sun, 24 May 2020 11:45:30 +0530 Subject: stderr writting before stdout In-Reply-To: <20200524060334.GA91516@cskk.homeip.net> References: <20200524060334.GA91516@cskk.homeip.net> Message-ID: Thank you I understood. Sorry for top posting... ? On Sun, 24 May, 2020, 11:34 am Cameron Simpson, wrote: > Please don't top post; I have rearranged your message so that the > discussion reads from top to bottom. Reponse below. > > On 24May2020 10:04, Souvik Dutta wrote: > >On Sun, 24 May, 2020, 9:57 am Souvik Dutta, > >wrote: > >> Is there any precedence or priority order by which sys.stderr.write() > >> and > >> sys.stdout.write() works. Because when running the below code... > >> > >> import sys > >> sys.stdout.write("Writting") > >> sys.stderr.write("No errors \n") > >> > >> No errors is written (displayed) first and writting is written later. > Why > >> does this happen? > > > >Also this code maintains order i.e. writting is displayed before no > >errors. > >Why is that? > > > >import sys > >sys.stdout.write("Writting \n") > >sys.stderr.write("No errors \n") > > This is all to do with buffering. > > Output streams are buffered (unless you go out of your way to avoid it). > This means that for throughput performance reasons, when you go > f.write(...) the daa are written into an in memory buffer, and not yet > to the file itself. The buffer is conventionally of fixe size. > > A fully buffered stream tries to minimise the OS-write calls (which copy > from the pogramme to the operating system) because they are > comparitively expensive. For thorughtput, writing a lot of data in bulk, > this is a win because the OS-write calls are as few as possibly. > > An unbuffered stream calls the OS-write as soon as any data are > received; there wouldn't even be an in memory beffer at all. This > presents data to the OS as soon as possible, at the cost of more frequnt > OS-write calls. > > In between these 2 extremes are onther policies. One such is line > buffering: the contents of the buffer are written to the OS when there > is a complete line in the bufeer (i.e. when a newline character arrives > in the data). This is common on terminals, and writes complete lines to > the terminal. This is common for writing "text" to a terminal, and makes > more OS-writes that full buffeing and fewer than unbuffered as a > comprimise to present timely display to a human. > > You can force an OS-write of a buffered stream by calling its flush() > method. > > Conventionally, on UNIX systems, an output stream connected to a regular > file is fully buffered, to maximise bulk data writing throughput. An > output stream connected to a terminal is line buffered. Except for > stderr, which is _unbuffered_ because it is felt that error messages > should always show up as soon as possible. > > These different policies explain the behaviour you see. > > By inserting: > > sys.stdout.flush() > > calls at various points for can force OS-write calls and see data > immediately, which will make this more clear to you. > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Sun May 24 03:58:15 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 24 May 2020 19:58:15 +1200 Subject: Strings: double versus single quotes In-Reply-To: References: <20200519201043.368b6157@arcor.com> <3067f41d-43f1-1446-08b8-c4a468251782@DancesWithMice.info> Message-ID: <2b3a4c80-7fa8-8a9f-8580-11eb88bc8deb@DancesWithMice.info> On 24/05/20 5:43 PM, Frank Millman wrote: > On 2020-05-23 9:45 PM, DL Neil via Python-list wrote: >> >> My habit with SQL queries is to separate them from other code, cf the >> usual illustration of having them 'buried' within the code, >> immediately before, or even part of, the query call. >> > > I like that idea, as I find that I am embedding more and more SQL in my > code. > > How do you handle parameters? Do you leave placeholders ('?' or '%s') in > the query, and leave it to the 'importer' of the query to figure out > what is required? Yes. Most "connector" software includes a feature which auto-magically escapes all variable-data - a valuable safety feature! I've been experimenting by going further and providing app.devs with functions/methods, a mini-API if you will. Given that many?most don't like having to deal with SQL, the extra 'insulation' boosts my personal popularity... (and I need as much of that as I can get!) -- Regards =dn From frank at chagford.com Sun May 24 04:41:36 2020 From: frank at chagford.com (Frank Millman) Date: Sun, 24 May 2020 10:41:36 +0200 Subject: Strings: double versus single quotes In-Reply-To: <2b3a4c80-7fa8-8a9f-8580-11eb88bc8deb@DancesWithMice.info> References: <20200519201043.368b6157@arcor.com> <3067f41d-43f1-1446-08b8-c4a468251782@DancesWithMice.info> <2b3a4c80-7fa8-8a9f-8580-11eb88bc8deb@DancesWithMice.info> Message-ID: <22608156-1961-5975-d21c-1adda9af4889@chagford.com> On 2020-05-24 9:58 AM, DL Neil via Python-list wrote: > On 24/05/20 5:43 PM, Frank Millman wrote: >> On 2020-05-23 9:45 PM, DL Neil via Python-list wrote: >>> >>> My habit with SQL queries is to separate them from other code, cf the >>> usual illustration of having them 'buried' within the code, >>> immediately before, or even part of, the query call. >>> >> >> I like that idea, as I find that I am embedding more and more SQL in >> my code. >> >> How do you handle parameters? Do you leave placeholders ('?' or '%s') >> in the query, and leave it to the 'importer' of the query to figure >> out what is required? > > > Yes. Most "connector" software includes a feature which auto-magically > escapes all variable-data - a valuable safety feature! > > I've been experimenting by going further and providing app.devs with > functions/methods, a mini-API if you will. Given that many?most don't > like having to deal with SQL, the extra 'insulation' boosts my personal > popularity... > (and I need as much of that as I can get!) Ok. I will have to give it some thought. I generate most of my SQL dynamically, constructing the query programmatically using the meta-data in my system. But now I am constructing some more complex queries, which I can't generate automatically yet. I am hoping that a pattern emerges which I can use to automate them, but for now I am doing it by hand. There are a number of parameters required, and it will not be obvious at first sight what values are required. If I am going to keep the queries in a separate module, I think that I will have to provide some sort of accompanying documentation with each query explaining what the required parameters are. Thinking aloud, I may set up a separate module for the queries, but make each one a 'function', which specifies what data is required. The caller calls the function with the data as an argument, and the function uses it to build the parameter list and returns the SQL along with the parameters. The function can also contain documentation explaining how the query works. As you say, this has the benefit of separating the SQL from the Python code, so I will definitely pursue this idea. Thanks Frank From frank at chagford.com Sun May 24 04:41:36 2020 From: frank at chagford.com (Frank Millman) Date: Sun, 24 May 2020 10:41:36 +0200 Subject: Strings: double versus single quotes In-Reply-To: <2b3a4c80-7fa8-8a9f-8580-11eb88bc8deb@DancesWithMice.info> References: <20200519201043.368b6157@arcor.com> <3067f41d-43f1-1446-08b8-c4a468251782@DancesWithMice.info> <2b3a4c80-7fa8-8a9f-8580-11eb88bc8deb@DancesWithMice.info> Message-ID: <22608156-1961-5975-d21c-1adda9af4889@chagford.com> On 2020-05-24 9:58 AM, DL Neil via Python-list wrote: > On 24/05/20 5:43 PM, Frank Millman wrote: >> On 2020-05-23 9:45 PM, DL Neil via Python-list wrote: >>> >>> My habit with SQL queries is to separate them from other code, cf the >>> usual illustration of having them 'buried' within the code, >>> immediately before, or even part of, the query call. >>> >> >> I like that idea, as I find that I am embedding more and more SQL in >> my code. >> >> How do you handle parameters? Do you leave placeholders ('?' or '%s') >> in the query, and leave it to the 'importer' of the query to figure >> out what is required? > > > Yes. Most "connector" software includes a feature which auto-magically > escapes all variable-data - a valuable safety feature! > > I've been experimenting by going further and providing app.devs with > functions/methods, a mini-API if you will. Given that many?most don't > like having to deal with SQL, the extra 'insulation' boosts my personal > popularity... > (and I need as much of that as I can get!) Ok. I will have to give it some thought. I generate most of my SQL dynamically, constructing the query programmatically using the meta-data in my system. But now I am constructing some more complex queries, which I can't generate automatically yet. I am hoping that a pattern emerges which I can use to automate them, but for now I am doing it by hand. There are a number of parameters required, and it will not be obvious at first sight what values are required. If I am going to keep the queries in a separate module, I think that I will have to provide some sort of accompanying documentation with each query explaining what the required parameters are. Thinking aloud, I may set up a separate module for the queries, but make each one a 'function', which specifies what data is required. The caller calls the function with the data as an argument, and the function uses it to build the parameter list and returns the SQL along with the parameters. The function can also contain documentation explaining how the query works. As you say, this has the benefit of separating the SQL from the Python code, so I will definitely pursue this idea. Thanks Frank From genc061907 at hotmail.com Sun May 24 07:14:58 2020 From: genc061907 at hotmail.com (=?iso-8859-3?Q?H=DCSEY=A9N_KO=C7?=) Date: Sun, 24 May 2020 11:14:58 +0000 Subject: Strings: double versus single quotes In-Reply-To: <22608156-1961-5975-d21c-1adda9af4889@chagford.com> References: <20200519201043.368b6157@arcor.com> <3067f41d-43f1-1446-08b8-c4a468251782@DancesWithMice.info> <2b3a4c80-7fa8-8a9f-8580-11eb88bc8deb@DancesWithMice.info>, <22608156-1961-5975-d21c-1adda9af4889@chagford.com> Message-ID: ?ok fazla mail geliyor abonelik iptal i?in ne yapmam gerekiyor Android i?in Outlook'u edinin ________________________________ From: Python-list on behalf of Frank Millman Sent: Sunday, May 24, 2020 11:41:36 AM To: python-list at python.org Subject: Re: Strings: double versus single quotes On 2020-05-24 9:58 AM, DL Neil via Python-list wrote: > On 24/05/20 5:43 PM, Frank Millman wrote: >> On 2020-05-23 9:45 PM, DL Neil via Python-list wrote: >>> >>> My habit with SQL queries is to separate them from other code, cf the >>> usual illustration of having them 'buried' within the code, >>> immediately before, or even part of, the query call. >>> >> >> I like that idea, as I find that I am embedding more and more SQL in >> my code. >> >> How do you handle parameters? Do you leave placeholders ('?' or '%s') >> in the query, and leave it to the 'importer' of the query to figure >> out what is required? > > > Yes. Most "connector" software includes a feature which auto-magically > escapes all variable-data - a valuable safety feature! > > I've been experimenting by going further and providing app.devs with > functions/methods, a mini-API if you will. Given that many?most don't > like having to deal with SQL, the extra 'insulation' boosts my personal > popularity... > (and I need as much of that as I can get!) Ok. I will have to give it some thought. I generate most of my SQL dynamically, constructing the query programmatically using the meta-data in my system. But now I am constructing some more complex queries, which I can't generate automatically yet. I am hoping that a pattern emerges which I can use to automate them, but for now I am doing it by hand. There are a number of parameters required, and it will not be obvious at first sight what values are required. If I am going to keep the queries in a separate module, I think that I will have to provide some sort of accompanying documentation with each query explaining what the required parameters are. Thinking aloud, I may set up a separate module for the queries, but make each one a 'function', which specifies what data is required. The caller calls the function with the data as an argument, and the function uses it to build the parameter list and returns the SQL along with the parameters. The function can also contain documentation explaining how the query works. As you say, this has the benefit of separating the SQL from the Python code, so I will definitely pursue this idea. Thanks Frank -- https://eur06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-list&data=02%7C01%7C%7C7b64f6336b064514601d08d7ffbec673%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637259067140058397&sdata=icodnDnk5HSEtY8WyPBAE6qkc3KalHFf%2F5kEcLgB0Uw%3D&reserved=0 From PythonList at DancesWithMice.info Sun May 24 15:49:41 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Mon, 25 May 2020 07:49:41 +1200 Subject: Strings: double versus single quotes In-Reply-To: <22608156-1961-5975-d21c-1adda9af4889@chagford.com> References: <20200519201043.368b6157@arcor.com> <3067f41d-43f1-1446-08b8-c4a468251782@DancesWithMice.info> <2b3a4c80-7fa8-8a9f-8580-11eb88bc8deb@DancesWithMice.info> <22608156-1961-5975-d21c-1adda9af4889@chagford.com> Message-ID: <3b948437-79eb-5d25-0ce5-95cf81a92d18@DancesWithMice.info> On 24/05/20 8:41 PM, Frank Millman wrote: > On 2020-05-24 9:58 AM, DL Neil via Python-list wrote: >> On 24/05/20 5:43 PM, Frank Millman wrote: >>> On 2020-05-23 9:45 PM, DL Neil via Python-list wrote: >>>> >>>> My habit with SQL queries is to separate them from other code, cf >>>> the usual illustration of having them 'buried' within the code, >>>> immediately before, or even part of, the query call. >>>> >>> >>> I like that idea, as I find that I am embedding more and more SQL in >>> my code. >>> >>> How do you handle parameters? Do you leave placeholders ('?' or '%s') >>> in the query, and leave it to the 'importer' of the query to figure >>> out what is required? >> >> >> Yes. Most "connector" software includes a feature which auto-magically >> escapes all variable-data - a valuable safety feature! >> >> I've been experimenting by going further and providing app.devs with >> functions/methods, a mini-API if you will. Given that many?most don't >> like having to deal with SQL, the extra 'insulation' boosts my >> personal popularity... >> (and I need as much of that as I can get!) > > Ok. I will have to give it some thought. > > I generate most of my SQL dynamically, constructing the query > programmatically using the meta-data in my system. > > But now I am constructing some more complex queries, which I can't > generate automatically yet. I am hoping that a pattern emerges which I > can use to automate them, but for now I am doing it by hand. > > There are a number of parameters required, and it will not be obvious at > first sight what values are required. If I am going to keep the queries > in a separate module, I think that I will have to provide some sort of > accompanying documentation with each query explaining what the required > parameters are. > > Thinking aloud, I may set up a separate module for the queries, but make > each one a 'function', which specifies what data is required. The caller > calls the function with the data as an argument, and the function uses > it to build the parameter list and returns the SQL along with the > parameters. The function can also contain documentation explaining how > the query works. > > As you say, this has the benefit of separating the SQL from the Python > code, so I will definitely pursue this idea. We have been talking (slightly OT for thread - apologies) about the narrow sub-objectives of transferring data between a Python application and an RDBMS. May I advise consideration of the wider specification? For example, one may find it helpful to use a library/abstraction such as SQLAlchemy. Such facilitates transaction data being taken directly from/returned to a Python class! Whereas this discussion (above) only returns raw data-items, thus necessitating the application programmers coding an appropriate 'getter' to provide data to the RDBMS interface-functions, and/or a 'setter' to absorb query-results into the application's data-class(es)! Of course, there are plenty of applications where one might eschew such advantages, eg a simple interface, and at the other end of the scale: if the data were to be formatted into a pandas data-frame. Horses for courses! -- Regards =dn From souvik.viksou at gmail.com Sun May 24 00:27:03 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Sun, 24 May 2020 09:57:03 +0530 Subject: stderr writting before stdout Message-ID: Hi, Is there any precedence or priority order by which sys.stderr.write() and sys.stdout.write() works. Because when running the below code... import sys sys.stdout.write("Writting") sys.stderr.write("No errors \n") No errors is written (displayed) first and writting is written later. Why does this happen? From dylan at dje.me Sun May 24 00:49:07 2020 From: dylan at dje.me (Dylan Evans) Date: Sun, 24 May 2020 14:49:07 +1000 Subject: stderr writting before stdout In-Reply-To: References: Message-ID: Hi, This data is being line buffered, so either a newline or flush is required to get it to actually write to the terminal / file. On Sun, May 24, 2020 at 2:34 PM Souvik Dutta wrote: > Also this code maintains order i.e. writting is displayed before no errors. > Why is that? > > import sys > sys.stdout.write("Writting \n") > sys.stderr.write("No errors \n") > > On Sun, 24 May, 2020, 9:57 am Souvik Dutta, > wrote: > > > Hi, > > Is there any precedence or priority order by which sys.stderr.write() and > > sys.stdout.write() works. Because when running the below code... > > > > import sys > > sys.stdout.write("Writting") > > sys.stderr.write("No errors \n") > > > > No errors is written (displayed) first and writting is written later. Why > > does this happen? > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From rhodri at kynesim.co.uk Mon May 25 08:20:49 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 25 May 2020 13:20:49 +0100 Subject: stderr writting before stdout In-Reply-To: References: Message-ID: On 24/05/2020 05:27, Souvik Dutta wrote: > Is there any precedence or priority order by which sys.stderr.write() and > sys.stdout.write() works. No. -- Rhodri James *-* Kynesim Ltd From ciaran.hudson at gmail.com Mon May 25 14:00:27 2020 From: ciaran.hudson at gmail.com (=?UTF-8?Q?Ciar=C3=A1n_Hudson?=) Date: Mon, 25 May 2020 11:00:27 -0700 (PDT) Subject: Writing output of function to a csv file Message-ID: Hi, In the code below, which is an exercise I'm doing in class inheritance, almost everything is working except outputting my results, which as the function stock_count, to a csv. stock_count is working in the code. And I'm able to open and close the csv called cars, but the stock_count output is not being written to the file. Any suggestions? There are 2 python files as the exercise is about class inheritance. I'll paste the code from both. cars.py # Define a class for my car class Car(object): # implement the car object. def __init__(self): self.__colour = '' self.__make = '' self.__mileage = 0 self.engineSize = '' def getColour(self): return self.__colour def getMake(self): return self.__make def getMileage(self): return self.__mileage def setColour(self, colour): self.__colour = colour def setMake(self, make): self.__make = make def setMileage(self, mileage): self.__mileage = mileage def paint(self, colour): self.__colour = colour return self.__colour def move(self, distance): self.__mileage = self.__mileage + distance return self.__mileage class ElectricCar(Car): def __init__(self): self.__numberFuelCells = 1 def getNumberFuelCells(self): return self.__numberFuelCells def setNumberFuelCells(self, value): self.__numberFuelCells class PetrolCar(Car): def __init__(self): self.__choke = 0 def __getChoke(self): return self.__choke def __setChoke(self, value): self.__choke = value class DieselCar(Car): def __init__(self): self.__dpf = 0 def __getDpf(self): return self.__dpf def __setDpf(self, value): self.__dpf = value class HybridCar(Car): def __init__(self): self.__regeneration = 0 def __getRegeneration(self): return self.__regeneration def __setRegeneration(self, value): self.__regeneration = value dealership.py import csv from car import Car, ElectricCar, PetrolCar, DieselCar, HybridCar class Dealership(object): def __init__(self): self.electric_cars = [] self.petrol_cars = [] self.diesel_cars = [] self.hybrid_cars = [] def create_current_stock(self): for i in range(6): self.electric_cars.append(ElectricCar()) for i in range(20): self.petrol_cars.append(PetrolCar()) for i in range(10): self.diesel_cars.append(DieselCar()) for i in range(4): self.hybrid_cars.append(HybridCar()) def stock_count(self): print('petrol cars in stock ' + str(len(self.petrol_cars))) print('electric cars in stock ' + str(len(self.electric_cars))) print('diesel cars in stock ' + str(len(self.diesel_cars))) print('hybrid cars in stock ' + str(len(self.hybrid_cars))) def rent(self, car_list, amount): if len(car_list) < amount: print('Not enough cars in stock') return total = 0 while total < amount: car_list.pop() total = total + 1 def process_rental(self): answer = input('would you like to rent a car? y/n') if answer == 'y': self.stock_count() answer = input('what type would you like? p/e/d/h') amount = int(input('how many would you like?')) if answer == 'p': self.rent(self.petrol_cars, amount) if answer == 'd': self.rent(self.diesel_cars, amount) if answer == 'h': self.rent(self.hybrid_cars, amount) else: self.rent(self.electric_cars, amount) self.stock_count() file = open("cars.csv","w") file.write(str(self.stock_count())) file.close() dealership = Dealership() dealership.create_current_stock() proceed = 'y' while proceed == 'y': dealership.process_rental() proceed = input('continue? y/n') From python at mrabarnett.plus.com Mon May 25 14:25:08 2020 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 25 May 2020 19:25:08 +0100 Subject: Writing output of function to a csv file In-Reply-To: References: Message-ID: On 2020-05-25 19:00, Ciar?n Hudson wrote: > Hi, > > In the code below, which is an exercise I'm doing in class inheritance, almost everything is working except outputting my results, which as the function stock_count, to a csv. > stock_count is working in the code. > And I'm able to open and close the csv called cars, but the stock_count output is not being written to the file. > Any suggestions? > [snip] > > def stock_count(self): > print('petrol cars in stock ' + str(len(self.petrol_cars))) > print('electric cars in stock ' + str(len(self.electric_cars))) > print('diesel cars in stock ' + str(len(self.diesel_cars))) > print('hybrid cars in stock ' + str(len(self.hybrid_cars))) > > > def process_rental(self): > answer = input('would you like to rent a car? y/n') > if answer == 'y': > self.stock_count() > answer = input('what type would you like? p/e/d/h') > amount = int(input('how many would you like?')) > if answer == 'p': > self.rent(self.petrol_cars, amount) > if answer == 'd': > self.rent(self.diesel_cars, amount) > if answer == 'h': > self.rent(self.hybrid_cars, amount) > else: > self.rent(self.electric_cars, amount) > self.stock_count() > > file = open("cars.csv","w") > file.write(str(self.stock_count())) > file.close() > In 'stock_count' you're telling it to print to the screen. Nowhere in that function are you telling it to write to a file. From Irv at furrypants.com Mon May 25 15:31:00 2020 From: Irv at furrypants.com (Irv Kalb) Date: Mon, 25 May 2020 12:31:00 -0700 Subject: Writing output of function to a csv file In-Reply-To: References: Message-ID: <5857EF20-BFA3-4462-9900-B905A013D5F4@furrypants.com> > On May 25, 2020, at 11:25 AM, MRAB > wrote: > > On 2020-05-25 19:00, Ciar?n Hudson wrote: >> Hi, >> In the code below, which is an exercise I'm doing in class inheritance, almost everything is working except outputting my results, which as the function stock_count, to a csv. >> stock_count is working in the code. >> And I'm able to open and close the csv called cars, but the stock_count output is not being written to the file. >> Any suggestions? > [snip] >> def stock_count(self): >> print('petrol cars in stock ' + str(len(self.petrol_cars))) >> print('electric cars in stock ' + str(len(self.electric_cars))) >> print('diesel cars in stock ' + str(len(self.diesel_cars))) >> print('hybrid cars in stock ' + str(len(self.hybrid_cars))) >> def process_rental(self): >> answer = input('would you like to rent a car? y/n') >> if answer == 'y': >> self.stock_count() >> answer = input('what type would you like? p/e/d/h') >> amount = int(input('how many would you like?')) >> if answer == 'p': >> self.rent(self.petrol_cars, amount) >> if answer == 'd': >> self.rent(self.diesel_cars, amount) >> if answer == 'h': >> self.rent(self.hybrid_cars, amount) >> else: >> self.rent(self.electric_cars, amount) >> self.stock_count() >> file = open("cars.csv","w") >> file.write(str(self.stock_count())) >> file.close() >> > In 'stock_count' you're telling it to print to the screen. Nowhere in that function are you telling it to write to a file. More specifically, your main code calls the dealership.process_rental method. That method calls self.stock_count() which writes to the screen. Then, you are attempting to write the same information to a file. Your code successfully opens a file, but your next line: file.write(str(self.stock_count())) tries to take the output of that self.sock_count() and write that to the file. Your self.stock_count does not return anything, so it returns the special value: None. So, the file is created, and the only thing written to the file is None. Since this is a homework assignment, I won't show you how to do it (I am a teacher). But you need to format the information that you want to write as a string and write that to a file. From ml_news at posteo.de Mon May 25 15:50:36 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Mon, 25 May 2020 21:50:36 +0200 Subject: Writing output of function to a csv file References: Message-ID: <20200525215036.1c1573b7@arcor.com> On Mon, 25 May 2020 19:25:08 +0100 MRAB wrote: > On 2020-05-25 19:00, Ciar?n Hudson wrote: > > Hi, > > > > In the code below, which is an exercise I'm doing in class > > inheritance, almost everything is working except outputting my > > results, which as the function stock_count, to a csv. stock_count > > is working in the code. And I'm able to open and close the csv > > called cars, but the stock_count output is not being written to the > > file. Any suggestions? > [snip] > > > > def stock_count(self): > > print('petrol cars in stock ' + str(len(self.petrol_cars))) > > print('electric cars in stock ' + > > str(len(self.electric_cars))) print('diesel cars in stock ' + > > str(len(self.diesel_cars))) print('hybrid cars in stock ' + > > str(len(self.hybrid_cars))) > > > > def process_rental(self): > > answer = input('would you like to rent a car? y/n') > > if answer == 'y': > > self.stock_count() > > answer = input('what type would you like? p/e/d/h') > > amount = int(input('how many would you like?')) > > if answer == 'p': > > self.rent(self.petrol_cars, amount) > > if answer == 'd': > > self.rent(self.diesel_cars, amount) > > if answer == 'h': > > self.rent(self.hybrid_cars, amount) > > else: > > self.rent(self.electric_cars, amount) > > self.stock_count() > > > > file = open("cars.csv","w") > > file.write(str(self.stock_count())) > > file.close() > > > In 'stock_count' you're telling it to print to the screen. Nowhere in > that function are you telling it to write to a file. I think something gets written to 'cars.csv', namely the string 'None'. -- Manfred From zljubisic at gmail.com Mon May 25 16:26:12 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Mon, 25 May 2020 13:26:12 -0700 (PDT) Subject: Custom logging function Message-ID: Hi, I have a case in which I have to use custom function for logging. For example, all messages should go to stderr and end with '\r\n'. Can I somehow use standard python logging module but send all message to stderr with '\r\n' line endings? Regards From PythonList at DancesWithMice.info Mon May 25 16:49:01 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 26 May 2020 08:49:01 +1200 Subject: Custom logging function In-Reply-To: References: Message-ID: <9496ec6f-01e1-4c81-a34c-eeeb947a5cda@DancesWithMice.info> On 26/05/20 8:26 AM, zljubisic at gmail.com wrote: > Hi, > > I have a case in which I have to use custom function for logging. > For example, all messages should go to stderr and end with '\r\n'. > > Can I somehow use standard python logging module but send all message to stderr with '\r\n' line endings? - use a logging formatter (with the below, linesep) to construct log.msgs (and their endings) - use the logging library's helper function to direct log.msgs to stderr (or wherever) os.linesep in The Python Standard Library: os ? Miscellaneous operating system interfaces https://docs.python.org/3/library/os.html stderr is the default destination for logging Logging HOWTO https://docs.python.org/3/howto/logging.html https://docs.python.org/3/library/logging.html -- Regards =dn From cbdevidal.jk1 at gmail.com Mon May 25 18:18:50 2020 From: cbdevidal.jk1 at gmail.com (Christopher de Vidal) Date: Mon, 25 May 2020 18:18:50 -0400 Subject: Decorators with arguments? In-Reply-To: References: Message-ID: Peter Otten, Cameron Simpson, thank you for your detailed replies :-) I confess, I didn't quite understand all you were saying. (Still only an intermediate-level programmer.) But Cameron what you said questioning my use of decorators and maybe a class instead got me thinking. I realized what I needed was a function within a function. Couldn't have gotten there without your help. Working code: #!/usr/bin/env python3 from google.cloud import firestore import firebase_admin from firebase_admin import credentials import json import mqtt from time import sleep def bridge(col_name): def on_snapshot(col_snapshot, changes, read_time): data = dict() for doc in col_snapshot: serial = doc.id data[serial] = json.dumps(doc.to_dict()['value']) for change in changes: serial = change.document.id mqtt_topic = col_name + '/outgoing/' + serial if change.type.name in ['ADDED', 'MODIFIED']: contents = data[serial] mqtt.publish(mqtt_topic, contents) elif change.type.name == 'REMOVED': mqtt.publish(mqtt_topic, '') @mqtt.incoming def mqtt_subscribe(serial, value): # TODO Passing a None entry to delete from MQTT doesn't trigger this # callback, so it doesn't delete from Firestore. Need this ugly # workaround 'clear_mqtt'. if value == 'clear_mqtt': value = None mqtt.publish(col_name + '/incoming/' + serial, None) mqtt.publish(col_name + '/outgoing/' + serial, None) db.collection(col_name).document(serial).set({'value': value}) col_watch = db.collection(col_name).on_snapshot(on_snapshot) mqtt.subscribe(col_name + '/incoming/#', mqtt_subscribe) return col_watch cred = credentials.Certificate("certs/firebase.json") firebase_admin.initialize_app(cred) db = firestore.Client() mqtt.connect() adapters = list() for collection in ['door_status', 'cpu_temp']: adapters.append(bridge(collection)) while True: sleep(1) for adapter in adapters: adapter.unsubscribe() Christopher de Vidal Would you consider yourself a good person? Have you ever taken the 'Good Person' test? It's a fascinating five minute quiz. Google it. On Fri, May 15, 2020 at 9:55 AM Peter Otten <__peter__ at web.de> wrote: > Christopher de Vidal wrote: > > > Help please? Creating an MQTT-to-Firestore bridge and I know a decorator > > would help but I'm stumped how to create one. I've used decorators before > > but not with arguments. > > > > The Firestore collection.on_snapshot() method invokes a callback and > sends > > it three parameters (collection_snapshot, changes, and read_time). I need > > the callback to also know the name of the collection so that I can > publish > > to the equivalent MQTT topic name. I had thought to add a fourth > parameter > > and I believe a decorator is the right approach but am stumped how to add > > that fourth parameter. How would I do this with the code below? > > > > #!/usr/bin/env python3 > > from google.cloud import firestore > > import firebase_admin > > from firebase_admin import credentials > > import json > > import mqtt > > > > > > firebase_admin.initialize_app(credentials.Certificate("certs/firebase.json")) > > db = firestore.Client() > > mqtt.connect() > > > > > > def load_json(contents): > > try: > > return json.loads(contents) > > except (json.decoder.JSONDecodeError, TypeError): > > return contents > > > > > > def on_snapshot(col_name, col_snapshot, changes, read_time): > > data = dict() > > for doc in col_snapshot: > > serial = doc.id > > contents = load_json(doc.to_dict()['value']) > > data[serial] = contents > > for change in changes: > > serial = change.document.id > > mqtt_topic = col_name + '/' + serial > > contents = data[serial] > > if change.type.name in ['ADDED', 'MODIFIED']: > > mqtt.publish(mqtt_topic, contents) > > elif change.type.name == 'REMOVED': > > mqtt.publish(mqtt_topic, None) > > > > > > # Start repeated code section > > # TODO Better to use decorators but I was stumped on how to pass > arguments > > def door_status_on_snapshot(col_snapshot, changes, read_time): > > on_snapshot('door_status', col_snapshot, changes, read_time) > > > > > > door_status_col_ref = db.collection('door_status') > > door_status_col_watch = > > door_status_col_ref.on_snapshot(door_status_on_snapshot) > > > > # Repetition... > > def cpu_temp_on_snapshot(col_snapshot, changes, read_time): > > on_snapshot('cpu_temp', col_snapshot, changes, read_time) > > > > > > cpu_temp_col_ref = db.collection('cpu_temp') > > cpu_temp_col_watch = cpu_temp_col_ref.on_snapshot(cpu_temp_on_snapshot) > > # End repeated code section > > > > # Start repeated code section > > door_status_col_watch.unsubscribe() > > cpu_temp_col_watch.unsubscribe() > > # Repetition... > > # End repeated code section > > > > Christopher de Vidal > > You might also consider a contextmanager: > > https://docs.python.org/3/library/contextlib.html > > # untested > > @contextmanager > def subscribe(name, col_snapshot, changes, read_time): > def status_on_snapshot(col_snapshot, changes, read_time): > on_snapshot(name, col_snapshot, changes, read_time) > > status_col_ref = db.collection(name) > status_col_watch = status_col_ref.on_snapshot(door_status_on_snapshot) > try: > yield status_col_ref > finally: > status_col_watch.unsubscribe() > > > with subscribe("door_status", ...) as door_status_col_ref: > with subscribe("cpu_temp", ...) as cpu_temp_col_ref: > ... > > > If there are many uniform ones the nested with statements can be > generalized: > > NAMES = "door_status", "cpu_temp", ... > with ExitStack() as stack: > col_refs = [ > stack.enter_context(subscribe(name)) for name in NAMES > ] > > And if you like Camoron's suggestion or the subscribe() generator above > just > gets too unwieldy: a custom class can act as a contextmanager, too. > > https://docs.python.org/3/reference/compound_stmts.html#with > > -- > https://mail.python.org/mailman/listinfo/python-list > From benjamin at schollnick.net Mon May 25 19:35:24 2020 From: benjamin at schollnick.net (Benjamin Schollnick) Date: Mon, 25 May 2020 19:35:24 -0400 Subject: Managing plug-ins In-Reply-To: <5f6a0ccf-7210-d0ec-463a-644232201c8b@etelligence.info> References: <5f6a0ccf-7210-d0ec-463a-644232201c8b@etelligence.info> Message-ID: <7B51AC8A-A69C-4BD6-8AC7-E11132BB6E40@schollnick.net> Did you ever find anything that met your requirements? If not, I have a prototype that I need to build out some more? https://github.com/bschollnick/PyPlugInMgr I use it for some home grown utilities, but it needs to be fleshed out some more? If you?re interested feel free to take a look. - Benjamin > On Feb 23, 2020, at 5:45 PM, DL Neil via Python-list wrote: > > Please recommend a library which will manage plug-ins. > > > (Regret that searching PyPi or using a web SE results in an overwhelming number of 'false positives') > > Not wanting to 'reinvent the wheel, have been looking for an 'approved' way to manage a set of previously-prepared routines plus user-added functionality: > - user selects particular type of analysis (cmdLN) > - take that string and convert to a function/method > - 'plug-in' code could be located within application > - 'plug-in' could be 'included' from user > - interface standardisation/checking not part of question > - Python3 > > Application is statistical analysis. Users want to control aspects such as data selection/inclusion policies, other data pre-processing/massaging, distribution curve to be applied, and similar. > NB not looking for stats-code, but to easily manage a range of plug-ins from which users may select to suit their particular research objective. > -- > Regards, > =dn > -- > https://mail.python.org/mailman/listinfo/python-list From ciaran.hudson at gmail.com Mon May 25 18:05:12 2020 From: ciaran.hudson at gmail.com (=?UTF-8?Q?Ciar=C3=A1n_Hudson?=) Date: Mon, 25 May 2020 15:05:12 -0700 (PDT) Subject: Writing output of function to a csv file In-Reply-To: References: Message-ID: Thanks, between this message and the one below I was able to understand my error and fix it. I really appreciate the help. From PythonList at DancesWithMice.info Mon May 25 21:08:06 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Tue, 26 May 2020 13:08:06 +1200 Subject: Managing plug-ins In-Reply-To: <7B51AC8A-A69C-4BD6-8AC7-E11132BB6E40@schollnick.net> References: <5f6a0ccf-7210-d0ec-463a-644232201c8b@etelligence.info> <7B51AC8A-A69C-4BD6-8AC7-E11132BB6E40@schollnick.net> Message-ID: <4c5959d2-504c-143a-a0ad-ac45fffd342d@DancesWithMice.info> On 26/05/20 11:35 AM, Benjamin Schollnick wrote: > Did you ever find anything that met your requirements? > > If not, I have a prototype that I need to build out some more? > > https://github.com/bschollnick/PyPlugInMgr > > I use it for some home grown utilities, but it needs to be fleshed out > some more? > If you?re interested feel free to take a look. Thanks. Am on-the-road at present, but will take a look... -- Regards =dn From __peter__ at web.de Tue May 26 04:04:29 2020 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 May 2020 10:04:29 +0200 Subject: Custom logging function References: Message-ID: zljubisic at gmail.com wrote: > Hi, > > I have a case in which I have to use custom function for logging. > For example, all messages should go to stderr and end with '\r\n'. > > Can I somehow use standard python logging module but send all message to > stderr with '\r\n' line endings? Isn't that the default for windows? For unix you can reconfigure stdout sys.stdout.reconfigure(newline="\r\n") or set the terminator attribute of the handler: >>> import logging Here we should build a stream handler explicitly -- but I'm lazy and modify the one created by basicConfig(). >>> logging.basicConfig() >>> [handler] = logging.getLogger().handlers >>> handler.terminator '\n' >>> logging.warning("Default line endings.") WARNING:root:Default line endings. Let's choose something fancy so that you can see the effect: >>> handler.terminator = " -- here be dragons\r\n" >>> logging.warning("Unusual line endings.") WARNING:root:Unusual line endings. -- here be dragons From blindanagram at nowhere.com Tue May 26 10:56:02 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Tue, 26 May 2020 15:56:02 +0100 Subject: Behaviour of os.path.join Message-ID: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> I came across an issue that I am wondering whether I should report as an issue. If I have a directory, say: base='C:\\Documents' and I use os.path.join() as follows: join(base, '..\\..\\', 'build', '') I obtain as expected from the documentation: 'C:\\Documents\\..\\..\\build\\' But if I try to make the directory myself (as I tried first): join(base, '..\\..\\', 'build', '\\') I obtain: 'C:\\' The documentation says that an absolute path in the parameter list for join will discard all previous parameters but '\\' is not an absoute path! Moreover, if I use join(base, '..\\..\\', 'build', os.sep) I get the same result. This seems to me to be a bug that I should report but to avoid wasting developer time I wanted to hear what others feel about this. From ben.usenet at bsb.me.uk Tue May 26 11:22:27 2020 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Tue, 26 May 2020 16:22:27 +0100 Subject: Behaviour of os.path.join References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: <87tv02pvpo.fsf@bsb.me.uk> BlindAnagram writes: > I came across an issue that I am wondering whether I should report as an > issue. If I have a directory, say: > > base='C:\\Documents' > > and I use os.path.join() as follows: > > join(base, '..\\..\\', 'build', '') It rather defeats the purpose of os.sep if you include it in a part of the path. What you mean is better expressed as join(base, '..', '..', 'build', '') (and base includes it too, but I can't suggest an alternative because I don't know your intent is far as defaults go.) > The documentation says that an absolute path in the parameter list for > join will discard all previous parameters but '\\' is not an absoute > path! I think it is. The picture is messy on Windows (because of the drive letter) but absolute paths are usually taken to be those that start with a path separator. -- Ben. From blindanagram at nowhere.com Tue May 26 11:48:59 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Tue, 26 May 2020 16:48:59 +0100 Subject: Behaviour of os.path.join In-Reply-To: <87tv02pvpo.fsf@bsb.me.uk> References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <87tv02pvpo.fsf@bsb.me.uk> Message-ID: On 26/05/2020 16:22, Ben Bacarisse wrote: > BlindAnagram writes: > >> I came across an issue that I am wondering whether I should report as an >> issue. If I have a directory, say: >> >> base='C:\\Documents' >> >> and I use os.path.join() as follows: >> >> join(base, '..\\..\\', 'build', '') > > It rather defeats the purpose of os.sep if you include it in a part of > the path. What you mean is better expressed as > > join(base, '..', '..', 'build', '') > > (and base includes it too, but I can't suggest an alternative because I > don't know your intent is far as defaults go.) Thanks for your input but while that part of my path may not be to your liking, it works fine and does not seem to be relevant to my concern, which is that join appears to treat os.sep as an absolute path, which it is not. From blindanagram at nowhere.com Tue May 26 11:52:10 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Tue, 26 May 2020 16:52:10 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: <58CdnW9-SdC2plDDnZ2dnUU78RGdnZ2d@brightview.co.uk> On 26/05/2020 16:25, Stefan Ram wrote: > BlindAnagram writes: >> The documentation says that an absolute path in the parameter list for >> join will discard all previous parameters but '\\' is not an absoute path! > > The source code for "join" in "ntpath.py" does not seem to > bother to call "is_absolute". Instead it contains (simplified): > > seps = '\\/' > if p_path and p_path[0] in seps: > # Second path is absolute Thanks, that seems to confirm this as a bug. From mats at python.org Tue May 26 11:59:59 2020 From: mats at python.org (Mats Wichmann) Date: Tue, 26 May 2020 09:59:59 -0600 Subject: Behaviour of os.path.join In-Reply-To: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: On 5/26/20 8:56 AM, BlindAnagram wrote: > I came across an issue that I am wondering whether I should report as an > issue. If I have a directory, say: > > base='C:\\Documents' > > and I use os.path.join() as follows: > > join(base, '..\\..\\', 'build', '') > > I obtain as expected from the documentation: > > 'C:\\Documents\\..\\..\\build\\' > > But if I try to make the directory myself (as I tried first): > > join(base, '..\\..\\', 'build', '\\') > > I obtain: > > 'C:\\' > > The documentation says that an absolute path in the parameter list for > join will discard all previous parameters but '\\' is not an absoute path! But it is - an absolute path is one that starts with the pathname separator. The concept of paths is ugly in Windows because of the drive letter - a drive letter is not actually part of a path, it's an additional piece of context. If you leave out the drive letter, your path is relative or absolute within the current drive letter; if you include it your path is relative or absolute within the specified drive letter. So Python has behaved as documented here: the indicator for an absolute path has discarded everything (except the drive letter, which is necessary to maintain the context you provided) which came before it in the join. If indeed you're seeking a path that is terminated by the separator character, you need to do what you did in the first example - join an empty string at the end (this is documented). The terminating separator _usually_ isn't needed. Sadly, sometimes it appears to be... From python at mrabarnett.plus.com Tue May 26 12:46:34 2020 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 26 May 2020 17:46:34 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <87tv02pvpo.fsf@bsb.me.uk> Message-ID: <4bcbcff3-b339-b3c0-e54d-4b3238fbeb0d@mrabarnett.plus.com> On 2020-05-26 16:48, BlindAnagram wrote: > On 26/05/2020 16:22, Ben Bacarisse wrote: >> BlindAnagram writes: >> >>> I came across an issue that I am wondering whether I should report as an >>> issue. If I have a directory, say: >>> >>> base='C:\\Documents' >>> >>> and I use os.path.join() as follows: >>> >>> join(base, '..\\..\\', 'build', '') >> >> It rather defeats the purpose of os.sep if you include it in a part of >> the path. What you mean is better expressed as >> >> join(base, '..', '..', 'build', '') >> >> (and base includes it too, but I can't suggest an alternative because I >> don't know your intent is far as defaults go.) > > Thanks for your input but while that part of my path may not be to your > liking, it works fine and does not seem to be relevant to my concern, > which is that join appears to treat os.sep as an absolute path, which it > is not. > If it starts with the path separator, then it's absolute (well, absolute on that drive). Open a Command Prompt window and it'll open in the %HOME% folder. Then type "cd \" and it'll put you in the root folder. From blindanagram at nowhere.com Tue May 26 12:57:54 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Tue, 26 May 2020 17:57:54 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: On 26/05/2020 16:59, Mats Wichmann wrote: > On 5/26/20 8:56 AM, BlindAnagram wrote: >> I came across an issue that I am wondering whether I should report as an >> issue. If I have a directory, say: >> >> base='C:\\Documents' >> >> and I use os.path.join() as follows: >> >> join(base, '..\\..\\', 'build', '') >> >> I obtain as expected from the documentation: >> >> 'C:\\Documents\\..\\..\\build\\' >> >> But if I try to make the directory myself (as I tried first): >> >> join(base, '..\\..\\', 'build', '\\') >> >> I obtain: >> >> 'C:\\' >> >> The documentation says that an absolute path in the parameter list for >> join will discard all previous parameters but '\\' is not an absoute path! > > But it is - an absolute path is one that starts with the pathname separator. On Windows, when part of a string representing a file or directory path, '\\' acts as a directory separator. It may imply, as you say, that it is a path on the current drive but it also behaves as a move to a sub-directory of what has appeared to its left. And this is how it is treated in other os.path functions. For example: base = "C:\\Documents\\Finance\\" abspath(base) 'C:\\Documents\\Finance' where it can be seen that '\\' is being treated as a directory separator. In my view it is not sensible to have some functions treating '\\' in one way and others differently. I would hence expect join() to accept '\\' as an addition to a file path on Windows and not a signal of an absolute path. > The concept of paths is ugly in Windows because of the drive letter - a > drive letter is not actually part of a path, it's an additional piece of > context. If you leave out the drive letter, your path is relative or > absolute within the current drive letter; if you include it your path is > relative or absolute within the specified drive letter. So Python has > behaved as documented here: the indicator for an absolute path has > discarded everything (except the drive letter, which is necessary to > maintain the context you provided) which came before it in the join. > > If indeed you're seeking a path that is terminated by the separator > character, you need to do what you did in the first example - join an > empty string at the end (this is documented). The terminating separator > _usually_ isn't needed. Sadly, sometimes it appears to be... I agree that handling file paths on Windows is very ugly, especially so if some of the directory/file names include spaces. But I don't see that as an excuse for this specific ambiguity in Python in the handling of '\\' when embedded in, or added to, paths. From blindanagram at nowhere.com Tue May 26 13:01:16 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Tue, 26 May 2020 18:01:16 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: On 26/05/2020 17:09, Stefan Ram wrote: > Mats Wichmann writes: >> an absolute path is one that starts with the pathname separator. > > The Python Library Reference does not use the term > "pathname separator". It uses "directory separator" > (os.sep) and "filename separator" ('/' on Unix). > > On Windows: > > |>>> import pathlib > |>>> import os > |>>> pathlib.PureWindowsPath('\\').is_absolute() > |False > |>>> pathlib.PureWindowsPath(os.sep).is_absolute() > |False > |>>> pathlib.PureWindowsPath('/').is_absolute() > |False Thanks, that seems to suggest that there is an issue and that I should hence submit this as an issue. From blindanagram at nowhere.com Tue May 26 13:07:14 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Tue, 26 May 2020 18:07:14 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <87tv02pvpo.fsf@bsb.me.uk> <4bcbcff3-b339-b3c0-e54d-4b3238fbeb0d@mrabarnett.plus.com> Message-ID: On 26/05/2020 17:46, MRAB wrote: > On 2020-05-26 16:48, BlindAnagram wrote: >> On 26/05/2020 16:22, Ben Bacarisse wrote: >>> BlindAnagram writes: >>> >>>> I came across an issue that I am wondering whether I should report >>>> as an >>>> issue.? If I have a directory, say: >>>> >>>> ? base='C:\\Documents' >>>> >>>> and I use os.path.join() as follows: >>>> >>>> ? join(base, '..\\..\\', 'build', '') >>> >>> It rather defeats the purpose of os.sep if you include it in a part of >>> the path.? What you mean is better expressed as >>> >>> ? join(base, '..', '..', 'build', '') >>> >>> (and base includes it too, but I can't suggest an alternative because I >>> don't know your intent is far as defaults go.) >> >> Thanks for your input but while that part of my path may not be to your >> liking, it works fine and does not seem to be relevant to my concern, >> which is that join appears to treat os.sep as an absolute path, which it >> is not. >> > If it starts with the path separator, then it's absolute (well, absolute > on that drive). Agreed. I did not think that I needed to add this exception to my comment as I thought from the the context that it would be clear that I was questioning how it worked at the end of a path, not when used at its start. From rhodri at kynesim.co.uk Tue May 26 13:18:54 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 26 May 2020 18:18:54 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: <81974684-150a-e18f-ae79-0844bb722c67@kynesim.co.uk> On 26/05/2020 18:01, BlindAnagram wrote: > On 26/05/2020 17:09, Stefan Ram wrote: >> Mats Wichmann writes: >>> an absolute path is one that starts with the pathname separator. >> >> The Python Library Reference does not use the term >> "pathname separator". It uses "directory separator" >> (os.sep) and "filename separator" ('/' on Unix). >> >> On Windows: >> >> |>>> import pathlib >> |>>> import os >> |>>> pathlib.PureWindowsPath('\\').is_absolute() >> |False >> |>>> pathlib.PureWindowsPath(os.sep).is_absolute() >> |False >> |>>> pathlib.PureWindowsPath('/').is_absolute() >> |False > > Thanks, that seems to suggest that there is an issue and that I should > hence submit this as an issue. It is indeed most curious as to why this obviously absolute path is not recognised as such :-) -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Tue May 26 13:23:34 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 26 May 2020 18:23:34 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <87tv02pvpo.fsf@bsb.me.uk> <4bcbcff3-b339-b3c0-e54d-4b3238fbeb0d@mrabarnett.plus.com> Message-ID: <1c2a910f-9dd4-d958-1819-5fe007edd836@kynesim.co.uk> On 26/05/2020 18:07, BlindAnagram wrote: > On 26/05/2020 17:46, MRAB wrote: >> On 2020-05-26 16:48, BlindAnagram wrote: >>> On 26/05/2020 16:22, Ben Bacarisse wrote: >>>> BlindAnagram writes: >>>> >>>>> I came across an issue that I am wondering whether I should report >>>>> as an >>>>> issue.? If I have a directory, say: >>>>> >>>>> ? base='C:\\Documents' >>>>> >>>>> and I use os.path.join() as follows: >>>>> >>>>> ? join(base, '..\\..\\', 'build', '') >>>> >>>> It rather defeats the purpose of os.sep if you include it in a part of >>>> the path.? What you mean is better expressed as >>>> >>>> ? join(base, '..', '..', 'build', '') >>>> >>>> (and base includes it too, but I can't suggest an alternative because I >>>> don't know your intent is far as defaults go.) >>> >>> Thanks for your input but while that part of my path may not be to your >>> liking, it works fine and does not seem to be relevant to my concern, >>> which is that join appears to treat os.sep as an absolute path, which it >>> is not. >>> >> If it starts with the path separator, then it's absolute (well, absolute >> on that drive). > > Agreed. I did not think that I needed to add this exception to my > comment as I thought from the the context that it would be clear that I > was questioning how it worked at the end of a path, not when used at its > start. But you aren't talking about the end of the (finished) path, you are talking about the start of the final path component you pass to os.path.join(), "\\". As the documentation says, "If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component." Since "\\" is an absolute path component, all the previous components are thrown away and you are left with just "\\". -- Rhodri James *-* Kynesim Ltd From blindanagram at nowhere.com Tue May 26 13:23:50 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Tue, 26 May 2020 18:23:50 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: On 26/05/2020 16:59, Mats Wichmann wrote: > On 5/26/20 8:56 AM, BlindAnagram wrote: >> I came across an issue that I am wondering whether I should report as an >> issue. If I have a directory, say: >> >> base='C:\\Documents' >> >> and I use os.path.join() as follows: >> >> join(base, '..\\..\\', 'build', '') >> >> I obtain as expected from the documentation: >> >> 'C:\\Documents\\..\\..\\build\\' >> >> But if I try to make the directory myself (as I tried first): >> >> join(base, '..\\..\\', 'build', '\\') >> >> I obtain: >> >> 'C:\\' >> >> The documentation says that an absolute path in the parameter list for >> join will discard all previous parameters but '\\' is not an absoute path! > > But it is - an absolute path is one that starts with the pathname separator. In a string giving a file path on Windows '\\' is recognised as a separator between directories and not as an indicator that what follows is an absolute path based on the drive letter (although it might, as you say, imply a drive context). > The concept of paths is ugly in Windows because of the drive letter - a > drive letter is not actually part of a path, it's an additional piece of > context. If you leave out the drive letter, your path is relative or > absolute within the current drive letter; if you include it your path is > relative or absolute within the specified drive letter. So Python has > behaved as documented here: the indicator for an absolute path has > discarded everything (except the drive letter, which is necessary to > maintain the context you provided) which came before it in the join. This is not consistent with how other file management functions in os.path operate since they willingly accept '\\' as a directory separator. > If indeed you're seeking a path that is terminated by the separator > character, you need to do what you did in the first example - join an > empty string at the end (this is documented). The terminating separator > _usually_ isn't needed. Sadly, sometimes it appears to be... From meetsai2004 at gmail.com Tue May 26 10:45:15 2020 From: meetsai2004 at gmail.com (Meet Agrawal) Date: Tue, 26 May 2020 20:15:15 +0530 Subject: Issues regarding running of application. Message-ID: I have tried and installed the python application a lot of times but after the installation get completed and I try to run the application, it say that api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. Please tell me a way out. From mats at wichmann.us Tue May 26 13:51:46 2020 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 26 May 2020 11:51:46 -0600 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: On 5/26/20 10:57 AM, BlindAnagram wrote: > On 26/05/2020 16:59, Mats Wichmann wrote: >> On 5/26/20 8:56 AM, BlindAnagram wrote: >>> I came across an issue that I am wondering whether I should report as an >>> issue. If I have a directory, say: >>> >>> base='C:\\Documents' >>> >>> and I use os.path.join() as follows: >>> >>> join(base, '..\\..\\', 'build', '') >>> >>> I obtain as expected from the documentation: >>> >>> 'C:\\Documents\\..\\..\\build\\' >>> >>> But if I try to make the directory myself (as I tried first): >>> >>> join(base, '..\\..\\', 'build', '\\') >>> >>> I obtain: >>> >>> 'C:\\' >>> >>> The documentation says that an absolute path in the parameter list for >>> join will discard all previous parameters but '\\' is not an absoute path! >> >> But it is - an absolute path is one that starts with the pathname separator. > > On Windows, when part of a string representing a file or directory path, > '\\' acts as a directory separator. It may imply, as you say, that it > is a path on the current drive but it also behaves as a move to a > sub-directory of what has appeared to its left. And this is how it is > treated in other os.path functions. For example: > > base = "C:\\Documents\\Finance\\" > abspath(base) > 'C:\\Documents\\Finance' > > where it can be seen that '\\' is being treated as a directory > separator. In my view it is not sensible to have some functions > treating '\\' in one way and others differently. I would hence expect > join() to accept '\\' as an addition to a file path on Windows and not > a signal of an absolute path. Unlike the string join method, which would behave as you seem to want, the os.path.join method "knows" it is working on paths, so it's going to assign some meaning to the content of the pieces. If it was up to me I might not have chosen the approach Python did of "if we see a piece that looks like an absolute path, discard what came before", but that's the one that was chosen, presumably for good reasons, and it is so documented. And the pathlib library module chose to retain that behavior: "When several absolute paths are given, the last is taken as an anchor (mimicking os.path.join()?s behaviour)". So it's just something to get used to? From mats at wichmann.us Tue May 26 13:58:13 2020 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 26 May 2020 11:58:13 -0600 Subject: Issues regarding running of application. In-Reply-To: References: Message-ID: <461e8f59-645e-ea36-bfaf-8d001b9cbd03@wichmann.us> On 5/26/20 8:45 AM, Meet Agrawal wrote: > I have tried and installed the python application a lot of times but after > the installation get completed and I try to run the application, it say > that api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. > > Please tell me a way out. Install it? If you're not on Windows 10, this needs to be installed, and the side effect is that your install may need to take place with elevated privilege. === Recent versions of Python for Windows are built with a recent Microsoft build toolchain. Since the Python binary itself is a C-language application, it is automatically linked with the MS C runtime. That library, of the correct version, is a part of an up-to-date Windows 10, but has to be installed as an update on Win 7/8.1. Microsoft's package for that is included in the Python installer, but introduces a host of problems: it must be installed using elevated privilege (even though Python itself does not require this), and in general those kinds of packages only install if "everything is right" - if the MS installation subsystem thinks you are not up to date, for example, it may well give up. Sometimes it seems like if the phase of the moon is wrong, it gives up. This isn't unique to Python, by the way. Step one is to try an install with elevated privilege - the new Python installers default to installing at just user privilege level, so you need to go to advanced settings and tick a box. If that's not enough, look at this note from a different project suffering the same problems which proposes a solution: https://www.smartftp.com/support/kb/the-program-cant-start-because-api-ms-win-crt-runtime-l1-1-0dll-is-missing-f2702.html From blindanagram at nowhere.com Tue May 26 14:44:20 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Tue, 26 May 2020 19:44:20 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: On 26/05/2020 18:51, Mats Wichmann wrote: > On 5/26/20 10:57 AM, BlindAnagram wrote: >> On 26/05/2020 16:59, Mats Wichmann wrote: >>> On 5/26/20 8:56 AM, BlindAnagram wrote: >>>> I came across an issue that I am wondering whether I should report as an >>>> issue. If I have a directory, say: >>>> >>>> base='C:\\Documents' >>>> >>>> and I use os.path.join() as follows: >>>> >>>> join(base, '..\\..\\', 'build', '') >>>> >>>> I obtain as expected from the documentation: >>>> >>>> 'C:\\Documents\\..\\..\\build\\' >>>> >>>> But if I try to make the directory myself (as I tried first): >>>> >>>> join(base, '..\\..\\', 'build', '\\') >>>> >>>> I obtain: >>>> >>>> 'C:\\' >>>> >>>> The documentation says that an absolute path in the parameter list for >>>> join will discard all previous parameters but '\\' is not an absoute path! >>> >>> But it is - an absolute path is one that starts with the pathname separator. >> >> On Windows, when part of a string representing a file or directory path, >> '\\' acts as a directory separator. It may imply, as you say, that it >> is a path on the current drive but it also behaves as a move to a >> sub-directory of what has appeared to its left. And this is how it is >> treated in other os.path functions. For example: >> >> base = "C:\\Documents\\Finance\\" >> abspath(base) >> 'C:\\Documents\\Finance' >> >> where it can be seen that '\\' is being treated as a directory >> separator. In my view it is not sensible to have some functions >> treating '\\' in one way and others differently. I would hence expect >> join() to accept '\\' as an addition to a file path on Windows and not >> a signal of an absolute path. > > Unlike the string join method, which would behave as you seem to want, > the os.path.join method "knows" it is working on paths, so it's going to > assign some meaning to the content of the pieces. If it was up to me I > might not have chosen the approach Python did of "if we see a piece that > looks like an absolute path, discard what came before", but that's the > one that was chosen, presumably for good reasons, and it is so > documented. And the pathlib library module chose to retain that > behavior: "When several absolute paths are given, the last is taken as > an anchor (mimicking os.path.join()?s behaviour)". So it's just > something to get used to? I agree with much of what you say. But I believe that it is more natural and less 'dangerous' when a functions behaviour matches that which its name implies, that is, to join things together, not to throw one of them away! And, I don't presume that there were good reasons since it might simply have been an oversight, which is why I raised it (even Python developers are not perfect :-) From hfm_a at yahoo.com Tue May 26 14:13:38 2020 From: hfm_a at yahoo.com (R. A. Hoffman) Date: Tue, 26 May 2020 18:13:38 +0000 (UTC) Subject: Phyton 32 or 64 bit? References: <1070312794.1496644.1590516818712.ref@mail.yahoo.com> Message-ID: <1070312794.1496644.1590516818712@mail.yahoo.com> Good afternoon, ? Please forgive what may be a stupid question. I?m an absolute beginner and downloaded Python 3.8 for 32bits. I?m running Windows 10 on 64bit machine. ? Question 1?: is it OK to run Python (32 bits) on my machine?? ? Question 2?: The download went fine. How do I go from here to install and run Python?? ? Sorry for the dumb questions. Thanks for any help. ? From python at mrabarnett.plus.com Tue May 26 15:26:44 2020 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 26 May 2020 20:26:44 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <87tv02pvpo.fsf@bsb.me.uk> Message-ID: On 2020-05-26 16:52, Dennis Lee Bieber wrote: > On Tue, 26 May 2020 16:22:27 +0100, Ben Bacarisse > declaimed the following: > >>I think it is. The picture is messy on Windows (because of the drive >>letter) but absolute paths are usually taken to be those that start with >>a path separator. > > The drive letter is only required if one needs to access something that > is not on the "currently logged drive". Compare: > [snip] > > I'd also like to point out that the nasty "\\" is not needed. Windows > API understands "/" -- it is only the command line "DOS" shell that > requires back-slash (since / is used for command options, Powershell is > happy with / since options are prefixed with - ). > Dialog windows, e.g. Open and Save dialogs, also require backslashes. [snip] From python at mrabarnett.plus.com Tue May 26 15:38:15 2020 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 26 May 2020 20:38:15 +0100 Subject: Phyton 32 or 64 bit? In-Reply-To: <1070312794.1496644.1590516818712@mail.yahoo.com> References: <1070312794.1496644.1590516818712.ref@mail.yahoo.com> <1070312794.1496644.1590516818712@mail.yahoo.com> Message-ID: <28b154bb-ad94-8f60-710c-765b89fc3e7f@mrabarnett.plus.com> On 2020-05-26 19:13, R. A. Hoffman via Python-list wrote: > > Good afternoon, > > > > Please forgive what may be a stupid question. I?m an absolute beginner and downloaded Python 3.8 for 32bits. I?m running Windows 10 on 64bit machine. > > > > Question 1?: is it OK to run Python (32 bits) on my machine?? > The 32-bit version will run on both 32-bit and 64-bit machines. If you're intending to work with many gigs of RAM then you'd need the 64-bit version, otherwise the 32-bit version is fine. > > > Question 2?: The download went fine. How do I go from here to install and run Python?? > What exactly did you download? If it's the "executable installer", then just run it to install Python. > > > Sorry for the dumb questions. Thanks for any help. > From PythonList at DancesWithMice.info Tue May 26 15:56:54 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Wed, 27 May 2020 07:56:54 +1200 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: <77afaaea-ea11-5ab4-1780-c62cb61d5405@DancesWithMice.info> On 27/05/20 5:23 AM, BlindAnagram wrote: > On 26/05/2020 16:59, Mats Wichmann wrote: >> On 5/26/20 8:56 AM, BlindAnagram wrote: >>> I came across an issue that I am wondering whether I should report as an >>> issue. If I have a directory, say: >>> >>> base='C:\\Documents' >>> >>> and I use os.path.join() as follows: >>> >>> join(base, '..\\..\\', 'build', '') >>> >>> I obtain as expected from the documentation: >>> >>> 'C:\\Documents\\..\\..\\build\\' >>> >>> But if I try to make the directory myself (as I tried first): >>> >>> join(base, '..\\..\\', 'build', '\\') >>> >>> I obtain: >>> >>> 'C:\\' >>> >>> The documentation says that an absolute path in the parameter list for >>> join will discard all previous parameters but '\\' is not an absoute path! >> >> But it is - an absolute path is one that starts with the pathname separator. > > In a string giving a file path on Windows '\\' is recognised as a > separator between directories and not as an indicator that what follows > is an absolute path based on the drive letter (although it might, as you > say, imply a drive context). [some of this answer may appear 'obvious' to you. If so, please understand that this conversation has the side-benefit of assisting other readers to understand Python, and that I would not presume to 'talk down' to you-personally] Using the docs: <<< os.path.join(path, *paths) Join one or more path components intelligently. The return value is the concatenation of path and any members of *paths with exactly one directory separator (os.sep) following each non-empty part except the last, meaning that the result will only end in a separator if the last part is empty. If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component. On Windows... [previously discussed] >>> https://docs.python.org/3/library/os.path.html Let's start with the word "intelligently". Some might assume this to mean that it will distinguish between "separator between directories" and "absolute path". However, what it means is that it will select either the POSIX or the MS-Windows character(s) - depending upon whether the final-application is running on your machine or mine! It also means, that it expects to handle the assembly of the parameters into a single path (utilising the appropriate separator). Please be advised that the pathlib library and pathlike interface were added quite recently, and largely because the os library is considered dated. Accordingly, please don't attempt to draw parallels or 'rules' by comparing the under-pinning philosophies of 'past' with 'future'. Remember that Python does not define files, paths, directories (folders), and backing-store structures; and as observed, they differ between OpSys. The os and os.path libraries exist to help us (poor, long-suffering coders) to cope with the differences. Accordingly, in Python, we do not deal with the file system itself, but we code to an abstraction of a file system! Python's interpreter handles 'the real situation' at run-time. (thank you Python!) Please review the os library (https://docs.python.org/3/library/os.html). There (amongst other very useful facilities) you will find such as os.sep (and various other os.*seps which illustrate how difficult it is to harmonise the abstraction to cope with the various realities). Note also, the warning (which applies both to 'construction' and 'separation' of paths from path-components). Further reading? Because Python doesn't really define "path", let's turn to https://en.wikipedia.org/wiki/Path_%28computing%29 - but keep a headache remedy to-hand! This article provides such understandings as "path", "root", and "device" (the latter not existing in POSIX systems), per a range of operating systems. OK, after all that, back to the question:- Please examine the 'signature' of -join(): os.path.join(path, *paths) notice that the arguments are path[s] - NOT file-names, NOT directories (folders), and NOT path-components. Remember also the word "intelligent". The objective of the function is to create a legal AND OpSys-appropriate path, by joining other *path(s)* together. Accordingly, the function considers each parameter to be a path. A path commencing with the symbol indicating the "root" is considered an "absolute path". A path commencing with a character (etc) is considered a "relative path". [Apologies, in that experienced pythonista will find this 'stating the obvious', but learners often do not find such differences, immediately apparent] This may explain why the OP's use of, or interpretation of, arguments to the function, differs from that of the library. Why a subsequent parameter, interpreted as an absolute-path, should cause all previous parameters to be 'thrown away' is an implementation detail - and I can't explain that choice, except to say that because some systems use the same character to represent the "root" directory as they do for the path-component separator, there are situations where the two could be confused - whether this happens on MS-Windows (or not) is besides the point when dealing with the Python file-system 'abstraction' functions! IMHO: the best way to use -join() is not to mix its 'intelligence' with (OpSys-specific) string-literal separator characters of my own. (even though I am (so much) smarter than it. Hah!) >> The concept of paths is ugly in Windows because of the drive letter - a >> drive letter is not actually part of a path, it's an additional piece of >> context. If you leave out the drive letter, your path is relative or >> absolute within the current drive letter; if you include it your path is >> relative or absolute within the specified drive letter. So Python has >> behaved as documented here: the indicator for an absolute path has >> discarded everything (except the drive letter, which is necessary to >> maintain the context you provided) which came before it in the join. > > This is not consistent with how other file management functions in > os.path operate since they willingly accept '\\' as a directory separator. Back to the idea of an 'abstraction'. Please realise that sometimes libraries offer 'helper functions' or seek to be "accepting"/forgiving in accepting argument-data. However, this does not (necessarily) imply a "rule". Another "implementation detail"? (this time in your favor/to your liking) >> If indeed you're seeking a path that is terminated by the separator >> character, you need to do what you did in the first example - join an >> empty string at the end (this is documented). The terminating separator >> _usually_ isn't needed. Sadly, sometimes it appears to be... Another 'implementation detail' which copes with 'edge cases'. This one has caught me too! [so, not that 'intelligent' after all? (joke)] -- Regards =dn From zljubisic at gmail.com Tue May 26 16:01:46 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Tue, 26 May 2020 13:01:46 -0700 (PDT) Subject: Custom logging function In-Reply-To: References: Message-ID: <04d4e0a3-99b6-4d3f-94bf-8da702365494@googlegroups.com> Is this OK? import logging LOG_LEVEL = logging.getLevelName('DEBUG') logging.basicConfig(level=LOG_LEVEL, format='%(asctime)s %(levelname)s %(name)s %(funcName)-20s %(message)s', datefmt='%d.%m.%Y %H:%M:%S') stderr = logging.StreamHandler() stderr.terminator = '\r\n' logging.getLogger('').addHandler(stderr) logging.info('Main script started') From zljubisic at gmail.com Tue May 26 16:25:10 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Tue, 26 May 2020 13:25:10 -0700 (PDT) Subject: Custom logging function In-Reply-To: <04d4e0a3-99b6-4d3f-94bf-8da702365494@googlegroups.com> References: <04d4e0a3-99b6-4d3f-94bf-8da702365494@googlegroups.com> Message-ID: Furthermore, I must disable logging to stdout. From grant.b.edwards at gmail.com Tue May 26 16:34:50 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 26 May 2020 20:34:50 -0000 (UTC) Subject: Behaviour of os.path.join References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <87tv02pvpo.fsf@bsb.me.uk> Message-ID: On 2020-05-26, Dennis Lee Bieber wrote: > I'd also like to point out that the nasty "\\" is not needed. Windows > API understands "/" -- it is only the command line "DOS" shell that > requires back-slash Many, many applications also require that backslashes be used in path arguments (whether or not they're being executed via the "DOS" shell). Interestingly, the _real_ DOS shell from several decades ago let you change the "option" character from "/" to anything you wanted ("-" is one correct answer), and the shell would then be perfectly happy with forwards slashes in paths. But, there were still plenty of applications that whould choke on forward slashes in path arguments. Apparently a lot of application developers were ignorant of the fact that the system option character was configurable by the user. Thank Dog for the MKS toolkit. > Powershell is happy with / since options are prefixed with - ). One point to Microsoft on that one (they're still way behind). -- Grant From mystirk at gmail.com Tue May 26 17:37:20 2020 From: mystirk at gmail.com (Alex Kaye) Date: Tue, 26 May 2020 14:37:20 -0700 Subject: Phyton 32 or 64 bit? In-Reply-To: <28b154bb-ad94-8f60-710c-765b89fc3e7f@mrabarnett.plus.com> References: <1070312794.1496644.1590516818712.ref@mail.yahoo.com> <1070312794.1496644.1590516818712@mail.yahoo.com> <28b154bb-ad94-8f60-710c-765b89fc3e7f@mrabarnett.plus.com> Message-ID: To all: The only stupid question is one that wasn't asked ! Alex On Tue, May 26, 2020 at 12:42 PM MRAB wrote: > On 2020-05-26 19:13, R. A. Hoffman via Python-list wrote: > > > > Good afternoon, > > > > > > > > Please forgive what may be a stupid question. I?m an absolute beginner > and downloaded Python 3.8 for 32bits. I?m running Windows 10 on 64bit > machine. > > > > > > > > Question 1 : is it OK to run Python (32 bits) on my machine ? > > > The 32-bit version will run on both 32-bit and 64-bit machines. > > If you're intending to work with many gigs of RAM then you'd need the > 64-bit version, otherwise the 32-bit version is fine. > > > > > > Question 2 : The download went fine. How do I go from here to install > and run Python ? > > > What exactly did you download? If it's the "executable installer", then > just run it to install Python. > > > > > > Sorry for the dumb questions. Thanks for any help. > > > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Tue May 26 18:13:21 2020 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 May 2020 00:13:21 +0200 Subject: Custom logging function References: <04d4e0a3-99b6-4d3f-94bf-8da702365494@googlegroups.com> Message-ID: zljubisic at gmail.com wrote: > Is this OK? > > import logging > > LOG_LEVEL = logging.getLevelName('DEBUG') > > logging.basicConfig(level=LOG_LEVEL, > format='%(asctime)s %(levelname)s %(name)s > %(funcName)-20s %(message)s', datefmt='%d.%m.%Y > %H:%M:%S') > > stderr = logging.StreamHandler() > stderr.terminator = '\r\n' > logging.getLogger('').addHandler(stderr) > > logging.info('Main script started') You create two stream handlers that both log to stderr -- one with basicConfig() and one explicitly in your code. That's probably not what you want. From cs at cskk.id.au Tue May 26 18:45:17 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 27 May 2020 08:45:17 +1000 Subject: Custom logging function In-Reply-To: References: Message-ID: <20200526224517.GA89207@cskk.homeip.net> On 26May2020 13:25, zljubisic at gmail.com wrote: >Furthermore, I must disable logging to stdout. Normally logging does not happen to stdout. Do you have something which does? Cheers, Cameron Simpson From emadbo2tor at gmail.com Tue May 26 21:44:31 2020 From: emadbo2tor at gmail.com (Emad Boctor) Date: Tue, 26 May 2020 18:44:31 -0700 (PDT) Subject: yolov3 Real Time Object Detection in tensorflow 2.2 Message-ID: <8d78a4b1-8342-40db-acd9-a7d47a813f7a@googlegroups.com> Hello, I would like to share with you my implementation of yolov3 object detector in tensorflow 2.2 https://github.com/emadboctorx/yolov3-keras-tf2 Features tensorflow-2.X--keras-functional-api cpu-gpu support Random weights and DarkNet weights support csv-xml annotation parsers. Anchor generator. `matplotlib` visualization of all stages. `tf.data` input pipeline. `pandas` & `numpy` data handling. `imgaug` augmentation pipeline `logging` coverage. All-in-1 custom trainer. Stop and resume training support. Fully vectorized mAP evaluation. `labelpix` support. Photo & video detection From barry at barrys-emacs.org Wed May 27 04:16:47 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Wed, 27 May 2020 09:16:47 +0100 Subject: Issues regarding running of application. In-Reply-To: References: Message-ID: <38B9C7A1-0297-4E21-BC06-A5F26A00DF21@barrys-emacs.org> > On 26 May 2020, at 15:45, Meet Agrawal wrote: > > I have tried and installed the python application a lot of times but after > the installation get completed and I try to run the application, it say > that api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. That DLL is part of modern Windows. Which version of Windows are you using? Barry > > Please tell me a way out. > -- > https://mail.python.org/mailman/listinfo/python-list > From barry at barrys-emacs.org Wed May 27 04:09:10 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Wed, 27 May 2020 09:09:10 +0100 Subject: Behaviour of os.path.join In-Reply-To: <4bcbcff3-b339-b3c0-e54d-4b3238fbeb0d@mrabarnett.plus.com> References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <87tv02pvpo.fsf@bsb.me.uk> <4bcbcff3-b339-b3c0-e54d-4b3238fbeb0d@mrabarnett.plus.com> Message-ID: > On 26 May 2020, at 17:46, MRAB wrote: > > On 2020-05-26 16:48, BlindAnagram wrote: >> On 26/05/2020 16:22, Ben Bacarisse wrote: >>> BlindAnagram writes: >>>> I came across an issue that I am wondering whether I should report as an >>>> issue. If I have a directory, say: >>>> >>>> base='C:\\Documents' >>>> >>>> and I use os.path.join() as follows: >>>> >>>> join(base, '..\\..\\', 'build', '') >>> It rather defeats the purpose of os.sep if you include it in a part of >>> the path. What you mean is better expressed as >>> join(base, '..', '..', 'build', '') >>> (and base includes it too, but I can't suggest an alternative because I >>> don't know your intent is far as defaults go.) >> Thanks for your input but while that part of my path may not be to your >> liking, it works fine and does not seem to be relevant to my concern, >> which is that join appears to treat os.sep as an absolute path, which it >> is not. > If it starts with the path separator, then it's absolute (well, absolute on that drive). > > Open a Command Prompt window and it'll open in the %HOME% folder. Then type "cd \" and it'll put you in the root folder. HOME is not defined by windows. I have theses: HOMEDRIVE=C: HOMEPATH=\Users\barry USERPROFILE=C:\Users\barry I have always use USERPROFILE in place of HOME on Windows. Barry > -- > https://mail.python.org/mailman/listinfo/python-list > From souvik.viksou at gmail.com Wed May 27 04:37:18 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Wed, 27 May 2020 14:07:18 +0530 Subject: Issues regarding running of application. In-Reply-To: References: Message-ID: Do have the latest version of DirectX installed? If not then do that or you can google out the dll file you need (or is missing) and download it and cut - paste it wherever needed. Missing dll files is a very common issue in windows and thus Microsoft made DirectX. On Tue, 26 May, 2020, 11:14 pm Meet Agrawal, wrote: > I have tried and installed the python application a lot of times but after > the installation get completed and I try to run the application, it say > that api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. > > Please tell me a way out. > -- > https://mail.python.org/mailman/listinfo/python-list > From barry at barrys-emacs.org Wed May 27 04:13:48 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Wed, 27 May 2020 09:13:48 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: > On 26 May 2020, at 18:01, BlindAnagram wrote: > > On 26/05/2020 17:09, Stefan Ram wrote: >> Mats Wichmann writes: >>> an absolute path is one that starts with the pathname separator. >> >> The Python Library Reference does not use the term >> "pathname separator". It uses "directory separator" >> (os.sep) and "filename separator" ('/' on Unix). >> >> On Windows: >> >> |>>> import pathlib >> |>>> import os >> |>>> pathlib.PureWindowsPath('\\').is_absolute() >> |False >> |>>> pathlib.PureWindowsPath(os.sep).is_absolute() >> |False >> |>>> pathlib.PureWindowsPath('/').is_absolute() >> |False > > Thanks, that seems to suggest that there is an issue and that I should > hence submit this as an issue. Can you post the a link to the issue please? I note that >>> pathlib.Path('/').is_absolute() False >>> pathlib.Path('/').resolve().is_absolute() True >>> The resolve() is required and I think should not be required. Barry > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Wed May 27 04:55:20 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 May 2020 18:55:20 +1000 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: On Wed, May 27, 2020 at 6:50 PM Barry Scott wrote: > > > > > On 26 May 2020, at 18:01, BlindAnagram wrote: > > > > On 26/05/2020 17:09, Stefan Ram wrote: > >> Mats Wichmann writes: > >>> an absolute path is one that starts with the pathname separator. > >> > >> The Python Library Reference does not use the term > >> "pathname separator". It uses "directory separator" > >> (os.sep) and "filename separator" ('/' on Unix). > >> > >> On Windows: > >> > >> |>>> import pathlib > >> |>>> import os > >> |>>> pathlib.PureWindowsPath('\\').is_absolute() > >> |False > >> |>>> pathlib.PureWindowsPath(os.sep).is_absolute() > >> |False > >> |>>> pathlib.PureWindowsPath('/').is_absolute() > >> |False > > > > Thanks, that seems to suggest that there is an issue and that I should > > hence submit this as an issue. > > Can you post the a link to the issue please? > > I note that > > >>> pathlib.Path('/').is_absolute() > False > >>> pathlib.Path('/').resolve().is_absolute() > True > >>> > > The resolve() is required and I think should not be required. > Have a look at the difference between the original Path and the resolved one, and see if there's a difference there. I suspect that resolve() is adding the current drive onto that path and thus making it fully absolute. ChrisA From blindanagram at nowhere.com Wed May 27 07:54:11 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Wed, 27 May 2020 12:54:11 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: On 27/05/2020 09:13, Barry Scott wrote: > > >> On 26 May 2020, at 18:01, BlindAnagram wrote: >> >> On 26/05/2020 17:09, Stefan Ram wrote: >>> Mats Wichmann writes: >>>> an absolute path is one that starts with the pathname separator. >>> >>> The Python Library Reference does not use the term >>> "pathname separator". It uses "directory separator" >>> (os.sep) and "filename separator" ('/' on Unix). >>> >>> On Windows: >>> >>> |>>> import pathlib >>> |>>> import os >>> |>>> pathlib.PureWindowsPath('\\').is_absolute() >>> |False >>> |>>> pathlib.PureWindowsPath(os.sep).is_absolute() >>> |False >>> |>>> pathlib.PureWindowsPath('/').is_absolute() >>> |False >> >> Thanks, that seems to suggest that there is an issue and that I should >> hence submit this as an issue. > > Can you post the a link to the issue please? The issue that I raised here was whether the behaviour of os.path.join() in treating the Windows directory separator '\\' as an absolute path should be considered a bug. The behaviour of join came up for me when I tried to use the os.path functions to create a path that could only ever be used as a directory and never a file. The only way that I found to designate a path as a directory path was to add '\\' at the end. But this doesn't work in using os.path becaause the other os.path functions just strip it off and turn the directories back into files. I had hoped that join's documented use of an empty final parameter to add '\\' might behave differently but it gets stripped off as well :-( I thought that the description of pathlib behaviour above suported the view that the os.path.joing behaviour is a bug, and in a sense it does, but more importantly it an indication that pathib, not os.path, should be the module of choice for anyone who spends a lot of time manipulating paths on Windows. From ben.usenet at bsb.me.uk Wed May 27 08:30:01 2020 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 27 May 2020 13:30:01 +0100 Subject: Behaviour of os.path.join References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: <875zchtvau.fsf@bsb.me.uk> BlindAnagram writes: > The issue that I raised here was whether the behaviour of os.path.join() > in treating the Windows directory separator '\\' as an absolute path > should be considered a bug. You think it should be considered to be a relative path? The only meaning that would give you want you wanted from os.path.join(, '\\') would be to treat it as being relative to the drive and to the directory. In other words you want '\\' to be a synonym for '.' The usual meaning of '\\' (outside of this specific function) is "root on the current drive" but that can't sensibly be appended to any path. > The behaviour of join came up for me when I tried to use the os.path > functions to create a path that could only ever be used as a directory > and never a file. The only way that I found to designate a path as a > directory path was to add '\\' at the end. But this doesn't work in > using os.path becaause the other os.path functions just strip it off and > turn the directories back into files. Nothing about the name can turn a directory into a file (or vice versa). If c:\x\y is a file, calling it c:\x\y\ won't change that, but it might give you an error when you try to access it. That may be what you want. If so, appending '.' is likely to be more portable. -- Ben. From blindanagram at nowhere.com Wed May 27 09:41:16 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Wed, 27 May 2020 14:41:16 +0100 Subject: Behaviour of os.path.join In-Reply-To: <875zchtvau.fsf@bsb.me.uk> References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> Message-ID: On 27/05/2020 13:30, Ben Bacarisse wrote: > BlindAnagram writes: > >> The issue that I raised here was whether the behaviour of os.path.join() >> in treating the Windows directory separator '\\' as an absolute path >> should be considered a bug. > > You think it should be considered to be a relative path? The only > meaning that would give you want you wanted from > > os.path.join(, '\\') > > would be to treat it as being relative to the drive and to the > directory. In other words you want '\\' to be a synonym for '.' The > usual meaning of '\\' (outside of this specific function) is "root on > the current drive" but that can't sensibly be appended to any path. > >> The behaviour of join came up for me when I tried to use the os.path >> functions to create a path that could only ever be used as a directory >> and never a file. The only way that I found to designate a path as a >> directory path was to add '\\' at the end. But this doesn't work in >> using os.path becaause the other os.path functions just strip it off and >> turn the directories back into files. > > Nothing about the name can turn a directory into a file (or vice versa). > If c:\x\y is a file, calling it c:\x\y\ won't change that, but it might > give you an error when you try to access it. That may be what you want. > If so, appending '.' is likely to be more portable. That is true if you know for sure how your path will be used. But if you don't, there is a world of difference between passing the paths 'name' and 'name\\' on for others to use. And in this situation it doesn't help when os.path functions strip the directory separator off. This situation resulted in a bug that was surprisingly hard to track down because it created hidden files instead of directories as intended. After finding and correcting the '\\' that had been stripped off, the desired directories couldn't then be creaated on the target because hidden files were present with these names. From rhodri at kynesim.co.uk Wed May 27 09:53:18 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 27 May 2020 14:53:18 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> Message-ID: <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> On 27/05/2020 14:41, BlindAnagram wrote: > That is true if you know for sure how your path will be used. > > But if you don't, there is a world of difference between passing the > paths 'name' and 'name\\' on for others to use. And in this situation it > doesn't help when os.path functions strip the directory separator off. Only if you impose meaning externally, which implies you do know how your path will be used after all. If you want to know whether a given path corresponds to a file or a directory on a filing system, there's no real substitute for looking on the filing system. Anything else is, as you have discovered, error-prone. -- Rhodri James *-* Kynesim Ltd From aishan0403 at gmail.com Wed May 27 11:08:53 2020 From: aishan0403 at gmail.com (BBT) Date: Wed, 27 May 2020 08:08:53 -0700 (PDT) Subject: Write tables from Word (.docx) to Excel (.xlsx) using xlsxwriter Message-ID: <6b929c36-cede-483b-8dec-34bc09a5309a@googlegroups.com> I am trying to parse a word (.docx) for tables, then copy these tables over to excel using xlsxwriter. This is my code: from docx.api import Document import xlsxwriter document = Document('/Users/xxx/Documents/xxx/Clauses Sample - Copy v1 - for merge.docx') tables = document.tables wb = xlsxwriter.Workbook('C:/Users/xxx/Documents/xxx/test clause retrieval.xlsx') Sheet1 = wb.add_worksheet("Compliance") index_row = 0 print(len(tables)) for table in document.tables: data = [] keys = None for i, row in enumerate(table.rows): text = (cell.text for cell in row.cells) if i == 0: keys = tuple(text) continue row_data = dict(zip(keys, text)) data.append(row_data) #print (data) #big_data.append(data) Sheet1.write(index_row,0, str(row_data)) index_row = index_row + 1 print(row_data) wb.close() This is my desired output: https://i.stack.imgur.com/9qnbw.png However, here is my actual output: https://i.stack.imgur.com/vpXej.png I am aware that my current output produces a list of string instead. Is there anyway that I can get my desired output using xlsxwriter? From blindanagram at nowhere.com Wed May 27 11:12:02 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Wed, 27 May 2020 16:12:02 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> Message-ID: On 27/05/2020 14:53, Rhodri James wrote: > On 27/05/2020 14:41, BlindAnagram wrote: >> That is true if you know for sure how your path will be used. >> >> But if you don't, there is a world of difference between passing the >> paths 'name' and 'name\\' on for others to use. And in this situation it >> doesn't help when os.path functions strip the directory separator off. > > Only if you impose meaning externally, which implies you do know how > your path will be used after all.? If you want to know whether a given > path corresponds to a file or a directory on a filing system, there's no > real substitute for looking on the filing system.? Anything else is, as > you have discovered, error-prone. I'm sorry that you don't believe me but all I know is how I intend the path to be used. And the os.path functions aren't helpful here when they actually _change_ the meanings of paths on Windows: >> fp= "C:\\Documents\finance\\" >> abspath(fp) 'C:\\Documents\\finance' If you believe these 'before' and 'after' paths are the same I can only assume that you don't work on Windows (where one refers to a directory and the other a file without an extension). From rhodri at kynesim.co.uk Wed May 27 11:49:52 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 27 May 2020 16:49:52 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> Message-ID: <6472c1ef-2544-01a8-cc89-0a30ba99d5ca@kynesim.co.uk> On 27/05/2020 16:12, BlindAnagram wrote: > I'm sorry that you don't believe me but all I know is how I intend the > path to be used. And the os.path functions aren't helpful here when > they actually_change_ the meanings of paths on Windows: > >>> fp= "C:\\Documents\finance\\" >>> abspath(fp) > 'C:\\Documents\\finance' > > If you believe these 'before' and 'after' paths are the same I can only > assume that you don't work on Windows (where one refers to a directory > and the other a file without an extension). More accurately, one is not a legal filename but both are legal directory names. I entirely believe that you have a problem, but I'm inclined to think it's of your own making. You seem to have decided how paths work without checking whether the language agrees with you. It doesn't, and hasn't for over a decade without a significant number of complaints (as in I can't remember the last one, and I've been around here for a while -- it's too hot for me to want to go hunt in the archives :-). How are these unexpected extensionless files getting created? -- Rhodri James *-* Kynesim Ltd From ben.usenet at bsb.me.uk Wed May 27 11:53:55 2020 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 27 May 2020 16:53:55 +0100 Subject: Behaviour of os.path.join References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> Message-ID: <87zh9ts7ak.fsf@bsb.me.uk> BlindAnagram writes: > On 27/05/2020 13:30, Ben Bacarisse wrote: >> BlindAnagram writes: >> >>> The issue that I raised here was whether the behaviour of os.path.join() >>> in treating the Windows directory separator '\\' as an absolute path >>> should be considered a bug. >> >> You think it should be considered to be a relative path? The only >> meaning that would give you want you wanted from >> >> os.path.join(, '\\') >> >> would be to treat it as being relative to the drive and to the >> directory. In other words you want '\\' to be a synonym for '.' The >> usual meaning of '\\' (outside of this specific function) is "root on >> the current drive" but that can't sensibly be appended to any path. >> >>> The behaviour of join came up for me when I tried to use the os.path >>> functions to create a path that could only ever be used as a directory >>> and never a file. The only way that I found to designate a path as a >>> directory path was to add '\\' at the end. But this doesn't work in >>> using os.path becaause the other os.path functions just strip it off and >>> turn the directories back into files. >> >> Nothing about the name can turn a directory into a file (or vice versa). >> If c:\x\y is a file, calling it c:\x\y\ won't change that, but it might >> give you an error when you try to access it. That may be what you want. >> If so, appending '.' is likely to be more portable. > > That is true if you know for sure how your path will be used. > > But if you don't, there is a world of difference between passing the > paths 'name' and 'name\\' on for others to use. And in this situation it > doesn't help when os.path functions strip the directory separator off. As it should. Relying on a trailing \ having the right effect is brittle to say the least. > This situation resulted in a bug that was surprisingly hard to track > down because it created hidden files instead of directories as > intended. If so, the bug is not in os.path.join and trying to fix it by insisting that a path have trailing \ may well just stacking up more problems for later. > After finding and correcting the '\\' that had been stripped off, the > desired directories couldn't then be creaated on the target because > hidden files were present with these names. As I said, that's a dodgy thing to rely on. It may be that you can't fix the bug any other way (some aspect of the overall design may be broken), but I would urge you to try. There is well-known (*nix) software that relies on a/b/c/ meaning something different to a/b/c but I don't know anyone who thinks this is a good idea. It causes no end of confusion. -- Ben. From blindanagram at nowhere.com Wed May 27 12:39:32 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Wed, 27 May 2020 17:39:32 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> <6472c1ef-2544-01a8-cc89-0a30ba99d5ca@kynesim.co.uk> Message-ID: On 27/05/2020 16:49, Rhodri James wrote: > On 27/05/2020 16:12, BlindAnagram wrote: >> I'm sorry that you don't believe me but all I know is how I intend the >> path to be used.? And the os.path functions aren't helpful here when >> they actually_change_? the meanings of paths on Windows: >> >>>> fp= "C:\\Documents\finance\\" >>>> abspath(fp) >> 'C:\\Documents\\finance' >> >> If you believe these 'before' and 'after' paths are the same I can only >> assume that you don't work on Windows (where one refers to a directory >> and the other a file without an extension). > > More accurately, one is not a legal filename but both are legal > directory names. If they are to be created, which is my situation, the result will be a diretory and a file. > I entirely believe that you have a problem, but I'm inclined to think > it's of your own making.? You seem to have decided how paths work > without checking whether the language agrees with you.? It doesn't, and > hasn't for over a decade without a significant number of complaints (as > in I can't remember the last one, and I've been around here for a while > -- it's too hot for me to want to go hunt in the archives :-). Why do you believe my understanding of Python is lacking? It seems to me that I have tried to avoid this very issue by explicitly sending a directory and I have been thwarted by a combination of poor knowledge elsewhere and a poorly designed function that changes the semantics of what it is offered. I would be surprised if issues such as these were not, at least in significant part, the reason why we now have pathlib. > How are these unexpected extensionless files getting created? I believe by attempting to make the directory I send absolute with abspath() and then copying a file to this path. They expected this to copy the file into the directory with its original name but instead it copies it to the file that abspath 'kindly' converts my directory into. I did complain about their lack of knowledge but I also have a right to complain about a function that converts an explicitly specified directory into a file :-) From blindanagram at nowhere.com Wed May 27 12:53:49 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Wed, 27 May 2020 17:53:49 +0100 Subject: Behaviour of os.path.join In-Reply-To: <87zh9ts7ak.fsf@bsb.me.uk> References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <87zh9ts7ak.fsf@bsb.me.uk> Message-ID: On 27/05/2020 16:53, Ben Bacarisse wrote: > BlindAnagram writes: > >> On 27/05/2020 13:30, Ben Bacarisse wrote: >>> BlindAnagram writes: >>> >>>> The issue that I raised here was whether the behaviour of os.path.join() >>>> in treating the Windows directory separator '\\' as an absolute path >>>> should be considered a bug. >>> >>> You think it should be considered to be a relative path? The only >>> meaning that would give you want you wanted from >>> >>> os.path.join(, '\\') >>> >>> would be to treat it as being relative to the drive and to the >>> directory. In other words you want '\\' to be a synonym for '.' The >>> usual meaning of '\\' (outside of this specific function) is "root on >>> the current drive" but that can't sensibly be appended to any path. >>> >>>> The behaviour of join came up for me when I tried to use the os.path >>>> functions to create a path that could only ever be used as a directory >>>> and never a file. The only way that I found to designate a path as a >>>> directory path was to add '\\' at the end. But this doesn't work in >>>> using os.path becaause the other os.path functions just strip it off and >>>> turn the directories back into files. >>> >>> Nothing about the name can turn a directory into a file (or vice versa). >>> If c:\x\y is a file, calling it c:\x\y\ won't change that, but it might >>> give you an error when you try to access it. That may be what you want. >>> If so, appending '.' is likely to be more portable. >> >> That is true if you know for sure how your path will be used. >> >> But if you don't, there is a world of difference between passing the >> paths 'name' and 'name\\' on for others to use. And in this situation it >> doesn't help when os.path functions strip the directory separator off. > > As it should. Relying on a trailing \ having the right effect is > brittle to say the least. In my case less brittle than leaving it out. I don't want to bore people with the details but the convention on the target system is that directory paths must always end with '\\' into order to be interpreted as directories. Its not my choice but I see this as a perfectly reasonable convention. Obviously others may disagree. >> This situation resulted in a bug that was surprisingly hard to track >> down because it created hidden files instead of directories as >> intended. > > If so, the bug is not in os.path.join and trying to fix it by insisting > that a path have trailing \ may well just stacking up more problems for > later. > >> After finding and correcting the '\\' that had been stripped off, the >> desired directories couldn't then be creaated on the target because >> hidden files were present with these names. > > As I said, that's a dodgy thing to rely on. It may be that you can't > fix the bug any other way (some aspect of the overall design may be > broken), but I would urge you to try. Its not my bug to fix - the semantics of what I send is very clear on any Windows system. From rhodri at kynesim.co.uk Wed May 27 13:18:16 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 27 May 2020 18:18:16 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> <6472c1ef-2544-01a8-cc89-0a30ba99d5ca@kynesim.co.uk> Message-ID: On 27/05/2020 17:39, BlindAnagram wrote: > I believe by attempting to make the directory I send absolute with > abspath() and then copying a file to this path. They expected this to > copy the file into the directory with its original name but instead it > copies it to the file that abspath 'kindly' converts my directory into. > > I did complain about their lack of knowledge but I also have a right to > complain about a function that converts an explicitly specified > directory into a file:-) Well, they're getting exactly the behaviour I'd expect them to get (and not getting what they expect). I'm faintly gobsmacked that anyone expects something like that to work. If you want a directory, create it. That's what os.mkdir (and the pathlib equivalent) is for. -- Rhodri James *-* Kynesim Ltd From __peter__ at web.de Wed May 27 13:36:02 2020 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 May 2020 19:36:02 +0200 Subject: Write tables from Word (.docx) to Excel (.xlsx) using xlsxwriter References: <6b929c36-cede-483b-8dec-34bc09a5309a@googlegroups.com> Message-ID: BBT wrote: > I am trying to parse a word (.docx) for tables, then copy these tables > over to excel using xlsxwriter. This is my code: > > from docx.api import Document > import xlsxwriter > > document = Document('/Users/xxx/Documents/xxx/Clauses Sample - Copy v1 - > for merge.docx') tables = document.tables > > wb = xlsxwriter.Workbook('C:/Users/xxx/Documents/xxx/test clause > retrieval.xlsx') Sheet1 = wb.add_worksheet("Compliance") > index_row = 0 > > print(len(tables)) > > for table in document.tables: > data = [] > keys = None > for i, row in enumerate(table.rows): > text = (cell.text for cell in row.cells) > > if i == 0: > keys = tuple(text) > continue > row_data = dict(zip(keys, text)) > data.append(row_data) > #print (data) > #big_data.append(data) > Sheet1.write(index_row,0, str(row_data)) > index_row = index_row + 1 > > print(row_data) > > wb.close() > > > This is my desired output: https://i.stack.imgur.com/9qnbw.png > > However, here is my actual output: https://i.stack.imgur.com/vpXej.png > > I am aware that my current output produces a list of string instead. > > Is there anyway that I can get my desired output using xlsxwriter? I had to simulate docx.api. With that caveat the following seems to work: import xlsxwriter # begin simulation of # from docx.api import Document class Cell: def __init__(self, text): self.text = text class Row: def __init__(self, cells): self.cells = [Cell(c) for c in cells] class Table: def __init__(self, data): self.rows = [ Row(row) for row in data ] class Document: def __init__(self): self.tables = [ Table([ ["Hello", "Test"], ["est", "ing"], ["gg", "ff"] ]), Table([ ["Foo", "Bar", "Baz"], ["ham", "spam", "jam"] ]) ] document = Document() # end simulation wb = xlsxwriter.Workbook("tmp.xlsx") sheet = wb.add_worksheet("Compliance") offset = 0 for table in document.tables: for y, row in enumerate(table.rows): for x, cell in enumerate(row.cells): sheet.write(y + offset, x, cell.text) offset += len(table.rows) + 1 # one empty row between tables wb.close() From aishan0403 at gmail.com Wed May 27 13:50:36 2020 From: aishan0403 at gmail.com (BBT) Date: Wed, 27 May 2020 10:50:36 -0700 (PDT) Subject: Write tables from Word (.docx) to Excel (.xlsx) using xlsxwriter In-Reply-To: References: <6b929c36-cede-483b-8dec-34bc09a5309a@googlegroups.com> Message-ID: <6e70e6cf-4fa5-405f-a653-ad93030c353a@googlegroups.com> On Thursday, 28 May 2020 01:36:26 UTC+8, Peter Otten wrote: > BBT wrote: > > > I am trying to parse a word (.docx) for tables, then copy these tables > > over to excel using xlsxwriter. This is my code: > > > > from docx.api import Document > > import xlsxwriter > > > > document = Document('/Users/xxx/Documents/xxx/Clauses Sample - Copy v1 - > > for merge.docx') tables = document.tables > > > > wb = xlsxwriter.Workbook('C:/Users/xxx/Documents/xxx/test clause > > retrieval.xlsx') Sheet1 = wb.add_worksheet("Compliance") > > index_row = 0 > > > > print(len(tables)) > > > > for table in document.tables: > > data = [] > > keys = None > > for i, row in enumerate(table.rows): > > text = (cell.text for cell in row.cells) > > > > if i == 0: > > keys = tuple(text) > > continue > > row_data = dict(zip(keys, text)) > > data.append(row_data) > > #print (data) > > #big_data.append(data) > > Sheet1.write(index_row,0, str(row_data)) > > index_row = index_row + 1 > > > > print(row_data) > > > > wb.close() > > > > > > This is my desired output: https://i.stack.imgur.com/9qnbw.png > > > > However, here is my actual output: https://i.stack.imgur.com/vpXej.png > > > > I am aware that my current output produces a list of string instead. > > > > Is there anyway that I can get my desired output using xlsxwriter? > > I had to simulate docx.api. With that caveat the following seems to work: > > import xlsxwriter > > # begin simulation of > # from docx.api import Document > > class Cell: > def __init__(self, text): > self.text = text > > class Row: > def __init__(self, cells): > self.cells = [Cell(c) for c in cells] > > class Table: > def __init__(self, data): > self.rows = [ > Row(row) for row in data > ] > > class Document: > def __init__(self): > self.tables = [ > Table([ > ["Hello", "Test"], > ["est", "ing"], > ["gg", "ff"] > ]), > Table([ > ["Foo", "Bar", "Baz"], > ["ham", "spam", "jam"] > ]) > ] > > document = Document() > > # end simulation > > wb = xlsxwriter.Workbook("tmp.xlsx") > sheet = wb.add_worksheet("Compliance") > > offset = 0 > for table in document.tables: > for y, row in enumerate(table.rows): > for x, cell in enumerate(row.cells): > sheet.write(y + offset, x, cell.text) > offset += len(table.rows) + 1 # one empty row between tables > > wb.close() Hi Peter, thank you for your efforts :) However, what if there are many tables in the word document, it would be tedious to have to code the texts in the tables one by one. Can I instead, call on the word document and let Python do the parsing for tables and its contents? From __peter__ at web.de Wed May 27 14:40:25 2020 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 May 2020 20:40:25 +0200 Subject: Write tables from Word (.docx) to Excel (.xlsx) using xlsxwriter References: <6b929c36-cede-483b-8dec-34bc09a5309a@googlegroups.com> <6e70e6cf-4fa5-405f-a653-ad93030c353a@googlegroups.com> Message-ID: BBT wrote: > On Thursday, 28 May 2020 01:36:26 UTC+8, Peter Otten wrote: >> BBT wrote: >> >> > I am trying to parse a word (.docx) for tables, then copy these tables >> > over to excel using xlsxwriter. This is my code: >> > >> > from docx.api import Document >> > import xlsxwriter >> > >> > document = Document('/Users/xxx/Documents/xxx/Clauses Sample - Copy v1 >> > - for merge.docx') tables = document.tables >> > >> > wb = xlsxwriter.Workbook('C:/Users/xxx/Documents/xxx/test clause >> > retrieval.xlsx') Sheet1 = wb.add_worksheet("Compliance") >> > index_row = 0 >> > >> > print(len(tables)) >> > >> > for table in document.tables: >> > data = [] >> > keys = None >> > for i, row in enumerate(table.rows): >> > text = (cell.text for cell in row.cells) >> > >> > if i == 0: >> > keys = tuple(text) >> > continue >> > row_data = dict(zip(keys, text)) >> > data.append(row_data) >> > #print (data) >> > #big_data.append(data) >> > Sheet1.write(index_row,0, str(row_data)) >> > index_row = index_row + 1 >> > >> > print(row_data) >> > >> > wb.close() >> > >> > >> > This is my desired output: https://i.stack.imgur.com/9qnbw.png >> > >> > However, here is my actual output: https://i.stack.imgur.com/vpXej.png >> > >> > I am aware that my current output produces a list of string instead. >> > >> > Is there anyway that I can get my desired output using xlsxwriter? >> >> I had to simulate docx.api. With that caveat the following seems to work: >> >> import xlsxwriter >> >> # begin simulation of >> # from docx.api import Document >> >> class Cell: >> def __init__(self, text): >> self.text = text >> >> class Row: >> def __init__(self, cells): >> self.cells = [Cell(c) for c in cells] >> >> class Table: >> def __init__(self, data): >> self.rows = [ >> Row(row) for row in data >> ] >> >> class Document: >> def __init__(self): >> self.tables = [ >> Table([ >> ["Hello", "Test"], >> ["est", "ing"], >> ["gg", "ff"] >> ]), >> Table([ >> ["Foo", "Bar", "Baz"], >> ["ham", "spam", "jam"] >> ]) >> ] >> >> document = Document() >> >> # end simulation >> >> wb = xlsxwriter.Workbook("tmp.xlsx") >> sheet = wb.add_worksheet("Compliance") >> >> offset = 0 >> for table in document.tables: >> for y, row in enumerate(table.rows): >> for x, cell in enumerate(row.cells): >> sheet.write(y + offset, x, cell.text) >> offset += len(table.rows) + 1 # one empty row between tables >> >> wb.close() > > > Hi Peter, thank you for your efforts :) > > However, what if there are many tables in the word document, it would be > tedious to have to code the texts in the tables one by one. Can I instead, > call on the word document and let Python do the parsing for tables and its > contents? I don't understand. You have docx.api available, so you can replace the "simulation" part of my example with just these two lines: from docx.api import Document document = Document('/Users/xxx/Documents/xxx/Clauses Sample - Copy v1 - for merge.docx') I should work -- it's just that I cannot be sure it will work because I could not test it. From aishan0403 at gmail.com Wed May 27 14:53:41 2020 From: aishan0403 at gmail.com (BBT) Date: Wed, 27 May 2020 11:53:41 -0700 (PDT) Subject: Write tables from Word (.docx) to Excel (.xlsx) using xlsxwriter In-Reply-To: References: <6b929c36-cede-483b-8dec-34bc09a5309a@googlegroups.com> <6e70e6cf-4fa5-405f-a653-ad93030c353a@googlegroups.com> Message-ID: <07ad4f89-a822-4b42-9493-b1e4c7cab515@googlegroups.com> On Thursday, 28 May 2020 02:40:49 UTC+8, Peter Otten wrote: > BBT wrote: > > > On Thursday, 28 May 2020 01:36:26 UTC+8, Peter Otten wrote: > >> BBT wrote: > >> > >> > I am trying to parse a word (.docx) for tables, then copy these tables > >> > over to excel using xlsxwriter. This is my code: > >> > > >> > from docx.api import Document > >> > import xlsxwriter > >> > > >> > document = Document('/Users/xxx/Documents/xxx/Clauses Sample - Copy v1 > >> > - for merge.docx') tables = document.tables > >> > > >> > wb = xlsxwriter.Workbook('C:/Users/xxx/Documents/xxx/test clause > >> > retrieval.xlsx') Sheet1 = wb.add_worksheet("Compliance") > >> > index_row = 0 > >> > > >> > print(len(tables)) > >> > > >> > for table in document.tables: > >> > data = [] > >> > keys = None > >> > for i, row in enumerate(table.rows): > >> > text = (cell.text for cell in row.cells) > >> > > >> > if i == 0: > >> > keys = tuple(text) > >> > continue > >> > row_data = dict(zip(keys, text)) > >> > data.append(row_data) > >> > #print (data) > >> > #big_data.append(data) > >> > Sheet1.write(index_row,0, str(row_data)) > >> > index_row = index_row + 1 > >> > > >> > print(row_data) > >> > > >> > wb.close() > >> > > >> > > >> > This is my desired output: https://i.stack.imgur.com/9qnbw.png > >> > > >> > However, here is my actual output: https://i.stack.imgur.com/vpXej.png > >> > > >> > I am aware that my current output produces a list of string instead. > >> > > >> > Is there anyway that I can get my desired output using xlsxwriter? > >> > >> I had to simulate docx.api. With that caveat the following seems to work: > >> > >> import xlsxwriter > >> > >> # begin simulation of > >> # from docx.api import Document > >> > >> class Cell: > >> def __init__(self, text): > >> self.text = text > >> > >> class Row: > >> def __init__(self, cells): > >> self.cells = [Cell(c) for c in cells] > >> > >> class Table: > >> def __init__(self, data): > >> self.rows = [ > >> Row(row) for row in data > >> ] > >> > >> class Document: > >> def __init__(self): > >> self.tables = [ > >> Table([ > >> ["Hello", "Test"], > >> ["est", "ing"], > >> ["gg", "ff"] > >> ]), > >> Table([ > >> ["Foo", "Bar", "Baz"], > >> ["ham", "spam", "jam"] > >> ]) > >> ] > >> > >> document = Document() > >> > >> # end simulation > >> > >> wb = xlsxwriter.Workbook("tmp.xlsx") > >> sheet = wb.add_worksheet("Compliance") > >> > >> offset = 0 > >> for table in document.tables: > >> for y, row in enumerate(table.rows): > >> for x, cell in enumerate(row.cells): > >> sheet.write(y + offset, x, cell.text) > >> offset += len(table.rows) + 1 # one empty row between tables > >> > >> wb.close() > > > > > > Hi Peter, thank you for your efforts :) > > > > However, what if there are many tables in the word document, it would be > > tedious to have to code the texts in the tables one by one. Can I instead, > > call on the word document and let Python do the parsing for tables and its > > contents? > > I don't understand. You have docx.api available, so you can replace > > the "simulation" part of my example with just these two lines: > > from docx.api import Document > document = Document('/Users/xxx/Documents/xxx/Clauses Sample - Copy v1 - for merge.docx') > > I should work -- it's just that I cannot be sure it will work because I could > not test it. I tried your code by replacing the Document portion: import xlsxwriter # begin simulation of # from docx.api import Document class Cell: def __init__(self, text): self.text = text class Row: def __init__(self, cells): self.cells = [Cell(c) for c in cells] class Table: def __init__(self, data): self.rows = [ Row(row) for row in data ] class Document: def __init__(self): self.tables = [ Table([ ["Hello", "Test"], ["est", "ing"], ["gg", "ff"] ]), Table([ ["Foo", "Bar", "Baz"], ["ham", "spam", "jam"] ]) ] #document = Document() # end simulation document = Document('/Users/xxx/Documents/xx/Clauses Sample - Copy v1 - for merge.docx') wb = xlsxwriter.Workbook('C:/Users/xxx/Documents/xx/test clause retrieval.xlsx') Sheet1 = wb.add_worksheet("Compliance") offset = 0 for table in document.tables: for y, row in enumerate(table.rows): for x, cell in enumerate(row.cells): sheet.write(y + offset, x, cell.text) offset += len(table.rows) + 1 # one empty row between tables wb.close() But I received an error: TypeError: __init__() takes 1 positional argument but 2 were given From countryone77 at gmail.com Wed May 27 14:56:54 2020 From: countryone77 at gmail.com (Beverly Pope) Date: Wed, 27 May 2020 13:56:54 -0500 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <87zh9ts7ak.fsf@bsb.me.uk> Message-ID: I wasn?t going to say anything because I haven?t used MS Windows for years. The OP wants to add a path separator at the end of a path. Why the OP wants to do that doesn?t concern me. OTOH, as others have already mentioned, the documentation explicitly says, "If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component.? While I may not understand WHY anyone would want that to occur, this was the way it was designed; it is not a bug. The documentation also says, ?The return value is the concatenation of path and any members of *paths with exactly one directory separator (os.sep) following each non-empty part except the last, meaning that the result will only end in a separator if the last part is empty.? So, the module does allow one to add a path separator at the end of the path by simply adding an empty string as the last part of the path. The following is on macOS (I don?t have a MS Windows machine): >>> import os.path >>> os.path.join('/Users/myID/a', 'b','c') '/Users/myID/a/b/c' >>> os.path.join('/Users/myID/a', 'b','c', '') '/Users/myID/a/b/c/? So, it does work as advertised on Python 3.8 and all the OP should need to do is add that empty string to get the OP?s desired result. Bev in TX From aishan0403 at gmail.com Wed May 27 14:55:12 2020 From: aishan0403 at gmail.com (BBT) Date: Wed, 27 May 2020 11:55:12 -0700 (PDT) Subject: Write tables from Word (.docx) to Excel (.xlsx) using xlsxwriter In-Reply-To: References: <6b929c36-cede-483b-8dec-34bc09a5309a@googlegroups.com> <6e70e6cf-4fa5-405f-a653-ad93030c353a@googlegroups.com> Message-ID: <7075617e-ea45-4e98-a6d9-125bc41484e3@googlegroups.com> On Thursday, 28 May 2020 02:40:49 UTC+8, Peter Otten wrote: > BBT wrote: > > > On Thursday, 28 May 2020 01:36:26 UTC+8, Peter Otten wrote: > >> BBT wrote: > >> > >> > I am trying to parse a word (.docx) for tables, then copy these tables > >> > over to excel using xlsxwriter. This is my code: > >> > > >> > from docx.api import Document > >> > import xlsxwriter > >> > > >> > document = Document('/Users/xxx/Documents/xxx/Clauses Sample - Copy v1 > >> > - for merge.docx') tables = document.tables > >> > > >> > wb = xlsxwriter.Workbook('C:/Users/xxx/Documents/xxx/test clause > >> > retrieval.xlsx') Sheet1 = wb.add_worksheet("Compliance") > >> > index_row = 0 > >> > > >> > print(len(tables)) > >> > > >> > for table in document.tables: > >> > data = [] > >> > keys = None > >> > for i, row in enumerate(table.rows): > >> > text = (cell.text for cell in row.cells) > >> > > >> > if i == 0: > >> > keys = tuple(text) > >> > continue > >> > row_data = dict(zip(keys, text)) > >> > data.append(row_data) > >> > #print (data) > >> > #big_data.append(data) > >> > Sheet1.write(index_row,0, str(row_data)) > >> > index_row = index_row + 1 > >> > > >> > print(row_data) > >> > > >> > wb.close() > >> > > >> > > >> > This is my desired output: https://i.stack.imgur.com/9qnbw.png > >> > > >> > However, here is my actual output: https://i.stack.imgur.com/vpXej.png > >> > > >> > I am aware that my current output produces a list of string instead. > >> > > >> > Is there anyway that I can get my desired output using xlsxwriter? > >> > >> I had to simulate docx.api. With that caveat the following seems to work: > >> > >> import xlsxwriter > >> > >> # begin simulation of > >> # from docx.api import Document > >> > >> class Cell: > >> def __init__(self, text): > >> self.text = text > >> > >> class Row: > >> def __init__(self, cells): > >> self.cells = [Cell(c) for c in cells] > >> > >> class Table: > >> def __init__(self, data): > >> self.rows = [ > >> Row(row) for row in data > >> ] > >> > >> class Document: > >> def __init__(self): > >> self.tables = [ > >> Table([ > >> ["Hello", "Test"], > >> ["est", "ing"], > >> ["gg", "ff"] > >> ]), > >> Table([ > >> ["Foo", "Bar", "Baz"], > >> ["ham", "spam", "jam"] > >> ]) > >> ] > >> > >> document = Document() > >> > >> # end simulation > >> > >> wb = xlsxwriter.Workbook("tmp.xlsx") > >> sheet = wb.add_worksheet("Compliance") > >> > >> offset = 0 > >> for table in document.tables: > >> for y, row in enumerate(table.rows): > >> for x, cell in enumerate(row.cells): > >> sheet.write(y + offset, x, cell.text) > >> offset += len(table.rows) + 1 # one empty row between tables > >> > >> wb.close() > > > > > > Hi Peter, thank you for your efforts :) > > > > However, what if there are many tables in the word document, it would be > > tedious to have to code the texts in the tables one by one. Can I instead, > > call on the word document and let Python do the parsing for tables and its > > contents? > > I don't understand. You have docx.api available, so you can replace > > the "simulation" part of my example with just these two lines: > > from docx.api import Document > document = Document('/Users/xxx/Documents/xxx/Clauses Sample - Copy v1 - for merge.docx') > > I should work -- it's just that I cannot be sure it will work because I could > not test it. I tried your code by replacing the Document portion: import xlsxwriter # begin simulation of # from docx.api import Document class Cell: def __init__(self, text): self.text = text class Row: def __init__(self, cells): self.cells = [Cell(c) for c in cells] class Table: def __init__(self, data): self.rows = [ Row(row) for row in data ] class Document: def __init__(self): self.tables = [ Table([ ["Hello", "Test"], ["est", "ing"], ["gg", "ff"] ]), Table([ ["Foo", "Bar", "Baz"], ["ham", "spam", "jam"] ]) ] #document = Document() # end simulation document = Document('/Users/Ai Shan/Documents/CPFB Work/Clauses Sample - Copy v1 - for merge.docx') wb = xlsxwriter.Workbook('C:/Users/Ai Shan/Documents/CPFB Work/test clause retrieval.xlsx') Sheet1 = wb.add_worksheet("Compliance") offset = 0 for table in document.tables: for y, row in enumerate(table.rows): for x, cell in enumerate(row.cells): sheet.write(y + offset, x, cell.text) offset += len(table.rows) + 1 # one empty row between tables wb.close() But I received an error: TypeError: __init__() takes 1 positional argument but 2 were given From __peter__ at web.de Wed May 27 15:07:26 2020 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 May 2020 21:07:26 +0200 Subject: Write tables from Word (.docx) to Excel (.xlsx) using xlsxwriter References: <6b929c36-cede-483b-8dec-34bc09a5309a@googlegroups.com> <6e70e6cf-4fa5-405f-a653-ad93030c353a@googlegroups.com> <07ad4f89-a822-4b42-9493-b1e4c7cab515@googlegroups.com> Message-ID: BBT wrote: > I tried your code by replacing the Document portion: > But I received an error: > TypeError: __init__() takes 1 positional argument but 2 were given We seem to have different ideas of what replacing means. Here is the suggested script spelt out: import xlsxwriter from docx.api import Document document = Document('/Users/xxx/Documents/xxx/Clauses Sample - Copy v1 - for merge.docx') wb = xlsxwriter.Workbook('C:/Users/xxx/Documents/xx/test clause retrieval.xlsx') sheet = wb.add_worksheet("Compliance") offset = 0 for table in document.tables: for y, row in enumerate(table.rows): for x, cell in enumerate(row.cells): sheet.write(y + offset, x, cell.text) offset += len(table.rows) + 1 # one empty row between tables wb.close() From arj.python at gmail.com Wed May 27 15:46:44 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 27 May 2020 23:46:44 +0400 Subject: Access an object to which being bound Message-ID: Greetings, Lets say i have class A: ... class B: self.x = A then used b = B() z = b.x() now how in A i get a reference to B when z is assigned to b.x? Thanks Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy | blog github Mauritius From george at fischhof.hu Wed May 27 15:47:40 2020 From: george at fischhof.hu (George Fischhof) Date: Wed, 27 May 2020 21:47:40 +0200 Subject: Managing plug-ins In-Reply-To: <4c5959d2-504c-143a-a0ad-ac45fffd342d@DancesWithMice.info> References: <5f6a0ccf-7210-d0ec-463a-644232201c8b@etelligence.info> <7B51AC8A-A69C-4BD6-8AC7-E11132BB6E40@schollnick.net> <4c5959d2-504c-143a-a0ad-ac45fffd342d@DancesWithMice.info> Message-ID: DL Neil via Python-list ezt ?rta (id?pont: 2020. m?j. 26., K, 3:10): > On 26/05/20 11:35 AM, Benjamin Schollnick wrote: > > Did you ever find anything that met your requirements? > > > > If not, I have a prototype that I need to build out some more? > > > > https://github.com/bschollnick/PyPlugInMgr > > > > I use it for some home grown utilities, but it needs to be fleshed out > > some more? > > If you?re interested feel free to take a look. > > Thanks. > Am on-the-road at present, but will take a look... > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list HI, I do not understand your requirements fully, but two easy come to mind: registering function as plugin - you can find metaclass or functional programing examples in google; keywords: register plugin And the second one, is to put files to a given place and import them in runtime, I created a pluggable info monitor which does this: in every cycles imports the given files as plugins. https://pypi.org/project/pluggable-info-monitor/ BR, George From Bischoop at vimuster.net Wed May 27 02:35:29 2020 From: Bischoop at vimuster.net (Bischoop) Date: Wed, 27 May 2020 06:35:29 -0000 (UTC) Subject: Phyton 32 or 64 bit? References: <1070312794.1496644.1590516818712.ref@mail.yahoo.com> <1070312794.1496644.1590516818712@mail.yahoo.com> <28b154bb-ad94-8f60-710c-765b89fc3e7f@mrabarnett.plus.com> Message-ID: On 2020-05-26, Alex Kaye wrote: > To all: > > The only stupid question is one that wasn't asked ! > > Alex > Well, visit FB and you'll change your mind. From a.h.jaffe at gmail.com Wed May 27 11:46:55 2020 From: a.h.jaffe at gmail.com (Andrew Jaffe) Date: Wed, 27 May 2020 16:46:55 +0100 Subject: Behaviour of os.path.join In-Reply-To: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: Dear all, \On 26/05/2020 15:56, BlindAnagram wrote: > I came across an issue that I am wondering whether I should report as an > issue. If I have a directory, say: > > base='C:\\Documents' > > and I use os.path.join() as follows: > > join(base, '..\\..\\', 'build', '') > > I obtain as expected from the documentation: > > 'C:\\Documents\\..\\..\\build\\' > > But if I try to make the directory myself (as I tried first): > > join(base, '..\\..\\', 'build', '\\') > > I obtain: > > 'C:\\' > > The documentation says that an absolute path in the parameter list for > join will discard all previous parameters but '\\' is not an absoute path! > > Moreover, if I use > > join(base, '..\\..\\', 'build', os.sep) > > I get the same result. > > This seems to me to be a bug that I should report but to avoid wasting > developer time I wanted to hear what others feel about this. Maybe I am being obtuse (and apologies for not quoting any of the subsequent voluminous messages in this thread), but I think perhaps there is confusion at a somewhat more basic level. It seems that there is never (rarely?) any reason to explicitly pass a string which already contains an explicit separator to `os.path.join` -- the whole point of the function is to be os-agnostic. If you already know what the separator is, and you also don't like the behaviour of restarting the path if any of the items are (by the function's definition) absolute, then is there any reason to prefer `os.path.join` to `string.join`? A From roel at roelschroeven.net Wed May 27 13:37:47 2020 From: roel at roelschroeven.net (Roel Schroeven) Date: Wed, 27 May 2020 19:37:47 +0200 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> <6472c1ef-2544-01a8-cc89-0a30ba99d5ca@kynesim.co.uk> Message-ID: BlindAnagram schreef op 27/05/2020 om 18:39: > On 27/05/2020 16:49, Rhodri James wrote: >> On 27/05/2020 16:12, BlindAnagram wrote: >>> I'm sorry that you don't believe me but all I know is how I intend the >>> path to be used.? And the os.path functions aren't helpful here when >>> they actually_change_? the meanings of paths on Windows: >>> >>>>> fp= "C:\\Documents\finance\\" >>>>> abspath(fp) >>> 'C:\\Documents\\finance' >>> >>> If you believe these 'before' and 'after' paths are the same I can only >>> assume that you don't work on Windows (where one refers to a directory >>> and the other a file without an extension). >> >> More accurately, one is not a legal filename but both are legal >> directory names. > > If they are to be created, which is my situation, the result will be a > diretory and a file. os.mkdir('C:\\Documents\\finance') creates a directory. open('C:\\Documents\\finance', 'w') creates a file. The difference is in the operation, not in the name. 'C:\\Documents\\finance' is a pathname, which can refer to either a directory or a file. 'C:\\Documents\\finance\\' could refer to a directory, but to me looks more like a partial pathname, not a complete one. I can't think of any reason for ending pathnames with (back)slashes. Just use os.path.join(directory, filename) when you need to refer to a file in the directory. > I would be surprised if issues such as these were not, at least in > significant part, the reason why we now have pathlib. That should be easy to verify: the reasons are listed in the PEP: https://www.python.org/dev/peps/pep-0428 I don't see your issue there. I don't think anyone has ever considered it an issue at all really. >> How are these unexpected extensionless files getting created? > > I believe by attempting to make the directory I send absolute with > abspath() and then copying a file to this path. They expected this to > copy the file into the directory with its original name but instead it > copies it to the file that abspath 'kindly' converts my directory into. We're getting closer to the real issue here. What functions were used copy these files? With which parameters? Were the destination directories created before copying the files to them? > I did complain about their lack of knowledge but I also have a right to > complain about a function that converts an explicitly specified > directory into a file :-) Again, a pathname is never inherently a directory or a file. -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From roel at roelschroeven.net Wed May 27 13:42:19 2020 From: roel at roelschroeven.net (Roel Schroeven) Date: Wed, 27 May 2020 19:42:19 +0200 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <87zh9ts7ak.fsf@bsb.me.uk> Message-ID: BlindAnagram schreef op 27/05/2020 om 18:53: > Its not my bug to fix - the semantics of what I send is very clear on > any Windows system. That's the first time I see any mention of those semantics, and I've been using Windows since the Windows 3.1 days (and MS-DOS before that, since 3.2 IIRC). -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From roel at roelschroeven.net Wed May 27 13:40:26 2020 From: roel at roelschroeven.net (Roel Schroeven) Date: Wed, 27 May 2020 19:40:26 +0200 Subject: Behaviour of os.path.join In-Reply-To: <87zh9ts7ak.fsf@bsb.me.uk> References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <87zh9ts7ak.fsf@bsb.me.uk> Message-ID: Ben Bacarisse schreef op 27/05/2020 om 17:53: > There is well-known (*nix) software that relies on a/b/c/ meaning > something different to a/b/c but I don't know anyone who thinks this is > a good idea. It causes no end of confusion. rsync? I always have to look up whether or not I need to use a trailing / on the source directory. It's confusing indeed. -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From ben.usenet at bsb.me.uk Wed May 27 14:22:57 2020 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 27 May 2020 19:22:57 +0100 Subject: Behaviour of os.path.join References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <87zh9ts7ak.fsf@bsb.me.uk> Message-ID: <87tv01s0e6.fsf@bsb.me.uk> BlindAnagram writes: > On 27/05/2020 16:53, Ben Bacarisse wrote: >> As it should. Relying on a trailing \ having the right effect is >> brittle to say the least. > > In my case less brittle than leaving it out. Brittle does not mean broken. I know you can fix it by making sure the trailing \ is there. It's that solution that is brittle. > Its not my bug to fix - the semantics of what I send is very clear on > any Windows system. Then there is no bug. You just constructed the path using a method that did not behave as you expected. That happens all the time. -- Ben. From rosuav at gmail.com Wed May 27 16:15:37 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 May 2020 06:15:37 +1000 Subject: Access an object to which being bound In-Reply-To: References: Message-ID: On Thu, May 28, 2020 at 5:48 AM Abdur-Rahmaan Janhangeer wrote: > > Greetings, > > Lets say i have > > class A: > ... > > class B: > self.x = A > > then used > > b = B() > z = b.x() > > now how in A i get a reference to B when z is assigned to b.x? > Things are very tangled here. What exactly are you doing? Your code is incomplete at the moment, and I'm not sure what you're trying to achieve. As it currently stands, class A is completely stand-alone and will not have any way of knowing about B. ChrisA From rosuav at gmail.com Wed May 27 16:21:15 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 May 2020 06:21:15 +1000 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <87zh9ts7ak.fsf@bsb.me.uk> Message-ID: On Thu, May 28, 2020 at 6:14 AM Roel Schroeven wrote: > > Ben Bacarisse schreef op 27/05/2020 om 17:53: > > There is well-known (*nix) software that relies on a/b/c/ meaning > > something different to a/b/c but I don't know anyone who thinks this is > > a good idea. It causes no end of confusion. > > rsync? I always have to look up whether or not I need to use a trailing > / on the source directory. It's confusing indeed. > Possibly, but only as a means of forcing the interpretation. Plain vanilla cp has the same thing with its destination. If you say "cp a b c d" and d doesn't exist, cp will create it as a single file; but if you say "cp a b c d/" then cp will error out if d isn't a directory (including if it doesn't exist). But if d is a directory, then it makes no difference which way you do it. Similarly, a .gitignore file can reference a path name and include a trailing slash; this forces it to be interpreted as a directory, but otherwise has the same effect. A path is a path is a path. Whether it refers to a file, a directory, a symlink, a named pipe, a socket, or whatever, it's still a path. Windows does some weird things with drive letters, but the rest of it is still just a path. ChrisA From arj.python at gmail.com Wed May 27 16:26:57 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 May 2020 00:26:57 +0400 Subject: Access an object to which being bound In-Reply-To: References: Message-ID: Thanks, Actually i want to keep a reference from B to all A instantiated like in the case of z I have class A and i want to call class B via A You can have def x(self, *args, **kwargs): return A(*args, **kwargs) but was wondering if we could keep track while doing it via z = ... Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy | blog github Mauritius On Thu, May 28, 2020 at 12:15 AM Chris Angelico wrote: > On Thu, May 28, 2020 at 5:48 AM Abdur-Rahmaan Janhangeer > wrote: > > > > Greetings, > > > > Lets say i have > > > > class A: > > ... > > > > class B: > > self.x = A > > > > then used > > > > b = B() > > z = b.x() > > > > now how in A i get a reference to B when z is assigned to b.x? > > > > Things are very tangled here. What exactly are you doing? Your code is > incomplete at the moment, and I'm not sure what you're trying to > achieve. As it currently stands, class A is completely stand-alone and > will not have any way of knowing about B. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From arj.python at gmail.com Wed May 27 16:33:55 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 May 2020 00:33:55 +0400 Subject: Access an object to which being bound In-Reply-To: References: Message-ID: i have this: https://github.com/Abdur-rahmaanJ/hooman/blob/master/hooman/hooman.py someone PRed a Button class i want the class button to be available to the class Hooman via Human.button self.button = Button but button has update() which must be called individually one way to update all buttons is to keep track of buttons instantiated and calling update on each one. Wrap in a update_all () method And please close your eyes to the wonderful mess Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy | blog github Mauritius On Thu, May 28, 2020 at 12:15 AM Chris Angelico wrote: > On Thu, May 28, 2020 at 5:48 AM Abdur-Rahmaan Janhangeer > wrote: > > > > Greetings, > > > > Lets say i have > > > > class A: > > ... > > > > class B: > > self.x = A > > > > then used > > > > b = B() > > z = b.x() > > > > now how in A i get a reference to B when z is assigned to b.x? > > > > Things are very tangled here. What exactly are you doing? Your code is > incomplete at the moment, and I'm not sure what you're trying to > achieve. As it currently stands, class A is completely stand-alone and > will not have any way of knowing about B. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Wed May 27 16:41:35 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 May 2020 06:41:35 +1000 Subject: Access an object to which being bound In-Reply-To: References: Message-ID: On Thu, May 28, 2020 at 6:27 AM Abdur-Rahmaan Janhangeer wrote: > > Thanks, > > Actually i want to keep a reference from B to all A > instantiated like in the case of z > > I have class A and i want to call class B via A > > You can have > > def x(self, *args, **kwargs): > return A(*args, **kwargs) > > but was wondering if we could keep track while > doing it via z = ... > Okay, now I think I get what you're after. Let's simplify and clarify things. Let me know if I'm misinterpreting. 1) You have a container class that can instantiate objects of a thing class 2a) You wish for the container to be aware of all things it has created - OR - 2b) You wish for the Thing to be aware of all containers that have created them 3) You want this to happen automatically. I'm not sure which way round you're trying to do this, so I'll try to answer both. Your Container (Hooman) can construct multiple Things (Button), and other classes could also construct Things. So you need some way to automatically register the Thing as you create it. The easiest way to do this would, I think, be to have your Container subclass a utility class, and then use self.Button() instead of Button(). That can take care of registering the button in some sort of list, and then it can still return the button in case you need it for something else. Would that work? Or am I completely off on my analysis? ChrisA From arj.python at gmail.com Wed May 27 16:57:30 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 May 2020 00:57:30 +0400 Subject: Access an object to which being bound In-Reply-To: References: Message-ID: Hum yes a third class is a nice option! btw managed to do it with those in Hooman self._all_widgets = [] def button(self, *args, **kwargs): b = Button(*args, **kwargs) self._all_widgets.append(b) return b def update_all(self): for widget in self._all_widgets: widget.update() Just in the drawing loop i have (hapi is a Hooman object) for i in range(5): x = hapi.button( # params ) hapi.update_all() the update all adds a button in the array each frame, that's beyond the question but for creating buttons on the fly each frame was never a good option (better define before then update x and y in loop) that's the only caveat to watch out if people create objects on the fly Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy | blog github Mauritius On Thu, May 28, 2020 at 12:41 AM Chris Angelico wrote: > On Thu, May 28, 2020 at 6:27 AM Abdur-Rahmaan Janhangeer > wrote: > > > > Thanks, > > > > Actually i want to keep a reference from B to all A > > instantiated like in the case of z > > > > I have class A and i want to call class B via A > > > > You can have > > > > def x(self, *args, **kwargs): > > return A(*args, **kwargs) > > > > but was wondering if we could keep track while > > doing it via z = ... > > > > Okay, now I think I get what you're after. Let's simplify and clarify > things. Let me know if I'm misinterpreting. > > 1) You have a container class that can instantiate objects of a thing class > 2a) You wish for the container to be aware of all things it has created - > OR - > 2b) You wish for the Thing to be aware of all containers that have created > them > 3) You want this to happen automatically. > > I'm not sure which way round you're trying to do this, so I'll try to > answer both. Your Container (Hooman) can construct multiple Things > (Button), and other classes could also construct Things. So you need > some way to automatically register the Thing as you create it. > > The easiest way to do this would, I think, be to have your Container > subclass a utility class, and then use self.Button() instead of > Button(). That can take care of registering the button in some sort of > list, and then it can still return the button in case you need it for > something else. > > Would that work? Or am I completely off on my analysis? > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From ben.usenet at bsb.me.uk Wed May 27 16:57:46 2020 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 27 May 2020 21:57:46 +0100 Subject: Behaviour of os.path.join References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <87zh9ts7ak.fsf@bsb.me.uk> Message-ID: <87o8q9rt84.fsf@bsb.me.uk> Roel Schroeven writes: > Ben Bacarisse schreef op 27/05/2020 om 17:53: >> There is well-known (*nix) software that relies on a/b/c/ meaning >> something different to a/b/c but I don't know anyone who thinks this is >> a good idea. It causes no end of confusion. > > rsync? I always have to look up whether or not I need to use a > trailing / on the source directory. It's confusing indeed. That was the one I was thinking of. -- Ben. From blindanagram at nowhere.com Wed May 27 17:00:13 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Wed, 27 May 2020 22:00:13 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> <6472c1ef-2544-01a8-cc89-0a30ba99d5ca@kynesim.co.uk> Message-ID: On 27/05/2020 18:37, Roel Schroeven wrote: > BlindAnagram schreef op 27/05/2020 om 18:39: >> On 27/05/2020 16:49, Rhodri James wrote: >>> On 27/05/2020 16:12, BlindAnagram wrote: >>>> I'm sorry that you don't believe me but all I know is how I intend the >>>> path to be used.? And the os.path functions aren't helpful here when >>>> they actually_change_? the meanings of paths on Windows: >>>> >>>>>> fp= "C:\\Documents\finance\\" >>>>>> abspath(fp) >>>> 'C:\\Documents\\finance' >>>> >>>> If you believe these 'before' and 'after' paths are the same I can only >>>> assume that you don't work on Windows (where one refers to a directory >>>> and the other a file without an extension). >>> >>> More accurately, one is not a legal filename but both are legal >>> directory names. >> >> If they are to be created, which is my situation, the result will be a >> diretory and a file. > > os.mkdir('C:\\Documents\\finance') creates a directory. > open('C:\\Documents\\finance', 'w') creates a file. > > The difference is in the operation, not in the name. > > 'C:\\Documents\\finance' is a pathname, which can refer to either a > directory or a file. > 'C:\\Documents\\finance\\' could refer to a directory, but to me looks > more like a partial pathname, not a complete one. > > I can't think of any reason for ending pathnames with (back)slashes. > Just use os.path.join(directory, filename) when you need to refer to a > file in the directory. > >> I would be surprised if issues such as these were not, at least in >> significant part, the reason why we now have pathlib. > > That should be easy to verify: the reasons are listed in the PEP: > https://www.python.org/dev/peps/pep-0428 > I don't see your issue there. I don't think anyone has ever considered > it an issue at all really. > >>> How are these unexpected extensionless files getting created? >> >> I believe by attempting to make the directory I send absolute with >> abspath() and then copying a file to this path.? They expected this to >> copy the file into the directory with its original name but instead it >> copies it to the file that abspath 'kindly' converts my directory into. > > We're getting closer to the real issue here. What functions were used > copy these files? With which parameters? > Were the destination directories created before copying the files to them? > >> I did complain about their lack of knowledge but I also have a right to >> complain about a function that converts an explicitly specified >> directory into a file :-) > > Again, a pathname is never inherently a directory or a file. You can define a path however you want but it won't change the fact that on Windows a path that ends in '\\' is inherently a path to a directory. From blindanagram at nowhere.com Wed May 27 16:55:50 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Wed, 27 May 2020 21:55:50 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <87zh9ts7ak.fsf@bsb.me.uk> Message-ID: On 27/05/2020 18:42, Roel Schroeven wrote: > BlindAnagram schreef op 27/05/2020 om 18:53: >> Its not my bug to fix - the semantics of what I send is very clear on >> any Windows system. > > That's the first time I see any mention of those semantics, and I've > been using Windows since the Windows 3.1 days (and MS-DOS before that, > since 3.2 IIRC). Well I can only say that I am surpised that anyone working on Windows code development for as long as you have doesn't know that a path that ends in '\\' is a path to a directory. From PythonList at DancesWithMice.info Wed May 27 18:14:02 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 28 May 2020 10:14:02 +1200 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> <6472c1ef-2544-01a8-cc89-0a30ba99d5ca@kynesim.co.uk> Message-ID: ... >> Again, a pathname is never inherently a directory or a file. See previous contribution: until YOU define YOUR arena of operations, it will be difficult to select the correct tool or library - or for others to assist you. If dealing with strings (which happen to look as if they are file/directory names) then use str.join() plus build custom functions to suit yourself/your specification. If dealing with strings which represent files/directories, use pathlib's abstraction. If the above applies, but eventually are applied to a file-system, use pathlib's "concrete" classes, at that point. If you are prepared to accept the os/os.path library's abstraction(s), then please go-ahead with that alternative. If any of the provided libraries are insufficient, please search Pypi (etc) for a suitable alternative, or develop your own routines. > You can define a path however you want but it won't change the fact that > on Windows a path that ends in '\\' is inherently a path to a directory. Referring to the first clause: again, see previous contribution, and link to descriptions of paths (etc) and comparisons across OpSys. We can't define/re-define such terms to suit ourselves - nor does Python. If your specification embraces only MS-Windows, then please ignore the Python facilities which attempt a more universal solution. If, however, you choose a more universal abstraction, then please accept that it will not (necessarily) offer solutions which are Windows-specific - by definition. Referring to the final conclusion: a solution already exists (again, please refer to docs/link in previous contribution, and repeated 'here' by @Beverley). She provides evidence for macOS, here is same from Linux: >>> os.path.join( '/dir', 'dir', '' ) '/dir/dir/' Personally, I find the final path (as empty string) to be both ugly and a little confusing, but by ignoring the inherent 'intelligence' we can direct: >>> os.path.join( '/dir', 'dir/' ) '/dir/dir/' What happens on MS-Windows? Of course, given that this -join() doesn't care about content, but requires only "path(s)" as parameter(s), we can 'do our own thing': >>> os.path.join( '/dir', 'file' ) '/dir/file' >>> os.path.join( '/dir', 'file/' ) '/dir/file/' ??? With great power, comes great... - and from this conversation it would appear many (like me) wouldn't want to contemplate such a thing. However, it *is* possible, and given that it satisfies your stated spec, you could "define...however you want" and make the decision without reference to 'the rest of us'. Once you have coded your solution, which you could then use as 'sample code', please feel free to suggest a bug-fix which describes:- - the problem-set, - the scenario(s) in which it is a problem, - the problems of your solution (as coded), and - your idea for a more elegant, Pythonic, solution. -- Regards =dn From barry at barrys-emacs.org Wed May 27 17:48:41 2020 From: barry at barrys-emacs.org (Barry) Date: Wed, 27 May 2020 22:48:41 +0100 Subject: Issues regarding running of application. In-Reply-To: References: Message-ID: <1EDDC532-54C4-4223-ADCA-1832742FC8CD@barrys-emacs.org> > On 27 May 2020, at 09:44, Souvik Dutta wrote: > > ?Do have the latest version of DirectX installed? If not then do that or you > can google out the dll file you need (or is missing) and download it and > cut - paste it wherever needed. Missing dll files is a very common issue in > windows and thus Microsoft made DirectX. Maybe the c runtime but not direct x that?s typically for games. Barry > >> On Tue, 26 May, 2020, 11:14 pm Meet Agrawal, wrote: >> >> I have tried and installed the python application a lot of times but after >> the installation get completed and I try to run the application, it say >> that api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. >> >> Please tell me a way out. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Wed May 27 18:44:43 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Thu, 28 May 2020 10:44:43 +1200 Subject: Access an object to which being bound In-Reply-To: References: Message-ID: <45ba1c4e-8931-afc9-4c22-c58574dc1b97@DancesWithMice.info> @AR, On 28/05/20 8:41 AM, Chris Angelico wrote: > On Thu, May 28, 2020 at 6:27 AM Abdur-Rahmaan Janhangeer > wrote: >> >> Thanks, >> >> Actually i want to keep a reference from B to all A >> instantiated like in the case of z >> >> I have class A and i want to call class B via A >> >> You can have >> >> def x(self, *args, **kwargs): >> return A(*args, **kwargs) >> >> but was wondering if we could keep track while >> doing it via z = ... >> > > Okay, now I think I get what you're after. Let's simplify and clarify > things. Let me know if I'm misinterpreting. > > 1) You have a container class that can instantiate objects of a thing class > 2a) You wish for the container to be aware of all things it has created - OR - > 2b) You wish for the Thing to be aware of all containers that have created them > 3) You want this to happen automatically. > > I'm not sure which way round you're trying to do this, so I'll try to > answer both. Your Container (Hooman) can construct multiple Things > (Button), and other classes could also construct Things. So you need > some way to automatically register the Thing as you create it. > > The easiest way to do this would, I think, be to have your Container > subclass a utility class, and then use self.Button() instead of > Button(). That can take care of registering the button in some sort of > list, and then it can still return the button in case you need it for > something else. > > Would that work? Or am I completely off on my analysis? Here's some sample code, which may give you some ideas (intriguingly it comes from my playing-about with a project @Chris described (some time back), which includes the need to 'register' sub-components and to keep a count of them): # PSL import collections from itertools import count class Link(): '''Contain original link, manipulate for presentation, and retain for later action. ''' ID = count( 0 ) instances = [] def __init__( self, token:Token, )->None: '''Instantiate.''' self.token = token self.linkNR:int = next( self.ID ) #linkNR Link.instances.append( self ) #form a register of instances/links self.URL:str = "" ...more methods here - likely irrelevant to your needs... class LinksRegister( collections.UserList ): '''Links available for use within application.''' def __iter__( self ): '''Generator.''' for link in self.data: yield link def register_links( self, cls ): '''Register all links.''' self.data = cls.instances Once all of the Link() objects have been ascertained, we can make use of the class-attributes: links_register.register_links( Link ) NB in this scenario it is only necessary to register once - all of the links at-once, cf registering each link as it is itself instantiated. Also, that each Link() object is not aware that it is/will be 'registered'! Later, when it is necessary to carry-out the same action on each of the objects, we can use the register's iterator/generator (as above). Critique/other ideas welcome... -- Regards =dn From roel at roelschroeven.net Wed May 27 18:39:30 2020 From: roel at roelschroeven.net (Roel Schroeven) Date: Thu, 28 May 2020 00:39:30 +0200 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <87zh9ts7ak.fsf@bsb.me.uk> Message-ID: BlindAnagram schreef op 27/05/2020 om 22:55: > On 27/05/2020 18:42, Roel Schroeven wrote: >> BlindAnagram schreef op 27/05/2020 om 18:53: >>> Its not my bug to fix - the semantics of what I send is very clear on >>> any Windows system. >> >> That's the first time I see any mention of those semantics, and I've >> been using Windows since the Windows 3.1 days (and MS-DOS before that, >> since 3.2 IIRC). > > Well I can only say that I am surpised that anyone working on Windows > code development for as long as you have doesn't know that a path that > ends in '\\' is a path to a directory. A path ending in a backslash cannot refer to a file, that much is true. So if you have such a path and you insist that path is not an incomplete path, than it must out of necessity be a directory. But a path not ending in a backslash can refer to a directory just as well. If those semantics are as clear as you say, it shouldn't be too difficult to point us to a section in the Windows documentation that confirms that. A quick search turns up "Naming Files, Paths, and Namespaces" (https://docs.microsoft.com/nl-be/windows/win32/fileio/naming-a-file) which seems to be relevant. I see some example directory names without backslashes at the end, and I see text like "Note that a directory is simply a file with a special attribute designating it as a directory, but otherwise must follow all the same naming rules as a regular file. Because the term directory simply refers to a special type of file as far as the file system is concerned, some reference material will use the general term file to encompass both concepts of directories and data files as such. Because of this, unless otherwise specified, any naming or usage rules or examples for a file should also apply to a directory." and "Note that directory names are stored by the file system as a special type of file, but naming rules for files also apply to directory names. To summarize, a path is simply the string representation of the hierarchy between all of the directories that exist for a particular file or directory name." I find no hints of adding a backslash at the end to indicate directories. If you can point me to convincing evidence in the documentation I'll change my mind. I'm sorry if my language seems abrasive; that is not my intention. I'm only trying to help you and clear up a misunderstanding (which could be mine, if it turns out you're right after all). -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From rosuav at gmail.com Wed May 27 19:06:53 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 May 2020 09:06:53 +1000 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> <6472c1ef-2544-01a8-cc89-0a30ba99d5ca@kynesim.co.uk> Message-ID: On Thu, May 28, 2020 at 7:07 AM BlindAnagram wrote: > You can define a path however you want but it won't change the fact that > on Windows a path that ends in '\\' is inherently a path to a directory. Citation needed. ChrisA From rosuav at gmail.com Wed May 27 19:28:31 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 May 2020 09:28:31 +1000 Subject: Elegant hack or gross hack? TextWrapper and escape codes Message-ID: Situation: A terminal application. Requirement: Display nicely-wrapped text. With colour codes in it. And that text might be indented to any depth. label = f"{indent}\U0010cc32{code}\U0010cc00 @{tweet['user']['screen_name']}: " wrapper = textwrap.TextWrapper( initial_indent=label, subsequent_indent=indent + " " * 12, width=shutil.get_terminal_size().columns, break_long_words=False, break_on_hyphens=False, # Stop URLs from breaking ) for line in tweet["full_text"].splitlines(): print(wrapper.fill(line) .replace("\U0010cc32", "\x1b[32m\u2026") .replace("\U0010cc00", "\u2026\x1b[0m") ) wrapper.initial_indent = wrapper.subsequent_indent # For subsequent lines, just indent them The parameter "indent" is always some number of spaces (possibly zero). If I simply include the escape codes in the label, their characters will be counted, and the first line will be shorter. Rather than mess with how textwrap defines text, I just replace the escape codes *and one other character* with a placeholder. In the final display, \U0010cc32 means "colour code 32 and an ellipsis", and \U0010cc00 means "colour code 0 and an ellipsis", so textwrap correctly counts them as one character each. So what do you folks think? Is this a gloriously elegant way to collapse nonprinting text, or is it a gross hacky mess that's going to cause problems? ChrisA From arj.python at gmail.com Wed May 27 23:59:22 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 May 2020 07:59:22 +0400 Subject: Access an object to which being bound In-Reply-To: <45ba1c4e-8931-afc9-4c22-c58574dc1b97@DancesWithMice.info> References: <45ba1c4e-8931-afc9-4c22-c58574dc1b97@DancesWithMice.info> Message-ID: Greetings, .append(self) is a hit idea Updated the project with the button demo https://github.com/Abdur-rahmaanJ/hooman/ Next i will be attempting to add a grid system. I feel myself developing tkinter from scratch Thanks for the help everybody ^^_ Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy | blog github Mauritius On Thu, May 28, 2020 at 2:45 AM DL Neil via Python-list < python-list at python.org> wrote: > @AR, > > > On 28/05/20 8:41 AM, Chris Angelico wrote: > > On Thu, May 28, 2020 at 6:27 AM Abdur-Rahmaan Janhangeer > > wrote: > >> > >> Thanks, > >> > >> Actually i want to keep a reference from B to all A > >> instantiated like in the case of z > >> > >> I have class A and i want to call class B via A > >> > >> You can have > >> > >> def x(self, *args, **kwargs): > >> return A(*args, **kwargs) > >> > >> but was wondering if we could keep track while > >> doing it via z = ... > >> > > > > Okay, now I think I get what you're after. Let's simplify and clarify > > things. Let me know if I'm misinterpreting. > > > > 1) You have a container class that can instantiate objects of a thing > class > > 2a) You wish for the container to be aware of all things it has created > - OR - > > 2b) You wish for the Thing to be aware of all containers that have > created them > > 3) You want this to happen automatically. > > > > I'm not sure which way round you're trying to do this, so I'll try to > > answer both. Your Container (Hooman) can construct multiple Things > > (Button), and other classes could also construct Things. So you need > > some way to automatically register the Thing as you create it. > > > > The easiest way to do this would, I think, be to have your Container > > subclass a utility class, and then use self.Button() instead of > > Button(). That can take care of registering the button in some sort of > > list, and then it can still return the button in case you need it for > > something else. > > > > Would that work? Or am I completely off on my analysis? > > Here's some sample code, which may give you some ideas (intriguingly it > comes from my playing-about with a project @Chris described (some time > back), which includes the need to 'register' sub-components and to keep > a count of them): > > > # PSL > import collections > from itertools import count > > > class Link(): > '''Contain original link, manipulate for presentation, > and retain for later action. > ''' > > ID = count( 0 ) > instances = [] > > > def __init__( self, token:Token, )->None: > '''Instantiate.''' > self.token = token > > self.linkNR:int = next( self.ID ) #linkNR > Link.instances.append( self ) #form a register > of instances/links > > self.URL:str = "" > > ...more methods here - likely irrelevant to your needs... > > > class LinksRegister( collections.UserList ): > '''Links available for use within application.''' > > def __iter__( self ): > '''Generator.''' > for link in self.data: > yield link > > def register_links( self, cls ): > '''Register all links.''' > self.data = cls.instances > > > Once all of the Link() objects have been ascertained, we can make use of > the class-attributes: > > links_register.register_links( Link ) > > NB in this scenario it is only necessary to register once - all of the > links at-once, cf registering each link as it is itself instantiated. > Also, that each Link() object is not aware that it is/will be 'registered'! > > > Later, when it is necessary to carry-out the same action on each of the > objects, we can use the register's iterator/generator (as above). > > > Critique/other ideas welcome... > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From zljubisic at gmail.com Thu May 28 01:19:45 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 27 May 2020 22:19:45 -0700 (PDT) Subject: Custom logging function In-Reply-To: References: <04d4e0a3-99b6-4d3f-94bf-8da702365494@googlegroups.com> Message-ID: <4ed4c0f7-cea2-49ed-b568-b8f5cf902577@googlegroups.com> > You create two stream handlers that both log to stderr -- one with > basicConfig() and one explicitly in your code. That's probably not what you > want. How can I just add terminator = '\r\n' to the code bellow? Where should I put it? import logging LOG_LEVEL = logging.getLevelName('DEBUG') logging.basicConfig(level=LOG_LEVEL, format='%(asctime)s %(levelname)s %(name)s %(funcName)-20s %(message)s', datefmt='%d.%m.%Y %H:%M:%S') logging.info('Main script started') From rahulgupta100689 at gmail.com Thu May 28 01:49:53 2020 From: rahulgupta100689 at gmail.com (Rahul Gupta) Date: Wed, 27 May 2020 22:49:53 -0700 (PDT) Subject: Ram memory not freed after executing python script on ubuntu system Message-ID: I am having a Ubuntu system which has 125 Gb of RAM. I executed few python scripts on that system. Those scripts uses numpy arrays and pandas. Now execution was over but still 50 gb of RAM and 2 Gb cache and 8.4 Gb of swap is occupied. At this moment nothing is running on the system. I have googled it. Most of th result shows that python garbage collector is poor in performance. I want this memory to be cleaned and re claim. One of the easiest way is to restart the system but i dont want to restart i want a way to do this when the system is up and running. Kindly tell me how to do this. Thanks From rosuav at gmail.com Thu May 28 02:05:34 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 May 2020 16:05:34 +1000 Subject: Ram memory not freed after executing python script on ubuntu system In-Reply-To: References: Message-ID: On Thu, May 28, 2020 at 3:51 PM Rahul Gupta wrote: > > > I am having a Ubuntu system which has 125 Gb of RAM. I executed few python scripts on that system. Those scripts uses numpy arrays and pandas. Now execution was over but still 50 gb of RAM and 2 Gb cache and 8.4 Gb of swap is occupied. At this moment nothing is running on the system. I have googled it. Most of th result shows that python garbage collector is poor in performance. I want this memory to be cleaned and re claim. One of the easiest way is to restart the system but i dont want to restart i want a way to do this when the system is up and running. Kindly tell me how to do this. Thanks > The Python garbage collector is irrelevant once you have terminated Python. I suggest you look elsewhere in your system - if 50GB of RAM is still in use after the Python process has ended, it's not being used by Python. Also, that's an awful lot of RAM, but a surprising amount. Are you sure it's not 128GB? I don't know where you got your information from regarding the "poor performance" of the Python GC, but without citations, it's nothing but FUD. ChrisA From __peter__ at web.de Thu May 28 03:02:35 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 May 2020 09:02:35 +0200 Subject: Custom logging function References: <04d4e0a3-99b6-4d3f-94bf-8da702365494@googlegroups.com> <4ed4c0f7-cea2-49ed-b568-b8f5cf902577@googlegroups.com> Message-ID: zljubisic at gmail.com wrote: >> You create two stream handlers that both log to stderr -- one with >> basicConfig() and one explicitly in your code. That's probably not what >> you want. > > How can I just add terminator = '\r\n' to the code bellow? > Where should I put it? I already answered that in my first post in the thread. Spoon-feeding below ;) > import logging > > LOG_LEVEL = logging.getLevelName('DEBUG') > > logging.basicConfig(level=LOG_LEVEL, > format='%(asctime)s %(levelname)s %(name)s > %(funcName)-20s %(message)s', datefmt='%d.%m.%Y > %H:%M:%S') [handler] = logging.getLogger().handlers handler.terminator = "\r\n" > logging.info('Main script started') From __peter__ at web.de Thu May 28 03:52:40 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 May 2020 09:52:40 +0200 Subject: Elegant hack or gross hack? TextWrapper and escape codes References: Message-ID: Chris Angelico wrote: > Situation: A terminal application. Requirement: Display nicely-wrapped > text. With colour codes in it. And that text might be indented to any > depth. > > label = f"{indent}\U0010cc32{code}\U0010cc00 > @{tweet['user']['screen_name']}: " wrapper = textwrap.TextWrapper( > initial_indent=label, > subsequent_indent=indent + " " * 12, > width=shutil.get_terminal_size().columns, > break_long_words=False, break_on_hyphens=False, # Stop URLs from > breaking > ) > for line in tweet["full_text"].splitlines(): > print(wrapper.fill(line) > .replace("\U0010cc32", "\x1b[32m\u2026") > .replace("\U0010cc00", "\u2026\x1b[0m") > ) > wrapper.initial_indent = wrapper.subsequent_indent # For > subsequent lines, just indent them > > > The parameter "indent" is always some number of spaces (possibly > zero). If I simply include the escape codes in the label, their > characters will be counted, and the first line will be shorter. Rather > than mess with how textwrap defines text, I just replace the escape > codes *and one other character* with a placeholder. In the final > display, \U0010cc32 means "colour code 32 and an ellipsis", and > \U0010cc00 means "colour code 0 and an ellipsis", so textwrap > correctly counts them as one character each. > > So what do you folks think? Is this a gloriously elegant way to > collapse nonprinting text, or is it a gross hacky mess Yes ;) > that's going to cause problems? Probably not. I had a quick look at the TextWrapper class, and it doesn't really lend itself to clean and elegant customisation. However, my first idea to approach this problem was to patch the len() builtin: import re import textwrap text = """The parameter "indent" is always some number of spaces (possibly zero). If I simply include the escape codes in the label, their characters will be counted, and the first line will be shorter. Rather than mess with how textwrap defines text, I just replace the escape codes *and one other character* with a placeholder. In the final display, \U0010cc32 means "colour code 32 and an ellipsis", and \U0010cc00 means "colour code 0 and an ellipsis", so textwrap correctly counts them as one character each. """ print(textwrap.fill(text, width=40)) # add some color to the text sample GREEN = "\x1b[32m" NORMAL = "\x1b[0m" parts = text.split(" ") parts[::2] = [GREEN + p + NORMAL for p in parts[::2]] ctext = " ".join(parts) # wrong wrapping print(textwrap.fill(ctext, width=40)) # fixed wrapping def color_len(s): return len(re.compile("\x1b\[\d+m").sub("", s)) textwrap.len = color_len print(textwrap.fill(ctext, width=40)) The output of my ad-hoc test script looks OK. However, I did not try to understand the word-breaking regexes, so I don't know if the escape codes can be spread across words which would confuse color_len(). Likewise, I have no idea if textwrap can cope with zero-length chunks. But at least now you have two -- elegant or gross -- hacks to choose from ;) From rosuav at gmail.com Thu May 28 04:01:15 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 May 2020 18:01:15 +1000 Subject: Elegant hack or gross hack? TextWrapper and escape codes In-Reply-To: References: Message-ID: On Thu, May 28, 2020 at 5:54 PM Peter Otten <__peter__ at web.de> wrote: > > Chris Angelico wrote: > > > Situation: A terminal application. Requirement: Display nicely-wrapped > > text. With colour codes in it. And that text might be indented to any > > depth. > > > > label = f"{indent}\U0010cc32{code}\U0010cc00 > > @{tweet['user']['screen_name']}: " wrapper = textwrap.TextWrapper( > > initial_indent=label, > > subsequent_indent=indent + " " * 12, > > width=shutil.get_terminal_size().columns, > > break_long_words=False, break_on_hyphens=False, # Stop URLs from > > breaking > > ) > > for line in tweet["full_text"].splitlines(): > > print(wrapper.fill(line) > > .replace("\U0010cc32", "\x1b[32m\u2026") > > .replace("\U0010cc00", "\u2026\x1b[0m") > > ) > > wrapper.initial_indent = wrapper.subsequent_indent # For > > subsequent lines, just indent them > > > > > > The parameter "indent" is always some number of spaces (possibly > > zero). If I simply include the escape codes in the label, their > > characters will be counted, and the first line will be shorter. Rather > > than mess with how textwrap defines text, I just replace the escape > > codes *and one other character* with a placeholder. In the final > > display, \U0010cc32 means "colour code 32 and an ellipsis", and > > \U0010cc00 means "colour code 0 and an ellipsis", so textwrap > > correctly counts them as one character each. > > > > So what do you folks think? Is this a gloriously elegant way to > > collapse nonprinting text, or is it a gross hacky mess > > Yes ;) ... I should have expected a "yes" response to an either-or question. Silly of me. :) > > that's going to cause problems? > > Probably not. > > I had a quick look at the TextWrapper class, and it doesn't really lend > itself to clean and elegant customisation. However, my first idea to > approach this problem was to patch the len() builtin: > > import re > import textwrap > > text = """The parameter "indent" is always some number of spaces (possibly > zero). If I simply include the escape codes in the label, their > characters will be counted, and the first line will be shorter. Rather > than mess with how textwrap defines text, I just replace the escape > codes *and one other character* with a placeholder. In the final > display, \U0010cc32 means "colour code 32 and an ellipsis", and > \U0010cc00 means "colour code 0 and an ellipsis", so textwrap > correctly counts them as one character each. > """ > > print(textwrap.fill(text, width=40)) > > # add some color to the text sample > GREEN = "\x1b[32m" > NORMAL = "\x1b[0m" > parts = text.split(" ") > parts[::2] = [GREEN + p + NORMAL for p in parts[::2]] > ctext = " ".join(parts) > > # wrong wrapping > print(textwrap.fill(ctext, width=40)) > > # fixed wrapping > def color_len(s): > return len(re.compile("\x1b\[\d+m").sub("", s)) > > textwrap.len = color_len > print(textwrap.fill(ctext, width=40)) > > The output of my ad-hoc test script looks OK. However, I did not try to > understand the word-breaking regexes, so I don't know if the escape codes > can be spread across words which would confuse color_len(). Likewise, I have > no idea if textwrap can cope with zero-length chunks. > > But at least now you have two -- elegant or gross -- hacks to choose from ;) > Yeah, I thought of this originally as a challenge in redefining the concept of "length". But the trouble is that it might not always be the len() function that figures out the length - there might be a regex with a size threshold or any number of other things that effectively think about the length of the string. ChrisA From __peter__ at web.de Thu May 28 04:14:28 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 May 2020 10:14:28 +0200 Subject: Elegant hack or gross hack? TextWrapper and escape codes References: Message-ID: Chris Angelico wrote: > On Thu, May 28, 2020 at 5:54 PM Peter Otten <__peter__ at web.de> wrote: >> But at least now you have two -- elegant or gross -- hacks to choose from >> ;) >> > > Yeah, I thought of this originally as a challenge in redefining the > concept of "length". But the trouble is that it might not always be > the len() function that figures out the length - there might be a > regex with a size threshold or any number of other things that > effectively think about the length of the string. So start with your hack, and if the pain becomes too hard do it right, perhaps making TextWrapper a bit more intelligible in the process. From rahulgupta100689 at gmail.com Thu May 28 04:22:12 2020 From: rahulgupta100689 at gmail.com (Rahul Gupta) Date: Thu, 28 May 2020 01:22:12 -0700 (PDT) Subject: Ram memory not freed after executing python script on ubuntu system In-Reply-To: References: Message-ID: <914b2c71-075a-48a3-9ed8-2ae407fa9ac4@googlegroups.com> On Thursday, May 28, 2020 at 11:20:05 AM UTC+5:30, Rahul Gupta wrote: > I am having a Ubuntu system which has 125 Gb of RAM. I executed few python scripts on that system. Those scripts uses numpy arrays and pandas. Now execution was over but still 50 gb of RAM and 2 Gb cache and 8.4 Gb of swap is occupied. At this moment nothing is running on the system. I have googled it. Most of th result shows that python garbage collector is poor in performance. I want this memory to be cleaned and re claim. One of the easiest way is to restart the system but i dont want to restart i want a way to do this when the system is up and running. Kindly tell me how to do this. Thanks Yes i am sure 125 gb of ram is there. And you talked about refrences see these links https://stackoverflow.com/questions/39100971/how-do-i-release-memory-used-by-a-pandas-dataframe http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm From rosuav at gmail.com Thu May 28 04:45:45 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 May 2020 18:45:45 +1000 Subject: Ram memory not freed after executing python script on ubuntu system In-Reply-To: <914b2c71-075a-48a3-9ed8-2ae407fa9ac4@googlegroups.com> References: <914b2c71-075a-48a3-9ed8-2ae407fa9ac4@googlegroups.com> Message-ID: On Thu, May 28, 2020 at 6:26 PM Rahul Gupta wrote: > > On Thursday, May 28, 2020 at 11:20:05 AM UTC+5:30, Rahul Gupta wrote: > > I am having a Ubuntu system which has 125 Gb of RAM. I executed few python scripts on that system. Those scripts uses numpy arrays and pandas. Now execution was over but still 50 gb of RAM and 2 Gb cache and 8.4 Gb of swap is occupied. At this moment nothing is running on the system. I have googled it. Most of th result shows that python garbage collector is poor in performance. I want this memory to be cleaned and re claim. One of the easiest way is to restart the system but i dont want to restart i want a way to do this when the system is up and running. Kindly tell me how to do this. Thanks > Yes i am sure 125 gb of ram is there. > And you talked about refrences > see these links > https://stackoverflow.com/questions/39100971/how-do-i-release-memory-used-by-a-pandas-dataframe > http://effbot.org/pyfaq/why-doesnt-python-release-the-memory-when-i-delete-a-large-object.htm > Both of those are extremely old. Also, you said that you had terminated the Python process, so neither is relevant. You need to look elsewhere for your memory usage. If Python isn't running, it's not Python that's using up your memory. ChrisA From blindanagram at nowhere.com Thu May 28 05:00:55 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Thu, 28 May 2020 10:00:55 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <87zh9ts7ak.fsf@bsb.me.uk> Message-ID: On 27/05/2020 23:39, Roel Schroeven wrote: > BlindAnagram schreef op 27/05/2020 om 22:55: >> On 27/05/2020 18:42, Roel Schroeven wrote: >>> BlindAnagram schreef op 27/05/2020 om 18:53: >>>> Its not my bug to fix - the semantics of what I send is very clear on >>>> any Windows system. >>> >>> That's the first time I see any mention of those semantics, and I've >>> been using Windows since the Windows 3.1 days (and MS-DOS before that, >>> since 3.2 IIRC). >> >> Well I can only say that I am surpised that anyone working on Windows >> code development for as long as you have doesn't know that a path that >> ends in '\\' is a path to a directory. > > A path ending in a backslash cannot refer to a file, that much is true. > So if you have such a path and you insist that path is not an incomplete > path, than it must out of necessity be a directory. But a path not > ending in a backslash can refer to a directory just as well. I understand that directory paths do not necessarily end in a '\\'. But I am NOT claiming that paths on Windows are paths to directories if and only if they end in '\\' - there is only ONE 'if' in my claim. And this can be refuted with a single counterexample. > If those semantics are as clear as you say, it shouldn't be too > difficult to point us to a section in the Windows documentation that > confirms that. I don't know whether, in the many gigabytes of MS documentation that exists since Windows first emerged, this has ever been explicitly stated. And I am not going to look as it isn't important to me that people accept my claim. But I do find it interesting that it seems important to others here that I should withdraw it. [snip] > I find no hints of adding a backslash at the end to indicate directories. > If you can point me to convincing evidence in the documentation I'll > change my mind. And if you find a counterexample, I will change mine. > I'm sorry if my language seems abrasive; that is not my intention. I'm > only trying to help you and clear up a misunderstanding (which could be > mine, if it turns out you're right after all). No need to apologise, I don't have any problem with your input to this exchange. From jcasale at activenetwerx.com Thu May 28 07:48:24 2020 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 28 May 2020 11:48:24 +0000 Subject: Constructing mime image attachment Message-ID: I have some json encoded input for nodemailer (https://nodemailer.com/message/embedded-images) where the path key is a string value which contains the base64 encoded data such as: { html: 'Embedded image: ', attachments: [{ filename: 'image.png', path: 'data:image/png;base64,iVBORw....', cid: 'unique at nodemailer.com' }] } Does an approach exist to construct a MIMEImage object with the existing base64 string without parsing it and decoding it? Thanks, jlc From eryksun at gmail.com Thu May 28 09:19:10 2020 From: eryksun at gmail.com (Eryk Sun) Date: Thu, 28 May 2020 08:19:10 -0500 Subject: Behaviour of os.path.join In-Reply-To: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: On 5/26/20, BlindAnagram wrote: > > But if I try to make the directory myself (as I tried first): > > join(base, '..\\..\\', 'build', '\\') > > I obtain: > > 'C:\\' > > The documentation says that an absolute path in the parameter list for > join will discard all previous parameters but '\\' is not an absoute path! First, to be clear, a rooted path in Windows is not absolute (*), but that's not relevant here. What happens is that joining a path is like issuing successive "cd" commands in the shell, and "cd \" takes you to the root path of the current drive. The implementation of ntpath.join() similarly tracks the current drive via ntpath.splitdrive() while joining components. --- (*) When opened, a rooted path gets resolved relative to the drive of the process working directory. Except in a relative symlink, where a rooted target path is relative to the device of the parsed path of the symlink. For example, if the parsed, native NT path of a symlink is r"\Device\HarddiskVolume10\path\to\symlink", and the symlink targets r"\path\to\file", then it gets resolved as r"\Device\HarddiskVolume10\path\to\file". ntpath.isabs incorrectly classifies rooted paths as absolute, and its use is actually breaking part of the fallback code in the new implementation of ntpath.realpath when manually resolving relative symlinks. I've known of the problem for a few years and have discussed it one one or two issues on the tracker, but correcting the behavior of such a commonly used function is not an easy change to propose. Usually mistakes made early on in development become permanent warts. From eryksun at gmail.com Thu May 28 09:51:15 2020 From: eryksun at gmail.com (Eryk Sun) Date: Thu, 28 May 2020 08:51:15 -0500 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> <6472c1ef-2544-01a8-cc89-0a30ba99d5ca@kynesim.co.uk> Message-ID: On 5/27/20, Chris Angelico wrote: > On Thu, May 28, 2020 at 7:07 AM BlindAnagram > wrote: >> You can define a path however you want but it won't change the fact that >> on Windows a path that ends in '\\' is inherently a path to a directory. > > Citation needed. See [MS-FSA] 2.1.5.1 Server Requests an Open of a File [1]. Here are the relevant statements: The operation MUST be failed with STATUS_OBJECT_NAME_INVALID under any of the following conditions: .... * If PathName contains a trailing backslash and CreateOptions.FILE_NON_DIRECTORY_FILE is TRUE. .... If PathName contains a trailing backslash: * If StreamTypeToOpen is DataStream or CreateOptions.FILE_NON_DIRECTORY_FILE is TRUE, the operation MUST be failed with STATUS_OBJECT_NAME_INVALID Internally, WinAPI CreateFileW calls NTAPI NtCreateFile with the create option FILE_NON_DIRECTORY_FILE (i.e. only open or create a data file stream), unless backup semantics are requested in order to be able to open a directory (i.e. an index stream), in which case the call uses neither FILE_NON_DIRECTORY_FILE nor FILE_DIRECTORY_FILE and leaves it up to the path name. In other words, with backup semantics, if you need to ensure that only a directory is opened, add a trailing slash. NTAPI STATUS_OBJECT_NAME_INVALID translates to WinAPI ERROR_INVALID_NAME (123), which translates to C EINVAL (22). [1]: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/8ada5fbe-db4e-49fd-aef6-20d54b748e40 From blindanagram at nowhere.com Thu May 28 09:59:16 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Thu, 28 May 2020 14:59:16 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> <6472c1ef-2544-01a8-cc89-0a30ba99d5ca@kynesim.co.uk> Message-ID: On 28/05/2020 14:51, Eryk Sun wrote: > On 5/27/20, Chris Angelico wrote: >> On Thu, May 28, 2020 at 7:07 AM BlindAnagram >> wrote: >>> You can define a path however you want but it won't change the fact that >>> on Windows a path that ends in '\\' is inherently a path to a directory. >> >> Citation needed. > > See [MS-FSA] 2.1.5.1 Server Requests an Open of a File [1]. Here are > the relevant statements: > > The operation MUST be failed with STATUS_OBJECT_NAME_INVALID under > any of the following conditions: > .... > * If PathName contains a trailing backslash and > CreateOptions.FILE_NON_DIRECTORY_FILE is TRUE. > > .... > If PathName contains a trailing backslash: > * If StreamTypeToOpen is DataStream or > CreateOptions.FILE_NON_DIRECTORY_FILE is TRUE, the operation MUST > be failed with STATUS_OBJECT_NAME_INVALID > > Internally, WinAPI CreateFileW calls NTAPI NtCreateFile with the > create option FILE_NON_DIRECTORY_FILE (i.e. only open or create a data > file stream), unless backup semantics are requested in order to be > able to open a directory (i.e. an index stream), in which case the > call uses neither FILE_NON_DIRECTORY_FILE nor FILE_DIRECTORY_FILE and > leaves it up to the path name. In other words, with backup semantics, > if you need to ensure that only a directory is opened, add a trailing > slash. > > NTAPI STATUS_OBJECT_NAME_INVALID translates to WinAPI > ERROR_INVALID_NAME (123), which translates to C EINVAL (22). > > [1]: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/8ada5fbe-db4e-49fd-aef6-20d54b748e40 > Thank you for making the effort to answer a number of issues raaised in this thread. I much appreciate your input. From eryksun at gmail.com Thu May 28 10:37:44 2020 From: eryksun at gmail.com (Eryk Sun) Date: Thu, 28 May 2020 09:37:44 -0500 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> <6472c1ef-2544-01a8-cc89-0a30ba99d5ca@kynesim.co.uk> Message-ID: On 5/28/20, BlindAnagram wrote: > > Thank you for making the effort to answer a number of issues raaised in > this thread. I much appreciate your input. For a more practical POV, see the topic on "File System Navigation" [1] for the C++ standard API. In the C++ standard library, trailing slashes are not stripped and path p0(L"C:/Documents") compares as less than path p1(L"C:/Documents/"). Also, regarding whether rooted paths without a drive are absolute, you'll find that C++ is_absolute() requires has_root_name() && has_root_directory() in Windows. A rooted path without a drive is thus not absolute in the C++ standard library. [1]: https://docs.microsoft.com/en-us/cpp/standard-library/file-system-navigation?view=vs-2019 https://docs.microsoft.com/en-us/cpp/standard-library/file-system-navigation?view=vs-2019 [2]: https://docs.microsoft.com/en-us/cpp/standard-library/path-class?view=vs-2019#is_absolute From blindanagram at nowhere.com Thu May 28 12:57:43 2020 From: blindanagram at nowhere.com (BlindAnagram) Date: Thu, 28 May 2020 17:57:43 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <87zh9ts7ak.fsf@bsb.me.uk> Message-ID: <4ZCdnWgmSM8acFLDnZ2dnUU78e-dnZ2d@brightview.co.uk> On 27/05/2020 23:39, Roel Schroeven wrote: > I find no hints of adding a backslash at the end to indicate directories. > > If you can point me to convincing evidence in the documentation I'll > change my mind. See the post from Eryk Sun, later in this thread. From buddy.peacock at gmail.com Thu May 28 14:22:10 2020 From: buddy.peacock at gmail.com (Buddy Peacock) Date: Thu, 28 May 2020 14:22:10 -0400 Subject: SQLAlchemy & Postgresql Message-ID: Hello group, I have a pretty good background in MySQL & MSSQL as well as VB & Php, but I am new to Python and Postgresql. I am taking a class and working on a project to insert authors and books into a table. My code for this is: =============================================================== import csv import os from flask import Flask from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker app = Flask(__name__) # Configure session to use filesystem app.config["SESSION_PERMANENT"] = False app.config["SESSION_TYPE"] = "filesystem" # Session(app) # Set up database engine = create_engine(os.getenv("DATABASE_URL")) db = scoped_session(sessionmaker(bind=engine)) print (os.getenv("DATABASE_URL")) def main(): f = open("books.csv") reader = csv.reader(f) for isbn, title, author, year in reader: if db.execute("SELECT * FROM authors WHERE name = :author", {"name": author}).rowcount == 0: db.execute("INSERT INTO authors (name) VALUES (author)") print(f" {author} was read.") db.commit() if __name__ == "__main__": main() ==================================================================== If I comment out the "if" statement then the authors all print on screen. But when I run this with the if statement I am getting a message that says: ssqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) A value is required for bind parameter 'author' [SQL: SELECT * FROM authors WHERE name = %(author)s] [parameters: [{'name': 'author'}]] What am I missing? Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC (920) 740-3411 linkedin.com/in/buddypeacock From arj.python at gmail.com Thu May 28 14:25:47 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 May 2020 22:25:47 +0400 Subject: SQLAlchemy & Postgresql In-Reply-To: References: Message-ID: Greetings, where did you define your models? Kind Regards, Abdur-Rahmaan Janhangeer https://www.github.com/Abdur-RahmaanJ Mauritius sent from gmail client on Android, that's why the signature is so ugly. On Thu, 28 May 2020, 22:22 Buddy Peacock, wrote: > Hello group, > I have a pretty good background in MySQL & MSSQL as well as VB & Php, but I > am new to Python and Postgresql. > > I am taking a class and working on a project to insert authors and books > into a table. My code for this is: > =============================================================== > import csv > import os > > from flask import Flask > from sqlalchemy import create_engine > from sqlalchemy.orm import scoped_session, sessionmaker > > app = Flask(__name__) > > # Configure session to use filesystem > app.config["SESSION_PERMANENT"] = False > app.config["SESSION_TYPE"] = "filesystem" > # Session(app) > > # Set up database > engine = create_engine(os.getenv("DATABASE_URL")) > db = scoped_session(sessionmaker(bind=engine)) > > print (os.getenv("DATABASE_URL")) > > def main(): > f = open("books.csv") > reader = csv.reader(f) > for isbn, title, author, year in reader: > if db.execute("SELECT * FROM authors WHERE name = :author", > {"name": author}).rowcount == 0: > db.execute("INSERT INTO authors (name) VALUES (author)") > > print(f" {author} was read.") > db.commit() > > if __name__ == "__main__": > main() > ==================================================================== > If I comment out the "if" statement then the authors all print on screen. > But when I run this with the if statement I am getting a message that says: > ssqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) A > value is required for bind parameter 'author' > [SQL: SELECT * FROM authors WHERE name = %(author)s] > [parameters: [{'name': 'author'}]] > > What am I missing? > > > Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC > (920) 740-3411 > linkedin.com/in/buddypeacock > -- > https://mail.python.org/mailman/listinfo/python-list > From buddy.peacock at gmail.com Thu May 28 14:30:39 2020 From: buddy.peacock at gmail.com (Buddy Peacock) Date: Thu, 28 May 2020 14:30:39 -0400 Subject: SQLAlchemy & Postgresql In-Reply-To: References: Message-ID: I'm not sure what you mean by models? Am I missing something in my environment perhaps? Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC (920) 740-3411 linkedin.com/in/buddypeacock On Thu, May 28, 2020 at 2:26 PM Abdur-Rahmaan Janhangeer < arj.python at gmail.com> wrote: > Greetings, > > > where did you define your models? > > Kind Regards, > > > Abdur-Rahmaan Janhangeer > > https://www.github.com/Abdur-RahmaanJ > > Mauritius > > sent from gmail client on Android, that's why the signature is so ugly. > > On Thu, 28 May 2020, 22:22 Buddy Peacock, wrote: > >> Hello group, >> I have a pretty good background in MySQL & MSSQL as well as VB & Php, but >> I >> am new to Python and Postgresql. >> >> I am taking a class and working on a project to insert authors and books >> into a table. My code for this is: >> =============================================================== >> import csv >> import os >> >> from flask import Flask >> from sqlalchemy import create_engine >> from sqlalchemy.orm import scoped_session, sessionmaker >> >> app = Flask(__name__) >> >> # Configure session to use filesystem >> app.config["SESSION_PERMANENT"] = False >> app.config["SESSION_TYPE"] = "filesystem" >> # Session(app) >> >> # Set up database >> engine = create_engine(os.getenv("DATABASE_URL")) >> db = scoped_session(sessionmaker(bind=engine)) >> >> print (os.getenv("DATABASE_URL")) >> >> def main(): >> f = open("books.csv") >> reader = csv.reader(f) >> for isbn, title, author, year in reader: >> if db.execute("SELECT * FROM authors WHERE name = :author", >> {"name": author}).rowcount == 0: >> db.execute("INSERT INTO authors (name) VALUES (author)") >> >> print(f" {author} was read.") >> db.commit() >> >> if __name__ == "__main__": >> main() >> ==================================================================== >> If I comment out the "if" statement then the authors all print on screen. >> But when I run this with the if statement I am getting a message that >> says: >> ssqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) A >> value is required for bind parameter 'author' >> [SQL: SELECT * FROM authors WHERE name = %(author)s] >> [parameters: [{'name': 'author'}]] >> >> What am I missing? >> >> >> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >> (920) 740-3411 >> linkedin.com/in/buddypeacock >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From arj.python at gmail.com Thu May 28 14:44:40 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 May 2020 22:44:40 +0400 Subject: SQLAlchemy & Postgresql In-Reply-To: References: Message-ID: Well, See for isbn, title, author, year in reader: if db.execute("SELECT * FROM authors WHERE name = :author", {"name": author}).rowcount == 0: db.execute("INSERT INTO authors (name) VALUES (author)") but i don't see any code for creating the authors table also did you mean "name = author" instead of "name = :author" 3rd thing is that since you are using SQLALchemy, you should not be using pure SQL What i mean by models is something like this: https://github.com/Abdur-rahmaanJ/shopyo/blob/dev/shopyo/modules/product/models.py where you define code and your table is created the link uses flask-sqlalchemy but pure sqlalchemy should be somewhat similar 4th thing: when using for isbn, title, author, year in reader: without flask, do you actually see a value for author? Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy | blog github Mauritius On Thu, May 28, 2020 at 10:31 PM Buddy Peacock wrote: > I'm not sure what you mean by models? Am I missing something in my > environment perhaps? > > Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC > (920) 740-3411 > linkedin.com/in/buddypeacock > > > > > On Thu, May 28, 2020 at 2:26 PM Abdur-Rahmaan Janhangeer < > arj.python at gmail.com> wrote: > >> Greetings, >> >> >> where did you define your models? >> >> Kind Regards, >> >> >> Abdur-Rahmaan Janhangeer >> >> https://www.github.com/Abdur-RahmaanJ >> >> Mauritius >> >> sent from gmail client on Android, that's why the signature is so ugly. >> >> On Thu, 28 May 2020, 22:22 Buddy Peacock, >> wrote: >> >>> Hello group, >>> I have a pretty good background in MySQL & MSSQL as well as VB & Php, >>> but I >>> am new to Python and Postgresql. >>> >>> I am taking a class and working on a project to insert authors and books >>> into a table. My code for this is: >>> =============================================================== >>> import csv >>> import os >>> >>> from flask import Flask >>> from sqlalchemy import create_engine >>> from sqlalchemy.orm import scoped_session, sessionmaker >>> >>> app = Flask(__name__) >>> >>> # Configure session to use filesystem >>> app.config["SESSION_PERMANENT"] = False >>> app.config["SESSION_TYPE"] = "filesystem" >>> # Session(app) >>> >>> # Set up database >>> engine = create_engine(os.getenv("DATABASE_URL")) >>> db = scoped_session(sessionmaker(bind=engine)) >>> >>> print (os.getenv("DATABASE_URL")) >>> >>> def main(): >>> f = open("books.csv") >>> reader = csv.reader(f) >>> for isbn, title, author, year in reader: >>> if db.execute("SELECT * FROM authors WHERE name = :author", >>> {"name": author}).rowcount == 0: >>> db.execute("INSERT INTO authors (name) VALUES (author)") >>> >>> print(f" {author} was read.") >>> db.commit() >>> >>> if __name__ == "__main__": >>> main() >>> ==================================================================== >>> If I comment out the "if" statement then the authors all print on screen. >>> But when I run this with the if statement I am getting a message that >>> says: >>> ssqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) A >>> value is required for bind parameter 'author' >>> [SQL: SELECT * FROM authors WHERE name = %(author)s] >>> [parameters: [{'name': 'author'}]] >>> >>> What am I missing? >>> >>> >>> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >>> (920) 740-3411 >>> linkedin.com/in/buddypeacock >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> From __peter__ at web.de Thu May 28 14:47:38 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 28 May 2020 20:47:38 +0200 Subject: SQLAlchemy & Postgresql References: Message-ID: Buddy Peacock wrote: > Hello group, > I have a pretty good background in MySQL & MSSQL as well as VB & Php, but > I am new to Python and Postgresql. > > I am taking a class and working on a project to insert authors and books > into a table. My code for this is: > =============================================================== > import csv > import os > > from flask import Flask > from sqlalchemy import create_engine > from sqlalchemy.orm import scoped_session, sessionmaker > > app = Flask(__name__) > > # Configure session to use filesystem > app.config["SESSION_PERMANENT"] = False > app.config["SESSION_TYPE"] = "filesystem" > # Session(app) > > # Set up database > engine = create_engine(os.getenv("DATABASE_URL")) > db = scoped_session(sessionmaker(bind=engine)) > > print (os.getenv("DATABASE_URL")) > > def main(): > f = open("books.csv") > reader = csv.reader(f) > for isbn, title, author, year in reader: > if db.execute("SELECT * FROM authors WHERE name = :author", > {"name": author}).rowcount == 0: > db.execute("INSERT INTO authors (name) VALUES (author)") > > print(f" {author} was read.") > db.commit() > > if __name__ == "__main__": > main() > ==================================================================== > If I comment out the "if" statement then the authors all print on screen. > But when I run this with the if statement I am getting a message that > says: ssqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) > A value is required for bind parameter 'author' > [SQL: SELECT * FROM authors WHERE name = %(author)s] > [parameters: [{'name': 'author'}]] > > What am I missing? The variable name for name is :author. Therefore I think you have to use "author" as the key in the dict: db.execute("SELECT * FROM authors WHERE name = :author", {"author": author}) From buddy.peacock at gmail.com Thu May 28 15:31:27 2020 From: buddy.peacock at gmail.com (Buddy Peacock) Date: Thu, 28 May 2020 15:31:27 -0400 Subject: SQLAlchemy & Postgresql In-Reply-To: References: Message-ID: Thanks for your response Abdur-Rahmaan, The tables already exist and I have tried both "name = author" and "name = :author" Regards, Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC (920) 740-3411 linkedin.com/in/buddypeacock On Thu, May 28, 2020 at 2:44 PM Abdur-Rahmaan Janhangeer < arj.python at gmail.com> wrote: > Well, > > > See > > for isbn, title, author, year in reader: > if db.execute("SELECT * FROM authors WHERE name = :author", > {"name": author}).rowcount == 0: > db.execute("INSERT INTO authors (name) VALUES (author)") > > but i don't see any code for creating the authors table > > also did you mean "name = author" instead of "name = :author" > > 3rd thing is that since you are using SQLALchemy, you should not be using > pure SQL > > What i mean by models is something like this: > https://github.com/Abdur-rahmaanJ/shopyo/blob/dev/shopyo/modules/product/models.py > > where you define code and your table is created the link uses > flask-sqlalchemy but pure sqlalchemy should > be somewhat similar > > 4th thing: when using > > for isbn, title, author, year in reader: > > without flask, do you actually see a value for author? > > Kind Regards, > > Abdur-Rahmaan Janhangeer > compileralchemy | blog > > github > Mauritius > > > On Thu, May 28, 2020 at 10:31 PM Buddy Peacock > wrote: > >> I'm not sure what you mean by models? Am I missing something in my >> environment perhaps? >> >> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >> (920) 740-3411 >> linkedin.com/in/buddypeacock >> >> >> >> >> On Thu, May 28, 2020 at 2:26 PM Abdur-Rahmaan Janhangeer < >> arj.python at gmail.com> wrote: >> >>> Greetings, >>> >>> >>> where did you define your models? >>> >>> Kind Regards, >>> >>> >>> Abdur-Rahmaan Janhangeer >>> >>> https://www.github.com/Abdur-RahmaanJ >>> >>> Mauritius >>> >>> sent from gmail client on Android, that's why the signature is so ugly. >>> >>> On Thu, 28 May 2020, 22:22 Buddy Peacock, >>> wrote: >>> >>>> Hello group, >>>> I have a pretty good background in MySQL & MSSQL as well as VB & Php, >>>> but I >>>> am new to Python and Postgresql. >>>> >>>> I am taking a class and working on a project to insert authors and books >>>> into a table. My code for this is: >>>> =============================================================== >>>> import csv >>>> import os >>>> >>>> from flask import Flask >>>> from sqlalchemy import create_engine >>>> from sqlalchemy.orm import scoped_session, sessionmaker >>>> >>>> app = Flask(__name__) >>>> >>>> # Configure session to use filesystem >>>> app.config["SESSION_PERMANENT"] = False >>>> app.config["SESSION_TYPE"] = "filesystem" >>>> # Session(app) >>>> >>>> # Set up database >>>> engine = create_engine(os.getenv("DATABASE_URL")) >>>> db = scoped_session(sessionmaker(bind=engine)) >>>> >>>> print (os.getenv("DATABASE_URL")) >>>> >>>> def main(): >>>> f = open("books.csv") >>>> reader = csv.reader(f) >>>> for isbn, title, author, year in reader: >>>> if db.execute("SELECT * FROM authors WHERE name = :author", >>>> {"name": author}).rowcount == 0: >>>> db.execute("INSERT INTO authors (name) VALUES (author)") >>>> >>>> print(f" {author} was read.") >>>> db.commit() >>>> >>>> if __name__ == "__main__": >>>> main() >>>> ==================================================================== >>>> If I comment out the "if" statement then the authors all print on >>>> screen. >>>> But when I run this with the if statement I am getting a message that >>>> says: >>>> ssqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) A >>>> value is required for bind parameter 'author' >>>> [SQL: SELECT * FROM authors WHERE name = %(author)s] >>>> [parameters: [{'name': 'author'}]] >>>> >>>> What am I missing? >>>> >>>> >>>> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >>>> (920) 740-3411 >>>> linkedin.com/in/buddypeacock >>> > >>>> -- >>>> https://mail.python.org/mailman/listinfo/python-list >>>> >>> From rshepard at appl-ecosys.com Thu May 28 15:30:14 2020 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 28 May 2020 12:30:14 -0700 (PDT) Subject: SQLAlchemy & Postgresql In-Reply-To: References: Message-ID: On Thu, 28 May 2020, Buddy Peacock wrote: > I'm not sure what you mean by models? Am I missing something in my > environment perhaps? The model (or models if you prefer) define the sqlalchemy classes that reflect the structure and content of the postgrep table(s). I put all classes (for all database tables) in a single module, model.py. This assumes, of course, that you have defined the postgres database schema. Regards, Rich From arj.python at gmail.com Thu May 28 15:48:31 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 May 2020 23:48:31 +0400 Subject: SQLAlchemy & Postgresql In-Reply-To: References: Message-ID: You tried for isbn, title, author, year in reader: without flask, do you actually see a value for author? Like using a normal print Kind Regards, Abdur-Rahmaan Janhangeer https://www.github.com/Abdur-RahmaanJ Mauritius sent from gmail client on Android, that's why the signature is so ugly. On Thu, 28 May 2020, 23:31 Buddy Peacock, wrote: > Thanks for your response Abdur-Rahmaan, > > The tables already exist and I have tried both "name = author" and "name > = :author" > > Regards, > > Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC > (920) 740-3411 > linkedin.com/in/buddypeacock > > > > > On Thu, May 28, 2020 at 2:44 PM Abdur-Rahmaan Janhangeer < > arj.python at gmail.com> wrote: > >> Well, >> >> >> See >> >> for isbn, title, author, year in reader: >> if db.execute("SELECT * FROM authors WHERE name = :author", >> {"name": author}).rowcount == 0: >> db.execute("INSERT INTO authors (name) VALUES (author)") >> >> but i don't see any code for creating the authors table >> >> also did you mean "name = author" instead of "name = :author" >> >> 3rd thing is that since you are using SQLALchemy, you should not be using >> pure SQL >> >> What i mean by models is something like this: >> https://github.com/Abdur-rahmaanJ/shopyo/blob/dev/shopyo/modules/product/models.py >> >> where you define code and your table is created the link uses >> flask-sqlalchemy but pure sqlalchemy should >> be somewhat similar >> >> 4th thing: when using >> >> for isbn, title, author, year in reader: >> >> without flask, do you actually see a value for author? >> >> Kind Regards, >> >> Abdur-Rahmaan Janhangeer >> compileralchemy | blog >> >> github >> Mauritius >> >> >> On Thu, May 28, 2020 at 10:31 PM Buddy Peacock >> wrote: >> >>> I'm not sure what you mean by models? Am I missing something in my >>> environment perhaps? >>> >>> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >>> (920) 740-3411 >>> linkedin.com/in/buddypeacock >>> >>> >>> >>> >>> On Thu, May 28, 2020 at 2:26 PM Abdur-Rahmaan Janhangeer < >>> arj.python at gmail.com> wrote: >>> >>>> Greetings, >>>> >>>> >>>> where did you define your models? >>>> >>>> Kind Regards, >>>> >>>> >>>> Abdur-Rahmaan Janhangeer >>>> >>>> https://www.github.com/Abdur-RahmaanJ >>>> >>>> Mauritius >>>> >>>> sent from gmail client on Android, that's why the signature is so ugly. >>>> >>>> On Thu, 28 May 2020, 22:22 Buddy Peacock, >>>> wrote: >>>> >>>>> Hello group, >>>>> I have a pretty good background in MySQL & MSSQL as well as VB & Php, >>>>> but I >>>>> am new to Python and Postgresql. >>>>> >>>>> I am taking a class and working on a project to insert authors and >>>>> books >>>>> into a table. My code for this is: >>>>> =============================================================== >>>>> import csv >>>>> import os >>>>> >>>>> from flask import Flask >>>>> from sqlalchemy import create_engine >>>>> from sqlalchemy.orm import scoped_session, sessionmaker >>>>> >>>>> app = Flask(__name__) >>>>> >>>>> # Configure session to use filesystem >>>>> app.config["SESSION_PERMANENT"] = False >>>>> app.config["SESSION_TYPE"] = "filesystem" >>>>> # Session(app) >>>>> >>>>> # Set up database >>>>> engine = create_engine(os.getenv("DATABASE_URL")) >>>>> db = scoped_session(sessionmaker(bind=engine)) >>>>> >>>>> print (os.getenv("DATABASE_URL")) >>>>> >>>>> def main(): >>>>> f = open("books.csv") >>>>> reader = csv.reader(f) >>>>> for isbn, title, author, year in reader: >>>>> if db.execute("SELECT * FROM authors WHERE name = :author", >>>>> {"name": author}).rowcount == 0: >>>>> db.execute("INSERT INTO authors (name) VALUES (author)") >>>>> >>>>> print(f" {author} was read.") >>>>> db.commit() >>>>> >>>>> if __name__ == "__main__": >>>>> main() >>>>> ==================================================================== >>>>> If I comment out the "if" statement then the authors all print on >>>>> screen. >>>>> But when I run this with the if statement I am getting a message that >>>>> says: >>>>> ssqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) A >>>>> value is required for bind parameter 'author' >>>>> [SQL: SELECT * FROM authors WHERE name = %(author)s] >>>>> [parameters: [{'name': 'author'}]] >>>>> >>>>> What am I missing? >>>>> >>>>> >>>>> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >>>>> (920) 740-3411 >>>>> linkedin.com/in/buddypeacock < >>>>> https://www.linkedin.com/in/buddypeacock/> >>>>> -- >>>>> https://mail.python.org/mailman/listinfo/python-list >>>>> >>>> From hjp-python at hjp.at Thu May 28 16:09:23 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Thu, 28 May 2020 22:09:23 +0200 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <871rnh802d.fsf@nightsong.com> Message-ID: <20200528200923.GA17383@hjp.at> On 2020-05-19 09:53:01 +0100, Rhodri James wrote: > On 18/05/2020 22:07, Eli the Bearded wrote: > > camelCase -> noCamelCase > > snake_case -> no_snake_case > > > > One of those is easier to "grep" for than the other. > > Eh. A changed case in the one, an extra character in the other; that's > pretty much the same difficulty really. I certainly don't find it "hard" to > grep for _snake_case. I think you misunderstood his argument. He is saying that by searching for /snake_case/ you will find both "snake_case" and "no_snake_case". But /camelCase/ won't match "noCamelCase" - you have to search for /[cC]amelCase/ instead. I'm not sure if I'm convinced by that. I prefer snake_case simply for aesthetic reasons. My native language is German, so I should be used to gratuitous capitalisation from early childhood - but I still find camelCase ugly. 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 Thu May 28 16:18:54 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Thu, 28 May 2020 22:18:54 +0200 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> Message-ID: <20200528201854.GB17383@hjp.at> On 2020-05-19 05:59:30 +1000, Chris Angelico wrote: > PEP 8 is a style guide for the Python standard library. It is the > rules you must comply with if you are submitting a patch *to Python > itself*. Nobody ever requires you to comply with it for any other > code. That's obviously not true: Many companies and projects have a coding standard. Many of those coding standards will be based on or even identical to PEP 8. And as an employee or contributor you may be required to comply with it. Now you might argue that in this case you aren't required to comply with PEP 8, but with the coding standard of your company, but I would consider that excessive nitpickery. 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 buddy.peacock at gmail.com Thu May 28 16:23:27 2020 From: buddy.peacock at gmail.com (Buddy Peacock) Date: Thu, 28 May 2020 16:23:27 -0400 Subject: SQLAlchemy & Postgresql In-Reply-To: References: Message-ID: Yes, after commenting out all flask related lines and then running the print, I do see all the authors. Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC (920) 740-3411 linkedin.com/in/buddypeacock On Thu, May 28, 2020 at 3:48 PM Abdur-Rahmaan Janhangeer < arj.python at gmail.com> wrote: > You tried > > for isbn, title, author, year in reader: > > without flask, do you actually see a value for author? > > > > Like using a normal print > > Kind Regards, > > > Abdur-Rahmaan Janhangeer > > https://www.github.com/Abdur-RahmaanJ > > Mauritius > > sent from gmail client on Android, that's why the signature is so ugly. > > On Thu, 28 May 2020, 23:31 Buddy Peacock, wrote: > >> Thanks for your response Abdur-Rahmaan, >> >> The tables already exist and I have tried both "name = author" and "name >> = :author" >> >> Regards, >> >> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >> (920) 740-3411 >> linkedin.com/in/buddypeacock >> >> >> >> >> On Thu, May 28, 2020 at 2:44 PM Abdur-Rahmaan Janhangeer < >> arj.python at gmail.com> wrote: >> >>> Well, >>> >>> >>> See >>> >>> for isbn, title, author, year in reader: >>> if db.execute("SELECT * FROM authors WHERE name = :author", >>> {"name": author}).rowcount == 0: >>> db.execute("INSERT INTO authors (name) VALUES (author)") >>> >>> but i don't see any code for creating the authors table >>> >>> also did you mean "name = author" instead of "name = :author" >>> >>> 3rd thing is that since you are using SQLALchemy, you should not be >>> using >>> pure SQL >>> >>> What i mean by models is something like this: >>> https://github.com/Abdur-rahmaanJ/shopyo/blob/dev/shopyo/modules/product/models.py >>> >>> where you define code and your table is created the link uses >>> flask-sqlalchemy but pure sqlalchemy should >>> be somewhat similar >>> >>> 4th thing: when using >>> >>> for isbn, title, author, year in reader: >>> >>> without flask, do you actually see a value for author? >>> >>> Kind Regards, >>> >>> Abdur-Rahmaan Janhangeer >>> compileralchemy | blog >>> >>> github >>> Mauritius >>> >>> >>> On Thu, May 28, 2020 at 10:31 PM Buddy Peacock >>> wrote: >>> >>>> I'm not sure what you mean by models? Am I missing something in my >>>> environment perhaps? >>>> >>>> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >>>> (920) 740-3411 >>>> linkedin.com/in/buddypeacock >>>> >>>> >>>> >>>> >>>> >>>> On Thu, May 28, 2020 at 2:26 PM Abdur-Rahmaan Janhangeer < >>>> arj.python at gmail.com> wrote: >>>> >>>>> Greetings, >>>>> >>>>> >>>>> where did you define your models? >>>>> >>>>> Kind Regards, >>>>> >>>>> >>>>> Abdur-Rahmaan Janhangeer >>>>> >>>>> https://www.github.com/Abdur-RahmaanJ >>>>> >>>>> Mauritius >>>>> >>>>> sent from gmail client on Android, that's why the signature is so ugly. >>>>> >>>>> On Thu, 28 May 2020, 22:22 Buddy Peacock, >>>>> wrote: >>>>> >>>>>> Hello group, >>>>>> I have a pretty good background in MySQL & MSSQL as well as VB & Php, >>>>>> but I >>>>>> am new to Python and Postgresql. >>>>>> >>>>>> I am taking a class and working on a project to insert authors and >>>>>> books >>>>>> into a table. My code for this is: >>>>>> =============================================================== >>>>>> import csv >>>>>> import os >>>>>> >>>>>> from flask import Flask >>>>>> from sqlalchemy import create_engine >>>>>> from sqlalchemy.orm import scoped_session, sessionmaker >>>>>> >>>>>> app = Flask(__name__) >>>>>> >>>>>> # Configure session to use filesystem >>>>>> app.config["SESSION_PERMANENT"] = False >>>>>> app.config["SESSION_TYPE"] = "filesystem" >>>>>> # Session(app) >>>>>> >>>>>> # Set up database >>>>>> engine = create_engine(os.getenv("DATABASE_URL")) >>>>>> db = scoped_session(sessionmaker(bind=engine)) >>>>>> >>>>>> print (os.getenv("DATABASE_URL")) >>>>>> >>>>>> def main(): >>>>>> f = open("books.csv") >>>>>> reader = csv.reader(f) >>>>>> for isbn, title, author, year in reader: >>>>>> if db.execute("SELECT * FROM authors WHERE name = :author", >>>>>> {"name": author}).rowcount == 0: >>>>>> db.execute("INSERT INTO authors (name) VALUES (author)") >>>>>> >>>>>> print(f" {author} was read.") >>>>>> db.commit() >>>>>> >>>>>> if __name__ == "__main__": >>>>>> main() >>>>>> ==================================================================== >>>>>> If I comment out the "if" statement then the authors all print on >>>>>> screen. >>>>>> But when I run this with the if statement I am getting a message that >>>>>> says: >>>>>> ssqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) A >>>>>> value is required for bind parameter 'author' >>>>>> [SQL: SELECT * FROM authors WHERE name = %(author)s] >>>>>> [parameters: [{'name': 'author'}]] >>>>>> >>>>>> What am I missing? >>>>>> >>>>>> >>>>>> Al (Buddy) Peacock, PMP, MCCT, ITILv3, SMC, CSM, SPOC >>>>>> (920) 740-3411 >>>>>> linkedin.com/in/buddypeacock < >>>>>> https://www.linkedin.com/in/buddypeacock/> >>>>>> -- >>>>>> https://mail.python.org/mailman/listinfo/python-list >>>>>> >>>>> From rosuav at gmail.com Thu May 28 16:27:31 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 May 2020 06:27:31 +1000 Subject: why no camelCase in PEP 8? In-Reply-To: <20200528201854.GB17383@hjp.at> References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <20200528201854.GB17383@hjp.at> Message-ID: On Fri, May 29, 2020 at 6:20 AM Peter J. Holzer wrote: > > On 2020-05-19 05:59:30 +1000, Chris Angelico wrote: > > PEP 8 is a style guide for the Python standard library. It is the > > rules you must comply with if you are submitting a patch *to Python > > itself*. Nobody ever requires you to comply with it for any other > > code. > > That's obviously not true: Many companies and projects have a coding > standard. Many of those coding standards will be based on or even > identical to PEP 8. And as an employee or contributor you may be > required to comply with it. Now you might argue that in this case you > aren't required to comply with PEP 8, but with the coding standard of > your company, but I would consider that excessive nitpickery. > The OP said: > My preference for using camelCase (in PEP 8, AKA mixedCase) is putting me at odds with my colleagues, who point to PEP 8 as "the rules". > This smells like the incredibly strong misconception that PEP 8 needs to govern every line of Python code ever written, or else it's "bad code". This thread wouldn't have been started if it had been any other style guide that the company had been chosen, because then it's obvious that the choice is the company's. It's only when PEP 8 is considered to be some sort of universal standard that we get this kind of discussion. ChrisA From python at net153.net Thu May 28 16:25:41 2020 From: python at net153.net (Sam) Date: Thu, 28 May 2020 15:25:41 -0500 Subject: Ram memory not freed after executing python script on ubuntu system In-Reply-To: References: Message-ID: <551db770-cef8-9672-9fe4-4cf34198279c@net153.net> On 5/28/20 12:49 AM, Rahul Gupta wrote: > > I am having a Ubuntu system which has 125 Gb of RAM. I executed few python scripts on that system. Those scripts uses numpy arrays and pandas. Now execution was over but still 50 gb of RAM and 2 Gb cache and 8.4 Gb of swap is occupied. At this moment nothing is running on the system. I have googled it. Most of th result shows that python garbage collector is poor in performance. I want this memory to be cleaned and re claim. One of the easiest way is to restart the system but i dont want to restart i want a way to do this when the system is up and running. Kindly tell me how to do this. Thanks > Give us the output of: cat /proc/meminfo and ps aux Regards, From hjp-python at hjp.at Thu May 28 17:12:19 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Thu, 28 May 2020 23:12:19 +0200 Subject: creating a table within python code In-Reply-To: References: Message-ID: <20200528211219.GC17383@hjp.at> On 2020-05-22 10:22:40 -0400, Buddy Peacock wrote: > Thank you Souvik, but still having issues. I have pasted the command line > interaction this time. My prior message is what appeared in the browser. > ================================================================================================================ > c:\Harvard\project1>SET FLASK_APP="create_db.py" > > c:\Harvard\project1>set DATABASE_URL=postgres:// > guaqyugfujbudc:79ae65a6d8966991694906e4b96f20ebcfde5b80fb334e99d79d9300dd6ef95f at ec2-34-200-72-77.compute-1.amazonaws.com:5432/dep18tfh5g2eme > > c:\Harvard\project1>flask run > * Serving Flask app ""create_db.py"" (lazy loading) ^^^^^^^^^^^^^^^^ [...] > ModuleNotFoundError: No module named '"create_db' ^^^^^^^^^^^^ I don't think those quotes were a good idea. 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 Thu May 28 17:20:44 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Thu, 28 May 2020 23:20:44 +0200 Subject: Is there some reason that recent Windows 3.6 releases don't included executable nor msi installers? In-Reply-To: <4986af9e-0c1e-97d3-e830-268a1cc57684@python.org> References: <4986af9e-0c1e-97d3-e830-268a1cc57684@python.org> Message-ID: <20200528212044.GD17383@hjp.at> On 2020-05-23 13:22:26 -0600, Mats Wichmann wrote: > On 5/23/20 12:23 AM, Adam Preble wrote: > > I wanted to update from 3.6.8 on Windows without necessarily moving > > on to 3.7+ (yet), so I thought I'd try 3.6.9 or 3.6.10. > > > > All I see for both are source archives: [...] > > During the early part of a release cycle, installers are built. Once > the cycle moves into security fix-only mode, installers are not built. > That's all you are seeing. This seems a rather odd policy to me. Distributing a security fix in source-only form will prevent many people from applying it (especially on Windows). 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 grant.b.edwards at gmail.com Thu May 28 14:08:23 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 28 May 2020 18:08:23 -0000 (UTC) Subject: Behaviour of os.path.join References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <87zh9ts7ak.fsf@bsb.me.uk> Message-ID: On 2020-05-27, Roel Schroeven wrote: > I find no hints of adding a backslash at the end to indicate directories. I suspect that, like Unix, that's not an OS/filesystem thing but merely a convention used by some user space applications to allow the user to provide an additional hint as to his intention. -- Grant From roel at roelschroeven.net Thu May 28 14:18:01 2020 From: roel at roelschroeven.net (Roel Schroeven) Date: Thu, 28 May 2020 20:18:01 +0200 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> <6472c1ef-2544-01a8-cc89-0a30ba99d5ca@kynesim.co.uk> Message-ID: Eryk Sun schreef op 28/05/2020 om 15:51: > On 5/27/20, Chris Angelico wrote: >> On Thu, May 28, 2020 at 7:07 AM BlindAnagram >> wrote: >>> You can define a path however you want but it won't change the fact that >>> on Windows a path that ends in '\\' is inherently a path to a directory. >> >> Citation needed. > > See [MS-FSA] 2.1.5.1 Server Requests an Open of a File [1]. Here are > the relevant statements: > > The operation MUST be failed with STATUS_OBJECT_NAME_INVALID under > any of the following conditions: > .... > * If PathName contains a trailing backslash and > CreateOptions.FILE_NON_DIRECTORY_FILE is TRUE. i.e. trailing backslashes are not allowed for regular files > .... > If PathName contains a trailing backslash: > * If StreamTypeToOpen is DataStream or > CreateOptions.FILE_NON_DIRECTORY_FILE is TRUE, the operation MUST > be failed with STATUS_OBJECT_NAME_INVALID i.e. again, trailing backslashes are not allowed for non-directory files. There is no limitation listed that says something like "The operation must be failed if pathname doesn't contain a trailing backslash and CreateOptions.FILE_NON_DIRECTOR_FILE is FALSE". Path names referring to directories are allowed to have trailing backslashes, but no requirement to do so. Directory PathNames with and without trailing backslashes are handled exactly the same. > Internally, WinAPI CreateFileW calls NTAPI NtCreateFile with the > create option FILE_NON_DIRECTORY_FILE (i.e. only open or create a data > file stream), unless backup semantics are requested in order to be > able to open a directory (i.e. an index stream), in which case the > call uses neither FILE_NON_DIRECTORY_FILE nor FILE_DIRECTORY_FILE and > leaves it up to the path name. No, that is not my understanding. It is up to the actual type of file specified by the path. CreateFileW using FILE_FLAG_BACKUP_SEMANTICS can only open existing directories, so there is no need to look at the last character of the path. > In other words, with backup semantics, if you need to ensure that > only a directory is opened, add a trailing slash. It's not like you have some random path, you think "hey, I only want to open this if it is a directory", and then do CreateFileW( L"...\\...\\", .., ..., ..., ..., FILE_FLAG_BACKUP_SEMANTICS, NULL); What happens instead is that you have a path to a real existing object (CreateFileW on directories works only with both OPEN_EXISTING and FILE_FLAG_BACKUP_SEMANTICS specified: you can not create a directory using CreateFileW), and CreateFileW (via NtCreateFile) will open it as a directory if the object is a directory, and as a file it is a file. Exception is that it will refuse to open it as a file if there's a backslash in the end, while for directories backslashes are optional. But if you never add a backslash in the end, everything will work just fine for both files and directories. -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From roel at roelschroeven.net Thu May 28 14:39:28 2020 From: roel at roelschroeven.net (Roel Schroeven) Date: Thu, 28 May 2020 20:39:28 +0200 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <87zh9ts7ak.fsf@bsb.me.uk> Message-ID: BlindAnagram schreef op 28/05/2020 om 11:00: > On 27/05/2020 23:39, Roel Schroeven wrote: >> I find no hints of adding a backslash at the end to indicate directories. >> If you can point me to convincing evidence in the documentation I'll >> change my mind. > > And if you find a counterexample, I will change mine. It's hard to prove a negative. The only thing I can find is that there are cases where doing operations on files fail if there's a backslash at the end, whereas operations on directories do work with a backslash at the end; but those also work without the backslash. Even then, the distinction between what operation is done is never decided by the backslash; only if it is decided that you're doing something file-related and there is a backslash, then it fails. It's not like it turns into a directory-related operation. Ergo, adding backslashes practically accomplishes nothing. What really defines what kind of operation will be done, is - which function you call - or the flags you pass to the function - or for some operation when working with existing objects, the type of those existing objects Also, if we're going to look in the other direction: we can ask Windows for information about objects on disk, and it will tell use the type using flags, not by adding backslashes. We can use e.g. FindFirstFile / FindNextFile / FindClose. dwFileAttributes in the WIN32_FIND_DATA structure will have FILE_ATTRIBUTE_DIRECTORY set for directories and not for normal files. cFileName won't have a trailing backslash. If the semantics were as you say, I'd expect Windows to at least using them itself. In summary, IMO: - Windows allows trailing backslashes for directories. - Windows doesn't allow trailing backslashes for files. - Windows doesn't use trailing backslashes for distinction between files and directories. - And so I don't see how/why adding a backslash makes any real difference. -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From roel at roelschroeven.net Thu May 28 16:44:13 2020 From: roel at roelschroeven.net (Roel Schroeven) Date: Thu, 28 May 2020 22:44:13 +0200 Subject: why no camelCase in PEP 8? In-Reply-To: <20200528200923.GA17383@hjp.at> References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <871rnh802d.fsf@nightsong.com> <20200528200923.GA17383@hjp.at> Message-ID: Peter J. Holzer schreef op 28/05/2020 om 22:09: > On 2020-05-19 09:53:01 +0100, Rhodri James wrote: >> On 18/05/2020 22:07, Eli the Bearded wrote: >>> camelCase -> noCamelCase >>> snake_case -> no_snake_case >>> >>> One of those is easier to "grep" for than the other. >> >> Eh. A changed case in the one, an extra character in the other; that's >> pretty much the same difficulty really. I certainly don't find it "hard" to >> grep for _snake_case. > > I think you misunderstood his argument. He is saying that by searching > for /snake_case/ you will find both "snake_case" and "no_snake_case". > But /camelCase/ won't match "noCamelCase" - you have to search for > /[cC]amelCase/ instead. > > I'm not sure if I'm convinced by that. I prefer snake_case simply for > aesthetic reasons. My native language is German, so I should be used to > gratuitous capitalisation from early childhood - but I still find > camelCase ugly. For me, the reason for disliking camelCase is consistency. I don't like how in camelCase words are written differently just because they appear at the front or not at the front. I don't like that the c of camelCase changes to the C in noCamelCase; not for the easy of searching (though that is an argument, just not the one that irks me most) but because it's not consistent. Things should change when their meaning changes, not when their place changes. Both PascalCase and snake_case don't have that inconsistency, which is why I like them a lot better than camelCase. There's another reason why I don't like camelCase: it smells like Java, and I don't like Java. That's an entirely irrational feeling though, of course. -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From tjreedy at udel.edu Thu May 28 17:34:50 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 May 2020 17:34:50 -0400 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: On 5/28/2020 9:19 AM, Eryk Sun wrote: > On 5/26/20, BlindAnagram wrote: >> >> But if I try to make the directory myself (as I tried first): >> >> join(base, '..\\..\\', 'build', '\\') >> >> I obtain: >> >> 'C:\\' >> >> The documentation says that an absolute path in the parameter list for >> join will discard all previous parameters but '\\' is not an absoute path! > > First, to be clear, a rooted path in Windows is not absolute (*), but > that's not relevant here. What happens is that joining a path is like > issuing successive "cd" commands in the shell, and "cd \" takes you to > the root path of the current drive. The implementation of > ntpath.join() similarly tracks the current drive via > ntpath.splitdrive() while joining components. Ah. cd only changes the cwd within a device. Changing the active device is done otherwise. In Command Prompt C:\Users\Terry>f: # : required F:\>c: C:\Users\Terry>cd f: F:\ C:\Users\Terry>cd f:/dev C:\Users\Terry>f: f:\dev> -- Terry Jan Reedy From hjp-python at hjp.at Thu May 28 18:02:13 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 29 May 2020 00:02:13 +0200 Subject: Ram memory not freed after executing python script on ubuntu system In-Reply-To: References: Message-ID: <20200528220213.GE17383@hjp.at> On 2020-05-27 22:49:53 -0700, Rahul Gupta wrote: > I am having a Ubuntu system which has 125 Gb of RAM. I executed few > python scripts on that system. Those scripts uses numpy arrays and > pandas. Now execution was over but still 50 gb of RAM and 2 Gb cache > and 8.4 Gb of swap is occupied. At this moment nothing is running on > the system. I have googled it. Most of th result shows that python > garbage collector is poor in performance. I want this memory to be > cleaned and re claim. As others have already pointed out, a process which doesn't exist can't use memory (on Linux or any other sane OS). So either python is still running or something else is using the memory. To find out what is using the memory, run the command top in a terminal. Then press Shift-M to sort processes by memory consumption. The offenders should now be at the top. 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 PythonList at DancesWithMice.info Thu May 28 18:10:07 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Fri, 29 May 2020 10:10:07 +1200 Subject: Constructing mime image attachment In-Reply-To: References: Message-ID: <92edf367-882c-13e3-7da7-b3aa3e02fb2f@DancesWithMice.info> On 28/05/20 11:48 PM, Joseph L. Casale wrote: > I have some json encoded input for nodemailer (https://nodemailer.com/message/embedded-images) > where the path key is a string value which contains the base64 encoded data such as: > > { > html: 'Embedded image: ', > attachments: [{ > filename: 'image.png', > path: 'data:image/png;base64,iVBORw....', > cid: 'unique at nodemailer.com' > }] > } > > Does an approach exist to construct a MIMEImage object with the existing > base64 string without parsing it and decoding it? Might the Python Standard Library modules for Internet Handling offer suitable facilities, eg base64 or mimetypes? https://docs.python.org/3/library/netdata.html -- Regards =dn From hjp-python at hjp.at Thu May 28 18:25:53 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 29 May 2020 00:25:53 +0200 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <20200528201854.GB17383@hjp.at> Message-ID: <20200528222553.GF17383@hjp.at> On 2020-05-29 06:27:31 +1000, Chris Angelico wrote: > On Fri, May 29, 2020 at 6:20 AM Peter J. Holzer wrote: > > On 2020-05-19 05:59:30 +1000, Chris Angelico wrote: > > > PEP 8 is a style guide for the Python standard library. It is the > > > rules you must comply with if you are submitting a patch *to Python > > > itself*. Nobody ever requires you to comply with it for any other > > > code. > > > > That's obviously not true: Many companies and projects have a coding > > standard. Many of those coding standards will be based on or even > > identical to PEP 8. And as an employee or contributor you may be > > required to comply with it. Now you might argue that in this case you > > aren't required to comply with PEP 8, but with the coding standard of > > your company, but I would consider that excessive nitpickery. > > > > The OP said: > > My preference for using camelCase (in PEP 8, AKA mixedCase) is > > putting me at odds with my colleagues, who point to PEP 8 as "the > > rules". > > > > This smells like the incredibly strong misconception that PEP 8 needs > to govern every line of Python code ever written, or else it's "bad > code". This thread wouldn't have been started if it had been any other > style guide that the company had been chosen, because then it's > obvious that the choice is the company's. It's only when PEP 8 is > considered to be some sort of universal standard that we get this kind > of discussion. It may be the case in this specific instance (although I don't know, as I don't work for the OP's company and don't know his colleagues). I don't think it is generally the case. When a company introduces a coding standard, I think "just use PEP 8" is a very reasonable choice (it's not inherently better or worse than any other style, but just by being familiar to a lot of Python programmers it is likely to elicit less resistance and bike-shedding). So this might lead to the following exchange during a code review: A: Please don't use camelCase for variables. It's against our coding style. B: Why don't we allow camelCase for variables? A: Because PEP 8 doesn't allow it. B: Why doesn't PEP 8 allow it? A: Uh, ask the PEP 8 authors. At which point B becomes the OP of this thread. 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 python at mrabarnett.plus.com Thu May 28 18:33:20 2020 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 28 May 2020 23:33:20 +0100 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> Message-ID: On 2020-05-28 22:34, Terry Reedy wrote: > On 5/28/2020 9:19 AM, Eryk Sun wrote: >> On 5/26/20, BlindAnagram wrote: >>> >>> But if I try to make the directory myself (as I tried first): >>> >>> join(base, '..\\..\\', 'build', '\\') >>> >>> I obtain: >>> >>> 'C:\\' >>> >>> The documentation says that an absolute path in the parameter list for >>> join will discard all previous parameters but '\\' is not an absoute path! >> >> First, to be clear, a rooted path in Windows is not absolute (*), but >> that's not relevant here. What happens is that joining a path is like >> issuing successive "cd" commands in the shell, and "cd \" takes you to >> the root path of the current drive. The implementation of >> ntpath.join() similarly tracks the current drive via >> ntpath.splitdrive() while joining components. > > Ah. cd only changes the cwd within a device. Changing the active device > is done otherwise. In Command Prompt > > C:\Users\Terry>f: # : required > > F:\>c: > > C:\Users\Terry>cd f: > F:\ > > C:\Users\Terry>cd f:/dev > > C:\Users\Terry>f: > > f:\dev> > cd has a switch /d that will also change the drive: C:\Users\Terry>cd /d f:/dev f:\dev> From tjreedy at udel.edu Thu May 28 18:14:53 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 May 2020 18:14:53 -0400 Subject: why no camelCase in PEP 8? In-Reply-To: <20200528201854.GB17383@hjp.at> References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <20200528201854.GB17383@hjp.at> Message-ID: On 5/28/2020 4:18 PM, Peter J. Holzer wrote: > On 2020-05-19 05:59:30 +1000, Chris Angelico wrote: >> PEP 8 is a style guide for the Python standard library. It is the >> rules you must comply with if you are submitting a patch *to Python >> itself*. Nobody ever requires you to comply with it for any other >> code. > > That's obviously not true: Many companies and projects have a coding > standard. Many of those coding standards will be based on or even > identical to PEP 8. And as an employee or contributor you may be > required to comply with it. Revise Chris' claim to "Neither the PSF nor the Python core developers require* that owners of non-stdlib code comply with PEP 8" and it would be true. * We could have, by baking it into the language, by making uppercase following lowercase in identifiers illegal. But that would disabled part of the stdlib. > Now you might argue that in this case you > aren't required to comply with PEP 8, but with the coding standard of > your company, but I would consider that excessive nitpickery. I don't. If an entity with a police force adopts part of the Model Fire Code written by an International Association of Fire Marshals (or whatever), it matters that any enforcement is done by that state's officials rather toothless disapproval of the association. In any case, Guido as BDFL did not enforce the function-name rule, as illustrated by unittest (I would have prefered otherwise). Moveover, he made it clear in PEP 8 that strict enforcement of its rules was not one of its rules. Many of the rules explicitly allow for exceptions in exceptional circumstances. So required no-exception compliance is an add-on by other entities. -- Terry Jan Reedy From eryksun at gmail.com Thu May 28 20:24:50 2020 From: eryksun at gmail.com (Eryk Sun) Date: Thu, 28 May 2020 19:24:50 -0500 Subject: Behaviour of os.path.join In-Reply-To: References: <5MydnaN1loqes1DDnZ2dnUU78dPNnZ2d@brightview.co.uk> <875zchtvau.fsf@bsb.me.uk> <79fef982-1982-f610-04cd-fdaea1046ae4@kynesim.co.uk> <6472c1ef-2544-01a8-cc89-0a30ba99d5ca@kynesim.co.uk> Message-ID: On 5/28/20, Roel Schroeven wrote: > Eryk Sun schreef op 28/05/2020 om 15:51: >> On 5/27/20, Chris Angelico wrote: >>> On Thu, May 28, 2020 at 7:07 AM BlindAnagram >>> wrote: >>>> You can define a path however you want but it won't change the fact >>>> that on Windows a path that ends in '\\' is inherently a path to a >>>> directory. [snip] > i.e. again, trailing backslashes are not allowed for non-directory files. > > There is no limitation listed that says something like "The operation > must be failed if pathname doesn't contain a trailing backslash and > CreateOptions.FILE_NON_DIRECTOR_FILE is FALSE". Path names referring to > directories are allowed to have trailing backslashes, but no requirement > to do so. Directory PathNames with and without trailing backslashes are > handled exactly the same. The statement I was documenting (quoted above) is that a path that ends in a slash has to be a directory, not that a directory cannot be accessed without a trailing slash. The create option for NtCreateFile can be FILE_NON_DIRECTORY_FILE, FILE_DIRECTORY_FILE, or left undefined. If it's not defined, and the opened path has a trailing slash, then for an open-existing disposition, the existing stream must be a directory. It's an invalid-name error (STATUS_OBJECT_NAME_INVALID) if the existing stream is a regular file. If FILE_NON_DIRECTORY_FILE is specified (the default for WinAPI CreateFileW), the path cannot have a trailing slash because that designates a directory, which is inconsistent with the create option. Again, this is an invalid-name error, which is distinct from errors where the create option disagrees with the stream type (i.e. STATUS_FILE_IS_A_DIRECTORY and STATUS_NOT_A_DIRECTORY). >> Internally, WinAPI CreateFileW calls NTAPI NtCreateFile with the >> create option FILE_NON_DIRECTORY_FILE (i.e. only open or create a data >> file stream), unless backup semantics are requested in order to be >> able to open a directory (i.e. an index stream), in which case the >> call uses neither FILE_NON_DIRECTORY_FILE nor FILE_DIRECTORY_FILE and >> leaves it up to the path name. > > No, that is not my understanding. It is up to the actual type of file > specified by the path. CreateFileW using FILE_FLAG_BACKUP_SEMANTICS can > only open existing directories, so there is no need to look at the last > character of the path. It is true that just including a trailing slash does not set the StreamTypeToOpen to a directory stream. That's why a mismatch leads to an invalid-name error instead of a directory error (i.e. STATUS_NOT_A_DIRECTORY), because it's only the name in the opened path that's inconsistent with the existing stream type. In order to create a directory, the StreamTypeToOpen must be a directory. One way to set that is to explicitly use the FILE_DIRECTORY_FILE create option. This is possible by using a CREATE_NEW disposition with the flags and attributes FILE_ATTRIBUTE_DIRECTORY | FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_POSIX_SEMANTICS. For example: >>> flags = FILE_ATTRIBUTE_DIRECTORY >>> flags |= FILE_FLAG_BACKUP_SEMANTICS >>> flags |= FILE_FLAG_POSIX_SEMANTICS >>> disposition = CREATE_NEW >>> h = CreateFile('spam', 0, 0, None, disposition, flags, None) >>> os.path.isdir('spam') True AFAIK, Microsoft never documented the above capability, so, even though NT's implementation of the Windows API has included it for almost 30 years, it's still reasonable to ignore it. As documented in [MS-FSA], the other way to set StreamTypeToOpen to a directory is to explicitly open an $INDEX_ALLOCATION stream (named "$I30", but the name can be omitted). This requires the filesystem to support file streams (e.g. NTFS, ReFS). For example: >>> flags = 0 >>> disposition = CREATE_NEW >>> h = CreateFile('eggs::$INDEX_ALLOCATION', 0, 0, None, disposition, flags, None) >>> os.path.isdir('eggs') True Notice that I didn't have to request backup semantics. Thus it created a directory even though the default FILE_NON_DIRECTORY_FILE create option was used. That's peculiar, but it's actually documented by [MS-FSA]: * If CreateOptions.FILE_DIRECTORY_FILE is TRUE then StreamTypeToOpen = DirectoryStream. * Else if StreamTypeNameToOpen is "$INDEX_ALLOCATION" then StreamTypeToOpen = DirectoryStream. * Else if CreateOptions.FILE_NON_DIRECTORY_FILE is FALSE, StreamNameToOpen is empty, StreamTypeNameToOpen is empty, Open.File is not NULL, and Open.File.FileType is DirectoryFile then StreamTypeToOpen = DirectoryStream. * Else StreamTypeToOpen = DataStream. > But if you never add a backslash in the end, everything will work just > fine for both files and directories. If you expect to open a directory, then appending a trailing slash and relying on the the invalid-name error is a one way to ensure that, though the error isn't really specific enough for my liking. To be more explicit, if programming at a lower level in C/C++, query GetFileInformationByHandleEx: FileBasicInfo, and check the FileAttributes for FILE_ATTRIBUTE_DIRECTORY. From tjreedy at udel.edu Thu May 28 20:51:59 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 May 2020 20:51:59 -0400 Subject: Is there some reason that recent Windows 3.6 releases don't included executable nor msi installers? In-Reply-To: <20200528212044.GD17383@hjp.at> References: <4986af9e-0c1e-97d3-e830-268a1cc57684@python.org> <20200528212044.GD17383@hjp.at> Message-ID: On 5/28/2020 5:20 PM, Peter J. Holzer wrote: > On 2020-05-23 13:22:26 -0600, Mats Wichmann wrote: >> On 5/23/20 12:23 AM, Adam Preble wrote: >>> I wanted to update from 3.6.8 on Windows without necessarily moving >>> on to 3.7+ (yet), so I thought I'd try 3.6.9 or 3.6.10. >>> >>> All I see for both are source archives: >> During the early part of a release cycle, installers are built. Only for Windows and now for macOS. Python.org only ever distributes source archives for *nix. Distributors can add binaries to their package system. >> Once >> the cycle moves into security fix-only mode, installers are not built. We continue to apply security fixes for the benefit of server operators who are slow to upgrade and who want minimal change -- only those that they really need. We make security-fix releases primarily for the benefit of *nix distributors who want to update their x.y package, but not for every x.y commit. It also give a periodic new name for Python x.y with a new batch of fixes. > This seems a rather odd policy to me. Not if one considers the intended users. Do you prefer we not make these releases? Anyone running servers on Windows should have Visual Studio and git installed as they should be able to compile their own binaries. Anyone with control of their machine (so that they can download and install things) can install VS and git with the instructions in devguide.python.org. At that point, clone python/cpython and run PCbuild\build.bat -e (to build external dependencies) and maybe add other options, and python(_d).exe will appear in PCbuild\win32. > Distributing a security fix in > source-only form will prevent many people from applying it (especially > on Windows). Nearly all bug fixes considered to be security risk fixes are first applied to master (the 'next' version), then maintenance versions, which do get installers, and only then to old security-fix versions. The latter take extra effort as they are less likely to automatically backport, and on Windows, older versions run on more Windows versions. The OP is so far choosing to not use an installer with those fixes. By not doing so, he is missing out on the maybe 2000 non-security fixes and some enhancements that likely would benefit him more than maybe 50 mostly obscure fixes added between 3.6.8 and 3.6.10*. If a rare user such as Adam also chooses to not compile the latter, that is his choice. *In the last 12 months, the ratio of fixed security issues to all fixed issues is 51/2087 = 2.4%, and for 5 years, 112/7825 = 1.4%. There are 68 open security issues, some of which will be closed other than as 'fixed'. Source only releases only block Windows/Mac users who choose not to upgrade to a released installer and who cannot or choose not to compile. -- Terry Jan Reedy From miked at dewhirst.com.au Thu May 28 21:55:45 2020 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Fri, 29 May 2020 11:55:45 +1000 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: On 29/05/2020 10:51 am, Terry Reedy wrote: > On 5/28/2020 5:20 PM, Peter J. Holzer wrote: >> On 2020-05-23 13:22:26 -0600, Mats Wichmann wrote: >>> On 5/23/20 12:23 AM, Adam Preble wrote: >>>> I wanted to update from 3.6.8 on Windows without necessarily moving >>>> on to 3.7+ (yet), so I thought I'd try 3.6.9 or 3.6.10. >>>> >>>> All I see for both are source archives: > >>> During the early part of a release cycle, installers are built. > > Only for Windows and now for macOS.? Python.org only ever distributes > source archives for *nix.? Distributors can add binaries to their > package system. > >>> ?Once >>> the cycle moves into security fix-only mode, installers are not built. > > We continue to apply security fixes for the benefit of server > operators who are slow to upgrade and who want minimal change -- only > those that they really need.? We make security-fix releases primarily > for the benefit of *nix distributors who want to update their x.y > package, but not for every x.y commit.? It also give a periodic new > name for Python x.y with a new batch of fixes. > >> This seems a rather odd policy to me. > > Not if one considers the intended users. > Do you prefer we not make these releases? > > Anyone running servers on Windows should have Visual Studio and git > installed as they should be able to compile their own binaries.? > Anyone with control of their machine (so that they can download and > install things) can install VS and git with the instructions in > devguide.python.org. At that point, clone python/cpython and run > PCbuild\build.bat -e (to build external dependencies) and maybe add > other options, and python(_d).exe will appear in PCbuild\win32. > >> Distributing a security fix in >> source-only form will prevent many people from applying it (especially >> on Windows). > > Nearly all bug fixes considered to be security risk fixes are first > applied to master (the 'next' version), then maintenance versions, > which do get installers, and only then to old security-fix versions.? > The latter take extra effort as they are less likely to automatically > backport, and on Windows, older versions run on more Windows versions. > > The OP is so far choosing to not use an installer with those fixes.? > By not doing so, he is missing out on the maybe 2000 non-security > fixes and some enhancements that likely would benefit him more than > maybe 50 mostly obscure fixes added between 3.6.8 and 3.6.10*.? If a > rare user such as Adam also chooses to not compile the latter, that is > his choice. > > *In the last 12 months, the ratio of fixed security issues to all > fixed issues is 51/2087 = 2.4%, and for 5 years, 112/7825 = 1.4%. > There are 68 open security issues, some of which will be closed other > than as 'fixed'. > > Source only releases only block Windows/Mac users who choose not to > upgrade to a released installer and who cannot or choose not to compile. I am an example I installed all the Pythons on my Windows 10 dev machine (locked into Windows by having clients) but I'm also locked into Python 3.6.9 on my Ubuntu 18.04 production machines. After chasing down an obscure problem I decided to go back to Py36 on Windows to be using the same versions in dev as in prd. I couldn't find an installer on python.org so I retrieved one (3.6.5) from my archives. I choose to avoid Visual Studio and I won't bother with cygwin any more after some pain a decade or so ago. Therefore I choose not to compile. For me it won't be long before I can upgrade my production machines to 20.04 and whatever Python3 comes with that and all will be well. If I was asked to suggest a guide for which versions ought to get a Windows binary I would look at the most popular LTS *nix distros and keep Windows binaries in step just to support people like me who cannot live with too much Windows clutter. Think of it as deeply humanitarian generosity. Honestly, if you let it, Windows just absolutely knows what you really meant despite what you tell it. It is a necessary evil when your clients use it. Cheers Mike From rmlibre at riseup.net Thu May 28 21:56:50 2020 From: rmlibre at riseup.net (rmlibre at riseup.net) Date: Thu, 28 May 2020 18:56:50 -0700 Subject: Ram memory not freed after executing python script on ubuntu system (rmlibre) In-Reply-To: References: Message-ID: We just ran into this problem when running our aiootp package's memory hard password hashing function (https://github.com/rmlibre/aiootp/). The memory was not being cleared after the function finished running but the script was still live. We tried making sure everything went out of scope and deleting things explicitly inside the function, but that didn't help. We even tried forcing the garbage collector to free up unreferenced memory with import gc; gc.collect(). But that only had a small dent in the memory that was being built up. The most useful answer online had to do with Python's free lists being created automatically when very large datasets were being processed (https://stackoverflow.com/questions/23937189/how-do-i-use-subprocesses-to-force-python-to-release-memory/24126616#24126616). After putting the memory intensive work into a separate process, as the answer suggested, the memory was finally freed after execution. In our case, we wound up passing the result back in a ``multiprocessing.Manager().List()``. Though, passing your whole numpy dataset back doesn't seem feasible. I'd recommend doing the necessary memory intensive work in a separate process and passing only the necessary conclusions back to the main process. Or you could set up a multiprocessing queue to pass control messages to the spawned (daemon) process so it returns desired results on demand. Here's an excerpt from our code after the fix in case it's helpful. > @classmethod > def passcrypt(cls, password, salt, kb=1024, cpu=1024, hardness=256): > """ > The ``passcrypt`` function can be highly memory intensive. > These resources may not be freed up, & often are not, because of > python quirks around memory management. This is a huge problem. > So to force the release of those resources, we run the function > in another process which is guaranteed to release them. > """ > cls._validate_passcrypt_args(kb, cpu, hardness) > state = Manager().list() > process = Process( > target=cls._passcrypt, > args=(password, salt), > kwargs=dict(kb=kb, cpu=cpu, hardness=hardness, state=state), > ) > process.start() > process.join() > return state.pop() On 2020-05-28 16:00, python-list-request at python.org wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. Re: Custom logging function (zljubisic at gmail.com) > 2. Ram memory not freed after executing python script on ubuntu > system (Rahul Gupta) > 3. Re: Ram memory not freed after executing python script on > ubuntu system (Chris Angelico) > 4. Re: Custom logging function (Peter Otten) > 5. Re: Elegant hack or gross hack? TextWrapper and escape codes > (Peter Otten) > 6. Re: Elegant hack or gross hack? TextWrapper and escape codes > (Chris Angelico) > 7. Re: Elegant hack or gross hack? TextWrapper and escape codes > (Peter Otten) > 8. Re: Ram memory not freed after executing python script on > ubuntu system (Rahul Gupta) > 9. Re: Ram memory not freed after executing python script on > ubuntu system (Chris Angelico) > 10. Re: Behaviour of os.path.join (BlindAnagram) > 11. Constructing mime image attachment (Joseph L. Casale) > 12. Re: Behaviour of os.path.join (Eryk Sun) > 13. Re: Behaviour of os.path.join (Eryk Sun) > 14. Re: Behaviour of os.path.join (BlindAnagram) > 15. Re: Behaviour of os.path.join (Eryk Sun) From rosuav at gmail.com Thu May 28 22:26:22 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 May 2020 12:26:22 +1000 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: On Fri, May 29, 2020 at 11:57 AM Mike Dewhirst wrote: > > I am an example > > I installed all the Pythons on my Windows 10 dev machine (locked into > Windows by having clients) but I'm also locked into Python 3.6.9 on my > Ubuntu 18.04 production machines. Be careful of assuming too much here. The general policy with most Linux distributions is to number the version according to the oldest component in it, but they are free to backport whatever changes they choose. I have Python 3.4.4 and 3.5.3 on this system (Debian Stretch), but the 3.5 is numbered "3.5.3-1+deb9u1" which implies some collection of additional patches. (I'd have to dig deep in the changelogs if I cared exactly *which* patches.) > After chasing down an obscure problem I decided to go back to Py36 on > Windows to be using the same versions in dev as in prd. I couldn't find > an installer on python.org so I retrieved one (3.6.5) from my archives. That'd be the same feature version, but depending exactly what the problem is, there might not be *any* Windows build that exactly corresponds. > If I was asked to suggest a guide for which versions ought to get a > Windows binary I would look at the most popular LTS *nix distros and > keep Windows binaries in step just to support people like me who cannot > live with too much Windows clutter. Think of it as deeply humanitarian > generosity. Even if that were possible, who are you asking to do this? Whose time is going to be put into finessing every point release to make sure it's still buildable on Windows? "LTS" doesn't mean anything since basically EVERY version of Python is in an LTS of Red Hat (they're probably still shipping Python 2.3 somewhere). > Honestly, if you let it, Windows just absolutely knows what you really > meant despite what you tell it. It is a necessary evil when your clients > use it. If your clients use it, are you going to pay someone to build your installers? And if you aren't going to pay, who is? Find someone who'd be willing to maintain Windows binaries for you, and see what they'd charge you for that. Then judge that against the cost of dropping support for Python 3.6 and requiring your users to upgrade to a fully-supported version. ChrisA From rosuav at gmail.com Thu May 28 22:28:27 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 May 2020 12:28:27 +1000 Subject: Ram memory not freed after executing python script on ubuntu system (rmlibre) In-Reply-To: References: Message-ID: On Fri, May 29, 2020 at 12:08 PM wrote: > > > We just ran into this problem when running our aiootp package's memory > hard password hashing function (https://github.com/rmlibre/aiootp/). Have you considered implementing that module in something else? Try Cythonizing it and see if suddenly your memory usage drops - not because of garbage collection, but because you're no longer using integer objects at all. ChrisA From adam.preble at gmail.com Thu May 28 23:41:04 2020 From: adam.preble at gmail.com (Adam Preble) Date: Thu, 28 May 2020 20:41:04 -0700 (PDT) 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: <75e2a38c-6b2c-46c2-8adc-bdf00adf119d@googlegroups.com> On Thursday, May 28, 2020 at 7:57:04 PM UTC-5, Terry Reedy wrote: > The OP is so far choosing to not use an installer with those fixes. By > not doing so, he is missing out on the maybe 2000 non-security fixes and > some enhancements that likely would benefit him more than maybe 50 > mostly obscure fixes added between 3.6.8 and 3.6.10*. If a rare user > such as Adam also chooses to not compile the latter, that is his choice. I was going to just stay mute about why I was even looking at 3.6.10, but I felt I should weigh in after some of the other responses. I think somebody would find the issues interesting. We had found what looked like a bug in the Python Launcher where it would eat command line arguments meant for the script. I would find some stuff missing from sys.argv in a script that just imports sys and prints out sys.argv if I ran it directly in cmd.exe as "script.py." If I ran it as "python script.py" then everything was good as usual. So I figured while sorting out what was wrong that I should try the latest 3.6 interpreter since it would be a safe bet. Our organization finally lifted Sisyphus' rock over the 2.7 hump earlier in the year by moving to 3.6. So imagine my surprise when I found the latest 3.6 releases were just source tarballs. This left me with a dilemma and I'm still working through it. I haven't filed an issue about this because I haven't completed my own due diligence on the problem by trying it on a "latest." For the sake of this particular problem, I think I can just use 3.8.3 for exploration, but I'm worrying about my wider organization. I can't count on 3.8 because of some module dependencies our organization's software. 3.7 has a similar issue. So I figured I'd actually just build the thing and see what I can do. I did manage to build it, but there was surprisingly a few quirks. I caused some of it. For example, I didn't care about most of the externals before, but I made sure to include them if I was create a release for others. A few thousand people would be using this and I'm the one that would be accountable if it went bust. So I made sure all the major externals were incorporated, and a lot of those were messing up. Generally, the externals would download, but some would not get moved/renamed to their final name, and then the build would fail when trying to find them. So I wound up with an installation that seemed to run my own code just fine in trials, but I would be terrified to post into it our organization's software stack. I'm now concerned about how long we have with 3.6 because people clearly want us to move on even beyond that. I look online and the official support window for it ends at the end of next year, but it looks like the real support window for that on Windows has already ended. So our organization may have miscalculated this. What does that mean if we managed to make it to 3.8 in a few months? We can't do it right now due to a few missing modules, but now we have to question if we'll only get a year out of 3.8 before we're doing this all over again. From rosuav at gmail.com Thu May 28 23:56:58 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 May 2020 13:56:58 +1000 Subject: Is there some reason that recent Windows 3.6 releases don't included executable nor msi installers? In-Reply-To: <75e2a38c-6b2c-46c2-8adc-bdf00adf119d@googlegroups.com> References: <4986af9e-0c1e-97d3-e830-268a1cc57684@python.org> <20200528212044.GD17383@hjp.at> <75e2a38c-6b2c-46c2-8adc-bdf00adf119d@googlegroups.com> Message-ID: On Fri, May 29, 2020 at 1:46 PM Adam Preble wrote: > I'm now concerned about how long we have with 3.6 because people clearly > want us to move on even beyond that. I look online and the official support > window for it ends at the end of next year, but it looks like the real > support window for that on Windows has already ended. So our organization > may have miscalculated this. What does that mean if we managed to make it > to 3.8 in a few months? We can't do it right now due to a few missing > modules, but now we have to question if we'll only get a year out of 3.8 > before we're doing this all over again. Upgrading from 3.8 to 3.9 won't be hard. Check the release notes: https://docs.python.org/3.9/whatsnew/3.9.html In fact, even upgrading from 3.6 to 3.8 is unlikely to break anything. Or go direct to 3.9, depending on how soon you're likely to complete that transition (expected release date is October). Don't be afraid of the minor upgrades. I'm currently running a mix of 3.9 and 3.10, since there are a couple of things that broke in 3.10. But that's not even into its first alpha yet. By the time they get to release, generally most stuff won't break :) ChrisA From dieter at handshake.de Fri May 29 00:59:33 2020 From: dieter at handshake.de (Dieter Maurer) Date: Fri, 29 May 2020 06:59:33 +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: <24272.38581.608037.43991@ixdm.fritz.box> Mike Dewhirst wrote at 2020-5-29 11:55 +1000: >On 29/05/2020 10:51 am, Terry Reedy wrote: > ... >> Source only releases only block Windows/Mac users who choose not to >> upgrade to a released installer and who cannot or choose not to compile. > >I am an example > >I installed all the Pythons on my Windows 10 dev machine (locked into >Windows by having clients) but I'm also locked into Python 3.6.9 on my >Ubuntu 18.04 production machines. You are not locked into Python 3.6 on Ubuntu: it is quite easy to compile Python on *nix (this includes Ubuntu 18.04) yourself (I did so recently for Python 3.9[a5]). From miked at dewhirst.com.au Fri May 29 01:14:18 2020 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Fri, 29 May 2020 15:14:18 +1000 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: <15659556-8a24-ab10-b062-b77b05a42aa0@dewhirst.com.au> On 29/05/2020 12:26 pm, Chris Angelico wrote: > On Fri, May 29, 2020 at 11:57 AM Mike Dewhirst wrote: >> I am an example >> >> I installed all the Pythons on my Windows 10 dev machine (locked into >> Windows by having clients) but I'm also locked into Python 3.6.9 on my >> Ubuntu 18.04 production machines. > Be careful of assuming too much here. The general policy with most > Linux distributions is to number the version according to the oldest > component in it, but they are free to backport whatever changes they > choose. I have Python 3.4.4 and 3.5.3 on this system (Debian Stretch), > but the 3.5 is numbered "3.5.3-1+deb9u1" which implies some collection > of additional patches. (I'd have to dig deep in the changelogs if I > cared exactly *which* patches.) > >> After chasing down an obscure problem I decided to go back to Py36 on >> Windows to be using the same versions in dev as in prd. I couldn't find >> an installer on python.org so I retrieved one (3.6.5) from my archives. > That'd be the same feature version, but depending exactly what the > problem is, there might not be *any* Windows build that exactly > corresponds. > >> If I was asked to suggest a guide for which versions ought to get a >> Windows binary I would look at the most popular LTS *nix distros and >> keep Windows binaries in step just to support people like me who cannot >> live with too much Windows clutter. Think of it as deeply humanitarian >> generosity. > Even if that were possible, who are you asking to do this? Whose time > is going to be put into finessing every point release to make sure > it's still buildable on Windows? I was careful to not ask anyone to do anything. "If I was asked ..." Making sure something is buildable when it involves compiling on Windows is well beyond my pay-grade nowadays. I know just how hard it is. However, I would say (and I've said it before) Christoph Gohlke deserves a Nobel prize for his abovementioned deeply humanitarian generosity. Without him (and Mark Hammond) there would be very little Python dev done on Windows - if any! The only reason I took up Python (after being burned by proprietary tool makers) was because it was promised to run on pretty much everything. Especially Apache platforms - which also run on Windows. > "LTS" doesn't mean anything since > basically EVERY version of Python is in an LTS of Red Hat (they're > probably still shipping Python 2.3 somewhere). > >> Honestly, if you let it, Windows just absolutely knows what you really >> meant despite what you tell it. It is a necessary evil when your clients >> use it. > If your clients use it, They don't use Python. They use Windows and I need to use Windows to be able to support them in what they do. I install Apache on Windows if I need to. It would be handy if Microsoft delivered Windows with Python installed but what can you expect from them if they can't see demand for it. > are you going to pay someone to build your > installers? And if you aren't going to pay, who is? I agree with your sentiment. But without specific funding I can't afford to pay anyone. I'll choose different solutions. But if I needed it badly enough I'd find the brainspace and do it myself. > Find someone who'd be willing to maintain Windows binaries for you, > and see what they'd charge you for that. Then judge that against the > cost of dropping support for Python 3.6 and requiring your users to > upgrade to a fully-supported version. Chris, you are preaching to the converted. You won't get a counter-argument from me. I piped up in the first place because I saw the OP in trouble and felt it was necessary to say something. I thought my scenario might be interesting. As I said earlier it isn't critical for me. There are lot of Python people working on Windows and they do so because they have no choice. Windows is simply the dominant platform. That's where most clients live. All I'm saying (now) is I really hope PSF is supporting Christoph and Mark because they make it possible to use Python on Windows. Cheers Mike > > ChrisA From dieter at handshake.de Fri May 29 01:20:01 2020 From: dieter at handshake.de (Dieter Maurer) Date: Fri, 29 May 2020 07:20:01 +0200 Subject: Ram memory not freed after executing python script on ubuntu system (rmlibre) In-Reply-To: References: Message-ID: <24272.39809.536683.247631@ixdm.fritz.box> rmlibre at riseup.net wrote at 2020-5-28 18:56 -0700: >We just ran into this problem when running our aiootp package's memory >hard password hashing function (https://github.com/rmlibre/aiootp/). The >memory was not being cleared after the function finished running but the >script was still live. I hope you are aware that Python can do nothing to change this: the elementary memory management feature provided by operating systems is a way to increase or decrease the "heap" (there is a different possibility (memory mapping), but it is efficient only for large chunks of memory). Python cannot truncate the heap below the last used memory block. Python would need a "compacting" garbage collection to ensure that used memory is as tight as possible; then it could free more aggressively. But, a "compacting" garbage collection would make life **much** more difficult for extensions (implemented in C); especially, thousands existing extensions would stop working. Following the example of the C runtime library, Python manages free memory internally. This implies that operating system means do not show exact information about the amount of really used memory (for the operation system, free memory in the internal memory management is used). From miked at dewhirst.com.au Fri May 29 01:25:41 2020 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Fri, 29 May 2020 15:25:41 +1000 Subject: Is there some reason that recent Windows 3.6 releases don't included executable nor msi installers? In-Reply-To: <24272.38581.608037.43991@ixdm.fritz.box> References: <4986af9e-0c1e-97d3-e830-268a1cc57684@python.org> <20200528212044.GD17383@hjp.at> <24272.38581.608037.43991@ixdm.fritz.box> Message-ID: <5da8d8a7-915d-f86b-19f2-c751f08115a6@dewhirst.com.au> On 29/05/2020 2:59 pm, Dieter Maurer wrote: > Mike Dewhirst wrote at 2020-5-29 11:55 +1000: >> On 29/05/2020 10:51 am, Terry Reedy wrote: >> ... >>> Source only releases only block Windows/Mac users who choose not to >>> upgrade to a released installer and who cannot or choose not to compile. >> I am an example >> >> I installed all the Pythons on my Windows 10 dev machine (locked into >> Windows by having clients) but I'm also locked into Python 3.6.9 on my >> Ubuntu 18.04 production machines. > You are not locked into Python 3.6 on Ubuntu: it is quite easy > to compile Python on *nix (this includes Ubuntu 18.04) yourself > (I did so recently for Python 3.9[a5]). Thank you Dieter - yes I'm aware of that. You need to understand that I am lazy. I haven't done it before and I was persuaded by a grizzly old sysadmin that it is much easier to stick with the distro version. I have actually compiled mod-wsgi before in the days of Python 2.7 so I do know how brilliantly Linux is set up for software development compared with Windows. I will think about it seriously. Cheers Mike From rosuav at gmail.com Fri May 29 01:25:50 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 May 2020 15:25:50 +1000 Subject: Is there some reason that recent Windows 3.6 releases don't included executable nor msi installers? In-Reply-To: <15659556-8a24-ab10-b062-b77b05a42aa0@dewhirst.com.au> References: <4986af9e-0c1e-97d3-e830-268a1cc57684@python.org> <20200528212044.GD17383@hjp.at> <15659556-8a24-ab10-b062-b77b05a42aa0@dewhirst.com.au> Message-ID: On Fri, May 29, 2020 at 3:15 PM Mike Dewhirst wrote: > > On 29/05/2020 12:26 pm, Chris Angelico wrote: > > On Fri, May 29, 2020 at 11:57 AM Mike Dewhirst wrote: > >> I am an example > >> > >> I installed all the Pythons on my Windows 10 dev machine (locked into > >> Windows by having clients) but I'm also locked into Python 3.6.9 on my > >> Ubuntu 18.04 production machines. > > Be careful of assuming too much here. The general policy with most > > Linux distributions is to number the version according to the oldest > > component in it, but they are free to backport whatever changes they > > choose. I have Python 3.4.4 and 3.5.3 on this system (Debian Stretch), > > but the 3.5 is numbered "3.5.3-1+deb9u1" which implies some collection > > of additional patches. (I'd have to dig deep in the changelogs if I > > cared exactly *which* patches.) > > > >> After chasing down an obscure problem I decided to go back to Py36 on > >> Windows to be using the same versions in dev as in prd. I couldn't find > >> an installer on python.org so I retrieved one (3.6.5) from my archives. > > That'd be the same feature version, but depending exactly what the > > problem is, there might not be *any* Windows build that exactly > > corresponds. > > > >> If I was asked to suggest a guide for which versions ought to get a > >> Windows binary I would look at the most popular LTS *nix distros and > >> keep Windows binaries in step just to support people like me who cannot > >> live with too much Windows clutter. Think of it as deeply humanitarian > >> generosity. > > Even if that were possible, who are you asking to do this? Whose time > > is going to be put into finessing every point release to make sure > > it's still buildable on Windows? > > I was careful to not ask anyone to do anything. "If I was asked ..." You said that certain versions of Python "ought to get" Windows binaries. They don't appear out of nowhere. > The only reason I took up Python (after being burned by proprietary tool > makers) was because it was promised to run on pretty much everything. > Especially Apache platforms - which also run on Windows. It does. > It would be handy if Microsoft delivered Windows with Python installed > but what can you expect from them if they can't see demand for it. You can get Python from the Windows App Store or whatever they call it. > There are lot of Python people working on Windows and they do so because > they have no choice. Windows is simply the dominant platform. That's > where most clients live. And current versions of Python are easily available. It's just that there's a limit to how many different versions people are willing to go to the effort of building Windows binaries for. You can easily get any GA release of Python for any supported platform. Prerelease versions, old versions, or locally patched versions, generally require that you build them yourself (regardless of the platform). ChrisA From songofacandy at gmail.com Fri May 29 01:28:59 2020 From: songofacandy at gmail.com (Inada Naoki) Date: Fri, 29 May 2020 14:28:59 +0900 Subject: Ram memory not freed after executing python script on ubuntu system (rmlibre) In-Reply-To: References: Message-ID: pymalloc manages only small blocks of memory. Large (more than 512 byte) memory blocks are managed by malloc/free. glibc malloc doesn't return much freed memory to OS. You can try jemalloc instead of glibc. On Ubuntu 20.04, you can try it by: LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so python your-script.py On Fri, May 29, 2020 at 11:07 AM wrote: > > > We just ran into this problem when running our aiootp package's memory > hard password hashing function (https://github.com/rmlibre/aiootp/). The > memory was not being cleared after the function finished running but the > script was still live. We tried making sure everything went out of scope > and deleting things explicitly inside the function, but that didn't > help. We even tried forcing the garbage collector to free up > unreferenced memory with import gc; gc.collect(). But that only had a > small dent in the memory that was being built up. > > The most useful answer online had to do with Python's free lists being > created automatically when very large datasets were being processed > (https://stackoverflow.com/questions/23937189/how-do-i-use-subprocesses-to-force-python-to-release-memory/24126616#24126616). > > > After putting the memory intensive work into a separate process, as the > answer suggested, the memory was finally freed after execution. > > In our case, we wound up passing the result back in a > ``multiprocessing.Manager().List()``. Though, passing your whole numpy > dataset back doesn't seem feasible. I'd recommend doing the necessary > memory intensive work in a separate process and passing only the > necessary conclusions back to the main process. > > Or you could set up a multiprocessing queue to pass control messages to > the spawned (daemon) process so it returns desired results on demand. > > > Here's an excerpt from our code after the fix in case it's helpful. > > > @classmethod > > def passcrypt(cls, password, salt, kb=1024, cpu=1024, hardness=256): > > """ > > The ``passcrypt`` function can be highly memory intensive. > > These resources may not be freed up, & often are not, because of > > python quirks around memory management. This is a huge problem. > > So to force the release of those resources, we run the function > > in another process which is guaranteed to release them. > > """ > > cls._validate_passcrypt_args(kb, cpu, hardness) > > state = Manager().list() > > process = Process( > > target=cls._passcrypt, > > args=(password, salt), > > kwargs=dict(kb=kb, cpu=cpu, hardness=hardness, state=state), > > ) > > process.start() > > process.join() > > return state.pop() > > > > > On 2020-05-28 16:00, python-list-request at python.org wrote: > > Send Python-list mailing list submissions to > > python-list at python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://mail.python.org/mailman/listinfo/python-list > > or, via email, send a message with subject or body 'help' to > > python-list-request at python.org > > > > You can reach the person managing the list at > > python-list-owner at python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Python-list digest..." > > > > Today's Topics: > > > > 1. Re: Custom logging function (zljubisic at gmail.com) > > 2. Ram memory not freed after executing python script on ubuntu > > system (Rahul Gupta) > > 3. Re: Ram memory not freed after executing python script on > > ubuntu system (Chris Angelico) > > 4. Re: Custom logging function (Peter Otten) > > 5. Re: Elegant hack or gross hack? TextWrapper and escape codes > > (Peter Otten) > > 6. Re: Elegant hack or gross hack? TextWrapper and escape codes > > (Chris Angelico) > > 7. Re: Elegant hack or gross hack? TextWrapper and escape codes > > (Peter Otten) > > 8. Re: Ram memory not freed after executing python script on > > ubuntu system (Rahul Gupta) > > 9. Re: Ram memory not freed after executing python script on > > ubuntu system (Chris Angelico) > > 10. Re: Behaviour of os.path.join (BlindAnagram) > > 11. Constructing mime image attachment (Joseph L. Casale) > > 12. Re: Behaviour of os.path.join (Eryk Sun) > > 13. Re: Behaviour of os.path.join (Eryk Sun) > > 14. Re: Behaviour of os.path.join (BlindAnagram) > > 15. Re: Behaviour of os.path.join (Eryk Sun) > -- > https://mail.python.org/mailman/listinfo/python-list -- Inada Naoki From aishan0403 at gmail.com Fri May 29 02:00:13 2020 From: aishan0403 at gmail.com (BBT) Date: Thu, 28 May 2020 23:00:13 -0700 (PDT) Subject: Write tables from Word (.docx) to Excel (.xlsx) using xlsxwriter In-Reply-To: References: <6b929c36-cede-483b-8dec-34bc09a5309a@googlegroups.com> <6e70e6cf-4fa5-405f-a653-ad93030c353a@googlegroups.com> <07ad4f89-a822-4b42-9493-b1e4c7cab515@googlegroups.com> Message-ID: <2c102006-0292-4b1d-ac65-74785fe0bc88@googlegroups.com> On Thursday, 28 May 2020 03:07:48 UTC+8, Peter Otten wrote: > BBT wrote: > > > I tried your code by replacing the Document portion: > > > But I received an error: > > TypeError: __init__() takes 1 positional argument but 2 were given > > We seem to have different ideas of what replacing means. > Here is the suggested script spelt out: > > import xlsxwriter > > from docx.api import Document > document = Document('/Users/xxx/Documents/xxx/Clauses Sample - Copy v1 - for merge.docx') > > wb = xlsxwriter.Workbook('C:/Users/xxx/Documents/xx/test clause retrieval.xlsx') > sheet = wb.add_worksheet("Compliance") > > offset = 0 > for table in document.tables: > for y, row in enumerate(table.rows): > for x, cell in enumerate(row.cells): > sheet.write(y + offset, x, cell.text) > offset += len(table.rows) + 1 # one empty row between tables > > wb.close() Yes! That works well, thank you Peter! And I'm impressed by your object-oriented simulation too. Would look into it again :) From chiragdhyani at gmail.com Fri May 29 03:39:01 2020 From: chiragdhyani at gmail.com (Chirag Dhyani) Date: Fri, 29 May 2020 13:09:01 +0530 Subject: Create custom types using typing module? Message-ID: I am trying to create a custom type on Python 3.7 typing module. The new type (say Struct) should be same as type tuple. In Python3.6, I was able to do the same by taking cue from Typing.GenericMeta and typing.TupleMeta. With typing module updated in Python3.7, GenericMeta and TupleMeta do not exist, and the special class that I would like to subclass is not possible. e.g. _VariadicGenericAlias cannot be subclassed. What I really want is something similar to: Struct = _VariadicGenericAlias(tuple, (), , inst=False, special=True) and assert _origin(Struct[int, str]) == Note: def _origin(typ: Any) -> Any: """Get the original (the bare) typing class. Get the unsubscripted version of a type. Supports generic types, Union, Callable, and Tuple. Returns None for unsupported types. Examples:: get_origin(int) == None get_origin(ClassVar[int]) == None get_origin(Generic) == Generic get_origin(Generic[T]) == Generic get_origin(Union[T, int]) == Union get_origin(List[Tuple[T, T]][int]) == list """ if isinstance(typ, _GenericAlias): return typ.__origin__ if typ.__origin__ is not ClassVar else None if typ is Generic: return Generic return None Deeply appreciate your help around this !! Thanks, Chirag From eryksun at gmail.com Fri May 29 08:30:13 2020 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 29 May 2020 07:30:13 -0500 Subject: Is there some reason that recent Windows 3.6 releases don't included executable nor msi installers? In-Reply-To: <75e2a38c-6b2c-46c2-8adc-bdf00adf119d@googlegroups.com> References: <4986af9e-0c1e-97d3-e830-268a1cc57684@python.org> <20200528212044.GD17383@hjp.at> <75e2a38c-6b2c-46c2-8adc-bdf00adf119d@googlegroups.com> Message-ID: On 5/28/20, Adam Preble wrote: > > We had found what looked like a bug in the Python Launcher where it would > eat command line arguments meant for the script. I would find some stuff > missing from sys.argv in a script that just imports sys and prints out > sys.argv if I ran it directly in cmd.exe as "script.py." If I ran it as > "python script.py" then everything was good as usual. Sometimes a user will open a script via "open with" and browse to python.exe or py.exe. This associates .py files with a new progid that doesn't pass the %* command-line arguments. The installed Python.File progid should be listed in the open-with list, and, if the launcher is installed, the icon should have the Python logo with a rocket on it. Select that, lock it in by selecting to always use it, and open the script. This will only be wrong if a user or misbehaving program modified the Python.File progid and broke its "open" action. From mal at europython.eu Fri May 29 10:36:11 2020 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 29 May 2020 16:36:11 +0200 Subject: EuroPython 2020: Schedule published Message-ID: <1eecb6ea-8916-a1d9-9169-1cf176868842@europython.eu> We are very excited to announce the first version of our EuroPython 2020 schedule: * EuroPython 2020 Schedule * https://ep2020.europython.eu/schedule/ More sessions than we ever dreamed of ------------------------------------- After the 2nd CFP, we found that we had so many good talk submissions that we were able to open a fourth track. Together with the newly added slots for the Indian / Asian / Pacific and Americas time zones, we now have a fully packed program, with: - more than 110 sessions - more than 110 speakers from around the world - 4 brilliant keynotes, two of which are already published - 2 exciting lightning talk blocks - 4 all-day tracks, with a whole track dedicated to data science topics - a poster track, which we?ll announce next week - a virtual social event - an after party - and lots of socializing on our conference platform We are proud to have reached almost the size of our in-person event with the online version of EuroPython 2020. Never miss a talk ----------------- All talks will be made available to the attendees as live Webinars, with easy switching between tracks, as well as online streams, which will allow rewinding to watch talks you may have missed during the day. Conference Tickets ------------------ Conference tickets are available on our registration page. We have simplified and greatly reduced the prices for the EuroPython 2020 online edition: https://ep2020.europython.eu/registration/buy-tickets/ As always, all proceeds from the conference will go into our grants budget, which we use to fund financial aid for the next EuroPython edition, special workshops and other European conferences and projects: * EuroPython Society Grants Program * https://www.europython-society.org/grants We hope to see lots of you at the conference in July. Rest assured that we?ll make this a great event again ? even within the limitations of running the conference online. Sprints ------- On Saturday and Sunday, we will have sprints/hackathons on a variety of topics. Registration of sprint topics has already started. If you would like to run a sprint, please add your sprint topic to the wiki page we have available for this: * EuroPython 2020 Sprints Listing * https://wiki.python.org/moin/EuroPython2020/Sprints If registrations continue as they currently do, we will have a few hundred people waiting to participate in your sprint projects, so this is the perfect chance for you to promote your project and find new contributors. Participation in the sprints is free, but does require registration. We will provide the necessary collaboration tools in form of dedicated Jitsi or Zoom virtual rooms and text channels on our Discord server. EuroPython is your conference ----------------------------- EuroPython has always been a completely volunteer based effort. The organizers work hundreds of hours to make the event happen and will try very hard to create an inspiring and exciting event. However, we can only provide the setting. You, as our attendees, are the ones who fill it with life and creativity. We are very much looking forward to having you at the conference ! 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/619453140468629504/europython-2020-schedule-published Tweet: https://twitter.com/europython/status/1266352353961299971 Thanks, -- EuroPython 2020 Team https://ep2020.europython.eu/ https://www.europython-society.org/ From mats at wichmann.us Fri May 29 11:01:12 2020 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 29 May 2020 09:01:12 -0600 Subject: Is there some reason that recent Windows 3.6 releases don't included executable nor msi installers? In-Reply-To: <20200528212044.GD17383@hjp.at> References: <4986af9e-0c1e-97d3-e830-268a1cc57684@python.org> <20200528212044.GD17383@hjp.at> Message-ID: <2c0c57a0-3dc7-2f95-0b62-e9a52bd27e59@wichmann.us> On 5/28/20 3:20 PM, Peter J. Holzer wrote: > On 2020-05-23 13:22:26 -0600, Mats Wichmann wrote: >> On 5/23/20 12:23 AM, Adam Preble wrote: >>> I wanted to update from 3.6.8 on Windows without necessarily moving >>> on to 3.7+ (yet), so I thought I'd try 3.6.9 or 3.6.10. >>> >>> All I see for both are source archives: > [...] >> >> During the early part of a release cycle, installers are built. Once >> the cycle moves into security fix-only mode, installers are not built. >> That's all you are seeing. > > This seems a rather odd policy to me. Distributing a security fix in > source-only form will prevent many people from applying it (especially > on Windows). As others have pointed out, it's a problem of how many versions to build. By the time 3.N is at the stage of receiving security-only, patch-only types of releases, both 3.N+1 and 3.N+2 are being actively built and supported, including Windows installers, both later releases will will include those fixes (assuming they're necessary), so you have plenty to choose from. You have the option of picking the patches and building your own if something _requires_ you to stay on 3.N, though admittedly that is less easy. It seems to be a reasonable compromise to me, but that's from the point of view of a kibitzer! From kotichowdary28 at gmail.com Fri May 29 11:10:04 2020 From: kotichowdary28 at gmail.com (kotichowdary28 at gmail.com) Date: Fri, 29 May 2020 08:10:04 -0700 (PDT) Subject: How to convert csv to netcdf please help me python users Message-ID: <26cbcf71-b09f-448d-9e9d-2acfcbc414c6@googlegroups.com> Hi all I hope all are doing well please help me how to convert CSV to NetCDF. Im trying but its not working #!/usr/bin/env ipython import pandas as pd import numpy as np import netCDF4 import pandas as pd import xarray as xr stn_precip='ts_sept.csv' orig_precip='ts_sept.csv' stations = pd.read_csv(stn_precip) stncoords = stations.iloc[:] orig = pd.read_csv(orig_precip) lats = stncoords['latitude'] lons = stncoords['longitude'] nstations = np.size(lons) ncout = netCDF4.Dataset('Precip_1910-2018_homomod.nc', 'w') ncout.createDimension('station',nstations) ncout.createDimension('time',orig.shape[0]) lons_out = lons.tolist() lats_out = lats.tolist() time_out = orig.index.tolist() lats = ncout.createVariable('latitude',np.dtype('float32').char,('station',)) lons = ncout.createVariable('longitude',np.dtype('float32').char,('station',)) time = ncout.createVariable('time',np.dtype('float32').char,('time',)) precip = ncout.createVariable('precip',np.dtype('float32').char,('time', 'station')) lats[:] = lats_out lons[:] = lons_out time[:] = time_out precip[:] = orig ncout.close() From adam.preble at gmail.com Fri May 29 11:36:50 2020 From: adam.preble at gmail.com (Adam Preble) Date: Fri, 29 May 2020 08:36:50 -0700 (PDT) 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> <75e2a38c-6b2c-46c2-8adc-bdf00adf119d@googlegroups.com> Message-ID: On Friday, May 29, 2020 at 7:30:32 AM UTC-5, Eryk Sun wrote: > On 5/28/20, Adam Preble wrote: > Sometimes a user will open a script via "open with" and browse to > python.exe or py.exe. This associates .py files with a new progid that > doesn't pass the %* command-line arguments. > > The installed Python.File progid should be listed in the open-with > list, and, if the launcher is installed, the icon should have the > Python logo with a rocket on it. Select that, lock it in by selecting > to always use it, and open the script. This will only be wrong if a > user or misbehaving program modified the Python.File progid and broke > its "open" action. Thank you for responding! The computers showing the problem are remote to me and I won't be able to access one for a few days, but I will be making it a point in particular to check their associations before continuing without anything else with it. From arj.python at gmail.com Fri May 29 11:46:46 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 29 May 2020 19:46:46 +0400 Subject: David Beazley's Practical Python Course Now Open & Free Message-ID: Greetings, A Great Py Course: https://dabeaz-course.github.io/practical-python/ David Beazley is a celebrated python dev, previously he was a lecturer in compiler theory. His practical py course is: "A no-nonsense treatment of Python that has been actively taught to more than 400 in-person groups since 2007." It has been taught to: "Traders, systems admins, astronomers, tinkerers, and even a few hundred rocket scientists who used Python to help land a rover on Mars?they?ve all taken this course. Now, I?m pleased to make it available under a Creative Commons license. Enjoy!" If you need to recommend a beginner material, please add it to your list! Kind Regards, Abdur-Rahmaan Janhangeer https://www.github.com/Abdur-RahmaanJ Mauritius sent from gmail client on Android, that's why the signature is so ugly. From preetha1111 at gmail.com Fri May 29 05:41:57 2020 From: preetha1111 at gmail.com (Preetha M) Date: Fri, 29 May 2020 15:11:57 +0530 Subject: .dll problem Message-ID: Hello. Warm regards from india. I am a kid who is currently learning python. Hope you are doing well. I know that it is not a problem that you can fix but whenever i try to open the software it shows that api-ms-win-crt-runtime-l1-0-0.dll is missing. I tried reinstalling but it is not working. Every application i install shows that something.dll is missing. Please help. Sincerely, A random person From zljubisic at gmail.com Fri May 29 11:08:50 2020 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Fri, 29 May 2020 08:08:50 -0700 (PDT) Subject: Custom logging function In-Reply-To: References: <04d4e0a3-99b6-4d3f-94bf-8da702365494@googlegroups.com> <4ed4c0f7-cea2-49ed-b568-b8f5cf902577@googlegroups.com> Message-ID: <16cd0a27-1698-4e8e-a31c-d746c26aa12f@googlegroups.com> Hi Peter. Finally I got it. :) That's it. It works. Thanks. So, in each class, I will in init method execute: self.logger = logging.getLogger() and than everywhere use self.logger.debug('...') in order to produce the message. Best regards. From souvik.viksou at gmail.com Fri May 29 12:38:51 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Fri, 29 May 2020 22:08:51 +0530 Subject: .dll problem In-Reply-To: References: Message-ID: Do you have DirectX installed. It must solve the problem. On Fri, 29 May, 2020, 9:50 pm Preetha M, wrote: > Hello. Warm regards from india. I am a kid who is currently learning > python. Hope you are doing well. I know that it is not a problem that you > can fix but whenever i try to open the software it shows that > api-ms-win-crt-runtime-l1-0-0.dll is missing. I tried reinstalling but it > is not working. Every application i install shows that something.dll is > missing. Please help. > > > > Sincerely, > > A random person > -- > https://mail.python.org/mailman/listinfo/python-list > From connor.r.novak at gmail.com Fri May 29 12:52:07 2020 From: connor.r.novak at gmail.com (connor.r.novak at gmail.com) Date: Fri, 29 May 2020 09:52:07 -0700 (PDT) Subject: Format Logfile Name with logging.ini Message-ID: <4d9927f6-c88c-4c71-a766-bd9836a82579@googlegroups.com> In an effort to clean up my python logging practices when creating libraries, I have begun reading into "Advanced Logging" and converting my logging practices into logging configuration `.ini` files: [link](https://docs.python.org/3.4/howto/logging.html#configuring-logging) My question is: When defining a FileHandler in a `.ini` file, all of the examples that I've seen hardcode the name and location of the log file. In the code snippet below, `python.log` is hardcoded into the `.ini` file: ``` [handler_hand02] class=FileHandler level=DEBUG formatter=form02 args=('python.log', 'w') ``` [code reference link](https://docs.python.org/3.4/library/logging.config.html#logging-config-fileformat) Desired Behavior: On each run of the program, a new logfile is created in the `logs/` directory named "_program.log". Current Behavior: The format in the example above overwrites a single file called "python.log" on each run, which is not the desired behavior. Question: Is there a standard procedure for using .ini files to create a new logfile prepended with the current Unix timestamp on each run of the program? From rhodri at kynesim.co.uk Fri May 29 12:56:25 2020 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 29 May 2020 17:56:25 +0100 Subject: .dll problem In-Reply-To: References: Message-ID: [Re-ordered because top-posting is evil ]:-) On 29/05/2020 17:38, Souvik Dutta wrote: > On Fri, 29 May, 2020, 9:50 pm Preetha M, wrote: > >> Hello. Warm regards from india. I am a kid who is currently learning >> python. Hope you are doing well. I know that it is not a problem that you >> can fix but whenever i try to open the software it shows that >> api-ms-win-crt-runtime-l1-0-0.dll is missing. I tried reinstalling but it >> is not working. Every application i install shows that something.dll is >> missing. Please help. > Do you have DirectX installed. It must solve the problem. > DirectX is highly unlikely to be involved, as you have been told before Souvik. What the OP actually needs is the missing Windows runtime, which can be obtained straightforwardly from Microsoft. Here's the link: https://www.microsoft.com/en-in/download/details.aspx?id=48145 Incidentally, the first link Google turns up when you search for "windows runtime missing" explains what's going on and points to this link. -- Rhodri James *-* Kynesim Ltd From hjp-python at hjp.at Fri May 29 16:02:56 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 29 May 2020 22:02:56 +0200 Subject: Format Logfile Name with logging.ini In-Reply-To: <4d9927f6-c88c-4c71-a766-bd9836a82579@googlegroups.com> References: <4d9927f6-c88c-4c71-a766-bd9836a82579@googlegroups.com> Message-ID: <20200529200256.GA25073@hjp.at> On 2020-05-29 09:52:07 -0700, connor.r.novak at gmail.com wrote: > In an effort to clean up my python logging practices when creating > libraries, I have begun reading into "Advanced Logging" and converting > my logging practices into logging configuration `.ini` files: > > [link](https://docs.python.org/3.4/howto/logging.html#configuring-logging) > > My question is: When defining a FileHandler in a `.ini` file, all of > the examples that I've seen hardcode the name and location of the log > file. In the code snippet below, `python.log` is hardcoded into the > `.ini` file: This is a strange usage of the term "hardcoded", Normally, hardcoded means that it is in the *code*, not a configuration file. > ``` > [handler_hand02] > class=FileHandler > level=DEBUG > formatter=form02 > args=('python.log', 'w') > ``` > [code reference link](https://docs.python.org/3.4/library/logging.config.html#logging-config-fileformat) > > Desired Behavior: > On each run of the program, a new logfile is created in the `logs/` > directory named "_program.log". > > Current Behavior: > The format in the example above overwrites a single file called > "python.log" on each run, which is not the desired behavior. > > Question: Is there a standard procedure for using .ini files to create > a new logfile prepended with the current Unix timestamp on each run of > the program? You would have to use a different class for that. I don't know one offhand which implements the behaviour you want, but for example TimedRotatingFileHandler switches log files after a configurable interval. So for example class=TimedRotatingFileHandler when=H would start a new log every hour (and rename the old log to contain a timestamp). You may need to write a handler which implements the behaviour you want. Or maybe there is one on PyPi. 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 Fri May 29 16:24:25 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 29 May 2020 22:24:25 +0200 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <20200528201854.GB17383@hjp.at> Message-ID: <20200529202425.GB25073@hjp.at> On 2020-05-29 06:27:31 +1000, Chris Angelico wrote: > On Fri, May 29, 2020 at 6:20 AM Peter J. Holzer wrote: > > On 2020-05-19 05:59:30 +1000, Chris Angelico wrote: > > > PEP 8 is a style guide for the Python standard library. It is the > > > rules you must comply with if you are submitting a patch *to Python > > > itself*. Nobody ever requires you to comply with it for any other > > > code. > > > > That's obviously not true: Many companies and projects have a coding > > standard. Many of those coding standards will be based on or even > > identical to PEP 8. And as an employee or contributor you may be > > required to comply with it. [...] > The OP said: > > My preference for using camelCase (in PEP 8, AKA mixedCase) is > > putting me at odds with my colleagues, who point to PEP 8 as "the > > rules". > > > > This smells like the incredibly strong misconception that PEP 8 needs > to govern every line of Python code ever written, or else it's "bad > code". This thread wouldn't have been started if it had been any other > style guide that the company had been chosen, because then it's > obvious that the choice is the company's. It's only when PEP 8 is > considered to be some sort of universal standard that we get this kind > of discussion. I got a bit side-tracked in my previous reply, so I'm trying to stick to my original point more closely this time. Your claim was that "nobody ever requires you to comply with [PEP 8] for any other code". For this claim to be false, only one person/company/project needs to require somebody to comply with PEP 8. Their motives are completely irrelevant. They may believe that compliance with PEP 8 is necessary for any Python code. They may just think that PEP 8 is a good idea. They may have had a vision of Elvis singing the text of PEP 8 to the tune of Jailhouse Rock. It doesn't matter. Your claim was about their actions, not their motives. The OP seems to feel that he is required by his colleagues to comply with PEP 8. So his company would serve as a counter-example (though maybe a weak one, since it doesn't seem to be a hard requirement). hp PS: We have "PEP 8, unless you have a good reason to deviate" in our style guide, but we don't enforce that at all (unfortunately). -- _ | 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 Fri May 29 16:30:54 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 29 May 2020 22:30:54 +0200 Subject: why no camelCase in PEP 8? In-Reply-To: References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <20200528201854.GB17383@hjp.at> Message-ID: <20200529203054.GC25073@hjp.at> On 2020-05-28 18:14:53 -0400, Terry Reedy wrote: > On 5/28/2020 4:18 PM, Peter J. Holzer wrote: > > On 2020-05-19 05:59:30 +1000, Chris Angelico wrote: > > > Nobody ever requires you to comply with it for any other code. > > > > That's obviously not true: [...] > Revise Chris' claim to "Neither the PSF nor the Python core developers > require* that owners of non-stdlib code comply with PEP 8" and it would be > true. Well, yes. But "Neither the PSF nor the Python core developers" is quite different from "Nobody ever". That's like saying "Nobody has ever been on the moon" is true if you replace "Nobody" with "No catholic bishop". 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 msuginoo at reversalpoint.com Fri May 29 16:24:05 2020 From: msuginoo at reversalpoint.com (Michio Suginoo) Date: Fri, 29 May 2020 17:24:05 -0300 Subject: I cannot download python files from external source. Message-ID: Hi I installed python via Anaconda some months ago. And since then, I could not download python files from external sources. Basically, every time I tried to download python files, the python system that I installed via Anaconda gives me a system message with three options: - Modify (add or modify individual features), - Repair (ensure all current features are correctly installed), and - Uninstall (remove the entire Python 3.7.4 (32 bit) installation). Basically, none of these choices is what I want. I simply want to download a python file and open it in Jupyter Notebook. As an example, if I choose Repair, this will give me another system message saying ?Repair was successful?. But nothing else. At the end, I do not get what I want, the python file that I wanted to download from an external source. I just wonder what causes this problem. I would appreciate it if you can provide me a solution to resolve this problem. Thanks Michio From python at mrabarnett.plus.com Fri May 29 16:57:48 2020 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 29 May 2020 21:57:48 +0100 Subject: I cannot download python files from external source. In-Reply-To: References: Message-ID: <43307fe4-44c2-34c6-b86d-569226b4f51c@mrabarnett.plus.com> On 2020-05-29 21:24, Michio Suginoo wrote: > Hi > > I installed python via Anaconda some months ago. > And since then, I could not download python files from external sources. > Basically, every time I tried to download python files, the python system > that I installed via Anaconda gives me a system message with three options: > > - Modify (add or modify individual features), > - Repair (ensure all current features are correctly installed), and > - Uninstall (remove the entire Python 3.7.4 (32 bit) installation). > > Basically, none of these choices is what I want. I simply want to download > a python file and open it in Jupyter Notebook. > > As an example, if I choose Repair, this will give me another system message > saying ?Repair was successful?. But nothing else. At the end, I do not get > what I want, the python file that I wanted to download from an external > source. > > I just wonder what causes this problem. I would appreciate it if you can > provide me a solution to resolve this problem. > That program is an installer for Python. It's only purpose is to install or uninstall Python, and nothing else. It's not for downloading other files. From hjp-python at hjp.at Fri May 29 17:20:36 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 29 May 2020 23:20:36 +0200 Subject: Ram memory not freed after executing python script on ubuntu system (rmlibre) In-Reply-To: References: Message-ID: <20200529212036.GD25073@hjp.at> On 2020-05-29 14:28:59 +0900, Inada Naoki wrote: > pymalloc manages only small blocks of memory. > Large (more than 512 byte) memory blocks are managed by malloc/free. > > glibc malloc doesn't return much freed memory to OS. That depends on what "much" means. Glibc does return blocks to the OS which it allocated via mmap, By default, these are allocations larger than 128 kB. So that means that * Blocks smaller than 512 bytes are returned to the OS if the arena they are in is completely empty. * Blocks between 512 bytes and 128 kB are not returned to the OS (unless they happen to be at the end of the heap). * Blocks larger than 128 kB are returned to the OS: Most Python objects are probably smaller than 512 bytes, so whether "much" is returned to the OS mostly depends on whether arenas ever get completely empty. This stupid little test program returns memory to the OS quite nicely, because it allocates and frees lots of objects together: ---8<------8<------8<------8<------8<------8<------8<------8<--- #!/usr/bin/python3 import time a = [] for i in range(10): print('a', i) x = [] for j in range(1000000): x.append(j) a.append(x) time.sleep(1) if i >= 5: print('d', i - 5) a[i - 5] = None time.sleep(1) print('f') ---8<------8<------8<------8<------8<------8<------8<------8<--- (run it with strace to watch the mmap/munmap system calls) A program with more random allocation patterns may suffer severe internal fragmentation and end up with many mostly empty arenas. > You can try jemalloc instead of glibc. I think that would only make a difference if you have lots of objects between 512 B and 128 kB. And only if those of similar size are allocated and freed together. 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 python at mrabarnett.plus.com Fri May 29 21:38:39 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 30 May 2020 02:38:39 +0100 Subject: I cannot download python files from external source. In-Reply-To: References: <43307fe4-44c2-34c6-b86d-569226b4f51c@mrabarnett.plus.com> Message-ID: <422d5e7c-e3ce-04d6-b23b-d52970a44efa@mrabarnett.plus.com> On 2020-05-30 00:55, Michio Suginoo wrote: > Yes, it?s clear to me what you wrote. I was just communicating what > happened when I tried to download python files from external sources. > > My question is how I can enable the installed Python (Anaconda) to > download files from external sources. > > Thanks > Please keep this on python-list. How you download files depends on what/where they are. Some are downloaded via a browser (probably how you got Anaconda); some via FTP; if you're using version control software such as Git (GitHub), via that; if you're talking about Python modules and extensions on PyPI, via pip. > > > On Fri, 29 May 2020 at 18:01 MRAB > wrote: > > On 2020-05-29 21:24, Michio Suginoo wrote: > > Hi > > > > I installed python via Anaconda some months ago. > > And since then, I could not download python files from external > sources. > > Basically, every time I tried to download python files, the > python system > > that I installed via Anaconda gives me a system message with > three options: > > > >? ? ?- Modify (add or modify individual features), > >? ? ?- Repair (ensure all current features are correctly > installed), and > >? ? ?- Uninstall (remove the entire Python 3.7.4 (32 bit) > installation). > > > > Basically, none of these choices is what I want. I simply want > to download > > a python file and open it in Jupyter Notebook. > > > > As an example, if I choose Repair, this will give me another > system message > > saying ?Repair was successful?. But nothing else. At the end, I > do not get > > what I want, the python file that I wanted to download from an > external > > source. > > > > I just wonder what causes this problem. I would appreciate it if > you can > > provide me a solution to resolve this problem. > > > That program is an installer for Python. It's only purpose is to > install > or uninstall Python, and nothing else. It's not for downloading > other files. > -- > https://mail.python.org/mailman/listinfo/python-list > > -- > Michio Suginoo, > Chartered Financial Analyst^? > ^ > Website: > > www.reversalpoint.com ; > www.monetarywonderland.com > > Social Network: > https://au.linkedin.com/in/reversalpoint > From preetha1111 at gmail.com Sat May 30 03:42:30 2020 From: preetha1111 at gmail.com (Preetha M) Date: Sat, 30 May 2020 13:12:30 +0530 Subject: Python with text editor Message-ID: 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. From PythonList at DancesWithMice.info Sat May 30 16:16:01 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 31 May 2020 08:16:01 +1200 Subject: Python with text editor In-Reply-To: References: Message-ID: <3d01766c-7ad2-ea87-4d24-d3076712e0d0@DancesWithMice.info> On 30/05/20 7:42 PM, 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. ST is an editor/IDE which is not Python-specific. The build system on ST is (better) designed (and named) for compiled languages. Python does not require a compile-and-build process. However, we can use the command even though all it does is directly execute the code - exactly what we want. First, manually instruct ST how to build your (current) project: main menu > Tools > BuildSystem > Python3 (assumption!). Once done (configured), always remembered! Thereafter, when you select Build (ctrl+b), ST will know that it is working on a Python 'build'... -- Regards =dn From tjreedy at udel.edu Sat May 30 02:15:28 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 30 May 2020 02:15:28 -0400 Subject: why no camelCase in PEP 8? In-Reply-To: <20200529203054.GC25073@hjp.at> References: <9766f66d-b147-4e71-b279-a1ab630004e5@googlegroups.com> <20200528201854.GB17383@hjp.at> <20200529203054.GC25073@hjp.at> Message-ID: On 5/29/2020 4:30 PM, Peter J. Holzer wrote: > On 2020-05-28 18:14:53 -0400, Terry Reedy wrote: >> On 5/28/2020 4:18 PM, Peter J. Holzer wrote: >>> On 2020-05-19 05:59:30 +1000, Chris Angelico wrote: >>>> Nobody ever requires you to comply with it for any other code. >>> >>> That's obviously not true: > [...] >> Revise Chris' claim to "Neither the PSF nor the Python core developers >> require* that owners of non-stdlib code comply with PEP 8" and it would be >> true. > > Well, yes. But "Neither the PSF nor the Python core developers" is quite > different from "Nobody ever". Right, I modified a statement that takenly literally is obvious false, undefensible, and not worth discussing to one that I believe to be true and that says something important. I would qualify further to people in their PSF/core-dev roles. There might be core-devs who enforce PEP-8 in other roles. > That's like saying "Nobody has ever been on the moon" is true if you > replace "Nobody" with "No catholic bishop". Only as the level of an empty generic template. has ever . Semantically, the two statements are not at all paralley. The PSF/core-devs own python and PEP-8. Catholic bishops do not own either the moon or means of walking there. And there would be nothing wrong if a Catholic bishop were to walk on the moon, and I can imagine (and hope) that one might someday do so. -- Terry Jan Reedy From evan.schalton at gmail.com Sat May 30 18:52:14 2020 From: evan.schalton at gmail.com (evan.schalton at gmail.com) Date: Sat, 30 May 2020 15:52:14 -0700 (PDT) Subject: Binary Sort on Python List __xor__ Message-ID: I frequently use binary as bool placeholders and find myself filtering lists based on those bools, this seems to have a similar semantic meaning as the bit wise ^ or __xor__ operator and could add syntactic sugar to the base list class. Use Case: Controlling a stepper at half-step has the following cycle steps: CYCLE = [ [1,0,0,0], [1,1,0,0], [0,1,0,0], [0,1,1,0], [0,0,1,0], [0,0,1,1], [0,0,0,1], [1,0,0,1], ] which can be represented as follows: CYCLE = [ 1<<3, 1<<3|1<<2, 1<<2, 1<<2|1<<1, 1<<1, 1<<1|1<<0, 1<<0, 1<<3|1<<0 ] or more cleanly: CYCLE = [8, 12, 4, 6, 2, 3, 1, 9] on a raspberrypi, using (for illustration's sake) GPIO pins 1,2,3,4 I'd like to use the __xor__ method (currently not implemented) to perform the bit-wise filter as follows: class MyList(list): def __init__(self, *args): super().__init__(args) def __xor__(self, num): return [self[i] for i in [-index-1 for index, i in enumerate(bin(num)[:1:-1]) if i !='0']][::-1] PINS = MyList(1,2,3,4) PINS ^ 8 # [1] PINS ^ 12 # [1, 2] PINS ^ 4 # [2] PINS ^ 6 # [2, 3] PINS ^ 2 # [3] PINS ^ 3 # [3, 4] PINS ^ 1 # [4] PINS ^ 9 # [1, 4] The need here isn't strictly pi/stepper related; I've run into this several times in the past when evaluating combinations * permutations of items where a bitwise filter would be useful. From python at mrabarnett.plus.com Sat May 30 20:28:36 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 31 May 2020 01:28:36 +0100 Subject: Binary Sort on Python List __xor__ In-Reply-To: References: Message-ID: <8f0ca7d7-31ac-9793-33ed-dc97e181d87a@mrabarnett.plus.com> On 2020-05-30 23:52, evan.schalton at gmail.com wrote: > I frequently use binary as bool placeholders and find myself filtering lists based on those bools, this seems to have a similar semantic meaning as the bit wise ^ or __xor__ operator and could add syntactic sugar to the base list class. > > Use Case: > > Controlling a stepper at half-step has the following cycle steps: > > CYCLE = [ > [1,0,0,0], > [1,1,0,0], > [0,1,0,0], > [0,1,1,0], > [0,0,1,0], > [0,0,1,1], > [0,0,0,1], > [1,0,0,1], > ] > > which can be represented as follows: > > CYCLE = [ > 1<<3, > 1<<3|1<<2, > 1<<2, > 1<<2|1<<1, > 1<<1, > 1<<1|1<<0, > 1<<0, > 1<<3|1<<0 > ] > > or more cleanly: > > CYCLE = [8, 12, 4, 6, 2, 3, 1, 9] > Or more clearly: CYCLE = [ 0b1000, 0b1100, 0b0100, 0b0110, 0b0010, 0b0011, 0b0001, 0b1001, ] > on a raspberrypi, using (for illustration's sake) GPIO pins 1,2,3,4 I'd like to use the __xor__ method (currently not implemented) to perform the bit-wise filter as follows: Bit-masking is done with a bitwise AND, so I'd expect the __and__ method would be used. The __xor__ method would be for bit-toggling. > > class MyList(list): > def __init__(self, *args): > super().__init__(args) > > def __xor__(self, num): > return [self[i] for i in [-index-1 for index, i in enumerate(bin(num)[:1:-1]) if i !='0']][::-1] > > PINS = MyList(1,2,3,4) > > PINS ^ 8 > # [1] > > PINS ^ 12 > # [1, 2] > > PINS ^ 4 > # [2] > > PINS ^ 6 > # [2, 3] > > PINS ^ 2 > # [3] > > PINS ^ 3 > # [3, 4] > > PINS ^ 1 > # [4] > > PINS ^ 9 > # [1, 4] > > The need here isn't strictly pi/stepper related; I've run into this several times in the past when evaluating combinations * permutations of items where a bitwise filter would be useful. > Do you really need a class for this? CYCLE = [ 0b1000, 0b1100, 0b0100, 0b0110, 0b0010, 0b0011, 0b0001, 0b1001, ] PINS = [1, 2, 3, 4] def bit_filter(pins, bits): return [pin for pin, bit in zip(PINS, format(bits, '04b')) if bit == '1'] bit_filter(PINS, 0b1000) # [1] bit_filter(PINS, 0b0100) # [2] bit_filter(PINS, 0b0110) # [2, 3] bit_filter(PINS, 0b0010) # [3] bit_filter(PINS, 0b0011) # [3, 4] bit_filter(PINS, 0b0001) # [4] bit_filter(PINS, 0b1001) # [1, 4] From evan.schalton at gmail.com Sat May 30 20:54:19 2020 From: evan.schalton at gmail.com (Evan Schalton) Date: Sat, 30 May 2020 17:54:19 -0700 (PDT) Subject: Binary Sort on Python List __xor__ In-Reply-To: References: Message-ID: <5df4e9b5-dbf6-4f53-aecd-1b59705e3983@googlegroups.com> @MRAB, Yes -- good point, it should be the __and__ operator. do I need a new class? No, but based on this use case and other formatting techniques adding a filter method to the list class that takes in either bit mask or bool list would streamline a lot of code and not change any existing functionality From PythonList at DancesWithMice.info Sat May 30 23:56:59 2020 From: PythonList at DancesWithMice.info (DL Neil) Date: Sun, 31 May 2020 15:56:59 +1200 Subject: Format Logfile Name with logging.ini In-Reply-To: <4d9927f6-c88c-4c71-a766-bd9836a82579@googlegroups.com> References: <4d9927f6-c88c-4c71-a766-bd9836a82579@googlegroups.com> Message-ID: On 30/05/20 4:52 AM, connor.r.novak at gmail.com wrote: > In an effort to clean up my python logging practices when creating libraries, I have begun reading into "Advanced Logging" and converting my logging practices into logging configuration `.ini` files: > > [link](https://docs.python.org/3.4/howto/logging.html#configuring-logging) > > My question is: When defining a FileHandler in a `.ini` file, all of the examples that I've seen hardcode the name and location of the log file. In the code snippet below, `python.log` is hardcoded into the `.ini` file: > > ``` > [handler_hand02] > class=FileHandler > level=DEBUG > formatter=form02 > args=('python.log', 'w') > ``` > [code reference link](https://docs.python.org/3.4/library/logging.config.html#logging-config-fileformat) > > Desired Behavior: > On each run of the program, a new logfile is created in the `logs/` directory named "_program.log". > > Current Behavior: > The format in the example above overwrites a single file called "python.log" on each run, which is not the desired behavior. > > Question: Is there a standard procedure for using .ini files to create a new logfile prepended with the current Unix timestamp on each run of the program? There is nothing in the PSL to do this (to my knowledge) - correction/education welcome... However, it is a fairly standard pattern to take a base-name from a config file (.ini in MSFT wording) and then to post-process to suit the application's purposes. In this case, adding a timestamp makes sense - although perhaps a more human-readable option unless file-name length is a concern. The pattern is to: Compute the (log) file-name. Check to see if it name already exists (in this directory). Re-compute if necessary - rinse-and-repeat. Something like: Make unique file name https://code.activestate.com/recipes/577200-make-unique-file-name/ -- Regards =dn From __peter__ at web.de Sun May 31 05:33:44 2020 From: __peter__ at web.de (Peter Otten) Date: Sun, 31 May 2020 11:33:44 +0200 Subject: Binary Sort on Python List __xor__ References: Message-ID: evan.schalton at gmail.com wrote: > I frequently use binary as bool placeholders and find myself filtering > lists based on those bools, this seems to have a similar semantic meaning > as the bit wise ^ or __xor__ operator and could add syntactic sugar to the > base list class. > > Use Case: > > Controlling a stepper at half-step has the following cycle steps: > > CYCLE = [ > [1,0,0,0], > [1,1,0,0], > [0,1,0,0], > [0,1,1,0], > [0,0,1,0], > [0,0,1,1], > [0,0,0,1], > [1,0,0,1], > ] > > which can be represented as follows: > > CYCLE = [ > 1<<3, > 1<<3|1<<2, [...] > on a raspberrypi, using (for illustration's sake) GPIO pins 1,2,3,4 I'd > like to use the __xor__ method (currently not implemented) to perform the > bit-wise filter as follows: Python isn't C;) A matrix of booleans *can* be expressed using bit twiddling, but I don't see the point. Just the other day I read that raspis now come with up to 8 GB memory. Here's an alternative: >>> import numpy >>> CYCLE = [ ... [1,0,0,0], ... [1,1,0,0], ... [0,1,0,0], ... [0,1,1,0], ... [0,0,1,0], ... [0,0,1,1], ... [0,0,0,1], ... [1,0,0,1], ... ] >>> cycle = numpy.array(CYCLE, dtype=bool) >>> cycle array([[ True, False, False, False], [ True, True, False, False], [False, True, False, False], [False, True, True, False], [False, False, True, False], [False, False, True, True], [False, False, False, True], [ True, False, False, True]], dtype=bool) >>> numpy.where(cycle[1]) (array([0, 1]),) That's zero-based indexing, as it should be; you can convert with >>> numpy.where(cycle[1])[0] + 1 array([1, 2]) or (similar to your list subclass) you can pick arbitrary values: >>> labels = np.array(["first", "second", "third", "fourth"]) >>> labels[cycle[0]] array(['first'], dtype='>> labels[cycle[1]] array(['first', 'second'], dtype=' References: <43307fe4-44c2-34c6-b86d-569226b4f51c@mrabarnett.plus.com> <422d5e7c-e3ce-04d6-b23b-d52970a44efa@mrabarnett.plus.com> Message-ID: <12dda1c5-0d40-eee4-35b8-75b59d0f000a@mrabarnett.plus.com> On 2020-05-31 15:36, Michio Suginoo wrote: > Thanks MRAB, > > I try to download the external file in .ipynb. > And I get the message attached herewith. > > And this is not the first time, it has been like this. And I have > never been able to download any python file. > I just wonder if it has anything to do with the setting of my computer. > As I've already said, that's just the installer. It isn't used to download files. Where is the file? Is it on a website? If yes, download it using a browser. Here's an example: https://www.usna.edu/Users/math/uhan/sa421/2014f/ipynb-download.html From evan.schalton at gmail.com Sun May 31 12:24:56 2020 From: evan.schalton at gmail.com (Evan Schalton) Date: Sun, 31 May 2020 09:24:56 -0700 (PDT) Subject: Binary Sort on Python List __xor__ In-Reply-To: References: Message-ID: <0c2a145b-bd6c-4bd1-9eba-655a168312ae@googlegroups.com> Peter, This isn't a ram consideration as much it's a logical consideration. There are a lot of ways to handle this, I REALLY don't want to use a package here. Bit masking is incredibly useful for permutations/combinatoric algorithms. I can create my own class wrapper or functions, and optimize, but think that the __and__ operator would be a really useful syntactic tool. It would streamline these types of operations and *hopefully* help people write more efficient code. I'm less strictly interested in the & operator explicitly working with a bit int, but think it'd be great if the was a built-in filter something like: [1,2,3,4] & [0,0,1,1] => [3,4] OR [1,2,3,4] & [False, False, True, True] = [3,4] From evan.schalton at gmail.com Sun May 31 12:36:31 2020 From: evan.schalton at gmail.com (Evan Schalton) Date: Sun, 31 May 2020 09:36:31 -0700 (PDT) Subject: I cannot download python files from external source. In-Reply-To: References: Message-ID: <12c6ae90-f2f5-4e9a-8b5b-76919851009d@googlegroups.com> Michio, Are you trying to open the ipynb file with python? You need Jupyter Notebook to run ipynb files. Try installing jupyter notebook (cmd: pip install jupyter) then launching the jupyter notebook py server (cmd: jupyter notebook). You should be able to use the file browser in the notebook window to open the file. I'm not sure about your familiarity with Jupyter/python, sorry if this is off base. -E From __peter__ at web.de Sun May 31 12:44:40 2020 From: __peter__ at web.de (Peter Otten) Date: Sun, 31 May 2020 18:44:40 +0200 Subject: Binary Sort on Python List __xor__ References: <0c2a145b-bd6c-4bd1-9eba-655a168312ae@googlegroups.com> Message-ID: Evan Schalton wrote: > Peter, > > This isn't a ram consideration as much it's a logical consideration. There > are a lot of ways to handle this, I REALLY don't want to use a package > here. Bit masking is incredibly useful for permutations/combinatoric > algorithms. I can create my own class wrapper or functions, and optimize, > but think that the __and__ operator would be a really useful syntactic > tool. It would streamline these types of operations and *hopefully* help > people write more efficient code. > > I'm less strictly interested in the & operator explicitly working with a > bit int, but think it'd be great if the was a built-in filter something > like: > > [1,2,3,4] & [0,0,1,1] => [3,4] OR > [1,2,3,4] & [False, False, True, True] = [3,4] But, but, but... for numpy arrays this is done regularly, and the established way to spell it is >>> a = np.array([1,2,3,4]) >>> b = np.array([False, False, True, True]) >>> a[b] array([3, 4]) rather than a & b whereas for lists IMO it's a fringe application. I may be influenced by numpy's example, but I'd expect [1, 2, 3, 4] & [0, 0, 1, 1] --> [0, 0, 1, 0] i. e. bitwise per-element and. From evan.schalton at gmail.com Sun May 31 13:01:10 2020 From: evan.schalton at gmail.com (Evan Schalton) Date: Sun, 31 May 2020 10:01:10 -0700 (PDT) Subject: Binary Sort on Python List __xor__ In-Reply-To: References: <0c2a145b-bd6c-4bd1-9eba-655a168312ae@googlegroups.com> Message-ID: 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 From robin at reportlab.com Sun May 31 03:16:49 2020 From: robin at reportlab.com (Robin Becker) Date: Sun, 31 May 2020 08:16:49 +0100 Subject: [RELEASE] Python 3.9.0b1 is now available for testing In-Reply-To: <026F8D50-BEEF-4814-A984-08B7B41FF392@langa.pl> References: <026F8D50-BEEF-4814-A984-08B7B41FF392@langa.pl> Message-ID: 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 From msuginoo at reversalpoint.com Sun May 31 14:00:09 2020 From: msuginoo at reversalpoint.com (Michio Suginoo) Date: Sun, 31 May 2020 15:00:09 -0300 Subject: I cannot download python files from external source. In-Reply-To: <12c6ae90-f2f5-4e9a-8b5b-76919851009d@googlegroups.com> References: <12c6ae90-f2f5-4e9a-8b5b-76919851009d@googlegroups.com> Message-ID: Hi Evan, Thanks for your explaining the situation in a plain language. Thanks to your description, I have a better understanding. This is one step forward. I will try to open it from Jupyter Notebook. If I still have trouble, I might get back to this list. Then, if you can further advise me from there, I would appreciate it. Thanks for now. Best regards Michio On Sun, May 31, 2020 at 1:43 PM Evan Schalton wrote: > Michio, > > Are you trying to open the ipynb file with python? You need Jupyter > Notebook to run ipynb files. Try installing jupyter notebook (cmd: pip > install jupyter) then launching the jupyter notebook py server (cmd: > jupyter notebook). You should be able to use the file browser in the > notebook window to open the file. > > I'm not sure about your familiarity with Jupyter/python, sorry if this is > off base. > > -E > -- > https://mail.python.org/mailman/listinfo/python-list > From msuginoo at reversalpoint.com Sun May 31 14:10:22 2020 From: msuginoo at reversalpoint.com (Michio Suginoo) Date: Sun, 31 May 2020 15:10:22 -0300 Subject: I cannot download python files from external source. In-Reply-To: <12dda1c5-0d40-eee4-35b8-75b59d0f000a@mrabarnett.plus.com> References: <43307fe4-44c2-34c6-b86d-569226b4f51c@mrabarnett.plus.com> <422d5e7c-e3ce-04d6-b23b-d52970a44efa@mrabarnett.plus.com> <12dda1c5-0d40-eee4-35b8-75b59d0f000a@mrabarnett.plus.com> Message-ID: Thanks MRAB Sorry that I did not fully understand your previous message. I have been learning Python within the system of an online course provider. This is my new attempt to use Python outside of the system and everything about the operating environment is very new to me. Thanks On Sun, May 31, 2020 at 12:48 PM MRAB wrote: > On 2020-05-31 15:36, Michio Suginoo wrote: > > Thanks MRAB, > > > > I try to download the external file in .ipynb. > > And I get the message attached herewith. > > > > And this is not the first time, it has been like this. And I have > > never been able to download any python file. > > I just wonder if it has anything to do with the setting of my computer. > > > As I've already said, that's just the installer. It isn't used to > download files. > > Where is the file? Is it on a website? If yes, download it using a browser. > > Here's an example: > > https://www.usna.edu/Users/math/uhan/sa421/2014f/ipynb-download.html > > > -- > https://mail.python.org/mailman/listinfo/python-list > From giovanni.braschi2 at gmail.com Sun May 31 13:32:04 2020 From: giovanni.braschi2 at gmail.com (giovanni.braschi2 at gmail.com) Date: Sun, 31 May 2020 10:32:04 -0700 (PDT) Subject: Spotify Playlist Message-ID: <6ef738dc-c0fc-49d0-8545-c3fe4f3ec5d6@googlegroups.com> Hi everyone, first of all I must say I'm NOT a Python expert. In reality, I've never even used Python, but I know that it is a super powerful tool, useful in many contexts, also in Spotify. 2nd disclaimer: English is not my first language so I'll try to explain what I want to ask in the best way possible. So, this is my problem: I am a playlist curator on Spotify, with more than 50.000 followers over all through out all my playlist. Lately, people started falsely reporting playlists on Spotify to gain a better rank in Spotify search algorithm. (if you search on the web, you will find that is becoming more and more common) Each time a playlist is reported, the title, description and image disappear BEFORE the Spotify team check if the report is actually true or not. You will understand that this leads to a MASSIVE abuse of this tool, you just need to fill a form with name, telephone number and email and you can make this report. Obviously, people are filling this form with fake mails and identities. This means that a fraudulent user can report your playlist 10000000 times a day, and there is nothing you can do against it, because if Spotify bans his fake "mail" he will fill the form with another fake email. This also means that if the reporter flag my playlist 10.000 times, I have to rewrite title, caption and upload user 10.000 times, and it is absolutely absurd. I sent hundreds of mail to the spotify team, they told me they are working to fix it, but currently there is no way to stop this (THIS IS CRAZY!) So my question is: is there a way to create a code with Python, that auto rewrite the title of a playlist each time Python sees the title has disappeared? For example: The reporter reports my playlist --> Title, Description and Image are gone (until I don't rewrite them again) Python notices that the title is gone and automatically rewrite the title and caption Do you think this is possible? I am willing to pay for someone making this code for me, because these fake reports are becoming more and more frequent, and as a music blogger, Spotify Playlists are a part of my income. I can't stay 24/7 at home rewriting the titles of my falsely reported playlist (with no reason) Hope this was clear enough, thank you! From rosuav at gmail.com Sun May 31 19:10:08 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 1 Jun 2020 09:10:08 +1000 Subject: Spotify Playlist In-Reply-To: <6ef738dc-c0fc-49d0-8545-c3fe4f3ec5d6@googlegroups.com> References: <6ef738dc-c0fc-49d0-8545-c3fe4f3ec5d6@googlegroups.com> Message-ID: On Mon, Jun 1, 2020 at 8:34 AM wrote: > This means that a fraudulent user can report your playlist 10000000 times a day, and there is nothing you can do against it, because if Spotify bans his fake "mail" he will fill the form with another fake email. This also means that if the reporter flag my playlist 10.000 times, I have to rewrite title, caption and upload user 10.000 times, and it is absolutely absurd. I sent hundreds of mail to the spotify team, they told me they are working to fix it, but currently there is no way to stop this (THIS IS CRAZY!) > Yes. That is crazy. Spotify needs to fix that. However, in the meantime... > So my question is: is there a way to create a code with Python, that auto rewrite the title of a playlist each time Python sees the title has disappeared? > > For example: > The reporter reports my playlist --> Title, Description and Image are gone (until I don't rewrite them again) > > Python notices that the title is gone and automatically rewrite the title and caption > > Do you think this is possible? > Hmm. Leaving aside the automation part, I think it's going to be possible. You'd need to have a file somewhere with a list of your playlists and their Spotify IDs, and the desired titles and captions, and then a program that uses the Spotify API to reapply those details: https://developer.spotify.com/documentation/web-api/reference/playlists/change-playlist-details/ And for the cover image: https://developer.spotify.com/documentation/web-api/reference/playlists/upload-custom-playlist-cover/ 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 But that's a matter of striking a balance between how much you use the API and how quickly you notice a problem. Initially, just having something that you manually run would be fairly straight-forward, and should still be of value. > I am willing to pay for someone making this code for me, because these fake reports are becoming more and more frequent, and as a music blogger, Spotify Playlists are a part of my income. I can't stay 24/7 at home rewriting the titles of my falsely reported playlist (with no reason) > Can't blame you! I won't take on the job myself, but I fully support the notion :) To whoever ends up picking this up, it'll be a pretty straight-forward job of calling on an HTTP API. All the best! ChrisA From tjreedy at udel.edu Sun May 31 22:37:16 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 31 May 2020 22:37:16 -0400 Subject: Binary Sort on Python List __xor__ In-Reply-To: <0c2a145b-bd6c-4bd1-9eba-655a168312ae@googlegroups.com> References: <0c2a145b-bd6c-4bd1-9eba-655a168312ae@googlegroups.com> Message-ID: On 5/31/2020 12:24 PM, Evan Schalton wrote: > I'm less strictly interested in the & operator explicitly working with a bit int, but think it'd be great if the was a built-in filter something like: > [1,2,3,4] & [0,0,1,1] => [3,4] OR > [1,2,3,4] & [False, False, True, True] = [3,4] Leaving numpy aside, Python already has very flexible map and filter functions, and comprehensions encompassing both, that easily do both what *you* want: >>> list(map(lambda x: x[0], filter(lambda x: x[1], zip([1,2,3,4], [0,0,1,1])))) [3, 4] >>> [x[0] for x in zip([1,2,3,4], [0,0,1,1]) if x[1]] [3, 4] # This illustrates why comprehensions were added. and an infinity of related operations, that *others* may want or can imagine, such as: >>> ''.join(c[1] for c in enumerate('every third char') if not c[0] % 3) 'ertrcr' Python 3, even more than Python 2, is designed to work with generic sequences and streams rather than just lists. We would only add a specific list function if the function is specific to lists, and filtering a sequence of items according to a sequence of values treated as boolean values is definitely not. Please drop the idea. -- Terry Jan Reedy From tjreedy at udel.edu Sun May 31 23:11:29 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 31 May 2020 23:11:29 -0400 Subject: Spotify Playlist In-Reply-To: References: <6ef738dc-c0fc-49d0-8545-c3fe4f3ec5d6@googlegroups.com> Message-ID: On 5/31/2020 7:10 PM, Chris Angelico wrote: > On Mon, Jun 1, 2020 at 8:34 AM wrote: >> This means that a fraudulent user can report your playlist 10000000 times a day, and there is nothing you can do against it, because if Spotify bans his fake "mail" he will fill the form with another fake email. This also means that if the reporter flag my playlist 10.000 times, I have to rewrite title, caption and upload user 10.000 times, and it is absolutely absurd. I sent hundreds of mail to the spotify team, they told me they are working to fix it, but currently there is no way to stop this (THIS IS CRAZY!) >> > > Yes. That is crazy. Spotify needs to fix that. However, in the meantime... > >> So my question is: is there a way to create a code with Python, that auto rewrite the title of a playlist each time Python sees the title has disappeared? >> >> For example: >> The reporter reports my playlist --> Title, Description and Image are gone (until I don't rewrite them again) >> >> Python notices that the title is gone and automatically rewrite the title and caption >> >> Do you think this is possible? Python has tools to both make html requests and extract and decode json responses. (And to parse standard timestamps.) > Hmm. Leaving aside the automation part, I think it's going to be > possible. You'd need to have a file somewhere with a list of your > playlists and their Spotify IDs, and the desired titles and captions, > and then a program that uses the Spotify API to reapply those details: > https://developer.spotify.com/documentation/web-api/reference/playlists/change-playlist-details/ > > And for the cover image: > https://developer.spotify.com/documentation/web-api/reference/playlists/upload-custom-playlist-cover/ > > 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. There is also a mechanism to ask whether locally cached information has changed by sending a cache tag, but I could not tell if that would apply to your situation. > But that's a matter of striking a balance between how much you use the > API and how quickly you notice a problem. Initially, just having > something that you manually run would be fairly straight-forward, and > should still be of value. > >> I am willing to pay for someone making this code for me, because these fake reports are becoming more and more frequent, and as a music blogger, Spotify Playlists are a part of my income. I can't stay 24/7 at home rewriting the titles of my falsely reported playlist (with no reason) >> > > Can't blame you! > > I won't take on the job myself, but I fully support the notion :) To > whoever ends up picking this up, it'll be a pretty straight-forward > job of calling on an HTTP API. Let us hope that you can find a Python Web (REST) programmer who uses Spotify, and perhaps angered by the current abuse. -- Terry Jan Reedy