Re: Style qeustion: Multiple return values
On Tue, Apr 13, 2021 at 4:26 PM dn via Python-list wrote: > > On 12/04/2021 22.32, Chris Angelico wrote: > > On Mon, Apr 12, 2021 at 8:20 PM dn via Python-list > > wrote: > >> > >> On 12/04/2021 20.29, Steve Keller wrote: > >>> Just a short style question: When returning multiple return values, do > >>> you use parenthesis? > >> > >> Thus, the answer to your question is a matter of style, and thus the > >> understanding of those who might read the code. > >> > > > > Yes, just like the subject line says :) > > > It's cheeky day at your place is it? Isn't it always? > Time for your English lesson: with correct vocal-emphasis, the first > part of the statement reads as an affirmation or agreement with the OP: > > ...the answer to your question *is* a matter of style... > > Perhaps I should have written in English-English prose? > > ...the answer to your question *is indeed* a matter of style... > Yes, but this followed a logical argument as if to prove the point, when the point was already assumed by the question :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Style qeustion: Multiple return values
On 12/04/2021 22.32, Chris Angelico wrote: > On Mon, Apr 12, 2021 at 8:20 PM dn via Python-list > wrote: >> >> On 12/04/2021 20.29, Steve Keller wrote: >>> Just a short style question: When returning multiple return values, do >>> you use parenthesis? >> >> Thus, the answer to your question is a matter of style, and thus the >> understanding of those who might read the code. >> > > Yes, just like the subject line says :) It's cheeky day at your place is it? Time for your English lesson: with correct vocal-emphasis, the first part of the statement reads as an affirmation or agreement with the OP: ...the answer to your question *is* a matter of style... Perhaps I should have written in English-English prose? ...the answer to your question *is indeed* a matter of style... To follow-through, the second clause offers an idea of how the OP might like to proceed in settling-on his/her own style... > My personal preference: If the purpose is simply to return two values > (which will almost always be unpacked immediately), I would omit the > parens. +1 In response to A.N.Other who countered this view, my aged-eyes agree that a,b = foo() ie without space, is asking for trouble. It's far too easily (mis-)read as: ab = foo() which is why such single-character horizontal-spacing is as helpful to us silver-surfers as Python's block indentation idiom! Thus: a, b = foo() ie with space. Artists and designers refer to such as "the value of negative space"! To this end, in *my style* (ie the one, true, and only-acceptable way to write Python#) spaces are used* to assist the eye to separate ("parse") the components of the code-line - and conversely, a lack of spaces to indicate a 'tight linkage' within looser lists/streams of elements. For functions, adding a space after the opening and before the closing parentheses helps identify the beginning and end of the list of arguments or parameters, eg def my_function( fred, barney, wilma, betty ): NB putting a space before the left-parenthesis creates a disconnection: def my_function ( fred ### or even my_function (fred, ... To my taste (which may all be in my mouth), the spaces after each comma (and "betty" may also be followed by an optional/notional comma) help to make it clear that there are four parameters. However, it may seem confusing to then offer: def my_function( fred=None, barney=None, etc ): That said "fred=None" is a single unit, and clearly separated from "barney", whereas: def my_function( fred = None, barney = None, etc ): does not seem to help the eye associate the two?four parameters with their default values - indeed to be able to reliably count that there are two?four parameters within the function signature! However... adding typing to the mix does give pause for thought. Now, each parameter is a veritable list of object-name, colon, type (which may itself be multi-part), equals, default-value. Phew! The solution (again, to my taste) is to define each parameter on its own/a separate line - using the parentheses to both group the parameter-list and to continue the statement in multi-line form. YMMV! - also, your eyes may be better than mine! (in which case) My eyes have probably seen a lot more than yours - and if you'd seen some of the code-messes I've seen, your eyes would be clouding-over too! * even if some, including our linter over-lords, seem to feel they are "wrong"! # if you believe this, you'll believe anything... -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing text strings
On 12Apr2021 19:11, Rich Shepard wrote: >On Tue, 13 Apr 2021, Cameron Simpson wrote: >>Alternatively, and now that I think about it, more simply: _if_ the >>package files can be sorted by version, then all you need to do is read a >>sorted listing and note that latest fil for a particular package. If you >>need another one, it should be newer and you can remove the "known" >>package file, and update your record that to the new one. > >The problem is not that simple. Sometimes the package maintainer upgrades >the package for the same version number so there could be abc-1.0_1_SBo.tgz >and abc-1.0_2_SBo.tgz. The more involved route will be taken. If that _1, _2 thing is like RedHat's -1, -2 suffixes for later releases of the same source package version, you could just include that in the version string. Looks like it counts up. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing text strings
On Tue, 13 Apr 2021, Cameron Simpson wrote: I do not know if there are preexisting modules/tools for this, but I recommend looking at slackware's package management tool - they usually have some kind of 'clean" operation to purge "old" package install files. Sometimes that purges all the install files, not just the obsolete ones, so take care. Cameron, slackpkg clean removes all non-core distribution files. That's how I FUBAR'd my system a couple of months ago. If you're writing a script, what you want to do is read the names and extract the version information from them, and also the "package name" - the bit which identifies the package and does not change with an upgrade. Yes, that's the approach I would take. I would then make a dict mapping package names to a list of versions and/or the full "...tgz" names above. (Actually, use a defaultdict(list), it will avoid a lot of tedious mucking about.) Okay. That didn't occur to me. Alternatively, and now that I think about it, more simply: _if_ the package files can be sorted by version, then all you need to do is read a sorted listing and note that latest fil for a particular package. If you need another one, it should be newer and you can remove the "known" package file, and update your record that to the new one. The problem is not that simple. Sometimes the package maintainer upgrades the package for the same version number so there could be abc-1.0_1_SBo.tgz and abc-1.0_2_SBo.tgz. The more involved route will be taken. Thanks! Rich -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing text strings
On Tue, Apr 13, 2021 at 9:54 AM Cameron Simpson wrote: > Note that this depends on sorting by version. A lexical sort (eg > "ls|sort") will look good intil a package version crosses a boundary > like this: > > 1.9.1 > 1.10.0 > > A lexical sort will put those the other way around because "9" > "1". > Wrongness will ensue. > GNU sort has a -V option to sort by version numbers. I don't know how well that'd handle other tags though. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing text strings
On 12Apr2021 16:11, Rich Shepard wrote: >I'm running Slackware64-14.2 and keep a list of installed packages. When a >package is upgraded I want to remove the earlier version, and I've not >before written a script like this. Could there be a module or tool that >already exists to do this? If not, which string function would be best >suited to the task? > >Here's an example: >atftp-0.7.2-x86_64-2_SBo.tgz >atftp-0.7.4-x86_64-1_SBo.tgz > >and there are others like this. I want the python3 script to remove the >first one. Tools like like 'find' or 'sort -u' won't work because while the >file name is the same the version or build numbers differ. I do not know if there are preexisting modules/tools for this, but I recommend looking at slackware's package management tool - they usually have some kind of 'clean" operation to purge "old" package install files. Sometimes that purges all the install files, not just the obsolete ones, so take care. If you're writing a script, what you want to do is read the names and extract the version information from them, and also the "package name" - the bit which identifies the package and does not change with an upgrade. I would then make a dict mapping package names to a list of versions and/or the full "...tgz" names above. (Actually, use a defaultdict(list), it will avoid a lot of tedious mucking about.) Alternatively, and now that I think about it, more simply: _if_ the package files can be sorted by version, then all you need to do is read a sorted listing and note that latest fil for a particular package. If you need another one, it should be newer and you can remove the "known" package file, and update your record that to the new one. Note that this depends on sorting by version. A lexical sort (eg "ls|sort") will look good intil a package version crosses a boundary like this: 1.9.1 1.10.0 A lexical sort will put those the other way around because "9" > "1". Wrongness will ensue. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: Error 2503
On 13Apr2021 01:15, Crt Gorican wrote: >Dear Python team, > >I am writing to you because I am desperate. I've tried everything I >could find on the internet before writing to you. >I've started developing a python script in my IDE and the python was >simply not working for me. >I've tried it in cmd and there was this message "The system cannot >execute the specified program.". >I've added the python path and the problem was still not resolved so >I've decided to uninstall it and then the error 2503 occurred. >I am also sending you the pictures when I tried removing and modifying >with installer and a log file. >I am looking forward to your response. Unfortunately this is not enough information. What Operating System are you using? What IDE are you using? Did you install Python? Or was it already present on your system? This mailing list removes attachments, so we have not received your pictures. You could post them to a snapshotting web service and provide the URLs, but it would be better where possibly to paste the text from your commands and the output here in your message. You wrote: >I've tried it in cmd and there was this message "The system cannot >execute the specified program.". >I've added the python path and the problem was still not resolved so What command did you type, and at what prompt did you type it? Sometimes people type shell commands at the Python prompt and vice versa. >I've decided to uninstall it and then the error 2503 occurred. CWhat process did you do for the uninstall? If you're on Windows, I at least am not a Windows person. But others on this list are. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing text strings
On 2021-04-12 at 16:11:21 -0700, Rich Shepard wrote: > I'm running Slackware64-14.2 and keep a list of installed packages. When a > package is upgraded I want to remove the earlier version, and I've not > before written a script like this. Could there be a module or tool that > already exists to do this? If not, which string function would be best > suited to the task? > > Here's an example: > atftp-0.7.2-x86_64-2_SBo.tgz > atftp-0.7.4-x86_64-1_SBo.tgz > > and there are others like this. I want the python3 script to remove the > first one. Tools like like 'find' or 'sort -u' won't work because while the > file name is the same the version or build numbers differ. > > All suggestions welcome. The trick to this is to define "one" in the phrase "first one." What makes a package name a first one, or a second one? Is it the prefix before the first hyphen? Always? Does Slackware define all the possible bits, pieces, and permutations of package names, versions, builds, etc.? I don't know whether or how Slackware handles "compound" package names (e.g., python-flask), but at some point, you're going to have to pull apart (aka---gasp--parse), the package names to come up with the name itself and the version (and the architecture, etc.), compare the name parts to find the "duplicates," and then compare the versions (and maybe the build number) to eliminate the lesser ones. You'll also have to watch for the transitions from, say, 0.9 to 0.10, or from 1.0rc2 to 1.0, which may not sort simply. So to answer your question, a string function like split is a good start. IMO, if you think about the edge cases early, you'll have a better chance at not being bitten by them. -- https://mail.python.org/mailman/listinfo/python-list
Re: How does "__doc__ % globals()" work?
On 4/12/21 3:06 PM, Jaime wrote: > Hi all. Line 102 of https://github.com/python/peps/blob/master/pep2html.py says: > > print(__doc__ % globals(), file=out) > > I realise that globals() is a standard-library > built-in function that returns a dictionary representing the current > global symbol table, and that the result of this expression is the > value of the dictionary where the key is "__doc__" This is not correct. There are a couple ways to use %-interpolation: some_name = 'Jaime' # simple `hello, %s` % (some_name, ) # hello, Jaime # keyed `hello, %(a_name)s` % {'a_name': 'Ethan'} # hello, Ethan What you are seeing is the keyed version. So, if the module had, for example: version = 1.3 author = 'GvR' date = '2021-04-12' and the doc string was __doc__ = "version %(version)s was initially created by %(author)s" then __doc__ % globals() would substitute the `author` and `version` keys into __doc__, and printing that would yield version 1.3 was initially created by GvR Note that extra keys are ignored. -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Error 2503
Dear Python team, I am writing to you because I am desperate. I've tried everything I could find on the internet before writing to you. I've started developing a python script in my IDE and the python was simply not working for me. I've tried it in cmd and there was this message "The system cannot execute the specified program.". I've added the python path and the problem was still not resolved so I've decided to uninstall it and then the error 2503 occurred. I am also sending you the pictures when I tried removing and modifying with installer and a log file. I am looking forward to your response. Yours faithfully, Črt G. -- https://mail.python.org/mailman/listinfo/python-list
Comparing text strings
I'm running Slackware64-14.2 and keep a list of installed packages. When a package is upgraded I want to remove the earlier version, and I've not before written a script like this. Could there be a module or tool that already exists to do this? If not, which string function would be best suited to the task? Here's an example: atftp-0.7.2-x86_64-2_SBo.tgz atftp-0.7.4-x86_64-1_SBo.tgz and there are others like this. I want the python3 script to remove the first one. Tools like like 'find' or 'sort -u' won't work because while the file name is the same the version or build numbers differ. All suggestions welcome. Rich -- https://mail.python.org/mailman/listinfo/python-list
Re: How does "__doc__ % globals()" work?
On Tue, Apr 13, 2021 at 8:57 AM Jaime wrote: > > Hi all. Line 102 of https://github.com/python/peps/blob/master/pep2html.py > says: > > print(__doc__ % globals(), file=out) > > and I've just spent all day trying to understand "__doc__ % > globals()". The docstring for any function, class, or module, is available under the name __doc__. It's a string, so what you're seeing is simply an example of string formatting/interpolation, with the docstring containing markers that get populated by globals. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: googletrans in python
On 4/12/2021 12:48 PM, Quentin Bock wrote: Can someone explain the basics of googletrans in python? You most likely want to install https://pypi.org/project/googletrans/ -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
How does "__doc__ % globals()" work?
Hi all. Line 102 of https://github.com/python/peps/blob/master/pep2html.py says: print(__doc__ % globals(), file=out) and I've just spent all day trying to understand "__doc__ % globals()". Sure, I realise that globals() is a standard-library built-in functions that returns a dictionary representing the current global symbol table, and that the result of this expression is the value of the dictionary where the key is "__doc__", but I can't understand how this works. I've searched through dictionary tutorials to see whether they mention accessing dictionary values using a % (percent) operator, and they don't. I've searched through printf-string formatting tutorials, and they all say that I need a %-sign to start, and then some parentheses, so it can't be that either. Can someone please put me out of my misery - what, exactly, is the percent (%) sign doing in the expression "__doc__ % globals()"? Thank you! -- https://mail.python.org/mailman/listinfo/python-list
Re: googletrans in python
Am Mon, Apr 12, 2021 at 12:48:23PM -0400 schrieb Quentin Bock: > Can someone explain the basics of googletrans in python? > I want to make a program that translates stories into English, but I'm not > sure how to get a translation printed. Also, is this needed to be done in > an HTML file inside python? > If so can someone provide basic code for a translation and how that should > be written and work? You might want to post the entire homework assignment verbatim. That way people might better understand which part of it to help you with in what way. As to your description of what you want to achieve -- what did you already try ? Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B -- https://mail.python.org/mailman/listinfo/python-list
Re: Style qeustion: Multiple return values
On 12/04/2021 09:29, Steve Keller wrote: Just a short style question: When returning multiple return values, do you use parenthesis? E.g. would you write def foo(): return 1, 2 a, b = foo() or do you prefer def foo(): return (1, 2) (a, b) = foo() Steve My personal view: It's a matter of style; do whatever looks best to you. Looking at my own code I'm not consistent in my choice. That said: return item, cost # If I think of these as two distinct values I'd be inclined to omit the parentheses. return (x,y) # If I'm returning a point which I think of as a single entity, I'd probably put them in, # especially, for consistency, if the rest of my code contains lots of `(x,y)`s, `(u,v)`s etc. return (long-expression1, long-expression2) # It might be hard to spot the comma at first glance so the parentheses might help to recognise a tuple. Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list
Immutable view classes - inherit from dict or from Mapping?
Hi, I have written some classes that represent immutable views on collections (see "immutable-views" package on Pypi). Currently, these view classes inherit from the abstract collection classes such as Mapping, Sequence, Set. However, they implement the read-only methods of dict, list and set, which provides some more methods compared to the abstract collection classes. For example, class "dict" provides copy() or __reversed__() and the newer OR-operator methods all of which are not defined on the abstract class "Mapping". Note that the view classes do not provide any of the modifying methods of "dict" and "list", because after all the views are supposed to be immutable. My question is, should the dict view class inherit from Mapping or from dict, and likewise, should the list view class inherit from Sequence or from list? Thanks Andy -- https://mail.python.org/mailman/listinfo/python-list
ANN: Wing Python IDE 7.2.9 has been released
Wing 7.2.9 adds remote development for 64-bit Raspberry Pi, improves auto-closing of quotes, optimizes change tracking when large numbers of project files change at once, improves debugger data display for some value types, and makes a number of other usability improvements. Details: https://wingware.com/news/2021-04-12 Downloads: https://wingware.com/downloads == About Wing == Wing is a light-weight but full-featured Python IDE designed specifically for Python, with powerful editing, code inspection, testing, and debugging capabilities. Wing's deep code analysis provides auto-completion, auto-editing, and refactoring that speed up development. Its top notch debugger works with any Python code, locally or on a remote host. Wing also supports test-driven development, version control, UI color and layout customization, and includes extensive documentation and support. Wing is available in three product levels: Wing Pro is the full-featured Python IDE for professional developers, Wing Personal is a free Python IDE for students and hobbyists (omits some features), and Wing 101 is a very simplified free Python IDE for beginners (omits many features). Learn more at https://wingware.com/ -- https://mail.python.org/mailman/listinfo/python-list
Re: googletrans in python
Does this help? https://zetcode.com/python/googletrans/ It was the first google search hit on 'googletrans python example'. On Mon, Apr 12, 2021 at 9:49 AM Quentin Bock wrote: > Can someone explain the basics of googletrans in python? > I want to make a program that translates stories into English, but I'm not > sure how to get a translation printed. Also, is this needed to be done in > an HTML file inside python? > If so can someone provide basic code for a translation and how that should > be written and work? > Thank you > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Style qeustion: Multiple return values
On 2021-04-12 at 09:54:13 -0700, Dan Stromberg wrote: > On Mon, Apr 12, 2021 at 1:30 AM Steve Keller wrote: > > > Just a short style question: When returning multiple return values, do > > you use parenthesis? > > > > E.g. would you write > > > > def foo(): > > return 1, 2 > > > > a, b = foo() > > > > or do you prefer > > > > def foo(): > > return (1, 2) > > > > (a, b) = foo() > > > > I prefer the parens; it's too easy to miss a comma when reading. The > parentheses make it more clear that you're looking at a tuple. If I were to write it like this: a,b = foo() rather than like this: a, b = foo() then I might agree that the comma might be mistakable for a dot or even "disappear" altogether. To the compiler, the extraneous space doesn't matter, but to a human reader, it makes a huge difference. That said, consider this function: def f(*args): whatever() Do you prefer f(a, b) or f((a, b))? Okay, so it's a trick question, but that's how I think about *returning* multiple values, too: "a, b" is two values, but "(a, b)" is one value that happens to be a tuple. Lastly, with names like foo, a, and b, we might be misfocused. Does any of this change with names like coordinate, account_number, or distance? Do meaningful names help, or do they merely distract from the commas and the parentheses? (x_coord, y_coord) = locate_target(parameters) likely_name, probability = best_match(parameters) -- https://mail.python.org/mailman/listinfo/python-list
Re: Style qeustion: Multiple return values
On Mon, Apr 12, 2021 at 1:30 AM Steve Keller wrote: > Just a short style question: When returning multiple return values, do > you use parenthesis? > > E.g. would you write > > def foo(): > return 1, 2 > > a, b = foo() > > or do you prefer > > def foo(): > return (1, 2) > > (a, b) = foo() > I prefer the parens; it's too easy to miss a comma when reading. The parentheses make it more clear that you're looking at a tuple. pycodestyle and pylint don't appear to care one way or the other. -- https://mail.python.org/mailman/listinfo/python-list
googletrans in python
Can someone explain the basics of googletrans in python? I want to make a program that translates stories into English, but I'm not sure how to get a translation printed. Also, is this needed to be done in an HTML file inside python? If so can someone provide basic code for a translation and how that should be written and work? Thank you -- https://mail.python.org/mailman/listinfo/python-list
Re: Style qeustion: Multiple return values
On 4/12/2021 4:29 AM, Steve Keller wrote: Just a short style question: When returning multiple return values, do you use parenthesis? E.g. would you write def foo(): return 1, 2 a, b = foo() or do you prefer def foo(): return (1, 2) (a, b) = foo() No. Parentheses are for grouping (and separation from surrounding code). () and (1,) (can be though of as) group(ing) the a zero-width space and one-comma pair respectively and separate them from the rest of the code. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Ann: New Python curses book
On 12/04/2021 00:53, Daniel Nelson wrote: >> (It should be available in most other Amazon stores too) > > This looks handy, I'd love to buy a copy but I don't do business with > Amazon if I can avoid it. Any chance this will be available from other > locations? I tried to publish it on several open-source web sites but none of them responded to me so I went with Amazon as the commercial site most people turn to first and with the widest reach. Also the Amazon publishing tools are very easy to use. However, one of their conditions for low cost books is exclusivity, so no it won't appear anywhere else unless I increase the price significantly which I don't want to do. What I might do is host the original translation of the C document as a PDF on my own web site. But that's not likely to show up in many searches! If I get round to that I'll announce it here. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list
Re: Style qeustion: Multiple return values
On Mon, Apr 12, 2021 at 8:20 PM dn via Python-list wrote: > > On 12/04/2021 20.29, Steve Keller wrote: > > Just a short style question: When returning multiple return values, do > > you use parenthesis? > > Thus, the answer to your question is a matter of style, and thus the > understanding of those who might read the code. > Yes, just like the subject line says :) My personal preference: If the purpose is simply to return two values (which will almost always be unpacked immediately), I would omit the parens. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Style qeustion: Multiple return values
On 12/04/2021 20.29, Steve Keller wrote: > Just a short style question: When returning multiple return values, do > you use parenthesis? > > E.g. would you write > > def foo(): > return 1, 2 > > a, b = foo() > > or do you prefer > > def foo(): > return (1, 2) > > (a, b) = foo() Steve The data-structure being returned is a tuple. The tuple is defined by the comma-separator - not the parentheses. Of course, the way you use them (first example) involves "unpacking" after the tuple 'crosses' the equals/assignment. Thus, the answer to your question is a matter of style, and thus the understanding of those who might read the code. FWIW: I leave them out because it is easier on my eyes whilst scanning the line of code. -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list
Style qeustion: Multiple return values
Just a short style question: When returning multiple return values, do you use parenthesis? E.g. would you write def foo(): return 1, 2 a, b = foo() or do you prefer def foo(): return (1, 2) (a, b) = foo() Steve -- https://mail.python.org/mailman/listinfo/python-list