From brgrt2 at gmail.com Sun Jul 1 00:23:20 2018 From: brgrt2 at gmail.com (T Berger) Date: Sat, 30 Jun 2018 21:23:20 -0700 (PDT) Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <20180629225955.GA75408@cskk.homeip.net> Message-ID: <0a23fa7f-d50f-499c-a631-ba722868742d@googlegroups.com> On Saturday, June 30, 2018 at 6:39:36 PM UTC-4, MRAB wrote: > On 2018-06-30 23:01, T Berger wrote: > > On Friday, June 29, 2018 at 7:00:15 PM UTC-4, Cameron Simpson wrote: > > > >> The key point here from Jim is "simultaneously". Are you properly shutting down > >> the Flask instance in IDLE before running from Terminal, and vice versa? > > > > Cameron, I try every option to quit either program, but they don't work. Or I should say, they mostly don't work. Once in a while they do. The one option which works (which is not a feasible option) is rebooting my Mac (actually that might not work either. I think I got the error message again this morning when I rebooted). > > > >> Otherwise both will try to use the same local port and There Can Be Only One. > >> > >> Do you need to run from both environments at the same time? I'd have thought > >> not, which also leads me to: why are you flicking from IDLE to Terminal? I > >> would have imagined using one or the other normally, not both. It isn't wrong > >> to use both, just surprising. > > > > I'm working from a Python manual. I created the webapp in IDLE, and test it in Terminal, per the instructions in the manual. I use IDLE to edit my program, and then test it in terminal. When I go from one to the other, I get the error message. IDLE has a keyboard shortcut for quitting the shell?Cntl + C?but it doesn't work. Neither does restarting the shell. Neither does entering the kill command line, not in IDLE or terminal. > > Ctrl+C is the shortcut for interrupting a Python program running on > IDLE's or Windows command line. In IDLE's editor, Ctrl+C is the shortcut > for copying text the clipboard. > > The keyboard shortcut for quitting IDLE completely is Ctrl+Q. > > > > > Do you have any other suggestions? I'm going to email the writer. He doesn't mention how to deal with problems that might arise from working with two programs at the same time. Maybe Cntl+C should do it, but in my case it doesn't. > > From steve+comp.lang.python at pearwood.info Sun Jul 1 01:19:59 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 1 Jul 2018 05:19:59 +0000 (UTC) Subject: error in os.chdir References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sun, 01 Jul 2018 02:22:41 +0000, eryk sun wrote: > I use the native API a lot, so for me registry and file paths are just > paths. It's only the Windows API that separates the two and only the > Windows API that allows forward slash as a path separator in file paths. Not being a Windows user, I don't actually understand how this works. I gather that there's a low-level "native API" (DOS?) used by the Windows OS, and a higher level "Windows API" used by, er, another part of the API. But I'm not sure how that interacts with Python. The way I see it, when we say "always use forward slashes for file paths", we're talking about Python level file commands like open(), os.path.exists, etc. If you're using Python to directly call Windows external programs, say "os.system('dir')", then of course you have to follow the Windows rules. (The same applies to Unix/Linux systems too, of course.) But while you're using Python to manipulate files, you should use Python rules, and that is "always use forward slashes". Is that reasonable? Under what circumstances would a user calling open(pathname) in Python need to care about backslashes? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jul 1 04:50:22 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 1 Jul 2018 08:50:22 +0000 (UTC) Subject: error in os.chdir References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sun, 01 Jul 2018 03:18:23 +0000, eryk sun wrote: > On Sun, Jul 1, 2018 at 1:44 AM, Steven D'Aprano > wrote: >> On Sat, 30 Jun 2018 23:36:40 +0000, eryk sun wrote: >> >>> Only use forward slashes for legacy DOS paths passed to Windows API >>> functions. Do not use forward slashes for paths in command line >>> arguments, \\?\ prefixed paths, or registry paths. >> >> I don't see why this is relevant, or at least not the "command line >> arguments" and "registry paths" parts. > > Command-line arguments are relevant to executing a child process, e.g. > via subprocess.Popen. Ah, yes they are. But using subprocess is a little more of an advanced use than regular file handling. But your point is taken. >> I guess that if the user is using a path beginning with \\?\ they may >> or may not need to use backslashes, but I have no way of testing it, >> and I would expect that Python will correctly replace //?/ with >> backslashes the same as it does for any other file system path. > > The Windows API handles this, but not for a path that begins with \\?\. But what about the *Python* API? The Python open() function, and all the high-level os.* and os.path.* functions which take paths as strings are supposed to automatically convert forward slashes to backslashes. Aren't they? > The intent of this prefix is to bypass DOS-path normalization -- > allowing paths with length up to 32K characters that can use otherwise > reserved DOS-device names or names ending in spaces or dots. > >> (Besides, Python doesn't have an API for interacting directly with the >> registry.) > > The standard library has winreg -- or _winreg in 2.x. Oh, I live and learn. > Bear in mind that forward slash is just a name character in NT. Interesting... That's rather like on HFS Plus, where / is an ordinary character allowed in file names (although Mac OS goes to extraordinary effort to ensure that tools that expect / as a path separator see it, and those which expect : as the path separator see it instead). > We only need to clearly state that the > Windows API allows using forward slash as the path separator in file > paths that do not begin with the \\?\ prefix. I prefer to also add a > warning about command-line arguments, since it isn't an improbable or > inconsequential problem Fair enough. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jul 1 04:51:10 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 1 Jul 2018 08:51:10 +0000 (UTC) Subject: File names with slashes [was Re: error in os.chdir] References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sun, 01 Jul 2018 03:18:23 +0000, eryk sun wrote: > Bear in mind that forward slash is just a name character in NT. So, using Python, how could you open, write to, and then read from, a file with a slash in its name? Say, something like: spam/eggs in your home directory. (Is that still C:\\My Documents by default?) And how would that file be displayed in the Windows GUI file explorer? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From hjp-python at hjp.at Sun Jul 1 05:07:45 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 1 Jul 2018 11:07:45 +0200 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <20180630181951.vwcgixxvu67a2ksb@hjp.at> <20180630214941.j7tc4ar6xzdyvp55@hjp.at> Message-ID: <20180701090745.m33whdx6brs2naur@hjp.at> On 2018-07-01 01:52:12 +0000, Steven D'Aprano wrote: > On Sat, 30 Jun 2018 23:49:41 +0200, Peter J. Holzer wrote: > > The old adage that "security is binary" is utter balderdash. > > I think that "old adage" is one of those ones that only people denying it > actually use. > > I've never seen anyone say "security is binary" That was almost a dogma in some (mostly German) usenet groups 15 to 20 years ago. Some people apparently still believe it - it hasn't been that long (maybe a year or so) since I've last had a discussion about this. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From hjp-python at hjp.at Sun Jul 1 05:42:09 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 1 Jul 2018 11:42:09 +0200 Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: <20180701094209.6k6cyk62binnu65g@hjp.at> On 2018-07-01 08:50:22 +0000, Steven D'Aprano wrote: > On Sun, 01 Jul 2018 03:18:23 +0000, eryk sun wrote: > > On Sun, Jul 1, 2018 at 1:44 AM, Steven D'Aprano > > wrote: > >> I guess that if the user is using a path beginning with \\?\ they may > >> or may not need to use backslashes, but I have no way of testing it, > >> and I would expect that Python will correctly replace //?/ with > >> backslashes the same as it does for any other file system path. > > > > The Windows API handles this, but not for a path that begins with \\?\. > > But what about the *Python* API? The Python open() function, and all the > high-level os.* and os.path.* functions which take paths as strings are > supposed to automatically convert forward slashes to backslashes. Aren't > they? Are they? I don't see anything in the docs that support this (but maybe my Google Fu is weak). Rather from the existence and design of os.path I conclude that the programmer is supposed to construct path names in the local convention (i.e., you should use os.path.join(dirname, filename) instead of dirname + "/" + filename, which will ensure that the correct separator is used). I think the lazy approach using just forward slashes works because *Windows* treats slashes in filenames like backslashes (most of the time), not because Python converts them. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From mal at europython.eu Sun Jul 1 08:58:09 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Sun, 1 Jul 2018 14:58:09 +0200 Subject: EuroPython 2018: Inviting European Python Conference Organizers Message-ID: <22cd8819-1ba1-5eae-368d-6c2ef28b7c2f@europython.eu> The EuroPython Society (EPS), who is organizing the EuroPython conference, last year extended it?s mission to also provide help for the Python community in Europe in general. As part of this, we would like to get to know, and help create closer ties between organizers of other European Python events. Organizers? Lunch ----------------- We would like to invite representatives of all European Python conference to EuroPython 2018 to join us for an organizers? lunch. We?re planing the lunch for Friday, July 27, in the organizer?s room (Soutra Suite). Our aim is to get to know each other, exchange experience in organizing events and to find out how we, as EPS, can most effectively help other conferences going forward. Free Tickets ------------ To support and facilitate this, we are giving out one free conference ticket per conference team, so that each team can send a representative to the organizers? lunch. If your team wants to send someone to join, please write to board at europython.eu, mentioning the conference you?re organizing and some background on your team. 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/175435613817/europython-2018-inviting-european-python Tweet: https://twitter.com/europython/status/1013403476112691201 Enjoy, -- EuroPython Society https://ep2018.europython.eu/ https://www.europython-society.org/ From mal at europython.eu Sun Jul 1 08:58:27 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Sun, 1 Jul 2018 14:58:27 +0200 Subject: EuroPython 2018: Community Discounts Message-ID: <6e9b9cef-8c4b-eb8b-db0d-001b2f021310@europython.eu> The EuroPython Society (EPS) extended its mission last year to not only run the EuroPython conference, but also provide help for the Python community in Europe in general. Let?s all meet at EuroPython ---------------------------- In addition to the Python Organizers Lunch (see previous post), which focuses on conference organizers, we are also establishing a program to support attendees of Python user groups and conferences in Europe. We?d like to invite all of you to EuroPython 2018 this year. Of course, we cannot give out free tickets to everyone, but we can at least recognize your participation in the Python community by giving out discounts for the conference. Discounts for EuroPython Tickets -------------------------------- If you are running a Python event (conference or user group) in Europe, please reach out to board at europython.eu to request a coupon code for your group, which you can then pass on to your group members or attendees. If you are not running a user group or conference, but a regular attendee of one, please contact your organizers to have them submit a request. We can only distribute codes at the user group and conference organizer level. The coupon codes are valid for conference tickets bought starting today and will give you a 10% discount on the ticket price (both regular and late bird prices). The codes are setup for user group sizes of between 30-50 members, but we are also extending this to organizers and attendees of larger conferences. If you need a code valid for larger groups, please mention this in your email. 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/175435749712/europython-2018-community-discounts Tweet: https://twitter.com/europython/status/1013405285770252288 Enjoy, -- EuroPython Society https://ep2018.europython.eu/ https://www.europython-society.org/ From sharan.basappa at gmail.com Sun Jul 1 09:05:48 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 1 Jul 2018 06:05:48 -0700 (PDT) Subject: logging module Message-ID: <0f85f6c0-20bd-4e5f-b08e-3f6813d6372a@googlegroups.com> Folks, I am trying to use logging module and somehow I cannot make it work. A simple code that I am trying is below. The commented code line 5,6 are other options I have tried but don't work #importing module import logging #Create and configure logger #logging.basicConfig(filename="D:/Projects/Initiatives/machine learning/programs/newfile.log", #logging.basicConfig(filename="newfile.log", logging.basicConfig(format='%(asctime)s %(message)s') #Creating an object logger=logging.getLogger() #Setting the threshold of logger to DEBUG logger.setLevel(logging.DEBUG) #Test messages logger.debug("Harmless debug Message") logger.info("Just an information") logger.warning("Its a Warning") logger.error("Did you try to divide by zero") logger.critical("Internet is down") PS: I am running this under Enthought Canopy The following is the output %run "D:/Projects/Initiatives/machine learning/programs/debug_4.py" From greg.ewing at canterbury.ac.nz Sun Jul 1 09:40:02 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 02 Jul 2018 01:40:02 +1200 Subject: Assignments to ps1 In-Reply-To: References: Message-ID: Stefan Ram wrote: > from sys import ps1 > ps1 = 'alpha' >>> import sys >>> sys.ps1 = "alpha" alpha -- Greg From mikhailwas at gmail.com Sun Jul 1 09:49:32 2018 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 1 Jul 2018 16:49:32 +0300 Subject: File names with slashes [was Re: error in os.chdir] Message-ID: [Steven D'Aprano] > (The same applies to Unix/Linux systems too, of course.) But while you're > using Python to manipulate files, you should use Python rules, and that > is "always use forward slashes". > > Is that reasonable? > > Under what circumstances would a user calling open(pathname) in Python > need to care about backslashes? Cough cough On Windows a path is e.g.: C:\programs\util\ So why should I use forward slashes in a Python literal? I don't remember any problem caused by using backslashes in paths in Python - are there problems? (Apart from the fact that Python dos not have true raw string literals) So what is reasonable about using forward slashes? It happens to me that I need to copy-paste real paths like 100 times a day into scripts - do you propose to convert to forward slashes each time? From eryksun at gmail.com Sun Jul 1 11:22:23 2018 From: eryksun at gmail.com (eryk sun) Date: Sun, 1 Jul 2018 15:22:23 +0000 Subject: error in os.chdir In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sun, Jul 1, 2018 at 8:50 AM, Steven D'Aprano wrote: > On Sun, 01 Jul 2018 03:18:23 +0000, eryk sun wrote: > >> The Windows API handles this, but not for a path that begins with \\?\. > > But what about the *Python* API? The Python open() function, and all the > high-level os.* and os.path.* functions which take paths as strings are > supposed to automatically convert forward slashes to backslashes. Aren't > they? Python's I/O functions don't modify file paths, except to decode bytes paths in 3.6+. os.path.normpath uses backslash in Windows, without involving the OS, as does pathlib in Python 3. os.path.abspath calls WinAPI GetFullPathName to get a canonical, fully-qualified path, including transforming reserved paths, e.g. >>> os.path.abspath('C:/Temp/conout$.txt') '\\\\.\\conout$' >>> os.path.abspath('C:/Temp/spam. . .') 'C:\\Temp\\spam' (Note that the above "conout$" example is for Windows 8 and 10. In prior versions, "conin$" and "conout$" aren't reserved in qualified-relative or absolute paths, only when passed to CreateFile as unqualified names.) The \\?\ prefix allows using otherwise reserved names such as "con" and "spam...". For versions of Windows prior to 10 or Python prior to 3.6, the \\?\ prefix is also the only way to get past the 260 character limit of legacy DOS paths to work with paths with up to 32K characters. Python 3.6+ is manifested to support long paths in Windows 10 without requiring the \\?\ prefix. This can be enabled by setting the LongPathsEnabled value in "HKLM\System\CurrentControlSet\Control\FileSystem". Maybe in a future version this registry setting will be enabled by default. >> Bear in mind that forward slash is just a name character in NT. > > Interesting... > > That's rather like on HFS Plus, where / is an ordinary character allowed > in file names (although Mac OS goes to extraordinary effort to ensure > that tools that expect / as a path separator see it, and those which > expect : as the path separator see it instead). Many characters are reserved in Windows file systems that aren't generally reserved in NT, including forward slash. What happens here is that the Object Manager hands off parsing the rest of a path as soon as it reaches an object that has a parse procedure. This allows object types such as Key and Device objects to implement custom namespaces. The Configuration Manager's (registry) Key parse procedure limits names to 256 characters and the tree depth to 512 keys. (Note that HKCU is a pseudo-handle for "\Registry\User\", so subtract 3 from the depth.) However it doesn't reserve characters, except for the native backslash path separator. IIRC it allows NUL in key names, but that would render them impossible to access in the Windows API, which uses null-terminated strings. The I/O Manager's Device parse procedure sends an IRP_MJ_CREATE I/O request packet either to the first device in the stack (including lower/upper filter drivers), or to the file-system device stack that's managing it. The I/O manager doesn't reserve additional characters or limit name length, but most file systems limit names to 255 characters (127 for UDF) and reserve backslash (path separator), slash, colon, pipe, wildcards (*?<>"), and ASCII controls. In contrast, the named pipe file system (i.e. WinAPI \\.\PIPE or native \Device\NamedPipe) is extremely lenient. Pipe names can be up to 259 characters and can include any character except NUL. This file system doesn't support directories, so pipe names can even include backslash, which is a common practice. Except for disk volumes, most devices aren't file systems or managed by one. However, sometimes they do implement a simple namespace of hard-coded names. For example, the console device "\Device\ConDrv" implements a few names such as "Connect", "Input", "Output", "Console" (con), "CurrentIn" (conin$), and "CurrentOut" (conout$). From Richard at Damon-Family.org Sun Jul 1 11:42:16 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 1 Jul 2018 08:42:16 -0700 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: <1d6413f5-2012-5aed-a0e4-107b18fbaa72@Damon-Family.org> On 7/1/18 6:49 AM, Mikhail V wrote: > [Steven D'Aprano] > >> (The same applies to Unix/Linux systems too, of course.) But while you're >> using Python to manipulate files, you should use Python rules, and that >> is "always use forward slashes". >> >> Is that reasonable? >> >> Under what circumstances would a user calling open(pathname) in Python >> need to care about backslashes? > Cough cough > > On Windows a path is e.g.: > C:\programs\util\ > > So why should I use forward slashes in a Python literal? > I don't remember any problem caused by using backslashes in paths in Python - > are there problems? > (Apart from the fact that Python dos not have true raw string literals) > > So what is reasonable about using forward slashes? > It happens to me that I need to copy-paste real paths like 100 times > a day into scripts - do you propose to convert to forward slashes each time? The one major issue with backslashes is that they are a special character in string literals, so you either need to use raw literals a remember the few cases they still act as special characters, or remember to convert them to double back slashes, at a minimum for all the characters that they are special for (easier to double them all). I think it was originally an error to make the backslash followed by a character not defined as special with a backslash as keeping the backslash as a literal as it causes a number of these issues. Yes, it allows you to not need to double it in many cases but that just sets you up for the mistakes that started the thread. It is probably too late to change that behavior now though. -- Richard Damon From arj.python at gmail.com Sun Jul 1 12:00:54 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 1 Jul 2018 20:00:54 +0400 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: one common scenario is C:\Users\.... where \U is taken as a unicode litteral Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > > From eryksun at gmail.com Sun Jul 1 12:30:05 2018 From: eryksun at gmail.com (eryk sun) Date: Sun, 1 Jul 2018 16:30:05 +0000 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sun, Jul 1, 2018 at 8:51 AM, Steven D'Aprano wrote: > On Sun, 01 Jul 2018 03:18:23 +0000, eryk sun wrote: > >> Bear in mind that forward slash is just a name character in NT. > > So, using Python, how could you open, write to, and then read from, a > file with a slash in its name? Say, something like: By that I meant that NT's base object namespace treats forward slash as a name character, i.e. object names in the base NT namespace can include slash. This includes Device objects in the "\Device" directory and "DOS" device symbolic links to them in "\Global??" or a subdirectory of "\Sessions\0\DosDevices", as well as other named objects (Section, Job, Event, Semaphore, etc). The Windows API stores most of the latter in a single per-session directory that's named "\BaseNamedOjects" for session 0 (system services) and "\Sessions\\BaseNamedObjects" for interactive sessions. The base registry Key object is named "\Registry". Its parse procedure (for creating and opening key paths) only reserves backslash, which is the same as the object namespace itself. > spam/eggs You can create a named pipe with that name in the named-pipe file system. But regular file systems that I've used in Windows reserve forward slash, even though they don't use it for anything. They'll just fail the create/open with STATUS_OBJECT_NAME_INVALID. The way to observe this is to use forward slash in a \\?\ prefixed path. Note that the prefix must be \\?\, with backslash only. //?/ is basically the same as //./. As far as file paths go, "spam/eggs" could be set as a device name, which from Windows would only be accessible with a \\?\ prefixed path. For example: DefineDosDevice(DDD_RAW_TARGET_PATH, 'spam/eggs', '\\Device\\HarddiskVolume2\\Temp') f = open(r'\\?\spam/eggs\test.txt', 'w') h = msvcrt.get_osfhandle(f.fileno()) >>> GetFinalPathNameByHandle(h, VOLUME_NAME_DOS) '\\\\?\\C:\\Temp\\test.txt' >>> GetFinalPathNameByHandle(h, VOLUME_NAME_NT) '\\Device\\HarddiskVolume2\\Temp\\test.txt' > in your home directory. (Is that still C:\\My Documents by default?) No, the user profile directory is "C:\Users\", i.e. the %UserProfile% environment variable. In some cases a user may have a separate home directory configured, which is set in %HOMEDRIVE%%HOMEPATH%. Commonly no home directory is set, in which case %HOMEDRIVE%%HOMEPATH% is just the fixed %UserProfile% path. > And how would that file be displayed in the Windows GUI file explorer? I suppose if a file system allowed forward slash in names that Explorer would just display it. When I get the time, I'll attach a debugger to explorer.exe and hack a forward slash into one of the names in a directory listing, i.e. a result from WinAPI FindFirstFile (or native NtQueryDirectoryFile). From eryksun at gmail.com Sun Jul 1 12:36:25 2018 From: eryksun at gmail.com (eryk sun) Date: Sun, 1 Jul 2018 16:36:25 +0000 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: On Sun, Jul 1, 2018 at 4:00 PM, Abdur-Rahmaan Janhangeer wrote: > one common scenario is > > C:\Users\.... > > where \U is taken as a unicode litteral This one is especially annoying in Python 2, since it makes raw unicode strings useless for common path literals. For example: >>> ur'C:\Users' File "", line 1 SyntaxError: (unicode error) 'rawunicodeescape' codec can't decode bytes in position 2-3: truncated \uXXXX >>> ur'C:\users' File "", line 1 SyntaxError: (unicode error) 'rawunicodeescape' codec can't decode bytes in position 2-3: truncated \uXXXX Python 2 raw strings are half-baked. From arj.python at gmail.com Sun Jul 1 13:06:13 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 1 Jul 2018 21:06:13 +0400 Subject: PEP 526 - var annotations and the spirit of python Message-ID: was viewing pep526, so, finally, python cannot do without hinting the type as other languages? will python finally move to int x = 3 where int is a pre annotation? i am not arguing it's usefulness but rather, does it fit with python? Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ From python at mrabarnett.plus.com Sun Jul 1 13:17:20 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 1 Jul 2018 18:17:20 +0100 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 2018-07-01 18:06, Abdur-Rahmaan Janhangeer wrote: > was viewing pep526, so, finally, python cannot do without hinting the type > as other languages? > will python finally move to > int x = 3 where int is a pre annotation? > > i am not arguing it's usefulness but rather, does it fit with python? > PEP 526 says that the annotation would be: x: int = 3 It also says """It should also be emphasized that Python will remain a dynamically typed language, and the authors have no desire to ever make type hints mandatory, even by convention."" From ian.g.kelly at gmail.com Sun Jul 1 13:21:09 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 1 Jul 2018 11:21:09 -0600 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On Sun, Jul 1, 2018 at 11:09 AM Abdur-Rahmaan Janhangeer wrote: > > was viewing pep526, so, finally, python cannot do without hinting the type > as other languages? Python certainly can do without it. That's why it's an optional feature with no runtime effect beyond making the annotations inspectable and causing unassigned function variables to be considered locals. From arj.python at gmail.com Sun Jul 1 13:55:21 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 1 Jul 2018 21:55:21 +0400 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: i meant that x: int = 3 is dangerously close to int x = 3, in the long run, you'll come across people who come from other languages wanting to java/c style their code and end up sprinkling a lot of these, it'll be a sad day for me return type in function definition also managed to return via -> Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius PEP 526 says that the annotation would be: > > x: int = 3 > > It also says """It should also be emphasized that Python will remain a > dynamically typed language, and the authors have no desire to ever make > type hints mandatory, even by convention."" > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sun Jul 1 14:15:04 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 2 Jul 2018 04:15:04 +1000 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On Mon, Jul 2, 2018 at 3:55 AM, Abdur-Rahmaan Janhangeer wrote: > i meant that x: int = 3 is dangerously close to int x = 3, > > in the long run, you'll come across people who come from other languages > wanting to java/c style their code and end up sprinkling a lot of these, > it'll be a sad day for me People already write code like this: for i in range(len(stuff)): #{ frobnicate(stuff[i]) #} I'm sure people will misuse type hints too. What of it? Does it destroy Python when people use it inefficiently? ChrisA From arj.python at gmail.com Sun Jul 1 14:48:00 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 1 Jul 2018 22:48:00 +0400 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: not python, the spirit of python, i guess i must have been around when it was first discussed, now it's too late to discuss why it was introduced in the first place ... Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ I'm sure people will misuse type hints too. What of it? Does it > destroy Python when people use it inefficiently? > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From marko at pacujo.net Sun Jul 1 15:09:41 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 01 Jul 2018 22:09:41 +0300 Subject: EXTERNAL: OSError: [Errno 48] Address already in use References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <877emif9d1.fsf@elektro.pacujo.net> Message-ID: <87h8liepsa.fsf@elektro.pacujo.net> Gregory Ewing : > Dan Stromberg wrote: >> On Thu, Jun 28, 2018 at 10:30 PM, Marko Rauhamaa wrote: >> >>>Well, the same security issue can be demonstrated without >>>SO_REUSEADDR: >>> >>>The security issue can be real but is not directly related with >>>SO_REUSEADDR. >> >> Yes, it can. It just takes longer. > > I don't see how the address-reuse timeout can be a security measure, > because the process trying to take over the address can easily > circumvent it by setting SO_REUSEADDR. The address reuse timeout (TIME WAIT) is only used to deal with "Byzantine generals" loophole in the TCP protocol. Its purpose is to guarantee that both peers end up with a common understanding of the final state of the connection. Nevertheless, the later socket object cannot unilaterally take over a socket using SO_REUSEADDR. The earlier socket object must have set the same option previously. Marko From info at tundraware.com Sun Jul 1 18:22:43 2018 From: info at tundraware.com (Tim Daneliuk) Date: Sun, 1 Jul 2018 17:22:43 -0500 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 07/01/2018 12:17 PM, MRAB wrote: > On 2018-07-01 18:06, Abdur-Rahmaan Janhangeer wrote: >> was viewing pep526, so, finally, python cannot do without hinting the type >> as other languages? >> will python finally move to >> int x = 3 where int is a pre annotation? >> >> i am not arguing it's usefulness but rather, does it fit with python? >> > PEP 526 says that the annotation would be: > > x: int = 3 > > It also says """It should also be emphasized that Python will remain a dynamically typed language, and the authors have no desire to ever make type hints mandatory, even by convention."" This strikes me as syntactic noise. Python is dynamically typed and will remain so. Why clutter the language - even optionally - with stuff like this? From steve+comp.lang.python at pearwood.info Sun Jul 1 19:31:26 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 1 Jul 2018 23:31:26 +0000 (UTC) Subject: logging module References: <0f85f6c0-20bd-4e5f-b08e-3f6813d6372a@googlegroups.com> Message-ID: On Sun, 01 Jul 2018 06:05:48 -0700, Sharan Basappa wrote: > Folks, > > I am trying to use logging module and somehow I cannot make it work. > > A simple code that I am trying is below. The commented code line 5,6 are > other options I have tried but don't work > > #importing module > import logging > > #Create and configure logger > #logging.basicConfig(filename="D:/Projects/Initiatives/machine > learning/programs/newfile.log", > #logging.basicConfig(filename="newfile.log", > logging.basicConfig(format='%(asctime)s %(message)s') This is not the actual code you are using, because this gives a SyntaxError. You are missing a closing parentheses. Please don't retype your code from memory. Copy and paste the actual code. It is hard enough to work out what code does when we can see it, it is next to impossible to work out what it does when we're given *different* code and have to guess how many changes have been made. > #Creating an object > logger=logging.getLogger() > > #Setting the threshold of logger to DEBUG > logger.setLevel(logging.DEBUG) > > #Test messages > logger.debug("Harmless debug Message") > logger.info("Just an information") > logger.warning("Its a Warning") > logger.error("Did you try to divide by zero") > logger.critical("Internet is down") > > PS: I am running this under Enthought Canopy > > The following is the output > %run "D:/Projects/Initiatives/machine learning/programs/debug_4.py" Are you sure that is the OUTPUT? It looks more like the input -- the command you are running. Have you looked inside the file D:/Projects/Initiatives/machine learning/programs/newfile.log where output is going? By the way, as a total beginner to this, I don't think you need the extra complexity and discipline of using log files. Don't try catching errors and logging them. Let the errors fail. While you are learning, the BEST thing to do is to learn to read the tracebacks and fix the bug in your code, not to try to cover them up and bury the failures inside a log file. If you need informational messages, just use print. You can come back to logging when you have more experience. (I've been programming with Python for 20+ years, and I still use print for simple scripts and when learning a new library.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From countryone77 at gmail.com Sun Jul 1 19:32:59 2018 From: countryone77 at gmail.com (Bev in TX) Date: Sun, 1 Jul 2018 18:32:59 -0500 Subject: logging module In-Reply-To: <0f85f6c0-20bd-4e5f-b08e-3f6813d6372a@googlegroups.com> References: <0f85f6c0-20bd-4e5f-b08e-3f6813d6372a@googlegroups.com> Message-ID: <083F947A-0B60-475F-8C73-B566BAF41A8D@gmail.com> > On Jul 1, 2018, at 8:05 AM, Sharan Basappa wrote: > > Folks, > > I am trying to use logging module and somehow I cannot make it work. Saying that something does not work does not provide enough information for anyone to assist you. You need to provide both the exact code that did not work, what you expected and what happened, and the error message that you received, if any. Details, details and more details. > > A simple code that I am trying is below. The commented code line 5,6 are other options I have tried but don't work > > #importing module > import logging > > #Create and configure logger > #logging.basicConfig(filename="D:/Projects/Initiatives/machine learning/programs/newfile.log", > #logging.basicConfig(filename="newfile.log", > logging.basicConfig(format='%(asctime)s %(message)s') > > #Creating an object > logger=logging.getLogger() > > #Setting the threshold of logger to DEBUG > logger.setLevel(logging.DEBUG) > > #Test messages > logger.debug("Harmless debug Message") > logger.info("Just an information") > logger.warning("Its a Warning") > logger.error("Did you try to divide by zero") > logger.critical("Internet is down") > > PS: I am running this under Enthought Canopy > > The following is the output > %run "D:/Projects/Initiatives/machine learning/programs/debug_4.py" > -- > https://mail.python.org/mailman/listinfo/python-list Bev in TX From steve+comp.lang.python at pearwood.info Sun Jul 1 20:47:32 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 2 Jul 2018 00:47:32 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On Sun, 01 Jul 2018 21:55:21 +0400, Abdur-Rahmaan Janhangeer wrote: > i meant that x: int = 3 is dangerously close to int x = 3, > > in the long run, you'll come across people who come from other languages > wanting to java/c style their code and end up sprinkling a lot of these, > it'll be a sad day for me It is a sad day for me when I see Python programmers writing x=3 or using eight space tabs or putting a space before function call parentheses len (seq) too, but I cope. Its a sad day for me when I see people on mailing lists top posting and not using capital letters or correct punctuation, but I cope with that too. In the long run, why do we always fear people coming from other languages? Why don't they fear Python programmers coming to their language and saying "Why do I have to bother with these type declarations, why can't the compiler work it out?" -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From greg.ewing at canterbury.ac.nz Sun Jul 1 20:56:01 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 02 Jul 2018 12:56:01 +1200 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: eryk sun wrote: > Python 2 raw strings are half-baked. Obviously the "r" actually stand for "rare". -- Greg From steve+comp.lang.python at pearwood.info Sun Jul 1 21:21:21 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 2 Jul 2018 01:21:21 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On Sun, 01 Jul 2018 22:48:00 +0400, Abdur-Rahmaan Janhangeer wrote: > not python, the spirit of python, > > i guess i must have been around when it was first discussed, now it's > too late to discuss why it was introduced in the first place ... Guido has been talking about this for a LONG time: https://www.artima.com/weblogs/viewpost.jsp?thread=85551 https://www.artima.com/weblogs/viewpost.jsp?thread=86641 https://www.artima.com/weblogs/viewpost.jsp?thread=87182 And for a perspective on why this is not only something desirable, but something which historically dynamic languages *used to have* but lost, see https://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From eryksun at gmail.com Sun Jul 1 22:01:27 2018 From: eryksun at gmail.com (eryk sun) Date: Mon, 2 Jul 2018 02:01:27 +0000 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: On Sun, Jul 1, 2018 at 4:30 PM, eryk sun wrote: > On Sun, Jul 1, 2018 at 8:51 AM, Steven D'Aprano > >> spam/eggs [...] >> And how would that file be displayed in the Windows GUI file explorer? > > I suppose if a file system allowed forward slash in names that > Explorer would just display it. When I get the time, I'll attach a > debugger to explorer.exe and hack a forward slash into one of the > names in a directory listing, i.e. a result from WinAPI FindFirstFile > (or native NtQueryDirectoryFile). I checked this by attaching a debugger to an instance of explorer.exe and opening a folder that has a single file named "spam eggs.txt". With a breakpoint on NtQueryDirectoryFile, I changed the filename to "spam/eggs.txt" in the directory listing (an array of FILE_ID_BOTH_DIR_INFORMATION records). As expected, Explorer just displays the filename "spam/eggs.txt" if that's what the file system returns from the NtQueryDirectoryFile system call. However, even if a file system allowed such a name, it wouldn't be accessible normally. It requires a \\?\ path, which bypasses canonicalization. From jlee54 at gmail.com Sun Jul 1 23:51:42 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 1 Jul 2018 20:51:42 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 07/01/18 18:21, Steven D'Aprano wrote: > > Guido has been talking about this for a LONG time: You keep bringing that up.? It's not an argument. People have been talking about taxes for a long, long time.? Does it surprise you that they still do?? None of us has a time machine that will transport us back to the beginning to change the course of events.? We can only read them as history (if we're lucky).? You enter the discussion whenever you get there. > > And for a perspective on why this is not only something desirable, but > something which historically dynamic languages *used to have* but lost, > see > > https://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html > I did get one epiphany out of that.? He's right - there are orders of magnitude more programmers today than there were a couple of decades ago - and they ARE almost all entry level, in that they are fluent in only one (maybe two) languages. Back before the dot com boom, programmers (generally) knew at least 6, 7, 8 languages.? They were intimately familiar with machine architecture, and knew how to pick the right language for any given task to exploit the features they wanted - speed, code size, I/O throughput, concurrency, interrupt latency, whatever.? In my case, the languages I became fluent in were C, Fortran, Assembly (several dialects and architectures), Forth, PL/M, Pascal, Modula-2, Oberon, Basic, Lisp, and Smalltalk.? Later on, Tcl, Hypertalk, Object Pascal, Prolog, and C++ were added.? Today, Python, Perl, Java and Lua round out the list.? And I have at least a working familiarity with several more. The want ads used to be for positions like "systems programmer", "application programmer", "embedded engineer", "database designer", etc.? Today, the ads read "Java programmer", "Swift programmer", "Javascript programmer", ".NET architect".? The focus has shifted from the *domain* to the *language*. And so, *most* of the new generation of programmers want to stick with one language for the long haul, and they'd like to cram every possible feature into it.? They look at the *language* the way we used to look at the *operating system*. Languages that used to be small, lean, and exceptional at doing things really well in a given domain have morphed into large, monolithic, bloated language *systems* that do many things in many domains, and have many ways to do the *same* thing, but none of it particularly well.? Throwing more processor horsepower and more GB of memory at the problem can only mask it for so long. -Jim From dieter at handshake.de Mon Jul 2 01:21:27 2018 From: dieter at handshake.de (dieter) Date: Mon, 02 Jul 2018 07:21:27 +0200 Subject: I lost nearly all my modules installing 3.7 References: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> <0001HW.20E59C82038DC45270000F6362CF@news.giganews.com> <0001HW.20E7075803E2CEB770000F6362CF@news.giganews.com> <87a7rcangk.fsf@handshake.de> <0001HW.20E7F1020419929170000F6362CF@news.giganews.com> Message-ID: <87sh526wmg.fsf@handshake.de> Elliott Roper writes: > ... > I should have mentioned that none of this went wrong in 3.6. All I'm after > are packages I can install with pip3. I really don't need to go down all the > twisty passages installing Fortran "pip[*]" is a tool to install Python packages. But some Python packages are not pure Python and require additional (beyond Python) infrastructure in your target system: e.g. additional (operating) system packages, compilers, utilities, ... Ideally, the installation instructions for a package would describe which infrastructure is necessary. Of course, you would need to consult them to find out whether a package is pure Python or what additional components are necessary in the target. In my view, the packages you have reported problems with do quite a good job: they provide precise and helpfull error/warning messages during the installation process. With their help, you can resolve the problems (or decide that you do not need the package). Side note: a missing "pkg-config" or Fortran compiler is very likely not a "3.6" versus "3.7" issue. It has to do with the target system (and its available infrastructure), maybe the versions of the installed packages but not the Python versions. > I DID have pkg-config installed in ~/Library ..... site-packages. Jim told us that "pkg-config" is not a Python package (but an (operating) system package). Therefore, its expected place is not below ".../site-packages". You must install it where system packages are looked for -- or use system specific configuration (likely, the envvar "PATH" in your case) to look where you have installed it. >I > uninstalled it and re-installed with an Admin account, where it appeared in > /Library ... site-packages > but that made no difference, pip3 install -- user matplotlib still > complaining about pkg-config "pkg-config" (once successfully installed) will provide an operating system command "pkg-config". You can check whether it is available and working by invoking "pkg-config" from the command line. On my system (Ubuntu) is is located at "/usr/bin/pkg-config". On *nix like systems the envvar "PATH" controls where operating system level commands are looked for. Badly configuring "PATH" can lead to unexpectedly not finding some commands. > ... > I do have write access. It looks like a Mac specific per user directory tree > for temporary stuff and installation records. Apparently, you are on a "Mac". Its OS 10 started as a *nix like system - but with many peculiarities. Not sure, what of the above is applying. What remains true: your "pkg-config" problem is not a Python problem but an operating system level problem -- either with the installation of the "pkg-config" package or with the configuration where commands are looked for. From dieter at handshake.de Mon Jul 2 01:34:01 2018 From: dieter at handshake.de (dieter) Date: Mon, 02 Jul 2018 07:34:01 +0200 Subject: logging module References: <0f85f6c0-20bd-4e5f-b08e-3f6813d6372a@googlegroups.com> Message-ID: <87o9fq6w1i.fsf@handshake.de> Sharan Basappa writes: > I am trying to use logging module and somehow I cannot make it work. > > A simple code that I am trying is below. The commented code line 5,6 are other options I have tried but don't work > > #importing module > import logging > > #Create and configure logger > #logging.basicConfig(filename="D:/Projects/Initiatives/machine learning/programs/newfile.log", > #logging.basicConfig(filename="newfile.log", > logging.basicConfig(format='%(asctime)s %(message)s') You can provide more than a single argument to "basicConfig", e.g. "...basicConfig(filename='...', format='...')". > ... > #Creating an object > logger=logging.getLogger() > > #Setting the threshold of logger to DEBUG > logger.setLevel(logging.DEBUG) > > #Test messages > logger.debug("Harmless debug Message") > logger.info("Just an information") > logger.warning("Its a Warning") > logger.error("Did you try to divide by zero") > logger.critical("Internet is down") > > PS: I am running this under Enthought Canopy > > The following is the output > %run "D:/Projects/Initiatives/machine learning/programs/debug_4.py" Not sure, that "basicConfig" (without "filename" parameter) logs to "stdout" or "stderr" (what you seem to expect). Apart from that, your use of the "logging" module looks okay. It should work (and usually does). From tljarolimek at gmail.com Mon Jul 2 01:43:53 2018 From: tljarolimek at gmail.com (tljarolimek at gmail.com) Date: Sun, 1 Jul 2018 22:43:53 -0700 (PDT) Subject: I lost nearly all my modules installing 3.7 In-Reply-To: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> References: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> Message-ID: <53e9f599-c379-4748-82e5-08de43ab7dae@googlegroups.com> On Thursday, June 28, 2018 at 1:09:04 PM UTC-4, Elliott Roper wrote: > I have done something stupid. Don't know what. > > My $PATH looks like this > XXXMac:~ elliott$ echo $PATH > /Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Pyth > on.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3. > 5/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/Users/elliott/bin > :/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/MacGPG2/bin:/Applications/Wireshark.app/Contents/MacOS:/usr/local/git/bin > > pip3 list or pip3.7 list gives me > Package Version > ---------- ------- > pip 10.0.1 > setuptools 39.0.1 > > > > import numpy as np > Traceback (most recent call last): > File "", line 1, in > ModuleNotFoundError: No module named 'numpy' > So it is not lying to me!!! > > pip list or pip3.6 list > gives the whole caboodle I was expecting with a far smaller version number > for setuptools. > > My understanding is that the whole $PATH is searched in order to resolve an > import, but it isn't. > > It might be relevant that I have had a bit of hassle installing module > updates in the past. I would get an error saying the module version being > replaced could not be deleted with permissions errors which I resolved with a > bit of sudo -H. > > Python 3.6 is still working properly when invoked explicitly > > -- > To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 3CF7 > 637F 896B C810 E199 7E5C A9E4 8E59 E248 https://www.youtube.com/watch?v=rAlTOfl9F2w From arj.python at gmail.com Mon Jul 2 01:45:23 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Mon, 2 Jul 2018 09:45:23 +0400 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: me too i come from "other languages" but what i liked in python was python now the world got mixed up again Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ In the long run, why do we always fear people coming from other > languages? Why don't they fear Python programmers coming to their > language and saying "Why do I have to bother with these type > declarations, why can't the compiler work it out? https://mail.python.org/mailman/listinfo/python-list > From Karsten.Hilbert at gmx.net Mon Jul 2 04:57:06 2018 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Mon, 2 Jul 2018 10:57:06 +0200 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: <34043905-9c8b-4c4b-9d10-8d786381b799@googlegroups.com> Message-ID: <20180702085706.GA2432@hermes.hilbert.loc> Eryk, thanks for your to-the-point in-depth posts. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From steve+comp.lang.python at pearwood.info Mon Jul 2 07:01:13 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 2 Jul 2018 11:01:13 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On Sun, 01 Jul 2018 20:51:42 -0700, Jim Lee wrote: > Back before the dot com boom, programmers (generally) knew at least 6, > 7, 8 languages. You obviously didn't know (m)any of the hundreds of thousands of COBOL programmers. (A language conspicuous by its absence from your impressively large list of languages.) http://catb.org/jargon/html/C/COBOL.html Of for that matter, the vast horde of BASIC/VB coders, or even for that matter the C coders who *if they were especially adventurous* might have had a passing acquaintance with one or two shell scripting languages. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From grant.b.edwards at gmail.com Mon Jul 2 09:30:33 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 2 Jul 2018 13:30:33 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On 2018-07-02, Steven D'Aprano wrote: > In the long run, why do we always fear people coming from other > languages? Tribalism and fear of outsiders was bred into H. sapiens (and ancestors) millions of years ago? -- Grant Edwards grant.b.edwards Yow! My Aunt MAUREEN was a at military advisor to IKE & gmail.com TINA TURNER!! From torriem at gmail.com Mon Jul 2 09:50:02 2018 From: torriem at gmail.com (Michael Torrie) Date: Mon, 2 Jul 2018 07:50:02 -0600 Subject: I lost nearly all my modules installing 3.7 In-Reply-To: <0001HW.20E7F1020419929170000F6362CF@news.giganews.com> References: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> <0001HW.20E59C82038DC45270000F6362CF@news.giganews.com> <0001HW.20E7075803E2CEB770000F6362CF@news.giganews.com> <87a7rcangk.fsf@handshake.de> <0001HW.20E7F1020419929170000F6362CF@news.giganews.com> Message-ID: <2d746dad-0406-94b3-9495-cb20ea842944@gmail.com> On 06/30/2018 11:10 AM, Elliott Roper wrote: > I should have mentioned that none of this went wrong in 3.6. All I'm after > are packages I can install with pip3. I really don't need to go down all the > twisty passages installing Fortran That's because there were likely binary packages available in the PyPi repository for matplotlib. Python 3.7 is new enough that there are not yet binary "wheels" for matplotlib. So you'll either have to compile it from source (hence the fortran compiler), or wait until binary wheels show up in pip. If you're wanting to use SciPy and matplotlib, I suggest you stick with Python 3.6. There's little reason to immediately go to Python 3.7. Anytime you upgrade to the very latest version of Python, it's going to take some time for binary wheels to be built and placed on PyPi, installable with pip. Either that, or make sure you do have the compilers, dependent libraries and tools (pkg-config) installed. This is easy on Linux. On Mac it's more involved and will likely involve installing a whole suite of 3rd-party software like MacPorts. From dmitrey15 at gmail.com Mon Jul 2 09:53:29 2018 From: dmitrey15 at gmail.com (dmitrey15 at gmail.com) Date: Mon, 2 Jul 2018 06:53:29 -0700 (PDT) Subject: ANN: OpenOpt Suite v 0.5627 Message-ID: <0fe51f54-9a46-4b61-b244-bc5ba1dbf8f3@googlegroups.com> hello, OpenOpt Suite v 0.5627 (OpenOpt, FuncDesigner, SpaceFuncs, DerApproximator) is available for downloading from the link https://app.box.com/s/yubipvy5q91x8w3eoglhi0tn5d9i854a (unfortunately, I still cannot update it in PYPI entries because of problems with incorrect password) It fixes compatibility issues with latest Python / NumPy / matplotlib versions and has some improvements. Unfortunately, I had no possibilities to perform essential changes since last release in 2015 due to lack of finance support, however I still intend to continue its development. Regards, D. From tjreedy at udel.edu Mon Jul 2 10:37:00 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 2 Jul 2018 10:37:00 -0400 Subject: I lost nearly all my modules installing 3.7 In-Reply-To: <2d746dad-0406-94b3-9495-cb20ea842944@gmail.com> References: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> <0001HW.20E59C82038DC45270000F6362CF@news.giganews.com> <0001HW.20E7075803E2CEB770000F6362CF@news.giganews.com> <87a7rcangk.fsf@handshake.de> <0001HW.20E7F1020419929170000F6362CF@news.giganews.com> <2d746dad-0406-94b3-9495-cb20ea842944@gmail.com> Message-ID: On 7/2/2018 9:50 AM, Michael Torrie wrote: > If you're wanting to use SciPy and matplotlib, I suggest you stick with > Python 3.6. There's little reason to immediately go to Python 3.7. > Anytime you upgrade to the very latest version of Python, it's going to > take some time for binary wheels to be built and placed on PyPi, > installable with pip. Either that, or make sure you do have the > compilers, dependent libraries and tools (pkg-config) installed. This > is easy on Linux. On Mac it's more involved and will likely involve > installing a whole suite of 3rd-party software like MacPorts. It used to take about 6 months after x.y was released before most major packages were available for x.y. I hope they come faster now. For Windows, a few hundred unofficial whls, for both win32 and amd64, including for matplotlib, are available for (2.7?, 3.4-) 3.7 from https://www.lfd.uci.edu/~gohlke/pythonlibs/, and have been for some number of months. -- Terry Jan Reedy From mikhailwas at gmail.com Mon Jul 2 12:20:52 2018 From: mikhailwas at gmail.com (Mikhail V) Date: Mon, 2 Jul 2018 19:20:52 +0300 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: [Richard Damon] > The one major issue with backslashes is that they are a special > character in string literals, so you either need to use raw literals a > remember the few cases they still act as special characters, or remember > to convert them to double back slashes, at a minimum for all the > characters that they are special for (easier to double them all). > I think it was originally an error to make the backslash followed by a > character not defined as special with a backslash as keeping the > backslash as a literal as it causes a number of these issues. Yes, it > allows you to not need to double it in many cases but that just sets you > up for the mistakes that started the thread. It is probably too late to > change that behavior now though. Yes this would at least make less mistakes. I find the whole situation with strings a bit disappointing. On the one hand - there were so many string types added, on the other hand - there are still many inconveniences. There is an english proverb, "it does too much, but still too little". (or something like that) The initial string syntax -- I think it's direct copy of C strings syntax. And it sucks. (path dependency?) I'd say there should be just two main string types: 1. string literal where all special character goes into, say, figure braces {}; (if only there was a time machine) 2. raw strings, including multiline raw strings which should be PEP-8 compliant. So Imo default syntax should be something like: S = "A:{x41}B:{x42}" instead of backslashes and Co. From rosuav at gmail.com Mon Jul 2 13:10:28 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Jul 2018 03:10:28 +1000 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: On Tue, Jul 3, 2018 at 2:20 AM, Mikhail V wrote: > [Richard Damon] > >> The one major issue with backslashes is that they are a special >> character in string literals, so you either need to use raw literals a >> remember the few cases they still act as special characters, or remember >> to convert them to double back slashes, at a minimum for all the >> characters that they are special for (easier to double them all). > >> I think it was originally an error to make the backslash followed by a >> character not defined as special with a backslash as keeping the >> backslash as a literal as it causes a number of these issues. Yes, it >> allows you to not need to double it in many cases but that just sets you >> up for the mistakes that started the thread. It is probably too late to >> change that behavior now though. > > Yes this would at least make less mistakes. > I find the whole situation with strings a bit disappointing. > On the one hand - there were so many string types added, on the other > hand - there are still many inconveniences. There is an english proverb, > "it does too much, but still too little". (or something like that) > > The initial string syntax -- I think it's direct copy of C strings syntax. > And it sucks. (path dependency?) > > I'd say there should be just two main string types: > 1. string literal where all special character goes into, say, figure braces {}; > (if only there was a time machine) > 2. raw strings, including multiline raw strings which should be PEP-8 compliant. > > So Imo default syntax should be something like: > > S = "A:{x41}B:{x42}" > > instead of backslashes and Co. So how do you represent brace characters in a string? > 2. raw strings, including multiline raw strings which should be PEP-8 compliant. ??? ChrisA From Richard at Damon-Family.org Mon Jul 2 13:16:28 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Mon, 2 Jul 2018 10:16:28 -0700 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: On 7/2/18 9:20 AM, Mikhail V wrote: > [Richard Damon] > >> The one major issue with backslashes is that they are a special >> character in string literals, so you either need to use raw literals a >> remember the few cases they still act as special characters, or remember >> to convert them to double back slashes, at a minimum for all the >> characters that they are special for (easier to double them all). >> I think it was originally an error to make the backslash followed by a >> character not defined as special with a backslash as keeping the >> backslash as a literal as it causes a number of these issues. Yes, it >> allows you to not need to double it in many cases but that just sets you >> up for the mistakes that started the thread. It is probably too late to >> change that behavior now though. > Yes this would at least make less mistakes. > I find the whole situation with strings a bit disappointing. > On the one hand - there were so many string types added, on the other > hand - there are still many inconveniences. There is an english proverb, > "it does too much, but still too little". (or something like that) > > The initial string syntax -- I think it's direct copy of C strings syntax. > And it sucks. (path dependency?) > > I'd say there should be just two main string types: > 1. string literal where all special character goes into, say, figure braces {}; > (if only there was a time machine) > 2. raw strings, including multiline raw strings which should be PEP-8 compliant. > > So Imo default syntax should be something like: > > S = "A:{x41}B:{x42}" > > instead of backslashes and Co. Yes, the backslash notation is just like what C uses (an likely the source of it). The exact same problem pops up in the C forums too. Not sure where it got the notation from. -- Richard Damon From brgrt2 at gmail.com Mon Jul 2 13:22:43 2018 From: brgrt2 at gmail.com (T Berger) Date: Mon, 2 Jul 2018 10:22:43 -0700 (PDT) Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: References: <20180629225955.GA75408@cskk.homeip.net> Message-ID: <134fa0d6-14ec-443b-a7b0-0b1f7102e540@googlegroups.com> On Saturday, June 30, 2018 at 6:02:06 PM UTC-4, T Berger wrote: > On Friday, June 29, 2018 at 7:00:15 PM UTC-4, Cameron Simpson wrote: > > > The key point here from Jim is "simultaneously". Are you properly shutting down > > the Flask instance in IDLE before running from Terminal, and vice versa? > > Cameron, I try every option to quit either program, but they don't work. Or I should say, they mostly don't work. Once in a while they do. The one option which works (which is not a feasible option) is rebooting my Mac (actually that might not work either. I think I got the error message again this morning when I rebooted). > > > Otherwise both will try to use the same local port and There Can Be Only One. > > > > Do you need to run from both environments at the same time? I'd have thought > > not, which also leads me to: why are you flicking from IDLE to Terminal? I > > would have imagined using one or the other normally, not both. It isn't wrong > > to use both, just surprising. > > I'm working from a Python manual. I created the webapp in IDLE, and test it in Terminal, per the instructions in the manual. I use IDLE to edit my program, and then test it in terminal. When I go from one to the other, I get the error message. IDLE has a keyboard shortcut for quitting the shell?Cntl + C?but it doesn't work. Neither does restarting the shell. Neither does entering the kill command line, not in IDLE or terminal. > > Do you have any other suggestions? I'm going to email the writer. He doesn't mention how to deal with problems that might arise from working with two programs at the same time. Maybe Cntl+C should do it, but in my case it doesn't. > > Tamara Cameron, I'd like to add screenshots of my idle and terminal windows. Perhaps this would shed light on my this issue. This is my last window in terminal: [Restored Jul 2, 2018, 1:12:09 PM] Last login: Mon Jul 2 10:58:54 on ttys000 Restored session: Mon Jul 2 11:04:19 EDT 2018 192:Webapp TamaraB$ exit logout Saving session... ...saving history...truncating history files... ...completed. [Process completed] ~~~~ To me this looks like the program running in terminal has been killed. Now this is my idle shell: RESTART: /Users/TamaraB/Desktop/Webapp/vsearch4web.py * Serving Flask app "vsearch4web" (lazy loading) * Environment: production  WARNING: Do not use the development server in a production environment.  Use a production WSGI server instead. * Debug mode: on Traceback (most recent call last): File "/Users/TamaraB/Desktop/Webapp/vsearch4web.py", line 26, in app.run(debug=True) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 943, in run run_simple(host, port, self, **options) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/werkzeug/serving.py", line 795, in run_simple s.bind(get_sockaddr(hostname, port, address_family)) OSError: [Errno 48] Address already in use >>> Why should there be an error in idle? It's the only app running. I emailed the writer of the manual I'm using, but who knows if, or when, he'll reply. So any help you provide would be great. Thanks, Tamara From brgrt2 at gmail.com Mon Jul 2 13:51:28 2018 From: brgrt2 at gmail.com (T Berger) Date: Mon, 2 Jul 2018 10:51:28 -0700 (PDT) Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: <134fa0d6-14ec-443b-a7b0-0b1f7102e540@googlegroups.com> References: <20180629225955.GA75408@cskk.homeip.net> <134fa0d6-14ec-443b-a7b0-0b1f7102e540@googlegroups.com> Message-ID: <8069c2eb-6d34-4f4b-aabe-31222e62b975@googlegroups.com> On Monday, July 2, 2018 at 1:22:59 PM UTC-4, T Berger wrote: > On Saturday, June 30, 2018 at 6:02:06 PM UTC-4, T Berger wrote: > > On Friday, June 29, 2018 at 7:00:15 PM UTC-4, Cameron Simpson wrote: > > > > > The key point here from Jim is "simultaneously". Are you properly shutting down > > > the Flask instance in IDLE before running from Terminal, and vice versa? > > > > Cameron, I try every option to quit either program, but they don't work. Or I should say, they mostly don't work. Once in a while they do. The one option which works (which is not a feasible option) is rebooting my Mac (actually that might not work either. I think I got the error message again this morning when I rebooted). > > > > > Otherwise both will try to use the same local port and There Can Be Only One. > > > > > > Do you need to run from both environments at the same time? I'd have thought > > > not, which also leads me to: why are you flicking from IDLE to Terminal? I > > > would have imagined using one or the other normally, not both. It isn't wrong > > > to use both, just surprising. > > > > I'm working from a Python manual. I created the webapp in IDLE, and test it in Terminal, per the instructions in the manual. I use IDLE to edit my program, and then test it in terminal. When I go from one to the other, I get the error message. IDLE has a keyboard shortcut for quitting the shell?Cntl + C?but it doesn't work. Neither does restarting the shell. Neither does entering the kill command line, not in IDLE or terminal. > > > > Do you have any other suggestions? I'm going to email the writer. He doesn't mention how to deal with problems that might arise from working with two programs at the same time. Maybe Cntl+C should do it, but in my case it doesn't. > > > > Tamara > > Cameron, I'd like to add screenshots of my idle and terminal windows. Perhaps this would shed light on my this issue. > > This is my last window in terminal: > > [Restored Jul 2, 2018, 1:12:09 PM] > Last login: Mon Jul 2 10:58:54 on ttys000 > Restored session: Mon Jul 2 11:04:19 EDT 2018 > 192:Webapp TamaraB$ exit > logout > Saving session... > ...saving history...truncating history files... > ...completed. > > [Process completed] > ~~~~ > To me this looks like the program running in terminal has been killed. > > Now this is my idle shell: > > RESTART: /Users/TamaraB/Desktop/Webapp/vsearch4web.py > * Serving Flask app "vsearch4web" (lazy loading) > * Environment: production > [31m WARNING: Do not use the development server in a production environment. [0m > [2m Use a production WSGI server instead. [0m > * Debug mode: on > Traceback (most recent call last): > File "/Users/TamaraB/Desktop/Webapp/vsearch4web.py", line 26, in > app.run(debug=True) > File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 943, in run > run_simple(host, port, self, **options) > File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/werkzeug/serving.py", line 795, in run_simple > s.bind(get_sockaddr(hostname, port, address_family)) > OSError: [Errno 48] Address already in use > >>> > > Why should there be an error in idle? It's the only app running. > > I emailed the writer of the manual I'm using, but who knows if, or when, he'll reply. So any help you provide would be great. > > Thanks, > > Tamara Addendum I forgot to add that I get the error message even after I exit from idle. Exiting from idle is supposed to kill the running program. That is what the the confirming dialog box explicitly states. From brgrt2 at gmail.com Mon Jul 2 14:02:59 2018 From: brgrt2 at gmail.com (T Berger) Date: Mon, 2 Jul 2018 11:02:59 -0700 (PDT) Subject: Getting posts to sort chronologically in tree view Message-ID: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> Is there any way to set posts to appear chronologically in tree view? And why is the tree view completely out of order? My last two posts in this view are from 6/27 and 6/28. From python at mrabarnett.plus.com Mon Jul 2 14:30:16 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 2 Jul 2018 19:30:16 +0100 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: <672fa3c5-b2be-16f3-03b1-9dfadca260b8@mrabarnett.plus.com> On 2018-07-02 18:16, Richard Damon wrote: > On 7/2/18 9:20 AM, Mikhail V wrote: >> [Richard Damon] >> >>> The one major issue with backslashes is that they are a special >>> character in string literals, so you either need to use raw literals a >>> remember the few cases they still act as special characters, or remember >>> to convert them to double back slashes, at a minimum for all the >>> characters that they are special for (easier to double them all). >>> I think it was originally an error to make the backslash followed by a >>> character not defined as special with a backslash as keeping the >>> backslash as a literal as it causes a number of these issues. Yes, it >>> allows you to not need to double it in many cases but that just sets you >>> up for the mistakes that started the thread. It is probably too late to >>> change that behavior now though. >> Yes this would at least make less mistakes. >> I find the whole situation with strings a bit disappointing. >> On the one hand - there were so many string types added, on the other >> hand - there are still many inconveniences. There is an english proverb, >> "it does too much, but still too little". (or something like that) >> >> The initial string syntax -- I think it's direct copy of C strings syntax. >> And it sucks. (path dependency?) >> >> I'd say there should be just two main string types: >> 1. string literal where all special character goes into, say, figure braces {}; >> (if only there was a time machine) >> 2. raw strings, including multiline raw strings which should be PEP-8 compliant. >> >> So Imo default syntax should be something like: >> >> S = "A:{x41}B:{x42}" >> >> instead of backslashes and Co. > > Yes, the backslash notation is just like what C uses (an likely the > source of it). The exact same problem pops up in the C forums too. Not > sure where it got the notation from. > C is descended from BCPL, which used '*', e.g. newline was "*N". From drsalists at gmail.com Mon Jul 2 14:35:43 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 2 Jul 2018 11:35:43 -0700 Subject: Getting posts to sort chronologically in tree view In-Reply-To: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> Message-ID: On Mon, Jul 2, 2018 at 11:02 AM, T Berger wrote: > Is there any way to set posts to appear chronologically in tree view? And > why is the tree view completely out of order? My last two posts in this > view are from 6/27 and 6/28. > I'm thinking you may want to specify what software you're talking about. If it's software for reading python-list, we don't all use the same programs. From python at mrabarnett.plus.com Mon Jul 2 14:37:27 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 2 Jul 2018 19:37:27 +0100 Subject: Getting posts to sort chronologically in tree view In-Reply-To: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> Message-ID: <6c40ec30-ca3f-b56b-3ec0-86334dfdd8c3@mrabarnett.plus.com> On 2018-07-02 19:02, T Berger wrote: > Is there any way to set posts to appear chronologically in tree view? And why is the tree view completely out of order? My last two posts in this view are from 6/27 and 6/28. > You haven't said what software you're using to view this list. Judging by your email address, I'm guessing that you're accessing this list via Google Groups in a browser. From nospam at yrl.co.uk Mon Jul 2 14:59:08 2018 From: nospam at yrl.co.uk (Elliott Roper) Date: Mon, 02 Jul 2018 19:59:08 +0100 Subject: I lost nearly all my modules installing 3.7 References: <0001HW.20E54D9E037B46DA700000D972CF@news.giganews.com> <0001HW.20E59C82038DC45270000F6362CF@news.giganews.com> <0001HW.20E7075803E2CEB770000F6362CF@news.giganews.com> <87a7rcangk.fsf@handshake.de> <0001HW.20E7F1020419929170000F6362CF@news.giganews.com> <2d746dad-0406-94b3-9495-cb20ea842944@gmail.com> Message-ID: <0001HW.20EAAD7C04BDBF7470000D2092CF@news.giganews.com> On 2 Jul 2018, Michael Torrie wrote (in article): > On 06/30/2018 11:10 AM, Elliott Roper wrote: > > I should have mentioned that none of this went wrong in 3.6. All I'm after > > are packages I can install with pip3. I really don't need to go down all the > > twisty passages installing Fortran > > That's because there were likely binary packages available in the PyPi > repository for matplotlib. Python 3.7 is new enough that there are not > yet binary "wheels" for matplotlib. So you'll either have to compile it > from source (hence the fortran compiler), or wait until binary wheels > show up in pip. > > If you're wanting to use SciPy and matplotlib, I suggest you stick with > Python 3.6. There's little reason to immediately go to Python 3.7. > Anytime you upgrade to the very latest version of Python, it's going to > take some time for binary wheels to be built and placed on PyPi, > installable with pip. Either that, or make sure you do have the > compilers, dependent libraries and tools (pkg-config) installed. This > is easy on Linux. On Mac it's more involved and will likely involve > installing a whole suite of 3rd-party software like MacPorts. Thanks Michael, Back to 3.6 after a short wait for a miracle or when I really need matplotlib. My doctor read the blood pressure riot act to me, so I decided to hit the Python big guns to track my BP after some drastic lifestyle changes. I have just had my second and last single shot of coffee for the day. I used to down 10 shots before lunch! And I'm typing this stone cold sober. Pandas and Numpy are working OK on 3.7 and I think I have fixed the mess I had with some packages needing sudo magic to update, so this whole exercise has not been wasted. -- To de-mung my e-mail address:- fsnospam$elliott$$ PGP Fingerprint: 1A96 3CF7 637F 896B C810 E199 7E5C A9E4 8E59 E248 From jlee54 at gmail.com Mon Jul 2 15:45:24 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 2 Jul 2018 12:45:24 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 07/02/18 04:01, Steven D'Aprano wrote: > On Sun, 01 Jul 2018 20:51:42 -0700, Jim Lee wrote: > >> Back before the dot com boom, programmers (generally) knew at least 6, >> 7, 8 languages. > You obviously didn't know (m)any of the hundreds of thousands of COBOL > programmers. > ? I did know a handful, but we generally didn't admit to it. :) > > > Of for that matter, the vast horde of BASIC/VB coders, or even for that > matter the C coders who *if they were especially adventurous* might have > had a passing acquaintance with one or two shell scripting languages. > > > VB is after the time frame I was thinking of.? I consider VB programmers as part of the "new generation" but, since VB is closed source, they had little opportunity to influence its design. And the BASIC programmers before them were vastly comprised of hobby programmers, not professionals (though many made the transition later). So yes, there are always exceptions when one is speaking in generalities. -Jim From ian.g.kelly at gmail.com Mon Jul 2 16:27:58 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 2 Jul 2018 14:27:58 -0600 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On Sun, Jul 1, 2018 at 10:53 PM Jim Lee wrote: > I did get one epiphany out of that. He's right - there are orders of > magnitude more programmers today than there were a couple of decades ago > - and they ARE almost all entry level, in that they are fluent in only > one (maybe two) languages. There are much better yardsticks for measuring seniority than number of languages known. Just because somebody knows a dozen languages doesn't mean that they can come up with the correct algorithm, or design an entire system, for a hill of beans. I'll take somebody at a senior level who can do the latter well, but only codes in Smalltalk, any day of the week. > Back before the dot com boom, programmers (generally) knew at least 6, > 7, 8 languages. They were intimately familiar with machine > architecture, and knew how to pick the right language for any given task > to exploit the features they wanted - speed, code size, I/O throughput, > concurrency, interrupt latency, whatever. In my case, the languages I > became fluent in were C, Fortran, Assembly (several dialects and > architectures), Forth, PL/M, Pascal, Modula-2, Oberon, Basic, Lisp, and > Smalltalk. Later on, Tcl, Hypertalk, Object Pascal, Prolog, and C++ > were added. Today, Python, Perl, Java and Lua round out the list. And > I have at least a working familiarity with several more. > > The want ads used to be for positions like "systems programmer", > "application programmer", "embedded engineer", "database designer", > etc. Today, the ads read "Java programmer", "Swift programmer", > "Javascript programmer", ".NET architect". The focus has shifted from > the *domain* to the *language*. I still see plenty of the former, but there's also good reason for the latter. If your production system is built out of a dozen languages, you may have a well-tuned system where each language was chosen for a solid, specific reason; but you've also got a maintenance nightmare on the day that the one programmer who actually understands all of it decides to leave. Companies don't want the best possible language for the job; they want code that they can continue to maintain into the future. This is why, e.g., a large company like Google only has four languages that are approved for general usage. It's not that they wouldn't be useful; it's that the overhead of engineering complexity (and therefore cost) goes up with the more that you use. > Languages that used to be small, lean, and exceptional at doing things > really well in a given domain have morphed into large, monolithic, > bloated language *systems* that do many things in many domains, and have > many ways to do the *same* thing, but none of it particularly well. > Throwing more processor horsepower and more GB of memory at the problem > can only mask it for so long. Actually, the thinking is that as processors get ever faster and cheaper, and as memory gets ever larger and cheaper, the cost of software execution continues to drop, while the cost of software development and maintenance remain the same. The latter is, therefore, the component that is more important to address. General-purpose languages haven't arisen because the programmers are lazy; it's because the special-purpose languages are simply no longer necessary for the majority of tasks, and in many cases are no longer worth the costs of additional development overhead. From daviddschool at gmail.com Mon Jul 2 16:45:09 2018 From: daviddschool at gmail.com (David D) Date: Mon, 2 Jul 2018 13:45:09 -0700 (PDT) Subject: Multi-threading with a simple timer? Message-ID: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> Is there a SIMPLE method that I can have a TIMER count down at a user input prompt - if the user doesn't enter information within a 15 second period, it times out. I am going to be using pycharm and not the shell. Thanks in advance. From brgrt2 at gmail.com Mon Jul 2 17:12:20 2018 From: brgrt2 at gmail.com (T Berger) Date: Mon, 2 Jul 2018 14:12:20 -0700 (PDT) Subject: Getting posts to sort chronologically in tree view In-Reply-To: References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> Message-ID: <876fad17-15a9-486c-b72d-716adedccbc0@googlegroups.com> On Monday, July 2, 2018 at 2:36:00 PM UTC-4, Dan Stromberg wrote: > On Mon, Jul 2, 2018 at 11:02 AM, T Berger wrote: > > > Is there any way to set posts to appear chronologically in tree view? And > > why is the tree view completely out of order? My last two posts in this > > view are from 6/27 and 6/28. > > > > I'm thinking you may want to specify what software you're talking about. > If it's software for reading python-list, we don't all use the same > programs. Here is another question. I replied to this email in my inbox. But it's not showing here. And Dan's post did not arrive in my inbox. Neither are most posters' to my other questions. Yet I checked the box for "Automatically subscribe me to email updates when I post to a topic." What gives? From grant.b.edwards at gmail.com Mon Jul 2 17:17:21 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 2 Jul 2018 21:17:21 +0000 (UTC) Subject: Getting posts to sort chronologically in tree view References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> Message-ID: On 2018-07-02, T Berger wrote: > Is there any way to set posts to appear chronologically in tree > view? http://slrn.sourceforge.net/docs/slrn-manual.html -- Grant Edwards grant.b.edwards Yow! Now we can become at alcoholics! gmail.com From gheskett at shentel.net Mon Jul 2 17:40:27 2018 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 2 Jul 2018 17:40:27 -0400 Subject: Getting posts to sort chronologically in tree view In-Reply-To: References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> Message-ID: <201807021740.27479.gheskett@shentel.net> On Monday 02 July 2018 17:17:21 Grant Edwards wrote: > On 2018-07-02, T Berger wrote: > > Is there any way to set posts to appear chronologically in tree > > view? > > http://slrn.sourceforge.net/docs/slrn-manual.html That s/b the default if threading is turned off. It is in T-bird and kmail. But I've zero experience with slrn. -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From grant.b.edwards at gmail.com Mon Jul 2 18:29:17 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 2 Jul 2018 22:29:17 +0000 (UTC) Subject: Getting posts to sort chronologically in tree view References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> <201807021740.27479.gheskett@shentel.net> Message-ID: On 2018-07-02, Gene Heskett wrote: > On Monday 02 July 2018 17:17:21 Grant Edwards wrote: > >> On 2018-07-02, T Berger wrote: >> > Is there any way to set posts to appear chronologically in tree >> > view? >> >> http://slrn.sourceforge.net/docs/slrn-manual.html > > That s/b the default if threading is turned off. It is in T-bird and > kmail. But I've zero experience with slrn. I doubt the OP is using slrn. But, since T Berger declined to provide any information at all about what _was_ being used, I thought I'd be snarky and assume that it was slrn, since it's obviously the best. :) -- Grant Edwards grant.b.edwards Yow! Hold the MAYO & pass at the COSMIC AWARENESS ... gmail.com From roel at roelschroeven.net Mon Jul 2 18:38:05 2018 From: roel at roelschroeven.net (Roel Schroeven) Date: Tue, 03 Jul 2018 00:38:05 +0200 Subject: Python 3.7 Windows Help Behaviour In-Reply-To: References: Message-ID: BlindAnagram schreef op 30/06/2018 15:50: > On 30/06/2018 10:43, Steven D'Aprano wrote: >> On Fri, 29 Jun 2018 12:53:15 -0400, Terry Reedy wrote: >> >>> On 6/29/2018 6:14 AM, BlindAnagram wrote: >>>> In Python 3.7.0 on Windows the help file (python370.chm) displays with >>>> a fixed line length and does not adjust its line length when the user >>>> expands the help window horizontally. This behaviour is different to >>>> that of the Python 3.6 help file (python360.chm) which adjusts its text >>>> to fit the horizontal width of the help window. >>>> >>>> Is this a deliberate change or one that can be turned on or off in some >>>> way (I prefer the Python 3.6 behaviour)? >>> I believe that this is a deliberate regression imposed by 'experts' who >>> believe in form over function and 'controlling the user experience'. >>> 3.6.6 has been 'fixated' also. >> Sounds like somebody should raise a bug report. > > I see that this has been done: > > https://bugs.python.org/issue34006 Fixed now! To Terry Reedy and all others involved: thanks for quickly fixing this. Best regards, Roel -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From mikhailwas at gmail.com Mon Jul 2 18:42:09 2018 From: mikhailwas at gmail.com (Mikhail V) Date: Tue, 3 Jul 2018 01:42:09 +0300 Subject: File names with slashes [was Re: error in os.chdir] Message-ID: [Chris A] > [Mikhail] > > So Imo default syntax should be something like: > > > > S = "A:{x41}B:{x42}" > > > > instead of backslashes and Co. > > So how do you represent brace characters in a string? \{ and \} just kidding :-D I would be ok with {L} and {R} - easy on eye and easy to remember. Why don't ask how would I represent double-quote character? It's more important, but I would not use double quote as string delimiter, I'd use {} as delimiter: s= "\"s\"" -> s= {"s"} is much better. > > 2. raw strings, including multiline raw strings which should be PEP-8 compliant. > > ??? Raw strings - as I suggested here like 3 weeks ago or so? S = `op` multi-line raw string block parsed by indentation From ben+python at benfinney.id.au Mon Jul 2 19:12:56 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Jul 2018 09:12:56 +1000 Subject: Getting posts to sort chronologically in tree view References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> Message-ID: <851sclcjuv.fsf@benfinney.id.au> T Berger writes: > Is there any way to set posts to appear chronologically in tree view? Yes, depending on what software you use to interact with this forum. See the documentation for that software. In the case of Gnus, that ordering is the default when viewing the group summary. -- \ ?The entertainment industry calls DRM "security" software, | `\ because it makes them secure from their customers.? ?Cory | _o__) Doctorow, 2014-02-05 | Ben Finney From ben+python at benfinney.id.au Mon Jul 2 19:15:32 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 03 Jul 2018 09:15:32 +1000 Subject: Getting posts to sort chronologically in tree view References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> <876fad17-15a9-486c-b72d-716adedccbc0@googlegroups.com> Message-ID: <85woudb563.fsf@benfinney.id.au> T Berger writes: > Here is another question. I replied to this email in my inbox. But > it's not showing here. Please understand that the ?here? you mention is subjective, for your particular view of this forum. This forum is distributed over many servers, and the participants here use various different software ? even different network protocols ? to interact. Your view, your ?here? is *not* universal for the participants in this forum. So, if you want help with some specific software, you should ask the people who support *that software*. This forum is unlikely to be the best place to get that help. -- \ ?I tell you the truth: this generation will certainly not pass | `\ away until all these things [the end of the world] have | _o__) happened.? ?Jesus, c. 30 CE, as quoted in Matthew 24:34 | Ben Finney From greg.ewing at canterbury.ac.nz Mon Jul 2 19:22:56 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 Jul 2018 11:22:56 +1200 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: Ian Kelly wrote: > Just because somebody knows a dozen languages > doesn't mean that they can come up with the correct algorithm, That doesn't mean there's no correlation. Someone who is familiar with a variety of languages is also very likely to be self-motivated and have enough passion and curiosity to have acquired a broad and deep knowledge of other aspects of the craft. > If your production system is built out of a dozen languages, > you may have a well-tuned system where each language was chosen for a > solid, specific reason; but you've also got a maintenance nightmare on > the day that the one programmer who actually understands all of it > decides to leave. There are good reasons to restrict the number of languages used, but it doesn't mean that language-specific job advertisements are the best way to go about getting staff. The company doesn't really want a "Java programmer" or whatever, they want a *good* programmer. A truly good programmer will be able to learn about the language being used on the job. -- Greg From gheskett at shentel.net Mon Jul 2 19:58:16 2018 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 2 Jul 2018 19:58:16 -0400 Subject: Getting posts to sort chronologically in tree view In-Reply-To: References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> <201807021740.27479.gheskett@shentel.net> Message-ID: <201807021958.16407.gheskett@shentel.net> On Monday 02 July 2018 18:29:17 Grant Edwards wrote: > On 2018-07-02, Gene Heskett wrote: > > On Monday 02 July 2018 17:17:21 Grant Edwards wrote: > >> On 2018-07-02, T Berger wrote: > >> > Is there any way to set posts to appear chronologically in tree > >> > view? > >> > >> http://slrn.sourceforge.net/docs/slrn-manual.html > > > > That s/b the default if threading is turned off. It is in T-bird and > > kmail. But I've zero experience with slrn. > > I doubt the OP is using slrn. But, since T Berger declined to provide > any information at all about what _was_ being used, I thought I'd be > snarky and assume that it was slrn, since it's obviously the best. :) > That depends on ones point of view, Grant. Best for me was Thor, on amigados. There were no "fences" between email and a newsgroup, it handled it all. > -- > Grant Edwards grant.b.edwards Yow! Hold the MAYO > & pass at the COSMIC AWARENESS ... gmail.com -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From jlee54 at gmail.com Mon Jul 2 20:10:37 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 2 Jul 2018 17:10:37 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 07/02/18 16:22, Gregory Ewing wrote: > Ian Kelly wrote: >> Just because somebody knows a dozen languages >> doesn't mean that they can come up with the correct algorithm, > > That doesn't mean there's no correlation. Someone who is familiar > with a variety of languages is also very likely to be self-motivated > and have enough passion and curiosity to have acquired a broad and > deep knowledge of other aspects of the craft. > Well put.?? And "correct algorithm" sounds like something a CS major would say.? In the real world, it's more important to come up with a working algorithm, or an efficient algorithm.? In fact, I often choose my algorithms based more on readability (simplicity) and maintainability than textbook correctness.? You can always tell when an intern has been in the code - they implement a full b-tree to sort a simple one-dimensional list.? On the other hand, someone with exposure to multiple languages has seen multiple ways to accomplish a given task, and is likely to choose the best fit for the task at hand. >> If your production system is built out of a dozen languages, >> you may have a well-tuned system where each language was chosen for a >> solid, specific reason; but you've also got a maintenance nightmare on >> the day that the one programmer who actually understands all of it >> decides to leave. > > There are good reasons to restrict the number of languages used, but > it doesn't mean that language-specific job advertisements are the > best way to go about getting staff. The company doesn't really want > a "Java programmer" or whatever, they want a *good* programmer. A > truly good programmer will be able to learn about the language > being used on the job. > I wish that were universally true.? I have seen all too often where a company will hire an intern fresh out of school (who knows the requested language) over a more experienced individual who knows multiple languages, but not the one asked for. The mere fact of knowing multiple languages demonstrates adaptability and the ability to think in multiple paradigms. However, the hiring process today is based on tick boxes in an automated search form.? Qualified individuals don't even come up on the radar because the criteria for qualification has changed. -Jim From drsalists at gmail.com Mon Jul 2 20:34:10 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 2 Jul 2018 17:34:10 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On Sun, Jul 1, 2018 at 8:51 PM, Jim Lee wrote: > Languages that used to be small, lean, and exceptional at doing things > really well in a given domain have morphed into large, monolithic, bloated > language *systems* that do many things in many domains, and have many ways > to do the *same* thing, but none of it particularly well. Throwing more > processor horsepower and more GB of memory at the problem can only mask it > for so long. > I used to write useful programs that ran in 256 bytes of RAM. Back then, the phone in my pocket right now would've been a supercomputer. The fact of the matter is the economics have changed a lot since then. Machine time used to be really expensive compared to developer time. Today, it's the opposite: developer time is really expensive compared to machine time. It doesn't make much sense anymore to wring one's hands about "throwing" more computer power at a problem. From info at tundraware.com Mon Jul 2 20:51:29 2018 From: info at tundraware.com (Tim Daneliuk) Date: Mon, 2 Jul 2018 19:51:29 -0500 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 07/02/2018 06:22 PM, Gregory Ewing wrote: > A > truly?good?programmer?will?be?able?to?learn?about?the?language > being?used?on?the?job. Except that the current attempt is to use techniques like agile, scrum, pair programming, and so forth to turn programming into a factory activity. High degrees of specialization are segmented by architectural role (front end, back end, infrastructure, DevOps ...), language, and even business unit. In my view, systems architecture, software design, and non functional capabilities suffer thereby, but I am old and crabby :) In particular, there is little interest in having programmers learn on the job, only that they be as productive as possible as fast they can. Hiring specific languages skills - the theory goes - means that the individual will be fluent in the entire language ecosystem of libraries, tools, and so forth. What gets lost in this factory model is that fewer and fewer people are able to stand back and ask, "Are we even using a good design, language, toolkit, ..." While it is true that a good programmer will pick up new things out of personal curiosity, it is also true that this is not as rewarded a behavior as we'd like to believe. From steve+comp.lang.python at pearwood.info Mon Jul 2 20:51:37 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 3 Jul 2018 00:51:37 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On Tue, 03 Jul 2018 11:22:56 +1200, Gregory Ewing wrote: > Someone who is familiar with a > variety of languages is also very likely to be self-motivated and have > enough passion and curiosity to have acquired a broad and deep knowledge > of other aspects of the craft. "Jack of all trades, master of none" sort of thing? Or are you thinking more along the lines of one of those guys who masters a new language in an hour and reaches expert level in a week? Such a beast is not *quite* mythical -- I'm married to one, when it comes to musical instruments not programming languages. But they're damn rare. For most of us mere mortals, the "ten thousand hours" rule of thumb applies. Ten thousand hours should be read as an indefinitely large number, not a specific figure: see the authors of the original study: https://www.salon.com/2016/04/10/malcolm_gladwell_got_us_wrong_our_research_was_key_to_the_10000_hour_rule_but_heres_what_got_oversimplified/ > A truly good programmer will be able to learn about the > language being used on the job. Indeed, if you don't mind paying them for the couple of weeks it takes them to come up to speed on the language and the couple of years it takes to master it. If I needed, let's say, a SNOBOL programmer, or a F# programmer, I'd take what I could get and train them up in the language if needed. But if I wanted somebody to program in Java, or C, or PHP, why pay somebody to learn the language at full senior rates when there are millions of senior developers who already know the language? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jul 2 20:57:09 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 3 Jul 2018 00:57:09 +0000 (UTC) Subject: Python 3.7 Windows Help Behaviour References: Message-ID: On Fri, 29 Jun 2018 12:53:15 -0400, Terry Reedy wrote: > On 6/29/2018 6:14 AM, BlindAnagram wrote: >> In Python 3.7.0 on Windows the help file (python370.chm) displays with >> a fixed line length and does not adjust its line length when the user >> expands the help window horizontally. This behaviour is different to >> that of the Python 3.6 help file (python360.chm) which adjusts its text >> to fit the horizontal width of the help window. >> >> Is this a deliberate change or one that can be turned on or off in some >> way (I prefer the Python 3.6 behaviour)? > > I believe that this is a deliberate regression imposed by 'experts' who > believe in form over function and 'controlling the user experience'. > 3.6.6 has been 'fixated' also. I think that's been reverted: https://github.com/python/cpython/commit/580c7db172a41d6311c0f3a7aec321597576e214 -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jlee54 at gmail.com Mon Jul 2 21:10:07 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 2 Jul 2018 18:10:07 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: <0a06193d-5ba7-4ee2-20f0-57041e9557ab@gmail.com> On 07/02/18 17:34, Dan Stromberg wrote: > > > The fact of the matter is the economics have changed a lot since then. > Machine time used to be really expensive compared to developer time.? > Today, it's the opposite: developer time is really expensive compared > to machine time. > If you go back far enough, yes.? But for the majority of the past, the tradeoff was developer time vs time to market.? That's why we had an explosion of RAD tools in the '90s.? It became more important to develop an application *quickly* rather than *correctly*.? And that philosophy continues to this day.? Python is a descendant of the RAD philosophy. (By correctly, I mean using the resources available in an efficient and non-wasteful manner.) > It doesn't make much sense anymore to wring one's hands about > "throwing" more computer power at a problem. > We've already hit a wall performance-wise.? Physics only allows so many electrons to flow through a nm-sized pipe.? Now, the "solution" is to keep adding more cores. But that doesn't help if an application doesn't lend itself to a multi-threaded design.? So, software efficiency will once again become the bottleneck. -Jim From jlee54 at gmail.com Mon Jul 2 21:20:53 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 2 Jul 2018 18:20:53 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 07/02/18 17:51, Steven D'Aprano wrote: > > For most of us mere mortals, the "ten thousand hours" rule of thumb > applies. > > Ten thousand hours should be read as an indefinitely large number > >> A truly good programmer will be able to learn about the >> language being used on the job. > Indeed, if you don't mind paying them for the couple of weeks it takes > them to come up to speed on the language and the couple of years it takes > to master it. So we went from 10,000 hours, to infinite, and then back to a couple of years? The 10,000 hour rule would apply to mastering the general craft of programming, not a specific language. Since 10,000 hours is about 5 years in a 9-5 setting, I'd say that's about right. As I'm sure you've experienced, picking up a second language after mastering the general craft of programming takes far less time. -Jim From tjreedy at udel.edu Mon Jul 2 22:41:35 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 2 Jul 2018 22:41:35 -0400 Subject: Python 3.7 Windows Help Behaviour In-Reply-To: References: Message-ID: On 7/2/2018 8:57 PM, Steven D'Aprano wrote: > On Fri, 29 Jun 2018 12:53:15 -0400, Terry Reedy wrote: > >> On 6/29/2018 6:14 AM, BlindAnagram wrote: >>> In Python 3.7.0 on Windows the help file (python370.chm) displays with >>> a fixed line length and does not adjust its line length when the user >>> expands the help window horizontally. This behaviour is different to >>> that of the Python 3.6 help file (python360.chm) which adjusts its text >>> to fit the horizontal width of the help window. >>> >>> Is this a deliberate change or one that can be turned on or off in some >>> way (I prefer the Python 3.6 behaviour)? >> >> I believe that this is a deliberate regression imposed by 'experts' who >> believe in form over function and 'controlling the user experience'. >> 3.6.6 has been 'fixated' also. > > I think that's been reverted: > > https://github.com/python/cpython/commit/580c7db172a41d6311c0f3a7aec321597576e214 Yes, I wrote the blurb, merged it, and ordered and approved the backports. -- Terry Jan Reedy From arj.python at gmail.com Mon Jul 2 23:52:42 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 3 Jul 2018 07:52:42 +0400 Subject: .replace("a" or "b") Message-ID: that's another oddity i wanted to clear how do i know that string methods accept or and and in like .replace("a" or "b") i can't figure out how to deduce that it can accept that Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ From cs at cskk.id.au Tue Jul 3 01:10:36 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 3 Jul 2018 15:10:36 +1000 Subject: .replace("a" or "b") In-Reply-To: References: Message-ID: <20180703051036.GA42777@cskk.homeip.net> On 03Jul2018 07:52, Abdur-Rahmaan Janhangeer wrote: >that's another oddity i wanted to clear > >how do i know that string methods accept or and and in like .replace("a" or >"b") > >i can't figure out how to deduce that it can accept that Well, it accepts an expression like that, but it doesn't do what I think you think it does. Here's the help on str's replace method: >>> help(str.replace) Help on method_descriptor: replace(...) S.replace(old, new[, count]) -> str Return a copy of S with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced. So you're supplying a value for the "old" parameter. And what you're supplying is the _result_ of the expression: "a" or "b" So "replace" doesn't see a compound thing meaning 'replace "a" or replace "b"', it sees a single value. The "or" operator is a short circuiting operator, returning the first operand if it is true, otherwise the second. Since "a" is considered true ("" is false, all the nonempty strings are true), the result of: "a" or "b" is just "a". So replace() gets handed "a", and replaces instances of the string "a". The "b" never enters the picture. So there's no gap in the documentation for replace: it accepts an old string and a new string. When you write: "a" or "b" you're computing that value to pass to replace _before_ replace gets called. I hope this clarifies what's going on. Cheers, Cameron Simpson From greg.ewing at canterbury.ac.nz Tue Jul 3 02:03:53 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 Jul 2018 18:03:53 +1200 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: <87h8liepsa.fsf@elektro.pacujo.net> References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <877emif9d1.fsf@elektro.pacujo.net> <87h8liepsa.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Nevertheless, the later socket object cannot unilaterally take over a > socket using SO_REUSEADDR. The earlier socket object must have set the > same option previously. I just did an experiment that suggests that's not the case. I created a socket without SO_REUSEADDR, made a connection to it, and killed it. Then I created another socket within the timeout period with SO_REUSEADDR, and it succeeded. This was on MacOSX -- it's possible that other systems behave differently. -- Greg From greg.ewing at canterbury.ac.nz Tue Jul 3 02:12:57 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 Jul 2018 18:12:57 +1200 Subject: Multi-threading with a simple timer? In-Reply-To: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> References: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> Message-ID: David D wrote: > Is there a SIMPLE method that I can have a TIMER count down at a user input > prompt - if the user doesn't enter information within a 15 second period, it > times out. import signal, sys def timeout(*args): print("Too late!") sys.exit(0) signal.signal(signal.SIGALRM, timeout) signal.setitimer(signal.ITIMER_REAL, 15) data = input("Enter something: ") print("You entered: ", data) -- Greg From drsalists at gmail.com Tue Jul 3 02:49:27 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 2 Jul 2018 23:49:27 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: <0a06193d-5ba7-4ee2-20f0-57041e9557ab@gmail.com> References: <0a06193d-5ba7-4ee2-20f0-57041e9557ab@gmail.com> Message-ID: On Mon, Jul 2, 2018 at 6:10 PM, Jim Lee wrote: > On 07/02/18 17:34, Dan Stromberg wrote: > > The fact of the matter is the economics have changed a lot since then. > Machine time used to be really expensive compared to developer time. > Today, it's the opposite: developer time is really expensive compared to > machine time. > > > If you go back far enough, yes. But for the majority of the past, the > tradeoff was developer time vs time to market. That's why we had an > explosion of RAD tools in the '90s. It became more important to develop an > application *quickly* rather than *correctly*. And that philosophy > continues to this day. Python is a descendant of the RAD philosophy. > > (By correctly, I mean using the resources available in an efficient and > non-wasteful manner.) > Nod. It's really common for a startup to slap something together in a hurry, cutting corners all over, to secure funding. Then after they get the funding, they go back and fix the mess they created. This isn't shoddy craftsmanship. It's the reality of investment and first mover advantage. > It doesn't make much sense anymore to wring one's hands about "throwing" > more computer power at a problem. > > We've already hit a wall performance-wise. Physics only allows so many > electrons to flow through a nm-sized pipe. Now, the "solution" is to keep > adding more cores. But that doesn't help if an application doesn't lend > itself to a multi-threaded design. So, software efficiency will once again > become the bottleneck. > I'm inclined to agree that we've hit a bit of a wall in singlecore performance. We'll almost certainly blast past it at some point, but new physics may have to be explored first. However, singlecore performance is fast enough now that we don't have to obsess about minutia. I think soon a language like Haskell, OCaml, Scala, Clojure, etcetera will autoparallelize well. I'd love to see that be a Python implementation, but I'm not that confident it will be - Python has too many side effects for that to be likely. Fortunately, multithreading isn't the only way to take advantage of many cores. From drsalists at gmail.com Tue Jul 3 02:59:03 2018 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 2 Jul 2018 23:59:03 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On Mon, Jul 2, 2018 at 5:51 PM, Tim Daneliuk wrote: > In particular, there is little interest in having programmers > learn on the job, only that they be as productive as possible > as fast they can. Hiring specific languages skills - the theory > goes - means that the individual will be fluent in the entire > language ecosystem of libraries, tools, and so forth. What gets > lost in this factory model is that fewer and fewer people are able > to stand back and ask, "Are we even using a good design, language, > toolkit, ..." > One way of looking at it, is the employer doesn't want to hire someone and see them fail to come up to speed. It's not fun firing people - it may be the worst part of being a manager. Looked at this way, it's a kindness. Another way of looking at it, is shortsightedness on the part of the employer. A good developer can (and should be allowed to) learn new things. I think the most pragmatic view might be that employers _hire_ for specific skills, but when those skills are no longer needed as much, _then_ they talk about training on something new instead of firing a good developer and hiring another to fill a (somewhat?) similar role. I've seen a this happen. I don't mean to claim that this is always what happens. From robin at reportlab.com Tue Jul 3 03:36:43 2018 From: robin at reportlab.com (Robin Becker) Date: Tue, 3 Jul 2018 08:36:43 +0100 Subject: Multi-threading with a simple timer? In-Reply-To: References: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> Message-ID: On 03/07/2018 07:12, Gregory Ewing wrote: > import?signal,?sys > > def?timeout(*args): > ????print("Too?late!") > ????sys.exit(0) > > signal.signal(signal.SIGALRM,?timeout) > signal.setitimer(signal.ITIMER_REAL,?15) > data?=?input("Enter?something:?") > print("You?entered:?",?data) This doesn't work in windows (SIGALRM not available see https://stackoverflow.com/questions/6947065/right-way-to-run-some-code-with-timeout-in-python) For completeness I think it needs the handler restoring; this seemed to work for me in linux; I did try using SIG_DFL, but apparently that just prints 'Alarm clock' and exits at least import signal, sys, time def timeout(*args): print("Too late!") sys.exit(0) signal.signal(signal.SIGALRM, timeout) signal.setitimer(signal.ITIMER_REAL, 15) data = input("Enter something: ") signal.signal(signal.SIGALRM,signal.SIG_IGN) print("You entered: ", data) for i in reversed(xrange(15)): print i time.sleep(1) print 'finished!' if I leave out the signal.signal(signal.SIGALRM,signal.SIG_IGN) then the timeout function gets called anyway. -- Robin Becker From greg.ewing at canterbury.ac.nz Tue Jul 3 03:37:56 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 Jul 2018 19:37:56 +1200 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > "Jack of all trades, master of none" sort of thing? > > Or are you thinking more along the lines of one of those guys who masters > a new language in an hour and reaches expert level in a week? I'm not talking about someone who hasn't mastered anything. I'm talking about someone who has mastered the art of programming in general. Such a person can learn enough about an unfamiliar language to do something useful with it in quite a short time. > why pay somebody to > learn the language at full senior rates when there are millions of senior > developers who already know the language? If they're truly a seasoned programmer, you'll get your money's worth out of them long before they've mastered every nook and cranny of the language. Whereas if you hire a total greenhorn who knows Java on paper but has no practical programming experience, you'll be paying them for quite a while before they're doing you more good than harm. If you can find someone who's both a seasoned developer *and* experienced in the particular language required, that's a bonus, but only a small one. Also, it assumes you can find two people who are both equally experienced, except that one knows Java and the other doesn't. My conjecture is that given two people, who have been programming for the same length of time, one of which knows a wide variety of languages other than Java, and one that knows *only* Java, the one that knows multiple languages will almost certainly be a better programmer, and will be better value for money *even though* it will take him a little bit of time to pick up Java. -- Greg From steve+comp.lang.python at pearwood.info Tue Jul 3 04:34:23 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 3 Jul 2018 08:34:23 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On Mon, 02 Jul 2018 18:20:53 -0700, Jim Lee wrote: > On 07/02/18 17:51, Steven D'Aprano wrote: >> >> For most of us mere mortals, the "ten thousand hours" rule of thumb >> applies. >> >> Ten thousand hours should be read as an indefinitely large number >> >>> A truly good programmer will be able to learn about the language being >>> used on the job. >> Indeed, if you don't mind paying them for the couple of weeks it takes >> them to come up to speed on the language and the couple of years it >> takes to master it. > > So we went from 10,000 hours, to infinite, and then back to a couple of > years? I said *indefinite* not infinite. You did read the article I linked to, right? You know that people don't suddenly and instantly turn from "beginner" to "expert" when they exceed 9,999 hours 59 minutes and 59 seconds? Quibbling over the exact number of hours is foolish. Ten thousand hours is a nice round number, and should not be considered more precise than an order of magnitude estimate ("more than 1000 hours, less than 100,000 hours, on average"). But for what it's worth, if you estimate that the average dedicated developer programs 8 hours a day for 330 days a year, between paid work, overtime, private projects, and directed study, 10,000 hours works out at a bit less than four years. Or as my wife would say, "did you mean an Aussie couple or an actual couple?" I meant an Aussie couple, which could be anything from two to four or five. Six at a stretch. As in, "no worries mate, it'll be ready in a coupla days." -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From greg.ewing at canterbury.ac.nz Tue Jul 3 05:45:36 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 03 Jul 2018 21:45:36 +1200 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: Mikhail V wrote: > s= "\"s\"" -> > s= {"s"} But now you need to find another way to represent set literals. -- Greg From mal at europython.eu Tue Jul 3 06:49:00 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Tue, 3 Jul 2018 12:49:00 +0200 Subject: EuroPython 2018: Schedule available Message-ID: Over the last few weeks, our program WG has been working hard on getting the schedule all lined up. Today, we?re releasing it to the Python world. Schedule for EuroPython 2018 * https://ep2018.europython.eu/en/events/schedule/ * With 140 speakers and more than 150 sessions, we have a full packed program waiting for you. Please note that the schedule may still change in details, but the overall layout is fixed now. Book your EuroPython 2018 Ticket -------------------------------- Please make sure you book your ticket in the coming days. We will switch to late bird rates closer to the event. If you want to attend the training sessions, please buy a training pass. We only have very few left and will close sales for these later this week. Travel & accommodation tips --------------------------- Since we?re close the conference and The Fringe is starting a week later, Edinburgh is in high demand. If you?re having problems finding a hotel, please also consider searching for apartments on the well known booking sites. For traveling to Edinburgh, we suggest also considering a combination of plane and train or bus. London, Birmingham and Manchester all provide train and bus lines going to Edinburgh and by booking a combination, you can often save a lot, compared to a direct flight to Edinburgh. 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/175502948797/europython-2018-schedule-available Tweet: https://twitter.com/europython/status/1014097708536221696 Enjoy, -- EuroPython Society https://ep2018.europython.eu/ https://www.europython-society.org/ From info at egenix.com Tue Jul 3 07:54:49 2018 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 3 Jul 2018 13:54:49 +0200 Subject: =?UTF-8?Q?ANN:_Python_Meeting_D=c3=bcsseldorf_-_04.07.2018?= Message-ID: <129c982c-7069-8f5c-9628-d08f62ad11ca@egenix.com> [This announcement is in German since it targets a local user group meeting in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG Python Meeting D?sseldorf http://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Mittwoch, 04.07.2018, 18:00 Uhr Raum 1, 2.OG im B?rgerhaus Stadtteilzentrum Bilk D?sseldorfer Arcaden, Bachstr. 145, 40217 D?sseldorf Diese Nachricht ist auch online verf?gbar: https://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2018-07-04 ________________________________________________________________________ NEUIGKEITEN * Bereits angemeldete Vortr?ge: Charlie Clark "Managing package metadata and dynamically loading modules" Tobey Announced "Trading mit Python" Charlie Clark "Einleitung ins Testing" Weitere Vortr?ge k?nnen gerne noch angemeldet werden: info at pyddf.de * Startzeit und Ort: Wir treffen uns um 18:00 Uhr im B?rgerhaus in den D?sseldorfer Arcaden. Das B?rgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet sich an der Seite der Tiefgarageneinfahrt der D?sseldorfer Arcaden. ?ber dem Eingang steht ein gro?es "Schwimm' in Bilk" Logo. Hinter der T?r direkt links zu den zwei Aufz?gen, dann in den 2. Stock hochfahren. Der Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt. Google Street View: http://bit.ly/11sCfiw ________________________________________________________________________ EINLEITUNG Das Python Meeting D?sseldorf ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: * http://pyddf.de/ Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: * http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ ________________________________________________________________________ PROGRAMM Das Python Meeting D?sseldorf nutzt eine Mischung aus (Lightning) Talks und offener Diskussion. Vortr?ge k?nnen vorher angemeldet werden, oder auch spontan w?hrend des Treffens eingebracht werden. Ein Beamer mit XGA Aufl?sung steht zur Verf?gung. (Lightning) Talk Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ KOSTENBETEILIGUNG Das Python Meeting D?sseldorf wird von Python Nutzern f?r Python Nutzer veranstaltet. Um die Kosten zumindest teilweise zu refinanzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,00 inkl. 19% Mwst, Sch?ler und Studenten zahlen EUR 5,00 inkl. 19% Mwst. Wir m?chten alle Teilnehmer bitten, den Betrag in bar mitzubringen. ________________________________________________________________________ ANMELDUNG Da wir nur f?r ca. 20 Personen Sitzpl?tze haben, m?chten wir bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen. Es erleichtert uns allerdings die Planung. Meeting Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ WEITERE INFORMATIONEN Weitere Informationen finden Sie auf der Webseite des Meetings: http://pyddf.de/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Jul 03 2018) >>> Python Projects, Coaching and Consulting ... http://www.egenix.com/ >>> Python Database Interfaces ... http://products.egenix.com/ >>> Plone/Zope Database Interfaces ... http://zope.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ http://www.malemburg.com/ From mikhailwas at gmail.com Tue Jul 3 08:06:50 2018 From: mikhailwas at gmail.com (Mikhail V) Date: Tue, 3 Jul 2018 15:06:50 +0300 Subject: File names with slashes [was Re: error in os.chdir] Message-ID: Greg wrote: > Mikhail V wrote: > > s= "\"s\"" -> > > s= {"s"} > > But now you need to find another way to represent set literals. I need to find? That comment was not about (current) Python but rather how I think string should have been from the beginning. So you already like it and want in Python ? :-) Fitting it into current Python would need some prefix e.g. s = !{hello} From marko at pacujo.net Tue Jul 3 08:26:58 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 03 Jul 2018 15:26:58 +0300 Subject: EXTERNAL: OSError: [Errno 48] Address already in use References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <877emif9d1.fsf@elektro.pacujo.net> <87h8liepsa.fsf@elektro.pacujo.net> Message-ID: <87r2kk33ot.fsf@elektro.pacujo.net> Gregory Ewing : > Marko Rauhamaa wrote: >> Nevertheless, the later socket object cannot unilaterally take over a >> socket using SO_REUSEADDR. The earlier socket object must have set the >> same option previously. > > I just did an experiment that suggests that's not the case. > I created a socket without SO_REUSEADDR, made a connection to > it, and killed it. Then I created another socket within the > timeout period with SO_REUSEADDR, and it succeeded. > > This was on MacOSX -- it's possible that other systems > behave differently. I tried it, too, (on Linux) and it failed. It's crucial that the killed party is the server for the situation to arise. That's why polite clients close their end of the connection before the server. Whoever closes first will suffer the TIME-WAIT state. Marko From robin at reportlab.com Tue Jul 3 08:54:55 2018 From: robin at reportlab.com (Robin Becker) Date: Tue, 3 Jul 2018 13:54:55 +0100 Subject: Python 3.7 configuration issue Message-ID: On a Ubuntu trusty system I ran ./configure --prefix=/home/rptlab/PYTHON make && make install and get an error related to the ctypes module not being importable. I needed to do sudo apt-get install libffi-dev ./configure --prefix=/home/rptlab/PYTHON --with-system-ffi make && make install Something in setup.py seems to want ctypes irrespective of what I give to configure; I don't actually know what the alternative to --with-system-ffi does, but it didn't work for me. -- Robin Becker From michael.vilain at gmail.com Tue Jul 3 09:06:40 2018 From: michael.vilain at gmail.com (Michael Vilain) Date: Tue, 3 Jul 2018 06:06:40 -0700 Subject: Multi-threading with a simple timer? In-Reply-To: References: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> Message-ID: Won't this code send a signal *regardless* of the user input to the process within 15 seconds. I don't see how it's tied to terminal input. From what I can tell, you need to create your own version of input with a timeout option. This doesn't do that. -- Michael Vilain 650-322-6755 > On 02-Jul-2018, at 11:12 PM ?, Gregory Ewing wrote: > > David D wrote: >> Is there a SIMPLE method that I can have a TIMER count down at a user input >> prompt - if the user doesn't enter information within a 15 second period, it >> times out. > > import signal, sys > > def timeout(*args): > print("Too late!") > sys.exit(0) > > signal.signal(signal.SIGALRM, timeout) > signal.setitimer(signal.ITIMER_REAL, 15) > data = input("Enter something: ") > print("You entered: ", data) > > -- > Greg > -- > https://mail.python.org/mailman/listinfo/python-list From greg.ewing at canterbury.ac.nz Tue Jul 3 09:25:21 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 04 Jul 2018 01:25:21 +1200 Subject: Multi-threading with a simple timer? In-Reply-To: References: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> Message-ID: Robin Becker wrote: > if I leave out the signal.signal(signal.SIGALRM,signal.SIG_IGN) then the > timeout function gets called anyway. Yes, it needs some more stuff around it to make it useful. Probably you also want the signal handler to raise an exception and catch it somewhere rather than exiting the process. -- Greg From rosuav at gmail.com Tue Jul 3 09:35:57 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Jul 2018 23:35:57 +1000 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On Tue, Jul 3, 2018 at 6:34 PM, Steven D'Aprano wrote: > Or as my wife would say, "did you mean an Aussie couple or an actual > couple?" I meant an Aussie couple, which could be anything from two to > four or five. Six at a stretch. As in, "no worries mate, it'll be ready > in a coupla days." cf https://xkcd.com/1070/ ChrisA From bc at freeuk.com Tue Jul 3 09:36:23 2018 From: bc at freeuk.com (Bart) Date: Tue, 3 Jul 2018 14:36:23 +0100 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 01/07/2018 18:06, Abdur-Rahmaan Janhangeer wrote: > was viewing pep526, so, finally, python cannot do without hinting the type > as other languages? > will python finally move to > int x = 3 where int is a pre annotation? > > i am not arguing it's usefulness but rather, does it fit with python? Not in my opinion. Just more of the kind of clutter that people turn to Python to avoid. But it might suit a statically typed language with Python-like syntax, as some people prefer it to the syntax of their actual typed language. -- bart From rosuav at gmail.com Tue Jul 3 09:40:45 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 3 Jul 2018 23:40:45 +1000 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: <87r2kk33ot.fsf@elektro.pacujo.net> References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <877emif9d1.fsf@elektro.pacujo.net> <87h8liepsa.fsf@elektro.pacujo.net> <87r2kk33ot.fsf@elektro.pacujo.net> Message-ID: On Tue, Jul 3, 2018 at 10:26 PM, Marko Rauhamaa wrote: > Gregory Ewing : > >> Marko Rauhamaa wrote: >>> Nevertheless, the later socket object cannot unilaterally take over a >>> socket using SO_REUSEADDR. The earlier socket object must have set the >>> same option previously. >> >> I just did an experiment that suggests that's not the case. >> I created a socket without SO_REUSEADDR, made a connection to >> it, and killed it. Then I created another socket within the >> timeout period with SO_REUSEADDR, and it succeeded. >> >> This was on MacOSX -- it's possible that other systems >> behave differently. > > I tried it, too, (on Linux) and it failed. > > It's crucial that the killed party is the server for the situation to > arise. > > That's why polite clients close their end of the connection before > the server. Whoever closes first will suffer the TIME-WAIT state. The same thing can happen with clients AND servers, but it's very common with clients to allow an arbitrary port number to be chosen for you. To trigger this problem from the client end, you would need to use the same port. An attacker can do this easily. ChrisA From gheskett at shentel.net Tue Jul 3 09:46:25 2018 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 3 Jul 2018 09:46:25 -0400 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: <201807030946.25116.gheskett@shentel.net> On Tuesday 03 July 2018 09:32:52 Dennis Lee Bieber wrote: > On Mon, 2 Jul 2018 19:51:29 -0500, Tim Daneliuk > > declaimed the following: > >Except that the current attempt is to use techniques like agile, > >scrum, pair programming, and so forth to turn programming into > >a factory activity. High degrees of specialization are segmented > >by architectural role (front end, back end, infrastructure, > >DevOps ...), language, and even business unit. In my view, > >systems architecture, software design, and non functional > >capabilities suffer thereby, but I am old and crabby :) > > Where do I join the "old and crabby" club? You become a member automatically when you've accumulated enough birthdays. I'm 83, and it just sorta sneaks up on you while you're busy with life. > > After 30 years with a DOD contractor where things went through PDR, > CDR (and often separate sets for requirements, followed by design, > followed by implementation), my last four years were in an environment > as you describe above -- where the requirements seemed to be written > based upon what the implementation of the week performed... > Thats horrible, you never know what the true target is. And realizing it makes you a member of the club. > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com HTTP://wlfraed.home.netcom.com/ -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From marko at pacujo.net Tue Jul 3 10:01:12 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 03 Jul 2018 17:01:12 +0300 Subject: EXTERNAL: OSError: [Errno 48] Address already in use References: <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <877emif9d1.fsf@elektro.pacujo.net> <87h8liepsa.fsf@elektro.pacujo.net> <87r2kk33ot.fsf@elektro.pacujo.net> Message-ID: <87muv82zbr.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Jul 3, 2018 at 10:26 PM, Marko Rauhamaa wrote: >> It's crucial that the killed party is the server for the situation to >> arise. >> >> That's why polite clients close their end of the connection before >> the server. Whoever closes first will suffer the TIME-WAIT state. > > The same thing can happen with clients AND servers, but it's very > common with clients to allow an arbitrary port number to be chosen for > you. To trigger this problem from the client end, you would need to > use the same port. An attacker can do this easily. No, I mean that the TIME-WAIT state is triggered asymmetrically. See RFC 793 page 23. Whoever sends FIN first will end up in TIME-WAIT for 2*MSL. A client that doesn't send FIN first will cause an accumulation of connection objects (TCBs) at the server end. It can also prevent the server from being restarted quickly. The SO_REUSEADDR discussion has no direct relationship with computer or network security. In fact, I don't see any reason why it's not always on for TCP. Maybe it's done so UDP and TCP (and other protocols) would work similarly. Marko From marko at pacujo.net Tue Jul 3 10:05:32 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 03 Jul 2018 17:05:32 +0300 Subject: Multi-threading with a simple timer? References: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> Message-ID: <87in5w2z4j.fsf@elektro.pacujo.net> Gregory Ewing : > Robin Becker wrote: >> if I leave out the signal.signal(signal.SIGALRM,signal.SIG_IGN) then >> the timeout function gets called anyway. > > Yes, it needs some more stuff around it to make it useful. Probably > you also want the signal handler to raise an exception and catch it > somewhere rather than exiting the process. My advice: stay away from (non-terminal) signals. They are a primitive communication scheme that *might* have had uses in the early 1970's. At the time signals were part of so-called "asynchronous programming." The pattern called for the main routine to have: for (;;) pause() and *everything* in the program was done in signal handlers. Unless you do *everything* in signal handlers, you should do *nothing* in signal handlers. Marko From grant.b.edwards at gmail.com Tue Jul 3 10:24:26 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 3 Jul 2018 14:24:26 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On 2018-07-03, Dan Stromberg wrote: > I used to write useful programs that ran in 256 bytes of RAM. Me too. Less than 10 years ago. In a real product. That's still shipping. -- Grant Edwards grant.b.edwards Yow! Are you mentally here at at Pizza Hut?? gmail.com From grant.b.edwards at gmail.com Tue Jul 3 10:38:23 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 3 Jul 2018 14:38:23 +0000 (UTC) Subject: EXTERNAL: OSError: [Errno 48] Address already in use References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <877emif9d1.fsf@elektro.pacujo.net> <87h8liepsa.fsf@elektro.pacujo.net> Message-ID: On 2018-07-01, Marko Rauhamaa wrote: > Gregory Ewing : > >> I don't see how the address-reuse timeout can be a security measure, >> because the process trying to take over the address can easily >> circumvent it by setting SO_REUSEADDR. > > [...] > > Nevertheless, the later socket object cannot unilaterally take over a > socket using SO_REUSEADDR. The earlier socket object must have set the > same option previously. On what OS? In my experience, that's not true on Linux or BSD Unix. -- Grant Edwards grant.b.edwards Yow! Yes, but will I at see the EASTER BUNNY in gmail.com skintight leather at an IRON MAIDEN concert? From grant.b.edwards at gmail.com Tue Jul 3 10:45:24 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 3 Jul 2018 14:45:24 +0000 (UTC) Subject: EXTERNAL: OSError: [Errno 48] Address already in use References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <877emif9d1.fsf@elektro.pacujo.net> <87h8liepsa.fsf@elektro.pacujo.net> Message-ID: On 2018-07-03, Grant Edwards wrote: > On 2018-07-01, Marko Rauhamaa wrote: >> Gregory Ewing : >> >>> I don't see how the address-reuse timeout can be a security measure, >>> because the process trying to take over the address can easily >>> circumvent it by setting SO_REUSEADDR. >> >> [...] >> >> Nevertheless, the later socket object cannot unilaterally take over a >> socket using SO_REUSEADDR. The earlier socket object must have set the >> same option previously. > > On what OS? In my experience, that's not true on Linux or BSD Unix. I was wrong. I just did a quick test on Linux, and it works the way Marko Hauhamaa describes. [Don't have handy access to a BSD system at the moment.] -- Grant Edwards grant.b.edwards Yow! I'm wearing PAMPERS!! at gmail.com From grant.b.edwards at gmail.com Tue Jul 3 10:55:05 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 3 Jul 2018 14:55:05 +0000 (UTC) Subject: EXTERNAL: OSError: [Errno 48] Address already in use References: <616c1e2beebc44fe8161125767f7ff33@BSKEXCH2013HYPV.mwrinfosecurity.com> <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <877emif9d1.fsf@elektro.pacujo.net> <87h8liepsa.fsf@elektro.pacujo.net> Message-ID: On 2018-07-03, Grant Edwards wrote: > On 2018-07-03, Grant Edwards wrote: >> On 2018-07-01, Marko Rauhamaa wrote: >>> Gregory Ewing : >>> >>>> I don't see how the address-reuse timeout can be a security measure, >>>> because the process trying to take over the address can easily >>>> circumvent it by setting SO_REUSEADDR. >>> >>> [...] >>> >>> Nevertheless, the later socket object cannot unilaterally take over a >>> socket using SO_REUSEADDR. The earlier socket object must have set the >>> same option previously. >> >> On what OS? In my experience, that's not true on Linux or BSD Unix. > > I was wrong. I just did a quick test on Linux, and it works the way > Marko Hauhamaa describes. Um that was supposed to be Rauhamaa... sorry about that. > [Don't have handy access to a BSD system at the moment.] Found a NetBSD 7.1 system to test on... After killing a server with an active connection, a new server can bind to the same socket regardless of the SO_REUSEADDR setting in either server. I don't know if that's some sort of system configuration setting or what... -- Grant Edwards grant.b.edwards Yow! Where's the Coke at machine? Tell me a joke!! gmail.com From rosuav at gmail.com Tue Jul 3 11:21:03 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Jul 2018 01:21:03 +1000 Subject: Multi-threading with a simple timer? In-Reply-To: <87in5w2z4j.fsf@elektro.pacujo.net> References: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> <87in5w2z4j.fsf@elektro.pacujo.net> Message-ID: On Wed, Jul 4, 2018 at 12:05 AM, Marko Rauhamaa wrote: > Gregory Ewing : > >> Robin Becker wrote: >>> if I leave out the signal.signal(signal.SIGALRM,signal.SIG_IGN) then >>> the timeout function gets called anyway. >> >> Yes, it needs some more stuff around it to make it useful. Probably >> you also want the signal handler to raise an exception and catch it >> somewhere rather than exiting the process. > > My advice: stay away from (non-terminal) signals. They are a primitive > communication scheme that *might* have had uses in the early 1970's. > > At the time signals were part of so-called "asynchronous programming." > The pattern called for the main routine to have: > > for (;;) > pause() > > and *everything* in the program was done in signal handlers. > > Unless you do *everything* in signal handlers, you should do *nothing* > in signal handlers. Yeah, signal handlers are utterly useless. You never want to use them to receive messages from the operating system in a process-independent way. The fact that it's possible to use them badly means that we should abolish them completely and never use them, like ever. It's not like they're a really effective way for you to be notified that you no longer have a controlling terminal, thus permitting you to decide whether to continue or terminate. It's not like they're a standard way for the user to say "please interrupt this operation", thus allowing you to cleanly break off what you're doing and return to the main loop. No, signal handlers are utterly useless, and only MIGHT have had uses forty years ago. They're completely and utterly outmoded by modern systems that use HTTP and XML to send easy-to-use messages between processes. ChrisA From brgrt2 at gmail.com Tue Jul 3 11:49:23 2018 From: brgrt2 at gmail.com (T Berger) Date: Tue, 3 Jul 2018 08:49:23 -0700 (PDT) Subject: Getting posts to sort chronologically in tree view In-Reply-To: References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> Message-ID: <98abdd90-dac0-4e15-934f-47c33074ac3a@googlegroups.com> On Monday, July 2, 2018 at 2:36:00 PM UTC-4, Dan Stromberg wrote: > On Mon, Jul 2, 2018 at 11:02 AM, T Berger wrote: > > > Is there any way to set posts to appear chronologically in tree view? And > > why is the tree view completely out of order? My last two posts in this > > view are from 6/27 and 6/28. > > > > I'm thinking you may want to specify what software you're talking about. > If it's software for reading python-list, we don't all use the same > programs. Hi Dan, I'm posting directly to the forum (computer.lang.python, at this web address: https://groups.google.com/forum/#!topic/comp.lang.python/vWCvLYjOWUQ) and also following up on my posts here. And I have to apologize. The threads in my previous conversation, ERRNO 48: Address already in use, are so extensive and hierarchical, that they appear to be out of order. They're not. It's just that you guys continue talking amongst yourselves off my topic, so my last posts always get lost somewhere in the middle of the threads. Once I carefully followed the tree, I found that everything was listed chronologically. It would help if my conversations showed up in my gmail, but they don't. I thought that would happen when I chose the "Automatically subscribe me to email updates when I post to a topic" option in the forum settings. Am I wrong? And is there some way to have my conversations appear in both sites? Thanks, Tamara From steve+comp.lang.python at pearwood.info Tue Jul 3 11:51:12 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 3 Jul 2018 15:51:12 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On Tue, 03 Jul 2018 14:24:26 +0000, Grant Edwards wrote: > On 2018-07-03, Dan Stromberg wrote: > >> I used to write useful programs that ran in 256 bytes of RAM. > > Me too. > > Less than 10 years ago. > > In a real product. > > That's still shipping. Well don't be shy. Got a link? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From tjol at tjol.eu Tue Jul 3 11:59:00 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 3 Jul 2018 17:59:00 +0200 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: On 2018-07-03 14:06, Mikhail V wrote: > Greg wrote: > >> Mikhail V wrote: >>> s= "\"s\"" -> >>> s= {"s"} >> >> But now you need to find another way to represent set literals. > > > I need to find? That comment was not about (current) Python but > rather how I think string should have been from the beginning. > > So you already like it and want in Python ? :-) > Fitting it into current Python would need some prefix e.g. > > s = !{hello} Nothing new under the sun. Our old frenemy Perl has q{abc""} == "abc\"\"" q`{}` == "{}" Perl's sexy Japanese alter-ego Ruby has %Q{}, %q{}. I'm sure there are more. From jlee54 at gmail.com Tue Jul 3 12:14:37 2018 From: jlee54 at gmail.com (Jim Lee) Date: Tue, 3 Jul 2018 09:14:37 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> On 07/03/18 01:34, Steven D'Aprano wrote: > I said *indefinite* not infinite. Yes, you did.? My bad. > You did read the article I linked to, right? You know that people don't > suddenly and instantly turn from "beginner" to "expert" when they exceed > 9,999 hours 59 minutes and 59 seconds? Quibbling over the exact number of > hours is foolish. Of course I know that.? I've been familiar with the concept for a long time.? I've taught several guitarists and have seen it first hand.? I've also trained several programmers. Quibbling over the exact number of hours *is* foolish - but nobody was doing that.? I was simply pointing out that you used three vastly different numbers in almost the same breath to describe how long it takes a person to master something. I think we both get the idea - let's back out of this rabbit trail before we get lost, ok? :) -Jim From grant.b.edwards at gmail.com Tue Jul 3 12:28:37 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 3 Jul 2018 16:28:37 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On 2018-07-03, Steven D'Aprano wrote: > On Tue, 03 Jul 2018 14:24:26 +0000, Grant Edwards wrote: >> On 2018-07-03, Dan Stromberg wrote: >> >>> I used to write useful programs that ran in 256 bytes of RAM. >> >> Me too. >> >> Less than 10 years ago. >> >> In a real product. >> >> That's still shipping. > > Well don't be shy. Got a link? http://www.emerson.com/en-us/catalog/emerson-775-wireless-thum-adapter One of the processors inside (there are three) is a low-end version MSP430 with, either 128 or 256 bytes of RAM (I forget which). -- Grant Edwards grant.b.edwards Yow! I'm also pre-POURED at pre-MEDITATED and gmail.com pre-RAPHAELITE!! From jlee54 at gmail.com Tue Jul 3 12:35:38 2018 From: jlee54 at gmail.com (Jim Lee) Date: Tue, 3 Jul 2018 09:35:38 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 07/03/18 06:32, Dennis Lee Bieber wrote: > On Mon, 2 Jul 2018 19:51:29 -0500, Tim Daneliuk > declaimed the following: > >> Except that the current attempt is to use techniques like agile, >> scrum, pair programming, and so forth to turn programming into >> a factory activity. High degrees of specialization are segmented >> by architectural role (front end, back end, infrastructure, >> DevOps ...), language, and even business unit. In my view, >> systems architecture, software design, and non functional >> capabilities suffer thereby, but I am old and crabby :) >> > Where do I join the "old and crabby" club? > > After 30 years with a DOD contractor where things went through PDR, CDR > (and often separate sets for requirements, followed by design, followed by > implementation), my last four years were in an environment as you describe > above -- where the requirements seemed to be written based upon what the > implementation of the week performed... > > Welcome to the club, Dennis!? My last four years were also as Tim described, and that's what made me decide to retire early. Another trend is that, with the high degree of compartmentalization, many of the programming jobs are now being farmed out overseas as black box bids.? After I retired, my team was sent to China to "train" a new group (read brain dump), and was then summarily disbanded. -Jim From daviddschool at gmail.com Tue Jul 3 12:43:09 2018 From: daviddschool at gmail.com (David D) Date: Tue, 3 Jul 2018 09:43:09 -0700 (PDT) Subject: Multi-threading with a simple timer? In-Reply-To: References: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> Message-ID: <477eb8b9-703e-484a-afde-daba46e10e99@googlegroups.com> This works, but does not do exactly what I want. When the user enters in a correct answer, the program and threading stops. Any ideas on what I should change? import time from threading import Thread class Answer(Thread): def run(self): a=input("What is your answer:") if a=="yes": print("yes you got it") finished() else: print("no") class myTimer(Thread): def run(self): print() for x in range(5): time.sleep(1) Answer().start() myTimer().start() print("you lost") def finished(): print("done") From daviddschool at gmail.com Tue Jul 3 12:44:25 2018 From: daviddschool at gmail.com (David D) Date: Tue, 3 Jul 2018 09:44:25 -0700 (PDT) Subject: Multi-threading with a simple timer? In-Reply-To: References: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> Message-ID: <27129584-3b0d-4032-b1d0-30ef6cd8c143@googlegroups.com> This works, but does not do exactly what I want. What I want to happen is : when the user enters in a correct answer, the program and threading stops. Any ideas on what I should change? import time from threading import Thread class Answer(Thread): def run(self): a=input("What is your answer:") if a=="yes": print("yes you got it") finished() else: print("no") class myTimer(Thread): def run(self): print() for x in range(5): time.sleep(1) Answer().start() myTimer().start() print("you lost") def finished(): print("done") From jlee54 at gmail.com Tue Jul 3 12:45:04 2018 From: jlee54 at gmail.com (Jim Lee) Date: Tue, 3 Jul 2018 09:45:04 -0700 Subject: Getting posts to sort chronologically in tree view In-Reply-To: <98abdd90-dac0-4e15-934f-47c33074ac3a@googlegroups.com> References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> <98abdd90-dac0-4e15-934f-47c33074ac3a@googlegroups.com> Message-ID: <12567d72-d427-c061-3dba-654be8e55de9@gmail.com> On 07/03/18 08:49, T Berger wrote: > > It would help if my conversations showed up in my gmail, but they don't. I thought that would happen when I chose the "Automatically subscribe me to email updates when I post to a topic" option in the forum settings. Am I wrong? And is there some way to have my conversations appear in both sites? > > Thanks, > > Tamara For what it's worth, I don't get my own posts via email either, and I have that explicitly enabled in my subscription settings. -Jim From Richard at Damon-Family.org Tue Jul 3 13:58:58 2018 From: Richard at Damon-Family.org (Richard Damon) Date: Tue, 3 Jul 2018 10:58:58 -0700 Subject: Getting posts to sort chronologically in tree view In-Reply-To: <12567d72-d427-c061-3dba-654be8e55de9@gmail.com> References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> <98abdd90-dac0-4e15-934f-47c33074ac3a@googlegroups.com> <12567d72-d427-c061-3dba-654be8e55de9@gmail.com> Message-ID: <8071b284-83a1-b106-7e9f-38e043de581f@Damon-Family.org> On 7/3/18 9:45 AM, Jim Lee wrote: > > > On 07/03/18 08:49, T Berger wrote: >> >> ? It would help if my conversations showed up in my gmail, but they >> don't. I thought that would happen when I chose the "Automatically >> subscribe me to email updates when I post to a topic" option in the >> forum settings. Am I wrong? And is there some way to have my >> conversations appear in both sites? >> >> Thanks, >> >> Tamara > > For what it's worth, I don't get my own posts via email either, and I > have that explicitly enabled in my subscription settings. > > -Jim > Jim, That's a 'feature' of gmail, it automatically suppresses duplicate copies of messages (even if not identical) and considers the version back from the list to be a duplicate of the one you sent. -- Richard Damon From akkana at shallowsky.com Tue Jul 3 14:29:03 2018 From: akkana at shallowsky.com (Akkana Peck) Date: Tue, 3 Jul 2018 12:29:03 -0600 Subject: Multi-threading with a simple timer? In-Reply-To: References: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> Message-ID: <20180703182903.GC1204@shallowsky.com> David D wrote: > Is there a SIMPLE method that I can have a TIMER count down at a user input > prompt - if the user doesn't enter information within a 15 second period, it > times out. Does this do what you want? from threading import Timer import sys import os def run_later(): print("Timed out!") # sys.exit doesn't kill the main thread, but os._exit does. os._exit(1) if __name__ == '__main__': t = Timer(15, run_later) t.start() ans = input("Enter something, or time out in 15 seconds: ") print("You entered", ans) t.cancel() sys.exit(0) The only problem with that is if you want to continue with execution after the timeout (you didn't say what you want to do in that case). I couldn't find any straightforward way to interrupt the main thread in a way that interrupts the input(). There's something called _thread.interrupt_main() but it doesn't seem to work with threading.Timer threads; maybe it would work if you created the timer thread using _thread. Or signals, of course, as already discussed. ...Akkana From michael.vilain at gmail.com Tue Jul 3 15:32:03 2018 From: michael.vilain at gmail.com (Michael Vilain) Date: Tue, 3 Jul 2018 12:32:03 -0700 Subject: Multi-threading with a simple timer? In-Reply-To: References: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> <87in5w2z4j.fsf@elektro.pacujo.net> Message-ID: The way I've done the "input with timeout" requirement the OP requested is dependent on the operating system. The current implementation of the input function doesn't offer that feature. https://docs.python.org/3/library/functions.html#input In another language, I used low-levelsystem calls to the OS to get terminal assigned to the process running the program, open the terminal for read, and set a time-out for that read. This is by no means portable. I looked at the os.open() method and it doesn't offer a timeout option. Then I found curses. That has a getch() function that can be setup with a halfdelay() timer. https://docs.python.org/3/howto/curses.html That's the closest I could find to getting input with a time-out from the terminal. If it's to kludgy, you'll have to roll your own OS-specific version. My guess is that Windows and Linux (and whatever else you choose to implement) are different. Got code? -- Anything invented before you were eighteen was there all along. Anything invented before you?re thirty is exciting and will change the world forever. Anything invented after that is an abomination and should be banned. -- Cory Doctorow > On 03-Jul-2018, at 8:21 AM ?, Chris Angelico wrote: > > On Wed, Jul 4, 2018 at 12:05 AM, Marko Rauhamaa wrote: >> Gregory Ewing : >> >>> Robin Becker wrote: >>>> if I leave out the signal.signal(signal.SIGALRM,signal.SIG_IGN) then >>>> the timeout function gets called anyway. >>> >>> Yes, it needs some more stuff around it to make it useful. Probably >>> you also want the signal handler to raise an exception and catch it >>> somewhere rather than exiting the process. >> >> My advice: stay away from (non-terminal) signals. They are a primitive >> communication scheme that *might* have had uses in the early 1970's. >> >> At the time signals were part of so-called "asynchronous programming." >> The pattern called for the main routine to have: >> >> for (;;) >> pause() >> >> and *everything* in the program was done in signal handlers. >> >> Unless you do *everything* in signal handlers, you should do *nothing* >> in signal handlers. > > Yeah, signal handlers are utterly useless. You never want to use them > to receive messages from the operating system in a process-independent > way. The fact that it's possible to use them badly means that we > should abolish them completely and never use them, like ever. It's not > like they're a really effective way for you to be notified that you no > longer have a controlling terminal, thus permitting you to decide > whether to continue or terminate. It's not like they're a standard way > for the user to say "please interrupt this operation", thus allowing > you to cleanly break off what you're doing and return to the main > loop. No, signal handlers are utterly useless, and only MIGHT have had > uses forty years ago. They're completely and utterly outmoded by > modern systems that use HTTP and XML to send easy-to-use messages > between processes. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From saxri89 at gmail.com Tue Jul 3 15:41:20 2018 From: saxri89 at gmail.com (Xristos Xristoou) Date: Tue, 3 Jul 2018 12:41:20 -0700 (PDT) Subject: django-raster rendering raster url Message-ID: i want to add raster functionality in django using postgis database using django-raster package and this docs http://django-raster.readthedocs.io/en/latest/tms.html here my code : models.py from django.contrib.gis.db import models class RasterWithName(models.Model): raster = models.RasterField() name = models.TextField() add raster using console : from django.contrib.gis.gdal import GDALRaster from myapp.models import RasterWithName gdal_raster = GDALRaster('C:/Users/username/Desktop/image.tif') rast = RasterWithName(name='one', raster=gdal_raster) rast.save() but i am very confused with Rendering tiles and urls. docs say : /raster/tiles/layer_id/{z}/{x}/{y}.png where the layer_id is the primary key of a raster layer. This structure can be used directly in online mapping software such as OpenLayers or Leaflet. An example request could look like this: /raster/tiles/23/8/536/143.png, returning a tile in png format of the layer with ID pk=23 at zoom level z=8 and indexes x=536 and y=143 but indexes x,y mean some random x,y coordinate in image ?anyway i using this url http://127.0.0.1:8000/raster/tiles/1/8/536/143.png or http://127.0.0.1:8000/raster/tiles/1/8/20/40.png(origin x,y in my image) and i take a black window in my browser,any idea where i have wrong in my url rendering ? From ben+python at benfinney.id.au Tue Jul 3 15:59:36 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Jul 2018 05:59:36 +1000 Subject: Getting posts to sort chronologically in tree view References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> <98abdd90-dac0-4e15-934f-47c33074ac3a@googlegroups.com> Message-ID: <85sh50ay53.fsf@benfinney.id.au> T Berger writes: > I'm posting directly to the forum (computer.lang.python, at this web > address: > https://groups.google.com/forum/#!topic/comp.lang.python/vWCvLYjOWUQ) Thanks for being specific. So, from that description, you are using the Google Groups web interface to read and send messages in this forum. That is not ?posting directly to the forum?, because this forum doesn't have a single canonical direct location. (And if it did, that location would certainly not be Google Groups.) > And I have to apologize. The threads in my previous conversation, > ERRNO 48: Address already in use, are so extensive and hierarchical, > that they appear to be out of order. They're not. Right. I gather, from many complaints by Google Groups users over many years, that it is a terrible interface for interacting with any forum. The lack of proper threading support is just one of many well-known bugs that Google show no sign of correcting. They show every sign, in fact, of having no interest in listening to the requests from users of that software. Given that history, you might want to avoid Google Groups for interacting with forums, and choose software that works better with discussion forums. I am told Mozilla Thunderbird is a good choice, but there are likely others. -- \ ?Earth gets its price for what Earth gives us.? ?James Russell | `\ Lowell | _o__) | Ben Finney From daviddschool at gmail.com Tue Jul 3 16:56:57 2018 From: daviddschool at gmail.com (David D) Date: Tue, 3 Jul 2018 13:56:57 -0700 (PDT) Subject: Multi-threading with a simple timer? In-Reply-To: References: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> <20180703182903.GC1204@shallowsky.com> Message-ID: I have some success with this. I am not sure if this would work longer term, as in restarting it, but so far so good. Any issue with this new code? import time from threading import Thread th=Thread() class Answer(Thread): def run(self): a=input("What is your answer:") if a=="yes": print("yes you got it") th.daemon=False else: print("no") class myTimer(Thread): def run(self): print() for x in range(5): if th.daemon==True: print(x) time.sleep(1) else: break th.daemon=True Answer().start() myTimer().start() def finished(): print("done") From blindanagram at nowhere.com Tue Jul 3 18:05:07 2018 From: blindanagram at nowhere.com (BlindAnagram) Date: Tue, 3 Jul 2018 23:05:07 +0100 Subject: Python 3.7 Windows Help Behaviour In-Reply-To: References: Message-ID: On 03/07/2018 03:41, Terry Reedy wrote: > On 7/2/2018 8:57 PM, Steven D'Aprano wrote: >> On Fri, 29 Jun 2018 12:53:15 -0400, Terry Reedy wrote: >> >>> On 6/29/2018 6:14 AM, BlindAnagram wrote: >>>> In Python 3.7.0 on Windows the help file (python370.chm) displays with >>>> a fixed line length and does not adjust its line length when the user >>>> expands the help window horizontally.? This behaviour is different to >>>> that of the Python 3.6 help file (python360.chm) which adjusts its text >>>> to fit the horizontal width of the help window. >>>> >>>> Is this a deliberate change or one that can be turned on or off in some >>>> way (I prefer the Python 3.6 behaviour)? >>> >>> I believe that this is a deliberate regression imposed by 'experts' who >>> believe in form over function and 'controlling the user experience'. >>> 3.6.6 has been 'fixated' also. >> >> I think that's been reverted: >> >> https://github.com/python/cpython/commit/580c7db172a41d6311c0f3a7aec321597576e214 >> > > Yes, I wrote the blurb, merged it, and ordered and approved the backports. >Thank you, Terry (and others who contributed), for your help with this - I much appreciate all your efforts. Brian From steve+comp.lang.python at pearwood.info Tue Jul 3 19:51:50 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 3 Jul 2018 23:51:50 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> Message-ID: On Tue, 03 Jul 2018 09:14:37 -0700, Jim Lee wrote: > On 07/03/18 01:34, Steven D'Aprano wrote: >> I said *indefinite* not infinite. > > Yes, you did.? My bad. Thanks Jim, your acknowledgement is appreciated. >> You did read the article I linked to, right? You know that people don't >> suddenly and instantly turn from "beginner" to "expert" when they >> exceed 9,999 hours 59 minutes and 59 seconds? Quibbling over the exact >> number of hours is foolish. > > > Of course I know that.? I've been familiar with the concept for a long > time.? I've taught several guitarists and have seen it first hand.? I've > also trained several programmers. Okay, so you *do* understand that the "ten thousand hours" concept is a rough, order of magnitude, average figure. Great. Which makes your quibbling over whether it is 10,000 hours or five years or two years all the more mysterious. > Quibbling over the exact number of hours *is* foolish - but nobody was > doing that. Ah nice to see the ol' "deny everything" debating tactic. > I was simply pointing out that you used three vastly > different numbers in almost the same breath to describe how long it > takes a person to master something. I love watching pedantically precise people panic and dig themselves into a hole. Since I'm an extremely pedantic person myself, I can recognise it in others -- especially when they're not as precisely correct as they think they're being. It was two numbers, not three, and not even close to "vastly" different. Both numbers I mentioned (ten thousand hours, a couple of years) are within the bounds of acceptable precision to each other: their (figurative) error bars overlap. My first reference to the number was in quotation marks: "10,000 hours", not 10,000 hours. That was your first hint that I was not using it as a precise number, but as a "vague quantifier" (to give the technical name for the concept). https://en.wikipedia.org/wiki/Indefinite_and_fictitious_numbers#Specific_numbers_used_as_indefinite My second reference was to EXPLICITLY state the number was intended to be read as an imprecise quantity. No second number was mentioned. And the third was to reference a number (a couple of years) which even if read literally rather than figuratively is within an order of magnitude of the original. Even read as *different*, they're not "vastly" different (a vague quantifier which surely means more than merely a single order of magnitude: jumping from five to five billion would surely be a vast difference, not five to fifty). > I think we both get the idea - let's back out of this rabbit trail > before we get lost, ok? :) Translation: "Yeah Steve, you're right, I was kinda a dick for pedantically telling you off for imprecision in numbers even though I knew full well that no greater precision was possible or desirable, but how 'bout you drop it and leave me with the last word, hmmm?" No worries Jim, I totally agree. *wink* -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Tue Jul 3 20:29:26 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 4 Jul 2018 00:29:26 +0000 (UTC) Subject: .replace("a" or "b") References: Message-ID: On Tue, 03 Jul 2018 07:52:42 +0400, Abdur-Rahmaan Janhangeer wrote: > .replace("a" or "b") Oh I *wish* Python accepted that syntax to mean what you thought it meant. That's a common error: a surprising number of beginners are fooled by how close Python is to natural language and try writing things like: if x == 1 or 2: ... Reading Python is sometimes close to reading English, but not *that* close. There is currently no way to tell str.replace to replace "either this, or that". -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Tue Jul 3 21:59:46 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 4 Jul 2018 01:59:46 +0000 (UTC) Subject: Congrats to Chris for breaking his PEP curse Message-ID: Congratulations to Chris Angelico for breaking the dreaded "any PEP written by Chris will be rejected" curse :-) Guido has announced his intention to accept PEP 572 (assignment expressions) once the PEP has been cleaned up a bit. https://www.python.org/dev/peps/pep-0572/ (The current version of the PEP doesn't quite match the proposal as nutted out over about a bazillion emails on two mailing lists starting in FEBRUARY!!!) Summary: Python 3.8 will allow an assignment-as-expression operator. The most common uses are expected to be if and while statements: condition = expression while condition: do_something() condition = expression will become: while condition := expression: do_something() Cascades of if statements, such as: # the dreaded arrowhead anti-pattern mo = re.match(pattern, text) if mo: ... else: mo = re.match(another_pattern, text): if mo: ... else: mo = re.match(third_pattern, text): if mo: ... will become flatter and easier to read: if mo := re.match(pattern, text): ... elif mo := re.match(another_pattern, text): ... elif mo := re.match(third_pattern, text): ... FAQs: Q. Why Pascal's assignment operator := instead of regular = assignment? A. To avoid the C bug magnet of mistakenly writing "if x = expr" when you intended to write "if x == expr". Q. Why not use "as"? A. There is an ambiguity due to with and except statements: with expr as name except Exception as name are already permitted and mean something different to ordinary assignment expressions. Q. Oh no, Python is doomed! This is the end of the world! A. That's not actually a question, is it? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Tue Jul 3 22:05:11 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Jul 2018 12:05:11 +1000 Subject: Congrats to Chris for breaking his PEP curse In-Reply-To: References: Message-ID: On Wed, Jul 4, 2018 at 11:59 AM, Steven D'Aprano wrote: > Congratulations to Chris Angelico for breaking the dreaded "any PEP > written by Chris will be rejected" curse :-) I'm actually somewhat astonished at that part. But thanks anyway. ChrisA From jlee54 at gmail.com Tue Jul 3 22:28:43 2018 From: jlee54 at gmail.com (Jim Lee) Date: Tue, 3 Jul 2018 19:28:43 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> Message-ID: <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> On 07/03/18 16:51, Steven D'Aprano wrote: > > I love watching pedantically precise people panic and dig themselves into > a hole. Since I'm an extremely pedantic person myself, I can recognise it > in others -- especially when they're not as precisely correct as they > think they're being. > > It was two numbers, not three, and not even close to "vastly" different. ? Ah, I see we're not going to leave it alone.? In that case, "indefinite" is a "number", in that it was a quantity you cited along with the other two.? If you'd prefer to call it a "quantity", that's fine with me.? Talk about pedantic... > Both numbers I mentioned (ten thousand hours, a couple of years) are > within the bounds of acceptable precision to each other: their > (figurative) error bars overlap. Who is defining acceptable here?? And you are once again creating a strawman argument.? My quibble was *not* with the difference between 10,000 hours and 2 years. >> I think we both get the idea - let's back out of this rabbit trail >> before we get lost, ok? :) > Translation: > > "Yeah Steve, you're right, I was kinda a dick for pedantically telling > you off for imprecision in numbers even though I knew full well that no > greater precision was possible or desirable, but how 'bout you drop it and > leave me with the last word, hmmm?" > > Sigh.? I tried to give you a graceful way to end the pedantics. Now, I will gracefully allow you to have the last word as well. -Jim From rosuav at gmail.com Tue Jul 3 22:31:16 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Jul 2018 12:31:16 +1000 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> Message-ID: On Wed, Jul 4, 2018 at 12:28 PM, Jim Lee wrote: > > > On 07/03/18 16:51, Steven D'Aprano wrote: >> >> >> I love watching pedantically precise people panic and dig themselves into >> a hole. Since I'm an extremely pedantic person myself, I can recognise it >> in others -- especially when they're not as precisely correct as they >> think they're being. >> >> It was two numbers, not three, and not even close to "vastly" different. > > > Ah, I see we're not going to leave it alone. In that case, "indefinite" > is a "number", in that it was a quantity you cited along with the other two. > If you'd prefer to call it a "quantity", that's fine with me. Talk about > pedantic... I've had debates with people about whether "infinity" is a number or not, but I've never yet heard anyone say that "indefinite" is a number. Hmm. This could be interesting. ChrisA From marko at pacujo.net Tue Jul 3 22:49:47 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 04 Jul 2018 05:49:47 +0300 Subject: EXTERNAL: OSError: [Errno 48] Address already in use References: <87a7rggmbu.fsf@elektro.pacujo.net> <871scrh3y3.fsf@elektro.pacujo.net> <87muvefyh1.fsf@elektro.pacujo.net> <877emif9d1.fsf@elektro.pacujo.net> <87h8liepsa.fsf@elektro.pacujo.net> Message-ID: <877embemus.fsf@elektro.pacujo.net> Grant Edwards : > Found a NetBSD 7.1 system to test on... > > After killing a server with an active connection, a new server can > bind to the same socket regardless of the SO_REUSEADDR setting in > either server. I don't know if that's some sort of system > configuration setting or what... The question is, why shouldn't you be able to bind to an unbound socket that has stale connections in TIME-WAIT? Maybe the NetBSD people found the answer: there's no reason. Marko From jlee54 at gmail.com Tue Jul 3 22:51:14 2018 From: jlee54 at gmail.com (Jim Lee) Date: Tue, 3 Jul 2018 19:51:14 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> Message-ID: <6f8da285-2c72-2863-ff63-4dc39ab2c92a@gmail.com> On 07/03/18 19:31, Chris Angelico wrote: > > I've had debates with people about whether "infinity" is a number or > not, but I've never yet heard anyone say that "indefinite" is a > number. Hmm. This could be interesting. > > ChrisA If you were to say John had 2 apples, Jane had 4 apples, and Joe had an indefinite number of apples, how many numbers are we talking about? That's rhetorical by the way.? The other person is obviously focusing on pedantics in order to obfuscate the original (weak) argument. -Jim From ben+python at benfinney.id.au Tue Jul 3 22:58:08 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Jul 2018 12:58:08 +1000 Subject: PEP 526 - var annotations and the spirit of python References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> <6f8da285-2c72-2863-ff63-4dc39ab2c92a@gmail.com> Message-ID: <85o9fnbtbz.fsf@benfinney.id.au> Jim Lee writes: > If you were to say John had 2 apples, Jane had 4 apples, and Joe had > an indefinite number of apples, how many numbers are we talking about? Three numbers. And ?indefinite? is not one of those numbers. So, no, that doesn't support ?"indefinite" is a number?. -- \ ?That's the essence of science: Ask an impertinent question, | `\ and you're on the way to the pertinent answer.? ?Jacob | _o__) Bronowski, _The Ascent of Man_, 1973 | Ben Finney From brgrt2 at gmail.com Tue Jul 3 23:21:41 2018 From: brgrt2 at gmail.com (T Berger) Date: Tue, 3 Jul 2018 20:21:41 -0700 (PDT) Subject: Getting posts to sort chronologically in tree view In-Reply-To: References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> <98abdd90-dac0-4e15-934f-47c33074ac3a@googlegroups.com> <85sh50ay53.fsf@benfinney.id.au> Message-ID: <38be8d27-1a60-43af-ab65-c86e40b47e0d@googlegroups.com> On Tuesday, July 3, 2018 at 4:00:03 PM UTC-4, Ben Finney wrote: > T Berger writes: > > > I'm posting directly to the forum (computer.lang.python, at this web > > address: > > https://groups.google.com/forum/#!topic/comp.lang.python/vWCvLYjOWUQ) > > Thanks for being specific. So, from that description, you are using the > Google Groups web interface to read and send messages in this forum. > > That is not ?posting directly to the forum?, because this forum doesn't > have a single canonical direct location. (And if it did, that location > would certainly not be Google Groups.) I don't have to tell you that I find this all very confusing. > > And I have to apologize. The threads in my previous conversation, > > ERRNO 48: Address already in use, are so extensive and hierarchical, > > that they appear to be out of order. They're not. > > Right. I gather, from many complaints by Google Groups users over many > years, that it is a terrible interface for interacting with any forum. > > The lack of proper threading support is just one of many well-known bugs > that Google show no sign of correcting. They show every sign, in fact, > of having no interest in listening to the requests from users of that > software. Ben, you may not have finished reading my post. It turns out that I was wrong in thinking that the posts were out of order; they were just so hard to follow because of all the side conversations. Once I carefully followed the threads I saw that I had been wrong. > Given that history, you might want to avoid Google Groups for > interacting with forums, and choose software that works better with > discussion forums. I am told Mozilla Thunderbird is a good choice, but > there are likely others. I don't think I want to try a mail list. I had subscribed to the python-list a few weeks ago and then been forced to unsubscribe because of the flood of irrelevant posts. Ben, I tried responding to your email from gmail. I hit the reply button, and got the below message. Do you know why? Mail Delivery Subsystem 6:05 PM (5 hours ago) Reply to me Final-Recipient: rfc822; comp.lang.python at googlegroups.com Action: failed Status: 5.0.0 Diagnostic-Code: smtp; Posting by email is not allowed, to post to this group visit https://groups.google.com/forum/#!forum/comp.lang.python Last-Attempt-Date: Tue, 03 Jul 2018 15:05:28 -0700 (PDT) Tamara From jlee54 at gmail.com Tue Jul 3 23:23:58 2018 From: jlee54 at gmail.com (Jim Lee) Date: Tue, 3 Jul 2018 20:23:58 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: <85o9fnbtbz.fsf@benfinney.id.au> References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> <6f8da285-2c72-2863-ff63-4dc39ab2c92a@gmail.com> <85o9fnbtbz.fsf@benfinney.id.au> Message-ID: On 07/03/18 19:58, Ben Finney via Python-list wrote: > Jim Lee writes: > >> If you were to say John had 2 apples, Jane had 4 apples, and Joe had >> an indefinite number of apples, how many numbers are we talking about? > Three numbers. And ?indefinite? is not one of those numbers. So, no, > that doesn't support ?"indefinite" is a number?. > Exactly.? And you've just confirmed my original argument.? Thanks! -Jim From arj.python at gmail.com Wed Jul 4 00:12:09 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 4 Jul 2018 08:12:09 +0400 Subject: Congrats to Chris for breaking his PEP curse In-Reply-To: References: Message-ID: https://www.reddit.com/r/Python/comments/8vmq27/pep_572_assignment_expressions_is_officially/ XD nice feedbacks about the pep Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ On Wed, 4 Jul 2018, 06:02 Steven D'Aprano, < steve+comp.lang.python at pearwood.info> wrote: > Congratulations to Chris Angelico for breaking the dreaded "any PEP > written by Chris will be rejected" curse :-) > > Guido has announced his intention to accept PEP 572 (assignment > expressions) once the PEP has been cleaned up a bit. > > https://www.python.org/dev/peps/pep-0572/ > > (The current version of the PEP doesn't quite match the proposal as > nutted out over about a bazillion emails on two mailing lists starting in > FEBRUARY!!!) > > > Summary: > > Python 3.8 will allow an assignment-as-expression operator. The most > common uses are expected to be if and while statements: > > condition = expression > while condition: > do_something() > condition = expression > > will become: > > while condition := expression: > do_something() > > > Cascades of if statements, such as: > > # the dreaded arrowhead anti-pattern > mo = re.match(pattern, text) > if mo: > ... > else: > mo = re.match(another_pattern, text): > if mo: > ... > else: > mo = re.match(third_pattern, text): > if mo: > ... > > > will become flatter and easier to read: > > if mo := re.match(pattern, text): > ... > elif mo := re.match(another_pattern, text): > ... > elif mo := re.match(third_pattern, text): > ... > > > FAQs: > > Q. Why Pascal's assignment operator := instead of regular = assignment? > > A. To avoid the C bug magnet of mistakenly writing "if x = expr" when > you intended to write "if x == expr". > > > Q. Why not use "as"? > > A. There is an ambiguity due to with and except statements: > > with expr as name > > except Exception as name > > are already permitted and mean something different to ordinary > assignment expressions. > > > Q. Oh no, Python is doomed! This is the end of the world! > > A. That's not actually a question, is it? > > > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson > > -- > https://mail.python.org/mailman/listinfo/python-list > From ben+python at benfinney.id.au Wed Jul 4 00:25:38 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Jul 2018 14:25:38 +1000 Subject: PEP 526 - var annotations and the spirit of python References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> <6f8da285-2c72-2863-ff63-4dc39ab2c92a@gmail.com> <85o9fnbtbz.fsf@benfinney.id.au> Message-ID: <85h8lfbpa5.fsf@benfinney.id.au> Jim Lee writes: > On 07/03/18 19:58, Ben Finney via Python-list wrote: > > Jim Lee writes: > > > >> If you were to say John had 2 apples, Jane had 4 apples, and Joe had > >> an indefinite number of apples, how many numbers are we talking about? > > Three numbers. And ?indefinite? is not one of those numbers. So, no, > > that doesn't support ?"indefinite" is a number?. > > > Exactly.? And you've just confirmed my original argument.? Thanks! Still no, because you're the only one who claimed "indefinite" is a number. -- \ ?If you saw two guys named Hambone and Flippy, which one would | `\ you think liked dolphins the most? I'd say Flippy, wouldn't | _o__) you? You'd be wrong, though. It's Hambone.? ?Jack Handey | Ben Finney From arj.python at gmail.com Wed Jul 4 00:31:14 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 4 Jul 2018 08:31:14 +0400 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> Message-ID: list members have a nice way to wriggle out of the subject ^^_ apart from programming, other questions go like this : asker : what do you think about this python thing? next post : *on track* next post : *on track* next post : *on track* btw thon is the name of a fish in french next post : a sea fish actually next post : you don't need to tell *sea* it's obvious next post : i've been a fisherman having caught several types of fish for several years, and i can tell you those fish are easy to catch next post : being a fisherman for several years does not make you a good fisherman, you need to know how to implement fishing techniques next post : me i managed to catch a fish using a net made of spider webs next post : well several is a subset of infinity, you need to be precise next post : infinity can be bounded, i've always told myself next post : hey guys i've made a library called ton.py, you just reminded me to complete it next post : ton means yours in french next post : it's actually only half true, in reality ton ... *cut at this point* Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ From n_jayshankar at yahoo.com Wed Jul 4 00:32:44 2018 From: n_jayshankar at yahoo.com (jayshankar nair) Date: Wed, 4 Jul 2018 04:32:44 +0000 (UTC) Subject: openstack connection References: <1912919757.2228092.1530678764974.ref@mail.yahoo.com> Message-ID: <1912919757.2228092.1530678764974@mail.yahoo.com> Hi, I am trying to establish a connection to openstack cloud . I am able to establish a connection with the following statement from openstack import connectionconn = connection.Connection(auth_url="http://192.168.0.19:5000/v3",? ? ? ? ? ? ? ? ? ? ? project_name="admin",username="admin",? ? ? ? ? ? ? ? ? ? ? password="6908a8d218f843dd",? ? ? ? ? ? ? ? ? ? ? user_domain_id="default",? ? ? ? ? ? ? ? ? ? ? project_domain_id="default") I am looking for exact Connection api argument match in below connection.py file. Also, i am looking for api to access the object store(list out files,creating backup) and network(creating subnet). I am able to create duplicate subnet in network. It doesn't prompt out any error. Thanks,Jayshankar # Licensed under the Apache License, Version 2.0 (the "License"); you mayb# not use this file except in compliance with the License. You may obtain# a copy of the License at##? ? ? http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the# License for the specific language governing permissions and limitations# under the License. """The :class:`~openstack.connection.Connection` class is the primary interfaceto the Python SDK. It maintains a context for a connection to a region ofa cloud provider. The :class:`~openstack.connection.Connection` has anattribute to access each OpenStack service. At a minimum, the :class:`~openstack.connection.Connection` class needs to becreated with a config or the parameters to build one. While the overall system is very flexible, there are four main use casesfor different ways to create a :class:`~openstack.connection.Connection`. * Using config settings and keyword arguments as described in? :ref:`openstack-config`* Using only keyword arguments passed to the constructor ignoring config files? and environment variables.* Using an existing authenticated `keystoneauth1.session.Session`, such as? might exist inside of an OpenStack service operational context.* Using an existing :class:`~openstack.config.cloud_region.CloudRegion`. Using config settings--------------------- For users who want to create a :class:`~openstack.connection.Connection` makinguse of named clouds in ``clouds.yaml`` files, ``OS_`` environment variablesand python keyword arguments, the :func:`openstack.connect` factory functionis the recommended way to go: .. code-block:: python ? ? import openstack ? ? conn = openstack.connect(cloud='example', region_name='earth1') If the application in question is a command line application that should alsoaccept command line arguments, an `argparse.Namespace` can be passed to:func:`openstack.connect` that will have relevant arguments added to it andthen subsequently consumed by the construtor: .. code-block:: python ? ? import argparse? ? import openstack ? ? options = argparse.ArgumentParser(description='Awesome OpenStack App')? ? conn = openstack.connect(options=options) Using Only Keyword Arguments---------------------------- If the application wants to avoid loading any settings from ``clouds.yaml`` orenvironment variables, use the :class:`~openstack.connection.Connection`constructor directly. As long as the ``cloud`` argument is omitted or ``None``,the :class:`~openstack.connection.Connection` constructor will not loadsettings from files or the environment. .. note:: ? ? This is a different default behavior than the :func:`~openstack.connect`? ? factory function. In :func:`~openstack.connect` if ``cloud`` is omitted? ? or ``None``, a default cloud will be loaded, defaulting to the ``envvars``? ? cloud if it exists. .. code-block:: python ? ? from openstack import connection ? ? conn = connection.Connection(? ? ? ? region_name='example-region',? ? ? ? auth=dict(? ? ? ? ? ? auth_url='https://auth.example.com',? ? ? ? ? ? username='amazing-user',? ? ? ? ? ? password='super-secret-password',? ? ? ? ? ? project_id='33aa1afc-03fe-43b8-8201-4e0d3b4b8ab5',? ? ? ? ? ? user_domain_id='054abd68-9ad9-418b-96d3-3437bb376703'),? ? ? ? compute_api_version='2',? ? ? ? identity_interface='internal') Per-service settings as needed by `keystoneauth1.adapter.Adapter` such as``api_version``, ``service_name``, and ``interface`` can be set, as seenabove, by prefixing them with the official ``service-type`` name of theservice. ``region_name`` is a setting for the entire:class:`~openstack.config.cloud_region.CloudRegion` and cannot be set perservice. >From existing authenticated Session----------------------------------- For applications that already have an authenticated Session, simply passingit to the :class:`~openstack.connection.Connection` constructor is all thatis needed: .. code-block:: python ? ? from openstack import connection ? ? conn = connection.Connection(? ? ? ? session=session,? ? ? ? region_name='example-region',? ? ? ? compute_api_version='2',? ? ? ? identity_interface='internal') >From existing CloudRegion------------------------- If you already have an :class:`~openstack.config.cloud_region.CloudRegion`you can pass it in instead: .. code-block:: python ? ? from openstack import connection? ? import openstack.config ? ? config = openstack.config.get_cloud_region(? ? ? ? cloud='example', region_name='earth')? ? conn = connection.Connection(config=config) Using the Connection-------------------- Services are accessed through an attribute named after the service's officialservice-type. List~~~~ An iterator containing a list of all the projects is retrieved in this manner: .. code-block:: python ? ? projects = conn.identity.projects() Find or create~~~~~~~~~~~~~~ If you wanted to make sure you had a network named 'zuul', you would firsttry to find it and if that fails, you would create it:: ? ? network = conn.network.find_network("zuul")? ? if network is None:? ? ? ? network = conn.network.create_network(name="zuul") Additional information about the services can be found in the:ref:`service-proxies` documentation."""__all__ = [? ? 'from_config',? ? 'Connection',] import warnings import keystoneauth1.exceptionsimport requestsexceptionsimport six from openstack import _logfrom openstack import _metafrom openstack import config as _configfrom openstack.config import cloud_regionfrom openstack import exceptionsfrom openstack import service_descriptionfrom openstack import task_manager if requestsexceptions.SubjectAltNameWarning:? ? warnings.filterwarnings(? ? ? ? 'ignore', category=requestsexceptions.SubjectAltNameWarning) _logger = _log.setup_logging('openstack') def from_config(cloud=None, config=None, options=None, **kwargs):? ? """Create a Connection using openstack.config ? ? :param str cloud:? ? ? ? Use the `cloud` configuration details when creating the Connection.? ? :param openstack.config.cloud_region.CloudRegion config:? ? ? ? An existing CloudRegion configuration. If no `config` is provided,? ? ? ? `openstack.config.OpenStackConfig` will be called, and the provided? ? ? ? `name` will be used in determining which cloud's configuration? ? ? ? details will be used in creation of the `Connection` instance.? ? :param argparse.Namespace options:? ? ? ? Allows direct passing in of options to be added to the cloud config.? ? ? ? This does not have to be an actual instance of argparse.Namespace,? ? ? ? despite the naming of the the? ? ? ? `openstack.config.loader.OpenStackConfig.get_one` argument to which? ? ? ? it is passed. ? ? :rtype: :class:`~openstack.connection.Connection`? ? """? ? # TODO(mordred) Backwards compat while we transition? ? cloud = kwargs.pop('cloud_name', cloud)? ? config = kwargs.pop('cloud_config', config)? ? if config is None:? ? ? ? config = _config.OpenStackConfig().get_one(? ? ? ? ? ? cloud=cloud, argparse=options, **kwargs) ? ? return Connection(config=config) class Connection(six.with_metaclass(_meta.ConnectionMeta)): ? ? def __init__(self, cloud=None, config=None, session=None,? ? ? ? ? ? ? ? ?app_name=None, app_version=None,? ? ? ? ? ? ? ? ?# TODO(shade) Remove these once we've shifted? ? ? ? ? ? ? ? ?# python-openstackclient to not use the profile interface.? ? ? ? ? ? ? ? ?authenticator=None, profile=None,? ? ? ? ? ? ? ? ?extra_services=None,? ? ? ? ? ? ? ? ?**kwargs):? ? ? ? """Create a connection to a cloud. ? ? ? ? A connection needs information about how to connect, how to? ? ? ? authenticate and how to select the appropriate services to use. ? ? ? ? The recommended way to provide this information is by referencing? ? ? ? a named cloud config from an existing `clouds.yaml` file. The cloud? ? ? ? name ``envvars`` may be used to consume a cloud configured via ``OS_``? ? ? ? environment variables. ? ? ? ? A pre-existing :class:`~openstack.config.cloud_region.CloudRegion`? ? ? ? object can be passed in lieu of a cloud name, for cases where the user? ? ? ? already has a fully formed CloudRegion and just wants to use it. ? ? ? ? Similarly, if for some reason the user already has a? ? ? ? :class:`~keystoneauth1.session.Session` and wants to use it, it may be? ? ? ? passed in. ? ? ? ? :param str cloud: Name of the cloud from config to use.? ? ? ? :param config: CloudRegion object representing the config for the? ? ? ? ? ? region of the cloud in question.? ? ? ? :type config: :class:`~openstack.config.cloud_region.CloudRegion`? ? ? ? :param session: A session object compatible with? ? ? ? ? ? :class:`~keystoneauth1.session.Session`.? ? ? ? :type session: :class:`~keystoneauth1.session.Session`? ? ? ? :param str app_name: Name of the application to be added to User Agent.? ? ? ? :param str app_version: Version of the application to be added to? ? ? ? ? ? User Agent.? ? ? ? :param authenticator: DEPRECATED. Only exists for short-term backwards? ? ? ? ? ? ? ? ? ? ? ? ? ? ? compatibility for python-openstackclient while we? ? ? ? ? ? ? ? ? ? ? ? ? ? ? transition. See :doc:`transition_from_profile`? ? ? ? ? ? ? ? ? ? ? ? ? ? ? for details.? ? ? ? :param profile: DEPRECATED. Only exists for short-term backwards? ? ? ? ? ? ? ? ? ? ? ? compatibility for python-openstackclient while we? ? ? ? ? ? ? ? ? ? ? ? transition. See :doc:`transition_from_profile`? ? ? ? ? ? ? ? ? ? ? ? for details.? ? ? ? :param extra_services: List of? ? ? ? ? ? :class:`~openstack.service_description.ServiceDescription`? ? ? ? ? ? objects describing services that openstacksdk otherwise does not? ? ? ? ? ? know about.? ? ? ? :param kwargs: If a config is not provided, the rest of the parameters? ? ? ? ? ? provided are assumed to be arguments to be passed to the? ? ? ? ? ? CloudRegion contructor.? ? ? ? """? ? ? ? self.config = config? ? ? ? self._extra_services = {}? ? ? ? if extra_services:? ? ? ? ? ? for service in extra_services:? ? ? ? ? ? ? ? self._extra_services[service.service_type] = service ? ? ? ? if not self.config:? ? ? ? ? ? if profile:? ? ? ? ? ? ? ? import openstack.profile? ? ? ? ? ? ? ? # TODO(shade) Remove this once we've shifted? ? ? ? ? ? ? ? # python-openstackclient to not use the profile interface.? ? ? ? ? ? ? ? self.config = openstack.profile._get_config_from_profile(? ? ? ? ? ? ? ? ? ? profile, authenticator, **kwargs)? ? ? ? ? ? elif session:? ? ? ? ? ? ? ? self.config = cloud_region.from_session(? ? ? ? ? ? ? ? ? ? session=session,? ? ? ? ? ? ? ? ? ? app_name=app_name, app_version=app_version,? ? ? ? ? ? ? ? ? ? load_yaml_config=False,? ? ? ? ? ? ? ? ? ? load_envvars=False,? ? ? ? ? ? ? ? ? ? **kwargs)? ? ? ? ? ? else:? ? ? ? ? ? ? ? self.config = _config.get_cloud_region(? ? ? ? ? ? ? ? ? ? cloud=cloud,? ? ? ? ? ? ? ? ? ? app_name=app_name, app_version=app_version,? ? ? ? ? ? ? ? ? ? load_yaml_config=cloud is not None,? ? ? ? ? ? ? ? ? ? load_envvars=cloud is not None,? ? ? ? ? ? ? ? ? ? **kwargs) ? ? ? ? if self.config.name:? ? ? ? ? ? tm_name = ':'.join([? ? ? ? ? ? ? ? self.config.name,? ? ? ? ? ? ? ? self.config.region_name or 'unknown'])? ? ? ? else:? ? ? ? ? ? tm_name = self.config.region_name or 'unknown' ? ? ? ? self.task_manager = task_manager.TaskManager(name=tm_name) ? ? ? ? if session:? ? ? ? ? ? # TODO(mordred) Expose constructor option for this in OCC? ? ? ? ? ? self.config._keystone_session = session ? ? ? ? self.session = self.config.get_session()? ? ? ? # Hide a reference to the connection on the session to help with? ? ? ? # backwards compatibility for folks trying to just pass conn.session? ? ? ? # to a Resource method's session argument.? ? ? ? self.session._sdk_connection = self ? ? ? ? self._proxies = {} ? ? def add_service(self, service):? ? ? ? """Add a service to the Connection. ? ? ? ? Attaches an instance of the :class:`~openstack.proxy.BaseProxy`? ? ? ? class contained in? ? ? ? :class:`~openstack.service_description.ServiceDescription`.? ? ? ? The :class:`~openstack.proxy.BaseProxy` will be attached to the? ? ? ? `Connection` by its ``service_type`` and by any ``aliases`` that? ? ? ? may be specified. ? ? ? ? :param openstack.service_description.ServiceDescription service:? ? ? ? ? ? Object describing the service to be attached. As a convenience,? ? ? ? ? ? if ``service`` is a string it will be treated as a ``service_type``? ? ? ? ? ? and a basic? ? ? ? ? ? :class:`~openstack.service_description.ServiceDescription`? ? ? ? ? ? will be created.? ? ? ? """? ? ? ? # If we don't have a proxy, just instantiate BaseProxy so that? ? ? ? # we get an adapter.? ? ? ? if isinstance(service, six.string_types):? ? ? ? ? ? service = service_description.ServiceDescription(service) ? ? ? ? # Register the proxy class with every known alias? ? ? ? for attr_name in service.all_types:? ? ? ? ? ? setattr(self, attr_name.replace('-', '_'), service) ? ? def authorize(self):? ? ? ? """Authorize this Connection ? ? ? ? .. note:: This method is optional. When an application makes a call? ? ? ? ? ? ? ? ? to any OpenStack service, this method allows you to request? ? ? ? ? ? ? ? ? a token manually before attempting to do anything else. ? ? ? ? :returns: A string token. ? ? ? ? :raises: :class:`~openstack.exceptions.HttpException` if the? ? ? ? ? ? ? ? ?authorization fails due to reasons like the credentials? ? ? ? ? ? ? ? ?provided are unable to be authorized or the `auth_type`? ? ? ? ? ? ? ? ?argument is missing, etc.? ? ? ? """? ? ? ? try:? ? ? ? ? ? return self.session.get_token()? ? ? ? except keystoneauth1.exceptions.ClientException as e:? ? ? ? ? ? raise exceptions.raise_from_response(e.response) -----------------------------------------------------------------------------------------------------------I am looking for the corresponding api with exact arguments in openstack connection.py file(attached below).? Also i am looking for api to accesrs object store(list out files in object store,size of object store,other features of object store) and network(creating network). Also i am able to c---------------------------------------------------------------------------------------------------------------------------connection.py# Licensed under the Apache License, Version 2.0 (the "License"); you may# not use this file except in compliance with the License. You may obtain# a copy of the License at##? ? ? http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the# License for the specific language governing permissions and limitations# under the License. """The :class:`~openstack.connection.Connection` class is the primary interfaceto the Python SDK. It maintains a context for a connection to a region ofa cloud provider. The :class:`~openstack.connection.Connection` has anattribute to access each OpenStack service. At a minimum, the :class:`~openstack.connection.Connection` class needs to becreated with a config or the parameters to build one. While the overall system is very flexible, there are four main use casesfor different ways to create a :class:`~openstack.connection.Connection`. * Using config settings and keyword arguments as described in? :ref:`openstack-config`* Using only keyword arguments passed to the constructor ignoring config files? and environment variables.* Using an existing authenticated `keystoneauth1.session.Session`, such as? might exist inside of an OpenStack service operational context.* Using an existing :class:`~openstack.config.cloud_region.CloudRegion`. Using config settings--------------------- For users who want to create a :class:`~openstack.connection.Connection` makinguse of named clouds in ``clouds.yaml`` files, ``OS_`` environment variablesand python keyword arguments, the :func:`openstack.connect` factory functionis the recommended way to go: .. code-block:: python ? ? import openstack ? ? conn = openstack.connect(cloud='example', region_name='earth1') If the application in question is a command line application that should alsoaccept command line arguments, an `argparse.Namespace` can be passed to:func:`openstack.connect` that will have relevant arguments added to it andthen subsequently consumed by the construtor: .. code-block:: python ? ? import argparse? ? import openstack ? ? options = argparse.ArgumentParser(description='Awesome OpenStack App')? ? conn = openstack.connect(options=options) Using Only Keyword Arguments---------------------------- If the application wants to avoid loading any settings from ``clouds.yaml`` orenvironment variables, use the :class:`~openstack.connection.Connection`constructor directly. As long as the ``cloud`` argument is omitted or ``None``,the :class:`~openstack.connection.Connection` constructor will not loadsettings from files or the environment. .. note:: ? ? This is a different default behavior than the :func:`~openstack.connect`? ? factory function. In :func:`~openstack.connect` if ``cloud`` is omitted? ? or ``None``, a default cloud will be loaded, defaulting to the ``envvars``? ? cloud if it exists. .. code-block:: python ? ? from openstack import connection ? ? conn = connection.Connection(? ? ? ? region_name='example-region',? ? ? ? auth=dict(? ? ? ? ? ? auth_url='https://auth.example.com',? ? ? ? ? ? username='amazing-user',? ? ? ? ? ? password='super-secret-password',? ? ? ? ? ? project_id='33aa1afc-03fe-43b8-8201-4e0d3b4b8ab5',? ? ? ? ? ? user_domain_id='054abd68-9ad9-418b-96d3-3437bb376703'),? ? ? ? compute_api_version='2',? ? ? ? identity_interface='internal') Per-service settings as needed by `keystoneauth1.adapter.Adapter` such as``api_version``, ``service_name``, and ``interface`` can be set, as seenabove, by prefixing them with the official ``service-type`` name of theservice. ``region_name`` is a setting for the entire:class:`~openstack.config.cloud_region.CloudRegion` and cannot be set perservice. >From existing authenticated Session----------------------------------- For applications that already have an authenticated Session, simply passingit to the :class:`~openstack.connection.Connection` constructor is all thatis needed: .. code-block:: python ? ? from openstack import connection ? ? conn = connection.Connection(? ? ? ? session=session,? ? ? ? region_name='example-region',? ? ? ? compute_api_version='2',? ? ? ? identity_interface='internal') >From existing CloudRegion------------------------- If you already have an :class:`~openstack.config.cloud_region.CloudRegion`you can pass it in instead: .. code-block:: python ? ? from openstack import connection? ? import openstack.config ? ? config = openstack.config.get_cloud_region(? ? ? ? cloud='example', region_name='earth')? ? conn = connection.Connection(config=config) Using the Connection-------------------- Services are accessed through an attribute named after the service's officialservice-type. List~~~~ An iterator containing a list of all the projects is retrieved in this manner: .. code-block:: python ? ? projects = conn.identity.projects() Find or create~~~~~~~~~~~~~~ If you wanted to make sure you had a network named 'zuul', you would firsttry to find it and if that fails, you would create it:: ? ? network = conn.network.find_network("zuul")? ? if network is None:? ? ? ? network = conn.network.create_network(name="zuul") Additional information about the services can be found in the:ref:`service-proxies` documentation."""__all__ = [? ? 'from_config',? ? 'Connection',] import warnings import keystoneauth1.exceptionsimport requestsexceptionsimport six from openstack import _logfrom openstack import _metafrom openstack import config as _configfrom openstack.config import cloud_regionfrom openstack import exceptionsfrom openstack import service_descriptionfrom openstack import task_manager if requestsexceptions.SubjectAltNameWarning:? ? warnings.filterwarnings(? ? ? ? 'ignore', category=requestsexceptions.SubjectAltNameWarning) _logger = _log.setup_logging('openstack') def from_config(cloud=None, config=None, options=None, **kwargs):? ? """Create a Connection using openstack.config ? ? :param str cloud:? ? ? ? Use the `cloud` configuration details when creating the Connection.? ? :param openstack.config.cloud_region.CloudRegion config:? ? ? ? An existing CloudRegion configuration. If no `config` is provided,? ? ? ? `openstack.config.OpenStackConfig` will be called, and the provided? ? ? ? `name` will be used in determining which cloud's configuration? ? ? ? details will be used in creation of the `Connection` instance.? ? :param argparse.Namespace options:? ? ? ? Allows direct passing in of options to be added to the cloud config.? ? ? ? This does not have to be an actual instance of argparse.Namespace,? ? ? ? despite the naming of the the? ? ? ? `openstack.config.loader.OpenStackConfig.get_one` argument to which? ? ? ? it is passed. ? ? :rtype: :class:`~openstack.connection.Connection`? ? """? ? # TODO(mordred) Backwards compat while we transition? ? cloud = kwargs.pop('cloud_name', cloud)? ? config = kwargs.pop('cloud_config', config)? ? if config is None:? ? ? ? config = _config.OpenStackConfig().get_one(? ? ? ? ? ? cloud=cloud, argparse=options, **kwargs) ? ? return Connection(config=config) class Connection(six.with_metaclass(_meta.ConnectionMeta)): ? ? def __init__(self, cloud=None, config=None, session=None,? ? ? ? ? ? ? ? ?app_name=None, app_version=None,? ? ? ? ? ? ? ? ?# TODO(shade) Remove these once we've shifted? ? ? ? ? ? ? ? ?# python-openstackclient to not use the profile interface.? ? ? ? ? ? ? ? ?authenticator=None, profile=None,? ? ? ? ? ? ? ? ?extra_services=None,? ? ? ? ? ? ? ? ?**kwargs):? ? ? ? """Create a connection to a cloud. ? ? ? ? A connection needs information about how to connect, how to? ? ? ? authenticate and how to select the appropriate services to use. ? ? ? ? The recommended way to provide this information is by referencing? ? ? ? a named cloud config from an existing `clouds.yaml` file. The cloud? ? ? ? name ``envvars`` may be used to consume a cloud configured via ``OS_``? ? ? ? environment variables. ? ? ? ? A pre-existing :class:`~openstack.config.cloud_region.CloudRegion`? ? ? ? object can be passed in lieu of a cloud name, for cases where the user? ? ? ? already has a fully formed CloudRegion and just wants to use it. ? ? ? ? Similarly, if for some reason the user already has a? ? ? ? :class:`~keystoneauth1.session.Session` and wants to use it, it may be? ? ? ? passed in. ? ? ? ? :param str cloud: Name of the cloud from config to use.? ? ? ? :param config: CloudRegion object representing the config for the? ? ? ? ? ? region of the cloud in question.? ? ? ? :type config: :class:`~openstack.config.cloud_region.CloudRegion`? ? ? ? :param session: A session object compatible with? ? ? ? ? ? :class:`~keystoneauth1.session.Session`.? ? ? ? :type session: :class:`~keystoneauth1.session.Session`? ? ? ? :param str app_name: Name of the application to be added to User Agent.? ? ? ? :param str app_version: Version of the application to be added to? ? ? ? ? ? User Agent.? ? ? ? :param authenticator: DEPRECATED. Only exists for short-term backwards? ? ? ? ? ? ? ? ? ? ? ? ? ? ? compatibility for python-openstackclient while we? ? ? ? ? ? ? ? ? ? ? ? ? ? ? transition. See :doc:`transition_from_profile`? ? ? ? ? ? ? ? ? ? ? ? ? ? ? for details.? ? ? ? :param profile: DEPRECATED. Only exists for short-term backwards? ? ? ? ? ? ? ? ? ? ? ? compatibility for python-openstackclient while we? ? ? ? ? ? ? ? ? ? ? ? transition. See :doc:`transition_from_profile`? ? ? ? ? ? ? ? ? ? ? ? for details.? ? ? ? :param extra_services: List of? ? ? ? ? ? :class:`~openstack.service_description.ServiceDescription`? ? ? ? ? ? objects describing services that openstacksdk otherwise does not? ? ? ? ? ? know about.? ? ? ? :param kwargs: If a config is not provided, the rest of the parameters? ? ? ? ? ? provided are assumed to be arguments to be passed to the? ? ? ? ? ? CloudRegion contructor.? ? ? ? """? ? ? ? self.config = config? ? ? ? self._extra_services = {}? ? ? ? if extra_services:? ? ? ? ? ? for service in extra_services:? ? ? ? ? ? ? ? self._extra_services[service.service_type] = service ? ? ? ? if not self.config:? ? ? ? ? ? if profile:? ? ? ? ? ? ? ? import openstack.profile? ? ? ? ? ? ? ? # TODO(shade) Remove this once we've shifted? ? ? ? ? ? ? ? # python-openstackclient to not use the profile interface.? ? ? ? ? ? ? ? self.config = openstack.profile._get_config_from_profile(? ? ? ? ? ? ? ? ? ? profile, authenticator, **kwargs)? ? ? ? ? ? elif session:? ? ? ? ? ? ? ? self.config = cloud_region.from_session(? ? ? ? ? ? ? ? ? ? session=session,? ? ? ? ? ? ? ? ? ? app_name=app_name, app_version=app_version,? ? ? ? ? ? ? ? ? ? load_yaml_config=False,? ? ? ? ? ? ? ? ? ? load_envvars=False,? ? ? ? ? ? ? ? ? ? **kwargs)? ? ? ? ? ? else:? ? ? ? ? ? ? ? self.config = _config.get_cloud_region(? ? ? ? ? ? ? ? ? ? cloud=cloud,? ? ? ? ? ? ? ? ? ? app_name=app_name, app_version=app_version,? ? ? ? ? ? ? ? ? ? load_yaml_config=cloud is not None,? ? ? ? ? ? ? ? ? ? load_envvars=cloud is not None,? ? ? ? ? ? ? ? ? ? **kwargs) ? ? ? ? if self.config.name:? ? ? ? ? ? tm_name = ':'.join([? ? ? ? ? ? ? ? self.config.name,? ? ? ? ? ? ? ? self.config.region_name or 'unknown'])? ? ? ? else:? ? ? ? ? ? tm_name = self.config.region_name or 'unknown' ? ? ? ? self.task_manager = task_manager.TaskManager(name=tm_name) ? ? ? ? if session:? ? ? ? ? ? # TODO(mordred) Expose constructor option for this in OCC? ? ? ? ? ? self.config._keystone_session = session ? ? ? ? self.session = self.config.get_session()? ? ? ? # Hide a reference to the connection on the session to help with? ? ? ? # backwards compatibility for folks trying to just pass conn.session? ? ? ? # to a Resource method's session argument.? ? ? ? self.session._sdk_connection = self ? ? ? ? self._proxies = {} ? ? def add_service(self, service):? ? ? ? """Add a service to the Connection. ? ? ? ? Attaches an instance of the :class:`~openstack.proxy.BaseProxy`? ? ? ? class contained in? ? ? ? :class:`~openstack.service_description.ServiceDescription`.? ? ? ? The :class:`~openstack.proxy.BaseProxy` will be attached to the? ? ? ? `Connection` by its ``service_type`` and by any ``aliases`` that? ? ? ? may be specified. ? ? ? ? :param openstack.service_description.ServiceDescription service:? ? ? ? ? ? Object describing the service to be attached. As a convenience,? ? ? ? ? ? if ``service`` is a string it will be treated as a ``service_type``? ? ? ? ? ? and a basic? ? ? ? ? ? :class:`~openstack.service_description.ServiceDescription`? ? ? ? ? ? will be created.? ? ? ? """? ? ? ? # If we don't have a proxy, just instantiate BaseProxy so that? ? ? ? # we get an adapter.? ? ? ? if isinstance(service, six.string_types):? ? ? ? ? ? service = service_description.ServiceDescription(service) ? ? ? ? # Register the proxy class with every known alias? ? ? ? for attr_name in service.all_types:? ? ? ? ? ? setattr(self, attr_name.replace('-', '_'), service) ? ? def authorize(self):? ? ? ? """Authorize this Connection ? ? ? ? .. note:: This method is optional. When an application makes a call? ? ? ? ? ? ? ? ? to any OpenStack service, this method allows you to request? ? ? ? ? ? ? ? ? a token manually before attempting to do anything else. ? ? ? ? :returns: A string token. ? ? ? ? :raises: :class:`~openstack.exceptions.HttpException` if the? ? ? ? ? ? ? ? ?authorization fails due to reasons like the credentials? ? ? ? ? ? ? ? ?provided are unable to be authorized or the `auth_type`? ? ? ? ? ? ? ? ?argument is missing, etc.? ? ? ? """? ? ? ? try:? ? ? ? ? ? return self.session.get_token()? ? ? ? except keystoneauth1.exceptions.ClientException as e:? ? ? ? ? ? raise exceptions.raise_from_response(e.response) ------------------------------------------------------------------------------------------ | | Virus-free. www.avast.com | From ben+python at benfinney.id.au Wed Jul 4 00:33:27 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Jul 2018 14:33:27 +1000 Subject: Getting posts to sort chronologically in tree view References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> <98abdd90-dac0-4e15-934f-47c33074ac3a@googlegroups.com> <85sh50ay53.fsf@benfinney.id.au> <38be8d27-1a60-43af-ab65-c86e40b47e0d@googlegroups.com> Message-ID: <85bmbnbox4.fsf@benfinney.id.au> T Berger writes: > On Tuesday, July 3, 2018 at 4:00:03 PM UTC-4, Ben Finney wrote: > > Given that history [of ignoring user requests for improvement], you > > might want to avoid Google Groups for interacting with forums, and > > choose software that works better with discussion forums. I am told > > Mozilla Thunderbird is a good choice, but there are likely others. > > I don't think I want to try a mail list. Good news: you're already participating in one. That was easy! :-) This is because the forum you're participating is distributed in many media, *including* a mailing list. You may send some or all of your messages using a different interface, but you're still participating in the same forum as the rest of us and so you're participating on (among other things) a mailing list. > I had subscribed to the python-list a few weeks ago and then been > forced to unsubscribe because of the flood of irrelevant posts. Yes, this forum can sometimes host a high volume of discussion. You will want to learn the ?filter? feature (it may have a different name) of whatever interface you use. > Ben, I tried responding to your email from gmail. I hit the reply > button, and got the below message. Do you know why? I haven't got any insight to that error, no. If you have an easy way to get official support for Google Groups, ask there. If you don't have an easy way to get support for the software, I'd say that is a good hint to avoid using that software entirely. -- \ ?Members of the general public commonly find copyright rules | `\ implausible, and simply disbelieve them.? ?Jessica Litman, | _o__) _Digital Copyright_ | Ben Finney From ben+python at benfinney.id.au Wed Jul 4 00:35:08 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Jul 2018 14:35:08 +1000 Subject: PEP 526 - var annotations and the spirit of python References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> Message-ID: <857embboub.fsf@benfinney.id.au> Abdur-Rahmaan Janhangeer writes: > apart from programming, other questions go like this : > > [?] > *cut at this point* Ooh, I like that last step! How do we make that happen on demand? -- \ ?Everything you read in newspapers is absolutely true, except | `\ for that rare story of which you happen to have first-hand | _o__) knowledge.? ?Erwin Knoll | Ben Finney From arj.python at gmail.com Wed Jul 4 00:49:49 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 4 Jul 2018 08:49:49 +0400 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: <857embboub.fsf@benfinney.id.au> References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <857embboub.fsf@benfinney.id.au> Message-ID: conversation dies it denotes the end of the picture i was painting Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ From jlee54 at gmail.com Wed Jul 4 00:55:32 2018 From: jlee54 at gmail.com (Jim Lee) Date: Tue, 3 Jul 2018 21:55:32 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: <85h8lfbpa5.fsf@benfinney.id.au> References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> <6f8da285-2c72-2863-ff63-4dc39ab2c92a@gmail.com> <85o9fnbtbz.fsf@benfinney.id.au> <85h8lfbpa5.fsf@benfinney.id.au> Message-ID: On 07/03/18 21:25, Ben Finney wrote: > Jim Lee writes: > >> On 07/03/18 19:58, Ben Finney via Python-list wrote: >>> Jim Lee writes: >>> >>>> If you were to say John had 2 apples, Jane had 4 apples, and Joe had >>>> an indefinite number of apples, how many numbers are we talking about? >>> Three numbers. And ?indefinite? is not one of those numbers. So, no, >>> that doesn't support ?"indefinite" is a number?. >>> >> Exactly.? And you've just confirmed my original argument.? Thanks! > Still no, because you're the only one who claimed "indefinite" is a number. > No, I claimed that Steven was using three different numbers to refer to the time it takes to master a subject: 10,000 hours an indefinite number 2 years Being pedantic about the meaning of "number" is just a way to get off the subject.? You yourself said we were talking about THREE numbers! -Jim From jlee54 at gmail.com Wed Jul 4 00:58:37 2018 From: jlee54 at gmail.com (Jim Lee) Date: Tue, 3 Jul 2018 21:58:37 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: <857embboub.fsf@benfinney.id.au> References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <857embboub.fsf@benfinney.id.au> Message-ID: <1bcbdf04-ad65-f923-1e32-5fc6322b18ca@gmail.com> On 07/03/18 21:35, Ben Finney wrote: > Abdur-Rahmaan Janhangeer writes: > >> apart from programming, other questions go like this : >> >> [?] >> *cut at this point* > Ooh, I like that last step! How do we make that happen on demand? > You could start by not adding to the noise... :) From dieter at handshake.de Wed Jul 4 00:59:51 2018 From: dieter at handshake.de (dieter) Date: Wed, 04 Jul 2018 06:59:51 +0200 Subject: Python 3.7 configuration issue References: Message-ID: <87k1qb38ag.fsf@handshake.de> Robin Becker writes: > On a Ubuntu trusty system I ran > ./configure --prefix=/home/rptlab/PYTHON > make && make install > and get an error related to the ctypes module not being importable. > > I needed to do > > sudo apt-get install libffi-dev > ./configure --prefix=/home/rptlab/PYTHON --with-system-ffi > make && make install > > Something in setup.py seems to want ctypes irrespective of what I give > to configure; I don't actually know what the alternative to > --with-system-ffi does, but it didn't work for me. "libffi" contains the so called "foreign function interface" (an interface that allows code written in one language to call code written in another language). Likely, "ctypes" depends on it. Since some time, "ctypes" is part of Python's standard library. It is likely, that the Python test suite contains tests verifying that it could be build successfully. Your observations seem to indicate that "ctypes" contains its own "foreign function interface" specification and that this specification does not fit to the libraries available on your system. The "with-system-ffi" likely tells the Python generation process to use the system "foreign function interface" rather than its own. From ben+python at benfinney.id.au Wed Jul 4 01:03:00 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 04 Jul 2018 15:03:00 +1000 Subject: PEP 526 - var annotations and the spirit of python References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> <6f8da285-2c72-2863-ff63-4dc39ab2c92a@gmail.com> <85o9fnbtbz.fsf@benfinney.id.au> <85h8lfbpa5.fsf@benfinney.id.au> Message-ID: <8536wzbnjv.fsf@benfinney.id.au> Jim Lee writes: > I claimed that Steven was using three different numbers to refer to > the time it takes to master a subject: > > 10,000 hours > an indefinite number > 2 years Yes. He did so in the context of showing that *there is no precise number* that universally applies for the amount of effort required. Add as many numbers as you like, provided they're all in the same broad range. That is the point, and showing there are multiple numbers in play is *supporting* Steven's point. I still don't know what point you had, but I'm not really interested any more. -- \ ?This sentence contradicts itself ? no actually it doesn't.? | `\ ?Douglas Hofstadter | _o__) | Ben Finney From ian.g.kelly at gmail.com Wed Jul 4 01:05:01 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 3 Jul 2018 23:05:01 -0600 Subject: Congrats to Chris for breaking his PEP curse In-Reply-To: References: Message-ID: Now that I've actually read the PEP (sorry, I just assumed it would never fly), I have a couple of (tongue-in-cheek) observations about it: > group = re.match(data).group(1) if re.match(data) else None The only problem with this example of doing more work to save a line of code is that presumably the same programmer would now instead write: > group = match.group(1) if match := re.match(data) else None This abomination serves to convince me that the people who said the conditional expression should list the condition first were right. Secondly, I believe the order of evaluation means that, much as I would like to, I can't now write all my statements as: f(f := lambda f: do_something()) Because the outer f will be evaluated before the argument expression assigns it. Well, that's no fun. Is it too late to fix this? I'm only half-joking here; if it worked, this would be a much better way to pass a lambda to itself for recursion than the existing idiom: (lambda f: lambda *a: f(f, *a))(lambda s, x: 1 if x==0 else x * s(s, x-1))(10) That's a factorial function, in case you couldn't tell. Oh well, at least now I'll be able to write exec(x := 'del x'). On Tue, Jul 3, 2018 at 8:04 PM Steven D'Aprano wrote: > > Congratulations to Chris Angelico for breaking the dreaded "any PEP > written by Chris will be rejected" curse :-) > > Guido has announced his intention to accept PEP 572 (assignment > expressions) once the PEP has been cleaned up a bit. > > https://www.python.org/dev/peps/pep-0572/ > > (The current version of the PEP doesn't quite match the proposal as > nutted out over about a bazillion emails on two mailing lists starting in > FEBRUARY!!!) > > > Summary: > > Python 3.8 will allow an assignment-as-expression operator. The most > common uses are expected to be if and while statements: > > condition = expression > while condition: > do_something() > condition = expression > > will become: > > while condition := expression: > do_something() > > > Cascades of if statements, such as: > > # the dreaded arrowhead anti-pattern > mo = re.match(pattern, text) > if mo: > ... > else: > mo = re.match(another_pattern, text): > if mo: > ... > else: > mo = re.match(third_pattern, text): > if mo: > ... > > > will become flatter and easier to read: > > if mo := re.match(pattern, text): > ... > elif mo := re.match(another_pattern, text): > ... > elif mo := re.match(third_pattern, text): > ... > > > FAQs: > > Q. Why Pascal's assignment operator := instead of regular = assignment? > > A. To avoid the C bug magnet of mistakenly writing "if x = expr" when > you intended to write "if x == expr". > > > Q. Why not use "as"? > > A. There is an ambiguity due to with and except statements: > > with expr as name > > except Exception as name > > are already permitted and mean something different to ordinary > assignment expressions. > > > Q. Oh no, Python is doomed! This is the end of the world! > > A. That's not actually a question, is it? > > > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson > > -- > https://mail.python.org/mailman/listinfo/python-list From jlee54 at gmail.com Wed Jul 4 01:27:20 2018 From: jlee54 at gmail.com (Jim Lee) Date: Tue, 3 Jul 2018 22:27:20 -0700 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: <8536wzbnjv.fsf@benfinney.id.au> References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> <6f8da285-2c72-2863-ff63-4dc39ab2c92a@gmail.com> <85o9fnbtbz.fsf@benfinney.id.au> <85h8lfbpa5.fsf@benfinney.id.au> <8536wzbnjv.fsf@benfinney.id.au> Message-ID: On 07/03/18 22:03, Ben Finney wrote: > Jim Lee writes: > >> I claimed that Steven was using three different numbers to refer to >> the time it takes to master a subject: >> >> 10,000 hours >> an indefinite number >> 2 years > Yes. He did so in the context of showing that *there is no precise > number* that universally applies for the amount of effort required. > > Add as many numbers as you like, provided they're all in the same broad > range. That is the point, and showing there are multiple numbers in play > is *supporting* Steven's point. > > I still don't know what point you had, but I'm not really interested any > more. > That's the problem with jumping in and arguing pedantics.? You lose the original argument.? Paraphrasing what you *thought* the argument was does not help (unless your aim is to confuse things even further). -Jim From steve+comp.lang.python at pearwood.info Wed Jul 4 01:37:11 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 4 Jul 2018 05:37:11 +0000 (UTC) Subject: Infinity [was Re: PEP 526 - var annotations and the spirit of python] References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> Message-ID: On Wed, 04 Jul 2018 12:31:16 +1000, Chris Angelico wrote: [...] >> Ah, I see we're not going to leave it alone. In that case, >> "indefinite" >> is a "number", in that it was a quantity you cited along with the other >> two. If you'd prefer to call it a "quantity", that's fine with me. >> Talk about pedantic... > > I've had debates with people about whether "infinity" is a number or > not, but I've never yet heard anyone say that "indefinite" is a number. > Hmm. This could be interesting. What, haven't you ever raced somebody to see who can count to 100 fastest? "One, two, skip a few, ninety-nine, one hundred!" Clearly "indefinite" is just a synonym for "skip a few". For what it's worth, in the ordinary real numbers we all know and love, infinity is absolutely not a number, full stop. There's no debate about that. But there are a number (more than one, less than infinity *wink*) of areas of mathematics which treat one or more versions of infinity as entities which, for lack of a better name, I'll call "numbers". E.g. cardinal numbers, hyperreals, surreal numbers, and others. The mathematics of them is rather unintuitive. For instance, in the surreal numbers, ? is the smallest infinity; ?-1 is a separate infinity but one that you cannot get by counting up from 0, 1, 2, ... you have to start at ? and count down (by subtraction); 1+? is just ? but ?+1 is larger than infinity. (I'm not an expert on the surreals, I may have a couple of details wrong.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Wed Jul 4 01:52:34 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 4 Jul 2018 05:52:34 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On Sun, 01 Jul 2018 17:22:43 -0500, Tim Daneliuk wrote: >> x: int = 3 [...] > This strikes me as syntactic noise. Python is dynamically typed and > will remain so. Why clutter the language - even optionally - with stuff > like this? There's no need to declare x:int = 3 since any linter worth its salt ought to be able to infer that x is an int if it is assigned the value 3. Anyone writing that needs to be slapped with a clue-stick, it's not 1971 any more, type inference ought to be considered bare minimum for even a halfway decent type checker or linter. (If your linter doesn't, your linter sucks.) A better example would be: x: int = None which ought to be read as "x is an int, or None, and it's currently None". Better still would be something like this: alist: [int] = [] which is read as "x is a list of ints, currently empty". Guido believes that optional static typing is important and useful enough to dedicate syntax to it, so that editors, IDEs, linters and other tools can standardise on a single notation rather than every one picking their own: alist: [int] = [] is much better than: alist = [] # [int] List(Int) foolint:type=[integer] so having one syntax which everyone can agree on is a good thing. And as a general rule, using comments for semantically significant information is an anti-pattern. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Wed Jul 4 02:45:48 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 4 Jul 2018 06:45:48 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> Message-ID: On Tue, 03 Jul 2018 19:28:43 -0700, Jim Lee wrote: > On 07/03/18 16:51, Steven D'Aprano wrote: >> >> I love watching pedantically precise people panic and dig themselves >> into a hole. Since I'm an extremely pedantic person myself, I can >> recognise it in others -- especially when they're not as precisely >> correct as they think they're being. >> >> It was two numbers, not three, and not even close to "vastly" >> different. > > ? Ah, I see we're not going to leave it alone.? In that case, > "indefinite" is a "number", in that it was a quantity you cited along > with the other two. It would be nice if you consider the context of words rather than criticising them in isolation. In isolation, "10,000" and "some vaguely indefinite number between roughly one thousand and one hundred thousand, give or take some unspecified quantity" *wink* are clearly not the same. Any fool can see that. But in context, my description of the number as being "indefinite" was clarifying the meaning of the earlier use of 10,000 as a vague quantifier, not the specific number 9999+1. It hardly counts as a separate reference to a number when it is explicitly referring back to the first mention of the term "10,000" to clarify that it shouldn't be read as a specific number. Which you then treated as a specific number. >> Both numbers I mentioned (ten thousand hours, a couple of years) are >> within the bounds of acceptable precision to each other: their >> (figurative) error bars overlap. > > Who is defining acceptable here?? You *did* read the article I linked to, right? Given the factors that they mention -- the wide range in hours practiced, the lack of an upper limit, the variation between individuals, the lack of any hard dividing line between "expert" and "non-expert" -- what sort of precision do you think is acceptable? 10,000 ? 6 hours ? If you want to argue for a specific level of precision, I look forward to hearing your reasoning. Until then, I'm going to consider "ten thousand hours" to be a hand-wavy figure, not much more precise than "a shit-ton of hours". > And you are once again creating a > strawman argument.? My quibble was *not* with the difference between > 10,000 hours and 2 years. Quote: So we went from 10,000 hours, to infinite, and then back to a couple of years? followed by: I was simply pointing out that you used three vastly different numbers in almost the same breath to describe how long it takes a person to master something. Perhaps I have misunderstood you. If so, apologies. If you weren't complaining about them being "vastly different", what precisely was your complaint? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Wed Jul 4 03:05:44 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 4 Jul 2018 07:05:44 +0000 (UTC) Subject: Congrats to Chris for breaking his PEP curse References: Message-ID: On Tue, 03 Jul 2018 23:05:01 -0600, Ian Kelly wrote: > Now that I've actually read the PEP (sorry, I just assumed it would > never fly), I have a couple of (tongue-in-cheek) observations about it: > >> group = re.match(data).group(1) if re.match(data) else None > > The only problem with this example of doing more work to save a line of > code is that presumably the same programmer would now instead write: > >> group = match.group(1) if match := re.match(data) else None There's no stopping some people from making poor naming choices. Surely the standard name for match objects is "mo", not match? But if people were going to write that, surely they would now write: match = re.match(pattern, data) group = match.group(1) if match else None and I don't see how spreading it over two statements makes it better. Either you can tell the difference between re.match(pattern, data) and match, in which case one line or two makes little difference, or you can't, in which case one line or two makes little difference. group = re.match(pat, data).group(1) if re.match(pat, data) else None group = mo.group(1) if mo := re.match(pat, data) else None The second works for me. > Secondly, I believe the order of evaluation means that, much as I would > like to, I can't now write all my statements as: > > f(f := lambda f: do_something()) > > Because the outer f will be evaluated before the argument expression > assigns it. Watch out that you don't poke your tongue all the way through your cheek :-) > Well, that's no fun. Is it too late to fix this? I'm only > half-joking here; It doesn't work now: class X: pass obj = X() obj.f(setattr(obj, "f", lambda f: print(f+1))) raises AttributeError, as it bloody well ought to :-) > if it worked, this would be a much better way to pass > a lambda to itself for recursion than the existing idiom: > > (lambda f: lambda *a: f(f, *a))(lambda s, x: 1 if x==0 else x * s(s, > x-1))(10) /me reads that code "Kill it! Kill it with fire!!!" That was my *second*, more polite, reaction :-) > That's a factorial function, in case you couldn't tell. Well obviously. > Oh well, at least now I'll be able to write exec(x := 'del x'). I am *so* going to use that instead of "pass" from now on ;-) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Wed Jul 4 03:08:22 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Jul 2018 17:08:22 +1000 Subject: Infinity [was Re: PEP 526 - var annotations and the spirit of python] In-Reply-To: References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> Message-ID: On Wed, Jul 4, 2018 at 3:37 PM, Steven D'Aprano wrote: > On Wed, 04 Jul 2018 12:31:16 +1000, Chris Angelico wrote: > > [...] >>> Ah, I see we're not going to leave it alone. In that case, >>> "indefinite" >>> is a "number", in that it was a quantity you cited along with the other >>> two. If you'd prefer to call it a "quantity", that's fine with me. >>> Talk about pedantic... >> >> I've had debates with people about whether "infinity" is a number or >> not, but I've never yet heard anyone say that "indefinite" is a number. >> Hmm. This could be interesting. > > What, haven't you ever raced somebody to see who can count to 100 fastest? > > "One, two, skip a few, ninety-nine, one hundred!" > > Clearly "indefinite" is just a synonym for "skip a few". > > > For what it's worth, in the ordinary real numbers we all know and love, > infinity is absolutely not a number, full stop. There's no debate about > that. I'm sorry Steven, you have a fundamental misunderstanding here. Not about the nature of real numbers or infinity.... no, about the nature of debate. It doesn't matter that there is a pure and simple factual answer; you can get into a long debate about it anyway. (For the record, I was on the "no, 'infinity' is NOT a number" side of that debate. It gets amusing when you do it in JavaScript, though, because Infinity is a value of the type Number, despite not being a number; and NaN is also something of the type Number, despite not being a number *or* infinity. Of course, in Python, those values are all of type "float" instead.) ChrisA From breamoreboy at gmail.com Wed Jul 4 04:25:17 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Wed, 4 Jul 2018 09:25:17 +0100 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <6c16d466-4446-4e1f-214f-06001e000bc5@gmail.com> <6f8da285-2c72-2863-ff63-4dc39ab2c92a@gmail.com> <85o9fnbtbz.fsf@benfinney.id.au> <85h8lfbpa5.fsf@benfinney.id.au> Message-ID: On 04/07/18 05:55, Jim Lee wrote: > > > On 07/03/18 21:25, Ben Finney wrote: >> Jim Lee writes: >> >>> On 07/03/18 19:58, Ben Finney via Python-list wrote: >>>> Jim Lee writes: >>>> >>>>> If you were to say John had 2 apples, Jane had 4 apples, and Joe had >>>>> an indefinite number of apples, how many numbers are we talking about? >>>> Three numbers. And ?indefinite? is not one of those numbers. So, no, >>>> that doesn't support ?"indefinite" is a number?. >>>> >>> Exactly.? And you've just confirmed my original argument.? Thanks! >> Still no, because you're the only one who claimed "indefinite" is a >> number. >> > No, I claimed that Steven was using three different numbers to refer to > the time it takes to master a subject: > > 10,000 hours > an indefinite number > 2 years > > Being pedantic about the meaning of "number" is just a way to get off > the subject.? You yourself said we were talking about THREE numbers! > > -Jim > Please take this offline as it's completely irrelevant to this list. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From greg.ewing at canterbury.ac.nz Wed Jul 4 04:35:09 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 04 Jul 2018 20:35:09 +1200 Subject: Multi-threading with a simple timer? In-Reply-To: References: <1a9b7f3d-7405-44a1-b754-e9cf3569c824@googlegroups.com> <87in5w2z4j.fsf@elektro.pacujo.net> Message-ID: Another way on unix that doesn't use signals: import select, sys print("Enter something: ", end = "") sys.stdout.flush() fds = select.select((0,), (), (), 5) if fds[0] == [0]: data = sys.stdin.readline() print("You entered:", data) else: print("Too late!") -- Greg From greg.ewing at canterbury.ac.nz Wed Jul 4 04:42:53 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 04 Jul 2018 20:42:53 +1200 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: Grant Edwards wrote: > On 2018-07-03, Dan Stromberg wrote: > >>I used to write useful programs that ran in 256 bytes of RAM. > > Me too. The hex monitor I wrote for the keypad/display on my first computer fitted in 256 bytes. Which was important, seeing as the whole machine only had 1.5k. -- Greg From greg.ewing at canterbury.ac.nz Wed Jul 4 05:18:17 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 04 Jul 2018 21:18:17 +1200 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: <0ee06fb2-a3a0-ecab-a9b3-988123f812be@gmail.com> <857embboub.fsf@benfinney.id.au> Message-ID: Ben Finney wrote: > Abdur-Rahmaan Janhangeer writes: > >>[?] >>*cut at this point* > > Ooh, I like that last step! How do we make that happen on demand? You mention that Nazis ate fish. -- Greg From greg.ewing at canterbury.ac.nz Wed Jul 4 05:31:15 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 04 Jul 2018 21:31:15 +1200 Subject: Congrats to Chris for breaking his PEP curse In-Reply-To: References: Message-ID: Ian Kelly wrote: > I can't now write all my statements as: > > f(f := lambda f: do_something()) No, but you should be able to do (f := lambda f: do_something())(f) although since you're binding f in a scope that can be seen by the lambda, there's probably not much point in passing it, you could just do (f := lambda: do_something())() -- Greg From rosuav at gmail.com Wed Jul 4 06:09:20 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 4 Jul 2018 20:09:20 +1000 Subject: Congrats to Chris for breaking his PEP curse In-Reply-To: References: Message-ID: On Wed, Jul 4, 2018 at 7:31 PM, Gregory Ewing wrote: > Ian Kelly wrote: >> >> I can't now write all my statements as: >> >> f(f := lambda f: do_something()) > > > No, but you should be able to do > > (f := lambda f: do_something())(f) > > although since you're binding f in a scope that can be seen > by the lambda, there's probably not much point in passing it, > you could just do > > (f := lambda: do_something())() Not inside a loop, no. ChrisA From robin at reportlab.com Wed Jul 4 06:11:48 2018 From: robin at reportlab.com (Robin Becker) Date: Wed, 4 Jul 2018 11:11:48 +0100 Subject: Python 3.7 configuration issue In-Reply-To: <87k1qb38ag.fsf@handshake.de> References: <87k1qb38ag.fsf@handshake.de> Message-ID: <5e86629b-a728-4959-ad57-0b0460dd23f0@chamonix.reportlab.co.uk> On 04/07/2018 05:59, dieter wrote: .......... > > "libffi" contains the so called "foreign function interface" > (an interface that allows code written in one language to call > code written in another language). Likely, "ctypes" depends > on it. > > Since some time, "ctypes" is part of Python's standard library. > It is likely, that the Python test suite contains tests verifying > that it could be build successfully. > > Your observations seem to indicate that "ctypes" contains its > own "foreign function interface" specification and that this > specification does not fit to the libraries available on your > system. The "with-system-ffi" likely tells the Python generation > process to use the system "foreign function interface" rather > than its own. > I don't disagree with the above. I think the issue is that the configure process did not say anything about this. If ctypes is required and cannot be built then ./configure ...... should probably tell me; if that's not possible then the make step should do so and fail to complete. Failing at make install seems a bit late. I have to admit that I no longer understand how python builds its extensions; there used to be a step where you configured Modules/Setup*, but that seems no longer required. Any how as an experiment it seems that if I do have the libffi-dev package installed then the with-system-ffi flag is not required and the make install does work. It might be that make silently allows extension builds to fail even if they are 'required' and that later causes an error in the install phase. -- Robin Becker From bc at freeuk.com Wed Jul 4 08:48:26 2018 From: bc at freeuk.com (Bart) Date: Wed, 4 Jul 2018 13:48:26 +0100 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 04/07/2018 06:52, Steven D'Aprano wrote: > On Sun, 01 Jul 2018 17:22:43 -0500, Tim Daneliuk wrote: > >>> x: int = 3 > [...] > >> This strikes me as syntactic noise. Python is dynamically typed and >> will remain so. Why clutter the language - even optionally - with stuff >> like this? > There's no need to declare x:int = 3 since any linter worth its salt > ought to be able to infer that x is an int if it is assigned the value 3. > Anyone writing that needs to be slapped with a clue-stick, it's not 1971 > any more, type inference ought to be considered bare minimum for even a > halfway decent type checker or linter. Presumably one type hint applies for the whole scope of the variable, not just the one assignment. Which means that here: x: int = 3 x = f(x) you know x should still an int after these two statements, because the type hint says so. Without it: x = 3 x = f(x) x could be anything. > A better example would be: > > x: int = None > > which ought to be read as "x is an int, or None, and it's currently None". In that case the type hint is lying. If both x and y have type hints of 'int', then with this: z = x + y you might infer that z will be also 'int' (whether it it type hinted or not). But if either of x and y can be None, then this might not even execute. If something is an int, then make it an int: x: int = 0 -- bart From pfeiffer at cs.nmsu.edu Wed Jul 4 11:03:29 2018 From: pfeiffer at cs.nmsu.edu (Joe Pfeiffer) Date: Wed, 04 Jul 2018 09:03:29 -0600 Subject: File names with slashes [was Re: error in os.chdir] References: Message-ID: <1b601vf3ge.fsf@pfeifferfamily.net> Mikhail V writes: > [Steven D'Aprano] > >> (The same applies to Unix/Linux systems too, of course.) But while you're >> using Python to manipulate files, you should use Python rules, and that >> is "always use forward slashes". >> >> Is that reasonable? >> >> Under what circumstances would a user calling open(pathname) in Python >> need to care about backslashes? > > Cough cough > > On Windows a path is e.g.: > C:\programs\util\ > > So why should I use forward slashes in a Python literal? > I don't remember any problem caused by using backslashes in paths in Python - > are there problems? > (Apart from the fact that Python dos not have true raw string literals) > > So what is reasonable about using forward slashes? > It happens to me that I need to copy-paste real paths like 100 times > a day into scripts - do you propose to convert to forward slashes each time? That's what started the thread -- using backslashes caused a \a to be interpreted as a special character instead of two characters in the path. From muhammet_bozkurt795 at hotmail.com Wed Jul 4 11:30:36 2018 From: muhammet_bozkurt795 at hotmail.com (muhammet bozkurt) Date: Wed, 4 Jul 2018 15:30:36 +0000 Subject: installing sklearn Message-ID: When i try to install sklearn, i encounter a problem which is ?No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils? and ai don?t know how to deal with it therafore i need some help. Could you help me?(by the way i installed numpy) I put all error massage in to cmd.txt. -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: cmd.txt URL: From steve+comp.lang.python at pearwood.info Wed Jul 4 11:31:16 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 4 Jul 2018 15:31:16 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On Wed, 04 Jul 2018 13:48:26 +0100, Bart wrote: > Presumably one type hint applies for the whole scope of the variable, > not just the one assignment. You know how in C you can write int x = 1; # the type applies for just this one assignment x = 2.5; # perfectly legal, right? Wait, no, of course you can't do that. Why would you suggest that as even a possibility? Of course the type (whether inferred or annotated) applies for the entire scope of that variable. > Which means that here: > > x: int = 3 > x = f(x) > > you know x should still an int after these two statements, because the > type hint says so. Without it: > > x = 3 > x = f(x) > > x could be anything. That's not how type checking works. It makes *no difference* whether the type is inferred or hinted. Type hints only exist to cover the cases the type inference engine can't determine, or determine too strictly. See below. In the Dark Ages of type-checking, the compiler was too dumb to work out for itself what the type of variables is, so you have to explicitly declare them all, even the most obvious ones. Given such a declaration: int x = 3; # using C syntax the type checker is smart enough to look at the next line: x = f(x); and complain with a type-error if f() returns (say) a string, or a list. Checking that the types are compatible is the whole point of type checking. Now fast forward to the Enlightenment of type-inference, first used in a programming language in 1973 (so older than half the programmers alive today). That purpose doesn't go away because we're using type inference. With type-inference, the type-checker is smart enough to recognise what type a variable is supposed to be (at least sometimes): x = 3; # of course it's an int, what else could it be? x = f(x); and likewise complain if f(x) returns something other than an int. There's no point in type checking if you don't, you know, actually *check* the types. With type inference, the only reason to declare a variable's type is if the type checker can't infer it from the code, or if it infers the wrong type. (More on this later.) To do otherwise is as pointless and annoying as those comments which merely repeat what the code does: import math # import the math module mylist.append(v) # append v to mylist counter += 1 # add 1 to counter s = s.upper() # convert s to uppercase x: int = 3 # assign the int 3 to x Don't be That Guy who writes comments stating the bleeding obvious. There's not always enough information for the type checker to infer the right type. Sometimes the information simply isn't there: x = [] # a list of what? and sometimes you actually did intend what looks like a type-error to the checker: x = 3 # okay, x is intended to be an int x = "spam" # wait, this can't be right In the later case, you can annotate the variable with the most general "any type at all" type: from typing import Any x: Any = 3 # x can be anything, but happens to be an int now x = "spam" # oh that's fine then or you can simply not check that module. (Type checking is optional, not mandatory.) >> A better example would be: >> >> x: int = None >> >> which ought to be read as "x is an int, or None, and it's currently >> None". > > In that case the type hint is lying. "Practicality beats purity." "This type, or None" is such a common pattern that any half-way decent type checker ought to be able to recognise it. You can, of course, explicitly annotate it: x: Optional[int] = None but the type checker should infer that if you assign None to a variable which is declared int, you must have meant Optional[int] rather than just int. If it doesn't, get a better type checker. Note that None is a special case (because sometimes special cases *are* special enough to break the rules). This should be an error: x: int = "hello world" # wait, that's not an int But this is fine: x: Union[int, str] = "hello world" x is permitted to be an int or a string, and it happens to currently be a string. > If both x and y have type hints of 'int', then with this: > > z = x + y > > you might infer that z will be also 'int' Indeed. If you inferred that z was a list, you're doing it wrong :-) > (whether it it type hinted or not). But if either of x and y can > be None, then this might not even execute. If x or y could be None, the type checker should complain that None does not support the + operator. The whole point of type checking is to find bugs like that at compile time. A type checker that doesn't, you know, *actually find type bugs* is a waste of time and effort. This is Type-Checking 101 stuff. A type checker which can't even recognise that None+1 is a type error is a pretty crappy type checker. Why do you assume that the state of the art in type-checkers in 2018 is *worse* than the state of the art in 1953 when Fortran came out? > If something is an int, then make it an int: > > x: int = 0 Indeed, that's often the best way, except for the redundant type hint, which makes you That Guy: x: int = 0 # set x to the int 0 But the point of my example was that x is not an int. It is an optional int, that is, an int or None. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From none at invalid.com Wed Jul 4 13:41:00 2018 From: none at invalid.com (mm0fmf) Date: Wed, 04 Jul 2018 18:41:00 +0100 Subject: EXTERNAL: OSError: [Errno 48] Address already in use In-Reply-To: <8069c2eb-6d34-4f4b-aabe-31222e62b975@googlegroups.com> References: <20180629225955.GA75408@cskk.homeip.net> <134fa0d6-14ec-443b-a7b0-0b1f7102e540@googlegroups.com> <8069c2eb-6d34-4f4b-aabe-31222e62b975@googlegroups.com> Message-ID: On 02/07/2018 18:51, T Berger wrote: > On Monday, July 2, 2018 at 1:22:59 PM UTC-4, T Berger wrote: >> On Saturday, June 30, 2018 at 6:02:06 PM UTC-4, T Berger wrote: >>> On Friday, June 29, 2018 at 7:00:15 PM UTC-4, Cameron Simpson wrote: >>> >>>> The key point here from Jim is "simultaneously". Are you properly shutting down >>>> the Flask instance in IDLE before running from Terminal, and vice versa? >>> >>> Cameron, I try every option to quit either program, but they don't work. Or I should say, they mostly don't work. Once in a while they do. The one option which works (which is not a feasible option) is rebooting my Mac (actually that might not work either. I think I got the error message again this morning when I rebooted). >>> >>>> Otherwise both will try to use the same local port and There Can Be Only One. >>>> >>>> Do you need to run from both environments at the same time? I'd have thought >>>> not, which also leads me to: why are you flicking from IDLE to Terminal? I >>>> would have imagined using one or the other normally, not both. It isn't wrong >>>> to use both, just surprising. >>> >>> I'm working from a Python manual. I created the webapp in IDLE, and test it in Terminal, per the instructions in the manual. I use IDLE to edit my program, and then test it in terminal. When I go from one to the other, I get the error message. IDLE has a keyboard shortcut for quitting the shell?Cntl + C?but it doesn't work. Neither does restarting the shell. Neither does entering the kill command line, not in IDLE or terminal. >>> >>> Do you have any other suggestions? I'm going to email the writer. He doesn't mention how to deal with problems that might arise from working with two programs at the same time. Maybe Cntl+C should do it, but in my case it doesn't. >>> >>> Tamara >> >> Cameron, I'd like to add screenshots of my idle and terminal windows. Perhaps this would shed light on my this issue. >> >> This is my last window in terminal: >> >> [Restored Jul 2, 2018, 1:12:09 PM] >> Last login: Mon Jul 2 10:58:54 on ttys000 >> Restored session: Mon Jul 2 11:04:19 EDT 2018 >> 192:Webapp TamaraB$ exit >> logout >> Saving session... >> ...saving history...truncating history files... >> ...completed. >> >> [Process completed] >> ~~~~ >> To me this looks like the program running in terminal has been killed. >> >> Now this is my idle shell: >> >> RESTART: /Users/TamaraB/Desktop/Webapp/vsearch4web.py >> * Serving Flask app "vsearch4web" (lazy loading) >> * Environment: production >> [31m WARNING: Do not use the development server in a production environment. [0m >> [2m Use a production WSGI server instead. [0m >> * Debug mode: on >> Traceback (most recent call last): >> File "/Users/TamaraB/Desktop/Webapp/vsearch4web.py", line 26, in >> app.run(debug=True) >> File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 943, in run >> run_simple(host, port, self, **options) >> File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/werkzeug/serving.py", line 795, in run_simple >> s.bind(get_sockaddr(hostname, port, address_family)) >> OSError: [Errno 48] Address already in use >>>>> >> >> Why should there be an error in idle? It's the only app running. >> >> I emailed the writer of the manual I'm using, but who knows if, or when, he'll reply. So any help you provide would be great. >> >> Thanks, >> >> Tamara > > Addendum > > I forgot to add that I get the error message even after I exit from idle. Exiting from idle is supposed to kill the running program. That is what the the confirming dialog box explicitly states. > Tamara, read something on how TCP sockets work. Even if you close the program that created the socket, it doesn't mean the port in use will close immediately. It all depends on the state the socket was in. There is a process of exchanging info that sockets go through when closing to make sure both ends know the socket has closed. This can take time to complete. ISTR the default is 120secs. You can get past the wait by ensuring you close the socket when no connections are pending. Then you can use that port immediately. If there is something active on the socket, closing the socket puts you into TIME_WAIT and you cannot rebind to that socket till the timeout is over. Or you can set SO_REUSEADDR on the socket after you create it but before you use it. This allows another program to immediately use the port as soon as you call close on the socket. Only 1 program can use the port still, but this option allows you to bypass the wait state. This info has already been given in this thread but maybe you missed it or maybe didn't understand it. Please read up some general background information on sockets programming because it will make your programming life easier when you know what is meant to happen. From tjol at tjol.eu Wed Jul 4 13:41:38 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 4 Jul 2018 19:41:38 +0200 Subject: installing sklearn In-Reply-To: References: Message-ID: <6ffee330-0f8a-3d40-15bf-ae0106dd4b26@tjol.eu> On 04/07/18 17:30, muhammet bozkurt wrote: > When i try to install sklearn, i encounter a problem which is ?No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils? and ai don?t know how to deal with it therafore i need some help. Could you help me?(by the way i installed numpy) I'm pretty sure this is not a problem. The actual error message is at the bottom. > creating build\temp.win32-3.7\sklearn\svm\src\libsvm > C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\muham\appdata\local\programs\python\python37-32\lib\site-packages\numpy\core\include -I"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\ATLMFC\include" -I"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" -I"C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" /EHsc /Tpsklearn\svm\src\libsvm\libsvm_template.cpp /Fobuild\temp.win32-3.7\sklearn\svm\src\libsvm\libsvm_template.obj > Traceback (most recent call last): > File "", line 1, in > File "C:\Users\muham\AppData\Local\Temp\pip-install-_30ehor_\scikit-learn\setup.py", line 269, in > setup_package() > [snip] > File "c:\users\muham\appdata\local\programs\python\python37-32\lib\site-packages\numpy\distutils\ccompiler.py", line 139, in CCompiler_spawn > s, o = exec_command(cmd) > [snip] > UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 424: character maps to Now, I have no idea what causes this problem, and whether it's something about your system, or what. I do know that installing extension modules from source on Windows *can* be tricky. scikit-learn doesn't provide Python 3.7 binaries yet. They do provide binaries for Python 3.6. So the simplest solution to your immediate problem might be to stick with Python 3.6 for the time being until all the packages you rely on have been updated. -- Thomas From bc at freeuk.com Wed Jul 4 14:57:12 2018 From: bc at freeuk.com (Bart) Date: Wed, 4 Jul 2018 19:57:12 +0100 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 04/07/2018 16:31, Steven D'Aprano wrote: > On Wed, 04 Jul 2018 13:48:26 +0100, Bart wrote: > Of course the type (whether inferred or annotated) applies for the entire > scope of that variable. > In that case I don't understand what you're complaining about. You say that hinting is not needed here: x = 3 because you know x will be int at this point. But what you don't know if whether x will keep its int type. > With type-inference, the type-checker is smart enough to recognise what > type a variable is supposed to be (at least sometimes): > > x = 3; # of course it's an int, what else could it be? > x = f(x); > > and likewise complain if f(x) returns something other than an int. Are you still talking about Python here? Python is famous for being highly dynamic. So that that second assignment could set x to ANYTHING. I though the point of the type hint was to say that x has a particular type and it always keeps that same type. That way it is possible to make some assumptions about it. Otherwise, what's the point? I understand that type hinting doesn't enforce anything, such as checking that anything assigned to x is actually an int. Although that wouldn't be hard to do: just implement every x = y as x = int(y) or better, x = intcheck(y). > There's no point in type checking if you don't, you know, actually > *check* the types. > With type inference, the only reason to declare a variable's type is if > the type checker can't infer it from the code, or if it infers the wrong > type. (More on this later.) In Python, the reason to declare a variable's is presumably also to say that it HAS a fixed type. Type inference can still be used for certain purposes, such as optimising code, but it's not of much benefit to someone reading the code as the results of such analysis won't appear in the source. -- bart From ian.g.kelly at gmail.com Wed Jul 4 15:26:03 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Jul 2018 13:26:03 -0600 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On Wed, Jul 4, 2018, 9:36 AM Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Wed, 04 Jul 2018 13:48:26 +0100, Bart wrote: > >> A better example would be: > >> > >> x: int = None > >> > >> which ought to be read as "x is an int, or None, and it's currently > >> None". > > > > In that case the type hint is lying. > > "Practicality beats purity." > > "This type, or None" is such a common pattern that any half-way decent > type checker ought to be able to recognise it. You can, of course, > explicitly annotate it: > > x: Optional[int] = None > > but the type checker should infer that if you assign None to a variable > which is declared int, you must have meant Optional[int] rather than just > int. If it doesn't, get a better type checker. > > Note that None is a special case (because sometimes special cases *are* > special enough to break the rules). I don't think this case is special enough. As a person coming along later and trying to read the code, I should be able to trust that the type hint means what it says. I should not have to go look up the rules of the linter to infer that in this case, type A actually means type B. Optimize for readability, not writability. From mikhailwas at gmail.com Wed Jul 4 16:25:23 2018 From: mikhailwas at gmail.com (Mikhail V) Date: Wed, 4 Jul 2018 23:25:23 +0300 Subject: File names with slashes [was Re: error in os.chdir] Message-ID: Joe Pfeiffer wrote: >> On Windows a path is e.g.: >> C:\programs\util\ >> So what is reasonable about using forward slashes? >> It happens to me that I need to copy-paste real paths like 100 times >> a day into scripts - do you propose to convert to forward slashes each time? > That's what started the thread -- using backslashes caused a \a to be > interpreted as a special character instead of two characters in the > path. Yes, and the answer was a week ago: just put "r" before the string. r"C:\programs\util" And it worked till now. So why should I replace backslashes with forward slashes? There is one issue that I can't write \ on the end: r"C:\programs\util\" But since I know it's a path and not a file, I just write without trailing \. From rosuav at gmail.com Wed Jul 4 16:30:23 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Jul 2018 06:30:23 +1000 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: On Thu, Jul 5, 2018 at 6:25 AM, Mikhail V wrote: > Joe Pfeiffer wrote: > >>> On Windows a path is e.g.: >>> C:\programs\util\ >>> So what is reasonable about using forward slashes? >>> It happens to me that I need to copy-paste real paths like 100 times >>> a day into scripts - do you propose to convert to forward slashes each time? > >> That's what started the thread -- using backslashes caused a \a to be >> interpreted as a special character instead of two characters in the >> path. > > Yes, and the answer was a week ago: just put "r" before the string. > r"C:\programs\util" > > And it worked till now. So why should I replace backslashes with > forward slashes? > There is one issue that I can't write \ on the end: > r"C:\programs\util\" > > But since I know it's a path and not a file, I just write without trailing \. That's exactly the issue. But if you just always separate paths with forward slashes, you never have a problem. There is no "replace" happening; you simply use the correct path separation character from the start. You can assemble strings from pieces without having to remember to slap an "r" in front of each literal; you can have slashes at the ends of strings; everything will just work. ChrisA From ndbecker2 at gmail.com Wed Jul 4 16:44:36 2018 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 04 Jul 2018 16:44:36 -0400 Subject: profile guided optimization of loadable python modules? Message-ID: Has anyone tried to optimize shared libraries (for loadable python modules) using gcc with profile guided optimization? Is it possible? Thanks, Neal From breamoreboy at gmail.com Wed Jul 4 16:57:51 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Wed, 4 Jul 2018 21:57:51 +0100 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: On 04/07/18 21:30, Chris Angelico wrote: > On Thu, Jul 5, 2018 at 6:25 AM, Mikhail V wrote: >> Joe Pfeiffer wrote: >> >>>> On Windows a path is e.g.: >>>> C:\programs\util\ >>>> So what is reasonable about using forward slashes? >>>> It happens to me that I need to copy-paste real paths like 100 times >>>> a day into scripts - do you propose to convert to forward slashes each time? >> >>> That's what started the thread -- using backslashes caused a \a to be >>> interpreted as a special character instead of two characters in the >>> path. >> >> Yes, and the answer was a week ago: just put "r" before the string. >> r"C:\programs\util" >> >> And it worked till now. So why should I replace backslashes with >> forward slashes? >> There is one issue that I can't write \ on the end: >> r"C:\programs\util\" >> >> But since I know it's a path and not a file, I just write without trailing \. > > That's exactly the issue. But if you just always separate paths with > forward slashes, you never have a problem. There is no "replace" > happening; you simply use the correct path separation character from > the start. You can assemble strings from pieces without having to > remember to slap an "r" in front of each literal; you can have slashes > at the ends of strings; everything will just work. > > ChrisA > Maybe it would be smarter to build paths using os.sep, os.path.join and os.path.split rather than use literal strings. There is also os.altsep https://docs.python.org/3/library/os.html#os.altsep which if I'd heard about I'd forgotten about :) And others. Failing that there's always pathlib https://docs.python.org/3/library/pathlib.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From john_ladasky at sbcglobal.net Wed Jul 4 17:53:06 2018 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Wed, 4 Jul 2018 14:53:06 -0700 (PDT) Subject: Matplotlib 3D limitations, please recommend alternative Message-ID: <940a73c7-b232-44ae-b4c0-3b962fb538ee@googlegroups.com> I'm a regular Matplotlib user. Normally, I graph functions. I just attempted to graph an icosahedral surface using the plot_trisurf() methods of Matplotlib's Axes3D. I have discovered that Matplotlib is basically hard-wired for graphing functions, and therefore will not work for general-purpose 3D rendering. If I have repeated X and Y values in my arrays, it doesn't matter that the Z values might be different. Matplotlib raises a ValueError, with the message "x and y arrays must consist of at least 3 unique points." If I break down my polyhedron into individual triangles, I can get 16 of the 20 faces to render, but not all of them. Here's some minimal example code, which also catches and prints the cause of the ValueError. # ============================================================================ from itertools import cycle import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D COLOR = cycle("cmyrbg") ? = (1 + np.sqrt(5)) / 2 R = np.sqrt(1 + ?**2) VERTICES = np.array(((-1,0,?), (1,0,?), (-1,0,-?), (1,0,-?), (0,?,1), (0,?,-1), (0,-?,1), (0,-?,-1), (?,1,0), (-?,1,0), (?,-1,0), (-?,-1,0))) / R FACES = np.array(((0,4,1), (4,5,8), (4,8,1), (5,3,8), (0,9,4), (9,5,4), (9,2,5), (5,2,3), (9,0,11), (9,11,2), (7,2,11), (2,7,3), (11,0,6), (7,11,6), (7,6,10), (7,10,3), (0,1,6), (8,10,1), (6,1,10), (8,3,10))) fig = plt.figure(figsize=(8,8)) ax = fig.add_subplot(111, projection='3d') for t in FACES: print("\n\n", t, end=" ") try: ax.plot_trisurf(*zip(*VERTICES[t]), color=next(COLOR), alpha=0.5) except ValueError as e: print(e) print(VERTICES[t], end="") plt.show() # ============================================================================ I explored Python OpenGL bindings about three years ago, and quickly got bogged down. Even with Python to assist, dealing with OpenGL was like trying to program Java. Of course, OpenGL can do EVERYTHING. Far more than I need. I would like to render polyhedra, preferably with uniformly colored faces (I understand that color is a property that is associated with vertices in OpenGL). I would appreciate a simple interface. The rendering doesn't have to be especially fast or high quality. The Matplotlib visualization is acceptable, except of course for the missing faces. There are many 3D graphics packages on PyPI. Some appear to be quite specialized. I would appreciate your recommendations. Thanks! From mikhailwas at gmail.com Wed Jul 4 17:56:22 2018 From: mikhailwas at gmail.com (Mikhail V) Date: Thu, 5 Jul 2018 00:56:22 +0300 Subject: File names with slashes [was Re: error in os.chdir] Message-ID: ChrisA wrote: > Mikhail V wrote: >> Yes, and the answer was a week ago: just put "r" before the string. >> r"C:\programs\util" >> >> And it worked till now. So why should I replace backslashes with >> forward slashes? >> There is one issue that I can't write \ on the end: >> r"C:\programs\util\" >> >> But since I know it's a path and not a file, I just write without trailing \. > That's exactly the issue. If its about trailing \ - then this is issue with the syntax - not with the path. > But if you just always separate paths with > forward slashes, you never have a problem. There is no "replace" > happening; you simply use the correct path separation character from > the start. I am on windows, and the OP is (othrwise why would he ask?). If next version of windows will use forward slashes everywhere, then yes - there will be no "replace" happening. To the subject of the question - for the user it is most important to *see* and copy-paste the path string exactly as it is displayed everywhere else on windows. Other problems, like designing cross-platform utils, etc. are not really relevant to the simple use case (on windows). From ian.g.kelly at gmail.com Wed Jul 4 18:23:31 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 4 Jul 2018 16:23:31 -0600 Subject: Congrats to Chris for breaking his PEP curse In-Reply-To: References: Message-ID: On Wed, Jul 4, 2018 at 1:11 AM Steven D'Aprano wrote: > > On Tue, 03 Jul 2018 23:05:01 -0600, Ian Kelly wrote: > > > Now that I've actually read the PEP (sorry, I just assumed it would > > never fly), I have a couple of (tongue-in-cheek) observations about it: > > > >> group = re.match(data).group(1) if re.match(data) else None > > > > The only problem with this example of doing more work to save a line of > > code is that presumably the same programmer would now instead write: > > > >> group = match.group(1) if match := re.match(data) else None > > There's no stopping some people from making poor naming choices. Surely > the standard name for match objects is "mo", not match? I was referring to the variable "match" being referenced spatially prior to its assignment, not to the naming. > But if people were going to write that, surely they would now write: > > match = re.match(pattern, data) > group = match.group(1) if match else None Er, I think you're missing the point of the example from the PEP, which was documenting how sometimes people will make their code do extra work just to shave off a line. In retrospect, I should have explained this and not have assumed that the reader would be familiar with random parts of the PEP. The assignment expression makes it possible to shave the line without doing any extra work. Otherwise yes, I agree that this is better whether you have assignment expressions or not. From ataylor at faithlc.qld.edu.au Wed Jul 4 19:25:14 2018 From: ataylor at faithlc.qld.edu.au (Adrian Taylor) Date: Wed, 4 Jul 2018 23:25:14 +0000 Subject: Using Python with a website Message-ID: G'day All, I have just discovered Python and thanks to a script by Ethan I can read a foxpro database and change the required values. However my next big step is to be able to use this python feature within a website. Basically I want to be able to click on a button and call the script. This would in turn display some information on the webpage but do what it needs to do on the server. I have setup Apache and it all works on the server, my stumbling block is calling it from a website. I am using Server 2012 R2 Python 3.7 Apache 2.4 I can run the Python scripts from the command line prompt. Can anyone help? Regards, Adrian Taylor InfoHub - ICT - Helpdesk A : 5 Faith Avenue, Plainland , QLD 4341 T : 07 5466 9900 E : ataylor at faithlc.qld.edu.au W : www.faithlc.qld.edu.au [cid:image005.png at 01D2CD7E.0F6F4710] The information contained in this e-mail message and any attached files may be confidential information, and may also be the subject of legal professional privilege. If you are not the intended recipient any use, disclosure or copying of this e-mail is unauthorised. If you have received this e-mail in error, please notify the sender immediately by reply e-mail and delete all copies of this transmission together with any attachments. From ben+python at benfinney.id.au Wed Jul 4 19:57:40 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 05 Jul 2018 09:57:40 +1000 Subject: Using Python with a website References: Message-ID: <85o9fma70r.fsf@benfinney.id.au> Adrian Taylor writes: > I have just discovered Python [?] Welcome. The Python community has a starter page for beginners at . > However my next big step is to be able to use this python feature > within a website. Good. Be aware, though, that running a program on the public internet is a very complicated thing. Partly this is because your program needs to be on a web site, which itself needs to play nicely with the rest of the internet. And, an even more important part, is that the internet is a very wild place with a continual noise of malicious parties trying to compromise any site. So you need to do a lot of things just to defend against that. All of which is to say: There is a huge increase in complexity from ?my simple program which accepts input and produces output?, to a website that will do the same thing. See the community guides on web frameworks, which let you wrap your feature in a whole lot of code that will take care of the ?be a website? job . For general purpose use, I recommend Django which has excellent help . -- \ ?If sharing a thing in no way diminishes it, it is not rightly | `\ owned if it is not shared.? ?Augustine of Hippo (354?430 CE) | _o__) | Ben Finney From wrw at mac.com Wed Jul 4 21:37:59 2018 From: wrw at mac.com (William Ray Wing) Date: Wed, 04 Jul 2018 21:37:59 -0400 Subject: Matplotlib 3D limitations, please recommend alternative In-Reply-To: <940a73c7-b232-44ae-b4c0-3b962fb538ee@googlegroups.com> References: <940a73c7-b232-44ae-b4c0-3b962fb538ee@googlegroups.com> Message-ID: <38E2621C-0385-4845-907B-392B0AB0BA2F@mac.com> > On Jul 4, 2018, at 5:53 PM, John Ladasky wrote: > > I'm a regular Matplotlib user. Normally, I graph functions. I just attempted to graph an icosahedral surface using the plot_trisurf() methods of Matplotlib's Axes3D. I have discovered that Matplotlib is basically hard-wired for graphing functions, and therefore will not work for general-purpose 3D rendering. > > If I have repeated X and Y values in my arrays, it doesn't matter that the Z values might be different. Matplotlib raises a ValueError, with the message "x and y arrays must consist of at least 3 unique points." If I break down my polyhedron into individual triangles, I can get 16 of the 20 faces to render, but not all of them. Here's some minimal example code, which also catches and prints the cause of the ValueError. > > [big byte] > # ============================================================================ > > I explored Python OpenGL bindings about three years ago, and quickly got bogged down. Even with Python to assist, dealing with OpenGL was like trying to program Java. Of course, OpenGL can do EVERYTHING. Far more than I need. > The Python Open GL bindings have apparently changed fairly dramatically. I?m no expert, I?m working my way through the on-line book here: http://www.labri.fr/perso/nrougier/python-opengl/ But the author DOES lay things out in a nice step by step fashion - and with particular emphasis on scientific 3D plotting (which is what I?m after). > I would like to render polyhedra, preferably with uniformly colored faces (I understand that color is a property that is associated with vertices in OpenGL). I would appreciate a simple interface. The rendering doesn't have to be especially fast or high quality. The Matplotlib visualization is acceptable, except of course for the missing faces. > > There are many 3D graphics packages on PyPI. Some appear to be quite specialized. I would appreciate your recommendations. Thanks! > -- > https://mail.python.org/mailman/listinfo/python-list From steve+comp.lang.python at pearwood.info Wed Jul 4 21:40:46 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 5 Jul 2018 01:40:46 +0000 (UTC) Subject: Congrats to Chris for breaking his PEP curse References: Message-ID: On Wed, 04 Jul 2018 16:23:31 -0600, Ian Kelly wrote: [...] >> >> group = match.group(1) if match := re.match(data) else None >> >> There's no stopping some people from making poor naming choices. Surely >> the standard name for match objects is "mo", not match? > > I was referring to the variable "match" being referenced spatially prior > to its assignment, not to the naming. Oh. Well, that's the way ternary if works. Not everything in Python uses a strict left-to-right reading order. Just like English really. >> But if people were going to write that, surely they would now write: >> >> match = re.match(pattern, data) >> group = match.group(1) if match else None > > Er, I think you're missing the point of the example from the PEP No, I missed the point *you* were making. I thought you were complaining about the visual confusion of having a variable called match and a method called match. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Wed Jul 4 22:01:01 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 5 Jul 2018 02:01:01 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On Wed, 04 Jul 2018 19:57:12 +0100, Bart wrote: > On 04/07/2018 16:31, Steven D'Aprano wrote: >> On Wed, 04 Jul 2018 13:48:26 +0100, Bart wrote: > >> Of course the type (whether inferred or annotated) applies for the >> entire scope of that variable. >> >> > In that case I don't understand what you're complaining about. You say > that hinting is not needed here: > > x = 3 > > because you know x will be int at this point. But what you don't know if > whether x will keep its int type. *I* don't know, but that's why I'm running a type-checker. *The checker* knows, because it does static analysis of the code looking for mismatches between types (say, trying to add None to an int, or multiply a string by a dict, or assigning a list to something that ought to be a float). >> With type-inference, the type-checker is smart enough to recognise what >> type a variable is supposed to be (at least sometimes): >> >> x = 3; # of course it's an int, what else could it be? x = f(x); >> >> and likewise complain if f(x) returns something other than an int. > > Are you still talking about Python here? Python is famous for being > highly dynamic. So that that second assignment could set x to ANYTHING. Of course it could. And if that's your intention, as author of the code, you can simply *not run the type checker*, and the code will run just as you've written it. But we know (as so many people keep reminding us) that just because Python is extremely dynamic, that doesn't necessarily mean that we use it in extremely dynamic ways. Most of the time, say, 95% of the time, if x is an int *here*, it is intended to *stay* an int all the way through the lifetime of that variable. In those cases, if a later assignment to x sets it to "anything", that means you have a bug in your code. It might not be an obvious bug, or one that you spot up front. Testing can only prove the presence of bugs, not their absence. So you'll probably get a bunch of TypeErrors, one at a time, and over a period of many days or months or years, gradually your users will find each TypeError in your code, and report the bug, and you'll fix it. If that works for you, great! Or... you can run the type-checker, it will perform static analysis of your code, using whatever type information it can infer or you have annotated, and spot some (if not all) of those type errors ahead of time, so you can fix them immediately. If that doesn't work for you, that's cool too. That's why these are optional type hints not mandatory type declarations. > I though the point of the type hint was to say that x has a particular > type and it always keeps that same type. That way it is possible to make > some assumptions about it. Right. > Otherwise, what's the point? There wouldn't be one. > I understand that type hinting doesn't enforce anything, such as > checking that anything assigned to x is actually an int. Although that > wouldn't be hard to do: just implement every x = y as x = int(y) or > better, x = intcheck(y). No, that would needlessly slow down the runtime. First off, it would be redundant: x = int(2) is just a waste of a function call. Secondly, it would be *wrong*: x = f(x) is supposed to return an int, but is buggy and return a string, which by some ill chance happens to be "12345" which int() will happily convert. And thirdly, failures will still be *runtime failures*, just as they already are. So even when you catch the error, you aren't catching them ahead of time. Python already does runtime type checking. Every time you get a TypeError or AttributeError, that's a form of runtime type checking. The point of static type checking is to do some of the work ahead of time, and detect type errors before you run the code. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From robertvstepp at gmail.com Wed Jul 4 22:19:50 2018 From: robertvstepp at gmail.com (boB Stepp) Date: Wed, 4 Jul 2018 21:19:50 -0500 Subject: Getting posts to sort chronologically in tree view In-Reply-To: <38be8d27-1a60-43af-ab65-c86e40b47e0d@googlegroups.com> References: <4695f9b6-a737-41f5-9a8b-3625011499d9@googlegroups.com> <98abdd90-dac0-4e15-934f-47c33074ac3a@googlegroups.com> <85sh50ay53.fsf@benfinney.id.au> <38be8d27-1a60-43af-ab65-c86e40b47e0d@googlegroups.com> Message-ID: On Tue, Jul 3, 2018 at 10:26 PM T Berger wrote: > I don't think I want to try a mail list. I had subscribed to the > python-list a few weeks ago and then been forced to unsubscribe > because of the flood of irrelevant posts. I use Gmail. It does allow various ways of filtering emails as has been suggested. I normally use the Gmail web interface. This allows for the creation of a "Forums" tab. This is where I send all of my technical forum posts for reading when I get time. If you don't want to figure out how to filter emails, an easy thing to do with this Forums tab setup is when a Python List email arrives in your Inbox, click and drag that email to the Forums tab. Soon you will find that all of these emails will go there instead of your normal Inbox tab. If I find I don't want to read all of these emails (A true rarity!), then I don't find it burdensome to select all of the emails I might not want to read manually by checking all relevant check boxes and then clicking on the trash can icon to get rid of them all. Two things you _might_ want to do: 1) Subscribe to the Python Tutor email list. Though the main list people are more than happy to help out, you have noticed that this list generates a lot of emails on many days. The Tutor list is not so busy usually. Plus, if you are truly not comfortable with Python yet, you are more likely to find those _other_ emails of some interest. Also, many of the people like Ben, Steve, Cameron, etc. hang out in the Tutor list, too, and provide tons of help to Python learners. 2) Some of your questions have not been directly Python-related. You will probably find better and quicker answers if you search out the forums dedicated to those more specialized areas. -- boB From vpotlur1 at asu.edu Wed Jul 4 22:51:06 2018 From: vpotlur1 at asu.edu (Viswanath Potluri) Date: Wed, 4 Jul 2018 19:51:06 -0700 (PDT) Subject: Vectorizing operation involving multiple DataFrames Message-ID: <979bb8ec-2bd9-47c6-9cb9-8baf983204ee@googlegroups.com> I've a dataframe all_paths with say 9000 rows, and i've another dataframe Legs with 4000 rows. I need to filter all_paths dataframe based on a column called 'itineraries' which contains a list of strings, for each row in Legs. So, basically its like getting a dataframe that is subset of all_paths for each row in Legs. Then I need to perform a math operation on the columns of each subset and assign the values back to another column in all_paths. Following is my implementation def step1_vec(iti_list, idx): mask= all_paths.loc[all_paths['Path'].isin(iti_list)] Legs.loc[idx,'r']=np.dot(mask['demand'].values, mask['u'].values.T) Legs.loc[idx, 't']= Legs.loc[idx, 'k']/Legs.loc[idx, 'r'] def step2(): not_full_legs=Legs.loc[(~Legs['Leg ID'].isin(full_legs))&(Legs['t']<1)] np.vectorize(step1_vec (not_full_legs['itineraries'].values,not_full_legs.index.values) From dieter at handshake.de Thu Jul 5 00:47:57 2018 From: dieter at handshake.de (dieter) Date: Thu, 05 Jul 2018 06:47:57 +0200 Subject: Python 3.7 configuration issue References: <87k1qb38ag.fsf@handshake.de> <5e86629b-a728-4959-ad57-0b0460dd23f0@chamonix.reportlab.co.uk> Message-ID: <87a7r6i8zm.fsf@handshake.de> Robin Becker writes: > ... > I don't disagree with the above. I think the issue is that the > configure process did not say anything about this. If ctypes is > required and cannot be built then ./configure ...... should probably > tell me; if that's not possible then the make step should do so and > fail to complete. Failing at make install seems a bit late. I hope that "make test" would have shown this (and maybe other) problems. > ... > Any how as an experiment it seems that if I do have the libffi-dev > package installed then the with-system-ffi flag is not required and > the make install does work. It might be that make silently allows > extension builds to fail even if they are 'required' and that later > causes an error in the install phase. Some problems do not show dirrectly in the generation process but only during "import" of the extension module (or even when the module is actively used). That's why I always run the test suite after a Python generation. Typically, some of those tests fail (lacking necessary requirements) but I get an overview what I must expect. From greg.ewing at canterbury.ac.nz Thu Jul 5 01:34:55 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 Jul 2018 17:34:55 +1200 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > but the type checker should infer that if you assign None to a variable > which is declared int, you must have meant Optional[int] rather than just > int. This seems to be equivalent to saying that *all* types are Optional, in which case what point is there in having Optional at all? > Indeed, that's often the best way, except for the redundant type hint, > which makes you That Guy: > > x: int = 0 # set x to the int 0 But you've shown in an earlier example that such a hint is *not* always redundant, e.g. x = 0 x = 2.5 is legal and useful, whereas x: int = 0 x = 2.5 ought to be a type error. -- Greg From greg.ewing at canterbury.ac.nz Thu Jul 5 01:42:29 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 Jul 2018 17:42:29 +1200 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: Mikhail V wrote: > There is one issue that I can't write \ on the end: > r"C:\programs\util\" > > But since I know it's a path and not a file, I just write without trailing \. Indeed. There's never a need to put a backslash on the end of a path, as long as you always use os.path functions or equivalent to manipulate them. Which is a good idea anyway, since it will make things easier if anyone ever wants to run the code on something other than Windows. -- Greg From greg.ewing at canterbury.ac.nz Thu Jul 5 01:59:05 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 05 Jul 2018 17:59:05 +1200 Subject: Congrats to Chris for breaking his PEP curse In-Reply-To: References: Message-ID: Steven D'Aprano wrote: > Not everything in Python uses a strict left-to-right reading order. Just > like English really. Well, English is read left to right, but it doesn't always mean things in the order it says them. :-) -- Greg From arj.python at gmail.com Thu Jul 5 02:23:00 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 5 Jul 2018 10:23:00 +0400 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: *you know x should still an int after these two statements, because the type hint says so. Without it: x = 3 x = f(x)x could be anything.* *...* *If something is an int, then make it an int: x: int = 0* i'm not arguing about it being useful or not but rather people turn to python to have a sleek programming experience python has a personality unless of course we are interested in making it become a stylised copy cat or a mix-it-all language i make languages for fun during my spare time and from my experience i can tell that syntax beats the technical aspects it's like the front-end and back-end of a website, sure you need something that works and is efficient but the back-end can be switched. like a website can be powered by java, ruby, py, etc unless of course you've thoroughly connected those two like in the case of wordpress. decoupling the front and back end allows the same user experience across technologies. that's why we have IronPython, Jython etc. the back-end matters not, but the front-end yes, in our case it's the syntax. it's not an issue of being dynamic or not as py is dynamic and will remain so, rather we must concern ourselves with coding experience if type hinting is the approval of the steps taken by other languages, coerced by technical points and is something we miss in python or is like hey another feature : why not?, for both reasons it explains not it's purpose nevertheless type hinting is like an enhanced comment, from the language making point of view, it is interesting as it is a recognised ignored pattern. the real power of it will come later, for other implementations. let me illustrate this. take the example of javascript, it is like python loose, beginner candy but crazier and more work. let us see typescript, which at the end of the day compiles to js. in typescript you must specify for basic types as well as for arrays the type, number, string etc. type hinting will make it easier for source-to-source compilation to python or vice versa like you write your python code and it outputs to C or Java. tools doing this will have less effort to do as python already has an in-built way to specify the type. having an in-built way means no need for special comments, and ensures uniformity as errors are be raised by the interpreter itself. personally if i want to undertake a big project in C now, i'll maybe make python do it for me (source-to-source compilation). just imagine the power that python can unleash as the py coder will be able to become embedded systems programmers or android programmers (ideas for free) from a language maker's perspective, through type hinting python will be doing a premi?re, coupled with the -> operator, it has what it needs to ensure a dual personnality, the advantages of which can take another thread however, as a python user i have always liked a smooth experience, smooth to read and smooth to write, a language without much ado, a language simple to use and maintain. we must remember that type hinting relies on good faith as it can lie but that's not a prob if i were to choose type hinting or no type hinting i'd choose no but it's use can be regulated. like a style guide on why and when to use it or some special comments at the top (in the docstring) but it should be regulated. if it's use is specified then no prob a successful language lies in design, not in the implementation of the design. in language making, function follows form. by successful i have not included the marketing of it. python is not tied to C, actually C is too bad to be used by humanity in the 21st century, it is totally possible for python to replace it as the de-facto language for hard jobs. we'll just need to switch back-end, keeping the syntax intact (with minor modifs as needed). (the computer does not understand C). if so, it hints to two programming modes in python, one for your daily quick jobs and one for hard stuffs. final words : no to type hinting in your "everyday" codes yes for specific uses appendix : one language for all jobs is totally possible and python is very much suited for to become that language, but it all depends on human acceptance Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius (Paradise Island In the Indian Ocean) From steve+comp.lang.python at pearwood.info Thu Jul 5 02:50:09 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 5 Jul 2018 06:50:09 +0000 (UTC) Subject: File names with slashes [was Re: error in os.chdir] References: Message-ID: On Thu, 05 Jul 2018 00:56:22 +0300, Mikhail V wrote: > for the user it is most important to > *see* and copy-paste the path string exactly as it is displayed > everywhere else on windows. So in Windows, you see: dir directory\file.pdf so in Python, we have to use exactly the same path with absolutely no changes: open(directory\file.pdf, 'r') In Explorer and the open-file dialog of most applications, they will see paths like this: directory\file name with spaces with the extension (.jpg, .pdf, .docx etc) suppressed. So by your argument, Python needs to accept strings without quotes: open(directory\file name with spaces, 'r') and guess which extension you mean. That would be fun to watch in action. Python programmers on Macs will see lots of file paths that display with colons, like this: directory:file.txt and mentally translate it to have a forward slash. Linux programmers will see paths with spaces and other metacharacters escaped: directory/file\ name\ with\ spaces.txt and mentally translate it to remove the backslashes. If they're not already doing this, they'll surely have to do it soon, when unused backslash escapes become an error. https://bugs.python.org/issue32912 Do you believe Python programmers on Windows are especially dumber than Python programmers on Macs and Linux? I don't, but you seem to want to coddle them and protect them from having to think about what they're doing. I think that's patronising of your fellow Windows users. I'm reminded of a quote by the late Terry Pratchett, an English author, talking about his experience publishing books in the US. If I remember correctly, he said that American readers aren't dumb, but American publishers are convinced that they are. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Thu Jul 5 02:58:22 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 5 Jul 2018 06:58:22 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On Wed, 04 Jul 2018 13:26:03 -0600, Ian Kelly wrote: [...] >> Note that None is a special case (because sometimes special cases *are* >> special enough to break the rules). > > > I don't think this case is special enough. As a person coming along > later and trying to read the code, I should be able to trust that the > type hint means what it says. I should not have to go look up the rules > of the linter to infer that in this case, type A actually means type B. I hear what you're saying, and I neither agree nor disagree. But describing it as "Type A" versus "Type B" exaggerates the difference. Its more like "Type A" versus "Optional Type A" -- and, so the argument goes, it ought to be blindingly obvious from context. > Optimize for readability, not writability. And that is why we all hold COBOL up as the paragon of excellence for a programming language! *wink* Or if you don't like COBOL, how about Hypertalk? put 42 into x ask file "Which file would you like to open?" with "default.txt" if it is empty exit to Hypercard put it into thefile open file thefile repeat with num = 1 to x write "spam" to file thefile end repeat close file thefile -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Thu Jul 5 03:05:30 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Jul 2018 17:05:30 +1000 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On Thu, Jul 5, 2018 at 4:58 PM, Steven D'Aprano wrote: >> Optimize for readability, not writability. > > And that is why we all hold COBOL up as the paragon of excellence for a > programming language! *wink* > > Or if you don't like COBOL, how about Hypertalk? > > put 42 into x > ask file "Which file would you like to open?" with "default.txt" > if it is empty exit to Hypercard > put it into thefile > open file thefile > repeat with num = 1 to x > write "spam" to file thefile > end repeat > close file thefile > Using Chai and Mocha to test a Node.js web app ends up looking a bit like that, actually. You perform a request, then make assertions: expect(res).to.be.json; expect(res.body).to.be.an(object); expect(res.body.stuff).to.be.an(array); expect(res.body.stuff).to.have.length(5); etc etc etc. ChrisA From auriocus at gmx.de Thu Jul 5 03:17:20 2018 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 5 Jul 2018 09:17:20 +0200 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: Am 04.07.18 um 17:31 schrieb Steven D'Aprano: > On Wed, 04 Jul 2018 13:48:26 +0100, Bart wrote: > >> Presumably one type hint applies for the whole scope of the variable, >> not just the one assignment. > > You know how in C you can write > > int x = 1; # the type applies for just this one assignment > x = 2.5; # perfectly legal, right? > Not sure what point you are trying to make, but your example compiles in C, if you replace the '#' comment sign with '//'. Only it doesn't do what you might think: the 2.5 is down-converted to an integer, therefore x will be 2 in the end. There will be a compiler warning but no error. ===================================== Apfelkiste:Tests chris$ cat intx.c #include int main() { int x=1; x=2.5; printf("%d\n", x); return 0; } Apfelkiste:Tests chris$ gcc intx.c -o intx && ./intx intx.c:4:4: warning: implicit conversion from 'double' to 'int' changes value from 2.5 to 2 [-Wliteral-conversion] x=2.5; ~^~~ 1 warning generated. 2 Christian From antoon.pardon at vub.be Thu Jul 5 03:44:02 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 5 Jul 2018 09:44:02 +0200 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: <7ec27418-04b8-25fb-b4ce-adaa08e4e4b7@vub.be> On 05-07-18 08:58, Steven D'Aprano wrote: > >> Optimize for readability, not writability. > And that is why we all hold COBOL up as the paragon of excellence for a > programming language! *wink* > > Or if you don't like COBOL, how about Hypertalk? Well you always mention how like english the if-expression in python is and thus by implication readable. -- Antoon. From arj.python at gmail.com Thu Jul 5 03:47:10 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 5 Jul 2018 11:47:10 +0400 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: <7ec27418-04b8-25fb-b4ce-adaa08e4e4b7@vub.be> References: <7ec27418-04b8-25fb-b4ce-adaa08e4e4b7@vub.be> Message-ID: he means too much of it Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Well you always mention how like english the if-expression in python is and > thus by implication readable. > > -- > Antoon. > > -- > https://mail.python.org/mailman/listinfo/python-list > From arj.python at gmail.com Thu Jul 5 04:43:38 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 5 Jul 2018 12:43:38 +0400 Subject: about main() Message-ID: just when to use main() in if __name__ == '__main__' : main() is far is it good in py? or should file intended to be run just not include it? Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ From steve+comp.lang.python at pearwood.info Thu Jul 5 05:59:55 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 5 Jul 2018 09:59:55 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On Thu, 05 Jul 2018 17:34:55 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> but the type checker should infer that if you assign None to a variable >> which is declared int, you must have meant Optional[int] rather than >> just int. > > This seems to be equivalent to saying that *all* types are Optional, in > which case what point is there in having Optional at all? How do you reason that? x = 3 infers that x is an int, and only an int, not an optional int. An explicit hint, like: def func(x:int) -> something requires func(x) to only accept int arguments, not int-or-None. But: def func(x:int = None) -> something says to the type checker, in effect, "Yeah, I know I said an int, but I obviously also want to allow None because that's the default, so just deal with it, okay?" You may or may not like the "Do What I Mean" aspect of this, you might question whether Optional[int] is really more common than Union[int, str] (for example). But I don't see how you go from this narrowly defined exceptional situation ("use a hint for one type and assign None on the same line") and conclude that "all types are optional". >> Indeed, that's often the best way, except for the redundant type hint, >> which makes you That Guy: >> >> x: int = 0 # set x to the int 0 > > But you've shown in an earlier example that such a hint is *not* always > redundant But it is redundant in *that* example. Your hint is not giving any more information that what the reader, or type checker, can already infer. These are useful: x: Any = 3 # x can be anything, but is currently an int x: int = None # x can be an int, or None x: Union[int, str] = 'abc' # x can be either an int, or a # string, not just the string you see here but this is redundant (unless you're forced to use a type-checker with no type inference at all): x: int = 3 Well duh of course its an int. That's what 3 is. An int. If it were a comment, you'd slap the writer around the head with a clue-stick: x = 3 # x is an int > e.g. > > x = 0 > x = 2.5 > > is legal and useful, Of course it is useful -- well, not *literally* that pair of lines, but I know what you mean -- but its probably an error. Mypy allows ints wherever a float is expected: x = 0.0 # infer x is a float x = 1 # ints are compatible with floats https://github.com/python/typing/issues/48 which probably isn't *strictly* valid (ints can exceed the range of floats), so I assume there's a switch to disable it. But the other way is an error: x = 0 # infer x is an int x = 2.5 # that's not an int! Some type checkers may even enforce a strict separation of ints and floats. In any case, if you want to overrule the type checker, you can: x: Union[int, float] = 0 x = 2.5 A better example would be: x = 0 # infers type int, or maybe type Number x = "foo" # certainly not a number, so a type error > whereas > > x: int = 0 > x = 2.5 > > ought to be a type error. It ought to be a type error even without the hint. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Thu Jul 5 06:04:13 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 5 Jul 2018 10:04:13 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: Message-ID: On Thu, 05 Jul 2018 09:17:20 +0200, Christian Gollwitzer wrote: > Am 04.07.18 um 17:31 schrieb Steven D'Aprano: >> On Wed, 04 Jul 2018 13:48:26 +0100, Bart wrote: >> >>> Presumably one type hint applies for the whole scope of the variable, >>> not just the one assignment. >> >> You know how in C you can write >> >> int x = 1; # the type applies for just this one assignment x = >> 2.5; # perfectly legal, right? >> >> > Not sure what point you are trying to make, but your example compiles in > C, if you replace the '#' comment sign with '//'. Oops. But... it compiles? Seriously? > Only it doesn't do > what you might think: the 2.5 is down-converted to an integer, therefore > x will be 2 in the end. There will be a compiler warning but no error. Sometimes I wonder how C programmers manage to write a bug-free "Hello World" program. No wonder it is described as a type-unsafe language or a weakly-typed language. I understand upcasting ints to floats, that's cool (even if a few languages take a hard line on that too, I don't). I understand Python's dynamic typing approach. I don't understand C requiring type declarations, then down-casting floats to integers. At least it shows a warning. But hell, who pays attention to C compiler warnings? There's *so many of them*. (And I bet that by default the warning is disabled, amirite?) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Thu Jul 5 06:08:25 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 5 Jul 2018 10:08:25 +0000 (UTC) Subject: Congrats to Chris for breaking his PEP curse References: Message-ID: On Thu, 05 Jul 2018 17:59:05 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> Not everything in Python uses a strict left-to-right reading order. >> Just like English really. > > Well, English is read left to right, but it doesn't always mean things > in the order it says them. :-) "First things first, but not necessarily in that order." - Doctor Who -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rhodri at kynesim.co.uk Thu Jul 5 06:22:50 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 5 Jul 2018 11:22:50 +0100 Subject: about main() In-Reply-To: References: Message-ID: On 05/07/18 09:43, Abdur-Rahmaan Janhangeer wrote: > just when to use main() in > > if __name__ == '__main__' : > main() > > is far is it good in py? > > or should file intended to be run just not include it? It's a matter of taste. If your "file intended to be run" also contains things that might be useful as a module, use the "if __name__ == '__main__'" trick. Otherwise it can be more of a distraction than a help. I'm not a big fan of "main()" functions myself; creating a function which will be called exactly once seems rather wasteful. -- Rhodri James *-* Kynesim Ltd From bc at freeuk.com Thu Jul 5 06:26:54 2018 From: bc at freeuk.com (Bart) Date: Thu, 5 Jul 2018 11:26:54 +0100 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 05/07/2018 10:59, Steven D'Aprano wrote: > But it is redundant in *that* example. Your hint is not giving any more > information that what the reader, or type checker, can already infer. > > These are useful: > > x: Any = 3 # x can be anything, but is currently an int > > x: int = None # x can be an int, or None > > x: Union[int, str] = 'abc' # x can be either an int, or a > # string, not just the string you see here This is one reason I dropped type hinting from my own developments. It's a poor, half-baked version of both true static typing, and of true type inference. Look at Haskell for how type inference can be done well (I have to admire it even if I don't understand it). And at numerous other languages that are properly statically typed (Ada being one of the most rigorous, while C++ is a nightmare). -- bart From arj.python at gmail.com Thu Jul 5 06:39:07 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 5 Jul 2018 14:39:07 +0400 Subject: about main() In-Reply-To: References: Message-ID: i once saw a python course (by academics) advertising main() in it's promotional flier that's put me in doubt as whether it's that recommended or not Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > main() > > > > is far is it good in py? > > > > or should file intended to be run just not include it? > > It's a matter of taste. If your "file intended to be run" also contains > things that might be useful as a module, use the "if __name__ == > '__main__'" trick. Otherwise it can be more of a distraction than a > help. I'm not a big fan of "main()" functions myself; creating a > function which will be called exactly once seems rather wasteful. > > -- > Rhodri James *-* Kynesim Ltd > From vpotlur1 at asu.edu Thu Jul 5 06:39:36 2018 From: vpotlur1 at asu.edu (Viswanath Potluri) Date: Thu, 5 Jul 2018 03:39:36 -0700 (PDT) Subject: Vectorizing operation involving multiple DataFrames In-Reply-To: <979bb8ec-2bd9-47c6-9cb9-8baf983204ee@googlegroups.com> References: <979bb8ec-2bd9-47c6-9cb9-8baf983204ee@googlegroups.com> Message-ID: On Wednesday, July 4, 2018 at 7:51:19 PM UTC-7, Viswanath Potluri wrote: > I've a dataframe all_paths with say 9000 rows, and i've another dataframe Legs with 4000 rows. I need to filter all_paths dataframe based on a column called 'itineraries' which contains a list of strings, for each row in Legs. So, basically its like getting a dataframe that is subset of all_paths for each row in Legs. Then I need to perform a math operation on the columns of each subset and assign the values back to another column in all_paths. Following is my implementation > > def step1_vec(iti_list, idx): > mask= all_paths.loc[all_paths['Path'].isin(iti_list)] > Legs.loc[idx,'r']=np.dot(mask['demand'].values, mask['u'].values.T) > Legs.loc[idx, 't']= Legs.loc[idx, 'k']/Legs.loc[idx, 'r'] > > def step2(): > not_full_legs=Legs.loc[(~Legs['Leg ID'].isin(full_legs))&(Legs['t']<1)] > np.vectorize(step1_vec (not_full_legs['itineraries'].values,not_full_legs.index.values) does someone has a solution for my question?? From alister.ware at ntlworld.com Thu Jul 5 06:55:50 2018 From: alister.ware at ntlworld.com (Alister) Date: Thu, 05 Jul 2018 10:55:50 GMT Subject: Using Python with a website Message-ID: On Wed, 04 Jul 2018 23:25:14 +0000, Adrian Taylor wrote: > G'day All, > > I have just discovered Python and thanks to a script by Ethan I can read > a foxpro database and change the required values. > However my next big step is to be able to use this python feature within > a website. > > Basically I want to be able to click on a button and call the script. > This would in turn display some information on the webpage but do what > it needs to do on the server. > I have setup Apache and it all works on the server, my stumbling block > is calling it from a website. > > I am using Server 2012 R2 Python 3.7 Apache 2.4 I can run the Python > scripts from the command line prompt. > > Can anyone help? > > Regards, > Adrian Taylor InfoHub - ICT - Helpdesk > > > > A : 5 Faith Avenue, Plainland , QLD 4341 T : 07 5466 9900 E : > ataylor at faithlc.qld.edu.au > W : www.faithlc.qld.edu.au > > [cid:image005.png at 01D2CD7E.0F6F4710] > > > > The information contained in this e-mail message and any attached files > may be confidential information, and may also be the subject of legal > professional privilege. If you are not the intended recipient any use, > disclosure or copying of this e-mail is unauthorised. If you have > received this e-mail in error, please notify the sender immediately by > reply e-mail and delete all copies of this transmission together with > any attachments. start by looking up uwsgi -- Sun in the night, everyone is together, Ascending into the heavens, life is forever. -- Brand X, "Moroccan Roll/Sun in the Night" From marko at pacujo.net Thu Jul 5 07:11:52 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 05 Jul 2018 14:11:52 +0300 Subject: about main() References: Message-ID: <874lhe2ayv.fsf@elektro.pacujo.net> Abdur-Rahmaan Janhangeer : > just when to use main() in > > if __name__ == '__main__' : > main() > > is far is it good in py? > > or should file intended to be run just not include it? I think all Python programs should have it. Marko From marko at pacujo.net Thu Jul 5 07:20:04 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 05 Jul 2018 14:20:04 +0300 Subject: about main() References: Message-ID: <87zhz60w0r.fsf@elektro.pacujo.net> Rhodri James : > I'm not a big fan of "main()" functions myself; creating a function > which will be called exactly once seems rather wasteful. A function is the encapsulation of a distinct ... well ... function. Functions that are called just once are desirable. So I'm saying the opposite: * Have no code outside functions. * Make the functions as small as (meaningfully) possible. Most should be smaller than 20 lines. * Create as many functions as you can. Marko From bc at freeuk.com Thu Jul 5 07:41:24 2018 From: bc at freeuk.com (Bart) Date: Thu, 5 Jul 2018 12:41:24 +0100 Subject: about main() In-Reply-To: References: Message-ID: On 05/07/2018 11:22, Rhodri James wrote: > On 05/07/18 09:43, Abdur-Rahmaan Janhangeer wrote: >> just when to use main() in >> >> if __name__ == '__main__' : >> ???? main() >> >> is far is it good in py? >> >> or should file intended to be run just not include it? > > It's a matter of taste.? If your "file intended to be run" also contains > things that might be useful as a module, use the "if __name__ == > '__main__'" trick.? Otherwise it can be more of a distraction than a > help.? I'm not a big fan of "main()" functions myself; creating a > function which will be called exactly once seems rather wasteful. Wasteful of what? Since it will only be called once, that is not exactly an overhead. But packaging the main function like that has some advantages: 1. It /is/ tidily packaged 2. You can place it anywhere in the program 3. It can be more easily copied 4. If you had a need to, it could call itself 5. If sometimes you had to wrap extra code around it, that becomes easier: prologue() main() epilogue() 6. If you had to run it more than once /within the same execution environment/, that is easier too. 7. If you had a choice of main1() and main2(), that becomes easier as well. Actually, I can't think of any downsides. Not packaging main() into its own function reminds of sprawling, unstructured Fortran code from the 1970s, when people even frowned upon putting long stretches of code into a subroutine. -- bart From arj.python at gmail.com Thu Jul 5 07:45:19 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 5 Jul 2018 15:45:19 +0400 Subject: about main() In-Reply-To: <87zhz60w0r.fsf@elektro.pacujo.net> References: <87zhz60w0r.fsf@elektro.pacujo.net> Message-ID: performance? Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ * Create as many functions as you can From breamoreboy at gmail.com Thu Jul 5 07:50:07 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Thu, 5 Jul 2018 12:50:07 +0100 Subject: about main() In-Reply-To: References: Message-ID: On 05/07/18 11:39, Abdur-Rahmaan Janhangeer wrote: > i once saw a python course (by academics) advertising main() in it's > promotional flier > > that's put me in doubt as whether it's that recommended or not > > Abdur-Rahmaan Janhangeer > https://github.com/Abdur-rahmaanJ > I can remember back to the good old days when people on this list could write in English and didn't top post. So much for progress :( -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From antoon.pardon at vub.be Thu Jul 5 07:54:28 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 5 Jul 2018 13:54:28 +0200 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: <3e587ddc-d43a-d617-03ee-7b76b65c68da@vub.be> On 05-07-18 11:59, Steven D'Aprano wrote: > On Thu, 05 Jul 2018 17:34:55 +1200, Gregory Ewing wrote: > > >>> Indeed, that's often the best way, except for the redundant type hint, >>> which makes you That Guy: >>> >>> x: int = 0 # set x to the int 0 >> But you've shown in an earlier example that such a hint is *not* always >> redundant > But it is redundant in *that* example. Your hint is not giving any more > information that what the reader, or type checker, can already infer. Yes it gives more information. Without the hint you can only interfere that it is an int at that point. IIUC, with the hint you can interfere it is supposed to be an int during its life time, not just at that point. -- Antoon. From joel.goldstick at gmail.com Thu Jul 5 07:55:05 2018 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 5 Jul 2018 07:55:05 -0400 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> Message-ID: On Thu, Jul 5, 2018 at 7:45 AM, Abdur-Rahmaan Janhangeer wrote: > performance? You are asking basic file layout questions in the learning process of understand how to code in python. Performance should be very low on your list of concerns. The only thing that happens when the file is loaded is that it gets compiled, and run. If it is imported, and you have the 'if __name__ ... block, it will run the code within the if block. If that has a main() function it makes it simpler later to change what main does instead of cluttering up the if block. But there is no 'performance' issue that I can see. > > Abdur-Rahmaan Janhangeer > https://github.com/Abdur-rahmaanJ > > * Create as many functions as you can > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From breamoreboy at gmail.com Thu Jul 5 08:03:10 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Thu, 5 Jul 2018 13:03:10 +0100 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 05/07/18 11:26, Bart wrote: > > And at numerous other languages that are properly statically typed (Ada > being one of the most rigorous, while C++ is a nightmare). > I had to chuckle at that as friends of mine have had great fun rewriting Ada in C++ as it was just too damn slow. This was after they'd converted the code from CORAL 66 as Ada was the new kid on the block in the defence industry world. Then there was Ada and poor old ariane, didn't help too much there did it? Still I'm fairly certain that the insurers wouldn't have batted an eyelid at the mere $356,000,000 payout. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From arj.python at gmail.com Thu Jul 5 08:10:50 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 5 Jul 2018 16:10:50 +0400 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> Message-ID: no about wrapping everything in functions Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ On Thu, 5 Jul 2018, 15:55 Joel Goldstick, wrote: > On Thu, Jul 5, 2018 at 7:45 AM, Abdur-Rahmaan Janhangeer > wrote: > > performance? > > You are asking basic file layout questions in the learning process of > understand how to code in python. Performance should be very low on > your list of concerns. The only thing that happens when the file is > loaded is that it gets compiled, and run. If it is imported, and you > have the 'if __name__ ... block, it will run the code within the if > block. If that has a main() function it makes it simpler later to > change what main does instead of cluttering up the if block. But > there is no 'performance' issue that I can see. > > > > Abdur-Rahmaan Janhangeer > > https://github.com/Abdur-rahmaanJ > > > > * Create as many functions as you can > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > Joel Goldstick > http://joelgoldstick.com/blog > http://cc-baseballstats.info/stats/birthdays > -- > https://mail.python.org/mailman/listinfo/python-list > From marko at pacujo.net Thu Jul 5 08:14:35 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 05 Jul 2018 15:14:35 +0300 Subject: about main() References: <87zhz60w0r.fsf@elektro.pacujo.net> Message-ID: <87r2kh282c.fsf@elektro.pacujo.net> Abdur-Rahmaan Janhangeer : >> * Create as many functions as you can > performance? Python? Seriously, though. The principle of expressive encapsulation is one of the basic cornerstones of writing computer programs. Performance barely ever becomes a question, and even more rarely has anything to do with the number of function calls (low-level programming language compilers optimize efficiently). The most important objective of software development is the management of complexity. Silly performance optimizations are way down the priority list. Marko From arj.python at gmail.com Thu Jul 5 08:47:51 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 5 Jul 2018 16:47:51 +0400 Subject: about main() In-Reply-To: References: Message-ID: that's what happens when you type from mobile btw i have top posted since some days only in this thread as for my english well i got distinction in cambridge ucles in gp for high school but practicality beats purity Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > > From m.n.summerfield at googlemail.com Thu Jul 5 08:57:53 2018 From: m.n.summerfield at googlemail.com (Mark Summerfield) Date: Thu, 5 Jul 2018 05:57:53 -0700 (PDT) Subject: Is there a nice way to switch between 2 different packages providing the same APIs? Message-ID: For GUI programming I often use Python bindings for Qt. There are two competing bindings, PySide and PyQt. Ideally I like to have applications that can use either. This way, if I get a problem I can try with the other bindings: if I still get the problem, then it is probably me; but if I don't it may be an issue with the bindings. But working with both means that my imports are very messy. Here's a tiny example: if PYSIDE: # bool True -> Use PySide; False -> Use PyQt5 from PySide2.QtCore import Qt from PySide2.QtGui import QIcon from PySide2.QtWidgets import ( QDialog, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, QVBoxLayout) else: from PyQt5.QtCore import Qt from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import ( QDialog, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, QVBoxLayout) The PYSIDE constant is imported from another module and is used for all .py files in a given project so that just by changing PYSIDE's value I can run an entire application with PySide2 or with PyQt5. But I'd really rather just have one lot of imports per file. One obvious solution is to create a 'Qt.py' module that imports everything depending on the PYSIDE switch and that I then use in all the other .py files, something like this: from Qt.QtCore import Qt from Qt.QtGui import QIcon ... etc. But I'm just wondering if there's a nicer way to do all this? From bc at freeuk.com Thu Jul 5 08:57:58 2018 From: bc at freeuk.com (Bart) Date: Thu, 5 Jul 2018 13:57:58 +0100 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: On 05/07/2018 11:04, Steven D'Aprano wrote: > On Thu, 05 Jul 2018 09:17:20 +0200, Christian Gollwitzer wrote: >> Not sure what point you are trying to make, but your example compiles in >> C, if you replace the '#' comment sign with '//'. > Sometimes I wonder how C programmers manage to write a bug-free "Hello > World" program. No wonder it is described as a type-unsafe language or a > weakly-typed language. > > I understand upcasting ints to floats, that's cool (even if a few > languages take a hard line on that too, I don't). I understand Python's > dynamic typing approach. Do you? Python seems to have its own problems when mixing ints and floats: the calculation is done as float, that means converting int to float which can result in loss of precision when the int is bigger than about 2**52. > I don't understand C requiring type > declarations, then down-casting floats to integers. > > At least it shows a warning. You would need a warning both ways, since not all ints are representable as floats. And warnings when converting between signed and unsigned. Or from a wider int to a narrower one. Programs would be so full of explicit conversions that real problems will be hidden, and they would be difficult to read. Anyway lower level languages need more skill to write and you need to be very aware of what is going on. -- bart From steve+comp.lang.python at pearwood.info Thu Jul 5 09:07:12 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 5 Jul 2018 13:07:12 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: <3e587ddc-d43a-d617-03ee-7b76b65c68da@vub.be> Message-ID: On Thu, 05 Jul 2018 13:54:28 +0200, Antoon Pardon wrote: > On 05-07-18 11:59, Steven D'Aprano wrote: >> On Thu, 05 Jul 2018 17:34:55 +1200, Gregory Ewing wrote: >> >> >>>> Indeed, that's often the best way, except for the redundant type >>>> hint, which makes you That Guy: >>>> >>>> x: int = 0 # set x to the int 0 >>> But you've shown in an earlier example that such a hint is *not* >>> always redundant >> But it is redundant in *that* example. Your hint is not giving any more >> information that what the reader, or type checker, can already infer. > > Yes it gives more information. Without the hint you can only interfere > that it is an int at that point. That would be utterly pointless: x = 3 # infer x must be an int, but only at this point y = x + "Hello world" # who knows what x is now? maybe it's okay A type checker that did that would be a waste of time. > IIUC, with the hint you can interfere > it is supposed to be an int during its life time, not just at that > point. No. Mypy considers the initial assignment as the definition of a variable. If you do not explicitly specify the type of the variable, mypy infers the type based on the static type of the value expression http://mypy.readthedocs.io/en/latest/type_inference_and_annotations.html This is not an innovation of Mypy. It's how type inference is supposed to work. If a particular type checker doesn't do that, it is doing it wrong. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Thu Jul 5 09:20:29 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Jul 2018 23:20:29 +1000 Subject: about main() In-Reply-To: <87zhz60w0r.fsf@elektro.pacujo.net> References: <87zhz60w0r.fsf@elektro.pacujo.net> Message-ID: On Thu, Jul 5, 2018 at 9:20 PM, Marko Rauhamaa wrote: > Rhodri James : >> I'm not a big fan of "main()" functions myself; creating a function >> which will be called exactly once seems rather wasteful. > > A function is the encapsulation of a distinct ... well ... function. > Functions that are called just once are desirable. > > So I'm saying the opposite: > > * Have no code outside functions. So, no import statements outside functions, no "if name is main" incantation, and especially, no function definitions outside functions, because they are themselves code. What code is permitted outside functions and what isn't? ChrisA From rosuav at gmail.com Thu Jul 5 09:21:55 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 5 Jul 2018 23:21:55 +1000 Subject: about main() In-Reply-To: References: Message-ID: On Thu, Jul 5, 2018 at 10:47 PM, Abdur-Rahmaan Janhangeer wrote: > that's what happens when you type from mobile > > btw i have top posted since some days only in this thread > > as for my english well i got distinction in cambridge ucles in gp for high > school but practicality beats purity Ahh, yes. The elegant purity of reading every email that goes through this mailing list, or the practicality of killfiling people who can't be bothered to use correct grammar in English, and probably are comparably sloppy in their code. It's a very important decision to make. ChrisA From antoon.pardon at vub.be Thu Jul 5 10:09:52 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 5 Jul 2018 16:09:52 +0200 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: <3e587ddc-d43a-d617-03ee-7b76b65c68da@vub.be> Message-ID: <992d23dc-f37b-f789-b308-a707981b9228@vub.be> On 05-07-18 15:07, Steven D'Aprano wrote: > On Thu, 05 Jul 2018 13:54:28 +0200, Antoon Pardon wrote: > >> On 05-07-18 11:59, Steven D'Aprano wrote: >>> On Thu, 05 Jul 2018 17:34:55 +1200, Gregory Ewing wrote: >>> >>> >>>>> Indeed, that's often the best way, except for the redundant type >>>>> hint, which makes you That Guy: >>>>> >>>>> x: int = 0 # set x to the int 0 >>>> But you've shown in an earlier example that such a hint is *not* >>>> always redundant >>> But it is redundant in *that* example. Your hint is not giving any more >>> information that what the reader, or type checker, can already infer. >> Yes it gives more information. Without the hint you can only interfere >> that it is an int at that point. > That would be utterly pointless: > > x = 3 # infer x must be an int, but only at this point > y = x + "Hello world" # who knows what x is now? maybe it's okay > > > A type checker that did that would be a waste of time. > > >> IIUC, with the hint you can interfere >> it is supposed to be an int during its life time, not just at that >> point. > No. > > Mypy considers the initial assignment as the definition > of a variable. If you do not explicitly specify the type > of the variable, mypy infers the type based on the > static type of the value expression > > http://mypy.readthedocs.io/en/latest/type_inference_and_annotations.html > > This is not an innovation of Mypy. It's how type inference is supposed to > work. If a particular type checker doesn't do that, it is doing it wrong. That is how type interference works in languages that have some kind of static typing like Haskell. Sure if mypy want to impose something like that it can, but you can't interfere something like that for python programs in general. Unless you mean "A probable guess" by interfere. -- Antoon. From Joseph.Schachner at Teledyne.com Thu Jul 5 10:41:10 2018 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Thu, 5 Jul 2018 14:41:10 +0000 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: <166677007b9e42f294e867123672b864@Teledyne.com> It is interesting to contemplate how this could transform Python into nearly a statically typed language: x = 3 x = f(x) If you say the type checker should infer that x is an int, and then therefore complain about x=f(x) if f() does not return an int, then we have what in new C++ is auto type declaration by default, and after that it's statically typed. So this would still work valStr = QueryMeasuringInstrument("app.Meas.P1.Result.Mean") val = float(valStr) but this would not: val = QueryMeasuringInstrument("app.Meas.P1.Result.Mean") val = float(val) even though it works today in both Python 2 and Python 3. I don't think the intent of var annotations is to automatically extract the type for variables that are not annotated, and then insist that they retain the same type at all times. It would break this example. I think if I do annotate a variable, THEN the type checker can insist that I do not change its type. So this could cause an error: string val = QueryMeasuringInstrument("app.Meas.P1.Result.Mean") val = float(val) --- Joe S. -----Original Message----- From: Steven D'Aprano Sent: Wednesday, July 4, 2018 11:31 AM To: python-list at python.org Subject: Re: PEP 526 - var annotations and the spirit of python On Wed, 04 Jul 2018 13:48:26 +0100, Bart wrote: > Presumably one type hint applies for the whole scope of the variable, > not just the one assignment. You know how in C you can write int x = 1; # the type applies for just this one assignment x = 2.5; # perfectly legal, right? Wait, no, of course you can't do that. Why would you suggest that as even a possibility? Of course the type (whether inferred or annotated) applies for the entire scope of that variable. > Which means that here: > > x: int = 3 > x = f(x) > > you know x should still an int after these two statements, because the > type hint says so. Without it: > > x = 3 > x = f(x) > > x could be anything. That's not how type checking works. It makes *no difference* whether the type is inferred or hinted. Type hints only exist to cover the cases the type inference engine can't determine, or determine too strictly. See below. In the Dark Ages of type-checking, the compiler was too dumb to work out for itself what the type of variables is, so you have to explicitly declare them all, even the most obvious ones. Given such a declaration: int x = 3; # using C syntax the type checker is smart enough to look at the next line: x = f(x); and complain with a type-error if f() returns (say) a string, or a list. Checking that the types are compatible is the whole point of type checking. Now fast forward to the Enlightenment of type-inference, first used in a programming language in 1973 (so older than half the programmers alive today). That purpose doesn't go away because we're using type inference. With type-inference, the type-checker is smart enough to recognise what type a variable is supposed to be (at least sometimes): x = 3; # of course it's an int, what else could it be? x = f(x); and likewise complain if f(x) returns something other than an int. There's no point in type checking if you don't, you know, actually *check* the types. With type inference, the only reason to declare a variable's type is if the type checker can't infer it from the code, or if it infers the wrong type. (More on this later.) To do otherwise is as pointless and annoying as those comments which merely repeat what the code does: import math # import the math module mylist.append(v) # append v to mylist counter += 1 # add 1 to counter s = s.upper() # convert s to uppercase x: int = 3 # assign the int 3 to x Don't be That Guy who writes comments stating the bleeding obvious. There's not always enough information for the type checker to infer the right type. Sometimes the information simply isn't there: x = [] # a list of what? and sometimes you actually did intend what looks like a type-error to the checker: x = 3 # okay, x is intended to be an int x = "spam" # wait, this can't be right In the later case, you can annotate the variable with the most general "any type at all" type: from typing import Any x: Any = 3 # x can be anything, but happens to be an int now x = "spam" # oh that's fine then or you can simply not check that module. (Type checking is optional, not mandatory.) >> A better example would be: >> >> x: int = None >> >> which ought to be read as "x is an int, or None, and it's currently >> None". > > In that case the type hint is lying. "Practicality beats purity." "This type, or None" is such a common pattern that any half-way decent type checker ought to be able to recognise it. You can, of course, explicitly annotate it: x: Optional[int] = None but the type checker should infer that if you assign None to a variable which is declared int, you must have meant Optional[int] rather than just int. If it doesn't, get a better type checker. Note that None is a special case (because sometimes special cases *are* special enough to break the rules). This should be an error: x: int = "hello world" # wait, that's not an int But this is fine: x: Union[int, str] = "hello world" x is permitted to be an int or a string, and it happens to currently be a string. > If both x and y have type hints of 'int', then with this: > > z = x + y > > you might infer that z will be also 'int' Indeed. If you inferred that z was a list, you're doing it wrong :-) > (whether it it type hinted or not). But if either of x and y can > be None, then this might not even execute. If x or y could be None, the type checker should complain that None does not support the + operator. The whole point of type checking is to find bugs like that at compile time. A type checker that doesn't, you know, *actually find type bugs* is a waste of time and effort. This is Type-Checking 101 stuff. A type checker which can't even recognise that None+1 is a type error is a pretty crappy type checker. Why do you assume that the state of the art in type-checkers in 2018 is *worse* than the state of the art in 1953 when Fortran came out? > If something is an int, then make it an int: > > x: int = 0 Indeed, that's often the best way, except for the redundant type hint, which makes you That Guy: x: int = 0 # set x to the int 0 But the point of my example was that x is not an int. It is an optional int, that is, an int or None. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From mikhailwas at gmail.com Thu Jul 5 11:57:18 2018 From: mikhailwas at gmail.com (Mikhail V) Date: Thu, 5 Jul 2018 18:57:18 +0300 Subject: File names with slashes [was Re: error in os.chdir] Message-ID: Steven D'Aprano wrote: > In Explorer and the open-file dialog of most applications, they will see > paths like this: > > directory\file name with spaces > > with the extension (.jpg, .pdf, .docx etc) suppressed. So by your > argument, Python needs to accept strings without quotes: > > open(directory\file name with spaces, 'r') > > and guess which extension you mean. > > That would be fun to watch in action. I think it's what is called 'English humor'? Funny (just a little bit). Wait a moment - you are well aware of Windows features, that's suspicious... BTW Explorer with hidden extension that's a sign of "double-click, drag-and-drop" category of users. Definitely more advanced users turn on extensions, or don't even use explorer as a file manager. > Linux programmers will > see paths with spaces and other metacharacters escaped: > > directory/file\ name\ with\ spaces.txt ick. what I see is escaping of the most frequent Latin character. From tjandacw at gmail.com Thu Jul 5 12:08:30 2018 From: tjandacw at gmail.com (Tim Williams) Date: Thu, 5 Jul 2018 12:08:30 -0400 Subject: Is there a nice way to switch between 2 different packages providing the same APIs? In-Reply-To: References: Message-ID: On Thu, Jul 5, 2018 at 9:02 AM Mark Summerfield via Python-list < python-list at python.org> wrote: > For GUI programming I often use Python bindings for Qt. > > There are two competing bindings, PySide and PyQt. > > Ideally I like to have applications that can use either. This way, if I > get a problem I can try with the other bindings: if I still get the > problem, then it is probably me; but if I don't it may be an issue with the > bindings. > > But working with both means that my imports are very messy. Here's a tiny > example: > > if PYSIDE: # bool True -> Use PySide; False -> Use PyQt5 > from PySide2.QtCore import Qt > from PySide2.QtGui import QIcon > from PySide2.QtWidgets import ( > QDialog, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, > QVBoxLayout) > else: > from PyQt5.QtCore import Qt > from PyQt5.QtGui import QIcon > from PyQt5.QtWidgets import ( > QDialog, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, > QVBoxLayout) > > The PYSIDE constant is imported from another module and is used for all > .py files in a given project so that just by changing PYSIDE's value I can > run an entire application with PySide2 or with PyQt5. > > But I'd really rather just have one lot of imports per file. > > One obvious solution is to create a 'Qt.py' module that imports everything > depending on the PYSIDE switch and that I then use in all the other .py > files, something like this: > > from Qt.QtCore import Qt > from Qt.QtGui import QIcon > ... etc. > > But I'm just wondering if there's a nicer way to do all this? > -- > https://mail.python.org/mailman/listinfo/python-list Check out pyqtgraph It tries to use PyQt5/PyQt4/PySide depending on which if these packages were imported before importing pyqtgraph. From gheskett at shentel.net Thu Jul 5 12:21:31 2018 From: gheskett at shentel.net (Gene Heskett) Date: Thu, 5 Jul 2018 12:21:31 -0400 Subject: File names with slashes [was Re: error in os.chdir] In-Reply-To: References: Message-ID: <201807051221.31281.gheskett@shentel.net> On Thursday 05 July 2018 11:57:18 Mikhail V wrote: > Steven D'Aprano wrote: > > In Explorer and the open-file dialog of most applications, they will > > see paths like this: > > > > directory\file name with spaces > > > > with the extension (.jpg, .pdf, .docx etc) suppressed. So by your > > argument, Python needs to accept strings without quotes: > > > > open(directory\file name with spaces, 'r') > > > > and guess which extension you mean. > > > > That would be fun to watch in action. > > I think it's what is called 'English humor'? > Funny (just a little bit). > > Wait a moment - you are well aware of Windows features, > that's suspicious... > > > BTW Explorer with hidden extension that's a sign of > "double-click, drag-and-drop" category of users. > Definitely more advanced users turn on extensions, > or don't even use explorer as a file manager. > > > Linux programmers will > > see paths with spaces and other metacharacters escaped: > > > > directory/file\ name\ with\ spaces.txt > > ick. what I see is escaping of the most frequent Latin character. ick is a very weak adjective. For a change, why can't windows do it right? Oh wait, its windows so the question is moot. Sigh, and just one of the reasons there are zero windows machines on my premises. -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From jlee54 at gmail.com Thu Jul 5 12:59:15 2018 From: jlee54 at gmail.com (Jim Lee) Date: Thu, 5 Jul 2018 09:59:15 -0700 Subject: about main() In-Reply-To: <87r2kh282c.fsf@elektro.pacujo.net> References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> Message-ID: <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> On 07/05/18 05:14, Marko Rauhamaa wrote: > Abdur-Rahmaan Janhangeer : >>> * Create as many functions as you can >> performance? > Python? > > Seriously, though. The principle of expressive encapsulation is one of > the basic cornerstones of writing computer programs. Performance barely > ever becomes a question, and even more rarely has anything to do with > the number of function calls (low-level programming language compilers > optimize efficiently). > > The most important objective of software development is the management > of complexity. Silly performance optimizations are way down the priority > list. > > > Marko Sadly, this *is* the current mindset. "Don't bother optimizing, the compiler does it better than you can." Tell me, who writes the compilers?? When we die off, nobody will have a clue how to do it... -Jim From cspealma at redhat.com Thu Jul 5 13:15:40 2018 From: cspealma at redhat.com (Calvin Spealman) Date: Thu, 5 Jul 2018 13:15:40 -0400 Subject: about main() In-Reply-To: <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: On Thu, Jul 5, 2018 at 12:59 PM, Jim Lee wrote: > > > On 07/05/18 05:14, Marko Rauhamaa wrote: > >> Abdur-Rahmaan Janhangeer : >> >>> * Create as many functions as you can >>>> >>> performance? >>> >> Python? >> >> Seriously, though. The principle of expressive encapsulation is one of >> the basic cornerstones of writing computer programs. Performance barely >> ever becomes a question, and even more rarely has anything to do with >> the number of function calls (low-level programming language compilers >> optimize efficiently). >> >> The most important objective of software development is the management >> of complexity. Silly performance optimizations are way down the priority >> list. >> >> >> Marko >> > > Sadly, this *is* the current mindset. > > "Don't bother optimizing, the compiler does it better than you can." > I think that is a pretty clear mis-characterization of what was said. The mindset isn't that optimization will be done for you, but that it isn't high on a priority list. This is doubly true when looked at from a planning perspective. Make something work first, make it organized and understandable, and *then* and only if measurements warrant it do you need to put resources explicitly towards performance. Not because performance isn't important or that someone else will do it for you, but because most problems and contexts do not have constraints that warrant it as a high and immediate priority. Tell me, who writes the compilers? When we die off, nobody will have a > clue how to do it... > > -Jim > > -- > https://mail.python.org/mailman/listinfo/python-list > From steve+comp.lang.python at pearwood.info Thu Jul 5 13:37:22 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 5 Jul 2018 17:37:22 +0000 (UTC) Subject: RANT why the *%#&%^ does installing pip not install setuptools??? Message-ID: I'm trying to install pip on a Linux Mint box. The maintainers of Mint (or possibly their upstream distro, Ubuntu) decided in their infinite wisdom to remove the ensurepip package, so python3 -m ensurepip fails ("No module named ensurepip"). Okay, let's do this the hard way: sudo apt install python3-pip Yay, that worked! So then I try using it: python3 -m pip install blahblahblah and after downloading the entire package, it crashes: ImportError: No module named 'setuptools' because *of course* why would you treat setuptools as a dependency of pip, just because it happens to be a dependency of pip? That would be too sensible. sudo apt install python3-setuptools fixed the issue. But now I want to go out and kick puppies. /rant -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jlee54 at gmail.com Thu Jul 5 13:41:36 2018 From: jlee54 at gmail.com (Jim Lee) Date: Thu, 5 Jul 2018 10:41:36 -0700 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: On 07/05/18 10:15, Calvin Spealman wrote: > On Thu, Jul 5, 2018 at 12:59 PM, Jim Lee > wrote: > > > > On 07/05/18 05:14, Marko Rauhamaa wrote: > > Abdur-Rahmaan Janhangeer >: > > * Create as many functions as you can > > performance? > > Python? > > Seriously, though. The principle of expressive encapsulation > is one of > the basic cornerstones of writing computer programs. > Performance barely > ever becomes a question, and even more rarely has anything to > do with > the number of function calls (low-level programming language > compilers > optimize efficiently). > > The most important objective of software development is the > management > of complexity. Silly performance optimizations are way down > the priority > list. > > > Marko > > > Sadly, this *is* the current mindset. > > "Don't bother optimizing, the compiler does it better than you can." > > > I think that is a pretty clear mis-characterization of what was said. > Well, you did say "silly performance optimizations". > The mindset isn't that optimization will be done for you, but that it > isn't high on a priority list. Things at the bottom of a priority list tend to never get done - especially in the current era of software development.? And if you rarely or never do something, you lose the skill.? The horde of programmers a generation or two from now may have no clue how to do these things.? That's the pitfall behind "smart tools". > Tell me, who writes the compilers?? When we die off, nobody will > have a clue how to do it... > > -Jim > From cspealma at redhat.com Thu Jul 5 13:47:46 2018 From: cspealma at redhat.com (Calvin Spealman) Date: Thu, 5 Jul 2018 13:47:46 -0400 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: On Thu, Jul 5, 2018 at 1:41 PM, Jim Lee wrote: > > > On 07/05/18 10:15, Calvin Spealman wrote: > > On Thu, Jul 5, 2018 at 12:59 PM, Jim Lee wrote: > >> >> >> On 07/05/18 05:14, Marko Rauhamaa wrote: >> >>> Abdur-Rahmaan Janhangeer : >>> >>>> * Create as many functions as you can >>>>> >>>> performance? >>>> >>> Python? >>> >>> Seriously, though. The principle of expressive encapsulation is one of >>> the basic cornerstones of writing computer programs. Performance barely >>> ever becomes a question, and even more rarely has anything to do with >>> the number of function calls (low-level programming language compilers >>> optimize efficiently). >>> >>> The most important objective of software development is the management >>> of complexity. Silly performance optimizations are way down the priority >>> list. >>> >>> >>> Marko >>> >> >> Sadly, this *is* the current mindset. >> >> "Don't bother optimizing, the compiler does it better than you can." >> > > I think that is a pretty clear mis-characterization of what was said. > > > Well, you did say "silly performance optimizations". > That wasn't me, but I do agree with the sentiment in that its often silly to focus on them at the wrong time and without constraints that warrant that focus. > The mindset isn't that optimization will be done for you, but that it > isn't high on a priority list. > > > Things at the bottom of a priority list tend to never get done - > especially in the current era of software development. And if you rarely > or never do something, you lose the skill. The horde of programmers a > generation or two from now may have no clue how to do these things. That's > the pitfall behind "smart tools". > You say "pitfall", but I say "allow developers to focus on higher-level problems and enable developers to specialize among tasks so every single one of us doesn't have to be a jack of all trades just to build a todo list app". ?\_(?)_/? > Tell me, who writes the compilers? When we die off, nobody will have a >> clue how to do it... >> >> -Jim >> >> > From rosuav at gmail.com Thu Jul 5 13:47:55 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Jul 2018 03:47:55 +1000 Subject: RANT why the *%#&%^ does installing pip not install setuptools??? In-Reply-To: References: Message-ID: On Fri, Jul 6, 2018 at 3:37 AM, Steven D'Aprano wrote: > I'm trying to install pip on a Linux Mint box. The maintainers of Mint > (or possibly their upstream distro, Ubuntu) decided in their infinite > wisdom to remove the ensurepip package, so > > python3 -m ensurepip > > fails ("No module named ensurepip"). Okay, let's do this the hard way: > > sudo apt install python3-pip > > Yay, that worked! So then I try using it: > > python3 -m pip install blahblahblah > > and after downloading the entire package, it crashes: > > ImportError: No module named 'setuptools' > > because *of course* why would you treat setuptools as a dependency of > pip, just because it happens to be a dependency of pip? That would be too > sensible. > > sudo apt install python3-setuptools > > fixed the issue. But now I want to go out and kick puppies. What's the output of: $ apt-cache show python3-pip ? On my system (Debian Stretch), the dependencies are: Depends: ca-certificates, python3-distutils, python-pip-whl (= 9.0.1-2.3), python3:any (>= 3.4~) Recommends: build-essential, python3-dev (>= 3.2), python3-setuptools, python3-wheel It looks like this needs to be promoted out of recommends into depends, but if (as is commonly the default) your apt is configured to automatically install recommended packages, you should be fine. If kicking puppies isn't your thing, you may want to raise this with the package maintainer. Again, using the info from my system, which may not be quite the same as yours: Maintainer: Debian Python Modules Team ChrisA From steve+comp.lang.python at pearwood.info Thu Jul 5 13:57:03 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 5 Jul 2018 17:57:03 +0000 (UTC) Subject: Dealing with dicts in doctest Message-ID: I have a function which returns a dict, and I want to use doctest to ensure the documentation is correct. So I write a bunch of doctests: def func(arg): """blah blah blah >>> func(1) {'a': 1, 'b': 2, 'c': 3} """ which is correct, *except* that dict keys have arbitrary order in the versions of Python I'm using. I have three ways of dealing with this. Which do you prefer? 1. Re-write the doctest to compare with another dict: >>> actual = func(1) >>> expected = {'a': 1, 'b': 2, 'c': 3} >>> actual == expected True I don't like that because it obscures the clear relationship between "call the function" -> "here's the output you get". 2. Use a pretty-printer function that cleverly sorts the keys before printing: >>> _ppr(func(1)) {'a': 1, 'b': 2, 'c': 3} I don't like that, because the call to the pretty printer obscures the call to the function. 3. I thought, "what a pity I can't move the pretty printer to the end od the line, instead of the beginning, to reduce the emphasis on it". And then I thought, yes I can!" and re-wrote the pretty printer to use the __ror__ method instead: >>> func(1) | _ppr {'a': 1, 'b': 2, 'c': 3} I think that's really clever. Is it too clever? How do you deal with dicts in doctests? (Ensuring that the dicts only have a single item is not feasible.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From 2ndmowae at gmail.com Thu Jul 5 14:20:37 2018 From: 2ndmowae at gmail.com (Bonn Mowae lazaga) Date: Thu, 5 Jul 2018 11:20:37 -0700 Subject: is there a problem with IDLE, python3.7.0, or my computer? Message-ID: <5b3e6176.1c69fb81.73612.32fe@mx.google.com> hello, I would like to notify you that there may be a problem with IDLE or Python3.7.0 I installed python 3.7.0 for my 64 bit windows 10, and it was working fine, I could also use turtle graphics using the command:? ? from turtle import *??? and:??? forward(200)??? and other control commands for turtle, and it was drawing in screen like normal. A while later, I opened up IDLE again. I typed the command:????? ? from turtle import * then: forward(200) and it gave me an error message saying that the name forward could not be identified/it didn?t recognise it. I did the same with left(90) and a similar error message popped up, saying that the name left could not be identified/it didn?t recognise it. Also, it says the the else keyword is invalid syntax, even though it highlighted it in orange, (as shown in the email) meaning it recognised it as a keyword. Please notify me if there is a problem with python3.7.0, IDLE, or my windows 10 (64 bit.) Thank you for taking my email into consideration. P.S. I highlighted certain words in certain colors so you know how it was highlighted in IDLE From: Ancus Sent from Mail for Windows 10 From jlee54 at gmail.com Thu Jul 5 14:27:09 2018 From: jlee54 at gmail.com (Jim Lee) Date: Thu, 5 Jul 2018 11:27:09 -0700 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: On 07/05/18 10:47, Calvin Spealman wrote: > > > You say "pitfall", but I say "allow developers to focus on > higher-level problems and enable developers to specialize among tasks > so every single one of us doesn't have to be a jack of all trades just > to build a todo list app". > > Sure, that's the *benefit*, but the benefit doesn't erase the *pitfall*. It's the same as with any other convenience.? When a convenience becomes a necessity, skill is lost. Take a village of people.? They live mostly on wild berries.? One day, a man invents an automated way to sort good berries from poisonous berries.? Soon, all the villagers take their berries to him to be sorted.? The man dies, but passes the secret on to his son before doing so.? This continues for a few generations.? Eventually, the final descendant dies with no children, and the secret vanishes.? Now, the entire village is clueless when it comes to identifying the poisonous berries. -Jim -Jim From python at mrabarnett.plus.com Thu Jul 5 14:56:59 2018 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 5 Jul 2018 19:56:59 +0100 Subject: Dealing with dicts in doctest In-Reply-To: References: Message-ID: <8664d010-8adf-453b-1cd9-20008b2153bb@mrabarnett.plus.com> On 2018-07-05 18:57, Steven D'Aprano wrote: > I have a function which returns a dict, and I want to use doctest to > ensure the documentation is correct. So I write a bunch of doctests: > > def func(arg): > """blah blah blah > > >>> func(1) > {'a': 1, 'b': 2, 'c': 3} > """ > > which is correct, *except* that dict keys have arbitrary order in the > versions of Python I'm using. > > I have three ways of dealing with this. Which do you prefer? > > > 1. Re-write the doctest to compare with another dict: > > >>> actual = func(1) > >>> expected = {'a': 1, 'b': 2, 'c': 3} > >>> actual == expected > True > > I don't like that because it obscures the clear relationship between > "call the function" -> "here's the output you get". > > > > 2. Use a pretty-printer function that cleverly sorts the keys before > printing: > > >>> _ppr(func(1)) > {'a': 1, 'b': 2, 'c': 3} > > I don't like that, because the call to the pretty printer obscures the > call to the function. > > > > 3. I thought, "what a pity I can't move the pretty printer to the end od > the line, instead of the beginning, to reduce the emphasis on it". And > then I thought, yes I can!" and re-wrote the pretty printer to use the > __ror__ method instead: > > >>> func(1) | _ppr > {'a': 1, 'b': 2, 'c': 3} > > > I think that's really clever. Is it too clever? How do you deal with > dicts in doctests? > > > (Ensuring that the dicts only have a single item is not feasible.) > What about sorting the items? def func(arg): """blah blah blah >>> sorted(func(1).items()) [('a', 1), ('b', 2), ('c', 3)] """ From brian.j.oney at googlemail.com Thu Jul 5 15:25:24 2018 From: brian.j.oney at googlemail.com (Brian J. Oney) Date: Thu, 05 Jul 2018 21:25:24 +0200 Subject: RANT why the *%#&%^ does installing pip not install setuptools??? In-Reply-To: References: Message-ID: <1530818724.5916.1.camel@gmail.com> On Stretch: ~ $ aptitude show python-pip Package: python-pip?????????????????????? Version: 9.0.1-2 ... Maintainer: Debian Python Modules Team ... Depends: ca-certificates, python-pip-whl (= 9.0.1-2), python:any (< 2.8), python:any (>= 2.7.5-5~) Recommends: build-essential, python-all-dev (>= 2.6), python- setuptools, ????????????python-wheel ... Tags: admin::package-management, devel::lang:python, devel::packaging, ??????implemented-in::python, role::program And: ~ $ aptitude show python3-pip Package: python3-pip????????????????????? Version: 9.0.1-2 ... Maintainer: Debian Python Modules Team ... Depends: ca-certificates, python-pip-whl (= 9.0.1-2), python3:any (>= 3.4~) Recommends: build-essential, python3-dev (>= 3.2), python3-setuptools, python3-wheel ... It seems deliberate, but I am not the person to ask why. From rosuav at gmail.com Thu Jul 5 15:58:58 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Jul 2018 05:58:58 +1000 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: On Fri, Jul 6, 2018 at 4:27 AM, Jim Lee wrote: > > > On 07/05/18 10:47, Calvin Spealman wrote: >> >> >> >> You say "pitfall", but I say "allow developers to focus on higher-level >> problems and enable developers to specialize among tasks so every single one >> of us doesn't have to be a jack of all trades just to build a todo list >> app". >> >> > > Sure, that's the *benefit*, but the benefit doesn't erase the *pitfall*. > > It's the same as with any other convenience. When a convenience becomes a > necessity, skill is lost. > > Take a village of people. They live mostly on wild berries. One day, a man > invents an automated way to sort good berries from poisonous berries. Soon, > all the villagers take their berries to him to be sorted. The man dies, but > passes the secret on to his son before doing so. This continues for a few > generations. Eventually, the final descendant dies with no children, and > the secret vanishes. Now, the entire village is clueless when it comes to > identifying the poisonous berries. > I would respect your analogy more if every compiler used today were forty years old and not being developed by anyone other than its original creator(s). ChrisA From rosuav at gmail.com Thu Jul 5 16:00:09 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Jul 2018 06:00:09 +1000 Subject: is there a problem with IDLE, python3.7.0, or my computer? In-Reply-To: <5b3e6176.1c69fb81.73612.32fe@mx.google.com> References: <5b3e6176.1c69fb81.73612.32fe@mx.google.com> Message-ID: On Fri, Jul 6, 2018 at 4:20 AM, Bonn Mowae lazaga <2ndmowae at gmail.com> wrote: > hello, I would like to notify you that there may be a problem with IDLE or Python3.7.0 > I installed python 3.7.0 for my 64 bit windows 10, and it was working fine, I could also use turtle graphics using the command: > > from turtle import * > > and: > > forward(200) > > and other control commands for turtle, and it was drawing in screen like normal. A while later, I opened up IDLE again. I typed the command: > > from turtle import * > > then: > > > forward(200) > > and it gave me an error message saying that the name forward could not be identified/it didn?t recognise it. Did you create a file called turtle.py? If so, pick a different name for your own program - you've shadowed the standard library module. ChrisA From jlee54 at gmail.com Thu Jul 5 16:43:05 2018 From: jlee54 at gmail.com (Jim Lee) Date: Thu, 5 Jul 2018 13:43:05 -0700 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: <0cda33fa-6633-5f92-646a-d8f8494207f4@gmail.com> On 07/05/18 12:58, Chris Angelico wrote: > On Fri, Jul 6, 2018 at 4:27 AM, Jim Lee wrote: >> >> On 07/05/18 10:47, Calvin Spealman wrote: >>> >>> >>> You say "pitfall", but I say "allow developers to focus on higher-level >>> problems and enable developers to specialize among tasks so every single one >>> of us doesn't have to be a jack of all trades just to build a todo list >>> app". >>> >>> >> Sure, that's the *benefit*, but the benefit doesn't erase the *pitfall*. >> >> It's the same as with any other convenience. When a convenience becomes a >> necessity, skill is lost. >> >> Take a village of people. They live mostly on wild berries. One day, a man >> invents an automated way to sort good berries from poisonous berries. Soon, >> all the villagers take their berries to him to be sorted. The man dies, but >> passes the secret on to his son before doing so. This continues for a few >> generations. Eventually, the final descendant dies with no children, and >> the secret vanishes. Now, the entire village is clueless when it comes to >> identifying the poisonous berries. >> > I would respect your analogy more if every compiler used today were > forty years old and not being developed by anyone other than its > original creator(s). > > ChrisA It's not about compilers - it's about skills.? As programming becomes more and more specialized, it becomes harder and harder to find programmers with a skill set broad enough to be adaptable to a different task. -Jim From python at mrabarnett.plus.com Thu Jul 5 17:15:22 2018 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 5 Jul 2018 22:15:22 +0100 Subject: about main() In-Reply-To: <0cda33fa-6633-5f92-646a-d8f8494207f4@gmail.com> References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> <0cda33fa-6633-5f92-646a-d8f8494207f4@gmail.com> Message-ID: <1e51ce80-aa0c-bd01-da2a-e25d99c4b382@mrabarnett.plus.com> On 2018-07-05 21:43, Jim Lee wrote: > > > On 07/05/18 12:58, Chris Angelico wrote: >> On Fri, Jul 6, 2018 at 4:27 AM, Jim Lee wrote: >>> >>> On 07/05/18 10:47, Calvin Spealman wrote: >>>> >>>> >>>> You say "pitfall", but I say "allow developers to focus on higher-level >>>> problems and enable developers to specialize among tasks so every single one >>>> of us doesn't have to be a jack of all trades just to build a todo list >>>> app". >>>> >>>> >>> Sure, that's the *benefit*, but the benefit doesn't erase the *pitfall*. >>> >>> It's the same as with any other convenience. When a convenience becomes a >>> necessity, skill is lost. >>> >>> Take a village of people. They live mostly on wild berries. One day, a man >>> invents an automated way to sort good berries from poisonous berries. Soon, >>> all the villagers take their berries to him to be sorted. The man dies, but >>> passes the secret on to his son before doing so. This continues for a few >>> generations. Eventually, the final descendant dies with no children, and >>> the secret vanishes. Now, the entire village is clueless when it comes to >>> identifying the poisonous berries. >>> >> I would respect your analogy more if every compiler used today were >> forty years old and not being developed by anyone other than its >> original creator(s). >> >> ChrisA > > It's not about compilers - it's about skills.? As programming becomes > more and more specialized, it becomes harder and harder to find > programmers with a skill set broad enough to be adaptable to a different > task. > Fortunately the berry-sorter is open-source! From jlee54 at gmail.com Thu Jul 5 17:30:06 2018 From: jlee54 at gmail.com (Jim Lee) Date: Thu, 5 Jul 2018 14:30:06 -0700 Subject: about main() In-Reply-To: <1e51ce80-aa0c-bd01-da2a-e25d99c4b382@mrabarnett.plus.com> References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> <0cda33fa-6633-5f92-646a-d8f8494207f4@gmail.com> <1e51ce80-aa0c-bd01-da2a-e25d99c4b382@mrabarnett.plus.com> Message-ID: <5bd2e543-f91f-6138-99c8-1311632bdebb@gmail.com> On 07/05/18 14:15, MRAB wrote: > On 2018-07-05 21:43, Jim Lee wrote: >> >> >> On 07/05/18 12:58, Chris Angelico wrote: >>> On Fri, Jul 6, 2018 at 4:27 AM, Jim Lee wrote: >>>> >>>> On 07/05/18 10:47, Calvin Spealman wrote: >>>>> >>>>> >>>>> You say "pitfall", but I say "allow developers to focus on >>>>> higher-level >>>>> problems and enable developers to specialize among tasks so every >>>>> single one >>>>> of us doesn't have to be a jack of all trades just to build a todo >>>>> list >>>>> app". >>>>> >>>>> >>>> Sure, that's the *benefit*, but the benefit doesn't erase the >>>> *pitfall*. >>>> >>>> It's the same as with any other convenience.? When a convenience >>>> becomes a >>>> necessity, skill is lost. >>>> >>>> Take a village of people.? They live mostly on wild berries.? One >>>> day, a man >>>> invents an automated way to sort good berries from poisonous >>>> berries.? Soon, >>>> all the villagers take their berries to him to be sorted. The man >>>> dies, but >>>> passes the secret on to his son before doing so.? This continues >>>> for a few >>>> generations.? Eventually, the final descendant dies with no >>>> children, and >>>> the secret vanishes.? Now, the entire village is clueless when it >>>> comes to >>>> identifying the poisonous berries. >>>> >>> I would respect your analogy more if every compiler used today were >>> forty years old and not being developed by anyone other than its >>> original creator(s). >>> >>> ChrisA >> >> It's not about compilers - it's about skills.? As programming becomes >> more and more specialized, it becomes harder and harder to find >> programmers with a skill set broad enough to be adaptable to a different >> task. >> > Fortunately the berry-sorter is open-source! Yes, that helps, as long as the reader is able to understand all the concepts and algorithms used... -Jim From eryksun at gmail.com Thu Jul 5 18:17:09 2018 From: eryksun at gmail.com (eryk sun) Date: Thu, 5 Jul 2018 22:17:09 +0000 Subject: RANT why the *%#&%^ does installing pip not install setuptools??? In-Reply-To: References: Message-ID: On Thu, Jul 5, 2018 at 5:37 PM, Steven D'Aprano wrote: > I'm trying to install pip on a Linux Mint box. The maintainers of Mint > (or possibly their upstream distro, Ubuntu) decided in their infinite > wisdom to remove the ensurepip package, so > > python3 -m ensurepip In Debian distros, a customized version of ensurepip is part of python3-venv [1]. But it's only for use in virtual environments; it doesn't install the upstream version of pip as the system pip. Even with the customized python3-pip package, it's still recommended to use the system package manager (apt or dpkg) for the system Python. I only use pip in local builds and virtual environments, as suggested, so I can't provide concrete cases in which using it for the system site-packages actually breaks something due to a version mismatch. Of course you can remove a package and repair the system if it causes a conflict, but it's worth a warning at least. [1]: https://packages.debian.org/stretch/python3-venv From ingy at ingy.net Thu Jul 5 18:27:35 2018 From: ingy at ingy.net (Ingy dot Net) Date: Thu, 5 Jul 2018 15:27:35 -0700 Subject: [ANN] PyYAML-3.13: YAML parser and emitter for Python Message-ID: ======================== Announcing PyYAML-3.13 ======================== A new bug fix release of PyYAML is now available: http://pyyaml.org/wiki/PyYAML *** Important Note From Maintainers *** This is the first PyYAML release by the new maintainers. It was made critical because PyYAML-3.12 did not work with the recent Python 3.7 release. A more ambitious 4.1 release was attempted last week and needed to be retracted for many reasons. We apologize any pain caused by the 4.1 removal, but we remain confident that it was the best decision. There are over 60 pull requests in PyYAML and LibYAML that will be represented in the upcoming 4.2 release and we are working hard to get those to you as soon as the release is ready (but no sooner :). We are are excited that the PyYAML project is moving forward again. -- The PyYAML Maintenance Team Changes ======= * Rebuilt with the latest Cython to support the new Python 3.7 release. * No functionality is different from PyYAML 3.12 in this release. Resources ========= PyYAML IRC Channel: #pyyaml on irc.freenode.net YAML IRC Channel: #yaml-dev on irc.freenode.net LibYAML IRC Channel: #libyaml on irc.freenode.net PyYAML homepage: http://pyyaml.org/wiki/PyYAML PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation Source and binary installers: https://pypi.python.org/pypi/PyYAML/3.13 GitHub repository: https://github.com/yaml/pyyaml/ Bug tracking: https://github.com/yaml/pyyaml/issues YAML homepage: http://yaml.org/ YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core About PyYAML ============ YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object. PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistance. Example ======= >>> import yaml >>> yaml.load(""" ... name: PyYAML ... description: YAML parser and emitter for Python ... homepage: http://pyyaml.org/wiki/PyYAML ... keywords: [YAML, serialization, configuration, persistance, pickle] ... """) {'keywords': ['YAML', 'serialization', 'configuration', 'persistance', 'pickle'], 'homepage': 'http://pyyaml.org/wiki/PyYAML', 'description': 'YAML parser and emitter for Python', 'name': 'PyYAML'} >>> print yaml.dump(_) name: PyYAML homepage: http://pyyaml.org/wiki/PyYAML description: YAML parser and emitter for Python keywords: [YAML, serialization, configuration, persistance, pickle] Maintainers =========== The following people are currently responsible for maintaining PyYAML: * Ingy d?t Net * Tina Mueller * Matt Davis and many thanks to all who have contribributed! See: https://github.com/yaml/pyyaml/pulls Copyright ========= Copyright (c) 2017-2018 Ingy d?t Net Copyright (c) 2006-2016 Kirill Simonov The PyYAML module was written by Kirill Simonov . It is currently maintained by the YAML and Python communities. PyYAML is released under the MIT license. See the file LICENSE for more details. From cs at cskk.id.au Thu Jul 5 19:21:13 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 6 Jul 2018 09:21:13 +1000 Subject: about main() In-Reply-To: References: Message-ID: <20180705232113.GA87657@cskk.homeip.net> On 05Jul2018 11:22, Rhodri James wrote: >On 05/07/18 09:43, Abdur-Rahmaan Janhangeer wrote: >>just when to use main() in >> >>if __name__ == '__main__' : >> main() >> >>is far is it good in py? >> >>or should file intended to be run just not include it? > >It's a matter of taste. If your "file intended to be run" also >contains things that might be useful as a module, use the "if __name__ >== '__main__'" trick. Otherwise it can be more of a distraction than >a help. I'm not a big fan of "main()" functions myself; creating a function >which will be called exactly once seems rather wasteful. I almost always make a main. For several of my modules there's a meaningful command line mode, and for most of the rest I make main run the self tests. The main function has some advantages: - I put it at the top of the module, before anything other functions: that way the "main" operation of the module, if there is one, is in your face them you open the file, easy to find. Also, it is _immediately_ apparent that this module has a "main programme" mode. - You don't need to call it just once. Making a main() function, should it make sense, lets you call it _from other code_. Consider a wrapper which relies on the main function of this module for the core command line operation, or which runs this module's main as some kind of "subcommand" in a larger tool, such as most VCS commands, GraphicsMagick, etc - all have subcommandswhich are effectively standalone things in their own right. I also advocate making the boilerplate like this: if __name__ == '__main__': sys.exit(main(sys.argv)) and make main() like this: def main(argv=None): if argv is None: argv = sys.argv ... code here ... return meaningful_exit_code The "argv is None" shuffle is for PyPI packaging, where the standard script wrapper _doesn't_ pass in sys.argv, (no idea why, I should submit an enhancement proposal). Otherwise, there's argv, ready for reuse of the main() function from arbitrary code. Cheers, Cameron Simpson From cs at cskk.id.au Thu Jul 5 19:29:59 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 6 Jul 2018 09:29:59 +1000 Subject: Is there a nice way to switch between 2 different packages providing the same APIs? In-Reply-To: References: Message-ID: <20180705232959.GA18258@cskk.homeip.net> On 05Jul2018 05:57, Mark Summerfield wrote: >For GUI programming I often use Python bindings for Qt. > >There are two competing bindings, PySide and PyQt. > >Ideally I like to have applications that can use either. This way, if I get a problem I can try with the other bindings: if I still get the problem, then it is probably me; but if I don't it may be an issue with the bindings. > >But working with both means that my imports are very messy. Here's a tiny example: > >if PYSIDE: # bool True -> Use PySide; False -> Use PyQt5 > from PySide2.QtCore import Qt > from PySide2.QtGui import QIcon > from PySide2.QtWidgets import ( > QDialog, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, > QVBoxLayout) >else: > from PyQt5.QtCore import Qt > from PyQt5.QtGui import QIcon > from PyQt5.QtWidgets import ( > QDialog, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, > QVBoxLayout) > >The PYSIDE constant is imported from another module and is used for all .py files in a given project so that just by changing PYSIDE's value I can run an entire application with PySide2 or with PyQt5. > >But I'd really rather just have one lot of imports per file. > >One obvious solution is to create a 'Qt.py' module that imports everything depending on the PYSIDE switch and that I then use in all the other .py files, something like this: > >from Qt.QtCore import Qt >from Qt.QtGui import QIcon >... etc. > >But I'm just wondering if there's a nicer way to do all this? My recollection is that the Qt names are pretty unique; they're grouped into QtCore and QtGui and so forth for organisational, conceptual and maintenance reasons, but generally don't conflct. I tend to make a module like your "Qt.py" which doesn't have any hierarchy in its own namespace, so you get code like this: from Qt import Qt, QIcon, ... I would call it something other than "Qt" though, to avoid conflict with PyQt5.QtCore.Qt etc. Maybe "myqt" or the like. Your existing sample "if PYSIDE:" code should work directly, as all those names you import become simple flat names inside Qt (Qt.Qt, Qt.QIcon, Qt.QDialog, etc). Cheers, Cameron Simpson From cs at cskk.id.au Thu Jul 5 19:31:50 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 6 Jul 2018 09:31:50 +1000 Subject: Dealing with dicts in doctest In-Reply-To: References: Message-ID: <20180705233150.GA36640@cskk.homeip.net> On 05Jul2018 17:57, Steven D'Aprano wrote: >I have a function which returns a dict, and I want to use doctest to >ensure the documentation is correct. So I write a bunch of doctests: > >def func(arg): > """blah blah blah > > >>> func(1) > {'a': 1, 'b': 2, 'c': 3} > """ > >which is correct, *except* that dict keys have arbitrary order in the >versions of Python I'm using. > >I have three ways of dealing with this. Which do you prefer? Option 4: >>> func(1) == {'a': 1, 'b': 2, 'c': 3} True Cheers, Cameron Simpson From steve+comp.lang.python at pearwood.info Thu Jul 5 20:53:41 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Jul 2018 00:53:41 +0000 (UTC) Subject: about main() References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: On Thu, 05 Jul 2018 10:41:36 -0700, Jim Lee wrote: > The horde of > programmers a generation or two from now may have no clue how to do > these things. That's okay, the horde of programmers have never known how to do these things (optimization). They either don't do it at all, or they run riot prematurely "optimizing" everything in sight, either obfuscating their code and introducing bugs without actually speeding it up, or in many cases actually slowing it down. Actually *testing* whether the code is faster is not as much fun as writing the cleverest code you possibly can ("I sweated blood and tears to write this genius code, of course it will be faster") so the horde doesn't do it. And since they don't write tests either (boring and repetitive) they don't know when they've broken their own code by "optimizing" it. Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason ? including blind stupidity. -- W.A. Wulf The Rules of Optimization are simple. Rule 1: Don?t do it. Rule 2 (for experts only): Don?t do it yet. -- Michael A. Jackson, "Principles of Program Design" -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From torriem at gmail.com Thu Jul 5 21:14:02 2018 From: torriem at gmail.com (Michael Torrie) Date: Thu, 5 Jul 2018 19:14:02 -0600 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: On 07/05/2018 11:47 AM, Calvin Spealman wrote: > That wasn't me, but I do agree with the sentiment in that its often silly > to focus on them at the wrong time and without constraints that warrant > that focus. Premature optimization is the root of all evil, the saying goes. I see this kind of thing all the time on hobby programming forums for non-mainstream languages (as an example, FreeBASIC). People are delving into assembler all the time for "speed" rather than thinking about their data structures and algorithms. I'm not sure they even know where their programs are spending the majority of their execution time. I did some Python programming a while back that was pretty math heavy, but with a few simple optimizations like memoization I was able to make it run very acceptably fast. Still an order of magnitude slower than a C program might run, but I didn't care if it took half a second or a millisecond for my program to run. It was fast enough. From steve+comp.lang.python at pearwood.info Thu Jul 5 21:25:31 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Jul 2018 01:25:31 +0000 (UTC) Subject: about main() References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: On Thu, 05 Jul 2018 11:27:09 -0700, Jim Lee wrote: > Take a village of people.? They live mostly on wild berries. Because of course a community of people living on one food is so realistic. Even the Eskimos and Inuit, living in some of the harshest environments on earth, managed to have a relatively wide variety of foods in their diet. https://en.wikipedia.org/wiki/Inuit_cuisine But okay, let's run with this scenario... > One day, a man invents an automated way to sort good berries from > poisonous berries. Right, because it is totally realistic that a pre-agricultural society living on nothing but berries has mastered the technology to automate sorting berries. > Soon, all the villagers take their berries to him to be > sorted. Of course they do, because why pick only edible berries when it is so much more fun to pick both edible and poisonous berries, mix them together, and then play a game of "let's see if we missed any of the deadly berries and will die horribly after eating them accidentally". In this scenario of yours, is everyone in this a village a workaholic with a death-wish? Why exactly are they doing twice as much work as necessary picking poisonous berries and mixing them in together with the edible berries? >?The man dies, but passes the secret on to his son before doing > so.? This continues for a few generations.? Eventually, the final > descendant dies with no children, and the secret vanishes.? Now, the > entire village is clueless when it comes to identifying the poisonous > berries. Even this city boy knows enough to tell the difference between edible blackberries, raspberries and strawberries and the many maybe-its-edible- maybe-its-not berries which grown on random trees and bushes. Are there a bunch of dead birds around the tree? Then its poisonous. Do birds happily eat the berries and keep coming back? Then its worth trying one or two and see if they give you a stomach ache, if not, they're probably safe. A more sensible example would have been mushrooms. And its true, I'm entirely clueless how to identify poisonous mushrooms from edible ones. However will I survive? Nor do I know how to smelt copper, or tan leather using nothing but dung, or perform brain surgery. I guess civilization is about to collapse. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Thu Jul 5 21:35:37 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Jul 2018 01:35:37 +0000 (UTC) Subject: RANT why the *%#&%^ does installing pip not install setuptools??? References: Message-ID: On Fri, 06 Jul 2018 03:47:55 +1000, Chris Angelico wrote: > What's the output of: > > $ apt-cache show python3-pip Mysteriously, the output is repeated twice, in every-so-slightly different formats. It's the little details like that give us confidence in the quality of the software... Package: python3-pip Architecture: all Version: 8.1.1-2ubuntu0.4 Priority: optional Section: universe/python Source: python-pip Origin: Ubuntu Maintainer: Ubuntu Developers Original-Maintainer: Debian Python Modules Team Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 556 Depends: ca-certificates, python-pip-whl (= 8.1.1-2ubuntu0.4), python3:any (>= 3.4~) Recommends: build-essential, python3-dev (>= 3.2), python3-setuptools, python3-wheel Filename: pool/universe/p/python-pip/python3-pip_8.1.1-2ubuntu0.4_all.deb Size: 108962 MD5sum: e3dc92b0b965b3bea3ff4bf8526e24db SHA1: bcfb2aff46c05cc6b6a14d4faaa1cf2d0c90d1f3 SHA256: e55a2450e6dd6db15df0d9119e746af4f398e33a303a707cd660f159c9f78c5e Homepage: https://pip.pypa.io/en/stable/ Description-en_AU: alternative Python package installer - Python 3 version of the package pip is a replacement for easy_install, and is intended to be an improved Python package installer. It integrates with virtualenv, doesn't do partial installs, can save package state for replaying, can install from non-egg sources, and can install from version control repositories. . This is the Python 3 version of the package. Description-md5: 518fd76c787f6bd48e413ec4bcd3eb84 Package: python3-pip Priority: optional Section: universe/python Installed-Size: 554 Maintainer: Ubuntu Developers Original-Maintainer: Debian Python Modules Team Architecture: all Source: python-pip Version: 8.1.1-2 Depends: ca-certificates, python-pip-whl (= 8.1.1-2), python3:any (>= 3.4~) Recommends: build-essential, python3-dev (>= 3.2), python3-setuptools, python3-wheel Filename: pool/universe/p/python-pip/python3-pip_8.1.1-2_all.deb Size: 108740 MD5sum: 2df4cd61c524a0e7721e612e89f710e8 SHA1: 7eca35aaadf0e2a5246a256063fdfc4631630fbd SHA256: cf6a2d9befe0a6fb0002cd259bed40669588101a825006f4f07e2343a89e5f49 Description-en_AU: alternative Python package installer - Python 3 version of the package pip is a replacement for easy_install, and is intended to be an improved Python package installer. It integrates with virtualenv, doesn't do partial installs, can save package state for replaying, can install from non-egg sources, and can install from version control repositories. . This is the Python 3 version of the package. Description-md5: 518fd76c787f6bd48e413ec4bcd3eb84 Homepage: https://pip.pypa.io/en/stable/ Bugs: https://bugs.launchpad.net/ubuntu/+filebug Origin: Ubuntu -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jlee54 at gmail.com Thu Jul 5 21:36:57 2018 From: jlee54 at gmail.com (Jim Lee) Date: Thu, 5 Jul 2018 18:36:57 -0700 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: <1bbc97ec-66f5-d092-eff1-52361c645e0f@gmail.com> On 07/05/18 18:14, Michael Torrie wrote: > On 07/05/2018 11:47 AM, Calvin Spealman wrote: >> That wasn't me, but I do agree with the sentiment in that its often silly >> to focus on them at the wrong time and without constraints that warrant >> that focus. > Premature optimization is the root of all evil, the saying goes. I see > this kind of thing all the time on hobby programming forums for > non-mainstream languages (as an example, FreeBASIC). People are delving > into assembler all the time for "speed" rather than thinking about their > data structures and algorithms. I'm not sure they even know where their > programs are spending the majority of their execution time. Yup.? Like any other skill, part of mastery is knowing *when* to use it as well as *how*. -Jim From jlee54 at gmail.com Thu Jul 5 21:40:11 2018 From: jlee54 at gmail.com (Jim Lee) Date: Thu, 5 Jul 2018 18:40:11 -0700 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: <03c2ee5a-3e6b-c1ec-ca6d-e21bb177620d@gmail.com> On 07/05/18 18:25, Steven D'Aprano wrote: > On Thu, 05 Jul 2018 11:27:09 -0700, Jim Lee wrote: > >> Take a village of people.? They live mostly on wild berries. > Because of course a community of people living on one food is so > realistic. Even the Eskimos and Inuit, living in some of the harshest > environments on earth, managed to have a relatively wide variety of foods > in their diet. > > https://en.wikipedia.org/wiki/Inuit_cuisine > > Pedantics again.? Didn't even get the point before tearing apart the *analogy* rather than the *point itself*.? Childish. The rest was TL;DR. -Jim From steve+comp.lang.python at pearwood.info Thu Jul 5 21:40:12 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Jul 2018 01:40:12 +0000 (UTC) Subject: Dealing with dicts in doctest References: <8664d010-8adf-453b-1cd9-20008b2153bb@mrabarnett.plus.com> Message-ID: On Thu, 05 Jul 2018 19:56:59 +0100, MRAB wrote: > What about sorting the items? > > def func(arg): > """blah blah blah > > >>> sorted(func(1).items()) > [('a', 1), ('b', 2), ('c', 3)] > """ Hmmm.... it still has the disadvantage of putting the emphasis on the sorted() function instead of the function being doctested, and obscuring the fact that it returns a dict. But I actually like that. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Thu Jul 5 21:43:26 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Jul 2018 01:43:26 +0000 (UTC) Subject: Dealing with dicts in doctest References: <20180705233150.GA36640@cskk.homeip.net> Message-ID: On Fri, 06 Jul 2018 09:31:50 +1000, Cameron Simpson wrote: > On 05Jul2018 17:57, Steven D'Aprano > wrote: >>I have a function which returns a dict, and I want to use doctest to >>ensure the documentation is correct. So I write a bunch of doctests: >> >>def func(arg): >> """blah blah blah >> >> >>> func(1) >> {'a': 1, 'b': 2, 'c': 3} >> """ >> >>which is correct, *except* that dict keys have arbitrary order in the >>versions of Python I'm using. >> >>I have three ways of dealing with this. Which do you prefer? > > Option 4: > > >>> func(1) == {'a': 1, 'b': 2, 'c': 3} > True Alas, in reality func takes anything up to six arguments, at least one of which will be a moderately long sequence requiring two lines: >>> func([('a', 1), ('bb', 2), ('ccc', 4), ('dddd', 8)], ... ('eee', 16), ('ff', 32), ('g', 64)], ... and the output is similarly long. So making it a one-liner isn't generally practical. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From gheskett at shentel.net Thu Jul 5 21:50:30 2018 From: gheskett at shentel.net (Gene Heskett) Date: Thu, 5 Jul 2018 21:50:30 -0400 Subject: about main() In-Reply-To: References: Message-ID: <201807052150.30731.gheskett@shentel.net> On Thursday 05 July 2018 21:25:31 Steven D'Aprano wrote: > On Thu, 05 Jul 2018 11:27:09 -0700, Jim Lee wrote: > > Take a village of people.? They live mostly on wild berries. > > Because of course a community of people living on one food is so > realistic. Even the Eskimos and Inuit, living in some of the harshest > environments on earth, managed to have a relatively wide variety of > foods in their diet. > > https://en.wikipedia.org/wiki/Inuit_cuisine > > But okay, let's run with this scenario... > > > One day, a man invents an automated way to sort good berries from > > poisonous berries. > > Right, because it is totally realistic that a pre-agricultural society > living on nothing but berries has mastered the technology to automate > sorting berries. > > > Soon, all the villagers take their berries to him to be > > sorted. > > Of course they do, because why pick only edible berries when it is so > much more fun to pick both edible and poisonous berries, mix them > together, and then play a game of "let's see if we missed any of the > deadly berries and will die horribly after eating them accidentally". > > In this scenario of yours, is everyone in this a village a workaholic > with a death-wish? Why exactly are they doing twice as much work as > necessary picking poisonous berries and mixing them in together with > the edible berries? > > >?The man dies, but passes the secret on to his son before doing > > so.? This continues for a few generations.? Eventually, the final > > descendant dies with no children, and the secret vanishes.? Now, the > > entire village is clueless when it comes to identifying the > > poisonous berries. > > Even this city boy knows enough to tell the difference between edible > blackberries, raspberries and strawberries and the many > maybe-its-edible- maybe-its-not berries which grown on random trees > and bushes. > > Are there a bunch of dead birds around the tree? Then its poisonous. > > Do birds happily eat the berries and keep coming back? Then its worth > trying one or two and see if they give you a stomach ache, if not, > they're probably safe. > > A more sensible example would have been mushrooms. And its true, I'm > entirely clueless how to identify poisonous mushrooms from edible > ones. However will I survive? > The mushroom question is easy Steven. Since there is NO food value to a mushroom, simply avoid them all. The only reason we use them in our food is the flavoring. There are no calories, no or only trace amounts of vitamins or minerals. Skipping them is the sensible thing to do > Nor do I know how to smelt copper, or tan leather using nothing but > dung, or perform brain surgery. I guess civilization is about to > collapse. > In that case, I hate to say it, but your education is sorely lacking in the fundamentals. Smelting for instance was discussed at length in the high school physics books I was reading by the time I was in the 3rd grade. Don't they teach anything in school anymore? Tanning leather for instance involves a long soaking in strong tea, and doesn't name the brand or genus of the tea, the important part was the tannic acid content.> > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From rosuav at gmail.com Thu Jul 5 21:58:08 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Jul 2018 11:58:08 +1000 Subject: RANT why the *%#&%^ does installing pip not install setuptools??? In-Reply-To: References: Message-ID: On Fri, Jul 6, 2018 at 11:35 AM, Steven D'Aprano wrote: > On Fri, 06 Jul 2018 03:47:55 +1000, Chris Angelico wrote: > >> What's the output of: >> >> $ apt-cache show python3-pip > > Mysteriously, the output is repeated twice, in every-so-slightly > different formats. It's the little details like that give us confidence > in the quality of the software... The solution to the mystery is here: > Package: python3-pip > Version: 8.1.1-2ubuntu0.4 > > Package: python3-pip > Version: 8.1.1-2 You can see where the two packages come from with: $ apt-cache policy python3-pip It probably means you have multiple package sources configured; or perhaps you have one installed currently, and you could upgrade to a slightly updated version. In any case, setuptools is listed in the recommends. ChrisA From cs at cskk.id.au Thu Jul 5 22:24:12 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 6 Jul 2018 12:24:12 +1000 Subject: Dealing with dicts in doctest In-Reply-To: References: Message-ID: <20180706022412.GA7510@cskk.homeip.net> On 06Jul2018 01:43, Steven D'Aprano wrote: >On Fri, 06 Jul 2018 09:31:50 +1000, Cameron Simpson wrote: >> On 05Jul2018 17:57, Steven D'Aprano >> wrote: >>>I have three ways of dealing with this. Which do you prefer? >> >> Option 4: >> >> >>> func(1) == {'a': 1, 'b': 2, 'c': 3} >> True > >Alas, in reality func takes anything up to six arguments, at least one of >which will be a moderately long sequence requiring two lines: > > >>> func([('a', 1), ('bb', 2), ('ccc', 4), ('dddd', 8)], > ... ('eee', 16), ('ff', 32), ('g', 64)], ... > >and the output is similarly long. So making it a one-liner isn't >generally practical. If you're in Python 3 there's a DocTest.OutputChecker class. Maybe it's possible to subclass this in some doctest utility and use that to catch unsorted dicts? I speak freely here, as one who hasn't tried this. But I'm just starting with doctest myself, so I'm interested. Cheers, Cameron Simpson From sharan.basappa at gmail.com Thu Jul 5 22:56:50 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Thu, 5 Jul 2018 19:56:50 -0700 (PDT) Subject: testing code Message-ID: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> Hi All, I am new to Python though not new to programming. I have implemented my first program in python that uses ML to do some classification task. The whole code is in a single file currently. It contains executable code as well as functions. At the end of the program, I have series of calls that is used to test my code. Now, I would like to re-structure this to separate test code from the program. As I have not done this in Python, I am a bit lost. Please let me know if the following understanding of mine is correct. I need to put the program code in a separate file and organize every executable code in some form of function. If any code exists outside of function then it is not executable by importing. Import this in my test program (file/module) and then initiate calls present in the program. If there is some simple example, it would help a lot. From rosuav at gmail.com Thu Jul 5 23:52:17 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 6 Jul 2018 13:52:17 +1000 Subject: testing code In-Reply-To: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> References: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> Message-ID: On Fri, Jul 6, 2018 at 12:56 PM, Sharan Basappa wrote: > Please let me know if the following understanding of mine is correct. > I need to put the program code in a separate file and organize every executable code in some form of function. If any code exists outside of function then it is not executable by importing. > Kinda. It's actually the other way around: if any code exists outside of functions, it will be executed immediately when you import. So you're correct in that it would be hard (maybe impossible) to unit-test that; and yes, the normal way to do it is to put all your important code into functions. ChrisA From cs at cskk.id.au Fri Jul 6 00:01:52 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 6 Jul 2018 14:01:52 +1000 Subject: testing code In-Reply-To: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> References: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> Message-ID: <20180706040152.GA75278@cskk.homeip.net> On 05Jul2018 19:56, Sharan Basappa wrote: >I have implemented my first program in python that uses ML to do some >classification task. The whole code is in a single file currently. >It contains executable code as well as functions. I presume when you write "executable code" you mean some kind of "main program" that just runs when you run the .py file? >At the end of the program, I have series of calls that is used to test my code. >Now, I would like to re-structure this to separate test code from the program. >As I have not done this in Python, I am a bit lost. > >Please let me know if the following understanding of mine is correct. >I need to put the program code in a separate file and organize every executable code in some form of function. If any code exists outside of function then it is not executable by importing. This is not quite right. Because Python is a dynamic language, importing a file actually runs it. That is how the functions etc get defined. So what you need to do is arrange that your "series of calls that is used to test my code" live in their own function, and that that function only gets run if the file is directly run. Fortunately, this is a very common, almost universal, requirement and there is a standard idom for arranging it. Support you have your code in the file "foo.py" (because I need a concrete filename for the example). It might look like this at present: def func1(...): def func2(...): x = func1(...) y = func2(...) print(x + y) i.e. some function definitions and then you testing code. Now, you can write another file "foo_tests.py" which starts like this: import foo ... run some tests of foo.func1, foo.func2 etc ... The issue is that as written, foo.py will run your test calls during the import. Restructure foo.py like this: def main(): x = func1(...) y = func2(...) print(x + y) def func1(...): def func2(...): if __name__ == '__main__': main() This is very standard. When you run a python file directly the built in __name__ variable contains the string "__main__". This tells you that you're running it as a "main program" i.e. directly. If you import the file instead, as from your planned testing file, the __name__ variable will contain the string "foo" because that is the name of the module. So that "main" function and the "if" at the bottom is standard Python boilerplate code for what you're trying to do. >Import this in my test program (file/module) and then initiate calls present >in the program. >If there is some simple example, it would help a lot. Now you can do this part. Cheers, Cameron Simpson From steve+comp.lang.python at pearwood.info Fri Jul 6 00:17:58 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Jul 2018 04:17:58 +0000 (UTC) Subject: RANT why the *%#&%^ does installing pip not install setuptools??? References: Message-ID: On Fri, 06 Jul 2018 11:58:08 +1000, Chris Angelico wrote: > On Fri, Jul 6, 2018 at 11:35 AM, Steven D'Aprano > wrote: >> On Fri, 06 Jul 2018 03:47:55 +1000, Chris Angelico wrote: >> >>> What's the output of: >>> >>> $ apt-cache show python3-pip >> >> Mysteriously, the output is repeated twice, in every-so-slightly >> different formats. It's the little details like that give us confidence >> in the quality of the software... > > The solution to the mystery is here: > >> Package: python3-pip >> Version: 8.1.1-2ubuntu0.4 >> >> Package: python3-pip >> Version: 8.1.1-2 > > You can see where the two packages come from with: > > $ apt-cache policy python3-pip > > It probably means you have multiple package sources configured; I am using the default configuration. > or > perhaps you have one installed currently, and you could upgrade to a > slightly updated version. Given that I had just run apt install python3-pip yesterday, that would be surprising but not impossible... let's find out: steve at orac /home $ apt install python3-pip Reading package lists... Done Building dependency tree Reading state information... Done python3-pip is already the newest version (8.1.1-2ubuntu0.4). > In any case, setuptools is listed in the recommends. If setuptools isn't included, pip can fail. I don't know if it will fail *always*, but it will surely fail *most* of the time. setuptools should not be treated as an optional extra for pip. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Fri Jul 6 00:33:02 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Jul 2018 04:33:02 +0000 (UTC) Subject: about main() References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> <03c2ee5a-3e6b-c1ec-ca6d-e21bb177620d@gmail.com> Message-ID: On Thu, 05 Jul 2018 18:40:11 -0700, Jim Lee wrote: > On 07/05/18 18:25, Steven D'Aprano wrote: >> On Thu, 05 Jul 2018 11:27:09 -0700, Jim Lee wrote: >> >>> Take a village of people.? They live mostly on wild berries. >> Because of course a community of people living on one food is so >> realistic. Even the Eskimos and Inuit, living in some of the harshest >> environments on earth, managed to have a relatively wide variety of >> foods in their diet. >> >> https://en.wikipedia.org/wiki/Inuit_cuisine >> >> > Pedantics again.? Didn't even get the point before tearing apart the > *analogy* rather than the *point itself*.? I got the point. The point was "old man yells at clouds". Your point is simply *wrong* -- specialisation is what has created civilization, not generalisation, and your Golden Age when all programmers were "Real Programmers" who could not only optimize code at an expert level in a dozen different language but could probably make their own CPUs using nothing but a handful of sand and a cigarette lighter never actually existed. We are in no danger of losing the ability to optimize code that needs to be optimized, and we're in no danger of being stuck with compiler technology that nobody understands. As cautionary tales go, yours is as sensible as "Stop jumping around, you'll break gravity and we'll all float into space!" There's no shortage of people demanding of their programmers "can't you make it go faster?" and no shortage of people good enough to make it happen. Even if the absolute number of clueless code monkeys has gone up, and although certain areas of the software ecosystem are under assault by cascades of attention-deficit disorder teenagers, the proportion of decent coders has not changed in any meaningful way. There are still enough competent programmers and the average quality of code hasn't gone down, and if the industry as a whole has shifted towards more specialisation and less generalisation, that's a GOOD thing. > Childish. If an analogy is to be treated seriously, it ought to be at least plausible. Yours wasn't. I could have just mocked it mercilessly, but I gave it the benefit of the doubt and treated it seriously and saw where it fell down and failed even the simplest smoke test. Your analogy simply doesn't come close to describing either a realistic scenario or the state of computing in 2018. > The rest was TL;DR. I give you the benefit of the doubt, reading your posts and thinking about them before deciding whether to dismiss them as rubbish or not. You ought to give others the same courtesy. Who knows, you might learn something. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From greg.ewing at canterbury.ac.nz Fri Jul 6 02:04:13 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 06 Jul 2018 18:04:13 +1200 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: Steven D'Aprano wrote: > Even the Eskimos and Inuit, living in some of the harshest > environments on earth, managed to have a relatively wide variety of foods > in their diet. They might be living on a very wide variety of berries. Or perhaps, in their language, "berry" simply means "food". -- Greg From steve+comp.lang.python at pearwood.info Fri Jul 6 02:17:28 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Jul 2018 06:17:28 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: <3e587ddc-d43a-d617-03ee-7b76b65c68da@vub.be> <992d23dc-f37b-f789-b308-a707981b9228@vub.be> Message-ID: On Thu, 05 Jul 2018 16:09:52 +0200, Antoon Pardon wrote: >> This is not an innovation of Mypy. It's how type inference is supposed >> to work. If a particular type checker doesn't do that, it is doing it >> wrong. > > That is how type interference works in languages that have some kind of > static typing like Haskell. No, that's how type inference works in dynamically typed languages like Python as well. See Mypy for an example. Do you have a counter-example? I'm happy to be corrected by facts, but not by suppositions about hypothetical type-checkers which might someday exist but don't yet. > Sure if mypy want to impose something like > that it can, but you can't interfere something like that for python > programs in general. Naturally -- that's why type-checking remains opt-in. Nobody, especially not me, says that if you see x = 3 in a random Python program, that means that x must be an int everywhere in that program. That would be a foolish thing to say. But if you opt-in to using a type-checker, the assumption is that you are writing in a less-dynamic, more-static style that will actually get some advantage from static type checking. If you're not doing so, then you're just annoying yourself and wasting time and you won't enjoy the experience one bit. As many people -- including you, if I remember correctly -- have often pointed out, the amount of dynamism allowed in Python is a lot more than the amount typically used by most programs. Most of us, most of the time, treat variables as mostly statically typed. Reusing a variable for something completely unrelated is mildly frowned on, and in practice, most variables are only used for *one* thing during their lifetime. Python remains a fundamentally dynamically typed language, so a static type checker (whether it has type inference or not) cannot cope. It requires gradual typing: a type system capable of dealing with mixed code with parts written in a static-like style and parts that remain fully dynamic. Mypy makes pretty conservative decisions about which parts of your code to check. (E.g. it treats functions as duck-typed unless you explicitly annotate them.) But when it does infer types, it cannot always infer the type you, the programmer, intended. Often because there is insufficient information available: x = [] # we can infer that x is a list, but a list of what? x.append("hello world") # allowed, or a type error? And if the type checker turns out to make an overly-strict inference, and you want to overrule it, you can always annotate it as Any. Type checking algorithms, whether static or gradual, are predicated on the assumption that the type of variable is consistent over the lifetime of that variable. (By type, I include unions, optional types, etc. "A float or a string" is considered a type for these purposes. So is "anything at all".) That's the only reasonable assumption to make for static analysis. I'll grant you that a sufficiently clever type checking algorithm could track changes through time. Proof of concept is that we humans can do so, albeit imperfectly and often poorly, so it's certainly possible. But how we do it is by more-or-less running a simulated Python interpreter in our brain, tracking the types of variables as they change. So *in principle* there could be a type-checker which does that, but as far as I know, there isn't such a beast. As far as I know, nobody has a clue how to do so with any sort of reliability, and I doubt that it is possible since you would surely need runtime information not available to a source-code static analyser. We humans do it by focusing only on a small part of the program at once, and using heuristics to guess what the likely runtime information could be. The fact that we're not very good at it is provable by the number of bugs we let slip in. So the bottom line is, any *practical* static type checker has to assume that a single variable is always the same type during its lifetime, and treat any assignment to another type as an error unless told differently. (If you have counter-examples, I'm happy to learn better.) By the way, you keep writing "interfere", the word is "infer": infer v 1: reason by deduction; establish by deduction [syn: deduce, infer, deduct, derive] 2: draw from specific cases for more general cases [syn: generalize, generalise, extrapolate, infer] 3: conclude by reasoning; in logic [syn: deduce, infer] > Unless you mean "A probable guess" by interfere. No. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From m.n.summerfield at googlemail.com Fri Jul 6 02:53:13 2018 From: m.n.summerfield at googlemail.com (Mark) Date: Thu, 5 Jul 2018 23:53:13 -0700 (PDT) Subject: Is there a nice way to switch between 2 different packages providing the same APIs? In-Reply-To: References: Message-ID: <952efb73-7a33-441a-8243-39958596552b@googlegroups.com> On Thursday, July 5, 2018 at 6:24:09 PM UTC+1, Tim Williams wrote: > On Thu, Jul 5, 2018 at 9:02 AM Mark Summerfield via Python-list < > python-list at python.org> wrote: > > > For GUI programming I often use Python bindings for Qt. > > > > There are two competing bindings, PySide and PyQt. > > > > Ideally I like to have applications that can use either. This way, if I > > get a problem I can try with the other bindings: if I still get the > > problem, then it is probably me; but if I don't it may be an issue with the > > bindings. > > > > But working with both means that my imports are very messy. Here's a tiny > > example: > > > > if PYSIDE: # bool True -> Use PySide; False -> Use PyQt5 > > from PySide2.QtCore import Qt > > from PySide2.QtGui import QIcon > > from PySide2.QtWidgets import ( > > QDialog, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, > > QVBoxLayout) > > else: > > from PyQt5.QtCore import Qt > > from PyQt5.QtGui import QIcon > > from PyQt5.QtWidgets import ( > > QDialog, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, > > QVBoxLayout) > > > > The PYSIDE constant is imported from another module and is used for all > > .py files in a given project so that just by changing PYSIDE's value I can > > run an entire application with PySide2 or with PyQt5. > > > > But I'd really rather just have one lot of imports per file. > > > > One obvious solution is to create a 'Qt.py' module that imports everything > > depending on the PYSIDE switch and that I then use in all the other .py > > files, something like this: > > > > from Qt.QtCore import Qt > > from Qt.QtGui import QIcon > > ... etc. > > > > But I'm just wondering if there's a nicer way to do all this? > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > Check out pyqtgraph > > It tries to use PyQt5/PyQt4/PySide depending on which if these packages > were imported before importing pyqtgraph. I looked at the source for this and it is v. similar to what I'm doing myself right down to having an isObjectAlive() function done exactly as I'm doing it. The thing I'm not keen on is that the imports are like this: from .Qt import QtCore and then used as: p = QtCore.QPoint(0, 0) whereas I want to do something like this (incorrect & maybe not possible): from .Qt.QtCore import QPoint, QRect p = QPoint(0, 0) From __peter__ at web.de Fri Jul 6 02:54:41 2018 From: __peter__ at web.de (Peter Otten) Date: Fri, 06 Jul 2018 08:54:41 +0200 Subject: Dealing with dicts in doctest References: <20180705233150.GA36640@cskk.homeip.net> Message-ID: Steven D'Aprano wrote: > On Fri, 06 Jul 2018 09:31:50 +1000, Cameron Simpson wrote: > >> On 05Jul2018 17:57, Steven D'Aprano >> wrote: >>>I have a function which returns a dict, and I want to use doctest to >>>ensure the documentation is correct. So I write a bunch of doctests: >>> >>>def func(arg): >>> """blah blah blah >>> >>> >>> func(1) >>> {'a': 1, 'b': 2, 'c': 3} >>> """ >>> >>>which is correct, *except* that dict keys have arbitrary order in the >>>versions of Python I'm using. >>> >>>I have three ways of dealing with this. Which do you prefer? >> >> Option 4: >> >> >>> func(1) == {'a': 1, 'b': 2, 'c': 3} >> True > > Alas, in reality func takes anything up to six arguments, at least one of > which will be a moderately long sequence requiring two lines: > > >>> func([('a', 1), ('bb', 2), ('ccc', 4), ('dddd', 8)], > ... ('eee', 16), ('ff', 32), ('g', 64)], ... > > and the output is similarly long. So making it a one-liner isn't > generally practical. In that case: goodbye doctest, hello unittest ;) With complex or just long setup, underdefined output, and exceptions I usually ditch doctest, convenient as it may be. PS: the tinkerer in me wants to provide import sys class name(str): def __repr__(self): return str(self) def dh(obj): if type(obj) is dict: try: obj = name( "{" + ", ".join("%r: %r" % kv for kv in sorted(obj.items())) + "}" ) except TypeError: pass # might sort by (repr(key), repr(value)) _dh(obj) _dh = sys.__displayhook__ sys.__displayhook__ = dh def f(a): """ >>> f(dict(a=1, b=2)) {'a': 1, 'b': 2} """ return a From storchaka at gmail.com Fri Jul 6 03:09:36 2018 From: storchaka at gmail.com (Serhiy Storchaka) Date: Fri, 6 Jul 2018 10:09:36 +0300 Subject: Dealing with dicts in doctest In-Reply-To: References: Message-ID: 05.07.18 20:57, Steven D'Aprano ????: > I think that's really clever. Is it too clever? How do you deal with > dicts in doctests? There was a proposition for adding a doctest option for order-insensitive matching (like NORMALIZE_WHITESPACE and ELLIPSIS). But it was rejected because there is a simple alternative: >>> func(1) == {'a': 1, 'b': 2, 'c': 3} True And since 3.7 the need of this feature was reduced. From antoon.pardon at vub.be Fri Jul 6 03:42:09 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 6 Jul 2018 09:42:09 +0200 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: <3e587ddc-d43a-d617-03ee-7b76b65c68da@vub.be> <992d23dc-f37b-f789-b308-a707981b9228@vub.be> Message-ID: On 06-07-18 08:17, Steven D'Aprano wrote: > On Thu, 05 Jul 2018 16:09:52 +0200, Antoon Pardon wrote: > >>> This is not an innovation of Mypy. It's how type inference is supposed >>> to work. If a particular type checker doesn't do that, it is doing it >>> wrong. >> That is how type interference works in languages that have some kind of >> static typing like Haskell. > No, that's how type inference works in dynamically typed languages like > Python as well. See Mypy for an example. Sorry, but this kind of wording is misleading to me. IMO, it strongly suggests that we can have type inference in python without losing any of the dynamism. The impression that I got from this thread was that you could just trow any python program through mypy and it would work. > But if you opt-in to using a type-checker, the assumption is that you are > writing in a less-dynamic, more-static style that will actually get some > advantage from static type checking. If you're not doing so, then you're > just annoying yourself and wasting time and you won't enjoy the > experience one bit. Thank you for this clarification. It seems that we are largely agreeing but I seem to have understood your past contributions differently than you intended. -- Antoon. From antoon.pardon at vub.be Fri Jul 6 03:54:28 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 6 Jul 2018 09:54:28 +0200 Subject: Is there a nice way to switch between 2 different packages providing the same APIs? In-Reply-To: References: Message-ID: On 05-07-18 14:57, Mark Summerfield via Python-list wrote: > For GUI programming I often use Python bindings for Qt. > > There are two competing bindings, PySide and PyQt. > > Ideally I like to have applications that can use either. This way, if I get a problem I can try with the other bindings: if I still get the problem, then it is probably me; but if I don't it may be an issue with the bindings. > > But working with both means that my imports are very messy. Here's a tiny example: > > if PYSIDE: # bool True -> Use PySide; False -> Use PyQt5 > from PySide2.QtCore import Qt > from PySide2.QtGui import QIcon > from PySide2.QtWidgets import ( > QDialog, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, > QVBoxLayout) > else: > from PyQt5.QtCore import Qt > from PyQt5.QtGui import QIcon > from PyQt5.QtWidgets import ( > QDialog, QFrame, QGridLayout, QLabel, QLineEdit, QPushButton, > QVBoxLayout) > > The PYSIDE constant is imported from another module and is used for all .py files in a given project so that just by changing PYSIDE's value I can run an entire application with PySide2 or with PyQt5. The following is untested but what about if PYSIDE: import PySide2 as PyQt else: import PyQt5 as PyQt Qt = PyQt.QtCore.Qt QIcon = PyQt.QtGui.QIcon ... -- Antoon Pardon From john_ladasky at sbcglobal.net Fri Jul 6 03:58:27 2018 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 6 Jul 2018 00:58:27 -0700 (PDT) Subject: Matplotlib 3D limitations, please recommend alternative In-Reply-To: <06116498-df54-48d9-90a7-7246e5e52ed4@googlegroups.com> References: <940a73c7-b232-44ae-b4c0-3b962fb538ee@googlegroups.com> <06116498-df54-48d9-90a7-7246e5e52ed4@googlegroups.com> Message-ID: On Wednesday, July 4, 2018 at 3:30:32 PM UTC-7, Rick Johnson wrote: > On Wednesday, July 4, 2018 at 4:53:19 PM UTC-5, John Ladasky wrote: > > There are many 3D graphics packages on PyPI. Some appear to be quite specialized. I would appreciate your recommendations. Thanks! > > If you don't want to mess with pyOpenGL, then try VPython. Thanks for the suggestion Rick, I have found some VPython examples here: http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/ From john_ladasky at sbcglobal.net Fri Jul 6 04:05:26 2018 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 6 Jul 2018 01:05:26 -0700 (PDT) Subject: Matplotlib 3D limitations, please recommend alternative In-Reply-To: References: <940a73c7-b232-44ae-b4c0-3b962fb538ee@googlegroups.com> <38E2621C-0385-4845-907B-392B0AB0BA2F@mac.com> Message-ID: <43f2ce36-6773-475d-bf9d-9e14f3bcf69a@googlegroups.com> On Wednesday, July 4, 2018 at 6:38:18 PM UTC-7, William Ray Wing wrote: > > On Jul 4, 2018, at 5:53 PM, John Ladasky wrote: [snip] > > I explored Python OpenGL bindings about three years ago, and quickly got bogged down. Even with Python to assist, dealing with OpenGL was like trying to program Java. Of course, OpenGL can do EVERYTHING. Far more than I need. > > > > The Python Open GL bindings have apparently changed fairly dramatically. I?m no expert, I?m working my way through the on-line book here: > > http://www.labri.fr/perso/nrougier/python-opengl/ > > But the author DOES lay things out in a nice step by step fashion - and with particular emphasis on scientific 3D plotting (which is what I?m after). I've started to read your link. Maybe I will attempt OpenGL a second time. I found my posts documenting my request for help the last time that I attempted OpenGL here: https://groups.google.com/forum/#!msg/comp.lang.python/Hj-UHbAFpWs/7vz-vcSHCAAJ;context-place=forum/comp.lang.python Back then I wrote: "I have concluded that Qt, PyQt, and OpenGL are all rapidly-evolving, and huge, software packages. There may be compatibility problems, and relevant examples with the right software combination may be hard to find. Two weeks of searching web pages hasn't turned up a single example which demonstrates PyQt5 doing something simple in 3D with OpenGL that I can study." It's nice to see that Nicolas Rougier confirms exactly that very near the beginning of his book (Section 2.1, "A bit of history"). From m.n.summerfield at googlemail.com Fri Jul 6 04:14:15 2018 From: m.n.summerfield at googlemail.com (Mark) Date: Fri, 6 Jul 2018 01:14:15 -0700 (PDT) Subject: Is there a nice way to switch between 2 different packages providing the same APIs? In-Reply-To: References: Message-ID: <4c10f602-8450-4415-90ca-83e62f0f8bc4@googlegroups.com> In the end I changed to a completely different approach. I now have two parallel directories, one with PySide-based code and the other with auto-generated PyQt-based code. And I created a tiny script to copy the PySide code to the PyQt directory & do the necessary changes. (I can post the script if anyone's interested.) This means that there are no import hacks and no (manual) duplication, while still being easy to test using either binding library. From breamoreboy at gmail.com Fri Jul 6 06:41:22 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Fri, 6 Jul 2018 11:41:22 +0100 Subject: about main() In-Reply-To: <03c2ee5a-3e6b-c1ec-ca6d-e21bb177620d@gmail.com> References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> <03c2ee5a-3e6b-c1ec-ca6d-e21bb177620d@gmail.com> Message-ID: On 06/07/18 02:40, Jim Lee wrote: > > > On 07/05/18 18:25, Steven D'Aprano wrote: >> On Thu, 05 Jul 2018 11:27:09 -0700, Jim Lee wrote: >> >>> Take a village of people.? They live mostly on wild berries. >> Because of course a community of people living on one food is so >> realistic. Even the Eskimos and Inuit, living in some of the harshest >> environments on earth, managed to have a relatively wide variety of foods >> in their diet. >> >> https://en.wikipedia.org/wiki/Inuit_cuisine >> >> > Pedantics again.? Didn't even get the point before tearing apart the > *analogy* rather than the *point itself*.? Childish. The rest was TL;DR. > > -Jim > Welcome to an exclusive club, my dream team. Congratulations :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at gmail.com Fri Jul 6 06:45:19 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Fri, 6 Jul 2018 11:45:19 +0100 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: On 06/07/18 07:04, Gregory Ewing wrote: > Steven D'Aprano wrote: >> Even the Eskimos and Inuit, living in some of the harshest >> environments on earth, managed to have a relatively wide variety of >> foods in their diet. > > They might be living on a very wide variety of berries. > > Or perhaps, in their language, "berry" simply means "food". > IIRC their language didn't have a word for "toothache" owing to their diet and the use of their teeth as tools. Or was that a precursor of fake news, an urban myth? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From fabiofz at gmail.com Fri Jul 6 07:54:43 2018 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Fri, 6 Jul 2018 08:54:43 -0300 Subject: PyDev 6.4.3 Released Message-ID: *PyDev 6.4.3 Release Highlights* PyDev changes: - *Debugger* - Notification of threads is done as they're created instead of synchronized afterwards. - Support for using frame evaluation disabled by default as it made the debugger much slower on some cases. - Fixed case where breakpoint was missed if an exception was raised in a given line. - Properly break on unhandled exceptions on threads. - Add missing import which affected repl with IPython. - Fix for case where breakpoints could be missed. - Fixed issue tracing lamda functions. - pydevd.settrace() could end up not stopping the debugger properly. - Fixed critical error on debugger (could deadlock when creating a new thread). - *Code Formatter* - It's now possible to use the PyDev code formatter using the command line. - Install with: *pip install pydevf* - Fixes many common formatter errors. - Tries to keep code close to the original formatting. - see: https://github.com/fabioz/PyDev.Formatter for more details. - Fixed issue where blank line was being put in the wrong place in the PyDev code formatter. - Grammar: fixed issue parsing f-strings. - Fixed issue sending current line to interactive console (F2). About PyDev PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development, now also available for Python on Visual Studio Code. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. It is also available as a standalone through LiClipse with goodies such as multiple cursors, theming and support for many other languages, such as Django Templates, Jinja2, Html, JavaScript, etc. Links: PyDev: http://pydev.org PyDev Blog: http://pydev.blogspot.com PyDev on VSCode: http://pydev.org/vscode LiClipse: http://www.liclipse.com PyVmMonitor - Python Profiler: http://www.pyvmmonitor.com/ Cheers, Fabio Zadrozny ? From countryone77 at gmail.com Fri Jul 6 07:56:15 2018 From: countryone77 at gmail.com (Bev in TX) Date: Fri, 6 Jul 2018 06:56:15 -0500 Subject: Is there a nice way to switch between 2 different packages providing the same APIs? In-Reply-To: <4c10f602-8450-4415-90ca-83e62f0f8bc4@googlegroups.com> References: <4c10f602-8450-4415-90ca-83e62f0f8bc4@googlegroups.com> Message-ID: <6E3DDC8D-BDBD-4DDD-A649-E3C2DE68204B@gmail.com> > On Jul 6, 2018, at 3:14 AM, Mark via Python-list wrote: > > In the end I changed to a completely different approach. > > I now have two parallel directories, one with PySide-based code and the other with auto-generated PyQt-based code. And I created a tiny script to copy the PySide code to the PyQt directory & do the necessary changes. (I can post the script if anyone's interested.) I am interested. > > This means that there are no import hacks and no (manual) duplication, while still being easy to test using either binding library. > -- > https://mail.python.org/mailman/listinfo/python-list Bev in TX From m.n.summerfield at googlemail.com Fri Jul 6 08:33:38 2018 From: m.n.summerfield at googlemail.com (Mark) Date: Fri, 6 Jul 2018 05:33:38 -0700 (PDT) Subject: Is there a nice way to switch between 2 different packages providing the same APIs? In-Reply-To: References: <4c10f602-8450-4415-90ca-83e62f0f8bc4@googlegroups.com> <6E3DDC8D-BDBD-4DDD-A649-E3C2DE68204B@gmail.com> Message-ID: On Friday, July 6, 2018 at 1:22:46 PM UTC+1, Bev in TX wrote: > > On Jul 6, 2018, at 3:14 AM, Mark via Python-list wrote: > > > > In the end I changed to a completely different approach. > > > > I now have two parallel directories, one with PySide-based code and the other with auto-generated PyQt-based code. And I created a tiny script to copy the PySide code to the PyQt directory & do the necessary changes. (I can post the script if anyone's interested.) > > I am interested. > > > > This means that there are no import hacks and no (manual) duplication, while still being easy to test using either binding library. > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Bev in TX OK, here're the details. Note that the paths are hard-coded (but could easily be configurable using argparse). I assume: (1) the source dir is 'app'; (2) the dest dir is 'app-pyqt'; (3) there is a file called app/Uniform.py with this content: #!/usr/bin/env python3 # Uniform.py import PySide2.QtCore from PySide2.shiboken2 import isValid as isObjectAlive VERSION_STR = (f'PySide2 {PySide2.__version__} / ' f'Qt {PySide2.QtCore.__version__}') I then run pyside2pyqt.py in the dir *above* app and app-pyqt: #!/usr/bin/env python3 import contextlib import os import shutil SRC = 'app' DST = 'app-pyqt' UNIFORM_FILE = 'Uniform.py' def main(): with contextlib.suppress(FileNotFoundError): shutil.rmtree(DST) shutil.copytree(SRC, DST, ignore=shutil.ignore_patterns( '__pycache__', UNIFORM_FILE)) for root, _, files in os.walk(DST): for name in files: if name.endswith(('.py', '.pyw')): filename = os.path.join(root, name) with open(filename, 'rt', encoding='utf-8') as file: text = file.read().replace('PySide2', 'PyQt5') with open(filename, 'wt', encoding='utf-8') as file: for line in text.splitlines(): if 'pyside2pyqt: DELETE' not in line: print(line, file=file) with open(os.path.join(DST, UNIFORM_FILE), 'wt', encoding='utf-8') as file: file.write(UNIFORM) UNIFORM = '''#!/usr/bin/env python3 import PyQt5.QtCore import PyQt5.sip VERSION_STR = (f'PyQt5 {PyQt5.QtCore.PYQT_VERSION_STR} / ' f'Qt {PyQt5.QtCore.QT_VERSION_STR}') def isObjectAlive(obj): return not PyQt5.sip.isdeleted(obj) ''' if __name__ == '__main__': main() The reaons for being able to delete lines is that the APIs aren't identical. For example, PySide2's QStyleHints has a setCursorFlashTime() method; but PyQt5's doesn't. So for any lines you don't want copied just add the comment, e.g.: style_hints = self.styleHints() # pyside2pyqt: DELETE style_hints.setCursorFlashTime(0) # pyside2pyqt: DELETE I'm sure someone could come up with a more generalized script, but this is sufficient for my needs. From steve+comp.lang.python at pearwood.info Fri Jul 6 08:43:39 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Jul 2018 12:43:39 +0000 (UTC) Subject: Looking for a recent quote about dynamic typing, possibly on this list Message-ID: I think it might have been on this list, or possibly one of Python-Ideas or Python-Dev. Somebody gave a quote about dynamic typing, along the lines of "Just because a language allows a lot of dynamic features, doesn't mean people's code uses a lot of dynamism." Does anyone remember this? My google-fu is failing me. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From bc at freeuk.com Fri Jul 6 09:02:28 2018 From: bc at freeuk.com (Bart) Date: Fri, 6 Jul 2018 14:02:28 +0100 Subject: Looking for a recent quote about dynamic typing, possibly on this list In-Reply-To: References: Message-ID: On 06/07/2018 13:43, Steven D'Aprano wrote: > I think it might have been on this list, or possibly one of Python-Ideas > or Python-Dev. > > Somebody gave a quote about dynamic typing, along the lines of > > "Just because a language allows a lot of dynamic features, doesn't mean > people's code uses a lot of dynamism." > > Does anyone remember this? My google-fu is failing me. Wasn't that you? As in this quote in the PEP 526 thread, 5th July 03:01 BST: > But we know (as so many people keep reminding us) that just because > Python is extremely dynamic, that doesn't necessarily mean that we use it > in extremely dynamic ways. Most of the time, say, 95% of the time, if x > is an int *here*, it is intended to *stay* an int all the way through the > lifetime of that variable. -- bart From steve+comp.lang.python at pearwood.info Fri Jul 6 10:14:39 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Jul 2018 14:14:39 +0000 (UTC) Subject: Looking for a recent quote about dynamic typing, possibly on this list References: Message-ID: On Fri, 06 Jul 2018 14:02:28 +0100, Bart wrote: > On 06/07/2018 13:43, Steven D'Aprano wrote: >> I think it might have been on this list, or possibly one of >> Python-Ideas or Python-Dev. >> >> Somebody gave a quote about dynamic typing, along the lines of >> >> "Just because a language allows a lot of dynamic features, doesn't mean >> people's code uses a lot of dynamism." >> >> Does anyone remember this? My google-fu is failing me. > > Wasn't that you? No -- I have frequently expressed similar sentiments, but it wasn't mine. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From robin at reportlab.com Fri Jul 6 10:37:08 2018 From: robin at reportlab.com (Robin Becker) Date: Fri, 6 Jul 2018 15:37:08 +0100 Subject: about main() In-Reply-To: <0cda33fa-6633-5f92-646a-d8f8494207f4@gmail.com> References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> <0cda33fa-6633-5f92-646a-d8f8494207f4@gmail.com> Message-ID: <4e48f328-6a0c-a29f-8c3d-1332a77bfed9@chamonix.reportlab.co.uk> On 05/07/2018 21:43, Jim Lee wrote: >........... >>> identifying the poisonous berries. >>> >> I would respect your analogy more if every compiler used today were >> forty years old and not being developed by anyone other than its >> original creator(s). >> >> ChrisA > > It's not about compilers - it's about skills.? As programming becomes more and more specialized, it becomes harder and harder to > find programmers with a skill set broad enough to be adaptable to a different task. > > -Jim > I suspect compiler writing is a task that an AI could be taught. The villagers will shout "hey siri I need a compiler" and one will be provided, of course by that time they will all have forgotten about eating berries in favour of soma or equivalent. -- Robin Becker From jxn1558 at rit.edu Fri Jul 6 11:33:02 2018 From: jxn1558 at rit.edu (Joseph Netti (RIT Student)) Date: Fri, 6 Jul 2018 11:33:02 -0400 Subject: Fwd: SSLContext.load_verify_locations In-Reply-To: References: Message-ID: Hi, I think I found either a bug in the documentation or a bug in the load_verify_locations function (or I am just using the function wrong). https://docs.python.org/3/library/ssl.html#ssl.SSLContext. load_verify_locations I am trying to use crls with the ssl.py library which according to the documentation should be done by with the load_verify_locations function. Here is my stackoverflow post about it: https://stackoverflow.com/ques tions/51196492/how-to-use-crls-in-pyopenssl?noredirect=1# comment89404681_51196492 Thanks, Joe From tkadm30 at yandex.com Fri Jul 6 12:13:00 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Fri, 6 Jul 2018 12:13:00 -0400 Subject: Django-hotsauce 0.9.5 (Realistic Scenario) and libschevo 4.0.2 are out! Message-ID: <404a4d69-e3ae-882d-bdc1-6ac1503a83b2@yandex.com> Hi everyone, I'm really happy to announce the public release of Django-hotsauce 0.9.5 (Realistic Scenario) and libschevo 4.0.2 for Python! :-) Downloads: PyPi https://pypi.org/project/Django-hotsauce/ https://pypi.org/project/libschevo/ Master site https://www.isotopesoftware.ca/pub/django-hotsauce/django-hotsauce-0.9.5.tar.gz https://www.isotopesoftware.ca/pub/libschevo/libschevo-4.0.2.tar.gz Release notes: - Maintenance bugfixes (django-hotsauce) - Fixed several critical issues with transaction management and schema migration for the ZODB backend (libschevo) Have fun!! Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From sharan.basappa at gmail.com Fri Jul 6 13:22:00 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Fri, 6 Jul 2018 10:22:00 -0700 (PDT) Subject: testing code In-Reply-To: References: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> <20180706040152.GA75278@cskk.homeip.net> Message-ID: <143734a9-db70-471d-bbd1-b0687d5fd2b9@googlegroups.com> On Friday, 6 July 2018 09:32:08 UTC+5:30, Cameron Simpson wrote: > On 05Jul2018 19:56, Sharan Basappa wrote: > >I have implemented my first program in python that uses ML to do some > >classification task. The whole code is in a single file currently. > >It contains executable code as well as functions. > > I presume when you write "executable code" you mean some kind of "main program" > that just runs when you run the .py file? > > >At the end of the program, I have series of calls that is used to test my code. > >Now, I would like to re-structure this to separate test code from the program. > >As I have not done this in Python, I am a bit lost. > > > >Please let me know if the following understanding of mine is correct. > >I need to put the program code in a separate file and organize every executable code in some form of function. If any code exists outside of function then it is not executable by importing. > > This is not quite right. Because Python is a dynamic language, importing a file > actually runs it. That is how the functions etc get defined. > > So what you need to do is arrange that your "series of calls that is used to > test my code" live in their own function, and that that function only gets run > if the file is directly run. > > Fortunately, this is a very common, almost universal, requirement and there is > a standard idom for arranging it. > > Support you have your code in the file "foo.py" (because I need a concrete > filename for the example). It might look like this at present: > > def func1(...): > > def func2(...): > > x = func1(...) > y = func2(...) > print(x + y) > > i.e. some function definitions and then you testing code. > > Now, you can write another file "foo_tests.py" which starts like this: > > import foo > ... run some tests of foo.func1, foo.func2 etc ... > > The issue is that as written, foo.py will run your test calls during the > import. Restructure foo.py like this: > > def main(): > x = func1(...) > y = func2(...) > print(x + y) > > def func1(...): > > def func2(...): > > if __name__ == '__main__': > main() > > This is very standard. When you run a python file directly the built in > __name__ variable contains the string "__main__". This tells you that you're > running it as a "main program" i.e. directly. > > If you import the file instead, as from your planned testing file, the __name__ > variable will contain the string "foo" because that is the name of the module. > > So that "main" function and the "if" at the bottom is standard Python > boilerplate code for what you're trying to do. > > >Import this in my test program (file/module) and then initiate calls present > >in the program. > >If there is some simple example, it would help a lot. > > Now you can do this part. > > Cheers, > Cameron Simpson Cameron. thanks. this is much more easier than I thought. From sharan.basappa at gmail.com Fri Jul 6 13:22:51 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Fri, 6 Jul 2018 10:22:51 -0700 (PDT) Subject: testing code In-Reply-To: References: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> Message-ID: On Friday, 6 July 2018 09:22:31 UTC+5:30, Chris Angelico wrote: > On Fri, Jul 6, 2018 at 12:56 PM, Sharan Basappa > wrote: > > Please let me know if the following understanding of mine is correct. > > I need to put the program code in a separate file and organize every executable code in some form of function. If any code exists outside of function then it is not executable by importing. > > > > Kinda. It's actually the other way around: if any code exists outside > of functions, it will be executed immediately when you import. So > you're correct in that it would be hard (maybe impossible) to > unit-test that; and yes, the normal way to do it is to put all your > important code into functions. > > ChrisA thanks a lot From steve+comp.lang.python at pearwood.info Fri Jul 6 13:45:30 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 6 Jul 2018 17:45:30 +0000 (UTC) Subject: Thread-safe way to add a key to a dict only if it isn't already there? Message-ID: I have a dict with string keys: D = {'a': None, 'b': None} (the values don't matter for this question) and I want to add a key but only if it isn't already there. If I do the obvious: if not 'c' in D: D['c'] = None there's a Time Of Check to Time Of Use bug where some other thread could conceivably insert 'c' into the dict between the check and the insertion. How do I do a thread-safe insertion if, and only if, the key isn't already there? Thanks in advance, -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From songofacandy at gmail.com Fri Jul 6 13:51:41 2018 From: songofacandy at gmail.com (INADA Naoki) Date: Sat, 7 Jul 2018 02:51:41 +0900 Subject: Thread-safe way to add a key to a dict only if it isn't already there? In-Reply-To: References: Message-ID: D.setdefault('c', None) On Sat, Jul 7, 2018 at 2:49 AM Steven D'Aprano wrote: > > I have a dict with string keys: > > D = {'a': None, 'b': None} > > (the values don't matter for this question) and I want to add a key but > only if it isn't already there. If I do the obvious: > > if not 'c' in D: > D['c'] = None > > there's a Time Of Check to Time Of Use bug where some other thread could > conceivably insert 'c' into the dict between the check and the insertion. > > How do I do a thread-safe insertion if, and only if, the key isn't > already there? > > > > Thanks in advance, > > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson > > -- > https://mail.python.org/mailman/listinfo/python-list -- INADA Naoki From ian.g.kelly at gmail.com Fri Jul 6 13:57:57 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 6 Jul 2018 11:57:57 -0600 Subject: Thread-safe way to add a key to a dict only if it isn't already there? In-Reply-To: References: Message-ID: On Fri, Jul 6, 2018 at 11:56 AM INADA Naoki wrote: > > D.setdefault('c', None) Not guaranteed to be atomic. I think the only safe way to do it is with a Lock. From grant.b.edwards at gmail.com Fri Jul 6 14:24:04 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 6 Jul 2018 18:24:04 +0000 (UTC) Subject: about main() References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> Message-ID: On 2018-07-05, Jim Lee wrote: > Take a village of people. They live mostly on wild berries. It's completely orthogonal to your point of course, but I thought villages happened precisely because people had stopped living off wild stuff and had adopted organized agriculture... -- Grant Edwards grant.b.edwards Yow! Are you still an at ALCOHOLIC? gmail.com From grant.b.edwards at gmail.com Fri Jul 6 14:25:41 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 6 Jul 2018 18:25:41 +0000 (UTC) Subject: about main() References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> <03c2ee5a-3e6b-c1ec-ca6d-e21bb177620d@gmail.com> Message-ID: On 2018-07-06, Jim Lee wrote: > > Pedantics again. Didn't even get the point before tearing apart the > *analogy* rather than the *point itself*. Jim Lee, this is the Internet. Intenet, this is Jim Lee. :) -- Grant Edwards grant.b.edwards Yow! I'm encased in the at lining of a pure pork gmail.com sausage!! From grant.b.edwards at gmail.com Fri Jul 6 14:27:16 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 6 Jul 2018 18:27:16 +0000 (UTC) Subject: about main() References: <201807052150.30731.gheskett@shentel.net> Message-ID: On 2018-07-06, Gene Heskett wrote: > In that case, I hate to say it, but your education is sorely lacking in > the fundamentals. Smelting for instance was discussed at length in the > high school physics books I was reading by the time I was in the 3rd > grade. Don't they teach anything in school anymore? Tanning leather for > instance involves a long soaking in strong tea, and doesn't name the > brand or genus of the tea, the important part was the tannic acid > content. IIRC, oack leaves/chips work well also. -- Grant Edwards grant.b.edwards Yow! I'm shaving!! at I'M SHAVING!! gmail.com From gheskett at shentel.net Fri Jul 6 15:04:20 2018 From: gheskett at shentel.net (Gene Heskett) Date: Fri, 6 Jul 2018 15:04:20 -0400 Subject: about main() In-Reply-To: References: <201807052150.30731.gheskett@shentel.net> Message-ID: <201807061504.20425.gheskett@shentel.net> On Friday 06 July 2018 14:27:16 Grant Edwards wrote: > On 2018-07-06, Gene Heskett wrote: > > In that case, I hate to say it, but your education is sorely lacking > > in the fundamentals. Smelting for instance was discussed at length > > in the high school physics books I was reading by the time I was in > > the 3rd grade. Don't they teach anything in school anymore? Tanning > > leather for instance involves a long soaking in strong tea, and > > doesn't name the brand or genus of the tea, the important part was > > the tannic acid content. > > IIRC, oak leaves/chips work well also. Yes, and fairly well too from what I've read when I had a shed full of deer skins one winter about 50 years ago. > -- > Grant Edwards grant.b.edwards Yow! I'm shaving!! > at I'M SHAVING!! > gmail.com -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From jlee54 at gmail.com Fri Jul 6 15:09:13 2018 From: jlee54 at gmail.com (Jim Lee) Date: Fri, 6 Jul 2018 12:09:13 -0700 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> <03c2ee5a-3e6b-c1ec-ca6d-e21bb177620d@gmail.com> Message-ID: <519a87ca-1a6c-1ae5-e9f4-b6d986e78d56@gmail.com> On 07/06/18 11:25, Grant Edwards wrote: > On 2018-07-06, Jim Lee wrote: >> Pedantics again. Didn't even get the point before tearing apart the >> *analogy* rather than the *point itself*. > Jim Lee, this is the Internet. > > Intenet, this is Jim Lee. > > :) > You have an inaccurate anthropomorphic reference as well as a spelling error. [insert long diatribe on how Python annotations are God's gift to mankind] There.? Do I fit in now? :) From tjreedy at udel.edu Fri Jul 6 15:57:29 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 6 Jul 2018 15:57:29 -0400 Subject: about main() In-Reply-To: <03c2ee5a-3e6b-c1ec-ca6d-e21bb177620d@gmail.com> References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> <03c2ee5a-3e6b-c1ec-ca6d-e21bb177620d@gmail.com> Message-ID: On 7/5/2018 9:40 PM, Jim Lee wrote: > On 07/05/18 18:25, Steven D'Aprano wrote: >> On Thu, 05 Jul 2018 11:27:09 -0700, Jim Lee wrote: >> >>> Take a village of people.? They live mostly on wild berries. >> Because of course a community of people living on one food is so >> realistic. Even the Eskimos and Inuit, living in some of the harshest >> environments on earth, managed to have a relatively wide variety of foods >> in their diet. >> >> https://en.wikipedia.org/wiki/Inuit_cuisine >> >> > Pedantics again.? Didn't even get the point before tearing apart the > *analogy* rather than the *point itself*. The irony of both Steven's interruption and your reaction is that the Inuit story somewhat supports your point: "There has been a decline of hunting partially due to the fact that young people lack the skills to survive off the land. " -- because they are 'growing more accustomed to the Qallunaat ("white people") food that they receive from the south.' If 'white people' food stopped coming, they would starve where they are. But change scenarios that assume that everything else remains the same are flawed. Maintaining traditional skills comes up in every culture that is changing, which now is most all. But the same dynamism tends to generate new solutions where needed. -- Terry Jan Reedy From grant.b.edwards at gmail.com Fri Jul 6 16:08:58 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 6 Jul 2018 20:08:58 +0000 (UTC) Subject: about main() References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> <03c2ee5a-3e6b-c1ec-ca6d-e21bb177620d@gmail.com> <519a87ca-1a6c-1ae5-e9f4-b6d986e78d56@gmail.com> Message-ID: On 2018-07-06, Jim Lee wrote: > On 07/06/18 11:25, Grant Edwards wrote: >> On 2018-07-06, Jim Lee wrote: >> >>> Pedantics again. Didn't even get the point before tearing apart the >>> *analogy* rather than the *point itself*. >> Jim Lee, this is the Internet. >> >> Intenet, this is Jim Lee. >> >> :) > > You have an inaccurate anthropomorphic reference as well as a > spelling error. > > [insert long diatribe on how Python annotations are God's gift to mankind] > > There. Do I fit in now? Yes, brilliantly! -- Grant Edwards grant.b.edwards Yow! I'm having an at emotional outburst!! gmail.com From jlee54 at gmail.com Fri Jul 6 16:53:23 2018 From: jlee54 at gmail.com (Jim Lee) Date: Fri, 6 Jul 2018 13:53:23 -0700 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> <03c2ee5a-3e6b-c1ec-ca6d-e21bb177620d@gmail.com> Message-ID: <56f10304-4e3f-418c-9e5d-ab85920b35b3@gmail.com> On 07/06/18 12:57, Terry Reedy wrote: > On 7/5/2018 9:40 PM, Jim Lee wrote: > >> On 07/05/18 18:25, Steven D'Aprano wrote: >>> On Thu, 05 Jul 2018 11:27:09 -0700, Jim Lee wrote: >>> >>>> Take a village of people.? They live mostly on wild berries. >>> Because of course a community of people living on one food is so >>> realistic. Even the Eskimos and Inuit, living in some of the harshest >>> environments on earth, managed to have a relatively wide variety of >>> foods >>> in their diet. >>> >>> https://en.wikipedia.org/wiki/Inuit_cuisine >>> >>> >> Pedantics again.? Didn't even get the point before tearing apart the >> *analogy* rather than the *point itself*. > > The irony of both Steven's interruption and your reaction is that the > Inuit story somewhat supports your point: > > "There has been a decline of hunting partially due to the fact that > young people lack the skills to survive off the land. " > > -- because they are 'growing more accustomed to the Qallunaat ("white > people") food that they receive from the south.' > > If 'white people' food stopped coming, they would starve where they are. > > But change scenarios that assume that everything else remains the same > are flawed.? Maintaining traditional skills comes up in every culture > that is changing, which now is most all.? But the same dynamism tends > to generate new solutions where needed. > Finally, a person with sense enough to contribute a rational thought to this thread! >"But the same dynamism tends to generate new solutions where needed." Yes.? However,? technological evolution happens at a blindingly faster rate than cultural evolution.? Because of this, there are many of us still alive who have been here "from the beginning" of the computer era. That gives us a unique perspective, in that we have seen first-hand many cycles of these "solutions" being invented, re-invented, and re-re-invented.? We lament the continual re-emergence of bad ideas that have failed in the past (and applaud the good ones). People like that, in a cultural context, are treated as wise elders;? in the technology context, they're treated as doddering old fools. Somehow, we've adopted the notion that old == obsolete == useless when it comes to technological ideas.? I've seen more than one person refuse to consider some software application (even though it fit their requirements perfectly) simply because it hadn't been updated in 9 months.? That's too "old".? You'd think they were shopping for a gallon of milk. -Jim From steve+comp.lang.python at pearwood.info Fri Jul 6 21:36:41 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 7 Jul 2018 01:36:41 +0000 (UTC) Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: Message-ID: On Sat, 07 Jul 2018 02:51:41 +0900, INADA Naoki wrote: > D.setdefault('c', None) Oh that's clever! Thanks! -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From ben+python at benfinney.id.au Fri Jul 6 21:38:37 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 07 Jul 2018 11:38:37 +1000 Subject: Looking for a recent quote about dynamic typing, possibly on this list References: Message-ID: <85fu0vakpu.fsf@benfinney.id.au> Steven D'Aprano writes: > Somebody gave a quote about dynamic typing, along the lines of > > "Just because a language allows a lot of dynamic features, doesn't mean > people's code uses a lot of dynamism." You did refer us to on this forum. That contains a quote attributed to John Aycock with the meaning you paraphrase above. -- \ ?? it's best to confuse only one issue at a time.? ?Brian W. | `\ Kernighan and Dennis M. Ritchie, _The C programming language_, | _o__) 1988 | Ben Finney From steve+comp.lang.python at pearwood.info Fri Jul 6 21:54:10 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 7 Jul 2018 01:54:10 +0000 (UTC) Subject: about main() References: <201807052150.30731.gheskett@shentel.net> Message-ID: On Fri, 06 Jul 2018 18:27:16 +0000, Grant Edwards wrote: > On 2018-07-06, Gene Heskett wrote: > >> In that case, I hate to say it, but your education is sorely lacking in >> the fundamentals. Smelting for instance was discussed at length in the >> high school physics books I was reading by the time I was in the 3rd >> grade. Don't they teach anything in school anymore? Tanning leather for >> instance involves a long soaking in strong tea, and doesn't name the >> brand or genus of the tea, the important part was the tannic acid >> content. > > IIRC, oack leaves/chips work well also. But the *best* quality tanned leather was historically made from dog faeces, known as "pure" by the tanners of the time: Members only: https://www.vettimes.co.uk/article/a-dirty-job-but-not-to-be-sniffed-at/ But this might work for you: https://www.vettimes.co.uk/app/uploads/wp-post-to-pdf-enhanced-cache/1/a-dirty-job-but-not-to-be-sniffed-at.pdf -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From greg.ewing at canterbury.ac.nz Sat Jul 7 00:53:57 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 07 Jul 2018 16:53:57 +1200 Subject: about main() In-Reply-To: References: <87zhz60w0r.fsf@elektro.pacujo.net> <87r2kh282c.fsf@elektro.pacujo.net> <7ffedfcd-2698-272d-a370-f82dc6f746c1@gmail.com> <0cda33fa-6633-5f92-646a-d8f8494207f4@gmail.com> <4e48f328-6a0c-a29f-8c3d-1332a77bfed9@chamonix.reportlab.co.uk> Message-ID: Robin Becker wrote: > The > villagers will shout "hey siri I need a compiler" and one will be > provided Then one day someone says "Hey, Siri, make me an artificial intelligence that can respond to voice commands", and then it's not long before the AIs are breeding by themselves and take over. Berries are no longer required after that. -- Greg From steve+comp.lang.python at pearwood.info Sat Jul 7 01:18:55 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 7 Jul 2018 05:18:55 +0000 (UTC) Subject: PEP 526 - var annotations and the spirit of python References: <3e587ddc-d43a-d617-03ee-7b76b65c68da@vub.be> <992d23dc-f37b-f789-b308-a707981b9228@vub.be> Message-ID: On Fri, 06 Jul 2018 09:42:09 +0200, Antoon Pardon wrote: > On 06-07-18 08:17, Steven D'Aprano wrote: >> On Thu, 05 Jul 2018 16:09:52 +0200, Antoon Pardon wrote: >> >>>> This is not an innovation of Mypy. It's how type inference is >>>> supposed to work. If a particular type checker doesn't do that, it is >>>> doing it wrong. >>> That is how type interference works in languages that have some kind >>> of static typing like Haskell. >> No, that's how type inference works in dynamically typed languages like >> Python as well. See Mypy for an example. > > Sorry, but this kind of wording is misleading to me. IMO, it strongly > suggests that we can have type inference in python without losing any of > the dynamism. That's true in two senses, false in a third. 1. We can have the benefits of static type checking without losing any of the *available* dynamism -- the Python interpreter remains fully dynamic and we can make use of that dynamism by simply *not* type-checking a particular function or module; 2. we can get the benefits of static type checking without losing the dynamism we *actually use*, because in general we don't use much of it (you don't miss what you don't use); 3. but in the third sense, of course you do have to choose to forgo the opportunity for some dynamism in order to get the benefit of static type checking. With gradual typing you can statically check the parts of your code that benefit from it while other parts of the code remain fully dynamic. The bottom line is that every Python programmer can choose for their own projects just how much or how little dynamism is appropriate, trading off the convenience of runtime dynamic typing with the type-safety of static type checking without needing to make an All Or Nothing choice. > The impression that I got from this thread was that you could just trow > any python program through mypy and it would work. Not quite, but you might be surprised. I know I was :-) I just picked a random selection of modules out of my private toolbox, ran mypy over them, and in a few tries found some bugs: steve at orac ~ $ mypy python/utilities/enhanced_dir.py python/utilities/enhanced_dir.py:141: error: Module 'types' has no attribute 'ClassType' steve at orac ~ $ mypy python/excguard.py python/excguard.py:138: error: "str" has no attribute "uper"; maybe "upper"? That's not bad. With absolutely no type hinting, mypy found two bugs in my code from six attempts. And remember, with no type annotations, Mypy is treating all the functions as duck-typed, even if I'm not using them in a duck-typed fashion. If I were to add annotations, I'd probably find a lot more errors. (I don't fool myself into thinking my code is bug-free.) You aren't going to get the full benefit of Mypy without making a commitment to type-hinting at least *some* of your code. Running it over a random Python module with no hints is not going to do much. >> But if you opt-in to using a type-checker, the assumption is that you >> are writing in a less-dynamic, more-static style that will actually get >> some advantage from static type checking. If you're not doing so, then >> you're just annoying yourself and wasting time and you won't enjoy the >> experience one bit. > > Thank you for this clarification. It seems that we are largely agreeing > but I seem to have understood your past contributions differently than > you intended. I may have been a little unclear, if so mea culpa, sorry for any misunderstanding I caused. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sat Jul 7 01:29:07 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 7 Jul 2018 05:29:07 +0000 (UTC) Subject: Looking for a recent quote about dynamic typing, possibly on this list References: <85fu0vakpu.fsf@benfinney.id.au> Message-ID: On Sat, 07 Jul 2018 11:38:37 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> Somebody gave a quote about dynamic typing, along the lines of >> >> "Just because a language allows a lot of dynamic features, doesn't mean >> people's code uses a lot of dynamism." > > You did refer us to on > this forum. That contains a quote attributed to John Aycock with the > meaning you paraphrase above. That's it! You're my hero! I knew it wasn't *my* quote, I had forgotten that I linked to it. Thanks. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From stefan_ml at behnel.de Sat Jul 7 04:11:48 2018 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 7 Jul 2018 10:11:48 +0200 Subject: Looking for a recent quote about dynamic typing, possibly on this list In-Reply-To: <85fu0vakpu.fsf@benfinney.id.au> References: <85fu0vakpu.fsf@benfinney.id.au> Message-ID: Ben Finney schrieb am 07.07.2018 um 03:38: > Steven D'Aprano writes: > >> Somebody gave a quote about dynamic typing, along the lines of >> >> "Just because a language allows a lot of dynamic features, doesn't mean >> people's code uses a lot of dynamism." > > You did refer us to on > this forum. That contains a quote attributed to John Aycock with the > meaning you paraphrase above. And since the link in that article seems broken, here's the cited paper: https://legacy.python.org/workshops/2000-01/proceedings/papers/aycock/aycock.html Stefan PS: the link could probably be fixed with a redirect from python.org... From ruifernqq at gmail.com Sat Jul 7 06:23:05 2018 From: ruifernqq at gmail.com (ruifernqq at gmail.com) Date: Sat, 7 Jul 2018 03:23:05 -0700 (PDT) Subject: SWIG+Distutils - no harmony? In-Reply-To: <3c459006.8635157@news.muenster.de> References: <3c459006.8635157@news.muenster.de> Message-ID: Em ter?a-feira, 15 de janeiro de 2002 21:26:05 UTC+1, Martin Bless escreveu: > Getting courageous I try building 'example.pyd' > from the SWIG 'Simple Example' using SWIG and the Distutils. > Looks promising but doesn't succeed. I didn't > modify 'example.c' and 'example.i'. > > Problems/questions: > > (1) Is 'setup.py' ok? > (2) BEWARE: What's really shocking: > After see (unsuccessful) > python setup.py build -cmingw32 > the original 'example.c' is GONE AND AWAY - > replaced by the wrapper. > (3) What's going wrong? > > Martin > > Sources und logs following: > > >----------<>----------<>----------< > # setup.py > # mb: Is this ok? > import distutils > from distutils.core import setup, Extension > #from distutils.extension import Extension > > setup(name = "Example 'Simple' from the SWIG examples", > version = "2.2", > ext_modules = [Extension("example", ["example.i"])]) > > >----------<>----------<>----------< > /* File : example.i */ > %module example > > extern int gcd(int x, int y); > extern double Foo; > > >----------<>----------<>----------< > /* File : example.c */ > > /* A global variable */ > double Foo = 3.0; > > /* Compute the greatest common divisor of positive integers */ > int gcd(int x, int y) { > int g; > g = y; > while (x > 0) { > g = x; > x = y % x; > y = g; > } > return g; > } > > >----------<>----------<>----------< > C:\python > Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> > > >----------<>----------<>----------< > swig -version > > SWIG Version 1.3.10u-20011211-2004 > Copyright (c) 1995-1998 > University of Utah and the Regents of the University of California > Copyright (c) 1998-2001 > University of Chicago > > Compiled with CC > > >----------<>----------<>----------< > >python setup.py build -cmingw32 > > running build > running build_ext > building 'example' extension > swigging example.i to example.c > c:\pyext\swig\swig.exe -python -dnone > -ISWIG -o example.c example.i > c:\mingw\bin\gcc.exe -mno-cygwin -mdll > -O -Wall -IC:\PYTHON22\include > -c example.c -o build\temp.win32-2.2\Release\example.o > writing build\temp.win32-2.2\Release\example.def > > c:\mingw\bin\gcc.exe -mno-cygwin -mdll -static > -s build\temp.win32-2.2\Release\example.o > build\temp.win32-2.2\Release\example.def > -LC:\PYTHON22\libs -lpython22 > -o build\lib.win32-2.2\example.pyd > > swig: Warning. -dnone option deprecated. > > example.c: In function `SWIG_UnpackData': > example.c:363: warning: `uu' might be used uninitialized in this > function > example.c: In function `SWIG_ConvertPtr': > example.c:429: warning: suggest explicit braces to avoid ambiguous > `else' > example.c:432: warning: suggest explicit braces to avoid ambiguous > `else' > example.c:438: warning: suggest explicit braces to avoid ambiguous > `else' > example.c: At top level: > example.c:154: warning: `SWIG_TypeQuery' defined but not used > example.c:385: warning: `SWIG_ConvertPtr' defined but not used > example.c:468: warning: `SWIG_ConvertPacked' defined but not used > example.c:537: warning: `SWIG_MakeShadow' defined but not used > build\temp.win32-2.2\Release\example.o(.text+0xbda):example.c: > undefined reference to `gcd' > build\temp.win32-2.2\Release\example.o(.text+0xc35):example.c: > undefined reference to `Foo' > build\temp.win32-2.2\Release\example.o(.text+0xc6b):example.c: > undefined reference to `Foo' > build\temp.win32-2.2\Release\example.o(.text+0xc71):example.c: > undefined reference to `Foo' > error: command 'gcc' failed with exit status 1 > > >----------<>----------<>----------< From sharan.basappa at gmail.com Sat Jul 7 08:02:21 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 7 Jul 2018 05:02:21 -0700 (PDT) Subject: testing code In-Reply-To: References: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> Message-ID: <13e03c7f-6665-48c0-bf73-3d1ee46733e9@googlegroups.com> On Friday, 6 July 2018 09:22:31 UTC+5:30, Chris Angelico wrote: > On Fri, Jul 6, 2018 at 12:56 PM, Sharan Basappa > wrote: > > Please let me know if the following understanding of mine is correct. > > I need to put the program code in a separate file and organize every executable code in some form of function. If any code exists outside of function then it is not executable by importing. > > > > Kinda. It's actually the other way around: if any code exists outside > of functions, it will be executed immediately when you import. So > you're correct in that it would be hard (maybe impossible) to > unit-test that; and yes, the normal way to do it is to put all your > important code into functions. > > ChrisA Chris, Things do work as per expected with one exception. You mentioned that as soon as a file is imported, it executes immediately. Please see the example below: file: test_2.py x = 10 y = 20 c = x-y print c def func1(): return x+y test_2_test.py x = 10 y = 20 c = x-y print c def func1(): return x+y this is the output: %run "D:/Projects/Initiatives/machine learning/programs/test_2_test.py" 30 As you can see, print c in test_2 file was not executed upon import as there is no corresponding output From rosuav at gmail.com Sat Jul 7 08:52:06 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 7 Jul 2018 22:52:06 +1000 Subject: testing code In-Reply-To: <13e03c7f-6665-48c0-bf73-3d1ee46733e9@googlegroups.com> References: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> <13e03c7f-6665-48c0-bf73-3d1ee46733e9@googlegroups.com> Message-ID: On Sat, Jul 7, 2018 at 10:02 PM, Sharan Basappa wrote: > On Friday, 6 July 2018 09:22:31 UTC+5:30, Chris Angelico wrote: >> On Fri, Jul 6, 2018 at 12:56 PM, Sharan Basappa >> wrote: >> > Please let me know if the following understanding of mine is correct. >> > I need to put the program code in a separate file and organize every executable code in some form of function. If any code exists outside of function then it is not executable by importing. >> > >> >> Kinda. It's actually the other way around: if any code exists outside >> of functions, it will be executed immediately when you import. So >> you're correct in that it would be hard (maybe impossible) to >> unit-test that; and yes, the normal way to do it is to put all your >> important code into functions. >> >> ChrisA > > Chris, > > Things do work as per expected with one exception. > You mentioned that as soon as a file is imported, it executes immediately. > > Please see the example below: > > file: test_2.py > > x = 10 > y = 20 > > c = x-y > > print c > > def func1(): > return x+y > > test_2_test.py > > x = 10 > y = 20 > > c = x-y > > print c > > def func1(): > return x+y > > this is the output: > %run "D:/Projects/Initiatives/machine learning/programs/test_2_test.py" > 30 > > As you can see, print c in test_2 file was not executed upon import as there is no corresponding output I don't think you import your other module anywhere. ChrisA From marko at pacujo.net Sat Jul 7 09:41:31 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 07 Jul 2018 16:41:31 +0300 Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: Message-ID: <87o9fj9n90.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sat, 07 Jul 2018 02:51:41 +0900, INADA Naoki wrote: >> D.setdefault('c', None) > > Oh that's clever! Is that guaranteed to be thread-safe? The documentation () makes no such promise. At least __collectios_abc.py contains this method definition for MutableMapping: def setdefault(self, key, default=None): 'D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D' try: return self[key] except KeyError: self[key] = default return default There are more such non-thread-safe definitions. Marko From stefan_ml at behnel.de Sat Jul 7 10:00:15 2018 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 7 Jul 2018 16:00:15 +0200 Subject: Thread-safe way to add a key to a dict only if it isn't already there? In-Reply-To: <87o9fj9n90.fsf@elektro.pacujo.net> References: <87o9fj9n90.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa schrieb am 07.07.2018 um 15:41: > Steven D'Aprano : >> On Sat, 07 Jul 2018 02:51:41 +0900, INADA Naoki wrote: >>> D.setdefault('c', None) >> >> Oh that's clever! > > Is that guaranteed to be thread-safe? The documentation ( s://docs.python.org/3/library/stdtypes.html#dict.setdefault>) makes no > such promise. It's implemented in C and it's at least designed to avoid multiple lookups and hash value calculations, which suggests that it's also thread-safe by design (or by a side-effect of the design). Whether that's guaranteed, I cannot say, but a change that makes it non-thread-safe would probably be very controversial. > At least __collectios_abc.py > contains this method definition for MutableMapping: > > def setdefault(self, key, default=None): > 'D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D' > try: > return self[key] > except KeyError: > self[key] = default > return default > > There are more such non-thread-safe definitions. That's a different beast, because Python code can always be interrupted by thread switches (between each byte code execution). C code cannot, unless it starts executing byte code (e.g. for calculating a key's hash value) or explicitly allows a thread switch at a given point. Stefan From ian.g.kelly at gmail.com Sat Jul 7 11:09:52 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 7 Jul 2018 09:09:52 -0600 Subject: Thread-safe way to add a key to a dict only if it isn't already there? In-Reply-To: References: <87o9fj9n90.fsf@elektro.pacujo.net> Message-ID: On Sat, Jul 7, 2018 at 8:03 AM Stefan Behnel wrote: > > Marko Rauhamaa schrieb am 07.07.2018 um 15:41: > > Steven D'Aprano : > >> On Sat, 07 Jul 2018 02:51:41 +0900, INADA Naoki wrote: > >>> D.setdefault('c', None) > >> > >> Oh that's clever! > > > > Is that guaranteed to be thread-safe? The documentation ( > s://docs.python.org/3/library/stdtypes.html#dict.setdefault>) makes no > > such promise. > > It's implemented in C and it's at least designed to avoid multiple lookups > and hash value calculations, which suggests that it's also thread-safe by > design (or by a side-effect of the design). Whether that's guaranteed, I > cannot say, but a change that makes it non-thread-safe would probably be > very controversial. It's only implemented in C if you're using CPython (and if it's the builtin dict type and not a subclass). If there's any chance that your code might run under any other interpreter than CPython, then you can't rely on the GIL for thread-safety. I would also point out https://bugs.python.org/issue25343. While some operations are known to be atomic (and therefore thread-safe), the leaning of the devs seems to be to refrain from documenting it and instead document that *no* operations are guaranteed atomic. > > At least __collectios_abc.py > > contains this method definition for MutableMapping: > > > > def setdefault(self, key, default=None): > > 'D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D' > > try: > > return self[key] > > except KeyError: > > self[key] = default > > return default > > > > There are more such non-thread-safe definitions. > > That's a different beast, because Python code can always be interrupted by > thread switches (between each byte code execution). C code cannot, unless > it starts executing byte code (e.g. for calculating a key's hash value) or > explicitly allows a thread switch at a given point. dict.setdefault does potentially call __hash__ and __eq__ on the key. Since this is part of the lookup I don't know whether it affects thread-safety as long as the key is properly hashable, but it does make it more difficult to reason about. I don't *think* that setdefault calls Py_DECREF, but if it did then that is another potential point of thread interruption. By contrast, using a mutex to guard accesses is definitely safe, and it's also self-documenting of the fact that thread-safety is a concern. From jeanpierreda at gmail.com Sat Jul 7 11:12:16 2018 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 7 Jul 2018 08:12:16 -0700 Subject: Thread-safe way to add a key to a dict only if it isn't already there? In-Reply-To: <87o9fj9n90.fsf@elektro.pacujo.net> References: <87o9fj9n90.fsf@elektro.pacujo.net> Message-ID: On Sat, Jul 7, 2018 at 6:49 AM Marko Rauhamaa wrote: > Is that guaranteed to be thread-safe? The documentation ( s://docs.python.org/3/library/stdtypes.html#dict.setdefault>) makes no > such promise. It's guaranteed to be thread-safe because all of Python's core containers are thread safe (in as far as they document behaviors/invariants, which implicitly also hold in multithreaded code -- Python does not take the approach other languages do of "thread-compatible" containers that have undefined behavior if mutated from multiple threads simultaneously). It isn't guaranteed to be _atomic_ by the documentation, but I bet no Python implementation would make dict.setdefault non-atomic. There's no good description of the threading rules for Python data structures anywhere. ISTR there was a proposal to give Python some defined rules around thread-safety a couple of years ago (to help with things like GIL-less python projects), but I guess nothing ever came of it. -- Devin From ethan at stoneleaf.us Sat Jul 7 12:42:50 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 07 Jul 2018 09:42:50 -0700 Subject: Thread-safe way to add a key to a dict only if it isn't already there? In-Reply-To: References: Message-ID: <5B40ED8A.6070701@stoneleaf.us> On 07/06/2018 10:51 AM, INADA Naoki wrote: > On Sat, Jul 7, 2018 at 2:49 AM Steven D'Aprano wrote: >> I have a dict with string keys: >> >> --> D = {'a': None, 'b': None} >> How do I do a thread-safe insertion if, and only if, the key isn't >> already there? > > D.setdefault('c', None) This is how Enum avoids race conditions when setting up the re.RegexType enumeration. -- ~Ethan~ From marko at pacujo.net Sat Jul 7 17:00:26 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Jul 2018 00:00:26 +0300 Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> Message-ID: <8736wuahhx.fsf@elektro.pacujo.net> Ian Kelly : > the leaning of the devs seems to be to refrain from documenting it and > instead document that *no* operations are guaranteed atomic. I believe that to be wise. Otherwise, Python would limit its future implementation options. The only thing Python should guarantee is that the data structures stay "coherent" under race conditions. In other words, there cannot be a segmentation fault. For example, if two threads executed this code in parallel: global i i = 1 i += 1 a legal end result could be that i contains the string "impossible". Marko From skip.montanaro at gmail.com Sat Jul 7 19:24:46 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 7 Jul 2018 18:24:46 -0500 Subject: Generate a static back-of-a-book style index? Message-ID: I just generated a static website which is nothing more than around ten years of email messages from a defunct vintage bike mailing list (170k messages, one per file). Though I've submitted the front page URL to both Google and Bing, I was thinking that it would be handy to have something like a static index such as you might find in the back of a book. I poked around a bit, but the prevalence of JS-based static websites is hampering the search. I found this on PyPI: https://pypi.org/project/static_site_index/ but it looks fairly unmaintained and contains no documentation. (Fortunately, it appears small, so I will at least skim the code to see if it looks useful.) Surely this is a solved problem, hopefully in Python? Thx, Skip From cs at cskk.id.au Sat Jul 7 20:54:24 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 8 Jul 2018 10:54:24 +1000 Subject: Generate a static back-of-a-book style index? In-Reply-To: References: Message-ID: <20180708005424.GA24689@cskk.homeip.net> On 07Jul2018 18:24, Skip Montanaro wrote: >I just generated a static website which is nothing more than around >ten years of email messages from a defunct vintage bike mailing list >(170k messages, one per file). Though I've submitted the front page >URL to both Google and Bing, I was thinking that it would be handy to >have something like a static index such as you might find in the back >of a book. I poked around a bit, but the prevalence of JS-based static >websites is hampering the search. I found this on PyPI: > >https://pypi.org/project/static_site_index/ > >but it looks fairly unmaintained and contains no documentation. >(Fortunately, it appears small, so I will at least skim the code to >see if it looks useful.) > >Surely this is a solved problem, hopefully in Python? Have you looked at the ptx command? Might be called "gptx" on a system with the GNU coreutils installed with "g" prefixes. It does exactly this, and has done for decades :-) Cheers, Cameron Simpson From steve+comp.lang.python at pearwood.info Sat Jul 7 21:04:18 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 8 Jul 2018 01:04:18 +0000 (UTC) Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> Message-ID: On Sun, 08 Jul 2018 00:00:26 +0300, Marko Rauhamaa wrote: > Ian Kelly : >> the leaning of the devs seems to be to refrain from documenting it and >> instead document that *no* operations are guaranteed atomic. > > I believe that to be wise. Otherwise, Python would limit its future > implementation options. o_O By that logic, one should say we shouldn't document the semantics of operations, so we don't limit the implementation. "What does list.sort do?" "It currently sorts the list using a stable comparison sort, but you can't rely on that it, because we didn't want to limit the implementation." Sorting is guaranteed to be stable. Does that limit the implementation options? Yes, of course it does. So does the fact that it *sorts* -- we're limited to implementations which *sort*, and specifically comparison sorts (not, for example, radix sorts). Changing the implementation to a radix sort that only works on ints would break things. So would changing the implementation to something which empties the list of all elements. ("The empty list is always sorted.") Stable semantics are more important than freedom to change implementation. Whether or not an operation is thread-safe, or atomic, is part of the semantics of the operation. It's not merely a performance issue, and we ought to treat it will a bit more respect. I'm not saying that everything needs to be documented as thread-safe or not (for at least one release, Python's sorting actually was stable before it was documented as such) but the gung-ho attitude that safety is just an implementation detail should be resisted. Changing implementations from one which is thread safe to one which is not can break people's code, and shouldn't be done on a whim. Especially since such breakage could be subtle, hard to notice, harder to track down, and even harder still to fix. > The only thing Python should guarantee is that the data structures stay > "coherent" under race conditions. In other words, there cannot be a > segmentation fault. For example, if two threads executed this code in > parallel: > > global i > i = 1 > i += 1 > > a legal end result could be that i contains the string "impossible". That wouldn't be coherent. The only coherent results are that i could equal either 2 or 3: Possibility 1: i = 1 # thread 1 i += 1 # thread 1 i = 1 # thread 2 i += 1 # thread 2 assert i == 2 Possibility 2: i = 1 # thread 1 i = 1 # thread 2 i += 1 # thread 1 i += 1 # thread 2 assert i == 3 Executing statements out of order is impossible, even in threaded code. Redefining the meaning of the integer literal 1 is impossible (ignoring unsupported shenanigans with ctypes). Monkey-patching the int __iadd__ method is impossible. So there is no coherent way to get a result of "impossible" from just adding 1 to 1 in any coherent implementation of Python. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From skip.montanaro at gmail.com Sat Jul 7 21:11:51 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 7 Jul 2018 20:11:51 -0500 Subject: Generate a static back-of-a-book style index? In-Reply-To: <20180708005424.GA24689@cskk.homeip.net> References: <20180708005424.GA24689@cskk.homeip.net> Message-ID: > Have you looked at the ptx command? Might be called "gptx" on a system with the > GNU coreutils installed with "g" prefixes. Thanks, Cameron. I was unaware of it. Will check it out. Skip From john_ladasky at sbcglobal.net Sat Jul 7 21:12:17 2018 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Sat, 7 Jul 2018 18:12:17 -0700 (PDT) Subject: Matplotlib 3D limitations, please recommend alternative In-Reply-To: <412cf005-18e8-4b03-94f4-c596c5de5caf@googlegroups.com> References: <940a73c7-b232-44ae-b4c0-3b962fb538ee@googlegroups.com> <38E2621C-0385-4845-907B-392B0AB0BA2F@mac.com> <43f2ce36-6773-475d-bf9d-9e14f3bcf69a@googlegroups.com> <412cf005-18e8-4b03-94f4-c596c5de5caf@googlegroups.com> Message-ID: <05a8f05b-e655-4cc0-a214-32e6ce9f3351@googlegroups.com> On Saturday, July 7, 2018 at 6:36:16 AM UTC-7, Rick Johnson wrote: > John Ladasky wrote: > > > Back then I wrote: > > > > "I have concluded that Qt, PyQt, and OpenGL are all > > rapidly-evolving, and huge, software packages. There may > > be compatibility problems, and relevant examples with the > > right software combination may be hard to find. Two weeks > > of searching web pages hasn't turned up a single example > > which demonstrates PyQt5 doing something simple in 3D with > > OpenGL that I can study." > > PyQT is not the only GUI toolkit with OpenGL support, you > know. I would suggest you have a look at the alternatives. I'm fully aware of that. I have tried a few Python GUIs, and I have the most experience with PyQt5. It is not necessary for me to integrate my current 3D graphics project with PyQt5, but it would be nice. From rosuav at gmail.com Sat Jul 7 21:15:17 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Jul 2018 11:15:17 +1000 Subject: Thread-safe way to add a key to a dict only if it isn't already there? In-Reply-To: References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 8, 2018 at 11:04 AM, Steven D'Aprano wrote: >> The only thing Python should guarantee is that the data structures stay >> "coherent" under race conditions. In other words, there cannot be a >> segmentation fault. For example, if two threads executed this code in >> parallel: >> >> global i >> i = 1 >> i += 1 >> >> a legal end result could be that i contains the string "impossible". > > That wouldn't be coherent. The only coherent results are that i could > equal either 2 or 3: > > Possibility 1: > > i = 1 # thread 1 > i += 1 # thread 1 > i = 1 # thread 2 > i += 1 # thread 2 > assert i == 2 > > Possibility 2: > > i = 1 # thread 1 > i = 1 # thread 2 > i += 1 # thread 1 > i += 1 # thread 2 > assert i == 3 > > > Executing statements out of order is impossible, even in threaded code. > Redefining the meaning of the integer literal 1 is impossible (ignoring > unsupported shenanigans with ctypes). Monkey-patching the int __iadd__ > method is impossible. So there is no coherent way to get a result of > "impossible" from just adding 1 to 1 in any coherent implementation of > Python. Python threads don't switch only between lines of code, so the actual interaction is a bit more complicated than you say. In CPython, the increment operation is: 3 0 LOAD_GLOBAL 0 (i) 2 LOAD_CONST 1 (1) 4 INPLACE_ADD 6 STORE_GLOBAL 0 (i) A context switch could happen between any pair of statements. In this particular example, the end result doesn't change - coherent results are 2 and 3, nothing else - but in other situations, there may be times when the separate steps might be significant. For instance, if you replace "i += 1" with "i += i", to double the value, you'll get this: 3 0 LOAD_GLOBAL 0 (i) 2 LOAD_GLOBAL 0 (i) 4 INPLACE_ADD 6 STORE_GLOBAL 0 (i) and that could potentially have both of them load the initial value, then one of them runs to completion, and then the other loads the result - so it'll add 1 and 2 and have a result of 3, rather than 2 or 4. But you're absolutely right that there are only a small handful of plausible results, even with threading involved. ChrisA From cs at cskk.id.au Sat Jul 7 22:12:20 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 8 Jul 2018 12:12:20 +1000 Subject: Generate a static back-of-a-book style index? In-Reply-To: References: Message-ID: <20180708021220.GA39351@cskk.homeip.net> On 07Jul2018 20:11, Skip Montanaro wrote: >> Have you looked at the ptx command? Might be called "gptx" on a system with the >> GNU coreutils installed with "g" prefixes. > >Thanks, Cameron. I was unaware of it. Will check it out. BTW, it well predates the GNU coreutils; I used it on V7 UNIX. Nicely, it includes the surrounding words in the index output for context, makes for a far more usable index listing. You may need to postprocess the output to fit your needs. Cheers, Cameron Simpson From steve+comp.lang.python at pearwood.info Sat Jul 7 22:12:47 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 8 Jul 2018 02:12:47 +0000 (UTC) Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> Message-ID: On Sun, 08 Jul 2018 11:15:17 +1000, Chris Angelico wrote: [...] > Python threads don't switch only between lines of code, As I understand it, there could be a switch between any two byte codes, or maybe only between certain bytes codes. But certain more fine grained than just between lines of code. > so the actual > interaction is a bit more complicated than you say. In CPython, the > increment operation is: > > 3 0 LOAD_GLOBAL 0 (i) > 2 LOAD_CONST 1 (1) > 4 INPLACE_ADD > 6 STORE_GLOBAL 0 (i) > > A context switch could happen between any pair of statements. If you actually mean *statements* as opposed to byte codes, then the only place there could be a switch would be either before the LOAD_GLOBAL or after the STORE_GLOBAL (given that i is a built-in int and cannot have a custom __iadd__ method). Is that what you mean? > In this > particular example, the end result doesn't change - coherent results are > 2 and 3, nothing else - but in other situations, there may be times when > the separate steps might be significant. Fortunately I wasn't talking about other code snippets, only the one shown :-) > For instance, if you replace "i > += 1" with "i += i", to double the value, you'll get this: > > 3 0 LOAD_GLOBAL 0 (i) > 2 LOAD_GLOBAL 0 (i) > 4 INPLACE_ADD > 6 STORE_GLOBAL 0 (i) > > and that could potentially have both of them load the initial value, > then one of them runs to completion, and then the other loads the result > - so it'll add 1 and 2 and have a result of 3, rather than 2 or 4. Some people, when confronted with a problem, say, "I know, I'll use threads". Nothhtwo probw ey ave lems. > But you're absolutely right that there are only a small handful of > plausible results, even with threading involved. Indeed. Even though threading is non-deterministic, it isn't *entirely* unconstrained. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sat Jul 7 22:23:41 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Jul 2018 12:23:41 +1000 Subject: Thread-safe way to add a key to a dict only if it isn't already there? In-Reply-To: References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 8, 2018 at 12:12 PM, Steven D'Aprano wrote: > On Sun, 08 Jul 2018 11:15:17 +1000, Chris Angelico wrote: > > [...] >> Python threads don't switch only between lines of code, > > As I understand it, there could be a switch between any two byte codes, > or maybe only between certain bytes codes. But certain more fine grained > than just between lines of code. > > >> so the actual >> interaction is a bit more complicated than you say. In CPython, the >> increment operation is: >> >> 3 0 LOAD_GLOBAL 0 (i) >> 2 LOAD_CONST 1 (1) >> 4 INPLACE_ADD >> 6 STORE_GLOBAL 0 (i) >> >> A context switch could happen between any pair of statements. > > If you actually mean *statements* as opposed to byte codes, then the only > place there could be a switch would be either before the LOAD_GLOBAL or > after the STORE_GLOBAL (given that i is a built-in int and cannot have a > custom __iadd__ method). > > Is that what you mean? I may be wrong, but I always assume that a context switch could happen between any two bytecode operations - or, if you're reading the disassembly, between any two lines *of disassembly*. So there could be a switch before LOAD_GLOBAL, a switch between that and LOAD_CONST, another switch before the ADD, another before the STORE, and another right at the end. Well, there won't be *all* of those, but there could be any of them. This might not be entirely correct - there might be pairs that are functionally atomic - but it's the safe assumption. >> For instance, if you replace "i >> += 1" with "i += i", to double the value, you'll get this: >> >> 3 0 LOAD_GLOBAL 0 (i) >> 2 LOAD_GLOBAL 0 (i) >> 4 INPLACE_ADD >> 6 STORE_GLOBAL 0 (i) >> >> and that could potentially have both of them load the initial value, >> then one of them runs to completion, and then the other loads the result >> - so it'll add 1 and 2 and have a result of 3, rather than 2 or 4. > > Some people, when confronted with a problem, say, "I know, I'll use > threads". Nothhtwo probw ey ave lems. Right. Now they have to deal with interleaving, but that's all. And honestly, MOST CODE wouldn't notice interleaving; it's only when you change (either by rebinding or by mutating) something that can be seen by multiple threads. Which basically means "mutable globals are a risk, pretty much everything else is safe". >> But you're absolutely right that there are only a small handful of >> plausible results, even with threading involved. > > Indeed. Even though threading is non-deterministic, it isn't *entirely* > unconstrained. > Yeah. Quite far from it, in fact. Python threading is well-defined and fairly easy to work with. Only in a handful of operations do you need to worry about atomicity - like the one that started this thread. ChrisA From python.list at tim.thechases.com Sat Jul 7 22:57:07 2018 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 7 Jul 2018 21:57:07 -0500 Subject: Generate a static back-of-a-book style index? In-Reply-To: <20180708021220.GA39351@cskk.homeip.net> References: <20180708021220.GA39351@cskk.homeip.net> Message-ID: <20180707215707.2f998629@bigbox.christie.dr> On 2018-07-08 12:12, Cameron Simpson wrote: > On 07Jul2018 20:11, Skip Montanaro wrote: > >> Have you looked at the ptx command? Might be called "gptx" > > > >Thanks, Cameron. I was unaware of it. Will check it out. > > BTW, it well predates the GNU coreutils; I used it on V7 UNIX. Interesting. Despite your V7-provenance claim, it doesn't seem to have persisted into either the FreeBSD boxes or the OpenBSD boxes I have at hand. Bringing in anything that involves GNU coreutils adds it to the machine in question, but just kinda odd that those with a tighter tie to "real" Unix would have dropped it. Off to go read `man gptx` now... -tkc From cs at cskk.id.au Sat Jul 7 23:34:29 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 8 Jul 2018 13:34:29 +1000 Subject: Generate a static back-of-a-book style index? In-Reply-To: <20180707215707.2f998629@bigbox.christie.dr> References: <20180707215707.2f998629@bigbox.christie.dr> Message-ID: <20180708033429.GA74847@cskk.homeip.net> On 07Jul2018 21:57, Tim Chase wrote: >On 2018-07-08 12:12, Cameron Simpson wrote: >> On 07Jul2018 20:11, Skip Montanaro wrote: >> >> Have you looked at the ptx command? Might be called "gptx" >> > >> >Thanks, Cameron. I was unaware of it. Will check it out. >> >> BTW, it well predates the GNU coreutils; I used it on V7 UNIX. > >Interesting. Despite your V7-provenance claim, it doesn't seem to >have persisted into either the FreeBSD boxes or the OpenBSD boxes I >have at hand. Bringing in anything that involves GNU coreutils adds >it to the machine in question, but just kinda odd that those with a >tighter tie to "real" Unix would have dropped it. It's associated with the troff stuff generally. Maybe that's not installed? >Off to go read `man gptx` now... Or "man ptx", depends on your system and its install. Cheers, Cameron Simpson From steve+comp.lang.python at pearwood.info Sat Jul 7 23:58:14 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 8 Jul 2018 03:58:14 +0000 (UTC) Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> Message-ID: On Sun, 08 Jul 2018 12:23:41 +1000, Chris Angelico wrote: >> Some people, when confronted with a problem, say, "I know, I'll use >> threads". Nothhtwo probw ey ave lems. > > Right. Now they have to deal with interleaving, but that's all. And > honestly, MOST CODE wouldn't notice interleaving; it's only when you > change (either by rebinding or by mutating) something that can be seen > by multiple threads. Which basically means "mutable globals are a risk, > pretty much everything else is safe". Its not just globals though. Any mutable object shared between two threads is potentially a risk. Globals are just the most obvious example. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sun Jul 8 00:03:38 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 8 Jul 2018 14:03:38 +1000 Subject: Thread-safe way to add a key to a dict only if it isn't already there? In-Reply-To: References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 8, 2018 at 1:58 PM, Steven D'Aprano wrote: > On Sun, 08 Jul 2018 12:23:41 +1000, Chris Angelico wrote: > >>> Some people, when confronted with a problem, say, "I know, I'll use >>> threads". Nothhtwo probw ey ave lems. >> >> Right. Now they have to deal with interleaving, but that's all. And >> honestly, MOST CODE wouldn't notice interleaving; it's only when you >> change (either by rebinding or by mutating) something that can be seen >> by multiple threads. Which basically means "mutable globals are a risk, >> pretty much everything else is safe". > > Its not just globals though. Any mutable object shared between two > threads is potentially a risk. Globals are just the most obvious example. > Right; by "basically" I mean "yes there are others but this is what matters". The technically-accurate part is in the previous sentence: "can be seen by multiple threads". ChrisA From sharan.basappa at gmail.com Sun Jul 8 00:21:57 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 7 Jul 2018 21:21:57 -0700 (PDT) Subject: testing code In-Reply-To: References: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> <13e03c7f-6665-48c0-bf73-3d1ee46733e9@googlegroups.com> Message-ID: <90134431-b704-425a-8938-d32e864e92e7@googlegroups.com> On Saturday, 7 July 2018 18:22:23 UTC+5:30, Chris Angelico wrote: > On Sat, Jul 7, 2018 at 10:02 PM, Sharan Basappa > wrote: > > On Friday, 6 July 2018 09:22:31 UTC+5:30, Chris Angelico wrote: > >> On Fri, Jul 6, 2018 at 12:56 PM, Sharan Basappa > >> wrote: > >> > Please let me know if the following understanding of mine is correct. > >> > I need to put the program code in a separate file and organize every executable code in some form of function. If any code exists outside of function then it is not executable by importing. > >> > > >> > >> Kinda. It's actually the other way around: if any code exists outside > >> of functions, it will be executed immediately when you import. So > >> you're correct in that it would be hard (maybe impossible) to > >> unit-test that; and yes, the normal way to do it is to put all your > >> important code into functions. > >> > >> ChrisA > > > > Chris, > > > > Things do work as per expected with one exception. > > You mentioned that as soon as a file is imported, it executes immediately. > > > > Please see the example below: > > > > file: test_2.py > > > > x = 10 > > y = 20 > > > > c = x-y > > > > print c > > > > def func1(): > > return x+y > > > > test_2_test.py > > > > x = 10 > > y = 20 > > > > c = x-y > > > > print c > > > > def func1(): > > return x+y > > > > this is the output: > > %run "D:/Projects/Initiatives/machine learning/programs/test_2_test.py" > > 30 > > > > As you can see, print c in test_2 file was not executed upon import as there is no corresponding output > > I don't think you import your other module anywhere. > > ChrisA sorry. there was a copy paste error when i posted. I pasted test_2.py for both the files: here are the files again. The issue remains. test_2.py: x = 10 y = 20 c = x-y print c def func1(): return x+y test_2_test.py: import test_2 x = test_2.func1() print x output: %run "D:/Projects/Initiatives/machine learning/programs/test_2_test.py" 30 From jlee54 at gmail.com Sun Jul 8 02:22:21 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sat, 7 Jul 2018 23:22:21 -0700 Subject: testing code In-Reply-To: <90134431-b704-425a-8938-d32e864e92e7@googlegroups.com> References: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> <13e03c7f-6665-48c0-bf73-3d1ee46733e9@googlegroups.com> <90134431-b704-425a-8938-d32e864e92e7@googlegroups.com> Message-ID: <5b34857d-36ac-db02-e44a-8a5fcec70e0b@gmail.com> On 07/07/18 21:21, Sharan Basappa wrote: > > sorry. there was a copy paste error when i posted. I pasted test_2.py for both the files: > > here are the files again. The issue remains. > [...] > > output: > %run "D:/Projects/Initiatives/machine learning/programs/test_2_test.py" > 30 [11:24 PM jlee at kerndev ~] $cat test_2.py x = 10 y = 20 c = x-y print c def func1(): ??? return x+y [11:24 PM jlee at kerndev ~] $cat test_2_test.py import test_2 x = test_2.func1() print x [11:24 PM jlee at kerndev ~] $python test_2_test.py -10 30 [11:24 PM jlee at kerndev ~] $ As you can see, the? code from the import is indeed executed by the python interpreter. I'm not familiar with the "%run" prefix in your command - some sort of windows-ism? -Jim From sharan.basappa at gmail.com Sun Jul 8 03:04:17 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 8 Jul 2018 00:04:17 -0700 (PDT) Subject: testing code In-Reply-To: References: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> <13e03c7f-6665-48c0-bf73-3d1ee46733e9@googlegroups.com> <90134431-b704-425a-8938-d32e864e92e7@googlegroups.com> <5b34857d-36ac-db02-e44a-8a5fcec70e0b@gmail.com> Message-ID: On Sunday, 8 July 2018 11:52:39 UTC+5:30, Jim Lee wrote: > On 07/07/18 21:21, Sharan Basappa wrote: > > > > sorry. there was a copy paste error when i posted. I pasted test_2.py for both the files: > > > > here are the files again. The issue remains. > > [...] > > > > output: > > %run "D:/Projects/Initiatives/machine learning/programs/test_2_test.py" > > 30 > > [11:24 PM jlee at kerndev ~] $cat test_2.py > x = 10 > y = 20 > > c = x-y > > print c > > def func1(): > ??? return x+y > > [11:24 PM jlee at kerndev ~] $cat test_2_test.py > import test_2 > > x = test_2.func1() > print x > [11:24 PM jlee at kerndev ~] $python test_2_test.py > -10 > 30 > [11:24 PM jlee at kerndev ~] $ > > > As you can see, the? code from the import is indeed executed by the > python interpreter. > > I'm not familiar with the "%run" prefix in your command - some sort of > windows-ism? > > -Jim i think I figured out the issue. I am running this in Canopy. When I use Canopy Gui to run this, it appears that it loads the imported file only once. So, when I re-start canopy then everything goes fine the first time. When I use command prompt then it works all well. PS: run is nothing but the front end command that Canopy uses to run Python in the background. From auriocus at gmx.de Sun Jul 8 03:11:56 2018 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 8 Jul 2018 09:11:56 +0200 Subject: testing code In-Reply-To: <90134431-b704-425a-8938-d32e864e92e7@googlegroups.com> References: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> <13e03c7f-6665-48c0-bf73-3d1ee46733e9@googlegroups.com> <90134431-b704-425a-8938-d32e864e92e7@googlegroups.com> Message-ID: Am 08.07.18 um 06:21 schrieb Sharan Basappa: > sorry. there was a copy paste error when i posted. I pasted test_2.py for both the files: > > here are the files again. The issue remains. > output: > %run "D:/Projects/Initiatives/machine learning/programs/test_2_test.py" > 30 > Jim spotted it... '%run' is in IPython, right? "import" statements are executed only once for a given module (that's the purpose) - you have probably modified your imported file, and not restarted the interpreter. The second time you then import it, nothing happens. If you restart your interpreter, you should see both lines printed. Christian From marko at pacujo.net Sun Jul 8 03:52:15 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Jul 2018 10:52:15 +0300 Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> Message-ID: <87pnzy88r4.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Jul 8, 2018 at 11:04 AM, Steven D'Aprano > wrote: >>> The only thing Python should guarantee is that the data structures stay >>> "coherent" under race conditions. In other words, there cannot be a >>> segmentation fault. For example, if two threads executed this code in >>> parallel: >>> >>> global i >>> i = 1 >>> i += 1 >>> >>> a legal end result could be that i contains the string "impossible". >> >> That wouldn't be coherent. The only coherent results are that i could >> equal either 2 or 3: > > Python threads don't switch only between lines of code, so the actual > interaction is a bit more complicated than you say. [...] > > But you're absolutely right that there are only a small handful of > plausible results, even with threading involved. You are on the right track, Chris, but you are still deducing behavior from a particular implementation. For example Java's definition is approximately the one I give above: Without correct synchronization, very strange, confusing and counterintuitive behaviors are possible. And we know that Python has been implemented using Java... Marko From arj.python at gmail.com Sun Jul 8 06:11:20 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 8 Jul 2018 14:11:20 +0400 Subject: about main() In-Reply-To: References: Message-ID: i appreciate every suggestions though ^^_ Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Ahh, yes. The elegant purity of reading every email that goes through > this mailing list, or the practicality of killfiling people who can't > be bothered to use correct grammar in English, and probably are > comparably sloppy in their code. It's a very important decision to > make. > > ChrisA > From arj.python at gmail.com Sun Jul 8 06:48:58 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 8 Jul 2018 14:48:58 +0400 Subject: about main() In-Reply-To: References: Message-ID: non native speakers try to do their best as for ... who can't be bothered to use correct grammar in English, and probably are comparably sloppy in their code. ... maybe but check INADA NAOKI Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ or the practicality of killfiling people who can't > be bothered to use correct grammar in English, and probably are comparably sloppy in their code. It's a very important decision to > make. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From steve+comp.lang.python at pearwood.info Sun Jul 8 06:50:12 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 8 Jul 2018 10:50:12 +0000 (UTC) Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> <87pnzy88r4.fsf@elektro.pacujo.net> Message-ID: On Sun, 08 Jul 2018 10:52:15 +0300, Marko Rauhamaa wrote: > You are on the right track, Chris, but you are still deducing behavior > from a particular implementation. For example Java's definition is > approximately the one I give above: > > Without correct synchronization, very strange, confusing and > counterintuitive behaviors are possible. Indeed, and that applies to all languages with threading, including Python. But notice that it doesn't say: Without correct synchronization, impossible things are possible. > l#jls-17.4.5> You seem to have read this as "Java threading can do impossible things", but I think the correct reading of the article is "Here are the possible things that Java threading can do to mess with your mind". That's a much smaller subset of things which can go wrong. (But still pretty big.) See, for example Example 17.4-1, which explicitly shows that the Java execution model is permitted to reorder statements: r1 = A; B = 1; may be reordered to B = 1; r1 = A; That's harmless in single-threaded code, but risky in multi-threaded code. The result is that in the example given, r1 could end up being set to 1 instead of the expected values -- but it cannot possibly be set to the string "impossible", since that goes against the Java type system. In Python, there's no possible order of operations of assigning 1 and adding 1 that could result in a string. No Python compiler or interpreter is permitted to evaluate `1 + 1` or `2 + 1` as the string "impossible", even if threads are involved. (That's not to say that threads might not assign a string to the variable we expected to contain 2, but it would have to do so by assignment, not by mucking about with the execution order of integer addition.) In the case of Example 17.4-1, starting with A = B = 0, two threads execute: Thread 1: r2 = A; B = 1; Thread 2: r1 = B; A = 2; Java compilers are permitted to inspect each thread *in isolation*, decide that the order of lines is invisible to the caller, and so re- order them. The result of that is that those four lines can be executed in any permutation, giving a total of 24 separate possibilities. py> from itertools import permutations py> instructions = ["r2 = A;", "B = 1;", "r1 = B;", "A = 2;"] py> len(list(permutations(instructions))) 24 But Python (at least for now) cannot do this. It has a more deterministic execution order which guarantees top-to-bottom execution of Python statements. That implies that there are only *six* possible execution orders of those two threads (which is still enough to add non-determinism to your code!) not twenty-four: r2 = A; B = 1; r1 = B; A = 2; r2 = A; r1 = B; B = 1; A = 2; r2 = A; r1 = B; A = 2; B = 1; r1 = B; A = 2; r2 = A; B = 1; r1 = B; r2 = A; A = 2; B = 1; r1 = B; r2 = A; A = 2; B = 1; and that remains true even if the underlying implementation is written in Java, or Malbolge for that matter. > And we know that Python has been implemented using Java... That's irrelevant. A legal Python does not inherit the quirks of the underlying implementation -- it must still follow the rules of the language, or it isn't Python. Java is statically typed, with machine ints, Python is dynamically typed, with no machine ints. Relevant: http://doc.pypy.org/en/latest/cpython_differences.html http://docs.micropython.org/en/latest/unix/genrst/index.html -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From marko at pacujo.net Sun Jul 8 07:11:58 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Jul 2018 14:11:58 +0300 Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> Message-ID: <87h8la7zi9.fsf@elektro.pacujo.net> Steven D'Aprano : > Changing implementations from one which is thread safe to one which is > not can break people's code, and shouldn't be done on a whim. > Especially since such breakage could be subtle, hard to notice, harder > to track down, and even harder still to fix. Java's HotSpot does it all the time, and it did result in code breakage -- although the code was broken to begin with. > So there is no coherent way to get a result of "impossible" from just > adding 1 to 1 in any coherent implementation of Python. Back to Java, there was a real case of 64-bit integer operations not being atomic on 32-bit machines. Mixing up upper and lower halves between threads could result in really weird evaluations. More importantly, this loop may never finish: # Initially quit = False # Thread 1 global quit while not quit: time.sleep(1) # Thread 2 global quit quit = True That's the reality in Java and C. I see no reason why that wouldn't be the reality in Python as well -- unless the language specification said otherwise. Marko PS My example with "impossible" being the result of a racy integer operation is of course unlikely but could be the outcome if the Python runtime reorganized its object cache on the fly (in a hypothetical implementation). From python.list at tim.thechases.com Sun Jul 8 07:47:50 2018 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 8 Jul 2018 06:47:50 -0500 Subject: Generate a static back-of-a-book style index? In-Reply-To: <20180708033429.GA74847@cskk.homeip.net> References: <20180707215707.2f998629@bigbox.christie.dr> <20180708033429.GA74847@cskk.homeip.net> Message-ID: <20180708064750.7a05c793@bigbox.christie.dr> On 2018-07-08 13:34, Cameron Simpson wrote: > On 07Jul2018 21:57, Tim Chase wrote: > >On 2018-07-08 12:12, Cameron Simpson wrote: > >> On 07Jul2018 20:11, Skip Montanaro > >> wrote: > >> >> Have you looked at the ptx command? Might be called "gptx" > > It's associated with the troff stuff generally. Maybe that's not > installed? On my OpenBSD (6.3) boxes, there's no nroff/troff/groff nor any ptx/gptx. On my FreeBSD (11.2) boxes, I have nroff/troff/groff available but no ptx/gptx available in base. One of the machines has coreutils installed which provides /usr/local/bin/gptx (and its man-pages). So I can find it and read about it. Just curious that it's fallen out of base on both Free & OpenBSD (don't have a NetBSD machine at hand to test that). -tkc From sharan.basappa at gmail.com Sun Jul 8 08:32:31 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 8 Jul 2018 05:32:31 -0700 (PDT) Subject: testing code In-Reply-To: References: <7c370747-6a18-4ee7-b9f5-8301f5f2b4c6@googlegroups.com> <13e03c7f-6665-48c0-bf73-3d1ee46733e9@googlegroups.com> <90134431-b704-425a-8938-d32e864e92e7@googlegroups.com> Message-ID: On Sunday, 8 July 2018 12:42:07 UTC+5:30, Christian Gollwitzer wrote: > Am 08.07.18 um 06:21 schrieb Sharan Basappa: > > sorry. there was a copy paste error when i posted. I pasted test_2.py for both the files: > > > > here are the files again. The issue remains. > > > output: > > %run "D:/Projects/Initiatives/machine learning/programs/test_2_test.py" > > 30 > > > > Jim spotted it... '%run' is in IPython, right? "import" statements are > executed only once for a given module (that's the purpose) - you have > probably modified your imported file, and not restarted the interpreter. > The second time you then import it, nothing happens. > > If you restart your interpreter, you should see both lines printed. > > Christian yes, exactly. this is the issue although execution is in Canopy and not in iPython From steve+comp.lang.python at pearwood.info Sun Jul 8 09:38:17 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 8 Jul 2018 13:38:17 +0000 (UTC) Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> <87h8la7zi9.fsf@elektro.pacujo.net> Message-ID: On Sun, 08 Jul 2018 14:11:58 +0300, Marko Rauhamaa wrote: > Steven D'Aprano : >> Changing implementations from one which is thread safe to one which is >> not can break people's code, and shouldn't be done on a whim. >> Especially since such breakage could be subtle, hard to notice, harder >> to track down, and even harder still to fix. > > Java's HotSpot does it all the time, and it did result in code breakage > -- although the code was broken to begin with. I said "shouldn't be done", rather than claiming that was the situation right now with all compilers. But I'm willing to give a little bit of slack to aggressively optimizing compilers, provided they come with a warning. >> So there is no coherent way to get a result of "impossible" from just >> adding 1 to 1 in any coherent implementation of Python. > > Back to Java, there was a real case of 64-bit integer operations not > being atomic on 32-bit machines. Mixing up upper and lower halves > between threads could result in really weird evaluations. Oh don't get me wrong, I agree with you that threading can result in strange, unpredictable errors. That's why I try not to use threading. I have no illusions about my ability to debug those sorts of problems. > More importantly, this loop may never finish: > > # Initially > quit = False > > # Thread 1 > global quit > while not quit: > time.sleep(1) > > # Thread 2 > global quit > quit = True Assuming that thread 2 actually runs *at some point*, I don't see how that can't terminate. Neither thread sets quit to False, so provided thread 2 runs at all, it has to terminate. I suppose if the threading implementation *could* fall back to sequential code (thread 2 doesn't run until thread 1 finishes, which it never does...) that outcome is possible. But it would have to be a pretty poor implementation. Now if you said there were fifty threads (aside from the main thread, which is guaranteed to run) all reading quit, and only thread 50 ever assigns to it, I'd believe that perhaps thread 50 never gets a chance to run. But with just two threads? Explain please. > That's the reality in Java and C. I see no reason why that wouldn't be > the reality in Python as well -- unless the language specification said > otherwise. Because the Python core developers care more about correctness than speed. > Marko > > PS My example with "impossible" being the result of a racy integer > operation is of course unlikely but could be the outcome if the Python > runtime reorganized its object cache on the fly (in a hypothetical > implementation). That would be a cache bug :-) Not every interpreter bug should be considered the caller's fault :-) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From python at mrabarnett.plus.com Sun Jul 8 11:37:11 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 8 Jul 2018 16:37:11 +0100 Subject: Thread-safe way to add a key to a dict only if it isn't already there? In-Reply-To: References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> <87h8la7zi9.fsf@elektro.pacujo.net> Message-ID: On 2018-07-08 14:38, Steven D'Aprano wrote: > On Sun, 08 Jul 2018 14:11:58 +0300, Marko Rauhamaa wrote: > [snip] >> More importantly, this loop may never finish: >> >> # Initially >> quit = False >> >> # Thread 1 >> global quit >> while not quit: >> time.sleep(1) >> >> # Thread 2 >> global quit >> quit = True > > Assuming that thread 2 actually runs *at some point*, I don't see how > that can't terminate. Neither thread sets quit to False, so provided > thread 2 runs at all, it has to terminate. > [snip] The compiler could look at the code for thread 1 and see that 'quit' is never assigned to, meaning that it could be "optimised" to: global quit if not quit: while True: time.sleep(1) In C you'd declare 'quit' as 'volatile' to tell the compiler that it could change unexpectedly, so don't make that assumption. From marko at pacujo.net Sun Jul 8 12:11:43 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Jul 2018 19:11:43 +0300 Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> <87h8la7zi9.fsf@elektro.pacujo.net> Message-ID: <87d0vx9074.fsf@elektro.pacujo.net> MRAB : > On 2018-07-08 14:38, Steven D'Aprano wrote: >> On Sun, 08 Jul 2018 14:11:58 +0300, Marko Rauhamaa wrote: >> > [snip] >>> More importantly, this loop may never finish: >>> >>> # Initially >>> quit = False >>> >>> # Thread 1 >>> global quit >>> while not quit: >>> time.sleep(1) >>> >>> # Thread 2 >>> global quit >>> quit = True >> >> Assuming that thread 2 actually runs *at some point*, I don't see how >> that can't terminate. Neither thread sets quit to False, so provided >> thread 2 runs at all, it has to terminate. >> > [snip] > > The compiler could look at the code for thread 1 and see that 'quit' is > never assigned to, meaning that it could be "optimised" to: > > global quit > if not quit: > while True: > time.sleep(1) > > In C you'd declare 'quit' as 'volatile' to tell the compiler that it > could change unexpectedly, so don't make that assumption. C is an even tougher case. Even if the compiler kept on checking a volatile value, the CPU might never propagate the cache content to the other core. You'd need a memory barrier. In Java, "volatile" effectively creates a memory barrier, but in C (and C++) it does not. In C you need something like a mutex to see the effects of other threads running. (BTW, I think that's a terrible thing for the C standards committee to specify.) Marko From marko at pacujo.net Sun Jul 8 12:35:55 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Jul 2018 19:35:55 +0300 Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> <87h8la7zi9.fsf@elektro.pacujo.net> Message-ID: <878t6l8z2s.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sun, 08 Jul 2018 14:11:58 +0300, Marko Rauhamaa wrote: >> PS My example with "impossible" being the result of a racy integer >> operation is of course unlikely but could be the outcome if the Python >> runtime reorganized its object cache on the fly (in a hypothetical >> implementation). > > That would be a cache bug :-) > > Not every interpreter bug should be considered the caller's fault :-) Whether it's a bug or not depends on the language specification. Java has a very clear definition for correct synchronization. It's not so clear on what could happen in the event of a data race; it's not entirely unspecified, but the language spec admonishes the application to brace itself for surprising effects. If the Python Language Specification hasn't specified the effects of incorrect synchronization so we can rightly suppose that the results are unspecified. Marko From ksprafull at gmail.com Sun Jul 8 12:43:59 2018 From: ksprafull at gmail.com (Prafull Ks) Date: Sun, 8 Jul 2018 22:13:59 +0530 Subject: Invalid error in python program Message-ID: I miss studying in class 11 cbse.College as introduced us python. I installed it in my laptop but when I save and runed in idle mod. The 3.7.0 the 7 is highlighted and syntax error is showen. As showen in the screen shot below. Plz help me resolve this problem Ur faithful user Prafull. Thank you From rosuav at gmail.com Sun Jul 8 12:50:10 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Jul 2018 02:50:10 +1000 Subject: Thread-safe way to add a key to a dict only if it isn't already there? In-Reply-To: <87d0vx9074.fsf@elektro.pacujo.net> References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> <87h8la7zi9.fsf@elektro.pacujo.net> <87d0vx9074.fsf@elektro.pacujo.net> Message-ID: On Mon, Jul 9, 2018 at 2:11 AM, Marko Rauhamaa wrote: > MRAB : >> On 2018-07-08 14:38, Steven D'Aprano wrote: >>> On Sun, 08 Jul 2018 14:11:58 +0300, Marko Rauhamaa wrote: >>> >> [snip] >>>> More importantly, this loop may never finish: >>>> >>>> # Initially >>>> quit = False >>>> >>>> # Thread 1 >>>> global quit >>>> while not quit: >>>> time.sleep(1) >>>> >>>> # Thread 2 >>>> global quit >>>> quit = True >>> >>> Assuming that thread 2 actually runs *at some point*, I don't see how >>> that can't terminate. Neither thread sets quit to False, so provided >>> thread 2 runs at all, it has to terminate. >>> >> [snip] >> >> The compiler could look at the code for thread 1 and see that 'quit' is >> never assigned to, meaning that it could be "optimised" to: >> >> global quit >> if not quit: >> while True: >> time.sleep(1) >> >> In C you'd declare 'quit' as 'volatile' to tell the compiler that it >> could change unexpectedly, so don't make that assumption. > > C is an even tougher case. Even if the compiler kept on checking a > volatile value, the CPU might never propagate the cache content to the > other core. You'd need a memory barrier. In Java, "volatile" effectively > creates a memory barrier, but in C (and C++) it does not. In C you need > something like a mutex to see the effects of other threads running. > > (BTW, I think that's a terrible thing for the C standards committee to > specify.) None of this has any impact on Python whatsoever. ChrisA From arj.python at gmail.com Sun Jul 8 12:56:19 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 8 Jul 2018 20:56:19 +0400 Subject: Invalid error in python program In-Reply-To: References: Message-ID: screenshots are not sent in this list, can you please copy paste th error or use paste bin? thanks ! Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ From tkadm30 at yandex.com Sun Jul 8 13:02:35 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Sun, 8 Jul 2018 13:02:35 -0400 Subject: Invalid error in python program In-Reply-To: References: Message-ID: <3e90d90a-b901-b221-004c-af662dc97327@yandex.com> I'm guessing you may need some help in english writing too! Anyways, I don't think anyone here may want to make your homeworks for you... Regards, Etienne Le 2018-07-08 ? 12:43, Prafull Ks a ?crit?: > I miss studying in class 11 cbse.College as introduced us python. I > installed it in my laptop but when I save and runed in idle mod. The 3.7.0 > the 7 is highlighted and syntax error is showen. As showen in the screen > shot below. > Plz help me resolve this problem > Ur faithful user Prafull. > Thank you > -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From steve+comp.lang.python at pearwood.info Sun Jul 8 13:10:28 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 8 Jul 2018 17:10:28 +0000 (UTC) Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> <87h8la7zi9.fsf@elektro.pacujo.net> <878t6l8z2s.fsf@elektro.pacujo.net> Message-ID: On Sun, 08 Jul 2018 19:35:55 +0300, Marko Rauhamaa wrote: > Steven D'Aprano : >> On Sun, 08 Jul 2018 14:11:58 +0300, Marko Rauhamaa wrote: >>> PS My example with "impossible" being the result of a racy integer >>> operation is of course unlikely but could be the outcome if the Python >>> runtime reorganized its object cache on the fly (in a hypothetical >>> implementation). >> >> That would be a cache bug :-) >> >> Not every interpreter bug should be considered the caller's fault :-) > > Whether it's a bug or not depends on the language specification. "It is true that if you turn the indicator on at the same time that you turn the windshield wipers on, the car will explode in an enormous fireball releasing sufficient poisonous gases to kill everyone in a fifteen block radius. But we never said that it was safe to turn the indicator and windshield wipers on at the same time, so it's not a bug, its operator error." Compiler writers and language designers need to stop hiding behind specifications. No other industry so routinely tries (and too often succeeds) in playing the "but we never said our product wouldn't set you on fire" card with so little justification. > Java > has a very clear definition for correct synchronization. It's not so > clear on what could happen in the event of a data race; it's not > entirely unspecified, but the language spec admonishes the application > to brace itself for surprising effects. Incorrect synchronisation is irrelevant in this example. If the object cache is *ever* in an invalid state, such that (as per your example) the literal 1 (an int) could be evaluated as "impossible" (a string), that is a bug in the object management. Threads or no threads. The only excuse would be if the caller directly messed with the cache in an unsupported fashion (say, with ctypes). Software needs "fit for purpose" laws and end-user warranties with teeth. If that means that the software industry spends the next thirty years fixing bugs instead of adding features, that's a good thing. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jul 8 14:20:16 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 8 Jul 2018 18:20:16 +0000 (UTC) Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> <87h8la7zi9.fsf@elektro.pacujo.net> Message-ID: On Sun, 08 Jul 2018 16:37:11 +0100, MRAB wrote: > On 2018-07-08 14:38, Steven D'Aprano wrote: >> On Sun, 08 Jul 2018 14:11:58 +0300, Marko Rauhamaa wrote: >> > [snip] >>> More importantly, this loop may never finish: >>> >>> # Initially >>> quit = False >>> >>> # Thread 1 >>> global quit >>> while not quit: >>> time.sleep(1) >>> >>> # Thread 2 >>> global quit >>> quit = True >> >> Assuming that thread 2 actually runs *at some point*, I don't see how >> that can't terminate. Neither thread sets quit to False, so provided >> thread 2 runs at all, it has to terminate. >> > [snip] > > The compiler could look at the code for thread 1 and see that 'quit' is > never assigned to, meaning that it could be "optimised" to: > > global quit > if not quit: > while True: > time.sleep(1) I'm glad you put "optimized" in scare quotes there, because any optimizer that did that to code that runs in a thread is buggy. The re-write has changed the semantics of the code. Of course a compiler "could" do anything. If it re-wrote the code to instead perform: while True: print(math.sin(random.random()+1) instead, we'd have no trouble recognising that the compiler has changed the semantics of our code to something we didn't write, and in just about every language apart from C, we would rightly call it a compiler bug. If I write "Do X", and the compiler instead executes "Do Y", that's a compiler bug. The compiler has one job: to take my source code and convert it to something which can be executed, and if it cannot do that faithfully, it is buggy. C is the special case: C programmers routinely blame *themselves* when the compiler changes "Do X" to "Do Y", because the standard says it is permitted to do anything it likes in the event of undefined behaviour. Talk about victims coming to rationalise their own abuse and identify with their abuser. W.A. Wulf might have been talking about C compilers when he wrote: "More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason ? including blind stupidity." > In C you'd declare 'quit' as 'volatile' to tell the compiler that it > could change unexpectedly, so don't make that assumption. You shouldn't need to tell the compiler to assume that the variable could change. In multi-threaded code, there's no justification for assuming the variable can't change unless you've done a whole-program analysis and can prove that *no* thread ever writes to that variable. Even in single-threaded code, I think that optimizations which change execution order are dubious. There's far too much opportunity for "it's not a bug, because the specification says we can deny it is a bug" faults. It's simply *bad engineering practice*. When engineers design a bridge or a road or a building, the builders have to faithfully follow the engineer's design, unless the design itself explicitly allows them to make substitutions. "The blueprints say these supporting pillars have to be filled with steel- reinforced concrete. How about we just fill them with empty cans instead, what could possibly go wrong?" http://shanghaiist.com/2016/02/08/taiwan_earthquake_building_collapse/ (Disclaimer: there seems to be some controversy over whether the cans were actually in supporting columns or not. But the point still stands.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From marko at pacujo.net Sun Jul 8 14:57:08 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Jul 2018 21:57:08 +0300 Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> <87h8la7zi9.fsf@elektro.pacujo.net> <87d0vx9074.fsf@elektro.pacujo.net> Message-ID: <8736wt8sjf.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Jul 9, 2018 at 2:11 AM, Marko Rauhamaa wrote: >> MRAB : >>> In C you'd declare 'quit' as 'volatile' to tell the compiler that it >>> could change unexpectedly, so don't make that assumption. >> >> C is an even tougher case. Even if the compiler kept on checking a >> volatile value, the CPU might never propagate the cache content to >> the other core. You'd need a memory barrier. In Java, "volatile" >> effectively creates a memory barrier, but in C (and C++) it does not. >> In C you need something like a mutex to see the effects of other >> threads running. >> >> (BTW, I think that's a terrible thing for the C standards committee to >> specify.) > > None of this has any impact on Python whatsoever. [citation needed] Marko From rosuav at gmail.com Sun Jul 8 15:05:18 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Jul 2018 05:05:18 +1000 Subject: Thread-safe way to add a key to a dict only if it isn't already there? In-Reply-To: <8736wt8sjf.fsf@elektro.pacujo.net> References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> <87h8la7zi9.fsf@elektro.pacujo.net> <87d0vx9074.fsf@elektro.pacujo.net> <8736wt8sjf.fsf@elektro.pacujo.net> Message-ID: On Mon, Jul 9, 2018 at 4:57 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Mon, Jul 9, 2018 at 2:11 AM, Marko Rauhamaa wrote: >>> MRAB : >>>> In C you'd declare 'quit' as 'volatile' to tell the compiler that it >>>> could change unexpectedly, so don't make that assumption. >>> >>> C is an even tougher case. Even if the compiler kept on checking a >>> volatile value, the CPU might never propagate the cache content to >>> the other core. You'd need a memory barrier. In Java, "volatile" >>> effectively creates a memory barrier, but in C (and C++) it does not. >>> In C you need something like a mutex to see the effects of other >>> threads running. >>> >>> (BTW, I think that's a terrible thing for the C standards committee to >>> specify.) >> >> None of this has any impact on Python whatsoever. > > [citation needed] > Why? You might as well say "in Blurple, all integers greater than 5 compare equal to each other, and it's possible to implement a Python interpreter in Blurple, therefore we can't trust integer comparisons in Python". It's ridiculous to consider. The languages are completely independent. Are you assuming that Python's semantics are defined by the semantics of one possible implementation language? ChrisA From marko at pacujo.net Sun Jul 8 15:18:20 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Jul 2018 22:18:20 +0300 Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> <87h8la7zi9.fsf@elektro.pacujo.net> <87d0vx9074.fsf@elektro.pacujo.net> <8736wt8sjf.fsf@elektro.pacujo.net> Message-ID: <87tvp97czn.fsf@elektro.pacujo.net> Chris Angelico : > Are you assuming that Python's semantics are defined by the semantics > of one possible implementation language? What are Python's semantics defined by? I've been using these: Unfortunately, neither spec says anything about the atomicity of dict.setdefault(). Therefore, the application programmer must assume it is not atomic. In fact, as brought up in this discussion, the consultation of object.__hash__() and object.__eq__() almost guarantee the *non*-atomicity of dict.setdefault(). Marko From rosuav at gmail.com Sun Jul 8 16:01:14 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Jul 2018 06:01:14 +1000 Subject: Thread-safe way to add a key to a dict only if it isn't already there? In-Reply-To: <87tvp97czn.fsf@elektro.pacujo.net> References: <87o9fj9n90.fsf@elektro.pacujo.net> <8736wuahhx.fsf@elektro.pacujo.net> <87h8la7zi9.fsf@elektro.pacujo.net> <87d0vx9074.fsf@elektro.pacujo.net> <8736wt8sjf.fsf@elektro.pacujo.net> <87tvp97czn.fsf@elektro.pacujo.net> Message-ID: On Mon, Jul 9, 2018 at 5:18 AM, Marko Rauhamaa wrote: > Chris Angelico : >> Are you assuming that Python's semantics are defined by the semantics >> of one possible implementation language? > > What are Python's semantics defined by? I've been using these: > > > > > > Unfortunately, neither spec says anything about the atomicity of > dict.setdefault(). > > Therefore, the application programmer must assume it is not atomic. In > fact, as brought up in this discussion, the consultation of > object.__hash__() and object.__eq__() almost guarantee the > *non*-atomicity of dict.setdefault(). If by "atomic" you mean that absolutely no context switch can occur during setdefault, then it probably isn't. But the point of an atomic query/update operation is that there are exactly two possibilities: 1) The key did not exist in the dictionary. It now does, with the provided default, which was returned. 2) The key did exist in the dictionary. The provided default is ignored, and the previous value is returned. Neither object.__hash__ nor object.__eq__ gives any way for this to be violated (unless you mess with the concept of "the key did exist in the dictionary" by breaking the definition of equality, but that's nothing to do with atomicity). Here's the definition of setdefault: setdefault(key, default=None, /) method of builtins.dict instance Insert key with a value of default if key is not in the dictionary. Return the value for key if key is in the dictionary, else default. Simple semantics. Straight-forward. Now, maybe there's a bug in some implementation whereby threads can violate this; but that would be a bug to be fixed, and nothing more. You should be able to assume that it will behave as stated. ChrisA From marko at pacujo.net Sun Jul 8 16:42:28 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 08 Jul 2018 23:42:28 +0300 Subject: Thread-safe way to add a key to a dict only if it isn't already there? References: <8736wuahhx.fsf@elektro.pacujo.net> <87h8la7zi9.fsf@elektro.pacujo.net> <87d0vx9074.fsf@elektro.pacujo.net> <8736wt8sjf.fsf@elektro.pacujo.net> <87tvp97czn.fsf@elektro.pacujo.net> Message-ID: <87in5p793f.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Jul 9, 2018 at 5:18 AM, Marko Rauhamaa wrote: >> Chris Angelico : >>> Are you assuming that Python's semantics are defined by the semantics >>> of one possible implementation language? >> >> What are Python's semantics defined by? I've been using these: >> >> >> >> >> >> Unfortunately, neither spec says anything about the atomicity of >> dict.setdefault(). >> >> Therefore, the application programmer must assume it is not atomic. In >> fact, as brought up in this discussion, the consultation of >> object.__hash__() and object.__eq__() almost guarantee the >> *non*-atomicity of dict.setdefault(). > > If by "atomic" you mean that absolutely no context switch can occur > during setdefault, then it probably isn't. But the point of an atomic > query/update operation is that there are exactly two possibilities: > > 1) The key did not exist in the dictionary. It now does, with the > provided default, which was returned. > 2) The key did exist in the dictionary. The provided default is > ignored, and the previous value is returned. This is a classic test-and-set race condition: # Initially assert "A" not in d # Thread 1 d.setdefault("A", 1) # Thread 2 d["A"] = 2 If dict.setdefault() is atomic, the end result in all timings must be: d["A"] == 2 However, if dict.setdefault() is not atomic, the end result may also be: d["A"] == 1 > Neither object.__hash__ nor object.__eq__ gives any way for this to be > violated (unless you mess with the concept of "the key did exist in > the dictionary" by breaking the definition of equality, but that's > nothing to do with atomicity). Here's the definition of setdefault: > > setdefault(key, default=None, /) method of builtins.dict instance > Insert key with a value of default if key is not in the dictionary. > > Return the value for key if key is in the dictionary, else default. > > Simple semantics. Straight-forward. Now, maybe there's a bug in some > implementation whereby threads can violate this; but that would be a > bug to be fixed, and nothing more. You should be able to assume that > it will behave as stated. Since atomicity is not guaranteed by the definition of the method, the application programmer must be prepared for the end result to be 1 (or even something completely different because the Language Specification doesn't say anything about the outcome of data races). Marko From cs at cskk.id.au Sun Jul 8 18:11:35 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 9 Jul 2018 08:11:35 +1000 Subject: Generate a static back-of-a-book style index? In-Reply-To: <20180708064750.7a05c793@bigbox.christie.dr> References: <20180708064750.7a05c793@bigbox.christie.dr> Message-ID: <20180708221135.GA2993@cskk.homeip.net> On 08Jul2018 06:47, Tim Chase wrote: >On 2018-07-08 13:34, Cameron Simpson wrote: >> On 07Jul2018 21:57, Tim Chase wrote: >> >On 2018-07-08 12:12, Cameron Simpson wrote: >> >> On 07Jul2018 20:11, Skip Montanaro >> >> wrote: >> >> >> Have you looked at the ptx command? Might be called "gptx" >> >> It's associated with the troff stuff generally. Maybe that's not >> installed? > >On my OpenBSD (6.3) boxes, there's no nroff/troff/groff nor any >ptx/gptx. > >On my FreeBSD (11.2) boxes, I have nroff/troff/groff available but no >ptx/gptx available in base. One of the machines has coreutils >installed which provides /usr/local/bin/gptx (and its man-pages). > >So I can find it and read about it. Just curious that it's fallen >out of base on both Free & OpenBSD (don't have a NetBSD machine at >hand to test that). I'm curious too. I haven't an explaination. Cheers, Cameron Simpson From steve+comp.lang.python at pearwood.info Sun Jul 8 20:00:05 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 9 Jul 2018 00:00:05 +0000 (UTC) Subject: Invalid error in python program References: <3e90d90a-b901-b221-004c-af662dc97327@yandex.com> Message-ID: On Sun, 08 Jul 2018 13:02:35 -0400, Etienne Robillard wrote: > I'm guessing you may need some help in english writing too! Now that's not fair. Not everyone is fluent in English and so long as they make a genuine attempt we should be kind enough to ignore minor spelling and grammatical errors. Like writing "make your homeworks" for "do your homework"... *wink* > Anyways, I don't think anyone here may want to make your homeworks for > you... Prafull is not asking for us to do his or her homework, but for help with basic syntax. That's allowed. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jul 8 20:02:06 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 9 Jul 2018 00:02:06 +0000 (UTC) Subject: Invalid error in python program References: Message-ID: On Sun, 08 Jul 2018 22:13:59 +0530, Prafull Ks wrote: > I miss studying in class 11 cbse.College as introduced us python. I > installed it in my laptop but when I save and runed in idle mod. The > 3.7.0 the 7 is highlighted and syntax error is showen. As showen in the > screen shot below. Unless you edit your code with Photoshop, please don't send screenshots. They make it hard for the blind and visually impaired, and make it difficult for us to copy and paste your code if we need to run it. Instead, always copy the relevant code and the FULL error message, and paste it directly in your message. Thank you. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sun Jul 8 20:11:11 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 9 Jul 2018 10:11:11 +1000 Subject: Invalid error in python program In-Reply-To: References: Message-ID: On Mon, Jul 9, 2018 at 10:02 AM, Steven D'Aprano wrote: > On Sun, 08 Jul 2018 22:13:59 +0530, Prafull Ks wrote: > >> I miss studying in class 11 cbse.College as introduced us python. I >> installed it in my laptop but when I save and runed in idle mod. The >> 3.7.0 the 7 is highlighted and syntax error is showen. As showen in the >> screen shot below. > > Unless you edit your code with Photoshop, please don't send screenshots. Obligatory XKCD: https://xkcd.com/1685/ ChrisA From Rebeccaallmy at outlook.com Mon Jul 9 04:14:04 2018 From: Rebeccaallmy at outlook.com (=?gb2312?B?wqwgvM7Q0g==?=) Date: Mon, 9 Jul 2018 08:14:04 +0000 Subject: =?gb2312?B?16q3ojogTm8gcGlwIGZvciBteSBQeXRob24gMy42LjUh?= In-Reply-To: References: Message-ID: ??? Windows 10 ????? ________________________________ ???: ? ?? ????: Tuesday, June 26, 2018 8:25:58 PM ???: python-list at python.org ??: No pip for my Python 3.6.5! Hi~ I am a beginner with Python. My computer is of Windows version. And I dowloaded the lastest version of python on the https://www.python.org/ . My book, Automate the Boring Stuff With Python, teaches me to install a third-party module with the command line: pip install send2trash (for example). But there comes the error message !!! What is going wrong? It makes no sense since my Python is 3.6.5 version. I doubt that my poor Python doesn?t have a pip. Please tell me why and help me!! From arj.python at gmail.com Mon Jul 9 08:50:28 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Mon, 9 Jul 2018 16:50:28 +0400 Subject: No pip for my Python 3.6.5! In-Reply-To: References: Message-ID: according to all probabilities you have pip, you just need to add pip to path go to environment variables -> path then add ; Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ On Mon, 9 Jul 2018, 16:14 ? ??, wrote: > > > ??? Windows 10 ????? > > ________________________________ > ???: ? ?? > ????: Tuesday, June 26, 2018 8:25:58 PM > ???: python-list at python.org > ??: No pip for my Python 3.6.5! > > Hi~ > > I am a beginner with Python. > My computer is of Windows version. > And I dowloaded the lastest version of python on the > https://www.python.org/ . > My book, Automate the Boring Stuff With Python, teaches me to install a > third-party module with the command line: pip install send2trash (for > example). > But there comes the error message !!! > > What is going wrong? > It makes no sense since my Python is 3.6.5 version. > I doubt that my poor Python doesn?t have a pip. > > Please tell me why and help me!! > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From tjol at tjol.eu Mon Jul 9 09:47:39 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 9 Jul 2018 15:47:39 +0200 Subject: =?UTF-8?Q?Re:_=e8=bd=ac=e5=8f=91:_No_pip_for_my_Python_3.6.5!?= In-Reply-To: References: Message-ID: <9f79bbeb-56f6-359d-0327-e8a8738b31b9@tjol.eu> Welcome to the list! On 2018-07-09 10:14, ? ?? wrote: > But there comes the error message !!! > > What is going wrong? Without you telling us what "the error message" is, I'm afraid there's no way anybody can possibly know. -- Thomas From wolfgang.maier at biologie.uni-freiburg.de Mon Jul 9 10:03:13 2018 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 9 Jul 2018 16:03:13 +0200 Subject: =?UTF-8?Q?Re:_=e8=bd=ac=e5=8f=91:_No_pip_for_my_Python_3.6.5!?= In-Reply-To: References: Message-ID: On 07/09/2018 10:14 AM, ? ?? wrote: > > Hi~ > > I am a beginner with Python. > My computer is of Windows version. > And I dowloaded the lastest version of python on the https://www.python.org/ . > My book, Automate the Boring Stuff With Python, teaches me to install a third-party module with the command line: pip install send2trash (for example). > But there comes the error message !!! > > What is going wrong? > It makes no sense since my Python is 3.6.5 version. > I doubt that my poor Python doesn?t have a pip. > Does the following work for you? py -3 -m pip install send2trash work for you? If so, you can either continue to run pip like this (it is a good way) or you'll have to make pip.exe discoverable from your PATH as suggested by Abdur-Rahmaan. Best, Wolfgang From wolfgang.maier at biologie.uni-freiburg.de Mon Jul 9 10:03:13 2018 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Mon, 9 Jul 2018 16:03:13 +0200 Subject: =?UTF-8?Q?Re:_=e8=bd=ac=e5=8f=91:_No_pip_for_my_Python_3.6.5!?= In-Reply-To: References: Message-ID: On 07/09/2018 10:14 AM, ? ?? wrote: > > Hi~ > > I am a beginner with Python. > My computer is of Windows version. > And I dowloaded the lastest version of python on the https://www.python.org/ . > My book, Automate the Boring Stuff With Python, teaches me to install a third-party module with the command line: pip install send2trash (for example). > But there comes the error message !!! > > What is going wrong? > It makes no sense since my Python is 3.6.5 version. > I doubt that my poor Python doesn?t have a pip. > Does the following work for you? py -3 -m pip install send2trash work for you? If so, you can either continue to run pip like this (it is a good way) or you'll have to make pip.exe discoverable from your PATH as suggested by Abdur-Rahmaan. Best, Wolfgang From steve+comp.lang.python at pearwood.info Mon Jul 9 12:02:18 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 9 Jul 2018 16:02:18 +0000 (UTC) Subject: =?UTF-8?b?6L2s5Y+ROg==?= No pip for my Python 3.6.5! References: Message-ID: On Mon, 09 Jul 2018 08:14:04 +0000, ? ?? wrote: > I am a beginner with Python. > My computer is of Windows version. > And I dowloaded the lastest version of python on the > https://www.python.org/ . My book, Automate the Boring Stuff With > Python, teaches me to install a third-party module with the command > line: pip install send2trash (for example). But there comes the error > message !!! > > What is going wrong? Without knowing what the error message says, we cannot tell what the error is. Make sure you are running the Windows shell, not Python, and then try this command: python3 -m ensurepip --upgrade If that fails, COPY AND PASTE the full error, don't use a screen shot, and don't try to retype it. You could also try either of these instead: py -m pip install send2trash py3 -m pip install send2trash But without seeing the actual errors you are getting, I'm just guessing what the problem is. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From breamoreboy at gmail.com Mon Jul 9 12:21:37 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Mon, 9 Jul 2018 17:21:37 +0100 Subject: =?UTF-8?Q?Re:_=e8=bd=ac=e5=8f=91:_No_pip_for_my_Python_3.6.5!?= In-Reply-To: References: Message-ID: On 09/07/18 17:02, Steven D'Aprano wrote: > On Mon, 09 Jul 2018 08:14:04 +0000, ? ?? wrote: > >> I am a beginner with Python. >> My computer is of Windows version. >> And I dowloaded the lastest version of python on the >> https://www.python.org/ . My book, Automate the Boring Stuff With >> Python, teaches me to install a third-party module with the command >> line: pip install send2trash (for example). But there comes the error >> message !!! >> >> What is going wrong? > > Without knowing what the error message says, we cannot tell what the > error is. > > > Make sure you are running the Windows shell, not Python, and then try > this command: > > python3 -m ensurepip --upgrade > I don't think there is a python3 on Windows. > > If that fails, COPY AND PASTE the full error, don't use a screen shot, > and don't try to retype it. > > You could also try either of these instead: > > py -m pip install send2trash This will pick the default python. I've no idea how this is defined nowadays. > > py3 -m pip install send2trash Shouldn't that be:- py -3 -m...? > > > > But without seeing the actual errors you are getting, I'm just guessing > what the problem is. > -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From mal at europython.eu Mon Jul 9 12:49:11 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Mon, 9 Jul 2018 18:49:11 +0200 Subject: =?UTF-8?Q?EuroPython_2018:_EuroPython_2018:_Women=e2=80=99s_Django_?= =?UTF-8?Q?Workshop?= Message-ID: <803d6a7d-8c64-58f8-2732-545f8bd44d8c@europython.eu> We are pleased to host and sponsor a free Women?s Django Workshop on Monday 23rd July, from 9am-6pm. * EuroPython Women?s Django Workshop * https://ep2018.europython.eu/en/events/womens-django-workshop/ What to expect -------------- Would you like to learn about how to build websites, but don?t know where to start? A group of volunteers will lead you through HTML, CSS, Python & Django to build a blog in a one day workshop. No prior programming knowledge is needed to participate! How to register --------------- If you would like to take part, apply for a spot by filling in our application form. Participation is free of charge, but does require registration: https://docs.google.com/forms/d/e/1FAIpQLScQEWU5d4aqbpXkUvVYkdYaMO-iG5vQ1ujR08Cux1sktOzHMQ/viewform The EuroPython Society sponsors this event, providing space, catering and making available up to 30 discounted student rate conference tickets to the workshop attendees. Reminder: Book your EuroPython 2018 tickets soon ------------------------------------------------ Please make sure you book your ticket in the coming days. We will switch to late bird rates next week. https://ep2018.europython.eu/en/registration/buy-tickets/ If you want to attend the training sessions, please buy a training pass. We only have very few left and will close sales for these soon. 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/175710624987/europython-2018-womens-django-workshop Tweet: https://twitter.com/europython/status/1016329799864856577 Enjoy, -- EuroPython 2018 Team https://ep2018.europython.eu/ https://www.europython-society.org/ From steve+comp.lang.python at pearwood.info Mon Jul 9 19:57:47 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 9 Jul 2018 23:57:47 +0000 (UTC) Subject: Generator Comprehensions Message-ID: Based on feedback from people annoyed at having to write "comprehensions and generator expressions" to refer to what ought to be a single concept, Guido has given the thumbs up for a documentation change to start referring to "generator comprehensions". https://mail.python.org/pipermail/python-dev/2018-July/154554.html This now combines four related syntax under one umbrella term: Comprehension: - list comprehension [expr for x in values] - set comprehension {expr for x in values} - dict comprehension {key:value for x in values} - generator comprehension (expr for x in values) a.k.a. generator expression -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From arj.python at gmail.com Wed Jul 11 02:50:21 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 11 Jul 2018 10:50:21 +0400 Subject: indexed assignment in list Message-ID: saw this snippet on the internet : why assigning by index propagates it all? >>> a = [[1]] * 7 >>> a [[1], [1], [1], [1], [1], [1], [1]] >>> a[0][0] = 2 >>> a [[2], [2], [2], [2], [2], [2], [2]] why not [[1], [2], [2], [2], [2], [2], [2]] ? thank you ! -- Abdur-Rahmaan Janhangeer https://github.com/abdur-rahmaanj Mauritius From __peter__ at web.de Wed Jul 11 02:54:26 2018 From: __peter__ at web.de (Peter Otten) Date: Wed, 11 Jul 2018 08:54:26 +0200 Subject: indexed assignment in list References: Message-ID: Abdur-Rahmaan Janhangeer wrote: > saw this snippet on the internet : why assigning by index propagates it > all? It doesn't. > >>>> a = [[1]] * 7 >>>> a > [[1], [1], [1], [1], [1], [1], [1]] > >>> a[0][0] = 2 >>>> a > [[2], [2], [2], [2], [2], [2], [2]] > > why not > > [[1], [2], [2], [2], [2], [2], [2]] As to why you'd expect that one I've no idea. > ? > > thank you ! a = [[1]] * 7 creates a list containing seven references to the same inner list [1]. With seven distinct lists you get the expected >>> a = [[1], [1], [1], [1], [1], [1], [1]] >>> a[0][0] = 2 >>> a [[2], [1], [1], [1], [1], [1], [1]] From __peter__ at web.de Wed Jul 11 03:00:51 2018 From: __peter__ at web.de (Peter Otten) Date: Wed, 11 Jul 2018 09:00:51 +0200 Subject: indexed assignment in list References: Message-ID: Peter Otten wrote: > a = [[1]] * 7 > > creates a list containing seven references to the same inner list [1]. I. e. it is roughly equivalent to b = [1] a = [b, b, b, b, b, b, b] From arj.python at gmail.com Wed Jul 11 03:04:59 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 11 Jul 2018 11:04:59 +0400 Subject: indexed assignment in list In-Reply-To: References: Message-ID: On Wed, Jul 11, 2018 at 10:55 AM Peter Otten <__peter__ at web.de> wrote: As to why you'd expect that one I've no idea my mistake -- Abdur-Rahmaan Janhangeer https://github.com/abdur-rahmaanj Mauritius From jkn_gg at nicorp.f9.co.uk Wed Jul 11 10:09:17 2018 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Wed, 11 Jul 2018 07:09:17 -0700 (PDT) Subject: Feasibility of console based (non-Gui) Tkinter app which can accept keypresses? Message-ID: <250b4b1a-65d1-4d6e-a97b-8b48d53a9234@googlegroups.com> Hi All This is more of a Tkinter question rather than a python one, I think, but anyway... I have a Python simulator program with a Model-View_Controller architecture. I have written the View part using Tkinter in the first instance; later I plan to use Qt. However I also want to be able to offer an alternative of a console-only operation. So I have a variant View with the beginnings of this. Naturally I want to keep this as similar as possible to my Tkinter-based view. I had thought that I had seen a guide somewhere to using Tk/Tkinter in a non-GUI form. I don't seem to be able to track this down now, but I have at least been successful in hiding ('withdrawing') the main Frame, and running a main loop. The bit which I am now stumbling on is trying to bind key events to my view, and I am wondering if this actually makes any sense. In the absence of a GUI I want to accept keypresses to control the simulation. But in a console app I will have no visible or in focus window, and therefore at what level would any keys be bound? Not at the widget level, nor the frame, and I am not sure if the the root makes sense either. So I am looking for confirmation of this, and/or whether there is any way of running a Tkinter application in 'console' mode, running a main loop and both outputting data and accepting, and acting on, key presses. Thanks J^n From torriem at gmail.com Wed Jul 11 11:46:40 2018 From: torriem at gmail.com (Michael Torrie) Date: Wed, 11 Jul 2018 09:46:40 -0600 Subject: Feasibility of console based (non-Gui) Tkinter app which can accept keypresses? In-Reply-To: <250b4b1a-65d1-4d6e-a97b-8b48d53a9234@googlegroups.com> References: <250b4b1a-65d1-4d6e-a97b-8b48d53a9234@googlegroups.com> Message-ID: On 07/11/2018 08:09 AM, jkn wrote: > So I am looking for confirmation of this, and/or whether there is any way of > running a Tkinter application in 'console' mode, running a main loop and> both outputting data and accepting, and acting on, key presses. So far as I know, no this isn't possible, especially on any Unix system where Tk is getting events from the graphical windowing system, which doesn't exist in a console. NCurses is the usual go-to library for console applications that need to get keyboard events. From rosuav at gmail.com Wed Jul 11 13:41:38 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Jul 2018 03:41:38 +1000 Subject: Feasibility of console based (non-Gui) Tkinter app which can accept keypresses? In-Reply-To: <250b4b1a-65d1-4d6e-a97b-8b48d53a9234@googlegroups.com> References: <250b4b1a-65d1-4d6e-a97b-8b48d53a9234@googlegroups.com> Message-ID: On Thu, Jul 12, 2018 at 12:09 AM, jkn wrote: > Hi All > This is more of a Tkinter question rather than a python one, I think, but > anyway... > > I have a Python simulator program with a Model-View_Controller architecture. I > have written the View part using Tkinter in the first instance; later I plan > to use Qt. > > However I also want to be able to offer an alternative of a console-only > operation. So I have a variant View with the beginnings of this. > > Naturally I want to keep this as similar as possible to my Tkinter-based view. I > had thought that I had seen a guide somewhere to using Tk/Tkinter in a non-GUI > form. I don't seem to be able to track this down now, but I have at least been > successful in hiding ('withdrawing') the main Frame, and running a main loop. > > The bit which I am now stumbling on is trying to bind key events to my view, > and I am wondering if this actually makes any sense. In the absence of a GUI I > want to accept keypresses to control the simulation. But in a console app I will > have no visible or in focus window, and therefore at what level would any > keys be bound? Not at the widget level, nor the frame, and I am not sure if the > the root makes sense either. ISTM you want to have a variant Controller as well, to allow a completely different way of managing the display. The easiest and cleanest UI is probably a line-based console input command system, where the user would type something and hit enter, and you receive that using input(). That also plays nicely with input redirection, allowing you to control your program from another program. ChrisA From jlee54 at gmail.com Wed Jul 11 15:22:57 2018 From: jlee54 at gmail.com (Jim Lee) Date: Wed, 11 Jul 2018 12:22:57 -0700 Subject: Feasibility of console based (non-Gui) Tkinter app which can accept keypresses? In-Reply-To: <250b4b1a-65d1-4d6e-a97b-8b48d53a9234@googlegroups.com> References: <250b4b1a-65d1-4d6e-a97b-8b48d53a9234@googlegroups.com> Message-ID: <3fa1cc6a-0247-a543-646c-96f2da66cedd@gmail.com> On 07/11/18 07:09, jkn wrote: > Hi All > This is more of a Tkinter question rather than a python one, I think, but > anyway... > > I have a Python simulator program with a Model-View_Controller architecture. I > have written the View part using Tkinter in the first instance; later I plan > to use Qt. > > However I also want to be able to offer an alternative of a console-only > operation. So I have a variant View with the beginnings of this. > > Naturally I want to keep this as similar as possible to my Tkinter-based view. I > had thought that I had seen a guide somewhere to using Tk/Tkinter in a non-GUI > form. I don't seem to be able to track this down now, but I have at least been > successful in hiding ('withdrawing') the main Frame, and running a main loop. > > The bit which I am now stumbling on is trying to bind key events to my view, > and I am wondering if this actually makes any sense. In the absence of a GUI I > want to accept keypresses to control the simulation. But in a console app I will > have no visible or in focus window, and therefore at what level would any > keys be bound? Not at the widget level, nor the frame, and I am not sure if the > the root makes sense either. > > So I am looking for confirmation of this, and/or whether there is any way of > running a Tkinter application in 'console' mode, running a main loop and > both outputting data and accepting, and acting on, key presses. > > Thanks > J^n > I think the general answer is no, but beyond that, it may be worth considering switching from an MVC architecture to a simpler frontend-backend, especially if you intend to add a third interface (Qt): MVC w/Tk, console, Qt: Seven conceptual modules (three controllers, three views, one model) Two abstraction layers (controller<->model, model<->view) Frontend-backend w/Tk, console, Qt: Four conceptual modules (three frontends, one backend) One abstraction layer (frontend<->backend) -Jim From rbistolfi at gmail.com Wed Jul 11 20:05:06 2018 From: rbistolfi at gmail.com (Rodrigo Bistolfi) Date: Wed, 11 Jul 2018 21:05:06 -0300 Subject: Feasibility of console based (non-Gui) Tkinter app which can accept keypresses? In-Reply-To: <3fa1cc6a-0247-a543-646c-96f2da66cedd@gmail.com> References: <250b4b1a-65d1-4d6e-a97b-8b48d53a9234@googlegroups.com> <3fa1cc6a-0247-a543-646c-96f2da66cedd@gmail.com> Message-ID: You may want to check Urwid instead. 2018-07-11 16:22 GMT-03:00 Jim Lee : > On 07/11/18 07:09, jkn wrote: > >> Hi All >> This is more of a Tkinter question rather than a python one, I >> think, but >> anyway... >> >> I have a Python simulator program with a Model-View_Controller >> architecture. I >> have written the View part using Tkinter in the first instance; later I >> plan >> to use Qt. >> >> However I also want to be able to offer an alternative of a console-only >> operation. So I have a variant View with the beginnings of this. >> >> Naturally I want to keep this as similar as possible to my Tkinter-based >> view. I >> had thought that I had seen a guide somewhere to using Tk/Tkinter in a >> non-GUI >> form. I don't seem to be able to track this down now, but I have at least >> been >> successful in hiding ('withdrawing') the main Frame, and running a main >> loop. >> >> The bit which I am now stumbling on is trying to bind key events to my >> view, >> and I am wondering if this actually makes any sense. In the absence of a >> GUI I >> want to accept keypresses to control the simulation. But in a console app >> I will >> have no visible or in focus window, and therefore at what level would any >> keys be bound? Not at the widget level, nor the frame, and I am not sure >> if the >> the root makes sense either. >> >> So I am looking for confirmation of this, and/or whether there is any way >> of >> running a Tkinter application in 'console' mode, running a main loop and >> both outputting data and accepting, and acting on, key presses. >> >> Thanks >> J^n >> >> > I think the general answer is no, but beyond that, it may be worth > considering switching from an MVC architecture to a simpler > frontend-backend, especially if you intend to add a third interface (Qt): > > MVC w/Tk, console, Qt: > > Seven conceptual modules (three controllers, three views, one model) > Two abstraction layers (controller<->model, model<->view) > > Frontend-backend w/Tk, console, Qt: > > Four conceptual modules (three frontends, one backend) > One abstraction layer (frontend<->backend) > > -Jim > > -- > https://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Wed Jul 11 20:50:48 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 11 Jul 2018 20:50:48 -0400 Subject: Feasibility of console based (non-Gui) Tkinter app which can accept keypresses? In-Reply-To: <250b4b1a-65d1-4d6e-a97b-8b48d53a9234@googlegroups.com> References: <250b4b1a-65d1-4d6e-a97b-8b48d53a9234@googlegroups.com> Message-ID: On 7/11/2018 10:09 AM, jkn wrote: > Hi All > This is more of a Tkinter question rather than a python one, I think, but > anyway... > > I have a Python simulator program with a Model-View_Controller architecture. I > have written the View part using Tkinter in the first instance; later I plan > to use Qt. > > However I also want to be able to offer an alternative of a console-only > operation. So I have a variant View with the beginnings of this. > > Naturally I want to keep this as similar as possible to my Tkinter-based view. I > had thought that I had seen a guide somewhere to using Tk/Tkinter in a non-GUI > form. The only reason I can think of to use tkinter in a text application is to its multiple simultaneous timer loops. > I don't seem to be able to track this down now, but I have at least been > successful in hiding ('withdrawing') the main Frame, and running a main loop. At the end of this response is an experiment in driving text-output coroutines with tkinter, where I did as you say above. > The bit which I am now stumbling on is trying to bind key events to my view, > and I am wondering if this actually makes any sense. In the absence of a GUI I > want to accept keypresses to control the simulation. But in a console app I will > have no visible or in focus window, and therefore at what level would any > keys be bound? Not at the widget level, nor the frame, and I am not sure if the > the root makes sense either. You cannot use the tkinter widget bind command. If you can use curses or something to move the cursor around the screen, you can emulate widgets and key binding with characters, an after loop, and key handlers. +---------------------------------------+ | Find: _ | | Ignore case [ ] Up ( ) Down ( ) | +---------------------------------------+ keyhandle = entry def keyhit(): if kbhit(): # Windows, someone else gave linux equivalent keyhandle(getch()) root.after(50, keyhit) root.after(50, keyhit) # Start key polling keyhandler is initially entry, which echoes printable chars and moves cursor to Ignore case [_] on tab (assuming you have gui box do the same) and changes keyhandle to check. Check treats [space] as a left click and call whatever the gui checkbutton command is. Ditto for radio and the binding to radiobuttons. > So I am looking for confirmation of this, and/or whether there is any way of > running a Tkinter application in 'console' mode, running a main loop and > both outputting data and accepting, and acting on, key presses. Brett's countdown.py (see link below) implements an event loop using time.sleep and a priority queue. A 'keyhit loop could be added to that, but the result is still to text apps. --- """https://snarky.ca/how-the-heck-does-async-await-work-in-python-3-5/ How the heck does async/await work in Python 3.5? Bret Cannon """ import datetime import types from time import perf_counter from tkinter import Tk class SleepingLoop: """An event loop focused on delaying execution of coroutines. Think of this as being like asyncio.BaseEventLoop/curio.Kernel. """ def __init__(self, *coros): self.coros = coros self.waiting = set() self.root = Tk() self.root.withdraw() def callback(self, coro): try: # It's time to resume the coroutine. seconds = coro.send(perf_counter()) self.root.after(int(seconds * 1000), self.callback, coro) except StopIteration: # The coroutine is done. self.waiting.remove(coro) if not self.waiting: self.root.quit() def run_until_complete(self): # Start all the coroutines (async generators) for coro in self.coros: self.waiting.add(coro) seconds = coro.send(None) self.root.after(int(seconds * 1000), self.callback, coro) self.root.mainloop() @types.coroutine def sleep(seconds): """Pause a coroutine for the specified number of seconds. Think of this as being like asyncio.sleep()/curio.sleep(). """ now = perf_counter() actual = yield seconds # Resume the execution stack, sending back how long we actually waited. return actual - now async def countdown(label, length, *, delay=0): """Countdown a launch for `length` seconds, waiting `delay` seconds. This is what a user would typically write. """ print(label, 'waiting', delay, 'seconds before starting countdown') delta = await sleep(delay) print(label, 'starting after waiting', delta) while length: print(label, 'T-minus', length) waited = await sleep(1) length -= 1 print(label, 'lift-off!') def main(): """Start the event loop, counting down 3 separate launches. This is what a user would typically write. """ loop = SleepingLoop(countdown('A', 5, delay=2), countdown(' B', 3, delay=2), countdown(' C', 4, delay=1)) start = perf_counter() loop.run_until_complete() print('Total elapsed time is', perf_counter() - start) if __name__ == '__main__': main() -- Terry Jan Reedy From aleiphoenix at gmail.com Thu Jul 12 04:37:24 2018 From: aleiphoenix at gmail.com (aleiphoenix) Date: Thu, 12 Jul 2018 01:37:24 -0700 (PDT) Subject: variable scope in try ... EXCEPT block. Message-ID: suppose following code running with Python-3.4.8 and Python-3.6.5 # -*- coding: utf-8 -*- def hello(): err = None print('0: {}'.format(locals())) try: b = 2 print('1: {}'.format(locals())) raise ValueError() print('2: {}'.format(locals())) except ValueError as err: print('3: {}'.format(locals())) pass print('4: {}'.format(locals())) return '', err hello() got output: 0: {'err': None} 1: {'err': None, 'b': 2} 3: {'err': ValueError(), 'b': 2} 4: {'b': 2} Traceback (most recent call last): File "err.py", line 19, in hello() File "err.py", line 16, in hello return '', err UnboundLocalError: local variable 'err' referenced before assignment But without this UnboundLocalError with Python-2.7.14 My question is, does except ... as ... create a new scope from outer block, causing 'err' be hidden from outer scope? Is this intentional? Thanks. From ben.usenet at bsb.me.uk Thu Jul 12 05:45:36 2018 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Thu, 12 Jul 2018 10:45:36 +0100 Subject: variable scope in try ... EXCEPT block. References: Message-ID: <87muuwrdmn.fsf@bsb.me.uk> aleiphoenix writes: > suppose following code running with Python-3.4.8 and Python-3.6.5 > > > # -*- coding: utf-8 -*- > > > def hello(): > err = None > print('0: {}'.format(locals())) > try: > b = 2 > print('1: {}'.format(locals())) > raise ValueError() > print('2: {}'.format(locals())) > except ValueError as err: > print('3: {}'.format(locals())) > pass > print('4: {}'.format(locals())) > return '', err > > > hello() > > > > got output: > > 0: {'err': None} > 1: {'err': None, 'b': 2} > 3: {'err': ValueError(), 'b': 2} > 4: {'b': 2} > Traceback (most recent call last): > File "err.py", line 19, in > hello() > File "err.py", line 16, in hello > return '', err > UnboundLocalError: local variable 'err' referenced before assignment > > > But without this UnboundLocalError with Python-2.7.14 > > > My question is, does except ... as ... create a new scope from outer > block, causing 'err' be hidden from outer scope? Is this intentional? Yes, it's intentional, but it's not exactly a scope. In https://docs.python.org/3/reference/compound_stmts.html#try you will find: When an exception has been assigned using as target, it is cleared at the end of the except clause. This is as if except E as N: foo was translated to except E as N: try: foo finally: del N This means the exception must be assigned to a different name to be able to refer to it after the except clause. Exceptions are cleared because with the traceback attached to them, they form a reference cycle with the stack frame, keeping all locals in that frame alive until the next garbage collection occurs. This appears to be a change from Python 2. That wording is not present in https://docs.python.org/2/reference/compound_stmts.html#try -- Ben. From steve+comp.lang.python at pearwood.info Thu Jul 12 05:59:52 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 12 Jul 2018 09:59:52 +0000 (UTC) Subject: variable scope in try ... EXCEPT block. References: Message-ID: On Thu, 12 Jul 2018 01:37:24 -0700, aleiphoenix wrote: > My question is, does except ... as ... create a new scope from outer > block, causing 'err' be hidden from outer scope? Is this intentional? No, it is not a new scope, and yes, it is intentional. It's a nasty hack, but a *necessary* nasty hack: when the except block exits, the "err" local variable (or whatever it happens to be called) is implicitly deleted. You can work around this by explicitly assigning to another local variable: try: ... except Exception as e: err = e # only "e" will be deleted when we exit the block This is necessary in Python 3 (but not Python 2) because exception objects form a reference cycle with something (the traceback?) which is a big, heavyweight object. Allowing random exception objects to stay alive for long periods was consuming unacceptable amounts of memory, so it was decided to hit this problem with a hammer and fix it in the simplest, although least elegant, way: just delete the exception when leaving the except block. You can see the disassembled byte-code here. Here's the output from Python 3.5: py> dis.dis("try: pass\nexcept Exception as err: pass") 1 0 SETUP_EXCEPT 4 (to 7) 3 POP_BLOCK 4 JUMP_FORWARD 37 (to 44) 2 >> 7 DUP_TOP 8 LOAD_NAME 0 (Exception) 11 COMPARE_OP 10 (exception match) 14 POP_JUMP_IF_FALSE 43 17 POP_TOP 18 STORE_NAME 1 (err) 21 POP_TOP 22 SETUP_FINALLY 5 (to 30) 25 POP_BLOCK 26 POP_EXCEPT 27 LOAD_CONST 0 (None) >> 30 LOAD_CONST 0 (None) 33 STORE_NAME 1 (err) 36 DELETE_NAME 1 (err) 39 END_FINALLY 40 JUMP_FORWARD 1 (to 44) >> 43 END_FINALLY >> 44 LOAD_CONST 0 (None) 47 RETURN_VALUE -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jkn_gg at nicorp.f9.co.uk Thu Jul 12 06:08:08 2018 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Thu, 12 Jul 2018 03:08:08 -0700 (PDT) Subject: Feasibility of console based (non-Gui) Tkinter app which can accept keypresses? In-Reply-To: References: <250b4b1a-65d1-4d6e-a97b-8b48d53a9234@googlegroups.com> Message-ID: <7ac5d1d5-dcd6-4ed4-966d-c534a369dc40@googlegroups.com> Hi All thanks for the comments and confirmation that this is not really possible in a Tkinter environment. I had thought of using ncurses but was shying clear of learning about another set of widgets etc. just now. The output of the simulator is simple enough that it could just accept simple keystrokes for control, and every second or so there will be an output string saying what is happening - a sort of concatenation of the various output widgets in the Tkinter-based version. I have hoped to keep this text view so similar to the Tkinter one that it was using the same mechanisms (after(), Tk keyevents etc). Instead I think I will just write a simple mainloop() which is 'inspired by' Tkinter. I could then look at adding ncurses as a third alternative. Thanks again J^n From e+python-list at kellett.im Thu Jul 12 08:31:57 2018 From: e+python-list at kellett.im (Ed Kellett) Date: Thu, 12 Jul 2018 13:31:57 +0100 Subject: variable scope in try ... EXCEPT block. In-Reply-To: References: Message-ID: On 2018-07-12 10:59, Steven D'Aprano wrote: > On Thu, 12 Jul 2018 01:37:24 -0700, aleiphoenix wrote: > >> My question is, does except ... as ... create a new scope from outer >> block, causing 'err' be hidden from outer scope? Is this intentional? > > No, it is not a new scope, and yes, it is intentional. It's a nasty hack, > but a *necessary* nasty hack: when the except block exits, the "err" > local variable (or whatever it happens to be called) is implicitly > deleted. > > You can work around this by explicitly assigning to another local > variable: > > try: > ... > except Exception as e: > err = e # only "e" will be deleted when we exit the block > > > This is necessary in Python 3 [...] "necessary" is debatable. When we have reference counting, general garbage collection, *and* nasty hacks like this, one could be forgiven for thinking Python has chosen the worst of all memory-management worlds. That said, in this case it's entirely livable-with once one knows about it. Unrelatedly, having stared at this email for a moment, I really wish Thunderbird had an option to avoid orphan words Ed From rosuav at gmail.com Thu Jul 12 09:03:01 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 12 Jul 2018 23:03:01 +1000 Subject: variable scope in try ... EXCEPT block. In-Reply-To: References: Message-ID: On Thu, Jul 12, 2018 at 10:31 PM, Ed Kellett wrote: > On 2018-07-12 10:59, Steven D'Aprano wrote: >> On Thu, 12 Jul 2018 01:37:24 -0700, aleiphoenix wrote: >> >>> My question is, does except ... as ... create a new scope from outer >>> block, causing 'err' be hidden from outer scope? Is this intentional? >> >> No, it is not a new scope, and yes, it is intentional. It's a nasty hack, >> but a *necessary* nasty hack: when the except block exits, the "err" >> local variable (or whatever it happens to be called) is implicitly >> deleted. >> >> You can work around this by explicitly assigning to another local >> variable: >> >> try: >> ... >> except Exception as e: >> err = e # only "e" will be deleted when we exit the block >> >> >> This is necessary in Python 3 [...] > > "necessary" is debatable. When we have reference counting, general > garbage collection, *and* nasty hacks like this, one could be forgiven > for thinking Python has chosen the worst of all memory-management worlds. I don't understand you. Are you saying that there are other memory management systems that are perfect, without any tradeoffs? Because the problem here is a reference cycle thus: >>> def f(): ... try: 1/0 ... except Exception as e: print(e is e.__traceback__.tb_frame.f_locals["e"]) ... >>> f() True Dealing with reference cycles is generally done *periodically* rather than immediately (CPython disposes of unreferenced objects immediately upon last deref). You can avoid having a dedicated cycle detection pass by using a mark-and-sweep GC, but that just means that *all* garbage is dealt with periodically rather than immediately. I can imagine having some sort of flag on every object that's involved in a cycle, and then doing a mini-GC every time any of those objects gets any dereferencing, but that would be ridiculously expensive. There are ALWAYS tradeoffs. How is Python's arrangement "the worst"? Personally, I think this would be better with an *actual* subscope. But apparently that's a ridiculously insane suggestion with no chance whatsoever of being accepted. Kinda like assignment expressions. ChrisA From e+python-list at kellett.im Thu Jul 12 09:23:28 2018 From: e+python-list at kellett.im (Ed Kellett) Date: Thu, 12 Jul 2018 14:23:28 +0100 Subject: variable scope in try ... EXCEPT block. In-Reply-To: References: Message-ID: On 2018-07-12 14:03, Chris Angelico wrote: > Dealing with reference cycles is generally done *periodically* rather > than immediately (CPython disposes of unreferenced objects immediately > upon last deref). You can avoid having a dedicated cycle detection > pass by using a mark-and-sweep GC, but that just means that *all* > garbage is dealt with periodically rather than immediately. I can > imagine having some sort of flag on every object that's involved in a > cycle, and then doing a mini-GC every time any of those objects gets > any dereferencing, but that would be ridiculously expensive. There are > ALWAYS tradeoffs. How is Python's arrangement "the worst"? It pays the cost of a reference counter and a garbage collector and the language designers *still* feel like they have to add weird hacks like the implicit del. I agree there are always tradeoffs. But it feels like Python has made tradeoffs that should allow it to never worry about cycles ever, and then it goes ahead and worries about cycles anyway. > Personally, I think this would be better with an *actual* subscope. > But apparently that's a ridiculously insane suggestion with no chance > whatsoever of being accepted. Kinda like assignment expressions. FWIW, I'd vastly prefer some kind of reconsidering of the scoping approach to assignment expressions. I don't want to have a 10000th iteration of the same old argument about them, but I think subscoping is way more applicable: at least to me, it'd make all code more readable by default, because it'd tend to make namespaces emptier and therefore easier to hold in memory. Could we fix: for x in something: blah(lambda a: a + x) while we're at it? Also, since we're well into the realm of crazy here, when are we making nonlocal the default? Ed From mal at europython.eu Thu Jul 12 10:02:32 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 12 Jul 2018 16:02:32 +0200 Subject: EuroPython 2018: Call for On-site Volunteers Message-ID: Ever wanted to help out during Europython ? Do you want to *really* take part in EuroPython, meet new people and help them at the same time ? We have just the right thing for you: apply as EuroPython Volunteer and be part of the great team that is making EuroPython 2018 a reality this year. EuroPython Volunteers --------------------- Glad you want to help ! Please see our volunteers page for details on how to sign up: * EuroPython 2018 Volunteers * https://ep2018.europython.eu/en/registration/volunteers/ We are using a volunteer management app for the organization and a Telegram group for communication. https://ep2018.europython.eu/volunteer-app We have a few exciting tasks to offer such as helping out setting up and tearing down the conference space, giving out goodie bags and t-shirts, and being at the conference desk to answer all questions about EuroPython, session chairing or helping as room manager. We also have some perks for you, to give something back. Please check our volunteers page for details. Hope to see you there ! 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/175814086737/europython-2018-call-for-on-site-volunteers Tweet: https://twitter.com/europython/status/1017407947134066689 Enjoy, -- EuroPython 2018 Team https://ep2018.europython.eu/ https://www.europython-society.org/ From mal at europython.eu Thu Jul 12 12:24:47 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 12 Jul 2018 18:24:47 +0200 Subject: EuroPython 2018: Conference App available Message-ID: <87b9cd52-1b24-bca6-f12a-d7b9539696ac@europython.eu> We are pleased to announce the conference app for EuroPython 2018, again hosted on the Attendify platform: * EuroPython 2018 Conference App * https://ep2018.europython.eu/en/events/conference-app/ Engage with the conference and its attendees -------------------------------------------- The mobile app gives you access to the conference schedule (even offline), helps you in planing your conference experience (create your personal schedule with reminders) and provides a rich social engagement platform for all attendees. You can create a profile within the app or link this to your existing social accounts, share messages and photos, and easily reach out to other fellow attendees - all from within the app. Vital for all EuroPython 2018 attendees --------------------------------------- We will again use the conference app to keep you updated by sending updates of the schedule and inform you of important announcements via push notifications, so please consider downloading it. Many useful features -------------------- Please see our EuroPython 2018 Conference App page for more details on features and guides on how to use them. https://ep2018.europython.eu/en/events/conference-app/ Don?t forget to get your EuroPython ticket ------------------------------------------ If you want to join the EuroPython fun, be sure to get your tickets as soon as possible, since ticket sales have picked up a lot this and we may have to close sales prior to the event. 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/175817504647/europython-2018-conference-app-available Tweet: https://twitter.com/europython/status/1017444062306193409 Enjoy, -- EuroPython 2018 Team https://ep2018.europython.eu/ https://www.europython-society.org/ From rosuav at gmail.com Thu Jul 12 13:00:11 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Jul 2018 03:00:11 +1000 Subject: variable scope in try ... EXCEPT block. In-Reply-To: References: Message-ID: On Thu, Jul 12, 2018 at 11:23 PM, Ed Kellett wrote: > Could we fix: > > for x in something: > blah(lambda a: a + x) > > while we're at it? What do you mean by "fix"? Make the 'x' bind eagerly? That would break basically every other use of closures. ChrisA From darcy at vex.net Thu Jul 12 15:52:48 2018 From: darcy at vex.net (D'Arcy Cain) Date: Thu, 12 Jul 2018 15:52:48 -0400 Subject: Python 3.6 can find cairo libs but not Python 2.7 Message-ID: $ python2.7 -c "import ctypes.util; print(ctypes.util.find_library('cairo'))" libcairo.so.2 $ python3.6 -c "import ctypes.util; print(ctypes.util.find_library('cairo'))" None I have the 3.6 version of py-cairo installed. Any thoughts? NetBSD 7.1.2 Cheers. -- D'Arcy J.M. Cain System Administrator, Vex.Net http://www.Vex.Net/ IM:darcy at Vex.Net VoIP: sip:darcy at Vex.Net From tjreedy at udel.edu Thu Jul 12 16:17:32 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 12 Jul 2018 16:17:32 -0400 Subject: Python 3.6 can find cairo libs but not Python 2.7 In-Reply-To: References: Message-ID: On 7/12/2018 3:52 PM, D'Arcy Cain wrote: > $ python2.7 -c "import ctypes.util; > print(ctypes.util.find_library('cairo'))" > libcairo.so.2 > $ python3.6 -c "import ctypes.util; > print(ctypes.util.find_library('cairo'))" > None > > I have the 3.6 version of py-cairo installed. Any thoughts? > > NetBSD 7.1.2 what is sys.path? Where in py-cairo installed? -- Terry Jan Reedy From codewizard at gmail.com Thu Jul 12 18:10:41 2018 From: codewizard at gmail.com (codewizard at gmail.com) Date: Thu, 12 Jul 2018 15:10:41 -0700 (PDT) Subject: variable scope in try ... EXCEPT block. In-Reply-To: <87muuwrdmn.fsf@bsb.me.uk> References: <87muuwrdmn.fsf@bsb.me.uk> Message-ID: <6fac8fc5-e01d-4475-bb69-23b8cf931470@googlegroups.com> On Thursday, July 12, 2018 at 5:45:52 AM UTC-4, Ben Bacarisse wrote: > aleiphoenix writes: > > [snip] > > When an exception has been assigned using as target, it is cleared at > the end of the except clause. This is as if > > except E as N: > foo > > was translated to > > except E as N: > try: > foo > finally: > del N Is there a downside of implementing it similarly to this (untested): # generate a unique name for __except_N except E as __except_N: if 'N' in locals() or N in globals(): __original_N = N N = __except_N try: foo() finally: del __except_N if '__original_N' in locals(): N = __original_N del __original_N else: del N Regards, Igor. From roel at roelschroeven.net Thu Jul 12 18:20:57 2018 From: roel at roelschroeven.net (Roel Schroeven) Date: Fri, 13 Jul 2018 00:20:57 +0200 Subject: Guido van Rossum resigns as Python leader Message-ID: Yes, you read that right: Guido van Rossum resigns as Python leader. See his mail: (https://mail.python.org/pipermail/python-committers/2018-July/005664.html) > Now that PEP 572 is done, I don't ever want to have to fight so hard > for a PEP and find that so many people despise my decisions. > > I would like to remove myself entirely from the decision process. > I'll still be there for a while as an ordinary core dev, and I'll > still be available to mentor people -- possibly more available. But > I'm basically giving myself a permanent vacation from being BDFL, and > you all will be on your own. > > After all that's eventually going to happen regardless -- there's > still that bus lurking around the corner, and I'm not getting > younger... (I'll spare you the list of medical issues.) > > I am not going to appoint a successor. > > So what are you all going to do? Create a democracy? Anarchy? A > dictatorship? A federation? > > I'm not worried about the day to day decisions in the issue tracker > or on GitHub. Very rarely I get asked for an opinion, and usually it's > not actually important. So this can just be dealt with as it has > always been. > > The decisions that most matter are probably > - How are PEPs decided > - How are new core devs inducted > > We may be able to write up processes for these things as PEPs (maybe > those PEPs will form a kind of constitution). But here's the catch. > I'm going to try and let you all (the current committers) figure it > out for yourselves. > > Note that there's still the CoC -- if you don't like that document > your only option might be to leave this group voluntarily. Perhaps > there are issues to decide like when should someone be kicked out > (this could be banning people from python-dev or python-ideas too, > since those are also covered by the CoC). > > Finally. A reminder that the archives of this list are public ( > https://mail.python.org/pipermail/python-committers/) although > membership is closed (limited to core devs). > > I'll still be here, but I'm trying to let you all figure something > out for yourselves. I'm tired, and need a very long break. > > -- > --Guido van Rossum (python.org/~guido) -- "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 Thu Jul 12 18:27:02 2018 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Thu, 12 Jul 2018 23:27:02 +0100 Subject: variable scope in try ... EXCEPT block. References: <87muuwrdmn.fsf@bsb.me.uk> <6fac8fc5-e01d-4475-bb69-23b8cf931470@googlegroups.com> Message-ID: <87in5kozt5.fsf@bsb.me.uk> Just word on quoting... codewizard at gmail.com writes: > On Thursday, July 12, 2018 at 5:45:52 AM UTC-4, Ben Bacarisse wrote: >> >> [snip] You cut everything I wrote. What you left is what I quoted from the Python documentation. In fairness to the authors you should probably have cut the attribution line and left the URL I posted. -- Ben. From arj.python at gmail.com Thu Jul 12 18:48:06 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 13 Jul 2018 02:48:06 +0400 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: if linux boasts commits, python boasts community in any sphere, the human aspect of things reoccurs. python has not it's parallel in languages, for it has set up the pattern for rapid and effective amelioration besides those words, the core-devs said all what i had to say leader or not, you remain a steering guide Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > From rosuav at gmail.com Thu Jul 12 19:16:34 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Jul 2018 09:16:34 +1000 Subject: variable scope in try ... EXCEPT block. In-Reply-To: <6fac8fc5-e01d-4475-bb69-23b8cf931470@googlegroups.com> References: <87muuwrdmn.fsf@bsb.me.uk> <6fac8fc5-e01d-4475-bb69-23b8cf931470@googlegroups.com> Message-ID: On Fri, Jul 13, 2018 at 8:10 AM, wrote: > On Thursday, July 12, 2018 at 5:45:52 AM UTC-4, Ben Bacarisse wrote: >> aleiphoenix writes: >> >> [snip] >> >> When an exception has been assigned using as target, it is cleared at >> the end of the except clause. This is as if >> >> except E as N: >> foo >> >> was translated to >> >> except E as N: >> try: >> foo >> finally: >> del N > > Is there a downside of implementing > it similarly to this (untested): > > # generate a unique name for __except_N > except E as __except_N: > if 'N' in locals() or N in globals(): > __original_N = N > > N = __except_N > try: > foo() > finally: > del __except_N > > if '__original_N' in locals(): > N = __original_N > del __original_N > else: > del N Not sure, but here's a simpler implementation: except Exception as .err.0: print(.err.0) .err.0 = None del .err.0 In other words, exactly the same as the current behaviour, except that (sorry, pun intended) inside the block, the name is modified to something that can't actually be used. (The token ".err.0" functions like an actual local name, just one that's syntactically invalid and thus cannot ever conflict.) Once you exit the except block, the previous value will magically reappear, because it didn't go anywhere. Multiple except blocks - nested or separate - would have separate names (".err.1", ".err.2"), so they won't conflict with each other. ChrisA From __peter__ at web.de Thu Jul 12 19:41:58 2018 From: __peter__ at web.de (Peter Otten) Date: Fri, 13 Jul 2018 01:41:58 +0200 Subject: Python 3.6 can find cairo libs but not Python 2.7 References: Message-ID: D'Arcy Cain wrote: > $ python2.7 -c "import ctypes.util; > print(ctypes.util.find_library('cairo'))" > libcairo.so.2 > $ python3.6 -c "import ctypes.util; > print(ctypes.util.find_library('cairo'))" > None > > I have the 3.6 version of py-cairo installed. Any thoughts? > > NetBSD 7.1.2 Wild guess: one Python is 64 bit and the other is 32 bit, and you have only one version of the library installed. From python at mrabarnett.plus.com Thu Jul 12 20:44:09 2018 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 13 Jul 2018 01:44:09 +0100 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On 2018-07-12 23:20, Roel Schroeven wrote: > Yes, you read that right: Guido van Rossum resigns as Python leader. > > See his mail: > (https://mail.python.org/pipermail/python-committers/2018-July/005664.html) > [snip] That's very sad news. I believe the usual practice in a dictatorship is for the eldest child to take over. BTW, I've identified some places in the code for the regex module where I'll be able to make use of := when the time comes... From aleiphoenix at gmail.com Thu Jul 12 21:42:39 2018 From: aleiphoenix at gmail.com (aleiphoenix) Date: Thu, 12 Jul 2018 18:42:39 -0700 (PDT) Subject: variable scope in try ... EXCEPT block. In-Reply-To: <6fac8fc5-e01d-4475-bb69-23b8cf931470@googlegroups.com> References: <87muuwrdmn.fsf@bsb.me.uk> <6fac8fc5-e01d-4475-bb69-23b8cf931470@googlegroups.com> Message-ID: <46aeb2b3-a428-4531-a4e5-fcce66d147b6@googlegroups.com> On Thursday, July 12, 2018 at 5:45:52 PM UTC+8, Ben Bacarisse wrote: > > Yes, it's intentional, but it's not exactly a scope. In > > https://docs.python.org/3/reference/compound_stmts.html#try > > -- > Ben. Thank you for the reply. Never thought of this kind of problem in Python3. On Thursday, July 12, 2018 at 6:02:27 PM UTC+8, Steven D'Aprano wrote: > > You can work around this by explicitly assigning to another local > variable: > > try: > ... > except Exception as e: > err = e # only "e" will be deleted when we exit the block > I ended up with workaround like this. > This is necessary in Python 3 (but not Python 2) because exception > objects form a reference cycle with something (the traceback?) which is a > big, heavyweight object. Allowing random exception objects to stay alive > for long periods was consuming unacceptable amounts of memory, so it was > decided to hit this problem with a hammer and fix it in the simplest, > although least elegant, way: just delete the exception when leaving the > except block. > > You can see the disassembled byte-code here. Here's the output from > Python 3.5: > > [assembly code] And thanks for the kind answer here. Guest I should dig into Python3 deeper. On Friday, July 13, 2018 at 6:10:57 AM UTC+8, codew... at gmail.com wrote: > > Is there a downside of implementing > it similarly to this (untested): > > # generate a unique name for __except_N > except E as __except_N: > if 'N' in locals() or N in globals(): > __original_N = N > > N = __except_N > try: > foo() > finally: > del __except_N > > if '__original_N' in locals(): > N = __original_N > del __original_N > else: > del N I prefer it like this. Thus, like said Python3 have chosen "fix it in the simplest, although least elegant", I guess. From steve+comp.lang.python at pearwood.info Thu Jul 12 21:57:18 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Jul 2018 01:57:18 +0000 (UTC) Subject: Hey Ranting Rick, this is your moment to shine! Message-ID: Hey Rick, if you're reading this, now that Guido has resigned, this is your opportunity to declare yourself as the true Heir and take over as BDFL. *runs and hides* Sorry-sometimes-I-can't-help-myself-I-would-have-deleted-this-post-but-I- already-hit-send-ly y'rs, -- Steven D'Aprano From skip.montanaro at gmail.com Thu Jul 12 22:00:51 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 12 Jul 2018 21:00:51 -0500 Subject: Is this a known futurize problem? Message-ID: I'm using futurize to update the SpamBayes codebase to Python 3. It doesn't seem to properly handle code which already has __future__ imports. When it wants to insert imports, it blindly puts them ahead of the earliest import, even if it happens to be a __future__ import. For example, here's the first diff chunk of spambayes/testtools/timtest.py: diff --git a/spambayes/testtools/timtest.py b/spambayes/testtools/timtest.py index 12eee81..5d8936f 100644 --- a/spambayes/testtools/timtest.py +++ b/spambayes/testtools/timtest.py @@ -31,7 +31,10 @@ If you only want to use some of the messages in each set, In addition, an attempt is made to merge bayescustomize.ini into the options. If that exists, it can be used to change the settings in Options.options. """ +from __future__ import print_function +from builtins import zip +from builtins import range from __future__ import generators import os I'm using version 0.16.0 (which appears to be the latest) with just the -0 and -w flags. Skip From nobody at gmail.com Thu Jul 12 22:31:35 2018 From: nobody at gmail.com (Travis McGee) Date: Thu, 12 Jul 2018 22:31:35 -0400 Subject: Google weirdness Message-ID: I somehow managed to trigger the dialog below by typing in a certain Python phrase to Google. Anyone know what it's about? It shows up in what appears to be terminal screen. Viz: Google has a code challenge ready for you. Been here before? This invitation will expire if you close this page. Success! You've managed to infiltrate Commander Lambda's evil organization, and finally earned yourself an entry-level position as a Minion on her space station. From here, you just might be able to subvert her plans to use the LAMBCHOP doomsday device to destroy Bunny Planet. Problem is, Minions are the lowest of the low in the Lambda hierarchy. Better buck up and get working, or you'll never make it to the top... For a list of commands type help. To get started with your first challenge type request. foobar:~/ guest$ From codewizard at gmail.com Fri Jul 13 00:44:07 2018 From: codewizard at gmail.com (codewizard at gmail.com) Date: Thu, 12 Jul 2018 21:44:07 -0700 (PDT) Subject: variable scope in try ... EXCEPT block. In-Reply-To: References: <87muuwrdmn.fsf@bsb.me.uk> <6fac8fc5-e01d-4475-bb69-23b8cf931470@googlegroups.com> Message-ID: <07eb7a25-5a11-4d53-b6a4-bea5d92b2549@googlegroups.com> On Thursday, July 12, 2018 at 7:16:48 PM UTC-4, Chris Angelico wrote: > On Fri, Jul 13, 2018 at 8:10 AM Igor wrote: > > On Thursday, July 12, 2018 at 5:45:52 AM UTC-4, Ben Bacarisse wrote: > >> aleiphoenix writes: > >> > >> [snip] > >> > >> When an exception has been assigned using as target, it is cleared at > >> the end of the except clause. This is as if > >> > >> except E as N: > >> foo > >> > >> was translated to > >> > >> except E as N: > >> try: > >> foo > >> finally: > >> del N > > > > Is there a downside of implementing > > it similarly to this (untested): > > > > # generate a unique name for __except_N > > except E as __except_N: > > if 'N' in locals() or N in globals(): > > __original_N = N > > > > N = __except_N > > try: > > foo() > > finally: > > del __except_N > > > > if '__original_N' in locals(): > > N = __original_N > > del __original_N > > else: > > del N > > Not sure, but here's a simpler implementation: > > except Exception as .err.0: > print(.err.0) > .err.0 = None > del .err.0 > > In other words, exactly the same as the current behaviour, except that > (sorry, pun intended) inside the block, the name is modified to > something that can't actually be used. (The token ".err.0" functions > like an actual local name, just one that's syntactically invalid and > thus cannot ever conflict.) Once you exit the except block, the > previous value will magically reappear, because it didn't go anywhere. > Multiple except blocks - nested or separate - would have separate > names (".err.1", ".err.2"), so they won't conflict with each other. > > ChrisA Simpler is better. The point is that something like this would accomplish both: 1. Break the reference cycle. 2. Avoid what is (IMHO) an unexpected behavior of a variable declared prior to try/except disappearing after getting shadowed by "except as". Regards, Igor. From rosuav at gmail.com Fri Jul 13 00:54:14 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Jul 2018 14:54:14 +1000 Subject: variable scope in try ... EXCEPT block. In-Reply-To: <07eb7a25-5a11-4d53-b6a4-bea5d92b2549@googlegroups.com> References: <87muuwrdmn.fsf@bsb.me.uk> <6fac8fc5-e01d-4475-bb69-23b8cf931470@googlegroups.com> <07eb7a25-5a11-4d53-b6a4-bea5d92b2549@googlegroups.com> Message-ID: On Fri, Jul 13, 2018 at 2:44 PM, wrote: > On Thursday, July 12, 2018 at 7:16:48 PM UTC-4, Chris Angelico wrote: >> Not sure, but here's a simpler implementation: >> >> except Exception as .err.0: >> print(.err.0) >> .err.0 = None >> del .err.0 >> >> In other words, exactly the same as the current behaviour, except that >> (sorry, pun intended) inside the block, the name is modified to >> something that can't actually be used. (The token ".err.0" functions >> like an actual local name, just one that's syntactically invalid and >> thus cannot ever conflict.) Once you exit the except block, the >> previous value will magically reappear, because it didn't go anywhere. >> Multiple except blocks - nested or separate - would have separate >> names (".err.1", ".err.2"), so they won't conflict with each other. >> >> ChrisA > > Simpler is better. The point is that something like this would accomplish both: > > 1. Break the reference cycle. > > 2. Avoid what is (IMHO) an unexpected behavior of a variable declared prior to try/except disappearing after getting shadowed by "except as". > Added bonus: I've already implemented the version I described. So if you want it, dig around on python-ideas and find where I posted it. ChrisA From tkadm30 at yandex.com Fri Jul 13 04:36:04 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Fri, 13 Jul 2018 04:36:04 -0400 Subject: Generic OAuth2 authorization inside view-based decorator/middleware? Message-ID: <19dd8161-89c8-8e2e-b502-9f90e3dbbb26@yandex.com> Hi! This is quick post about my current attempt to develop a specific GoogleController extension for django-hotsauce 0.9.6 in order to allow OAuth2 authentication and authorization on a regular Django view. Code: from notmm.controllers.wsgi import WSGIController, sessionmanager from wsgi_oauth2 import client __all__ = ['OAuthController'] class OAuthController(WSGIController): debug = True def __init__(self, **kwargs): super(OAuthController, self).__init__(**kwargs) class GoogleController(OAuthController): scope = 'email' def __init__(self, request, **kwargs): super(GoogleController, self).__init__() self._request = request self._client = client.GoogleClient( self.settings.OAUTH2_CLIENT_ID, access_token=self.settings.OAUTH2_ACCESS_TOKEN, scope=self.scope, redirect_url=self.settings.OAUTH2_REDIRECT_URL, ) def application(self, env, start_response): with sessionmanager(self.request): # wsgi_oauth2 response middleware response = self._client.wsgi_middleware(self.get_response(request=self.request), secret=self.settings.SECRET_KEY, login_path=self.settings.OAUTH2_LOGIN_URL) return response(env, start_response) Decorator: from functools import wraps from notmm.controllers.oauth import GoogleController from notmm.utils.django_settings import LazySettings _settings = LazySettings() __all__ = ('require_oauth', 'with_schevo_database',) def require_oauth(view_func): controller_class = GoogleController def decorator(view_func, **kwargs): def _wrapper(*args, **kwargs): req = args[0] wsgi_app = controller_class(req, **kwargs) # XXX this does not work :-) response = wsgi_app.get_response(request=req) return response return wraps(view_func)(_wrapper, **kwargs) return decorator(view_func) I would like to know what's wrong with the code above... :-) Thank you, Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From darcy at VybeNetworks.com Fri Jul 13 06:18:29 2018 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Fri, 13 Jul 2018 06:18:29 -0400 Subject: Python 3.6 can find cairo libs but not Python 2.7 In-Reply-To: References: Message-ID: <2f91969b-8a97-5729-db53-d2f9023fc74f@VybeNetworks.com> On 2018-07-12 04:17 PM, Terry Reedy wrote: > On 7/12/2018 3:52 PM, D'Arcy Cain wrote: >> $ python2.7 -c "import ctypes.util; >> print(ctypes.util.find_library('cairo'))" >> libcairo.so.2 >> $ python3.6 -c "import ctypes.util; >> print(ctypes.util.find_library('cairo'))" >> None >> >> I have the 3.6 version of py-cairo installed.? Any thoughts? >> >> NetBSD 7.1.2 > > what is sys.path?? Where in py-cairo installed? For 3.6 it includes '/usr/pkg/lib/python3.6/site-packages' and for 2.7 it includes '/usr/pkg/lib/python2.7/site-packages'. The py-cairo files are in the 3.6 site-packages. There are no Cairo files in the 2.7 Python directory. I'm not sure why that matters though. It's the system libraries that it can't find unless having py-cairo installed is somehow blocking the search for the libraries. Of course, my actual use depends on a cairo package. In fact, the failure that led me to the above issue happens when I load cairocffi. $ python3.6 -c "import cairocffi" Traceback (most recent call last): File "", line 1, in File "/usr/pkg/lib/python3.6/site-packages/cairocffi/__init__.py", line 41, in cairo = dlopen(ffi, 'cairo', 'cairo-2') File "/usr/pkg/lib/python3.6/site-packages/cairocffi/__init__.py", line 38, in dlopen raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names)) OSError: dlopen() failed to load a library: cairo / cairo-2 -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From darcy at VybeNetworks.com Fri Jul 13 06:21:28 2018 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Fri, 13 Jul 2018 06:21:28 -0400 Subject: Python 3.6 can find cairo libs but not Python 2.7 In-Reply-To: References: Message-ID: <72d590d2-d1c6-5e88-6f89-8b7125477154@VybeNetworks.com> On 2018-07-12 07:41 PM, Peter Otten wrote: > Wild guess: one Python is 64 bit and the other is 32 bit, and you have only > one version of the library installed. Nope. Both are 64 bit. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From bc at freeuk.com Fri Jul 13 06:37:41 2018 From: bc at freeuk.com (Bart) Date: Fri, 13 Jul 2018 11:37:41 +0100 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On 13/07/2018 01:44, MRAB wrote: > On 2018-07-12 23:20, Roel Schroeven wrote: >> Yes, you read that right: Guido van Rossum resigns as Python leader. >> >> See his mail: >> (https://mail.python.org/pipermail/python-committers/2018-July/005664.html) >> >> > [snip] > > That's very sad news. And all over PEP 572 which apparently is Chris' proposal to introduce ":=" assignment expressions**. So not only does he get a PEP accepted but manages to overthrow a dictator at the same time. Good going! (** Something so radical I've been using them elsewhere since forever.) -- bart From breamoreboy at gmail.com Fri Jul 13 07:46:45 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Fri, 13 Jul 2018 12:46:45 +0100 Subject: Hey Ranting Rick, this is your moment to shine! In-Reply-To: References: Message-ID: On 13/07/18 02:57, Steven D'Aprano wrote: > Hey Rick, if you're reading this, now that Guido has resigned, this is > your opportunity to declare yourself as the true Heir and take over as > BDFL. I though that he'd done this years ago. Are you aware that the 11th commandment is "Thou shalt not extract the urine"? :) > > *runs and hides* > > Sorry-sometimes-I-can't-help-myself-I-would-have-deleted-this-post-but-I- > already-hit-send-ly y'rs, > -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From __peter__ at web.de Fri Jul 13 08:05:04 2018 From: __peter__ at web.de (Peter Otten) Date: Fri, 13 Jul 2018 14:05:04 +0200 Subject: Python 3.6 can find cairo libs but not Python 2.7 References: <72d590d2-d1c6-5e88-6f89-8b7125477154@VybeNetworks.com> Message-ID: D'Arcy Cain wrote: > On 2018-07-12 07:41 PM, Peter Otten wrote: >> Wild guess: one Python is 64 bit and the other is 32 bit, and you have >> only one version of the library installed. > > Nope. Both are 64 bit. Just to be 100% sure, what does $ python2.7 -c 'import struct; print(struct.calcsize("l"))' $ python3.6 -c 'import struct; print(struct.calcsize("l"))' print? If both print 8, what is sys.platform? (This is just that I can look at the right branch of the ctypes.util source for differences)? From rosuav at gmail.com Fri Jul 13 08:29:29 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Jul 2018 22:29:29 +1000 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On Fri, Jul 13, 2018 at 8:37 PM, Bart wrote: > On 13/07/2018 01:44, MRAB wrote: >> >> On 2018-07-12 23:20, Roel Schroeven wrote: >>> >>> Yes, you read that right: Guido van Rossum resigns as Python leader. >>> >>> See his mail: >>> >>> (https://mail.python.org/pipermail/python-committers/2018-July/005664.html) >>> >> [snip] >> >> That's very sad news. > > > And all over PEP 572 which apparently is Chris' proposal to introduce ":=" > assignment expressions**. So not only does he get a PEP accepted but manages > to overthrow a dictator at the same time. Good going! To be quite frank, the proposal would have quietly died on python-ideas if it hadn't been for Guido's explicit support early on. (I know this for sure because the same proposal HAS quietly died, more than once.) The controversy came because the rest of the world disagreed with Guido, not because of anything that I am capable of in myself. ChrisA From steve+comp.lang.python at pearwood.info Fri Jul 13 08:33:27 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Jul 2018 12:33:27 +0000 (UTC) Subject: Guido van Rossum resigns as Python leader References: Message-ID: On Fri, 13 Jul 2018 11:37:41 +0100, Bart wrote: > (** Something so radical I've been using them elsewhere since forever.) And you just can't resist making it about you and your language. "Hey Bart, did you hear? Nuclear war just broke out between Russia and Britain. Dozens of cities are aflame, tens of millions are dead across Europe, and a cloud of radioactive smoke is heading our way!" "Yes, I know, my language has a built-in command that analyzes news reports collated from 800 news sites over the internet and tallies up the death tolls from wars and major disasters. I've been using it since 1973. Doesn't Python have the same?" -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Fri Jul 13 08:36:43 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Jul 2018 12:36:43 +0000 (UTC) Subject: Google weirdness References: Message-ID: On Thu, 12 Jul 2018 22:31:35 -0400, Travis McGee wrote: > I somehow managed to trigger the dialog below by typing in a certain > Python phrase to Google. Is the phrase a secret? > Anyone know what it's about? My guess is that either: 1) You have accidentally discovered a back door through Google's firewalls and security, and now have total control over their entire network of tens of thousands of computers around the world; or 2) it's an Easter egg and coding challenge. My money is on number 1. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Fri Jul 13 08:43:34 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Jul 2018 12:43:34 +0000 (UTC) Subject: Guido van Rossum resigns as Python leader References: Message-ID: On Fri, 13 Jul 2018 22:29:29 +1000, Chris Angelico wrote: > To be quite frank, the proposal would have quietly died on python-ideas > if it hadn't been for Guido's explicit support early on. (I know this > for sure because the same proposal HAS quietly died, more than once.) > The controversy came because the rest of the world disagreed with Guido, > not because of anything that I am capable of in myself. I think Guido's post makes it fairly clear that what pushed him over the edge was not the opposition to the PEP in the first place, but (extrapolating from his comments) the levels of abuse he (probably) received privately and on social media after his announcement was made. The downside of being the visible face of a popular language while having a publicly visible email address. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From e+python-list at kellett.im Fri Jul 13 08:43:54 2018 From: e+python-list at kellett.im (Ed Kellett) Date: Fri, 13 Jul 2018 13:43:54 +0100 Subject: variable scope in try ... EXCEPT block. In-Reply-To: References: Message-ID: On 2018-07-12 18:00, Chris Angelico wrote: > What do you mean by "fix"? Make the 'x' bind eagerly? That would break > basically every other use of closures. No. I mean make each x a new variable--closures would work as before, for-loops would change. If we have subscopes, it seems natural that entering a subscope multiple times creates a new instance of that subscope's namespace. From steve+comp.lang.python at pearwood.info Fri Jul 13 09:09:44 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Jul 2018 13:09:44 +0000 (UTC) Subject: Enabling and disabling custom wanings Message-ID: I have a warning that my code generates using the warning module: https://docs.python.org/3/library/warnings.html def spam(n): if n < 10: warnings.warn("not enough spam!") return "spam" * n By default, I want this warning to be disabled, but I want the user to be able to enable or disable that warning at runtime. This is the code I use: def enable(): warnings.filterwarnings("always", category=UserWarning, module=__name__) def disable(): warnings.filterwarnings("ignore", category=UserWarning, module=__name__) Am I doing it right? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From darcy at VybeNetworks.com Fri Jul 13 09:29:49 2018 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Fri, 13 Jul 2018 09:29:49 -0400 Subject: Python 3.6 can find cairo libs but not Python 2.7 In-Reply-To: References: <72d590d2-d1c6-5e88-6f89-8b7125477154@VybeNetworks.com> Message-ID: <3644c7bd-1e3e-73c7-18cf-24b923be1853@VybeNetworks.com> On 2018-07-13 08:05 AM, Peter Otten wrote: > D'Arcy Cain wrote: >> Nope. Both are 64 bit. > > Just to be 100% sure, what does > > $ python2.7 -c 'import struct; print(struct.calcsize("l"))' > > $ python3.6 -c 'import struct; print(struct.calcsize("l"))' > > print? $ python2.7 -c 'import struct; print(struct.calcsize("l"))' 8 $ python3.6 -c 'import struct; print(struct.calcsize("l"))' 8 > If both print 8, what is sys.platform? (This is just that I can look at the > right branch of the ctypes.util source for differences)? $ python2.7 -c 'import sys; print(sys.platform)' netbsd7 $ python3.6 -c 'import sys; print(sys.platform)' netbsd7 Thanks for checking this. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From nicholas.cole at gmail.com Fri Jul 13 09:54:11 2018 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Fri, 13 Jul 2018 09:54:11 -0400 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On Fri, 13 Jul 2018 at 08:51, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Fri, 13 Jul 2018 22:29:29 +1000, Chris Angelico wrote: > > > To be quite frank, the proposal would have quietly died on python-ideas > > if it hadn't been for Guido's explicit support early on. (I know this > > for sure because the same proposal HAS quietly died, more than once.) > > The controversy came because the rest of the world disagreed with Guido, > > not because of anything that I am capable of in myself. > > I think Guido's post makes it fairly clear that what pushed him over the > edge was not the opposition to the PEP in the first place, but > (extrapolating from his comments) the levels of abuse he (probably) > received privately and on social media after his announcement was made. > > The downside of being the visible face of a popular language while having > a publicly visible email address. > > Oh people are awful. I hope (though don?t expect) he will change his mind. Is it irrational to wonder whether projects should be looking to migrate to new languages? This kind of announcement makes me worry for the future. Nicholas. From rosuav at gmail.com Fri Jul 13 09:58:40 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 13 Jul 2018 23:58:40 +1000 Subject: variable scope in try ... EXCEPT block. In-Reply-To: References: Message-ID: On Fri, Jul 13, 2018 at 10:43 PM, Ed Kellett wrote: > On 2018-07-12 18:00, Chris Angelico wrote: >> What do you mean by "fix"? Make the 'x' bind eagerly? That would break >> basically every other use of closures. > > No. I mean make each x a new variable--closures would work as before, > for-loops would change. If we have subscopes, it seems natural that > entering a subscope multiple times creates a new instance of that > subscope's namespace. Wait, "if we have subscopes"? Nobody's suggesting that a for loop would introduce a subscope. That would completely and utterly destroy any code that uses the iteration variable post-loop. ChrisA From rosuav at gmail.com Fri Jul 13 10:03:41 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Jul 2018 00:03:41 +1000 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On Fri, Jul 13, 2018 at 11:54 PM, Nicholas Cole wrote: > Is it irrational to wonder whether projects should be looking to migrate to > new languages? This kind of announcement makes me worry for the future. > The Python committers are currently in charge. If you don't trust them, you should have jumped ship ages ago. :) ChrisA From midrangel at agiletecharch.com Fri Jul 13 10:23:35 2018 From: midrangel at agiletecharch.com (Jim Oberholtzer) Date: Fri, 13 Jul 2018 09:23:35 -0500 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: <169601d41ab5$15f75340$41e5f9c0$@agiletecharch.com> Nicholas: I am relatively new to Python, and my system of choice, IBM i on POWER, now supports Python directly. The open source movement is so strong that I think Python will be just fine. I've been a system programmer for 35 years, and this tooling (along with the 1000's APIs that IBM has put into IBM i (OS/400, iSeries, System I, all the same thing) over the years makes this one of the most powerful tools I have in my toolkit. Might there be a bit of chaos for a while, sure, there always is when the unexpected occurs, however I sympathize with Guido in many ways since 90% of people will jump on a target just because it's a target, without even knowing or caring about the underlying issue. It's today's hyper-partisan world where the internet shields people from direct contact and thus the responsibility for what you say and do. That's why I always sign my posts with my real name and include my company name, to ensure to don't get involved in flame wars etc. While I'm genuinely sad to see that Guido chose to bow out under these circumstances, I also see a bright future. Remember, the addition of the POWER line of servers in IBM i (yes AIX and Linux run there too) adds a significant number of shops that might adopt Python. That means Python is growing on its own. The legacy is written already, it will just get better. -- Jim Oberholtzer Agile Technology Architects -----Original Message----- From: Python-list [mailto:python-list-bounces+midrangel=agiletecharch.com at python.org] On Behalf Of Nicholas Cole Sent: Friday, July 13, 2018 8:54 AM To: python-list at python.org Subject: Re: Guido van Rossum resigns as Python leader On Fri, 13 Jul 2018 at 08:51, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Fri, 13 Jul 2018 22:29:29 +1000, Chris Angelico wrote: > > > To be quite frank, the proposal would have quietly died on > > python-ideas if it hadn't been for Guido's explicit support early > > on. (I know this for sure because the same proposal HAS quietly > > died, more than once.) The controversy came because the rest of the > > world disagreed with Guido, not because of anything that I am capable of in myself. > > I think Guido's post makes it fairly clear that what pushed him over > the edge was not the opposition to the PEP in the first place, but > (extrapolating from his comments) the levels of abuse he (probably) > received privately and on social media after his announcement was made. > > The downside of being the visible face of a popular language while > having a publicly visible email address. > > Oh people are awful. I hope (though don?t expect) he will change his mind. Is it irrational to wonder whether projects should be looking to migrate to new languages? This kind of announcement makes me worry for the future. Nicholas. -- https://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Fri Jul 13 10:28:32 2018 From: __peter__ at web.de (Peter Otten) Date: Fri, 13 Jul 2018 16:28:32 +0200 Subject: Python 3.6 can find cairo libs but not Python 2.7 References: <72d590d2-d1c6-5e88-6f89-8b7125477154@VybeNetworks.com> <3644c7bd-1e3e-73c7-18cf-24b923be1853@VybeNetworks.com> Message-ID: D'Arcy Cain wrote: > On 2018-07-13 08:05 AM, Peter Otten wrote: >> D'Arcy Cain wrote: >>> Nope. Both are 64 bit. >> >> Just to be 100% sure, what does >> >> $ python2.7 -c 'import struct; print(struct.calcsize("l"))' >> >> $ python3.6 -c 'import struct; print(struct.calcsize("l"))' >> >> print? > > $ python2.7 -c 'import struct; print(struct.calcsize("l"))' > 8 > $ python3.6 -c 'import struct; print(struct.calcsize("l"))' > 8 > >> If both print 8, what is sys.platform? (This is just that I can look at >> the right branch of the ctypes.util source for differences)? > > $ python2.7 -c 'import sys; print(sys.platform)' > netbsd7 > $ python3.6 -c 'import sys; print(sys.platform)' > netbsd7 > > Thanks for checking this. As far as I can see -- without having access to a netbsd machine -- this leads to the standard 'posix' implementation of find_library() which in both Python 2 and 3 runs /sbin/ldconfig and then searches its output with a regex. On my (linux) machine that regex is the same for both python 2.7 and 3.6: $ python3.6 -c 'import sys; sys.platform="netbsd7"; from ctypes import util; print(util.find_library("cairo"))' XXX b'\\s+(libcairo\\.[^\\s]+)\\s+\\(libc6,x86-64' libcairo.so.2 $ python2.7 -c 'import sys; sys.platform="netbsd7"; from ctypes import util; print(util.find_library("cairo"))' YYY '\\s+(libcairo\\.[^\\s]+)\\s+\\(libc6,x86-64' libcairo.so.2 Given the implementation def find_library(name): return _findSoname_ldconfig(name) or _get_soname(_findLib_gcc(name)) you might try calling _findSoname_ldconfig() directly -- if it fails for both 2.7 and 3.6 the next step would be to have a look at the fallback. From bill at baddogconsulting.com Fri Jul 13 10:36:02 2018 From: bill at baddogconsulting.com (Bill Deegan) Date: Fri, 13 Jul 2018 07:36:02 -0700 Subject: Google weirdness In-Reply-To: References: Message-ID: I also got such. I'm guessing your track record of searches has flagged you as someone they might want to hire. On Fri, Jul 13, 2018 at 5:36 AM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Thu, 12 Jul 2018 22:31:35 -0400, Travis McGee wrote: > > > I somehow managed to trigger the dialog below by typing in a certain > > Python phrase to Google. > > Is the phrase a secret? > > > > Anyone know what it's about? > > My guess is that either: > > 1) You have accidentally discovered a back door through Google's > firewalls and security, and now have total control over their entire > network of tens of thousands of computers around the world; or > > 2) it's an Easter egg and coding challenge. > > > My money is on number 1. > > > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson > > -- > https://mail.python.org/mailman/listinfo/python-list > From darcy at VybeNetworks.com Fri Jul 13 10:48:34 2018 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Fri, 13 Jul 2018 10:48:34 -0400 Subject: Python 3.6 can find cairo libs but not Python 2.7 In-Reply-To: References: <72d590d2-d1c6-5e88-6f89-8b7125477154@VybeNetworks.com> <3644c7bd-1e3e-73c7-18cf-24b923be1853@VybeNetworks.com> Message-ID: On 2018-07-13 10:28 AM, Peter Otten wrote: > As far as I can see -- without having access to a netbsd machine -- this Would it help if I gave you a login on one? Interestingly, I don't have this issue on my NetBSD machine built from HEAD. Maybe it is something that was fixed but not pulled up to 7. More weirdness - I do have the issue on my HEAD system but only with 3.7. I can give you an account on that server as well. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From nicholas.cole at gmail.com Fri Jul 13 11:14:06 2018 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Fri, 13 Jul 2018 11:14:06 -0400 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On Fri, 13 Jul 2018 at 10:04, Chris Angelico wrote: > On Fri, Jul 13, 2018 at 11:54 PM, Nicholas Cole > wrote: > > Is it irrational to wonder whether projects should be looking to migrate > to > > new languages? This kind of announcement makes me worry for the future. > > > > The Python committers are currently in charge. If you don't trust > them, you should have jumped ship ages ago. :) It?s a fair point. I guess until this day I hadn?t really examined *why* I trusted Python, but a lot of it had to do with the fact that I trusted the project lead to make sensible decisions about evolving the language. Every time he?s made a call in the past that struck me as odd it has turned out to be for the best. But I manage a project that needs to answer questions on ?sustainability? all the time ? I guess that a lot of questions in that area recently have made this annxement seem more alarming than it might otherwise. Best wishes, Nicholas. > From nicholas.cole at gmail.com Fri Jul 13 11:16:20 2018 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Fri, 13 Jul 2018 11:16:20 -0400 Subject: Guido van Rossum resigns as Python leader In-Reply-To: <169601d41ab5$15f75340$41e5f9c0$@agiletecharch.com> References: <169601d41ab5$15f75340$41e5f9c0$@agiletecharch.com> Message-ID: On Fri, 13 Jul 2018 at 10:31, Jim Oberholtzer wrote: > Nicholas: > > I am relatively new to Python, and my system of choice, IBM i on POWER, > now supports Python directly. The open source movement is so strong that I > think Python will be just fine. I've been a system programmer for 35 > years, and this tooling (along with the 1000's APIs that IBM has put into > IBM i (OS/400, iSeries, System I, all the same thing) over the years makes > this one of the most powerful tools I have in my toolkit. > > Might there be a bit of chaos for a while, sure, there always is when the > unexpected occurs, however I sympathize with Guido in many ways since 90% > of people will jump on a target just because it's a target, without even > knowing or caring about the underlying issue. It's today's hyper-partisan > world where the internet shields people from direct contact and thus the > responsibility for what you say and do. That's why I always sign my posts > with my real name and include my company name, to ensure to don't get > involved in flame wars etc. > > While I'm genuinely sad to see that Guido chose to bow out under these > circumstances, I also see a bright future. Remember, the addition of the > POWER line of servers in IBM i (yes AIX and Linux run there too) adds a > significant number of shops that might adopt Python. That means Python is > growing on its own. The legacy is written already, it will just get > better. Jim, Thank you for this very measured and civilized reply Nicholas. > > From bc at freeuk.com Fri Jul 13 11:16:43 2018 From: bc at freeuk.com (Bart) Date: Fri, 13 Jul 2018 16:16:43 +0100 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On 13/07/2018 13:33, Steven D'Aprano wrote: > On Fri, 13 Jul 2018 11:37:41 +0100, Bart wrote: > >> (** Something so radical I've been using them elsewhere since forever.) > > And you just can't resist making it about you and your language. And you can't resist having a personal dig. You and others have given me some flak for bringing up certain simple features which I believe to be missing from Python, and there are endless discussions about why Python doesn't need them, with the fact that Python is so successful being the ultimate proof. And now lo and behold one of those basic features is green-lighted to be added to the language (although apparently with stiff opposition). BTW many language features I use including that one where inspired by Algol-68, while the use of ":=" for all assignments was pioneered even earlier; hardly my inventions. And actually, even C has assignment-expressions so anyone who's coded in C for decades could have said the same thing. > "Hey Bart, did you hear? Nuclear war just broke out between Russia and > Britain. Dozens of cities are aflame, tens of millions are dead across > Europe, and a cloud of radioactive smoke is heading our way!" Sorry, I thought this was a technical language newsgroup not about current affairs. From mal at europython.eu Fri Jul 13 11:21:14 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 13 Jul 2018 17:21:14 +0200 Subject: EuroPython 2018: Conference App available Message-ID: <0f45de14-c7f2-ce4d-89a1-32428eff2fa4@europython.eu> We will be switching to the late bird rates for tickets on Monday next week (July 16), so this is your last chance to get tickets at the regular rate, which is about 30% less than the late bird rate. * EuroPython 2018 Tickets * https://ep2018.europython.eu/en/registration/buy-tickets/ Late Bird Tickets ----------------- We will have the following categories of late bird ticket prices for the conference tickets: * Business conference ticket: EUR 750.00 excl. VAT, EUR 900.00 incl. 20% UK VAT (for people using Python to make a living) * Personal conference ticket: EUR 500.00 incl. 20% UK VAT (for people enjoying Python from home) Please note that we do not sell on-desk student tickets. Students who decide late will have to buy day passes or a personal ticket. Day Passes ---------- As in the past, we will also sell day passes for the conference. These allow attending the conference for a single day (Wednesday, Thursday or Friday; valid on the day you pick up the day pass): * Business conference day pass: EUR 375.00 excl. VAT, EUR 450.00 incl. 20% UK VAT (for people using Python to make a living) * Personal conference day pass: EUR 250.00 incl. 20% UK VAT (for people enjoying Python from home) * Student conference day pass: EUR 105.00 incl. 20% UK VAT (only available for pupils, students and postdoctoral researchers; please bring your student card or declaration from University, stating your affiliation, starting and end dates of your contract) Please see the registration page for full details of what is included in the ticket price. Also note that neither late bird tickets, nor day passes are refundable. 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/175849791367/europython-2018-late-bird-rates-and-day-passes Tweet: https://twitter.com/europython/status/1017788387561009152 Enjoy, -- EuroPython 2018 Team https://ep2018.europython.eu/ https://www.europython-society.org/ From arj.python at gmail.com Fri Jul 13 11:34:06 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 13 Jul 2018 19:34:06 +0400 Subject: Google weirdness In-Reply-To: References: Message-ID: euhh where is the original mail, may i ask? Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ On Fri, 13 Jul 2018, 16:42 Steven D'Aprano, < steve+comp.lang.python at pearwood.info> wrote: > On Thu, 12 Jul 2018 22:31:35 -0400, Travis McGee wrote: > > > I somehow managed to trigger the dialog below by typing in a certain > > Python phrase to Google. > > Is the phrase a secret? > > > > Anyone know what it's about? > > My guess is that either: > > 1) You have accidentally discovered a back door through Google's > firewalls and security, and now have total control over their entire > network of tens of thousands of computers around the world; or > > 2) it's an Easter egg and coding challenge. > > > My money is on number 1. > > > > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson > > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Fri Jul 13 11:52:01 2018 From: __peter__ at web.de (Peter Otten) Date: Fri, 13 Jul 2018 17:52:01 +0200 Subject: Python 3.6 can find cairo libs but not Python 2.7 References: <72d590d2-d1c6-5e88-6f89-8b7125477154@VybeNetworks.com> <3644c7bd-1e3e-73c7-18cf-24b923be1853@VybeNetworks.com> Message-ID: D'Arcy Cain wrote: > On 2018-07-13 10:28 AM, Peter Otten wrote: >> As far as I can see -- without having access to a netbsd machine -- this > > Would it help if I gave you a login on one? Sorry, no. > Interestingly, I don't have this issue on my NetBSD machine built from > HEAD. Maybe it is something that was fixed but not pulled up to 7. > > More weirdness - I do have the issue on my HEAD system but only with > 3.7. I can give you an account on that server as well. If you have a working 3.6 and a 3.7 that does not work the code in ctypes.util might be similar enough that you can spot suspicious changes in the diff between the two versions. From nimbiotics at gmail.com Fri Jul 13 12:14:27 2018 From: nimbiotics at gmail.com (Mario R. Osorio) Date: Fri, 13 Jul 2018 09:14:27 -0700 (PDT) Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: <8c156c03-6920-4773-b55a-3d43034ccfa5@googlegroups.com> On Friday, July 13, 2018 at 11:16:44 AM UTC-4, Bart wrote: > On 13/07/2018 13:33, Steven D'Aprano wrote: > > On Fri, 13 Jul 2018 11:37:41 +0100, Bart wrote: > > > >> (** Something so radical I've been using them elsewhere since forever.) > > > > And you just can't resist making it about you and your language. > > And you can't resist having a personal dig. > > You and others have given me some flak for bringing up certain simple > features which I believe to be missing from Python, and there are > endless discussions about why Python doesn't need them, with the fact > that Python is so successful being the ultimate proof. > > And now lo and behold one of those basic features is green-lighted to be > added to the language (although apparently with stiff opposition). > > BTW many language features I use including that one where inspired by > Algol-68, while the use of ":=" for all assignments was pioneered even > earlier; hardly my inventions. > > And actually, even C has assignment-expressions so anyone who's coded in > C for decades could have said the same thing. > > > "Hey Bart, did you hear? Nuclear war just broke out between Russia and > > Britain. Dozens of cities are aflame, tens of millions are dead across > > Europe, and a cloud of radioactive smoke is heading our way!" > > Sorry, I thought this was a technical language newsgroup not about > current affairs. You've made it a current affair issue... From arj.python at gmail.com Fri Jul 13 12:21:38 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 13 Jul 2018 20:21:38 +0400 Subject: Google weirdness In-Reply-To: References: Message-ID: exact found it ! thanks ! Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ On Fri, 13 Jul 2018, 20:19 Skip Montanaro, wrote: > > euhh where is the original mail, may i ask? > > Gmail routed the original to my spam folder. > > Skip > From arj.python at gmail.com Fri Jul 13 12:22:13 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 13 Jul 2018 20:22:13 +0400 Subject: Google weirdness In-Reply-To: References: Message-ID: btw google wants to hide even the mention of it? Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ From skip.montanaro at gmail.com Fri Jul 13 12:22:29 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 13 Jul 2018 11:22:29 -0500 Subject: Google weirdness In-Reply-To: References: Message-ID: > euhh where is the original mail, may i ask? Gmail routed the original to my spam folder. Skip From skip.montanaro at gmail.com Fri Jul 13 12:43:13 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 13 Jul 2018 11:43:13 -0500 Subject: Google weirdness In-Reply-To: References: Message-ID: > btw google wants to hide even the mention of it? From breamoreboy at gmail.com Fri Jul 13 13:01:04 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Fri, 13 Jul 2018 18:01:04 +0100 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On 13/07/18 16:16, Bart wrote: > On 13/07/2018 13:33, Steven D'Aprano wrote: >> On Fri, 13 Jul 2018 11:37:41 +0100, Bart wrote: >> >>> (** Something so radical I've been using them elsewhere since forever.) >> >> And you just can't resist making it about you and your language. > > And you can't resist having a personal dig. > You are a troll and should have been banned from this list years ago. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at gmail.com Fri Jul 13 13:02:58 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Fri, 13 Jul 2018 18:02:58 +0100 Subject: Guido van Rossum resigns as Python leader In-Reply-To: <8c156c03-6920-4773-b55a-3d43034ccfa5@googlegroups.com> References: <8c156c03-6920-4773-b55a-3d43034ccfa5@googlegroups.com> Message-ID: On 13/07/18 17:14, Mario R. Osorio wrote: > On Friday, July 13, 2018 at 11:16:44 AM UTC-4, Bart wrote: >> On 13/07/2018 13:33, Steven D'Aprano wrote: >>> On Fri, 13 Jul 2018 11:37:41 +0100, Bart wrote: >>> > > You've made it a current affair issue... > Please don't feed the troll, it's obvious that he's clueless. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From abrault at mapgears.com Fri Jul 13 13:37:24 2018 From: abrault at mapgears.com (Alexandre Brault) Date: Fri, 13 Jul 2018 13:37:24 -0400 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: The important question we should ask ourselves: Do we have a replacement Dutch person to figure out the one obvious way to do things that may not be obvious at first? Alex From rosuav at gmail.com Fri Jul 13 14:05:57 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Jul 2018 04:05:57 +1000 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On Sat, Jul 14, 2018 at 3:37 AM, Alexandre Brault wrote: > The important question we should ask ourselves: Do we have a replacement > Dutch person to figure out the one obvious way to do things that may not > be obvious at first? > We'll use distributed computing.. I, for example, had two Dutch grandparents, so I can contribute some obviousness to the farm; naturally it won't be as good as a dedicated Dutch server, but the donated Dutchness will be combined with other people's Dutchnesses (not to be confused with Duchesses), cross-referenced and cross-checked for validity, and eventually a 99.99% Dutch solution will be produced. ChrisA From larry.martell at gmail.com Fri Jul 13 14:14:59 2018 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 13 Jul 2018 14:14:59 -0400 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On Fri, Jul 13, 2018 at 2:05 PM, Chris Angelico wrote: > On Sat, Jul 14, 2018 at 3:37 AM, Alexandre Brault wrote: >> The important question we should ask ourselves: Do we have a replacement >> Dutch person to figure out the one obvious way to do things that may not >> be obvious at first? >> > > We'll use distributed computing.. I, for example, had two Dutch > grandparents, so I can contribute some obviousness to the farm; > naturally it won't be as good as a dedicated Dutch server, but the > donated Dutchness will be combined with other people's Dutchnesses > (not to be confused with Duchesses), cross-referenced and > cross-checked for validity, and eventually a 99.99% Dutch solution > will be produced. And while we're talking about the Dutch, why is the country called Holland, but then also The Netherlands, but the people are Dutch? From rosuav at gmail.com Fri Jul 13 14:26:08 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Jul 2018 04:26:08 +1000 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On Sat, Jul 14, 2018 at 4:14 AM, Larry Martell wrote: > On Fri, Jul 13, 2018 at 2:05 PM, Chris Angelico wrote: >> On Sat, Jul 14, 2018 at 3:37 AM, Alexandre Brault wrote: >>> The important question we should ask ourselves: Do we have a replacement >>> Dutch person to figure out the one obvious way to do things that may not >>> be obvious at first? >>> >> >> We'll use distributed computing.. I, for example, had two Dutch >> grandparents, so I can contribute some obviousness to the farm; >> naturally it won't be as good as a dedicated Dutch server, but the >> donated Dutchness will be combined with other people's Dutchnesses >> (not to be confused with Duchesses), cross-referenced and >> cross-checked for validity, and eventually a 99.99% Dutch solution >> will be produced. > > And while we're talking about the Dutch, why is the country called > Holland, but then also The Netherlands, but the people are Dutch? *engages obviousnessbot node* The obvious answer is this. Once upon a time, there were three gods: one of heaven, one of earth, and one of the afterlife. They argued and bickered, and eventually decided that they should write a long snake and give it to mankind. The snake purpled and oranged, but it was never able to blue. The end. (Caveat: There may still be some bugs in obviousnessbot.) ChrisA From jeanpierreda at gmail.com Fri Jul 13 14:27:29 2018 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 13 Jul 2018 11:27:29 -0700 Subject: Kindness In-Reply-To: References: Message-ID: On Fri, Jul 13, 2018 at 10:49 AM Mark Lawrence wrote: > > On 13/07/18 16:16, Bart wrote: > > On 13/07/2018 13:33, Steven D'Aprano wrote: > >> On Fri, 13 Jul 2018 11:37:41 +0100, Bart wrote: > >> > >>> (** Something so radical I've been using them elsewhere since forever.) > >> > >> And you just can't resist making it about you and your language. > > > > And you can't resist having a personal dig. > > > > You are a troll and should have been banned from this list years ago. This exchange is unacceptable. I don't know who Bart is or what their language is, but they left a basically OK (if kinda edgy) comment, and this was immediately escalated into a series of personal attacks. Not everyone is as familiar with the surrounding context. To me, it looks like you are all bullying someone. Even if you think it is justified, consider how it looks to others. I am afraid of ever getting on your "bad side", and I bet the same is true of other non-Bart people, too. -- Devin From larry.martell at gmail.com Fri Jul 13 14:36:28 2018 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 13 Jul 2018 14:36:28 -0400 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On Fri, Jul 13, 2018 at 2:26 PM, Chris Angelico wrote: > On Sat, Jul 14, 2018 at 4:14 AM, Larry Martell wrote: >> On Fri, Jul 13, 2018 at 2:05 PM, Chris Angelico wrote: >>> On Sat, Jul 14, 2018 at 3:37 AM, Alexandre Brault wrote: >>>> The important question we should ask ourselves: Do we have a replacement >>>> Dutch person to figure out the one obvious way to do things that may not >>>> be obvious at first? >>>> >>> >>> We'll use distributed computing.. I, for example, had two Dutch >>> grandparents, so I can contribute some obviousness to the farm; >>> naturally it won't be as good as a dedicated Dutch server, but the >>> donated Dutchness will be combined with other people's Dutchnesses >>> (not to be confused with Duchesses), cross-referenced and >>> cross-checked for validity, and eventually a 99.99% Dutch solution >>> will be produced. >> >> And while we're talking about the Dutch, why is the country called >> Holland, but then also The Netherlands, but the people are Dutch? > > *engages obviousnessbot node* > > The obvious answer is this. Once upon a time, there were three gods: > one of heaven, one of earth, and one of the afterlife. They argued and > bickered, and eventually decided that they should write a long snake > and give it to mankind. The snake purpled and oranged, but it was > never able to blue. The end. > > (Caveat: There may still be some bugs in obviousnessbot.) It's all Greek to me. From steve+comp.lang.python at pearwood.info Fri Jul 13 14:37:24 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Jul 2018 18:37:24 +0000 (UTC) Subject: Kindness References: Message-ID: On Fri, 13 Jul 2018 11:27:29 -0700, Devin Jeanpierre wrote: > I don't know who Bart is or what their language is Or apparently any of the context of the last six months (nine? twelve? how long has Bart been annoying people here? practically since his first post) of his interaction with the community here, or the fact that he's been kill-filed by probably half the regulars here. But nevertheless you felt qualified to state an opinion. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rhodri at kynesim.co.uk Fri Jul 13 14:52:45 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 13 Jul 2018 19:52:45 +0100 Subject: Kindness In-Reply-To: References: Message-ID: <063c290d-b10e-a3f8-93af-f6925920a0d4@kynesim.co.uk> On 13/07/18 19:27, Devin Jeanpierre wrote: > On Fri, Jul 13, 2018 at 10:49 AM Mark Lawrence wrote: >> >> On 13/07/18 16:16, Bart wrote: >>> On 13/07/2018 13:33, Steven D'Aprano wrote: >>>> On Fri, 13 Jul 2018 11:37:41 +0100, Bart wrote: >>>> >>>>> (** Something so radical I've been using them elsewhere since forever.) >>>> >>>> And you just can't resist making it about you and your language. >>> >>> And you can't resist having a personal dig. >>> >> >> You are a troll and should have been banned from this list years ago. > > This exchange is unacceptable. I don't know who Bart is or what their > language is, but they left a basically OK (if kinda edgy) comment, and > this was immediately escalated into a series of personal attacks. An interesting point of view, particularly since Bart's immediate escalation in response to Steven's (entirely accurate) comment was also exactly what you are decrying. I'm not at all sure it's justifiable. > Not everyone is as familiar with the surrounding context. Then you have had a remarkable escape. I'm fairly certain without going and trawling through the archives that Bart posts several times a week minimum. I see the posts go past though I don't read them any more; I killfiled him long ago for having too poor a signal-to-noise ratio to be worth wasting time on. In case you think I'm being snobbish about this, I should point out that the number of people I have killfiled in all my Internet dealings can be counted on the fingers of one hand. Honestly, I don't know why anybody bothers responding to him. Boredom, I suppose. -- Rhodri James *-* Kynesim Ltd From ethan at stoneleaf.us Fri Jul 13 14:58:21 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 13 Jul 2018 11:58:21 -0700 Subject: Kindness In-Reply-To: References: Message-ID: <5B48F64D.4040804@stoneleaf.us> On 07/13/2018 11:37 AM, Steven D'Aprano wrote: > On Fri, 13 Jul 2018 11:27:29 -0700, Devin Jeanpierre wrote: >> [a reminder to be kind] > > [ignored the reminder] Does anything good come from engaging with Bart? I haven't seen it yet. Seems to me the solution is not to engage. "If you're not part of the solution, you're part of the problem." -- ~Ethan~ From ethan at stoneleaf.us Fri Jul 13 15:46:17 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 13 Jul 2018 12:46:17 -0700 Subject: Kindness In-Reply-To: <063c290d-b10e-a3f8-93af-f6925920a0d4@kynesim.co.uk> References: <063c290d-b10e-a3f8-93af-f6925920a0d4@kynesim.co.uk> Message-ID: <5B490189.1000800@stoneleaf.us> On 07/13/2018 11:52 AM, Rhodri James wrote: > I should point out that the number of people I have killfiled in all my > Internet dealings can be counted on the fingers of one hand. Your left one? * -- ~Ethan~ * Bonus points for getting the reference. ;) From marko at pacujo.net Fri Jul 13 16:36:31 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 13 Jul 2018 23:36:31 +0300 Subject: Guido van Rossum resigns as Python leader References: Message-ID: <87va9i6fg0.fsf@elektro.pacujo.net> Larry Martell : > And while we're talking about the Dutch, why is the country called > Holland, but then also The Netherlands, but the people are Dutch? The Netherlands is a latter-day innovation. Holland is the central region of the Netherlands. Compare that with the UK and England. As for why they are called Dutch, see Generally Germanic peoples called themselves Dutch. Marko From bc at freeuk.com Fri Jul 13 17:16:16 2018 From: bc at freeuk.com (Bart) Date: Fri, 13 Jul 2018 22:16:16 +0100 Subject: Kindness In-Reply-To: <87r2k66f51.fsf@elektro.pacujo.net> References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> Message-ID: On 13/07/2018 21:43, Marko Rauhamaa wrote: > Ethan Furman : >> Does anything good come from engaging with Bart? I haven't seen it >> yet. Seems to me the solution is not to engage. > > He must be a very lonely person as he keeps coming here for repeated > beatings from the regulars. You are admitting they are 'beatings'? It doesn't make it sound very welcoming to newcomers does it? If you look at my posting history, my contributions start off low key but then people are intent on confrontation with someone who has different views, and I defend my position. It then escalates from there. I would also defend my right on a public newsgroup (I access it from usenet) to give my opinions about a programming language. People are welcome to disagree without descending into personal attacks. With regard to GvR's resignation partly due to disagreements, I can fully empathise. Here are some online comments about it: "Python's community is definitely a very opinionated one (but which one isn't?). It's not the first time that Guido indirectly mentions how stubborn and divided the community becomes around some PEPs." "What's bad is that people get so fanatical in their opinion about some issue, that they forget to show respect. Some people are so self-absorbed that they really don't "see" this ... lack of ability to empathize with others. The point is not to worship the leader, it's just about treating people (everyone) with respect - that's what makes or breaks a community." "For those who are curious, I looked up PEP 572. It's about adding an assignment expression (think in JS, while (token = loop()) {}. It's been approved." This last is pretty much what I said, complete with a tangential remark about how ubiquitous such a thing is elsewhere, which lead to the comment about nuclear war with Russia, whatever that was about. I think if anyone else had made that exact same post, it would not have had that reaction. This group is openly hostile and unwelcoming. -- bart From rosuav at gmail.com Fri Jul 13 17:28:58 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Jul 2018 07:28:58 +1000 Subject: Kindness In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> Message-ID: On Sat, Jul 14, 2018 at 7:16 AM, Bart wrote: > This group is openly hostile and unwelcoming. Have you noticed how a lot of the hostility seems to happen shortly after you make your posts about how Python sucks compared to your nameless and unpublished language? Oh, sorry, I mean "how Python lacks basic features that your language just happens to tick all the boxes on". People who come in and ask genuine questions about Python seem to find the group far more welcoming and helpful. ChrisA From marko at pacujo.net Fri Jul 13 17:45:00 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 14 Jul 2018 00:45:00 +0300 Subject: Kindness References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> Message-ID: <87muuu6c9v.fsf@elektro.pacujo.net> Chris Angelico : > On Sat, Jul 14, 2018 at 7:16 AM, Bart wrote: >> This group is openly hostile and unwelcoming. > > Have you noticed how a lot of the hostility seems to happen shortly > after you make your posts about how Python sucks compared to your > nameless and unpublished language? That's no excuse for hostility. > Oh, sorry, I mean "how Python lacks basic features that your language > just happens to tick all the boxes on". People who come in and ask > genuine questions about Python seem to find the group far more > welcoming and helpful. Yeah, that is cult behavior. Here's a few boxes to tick on: Marko From tzotzioy at gmail.com Fri Jul 13 17:58:33 2018 From: tzotzioy at gmail.com (=?UTF-8?B?zqTOls6pzqTOls6Zzp/OpQ==?=) Date: Fri, 13 Jul 2018 14:58:33 -0700 (PDT) Subject: =?UTF-8?Q?So_assignment_expressions_in_generators=E2=80=A6?= Message-ID: <72c9015b-3a75-41cd-b8aa-0737310455ed@googlegroups.com> ?will normally issue STORE_DEREF opcodes for the assignment? This is what I understand from reading PEP-572, just wanted to ask whether I got it right. Example of what I'm referring to: def f(): return ( (s := x*x) for x in range(5)) From tzotzioy at gmail.com Fri Jul 13 18:06:37 2018 From: tzotzioy at gmail.com (=?UTF-8?B?zqTOls6pzqTOls6Zzp/OpQ==?=) Date: Fri, 13 Jul 2018 15:06:37 -0700 (PDT) Subject: =?UTF-8?Q?So_assignment_expressions_in_generators=E2=80=A6?= In-Reply-To: <72c9015b-3a75-41cd-b8aa-0737310455ed@googlegroups.com> References: <72c9015b-3a75-41cd-b8aa-0737310455ed@googlegroups.com> Message-ID: Self correction: assignment expressions in generator comprehensions inside a function body. From rshepard at appl-ecosys.com Fri Jul 13 18:27:49 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 13 Jul 2018 15:27:49 -0700 (PDT) Subject: Guido van Rossum resigns as Python leader In-Reply-To: <87va9i6fg0.fsf@elektro.pacujo.net> References: <87va9i6fg0.fsf@elektro.pacujo.net> Message-ID: On Fri, 13 Jul 2018, Marko Rauhamaa wrote: > The Netherlands is a latter-day innovation. Holland is the central region > of the Netherlands. Compare that with the UK and England. > > As for why they are called Dutch, see > > > > Generally Germanic peoples called themselves Dutch. Marko, Thank you for an answer to a question it never occurred to me to ask. I appreciate the lesson. Carpe weekend, Rich From darcy at VybeNetworks.com Fri Jul 13 19:04:39 2018 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Fri, 13 Jul 2018 19:04:39 -0400 Subject: Kindness In-Reply-To: <87muuu6c9v.fsf@elektro.pacujo.net> References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> Message-ID: On 2018-07-13 05:45 PM, Marko Rauhamaa wrote: > Yeah, that is cult behavior. Here's a few boxes to tick on: > > I couldn't find a single item that applies to this group. What's your point? -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From steve+comp.lang.python at pearwood.info Fri Jul 13 19:56:29 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 13 Jul 2018 23:56:29 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> Message-ID: On Fri, 13 Jul 2018 19:04:39 -0400, D'Arcy Cain wrote: > On 2018-07-13 05:45 PM, Marko Rauhamaa wrote: >> Yeah, that is cult behavior. Here's a few boxes to tick on: >> >> > > I couldn't find a single item that applies to this group. What's your > point? I think that Marko sometimes likes to stir the ants nest by looking down at the rest of us and painting himself as the Lone Voice Of Sanity in a community gone mad *wink* Let's look at the very first point on the checklist: "The group displays excessively zealous and unquestioning commitment to its leader and (whether he is alive or dead) regards his belief system, ideology, and practices as the Truth, as law." Apparently Marko didn't notice the irony of suggesting that we display excessive commitment to GvR in the middle of a thread that started with Guido resigning his leadership position with these words: "I don't ever want to have to fight so hard for a PEP and find that so many people despise my decisions." Yeah, the *hundreds if not thousands* of emails, posts, tweets and other messages telling Guido off for getting it idiotically wrong *really* sounds like cultists taking the words of their leader as divine truth. /s -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From bc at freeuk.com Fri Jul 13 20:06:39 2018 From: bc at freeuk.com (Bart) Date: Sat, 14 Jul 2018 01:06:39 +0100 Subject: Kindness In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> Message-ID: On 13/07/2018 22:28, Chris Angelico wrote: > On Sat, Jul 14, 2018 at 7:16 AM, Bart wrote: >> This group is openly hostile and unwelcoming. > > Have you noticed how a lot of the hostility seems to happen shortly > after you make your posts about how Python sucks compared to your > nameless and unpublished language? Would it be any better if that language didn't exist but I just came up with the same criticisms and suggestions anyway? I'm sure they would be more appreciated when not backed up any knowledge or experience... Oh, sorry, I mean "how Python lacks > basic features that your language just happens to tick all the boxes > on". People who come in and ask genuine questions about Python seem to > find the group far more welcoming and helpful. Yes, that's one very useful purpose of such a group. To not question the language at all, deny the existence of anything else, and simply use what it already has to solve whatever coding problems people have. Another can be to look more objectively, more critically at the language itself, make comparisons, discuss what things could usefully be added (eg. assignment expressions) or removed, all that sort of thing. Fewer people are interested in that, because most people will just use the languages as they are (or switch to another) and are not interested in changing it because they have a job to finish. Some appear to get very cross if someone dares say a word against a tool that for their purposes works adequately. However some of that does need to happen and has happened otherwise everyone would still be using version 1.0. -- bart From steve+comp.lang.python at pearwood.info Fri Jul 13 20:12:32 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 14 Jul 2018 00:12:32 +0000 (UTC) Subject: Kindness References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> Message-ID: On Sat, 14 Jul 2018 00:45:00 +0300, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sat, Jul 14, 2018 at 7:16 AM, Bart wrote: >>> This group is openly hostile and unwelcoming. >> >> Have you noticed how a lot of the hostility seems to happen shortly >> after you make your posts about how Python sucks compared to your >> nameless and unpublished language? > > That's no excuse for hostility. Isn't it? 1. How much rude and obnoxious behaviour from somebody are we supposed to accept before responding with hostility? 2. To what degree should groups be permitted to enforce group norms through social disapproval and hostility? 3. Is shunning and "the silent treatment" really a better (kinder?) response to bad behaviour than anger? These are serious questions, not rhetorical ones. In interpersonal and societal relationships, shunning is one of the cruelest and most toxic ways to deal with conflict short of physical abuse, but we've made it the norm on the internet. If somebody says something you don't like, block them, ignore them silently, don't respond to their messages, even hell-ban them on web forums. https://en.wikipedia.org/wiki/Shadow_banning -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Fri Jul 13 20:15:09 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Jul 2018 10:15:09 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> Message-ID: On Sat, Jul 14, 2018 at 9:56 AM, Steven D'Aprano wrote: > On Fri, 13 Jul 2018 19:04:39 -0400, D'Arcy Cain wrote: > >> On 2018-07-13 05:45 PM, Marko Rauhamaa wrote: >>> Yeah, that is cult behavior. Here's a few boxes to tick on: >>> >>> >> >> I couldn't find a single item that applies to this group. What's your >> point? > > I think that Marko sometimes likes to stir the ants nest by looking down > at the rest of us and painting himself as the Lone Voice Of Sanity in a > community gone mad *wink* > > Let's look at the very first point on the checklist: > > "The group displays excessively zealous and unquestioning > commitment to its leader and (whether he is alive or dead) > regards his belief system, ideology, and practices as the > Truth, as law." > > > Apparently Marko didn't notice the irony of suggesting that we display > excessive commitment to GvR in the middle of a thread that started with > Guido resigning his leadership position with these words: > > "I don't ever want to have to fight so hard for a PEP and > find that so many people despise my decisions." > > > Yeah, the *hundreds if not thousands* of emails, posts, tweets and other > messages telling Guido off for getting it idiotically wrong *really* > sounds like cultists taking the words of their leader as divine truth. /s > Ahh but you misunderstand. The cult does not worship Guido. It worships Tim Batchelder, an infallible being that few people have ever actually heard from. > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson You don't say. ChrisA From d.dalrymple at sbcglobal.net Fri Jul 13 20:48:15 2018 From: d.dalrymple at sbcglobal.net (dbd) Date: Fri, 13 Jul 2018 17:48:15 -0700 (PDT) Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> Message-ID: On Friday, July 13, 2018 at 4:59:06 PM UTC-7, Steven D'Aprano wrote: ... > I think that Marko sometimes likes to stir the ants nest by looking down > at the rest of us and painting himself as the Lone Voice Of Sanity in a > community gone mad *wink* ... You mean he thinks he's Ranting Rick? Dale B. Dalrymple From steve+comp.lang.python at pearwood.info Fri Jul 13 20:50:49 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 14 Jul 2018 00:50:49 +0000 (UTC) Subject: Kindness References: <063c290d-b10e-a3f8-93af-f6925920a0d4@kynesim.co.uk> Message-ID: On Fri, 13 Jul 2018 19:52:45 +0100, Rhodri James wrote: > Honestly, I don't know why anybody bothers responding to him. Boredom, > I suppose. I respond to Bart because I recognise he does bring a perspective and experience to the community which many of us lack. That makes his troll-like behaviour all the more obnoxious. As far as I can tell, he's not just a troll stirring up trouble for the LOLs, he's just oblivious to the annoyance factor of having him constantly smacking us on the nose with a rolled up newspaper (figuratively speaking) for making trade-offs in our programming language of choice that he doesn't approve of. Over the many months, I've tried defending Bart, engaging with him, patiently explaining that his choices and our choices are not always the same and that there's no objective "right" and "wrong" between them, making subtle hints, and less subtle hints that he's being a dick. It's not helped by do-gooders who by their own admission have no idea of the context sticking their nose in to tell off those who chastise Bart. Not even Mark Lawrence is in the habit of accusing people of being trolls with no provocation. (I think Mark is mistaken, in this case, but I understand his sentiments.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Fri Jul 13 20:54:39 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 14 Jul 2018 00:54:39 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> Message-ID: On Fri, 13 Jul 2018 17:48:15 -0700, dbd wrote: > On Friday, July 13, 2018 at 4:59:06 PM UTC-7, Steven D'Aprano wrote: ... >> I think that Marko sometimes likes to stir the ants nest by looking >> down at the rest of us and painting himself as the Lone Voice Of Sanity >> in a community gone mad *wink* > ... > > You mean he thinks he's Ranting Rick? No, I said only *sometimes* :-) Besides, Rick thinks that millions of the silent majority agree with everything he says. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From tjreedy at udel.edu Fri Jul 13 21:17:48 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 13 Jul 2018 21:17:48 -0400 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On 7/13/2018 9:54 AM, Nicholas Cole wrote: > Is it irrational to wonder whether projects should be looking to migrate to > new languages? At this point, I would say yes. The immediate effect is no more PEP approvals for maybe 3 months. > This kind of announcement makes me worry for the future. Forcing core developers to collectively not lean on Guido might release new energy and end up being a plus. It is certainly too soon to assume the opposite. -- Terry Jan Reedy From mikhailwas at gmail.com Fri Jul 13 22:19:36 2018 From: mikhailwas at gmail.com (Mikhail V) Date: Sat, 14 Jul 2018 05:19:36 +0300 Subject: Kindness Message-ID: Steven D'Aprano wrote: > Over the many months, I've tried defending Bart, engaging with him, > patiently explaining that his choices and our choices are not always the > same and that there's no objective "right" and "wrong" between them, > making subtle hints, and less subtle hints that he's being a dick. Calm down a bit. Of course it is good that you communicate with Bart - it seems to me he is an old dude and kind of over-nostalgic about his language or something. But I can not remember he ever insulted anybody here. Trolling and old man's grumbling are completely different things. > ... in our programming language .. > ... at the rest of us ... > ... we ... we ... we >From Marko's check-list: [ ] The group has a polarized us-versus-them mentality From robertvstepp at gmail.com Fri Jul 13 22:25:59 2018 From: robertvstepp at gmail.com (boB Stepp) Date: Fri, 13 Jul 2018 21:25:59 -0500 Subject: Kindness In-Reply-To: References: <063c290d-b10e-a3f8-93af-f6925920a0d4@kynesim.co.uk> Message-ID: On Fri, Jul 13, 2018 at 7:54 PM Steven D'Aprano wrote: > It's not helped by do-gooders who by their own admission have no idea of > the context sticking their nose in to tell off those who chastise Bart... I'm not sure if I am one of the "do-gooders" or not in your perspective, Steve. I have been sniffing around this list for about the past four years, so I believe I have a good understanding of the "context" you refer to. I just cannot help but think there must be a better way of interacting with Bart? But the last time I "stuck my nose in", Bart, by his own self-admission, stated he had no intentions of either contributing to Python or trying to properly learn Python. He is beginning to remind me of a curmudgeonly old uncle that many families have, that keeps unexpectedly popping in for a stay, leaving the family exasperated and wondering what to do as the uncle continually offers his unsolicited advice. But leaving all issues of Bart aside, the news of Mr. van Rossum abdicating his role of leadership leaves me wondering about the welcoming aspect of the Python community. If the creator himself apparently has been burdened by sharp criticisms of his decisions, something seems definitely awry. But I only occasionally poke about in the dev and ideas mail archives, and did not know about the committers one until yesterday, so I am definitely unqualified to comment here. However, I have been following this list for a few years now, and my emotional perception of this list is that its "snarky content" has been gradually rising over this time frame. Of course this is just my perception, unbacked by data, and I freely admit I may be mistaken. But I wonder ... A few weeks ago I spent a good chunk of my weekend looking at this list's Gmane archives from the earliest years available. I did not read every post, but I don't recall stumbling onto any of the Bart-like threads. I may have just gotten lucky and missed them, but instead I was left with the impression of the type of community that Mr. van Rossum has obviously worked so hard to foster. I have read several articles since yesterday that noted that Mr. van Rossum's leadership skills went beyond his technical competence to somehow creating this warm, open community of Python-loving folks. I have greatly benefited from this community in my on-and-off attempts to learn Python. For instance, Steve, I have lost count of how many times you have helped me out on the Tutor list with long, carefully written answers to my questions that must have taken good chunks of your valuable time. Many thanks to you and others who have been so generous in sharing their expertise and time with me! But after delving in the archives, I cannot help but feel that the "now" is not quite as good as the "then". So I continue to wonder ... Only those of you who have been there from Python's earliest years can truly know if my emotional perceptions have any validity. I was *not* there. But what I finally wonder is if this might not be the time for the community to engage in self-reflection, and see if we can do better on achieving the welcoming and openness that I think this community continually strives for, and, perhaps, even make room for those curmudgeonly, old uncles that keep popping in for unexpected visits? -- boB From quintin9g at gmail.com Fri Jul 13 23:29:38 2018 From: quintin9g at gmail.com (Edward Montague) Date: Sat, 14 Jul 2018 15:29:38 +1200 Subject: os with python[s] Message-ID: I encounter numerous problems when changing between versions of python ; one possible answer , Fedora 28 Labs python . So far this has been fairly reliable , I installed Geany , as this is my preferred editor for Python. From steve+comp.lang.python at pearwood.info Sat Jul 14 00:38:40 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 14 Jul 2018 04:38:40 +0000 (UTC) Subject: Kindness References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> Message-ID: On Sat, 14 Jul 2018 00:45:00 +0300, Marko Rauhamaa wrote: > Chris Angelico : >> Oh, sorry, I mean "how Python lacks basic features that your language >> just happens to tick all the boxes on". People who come in and ask >> genuine questions about Python seem to find the group far more >> welcoming and helpful. > > Yeah, that is cult behavior. Cultists also breathe oxygen and consume food, what's your point? It is perfectly natural psychology that if somebody comes to you and politely ask for help, you are more likely to be polite and welcoming in return than if they come in, flop out their dick and start pissing all over your favourite things. "Why are you so unwelcoming? I'm just making a technical criticism." -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From arj.python at gmail.com Sat Jul 14 00:46:30 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sat, 14 Jul 2018 08:46:30 +0400 Subject: Kindness In-Reply-To: References: Message-ID: is Bart here the same as python-commiters? Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ From pfeiffer at cs.nmsu.edu Sat Jul 14 01:27:11 2018 From: pfeiffer at cs.nmsu.edu (Joe Pfeiffer) Date: Fri, 13 Jul 2018 23:27:11 -0600 Subject: Kindness References: Message-ID: <1bd0vq2xqo.fsf@pfeifferfamily.net> I notice a correlation: the less people have interacted with Bart, the more tolerant they are. He once went on for *weeks* about C's (yes, this was in c.l.c) failure to have what he regards as a "proper" for-loop. From greg.ewing at canterbury.ac.nz Sat Jul 14 01:41:51 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 14 Jul 2018 17:41:51 +1200 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: Chris Angelico wrote: > and eventually a 99.99% Dutch solution > will be produced. Does this mean we need an is_probably_dutch() function? -- Greg From greg.ewing at canterbury.ac.nz Sat Jul 14 01:43:31 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 14 Jul 2018 17:43:31 +1200 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: Larry Martell wrote: > And while we're talking about the Dutch, why is the country called > Holland, but then also The Netherlands, but the people are Dutch? And Germany is called Deutchland? -- Greg From greg.ewing at canterbury.ac.nz Sat Jul 14 02:04:29 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 14 Jul 2018 18:04:29 +1200 Subject: Kindness In-Reply-To: <1bd0vq2xqo.fsf@pfeifferfamily.net> References: <1bd0vq2xqo.fsf@pfeifferfamily.net> Message-ID: Joe Pfeiffer wrote: > He once went on for *weeks* about C's (yes, this was in c.l.c) failure > to have what he regards as a "proper" for-loop. That could only have happened if there were people willing to keep replying to him about it for weeks. So, if it was a bad thing, you can't say it was entirely his fault. -- Greg From bob.martin at excite.com Sat Jul 14 07:41:43 2018 From: bob.martin at excite.com (Bob Martin) Date: Sat, 14 Jul 2018 07:41:43 BST Subject: Guido van Rossum resigns as Python leader References: Message-ID: in 796624 20180714 064331 Gregory Ewing wrote: >Larry Martell wrote: >> And while we're talking about the Dutch, why is the country called >> Holland, but then also The Netherlands, but the people are Dutch? > >And Germany is called Deutchland? The real question is why do English speakers refer to Deutschland as Germany. From steve+comp.lang.python at pearwood.info Sat Jul 14 03:07:58 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 14 Jul 2018 07:07:58 +0000 (UTC) Subject: OT Why Germany? [was Re: Guido van Rossum resigns as Python leader] References: Message-ID: On Sat, 14 Jul 2018 07:41:43 +0000, Bob Martin wrote: > in 796624 20180714 064331 Gregory Ewing > wrote: >>Larry Martell wrote: >>> And while we're talking about the Dutch, why is the country called >>> Holland, but then also The Netherlands, but the people are Dutch? >> >>And Germany is called Deutchland? > > The real question is why do English speakers refer to Deutschland as > Germany. It comes from the Roman name for the region, which they may have got from the Gauls. https://en.wikipedia.org/wiki/Germania -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From marko at pacujo.net Sat Jul 14 03:18:51 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 14 Jul 2018 10:18:51 +0300 Subject: Guido van Rossum resigns as Python leader References: Message-ID: <87in5i5lpg.fsf@elektro.pacujo.net> Bob Martin : > in 796624 20180714 064331 Gregory Ewing wrote: >>Larry Martell wrote: >>> And while we're talking about the Dutch, why is the country called >>> Holland, but then also The Netherlands, but the people are Dutch? >> >>And Germany is called Deutchland? > > The real question is why do English speakers refer to Deutschland as > Germany. And the answer is near: "The War that Changed the English Language" Marko From balglaas at dds.nl Sat Jul 14 03:27:38 2018 From: balglaas at dds.nl (Jan van den Broek) Date: Sat, 14 Jul 2018 07:27:38 +0000 (UTC) Subject: Guido van Rossum resigns as Python leader References: Message-ID: On 2018-07-13, ElChino wrote: >> The important question we should ask ourselves: Do we have a replacement >> Dutch person to figure out the one obvious way to do things that may not >> be obvious at first? > > Skybuck?! Also Dutch. We try to deny that. It'll probably lead to ending every statement in your code with "lol !". -- Jan v/d Broek balglaas at dds.nl From steve+comp.lang.python at pearwood.info Sat Jul 14 03:35:53 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 14 Jul 2018 07:35:53 +0000 (UTC) Subject: Kindness References: Message-ID: On Sat, 14 Jul 2018 05:19:36 +0300, Mikhail V wrote: > From Marko's check-list: > [ ] The group has a polarized us-versus-them mentality Many Python programmers -- perhaps the majority -- know more than one programming language, enjoy some of them, and can appreciate their strengths and the differences between them. Most of the core devs are competent C programmers. I don't know what percentage of Python programmers know only Python, and no other language, but my guess is that outside of school kids learning the language because their school makes it compulsory, it's probably a small percentage. The Python community has a long and glorious history of borrowing ideas from other languages, without slavishly following them. Neither "not invented here" nor "never invented here". These are not the characteristics of "us-versus-them". -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From balglaas at dds.nl Sat Jul 14 03:39:12 2018 From: balglaas at dds.nl (Jan van den Broek) Date: Sat, 14 Jul 2018 07:39:12 +0000 (UTC) Subject: Guido van Rossum resigns as Python leader References: Message-ID: On 2018-07-13, Larry Martell wrote: [Schnipp] > And while we're talking about the Dutch, why is the country called > Holland, but then also The Netherlands, but the people are Dutch? Be careful here, this is a somewhat delicate matter. Strictly speaking Holland is part of Nederland (the Netherlands). Nederland is divided in twelve provinces[1], Noord- and ZuidHolland are two of them. Calling the Netherlands Holland is an guaranteed to annoy people from the other then. Historical speaking, Holland was (along with Zeeland) one of the more powerfull members in the Republic. [1] https://nl.wikipedia.org/wiki/Bestand:NederlandseProvinciesLarge.png -- Jan v/d Broek balglaas at dds.nl From marko at pacujo.net Sat Jul 14 04:00:00 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 14 Jul 2018 11:00:00 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> Message-ID: <87601i5jsv.fsf@elektro.pacujo.net> Steven D'Aprano : > Apparently Marko didn't notice the irony of suggesting that we display > excessive commitment to GvR The object of the "cult" isn't GvR, it's Python itself. Marko From auriocus at gmx.de Sat Jul 14 05:09:56 2018 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 14 Jul 2018 11:09:56 +0200 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87601i5jsv.fsf@elektro.pacujo.net> References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> Message-ID: Am 14.07.18 um 10:00 schrieb Marko Rauhamaa: > Steven D'Aprano : >> Apparently Marko didn't notice the irony of suggesting that we display >> excessive commitment to GvR > > The object of the "cult" isn't GvR, it's Python itself. > I agree with this observation and it feels quite strange to me. I regularly use three languages (C++, Python and Tcl), all three are under active development, and IMHO all of them have flaws, there are is always something which is elegantly solved in one system but needs more work in another. But only in the Python community I have seen a strange "worship" of the language of choice, the believe it is 100% perfect. If something isn't available, then "Python doesn't need it. It's missing for a reason! You're holding ot wrong!" This opinion is not so prevalent in other communities. Of course, C++ programmers also think that C++ is the best language, but they regularly admit that Python does have an edge in clear syntax sometimes. Typical conversation on this list / newsgroup: Q: "I could need a ?: operator just like in C. Is there something like that in Python?" A1: "No. You don't want it. It makes the code confusing. You said, you have a problem, you tried ?: - now you have two problems." A2: "Are you crazy? You want to make Python like Java?" A3: "Guido left it out for a reason. Guido's time machine has seen that in 5 years you'll wonder what the hell ?: means" A4: "?: is unpythonic, because there is already One Obvious Way To Do It" --------- in the meantime, PEP 308 passes ------------ A1: "Oh, nice, Python has invented a new feature! We're the leading edge in language development!" A2: "All hail to Guido. In 5 years, you'll ned that, and then His Time-Machine has struck again!" Q: "But isn't this the same as ?: in Java or C?" A3: "Never. There is a HUGE difference! ?: is sooo confusing. But a if c else b, look, the order is reversed. This is much more natural! And not strange punctuation, English words. Python is executable pseudocode!" Christian From arj.python at gmail.com Sat Jul 14 05:47:18 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sat, 14 Jul 2018 13:47:18 +0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> Message-ID: @ChristianGollwitzer Naa your type of qna is called pep and a pep is not rejected without a valid reason Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > From rosuav at gmail.com Sat Jul 14 06:06:28 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 14 Jul 2018 20:06:28 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> Message-ID: On Sat, Jul 14, 2018 at 7:47 PM, Abdur-Rahmaan Janhangeer wrote: > @ChristianGollwitzer > > Naa your type of qna is called pep and a pep is not rejected without a > valid reason > I have no idea what you mean here. Can you please clarify? ChrisA From bc at freeuk.com Sat Jul 14 06:20:24 2018 From: bc at freeuk.com (Bart) Date: Sat, 14 Jul 2018 11:20:24 +0100 Subject: Kindness In-Reply-To: References: <1bd0vq2xqo.fsf@pfeifferfamily.net> Message-ID: On 14/07/2018 07:04, Gregory Ewing wrote: > Joe Pfeiffer wrote: >> He once went on for *weeks* about C's (yes, this was in c.l.c) failure >> to have what he regards as a "proper" for-loop. > > That could only have happened if there were people willing > to keep replying to him about it for weeks. So, if it was > a bad thing, you can't say it was entirely his fault. Exactly. Someone even admitted that 99% of the time he only needed exactly the simple loop I suggested, but was still 100% against the idea! Another example of people over-defending /their/ language's lack of something so fundamental (this one was even part of Fortran in the 1950s), for no other reason than the language not having it, and the language is always right. Perhaps cult-like behaviour with the object of worship being a language rather than an individual. -- bart From larry.martell at gmail.com Sat Jul 14 06:32:19 2018 From: larry.martell at gmail.com (Larry Martell) Date: Sat, 14 Jul 2018 06:32:19 -0400 Subject: OT Why Germany? [was Re: Guido van Rossum resigns as Python leader] In-Reply-To: References: Message-ID: On Sat, Jul 14, 2018 at 3:11 AM Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > On Sat, 14 Jul 2018 07:41:43 +0000, Bob Martin wrote: > > > in 796624 20180714 064331 Gregory Ewing > > wrote: > >>Larry Martell wrote: > >>> And while we're talking about the Dutch, why is the country called > >>> Holland, but then also The Netherlands, but the people are Dutch? > >> > >>And Germany is called Deutchland? > > > > The real question is why do English speakers refer to Deutschland as > > Germany. > > > And then there?s the Pennsylvania Dutch. They make good egg noodles. From tjol at tjol.eu Sat Jul 14 06:35:09 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Sat, 14 Jul 2018 12:35:09 +0200 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On 13/07/18 00:20, Roel Schroeven wrote: > Yes, you read that right: Guido van Rossum resigns as Python leader. > > See his mail: > (https://mail.python.org/pipermail/python-committers/2018-July/005664.html) Thanks for posting this here, Roel. Much appreciated. Guido has been fantastic, and he will be missed in his well-deserved retirement. Of course I have complete faith that the core devs will do a great job in the future steering Python forward. The Python community is sure to prosper even if this unexpected change creates some minor temporary challenges. Threads like this, on the other hand, can make you worry for the soul of Python. > >> Now that PEP 572 is done, I don't ever want to have to fight so hard >> for a PEP and find that so many people despise my decisions. >> >> I would like to remove myself entirely from the decision process. >> I'll still be there for a while as an ordinary core dev, and I'll >> still be available to mentor people -- possibly more available. But >> I'm basically giving myself a permanent vacation from being BDFL, and >> you all will be on your own. >> >> After all that's eventually going to happen regardless -- there's >> still that bus lurking around the corner, and I'm not getting >> younger... (I'll spare you the list of medical issues.) >> >> I am not going to appoint a successor. >> >> So what are you all going to do? Create a democracy? Anarchy? A >> dictatorship? A federation? >> >> I'm not worried about the day to day decisions in the issue tracker >> or on GitHub. Very rarely I get asked for an opinion, and usually it's > > not actually important. So this can just be dealt with as it has >> always been. >> >> The decisions that most matter are probably >> - How are PEPs decided >> - How are new core devs inducted >> >> We may be able to write up processes for these things as PEPs (maybe >> those PEPs will form a kind of constitution). But here's the catch. >> I'm going to try and let you all (the current committers) figure it >> out for yourselves. >> >> Note that there's still the CoC -- if you don't like that document >> your only option might be to leave this group voluntarily. Perhaps >> there are issues to decide like when should someone be kicked out >> (this could be banning people from python-dev or python-ideas too, >> since those are also covered by the CoC). >> >> Finally. A reminder that the archives of this list are public ( >> https://mail.python.org/pipermail/python-committers/) although >> membership is closed (limited to core devs). >> >> I'll still be here, but I'm trying to let you all figure something >> out for yourselves. I'm tired, and need a very long break. >> >> -- >> --Guido van Rossum (python.org/~guido) > > > From bc at freeuk.com Sat Jul 14 06:59:38 2018 From: bc at freeuk.com (Bart) Date: Sat, 14 Jul 2018 11:59:38 +0100 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> Message-ID: On 14/07/2018 10:09, Christian Gollwitzer wrote: > Am 14.07.18 um 10:00 schrieb Marko Rauhamaa: >> Steven D'Aprano : >>> Apparently Marko didn't notice the irony of suggesting that we display >>> excessive commitment to GvR >> >> The object of the "cult" isn't GvR, it's Python itself. >> > > I agree with this observation and it feels quite strange to me. I > regularly use three languages (C++, Python and Tcl), all three are under > active development, and IMHO all of them have flaws, there are is always > something which is elegantly solved in one system but needs more work in > another. > > But only in the Python community I have seen a strange "worship" of the > language of choice, the believe it is 100% perfect. If something isn't > available, then "Python doesn't need it. It's missing for a reason! > You're holding ot wrong!" This opinion is not so prevalent in other > communities. Of course, C++ programmers also think that C++ is the best > language, but they regularly admit that Python does have an edge in > clear syntax sometimes. > > Typical conversation on this list / newsgroup: > > Q: "I could need a ?: operator just like in C. Is there something like > that in Python?" > > A1: "No. You don't want it. It makes the code confusing. You said, you > have a problem, you tried ?: - now you have two problems." > > A2: "Are you crazy? You want to make Python like Java?" > > A3: "Guido left it out for a reason. Guido's time machine has seen that > in 5 years you'll wonder what the hell ?: means" > > A4: "?: is unpythonic, because there is already One Obvious Way To Do It" > > --------- in the meantime, PEP 308 passes ------------ > A1: "Oh, nice, Python has invented a new feature! We're the leading edge > in language development!" > > A2: "All hail to Guido. In 5 years, you'll ned that, and then His > Time-Machine has struck again!" > > Q: "But isn't this the same as ?: in Java or C?" > > A3: "Never. There is a HUGE difference! ?: is sooo confusing. But a if c > else b, look, the order is reversed. This is much more natural! And not > strange punctuation, English words. Python is executable pseudocode!" Yeah... (And I have some issues with both of those 2-way selection operators, but I won't go into details here...) -- bart From arj.python at gmail.com Sat Jul 14 07:20:47 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sat, 14 Jul 2018 15:20:47 +0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> Message-ID: @ChrisAngelico py's dev is not mere whims here and there py does not assume, it waits for peps. peps are not flown direct dustbin, they are reviewed the qna gives the impression of hey python is weird and just brushes suggestions with the back of the hand or defends some parts without justification we'll long story short : *proposes to qna author to write a pep about what he thinks should be changed in python* Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ From gerlando.falauto at gmail.com Sat Jul 14 09:55:52 2018 From: gerlando.falauto at gmail.com (Gerlando Falauto) Date: Sat, 14 Jul 2018 06:55:52 -0700 (PDT) Subject: logging from time critical tasks -- QueueListener().stop() takes the whole CPU Message-ID: Hi, I'm adding logging to a time critical task running resource-constrained hardware (Raspberry Pi). I read about the QueueListener/QueueHandler in: https://docs.python.org/3/howto/logging-cookbook.html#dealing-with-handlers-that-block and I'm trying to understand how it really works and what's happening under the hood, and what the impact would be. So I wrote a test program (here at the bottom) that logs 500000 times and then waits for the listener to terminate. I ran it on a PC: $ python3 logtest.py 0 PID= 5974 [ 0.000] Logging like crazy 500000 times with que = queue.Queue [ 18.038] Done logging, waiting for completion [ 37.824] Test finished --- Here's the output while it's logging (within the first 18 seconds): $ ps um -L 5974 USER PID LWP %CPU NLWP %MEM VSZ RSS TTY STAT START TIME COMMAND iurly 5974 - 96.3 2 2.1 264232 170892 pts/2 - 15:30 0:07 python3 logtest.py 0 iurly - 5974 72.8 - - - - - Rl+ 15:30 0:05 - iurly - 5975 23.3 - - - - - Sl+ 15:30 0:01 - So the main thread is taking most of the CPU while the background thread is writing to disk, and that's reasonable. However, as soon as I start waiting for the logger terminate, I get something like this: $ ps um -L 5974 USER PID LWP %CPU NLWP %MEM VSZ RSS TTY STAT START TIME COMMAND iurly 5974 - 100 2 3.9 406724 313588 pts/2 - 15:30 0:31 python3 logtest.py 0 iurly - 5974 45.2 - - - - - Sl+ 15:30 0:14 - iurly - 5975 54.8 - - - - - Rl+ 15:30 0:17 - Why is the main thread taking up so much CPU? I believe at this point listener.stop() should only be waiting for the helper thread to terminate, which I reckon would be implemented by waiting on a semaphore or something (i.e. iowait i.e. 0% CPU). Thank you, Gerlando RANGE=500000 import logging import logging.handlers import multiprocessing as mp import queue import time import gc import sys import os if len(sys.argv) > 1: testlist = [int(q) for q in sys.argv[1:]] else: print ("no test list given, defaulting to 0 1 0 1") testlist = [0, 1, 0, 1] print("PID=", os.getpid()) for i, qtype in enumerate(testlist): handlers = [] if qtype == 0: que = queue.Queue(-1) qstring = "queue.Queue" else: que = mp.Queue(-1) qstring = "mp.Queue" handlers.append(logging.handlers.RotatingFileHandler("test%d.log" % (i), maxBytes=100000, backupCount=5)) #handlers.append(logging.lastResort) listener = logging.handlers.QueueListener(que, *handlers) formatter = logging.Formatter('%(asctime)s:%(threadName)s: %(message)s') for handler in handlers: handler.setFormatter(formatter) listener.start() queue_handler = logging.handlers.QueueHandler(que) logger = logging.getLogger() logger.setLevel(logging.DEBUG) logger.addHandler(queue_handler) start = time.time() print("[%7.03f] Logging like crazy %d times with que = %s" % (time.time()-start, RANGE, qstring)) for i in range(0,RANGE): logger.info("AAAAAA") if i % 2000 == 0: print(i, "/", RANGE, end='\r') print("[%7.03f] Done logging, waiting for completion" % (time.time() - start)) listener.stop() print("[%7.03f] Test finished" % (time.time() - start)) gc.collect() print("---") From cfkaran2 at gmail.com Sat Jul 14 10:36:05 2018 From: cfkaran2 at gmail.com (CFK) Date: Sat, 14 Jul 2018 10:36:05 -0400 Subject: FYI apparmor and lxc in Ubuntu Message-ID: Hi all, this is just an FYI in case anyone else has the same issue I just ran into. If you use python 3.6 or 3.7 under Ubuntu with lxc, you may discover that your site-packages aren't being imported correctly within the container, but when you SSH in, everything works correctly. If that happens, check the config file for apparmor; on my system (Ubuntu 16.0.4), it disallowed python 3.6+. You will also need to set the language environment variable for lxc to use UTF-8, or your strings may get discarded (it defaults to ASCII). SSH goes through a different path for setting up the environment, so sshing in won't trigger the error. Thanks, Cem Karan From ian.g.kelly at gmail.com Sat Jul 14 11:00:35 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 14 Jul 2018 09:00:35 -0600 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> Message-ID: On Sat, Jul 14, 2018 at 3:12 AM Christian Gollwitzer wrote: > Typical conversation on this list / newsgroup: > > Q: "I could need a ?: operator just like in C. Is there something like > that in Python?" > > A1: "No. You don't want it. It makes the code confusing. You said, you > have a problem, you tried ?: - now you have two problems." > > A2: "Are you crazy? You want to make Python like Java?" > > A3: "Guido left it out for a reason. Guido's time machine has seen that > in 5 years you'll wonder what the hell ?: means" > > A4: "?: is unpythonic, because there is already One Obvious Way To Do It" > > --------- in the meantime, PEP 308 passes ------------ > A1: "Oh, nice, Python has invented a new feature! We're the leading edge > in language development!" > > A2: "All hail to Guido. In 5 years, you'll ned that, and then His > Time-Machine has struck again!" > > Q: "But isn't this the same as ?: in Java or C?" > > A3: "Never. There is a HUGE difference! ?: is sooo confusing. But a if c > else b, look, the order is reversed. This is much more natural! And not > strange punctuation, English words. Python is executable pseudocode!" I think you're conflating dissenting voices. When the debate period ends and a feature gets adopted, the people who were opposed to it no longer have much reason to talk about their opposition (the ship has sailed). Meanwhile, the people who like the feature and are now able to start using it are more likely to bring it up, e.g. as the solution to a problem. So it's natural that the overall tone of the community shifts while individual opinions might not. And of course, sometimes people might change their opinion as a result of actually using the feature. I think we all can name things we don't like about Python. For example, you're not likely to ever convince me that piggybacking coroutines onto generators was anything but a terrible hack that results in added complexity and leaky abstraction now that the feature has been stretched even further into an async framework. I don't see much point in arguing about it though since it's highly unlikely to change. From skip.montanaro at gmail.com Sat Jul 14 11:16:29 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 14 Jul 2018 10:16:29 -0500 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: > Is it irrational to wonder whether projects should be looking to migrate to > new languages? This kind of announcement makes me worry for the future. Umm, yeah. The language is stable, widely used packages are stable. Guido actually has little involvement in the larger Python ecosystem. It's not like NumPy, Django, Pandas, Flask, PyPI, Conda, or other popular packages or subsystems built with/for Python are suddenly going to crumble because Guido is no longer BDFL. But, by all means, if rewriting your applications in a different language floats your boat, go right ahead... Skip From tjreedy at udel.edu Sat Jul 14 13:28:42 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Jul 2018 13:28:42 -0400 Subject: Kindness In-Reply-To: References: Message-ID: On 7/14/2018 3:35 AM, Steven D'Aprano wrote: > On Sat, 14 Jul 2018 05:19:36 +0300, Mikhail V wrote: > >> From Marko's check-list: >> [ ] The group has a polarized us-versus-them mentality > > Many Python programmers -- perhaps the majority -- know more than one > programming language, enjoy some of them, and can appreciate their > strengths and the differences between them. Though I mostly only use Python now, I have used over 20 languages. > Most of the core devs are competent C programmers. A good thing. I once was but to focus on Python instead. To work on IDLE, I had to learn tkinter, which is effective a different language. Numpy and Django, for instance, are also effectively different languages implemented in Python. I don't know what percentage of Python > programmers know only Python, and no other language, but my guess is that > outside of school kids learning the language because their school makes > it compulsory, it's probably a small percentage. > > The Python community has a long and glorious history of borrowing ideas > from other languages, without slavishly following them. Neither "not > invented here" nor "never invented here". A review of other languages is a routine part of PEP discussions, and sometimes included in the PEP. > These are not the characteristics of "us-versus-them". -- Terry Jan Reedy From jlee54 at gmail.com Sat Jul 14 14:02:32 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sat, 14 Jul 2018 11:02:32 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> Message-ID: On 07/14/18 02:09, Christian Gollwitzer wrote: > Am 14.07.18 um 10:00 schrieb Marko Rauhamaa: >> Steven D'Aprano : >>> Apparently Marko didn't notice the irony of suggesting that we display >>> excessive commitment to GvR >> >> The object of the "cult" isn't GvR, it's Python itself. >> > > I agree with this observation and it feels quite strange to me. I > regularly use three languages (C++, Python and Tcl), all three are > under active development, and IMHO all of them have flaws, there are > is always something which is elegantly solved in one system but needs > more work in another. > > But only in the Python community I have seen a strange "worship" of > the language of choice, the believe it is 100% perfect. If something > isn't available, then "Python doesn't need it. It's missing for a > reason! You're holding ot wrong!" This opinion is not so prevalent in > other communities. Of course, C++ programmers also think that C++ is > the best language, but they regularly admit that Python does have an > edge in clear syntax sometimes. > > Typical conversation on this list / newsgroup: > > Q: "I could need a ?: operator just like in C. Is there something like > that in Python?" > > A1: "No. You don't want it. It makes the code confusing. You said, you > have a problem, you tried ?: - now you have two problems." > > A2: "Are you crazy? You want to make Python like Java?" > > A3: "Guido left it out for a reason. Guido's time machine has seen > that in 5 years you'll wonder what the hell ?: means" > > A4: "?: is unpythonic, because there is already One Obvious Way To Do It" > > --------- in the meantime, PEP 308 passes ------------ > A1: "Oh, nice, Python has invented a new feature! We're the leading > edge in language development!" > > A2: "All hail to Guido. In 5 years, you'll ned that, and then His > Time-Machine has struck again!" > > Q: "But isn't this the same as ?: in Java or C?" > > A3: "Never. There is a HUGE difference! ?: is sooo confusing. But a if > c else b, look, the order is reversed. This is much more natural! And > not strange punctuation, English words. Python is executable pseudocode!" > > > ????Christian +1000 !! -Jim From marko at pacujo.net Sat Jul 14 14:44:26 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 14 Jul 2018 21:44:26 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> Message-ID: <87va9h4pyt.fsf@elektro.pacujo.net> Ian Kelly : > I think we all can name things we don't like about Python. For > example, you're not likely to ever convince me that piggybacking > coroutines onto generators was anything but a terrible hack that > results in added complexity and leaky abstraction now that the feature > has been stretched even further into an async framework. I don't see > much point in arguing about it though since it's highly unlikely to > change. Having gone through a recent 2to3 effort that left my conscience stained, I can only lament for the lost paradise which was Python 2.7. There *was* one real gain: MemoryBIO, but that's not enough to bring a smile to my face. Marko From info at tundraware.com Sat Jul 14 15:19:43 2018 From: info at tundraware.com (Tim Daneliuk) Date: Sat, 14 Jul 2018 14:19:43 -0500 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> Message-ID: On 07/14/2018 04:09 AM, Christian Gollwitzer wrote: > I agree with this observation and it feels quite strange to me. I regularly use three languages (C++, Python and Tcl), all three are under active development, and IMHO all of them have flaws, there are is always something which is elegantly solved in one system but needs more work in another. Dusting off some of my musings written years ago but at least tangentially related to all this: https://www.tundraware.com/TechnicalNotes/How-To-Pick-A-Programming-Language/ https://www.tundraware.com/TechnicalNotes/Bullet/ I am not particularly enamored of the feeping creaturism that that infested Python 3, but then again, I'm not required by law to use said feeping creatures... I wish GvR well. He's served this community magnificently and deserves far better than he got, especially lately. := pedantry aside (and I am NOT a fan), great things come from individual minds, not committees and I think it is simply inarguable that GvR built a Very Great Thing. So ... thanks ... and go enjoy your life, sir, you've more than earned it. From info at tundraware.com Sat Jul 14 15:30:35 2018 From: info at tundraware.com (Tim Daneliuk) Date: Sat, 14 Jul 2018 14:30:35 -0500 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: On 07/14/2018 10:16 AM, Skip Montanaro wrote: >> Is it irrational to wonder whether projects should be looking to migrate to >> new languages? This kind of announcement makes me worry for the future. > > Umm, yeah. The language is stable, widely used packages are stable. > Guido actually has little involvement in the larger Python ecosystem. > It's not like NumPy, Django, Pandas, Flask, PyPI, Conda, or other > popular packages or subsystems built with/for Python are suddenly > going to crumble because Guido is no longer BDFL. > > But, by all means, if rewriting your applications in a different > language floats your boat, go right ahead... > > Skip > +1 From rosuav at gmail.com Sat Jul 14 15:36:07 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Jul 2018 05:36:07 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87va9h4pyt.fsf@elektro.pacujo.net> References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 15, 2018 at 4:44 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> I think we all can name things we don't like about Python. For >> example, you're not likely to ever convince me that piggybacking >> coroutines onto generators was anything but a terrible hack that >> results in added complexity and leaky abstraction now that the feature >> has been stretched even further into an async framework. I don't see >> much point in arguing about it though since it's highly unlikely to >> change. > > Having gone through a recent 2to3 effort that left my conscience > stained, I can only lament for the lost paradise which was Python 2.7. > There *was* one real gain: MemoryBIO, but that's not enough to bring a > smile to my face. > Spoken like a true eight-bit-stringer (kinda like a flat-earther only a lot more wrong). ChrisA From marko at pacujo.net Sat Jul 14 15:54:52 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 14 Jul 2018 22:54:52 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> Message-ID: <87r2k54mpf.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Jul 15, 2018 at 4:44 AM, Marko Rauhamaa wrote: >> Having gone through a recent 2to3 effort that left my conscience >> stained, I can only lament for the lost paradise which was Python >> 2.7. There *was* one real gain: MemoryBIO, but that's not enough to >> bring a smile to my face. > > Spoken like a true eight-bit-stringer True enough. Modern-day protocols as well as Linux file formats and commands intentionally blur the line between strings and bytes. The software in question deals with all of the above. It is virtually impossible to keep track of what is "really" text and what is "really" binary. In the end, the Gordian Knot was sliced by using Python3's strings for everything and restricting oneself to Latin-1 codepoints (almost) everywhere. > (kinda like a flat-earther only a lot more wrong). Ah, that's called "shunning," isn't it? Marko From tjreedy at udel.edu Sat Jul 14 15:57:34 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 14 Jul 2018 15:57:34 -0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87va9h4pyt.fsf@elektro.pacujo.net> References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> Message-ID: On 7/14/2018 2:44 PM, Marko Rauhamaa wrote: > Having gone through a recent 2to3 effort that left my conscience > stained, I can only lament for the lost paradise which was Python 2.7. I am curious, which release of 2.7 do you apply that to? The initial 2.7.0? Should we have stopped there? The current 2.7.15? Should we stop with this? If you think paradise needed and needs improving, what help did you and will you contribute? What do you mean by 'lost'? All past releases since about 1.5 will remain available indefinitely. For some people, in particular core developers, 2.7 was more like hell, a developmental dead end. The different opinions may be responses to the same facts. -- Terry Jan Reedy From tkadm30 at yandex.com Sat Jul 14 15:57:42 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Sat, 14 Jul 2018 15:57:42 -0400 Subject: Guido van Rossum resigns as Python leader In-Reply-To: References: Message-ID: <481f6ae8-71a0-3b59-e330-5133a6efdada@yandex.com> I'm really sad to hear that news! Python is the language which made me gain the most skills in modern software programming ever! I have not encountered a better programming language than Python for quickly becoming a mature developer! I just hope the Python software foundation will continue to provide to his community all the same services than before and that the project will continue to evolve! Thanks for everything Guido! :-) Etienne -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From rosuav at gmail.com Sat Jul 14 16:02:24 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Jul 2018 06:02:24 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87r2k54mpf.fsf@elektro.pacujo.net> References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 15, 2018 at 5:54 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Jul 15, 2018 at 4:44 AM, Marko Rauhamaa wrote: >>> Having gone through a recent 2to3 effort that left my conscience >>> stained, I can only lament for the lost paradise which was Python >>> 2.7. There *was* one real gain: MemoryBIO, but that's not enough to >>> bring a smile to my face. >> >> Spoken like a true eight-bit-stringer > > True enough. Modern-day protocols as well as Linux file formats and > commands intentionally blur the line between strings and bytes. The > software in question deals with all of the above. It is virtually > impossible to keep track of what is "really" text and what is "really" > binary. In the end, the Gordian Knot was sliced by using Python3's > strings for everything and restricting oneself to Latin-1 codepoints > (almost) everywhere. > >> (kinda like a flat-earther only a lot more wrong). > > Ah, that's called "shunning," isn't it? > No, it isn't. Shunning would be killfiling you, which is apparently "more polite" than telling you how utterly and completely wrong you are. What I would like to do is ban you for endemic racism, honestly. By recommending and preferring eight-bit text strings, you're saying "Chinese text doesn't matter". And by stipulating Latin-1, you're also saying "Russian text doesn't matter" and "Thai text doesn't matter" and "Hebrew text doesn't matter" and more. You are declaring that YOUR culture is the only one that matters. When I see behaviour like that in a Twitch stream that I moderate, I smack it with a banhammer, because that is utterly unacceptable. Why should we tolerate it in programming? ChrisA From tkadm30 at yandex.com Sat Jul 14 16:08:22 2018 From: tkadm30 at yandex.com (Etienne Robillard) Date: Sat, 14 Jul 2018 16:08:22 -0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> Message-ID: <4db32fc1-7859-92fc-2a00-21bf752993c4@yandex.com> Le 2018-07-14 ? 16:02, Chris Angelico a ?crit?: > No, it isn't. Shunning would be killfiling you, which is apparently > "more polite" than telling you how utterly and completely wrong you > are. > > What I would like to do is ban you for endemic racism, honestly. By > recommending and preferring eight-bit text strings, you're saying > "Chinese text doesn't matter". And by stipulating Latin-1, you're also > saying "Russian text doesn't matter" and "Thai text doesn't matter" > and "Hebrew text doesn't matter" and more. You are declaring that YOUR > culture is the only one that matters. When I see behaviour like that > in a Twitch stream that I moderate, I smack it with a banhammer, > because that is utterly unacceptable. Why should we tolerate it in > programming? lol +1 > ChrisA -- Etienne Robillard tkadm30 at yandex.com https://www.isotopesoftware.ca/ From marko at pacujo.net Sat Jul 14 18:15:24 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 15 Jul 2018 01:15:24 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> Message-ID: <87muut4g77.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Jul 15, 2018 at 5:54 AM, Marko Rauhamaa wrote: >> True enough. Modern-day protocols as well as Linux file formats and >> commands intentionally blur the line between strings and bytes. The >> software in question deals with all of the above. It is virtually >> impossible to keep track of what is "really" text and what is "really" >> binary. In the end, the Gordian Knot was sliced by using Python3's >> strings for everything and restricting oneself to Latin-1 codepoints >> (almost) everywhere. > > [...] By recommending and preferring eight-bit text strings, you're > saying "Chinese text doesn't matter". And by stipulating Latin-1, > you're also saying "Russian text doesn't matter" and "Thai text > doesn't matter" and "Hebrew text doesn't matter" and more. You are > declaring that YOUR culture is the only one that matters. When I see > behaviour like that in a Twitch stream that I moderate, I smack it > with a banhammer, because that is utterly unacceptable. Why should we > tolerate it in programming? I'm not saying that at all. What I'm saying is that I'm using Python3 strings as holders for bytes. Since every byte is a valid Unicode code point, a Python3 string can hold any sequence of bytes. Couldn't you use bytes objects everywhere for the same purpose? Yes and no. Yes, but it would be ugly as hell and would involve changing a large percentage of the source code. No, as a large number of Python3 facilities require str objects as arguments. Consider urllib.request.urlopen(), for example, which requires a URL to be an str object. Marko From rosuav at gmail.com Sat Jul 14 19:07:17 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Jul 2018 09:07:17 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87muut4g77.fsf@elektro.pacujo.net> References: <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 15, 2018 at 8:15 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Jul 15, 2018 at 5:54 AM, Marko Rauhamaa wrote: >>> True enough. Modern-day protocols as well as Linux file formats and >>> commands intentionally blur the line between strings and bytes. The >>> software in question deals with all of the above. It is virtually >>> impossible to keep track of what is "really" text and what is "really" >>> binary. In the end, the Gordian Knot was sliced by using Python3's >>> strings for everything and restricting oneself to Latin-1 codepoints >>> (almost) everywhere. >> >> [...] By recommending and preferring eight-bit text strings, you're >> saying "Chinese text doesn't matter". And by stipulating Latin-1, >> you're also saying "Russian text doesn't matter" and "Thai text >> doesn't matter" and "Hebrew text doesn't matter" and more. You are >> declaring that YOUR culture is the only one that matters. When I see >> behaviour like that in a Twitch stream that I moderate, I smack it >> with a banhammer, because that is utterly unacceptable. Why should we >> tolerate it in programming? > > I'm not saying that at all. What I'm saying is that I'm using Python3 > strings as holders for bytes. Since every byte is a valid Unicode code > point, a Python3 string can hold any sequence of bytes. Since every byte is also a valid IEEE 754 64-bit binary floating point value, a sequence of floats can hold any sequence of bytes, too. Is it a good idea to use floats to represent bytes? Text strings and sequences of bytes *are different*. If you're going to try to blur the line, you do NOT want Latin-1. You *might* be able to do this with ASCII, but you cannot use an eight-bit character set. > Couldn't you use bytes objects everywhere for the same purpose? > > Yes and no. > > Yes, but it would be ugly as hell and would involve changing a large > percentage of the source code. > > No, as a large number of Python3 facilities require str objects as > arguments. Consider urllib.request.urlopen(), for example, which > requires a URL to be an str object. Well, duh. It also doesn't accept a list of floats, just because you COULD represent a text string that way. ChrisA From rosuav at gmail.com Sat Jul 14 20:40:27 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Jul 2018 10:40:27 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 15, 2018 at 5:19 AM, Tim Daneliuk wrote: > On 07/14/2018 04:09 AM, Christian Gollwitzer wrote: >> I agree with this observation and it feels quite strange to me. I regularly use three languages (C++, Python and Tcl), all three are under active development, and IMHO all of them have flaws, there are is always something which is elegantly solved in one system but needs more work in another. > > > Dusting off some of my musings written years ago but at least tangentially > related to all this: > > https://www.tundraware.com/TechnicalNotes/How-To-Pick-A-Programming-Language/ > https://www.tundraware.com/TechnicalNotes/Bullet/ No idea what this has to do with the features of different languages. You basically say "blah blah blah nothing matters", which is not entirely false, but far from true. (For example, you're right that it's important to understand algorithms independently of a language, but wrong that that means cross-platform code is irrelevant.) > I am not particularly enamored of the feeping creaturism that that infested > Python 3, but then again, I'm not required by law to use said feeping creatures... You'd better avoid most of JavaScript, C++, and most other languages, then. Every language feeps a little, and Python is definitely not as bad as some. > I wish GvR well. He's served this community magnificently and deserves far > better than he got, especially lately. := pedantry aside (and I am NOT a fan), > great things come from individual minds, not committees and I think it is > simply inarguable that GvR built a Very Great Thing. So ... thanks ... and > go enjoy your life, sir, you've more than earned it. And here's the big thing. People are STILL complaining about the := operator, while paying lip service to "Guido's design sensibilities are good". At some point, people have to simply accept or reject. Either you trust Guido to decide what's best for the language, or you think he's making mistakes. Either you believe that his idea of what's good for the language is worth following, or you don't. Either you continue to use Python, or you go and rewrite your code in another language. Quit beefing about how Guido's a smart person but you still hate what he's decided here. At very least, just cool off on it for a year. No wonder he's wanting to retire. ChrisA From steve+comp.lang.python at pearwood.info Sat Jul 14 22:55:27 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 15 Jul 2018 02:55:27 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> Message-ID: On Sun, 15 Jul 2018 09:07:17 +1000, Chris Angelico wrote: > On Sun, Jul 15, 2018 at 8:15 AM, Marko Rauhamaa > wrote: >> Chris Angelico : >> >>> On Sun, Jul 15, 2018 at 5:54 AM, Marko Rauhamaa >>> wrote: >>>> True enough. Modern-day protocols as well as Linux file formats and >>>> commands intentionally blur the line between strings and bytes. The >>>> software in question deals with all of the above. It is virtually >>>> impossible to keep track of what is "really" text and what is >>>> "really" binary. Of course we have no idea what Marko's software is, or what it is doing, but frankly that seems pretty implausible to me. On the face of it, it seems as ridiculous as the claim that he can't tell which variables are quote-unquote "really" lists of weights and which are lists of distances. On the face of things, this really sounds more like an admission that Marko is working with a shitty code base, not a fundamental problem with Python. But dealing with shitty code bases is the reality. >>>> In the end, the Gordian Knot was sliced by using >>>> Python3's strings for everything and restricting oneself to Latin-1 >>>> codepoints (almost) everywhere. [...] I wonder whether Marko's Python 2.7 code base was ever actually tested with non-Latin1 text. I suspect that if Marko had (let's say) Japanese users expecting to use CJK characters in the application, his affection for the 2.7 version would be a lot less. [Marko] >> What I'm saying is that I'm using Python3 >> strings as holders for bytes. Since every byte is a valid Unicode code >> point, a Python3 string can hold any sequence of bytes. [Chris] > Since every byte is also a valid IEEE 754 64-bit binary floating point > value, a sequence of floats can hold any sequence of bytes, too. Is it a > good idea to use floats to represent bytes? 3.6e-322 1.6e-322 4.8e-322 5.1e-322 5.63e-322 5e-322 5e-322 1.63e-322 > Text strings and sequences of bytes *are different*. At an implementation level, everything is bytes. People do so insist on conflating implementation with interface, even when they don't need to... (Sometimes I think people should be required to implement algorithms on analogue computing devices before they're allowed to write code for digital computers, just to drive home the point that neither bytes nor bits are fundamental to computing, but are mere implementation details.) At a semantic level, byte strings and text strings represent fundamentally different things, as distinct as weights and lengths. Unfortunately, due to the long influence of ASCII in computing, a lot of people have internalised that "byte 0x41 *really is* the letter A" when that's just a mere encoding convention. You wouldn't add 5kg to 5cm and expect to get a meaningful result, but people expect to combine bytes and text and "just make it work". One might as well say that bytes b'@=<\xed\x91hr\xb0' really is the number 29.238 and expect to multiple your name by 12.5 and get your height in seconds. [Marko] >> Couldn't you use bytes objects everywhere for the same purpose? >> >> Yes and no. >> >> Yes, but it would be ugly as hell and would involve changing a large >> percentage of the source code. It would also require re-inventing the entire Unicode infrastructure already provided -- unless you intended to just say No to 99% of human languages in the world, including English, in favour of restricting everyone, including English speakers, to an artificial subset of the characters they use in real life. (Even Latin1 doesn't cover all the English punctuation marks I expect to be able to use in text.) It's not 1970 any more. Under what circumstances is that acceptable? >> No, as a large number of Python3 facilities require str objects as >> arguments. Consider urllib.request.urlopen(), for example, which >> requires a URL to be an str object. That's because URLs are fundamentally text strings. Quick quiz: which of the following are real URLs? (a) http://?????????????.?? (b) http://??????????.?????? (c) http://??.??? (d) All of the above. https://uxmag.com/articles/a-url-in-any-language > Well, duh. It also doesn't accept a list of floats, just because you > COULD represent a text string that way. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From 00jhenryg at gmail.com Sat Jul 14 22:58:44 2018 From: 00jhenryg at gmail.com (Jack Gilbert) Date: Sat, 14 Jul 2018 21:58:44 -0500 Subject: Guido's leaving Message-ID: To Guido, I wish you much success in all your future endeavors. Jack G Python Newby From rosuav at gmail.com Sat Jul 14 23:38:01 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Jul 2018 13:38:01 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 15, 2018 at 12:55 PM, Steven D'Aprano wrote: > On Sun, 15 Jul 2018 09:07:17 +1000, Chris Angelico wrote: > >> On Sun, Jul 15, 2018 at 8:15 AM, Marko Rauhamaa >> wrote: >>> Chris Angelico : >>> >>>> On Sun, Jul 15, 2018 at 5:54 AM, Marko Rauhamaa >>>> wrote: >>>>> True enough. Modern-day protocols as well as Linux file formats and >>>>> commands intentionally blur the line between strings and bytes. The >>>>> software in question deals with all of the above. It is virtually >>>>> impossible to keep track of what is "really" text and what is >>>>> "really" binary. > > Of course we have no idea what Marko's software is, or what it is doing, > but frankly that seems pretty implausible to me. On the face of it, it > seems as ridiculous as the claim that he can't tell which variables are > quote-unquote "really" lists of weights and which are lists of distances. > > On the face of things, this really sounds more like an admission that > Marko is working with a shitty code base, not a fundamental problem with > Python. But dealing with shitty code bases is the reality. Fair point - but doesn't justify hating on Python 3 for making it easier to work with good code than with bad code. I've had to work with ridiculous data formats before (forty-ish lines of block comment concluding with "Cthulhu's got nothing on a determined bank"), but when that happens, I *know* that my code is being warped to fit the requirements. It's not something to replicate elsewhere. >>>>> In the end, the Gordian Knot was sliced by using >>>>> Python3's strings for everything and restricting oneself to Latin-1 >>>>> codepoints (almost) everywhere. > [...] > > I wonder whether Marko's Python 2.7 code base was ever actually tested > with non-Latin1 text. I suspect that if Marko had (let's say) Japanese > users expecting to use CJK characters in the application, his affection > for the 2.7 version would be a lot less. I very much doubt it has. He *restricted* to Latin-1, which means that he threw away all the support Python offers, restricting to one seventy-thousandth of the available characters, or a thousandth of the allocated ones. >> Text strings and sequences of bytes *are different*. > > At an implementation level, everything is bytes. People do so insist on > conflating implementation with interface, even when they don't need to... And at a different implementation level, everything is electrical signals. > (Sometimes I think people should be required to implement algorithms on > analogue computing devices before they're allowed to write code for > digital computers, just to drive home the point that neither bytes nor > bits are fundamental to computing, but are mere implementation details.) Every week, I live-stream a workshop on data structures and algorithms. (You're all most welcome to come by; it's Friday lunchtime in the US, or Saturday early morning in Australia.) I use JavaScript (because a lot of people know it), Python (because it's a really expressive language), or a deck of cards. Have you ever seen merge-sort implemented on a deck of cards? It's beautifully simple and elegant. Interestingly, quick-sort looks very different from merge-sort when implemented in C, but they're fairly similar when implemented in cards. Bytes? Bits? Arrays? If you want them, you have to first implement them. > At a semantic level, byte strings and text strings represent > fundamentally different things, as distinct as weights and lengths. Or, as I keep running into when I try to mod Team Fortress 2, entities and clients and users. They're all represented by the "int" data type, and I have to spend an insane amount of effort trying to keep them straight - does this function take a user or a client? Oh wait, this isn't the user at all, it's the entity ID of that user's gun. But it's still just an int... *sigh* SourcePawn (the language in question) lacks a type system strong enough to handle this. Having different data types for fundamentally different types of data is not a weakness. It is a strength. > One might as well say that bytes b'@=<\xed\x91hr\xb0' really is the > number 29.238 and expect to multiple your name by 12.5 and get your > height in seconds. QOTD. >>> No, as a large number of Python3 facilities require str objects as >>> arguments. Consider urllib.request.urlopen(), for example, which >>> requires a URL to be an str object. > > That's because URLs are fundamentally text strings. > > Quick quiz: which of the following are real URLs? > > (a) http://?????????????.?? > > (b) http://??????????.?????? > > (c) http://??.??? > > (d) All of the above. > > https://uxmag.com/articles/a-url-in-any-language I had to actually check two of those to be sure they really truly were *real* URLs, not merely *correctly formatted* URLs. But yes, URLs are fundamentally text. For hysterical raisins, DNS has some oddities to it, so when you dive into how these are actually represented, the Korean example is actually http://xn--9n2bp8q.xn--9t4b11yi5a - but I don't believe there are any byte-based encodings involved. This is encoding text using other text, where the encoded form uses an extremely restricted alphabet (a-z 0-9 and hyphen). ChrisA From steve+comp.lang.python at pearwood.info Sat Jul 14 23:44:50 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 15 Jul 2018 03:44:50 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> Message-ID: On Sat, 14 Jul 2018 22:54:52 +0300, Marko Rauhamaa wrote: > Ah, that's called "shunning," isn't it? No, shunning is when people simply stop responding to those they don't approve of, turn their back on them in the street, and refuse to acknowledge their existence in any way. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From greg.ewing at canterbury.ac.nz Sun Jul 15 02:20:27 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 15 Jul 2018 18:20:27 +1200 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <877elxqohl.fsf@nightsong.com> References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <877elxqohl.fsf@nightsong.com> Message-ID: Paul Rubin wrote: > If you see the historical absence > of an assignment operator in Python as a mistake, then the introduction > of := is a fix for the mistake that only happened because people kept > complaining. That's not quite the same thing. There was no a PEP saying that there would never be assignment expressions in Python, so there was room for useful debate. Now that the := PEP is accepted, further argument about it is not productive. As far as I know, no PEP has ever been revoked after acceptance, and that's a good thing for the stability of the language. It's like the rule sports usually have that the referee's decision is final, even if it turns out to be wrong. At some point you need to make a decision and move on. -- Greg From arj.python at gmail.com Sun Jul 15 02:35:34 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 15 Jul 2018 10:35:34 +0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <877elxqohl.fsf@nightsong.com> Message-ID: @GregoryEwing maybe another word for pep revocation is fork Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ From auriocus at gmx.de Sun Jul 15 02:37:05 2018 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 15 Jul 2018 08:37:05 +0200 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: Am 05.07.18 um 12:04 schrieb Steven D'Aprano: > On Thu, 05 Jul 2018 09:17:20 +0200, Christian Gollwitzer wrote: > >> Am 04.07.18 um 17:31 schrieb Steven D'Aprano: >>> On Wed, 04 Jul 2018 13:48:26 +0100, Bart wrote: >>> >>>> Presumably one type hint applies for the whole scope of the variable, >>>> not just the one assignment. >>> >>> You know how in C you can write >>> >>> int x = 1; # the type applies for just this one assignment x = >>> 2.5; # perfectly legal, right? >>> >>> >> Not sure what point you are trying to make, but your example compiles in >> C, if you replace the '#' comment sign with '//'. > > > Oops. > > > But... it compiles? Seriously? > >> Only it doesn't do >> what you might think: the 2.5 is down-converted to an integer, therefore >> x will be 2 in the end. There will be a compiler warning but no error. > > Sometimes I wonder how C programmers manage to write a bug-free "Hello > World" program. No wonder it is described as a type-unsafe language or a > weakly-typed language. Even this compiles: #include int main() { int x=1; x="This is serious"; printf("%d\n", x); return 0; } Apfelkiste:Tests chris$ gcc intx.c && ./a.out intx.c:4:3: warning: incompatible pointer to integer conversion assigning to 'int' from 'char [16]' [-Wint-conversion] x="This is serious"; ^~~~~~~~~~~~~~~~~~ 1 warning generated. 15294370 Assignment in C to an integer will only fail when the source is a struct. Everything else can be "converted" to an integer by the compiler. > I understand upcasting ints to floats, that's cool (even if a few > languages take a hard line on that too, I don't). I understand Python's > dynamic typing approach. I don't understand C requiring type > declarations, then down-casting floats to integers. Without prototypes, it would be worse; the compiler would put the bit-pattern of a float onto the stack and reinterpret that as an integer. With prototypes there is a "sensible" result, namely the integer part of the float. At least it doesn't crash ("2.5" in C is a double constant, which is usually 64 bit, whereas int is usually 32 bit only). > > At least it shows a warning. But hell, who pays attention to C compiler > warnings? There's *so many of them*. In programs that are maintained, the warnings are typically taken seriously. Some warnings can be annoying, e.g. warnings from generated code about unused variables and such, but if you see a flood of warnings in regular code, that is a sign that the code has bad quality or wasn't ever tested on the platform you try it to compile. > > (And I bet that by default the warning is disabled, amirite?) Some people develop with -Werror (treat warnings as error and abort). Christian From marko at pacujo.net Sun Jul 15 03:33:03 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 15 Jul 2018 10:33:03 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> Message-ID: <87d0vp3qds.fsf@elektro.pacujo.net> Paul Rubin : > Py3's unicode picture is described here and it isn't pretty: > http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/ >From the link: The much more likely thing to happen is that people stick to Python 2 or build broken stuff on Python 3. Or they go with Go. Which uses an even simpler model than Python 2: everything is a byte string. The assumed encoding is UTF-8. End of the story. I have similar feelings, except that I'm not convinced Go is the answer. Marko From marko at pacujo.net Sun Jul 15 04:39:40 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 15 Jul 2018 11:39:40 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> Message-ID: <878t6c51v7.fsf@elektro.pacujo.net> Steven D'Aprano : > Of course we have no idea what Marko's software is, or what it is doing, Correct, you don't, but the link Paul Rubin posted gives you an idea: Python 3 says: everything is Unicode (by default, except in certain situations, and except if we send you crazy reencoded data, and even then it's sometimes still unicode, albeit wrong unicode). Filenames are Unicode, Terminals are Unicode, stdin and out are Unicode, there is so much Unicode! And because UNIX is not Unicode, Python 3 now has the stance that it's right and UNIX is wrong > [Marko] >>> No, as a large number of Python3 facilities require str objects as >>> arguments. Consider urllib.request.urlopen(), for example, which >>> requires a URL to be an str object. > > That's because URLs are fundamentally text strings. : In most URL schemes, the sequences of characters in different parts of a URL are used to represent sequences of octets used in Internet protocols. For example, in the ftp scheme, the host name, directory name and file names are such sequences of octets, represented by parts of the URL. (RFC 3986 says the same thing in a more roundabout way.) A URL consists of ASCII-only characters that represent an octet string. Of course, ASCII characters *are* Unicode characters. > Quick quiz: which of the following are real URLs? > (a) http://?????????????.?? On the face of it, that is not a valid URL. However, hostnames can be dealt with somewhat bijectively using punycode. But try this: >>> import http.client >>> conn = http.client.HTTPConnection("example.com") >>> conn.request("GET", "/?") Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python3.5/http/client.py", line 1107, in request self._send_request(method, url, body, headers) File "/usr/lib64/python3.5/http/client.py", line 1142, in _send_request self.putrequest(method, url, **skips) File "/usr/lib64/python3.5/http/client.py", line 984, in putrequest self._output(request.encode('ascii')) UnicodeEncodeError: 'ascii' codec can't encode character '\xe4' in positi\ on 5: ordinal not in range(128) >>> conn = http.client.HTTPConnection("example.com") >>> conn.request("G?T", "/") Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python3.5/http/client.py", line 1107, in request self._send_request(method, url, body, headers) File "/usr/lib64/python3.5/http/client.py", line 1142, in _send_request self.putrequest(method, url, **skips) File "/usr/lib64/python3.5/http/client.py", line 984, in putrequest self._output(request.encode('ascii')) UnicodeEncodeError: 'ascii' codec can't encode character '\xc4' in positi\ on 1: ordinal not in range(128) IOW, the method and URL path given to conn.request are str objects but they are really just thinly veiled containers for ASCII bytes objects. That approach is very similar to mine. Marko From marko at pacujo.net Sun Jul 15 04:43:14 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 15 Jul 2018 11:43:14 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> Message-ID: <874lh051p9.fsf@elektro.pacujo.net> Paul Rubin : > Marko Rauhamaa writes: >> I have similar feelings, except that I'm not convinced Go is the answer. > > I don't think Go is the answer either, but it probably got strings > right. What is the answer? That's the ten-billion-dollar question, isn't it?! Marko From greg.ewing at canterbury.ac.nz Sun Jul 15 05:28:35 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 15 Jul 2018 21:28:35 +1200 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <877elxqohl.fsf@nightsong.com> Message-ID: Abdur-Rahmaan Janhangeer wrote: > maybe another word for pep revocation is fork No, anyone can fork Python whenever they want, no discussion required, without affecting Python itself. Revoking a PEP would mean removing its implementation from the main CPython repository. -- Greg From pcmanticore at gmail.com Sun Jul 15 05:54:27 2018 From: pcmanticore at gmail.com (Claudiu Popa) Date: Sun, 15 Jul 2018 11:54:27 +0200 Subject: pylint 2.0 / astroid 2.0 released! Message-ID: Hi folks, The pylint team is happy to announce the release of pylint 2.0 and astroid 2.0! This release only works with Python 3.4+, while older pylint releases are still maintained for Python 2 compatibility, at least until next year. You can find more details about what's new in this release over here: http://pylint.pycqa.org/en/latest/whatsnew/2.0.html Thanks and enjoy linting! Claudiu & all the Pylint contributors From steve+comp.lang.python at pearwood.info Sun Jul 15 06:43:00 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 15 Jul 2018 10:43:00 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> Message-ID: On Sun, 15 Jul 2018 11:43:14 +0300, Marko Rauhamaa wrote: > Paul Rubin : > >> Marko Rauhamaa writes: >>> I have similar feelings, except that I'm not convinced Go is the >>> answer. >> >> I don't think Go is the answer either, but it probably got strings >> right. What is the answer? Go strings aren't text strings. They're byte strings. When you say that Go got them right, that depends on your definition of success. If your definition of "success" is: - fail to be able to support 80% + of the world's languages and a majority of the world's text; - perpetuate the anti-pattern where a single code point (hex value) can represent multiple characters, depending on what encoding you have in mind; - to have a language where legal variable names cannot be represented as strings; [1] - to have a language where text strings are a second-class data type, not available in the language itself, only in the libraries; - to have a language where text characters are *literally* 32-bit integers ("rune" is an alias to int32); (you can multiple a linefeed by a grave accent and get pi) then I guess Go got it right. > That's the ten-billion-dollar question, isn't it?! No. The real ten billion dollar question is how people in 2018 can stick their head in the sand and take seriously the position that Latin-1 (let alone ASCII) is enough for text strings. [1] Go identifiers are Unicode. Go strings are not. Go figure. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jul 15 07:04:46 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 15 Jul 2018 11:04:46 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> Message-ID: On Sun, 15 Jul 2018 11:39:40 +0300, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Of course we have no idea what Marko's software is, or what it is >> doing, > > Correct, you don't, but the link Paul Rubin posted gives you an idea: > > Python 3 says: everything is Unicode (by default, except in certain > situations, and except if we send you crazy reencoded data, and even > then it's sometimes still unicode, albeit wrong unicode). I have a lot of respect for Armin Ronacher, but I think here he is badly wrong and he's just ranting. It is ludicrous to say "everything" is Unicode when Python provides a rich set of bytes APIs. He squeezes in a parenthesised "by default" there, but that undermines his rant. That's like saying that "everything in Python is an int" rather than a float, because is you don't include a decimal point or an exponent in numeric literals, you get ints. Or that "files in Python are always read-only" because the default for open() is to use read mode rather than write mode. > Filenames > are Unicode, Terminals are Unicode, stdin and out are Unicode, And indeed they are, in Windows, and so they should be, in Unix too. Maybe some day POSIX will recognise that the rest of the world exists and stop privileging ASCII. > there > is so much Unicode! And because UNIX is not Unicode, Python 3 now has > the stance that it's right and UNIX is wrong Armin seems to be implying that Unix is (1) the only OS in the world, and (2) beyond criticism. Neither of these are correct. Windows users might rightly ask why Armin cares what Unix does. Unix does a lot right, but not everything http://web.mit.edu/~simsong/www/ugh.pdf and its "everything is bytes" stance is badly wrong when it comes to user- visible textual elements like file names and the command prompt. We write `less README`, not `6c7320524541444d45`, and we should stop pretending that we're using bytes just because the underlying infrastructure uses bytes. We're using text. >> That's because URLs are fundamentally text strings. > > : Irrelevant or obsolete or both. > A URL consists of ASCII-only characters that represent an octet string. Wrong. >> Quick quiz: which of the following are real URLs? (a) >> http://?????????????.?? > > On the face of it, that is not a valid URL. If you had read the link I gave, or even if you copied and pasted the URL into any reasonably modern browser, you might have learned that it is a valid URL. > But try this: [snip] Indeed. Is there a reason why these shouldn't be considered serious bugs in the http library? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From mal at europython.eu Sun Jul 15 07:13:17 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Sun, 15 Jul 2018 13:13:17 +0200 Subject: Invitation to the EuroPython Society General Assembly 2018 Message-ID: <7005b993-c82b-89b2-f4f8-cbd13a5ce4e6@europython.eu> We would like to invite all EuroPython attendees and EuroPython Society (EPS) members to attend this year?s EPS General Assembly (GA), which we will run as in-person meeting at the upcoming EuroPython 2018, held in Edinburgh, Scotland, UK from July 23 - 29. We had already sent a invite to the members mailing on 2018-06-17, but would like to announce this more broadly as well and with complete agenda. Place of the General Assembly meeting ------------------------------------- We will meet on Friday, July 27, at 14:15 BST in room Kilsyth of the EICC, The Exchange, Edinburgh EH3 8EE. There will be a short talk to invite volunteers to participate in organizing EuroPython 2019 in preparation for next year?s event at 14:00 BST in the same room, right before the General Assembly. You may want to attend that talk as well. In this talk, we will present the EuroPython Workgroup Concept, we have been using successfully for the past years now. General Assembly Agenda ----------------------- The agenda contents for the assembly is defined by the EPS bylaws. We are planning to use the following structure: - Opening of the meeting - Selection of meeting chair, secretary and 2 checkers of the minutes - Motion establishing the timeliness of the call to the meeting - Presentation of the annual report and annual accounts by the board - Presentation of the report of the auditor - Discharge from liability for the board - Presentation of a budget by the outgoing board. - Acceptance of budget and decision on membership fees for the upcoming year - Election of members of the board - Election of chair of the board - Election of one auditor and one replacement. The auditor does not have to be certified in any way and is normally selected among the members of the society. - The optional election of a nomination committee for the next annual meeting of the General Assembly - Propositions from the board, if any - Motions from the members, if any - Closing of the meeting In an effort to reduce the time it takes to go through this long list, which is mandated by the bylaws, we will try to send as much information to the members mailing list before the GA, so that we can limit presentations to a minimum. Election of the members of the board ------------------------------------ The EPS bylaws limit the number of board members to one chair and 2 - 8 directors, at most 9 directors in total. Experience has shown that the board members are the most active organizers of the EuroPython conference, so we try to get as many board members as possible to spread the work load. All members of the EPS are free to nominate or self nominate board members. Please write to board at europython-society.org no later than Friday, July 20 2017, if you want to run for board. We will then include you in the list we?ll have in the final nomination announcement before the GA, which is scheduled for July 21. The following people from the current board have already shown interest in running for board in the next term as well (in alphabetical order): - Anders Hammarquist - Darya Chyzhyk - Marc-Andr? Lemburg We will post more detailed information about the candidates and any new nominations we receive in a separate blog post. Propositions from the board --------------------------- We would like to propose to grant CPython Core Developers a lifetime free entry to EuroPython conferences in recognition for their efforts to build the foundation on what our community is built. The details are to be defined by the EPS board. The bylaws allow for additional propositions to be announced up until 5 days before the GA, so the above list is not necessarily the final list. Motions from the members ------------------------ None at the moment. EPS members are entitled to suggest motions to be voted on at the GA. The bylaws require any such motions to be announced at least 5 days before the GA. If you would like to propose a motion, please send it to board at europython-society.org no later than Friday, July 20 2017, so we can announce the final list to everyone. 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/175911344495/invitation-to-the-europython-society-general Tweet: https://twitter.com/europythons/status/1018446170933420033 Enjoy, -- EuroPython Society https://ep2018.europython.eu/ https://www.europython-society.org/ From marko at pacujo.net Sun Jul 15 07:17:51 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 15 Jul 2018 14:17:51 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> Message-ID: <87zhys3fz4.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sun, 15 Jul 2018 11:43:14 +0300, Marko Rauhamaa wrote: >> Paul Rubin : >>> I don't think Go is the answer either, but it probably got strings >>> right. What is the answer? > > Go strings aren't text strings. They're byte strings. When you say that > Go got them right, that depends on your definition of success. > > If your definition of "success" is: > > - fail to be able to support 80% + of the world's languages > and a majority of the world's text; Of course byte strings can support at least as many languages as Python3's code point strings and at least equally well. > - perpetuate the anti-pattern where a single code point > (hex value) can represent multiple characters, depending > on what encoding you have in mind; That doesn't follow at all. > - to have a language where legal variable names cannot be > represented as strings; [1] That's a rather Go-specific and uninteresting question, but I'm fairly certain you can write a Go parser in Go (if that's not how it's done already). > - to have a language where text strings are a second-class > data type, not available in the language itself, only in > the libraries; Unicode code point strings *ought* to be a second--class data type. They were a valiant idea but in the end turned out to be a mistake. > - to have a language where text characters are *literally* > 32-bit integers ("rune" is an alias to int32); > > (you can multiple a linefeed by a grave accent and get pi) Again, that has barely anything to do with the topic at hand. I don't think there's any unproblematic way to capture a true text character, period. Python3 certainly hasn't been able to capture it. >> That's the ten-billion-dollar question, isn't it?! > > No. The real ten billion dollar question is how people in 2018 can > stick their head in the sand and take seriously the position that > Latin-1 (let alone ASCII) is enough for text strings. Here's the deal: text strings are irrelevant for most modern programming needs. Most software is middleware between the human and the terminal device. Carrying opaque octet strings from end to end is often the most correct and least problematic thing to do. On the other hand, Python3's code point strings mess things up for no added value. You still can't upcase or downcase strings. You still can't sort strings. You still can't perform random access on strings. You still don't know how long your string is. You still don't know where you can break a string safely. You still don't know how to normalize a string. You still don't know if two strings are equal or not. You still don't know how to concatenate strings. Marko From mal at europython.eu Sun Jul 15 07:30:56 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Sun, 15 Jul 2018 13:30:56 +0200 Subject: EuroPython 2018: Delaying switch to Late Bird Tickets by one day - please use your coupons today ! Message-ID: Since we still have quite a few people with discount coupons who haven?t bought their tickets yet, we are extending the regular ticket sales by one day. * EuroPython 2018 Tickets * https://ep2018.europython.eu/en/registration/buy-tickets/ Switch to Late Bird Tickets on July 17, 00:00 CEST -------------------------------------------------- We will now switch to late bird prices, which are about 30% higher than the regular ones on Tuesday, July 17. Issued coupons are not valid for Late Bird Tickets -------------------------------------------------- Please note that the coupons we have issued so far are not valid for the late bird tickets, so if you have a coupon for the conference, please order your tickets before we switch to late bird. This includes coupons for sponsors, speakers, trainers and also the EPS community discount coupons we have given to several user groups. Please make sure you use your coupon before the switch on Tuesday, 00:00 CEST. Late Bird Tickets ----------------- We will have the following categories of late bird ticket prices for the conference tickets (starting 2018-07-17): * Business conference ticket: EUR 750.00 excl. VAT, EUR 900.00 incl. 20% UK VAT (for people using Python to make a living) * Personal conference ticket: EUR 500.00 incl. 20% UK VAT (for people enjoying Python from home) Please note that we do not sell on-desk student tickets. Students who decide late will have to buy day passes or a personal ticket. Day Passes ---------- As in the past, we will also sell day passes for the conference (starting 2018-07-16). These allow attending the conference for a single day (Wednesday, Thursday or Friday; valid on the day you pick up the day pass): * Business conference day pass: EUR 375.00 excl. VAT, EUR 450.00 incl. 20% UK VAT (for people using Python to make a living) * Personal conference day pass: EUR 250.00 incl. 20% UK VAT (for people enjoying Python from home) * Student conference day pass: EUR 105.00 incl. 20% UK VAT (only available for pupils, students and postdoctoral researchers; please bring your student card or declaration from University, stating your affiliation, starting and end dates of your contract) Please see the registration page for full details of what is included in the ticket price. Also note that neither late bird tickets, nor day passes are refundable. 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/175911806047/europython-2018-delaying-switch-to-late-bird Tweet: https://twitter.com/europython/status/1018456935950114816 Enjoy, -- EuroPython 2018 Team https://ep2018.europython.eu/ https://www.europython-society.org/ From breamoreboy at gmail.com Sun Jul 15 07:36:24 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Sun, 15 Jul 2018 12:36:24 +0100 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <877elxqohl.fsf@nightsong.com> Message-ID: On 15/07/18 07:35, Abdur-Rahmaan Janhangeer wrote: > @GregoryEwing > > maybe another word for pep revocation is fork All ready been tried and failed with Python as the PSF holds the rights to the name, so you have to call it something else. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From marko at pacujo.net Sun Jul 15 07:37:18 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 15 Jul 2018 14:37:18 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> Message-ID: <87tvp03f2p.fsf@elektro.pacujo.net> Steven D'Aprano : > On Sun, 15 Jul 2018 11:39:40 +0300, Marko Rauhamaa wrote: > Armin seems to be implying that Unix is (1) the only OS in the world, > and (2) beyond criticism. If Unix is your world, of course you can criticize how badly Python3 performs in that world. > Neither of these are correct. Windows users might rightly ask why > Armin cares what Unix does. Huh? Windows users should judge Python3 from their point of view and leave Armin and Unix alone. > Unix does a lot right, but not everything So we agree that Python3 is not a good fit for Unix/Linux/OSX/POSIX (or vice versa)? Too bad because Python2 fit like a glove. > http://web.mit.edu/~simsong/www/ugh.pdf > > and its "everything is bytes" stance is badly wrong when it comes to > user- visible textual elements like file names and the command prompt. > We write `less README`, not `6c7320524541444d45`, and we should stop > pretending that we're using bytes just because the underlying > infrastructure uses bytes. We're using text. One of the classic Unix and Internet tenets is that text is bytes is text. Of course, much of it was na?ve, but UTF-8 has miraculously given it a new life. Now, Python3's Unicode folly has spread to wider circles. Guile, GNU Textutils and glibc have been afflicted by the same mal-meme. > If you had read the link I gave, or even if you copied and pasted the > URL into any reasonably modern browser, you might have learned that it > is a valid URL. > > [...] > > Indeed. Is there a reason why these shouldn't be considered serious > bugs in the http library? Oh, that would be some development, indeed. Browsers' behavior is hardly relevent here but that you'd be ready to throw Python3's http.client under the bus... So do you think http.client is abusing Python3's data types? Marko From list at qtrac.plus.com Sun Jul 15 08:05:53 2018 From: list at qtrac.plus.com (Mark) Date: Sun, 15 Jul 2018 05:05:53 -0700 (PDT) Subject: Can anyone tell me where the old MacPython "16 ton" logo came from? Message-ID: <840efa74-1643-442e-9807-cafa044f1c6b@googlegroups.com> I'm curious to understand how come the original MacPython logo is of a 16 ton weight (rather than, say the word 'python' or a picture of a snake)? You can see the logo here: https://homepages.cwi.nl/~jack/macpython/ From christian at python.org Sun Jul 15 08:49:02 2018 From: christian at python.org (Christian Heimes) Date: Sun, 15 Jul 2018 14:49:02 +0200 Subject: Can anyone tell me where the old MacPython "16 ton" logo came from? In-Reply-To: <840efa74-1643-442e-9807-cafa044f1c6b@googlegroups.com> References: <840efa74-1643-442e-9807-cafa044f1c6b@googlegroups.com> Message-ID: On 2018-07-15 14:05, Mark wrote: > I'm curious to understand how come the original MacPython logo is of a 16 ton weight (rather than, say the word 'python' or a picture of a snake)? > You can see the logo here: https://homepages.cwi.nl/~jack/macpython/ Most obscure references in Python are based on Monty Python sketches, e.g. https://www.youtube.com/watch?v=o13glRURgTE From rosuav at gmail.com Sun Jul 15 09:18:41 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 15 Jul 2018 23:18:41 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87zhys3fz4.fsf@elektro.pacujo.net> References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <87zhys3fz4.fsf@elektro.pacujo.net> Message-ID: On Sun, Jul 15, 2018 at 9:17 PM, Marko Rauhamaa wrote: > Steven D'Aprano : >> - to have a language where text strings are a second-class >> data type, not available in the language itself, only in >> the libraries; > > Unicode code point strings *ought* to be a second--class data type. They > were a valiant idea but in the end turned out to be a mistake. So let's see. Suppose I go to a web site that asks me to type in a title; I enter something and hit "Save". That title goes through JavaScript, gets sent to the back-end API via AJAX and JSON, received by a Python web app, and saved into a database. Later, it gets retrieved from that database and displayed to me on the same web page, where I click on it, and it gets put into an input field. I then submit it using standard form fill-out (no JS), it is received by the web app, and then gets sent to the Twitch.tv API to become my stream title. I look at my stream, and the title is the exact string that I entered originally. During this time, I consider that string to be text. Always text. But if Unicode strings are second-class data, then that title changed from being text (in the input box) to UTF-16 (in JS) to UTF-8 (in JSON) to UTF-32 (in Python) to UTF-8 (in the database) to UTF-32 (retrieved into Python later) to ASCII with "\uXXXX" escapes (being sent to the web page) to text (in the input box). Then it gets converted to URL-encoded UTF-8 (form submission), then UTF-8, and UTF-32 (retrieval in Python), then UTF-8 (Twitch API), and finally back to text (displayed on the screen). Remind me how it's such a mistake to treat that string as text all the way through? >> - to have a language where text characters are *literally* >> 32-bit integers ("rune" is an alias to int32); >> >> (you can multiple a linefeed by a grave accent and get pi) > > Again, that has barely anything to do with the topic at hand. I don't > think there's any unproblematic way to capture a true text character, > period. Python3 certainly hasn't been able to capture it. Python's Unicode type is an accurate representation of a Unicode text string, just as Python's float type is an accurate representation of IEEE 754 floating-point. Just as floats are not reals, so too is Unicode not perfectly able to represent all human text, and has to mess around with things like combining characters. It's not 100% perfect (https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ point #11), but it's about as close as you'll ever get inside a computer. >>> That's the ten-billion-dollar question, isn't it?! >> >> No. The real ten billion dollar question is how people in 2018 can >> stick their head in the sand and take seriously the position that >> Latin-1 (let alone ASCII) is enough for text strings. > > Here's the deal: text strings are irrelevant for most modern programming > needs. Most software is middleware between the human and the terminal > device. Carrying opaque octet strings from end to end is often the most > correct and least problematic thing to do. Uhh, so the human uses byte/octet strings? You can argue that the terminal device is fundamentally byte-oriented, but if you do, I'm going to dispute the use of the definite article, and say that *many* terminal devices are byte-oriented as of today. There's no fundamental reason for that to remain the case, and even today, we have fundamentally text-oriented terminal devices. I know this because I maintain one (okay, it's called a "MUD client" rather than a "terminal device", but it's basically the same thing). > On the other hand, Python3's code point strings mess things up for no > added value. You still can't upcase or downcase strings. Not entirely sure what the .upper() and .lower() methods do, then. Case conversion of arbitrary text strings is hard, but Python definitely gives you as good as you'll ever get without actually stipulating, not just the language, but the context. > You still can't sort strings. Strings are intrinsically totally ordered in a mostly-sane way. If you want anything more than that, you have to stipulate the language. Python offers this in the 'locale' module, with strcoll and strxfrm. > You still can't perform random access on strings. Say what? > You still don't know how long your string is. How long is a piece of string? 1) Do you count code points? len(x) 2) Do you count code units? len(x.encode("...")) 3) Do you count base characters, ignoring combining characters? 4) Do you count pixels of display width? 5) Do you count advancement (like pixels, but negative for RTL text)? Two of them are easy. Two require font metrics (so they're the job of a display engine). Only #3 is moderately hard, and you could do that with a one-liner by checking the Unicode categories. But it isn't very useful except to "prove" that Python sucks. > You still don't know where you can break a string safely. Impossible without language-based and font-based information. For instance, in the string "python", you cannot break the string between the "t" and the "h", because they are parts of one phonogram. Splitting the string "????? ???" anywhere other than at the space will result in the two halves displaying differently from the combined whole, because of the way Arabic text is written. Python lets you split the string between any two code points, a massive step up from exposing UTF-8 or UTF-16 code units, so that's about as safe as it gets. > You still don't know how to normalize a string. You mean unicodedata.normalize? Yeah, you're right, I don't know how to do it. I can never remember whether it's normalize(str, "NFC") or normalize("NFC", str). > You still don't know if two strings are equal or not. Do an NFD or NFKD normalization on both strings, then compare. > You still don't know how to concatenate strings. Uhh.... s1 + s2? I'm fairly sure you have no clue about Unicode or Python, but I'll give you the benefit of the doubt and assume you're merely trolling. ChrisA From marko at pacujo.net Sun Jul 15 09:57:11 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 15 Jul 2018 16:57:11 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <87zhys3fz4.fsf@elektro.pacujo.net> Message-ID: <87pnzo38lk.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Jul 15, 2018 at 9:17 PM, Marko Rauhamaa wrote: > Remind me how it's such a mistake to treat that string as text all the > way through? Many times you need to make tricky ontological conversion decisions when all you should need to do is relay the information. > Python's Unicode type is an accurate representation of a Unicode text > string, just as Python's float type is an accurate representation of > IEEE 754 floating-point. Just as floats are not reals, so too is > Unicode not perfectly able to represent all human text, and has to > mess around with things like combining characters. It's not 100% > perfect The floating-point argument is a diversion. The competing solutions are 1. byte strings carrying UTF-8 2. code point strings carrying UTF-32 The latter solution was supposed to relieve the programmer from the downsides of the former. It turns out it does no such thing. >> Here's the deal: text strings are irrelevant for most modern >> programming needs. Most software is middleware between the human and >> the terminal device. Carrying opaque octet strings from end to end is >> often the most correct and least problematic thing to do. > > Uhh, so the human uses byte/octet strings? You can argue that the > terminal device is fundamentally byte-oriented, but if you do, I'm > going to dispute the use of the definite article, and say that *many* > terminal devices are byte-oriented as of today. There's no fundamental > reason for that to remain the case, and even today, we have > fundamentally text-oriented terminal devices. I know this because I > maintain one (okay, it's called a "MUD client" rather than a "terminal > device", but it's basically the same thing). The human user uses keyboards with character shapes painted on the keys, icons to tap or click on, display devices with recognizable pixel patterns and other audio-visual mechanisms. Then there's a lot of middleware that routes information and carries it in over distances in chunks of octets. >> On the other hand, Python3's code point strings mess things up for no >> added value. You still can't upcase or downcase strings. > > Not entirely sure what the .upper() and .lower() methods do, then. > Case conversion of arbitrary text strings is hard, but Python > definitely gives you as good as you'll ever get without actually > stipulating, not just the language, but the context. So we agree. >> You still can't sort strings. > > Strings are intrinsically totally ordered in a mostly-sane way. If you > want anything more than that, you have to stipulate the language. > Python offers this in the 'locale' module, with strcoll and strxfrm. So we agree. >> You still can't perform random access on strings. > > Say what? You can't look up the nth glyph in O(1). >> You still don't know how long your string is. > > How long is a piece of string? > > 1) Do you count code points? len(x) > 2) Do you count code units? len(x.encode("...")) > 3) Do you count base characters, ignoring combining characters? > 4) Do you count pixels of display width? > 5) Do you count advancement (like pixels, but negative for RTL text)? > > Two of them are easy. Two require font metrics (so they're the job of > a display engine). Only #3 is moderately hard, and you could do that > with a one-liner by checking the Unicode categories. But it isn't very > useful except to "prove" that Python sucks. I didn't say Python sucked. I said Python3's str objects are inferior to Python2's str objects. As you say yourself, Python3's str objects don't actually solve any of the real problems that Python2's str objects (with UTF-8 inside) have. > I'm fairly sure you have no clue about Unicode or Python, but I'll > give you the benefit of the doubt and assume you're merely trolling. Are you even aware of the ad hominems? Marko From tjol at tjol.eu Sun Jul 15 10:10:44 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 15 Jul 2018 16:10:44 +0200 Subject: Can anyone tell me where the old MacPython "16 ton" logo came from? In-Reply-To: References: <840efa74-1643-442e-9807-cafa044f1c6b@googlegroups.com> Message-ID: <69191be5-0815-75db-d83b-2032fb0fd7d7@tjol.eu> On 15/07/18 14:49, Christian Heimes wrote: > On 2018-07-15 14:05, Mark wrote: >> I'm curious to understand how come the original MacPython logo is of a 16 ton weight (rather than, say the word 'python' or a picture of a snake)? >> You can see the logo here: https://homepages.cwi.nl/~jack/macpython/ > > Most obscure references in Python are based on Monty Python sketches, > e.g. https://www.youtube.com/watch?v=o13glRURgTE > More specifically, this Monty Python motif appears in the "self-defense against fruit" sketch . (Apples are mentioned. Briefly.) From steve+comp.lang.python at pearwood.info Sun Jul 15 10:52:46 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 15 Jul 2018 14:52:46 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <87zhys3fz4.fsf@elektro.pacujo.net> Message-ID: On Sun, 15 Jul 2018 14:17:51 +0300, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Sun, 15 Jul 2018 11:43:14 +0300, Marko Rauhamaa wrote: >>> Paul Rubin : >>>> I don't think Go is the answer either, but it probably got strings >>>> right. What is the answer? >> >> Go strings aren't text strings. They're byte strings. When you say that >> Go got them right, that depends on your definition of success. >> >> If your definition of "success" is: >> >> - fail to be able to support 80% + of the world's languages >> and a majority of the world's text; > > Of course byte strings can support at least as many languages as > Python3's code point strings and at least equally well. You cannot possibly be serious. There are 256 possible byte values. China alone has over 10,000 different characters. You can't represent 10,000+ characters using only 256 distinct code points. You can't even represent the world's languages using 16-bit word-strings instead of byte strings. Watching somebody argue that byte strings are "equally as good" as a dedicated Unicode string type in 2018 is like seeing people argue in the late 1990s that this new-fangled "structured code" will never be better than unstructured code with GOTO. >> - perpetuate the anti-pattern where a single code point >> (hex value) can represent multiple characters, depending on what >> encoding you have in mind; > > That doesn't follow at all. Of course it does. You talked about using Latin-1. What's so special about Latin-1? Ask your Greek customers how useful that is to them, and explain why they can't use ISO-8859-7 instead. >> - to have a language where legal variable names cannot be >> represented as strings; [1] > > That's a rather Go-specific We were talking about whether or not Go had done strings right. > and uninteresting question, It's not a question, its a statement. And it might be uninteresting to you, but I find it astonishing. > but I'm fairly certain you can write a Go parser in Go So what? You can write a Go parser in Floop if you like. https://en.wikipedia.org/wiki/BlooP_and_FlooP > (if that's not how it's done already). > >> - to have a language where text strings are a second-class >> data type, not available in the language itself, only in the >> libraries; > > Unicode code point strings *ought* to be a second--class data type. They > were a valiant idea but in the end turned out to be a mistake. Just because you say they were a mistake, doesn't make it so. >> - to have a language where text characters are *literally* >> 32-bit integers ("rune" is an alias to int32); >> >> (you can multiple a linefeed by a grave accent and get pi) > > Again, that has barely anything to do with the topic at hand. It has *everything* to do with the topic at hand: did Go get strings right? > I don't > think there's any unproblematic way to capture a true text character, > period. Python3 certainly hasn't been able to capture it. Isaac Asimov's quote here is appropriate: When people thought the Earth was flat, they were wrong. When people thought the Earth was spherical, they were wrong. But if you think that thinking the Earth is spherical is just as wrong as thinking the Earth is flat, then your view is wronger than both of them put together. Unicode does not perfectly capture the human concept of "text characters" (and no consistent system ever will, because the human concept of a character is not consistent). But if you think that makes byte-strings *better* than Unicode text strings at representing text, then you are wronger than wrong. >>> That's the ten-billion-dollar question, isn't it?! >> >> No. The real ten billion dollar question is how people in 2018 can >> stick their head in the sand and take seriously the position that >> Latin-1 (let alone ASCII) is enough for text strings. > > Here's the deal: text strings are irrelevant for most modern programming > needs. Most software is middleware between the human and the terminal > device. Your view is completely, utterly inside out. The terminal is the middle layer, between the software and the human, not the software. > Carrying opaque octet strings from end to end is often the most > correct and least problematic thing to do. > On the other hand, Python3's code point strings mess things up for no > added value. You still can't upcase or downcase strings. Ah, the ol' "argument by counter-factual assertions". State something that isn't true, and claim it is true. py> "???".upper() '???' Looks like uppercasing to me. What does it look like to you? Taking a square root? (I can't believe I need to actually demonstrate this.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From list at qtrac.plus.com Sun Jul 15 11:39:59 2018 From: list at qtrac.plus.com (Mark) Date: Sun, 15 Jul 2018 08:39:59 -0700 (PDT) Subject: Can anyone tell me where the old MacPython "16 ton" logo came from? In-Reply-To: References: <840efa74-1643-442e-9807-cafa044f1c6b@googlegroups.com> Message-ID: <43f43a77-ead4-49b6-b2b6-8175340ef90b@googlegroups.com> On Sunday, July 15, 2018 at 1:49:22 PM UTC+1, Christian Heimes wrote: > On 2018-07-15 14:05, Mark wrote: > > I'm curious to understand how come the original MacPython logo is of a 16 ton weight (rather than, say the word 'python' or a picture of a snake)? > > You can see the logo here: https://homepages.cwi.nl/~jack/macpython/ > > Most obscure references in Python are based on Monty Python sketches, > e.g. https://www.youtube.com/watch?v=o13glRURgTE Thanks to both of you, I understand it now:-) From arj.python at gmail.com Sun Jul 15 11:44:56 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 15 Jul 2018 19:44:56 +0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <877elxqohl.fsf@nightsong.com> Message-ID: @MarkLawrence this i fell compelled to reply. no name issue. fork with features intended meaning python is open source, you want to add as many feature as you want np, just like a user modifies a script. you just need to master c and compiler theory and it becomes easy or add like a "plugin" to make it modify original on user system people consider languages like whoaa but really py is just a specification, a c program if you intend to mean the original one. Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > > From arj.python at gmail.com Sun Jul 15 11:46:19 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 15 Jul 2018 19:46:19 +0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87d0vp3qds.fsf@elektro.pacujo.net> References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> Message-ID: should have switched treads from here Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ >From the link: > > The much more likely thing to happen is that people stick to Python 2 > or build broken stuff on Python 3. Or they go with Go. Which uses an > even simpler model than Python 2: everything is a byte string. The > assumed encoding is UTF-8. End of the story. > > I have similar feelings, except that I'm not convinced Go is the answer. > > > Marko > -- > https://mail.python.org/mailman/listinfo/python-list > From arj.python at gmail.com Sun Jul 15 11:57:38 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 15 Jul 2018 19:57:38 +0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> Message-ID: @ChrisAngelico don't know [replying to your message but addressing to all] i respect you all, i respect your involvement, i doubt not your py skills but can you please stay on topic and be concise i value all posts here and try to read them all as they are all serious stuffs but when you mix in long paragraphs i have to take the pain to summarise what you just said also i *beg* you all if possible to ignore the like of postx : you are a vermicelli pudding from the north korean suburb of some south pole city posty : you seem like a childish python programmer having Phe in Haskell postz : *some more obscure references* i can feel the octopus nature of some threads in my bones Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ > Of course we have no idea what Marko's software is, or what it is doing, > > but frankly that seems pretty implausible to me. On the face of it, it > > seems as ridiculous as the claim that he can't tell which variables are > > quote-unquote "really" lists of weights and which are lists of distances. > > > > On the face of things, this really sounds more like an admission that > > Marko is working with a shitty code base, not a fundamental problem with > > Python. But dealing with shitty code bases is the reality. > > Fair point - but doesn't justify hating on Python 3 for making it > easier to work with good code than with bad code. I've had to work > with ridiculous data formats before (forty-ish lines of block comment > concluding with "Cthulhu's got nothing on a determined bank"), but > when that happens, I *know* that my code is being warped to fit the > requirements. It's not something to replicate elsewhere. > > >>>>> In the end, the Gordian Knot was sliced by using > >>>>> Python3's strings for everything and restricting oneself to Latin-1 > >>>>> codepoints (almost) everywhere. > > [...] > > > > I wonder whether Marko's Python 2.7 code base was ever actually tested > > with non-Latin1 text. I suspect that if Marko had (let's say) Japanese > > users expecting to use CJK characters in the application, his affection > > for the 2.7 version would be a lot less. > > I very much doubt it has. He *restricted* to Latin-1, which means that > he threw away all the support Python offers, restricting to one > seventy-thousandth of the available characters, or a thousandth of the > allocated ones. > > >> Text strings and sequences of bytes *are different*. > > > > At an implementation level, everything is bytes. People do so insist on > > conflating implementation with interface, even when they don't need to... > > And at a different implementation level, everything is electrical signals. > > > (Sometimes I think people should be required to implement algorithms on > > analogue computing devices before they're allowed to write code for > > digital computers, just to drive home the point that neither bytes nor > > bits are fundamental to computing, but are mere implementation details.) > > Every week, I live-stream a workshop on data structures and > algorithms. (You're all most welcome to come by; it's Friday lunchtime > in the US, or Saturday early morning in Australia.) I use JavaScript > (because a lot of people know it), Python (because it's a really > expressive language), or a deck of cards. Have you ever seen > merge-sort implemented on a deck of cards? It's beautifully simple and > elegant. Interestingly, quick-sort looks very different from > merge-sort when implemented in C, but they're fairly similar when > implemented in cards. > > Bytes? Bits? Arrays? If you want them, you have to first implement them. > > > At a semantic level, byte strings and text strings represent > > fundamentally different things, as distinct as weights and lengths. > > Or, as I keep running into when I try to mod Team Fortress 2, entities > and clients and users. They're all represented by the "int" data type, > and I have to spend an insane amount of effort trying to keep them > straight - does this function take a user or a client? Oh wait, this > isn't the user at all, it's the entity ID of that user's gun. But it's > still just an int... *sigh* SourcePawn (the language in question) > lacks a type system strong enough to handle this. > > Having different data types for fundamentally different types of data > is not a weakness. It is a strength. > > > One might as well say that bytes b'@=<\xed\x91hr\xb0' really is the > > number 29.238 and expect to multiple your name by 12.5 and get your > > height in seconds. > > QOTD. > > >>> No, as a large number of Python3 facilities require str objects as > >>> arguments. Consider urllib.request.urlopen(), for example, which > >>> requires a URL to be an str object. > > > > That's because URLs are fundamentally text strings. > > > > Quick quiz: which of the following are real URLs? > > > > (a) http://?????????????.?? > > > > (b) http://??????????.?????? > > > > (c) http://??.??? > > > > (d) All of the above. > > > > https://uxmag.com/articles/a-url-in-any-language > > I had to actually check two of those to be sure they really truly were > *real* URLs, not merely *correctly formatted* URLs. But yes, URLs are > fundamentally text. For hysterical raisins, DNS has some oddities to > it, so when you dive into how these are actually represented, the > Korean example is actually http://xn--9n2bp8q.xn--9t4b11yi5a - but I > don't believe there are any byte-based encodings involved. This is > encoding text using other text, where the encoded form uses an > extremely restricted alphabet (a-z 0-9 and hyphen). > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From arj.python at gmail.com Sun Jul 15 12:05:44 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 15 Jul 2018 20:05:44 +0400 Subject: python on open hatch Message-ID: saw python still on open hatch last week, can some illuminated member explain to me the purpose there was a link to a contributing walkthrough (dead link), seems no longer maintaining descriptions Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ From e+python-list at kellett.im Sun Jul 15 13:04:59 2018 From: e+python-list at kellett.im (Ed Kellett) Date: Sun, 15 Jul 2018 18:04:59 +0100 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <87zhys3fz4.fsf@elektro.pacujo.net> Message-ID: <836c88f4-17f0-37fc-e11a-bbddb88f31d2@kellett.im> On 2018-07-15 15:52, Steven D'Aprano wrote: > On Sun, 15 Jul 2018 14:17:51 +0300, Marko Rauhamaa wrote: > >> Steven D'Aprano : >> >>> On Sun, 15 Jul 2018 11:43:14 +0300, Marko Rauhamaa wrote: >>>> Paul Rubin : >>>>> I don't think Go is the answer either, but it probably got strings >>>>> right. What is the answer? >>> >>> Go strings aren't text strings. They're byte strings. When you say that >>> Go got them right, that depends on your definition of success. >>> >>> If your definition of "success" is: >>> >>> - fail to be able to support 80% + of the world's languages >>> and a majority of the world's text; >> >> Of course byte strings can support at least as many languages as >> Python3's code point strings and at least equally well. > > You cannot possibly be serious. > > There are 256 possible byte values. China alone has over 10,000 different > characters. You can't represent 10,000+ characters using only 256 > distinct code points. > > You can't even represent the world's languages using 16-bit word-strings > instead of byte strings. I think you're tearing down a straw man here. (So is Marko.) The byte-string-only argument is to use byte strings containing encoded text. This does always work. It's just very easy to make mistakes like double-encoding. The "do what Python 3 does" argument is, as I see it, that it's better to deal with text independently of its encoding, and explicitly converting to and from byte representations. I'm very much in favour, not particularly because it prevents errors (though it does), but because it saves me from having to manage irrelevant details like the encoding of the text in question. Imagine if people made the same argument: "byte strings are better than a representation-independent type" about, say, integers. Using byte strings instead of integers is great! You can roundtrip any integer and not care how it's encoded! You can print it to a terminal or a file or anything without having to pointlessly re-encode it! Okay, so things get a bit hairy if someone uses hex instead of the obviously-superior decimal, but nobody does that. And when they do, you can just bytes.decode('int-hex'). Just remember not to do it more than once, a famously easy problem in programming that has never bitten anyone ever, and you're golden. Look at all the problems this solves! Now we can even parse a file format with integers in it and emit them again without having to know what encoding the integers are, which doesn't actually save us from any encoding headaches because we need to figure out the encoding to work with those integers at all, but will make for good ammunition against those ridiculous integer zealots. On a more serious note, I think this particular aspect of Python causes quite a lot of difficulty for Python 2 programs that make heavy use of the bytes-text duality, and quite a lot of peace of mind for every other case. So, Marko, I don't know what code you work on, but I think it's unfair to attack Python 3's unicode handling too hard if you haven't written a new project with it. From ethan at stoneleaf.us Sun Jul 15 13:25:37 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 15 Jul 2018 10:25:37 -0700 Subject: Users banned Message-ID: <5B4B8391.3060808@stoneleaf.us> From the Python List sign-up page: About Python-list: This mailing list is a general discussion list for the Python programming language. --- From the Python CoC A member of the Python community is: Open, Considerate, Respectful --- There is only a handful of volunteer list moderators, and we cannot read every message, nor every thread on Python List. If anyone notices a bad actor [1] they are responsible for two things: do not engage with them any further; and report them to the list moderators [2]. Continuing to talk them or about them on the list only damages this community and your own reputation. --- The following users are now banned from Python List: Ranting Rick Johnson BartC voteswithfeet at gmail.com Rick, Bart, voteswithfeet, if you would like to be reinstated you may petition us in 2019. --- For those who access Python List via the usenet and still see their posts, please do not engage with them. -- Python List Moderators [1] Most bad actors are not obvious at first, but are usually discernible after a few interactions. [2] python-list-owner at python.org From jlee54 at gmail.com Sun Jul 15 14:22:11 2018 From: jlee54 at gmail.com (James Lee) Date: Sun, 15 Jul 2018 11:22:11 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> Message-ID: <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> On 7/15/2018 3:43 AM, Steven D'Aprano wrote: > > No. The real ten billion dollar question is how people in 2018 can stick > their head in the sand and take seriously the position that Latin-1 (let > alone ASCII) is enough for text strings. > > Easy - for many people, 90% of the Python code they write is not intended for world-wide distribution, let alone use. The smart thing would be for a language to have a switch of some sort to turn on/off all I18N features. -Jim From info at tundraware.com Sun Jul 15 14:30:33 2018 From: info at tundraware.com (Tim Daneliuk) Date: Sun, 15 Jul 2018 13:30:33 -0500 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> Message-ID: <9fgs1f-tjk1.ln1@oceanview.tundraware.com> On 07/14/2018 07:40 PM, Chris Angelico wrote: > You'd better avoid most of JavaScript, C++, and most other languages, > then. Every language feeps a little, and Python is definitely not as > bad as some. Point Of Order: C++ is one gigantic feep to be avoided at all costs... :) From auriocus at gmx.de Sun Jul 15 15:18:03 2018 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 15 Jul 2018 21:18:03 +0200 Subject: Users banned In-Reply-To: References: <5B4B8391.3060808@stoneleaf.us> Message-ID: Am 15.07.18 um 19:25 schrieb Ethan Furman: > > The following users are now banned from Python List: > > ... > BartC I don't really think that this is appropriate. Bart may have deviant optinions, mostly he thinks that his own work is superior to Python - but he has always argued in a calm and technical manner. Christian From python at mrabarnett.plus.com Sun Jul 15 15:37:56 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 15 Jul 2018 20:37:56 +0100 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> References: <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> Message-ID: On 2018-07-15 19:22, James Lee wrote: > > > On 7/15/2018 3:43 AM, Steven D'Aprano wrote: >> >> No. The real ten billion dollar question is how people in 2018 can stick >> their head in the sand and take seriously the position that Latin-1 (let >> alone ASCII) is enough for text strings. >> >> > > Easy - for many people, 90% of the Python code they write is not > intended for world-wide distribution, let alone use. > True. > The smart thing would be for a language to have a switch of some sort to > turn on/off all I18N features. > To me, Unicode and UTF-8 aren't things to be reserved for I18N. I use them as a matter of course because I find it a lot easier to stick with just one encoding, one that will work with _any_ text I have. From tjreedy at udel.edu Sun Jul 15 16:06:35 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 15 Jul 2018 16:06:35 -0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87tvp03f2p.fsf@elektro.pacujo.net> References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> Message-ID: On 7/15/2018 7:37 AM, Marko Rauhamaa wrote: > One of the classic Unix and Internet tenets is that text is bytes is > text. Tenets of a faith may be wrong ;-). An informatic paradigm from more than 45 years ago may be outdated and in need of revision. On byte storage and on the Internet, **everything** is (encoded) bytes, so saying 'text is bytes' says nothing because it is trivially true. On the other hand, 'bytes is text' is wrong unless one uses a character encoding that assigns a visible character (including ) to every byte. I believe both PCs and Macs had 1 or more such encodings. (I am only uncertain as to whether b'\x00' was mapped.) Images are bytes as much as text is. I suggest that 'bytes is image' is more true than 'bytes is text'. Every byte can be mapped, for instance, into an 8 x 1 or 1 x 8 pixel image after deciding which end gets the high and low bits. Bit mapping is likely older than Unix. Bar codes and QR codes are commonplace as international machine-readable images of bytes. In a context where 'everything is bytes', then 'bytes is everything' or 'bytes can be anything' are the proper reverses. > Of course, much of it was na?ve, but UTF-8 has miraculously given > it a new life. UTF-8 makes 'bytes is text' even less true. Not only are some leading bytes not text, but some byte sequences are illegal. Bytes are not UTF-8 text. As n increases, the probability that a string of n random bytes will be utf-8 text approaches 0 faster than interpreting the same bytes as Latin1. -- Terry Jan Reedy From rosuav at gmail.com Sun Jul 15 16:09:21 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Jul 2018 06:09:21 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> Message-ID: On Mon, Jul 16, 2018 at 4:22 AM, James Lee wrote: > > > On 7/15/2018 3:43 AM, Steven D'Aprano wrote: >> >> >> No. The real ten billion dollar question is how people in 2018 can stick >> their head in the sand and take seriously the position that Latin-1 (let >> alone ASCII) is enough for text strings. >> >> > > Easy - for many people, 90% of the Python code they write is not intended > for world-wide distribution, let alone use. > > The smart thing would be for a language to have a switch of some sort to > turn on/off all I18N features. > Earlier I cited an example of round-tripping from human to human via various web protocols. Here's an actual example of a Twitch stream title: ?? Stardew Valley Fanart ??*:???? 800 Subpoints = NEW EMOTE ?#devicat #anime #stardewvalley #fantasy Citation: https://www.twitch.tv/devicat just went live with that title. This is a channel where rule #3 is that everyone should speak English. If "all I18N features" are disabled, would this title be disallowed? Several of those characters are not in Latin-1; one of them (occurring twice) isn't even in the BMP. ChrisA From jlee54 at gmail.com Sun Jul 15 16:09:59 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 15 Jul 2018 13:09:59 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> Message-ID: On 07/15/18 12:37, MRAB wrote: > To me, Unicode and UTF-8 aren't things to be reserved for I18N. I use > them as a matter of course because I find it a lot easier to stick > with just one encoding, one that will work with _any_ text I have. Which is exactly the same rationale for using any other single encoding (including ASCII).? If the text you deal with is not multi-lingual, why complicate matters by trying to support a plethora of encodings which will never be used (and the attendant opportunity for more bugs)? Note that I'm *not* saying Unicode? is *bad*, just that it's an unnecessary complication for a great deal of programming tasks.? For a great deal more, it's absolutely necessary.? That why I said a "smart" language would make it easy to turn on and off. -Jim From jlee54 at gmail.com Sun Jul 15 16:20:26 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 15 Jul 2018 13:20:26 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> Message-ID: <415de53d-25a4-0eb6-6560-7460ece24093@gmail.com> On 07/15/18 13:09, Chris Angelico wrote: > On Mon, Jul 16, 2018 at 4:22 AM, James Lee wrote: >> >> On 7/15/2018 3:43 AM, Steven D'Aprano wrote: >>> >>> No. The real ten billion dollar question is how people in 2018 can stick >>> their head in the sand and take seriously the position that Latin-1 (let >>> alone ASCII) is enough for text strings. >>> >>> >> Easy - for many people, 90% of the Python code they write is not intended >> for world-wide distribution, let alone use. >> >> The smart thing would be for a language to have a switch of some sort to >> turn on/off all I18N features. >> > Earlier I cited an example of round-tripping from human to human via > various web protocols. Here's an actual example of a Twitch stream > title: > > ?? Stardew Valley Fanart ??*:???? 800 Subpoints = NEW EMOTE > ?#devicat #anime #stardewvalley #fantasy > > Citation: https://www.twitch.tv/devicat just went live with that > title. This is a channel where rule #3 is that everyone should speak > English. If "all I18N features" are disabled, would this title be > disallowed? Several of those characters are not in Latin-1; one of > them (occurring twice) isn't even in the BMP. > > ChrisA I have absolutely zero interest in Twitch - I don't even know what it is. This should drive home my point that, for many tasks, I18N or, more specifically, Unicode is an unnecessary complication. If my program doesn't give a whit about web protocols or emoji, then how some Twitch title displays itself is irrelevant. -Jim From rosuav at gmail.com Sun Jul 15 16:26:04 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Jul 2018 06:26:04 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> Message-ID: On Mon, Jul 16, 2018 at 6:06 AM, Terry Reedy wrote: > On 7/15/2018 7:37 AM, Marko Rauhamaa wrote: > >> One of the classic Unix and Internet tenets is that text is bytes is >> text. > > > Tenets of a faith may be wrong ;-). An informatic paradigm from more than > 45 years ago may be outdated and in need of revision. > > On byte storage and on the Internet, **everything** is (encoded) bytes, so > saying 'text is bytes' says nothing because it is trivially true. True, but only at *some* abstraction levels. We have to dive down low enough that it's no longer text, but not so low that the bytes become bits, or electrical signals. The ONLY reason that people think "everything is bytes" is that most application programmers never have to go to the lower abstraction layers - in the same way that most application programmers pretend that TCP/IP sockets are pipes that you push stuff onto and it comes out at the other end. It would be just as valid for an accountant to assert that all money amounts are pencil strokes - not numbers, not marks on paper, but movements of a pencil. ChrisA From rosuav at gmail.com Sun Jul 15 16:30:39 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Jul 2018 06:30:39 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> Message-ID: On Mon, Jul 16, 2018 at 6:09 AM, Jim Lee wrote: > > > On 07/15/18 12:37, MRAB wrote: >> >> To me, Unicode and UTF-8 aren't things to be reserved for I18N. I use them >> as a matter of course because I find it a lot easier to stick with just one >> encoding, one that will work with _any_ text I have. > > > Which is exactly the same rationale for using any other single encoding > (including ASCII). If the text you deal with is not multi-lingual, why > complicate matters by trying to support a plethora of encodings which will > never be used (and the attendant opportunity for more bugs)? > > Note that I'm *not* saying Unicode is *bad*, just that it's an unnecessary > complication for a great deal of programming tasks. For a great deal more, > it's absolutely necessary. That why I said a "smart" language would make it > easy to turn on and off. > If you're going to use just one encoding, use UTF-8. That way, you support all the world's languages, but you still don't have to worry about "a plethora of encodings". On Mon, Jul 16, 2018 at 6:20 AM, Jim Lee wrote: > I have absolutely zero interest in Twitch - I don't even know what it is. > > This should drive home my point that, for many tasks, I18N or, more specifically, Unicode is an unnecessary complication. > > If my program doesn't give a whit about web protocols or emoji, then how some Twitch title displays itself is irrelevant. It doesn't matter what Twitch is, except for the fact that it is a platform for HUMANS to communicate with HUMANS. Ultimately, that is what matters. Pick any other web site or communication protocol you please. ChrisA From pkpearson at nowhere.invalid Sun Jul 15 16:40:57 2018 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 15 Jul 2018 20:40:57 GMT Subject: Morning after Message-ID: As if in a wake for Guido, grief was grieved, drinks were drunk, voices were raised, and some furniture was broken. Now, please, let's resume being the most civil newsgroup on the net. -- To email me, substitute nowhere->runbox, invalid->com. From jlee54 at gmail.com Sun Jul 15 17:02:11 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 15 Jul 2018 14:02:11 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> Message-ID: <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> On 07/15/18 13:30, Chris Angelico wrote: > > It doesn't matter what Twitch is, except for the fact that it is a > platform for HUMANS to communicate with HUMANS. Ultimately, that is > what matters. Pick any other web site or communication protocol you > please. > > ChrisA Yes, and for *that*, language matters;? but, for a vast array of programming tasks that *don't* involve global communications, it's an added level of complexity with zero benefit.? It would be *nice* to be able to turn support on or off, depending on the requirements of the individual program or, better yet, be able to simply ignore the feature(s). -Jim From marko at pacujo.net Sun Jul 15 17:15:52 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 16 Jul 2018 00:15:52 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <87zhys3fz4.fsf@elektro.pacujo.net> <836c88f4-17f0-37fc-e11a-bbddb88f31d2@kellett.im> Message-ID: <87fu0k2oaf.fsf@elektro.pacujo.net> Ed Kellett : > So, Marko, I don't know what code you work on, but I think it's unfair > to attack Python 3's unicode handling too hard if you haven't written > a new project with it. I don't believe the problem was solely in the difficulty of conversion. It was primarily in the tricky (and apparently pointless) decision-making. Which of these are text (really) and bytes (really): * Pathnames * Commands * Stdin/Stdout/Stderr * environment variables * URIs * HTTP header field names * HTTP header field values * HTTP methods * HTTP content * SMTP messages * Email messages * Base64 encodings * Hexadecimal encodings * JSON encoding and so on. And BTW, I have implemented an SMTP server in Python3 from scratch, and was struggling with similar issues. The code riddled with lines like this: conn.request('EHLO {}\r\n'.format(domain).encode()) In Linux protocol and system programming, text is just the wrong abstraction. I doubt there are very many situations where Python3's UTF-32 strings are a more opportune abstraction than UTF-8 strings are. Marko From marko at pacujo.net Sun Jul 15 17:28:39 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 16 Jul 2018 00:28:39 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> Message-ID: <87bmb82np4.fsf@elektro.pacujo.net> Terry Reedy : > On 7/15/2018 7:37 AM, Marko Rauhamaa wrote: >> One of the classic Unix and Internet tenets is that text is bytes is >> text. > > Tenets of a faith may be wrong ;-). An informatic paradigm from more > than 45 years ago may be outdated and in need of revision. > > [...] > >> Of course, much of it was na?ve, but UTF-8 has miraculously given >> it a new life. > > UTF-8 makes 'bytes is text' even less true. Not only are some leading > bytes not text, but some byte sequences are illegal. Bytes are not > UTF-8 text. As n increases, the probability that a string of n random > bytes will be utf-8 text approaches 0 faster than interpreting the > same bytes as Latin1. Yes, but Linux and the Internet are my bread and butter (and more). The 45-year-old axioms still hold, whatever complications they lead to. If you wanted to change that, you'd have to build your system from ground up. Windows, BTW, isn't that system, nor is macOS. They made some moves in that direction, but ended up making some missteps as well. And beware, if your new system used Python3's UTF-32 strings as a foundation, that would be an equally na?ve misstep. You'd need to reach a notch higher and use glyphs or other "semiotic atoms" as building blocks. UTF-32, after all, is a variable-width encoding. Marko From marko at pacujo.net Sun Jul 15 17:35:28 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 16 Jul 2018 00:35:28 +0300 Subject: Users banned References: <5B4B8391.3060808@stoneleaf.us> Message-ID: <877elw2ndr.fsf@elektro.pacujo.net> Christian Gollwitzer : > Am 15.07.18 um 19:25 schrieb Ethan Furman: >> The following users are now banned from Python List: >> ... >> BartC > > I don't really think that this is appropriate. Bart may have deviant > optinions, mostly he thinks that his own work is superior to Python - > but he has always argued in a calm and technical manner. +1 Marko From marko at pacujo.net Sun Jul 15 17:50:20 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 16 Jul 2018 00:50:20 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> Message-ID: <87y3ec184j.fsf@elektro.pacujo.net> Jim Lee : > Yes, and for *that*, language matters;? but, for a vast array of > programming tasks that *don't* involve global communications, it's an > added level of complexity with zero benefit.? It would be *nice* to be > able to turn support on or off, depending on the requirements of the > individual program or, better yet, be able to simply ignore the > feature(s). Can you illustrate your point with some lines of Python code? Marko From rosuav at gmail.com Sun Jul 15 17:53:17 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Jul 2018 07:53:17 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> Message-ID: On Mon, Jul 16, 2018 at 7:02 AM, Jim Lee wrote: > > > On 07/15/18 13:30, Chris Angelico wrote: >> >> >> It doesn't matter what Twitch is, except for the fact that it is a >> platform for HUMANS to communicate with HUMANS. Ultimately, that is >> what matters. Pick any other web site or communication protocol you >> please. >> >> ChrisA > > > Yes, and for *that*, language matters; but, for a vast array of programming > tasks that *don't* involve global communications, it's an added level of > complexity with zero benefit. It would be *nice* to be able to turn support > on or off, depending on the requirements of the individual program or, > better yet, be able to simply ignore the feature(s). > Okay. Show me something where language doesn't matter, but you still need characters. ChrisA From rosuav at gmail.com Sun Jul 15 17:53:55 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Jul 2018 07:53:55 +1000 Subject: Users banned In-Reply-To: <877elw2ndr.fsf@elektro.pacujo.net> References: <5B4B8391.3060808@stoneleaf.us> <877elw2ndr.fsf@elektro.pacujo.net> Message-ID: On Mon, Jul 16, 2018 at 7:35 AM, Marko Rauhamaa wrote: > Christian Gollwitzer : > >> Am 15.07.18 um 19:25 schrieb Ethan Furman: >>> The following users are now banned from Python List: >>> ... >>> BartC >> >> I don't really think that this is appropriate. Bart may have deviant >> optinions, mostly he thinks that his own work is superior to Python - >> but he has always argued in a calm and technical manner. > > +1 > How about we trust the moderators to moderate wisely? ChrisA From jlee54 at gmail.com Sun Jul 15 17:57:28 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 15 Jul 2018 14:57:28 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> Message-ID: <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> On 07/15/18 14:53, Chris Angelico wrote: > On Mon, Jul 16, 2018 at 7:02 AM, Jim Lee wrote: >> >> On 07/15/18 13:30, Chris Angelico wrote: >>> >>> It doesn't matter what Twitch is, except for the fact that it is a >>> platform for HUMANS to communicate with HUMANS. Ultimately, that is >>> what matters. Pick any other web site or communication protocol you >>> please. >>> >>> ChrisA >> >> Yes, and for *that*, language matters; but, for a vast array of programming >> tasks that *don't* involve global communications, it's an added level of >> complexity with zero benefit. It would be *nice* to be able to turn support >> on or off, depending on the requirements of the individual program or, >> better yet, be able to simply ignore the feature(s). >> > Okay. Show me something where language doesn't matter, but you still > need characters. > > ChrisA You seem to be purposefully obfuscating things. One language, not zero languages.? Obviously. -Jim From rosuav at gmail.com Sun Jul 15 18:07:45 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Jul 2018 08:07:45 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> Message-ID: On Mon, Jul 16, 2018 at 7:57 AM, Jim Lee wrote: > > > On 07/15/18 14:53, Chris Angelico wrote: >> >> On Mon, Jul 16, 2018 at 7:02 AM, Jim Lee wrote: >>> >>> >>> On 07/15/18 13:30, Chris Angelico wrote: >>>> >>>> >>>> It doesn't matter what Twitch is, except for the fact that it is a >>>> platform for HUMANS to communicate with HUMANS. Ultimately, that is >>>> what matters. Pick any other web site or communication protocol you >>>> please. >>>> >>>> ChrisA >>> >>> >>> Yes, and for *that*, language matters; but, for a vast array of >>> programming >>> tasks that *don't* involve global communications, it's an added level of >>> complexity with zero benefit. It would be *nice* to be able to turn >>> support >>> on or off, depending on the requirements of the individual program or, >>> better yet, be able to simply ignore the feature(s). >>> >> Okay. Show me something where language doesn't matter, but you still >> need characters. >> >> ChrisA > > > You seem to be purposefully obfuscating things. > > One language, not zero languages. Obviously. DeviCat's channel specifically has "English only" as chat rule #3, yet you admit that it requires "language" and thus text. One language or many, you need text. Nothing I ever said was assuming multiple languages. ChrisA From skip.montanaro at gmail.com Sun Jul 15 18:16:06 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 15 Jul 2018 17:16:06 -0500 Subject: Reading EmailMessage from file Message-ID: I have an email message in a file (see attached). According to this page: https://docs.python.org/3/library/email.examples.html something like this should construct an email message from the file: >>> from email.message import EmailMessage >>> msg = EmailMessage() >>> fp = open("/home/skip/tmp/79487694") >>> msg.set_content(fp.read()) However, my default encoding is utf-8 and the mail message is encoded using iso-8859-1, so it barfs trying to read the file. I know I can explicitly specify the encoding in an isolated case like this, but it seems like that shouldn't be necessary when reading a message from a stream or file. I tried opening the file with "rb", but got further downstream errors because I failed to set maintype and subtype. Again, these are elements of the message structure and should be decipherable by some bit of code which wants to construct the message object. I'm clearly missing something. Thx, Skip From jlee54 at gmail.com Sun Jul 15 18:53:50 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 15 Jul 2018 15:53:50 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> Message-ID: <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> On 07/15/18 15:07, Chris Angelico wrote: > On Mon, Jul 16, 2018 at 7:57 AM, Jim Lee wrote: >> >> On 07/15/18 14:53, Chris Angelico wrote: >>> On Mon, Jul 16, 2018 at 7:02 AM, Jim Lee wrote: >>>> >>>> On 07/15/18 13:30, Chris Angelico wrote: >>>>> >>>>> It doesn't matter what Twitch is, except for the fact that it is a >>>>> platform for HUMANS to communicate with HUMANS. Ultimately, that is >>>>> what matters. Pick any other web site or communication protocol you >>>>> please. >>>>> >>>>> ChrisA >>>> >>>> Yes, and for *that*, language matters; but, for a vast array of >>>> programming >>>> tasks that *don't* involve global communications, it's an added level of >>>> complexity with zero benefit. It would be *nice* to be able to turn >>>> support >>>> on or off, depending on the requirements of the individual program or, >>>> better yet, be able to simply ignore the feature(s). >>>> >>> Okay. Show me something where language doesn't matter, but you still >>> need characters. >>> >>> ChrisA >> >> You seem to be purposefully obfuscating things. >> >> One language, not zero languages. Obviously. > DeviCat's channel specifically has "English only" as chat rule #3, yet > you admit that it requires "language" and thus text. One language or > many, you need text. Nothing I ever said was assuming multiple > languages. > > ChrisA I have no clue what this has to do with the original point - that sometimes programs only need to deal with one language, not many (and emoji are tangential to the discussion). -Jim From rosuav at gmail.com Sun Jul 15 19:04:15 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Jul 2018 09:04:15 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> Message-ID: On Mon, Jul 16, 2018 at 8:53 AM, Jim Lee wrote: > > > On 07/15/18 15:07, Chris Angelico wrote: >> >> On Mon, Jul 16, 2018 at 7:57 AM, Jim Lee wrote: >>> >>> >>> On 07/15/18 14:53, Chris Angelico wrote: >>>> >>>> On Mon, Jul 16, 2018 at 7:02 AM, Jim Lee wrote: >>>>> >>>>> >>>>> On 07/15/18 13:30, Chris Angelico wrote: >>>>>> >>>>>> >>>>>> It doesn't matter what Twitch is, except for the fact that it is a >>>>>> platform for HUMANS to communicate with HUMANS. Ultimately, that is >>>>>> what matters. Pick any other web site or communication protocol you >>>>>> please. >>>>>> >>>>>> ChrisA >>>>> >>>>> >>>>> Yes, and for *that*, language matters; but, for a vast array of >>>>> programming >>>>> tasks that *don't* involve global communications, it's an added level >>>>> of >>>>> complexity with zero benefit. It would be *nice* to be able to turn >>>>> support >>>>> on or off, depending on the requirements of the individual program or, >>>>> better yet, be able to simply ignore the feature(s). >>>>> >>>> Okay. Show me something where language doesn't matter, but you still >>>> need characters. >>>> >>>> ChrisA >>> >>> >>> You seem to be purposefully obfuscating things. >>> >>> One language, not zero languages. Obviously. >> >> DeviCat's channel specifically has "English only" as chat rule #3, yet >> you admit that it requires "language" and thus text. One language or >> many, you need text. Nothing I ever said was assuming multiple >> languages. >> >> ChrisA > > > I have no clue what this has to do with the original point - that sometimes > programs only need to deal with one language, not many (and emoji are > tangential to the discussion). > You claimed that Unicode was insignificant to many programs. I'm trying to say that a Unicode text string is a vital part of any program that works with text, which is pretty much anything that talks to humans. You keep saying that ... well you keep saying different things, and I've lost track of what your point actually is, but you want a way to... disable Unicode? Or something? And you have yet to give any example of a program that doesn't need Unicode, but still uses text. ChrisA From jlee54 at gmail.com Sun Jul 15 19:08:15 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 15 Jul 2018 16:08:15 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87y3ec184j.fsf@elektro.pacujo.net> References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> Message-ID: <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> On 07/15/18 14:50, Marko Rauhamaa wrote: > Jim Lee : >> Yes, and for *that*, language matters;? but, for a vast array of >> programming tasks that *don't* involve global communications, it's an >> added level of complexity with zero benefit.? It would be *nice* to be >> able to turn support on or off, depending on the requirements of the >> individual program or, better yet, be able to simply ignore the >> feature(s). > Can you illustrate your point with some lines of Python code? > > > Marko Python3 is intrinsically tied to Unicode for string handling. Therefore, the Python programmer is forced to deal with it (in all but trivial cases), rather than given a choice.? So I don't understand how I can illustrate my point with Python code since Python won't let me deal with strings without also dealing with Unicode. -Jim -Jim From jlee54 at gmail.com Sun Jul 15 19:10:33 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 15 Jul 2018 16:10:33 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> Message-ID: <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> On 07/15/18 16:04, Chris Angelico wrote: > > You claimed that Unicode was insignificant to many programs. I'm > trying to say that a Unicode text string is a vital part of any > program that works with text, which is pretty much anything that talks > to humans. You keep saying that ... well you keep saying different > things, and I've lost track of what your point actually is, but you > want a way to... disable Unicode? Or something? And you have yet to > give any example of a program that doesn't need Unicode, but still > uses text. > > ChrisA Why does this seem so obtuse to you? Have you never heard of programming BEFORE Unicode existed? How ever did we get along?? It must have been a hallucination... -Jim From rosuav at gmail.com Sun Jul 15 19:13:24 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Jul 2018 09:13:24 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On Mon, Jul 16, 2018 at 9:08 AM, Jim Lee wrote: > > > On 07/15/18 14:50, Marko Rauhamaa wrote: >> >> Jim Lee : >>> >>> Yes, and for *that*, language matters; but, for a vast array of >>> programming tasks that *don't* involve global communications, it's an >>> added level of complexity with zero benefit. It would be *nice* to be >>> able to turn support on or off, depending on the requirements of the >>> individual program or, better yet, be able to simply ignore the >>> feature(s). >> >> Can you illustrate your point with some lines of Python code? >> >> >> Marko > > > Python3 is intrinsically tied to Unicode for string handling. Therefore, the > Python programmer is forced to deal with it (in all but trivial cases), > rather than given a choice. So I don't understand how I can illustrate my > point with Python code since Python won't let me deal with strings without > also dealing with Unicode. When a Python program works with integers, the programmer isn't given the choice of being restricted to machine words, but is forced to have the freedom to use any integer at all (bignums). There are very rare situations where you actually want integer wrap-around, and those have to be implemented using modulo arithmetic or similar. This is generally considered to be the correct trade-off, since those situations are usually fairly low-level anyway (implementing an algorithm originally spec'd up in C). Provide a single example of something where the freedom to use all of Unicode in text handling is actually a bad thing. ChrisA From jlee54 at gmail.com Sun Jul 15 19:22:17 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 15 Jul 2018 16:22:17 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On 07/15/18 16:13, Chris Angelico wrote: > On Mon, Jul 16, 2018 at 9:08 AM, Jim Lee wrote: >> >> On 07/15/18 14:50, Marko Rauhamaa wrote: >>> Jim Lee : >>>> Yes, and for *that*, language matters; but, for a vast array of >>>> programming tasks that *don't* involve global communications, it's an >>>> added level of complexity with zero benefit. It would be *nice* to be >>>> able to turn support on or off, depending on the requirements of the >>>> individual program or, better yet, be able to simply ignore the >>>> feature(s). >>> Can you illustrate your point with some lines of Python code? >>> >>> >>> Marko >> >> Python3 is intrinsically tied to Unicode for string handling. Therefore, the >> Python programmer is forced to deal with it (in all but trivial cases), >> rather than given a choice. So I don't understand how I can illustrate my >> point with Python code since Python won't let me deal with strings without >> also dealing with Unicode. > When a Python program works with integers, the programmer isn't given > the choice of being restricted to machine words, but is forced to have > the freedom to use any integer at all (bignums). There are very rare > situations where you actually want integer wrap-around, and those have > to be implemented using modulo arithmetic or similar. This is > generally considered to be the correct trade-off, since those > situations are usually fairly low-level anyway (implementing an > algorithm originally spec'd up in C). > > Provide a single example of something where the freedom to use all of > Unicode in text handling is actually a bad thing. > > ChrisA You've turned my argument upside down by redefine terms mid-stream. Now, using Unicode is a "freedom" rather than a restriction.? You've also introduced a straw-man argument by introducing integers as a parallel analogy (which it isn't - integers are language agnostic). There's no point in debating when the target keeps changing. -Jim From rosuav at gmail.com Sun Jul 15 19:24:08 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Jul 2018 09:24:08 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> Message-ID: On Mon, Jul 16, 2018 at 9:10 AM, Jim Lee wrote: > > > On 07/15/18 16:04, Chris Angelico wrote: >> >> >> You claimed that Unicode was insignificant to many programs. I'm >> trying to say that a Unicode text string is a vital part of any >> program that works with text, which is pretty much anything that talks >> to humans. You keep saying that ... well you keep saying different >> things, and I've lost track of what your point actually is, but you >> want a way to... disable Unicode? Or something? And you have yet to >> give any example of a program that doesn't need Unicode, but still >> uses text. >> >> ChrisA > > > Why does this seem so obtuse to you? > > Have you never heard of programming BEFORE Unicode existed? > > How ever did we get along? It must have been a hallucination... Yes, I was writing code before Unicode existed. Have you ever heard of IBM DBCS? Here's something I could find on the web, though back then, I was using non-internet documentation for everything: https://www.ibm.com/support/knowledgecenter/en/ssw_i5_54/nls/rbagssqlanddbchars.htm Most programs assumed SBCS, with a single system-wide primary codepage, and a number of "available" codepages. If you needed to switch code pages, you would generally do so for the entire program. If you needed to mix and match codepages in a program, life was hard. If you needed to mix and match codepages in a document, life was extremely hard. Using DBCS allowed a lot more variety of languages, but you had to use dedicated DBCS APIs for everything. Even just indexing characters couldn't be done, because of shift codes and such. An operation like "remove the rightmost three characters from this string" required a function like DBRRIGHT() rather than taking it the easy way. I do not want to go back to those days. UTF-8 has a few of those problems (for instance, indexing characters is hard, since it's a variable-width encoding), but at least every character has a single byte representation, meaning that valid UTF-8 strings can be joined trivially and interpreted without needing context. Using a Python 3 string, you don't even have to worry about that - you just work with characters as fundamental units. That is why this seems obtuse to me. There is no benefit to going to a pre-Unicode way of working with text. ChrisA From rosuav at gmail.com Sun Jul 15 19:24:59 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 16 Jul 2018 09:24:59 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On Mon, Jul 16, 2018 at 9:22 AM, Jim Lee wrote: > > You've turned my argument upside down by redefine terms mid-stream. Now, > using Unicode is a "freedom" rather than a restriction. You've also > introduced a straw-man argument by introducing integers as a parallel > analogy (which it isn't - integers are language agnostic). > > There's no point in debating when the target keeps changing. Explain to me how Unicode is a restriction. You keep asserting things without giving evidence, let alone proof. ChrisA From jon+usenet at unequivocal.eu Sun Jul 15 19:29:20 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 15 Jul 2018 23:29:20 -0000 (UTC) Subject: Users banned References: <5B4B8391.3060808@stoneleaf.us> <877elw2ndr.fsf@elektro.pacujo.net> Message-ID: On 2018-07-15, Chris Angelico wrote: > On Mon, Jul 16, 2018 at 7:35 AM, Marko Rauhamaa wrote: >> Christian Gollwitzer : >>> Am 15.07.18 um 19:25 schrieb Ethan Furman: >>>> The following users are now banned from Python List: >>>> ... >>>> BartC >>> >>> I don't really think that this is appropriate. Bart may have deviant >>> optinions, mostly he thinks that his own work is superior to Python - >>> but he has always argued in a calm and technical manner. >> >> +1 > > How about we trust the moderators to moderate wisely? Do you have any reason to believe the message at the top of the thread purporting to ban users was genuinely from the moderators? Because there are obvious reasons to believe otherwise. From jlee54 at gmail.com Sun Jul 15 19:30:47 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 15 Jul 2018 16:30:47 -0700 Subject: Users banned In-Reply-To: References: <5B4B8391.3060808@stoneleaf.us> <877elw2ndr.fsf@elektro.pacujo.net> Message-ID: <5b7046a6-4c96-c8b0-9b5b-ec7999d4865d@gmail.com> On 07/15/18 14:53, Chris Angelico wrote: > On Mon, Jul 16, 2018 at 7:35 AM, Marko Rauhamaa wrote: >> Christian Gollwitzer : >> >>> Am 15.07.18 um 19:25 schrieb Ethan Furman: >>>> The following users are now banned from Python List: >>>> ... >>>> BartC >>> I don't really think that this is appropriate. Bart may have deviant >>> optinions, mostly he thinks that his own work is superior to Python - >>> but he has always argued in a calm and technical manner. >> +1 >> > How about we trust the moderators to moderate wisely? > > ChrisA That is, of course, the decision of the moderators - but I happen to agree with both Christian and Ethan.? Banning for the simple reason of a dissenting opinion is censorship, pure and simple.? While Bart may have been prolific in his arguments, he never spoke in a toxic or condescending manner, or broke any of the rules of conduct.? I cannot say the same for several who engaged with him. -Jim From jon+usenet at unequivocal.eu Sun Jul 15 19:34:12 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 15 Jul 2018 23:34:12 -0000 (UTC) Subject: Reading EmailMessage from file References: Message-ID: On 2018-07-15, Skip Montanaro wrote: > I have an email message in a file (see attached). Attachments don't work here. > something like this should construct an email message from the file: > >>>> from email.message import EmailMessage >>>> msg = EmailMessage() >>>> fp = open("/home/skip/tmp/79487694") >>>> msg.set_content(fp.read()) What are you actually trying to do? You're talking like you're trying to read an existing RFC822 email-with-headers from a file, but you're showing code that creates a new email with body content set from a file, which is a completely different thing. From sleadpc at gmail.com Sun Jul 15 19:37:01 2018 From: sleadpc at gmail.com (S Lea) Date: Sun, 15 Jul 2018 16:37:01 -0700 Subject: can't install/run pip (Latest version of Python) Message-ID: I can't seem to install the pips, DOS gives me the syntex i invalid, any thoughts?? Thank you From jlee54 at gmail.com Sun Jul 15 19:38:41 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 15 Jul 2018 16:38:41 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> Message-ID: On 07/15/18 16:24, Chris Angelico wrote: > > That is why this seems obtuse to me. There is no benefit to going to a > pre-Unicode way of working with text. > > ChrisA In a word - simplicity. As I said, there are programming situations where the programmer only needs to deal with a single language - his own. As I also said, Unicode (which is the best solution we have at the moment for global interchange) is necessary when we *do* need to deal with text on a broader scale. -Jim From steve+comp.lang.python at pearwood.info Sun Jul 15 19:55:12 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 15 Jul 2018 23:55:12 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> Message-ID: On Sun, 15 Jul 2018 11:22:11 -0700, James Lee wrote: > On 7/15/2018 3:43 AM, Steven D'Aprano wrote: >> >> No. The real ten billion dollar question is how people in 2018 can >> stick their head in the sand and take seriously the position that >> Latin-1 (let alone ASCII) is enough for text strings. >> >> >> > Easy - for many people, 90% of the Python code they write is not > intended for world-wide distribution, let alone use. But they're not making claims about what works for *them*. If they did, I'd say "Okay, that works for you. Sorry you got left behind by progress." They're making grand sweeping claims about what works best for a language intended to be used by *everyone*. Marko isn't saying "I know my use-case is atypical, but I inherited a code base where the bytes/pseudo-text duality of Python2 strings was helpful to me, and Python3's strict division into byte strings and text strings is less useful." Rather, he is making the sweeping generalisation that having a text string type *at all* is a mistake, because the Python 2 dual bytes+pseudo text approach is superior, *for everyone*. > The smart thing would be for a language to have a switch of some sort to > turn on/off all I18N features. The Python language has no builtin I18N features. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jul 15 20:16:57 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 16 Jul 2018 00:16:57 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> Message-ID: On Sun, 15 Jul 2018 13:09:59 -0700, Jim Lee wrote: > On 07/15/18 12:37, MRAB wrote: >> To me, Unicode and UTF-8 aren't things to be reserved for I18N. I use >> them as a matter of course because I find it a lot easier to stick with >> just one encoding, one that will work with _any_ text I have. > > Which is exactly the same rationale for using any other single encoding > (including ASCII). Which encoding should I choose? Having chosen one today, which encoding should I choose tomorrow? > If the text you deal with is not multi-lingual, why > complicate matters by trying to support a plethora of encodings which > will never be used (and the attendant opportunity for more bugs)? Who mentioned a plethora of encodings? With the boundaries of your application, using Python 3 text strings means never needing to even consider encodings. The only time you should care about them is when your data crosses the boundary between your application and the rest of the world (e.g. writing to files), and in that case, we should standardise on UTF-8 (unless there's a really good reason not to). Honestly Jim, your response sounds to me the equivalent of: "... and that's why structured programming will never catch on, and why unstructured programming with GOTO is better, faster, more reliable, and can do everything that the programmer needs." Aside from occasional legacy software reasons, I believe that one would have to ignore the last 30+ years of "code page hell" to even consider using anything but Unicode in modern application software. > Note that I'm *not* saying Unicode? is *bad*, just that it's an > unnecessary complication for a great deal of programming tasks.? For a > great deal more, it's absolutely necessary.? That why I said a "smart" > language would make it easy to turn on and off. You actually said that I18N features should be able to be turned on and off. Unicode and I18N are unrelated. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From python at mrabarnett.plus.com Sun Jul 15 20:17:55 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 16 Jul 2018 01:17:55 +0100 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> Message-ID: On 2018-07-16 00:10, Jim Lee wrote: > > > On 07/15/18 16:04, Chris Angelico wrote: >> >> You claimed that Unicode was insignificant to many programs. I'm >> trying to say that a Unicode text string is a vital part of any >> program that works with text, which is pretty much anything that talks >> to humans. You keep saying that ... well you keep saying different >> things, and I've lost track of what your point actually is, but you >> want a way to... disable Unicode? Or something? And you have yet to >> give any example of a program that doesn't need Unicode, but still >> uses text. >> >> ChrisA > > Why does this seem so obtuse to you? > > Have you never heard of programming BEFORE Unicode existed? > > How ever did we get along?? It must have been a hallucination... > It wasn't a hallucination, but it was annoying having to deal with code pages. The UK had a version of ASCII that had ? instead of #, France had a version that had both that and ? instead of some character, etc, and, more than once, someone has posted here code that has ? instead of \. Someone on the Auxlang list used to complain about the alphabet used by Esperanto because of some of its letters. He was eventually persuaded to try switching to Unicode and UTF-8. He reported that the switch was a lot easier than he'd expected (because, as had been pointed out, any decent software he was using would already support Unicode, or, if it didn't, there would be an alternative that did). After the switch, he didn't see those letters as a problem any more! From steve+comp.lang.python at pearwood.info Sun Jul 15 20:18:07 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 16 Jul 2018 00:18:07 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On Sun, 15 Jul 2018 16:08:15 -0700, Jim Lee wrote: > Python3 is intrinsically tied to Unicode for string handling. Therefore, > the Python programmer is forced to deal with it (in all but trivial > cases), rather than given a choice.? So I don't understand how I can > illustrate my point with Python code since Python won't let me deal with > strings without also dealing with Unicode. Nonsense. b"Look ma, a Python 2 style ASCII string." -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jlee54 at gmail.com Sun Jul 15 20:28:15 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 15 Jul 2018 17:28:15 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> Message-ID: On 07/15/18 16:55, Steven D'Aprano wrote: > On Sun, 15 Jul 2018 11:22:11 -0700, James Lee wrote: > >> On 7/15/2018 3:43 AM, Steven D'Aprano wrote: >>> No. The real ten billion dollar question is how people in 2018 can >>> stick their head in the sand and take seriously the position that >>> Latin-1 (let alone ASCII) is enough for text strings. >>> >>> >>> >> Easy - for many people, 90% of the Python code they write is not >> intended for world-wide distribution, let alone use. > But they're not making claims about what works for *them*. If they did, > I'd say "Okay, that works for you. Sorry you got left behind by > progress." They're making grand sweeping claims about what works best for > a language intended to be used by *everyone*. "Intended to be used by *everyone*" is also a grand sweeping claim - but I get your point. If you define progress as the direction in which the majority moves, then progress is often wrong. > Marko isn't saying "I know my use-case is atypical, but I inherited a > code base where the bytes/pseudo-text duality of Python2 strings was > helpful to me, and Python3's strict division into byte strings and text > strings is less useful." > > Rather, he is making the sweeping generalisation that having a text > string type *at all* is a mistake, because the Python 2 dual bytes+pseudo > text approach is superior, *for everyone*. > I do agree that it was a step in the wrong direction, but I also realize that it works sufficiently for many use cases (not all). >> The smart thing would be for a language to have a switch of some sort to >> turn on/off all I18N features. > The Python language has no builtin I18N features. > I don't want to argue over the definition of I18N. Unicode is an attempt to solve at least one I18N issue - therefore Python *does* have builtin (and unavoidable) I18N features. -Jim From sleadpc at gmail.com Sun Jul 15 20:32:57 2018 From: sleadpc at gmail.com (S Lea) Date: Sun, 15 Jul 2018 17:32:57 -0700 Subject: can't install/run pip (Latest version of Python) Message-ID: I can't seem to install the pips, DOS gives me the syntex i invalid, any thoughts?? Thank you From jlee54 at gmail.com Sun Jul 15 20:39:55 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 15 Jul 2018 17:39:55 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On 07/15/18 17:18, Steven D'Aprano wrote: > On Sun, 15 Jul 2018 16:08:15 -0700, Jim Lee wrote: > >> Python3 is intrinsically tied to Unicode for string handling. Therefore, >> the Python programmer is forced to deal with it (in all but trivial >> cases), rather than given a choice.? So I don't understand how I can >> illustrate my point with Python code since Python won't let me deal with >> strings without also dealing with Unicode. > Nonsense. > > b"Look ma, a Python 2 style ASCII string." > As I said, all but trivial cases. Do you consider separating Unicode strings from byte strings, having to decode and encode from one to the other, and knowing which functions/methods accept one, the other, or both as arguments, as "not dealing with Unicode"?? I don't. -Jim From cs at cskk.id.au Sun Jul 15 20:40:07 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 16 Jul 2018 10:40:07 +1000 Subject: can't install/run pip (Latest version of Python) In-Reply-To: References: Message-ID: <20180716004007.GA17382@cskk.homeip.net> On 15Jul2018 17:32, S Lea wrote: > I can't seem to install the pips, DOS gives me the syntex i invalid, any >thoughts? Please post, inline as text, the commands you're trying to run, including the prompt at which you're running the command and including any error messages that happen. Also tell us what kind of system you're running this on (Windows, Mac, so forth). A common mistake is to run "pip install" inside Python (the ">>> " prompt) instead of and the command line prompt, because "pip" is a command in its own right, not a Python internal. With a transcript of what you're doing people will be better able to help you. Cheers, Cameron Simpson From robertvstepp at gmail.com Sun Jul 15 20:44:54 2018 From: robertvstepp at gmail.com (boB Stepp) Date: Sun, 15 Jul 2018 19:44:54 -0500 Subject: can't install/run pip (Latest version of Python) In-Reply-To: References: Message-ID: On Sun, Jul 15, 2018 at 7:34 PM S Lea wrote: > > I can't seem to install the pips, DOS gives me the syntex i invalid, any > thoughts?? You provide insufficient information for anyone to be able to help you. 1) Copy and paste the entire traceback into a plain text email, no screen shots please. 2) Copy and paste exactly what you typed that generated the syntax error. 3) Did you do all of this in cmd.exe in what version of Windows? Or did you use something else? Hopefully not in the interactive Python interpreter or IDLE! 4) What Python version are you using? 5) Did you try searching for the exact error message and see what answers might already be out there? If you provide these things, or, better, search and find the answer yourself, I'm sure someone will be happy to assist. Good luck! -- boB From cs at cskk.id.au Sun Jul 15 20:48:21 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 16 Jul 2018 10:48:21 +1000 Subject: Reading EmailMessage from file In-Reply-To: References: Message-ID: <20180716004821.GA28858@cskk.homeip.net> On 15Jul2018 23:34, Jon Ribbens wrote: >On 2018-07-15, Skip Montanaro wrote: >> I have an email message in a file (see attached). > >Attachments don't work here. > >> something like this should construct an email message from the file: >> >>>>> from email.message import EmailMessage >>>>> msg = EmailMessage() >>>>> fp = open("/home/skip/tmp/79487694") >>>>> msg.set_content(fp.read()) > >What are you actually trying to do? You're talking like you're trying >to read an existing RFC822 email-with-headers from a file, but you're >showing code that creates a new email with body content set from >a file, which is a completely different thing. Also, RFC822 messages tend not to be Unicode themselves, _or_ ISO8859-1. Email message file tend to be 7-bit ASCII, with a (small, well defined) variety of methods for passing other text encodings though that form. When I read a mail message from a file I do it like this: msg = email.parser.Parser().parse(msgfile, headersonly=headersonly) where `msgfile` is an open file (just "open(pathname, errors='replace')"). That returns a Message object. Cheers, Cameron Simpson (formerly cs at zip.com.au) From jlee54 at gmail.com Sun Jul 15 21:02:51 2018 From: jlee54 at gmail.com (Jim Lee) Date: Sun, 15 Jul 2018 18:02:51 -0700 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> Message-ID: <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> On 07/15/18 17:17, MRAB wrote: > On 2018-07-16 00:10, Jim Lee wrote: >> >> >> On 07/15/18 16:04, Chris Angelico wrote: >>> >>> You claimed that Unicode was insignificant to many programs. I'm >>> trying to say that a Unicode text string is a vital part of any >>> program that works with text, which is pretty much anything that talks >>> to humans. You keep saying that ... well you keep saying different >>> things, and I've lost track of what your point actually is, but you >>> want a way to... disable Unicode? Or something? And you have yet to >>> give any example of a program that doesn't need Unicode, but still >>> uses text. >>> >>> ChrisA >> >> Why does this seem so obtuse to you? >> >> Have you never heard of programming BEFORE Unicode existed? >> >> How ever did we get along?? It must have been a hallucination... >> > It wasn't a hallucination, but it was annoying having to deal with > code pages. Yes, it was.? However, dealing with Unicode is also annoying.? If there were only one encoding, such as UTF-8, I wouldn't mind so much. > > The UK had a version of ASCII that had ? instead of #, France had a > version that had both that and ? instead of some character, etc, and, > more than once, someone has posted here code that has ? instead of \. > > Someone on the Auxlang list used to complain about the alphabet used > by Esperanto because of some of its letters. He was eventually > persuaded to try switching to Unicode and UTF-8. He reported that the > switch was a lot easier than he'd expected (because, as had been > pointed out, any decent software he was using would already support > Unicode, or, if it didn't, there would be an alternative that did). > After the switch, he didn't see those letters as a problem any more! But I don't speak Esperanto,? and my programs don't generally care what characters are used for European currencies.? When I create a simple program that takes a text file (created by me) and munges it into a different format, I don't care if someone from Uzbekistan can read it or not.? When I create a one-time use program to visualize some data on a graph, I don't care if anyone else can read the axis labels but me.? These are realities.? A good programming language will allow for these realities without putting the burden on the programmer to turn *every* program into a politically correct, globalization compliant model of modern groupthink. -Jim From skip.montanaro at gmail.com Sun Jul 15 21:31:45 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 15 Jul 2018 20:31:45 -0500 Subject: Reading EmailMessage from file In-Reply-To: References: Message-ID: > What are you actually trying to do? You're talking like you're trying > to read an existing RFC822 email-with-headers from a file, but you're > showing code that creates a new email with body content set from > a file, which is a completely different thing. Yes, that's exactly what I'm trying to do. A bit more context... I'm trying to port SpamBayes from Python 2 to Python 3. The file I attached which failed to come through was exactly what you suggested, an email in a file. That is what the example from the 3.7 docs suggested I should be able to do. Had the message in the file been encoded as utf-8, that would have worked. I just tested it with another message which is utf-8-encoded. To Cameron's response suggesting opening the file with errors="replace", that's not likely to work here. The content in the message needs to be available to the SpamBayes checkers. Replacing unrecognized characters with "?" or other replacement characters is generally not the best course. Still, Cameron's reply gave me the clue I needed. There is a BytesParser in the email.parser module: >>> parser = email.parser.BytesParser() >>> parser.parse(open("/home/skip/Data/Ham/Set6/754", "rb")) That file is utf-8-encoded. Here's the problematic iso-8859-1-encoded file: >>> parser.parse(open("/home/skip/tmp/79487694", "rb")) So, problem solved. The example I originally referred to clearly requires the caller know the encoding of the input file. When you don't know the encoding, you need bytes. The BytesParser gave me that. Also, I must admit to having not completely read the examples page, where it described use of the BytesParser class a bit further down the page, but I stopped when the simple example failed for me. Thx, Skip From Richard at Damon-family.org Sun Jul 15 21:45:44 2018 From: Richard at Damon-family.org (Richard Damon) Date: Sun, 15 Jul 2018 21:45:44 -0400 Subject: Reading EmailMessage from file In-Reply-To: References: Message-ID: A raw email message should be treated as a ?bag of bytes?, and in processing it, the encoding of the various sections determined by headers in the message (or taking defined defaults if not specified). I suspect that means that you should read as a binary file. I would hope that the module has the smarts to detect the encoding/character set in the message, but maybe you need to parse some of the headers yourself to supply that information. One thing that you do need to watch out for, is there do exist messages in the wind where the declared formatting/encode doesn?t match what the message actually uses. On Jul 15, 2018, at 9:31 PM, Skip Montanaro wrote: >> What are you actually trying to do? You're talking like you're trying >> to read an existing RFC822 email-with-headers from a file, but you're >> showing code that creates a new email with body content set from >> a file, which is a completely different thing. > > Yes, that's exactly what I'm trying to do. A bit more context... I'm > trying to port SpamBayes from Python 2 to Python 3. The file I > attached which failed to come through was exactly what you suggested, > an email in a file. That is what the example from the 3.7 docs > suggested I should be able to do. Had the message in the file been > encoded as utf-8, that would have worked. I just tested it with > another message which is utf-8-encoded. > > To Cameron's response suggesting opening the file with > errors="replace", that's not likely to work here. The content in the > message needs to be available to the SpamBayes checkers. Replacing > unrecognized characters with "?" or other replacement characters is > generally not the best course. > > Still, Cameron's reply gave me the clue I needed. There is a > BytesParser in the email.parser module: > >>>> parser = email.parser.BytesParser() >>>> parser.parse(open("/home/skip/Data/Ham/Set6/754", "rb")) > > > That file is utf-8-encoded. Here's the problematic iso-8859-1-encoded file: > >>>> parser.parse(open("/home/skip/tmp/79487694", "rb")) > > > So, problem solved. The example I originally referred to clearly > requires the caller know the encoding of the input file. When you > don't know the encoding, you need bytes. The BytesParser gave me that. > > Also, I must admit to having not completely read the examples page, > where it described use of the BytesParser class a bit further down the > page, but I stopped when the simple example failed for me. > > Thx, > > Skip > -- > https://mail.python.org/mailman/listinfo/python-list From jeanpierreda at gmail.com Sun Jul 15 22:13:08 2018 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 15 Jul 2018 19:13:08 -0700 Subject: Users banned In-Reply-To: <5b7046a6-4c96-c8b0-9b5b-ec7999d4865d@gmail.com> References: <5B4B8391.3060808@stoneleaf.us> <877elw2ndr.fsf@elektro.pacujo.net> <5b7046a6-4c96-c8b0-9b5b-ec7999d4865d@gmail.com> Message-ID: On Sun, Jul 15, 2018 at 5:09 PM Jim Lee wrote: > That is, of course, the decision of the moderators - but I happen to > agree with both Christian and Ethan. Banning for the simple reason of a > dissenting opinion is censorship, pure and simple. While Bart may have > been prolific in his arguments, he never spoke in a toxic or > condescending manner, or broke any of the rules of conduct. I cannot > say the same for several who engaged with him. +1000 It seems to me like the python-list moderators are rewarding people for being bullies, by banning the people they were bullying. The behavior on the list the past few days has been unforgivably toxic, and that has nothing to do with the behavior of Bart et al. -- Devin From dieter at handshake.de Mon Jul 16 00:55:59 2018 From: dieter at handshake.de (dieter) Date: Mon, 16 Jul 2018 06:55:59 +0200 Subject: logging from time critical tasks -- QueueListener().stop() takes the whole CPU References: Message-ID: <877elvpyn4.fsf@handshake.de> Gerlando Falauto writes: > ... > Why is the main thread taking up so much CPU? > I believe at this point listener.stop() should only be waiting for the helper thread to terminate, which I reckon would be implemented by waiting on a semaphore or something (i.e. iowait i.e. 0% CPU). Maybe, you look at the source code of "listener.stop"? From gerlando.falauto at gmail.com Mon Jul 16 01:39:06 2018 From: gerlando.falauto at gmail.com (Gerlando Falauto) Date: Sun, 15 Jul 2018 22:39:06 -0700 (PDT) Subject: logging from time critical tasks -- QueueListener().stop() takes the whole CPU In-Reply-To: References: <877elvpyn4.fsf@handshake.de> Message-ID: On Monday, July 16, 2018 at 6:56:19 AM UTC+2, dieter wrote: > > ... > > Why is the main thread taking up so much CPU? > > I believe at this point listener.stop() should only be waiting for the helper thread to terminate, which I reckon would be implemented by waiting on a semaphore or something (i.e. iowait i.e. 0% CPU). > > Maybe, you look at the source code of "listener.stop"? I did, forgot to mention that. Culprit is self._thread.join(). Which is where it waits for the internal thread to terminate, which I would've expected to wait on a lock or semaphore (pthread_join()?) So there's something I'm totally missing here, which has more to do with queues and threads in general than it has with logging. Any ideas? From tjol at tjol.eu Mon Jul 16 02:12:33 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 16 Jul 2018 08:12:33 +0200 Subject: logging from time critical tasks -- QueueListener().stop() takes the whole CPU In-Reply-To: References: <877elvpyn4.fsf@handshake.de> Message-ID: On 16/07/18 07:39, Gerlando Falauto wrote: > On Monday, July 16, 2018 at 6:56:19 AM UTC+2, dieter wrote: >>> ... >>> Why is the main thread taking up so much CPU? >>> I believe at this point listener.stop() should only be waiting for the helper thread to terminate, which I reckon would be implemented by waiting on a semaphore or something (i.e. iowait i.e. 0% CPU). >> >> Maybe, you look at the source code of "listener.stop"? > > I did, forgot to mention that. Culprit is self._thread.join(). > Which is where it waits for the internal thread to terminate, > which I would've expected to wait on a lock or semaphore (pthread_join()?) > So there's something I'm totally missing here, which has more to do > with queues and threads in general than it has with logging. > Any ideas? > I have no idea what's really going on there, but a quick look through the source reveals that the actual waiting in Thread.join() is done by sem_wait(). via https://github.com/python/cpython/blob/13ff24582c99dfb439b1af7295b401415e7eb05b/Python/thread_pthread.h#L304 via https://github.com/python/cpython/blob/master/Modules/_threadmodule.c#L45 via https://github.com/python/cpython/blob/master/Modules/_threadmodule.c#L136 via https://github.com/python/cpython/blob/master/Lib/threading.py#L1000 From gerlando.falauto at gmail.com Mon Jul 16 02:24:43 2018 From: gerlando.falauto at gmail.com (Gerlando Falauto) Date: Sun, 15 Jul 2018 23:24:43 -0700 (PDT) Subject: logging from time critical tasks -- QueueListener().stop() takes the whole CPU In-Reply-To: References: <877elvpyn4.fsf@handshake.de> Message-ID: <68ef89f3-3eb4-4669-9968-5f61f2b8ef5c@googlegroups.com> On Monday, July 16, 2018 at 8:13:46 AM UTC+2, Thomas Jollans wrote: > On 16/07/18 07:39, Gerlando Falauto wrote: > > On Monday, July 16, 2018 at 6:56:19 AM UTC+2, dieter wrote: > >>> ... > >>> Why is the main thread taking up so much CPU? > >>> I believe at this point listener.stop() should only be waiting for the helper thread to terminate, which I reckon would be implemented by waiting on a semaphore or something (i.e. iowait i.e. 0% CPU). > >> > >> Maybe, you look at the source code of "listener.stop"? > > > > I did, forgot to mention that. Culprit is self._thread.join(). > > Which is where it waits for the internal thread to terminate, > > which I would've expected to wait on a lock or semaphore (pthread_join()?) > > So there's something I'm totally missing here, which has more to do > > with queues and threads in general than it has with logging. > > Any ideas? > > > > I have no idea what's really going on there, but a quick look through > the source reveals that the actual waiting in Thread.join() is done by > sem_wait(). > > via > https://github.com/python/cpython/blob/13ff24582c99dfb439b1af7295b401415e7eb05b/Python/thread_pthread.h#L304 > via > https://github.com/python/cpython/blob/master/Modules/_threadmodule.c#L45 Hmm... do you think it's possible it's really getting interrupted the whole time, effectively turning the lock into a sort of spinlock? Any idea how to confirm that without recompiling the whole code? From auriocus at gmx.de Mon Jul 16 02:26:53 2018 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 16 Jul 2018 08:26:53 +0200 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: Am 16.07.18 um 03:02 schrieb Jim Lee: > But I don't speak Esperanto,? and my programs don't generally care what > characters are used for European currencies.? When I create a simple > program that takes a text file (created by me) and munges it into a > different format, I don't care if someone from Uzbekistan can read it or > not.? When I create a one-time use program to visualize some data on a > graph, I don't care if anyone else can read the axis labels but me. > These are realities.? A good programming language will allow for these > realities without putting the burden on the programmer to turn *every* > program into a politically correct, globalization compliant model of > modern groupthink. Then please show a program of that kind where you need to put additional effort in to make it run under Python3, but it'd be easy in Python2! I regularly write similar programs, and it works for me to simply ignore that there is Unicode etc. Just load some data and show it in numpy, why do I need to care about Unicode? Christian From tjol at tjol.eu Mon Jul 16 02:33:39 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 16 Jul 2018 08:33:39 +0200 Subject: logging from time critical tasks -- QueueListener().stop() takes the whole CPU In-Reply-To: <68ef89f3-3eb4-4669-9968-5f61f2b8ef5c@googlegroups.com> References: <877elvpyn4.fsf@handshake.de> <68ef89f3-3eb4-4669-9968-5f61f2b8ef5c@googlegroups.com> Message-ID: <22097e96-08cb-d00b-3cf6-0f47393e943b@tjol.eu> On 16/07/18 08:24, Gerlando Falauto wrote: > On Monday, July 16, 2018 at 8:13:46 AM UTC+2, Thomas Jollans wrote: >> On 16/07/18 07:39, Gerlando Falauto wrote: >>> On Monday, July 16, 2018 at 6:56:19 AM UTC+2, dieter wrote: >>>>> ... >>>>> Why is the main thread taking up so much CPU? >>>>> I believe at this point listener.stop() should only be waiting for the helper thread to terminate, which I reckon would be implemented by waiting on a semaphore or something (i.e. iowait i.e. 0% CPU). >>>> >>>> Maybe, you look at the source code of "listener.stop"? >>> >>> I did, forgot to mention that. Culprit is self._thread.join(). >>> Which is where it waits for the internal thread to terminate, >>> which I would've expected to wait on a lock or semaphore (pthread_join()?) >>> So there's something I'm totally missing here, which has more to do >>> with queues and threads in general than it has with logging. >>> Any ideas? >>> >> >> I have no idea what's really going on there, but a quick look through >> the source reveals that the actual waiting in Thread.join() is done by >> sem_wait(). >> >> via >> https://github.com/python/cpython/blob/13ff24582c99dfb439b1af7295b401415e7eb05b/Python/thread_pthread.h#L304 >> via >> https://github.com/python/cpython/blob/master/Modules/_threadmodule.c#L45 > > Hmm... do you think it's possible it's really getting interrupted the whole time, effectively turning the lock into a sort of spinlock? > Any idea how to confirm that without recompiling the whole code? > Profiling, maybe? Or you might be able to find out if it's being interrupted by listening for signals yourself (though I'm not sure which one(s))? From cs at cskk.id.au Mon Jul 16 04:00:31 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 16 Jul 2018 18:00:31 +1000 Subject: logging from time critical tasks -- QueueListener().stop() takes the whole CPU In-Reply-To: <22097e96-08cb-d00b-3cf6-0f47393e943b@tjol.eu> References: <22097e96-08cb-d00b-3cf6-0f47393e943b@tjol.eu> Message-ID: <20180716080031.GA71120@cskk.homeip.net> On 16Jul2018 08:33, Thomas Jollans wrote: >On 16/07/18 08:24, Gerlando Falauto wrote: >> On Monday, July 16, 2018 at 8:13:46 AM UTC+2, Thomas Jollans wrote: >>> On 16/07/18 07:39, Gerlando Falauto wrote: >>>> On Monday, July 16, 2018 at 6:56:19 AM UTC+2, dieter wrote: >>>>>> ... >>>>>> Why is the main thread taking up so much CPU? >>>>>> I believe at this point listener.stop() should only be waiting for the helper thread to terminate, which I reckon would be implemented by waiting on a semaphore or something (i.e. iowait i.e. 0% CPU). Presuming you're using Linux on the Pi, the strace command will show you exactly what system calls the processis making. A real spin lock situation will be very apparent. 100% CPU with no system calls means a busy wait (polling). Strace is an outstandingly useful and often overlooked tool for debugging otherwise opaque behaviour. Cheers, Cameron Simpson From clarencechandai8 at gmail.com Mon Jul 16 05:22:49 2018 From: clarencechandai8 at gmail.com (Clarence Chanda) Date: Mon, 16 Jul 2018 11:22:49 +0200 Subject: IDLE Python won't run or open, neither will it state the error for behaving this way Message-ID: HI, I downloaded python 3.7.0 from your python website and it was installed successfully and I was able to run/open python but when I try to run/open IDLE python, it just wont open or run, it wont even state the error causing this... Please help me, how do I fix this? From p.f.moore at gmail.com Mon Jul 16 05:40:31 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 16 Jul 2018 10:40:31 +0100 Subject: Reading EmailMessage from file In-Reply-To: References: Message-ID: On 16 July 2018 at 02:31, Skip Montanaro wrote: >> What are you actually trying to do? You're talking like you're trying >> to read an existing RFC822 email-with-headers from a file, but you're >> showing code that creates a new email with body content set from >> a file, which is a completely different thing. > > Yes, that's exactly what I'm trying to do. A bit more context... I'm > trying to port SpamBayes from Python 2 to Python 3. The file I > attached which failed to come through was exactly what you suggested, > an email in a file. That is what the example from the 3.7 docs > suggested I should be able to do. Had the message in the file been > encoded as utf-8, that would have worked. I just tested it with > another message which is utf-8-encoded. As I understand it, an email is a logical object, and when it's saved to disk it should be done in some mailbox format or other. So rather than grabbing raw file data and trying to deserialise it, maybe you'd be better using one of the classes in the mailbox module (https://docs.python.org/3.7/library/mailbox.html)? Alternatively, maybe email.parser.message_from_binary_file (with a file object opened in binary) would do what you're after? Note: I've not actually used any of these methods myself... Paul From steve+comp.lang.python at pearwood.info Mon Jul 16 06:26:23 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 16 Jul 2018 10:26:23 +0000 (UTC) Subject: Unicode [was Re: Cult-like behaviour] References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On Sun, 15 Jul 2018 17:39:55 -0700, Jim Lee wrote: > On 07/15/18 17:18, Steven D'Aprano wrote: >> On Sun, 15 Jul 2018 16:08:15 -0700, Jim Lee wrote: >> >>> Python3 is intrinsically tied to Unicode for string handling. >>> Therefore, the Python programmer is forced to deal with it (in all but >>> trivial cases), rather than given a choice.? So I don't understand how >>> I can illustrate my point with Python code since Python won't let me >>> deal with strings without also dealing with Unicode. >> Nonsense. >> >> b"Look ma, a Python 2 style ASCII string." >> >> > As I said, all but trivial cases. > > Do you consider separating Unicode strings from byte strings, having to > decode and encode from one to the other, If you use nothing but byte strings, you don't need to separate the non- existent text strings from the byte strings, nor do you need to decode or encode. > and knowing which > functions/methods accept one, the other, or both as arguments, That's certainly a real complication, if I may stretch the meaning of the word "complication" beyond breaking point. Surely you are already having to read the documentation of the function to learn what arguments it takes, and what types they are (int or float, list or iterator, 'r' or 'a', etc). If someone can't deal with the question of "unicode or bytes" as well, then perhaps they ought to consider a career change to something less demanding, like politics. If, as you insinuate, all your data is 100% ASCII, then you have nothing to fear. Just treat str(bytes_obj, 'ASCII') bytes(str_obj, 'ASCII') as the equivalent of a cast or coercion, and you won't go wrong. (Of course, in 2018, the number of applications that can truly say all their data is pure ASCII is vanishingly small.) Or use Latin-1, if you want to do the most simple-minded thing that you can to make errors go away, without caring about correctness. But the thing is, that complexity is *inherent in the domain*. You can try to deal with it without Unicode, and as soon as you have users expecting to use more than one code page, you're doomed. > as "not dealing with Unicode"?? I don't. Frankly, I do. Dealing with all the vagaries of human text *is* complicated, that's the nature of the beast. Dealing with the complexities of Unicode can be as complex as dealing with the complexities of floating point arithmetic. (But neither of those are even in the same ballpark as dealing with the complexities of *not* using Unicode: legacy code pages and encodings are a nightmare to deal with.) Nevertheless, just as casual users can go a very, very long way just treating floats as the real numbers we learn about in school, and trust that IEEE-754 semantics will mean your answers are "close enough", so the casual user can go a very long way ignoring the complexities of Unicode, so long as they control their own data and know what it is. If you don't know what your data is, then you're doomed, Unicode or no Unicode. (If you don't think that's a problem, if you think that "just treat text as octets" works, then people like you are the reason there is so much mojibake in the world, screwing it up for the rest of us.) -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jon+usenet at unequivocal.eu Mon Jul 16 06:35:21 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 16 Jul 2018 10:35:21 -0000 (UTC) Subject: Reading EmailMessage from file References: Message-ID: On 2018-07-16, Skip Montanaro wrote: >> What are you actually trying to do? You're talking like you're trying >> to read an existing RFC822 email-with-headers from a file, but you're >> showing code that creates a new email with body content set from >> a file, which is a completely different thing. > > Yes, that's exactly what I'm trying to do. That's not entirely helpful; I said I couldn't tell what you were trying to do, was it (a) or (b), and you've replied "Yes". > A bit more context... I'm trying to port SpamBayes from Python 2 to > Python 3. The file I attached which failed to come through was > exactly what you suggested, an email in a file. That is what the > example from the 3.7 docs suggested I should be able to do If you are actually trying to read an RFC822 message-with-headers from a file, which the above suggests you are, then the example has nothing to do with your situation and as has been suggested you want the email.message_from_binary_file(fp) function (the documentation for which is cunningly hidden near the bottom of https://docs.python.org/3/library/email.parser.html). From steve+comp.lang.python at pearwood.info Mon Jul 16 06:39:49 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 16 Jul 2018 10:39:49 +0000 (UTC) Subject: Unicode [was Re: Cult-like behaviour] References: <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On Sun, 15 Jul 2018 18:02:51 -0700, Jim Lee wrote: > On 07/15/18 17:17, MRAB wrote: >> On 2018-07-16 00:10, Jim Lee wrote: [...] >>> Have you never heard of programming BEFORE Unicode existed? >>> >>> How ever did we get along? Mostly by not exchanging data with anyone else using a different language or operating system. As one of those people who *did* need to exchange data, between Windows using Latin-1 and Macs using MacRoman, I can absolutely tell you that we got on **REALLY, REALLY, REALLY BADLY** with data loss and corruption an almost guarantee. [...] > Yes, it was.? However, dealing with Unicode is also annoying.? If there > were only one encoding, such as UTF-8, I wouldn't mind so much. O_o As an application developer, you should (almost) never need to use any Unicode encoding other than UTF-8. [...] > But I don't speak Esperanto,? and my programs don't generally care what > characters are used for European currencies.? When I create a simple > program that takes a text file (created by me) and munges it into a > different format, I don't care if someone from Uzbekistan can read it or > not. Good for you. But Python is not a programming language written to satisfy the needs of people like you, and ONLY people like you. It is a language written to satisfy the needs of people from Uzbekistan, and China, and Japan, and India, and Brazil, and France, and Russia, and Australia, and the UK, and mathematicians, and historians, and linguists, and, yes, even people who think that if ISO-8859-7 was good enough for Jesus, the whole world ought to be using it. > When I create a one-time use program to visualize some data on a > graph, I don't care if anyone else can read the axis labels but me. > These are realities.? A good programming language will allow for these > realities without putting the burden on the programmer to turn *every* > program into a politically correct, globalization compliant model of > modern groupthink. And here we get to the crux of the matter. It isn't really the technical issues of Unicode that annoy you. It is the loss of privilege that you, as an ASCII user, no longer get to dismiss 90% of the world as beneath your notice. Nice. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From antoon.pardon at vub.be Mon Jul 16 08:12:06 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 16 Jul 2018 14:12:06 +0200 Subject: [SUSPICIOUS MESSAGE] Re: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87d0vp3qds.fsf@elektro.pacujo.net> References: <5B48F64D.4040804@stoneleaf.us> <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> Message-ID: <44abd7c0-c7dd-0e98-d756-ca0a507cc1ba@vub.be> On 15-07-18 09:33, Marko Rauhamaa wrote: > Paul Rubin : >> Py3's unicode picture is described here and it isn't pretty: >> http://secure-web.cisco.com/1IcToGhkZqGKNSVqMv5ljEo0GVPh0uuAPgKzSBMCkoNElVbHgu4uHpyfdyIj8PrqISD2JssJJnw1yWSFp13DBGOiCdp_Mk9wI4ph_RJ63PeRB_HErunPFzgNvsDR5SDgVe66MmpAG7A4O1NO-NKKjf_5KwnmaAxd5FK89NvKf06tU6H_UmjMt8uYj4487Hc4WDmMhewkSSC86Bu6Eh9Ga_yuzYAMuTpiEftZb30M3pMdyhhTCVGK0KGz4kGPFkgGhaN2hGrNfjYZTdo-CUDcWPw/http%3A%2F%2Flucumr.pocoo.org%2F2014%2F5%2F12%2Feverything-about-unicode%2F > From the link: > > The much more likely thing to happen is that people stick to Python 2 > or build broken stuff on Python 3. Or they go with Go. Which uses an > even simpler model than Python 2: everything is a byte string. The > assumed encoding is UTF-8. End of the story. > > I have similar feelings, except that I'm not convinced Go is the answer. I really don't understand why the author of that article didn't just copy his python2 program but used sys.stdin.buffer and sys.sydout.buffer instead of plain sys.stdin and stdout. AFAIU that would have worked like he wanted to, since it would have copied bytes just as he wanted to. I have searched for an explanation for why that wouldn't have worked and didn't find it. -- Antoon. From jpcookie at gmail.com Mon Jul 16 08:47:53 2018 From: jpcookie at gmail.com (John T. Haggerty) Date: Mon, 16 Jul 2018 06:47:53 -0600 Subject: Getting process details on an operating system process/question answer by vouce Message-ID: So, it's early for me---and I'm not sure if these things can be done but I'd like to know the following: 1. How can Python connect to a running operating system process on a host operating system to see what part of the execution is like?---ie keep track of health stats like it's stuck on disk access or inside some kind of wait state etc. 2. Be able to pass questions and take answers via say a customized "okay google" to try to explain: Ask: how was your day record answer in voice translate it via google ask new question Hope the two questions make sense Thanks. From redstone-cold at 163.com Mon Jul 16 08:51:57 2018 From: redstone-cold at 163.com (iMath) Date: Mon, 16 Jul 2018 05:51:57 -0700 (PDT) Subject: send PIL.Image to django server side and get it back Message-ID: I also posted the question here https://stackoverflow.com/questions/51355926/send-pil-image-to-django-server-side-and-get-it-back I don't know what's under the hood of sending an image from client side to server side, so stuck by the following scenario. I want to send a PIL.Image object to django server side using the Python requests lib and get it back in order to use the PIL.Image object on server side. As I have tested , if sent the PIL.Image object without any conversion , that is r = requests.post(SERVER_URL, data={ 'image': PILimage,#PILimage is of type PIL.Image 'wordPos':(86,23) }, ) then I just got a str object with value on server side, I guess it was caused by requests, which converted the PIL.Image object to a str object before sending, so why requestsdo the conversion ? why cannot we send the PIL.Image object without any conversion over the Internet ? please give some explanation here, thanks! From rhodri at kynesim.co.uk Mon Jul 16 09:22:32 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 16 Jul 2018 14:22:32 +0100 Subject: Kindness In-Reply-To: <5B490189.1000800@stoneleaf.us> References: <063c290d-b10e-a3f8-93af-f6925920a0d4@kynesim.co.uk> <5B490189.1000800@stoneleaf.us> Message-ID: On 13/07/18 20:46, Ethan Furman wrote: > On 07/13/2018 11:52 AM, Rhodri James wrote: > >> I should point out that the number of people I have killfiled in all my > > Internet dealings can be counted on the fingers of one hand. > > Your left one? * > > -- > ~Ethan~ > > > * Bonus points for getting the reference.? ;) Huh. All I can come up with at the moment is the Princess Bride, and I suspect you mean something else :-) -- Rhodri James *-* Kynesim Ltd From tzotzioy at gmail.com Mon Jul 16 09:40:45 2018 From: tzotzioy at gmail.com (=?UTF-8?B?Q2hyaXN0b3MgR2Vvcmdpb3UgLSDOpM6WzqnOpM6WzpnOn86l?=) Date: Mon, 16 Jul 2018 06:40:45 -0700 (PDT) Subject: send PIL.Image to django server side and get it back In-Reply-To: References: Message-ID: <654f6297-a091-4ab8-a924-e7ed1987bbe5@googlegroups.com> On Monday, July 16, 2018 at 3:52:09 PM UTC+3, iMath wrote: > I also posted the question here > https://stackoverflow.com/questions/51355926/send-pil-image-to-django-server-side-and-get-it-back > > I don't know what's under the hood of sending an image from client side to server side, so stuck by the following scenario. > > I want to send a PIL.Image object to django server side using the Python requests lib and get it back in order to use the PIL.Image object on server side. As I have tested , if sent the PIL.Image object without any conversion , that is > > r = requests.post(SERVER_URL, > data={ > 'image': PILimage,#PILimage is of type PIL.Image > 'wordPos':(86,23) > }, > ) > then I just got a str object with value on server side, I guess it was caused by requests, which converted the PIL.Image object to a str object before sending, so why requestsdo the conversion ? why cannot we send the PIL.Image object without any conversion over the Internet ? please give some explanation here, thanks! You need first to serialize the object to bytes that can go over the wire. There is no predefined way to do that, so you can: >>> import io >>> file_like_object = io.BytesIO() >>> PILImage.save(file_like_object, format='png') and then in your POST request send file_like_object.getvalue() as the image data. You will most probably need to add a Content-Type: image/png as a header. From dan at tombstonezero.net Mon Jul 16 10:17:35 2018 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 16 Jul 2018 14:17:35 +0000 (UTC) Subject: Unicode [was Re: Cult-like behaviour] References: <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On Mon, 16 Jul 2018 10:39:49 +0000, Steven D'Aprano wrote: > ... people who think that if ISO-8859-7 was good enough for Jesus ... It may have been good enough for his disciples, but Jesus spoke Aramaic. Also, ISO-8859-7 doesn't cover ancient polytonic Greek; it only covers modern monotonic Greek. See also the Unicode Greek FAQ (https://www.unicode.org/faq/greek.html). From ethan at stoneleaf.us Mon Jul 16 10:20:23 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 16 Jul 2018 07:20:23 -0700 Subject: Kindness In-Reply-To: References: <063c290d-b10e-a3f8-93af-f6925920a0d4@kynesim.co.uk> <5B490189.1000800@stoneleaf.us> Message-ID: <5B4CA9A7.8070309@stoneleaf.us> On 07/16/2018 06:22 AM, Rhodri James wrote: > On 13/07/18 20:46, Ethan Furman wrote: >> On 07/13/2018 11:52 AM, Rhodri James wrote: >>> I should point out that the number of people I have killfiled in all my >> > Internet dealings can be counted on the fingers of one hand. >> >> Your left one? * >> >> * Bonus points for getting the reference. ;) > > Huh. All I can come up with at the moment is the Princess Bride, and I suspect you mean something else :-) The Moon is a Harsh Mistress. -- ~Ethan~ From rhodri at kynesim.co.uk Mon Jul 16 10:23:48 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 16 Jul 2018 15:23:48 +0100 Subject: Kindness In-Reply-To: <5B4CA9A7.8070309@stoneleaf.us> References: <063c290d-b10e-a3f8-93af-f6925920a0d4@kynesim.co.uk> <5B490189.1000800@stoneleaf.us> <5B4CA9A7.8070309@stoneleaf.us> Message-ID: On 16/07/18 15:20, Ethan Furman wrote: > On 07/16/2018 06:22 AM, Rhodri James wrote: >> On 13/07/18 20:46, Ethan Furman wrote: >>> On 07/13/2018 11:52 AM, Rhodri James wrote: > >>>> I should point out that the number of people I have killfiled in all my >>> ?> Internet dealings can be counted on the fingers of one hand. >>> >>> Your left one? * >>> >>> * Bonus points for getting the reference.? ;) >> >> Huh.? All I can come up with at the moment is the Princess Bride, and >> I suspect you mean something else :-) > > The Moon is a Harsh Mistress. Duh. Clearly it's time I sit down and re-read that. -- Rhodri James *-* Kynesim Ltd From steve+comp.lang.python at pearwood.info Mon Jul 16 10:24:26 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 16 Jul 2018 14:24:26 +0000 (UTC) Subject: Getting process details on an operating system process/question answer by vouce References: Message-ID: On Mon, 16 Jul 2018 06:47:53 -0600, John T. Haggerty wrote: > So, it's early for me---and I'm not sure if these things can be done but > I'd like to know the following: > > 1. How can Python connect to a running operating system process on a > host operating system to see what part of the execution is like?---ie > keep track of health stats like it's stuck on disk access or inside some > kind of wait state etc. Start by answering the question: "How can *any* process connect to another running process ...". Once you know how to do that, that may give us a hint how to do the same using Python. I would expect that there needs to be some sort of OS-specific interface where you pass the process ID you care about to some OS function, and it will report the process state. If your operating system doesn't support that, the only other option that I know of is if the application you are interested in *itself* provides an interface to question it while it is running. On Linux, that might including sending it a signal (see the signal.py library) or it might include some form of interprocess communication. But whatever it is, it will likely be application specific. So if the OS doesn't support this, and the process you are interested in doesn't support this, then it likely can't be done. > 2. Be able to pass questions and take answers via say a customized "okay > google" to try to explain: > > Ask: how was your day > record answer in voice translate it via google ask new question Sorry, I don't understand this. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From marko at pacujo.net Mon Jul 16 10:24:28 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 16 Jul 2018 17:24:28 +0300 Subject: [SUSPICIOUS MESSAGE] Re: Cult-like behaviour [was Re: Kindness] References: <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <44abd7c0-c7dd-0e98-d756-ca0a507cc1ba@vub.be> Message-ID: <87sh4jw95v.fsf@elektro.pacujo.net> Antoon Pardon : > I really don't understand why the author of that article didn't just > copy his python2 program but used sys.stdin.buffer and > sys.sydout.buffer instead of plain sys.stdin and stdout. Yes, it would be nice if you could simply restrict yourself to bytes everywhere when your application needed it. Unfortunately, quite many facilities demand text, and you will need to ponder carefully at each such place how you deal with encoding/decoding exceptions. Plus the bytes syntax is really ugly. I wish Python3 had reserved '...' for byte strings and "..." for UTF-32 strings. And just look at this: AUTH_REQ = base64.b64encode( ("\0{}\0{}".format(USERNAME, PASSWORD)).encode("latin1")).decode( "latin1") versus (Python2): AUTH_REQ = "\0{}\0{}".format(USERNAME, PASSWORD).encode("base64") Marko From steve+comp.lang.python at pearwood.info Mon Jul 16 10:35:34 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 16 Jul 2018 14:35:34 +0000 (UTC) Subject: Unicode [was Re: Cult-like behaviour] References: <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On Mon, 16 Jul 2018 14:17:35 +0000, Dan Sommers wrote: > On Mon, 16 Jul 2018 10:39:49 +0000, Steven D'Aprano wrote: > >> ... people who think that if ISO-8859-7 was good enough for Jesus ... > > It may have been good enough for his disciples, but Jesus spoke Aramaic. The buzzing noise you just heard was the joke whizzing past your head *wink* It was a riff on the apocryphal American (occasionally other nationality) who said that if English was good enough for Jesus Christ, it is good enough for everyone: http://itre.cis.upenn.edu/~myl/languagelog/archives/003084.html with the twist that in my example, I picked *another* language rather than English. I shouldn't have picked Greek, an unfortunate choice that may have lead you to imagine I was serious. Perhaps ISO-8859-5 (Cyrillic) or Shift_JIS would have been funnier :-( And of course there is the absurdity of any ISO standards existing two thousand years ago. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From wegge at wegge.dk Mon Jul 16 10:49:12 2018 From: wegge at wegge.dk (Anders Wegge Keller) Date: Mon, 16 Jul 2018 16:49:12 +0200 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: <20180716164912.52f3c7d1@wegge.dk> > The buzzing noise you just heard was the joke whizzing past your head > *wink* I have twins aged four. They also like to yell "I cheated!", whenever they are called out. In general, you need to get rid of tat teenage brat persona you practice. The "ranting rick" charade was especially toe-curling. -- //Wegge From gheskett at shentel.net Mon Jul 16 10:54:04 2018 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 16 Jul 2018 10:54:04 -0400 Subject: [SUSPICIOUS MESSAGE] Re: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87sh4jw95v.fsf@elektro.pacujo.net> References: <87sh4jw95v.fsf@elektro.pacujo.net> Message-ID: <201807161054.04480.gheskett@shentel.net> On Monday 16 July 2018 10:24:28 Marko Rauhamaa wrote: > Antoon Pardon : > > I really don't understand why the author of that article didn't just > > copy his python2 program but used sys.stdin.buffer and > > sys.sydout.buffer instead of plain sys.stdin and stdout. > > Yes, it would be nice if you could simply restrict yourself to bytes > everywhere when your application needed it. Unfortunately, quite many > facilities demand text, and you will need to ponder carefully at each > such place how you deal with encoding/decoding exceptions. > > Plus the bytes syntax is really ugly. I wish Python3 had reserved > '...' for byte strings and "..." for UTF-32 strings. From a lurker, that does sound usefull. The next PEP maybe? > And just look at this: > > AUTH_REQ = base64.b64encode( > ("\0{}\0{}".format(USERNAME, > PASSWORD)).encode("latin1")).decode( "latin1") > > versus (Python2): > > AUTH_REQ = "\0{}\0{}".format(USERNAME, PASSWORD).encode("base64") > > > Marko -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From antoon.pardon at vub.be Mon Jul 16 11:02:46 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 16 Jul 2018 17:02:46 +0200 Subject: [SUSPICIOUS MESSAGE] Re: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87sh4jw95v.fsf@elektro.pacujo.net> References: <87r2k66f51.fsf@elektro.pacujo.net> <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <44abd7c0-c7dd-0e98-d756-ca0a507cc1ba@vub.be> <87sh4jw95v.fsf@elektro.pacujo.net> Message-ID: On 16-07-18 16:24, Marko Rauhamaa wrote: > Antoon Pardon : > >> I really don't understand why the author of that article didn't just >> copy his python2 program but used sys.stdin.buffer and >> sys.sydout.buffer instead of plain sys.stdin and stdout. > Yes, it would be nice if you could simply restrict yourself to bytes > everywhere when your application needed it. Unfortunately, quite many > facilities demand text, and you will need to ponder carefully at each > such place how you deal with encoding/decoding exceptions. And in what way is the python3 string type part of the problem with that? I don't really understand your point here. You refered to an article where someone seemed to be having trouble because he used a text-interface while he wanted to treat things as bytes and this would somehow show how python3 unicode was trouble some. So I remarked that the problem IMO was using the wrong interface and now you come with a different kind of situation, but I still don't see python3 big string problems being illustrated. > Plus the bytes syntax is really ugly. I wish Python3 had reserved '...' > for byte strings and "..." for UTF-32 strings. > > And just look at this: > > AUTH_REQ = base64.b64encode( > ("\0{}\0{}".format(USERNAME, PASSWORD)).encode("latin1")).decode( > "latin1") > > versus (Python2): > > AUTH_REQ = "\0{}\0{}".format(USERNAME, PASSWORD).encode("base64") Well this may be somewhat annoying but it hardly seems to illustrate a big problem. From rosuav at gmail.com Mon Jul 16 11:23:47 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 01:23:47 +1000 Subject: [SUSPICIOUS MESSAGE] Re: Cult-like behaviour [was Re: Kindness] In-Reply-To: <201807161054.04480.gheskett@shentel.net> References: <87sh4jw95v.fsf@elektro.pacujo.net> <201807161054.04480.gheskett@shentel.net> Message-ID: On Tue, Jul 17, 2018 at 12:54 AM, Gene Heskett wrote: > On Monday 16 July 2018 10:24:28 Marko Rauhamaa wrote: > >> Antoon Pardon : >> > I really don't understand why the author of that article didn't just >> > copy his python2 program but used sys.stdin.buffer and >> > sys.sydout.buffer instead of plain sys.stdin and stdout. >> >> Yes, it would be nice if you could simply restrict yourself to bytes >> everywhere when your application needed it. Unfortunately, quite many >> facilities demand text, and you will need to ponder carefully at each >> such place how you deal with encoding/decoding exceptions. >> >> Plus the bytes syntax is really ugly. I wish Python3 had reserved >> '...' for byte strings and "..." for UTF-32 strings. > > From a lurker, that does sound usefull. The next PEP maybe? Definitely not. Mainly, this is a massive break of backward compatibility; but even aside from that, I am NOT a fan of having multiple string types with sneakily different meanings. Let's look at a few other languages where the quote type changes the meaning: * C and its direct derivatives: "string", 'c' 'h' 'a' 'r'. Completely different (a character is an integer). * JavaScript: "string", 'string', `formatted string`. Annoyingly similar. Hard to do anything else though. * SQL: 'string', "identifier", `broken MySQL identifier`. Constantly tripping people up. * Bourne shell: 'literal string', "interpolated string". Periodically annoys people who "use quoted strings like this!" All of them cause confusion, frequently. I think the C example causes the least confusion, due to it being so completely different (you can't write 'Hello, world' because that's too long for a string, and C's static typing system is strong enough to catch most bugs of this nature fairly quickly); all the others cause frequent problems. In JavaScript's case, I kinda feel for the ECMAScript people in that they wanted to add the feature but didn't really have any good options (JS doesn't have string prefixes the way Python does), but it still causes confusion; a backtick string in JS can span multiple lines, but the others can't, so sometimes backticks are used even without interpolation, and it's confusing. With SQL's different quoting types, MySQL decided to go and violate the standard by making double quotes into strings, but that just introduced even MORE confusion, rather than solving anything. And shell scripting... well, if anyone truly understands all the quoting and interpolation rules in bash, I would be terrified of how many marbles that person has lost. Python 2 had backticks meaning something completely different from string literals. Starting with 3.0, backticks are explicitly excluded from syntax, and the only way a quote character changes the string is that three of them means you can span lines. Let's keep it simple. Prefixes are there for a reason. ChrisA From gheskett at shentel.net Mon Jul 16 11:48:16 2018 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 16 Jul 2018 11:48:16 -0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> Message-ID: <201807161148.16707.gheskett@shentel.net> On Sunday 15 July 2018 16:09:21 Chris Angelico wrote: > On Mon, Jul 16, 2018 at 4:22 AM, James Lee wrote: > > On 7/15/2018 3:43 AM, Steven D'Aprano wrote: > >> No. The real ten billion dollar question is how people in 2018 can > >> stick their head in the sand and take seriously the position that > >> Latin-1 (let alone ASCII) is enough for text strings. > > > > Easy - for many people, 90% of the Python code they write is not > > intended for world-wide distribution, let alone use. > > > > The smart thing would be for a language to have a switch of some > > sort to turn on/off all I18N features. > > Earlier I cited an example of round-tripping from human to human via > various web protocols. Here's an actual example of a Twitch stream > title: > > ?? Stardew Valley Fanart ??*:???? 800 Subpoints = NEW EMOTE > ?#devicat #anime #stardewvalley #fantasy > Ok, I'll bite. What font would be used to properly display the above? > Citation: https://www.twitch.tv/devicat just went live with that > title. This is a channel where rule #3 is that everyone should speak > English. If "all I18N features" are disabled, would this title be > disallowed? Several of those characters are not in Latin-1; one of > them (occurring twice) isn't even in the BMP. > > ChrisA -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From rosuav at gmail.com Mon Jul 16 11:57:25 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 01:57:25 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <201807161148.16707.gheskett@shentel.net> References: <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <201807161148.16707.gheskett@shentel.net> Message-ID: On Tue, Jul 17, 2018 at 1:48 AM, Gene Heskett wrote: > On Sunday 15 July 2018 16:09:21 Chris Angelico wrote: > >> On Mon, Jul 16, 2018 at 4:22 AM, James Lee wrote: >> > On 7/15/2018 3:43 AM, Steven D'Aprano wrote: >> >> No. The real ten billion dollar question is how people in 2018 can >> >> stick their head in the sand and take seriously the position that >> >> Latin-1 (let alone ASCII) is enough for text strings. >> > >> > Easy - for many people, 90% of the Python code they write is not >> > intended for world-wide distribution, let alone use. >> > >> > The smart thing would be for a language to have a switch of some >> > sort to turn on/off all I18N features. >> >> Earlier I cited an example of round-tripping from human to human via >> various web protocols. Here's an actual example of a Twitch stream >> title: >> >> ?? Stardew Valley Fanart ??*:???? 800 Subpoints = NEW EMOTE >> ?#devicat #anime #stardewvalley #fantasy >> > Ok, I'll bite. What font would be used to properly display the above? Not sure, but the default fonts in my web browser, text editor, and terminal all have no problems with it. I'm on Debian Linux running Xfce, fwiw. Haven't had any issues anywhere. ChrisA From darcy at VybeNetworks.com Mon Jul 16 12:03:29 2018 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Mon, 16 Jul 2018 12:03:29 -0400 Subject: Python 2.7 can find cairo libs but not Python 3.6 In-Reply-To: References: <72d590d2-d1c6-5e88-6f89-8b7125477154@VybeNetworks.com> <3644c7bd-1e3e-73c7-18cf-24b923be1853@VybeNetworks.com> Message-ID: I just realized that my subject was backwards. It's 2.7 that can find the libs and 3.6 than cannot. Just in case that makes a difference. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From breamoreboy at gmail.com Mon Jul 16 12:05:39 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Mon, 16 Jul 2018 17:05:39 +0100 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On 16/07/18 15:17, Dan Sommers wrote: > On Mon, 16 Jul 2018 10:39:49 +0000, Steven D'Aprano wrote: > >> ... people who think that if ISO-8859-7 was good enough for Jesus ... > > It may have been good enough for his disciples, but Jesus spoke Aramaic. > > Also, ISO-8859-7 doesn't cover ancient polytonic Greek; it only covers > modern monotonic Greek. > > See also the Unicode Greek FAQ (https://www.unicode.org/faq/greek.html). > Out of curiosity where does my mum's Welsh come into the equation as I believe that it is not recognised by the EU as a language? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rosuav at gmail.com Mon Jul 16 12:22:59 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 02:22:59 +1000 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On Tue, Jul 17, 2018 at 2:05 AM, Mark Lawrence wrote: > On 16/07/18 15:17, Dan Sommers wrote: >> >> On Mon, 16 Jul 2018 10:39:49 +0000, Steven D'Aprano wrote: >> >>> ... people who think that if ISO-8859-7 was good enough for Jesus ... >> >> >> It may have been good enough for his disciples, but Jesus spoke Aramaic. >> >> Also, ISO-8859-7 doesn't cover ancient polytonic Greek; it only covers >> modern monotonic Greek. >> >> See also the Unicode Greek FAQ (https://www.unicode.org/faq/greek.html). >> > > Out of curiosity where does my mum's Welsh come into the equation as I > believe that it is not recognised by the EU as a language? > What characters does it use? Mostly Latin letters? If so, it's easy - most Western European languages are covered by the basic Latin alphabetics (the ASCII ones), plus the combining diacriticals (U+0300 and following), plus a small handful of language-specific characters (eg U+0130/U+0131 for Turkish). There are combined forms of some of these, which can be found via NFC normalization, and a few ligatures for some languages, but by and large, that's all you need for most Latin-derived languages. ChrisA From gheskett at shentel.net Mon Jul 16 12:24:49 2018 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 16 Jul 2018 12:24:49 -0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <201807161148.16707.gheskett@shentel.net> Message-ID: <201807161224.49133.gheskett@shentel.net> On Monday 16 July 2018 11:57:25 Chris Angelico wrote: > On Tue, Jul 17, 2018 at 1:48 AM, Gene Heskett wrote: > > On Sunday 15 July 2018 16:09:21 Chris Angelico wrote: > >> On Mon, Jul 16, 2018 at 4:22 AM, James Lee wrote: > >> > On 7/15/2018 3:43 AM, Steven D'Aprano wrote: > >> >> No. The real ten billion dollar question is how people in 2018 > >> >> can stick their head in the sand and take seriously the position > >> >> that Latin-1 (let alone ASCII) is enough for text strings. > >> > > >> > Easy - for many people, 90% of the Python code they write is not > >> > intended for world-wide distribution, let alone use. > >> > > >> > The smart thing would be for a language to have a switch of some > >> > sort to turn on/off all I18N features. > >> > >> Earlier I cited an example of round-tripping from human to human > >> via various web protocols. Here's an actual example of a Twitch > >> stream title: > >> > >> ?? Stardew Valley Fanart ??*:???? 800 Subpoints = NEW EMOTE > >> ?#devicat #anime #stardewvalley #fantasy > > > > Ok, I'll bite. What font would be used to properly display the > > above? > > Not sure, but the default fonts in my web browser, text editor, and > terminal all have no problems with it. I'm on Debian Linux running > Xfce, fwiw. Haven't had any issues anywhere. > > ChrisA Whereas I am on wheezy, 32 bit pae, using TDE as a desktop, with kmail-1.9-10-enterprise, using a 14 point unifont for the message body display. Its a nice clear, very readable font for these elderly eyes. I just tried several of the more std fonts w/o affecting the display of the rectangles you see above. Hence the question and thread noise. Apparently, and despite being set for utf-8, I don't have a font capable of displaying this string in its entirety as I've just tried a couple dozen more. Thanks ChrisA. -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From larry.martell at gmail.com Mon Jul 16 12:26:45 2018 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 16 Jul 2018 12:26:45 -0400 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On Mon, Jul 16, 2018 at 12:05 PM, Mark Lawrence wrote: > On 16/07/18 15:17, Dan Sommers wrote: >> >> On Mon, 16 Jul 2018 10:39:49 +0000, Steven D'Aprano wrote: >> >>> ... people who think that if ISO-8859-7 was good enough for Jesus ... >> >> >> It may have been good enough for his disciples, but Jesus spoke Aramaic. >> >> Also, ISO-8859-7 doesn't cover ancient polytonic Greek; it only covers >> modern monotonic Greek. >> >> See also the Unicode Greek FAQ (https://www.unicode.org/faq/greek.html). >> > > Out of curiosity where does my mum's Welsh come into the equation as I > believe that it is not recognised by the EU as a language? Is she from Llanfair?pwllgwyngyll?gogery?chwyrn?drobwll?llan?tysilio?gogo?goch? From steve+comp.lang.python at pearwood.info Mon Jul 16 12:31:14 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 16 Jul 2018 16:31:14 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> Message-ID: On Sun, 15 Jul 2018 16:38:41 -0700, Jim Lee wrote: > As I said, there are programming situations where the programmer only > needs to deal with a single language - his own. This might come as a shock to you, but just because Python's native string type supports (for example) the Devanagari alphabet, that doesn't mean you are forced to use it in your code or application. # Look ma, not a single Cyrillic or Greek or Tagalog letter in sight! label = "something interesting" Don't worry, the UN Language Police aren't going to force you at gunpoint to label your output in Khmer, Hiragana and Gujarati if you don't want to. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rhodri at kynesim.co.uk Mon Jul 16 12:33:39 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 16 Jul 2018 17:33:39 +0100 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On 16/07/18 17:05, Mark Lawrence wrote: > On 16/07/18 15:17, Dan Sommers wrote: >> On Mon, 16 Jul 2018 10:39:49 +0000, Steven D'Aprano wrote: >> >>> ... people who think that if ISO-8859-7 was good enough for Jesus ... >> >> It may have been good enough for his disciples, but Jesus spoke Aramaic. >> >> Also, ISO-8859-7 doesn't cover ancient polytonic Greek; it only covers >> modern monotonic Greek. >> >> See also the Unicode Greek FAQ (https://www.unicode.org/faq/greek.html). >> > > Out of curiosity where does my mum's Welsh come into the equation as I > believe that it is not recognised by the EU as a language? Actually the EU does recognise Welsh as a language, just not as an official language (one that EU primary and secondary legislation is translated into). It isn't an official language of the UK government either, just the Welsh Assembly. As fonts and Unicode go, there's also a question of what's required to correctly notate modern Welsh. Back in the late 1980s Acorn asked four Welsh-language scholars that question. They got four different answers :-( -- Rhodri James *-* Kynesim Ltd From breamoreboy at gmail.com Mon Jul 16 12:36:28 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Mon, 16 Jul 2018 17:36:28 +0100 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On 16/07/18 17:22, Chris Angelico wrote: > On Tue, Jul 17, 2018 at 2:05 AM, Mark Lawrence wrote: >> On 16/07/18 15:17, Dan Sommers wrote: >>> >>> On Mon, 16 Jul 2018 10:39:49 +0000, Steven D'Aprano wrote: >>> >>>> ... people who think that if ISO-8859-7 was good enough for Jesus ... >>> >>> >>> It may have been good enough for his disciples, but Jesus spoke Aramaic. >>> >>> Also, ISO-8859-7 doesn't cover ancient polytonic Greek; it only covers >>> modern monotonic Greek. >>> >>> See also the Unicode Greek FAQ (https://www.unicode.org/faq/greek.html). >>> >> >> Out of curiosity where does my mum's Welsh come into the equation as I >> believe that it is not recognised by the EU as a language? >> > > What characters does it use? Mostly Latin letters? If so, it's easy - > most Western European languages are covered by the basic Latin > alphabetics (the ASCII ones), plus the combining diacriticals (U+0300 > and following), plus a small handful of language-specific characters > (eg U+0130/U+0131 for Turkish). There are combined forms of some of > these, which can be found via NFC normalization, and a few ligatures > for some languages, but by and large, that's all you need for most > Latin-derived languages. > > ChrisA > Frankly I haven't got the faintest idea or I wouldn't be asking. The only thing that I am aware of is if you try pronouncing any Welsh name that starts with Ll, and there are lots of them, you need a huge amount of phlegm. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rhodri at kynesim.co.uk Mon Jul 16 12:37:42 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 16 Jul 2018 17:37:42 +0100 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On 16/07/18 17:22, Chris Angelico wrote: > What characters does it use? Mostly Latin letters? Basic Latin plus U+0174 (LATIN CAPITAL LETTER W WITH CIRCUMFLEX) through to U+0177 (LATIN SMALL LETTER Y WITH CIRCUMFLEX) I think. -- Rhodri James *-* Kynesim Ltd From breamoreboy at gmail.com Mon Jul 16 12:41:11 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Mon, 16 Jul 2018 17:41:11 +0100 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On 16/07/18 17:26, Larry Martell wrote: > On Mon, Jul 16, 2018 at 12:05 PM, Mark Lawrence wrote: >> On 16/07/18 15:17, Dan Sommers wrote: >>> >>> On Mon, 16 Jul 2018 10:39:49 +0000, Steven D'Aprano wrote: >>> >>>> ... people who think that if ISO-8859-7 was good enough for Jesus ... >>> >>> >>> It may have been good enough for his disciples, but Jesus spoke Aramaic. >>> >>> Also, ISO-8859-7 doesn't cover ancient polytonic Greek; it only covers >>> modern monotonic Greek. >>> >>> See also the Unicode Greek FAQ (https://www.unicode.org/faq/greek.html). >>> >> >> Out of curiosity where does my mum's Welsh come into the equation as I >> believe that it is not recognised by the EU as a language? > > Is she from Llanfair?pwllgwyngyll?gogery?chwyrn?drobwll?llan?tysilio?gogo?goch? > She was from a small mining village near Tredegar. The name was and is unprounoncable to an English speaking person hence Tredegar had to suffice. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Mon Jul 16 12:45:10 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 16 Jul 2018 16:45:10 +0000 (UTC) Subject: I18N and Unicode [was Re: Cult-like behaviour] References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> Message-ID: On Sun, 15 Jul 2018 17:28:15 -0700, Jim Lee wrote: > Unicode is an attempt to solve at least one I18N issue If you're going to insist on digging your heels in and using definitions which nobody else does, this discussion is going to go nowhere fast. Unicode is (ideally) a universal character set; in practice it is an industry standard for the consistent encoding, representation, and handling of text expressed in most of the world's writing systems. I18N is recognised as the abbreviation for internationalization and localization. https://en.wikipedia.org/wiki/Internationalization_and_localization There is no overlap between the two: Unicode doesn't help with internationalization (except in the non-trivial but purely mechanical sense that it removes the need for metadata specifying the current code page), and internationalization doesn't require Unicode: (1) Unicode provides no support for internationalization or localization. Just because I have the Unicode string "street" in my application, doesn't mean it magically transforms to "Stra?e" when used by German users. (2) Internationalization can occur even between groups of users who share a single character set, even ASCII. My application might display "Rubbish Bin" in the UK and Australia and "Trash Can" in the USA. If you think that Unicode is about internationalization, you are labouring under serious misapprehensions about the nature of both Unicode and internationalization. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jul 16 12:51:25 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 16 Jul 2018 16:51:25 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> Message-ID: On Mon, 16 Jul 2018 00:28:39 +0300, Marko Rauhamaa wrote: > if your new system used Python3's UTF-32 strings as a foundation, that > would be an equally na?ve misstep. You'd need to reach a notch higher > and use glyphs or other "semiotic atoms" as building blocks. UTF-32, > after all, is a variable-width encoding. Python's strings aren't UTF-32. They are sequences of abstract code points. UTF-32 is not a variable-width encoding. I don't know what *you* mean by "semiotic atoms", (possibly you mean graphemes?) but "glyphs" are the visual images of characters, and there's a virtual infinity of those for each character, differing in type-face, size, and style (roman, italic, bold, reverse-oblique, etc). There is no evidence aside from your say-so that a programming language "need" support "glyphs" as a native data type, or even graphemes. For starters, such a system would be exceedingly complex: graphemes are both language and context dependent. English, for example, has around 250 distinct graphemes: https://books.google.com.au/books? id=QrBQAmfXYooC&pg=PT238&lpg=PT238&dq=250 +graphemes&source=bl&ots=abiymnQ5pq&sig=eq3k06BkuGfpuGC6wKqPkCR_8Bw&hl=en&sa=X&ei=HAdyUbfULpCnqwGRi4DYAg&redir_esc=y Certainly it would be utterly impractical for a programming language designer, knowing nothing but a few half-remembered jargon terms, to try to design a native string type that matched the grapheme rules for the hundreds of human languages around the world. Or even just for English. Let third-party libraries blaze that trail first. By no means is Unicode the last word in text processing. It might not even be the last word in native string types for programming languages. But it is a true international standard which provides a universal character set and a selection of useful algorithms able to be used as powerful building blocks for text-processing libraries. Honestly Marko, your argument strikes me as akin to somebody who insists that because Python's float data type doesn't support full CAS (computer algebra system) and theorem prover, its useless and a step backwards and we should abandon IEEE-754 float semantics and let users implement their own floating point maths using nothing but fixed 1-byte integers. A float, after all, is nothing but 8 bytes. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jul 16 13:10:48 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 16 Jul 2018 17:10:48 +0000 (UTC) Subject: Unicode [was Re: Cult-like behaviour] References: <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On Tue, 17 Jul 2018 02:22:59 +1000, Chris Angelico wrote: > On Tue, Jul 17, 2018 at 2:05 AM, Mark Lawrence > wrote: >> Out of curiosity where does my mum's Welsh come into the equation as I >> believe that it is not recognised by the EU as a language? >> >> > What characters does it use? Mostly Latin letters? Yes, Welsh uses the Latin script. It has an alphabet of 29 letters (including 8 digraphs), plus four diacritics used on some vowels: circumflex e.g. ? acute accent e.g. ? diaeresis e.g. ? grave accent e.g. ? Yes, w is a vowel in Welsh -- and very occasionally in English as well. http://www.dictionary.com/e/w-vowel/ Accented vowels are not considered separate letters. https://en.wikipedia.org/wiki/Welsh_orthography Some older sources will exclude J (making 28 letters). Patagonian Welsh also includes the letter "V", although that's non-standard. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From Richard at Damon-family.org Mon Jul 16 13:11:23 2018 From: Richard at Damon-family.org (Richard Damon) Date: Mon, 16 Jul 2018 13:11:23 -0400 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> Message-ID: <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> > On Jul 16, 2018, at 12:51 PM, Steven D'Aprano wrote: > >> On Mon, 16 Jul 2018 00:28:39 +0300, Marko Rauhamaa wrote: >> >> if your new system used Python3's UTF-32 strings as a foundation, that >> would be an equally na?ve misstep. You'd need to reach a notch higher >> and use glyphs or other "semiotic atoms" as building blocks. UTF-32, >> after all, is a variable-width encoding. > > Python's strings aren't UTF-32. They are sequences of abstract code > points. > > UTF-32 is not a variable-width encoding. > > -- > Steven D'Aprano > Many consider that UTF-32 is a variable-width encoding because of the combining characters. It can take multiple ?codepoints? to define what should be a single ?character? for display. From jlee54 at gmail.com Mon Jul 16 13:13:59 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 16 Jul 2018 10:13:59 -0700 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On 07/16/18 03:26, Steven D'Aprano wrote: > > But the thing is, that complexity is *inherent in the domain*. You can > try to deal with it without Unicode, and as soon as you have users > expecting to use more than one code page, you're doomed. > No, I'm not doomed, because there *are* no other users.? Never will be.? I thought I made that clear. Many programming tasks do not go beyond the machine they were written on. You seem to think I'm trying to rid the world of Unicode - I've stressed that I'm not. I just think that a language should allow one to bypass Unicode handling easily *when it's not needed*. -Jim From jlee54 at gmail.com Mon Jul 16 13:27:18 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 16 Jul 2018 10:27:18 -0700 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On 07/16/18 03:39, Steven D'Aprano wrote: > Good for you. > > But Python is not a programming language written to satisfy the needs of > people like you, and ONLY people like you. > > It is a language written to satisfy the needs of people from Uzbekistan, > and China, and Japan, and India, and Brazil, and France, and Russia, and > Australia, and the UK, and mathematicians, and historians, and linguists, > and, yes, even people who think that if ISO-8859-7 was good enough for > Jesus, the whole world ought to be using it. > > >> When I create a one-time use program to visualize some data on a >> graph, I don't care if anyone else can read the axis labels but me. >> These are realities.? A good programming language will allow for these >> realities without putting the burden on the programmer to turn *every* >> program into a politically correct, globalization compliant model of >> modern groupthink. > And here we get to the crux of the matter. It isn't really the technical > issues of Unicode that annoy you. It is the loss of privilege that you, > as an ASCII user, no longer get to dismiss 90% of the world as beneath > your notice. > > Nice. > 90% of the world *is* "beneath my notice" when it comes to programming for myself.?? I really don't care if that's not PC enough for you. Had you actually read my words with *intent* rather than *reaction*, you would notice that I suggested the *option* of turning off Unicode.? I didn't say get *rid* of Unicode.? I didn't say make it *harder* to use Unicode.? Once again - reaction rather than reading. Obviously, the most vocal representatives of the Python community are too sensitive about their language to enable rational discussion. -Jim From python at mrabarnett.plus.com Mon Jul 16 13:27:52 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 16 Jul 2018 18:27:52 +0100 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> Message-ID: On 2018-07-16 17:31, Steven D'Aprano wrote: > On Sun, 15 Jul 2018 16:38:41 -0700, Jim Lee wrote: > >> As I said, there are programming situations where the programmer only >> needs to deal with a single language - his own. > > This might come as a shock to you, but just because Python's native > string type supports (for example) the Devanagari alphabet, that doesn't > mean you are forced to use it in your code or application. > > # Look ma, not a single Cyrillic or Greek or Tagalog letter in sight! > label = "something interesting" > > > Don't worry, the UN Language Police aren't going to force you at gunpoint > to label your output in Khmer, Hiragana and Gujarati if you don't want to. > The vast majority of what I write could be handled by ASCII. However, sometimes I want to write ?, so I'd have to extend that to Latin-1. On rare occasions I want to write something that Latin-1 can't handle. That would mean having modify any scripts to support some other encoding too. Being lazy, I just opted for doing it all in Unicode and UTF-8. From breamoreboy at gmail.com Mon Jul 16 13:35:25 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Mon, 16 Jul 2018 18:35:25 +0100 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On 16/07/18 18:13, Jim Lee wrote: > > I just think that a language should allow one to bypass Unicode handling > easily *when it's not needed*. > I have no idea what this is meant to mean. I've written loads of code for my own purposes and I've never had to think about Unicode, so why should anybody need to bypass it? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Mon Jul 16 13:36:07 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 16 Jul 2018 17:36:07 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> Message-ID: On Mon, 16 Jul 2018 13:11:23 -0400, Richard Damon wrote: >> On Jul 16, 2018, at 12:51 PM, Steven D'Aprano >> wrote: >> >>> On Mon, 16 Jul 2018 00:28:39 +0300, Marko Rauhamaa wrote: >>> >>> if your new system used Python3's UTF-32 strings as a foundation, that >>> would be an equally na?ve misstep. You'd need to reach a notch higher >>> and use glyphs or other "semiotic atoms" as building blocks. UTF-32, >>> after all, is a variable-width encoding. >> >> Python's strings aren't UTF-32. They are sequences of abstract code >> points. >> >> UTF-32 is not a variable-width encoding. >> >> -- >> Steven D'Aprano >> >> > Many consider that UTF-32 is a variable-width encoding because of the > combining characters. It can take multiple ?codepoints? to define what > should be a single ?character? for display. Ah, well if we're going to start making up our own definitions of terms, then ASCII is a variable-width encoding too. "Ch" (a single letter of the alphabet in a number of European languages, including Welsh and Czech) requires two code points in ASCII. Even in English, "qu" could be considered a two-byte "character" (grapheme), and for ASCII users, (c) is a THREE code point character for what ought to be a single character ?. The standard definition of variable- and fixed-width encodings refers to how many *code units* is required to make up a single *code point*. Under that standard definition, UTF-8 and UTF-16 are variable-width, and UTF-32 is fixed-width. But I'll accept that UTF-32 is variable-width if Marko accepts that ASCII is too. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From tjreedy at udel.edu Mon Jul 16 13:36:42 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Jul 2018 13:36:42 -0400 Subject: IDLE Python won't run or open, neither will it state the error for behaving this way In-Reply-To: References: Message-ID: On 7/16/2018 5:22 AM, Clarence Chanda wrote: > HI, I downloaded python 3.7.0 from your python website Which installer for what OS? > and it was installed successfully and I was able to run/open python How did you run it? > but when I try to run/open IDLE python, How? > it just wont open or run, it wont even state the error causing this... What did happen? > Please help me, how do I fix this? Answer the above and the result of the following: What happens if you try to start IDLE from a command-line terminal/console with python -m idlelib, where 'python' is the command-line command that runs 3.7.0? -- Terry Jan Reedy From rhodri at kynesim.co.uk Mon Jul 16 13:38:07 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 16 Jul 2018 18:38:07 +0100 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: <4ce10695-9d26-bb69-768f-0601d360f8f8@kynesim.co.uk> On 16/07/18 18:27, Jim Lee wrote: > 90% of the world *is* "beneath my notice" when it comes to programming > for myself.?? I really don't care if that's not PC enough for you. > > Had you actually read my words with *intent* rather than *reaction*, you > would notice that I suggested the *option* of turning off Unicode.? I > didn't say get *rid* of Unicode.? I didn't say make it *harder* to use > Unicode.? Once again - reaction rather than reading. Actually having an option of turning off Unicode *does* make it harder to use, because you end up coming across programs that have Unicode and surprise you when they misbehave. And yes I saw that 90% of your programs aren't intended to get out into the world. 90% is never meant to leave the office. 90% of that does anyway. I still don't get why strings being Unicode is such a problem for you. Could you explain? I've only ever had problems with strings *not* being Unicode, and I really don't understand what has you so hot under the collar. -- Rhodri James *-* Kynesim Ltd From breamoreboy at gmail.com Mon Jul 16 13:40:48 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Mon, 16 Jul 2018 18:40:48 +0100 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On 16/07/18 18:27, Jim Lee wrote: > > Obviously, the most vocal representatives of the Python community are > too sensitive about their language to enable rational discussion. Please moderators ban this person as he's going down the same line as bartc and similar, it is completely unacceptable, he's just the latest in a long line of trolls. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Mon Jul 16 13:56:37 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Jul 2018 13:56:37 -0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87bmb82np4.fsf@elektro.pacujo.net> References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> Message-ID: On 7/15/2018 5:28 PM, Marko Rauhamaa wrote: > if your new system used Python3's UTF-32 strings as a foundation, Since 3.3, Python's strings are not (always) UFT-32 strings. Nor are they always UCS-2 (or partly UTF-16) strings. Nor are the always Latin-1 or Ascii strings. Python's Flexible String Representation uses the narrowest possible internal code for any particular string. This is all transparent to the user except for memory size. In 3.2 and before, Python's Unicode strings were either wide (UFT-32) or narrow (UCS-2 + surrogates or UFT-16 minus full compliance). The difference was sometimes not transparent, and code that worked on one build could fail on the other. Since 3.3, string code should work the same on any machines running the same Python version. > UTF-32, after all, is a variable-width encoding. Nope. It a fixed-width (32 bits, 4 bytes) encoding. Perhaps you should ask more questions before pontificating. -- Terry Jan Reedy From rosuav at gmail.com Mon Jul 16 14:01:54 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 04:01:54 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <201807161224.49133.gheskett@shentel.net> References: <201807161148.16707.gheskett@shentel.net> <201807161224.49133.gheskett@shentel.net> Message-ID: On Tue, Jul 17, 2018 at 2:24 AM, Gene Heskett wrote: > On Monday 16 July 2018 11:57:25 Chris Angelico wrote: > >> On Tue, Jul 17, 2018 at 1:48 AM, Gene Heskett > wrote: >> > On Sunday 15 July 2018 16:09:21 Chris Angelico wrote: >> >> On Mon, Jul 16, 2018 at 4:22 AM, James Lee wrote: >> >> > On 7/15/2018 3:43 AM, Steven D'Aprano wrote: >> >> >> No. The real ten billion dollar question is how people in 2018 >> >> >> can stick their head in the sand and take seriously the position >> >> >> that Latin-1 (let alone ASCII) is enough for text strings. >> >> > >> >> > Easy - for many people, 90% of the Python code they write is not >> >> > intended for world-wide distribution, let alone use. >> >> > >> >> > The smart thing would be for a language to have a switch of some >> >> > sort to turn on/off all I18N features. >> >> >> >> Earlier I cited an example of round-tripping from human to human >> >> via various web protocols. Here's an actual example of a Twitch >> >> stream title: >> >> >> >> ?? Stardew Valley Fanart ??*:???? 800 Subpoints = NEW EMOTE >> >> ?#devicat #anime #stardewvalley #fantasy >> > >> > Ok, I'll bite. What font would be used to properly display the >> > above? >> >> Not sure, but the default fonts in my web browser, text editor, and >> terminal all have no problems with it. I'm on Debian Linux running >> Xfce, fwiw. Haven't had any issues anywhere. >> >> ChrisA > > Whereas I am on wheezy, 32 bit pae, using TDE as a desktop, with > kmail-1.9-10-enterprise, using a 14 point unifont for the message body > display. > > Its a nice clear, very readable font for these elderly eyes. I just tried > several of the more std fonts w/o affecting the display of the > rectangles you see above. Hence the question and thread noise. > Apparently, and despite being set for utf-8, I don't have a font capable > of displaying this string in its entirety as I've just tried a couple > dozen more. > > Thanks ChrisA. Oh! I just remembered. Try installing (through apt-get or equivalent) the "unifont" package. It'll drag in a few fonts designed to provide good coverage of all of Unicode, making them available as fallback fonts. That way, when you use a font that doesn't have all the characters, it'll use that for the bulk of the text, but instead of the rectangles that you're seeing, you'll get the correct glyphs. ChrisA From ian.g.kelly at gmail.com Mon Jul 16 14:15:19 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 16 Jul 2018 12:15:19 -0600 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> Message-ID: On Mon, Jul 16, 2018 at 12:02 PM Terry Reedy wrote: > > On 7/15/2018 5:28 PM, Marko Rauhamaa wrote: > > > if your new system used Python3's UTF-32 strings as a foundation, > > Since 3.3, Python's strings are not (always) UFT-32 strings. Nor are > they always UCS-2 (or partly UTF-16) strings. Nor are the always > Latin-1 or Ascii strings. Python's Flexible String Representation uses > the narrowest possible internal code for any particular string. This is > all transparent to the user except for memory size. > > In 3.2 and before, Python's Unicode strings were either wide (UFT-32) or > narrow (UCS-2 + surrogates or UFT-16 minus full compliance). The > difference was sometimes not transparent, and code that worked on one > build could fail on the other. Since 3.3, string code should work the > same on any machines running the same Python version. > > > UTF-32, after all, is a variable-width encoding. > > Nope. It a fixed-width (32 bits, 4 bytes) encoding. Although it only really uses 21 (actually, more like 20.087) of those bits. Given that and the similar naming, it's easy to see how people sometimes confuse its structure with UTF-8. From larry.martell at gmail.com Mon Jul 16 14:17:57 2018 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 16 Jul 2018 14:17:57 -0400 Subject: doubling the number of tests, but not taking twice as long Message-ID: I had some code that did this: meas_regex = '_M\d+_' meas_re = re.compile(meas_regex) if meas_re.search(filename): stuff1() else: stuff2() I then had to change it to this: if meas_re.search(filename): if 'MeasDisplay' in filename: stuff1a() else: stuff1() else: if 'PatternFov' in filename: stuff2a() else: stuff2() This code needs to process many tens of 1000's of files, and it runs often, so it needs to run very fast. Needless to say, my change has made it take 2x as long. Can anyone see a way to improve that? From Richard at Damon-family.org Mon Jul 16 14:22:27 2018 From: Richard at Damon-family.org (Richard Damon) Date: Mon, 16 Jul 2018 14:22:27 -0400 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> Message-ID: <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> > On Jul 16, 2018, at 1:36 PM, Steven D'Aprano wrote: > > On Mon, 16 Jul 2018 13:11:23 -0400, Richard Damon wrote: > >>> On Jul 16, 2018, at 12:51 PM, Steven D'Aprano >>> wrote: >>> >>>> On Mon, 16 Jul 2018 00:28:39 +0300, Marko Rauhamaa wrote: >>>> >>>> if your new system used Python3's UTF-32 strings as a foundation, that >>>> would be an equally na?ve misstep. You'd need to reach a notch higher >>>> and use glyphs or other "semiotic atoms" as building blocks. UTF-32, >>>> after all, is a variable-width encoding. >>> >>> Python's strings aren't UTF-32. They are sequences of abstract code >>> points. >>> >>> UTF-32 is not a variable-width encoding. >>> >>> -- >>> Steven D'Aprano >>> >>> >> Many consider that UTF-32 is a variable-width encoding because of the >> combining characters. It can take multiple ?codepoints? to define what >> should be a single ?character? for display. > > Ah, well if we're going to start making up our own definitions of terms, > then ASCII is a variable-width encoding too. > > "Ch" (a single letter of the alphabet in a number of European languages, > including Welsh and Czech) requires two code points in ASCII. Even in > English, "qu" could be considered a two-byte "character" (grapheme), and > for ASCII users, (c) is a THREE code point character for what ought to be > a single character ?. > > The standard definition of variable- and fixed-width encodings refers to > how many *code units* is required to make up a single *code point*. > > Under that standard definition, UTF-8 and UTF-16 are variable-width, and > UTF-32 is fixed-width. > > But I'll accept that UTF-32 is variable-width if Marko accepts that ASCII > is too. > > -- > Steven D'Aprano > But I am not talking about those sort of characters or ligatures, but ?characters? that are built up of a combining diacritical marks (like accents) and a base character. Unicode define many code points for the more common of these, but many others do not. From steve+comp.lang.python at pearwood.info Mon Jul 16 14:31:46 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 16 Jul 2018 18:31:46 +0000 (UTC) Subject: Unicode [was Re: Cult-like behaviour] References: <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On Mon, 16 Jul 2018 10:27:18 -0700, Jim Lee wrote: > Had you actually read my words with *intent* rather than *reaction*, you > would notice that I suggested the *option* of turning off Unicode. Yes, I know what you wrote, and I read it with intent. Jim, you seem to be labouring under the misapprehension that anytime somebody spots a flaw in your argument, or an unpleasant implication of your words, it can only be because they must not have read your words carefully. Believe me, that is not the case. YOU are the one who raised the specter of politically correct groupthink, not me. That's dog-whistle politics. But okay, let's move on from that. You say that all you want is a switch to turn off Unicode (and replace it with what? Kanji strings? Cyrillic? Shift_JS? no of course not, I'm being absurd -- replace it with ASCII, what else could any right-thinking person want, right?). Let's look at this from a purely technical perspective: Python already has two string data types, bytes and text. You want something that is almost functionally identical to bytes, but to call it text, presumably because you don't want to have to prefix your strings with a b"" (that was also Marko's objection to byte strings). Let's say we do it. Now we have three string implementations that need to be added, documented, tested, maintained, instead of two. (Are you volunteering to do this work?) Now we need to double the testing: every library needs to be tested twice, once with the "Unicode text" switch on, once with it off, to ensure that features behave as expected in the appropriate mode. Is this switch a build-time option, so that we have interpreters built with support for Unicode and interpreters built without it? We've been there: it's a horribly bad idea. We used to have Python builds with threading support, and others without threading support. We used to have Python builds with "wide Unicode" and others with "narrow Unicode". Nothing good comes of this design. Or perhaps the switch is a runtime global option? Surely you can imagine the opportunities for bugs, both obvious crashing bugs and non-obvious silent failure bugs, that will occur when users run libraries intended for one mode under the other mode. Not every library is going to be fully tested under both modes. Perhaps it is a compile-time option that only affects the current module, like the __future__ imports. That's a bit more promising, it might even use the __future__ infrastructure -- but then you have the problem of interaction between modules that have this switch enabled and those that have it disabled. More complexity, more cruft, more bugs. It's not clear that your switch gives us *any* advantage at all, except the warm fuzzy feelings that no dirty foreign characters might creep into our pure ASCII strings. Hmm, okay, but frankly apart from when I copy and paste code from the internet and it ends up bringing in en-dashes and curly quotes instead of hyphens and type-writer quotes, that never happens to me by accident, and I'm having a lot of trouble seeing how it could. If you want ASCII byte strings, you have them right now -- you just have to use the b"" string syntax. If you want ASCII strings without the b prefix, you have them right now. Just use only ASCII characters in your strings. I'm simply not seeing the advantage of: from __future__ import no_unicode print("Hello World!") # stand in for any string handling on ASCII over print("Hello World!") which works just as well if you control the data you are working with and know that it is pure ASCII. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From stephanh42 at gmail.com.invalid Mon Jul 16 14:33:07 2018 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 16 Jul 2018 18:33:07 GMT Subject: doubling the number of tests, but not taking twice as long References: Message-ID: Op 2018-07-16, Larry Martell schreef : > I had some code that did this: > > meas_regex = '_M\d+_' > meas_re = re.compile(meas_regex) > > if meas_re.search(filename): > stuff1() > else: > stuff2() > > I then had to change it to this: > > if meas_re.search(filename): > if 'MeasDisplay' in filename: > stuff1a() > else: > stuff1() > else: > if 'PatternFov' in filename: > stuff2a() > else: > stuff2() > > This code needs to process many tens of 1000's of files, and it runs > often, so it needs to run very fast. Needless to say, my change has > made it take 2x as long. It's not at all obvious to me. Did you actually measure it? Seems to depend strongly on what stuff1a and stuff2a are doing. > Can anyone see a way to improve that? Use multiprocessing.Pool to exploit multiple CPUs? Stephan From jlee54 at gmail.com Mon Jul 16 14:33:46 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 16 Jul 2018 11:33:46 -0700 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On 07/16/18 10:40, Mark Lawrence wrote: > On 16/07/18 18:27, Jim Lee wrote: >> >> Obviously, the most vocal representatives of the Python community are >> too sensitive about their language to enable rational discussion. > Please moderators ban this person as he's going down the same line as > bartc and similar, it is completely unacceptable, he's just the latest > in a long line of trolls. > That was completely predictable (though I expected it from a different person). Go right ahead.? I find it surprising that Stephen isn't banned, considering the fact that he ridicules anyone he doesn't agree with.? But I guess he's one of the 'good 'ol boys', and so exempt from the code of conduct. Bye guys. From rosuav at gmail.com Mon Jul 16 14:40:15 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 04:40:15 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> Message-ID: On Tue, Jul 17, 2018 at 4:15 AM, Ian Kelly wrote: > On Mon, Jul 16, 2018 at 12:02 PM Terry Reedy wrote: >> >> On 7/15/2018 5:28 PM, Marko Rauhamaa wrote: >> >> > if your new system used Python3's UTF-32 strings as a foundation, >> >> Since 3.3, Python's strings are not (always) UFT-32 strings. Nor are >> they always UCS-2 (or partly UTF-16) strings. Nor are the always >> Latin-1 or Ascii strings. Python's Flexible String Representation uses >> the narrowest possible internal code for any particular string. This is >> all transparent to the user except for memory size. >> >> In 3.2 and before, Python's Unicode strings were either wide (UFT-32) or >> narrow (UCS-2 + surrogates or UFT-16 minus full compliance). The >> difference was sometimes not transparent, and code that worked on one >> build could fail on the other. Since 3.3, string code should work the >> same on any machines running the same Python version. >> >> > UTF-32, after all, is a variable-width encoding. >> >> Nope. It a fixed-width (32 bits, 4 bytes) encoding. > > Although it only really uses 21 (actually, more like 20.087) of those > bits. Given that and the similar naming, it's easy to see how people > sometimes confuse its structure with UTF-8. Yes, but that's on par with ASCII text putting seven bits' worth of information into an eight-bit byte. UTF-32 still assigns four bytes per codepoint, even though you could represent any Unicode character with just 21 bits (or, as you say, a smidgen over twenty bits). (Nobody's yet proposed a UTF-24, to my knowledge, even though it would technically work. I suspect that either UTF-32 or UTF-8 would be superior in any situation where UTF-24 might have been used.) ChrisA From tjreedy at udel.edu Mon Jul 16 14:42:09 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Jul 2018 14:42:09 -0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87muuu6c9v.fsf@elektro.pacujo.net> <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> Message-ID: On 7/15/2018 4:09 PM, Jim Lee wrote: > > > On 07/15/18 12:37, MRAB wrote: >> To me, Unicode and UTF-8 aren't things to be reserved for I18N. I use >> them as a matter of course because I find it a lot easier to stick >> with just one encoding, one that will work with _any_ text I have. > > Which is exactly the same rationale for using any other single encoding > (including ASCII).? If the text you deal with is not multi-lingual, why > complicate matters by trying to support a plethora of encodings which > will never be used (and the attendant opportunity for more bugs)? What you are describing -- supporting hundreds of encodings with occasional bugs, including multiple encodings in a single string -- describes the text as bytes mess. Switching to unicode strings was a vast simplification. Being able to dump the hundreds of byte encoding would be a further simplification, but it will be decades or more before we can do that ;-) > Note that I'm *not* saying Unicode? is *bad*, just that it's an > unnecessary complication for a great deal of programming tasks. I do not understand what you mean by 'unicode is complication'. From the viewpoint of core developers, it is a simplification. > For a > great deal more, it's absolutely necessary.? That why I said a "smart" > language would make it easy to turn on and off. What you mean by 'turn unicode off'? -- Terry Jan Reedy From jlee54 at gmail.com Mon Jul 16 14:43:27 2018 From: jlee54 at gmail.com (Jim Lee) Date: Mon, 16 Jul 2018 11:43:27 -0700 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On 07/16/18 11:31, Steven D'Aprano wrote: > On Mon, 16 Jul 2018 10:27:18 -0700, Jim Lee wrote: > >> Had you actually read my words with *intent* rather than *reaction*, you >> would notice that I suggested the *option* of turning off Unicode. > Yes, I know what you wrote, and I read it with intent. > > Jim, you seem to be labouring under the misapprehension that anytime > somebody spots a flaw in your argument, or an unpleasant implication of > your words, it can only be because they must not have read your words > carefully. Believe me, that is not the case. > > YOU are the one who raised the specter of politically correct groupthink, > not me. That's dog-whistle politics. But okay, let's move on from that. > > You say that all you want is a switch to turn off Unicode (and replace it > with what? Kanji strings? Cyrillic? Shift_JS? no of course not, I'm being > absurd -- replace it with ASCII, what else could any right-thinking > person want, right?). Let's look at this from a purely technical > perspective: > > Python already has two string data types, bytes and text. You want > something that is almost functionally identical to bytes, but to call it > text, presumably because you don't want to have to prefix your strings > with a b"" (that was also Marko's objection to byte strings). > > Let's say we do it. Now we have three string implementations that need to > be added, documented, tested, maintained, instead of two. > > (Are you volunteering to do this work?) > > Now we need to double the testing: every library needs to be tested > twice, once with the "Unicode text" switch on, once with it off, to > ensure that features behave as expected in the appropriate mode. > > Is this switch a build-time option, so that we have interpreters built > with support for Unicode and interpreters built without it? We've been > there: it's a horribly bad idea. We used to have Python builds with > threading support, and others without threading support. We used to have > Python builds with "wide Unicode" and others with "narrow Unicode". > Nothing good comes of this design. > > Or perhaps the switch is a runtime global option? > > Surely you can imagine the opportunities for bugs, both obvious crashing > bugs and non-obvious silent failure bugs, that will occur when users run > libraries intended for one mode under the other mode. Not every library > is going to be fully tested under both modes. > > Perhaps it is a compile-time option that only affects the current module, > like the __future__ imports. That's a bit more promising, it might even > use the __future__ infrastructure -- but then you have the problem of > interaction between modules that have this switch enabled and those that > have it disabled. > > More complexity, more cruft, more bugs. > > It's not clear that your switch gives us *any* advantage at all, except > the warm fuzzy feelings that no dirty foreign characters might creep into > our pure ASCII strings. Hmm, okay, but frankly apart from when I copy and > paste code from the internet and it ends up bringing in en-dashes and > curly quotes instead of hyphens and type-writer quotes, that never > happens to me by accident, and I'm having a lot of trouble seeing how it > could. > > If you want ASCII byte strings, you have them right now -- you just have > to use the b"" string syntax. > > If you want ASCII strings without the b prefix, you have them right now. > Just use only ASCII characters in your strings. > > I'm simply not seeing the advantage of: > > from __future__ import no_unicode > print("Hello World!") # stand in for any string handling on ASCII > > over > > print("Hello World!") > > which works just as well if you control the data you are working with and > know that it is pure ASCII. > > Had you spoken this way from the start instead of ridiculing and name calling, perhaps we could have reached an agreement. However, the point is moot, as I have unsubscribed from the list. The conversations here (especially yours) are too condescending to waste more time with. From rosuav at gmail.com Mon Jul 16 14:51:55 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 04:51:55 +1000 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> Message-ID: On Tue, Jul 17, 2018 at 4:22 AM, Richard Damon wrote: > > But I am not talking about those sort of characters or ligatures, but ?characters? that are built up of a combining diacritical marks (like accents) and a base character. Unicode define many code points for the more common of these, but many others do not. > So, you're talking about "grapheme clusters". Those can be arbitrarily large and complex. Trolls revel in the ability to adorn base characters with ridiculous numbers of "dripping" marks, making it hard to type their names. Since the amount of information in one grapheme cluster is (as far as I know) potentially infinite, it's fundamentally impossible to create a fixed-size encoding that can represent them. If I'm wrong about the possibilities being infinite, then they are certainly very extensive, as there are MANY combining characters available (the only question is whether you can use the same characters multiple times, in which case there are infinite possibilities, or if not, in which case the possibilities are base_characters*2^combining_characters aka "virtually infinite"). http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries This is a display feature, not an input feature, and certainly not a string representation feature. ChrisA From steve+comp.lang.python at pearwood.info Mon Jul 16 14:55:46 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 16 Jul 2018 18:55:46 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> Message-ID: On Mon, 16 Jul 2018 14:22:27 -0400, Richard Damon wrote: [...] > But I am not talking about those sort of characters or ligatures, So what? I am. You don't get to say "only non-standard definitions I approve of count". There is the industry standard definition of what it means to be a fixed- or variable-width encoding, which we can all agree on, or we can have a free-for-all where I reject your non-standard meaning and you reject mine and nobody can understand anything that anyone else says. You (generic "you", not necessarily you personally) don't get to demand that I must accept your redefinition, while simultaneously refusing to return the favour. If you try, I will simply dismiss what you say as nonsense on stilts: you (still generic you) clearly don't know what variable-width means and are trying to shift the terms of the debate by redefining terms so that black means white and white means purple. > but > ?characters? that are built up of a combining diacritical marks (like > accents) and a base character. Unicode define many code points for the > more common of these, but many others do not. I am aware how Unicode works, and it doesn't change a thing. Fixed/variable width is NOT defined in terms of "characters", but if it were, ASCII would be variable width too. Limiting the definition to only diacritics is just a feeble attempt to wiggle out of the logical consequences of your (generic your) position. There is nothing special about diacritics such that we ought to treat some combinations like "Ch" (two code points = one character) as "fixed width" while others like "?" (two code points = one character) as "variable width". To do so is just special pleading. And the thing about special pleading is that we're not obliged to accept it. Plead as much as you like, the answer is still no. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From square.steve at gmail.com Mon Jul 16 15:03:39 2018 From: square.steve at gmail.com (Steve Simmons) Date: Mon, 16 Jul 2018 20:03:39 +0100 Subject: Users banned In-Reply-To: References: <5B4B8391.3060808@stoneleaf.us> <877elw2ndr.fsf@elektro.pacujo.net> <5b7046a6-4c96-c8b0-9b5b-ec7999d4865d@gmail.com> Message-ID: <6ef56d48-eb59-ac77-2e5f-d0c6fdc7b1b9@gmail.com> On 16/07/2018 03:13, Devin Jeanpierre wrote: > On Sun, Jul 15, 2018 at 5:09 PM Jim Lee wrote: >> That is, of course, the decision of the moderators - but I happen to >> agree with both Christian and Ethan. Banning for the simple reason of a >> dissenting opinion is censorship, pure and simple. While Bart may have >> been prolific in his arguments, he never spoke in a toxic or >> condescending manner, or broke any of the rules of conduct. I cannot >> say the same for several who engaged with him. > +1000 It seems to me like the python-list moderators are rewarding > people for being bullies, by banning the people they were bullying. > The behavior on the list the past few days has been unforgivably > toxic, and that has nothing to do with the behavior of Bart et al. > > -- Devin +1? Seems to me Bart is being banned for "being a dick" and "talking rubbish" (my words/interpretation) with irritating persistence. Wonder how many of the non-banned members have been guilty of the same thing in one way or another. Steve Simmons From tjreedy at udel.edu Mon Jul 16 15:04:53 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Jul 2018 15:04:53 -0400 Subject: [SUSPICIOUS MESSAGE] Re: Cult-like behaviour [was Re: Kindness] In-Reply-To: <201807161054.04480.gheskett@shentel.net> References: <87sh4jw95v.fsf@elektro.pacujo.net> <201807161054.04480.gheskett@shentel.net> Message-ID: On 7/16/2018 10:54 AM, Gene Heskett wrote: > On Monday 16 July 2018 10:24:28 Marko Rauhamaa wrote: >> Plus the bytes syntax is really ugly. I wish Python3 had reserved >> '...' for byte strings and "..." for UTF-32 strings. Aside from the fact that Python3 strings are not UTF-32 strings, this would have broken all the code that used '' and "" interchangeably and prohibited such conveniences as "In formal English, do not use don't, isn't, and ain't." > From a lurker, that does sound usefull. The next PEP maybe? I hope you are joking or teasing Marko. -- Terry Jan Reedy From tjreedy at udel.edu Mon Jul 16 15:09:16 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Jul 2018 15:09:16 -0400 Subject: [SUSPICIOUS MESSAGE] Re: Cult-like behaviour [was Re: Kindness] In-Reply-To: <3gfpkdp7fojv7go5gf938noc6qampce9ur@4ax.com> References: <87sh4jw95v.fsf@elektro.pacujo.net> <201807161054.04480.gheskett@shentel.net> <3gfpkdp7fojv7go5gf938noc6qampce9ur@4ax.com> Message-ID: On 7/16/2018 11:50 AM, Dennis Lee Bieber wrote: > For Python 4000 maybe Please don't give people the idea that there is any current intention to have a 'Python 4000' similar to 'Python 3000'. Call it 'a mythical Python 4000', if you must use such a term. -- Terry Jan Reedy From gheskett at shentel.net Mon Jul 16 15:16:54 2018 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 16 Jul 2018 15:16:54 -0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <201807161224.49133.gheskett@shentel.net> Message-ID: <201807161516.54390.gheskett@shentel.net> On Monday 16 July 2018 14:01:54 Chris Angelico wrote: > On Tue, Jul 17, 2018 at 2:24 AM, Gene Heskett wrote: > > On Monday 16 July 2018 11:57:25 Chris Angelico wrote: > >> On Tue, Jul 17, 2018 at 1:48 AM, Gene Heskett > >> > > > > wrote: > >> > On Sunday 15 July 2018 16:09:21 Chris Angelico wrote: > >> >> On Mon, Jul 16, 2018 at 4:22 AM, James Lee wrote: > >> >> > On 7/15/2018 3:43 AM, Steven D'Aprano wrote: > >> >> >> No. The real ten billion dollar question is how people in > >> >> >> 2018 can stick their head in the sand and take seriously the > >> >> >> position that Latin-1 (let alone ASCII) is enough for text > >> >> >> strings. > >> >> > > >> >> > Easy - for many people, 90% of the Python code they write is > >> >> > not intended for world-wide distribution, let alone use. > >> >> > > >> >> > The smart thing would be for a language to have a switch of > >> >> > some sort to turn on/off all I18N features. > >> >> > >> >> Earlier I cited an example of round-tripping from human to human > >> >> via various web protocols. Here's an actual example of a Twitch > >> >> stream title: > >> >> > >> >> ?? Stardew Valley Fanart ??*:???? 800 Subpoints = NEW EMOTE > >> >> ?#devicat #anime #stardewvalley #fantasy > >> > > >> > Ok, I'll bite. What font would be used to properly display the > >> > above? > >> > >> Not sure, but the default fonts in my web browser, text editor, and > >> terminal all have no problems with it. I'm on Debian Linux running > >> Xfce, fwiw. Haven't had any issues anywhere. > >> > >> ChrisA > > > > Whereas I am on wheezy, 32 bit pae, using TDE as a desktop, with > > kmail-1.9-10-enterprise, using a 14 point unifont for the message > > body display. > > > > Its a nice clear, very readable font for these elderly eyes. I just > > tried several of the more std fonts w/o affecting the display of the > > rectangles you see above. Hence the question and thread noise. > > Apparently, and despite being set for utf-8, I don't have a font > > capable of displaying this string in its entirety as I've just tried > > a couple dozen more. > > > > Thanks ChrisA. > > Oh! I just remembered. Try installing (through apt-get or equivalent) > the "unifont" package. It'll drag in a few fonts designed to provide > good coverage of all of Unicode, making them available as fallback > fonts. That way, when you use a font that doesn't have all the > characters, it'll use that for the bulk of the text, but instead of > the rectangles that you're seeing, you'll get the correct glyphs. > > ChrisA Checking now ChrisA, and I already have installed: unifont unifont.bin xfonts-unifont ttf-unifont all version 1:5.1.200809-14-1.3 Is there another package to make it complete? I did select and install a couple that might have some connection. But I am still seeing the same rectangles. Obviously my guesses weren't SWAG's. Thanks ChrisA -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From gheskett at shentel.net Mon Jul 16 15:22:37 2018 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 16 Jul 2018 15:22:37 -0400 Subject: [SUSPICIOUS MESSAGE] Re: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <201807161054.04480.gheskett@shentel.net> Message-ID: <201807161522.37307.gheskett@shentel.net> On Monday 16 July 2018 15:04:53 Terry Reedy wrote: > On 7/16/2018 10:54 AM, Gene Heskett wrote: > > On Monday 16 July 2018 10:24:28 Marko Rauhamaa wrote: > >> Plus the bytes syntax is really ugly. I wish Python3 had reserved > >> '...' for byte strings and "..." for UTF-32 strings. > > Aside from the fact that Python3 strings are not UTF-32 strings, > this would have broken all the code that used '' and "" > interchangeably and prohibited such conveniences as "In formal > English, do not use don't, isn't, and ain't." > > > From a lurker, that does sound usefull. The next PEP maybe? > > I hope you are joking or teasing Marko. > I wasn't, but obviously didn't consider the ramifications of that on existing programs. My bad. I note that it also elicited a strong defense of the status quo. Expected though, given the tone of this list over the last year or so. So I'll go back to lurking. :) I am here to learn. If I can... > -- > Terry Jan Reedy -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From grant.b.edwards at gmail.com Mon Jul 16 15:27:20 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 16 Jul 2018 19:27:20 +0000 (UTC) Subject: Users banned References: <5B4B8391.3060808@stoneleaf.us> <877elw2ndr.fsf@elektro.pacujo.net> <5b7046a6-4c96-c8b0-9b5b-ec7999d4865d@gmail.com> <6ef56d48-eb59-ac77-2e5f-d0c6fdc7b1b9@gmail.com> Message-ID: On 2018-07-16, Steve Simmons wrote: > +1? Seems to me Bart is being banned for "being a dick" and "talking > rubbish" (my words/interpretation) with irritating persistence. Wonder > how many of the non-banned members have been guilty of the same thing in > one way or another. I'm sure many of us have been guilty of one or both at some time or another. I think the level of "persistence" is the key. -- Grant Edwards grant.b.edwards Yow! I represent a at sardine!! gmail.com From tjreedy at udel.edu Mon Jul 16 15:28:51 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Jul 2018 15:28:51 -0400 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> Message-ID: On 7/16/2018 1:11 PM, Richard Damon wrote: > Many consider that UTF-32 is a variable-width encoding because of the combining characters. It can take multiple ?codepoints? to define what should be a single ?character? for display. I hope you realize that this is not the standard meaning of 'variable-width encoding', which is 'variable number of bytes for a codepoint'. UTF-16 and UTF-8 are variable width. If one expands the definition enough, Ascii is 'variable width' because 'fi' is two bytes, or more realistically, because <= and >= are two bytes instead of one (as they can be in Unicode!). If one is using a broader definition than usual, it is clearer to say so. -- Terry Jan Reedy From rhodri at kynesim.co.uk Mon Jul 16 15:35:40 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 16 Jul 2018 20:35:40 +0100 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: <4ce10695-9d26-bb69-768f-0601d360f8f8@kynesim.co.uk> References: <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> <4ce10695-9d26-bb69-768f-0601d360f8f8@kynesim.co.uk> Message-ID: <0f0dd150-6466-839c-6acc-4a0b8b9d092e@kynesim.co.uk> On 16/07/18 18:38, Rhodri James wrote: > Actually having an option of turning off Unicode *does* make it harder > to use, because you end up coming across programs that have Unicode and > surprise you when they misbehave.? And yes I saw that 90% of your > programs aren't intended to get out into the world.? 90% is never meant > to leave the office.? 90% of that does anyway. I meant to say "90% *of my Python code* is never meant to leave the office." Never post when in a hurry :-( -- Rhodri James *-* Kynesim Ltd From marko at pacujo.net Mon Jul 16 15:40:13 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 16 Jul 2018 22:40:13 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> Message-ID: <87fu0j0y1u.fsf@elektro.pacujo.net> Terry Reedy : > On 7/15/2018 5:28 PM, Marko Rauhamaa wrote: >> if your new system used Python3's UTF-32 strings as a foundation, > > Since 3.3, Python's strings are not (always) UFT-32 strings. You are right. Python's strings are a superset of UTF-32. More accurately, Python's strings are UTF-32 plus surrogate characters. > Nor are they always UCS-2 (or partly UTF-16) strings. Nor are the > always Latin-1 or Ascii strings. Python's Flexible String > Representation uses the narrowest possible internal code for any > particular string. This is all transparent to the user except for > memory size. How CPython chooses to represent its strings internally is not what I'm talking about. >> UTF-32, after all, is a variable-width encoding. > > Nope. It a fixed-width (32 bits, 4 bytes) encoding. > > Perhaps you should ask more questions before pontificating. You mean each code point is one code point wide. But that's rather an irrelevant thing to state. The main point is that UTF-32 (aka Unicode) uses one or more code points to represent what people would consider an individual character. The letter "a" is encoded as a single code point, but ?? (Flag, United Kingdom) is two code points wide and ? (Flag, England) is seven (!) code points wide, not to forget ???? (Man in Steamy Room) with four code points. And of course, regular West-European letters can be represented by multiple code points. Code points are about as interesting as individual bytes in UTF-8. Marko From rhodri at kynesim.co.uk Mon Jul 16 15:41:55 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 16 Jul 2018 20:41:55 +0100 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: <57a17998-71d3-8d0d-f105-2551a7b31584@kynesim.co.uk> On 16/07/18 19:31, Steven D'Aprano wrote: > I'm simply not seeing the advantage of: > > from __future__ import no_unicode > print("Hello World!") # stand in for any string handling on ASCII Sure this should be "from __past__ import no_unicode"? gd&r -- Rhodri James *-* Kynesim Ltd From marko at pacujo.net Mon Jul 16 15:51:32 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 16 Jul 2018 22:51:32 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> Message-ID: <87bmb70xiz.fsf@elektro.pacujo.net> Steven D'Aprano : > Under that standard definition, UTF-8 and UTF-16 are variable-width, > and UTF-32 is fixed-width. > > But I'll accept that UTF-32 is variable-width if Marko accepts that > ASCII is too. If that makes you happy, fine. The point is, UTF-32 has no advantages over UTF-8. And I'm referring to the text abstraction as seen by the programmer. It has nothing to do with the layout of bytes inside CPython. I use UTF-8 in my C programs and sense no disadvantage. I have never felt a need for wchar_t. Similarly, I had a small Python2 program that quizzed me about Hebrew vocabulary with Finnish translations and Esperanto pronunciation instructions. All UTF-8. No unicode strings. (I *have* converted that to Python3 just to be on the bleeding edge, but it didn't give me any advantages over Python2.) Marko From tjreedy at udel.edu Mon Jul 16 15:52:07 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Jul 2018 15:52:07 -0400 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On 7/16/2018 1:13 PM, Jim Lee wrote: > I just think that a language should allow one to bypass Unicode handling > easily *when it's not needed*. Both for patching IDLE and for my currently private work, I usually only use Ascii, and no unicode escapes. When I do, it does not matter whether editor and python internally use ascii unicode or ascii bytes. So I don't understand 'bypass Unicode handling'. When I do want to use other characters, whether to test IDLE or just for fun, Python 3 in much nicer. Since I have not bothered to learn ann non-Englich Windows Input Methods, I just use \unnnn or, for non-BMP chars, \U000nnnnn escapes. I don't need a 'u' prefix or unicode(s, encoding=???) conversion. Thus, I was able to expand IDLE's font sample of the font selection dialog tab from 40 ascii chars to this. AaBbCcDdEeFfGgHhIiJj 1234567890#:+=(){}[] ???????????????????? ???????????????????? ???????????????????? ???????????????????? ???????????????????? ???????????????????? ???????????????????? ?????????????? ?????????? ?????????? ?????????? ?????????? *You* may not care about the non-Ascii parts, but people who use other scripts do. So I don't understand why you are bothered by having the option of easily using other characters if you want to, or if external circumstances were to compel you. I love it. -- Terry Jan Reedy From rosuav at gmail.com Mon Jul 16 15:52:23 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 05:52:23 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <201807161516.54390.gheskett@shentel.net> References: <201807161224.49133.gheskett@shentel.net> <201807161516.54390.gheskett@shentel.net> Message-ID: On Tue, Jul 17, 2018 at 5:16 AM, Gene Heskett wrote: > On Monday 16 July 2018 14:01:54 Chris Angelico wrote: > >> On Tue, Jul 17, 2018 at 2:24 AM, Gene Heskett > wrote: >> > On Monday 16 July 2018 11:57:25 Chris Angelico wrote: >> >> On Tue, Jul 17, 2018 at 1:48 AM, Gene Heskett >> >> >> > >> > wrote: >> >> > On Sunday 15 July 2018 16:09:21 Chris Angelico wrote: >> >> >> On Mon, Jul 16, 2018 at 4:22 AM, James Lee > wrote: >> >> >> > On 7/15/2018 3:43 AM, Steven D'Aprano wrote: >> >> >> >> No. The real ten billion dollar question is how people in >> >> >> >> 2018 can stick their head in the sand and take seriously the >> >> >> >> position that Latin-1 (let alone ASCII) is enough for text >> >> >> >> strings. >> >> >> > >> >> >> > Easy - for many people, 90% of the Python code they write is >> >> >> > not intended for world-wide distribution, let alone use. >> >> >> > >> >> >> > The smart thing would be for a language to have a switch of >> >> >> > some sort to turn on/off all I18N features. >> >> >> >> >> >> Earlier I cited an example of round-tripping from human to human >> >> >> via various web protocols. Here's an actual example of a Twitch >> >> >> stream title: >> >> >> >> >> >> ?? Stardew Valley Fanart ??*:???? 800 Subpoints = NEW EMOTE >> >> >> ?#devicat #anime #stardewvalley #fantasy >> >> > >> >> > Ok, I'll bite. What font would be used to properly display the >> >> > above? >> >> >> >> Not sure, but the default fonts in my web browser, text editor, and >> >> terminal all have no problems with it. I'm on Debian Linux running >> >> Xfce, fwiw. Haven't had any issues anywhere. >> >> >> >> ChrisA >> > >> > Whereas I am on wheezy, 32 bit pae, using TDE as a desktop, with >> > kmail-1.9-10-enterprise, using a 14 point unifont for the message >> > body display. >> > >> > Its a nice clear, very readable font for these elderly eyes. I just >> > tried several of the more std fonts w/o affecting the display of the >> > rectangles you see above. Hence the question and thread noise. >> > Apparently, and despite being set for utf-8, I don't have a font >> > capable of displaying this string in its entirety as I've just tried >> > a couple dozen more. >> > >> > Thanks ChrisA. >> >> Oh! I just remembered. Try installing (through apt-get or equivalent) >> the "unifont" package. It'll drag in a few fonts designed to provide >> good coverage of all of Unicode, making them available as fallback >> fonts. That way, when you use a font that doesn't have all the >> characters, it'll use that for the bulk of the text, but instead of >> the rectangles that you're seeing, you'll get the correct glyphs. >> >> ChrisA > > Checking now ChrisA, and I already have installed: > unifont > unifont.bin > xfonts-unifont > ttf-unifont > > all version 1:5.1.200809-14-1.3 > > Is there another package to make it complete? > > I did select and install a couple that might have some connection. But I > am still seeing the same rectangles. Obviously my guesses weren't > SWAG's. Hmm, now I'm not sure. I do know that, back when I was messing with Thai and Chinese subtitles, I spent a LONG time messing around, because inevitably, whichever font I picked, one or the other of them, or the English subs, would look ugly. Dig around with fonts, install a bunch of them; worst case, they just take up space on your disk. Sorry I can't be more help. ChrisA From rhodri at kynesim.co.uk Mon Jul 16 15:56:11 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 16 Jul 2018 20:56:11 +0100 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87fu0j0y1u.fsf@elektro.pacujo.net> References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <87fu0j0y1u.fsf@elektro.pacujo.net> Message-ID: <8fd795ac-2264-a835-aab3-ff5ef82ee852@kynesim.co.uk> On 16/07/18 20:40, Marko Rauhamaa wrote: > Terry Reedy: > >> On 7/15/2018 5:28 PM, Marko Rauhamaa wrote: >>> if your new system used Python3's UTF-32 strings as a foundation, >> Since 3.3, Python's strings are not (always) UFT-32 strings. > You are right. Python's strings are a superset of UTF-32. More > accurately, Python's strings are UTF-32 plus surrogate characters. > >> Nor are they always UCS-2 (or partly UTF-16) strings. Nor are the >> always Latin-1 or Ascii strings. Python's Flexible String >> Representation uses the narrowest possible internal code for any >> particular string. This is all transparent to the user except for >> memory size. > How CPython chooses to represent its strings internally is not what I'm > talking about. > >>> UTF-32, after all, is a variable-width encoding. >> Nope. It a fixed-width (32 bits, 4 bytes) encoding. >> >> Perhaps you should ask more questions before pontificating. > You mean each code point is one code point wide. But that's rather an > irrelevant thing to state. The main point is that UTF-32 (aka Unicode) > uses one or more code points to represent what people would consider an > individual character. UTF-32 != Unicode, but that's a separate esoteric argument. The problem everyone is having with you, Marko, is that you are using the terminology incorrectly. When you say that more than one codepoint can be used to represent what people would consider an individual character, you are correct (and would be more correct if you called "what people would consider an individual character" a "glyph"). When you call UTF-32 a variable-width encoding, you are incorrect. You are of course welcome to use whatever terminology you personally like, like Humpty Dumpty. However when you point to a duck and say "That's a gnu," people are likely to stop taking you seriously. -- Rhodri James *-* Kynesim Ltd From tjreedy at udel.edu Mon Jul 16 15:58:05 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Jul 2018 15:58:05 -0400 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: On 7/16/2018 1:27 PM, Jim Lee wrote: > 90% of the world *is* "beneath my notice" when it comes to programming > for myself.?? I really don't care if that's not PC enough for you. > > Had you actually read my words with *intent* rather than *reaction*, you > would notice that I suggested the *option* of turning off Unicode.? I > didn't say get *rid* of Unicode.? I didn't say make it *harder* to use > Unicode.? Once again - reaction rather than reading. > > Obviously, the most vocal representatives of the Python community are > too sensitive about their language to enable rational discussion. My empirical observation is that the more abrasive posters get rewarded with more response, while my attempts to engage in rational discussion, without ad hominems, gets less. -- Terry Jan Reedy From wegge at wegge.dk Mon Jul 16 16:00:03 2018 From: wegge at wegge.dk (Anders Wegge Keller) Date: Mon, 16 Jul 2018 22:00:03 +0200 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: <20180716220003.3d64746e@wegge.dk> P? Mon, 16 Jul 2018 11:33:46 -0700 Jim Lee skrev: > Go right ahead.? I find it surprising that Stephen isn't banned, > considering the fact that he ridicules anyone he doesn't agree with.? > But I guess he's one of the 'good 'ol boys', and so exempt from the code > of conduct. Well said! -- //Wegge From rosuav at gmail.com Mon Jul 16 16:07:33 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 06:07:33 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87fu0j0y1u.fsf@elektro.pacujo.net> References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <87fu0j0y1u.fsf@elektro.pacujo.net> Message-ID: On Tue, Jul 17, 2018 at 5:40 AM, Marko Rauhamaa wrote: > Terry Reedy : > >> On 7/15/2018 5:28 PM, Marko Rauhamaa wrote: >>> if your new system used Python3's UTF-32 strings as a foundation, >> >> Since 3.3, Python's strings are not (always) UFT-32 strings. > > You are right. Python's strings are a superset of UTF-32. More > accurately, Python's strings are UTF-32 plus surrogate characters. > >> Nor are they always UCS-2 (or partly UTF-16) strings. Nor are the >> always Latin-1 or Ascii strings. Python's Flexible String >> Representation uses the narrowest possible internal code for any >> particular string. This is all transparent to the user except for >> memory size. > > How CPython chooses to represent its strings internally is not what I'm > talking about. Then don't talk about UTF-32, which is a representation format. >>> UTF-32, after all, is a variable-width encoding. >> >> Nope. It a fixed-width (32 bits, 4 bytes) encoding. >> >> Perhaps you should ask more questions before pontificating. > > You mean each code point is one code point wide. But that's rather an > irrelevant thing to state. The main point is that UTF-32 (aka Unicode) > uses one or more code points to represent what people would consider an > individual character. No, each code point is one code unit wide. It's not irrelevant. > The letter "a" is encoded as a single code point, but ?? (Flag, United > Kingdom) is two code points wide and ? (Flag, England) is seven (!) > code points wide, not to forget ???? (Man in Steamy Room) with four code > points. > > And of course, regular West-European letters can be represented by > multiple code points. > > Code points are about as interesting as individual bytes in UTF-8. Individual bytes in UTF-8 do not have individual meaning. Individual code points do, with the partial exception of the flag characters (which are pretty poorly supported anyway). Otherwise, every code point is either a base character with general meaning, or a combining character (or variant selector) that represents a specific change. They can be composed in different ways. For example: U+006F U+0301 "o?" LATIN SMALL LETTER O WITH ACUTE U+006F U+030B "o?" LATIN SMALL LETTER O WITH DOUBLE ACUTE U+0075 U+0301 "u?" LATIN SMALL LETTER U WITH ACUTE U+0075 U+030B "u?" LATIN SMALL LETTER U WITH DOUBLE ACUTE The UTF-8 representations of the combined forms of these characters are: C3 B3 C5 91 C3 BA C5 B1 What does byte value C5 mean? What does 91 mean? None of these has meaning on its own. The only way you can interpret them is as a full set. In contrast, the combining characters have meaning: a base character, or a combining character. So, no, individual code points are very interesting. ChrisA From rhodri at kynesim.co.uk Mon Jul 16 16:11:25 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 16 Jul 2018 21:11:25 +0100 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <87bmb70xiz.fsf@elektro.pacujo.net> References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> Message-ID: On 16/07/18 20:51, Marko Rauhamaa wrote: > I use UTF-8 in my C programs and sense no disadvantage. I have never > felt a need for wchar_t. That's not a good comparison, though, because wchar_t in C really doesn't give you much (if any) advantage over rolling your own UTF-8 support, even when that means making sure you don't split characters across buffers. -- Rhodri James *-* Kynesim Ltd From rosuav at gmail.com Mon Jul 16 16:11:27 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 06:11:27 +1000 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <87bmb70xiz.fsf@elektro.pacujo.net> References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> Message-ID: On Tue, Jul 17, 2018 at 5:51 AM, Marko Rauhamaa wrote: > Steven D'Aprano : >> Under that standard definition, UTF-8 and UTF-16 are variable-width, >> and UTF-32 is fixed-width. >> >> But I'll accept that UTF-32 is variable-width if Marko accepts that >> ASCII is too. > > If that makes you happy, fine. The point is, UTF-32 has no advantages > over UTF-8. And I'm referring to the text abstraction as seen by the > programmer. It has nothing to do with the layout of bytes inside > CPython. > > I use UTF-8 in my C programs and sense no disadvantage. I have never > felt a need for wchar_t. Similarly, I had a small Python2 program that > quizzed me about Hebrew vocabulary with Finnish translations and > Esperanto pronunciation instructions. All UTF-8. No unicode strings. (I > *have* converted that to Python3 just to be on the bleeding edge, but it > didn't give me any advantages over Python2.) Challenge: Reverse a string in UTF-8. Challenge: Center text in UTF-8. Challenge: Given a (non-initial) character in a buffer of UTF-8 bytes, find the immediately preceding character. All of these are fundamentally difficult by nature, but if you index by code points, you eliminate one level of difficulty; indexing by bytes retains all the existing difficulty and adds another layer. ChrisA From tjreedy at udel.edu Mon Jul 16 16:15:13 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Jul 2018 16:15:13 -0400 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <201807161148.16707.gheskett@shentel.net> <201807161224.49133.gheskett@shentel.net> Message-ID: On 7/16/2018 2:01 PM, Chris Angelico wrote: >>>>> ?? Stardew Valley Fanart ??*:???? 800 Subpoints = NEW EMOTE >>>>> ?#devicat #anime #stardewvalley #fantasy Just to be clear, ?? ?????? ?, \U0001f331, \u3010, \u3011, \uff65, \uff9f, \u2727 are the non-ascii chars in the above. for c in """?? Stardew Valley Fanart ??*:???? 800 Subpoints = NEW EMOTE?#devicat #anime #stardewvalley #fantasy""": print(hex(ord(c))) They look fine on Thunderbird, including the orange and green fruit. They look ok in Notepad++ (the fruit is black and white and not recognizable without knowing what it is). >>>> Ok, I'll bite. What font would be used to properly display the >>>> above? > Oh! I just remembered. Try installing (through apt-get or equivalent) > the "unifont" package. It'll drag in a few fonts designed to provide > good coverage of all of Unicode, making them available as fallback > fonts. That way, when you use a font that doesn't have all the > characters, it'll use that for the bulk of the text, but instead of > the rectangles that you're seeing, you'll get the correct glyphs. Windows 10 comes with good coverage of Unicode, fallback, and bidirectional (bidi) support. -- Terry Jan Reedy From rosuav at gmail.com Mon Jul 16 16:15:25 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 06:15:25 +1000 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> Message-ID: On Tue, Jul 17, 2018 at 4:55 AM, Steven D'Aprano wrote: > There is nothing special about diacritics such that we ought to treat > some combinations like "Ch" (two code points = one character) as "fixed > width" while others like "?" (two code points = one character) as > "variable width". When you reverse a word, do you treat "ch" and "sh" as one character or two? I'm of the opinion that they're single characters, and thus this should be "dalokosh": https://wiki.teamfortress.com/wiki/Dalokohs_Bar (It's the Russian for "chocolate" - "???????" - transliterated to English/Latin - "?okolad" or "shokolad" - and then reversed.) But that's an extremely difficult thing to explain to your average gamer... ChrisA From rhodri at kynesim.co.uk Mon Jul 16 16:16:34 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 16 Jul 2018 21:16:34 +0100 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: <8f3400e9-291e-3bcb-2ee9-6e4c8f254a7a@kynesim.co.uk> On 16/07/18 20:58, Terry Reedy wrote: > On 7/16/2018 1:27 PM, Jim Lee wrote: > >> 90% of the world *is* "beneath my notice" when it comes to programming >> for myself.?? I really don't care if that's not PC enough for you. >> >> Had you actually read my words with *intent* rather than *reaction*, >> you would notice that I suggested the *option* of turning off >> Unicode.? I didn't say get *rid* of Unicode.? I didn't say make it >> *harder* to use Unicode.? Once again - reaction rather than reading. >> >> Obviously, the most vocal representatives of the Python community are >> too sensitive about their language to enable rational discussion. > > My empirical observation is that the more abrasive posters get rewarded > with more response, while my attempts to engage in rational discussion, > without ad hominems, gets less. I wouldn't disagree with you. Fortunately Jim has pulled the "storming off in a huff rather than answer a question anyone actually asked" defence, so we can go back to debating about important things like how to spell assignment expressions. Oh wait... :-) -- Rhodri James *-* Kynesim Ltd From rosuav at gmail.com Mon Jul 16 16:19:06 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 06:19:06 +1000 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: <8f3400e9-291e-3bcb-2ee9-6e4c8f254a7a@kynesim.co.uk> References: <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> <8f3400e9-291e-3bcb-2ee9-6e4c8f254a7a@kynesim.co.uk> Message-ID: On Tue, Jul 17, 2018 at 6:16 AM, Rhodri James wrote: > On 16/07/18 20:58, Terry Reedy wrote: >> >> On 7/16/2018 1:27 PM, Jim Lee wrote: >> >>> 90% of the world *is* "beneath my notice" when it comes to programming >>> for myself. I really don't care if that's not PC enough for you. >>> >>> Had you actually read my words with *intent* rather than *reaction*, you >>> would notice that I suggested the *option* of turning off Unicode. I didn't >>> say get *rid* of Unicode. I didn't say make it *harder* to use Unicode. >>> Once again - reaction rather than reading. >>> >>> Obviously, the most vocal representatives of the Python community are too >>> sensitive about their language to enable rational discussion. >> >> >> My empirical observation is that the more abrasive posters get rewarded >> with more response, while my attempts to engage in rational discussion, >> without ad hominems, gets less. > > > I wouldn't disagree with you. Fortunately Jim has pulled the "storming off > in a huff rather than answer a question anyone actually asked" defence, so > we can go back to debating about important things like how to spell > assignment expressions. > > Oh wait... :-) > +1 QOTD. ChrisA From marko at pacujo.net Mon Jul 16 16:27:49 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 16 Jul 2018 23:27:49 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <87fu0j0y1u.fsf@elektro.pacujo.net> <8fd795ac-2264-a835-aab3-ff5ef82ee852@kynesim.co.uk> Message-ID: <877elv0vui.fsf@elektro.pacujo.net> Rhodri James : > On 16/07/18 20:40, Marko Rauhamaa wrote: >> You mean each code point is one code point wide. But that's rather an >> irrelevant thing to state. The main point is that UTF-32 (aka Unicode) >> uses one or more code points to represent what people would consider an >> individual character. > > UTF-32 != Unicode, but that's a separate esoteric argument. > > The problem everyone "Everyone"!!! > is having with you, Marko, is that you are using the terminology > incorrectly. When you say that more than one codepoint can be used to > represent what people would consider an individual character, you are > correct (and would be more correct if you called "what people would > consider an individual character" a "glyph"). When you call UTF-32 a > variable-width encoding, you are incorrect. Unicode is one of the primary selling points of Python3, and the uninitiated are led to believe the false dichotomy between 1. The ugly American who believes the whole world runs with ASCII and is happy with Python2. 2. The refined cosmopolitan who can appreciate the ease with which Python3 brings them the whole world. People (including "everyone" and the uninitiated) need to understand that Unicode strings are no better at cosmopolitan code than UTF-8 inside byte strings. In their time, Windows and Java believed UCS-2 is the solution to the woes of 8-bitness. They were sorely disappointed. Python3 thought it could benefit from hindsight and went directly to 21-bit Unicode code points (plus surrogate characters, which really have no business in Unicode strings). Alas, even that didn't cut it -- even for the Americans, who are abandoning English in droves for hieroglyphs, i.e., emojis. > You are of course welcome to use whatever terminology you personally > like, like Humpty Dumpty. However when you point to a duck and say > "That's a gnu," people are likely to stop taking you seriously. Who hath ears to hear, let him hear. Marko From python.list at tim.thechases.com Mon Jul 16 16:32:44 2018 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Jul 2018 15:32:44 -0500 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: References: <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> Message-ID: <20180716153244.50268123@bigbox.christie.dr> On 2018-07-16 18:31, Steven D'Aprano wrote: > You say that all you want is a switch to turn off Unicode (and > replace it with what? Kanji strings? Cyrillic? Shift_JS? no of > course not, I'm being absurd -- replace it with ASCII, what else > could any right-thinking person want, right?). But we already have this. If I want to turn off Unicode strings, I type "python2", and if I want to enable Unicode strings, I type "python3". While the python world has moved its efforts into improving Python3, Python2 hasn't suddenly stopped working. It just stopped receiving improvements. If the "old-man shakes-fist at progress" crowd doesn't like unicode stings in Py3, just keep on using Py2. You (generic) won't get arrested. There are no church^WPython police. -tkc From marko at pacujo.net Mon Jul 16 16:36:17 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 16 Jul 2018 23:36:17 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <87fu0j0y1u.fsf@elektro.pacujo.net> Message-ID: <8736wi2a0u.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Jul 17, 2018 at 5:40 AM, Marko Rauhamaa wrote: >> You mean each code point is one code point wide. But that's rather an >> irrelevant thing to state. The main point is that UTF-32 (aka >> Unicode) uses one or more code points to represent what people would >> consider an individual character. > > No, each code point is one code unit wide. It's not irrelevant. Finally, we have reached the simple crux of the debate, and that's where you and I disagree. Unicode code points sure express many more things than UTF-8 bytes. UTF-8 bytes can only represent the first 128 code points of Unicode. However, even Unicode has given up trying to represent even basic everyday symbols with single codepoints, which leads back to the question of how Python3's Unicode strings are superior to Python2's UTF-8 strings. They have the same up and downsides. Marko From marko at pacujo.net Mon Jul 16 16:54:35 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 16 Jul 2018 23:54:35 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> Message-ID: <87y3eazyt0.fsf@elektro.pacujo.net> Chris Angelico : > Challenge: Reverse a string in UTF-8. Counter-challenge: Reverse a Unicode string: >>> s = "a\u0304e" >>> s 'a?e' >>> L = list(s) >>> L.reverse() >>> "".join(L) 'e?a' > Challenge: Center text in UTF-8. Counter-challenge: Center a Unicode string: >>> t = s * 3 >>> t 'a?ea?ea?e' >>> t.center(9) 'a?ea?ea?e' > Challenge: Given a (non-initial) character in a buffer of UTF-8 bytes, > find the immediately preceding character. The counter-challenge is left as an exercise for the reader. > All of these are fundamentally difficult by nature, but if you index > by code points, you eliminate one level of difficulty; indexing by > bytes retains all the existing difficulty and adds another layer. Oh, sorry. I thought you were suggesting Unicode strings would make the challenges somehow easy. Marko From marko at pacujo.net Mon Jul 16 16:59:59 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 16 Jul 2018 23:59:59 +0300 Subject: Unicode [was Re: Cult-like behaviour] References: <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> <20180716153244.50268123@bigbox.christie.dr> Message-ID: <87tvoyzyk0.fsf@elektro.pacujo.net> Tim Chase : > While the python world has moved its efforts into improving Python3, > Python2 hasn't suddenly stopped working. The sword of Damocles is hanging on its head. Unless a consortium is erected to support Python2, no vendor will be able to use it in the medium term. Given the recent events, maybe that's exactly what's going to happen. A business consortium will take it on themselves to support and enhance Python2 ad infinitum. I wouldn't be surprised. (Although it might make me regret my knee-jerk porting effort.) Marko From rosuav at gmail.com Mon Jul 16 17:00:40 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 07:00:40 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <8736wi2a0u.fsf@elektro.pacujo.net> References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <87fu0j0y1u.fsf@elektro.pacujo.net> <8736wi2a0u.fsf@elektro.pacujo.net> Message-ID: On Tue, Jul 17, 2018 at 6:36 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Tue, Jul 17, 2018 at 5:40 AM, Marko Rauhamaa wrote: >>> You mean each code point is one code point wide. But that's rather an >>> irrelevant thing to state. The main point is that UTF-32 (aka >>> Unicode) uses one or more code points to represent what people would >>> consider an individual character. >> >> No, each code point is one code unit wide. It's not irrelevant. > > Finally, we have reached the simple crux of the debate, and that's where > you and I disagree. > > Unicode code points sure express many more things than UTF-8 bytes. > UTF-8 bytes can only represent the first 128 code points of Unicode. > However, even Unicode has given up trying to represent even basic > everyday symbols with single codepoints, which leads back to the > question of how Python3's Unicode strings are superior to Python2's > UTF-8 strings. They have the same up and downsides. > You snipped my explanation of how what you just said is flat out false. ChrisA From ethan at stoneleaf.us Mon Jul 16 17:02:43 2018 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 16 Jul 2018 14:02:43 -0700 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> Message-ID: <5B4D07F3.1010404@stoneleaf.us> On 07/16/2018 01:15 PM, Chris Angelico wrote: > On Tue, Jul 17, 2018 at 4:55 AM, Steven D'Aprano wrote: >> There is nothing special about diacritics such that we ought to treat >> some combinations like "Ch" (two code points = one character) as "fixed >> width" while others like "?" (two code points = one character) as >> "variable width". > > When you reverse a word, do you treat "ch" and "sh" as one character > or two? I'm of the opinion that they're single characters, and thus > this should be "dalokosh": Depends on the language: in Spanish, "ch" is it's own letter (at least it was when I grew up), so any word containing it should still contain it when reversed: "chica" would be "acich". -- ~Ethan~ From rosuav at gmail.com Mon Jul 16 17:04:05 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 07:04:05 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <877elv0vui.fsf@elektro.pacujo.net> References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <87fu0j0y1u.fsf@elektro.pacujo.net> <8fd795ac-2264-a835-aab3-ff5ef82ee852@kynesim.co.uk> <877elv0vui.fsf@elektro.pacujo.net> Message-ID: On Tue, Jul 17, 2018 at 6:27 AM, Marko Rauhamaa wrote: > Rhodri James : > >> On 16/07/18 20:40, Marko Rauhamaa wrote: >>> You mean each code point is one code point wide. But that's rather an >>> irrelevant thing to state. The main point is that UTF-32 (aka Unicode) >>> uses one or more code points to represent what people would consider an >>> individual character. >> >> UTF-32 != Unicode, but that's a separate esoteric argument. >> >> The problem everyone > > "Everyone"!!! > >> is having with you, Marko, is that you are using the terminology >> incorrectly. When you say that more than one codepoint can be used to >> represent what people would consider an individual character, you are >> correct (and would be more correct if you called "what people would >> consider an individual character" a "glyph"). When you call UTF-32 a >> variable-width encoding, you are incorrect. > > Unicode is one of the primary selling points of Python3 Here, have a look at the original plans for Python 3.0: https://www.python.org/dev/peps/pep-3100/ The default string type becoming Unicode was just one bullet point among many. Remember, Python 2 had Unicode strings for a long time; the change is not "now we use Unicode" but "now the simple and obvious string type is the text string rather than the byte sequence". Both types had previously been available. Both types remained available. This was not a "primary selling point". The main selling point was cleanups and simplifications. ChrisA From rosuav at gmail.com Mon Jul 16 17:05:24 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 07:05:24 +1000 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <87y3eazyt0.fsf@elektro.pacujo.net> References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <87y3eazyt0.fsf@elektro.pacujo.net> Message-ID: On Tue, Jul 17, 2018 at 6:54 AM, Marko Rauhamaa wrote: > Chris Angelico : >> Challenge: Reverse a string in UTF-8. > > Counter-challenge: Reverse a Unicode string: > > >>> s = "a\u0304e" > >>> s > 'a?e' > >>> L = list(s) > >>> L.reverse() > >>> "".join(L) > 'e?a' > >> Challenge: Center text in UTF-8. > > Counter-challenge: Center a Unicode string: > > >>> t = s * 3 > >>> t > 'a?ea?ea?e' > >>> t.center(9) > 'a?ea?ea?e' > >> Challenge: Given a (non-initial) character in a buffer of UTF-8 bytes, >> find the immediately preceding character. > > The counter-challenge is left as an exercise for the reader. > >> All of these are fundamentally difficult by nature, but if you index >> by code points, you eliminate one level of difficulty; indexing by >> bytes retains all the existing difficulty and adds another layer. > > Oh, sorry. I thought you were suggesting Unicode strings would make the > challenges somehow easy. So now that you've actually read my entire post, you'll see that there are fundamental difficulties, but that UTF-8 introduces more. Great. Now go ahead and reply to my post, knowing my actual point. Congratulations on posting something of no value. ChrisA From rosuav at gmail.com Mon Jul 16 17:11:53 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 07:11:53 +1000 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <5B4D07F3.1010404@stoneleaf.us> References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> <5B4D07F3.1010404@stoneleaf.us> Message-ID: On Tue, Jul 17, 2018 at 7:02 AM, Ethan Furman wrote: > On 07/16/2018 01:15 PM, Chris Angelico wrote: >> >> On Tue, Jul 17, 2018 at 4:55 AM, Steven D'Aprano wrote: > > >>> There is nothing special about diacritics such that we ought to treat >>> some combinations like "Ch" (two code points = one character) as "fixed >>> width" while others like "?" (two code points = one character) as >>> "variable width". >> >> >> When you reverse a word, do you treat "ch" and "sh" as one character >> or two? I'm of the opinion that they're single characters, and thus >> this should be "dalokosh": > > > Depends on the language: in Spanish, "ch" is it's own letter (at least it > was when I grew up), so any word containing it should still contain it when > reversed: "chica" would be "acich". > Yeah. In Russian, "sh" is the single character "?". I'm of the opinion that, even after being transliterated into English phonetics, that should be treated as a unit. ISO-9 uses "?" rather than "sh", which is an improvement in character correspondence, but your average English speaker is more likely to be able to pronounce "dalokosh" correctly than to figure out "daloko?". In the same way, I created a magic item in a D&D campaign called "Yasham Burda", even though the more correct spelling would be "Ya?am Burda" or even "Yasam Burda", for the benefit of my monolingual players. But I'd still treat the "sh" as one character. Ain't transliteration fun? ChrisA From rosuav at gmail.com Mon Jul 16 17:16:48 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 07:16:48 +1000 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: <20180716153244.50268123@bigbox.christie.dr> References: <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> <20180716153244.50268123@bigbox.christie.dr> Message-ID: On Tue, Jul 17, 2018 at 6:32 AM, Tim Chase wrote: > On 2018-07-16 18:31, Steven D'Aprano wrote: >> You say that all you want is a switch to turn off Unicode (and >> replace it with what? Kanji strings? Cyrillic? Shift_JS? no of >> course not, I'm being absurd -- replace it with ASCII, what else >> could any right-thinking person want, right?). > > But we already have this. If I want to turn off Unicode strings, I > type "python2", and if I want to enable Unicode strings, I type > "python3". > > While the python world has moved its efforts into improving Python3, > Python2 hasn't suddenly stopped working. It just stopped receiving > improvements. If the "old-man shakes-fist at progress" crowd > doesn't like unicode stings in Py3, just keep on using Py2. You > (generic) won't get arrested. There are no church^WPython police. Except that Python 2 still supports Unicode, and Python 3 still supports bytes. Py3 just makes a stronger distinction between text and bytes. >>> b"Hello, %s!" % b"world" b'Hello, world!' ChrisA From marko at pacujo.net Mon Jul 16 17:17:14 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 00:17:14 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> <5B4D07F3.1010404@stoneleaf.us> Message-ID: <87in5ezxr9.fsf@elektro.pacujo.net> Ethan Furman : > Depends on the language: in Spanish, "ch" is it's own letter (at least > it was when I grew up), so any word containing it should still contain > it when reversed: "chica" would be "acich". The Royal Academy broke "ch" and "ll" up into separate letters a decade or so back. It had become accepted practice in dictionaries way before that. In Finnish, "v" and "w" are still ortographic variants of the same letter. In practice, Finns don't have a problem with computers insisting they are separate letters. While the Royal Academy of the Spanish Language has now accepted that "?" is an accented "n", no Finn would think that "?" is an accented "a" any more than an English-speaker would think that "G" is an accented "C" (which it originally was). Marko From roel at roelschroeven.net Mon Jul 16 17:50:12 2018 From: roel at roelschroeven.net (Roel Schroeven) Date: Mon, 16 Jul 2018 23:50:12 +0200 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: Steven D'Aprano schreef op 16/07/2018 2:18: > On Sun, 15 Jul 2018 16:08:15 -0700, Jim Lee wrote: > >> Python3 is intrinsically tied to Unicode for string handling. Therefore, >> the Python programmer is forced to deal with it (in all but trivial >> cases), rather than given a choice. So I don't understand how I can >> illustrate my point with Python code since Python won't let me deal with >> strings without also dealing with Unicode. > > Nonsense. > > b"Look ma, a Python 2 style ASCII string." Except for one little difference, which has bitten be me a few times. Consider this code: from __future__ import print_function s = b"Look ma, a Python 2 style ASCII string." print('First element:', s[0]) Result in Python 2: First element: L Result in Python 3: First element: 76 Likewise this code: from __future__ import print_function for e in b'hello': print(e, end=', ') print() Result in Python 2: h, e, l, l, o, Result in Python 3: 104, 101, 108, 108, 111, There are times (encoding/decoding network protocols and other data formats) when I have a byte string and I want/need to process it like Python 2 does, and that is the one area where I feel Python 3 make things a bit more difficult. -- "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 Mon Jul 16 17:57:04 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 07:57:04 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On Tue, Jul 17, 2018 at 7:50 AM, Roel Schroeven wrote: > Steven D'Aprano schreef op 16/07/2018 2:18: >> >> On Sun, 15 Jul 2018 16:08:15 -0700, Jim Lee wrote: >> >>> Python3 is intrinsically tied to Unicode for string handling. Therefore, >>> the Python programmer is forced to deal with it (in all but trivial >>> cases), rather than given a choice. So I don't understand how I can >>> illustrate my point with Python code since Python won't let me deal with >>> strings without also dealing with Unicode. >> >> >> Nonsense. >> >> b"Look ma, a Python 2 style ASCII string." > > > Except for one little difference, which has bitten be me a few times. > Consider this code: > > from __future__ import print_function > s = b"Look ma, a Python 2 style ASCII string." > print('First element:', s[0]) > > Result in Python 2: First element: L > Result in Python 3: First element: 76 > > Likewise this code: > > from __future__ import print_function > for e in b'hello': > print(e, end=', ') > print() > > Result in Python 2: h, e, l, l, o, > Result in Python 3: 104, 101, 108, 108, 111, > > There are times (encoding/decoding network protocols and other data formats) > when I have a byte string and I want/need to process it like Python 2 does, > and that is the one area where I feel Python 3 make things a bit more > difficult. > For the most part, you probably want to decode it as ASCII, if you want to process it as text. Remember, bytes are simply numbers - octets, groups of eight bits. For it to mean the English word "hello", that byte sequence has to be interpreted as ASCII, which is accurately indicated as b'hello'.decode('ascii'). ChrisA From grant.b.edwards at gmail.com Mon Jul 16 18:01:00 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 16 Jul 2018 22:01:00 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On 2018-07-16, Roel Schroeven wrote: > There are times (encoding/decoding network protocols and other data > formats) when I have a byte string and I want/need to process it like > Python 2 does, and that is the one area where I feel Python 3 make > things a bit more difficult. I use Python to work with various network and serial protocols a lot, and using Python 3 certainly seems like more work. The fact that Python 2 and 3 both have a type called 'bytes' but the two types are completely incompatible makes it especially hard to write portable code that doesn't look like it's been intentionally obfuscated. -- Grant Edwards grant.b.edwards Yow! I represent a at sardine!! gmail.com From tjreedy at udel.edu Mon Jul 16 18:01:47 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 16 Jul 2018 18:01:47 -0400 Subject: Users banned In-Reply-To: References: <5B4B8391.3060808@stoneleaf.us> <877elw2ndr.fsf@elektro.pacujo.net> <5b7046a6-4c96-c8b0-9b5b-ec7999d4865d@gmail.com> <6ef56d48-eb59-ac77-2e5f-d0c6fdc7b1b9@gmail.com> Message-ID: On 7/16/2018 3:27 PM, Grant Edwards wrote: > On 2018-07-16, Steve Simmons wrote: > >> +1? Seems to me Bart is being banned for "being a dick" and "talking >> rubbish" (my words/interpretation) with irritating persistence. Wonder >> how many of the non-banned members have been guilty of the same thing in >> one way or another. > > I'm sure many of us have been guilty of one or both at some time or > another. I think the level of "persistence" is the key. What we have not and will not see on the list is the private interchange between Bart and the moderators before they took the next to most extreme step (of permaban). -- Terry Jan Reedy From roel at roelschroeven.net Mon Jul 16 18:06:38 2018 From: roel at roelschroeven.net (Roel Schroeven) Date: Tue, 17 Jul 2018 00:06:38 +0200 Subject: Reading EmailMessage from file In-Reply-To: References: Message-ID: Skip Montanaro schreef op 16/07/2018 3:31: > So, problem solved. The example I originally referred to clearly > requires the caller know the encoding of the input file. When you > don't know the encoding, you need bytes. The BytesParser gave me that. > > Also, I must admit to having not completely read the examples page, > where it described use of the BytesParser class a bit further down the > page, but I stopped when the simple example failed for me. I've been there too some time ago. I Was going to complain about it here (or rather ask for a better way to do it); in order to do that, I did a bit more research than I had apparently done the first time around, and discovered the right way to create an email message from raw bytes. -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From larry.martell at gmail.com Mon Jul 16 18:22:01 2018 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 16 Jul 2018 18:22:01 -0400 Subject: doubling the number of tests, but not taking twice as long In-Reply-To: References: Message-ID: On Mon, Jul 16, 2018 at 6:01 PM, Gilmeh Serda wrote: > On Mon, 16 Jul 2018 14:17:57 -0400, Larry Martell wrote: > >> This code needs to process many tens of 1000's of files, and it runs >> often, so it needs to run very fast. Needless to say, my change has made >> it take 2x as long. Can anyone see a way to improve that? > > Don't use RegEx search? > > My version 361, and a simple benchmarking thing, tells me it's about 2.7 > times slower than "if ... in ..." on 1,000,000 loops. Without the regex how would you suggest I search for '_M\d+_' efficiently? From roel at roelschroeven.net Mon Jul 16 18:41:01 2018 From: roel at roelschroeven.net (Roel Schroeven) Date: Tue, 17 Jul 2018 00:41:01 +0200 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: Chris Angelico schreef op 16/07/2018 23:57: > On Tue, Jul 17, 2018 at 7:50 AM, Roel Schroeven wrote: >> Steven D'Aprano schreef op 16/07/2018 2:18: >>> On Sun, 15 Jul 2018 16:08:15 -0700, Jim Lee wrote: >>> >>>> Python3 is intrinsically tied to Unicode for string handling. Therefore, >>>> the Python programmer is forced to deal with it (in all but trivial >>>> cases), rather than given a choice. So I don't understand how I can >>>> illustrate my point with Python code since Python won't let me deal with >>>> strings without also dealing with Unicode. >>> >>> Nonsense. >>> >>> b"Look ma, a Python 2 style ASCII string." >> >> Except for one little difference, which has bitten be me a few times. >> Consider this code: >> >> from __future__ import print_function >> s = b"Look ma, a Python 2 style ASCII string." >> print('First element:', s[0]) >> >> Result in Python 2: First element: L >> Result in Python 3: First element: 76 >> >> Likewise this code: >> >> from __future__ import print_function >> for e in b'hello': >> print(e, end=', ') >> print() >> >> Result in Python 2: h, e, l, l, o, >> Result in Python 3: 104, 101, 108, 108, 111, >> >> There are times (encoding/decoding network protocols and other data formats) >> when I have a byte string and I want/need to process it like Python 2 does, >> and that is the one area where I feel Python 3 make things a bit more >> difficult. >> > > For the most part, you probably want to decode it as ASCII, if you > want to process it as text. Remember, bytes are simply numbers - > octets, groups of eight bits. For it to mean the English word "hello", > that byte sequence has to be interpreted as ASCII, which is accurately > indicated as b'hello'.decode('ascii'). I think I've had cases where that approach didn't work very well, but unfortunately I can't readily think of any concrete examples. In any case, even though Python 3's byte strings are not quite unlike Python 2's strings, they're not exactly like them either. And I feel there are cases where that makes things somewhat harder, even though I can't prove it. -- "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 Mon Jul 16 18:48:55 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 08:48:55 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On Tue, Jul 17, 2018 at 8:41 AM, Roel Schroeven wrote: > In any case, even though Python 3's byte strings are not quite unlike Python > 2's strings, they're not exactly like them either. And I feel there are > cases where that makes things somewhat harder, even though I can't prove it. You're absolutely right, and some of those differences were repaired in different 3.x versions (for instance, the ability to use percent-formatting with byte strings was reinstated in 3.5). Some of the differences are fundamental, but anything else should be considered fair game for an enhancement request. So next time you go "ugh, Python 3's byte strings are such a pain because XYZ", post here or on python-ideas about a possible fix. That said, though, the fact that indexing a byte string yields an int instead of a one-byte string is basically unable to be changed now, and IMO it'd be better to be consistent with text strings than with bytearray. I'm not sure how many of the core devs agree that b'spam'[1] ought to be b'p' rather than 112, but I'd say they all agree that it's too late to change it. ChrisA From Richard at Damon-family.org Mon Jul 16 19:02:36 2018 From: Richard at Damon-family.org (Richard Damon) Date: Mon, 16 Jul 2018 19:02:36 -0400 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> Message-ID: <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> > On Jul 16, 2018, at 3:28 PM, Terry Reedy wrote: > >> On 7/16/2018 1:11 PM, Richard Damon wrote: >> >> Many consider that UTF-32 is a variable-width encoding because of the combining characters. It can take multiple ?codepoints? to define what should be a single ?character? for display. > > I hope you realize that this is not the standard meaning of 'variable-width encoding', which is 'variable number of bytes for a codepoint'. UTF-16 and UTF-8 are variable width. If one expands the definition enough, Ascii is 'variable width' because 'fi' is two bytes, or more realistically, because <= and >= are two bytes instead of one (as they can be in Unicode!). > > If one is using a broader definition than usual, it is clearer to say so. > > -- > Terry Jan Reedy > You are defining a variable/fixed width codepoint set. Many others want to deal with CHARACTER sets. The Unicode consortium agrees that a code point is not necessarily a character (which is one reason they came up with the term). When actually trying to do work with text strings, the fact that some codepoints are combining codes that need to ?stick? to their mate becomes important. One of the claimed advantages of fixed width character set encodings is that you aren?t supposed to need to worry about breaking strings in two, but that doesn?t work in Unicode, you need to make sure you aren?t breaking a combining sequence. Even worse, Unicode really needs arbitrary look back to render substrings because it uses shift codes for things like left-to-right/right-to-left rendering control. This doesn?t mean that UTF-32 is an awful system, just that it isn?t the magical cure that some were hoping for. From python at mrabarnett.plus.com Mon Jul 16 19:03:22 2018 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 17 Jul 2018 00:03:22 +0100 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: <87tvoyzyk0.fsf@elektro.pacujo.net> References: <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> <20180716153244.50268123@bigbox.christie.dr> <87tvoyzyk0.fsf@elektro.pacujo.net> Message-ID: On 2018-07-16 21:59, Marko Rauhamaa wrote: > Tim Chase : >> While the python world has moved its efforts into improving Python3, >> Python2 hasn't suddenly stopped working. > > The sword of Damocles is hanging on its head. Unless a consortium is > erected to support Python2, no vendor will be able to use it in the > medium term. > > Given the recent events, maybe that's exactly what's going to happen. A > business consortium will take it on themselves to support and enhance > Python2 ad infinitum. I wouldn't be surprised. > > (Although it might make me regret my knee-jerk porting effort.) > In open source, it's up to those with the itch to scratch it. Someone finally did, and it's called Tauthon. From dan at tombstonezero.net Mon Jul 16 19:18:17 2018 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 16 Jul 2018 23:18:17 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On Tue, 17 Jul 2018 08:48:55 +1000, Chris Angelico wrote: > That said, though, the fact that indexing a byte string yields an int > instead of a one-byte string is basically unable to be changed now ... Agreed. > ... and IMO it'd be better to be consistent with text strings than > with bytearray ... Disagreed. Given an arbitrary byte string, you can't know whether it's semantically text or semantically an array of bytes. (Sometimes a good byte array is just a byte array?) In the past, I've done plenty of work with "strings" (in the generic sense) of octets to/from wire-level protocols. It would have been much easier had Python *not* tried to pretend they were text, and *not* rendered some of the bytes as their ASCII equivalent and some of the bytes as hex escapes (especially in the cases that some of the bytes happened to be 0x58, 0x78, 0x5c, or in range(0x30, 0x3a)). > ... I'm not sure how many of the core devs agree that b'spam'[1] ought > to be b'p' rather than 112, but I'd say they all agree that it's too > late to change it. Curmudgeonly C programmer that I am, b'p' *is* 112. ;-) Quick: how long is the byte array that displays as '\xff'? Too easy? What about '\0xff' and '0\xff'? FWIW, Erlang, a language all but designed to read/write wire level protocols, prints any array of integers less than 256 as a(n ASCII) text string. It never *mixes* integers and characters, but often picks the wrong one. From rosuav at gmail.com Mon Jul 16 19:57:56 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 09:57:56 +1000 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On Tue, Jul 17, 2018 at 9:18 AM, Dan Sommers wrote: > Quick: how long is the byte array that displays as '\xff'? Too easy? > What about '\0xff' and '0\xff'? 1, 4, 2 bytes respectively. Yep, easy... but then, I'm used to reading backslash escapes. Nothing to do with text vs bytes. DNS, of course, is different. ChrisA From breamoreboy at gmail.com Mon Jul 16 20:17:43 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Tue, 17 Jul 2018 01:17:43 +0100 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: <8f3400e9-291e-3bcb-2ee9-6e4c8f254a7a@kynesim.co.uk> References: <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> <8f3400e9-291e-3bcb-2ee9-6e4c8f254a7a@kynesim.co.uk> Message-ID: On 16/07/18 21:16, Rhodri James wrote: > On 16/07/18 20:58, Terry Reedy wrote: >> On 7/16/2018 1:27 PM, Jim Lee wrote: >> >>> 90% of the world *is* "beneath my notice" when it comes to >>> programming for myself.?? I really don't care if that's not PC enough >>> for you. >>> >>> Had you actually read my words with *intent* rather than *reaction*, >>> you would notice that I suggested the *option* of turning off >>> Unicode.? I didn't say get *rid* of Unicode.? I didn't say make it >>> *harder* to use Unicode.? Once again - reaction rather than reading. >>> >>> Obviously, the most vocal representatives of the Python community are >>> too sensitive about their language to enable rational discussion. >> >> My empirical observation is that the more abrasive posters get >> rewarded with more response, while my attempts to engage in rational >> discussion, without ad hominems, gets less. > > I wouldn't disagree with you.? Fortunately Jim has pulled the "storming > off in a huff rather than answer a question anyone actually asked" > defence, so we can go back to debating about important things like how > to spell assignment expressions. > > Oh wait... :-) > Cheeky :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Mon Jul 16 20:24:03 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 00:24:03 +0000 (UTC) Subject: Users banned References: <5B4B8391.3060808@stoneleaf.us> <877elw2ndr.fsf@elektro.pacujo.net> <5b7046a6-4c96-c8b0-9b5b-ec7999d4865d@gmail.com> <6ef56d48-eb59-ac77-2e5f-d0c6fdc7b1b9@gmail.com> Message-ID: On Mon, 16 Jul 2018 20:03:39 +0100, Steve Simmons wrote: > +1? Seems to me Bart is being banned for "being a dick" and "talking > rubbish" (my words/interpretation) with irritating persistence. I know that when I first started here, I often talked rubbish. The difference is, I was willing to listen and consider when people gave alternate viewpoints. Eventually. And I know that some people think that I'm sometimes still being a dick. They're wrong, I'm just charmingly forthright *wink* Bart is often frustratingly resistant to reasonable argument, and has been obnoxious in his habit of bringing virtually every conversation into an opportunity to make a dig at Python. But neither of these are prohibited by the CoC, neither of these should be banning offense, and even if they were, he should have had a formal warning first. Preferably TWO formal warnings: the first privately, the second publicly, and only on the third offence a ban. And I question the fairness of a six month ban, rather than (let's say) an initial one month ban. As for banning Rick, when he isn't even posting at the moment, I don't even have words for that. There's no statute of limitation for murder, but surely "being obnoxious on the internet" ought to come with a fairly short period of forgiveness. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jul 16 20:25:33 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 00:25:33 +0000 (UTC) Subject: Python 4000 was Re: [SUSPICIOUS MESSAGE] Re: Cult-like behaviour] References: <87sh4jw95v.fsf@elektro.pacujo.net> <201807161054.04480.gheskett@shentel.net> <3gfpkdp7fojv7go5gf938noc6qampce9ur@4ax.com> Message-ID: On Mon, 16 Jul 2018 15:09:16 -0400, Terry Reedy wrote: > On 7/16/2018 11:50 AM, Dennis Lee Bieber wrote: > >> For Python 4000 maybe > > Please don't give people the idea that there is any current intention to > have a 'Python 4000' similar to 'Python 3000'. Call it 'a mythical > Python 4000', if you must use such a term. I prefer to say Python 5000, to make it even more clear that should such a thing happen again, it will be a *REALLY* long time from now. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From python.list at tim.thechases.com Mon Jul 16 20:48:26 2018 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Jul 2018 19:48:26 -0500 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: <87tvoyzyk0.fsf@elektro.pacujo.net> References: <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> <20180716153244.50268123@bigbox.christie.dr> <87tvoyzyk0.fsf@elektro.pacujo.net> Message-ID: <20180716194826.7cf9b53b@bigbox.christie.dr> On 2018-07-16 23:59, Marko Rauhamaa wrote: > Tim Chase : > > While the python world has moved its efforts into improving > > Python3, Python2 hasn't suddenly stopped working. > > The sword of Damocles is hanging on its head. Unless a consortium is > erected to support Python2, no vendor will be able to use it in the > medium term. Wait, but now you're talking about vendors. Much of the crux of this discussion has been about personal scripts that don't need to marshal Unicode strings in and out of various functions/objects. If you have a py2 script that works with py2 and breaks with py3, and you don't want to update to py3 unicode-strings-by-default, then stick with py2. They even coexist nicely on the same machine. It doesn't have a self-destruct clause. As long as py2 continues to build, it will continue to run which is a long lifetime. To point, I still have the "joy" of maintaining some py2.4 code that's in production. Would I rather upgrade it to 3.x? You bet. But the powers in place are willing to forego python updates in order to not rock the boat. -tkc From steve+comp.lang.python at pearwood.info Mon Jul 16 20:58:09 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 00:58:09 +0000 (UTC) Subject: Unicode is not UTF-32 [was Re: Cult-like behaviour] References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <87fu0j0y1u.fsf@elektro.pacujo.net> Message-ID: On Mon, 16 Jul 2018 22:40:13 +0300, Marko Rauhamaa wrote: > Terry Reedy : > >> On 7/15/2018 5:28 PM, Marko Rauhamaa wrote: >>> if your new system used Python3's UTF-32 strings as a foundation, >> >> Since 3.3, Python's strings are not (always) UFT-32 strings. > > You are right. Python's strings are a superset of UTF-32. More > accurately, Python's strings are UTF-32 plus surrogate characters. The first thing you are doing wrong is conflating the semantics of the data type with one possible implementation of that data type. UTF-32 is implementation, not semantics: it specifies how to represent Unicode code points as bytes in memory, not what Unicode code points are. Python 3 strings are sequences of abstract characters ("code points") with no mandatory implementation. In CPython, some string objects are encoded in Latin-1. Some are encoded in UTF-16. Some are encoded in UTF-32. Some implementations (MicroPython) use UTF-8. Your second error is a more minor point: it isn't clear (at least not to me) that "Unicode plus surrogates" is a superset of Unicode. Surrogates are part of Unicode. The only extension here is that Python strings are not necessarily well-formed surrogate-free Unicode strings, but they're still Unicode strings. >> Nor are they always UCS-2 (or partly UTF-16) strings. Nor are the >> always Latin-1 or Ascii strings. Python's Flexible String >> Representation uses the narrowest possible internal code for any >> particular string. This is all transparent to the user except for >> memory size. > > How CPython chooses to represent its strings internally is not what I'm > talking about. Then why do you repeatedly talk about the internal storage representation? UTF-32 is not a character set, it is an encoding. It specifies how to implement a sequence of Unicode abstract characters. >>> UTF-32, after all, is a variable-width encoding. >> >> Nope. It a fixed-width (32 bits, 4 bytes) encoding. >> >> Perhaps you should ask more questions before pontificating. > > You mean each code point is one code point wide. But that's rather an > irrelevant thing to state. No, he means that each code point is one code unit wide. > The main point is that UTF-32 (aka Unicode) UTF-32 is not a synonym for Unicode. Many legacy encodings don't distinguish between the character set and the mapping between bytes and characters, but Unicode is not one of those. > uses one or more code points to represent what people would consider an > individual character. That's a reasonable observation to make. But that's not what fixed- and variable-width refers to. So does ASCII, and in both cases, it is irrelevant since the term of art is to define fixed- and variable-width in terms of *code points* not human meaningful characters. "Character" is context- and language- dependent and frequently ambiguous. "LL" or "CH" (for example) could be a single character or a double character, depending on context and language. Even in ASCII English, something as large as "ough" might be considered to be a single unit of language, which some people might choose to call a character. (But not a single letter, naturally.) If you don't like that example, "qu" is probably a better one: aside from acronyms and loan words, no modern English word can fail to follow a Q with a U. > Code points are about as interesting as individual bytes in UTF-8. That's your opinion. I see no justification for it. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jul 16 21:08:02 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 01:08:02 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> Message-ID: On Tue, 17 Jul 2018 06:15:25 +1000, Chris Angelico wrote: > On Tue, Jul 17, 2018 at 4:55 AM, Steven D'Aprano > wrote: >> There is nothing special about diacritics such that we ought to treat >> some combinations like "Ch" (two code points = one character) as "fixed >> width" while others like "?" (two code points = one character) as >> "variable width". > > When you reverse a word, do you treat "ch" and "sh" as one character or > two? In English, "ch" is always two letters of the alphabet. In Welsh and Czech, they can be one or two letters. (I think they will be two letters only in loan words, but I'm not certain about that.) Whether that makes them one or two characters depends on how you define "character". Good luck with finding a universal, objective, unambiguous definition. > I'm of the opinion that they're single characters, and thus this > should be "dalokosh": > > https://wiki.teamfortress.com/wiki/Dalokohs_Bar > > (It's the Russian for "chocolate" - "???????" - transliterated to > English/Latin - "?okolad" or "shokolad" - and then reversed.) In English, I think most people would prefer to use a different term for whatever "sh" and "ch" represent than "character". But you make a good point that even in English, we sometimes want to treat two letter combinations as a single unit. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jul 16 21:17:06 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 01:17:06 +0000 (UTC) Subject: Cult-like behaviour [was Re: Kindness] References: <87601i5jsv.fsf@elektro.pacujo.net> <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: On Mon, 16 Jul 2018 23:50:12 +0200, Roel Schroeven wrote: > There are times (encoding/decoding network protocols and other data > formats) when I have a byte string and I want/need to process it like > Python 2 does, and that is the one area where I feel Python 3 make > things a bit more difficult. Ah yes, the unfortunate design error that iterating over byte-strings returns ints rather than single-byte strings. That decision seemed to make sense at the time it was made, but turned out to be an annoyance. It's a wart on Python 3, but fortunately one which is fairly easily dealt with by a helper function. That *is* a nice example of where byte strings in Python 3 aren't as nice as in Python 2. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From python at mrabarnett.plus.com Mon Jul 16 21:18:04 2018 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 17 Jul 2018 02:18:04 +0100 Subject: Python 4000 was Re: [SUSPICIOUS MESSAGE] Re: Cult-like behaviour] In-Reply-To: References: <87sh4jw95v.fsf@elektro.pacujo.net> <201807161054.04480.gheskett@shentel.net> <3gfpkdp7fojv7go5gf938noc6qampce9ur@4ax.com> Message-ID: <4d7affa4-db6d-3021-a845-12b5b09eb71c@mrabarnett.plus.com> On 2018-07-17 01:25, Steven D'Aprano wrote: > On Mon, 16 Jul 2018 15:09:16 -0400, Terry Reedy wrote: > >> On 7/16/2018 11:50 AM, Dennis Lee Bieber wrote: >> >>> For Python 4000 maybe >> >> Please don't give people the idea that there is any current intention to >> have a 'Python 4000' similar to 'Python 3000'. Call it 'a mythical >> Python 4000', if you must use such a term. > > I prefer to say Python 5000, to make it even more clear that should such > a thing happen again, it will be a *REALLY* long time from now. > I think that Python 5000 would be more to do with an internal change, such as going GIL-less, than a change in, say, syntax. From steve+comp.lang.python at pearwood.info Mon Jul 16 21:21:15 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 01:21:15 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> Message-ID: On Mon, 16 Jul 2018 19:02:36 -0400, Richard Damon wrote: > You are defining a variable/fixed width codepoint set. Many others want > to deal with CHARACTER sets. Good luck coming up with a universal, objective, language-neutral, consistent definition for a character. > This doesn?t mean that UTF-32 is an awful system, just that it isn?t the > magical cure that some were hoping for. Nobody ever claimed it was, except for the people railing that since it isn't a magically system we ought to go back to the Good Old Days of code page hell, or even further back when everyone just used ASCII. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jul 16 21:26:55 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 01:26:55 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> Message-ID: On Mon, 16 Jul 2018 22:51:32 +0300, Marko Rauhamaa wrote: > All UTF-8. No unicode strings. That just means you are re-implementing the bits of Unicode you care about (which may be "nothing at all") as UTF-8. If your application is nothing but middleware squirting bytes from one layer to another layer, that might be all you need care about. But then you're not processing text in your application, and why should your experience in not-processing-text be given any weight over the experiences of those who do process text? And later, in another post: > UTF-8 bytes can only represent the first 128 code points of Unicode. This is DailyWTF material. Perhaps you want to rethink your wording and maybe even learn a bit more about Unicode and the UTF encodings before making such statements. The idea that UTF-8 bytes cannot represent the whole of Unicode is not even wrong. Of course a *single* byte cannot, but a single byte is not "UTF-8 bytes". -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jul 16 21:27:18 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 01:27:18 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87va9h4pyt.fsf@elektro.pacujo.net> <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> Message-ID: On Mon, 16 Jul 2018 15:28:51 -0400, Terry Reedy wrote: > On 7/16/2018 1:11 PM, Richard Damon wrote: > >> Many consider that UTF-32 is a variable-width encoding because of the >> combining characters. It can take multiple ?codepoints? to define what >> should be a single ?character? for display. > > I hope you realize that this is not the standard meaning of > 'variable-width encoding', which is 'variable number of bytes for a > codepoint'. A minor correction Terry: it is the number of code units, not bytes. UTF-8 uses 1-byte code units, and from 1 to 4 code units per code point; UTF-16 uses 2-byte code units (a 16-bit word), and 1 or 2 words per code point; UTF-32 uses 4-byte code units (a 32-bit word), and only ever a single code unit for every code point. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From Richard at Damon-family.org Mon Jul 16 21:48:42 2018 From: Richard at Damon-family.org (Richard Damon) Date: Mon, 16 Jul 2018 21:48:42 -0400 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> Message-ID: <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> > On Jul 16, 2018, at 9:21 PM, Steven D'Aprano wrote: > >> On Mon, 16 Jul 2018 19:02:36 -0400, Richard Damon wrote: >> >> You are defining a variable/fixed width codepoint set. Many others want >> to deal with CHARACTER sets. > > Good luck coming up with a universal, objective, language-neutral, > consistent definition for a character. > Who says there needs to be one. A good engineer will use the definition that is most appropriate to the task at hand. Some things need very solid definitions, and some things don?t. This goes back to my original point, where I said some people consider UTF-32 as a variable width encoding. For very many things, practically, the ?codepoint? isn?t the important thing, so the fact that every UTF-32 code point takes the same number of bytes or code words isn?t that important. They are dealing with something that needs to be rendered and preserving larger units, like the grapheme is important. > >> This doesn?t mean that UTF-32 is an awful system, just that it isn?t the >> magical cure that some were hoping for. > > Nobody ever claimed it was, except for the people railing that since it > isn't a magically system we ought to go back to the Good Old Days of code > page hell, or even further back when everyone just used ASCII. > Sometimes ASCII is good enough, especially on a small machine with limited resources. Sometimes you do need to use a ?Code Page? because of limited resources and that unit will only be able to talk a single language because of that too). Sometimes you have the luxury of being able to use a somewhat complete Unicode implementation. Sometimes you are never going to be displaying anything, and you can mostly just treat everything as a bag of bytes. You use the tool that is right for the job. > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson > > -- > https://mail.python.org/mailman/listinfo/python-list From python at bladeshadow.org Mon Jul 16 21:52:51 2018 From: python at bladeshadow.org (Python) Date: Mon, 16 Jul 2018 20:52:51 -0500 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <8fd795ac-2264-a835-aab3-ff5ef82ee852@kynesim.co.uk> References: <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <87fu0j0y1u.fsf@elektro.pacujo.net> <8fd795ac-2264-a835-aab3-ff5ef82ee852@kynesim.co.uk> Message-ID: <20180717015251.GB16968@bladeshadow.org> On Mon, Jul 16, 2018 at 08:56:11PM +0100, Rhodri James wrote: > The problem everyone is having with you, Marko, is that you are > using the terminology incorrectly. [...] When you call UTF-32 a > variable-width encoding, you are incorrect. But please don't overlook that the "terminology" is in fact rather specialized jargon, far less common than even most computer jargon. Unless you're uncommonly familiar with the subject matter, you simply don't have this vocabulary. Under the circumstances it seems not horribly unreasonable to expect such a person to consider the bytes required to represent a glyph as an encoding's width, and you as "experts" rightly should expect, let's call them lay people, to make this mistake and adjust for it, or politely correct it, without the condescension. > You are of course welcome to use whatever terminology you personally > like, like Humpty Dumpty. However when you point to a duck and say > "That's a gnu," people are likely to stop taking you seriously. Shouldn't experts "be generous in what they accept, but conservative in what they emit?" If your goal here is to educate, and come to a common understanding, rather than to simply prove how superior (the generic) you are, then perhaps both you and the community would be better served if you strived to understand Marko's points, rather than just point out how horribly wrong he is? The tone here is often extremely adversarial, which I think mostly serves to incite others to respond adversarialy. I certainly know I've fallen into that trap more than once, myself. I work primarily in Unix environments, and I daresay the way Unix treats text as bytes--barring certain very specialized applications, which require knowledge of what bytes correspond to what units of linguistic representations, like reversing strings (which FWIW I've never found a use for, other than academic ones)--works just fine. You can--and I do (or have, at least)--write non-ASCII unicode strings as bytes in your Python-2.7 code, or read them from a file, or whatever other input your program desires, and send them to whatever terminal or GUI program you want to, and they will appear as they should to the user, provided the system is configured appropriately (which these days mostly means configured to use UTF-8, and which these days is generally the case). It's reasonable to assume users either know what encoding their systems are using, or don't have a clue but won't change it, so it will always be "right." And if the system is configured correctly, and you sensibly used UTF-8 encoded byte strings in your program, but the system is configured in some other encoding, it's a fairly trivial matter to use iconv to convert to the system's encoding (which I have also done, but perhaps not in Python--I can't recall), assuming the data can be converted (and if not you're kinda screwed anyway). In the overwhelming majority of cases, this gets you everything you need, and the language internally understanding Unicode (especially if that understanding requires more work from the programmer to deal with it) mostly gets you very little. Yes, of course there are specific applications for which that intelligence is neccessary, and in those cases it should be made use of. The rest of the time--the overwhelming majority of the time--it's just superfluous complexity. So, sure, in uncommon cases knowing about Unicode may reduce (but not eliminate) complications dealing with different languages, but in the common cases it may only serve to make more work for the programmer. I don't know about you, but I prefer to do less, if less is required. If these features exist because Windows needs them in order to reliably get the common cases right, then maybe, just maybe, Unix really did get it right after all. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available URL: From python.list at tim.thechases.com Mon Jul 16 22:25:20 2018 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Jul 2018 21:25:20 -0500 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> Message-ID: <20180716212520.7d560841@bigbox.christie.dr> On 2018-07-17 01:08, Steven D'Aprano wrote: > In English, I think most people would prefer to use a different > term for whatever "sh" and "ch" represent than "character". The term you may be reaching for is "consonant cluster"? https://en.wikipedia.org/wiki/Consonant_cluster -tkc From python.list at tim.thechases.com Mon Jul 16 22:36:41 2018 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 16 Jul 2018 21:36:41 -0500 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> Message-ID: <20180716213641.2af91097@bigbox.christie.dr> On 2018-07-17 01:21, Steven D'Aprano wrote: > > This doesn?t mean that UTF-32 is an awful system, just that it > > isn?t the magical cure that some were hoping for. > > Nobody ever claimed it was, except for the people railing that > since it isn't a magically system we ought to go back to the Good > Old Days of code page hell, or even further back when everyone just > used ASCII. But even ed(1) on most systems is 8-bit clean so even there you're not limited to ASCII. I can't say I miss code-pages in the least. -tkc From sleadpc at gmail.com Mon Jul 16 23:03:30 2018 From: sleadpc at gmail.com (S Lea) Date: Mon, 16 Jul 2018 20:03:30 -0700 Subject: can't install/run pip (Latest version of Python) In-Reply-To: References: Message-ID: Thank you for reaching out. 1) Don't know what do you mean by the traceback. 2) In DOS, pip install pandas 3) Yes, in DOS, Win 10 4) 3.7 5) Not getting much info On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp wrote: > On Sun, Jul 15, 2018 at 7:34 PM S Lea wrote: > > > > I can't seem to install the pips, DOS gives me the syntex i invalid, any > > thoughts?? > > You provide insufficient information for anyone to be able to help you. > > 1) Copy and paste the entire traceback into a plain text email, no > screen shots please. > 2) Copy and paste exactly what you typed that generated the syntax error. > 3) Did you do all of this in cmd.exe in what version of Windows? Or > did you use something else? Hopefully not in the interactive Python > interpreter or IDLE! > 4) What Python version are you using? > 5) Did you try searching for the exact error message and see what > answers might already be out there? > > If you provide these things, or, better, search and find the answer > yourself, I'm sure someone will be happy to assist. > > Good luck! > -- > boB > -- > https://mail.python.org/mailman/listinfo/python-list > From sleadpc at gmail.com Mon Jul 16 23:06:19 2018 From: sleadpc at gmail.com (S Lea) Date: Mon, 16 Jul 2018 20:06:19 -0700 Subject: can't install/run pip (Latest version of Python) In-Reply-To: References: Message-ID: 'pip' not recognized as internal or external command, operable program or batch. And for some reason it's a 32 bit version On Mon, Jul 16, 2018 at 8:03 PM, S Lea wrote: > Thank you for reaching out. > > 1) Don't know what do you mean by the traceback. > 2) In DOS, pip install pandas > 3) Yes, in DOS, Win 10 > 4) 3.7 > 5) Not getting much info > > On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp wrote: > >> On Sun, Jul 15, 2018 at 7:34 PM S Lea wrote: >> > >> > I can't seem to install the pips, DOS gives me the syntex i invalid, >> any >> > thoughts?? >> >> You provide insufficient information for anyone to be able to help you. >> >> 1) Copy and paste the entire traceback into a plain text email, no >> screen shots please. >> 2) Copy and paste exactly what you typed that generated the syntax error. >> 3) Did you do all of this in cmd.exe in what version of Windows? Or >> did you use something else? Hopefully not in the interactive Python >> interpreter or IDLE! >> 4) What Python version are you using? >> 5) Did you try searching for the exact error message and see what >> answers might already be out there? >> >> If you provide these things, or, better, search and find the answer >> yourself, I'm sure someone will be happy to assist. >> >> Good luck! >> -- >> boB >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > From sleadpc at gmail.com Mon Jul 16 23:06:40 2018 From: sleadpc at gmail.com (S Lea) Date: Mon, 16 Jul 2018 20:06:40 -0700 Subject: can't install/run pip (Latest version of Python) In-Reply-To: References: Message-ID: of python 3.7 On Mon, Jul 16, 2018 at 8:06 PM, S Lea wrote: > 'pip' not recognized as internal or external command, operable program or > batch. > > And for some reason it's a 32 bit version > > On Mon, Jul 16, 2018 at 8:03 PM, S Lea wrote: > >> Thank you for reaching out. >> >> 1) Don't know what do you mean by the traceback. >> 2) In DOS, pip install pandas >> 3) Yes, in DOS, Win 10 >> 4) 3.7 >> 5) Not getting much info >> >> On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp >> wrote: >> >>> On Sun, Jul 15, 2018 at 7:34 PM S Lea wrote: >>> > >>> > I can't seem to install the pips, DOS gives me the syntex i invalid, >>> any >>> > thoughts?? >>> >>> You provide insufficient information for anyone to be able to help you. >>> >>> 1) Copy and paste the entire traceback into a plain text email, no >>> screen shots please. >>> 2) Copy and paste exactly what you typed that generated the syntax error. >>> 3) Did you do all of this in cmd.exe in what version of Windows? Or >>> did you use something else? Hopefully not in the interactive Python >>> interpreter or IDLE! >>> 4) What Python version are you using? >>> 5) Did you try searching for the exact error message and see what >>> answers might already be out there? >>> >>> If you provide these things, or, better, search and find the answer >>> yourself, I'm sure someone will be happy to assist. >>> >>> Good luck! >>> -- >>> boB >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> >> > From sleadpc at gmail.com Mon Jul 16 23:11:10 2018 From: sleadpc at gmail.com (S Lea) Date: Mon, 16 Jul 2018 20:11:10 -0700 Subject: can't install/run pip (Latest version of Python) In-Reply-To: References: Message-ID: Also, I can't find the location of Python insallation, it refers to C:\Users\Precision\PycharmProjects\my first project from video\venv\Scripts On Mon, Jul 16, 2018 at 8:06 PM, S Lea wrote: > of python 3.7 > > On Mon, Jul 16, 2018 at 8:06 PM, S Lea wrote: > >> 'pip' not recognized as internal or external command, operable program or >> batch. >> >> And for some reason it's a 32 bit version >> >> On Mon, Jul 16, 2018 at 8:03 PM, S Lea wrote: >> >>> Thank you for reaching out. >>> >>> 1) Don't know what do you mean by the traceback. >>> 2) In DOS, pip install pandas >>> 3) Yes, in DOS, Win 10 >>> 4) 3.7 >>> 5) Not getting much info >>> >>> On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp >>> wrote: >>> >>>> On Sun, Jul 15, 2018 at 7:34 PM S Lea wrote: >>>> > >>>> > I can't seem to install the pips, DOS gives me the syntex i invalid, >>>> any >>>> > thoughts?? >>>> >>>> You provide insufficient information for anyone to be able to help you. >>>> >>>> 1) Copy and paste the entire traceback into a plain text email, no >>>> screen shots please. >>>> 2) Copy and paste exactly what you typed that generated the syntax >>>> error. >>>> 3) Did you do all of this in cmd.exe in what version of Windows? Or >>>> did you use something else? Hopefully not in the interactive Python >>>> interpreter or IDLE! >>>> 4) What Python version are you using? >>>> 5) Did you try searching for the exact error message and see what >>>> answers might already be out there? >>>> >>>> If you provide these things, or, better, search and find the answer >>>> yourself, I'm sure someone will be happy to assist. >>>> >>>> Good luck! >>>> -- >>>> boB >>>> -- >>>> https://mail.python.org/mailman/listinfo/python-list >>>> >>> >>> >> > From gheskett at shentel.net Mon Jul 16 23:47:11 2018 From: gheskett at shentel.net (Gene Heskett) Date: Mon, 16 Jul 2018 23:47:11 -0400 Subject: can't install/run pip (Latest version of Python) In-Reply-To: References: Message-ID: <201807162347.11233.gheskett@shentel.net> On Monday 16 July 2018 23:06:19 S Lea wrote: > 'pip' not recognized as internal or external command, operable program > or batch. > > And for some reason it's a 32 bit version > Huh? My ancient wet ram memory is probably out to lunch, but ISTR reading about someone else with the same problem at least a year ago on this list, unfortunately I have a 90 day expiry setup on this list so searching is just an exercise. My email corpus is nearly 20 gigabytes now. pip has been around since it seems forever, but I would have thought by now it would have been rebuilt for 64 bit systems. And that leads to a question, where did you get it?, and how long ago? Maybe its an old version? Head scratcher for sure. > On Mon, Jul 16, 2018 at 8:03 PM, S Lea wrote: > > Thank you for reaching out. > > > > 1) Don't know what do you mean by the traceback. What you see in the terminal screen you ran it in. It should a press the left mouse button and wipe the mouse from beginning to end so its all highlighted, then position the curser in an email and press the middle mouse button, which should copy the highlighted text into the email. > > 2) In DOS, pip install pandas > > 3) Yes, in DOS, Win 10 > > 4) 3.7 > > 5) Not getting much info > > > > On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp wrote: > >> On Sun, Jul 15, 2018 at 7:34 PM S Lea wrote: > >> > I can't seem to install the pips, DOS gives me the syntex i > >> > invalid, > >> > >> any > >> > >> > thoughts?? > >> > >> You provide insufficient information for anyone to be able to help > >> you. > >> > >> 1) Copy and paste the entire traceback into a plain text email, no > >> screen shots please. > >> 2) Copy and paste exactly what you typed that generated the syntax > >> error. 3) Did you do all of this in cmd.exe in what version of > >> Windows? Or did you use something else? Hopefully not in the > >> interactive Python interpreter or IDLE! > >> 4) What Python version are you using? > >> 5) Did you try searching for the exact error message and see what > >> answers might already be out there? > >> > >> If you provide these things, or, better, search and find the answer > >> yourself, I'm sure someone will be happy to assist. > >> > >> Good luck! > >> -- > >> boB > >> -- > >> https://mail.python.org/mailman/listinfo/python-list -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From marko at pacujo.net Tue Jul 17 01:26:45 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 08:26:45 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> Message-ID: <871sc2zb3e.fsf@elektro.pacujo.net> Steven D'Aprano : > On Mon, 16 Jul 2018 22:51:32 +0300, Marko Rauhamaa wrote: >> UTF-8 bytes can only represent the first 128 code points of Unicode. > > This is DailyWTF material. Perhaps you want to rethink your wording > and maybe even learn a bit more about Unicode and the UTF encodings > before making such statements. > > The idea that UTF-8 bytes cannot represent the whole of Unicode is not > even wrong. Of course a *single* byte cannot, but a single byte is not > "UTF-8 bytes". So I hope that by now you have understood my point and been able to decide if you agree with it or not. Marko From marko at pacujo.net Tue Jul 17 01:37:34 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 08:37:34 +0300 Subject: Unicode [was Re: Cult-like behaviour] References: <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> <20180716153244.50268123@bigbox.christie.dr> <87tvoyzyk0.fsf@elektro.pacujo.net> <20180716194826.7cf9b53b@bigbox.christie.dr> Message-ID: <87wotuxw0x.fsf@elektro.pacujo.net> Tim Chase : > On 2018-07-16 23:59, Marko Rauhamaa wrote: >> Tim Chase : >> > While the python world has moved its efforts into improving >> > Python3, Python2 hasn't suddenly stopped working. >> >> The sword of Damocles is hanging on its head. Unless a consortium is >> erected to support Python2, no vendor will be able to use it in the >> medium term. > > Wait, but now you're talking about vendors. Much of the crux of this > discussion has been about personal scripts that don't need to > marshal Unicode strings in and out of various functions/objects. In both personal and professional settings, you face the same issues. But you don't want to build on something that will disappear from the Linux distros. Marko From songofacandy at gmail.com Tue Jul 17 02:20:16 2018 From: songofacandy at gmail.com (INADA Naoki) Date: Tue, 17 Jul 2018 15:20:16 +0900 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <871sc2zb3e.fsf@elektro.pacujo.net> References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> Message-ID: On Tue, Jul 17, 2018 at 2:31 PM Marko Rauhamaa wrote: > > Steven D'Aprano : > > On Mon, 16 Jul 2018 22:51:32 +0300, Marko Rauhamaa wrote: > >> UTF-8 bytes can only represent the first 128 code points of Unicode. > > > > This is DailyWTF material. Perhaps you want to rethink your wording > > and maybe even learn a bit more about Unicode and the UTF encodings > > before making such statements. > > > > The idea that UTF-8 bytes cannot represent the whole of Unicode is not > > even wrong. Of course a *single* byte cannot, but a single byte is not > > "UTF-8 bytes". > > So I hope that by now you have understood my point and been able to > decide if you agree with it or not. > > > Marko I still don't understand what's your original point. I think UTF-8 vs UTF-32 is totally different from Python 2 vs 3. For example, string in Rust and Swift (2010s languages!) are *valid* UTF-8. There are strong separation between byte array and string, even they use UTF-8. They looks similar to Python 3, not Python 2. And Python can use UTF-8 for internal encoding in the future. AFAIK, PyPy tries it now. After they succeeded, I want to try port it to CPython after we removed legacy Unicode APIs. (ref PEP 393) So "UTF-8 is better than UTF-32" is totally different problem from "Python 2 is better than 3". Is your point "accepting invalid UTF-8 implicitly by default is better than explicit 'surrogateescape' error handler" like Go? (It's 2010s languages with UTF-8 based string too, but accept invalid UTF-8). Regards, -- INADA Naoki From tjreedy at udel.edu Tue Jul 17 02:38:58 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Jul 2018 02:38:58 -0400 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> Message-ID: On 7/16/2018 7:02 PM, Richard Damon wrote: > >> On Jul 16, 2018, at 3:28 PM, Terry Reedy wrote: >> If one is using a broader definition than usual, it is clearer to say so. This is the core of what I wrote. Do you disagree? > You are defining a variable/fixed width codepoint set. No, I did not define anything. I said, I believe accurately, that this is the, or at least one common understanding of 'variable/fixed width encoding. To repeat, it one is writing to be understood, rather than create an effect, and one uses a word or phrase in a non-standard fashion (which I myself do occasionally), then it is clearer to say what one is doing (which I try to also do). -- Terry Jan Reedy From hjp-python at hjp.at Tue Jul 17 02:44:53 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 17 Jul 2018 08:44:53 +0200 Subject: PEP 526 - var annotations and the spirit of python In-Reply-To: References: Message-ID: <20180717064453.4kshbg4nbeciv2ty@hjp.at> On 2018-07-15 08:37:05 +0200, Christian Gollwitzer wrote: > Am 05.07.18 um 12:04 schrieb Steven D'Aprano: > > On Thu, 05 Jul 2018 09:17:20 +0200, Christian Gollwitzer wrote: > > But... it compiles? Seriously? [...] > > Sometimes I wonder how C programmers manage to write a bug-free "Hello > > World" program. No wonder it is described as a type-unsafe language or a > > weakly-typed language. > > Even this compiles: > > #include > int main() { > int x=1; > x="This is serious"; > printf("%d\n", x); > return 0; > } > Apfelkiste:Tests chris$ gcc intx.c && ./a.out > intx.c:4:3: warning: incompatible pointer to integer conversion assigning to > 'int' from 'char [16]' [-Wint-conversion] > x="This is serious"; > ^~~~~~~~~~~~~~~~~~ > 1 warning generated. > 15294370 > > > Assignment in C to an integer will only fail when the source is a struct. > Everything else can be "converted" to an integer by the compiler. "It compiles" is meaningless when you are talking about the language C (and not about a particular compiler). The C standard doesn't say that compilation has to terminate in case of an error. It just requires that a "conforming implementation shall produce at least one diagnostic message ... contains a violation of any syntax rule or constraint, even if the behavior is also explicitly specified as undefined or implementation-defined." (? 5.1.1.3). Assigning a pointer to an integer is a constraint violation (? 6.5.16.1), and the compiler produces a diagnostic message, so GCC is conforming here. A compiler which accepted a sonnet by Shakespeare, printed the message "This source code may not be valid C" and produced an executable which printed "Francis Bacon" in an infinite loop would also be conforming. > > At least it shows a warning. But hell, who pays attention to C compiler > > warnings? There's *so many of them*. > > In programs that are maintained, the warnings are typically taken seriously. > Some warnings can be annoying, e.g. warnings from generated code about > unused variables and such, but if you see a flood of warnings in regular > code, that is a sign that the code has bad quality or wasn't ever tested on > the platform you try it to compile. Right. Also, modern compilers let you turn on and off warning messages individually. So you can turn off those messages you think are useless and distracting (and maybe turn on a few additional ones). I remember a time when many compilers had "warning levels". That was really annoying, because level n always was missing a few warnings I found very useful while level n + 1 was burying me in a deluge of useless warnings. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From marko at pacujo.net Tue Jul 17 02:52:13 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 09:52:13 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> Message-ID: <87h8kyxski.fsf@elektro.pacujo.net> INADA Naoki : > On Tue, Jul 17, 2018 at 2:31 PM Marko Rauhamaa wrote: >> So I hope that by now you have understood my point and been able to >> decide if you agree with it or not. > > I still don't understand what's your original point. > I think UTF-8 vs UTF-32 is totally different from Python 2 vs 3. > > For example, string in Rust and Swift (2010s languages!) are *valid* > UTF-8. There are strong separation between byte array and string, even > they use UTF-8. They looks similar to Python 3, not Python 2. I won't comment on Rust and Swift because I don't know them. > And Python can use UTF-8 for internal encoding in the future. AFAIK, > PyPy tries it now. After they succeeded, I want to try port it to > CPython after we removed legacy Unicode APIs. (ref PEP 393) How CPython3 implements str objects internally is not what I'm talking about. It's the programmer's model in any compliant Python3 implementation. Both Python2 and Python3 provide two forms of string, one containing 8-bit integers and another one containing 21-bit integers. Python3 made the situation worse in a minor way and a major way. The minor way is the uglification of the byte string notation. The major way is the wholesale preference or mandating of Unicode strings in numerous standard-library interfaces. > So "UTF-8 is better than UTF-32" is totally different problem from > "Python 2 is better than 3". Unix programming is smoothest when the programmer can operate on bytes. Bytes are the mother tongue of Unix, and programming languages should not try to present a different model to the programmer. > Is your point "accepting invalid UTF-8 implicitly by default is better > than explicit 'surrogateescape' error handler" like Go? > (It's 2010s languages with UTF-8 based string too, but accept invalid > UTF-8). I won't comment on Go, either. Marko From tjreedy at udel.edu Tue Jul 17 02:57:01 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Jul 2018 02:57:01 -0400 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <20180716212520.7d560841@bigbox.christie.dr> References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> <20180716212520.7d560841@bigbox.christie.dr> Message-ID: On 7/16/2018 10:25 PM, Tim Chase wrote: > On 2018-07-17 01:08, Steven D'Aprano wrote: >> In English, I think most people would prefer to use a different >> term for whatever "sh" and "ch" represent than "character". > > The term you may be reaching for is "consonant cluster"? > > https://en.wikipedia.org/wiki/Consonant_cluster Sibilant (soft) ch (as opposed to hard aspirated chi as in Greek letter khi (visually like X)) and sh are single consonants, single phonemes in spoken language. In less parsimonious writing systems than Latin, they are often represented by single characters. When transliterated into Latin characters, both decorated c and s and ch and sh are used. 'str', as in string or street is a consonant cluster. It might be represented by a single ligature, but I would not expect any phoneme-based writing system to consider the result to be a single character. (Given that the sound of X (hard chi) mutated into 'ks', the latter is not impossible.) -- Terry Jan Reedy From __peter__ at web.de Tue Jul 17 02:59:22 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Jul 2018 08:59:22 +0200 Subject: doubling the number of tests, but not taking twice as long References: Message-ID: Larry Martell wrote: > I had some code that did this: > > meas_regex = '_M\d+_' > meas_re = re.compile(meas_regex) > > if meas_re.search(filename): > stuff1() > else: > stuff2() > > I then had to change it to this: > > if meas_re.search(filename): > if 'MeasDisplay' in filename: > stuff1a() > else: > stuff1() > else: > if 'PatternFov' in filename: > stuff2a() > else: > stuff2() > > This code needs to process many tens of 1000's of files, and it runs > often, so it needs to run very fast. Needless to say, my change has > made it take 2x as long. That is *not* self-evident. Usually stuffX() would take much longer than the initial tests. So the first step would be to verify that if meas_re.search(filename): if 'MeasDisplay' in filename: pass else: pass else: if 'PatternFov' in filename: pass else: pass takes a significant amount of the total time the piece of code you give takes to execute. > Can anyone see a way to improve that? Not really. I'd check if there is a branch that is executed most of the time or that takes much longer to execute than the other ones, and then try to optimize that. From tjreedy at udel.edu Tue Jul 17 03:09:25 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Jul 2018 03:09:25 -0400 Subject: can't install/run pip (Latest version of Python) In-Reply-To: References: Message-ID: On 7/16/2018 11:03 PM, S Lea wrote: Some additional info, which allows me to say the following: > 1) Don't know what do you mean by the traceback. >>> 1/o Traceback (most recent call last): File "", line 1, in 1/o NameError: name 'o' is not defined The last four lines > 2) In DOS, pip install pandas Try the core-developer recommended way to run modules: python -m pip install pandas or, if you installed the py launcher and have multiple python versions py -3.7 -m pip install pandas If you see something about pip not being installed, python -m ensurepip > 3) Yes, in DOS, Win 10 Crucial info. > 4) 3.7 Allowed me to specify how to specifically launch 3.7. > 5) Not getting much info -- Terry Jan Reedy From songofacandy at gmail.com Tue Jul 17 03:09:48 2018 From: songofacandy at gmail.com (INADA Naoki) Date: Tue, 17 Jul 2018 16:09:48 +0900 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <87h8kyxski.fsf@elektro.pacujo.net> References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> <87h8kyxski.fsf@elektro.pacujo.net> Message-ID: > I won't comment on Rust and Swift because I don't know them. ... > I won't comment on Go, either. Hmm, do you say Python 3 is "cult-like" without survey other popular, programming languages? There are many popular languages which separate bytes and unicode string explicitly and string is not byte-transparent; C#, Java, ECMAScript, (including families like TypeScript), Rust, Swift, Julia, and more. I can't agree that it's cult-like behavior. I think it's practical design decision. Regards, -- INADA Naoki From steve+comp.lang.python at pearwood.info Tue Jul 17 03:44:47 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 07:44:47 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> Message-ID: On Mon, 16 Jul 2018 21:48:42 -0400, Richard Damon wrote: >> On Jul 16, 2018, at 9:21 PM, Steven D'Aprano >> wrote: >> >>> On Mon, 16 Jul 2018 19:02:36 -0400, Richard Damon wrote: >>> >>> You are defining a variable/fixed width codepoint set. Many others >>> want to deal with CHARACTER sets. >> >> Good luck coming up with a universal, objective, language-neutral, >> consistent definition for a character. >> > Who says there needs to be one. A good engineer will use the definition > that is most appropriate to the task at hand. Some things need very > solid definitions, and some things don?t. The the problem is solved: we have a perfectly good de facto definition of character: it is a synonym for "code point", and every single one of Marko's objections disappears. > This goes back to my original point, where I said some people consider > UTF-32 as a variable width encoding. For very many things, practically, > the ?codepoint? isn?t the important thing, Ah, is this another one of those "let's pick a definition that nobody else uses, and state it as a fact" like UTF-32 being variable width? If by "very many things", you mean "not very many things", I agree with you. In my experience, dealing with code points is "good enough", especially if you use Western European alphabets, and even more so if you're willing to do a normalization step before processing text. But of course other people's experience may vary. I'm interested in learning about the library you use to process graphemes in your software. > so the fact that every UTF-32 > code point takes the same number of bytes or code words isn?t that > important. They are dealing with something that needs to be rendered and > preserving larger units, like the grapheme is important. If you're writing a text widget or a shell, you need to worry about rendering glyphs. Everyone else just delegates to their text widget, GUI framework, or shell. >>> This doesn?t mean that UTF-32 is an awful system, just that it isn?t >>> the magical cure that some were hoping for. >> >> Nobody ever claimed it was, except for the people railing that since it >> isn't a magically system we ought to go back to the Good Old Days of >> code page hell, or even further back when everyone just used ASCII. >> > Sometimes ASCII is good enough, especially on a small machine with > limited resources. I doubt that there are many general purpose computers with resources *that* limited. Even MicroPython supports Unicode, and that runs on embedded devices with memory measured in kilobytes. 8K is considered the smallest amount of memory usable with MicroPython, although 128K is more realistic as the *practical* lower limit. In the mid 1980s, I was using computers with 128K of RAM, and they were still able to deal with more than just ASCII. I think the "limited resources" argument is bogus. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Tue Jul 17 03:46:19 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 07:46:19 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> <20180716212520.7d560841@bigbox.christie.dr> Message-ID: On Mon, 16 Jul 2018 21:25:20 -0500, Tim Chase wrote: > On 2018-07-17 01:08, Steven D'Aprano wrote: >> In English, I think most people would prefer to use a different term >> for whatever "sh" and "ch" represent than "character". > > The term you may be reaching for is "consonant cluster"? > > https://en.wikipedia.org/wiki/Consonant_cluster Thanks! -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Tue Jul 17 03:50:57 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 07:50:57 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> Message-ID: On Tue, 17 Jul 2018 08:26:45 +0300, Marko Rauhamaa wrote: > Steven D'Aprano : >> On Mon, 16 Jul 2018 22:51:32 +0300, Marko Rauhamaa wrote: >>> UTF-8 bytes can only represent the first 128 code points of Unicode. >> >> This is DailyWTF material. Perhaps you want to rethink your wording and >> maybe even learn a bit more about Unicode and the UTF encodings before >> making such statements. >> >> The idea that UTF-8 bytes cannot represent the whole of Unicode is not >> even wrong. Of course a *single* byte cannot, but a single byte is not >> "UTF-8 bytes". > > So I hope that by now you have understood my point and been able to > decide if you agree with it or not. If your point was not what you wrote, then no, I'm sorry, my crystal ball unexpectedly broke down (why it didn't foresee its own failure I'll never know...). I can't tell what you are thinking, only what you write. Sometimes I can guess (like my earlier guess that you meant grapheme, rather than glyph) but in this case, if you mean something other than "UTF-8 bytes can only represent the first 128 code points of Unicode" I'm flummoxed. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From marko at pacujo.net Tue Jul 17 03:51:38 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 10:51:38 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> <87h8kyxski.fsf@elektro.pacujo.net> Message-ID: <87k1puwb91.fsf@elektro.pacujo.net> INADA Naoki : >> I won't comment on Rust and Swift because I don't know them. > ... >> I won't comment on Go, either. > > Hmm, do you say Python 3 is "cult-like" without survey other popular, > programming languages? You can talk about Python3 independently of other programming languages. Python3 is not a cult. It's a programming language. What is cult-like is the manner in which Python3's honor is defended in a good many of the discussions in this newsgroup: anger, condescension, ridicule, name-calling. > I can't agree that it's cult-like behavior. I think it's practical > design decision. If Python3 works for you, I'm happy for you. Marko From steve+comp.lang.python at pearwood.info Tue Jul 17 03:56:39 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 07:56:39 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> <87h8kyxski.fsf@elektro.pacujo.net> Message-ID: On Tue, 17 Jul 2018 09:52:13 +0300, Marko Rauhamaa wrote: > Both Python2 and Python3 provide two forms of string, one containing > 8-bit integers and another one containing 21-bit integers. Why do you insist on making counter-factual statements as facts? Don't you have a Python REPL you can try these outrageous claims out before making them? py> b'abcd'[2] + 1 # bytes are sequences of integers 100 py> 'abcd'[2] + 1 # strings are not sequences of integers Traceback (most recent call last): File "", line 1, in TypeError: Can't convert 'int' object to str implicitly Python strings are sequences of abstract characters. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Tue Jul 17 04:04:29 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 08:04:29 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> Message-ID: On Tue, 17 Jul 2018 15:20:16 +0900, INADA Naoki wrote (replying to Marko): > I still don't understand what's your original point. I think UTF-8 vs > UTF-32 is totally different from Python 2 vs 3. > > For example, string in Rust and Swift (2010s languages!) are *valid* > UTF-8. There are strong separation between byte array and string, even > they use UTF-8. They looks similar to Python 3, not Python 2. > > And Python can use UTF-8 for internal encoding in the future. AFAIK, > PyPy tries it now. After they succeeded, I want to try port it to > CPython after we removed legacy Unicode APIs. (ref PEP 393) I'm not sure about PyPy, but I'm fairly certain that MicroPython uses UTF-8. I would be very interested to see the results of using UTF-8 in CPython. At the least, it would remove the need to keep a separate UTF-8 representation in the string object, as they do now. It might even be more compact, although a naive implementation would lose the ability to do constant time indexing into strings. That might be a tradeoff worth keeping, if indexing remained sufficiently fast. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From songofacandy at gmail.com Tue Jul 17 04:22:53 2018 From: songofacandy at gmail.com (INADA Naoki) Date: Tue, 17 Jul 2018 17:22:53 +0900 Subject: What "cult-like behavior" meant (was: Re: Glyphs and graphemes In-Reply-To: <87k1puwb91.fsf@elektro.pacujo.net> References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> <87h8kyxski.fsf@elektro.pacujo.net> <87k1puwb91.fsf@elektro.pacujo.net> Message-ID: On Tue, Jul 17, 2018 at 4:57 PM Marko Rauhamaa wrote: > > Python3 is not a cult. It's a programming language. What is cult-like is > the manner in which Python3's honor is defended in a good many of the > discussions in this newsgroup: anger, condescension, ridicule, > name-calling. OK, I understand now. But I think it's true for all popular programming languages, not only Python. And it's not only for programming languages. I can see many too-defensive people on Twitter. Honestly speaking, I'm too defensive sometimes, too. Anyway, I feel "Cult-like behavior" in mail subject was misleading when discussing about byte-transparent string vs unicode string. Such powerful words may make people more defensive, and heat non productive discussion. (I know it's not you start using "cult-like behavior" in subject. I don't blame anyone. I just want share I noticed.) Regards, -- INADA Naoki From steve+comp.lang.python at pearwood.info Tue Jul 17 04:23:16 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 08:23:16 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> <87h8kyxski.fsf@elektro.pacujo.net> <87k1puwb91.fsf@elektro.pacujo.net> Message-ID: On Tue, 17 Jul 2018 10:51:38 +0300, Marko Rauhamaa wrote: > in which Python3's honor is defended in a good many of the discussions > in this newsgroup: anger, condescension, ridicule, name-calling. You call it defending Python 3's honour. I call it responding to people who insist on spreading misinformation and falsehoods even when given the correct details. Some people have their self-image wrapped up in being able to portray themselves as a maverick who, almost alone, sees through the "lies" about to see "the truth". Others prefer reality instead, and get upset when false facts are repeated, over and over again, as truth. If instead you want to discuss actual concrete areas where Python's text/ bytes divide hurts, you'll find that there are plenty of people who agree. Especially if they have to write string-handling code that needs to run under both 2 and 3. Been there, done that, don't want to do it again. The Python 3 redesign was done to fix certain common, hard-to-diagnose problems in string handling caused by Python2's violation of the Zen "in the face of ambiguity, refuse the temptation to guess". (Python 2 guesses what encoding you probably mean when it comes to strings and bytes, and when it gets it right it is convenient, but when it gets it wrong, it is badly wrong, and hard to diagnose and fix.) It impossible to improve the text handling experience for every single programmer writing every single kind of program under every single set of circumstances. Like any semantic change, there are going to be winners and losers, and the core devs' position is that if the losers have concrete and backwards-compatible suggestions for improving their experience (e.g. re-adding % support for byte strings) they will consider them, but going back to the Python 2 misdesign is off the table. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From marko at pacujo.net Tue Jul 17 04:27:34 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 11:27:34 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> Message-ID: <87fu0iw9l5.fsf@elektro.pacujo.net> Steven D'Aprano : > On Mon, 16 Jul 2018 21:48:42 -0400, Richard Damon wrote: >> Who says there needs to be one. A good engineer will use the >> definition that is most appropriate to the task at hand. Some things >> need very solid definitions, and some things don?t. > > The the problem is solved: we have a perfectly good de facto definition > of character: it is a synonym for "code point", and every single one of > Marko's objections disappears. I admit it. Python3 is the perfect medium for your codepoint delivery needs. What you don't seem to understand about my objections is that no programmer needs codepoints per se. Also, Python2's strings do as good a job at delivering codepoints as Python3. Simultaneously, Python2's strings are a better fit for the Unix system and network programming model. >> This goes back to my original point, where I said some people >> consider UTF-32 as a variable width encoding. For very many things, >> practically, the ?codepoint? isn?t the important thing, > > Ah, is this another one of those "let's pick a definition that nobody > else uses, and state it as a fact" like UTF-32 being variable width? Each 32-bit value in UTF-32 represents one Unicode code point and is exactly equal to that code point's numerical value. That is called bijection. Even more, it's a homomorphism. Homomorphism is very high degree of sameness. It is essential for people to understand that the very same issues that plague UTF-8 plague UTF-32 as well. Using UTF in both highlights that fact. > If by "very many things", you mean "not very many things", I agree > with you. In my experience, dealing with code points is "good enough", > especially if you use Western European alphabets, and even more so if > you're willing to do a normalization step before processing text. Of course, UTF-8 doesn't relieve you from Unicode problems. But it has one big advantage: it can usually deal with non-Unicode data without any extra considerations while Python3's strings make you have to take elaborate measures to handle those special cases. Why, even print() must be guarded against UnicodeEncodeError when the printed string is not in the programmer's control. > But of course other people's experience may vary. I'm interested in > learning about the library you use to process graphemes in your software. For me, the issue is where do I produce a line break in my text output? Currently, I'm just counting codepoints to estimate the width of the output. Marko From marko at pacujo.net Tue Jul 17 04:30:25 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 11:30:25 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> <87h8kyxski.fsf@elektro.pacujo.net> Message-ID: <87bmb6w9ge.fsf@elektro.pacujo.net> Steven D'Aprano : > On Tue, 17 Jul 2018 09:52:13 +0300, Marko Rauhamaa wrote: > >> Both Python2 and Python3 provide two forms of string, one containing >> 8-bit integers and another one containing 21-bit integers. > > Why do you insist on making counter-factual statements as facts? Don't > you have a Python REPL you can try these outrageous claims out before > making them? > > [...] > > Python strings are sequences of abstract characters. which -- by your definition -- are codepoints -- which by any definition -- are integers. Marko From marko at pacujo.net Tue Jul 17 04:41:01 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 11:41:01 +0300 Subject: What "cult-like behavior" meant (was: Re: Glyphs and graphemes References: <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> <87h8kyxski.fsf@elektro.pacujo.net> <87k1puwb91.fsf@elektro.pacujo.net> Message-ID: <877eluw8yq.fsf@elektro.pacujo.net> INADA Naoki : > On Tue, Jul 17, 2018 at 4:57 PM Marko Rauhamaa wrote: >> >> Python3 is not a cult. It's a programming language. What is cult-like is >> the manner in which Python3's honor is defended in a good many of the >> discussions in this newsgroup: anger, condescension, ridicule, >> name-calling. > > OK, I understand now. > > But I think it's true for all popular programming languages, not only > Python. And it's not only for programming languages. I can see many > too-defensive people on Twitter. Honestly speaking, I'm too defensive > sometimes, too. You are absolutely right. That behavior is a (lamentable) hereditary trait in our species and apparently serves an important evolutionary function (or it would have disappeared). > Anyway, I feel "Cult-like behavior" in mail subject was misleading > when discussing about byte-transparent string vs unicode string. Yeah, discussions meander a lot. > Such powerful words may make people more defensive, and heat non > productive discussion. Thing is, you need to stand up to bullying. Maybe you are not seeing it, but quite many people have become victims of it here while the bullies thrive and lead the pack. I can see that the bullying behavior comes from exasperation instead of an outright meanness. They sincerely believe they understand the issues better than their opponents and are at a loss to get the message across without resorting to ad hominems. Marko From rosuav at gmail.com Tue Jul 17 04:46:12 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 18:46:12 +1000 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <87fu0iw9l5.fsf@elektro.pacujo.net> References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> <87fu0iw9l5.fsf@elektro.pacujo.net> Message-ID: On Tue, Jul 17, 2018 at 6:27 PM, Marko Rauhamaa wrote: >> But of course other people's experience may vary. I'm interested in >> learning about the library you use to process graphemes in your software. > > For me, the issue is where do I produce a line break in my text output? > Currently, I'm just counting codepoints to estimate the width of the > output. Well, that's just flat out wrong, then. Counting graphemes isn't going to make it any better. Grab a well-known library like Pango and let it do your measurements for you, *in pixels*. Or better still, just poke your text to a dedicated text-display widget and let it display it correctly. Back in the early 2000s, I built a program that displayed text in a monospaced font, and it was riddled with assumptions that "one byte == one character == N pixels of width" (for some value of N that changed only when you change font). It was easier to throw it out completely and start over than to try to "bolt on" true Unicode support. The replacement program uses GTK and Pango to do all its display work, and while it still has a lot of complexities (because it has to handle colour codes, highlighting, point-to-word, and such, all of which get very complicated when you mix LTR and RTL text), at least it can 100% dependably say "wrap to this point". For the convenience of the human using it, it specifies a wrap width in characters, but in the fine print, the wrap width is defined as "the width of that many of the letter 'n' in the chosen font". At no point do I ever count bytes, code units, code points, grapheme clusters, or blue-faced baboons, to try to pretend that I know the width of the string. All of them are wrong for the wrapping of text. ChrisA From rosuav at gmail.com Tue Jul 17 04:49:51 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 18:49:51 +1000 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <87fu0iw9l5.fsf@elektro.pacujo.net> References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> <87fu0iw9l5.fsf@elektro.pacujo.net> Message-ID: On Tue, Jul 17, 2018 at 6:27 PM, Marko Rauhamaa wrote: > It is essential for people to understand that the very same issues that > plague UTF-8 plague UTF-32 as well. Using UTF in both highlights that > fact. What a wonderful nonsense. I suppose that the same issues plague Elon Musk as plague the musk sticks in the sweets aisle in the supermarket - they do use the same letters, after all. >> If by "very many things", you mean "not very many things", I agree >> with you. In my experience, dealing with code points is "good enough", >> especially if you use Western European alphabets, and even more so if >> you're willing to do a normalization step before processing text. > > Of course, UTF-8 doesn't relieve you from Unicode problems. But it has > one big advantage: it can usually deal with non-Unicode data without any > extra considerations while Python3's strings make you have to take > elaborate measures to handle those special cases. Why, even print() must > be guarded against UnicodeEncodeError when the printed string is not in > the programmer's control. What is this "non-Unicode data" that UTF-8 can handle? Do you mean arbitrary byte sequences? Because no, it cannot; properly-formed UTF-8 sequences MUST comply with the precise requirements of the format. Can you give an example of how Python 3's print function can raise UnicodeEncodeError when given a Python 3 string? ChrisA From rosuav at gmail.com Tue Jul 17 04:51:39 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 18:51:39 +1000 Subject: What "cult-like behavior" meant (was: Re: Glyphs and graphemes In-Reply-To: <877eluw8yq.fsf@elektro.pacujo.net> References: <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> <87h8kyxski.fsf@elektro.pacujo.net> <87k1puwb91.fsf@elektro.pacujo.net> <877eluw8yq.fsf@elektro.pacujo.net> Message-ID: On Tue, Jul 17, 2018 at 6:41 PM, Marko Rauhamaa wrote: > I can see that the bullying behavior comes from exasperation instead of > an outright meanness. They sincerely believe they understand the issues > better than their opponents and are at a loss to get the message across > without resorting to ad hominems. Have you considered the possibility that you're the one who doesn't understand the issues? Possible evidence to support this fact includes that many of us have ACTUAL REAL WORLD EXPERIENCE writing code for different languages' texts. ChrisA From marko at pacujo.net Tue Jul 17 05:03:38 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 12:03:38 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> <87fu0iw9l5.fsf@elektro.pacujo.net> Message-ID: <8736wiw7x1.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Jul 17, 2018 at 6:27 PM, Marko Rauhamaa wrote: >> For me, the issue is where do I produce a line break in my text output? >> Currently, I'm just counting codepoints to estimate the width of the >> output. > > Well, that's just flat out wrong, then. Counting graphemes isn't going > to make it any better. Grab a well-known library like Pango and let it > do your measurements for you, *in pixels*. Or better still, just poke > your text to a dedicated text-display widget and let it display it > correctly. What I'd need is for the tty to tell me what column the cursor is visually. Or better yet, the tty would have to tell me where the column would be *after* I emit the next grapheme cluster. The tty *does* know that but I don't know if there is an interface to query it. This doesn't seem to be working properly: sys.stdout.write("a\u0300\u001b[6n\n") (and would be a tricky interface even if it did) Marko From robin at reportlab.com Tue Jul 17 05:10:49 2018 From: robin at reportlab.com (Robin Becker) Date: Tue, 17 Jul 2018 10:10:49 +0100 Subject: test for absence of infinite loop Message-ID: A user reported an infinite loop in reportlab. I determined a possible cause and fix and would like to test for absence of the loop. Is there any way to check for presence/absence of an infinite loop in python? I imagine we could do something like call an external process and see if it takes too long, but that seems a bit flaky. -- Robin Becker From mail at timgolden.me.uk Tue Jul 17 05:18:48 2018 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 17 Jul 2018 10:18:48 +0100 Subject: Moderator interjection [WAS: Re: What "cult-like behavior" meant] In-Reply-To: <877eluw8yq.fsf@elektro.pacujo.net> References: <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> <87h8kyxski.fsf@elektro.pacujo.net> <87k1puwb91.fsf@elektro.pacujo.net> <877eluw8yq.fsf@elektro.pacujo.net> Message-ID: <7c7b2afe-0e82-4443-b17f-ea01737fe555@timgolden.me.uk> [Moderator hat on] Please. Step back. We've gone over and over this (and not for the first time). This has ceased to be a enlightening discussion into possibly interesting issues of Unicode implementation. It has effectively become a restatement of entrenched positions. If the key participants (and there are really very few of you) wish to pursue this in some other forum, please do so. But please don't pursue it here: it's creating an amount of noise disproportionate to its possible value. Thank you TJG From rosuav at gmail.com Tue Jul 17 05:30:42 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 19:30:42 +1000 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <8736wiw7x1.fsf@elektro.pacujo.net> References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> <87fu0iw9l5.fsf@elektro.pacujo.net> <8736wiw7x1.fsf@elektro.pacujo.net> Message-ID: On Tue, Jul 17, 2018 at 7:03 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Tue, Jul 17, 2018 at 6:27 PM, Marko Rauhamaa wrote: >>> For me, the issue is where do I produce a line break in my text output? >>> Currently, I'm just counting codepoints to estimate the width of the >>> output. >> >> Well, that's just flat out wrong, then. Counting graphemes isn't going >> to make it any better. Grab a well-known library like Pango and let it >> do your measurements for you, *in pixels*. Or better still, just poke >> your text to a dedicated text-display widget and let it display it >> correctly. > > What I'd need is for the tty to tell me what column the cursor is > visually. Or better yet, the tty would have to tell me where the column > would be *after* I emit the next grapheme cluster. Are you prepared for the possibility that emitting characters won't change what column you're in? Start a new line, then emit one Arabic character. What column are you in? Now emit three more Arabic characters, completing the word. What column? Now emit a U+0020 SPACE. What column? Now emit some Latin characters, followed by more Arabic. Where are you? ChrisA From rosuav at gmail.com Tue Jul 17 05:32:17 2018 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 17 Jul 2018 19:32:17 +1000 Subject: test for absence of infinite loop In-Reply-To: References: Message-ID: On Tue, Jul 17, 2018 at 7:10 PM, Robin Becker wrote: > A user reported an infinite loop in reportlab. I determined a possible cause > and fix and would like to test for absence of the loop. Is there any way to > check for presence/absence of an infinite loop in python? I imagine we could > do something like call an external process and see if it takes too long, but > that seems a bit flaky. All you gotta do is solve the halting problem... https://en.wikipedia.org/wiki/Halting_problem ChrisA From marko at pacujo.net Tue Jul 17 05:36:13 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 12:36:13 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> <87fu0iw9l5.fsf@elektro.pacujo.net> Message-ID: <87y3eaurua.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Jul 17, 2018 at 6:27 PM, Marko Rauhamaa wrote: >> Of course, UTF-8 doesn't relieve you from Unicode problems. But it has >> one big advantage: it can usually deal with non-Unicode data without any >> extra considerations while Python3's strings make you have to take >> elaborate measures to handle those special cases. Why, even print() must >> be guarded against UnicodeEncodeError when the printed string is not in >> the programmer's control. > > What is this "non-Unicode data" that UTF-8 can handle? Do you mean > arbitrary byte sequences? Because no, it cannot; properly-formed UTF-8 > sequences MUST comply with the precise requirements of the format. I was being imprecise: byte strings carrying UTF-8 can handle bad UTF-8 with equal ease. And that's a real, practical advantage. > Can you give an example of how Python 3's print function can raise > UnicodeEncodeError when given a Python 3 string? >>> print("\ud810") Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'utf-8' codec can't encode character '\ud810' \ in position 0: surrogates not allowed Marko From marko at pacujo.net Tue Jul 17 05:37:37 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 12:37:37 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> <87fu0iw9l5.fsf@elektro.pacujo.net> <8736wiw7x1.fsf@elektro.pacujo.net> Message-ID: <87tvoyurry.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Jul 17, 2018 at 7:03 PM, Marko Rauhamaa wrote: >> What I'd need is for the tty to tell me what column the cursor is >> visually. Or better yet, the tty would have to tell me where the column >> would be *after* I emit the next grapheme cluster. > > Are you prepared for the possibility that emitting characters won't > change what column you're in? Absolutely. Marko From robin at reportlab.com Tue Jul 17 06:04:15 2018 From: robin at reportlab.com (Robin Becker) Date: Tue, 17 Jul 2018 11:04:15 +0100 Subject: test for absence of infinite loop In-Reply-To: References: Message-ID: On 17/07/2018 10:32, Chris Angelico wrote: .......... > > All you gotta do is solve the halting problem... > > https://en.wikipedia.org/wiki/Halting_problem > > ChrisA > ah so it's easy :) -- Robin Becker From jon+usenet at unequivocal.eu Tue Jul 17 06:39:06 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 17 Jul 2018 10:39:06 -0000 (UTC) Subject: Users banned References: <5B4B8391.3060808@stoneleaf.us> <877elw2ndr.fsf@elektro.pacujo.net> <5b7046a6-4c96-c8b0-9b5b-ec7999d4865d@gmail.com> <6ef56d48-eb59-ac77-2e5f-d0c6fdc7b1b9@gmail.com> Message-ID: On 2018-07-17, Steven D'Aprano wrote: > But neither of these are prohibited by the CoC, neither of these should > be banning offense, and even if they were, he should have had a formal > warning first. > > Preferably TWO formal warnings: the first privately, the second publicly, > and only on the third offence a ban. > > And I question the fairness of a six month ban, rather than (let's say) > an initial one month ban. > > As for banning Rick, when he isn't even posting at the moment, I don't > even have words for that. There's no statute of limitation for murder, > but surely "being obnoxious on the internet" ought to come with a fairly > short period of forgiveness. Why is anyone responding as if the original "Users banned" message was genuine, rather than the obvious troll it actually was? From cs at cskk.id.au Tue Jul 17 07:16:30 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 17 Jul 2018 21:16:30 +1000 Subject: test for absence of infinite loop In-Reply-To: References: Message-ID: <20180717111630.GA38537@cskk.homeip.net> On 17Jul2018 10:10, Robin Becker wrote: >A user reported an infinite loop in reportlab. I determined a possible >cause and fix and would like to test for absence of the loop. Is there >any way to check for presence/absence of an infinite loop in python? I >imagine we could do something like call an external process and see if it >takes too long, but that seems a bit flaky. While others have kindly pointed you at the halting problem (unsolvable in the general case) you can usually verify that the specific problem you fixed is fixed. Can you figure out how long the task should run with your fix in a test case? Not as time, but in loop iterations? Put a counter in the loop and check that its value doesn't exceed that. Cheers, Cameron Simpson From Richard at Damon-family.org Tue Jul 17 07:29:20 2018 From: Richard at Damon-family.org (Richard Damon) Date: Tue, 17 Jul 2018 07:29:20 -0400 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87r2k54mpf.fsf@elektro.pacujo.net> <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> Message-ID: <18888E27-78A5-47A3-B328-842DACBA578C@Damon-family.org> > On Jul 17, 2018, at 3:44 AM, Steven D'Aprano wrote: > > On Mon, 16 Jul 2018 21:48:42 -0400, Richard Damon wrote: > >>> On Jul 16, 2018, at 9:21 PM, Steven D'Aprano >>> wrote: >>> >>>> On Mon, 16 Jul 2018 19:02:36 -0400, Richard Damon wrote: >>>> >>>> You are defining a variable/fixed width codepoint set. Many others >>>> want to deal with CHARACTER sets. >>> >>> Good luck coming up with a universal, objective, language-neutral, >>> consistent definition for a character. >>> >> Who says there needs to be one. A good engineer will use the definition >> that is most appropriate to the task at hand. Some things need very >> solid definitions, and some things don?t. > > The the problem is solved: we have a perfectly good de facto definition > of character: it is a synonym for "code point", and every single one of > Marko's objections disappears. > Which is a ?changed? definition! Do you agree that the concept of variable width encoding vastly predates the creation of Unicode? Can you also find any use of the word codepoint that predates the development of Unicode? Code points and code words are an invention of the Unicode consortium, and as such should really only be used in talking about IT and not some other encodings. I believe that Unicode also created the idea of storing composed characters as a series of codepoints instead of it being done in the input routine and the character set needing to define a character code for every needed composed character. > >> This goes back to my original point, where I said some people consider >> UTF-32 as a variable width encoding. For very many things, practically, >> the ?codepoint? isn?t the important thing, > > Ah, is this another one of those "let's pick a definition that nobody > else uses, and state it as a fact" like UTF-32 being variable width? > > If by "very many things", you mean "not very many things", I agree with > you. In my experience, dealing with code points is "good enough", > especially if you use Western European alphabets, and even more so if > you're willing to do a normalization step before processing text. > AH, that is the rub, you only deal with the parts of Unicode that are simple and regular. This is EXACTLY the issue that you blame people who want to use ASCII or Codepages to solve, just the next step in the evolution. One problem with normalization is that for Western European characters it tends to be able to convert every ?Character? to a code point, but in some corner cases, especially for other languages it can?t. I am not just talking about digraphs like ch that have been mentioned, but the real composed characters with a base glyph with marks above/below/embedded on it. Unicode represents many of them with a code point, but no where near all of them. If you actually read the Unicode documents, they do talk about Characters, and admit that they aren?t necessarily codepoints, so if you actually want to talk about a CHARACTER set, Unicode, even UTF-32 needs to sometimes be treated as variable width. > But of course other people's experience may vary. I'm interested in > learning about the library you use to process graphemes in your software. > > >> so the fact that every UTF-32 >> code point takes the same number of bytes or code words isn?t that >> important. They are dealing with something that needs to be rendered and >> preserving larger units, like the grapheme is important. > > If you're writing a text widget or a shell, you need to worry about > rendering glyphs. Everyone else just delegates to their text widget, GUI > framework, or shell. > But someone needs to write that text widget, or it might not do exactly what you want, say wrapping the text around obstacles already placed on the screen/page. And try using that text widget to find the ?middle? (as shown) of a text string, (other than iterating with multiple calls to it to try and find it). Unicode made the processing of Codepoints simpler, but made the processing of actual rendered text much more complicated if you want to handle everything right. > >>>> This doesn?t mean that UTF-32 is an awful system, just that it isn?t >>>> the magical cure that some were hoping for. >>> >>> Nobody ever claimed it was, except for the people railing that since it >>> isn't a magically system we ought to go back to the Good Old Days of >>> code page hell, or even further back when everyone just used ASCII. >>> >> Sometimes ASCII is good enough, especially on a small machine with >> limited resources. > > I doubt that there are many general purpose computers with resources > *that* limited. Even MicroPython supports Unicode, and that runs on > embedded devices with memory measured in kilobytes. 8K is considered the > smallest amount of memory usable with MicroPython, although 128K is more > realistic as the *practical* lower limit. > > In the mid 1980s, I was using computers with 128K of RAM, and they were > still able to deal with more than just ASCII. I think the "limited > resources" argument is bogus. > I regularly use processors with 8k of Ram and 32k of flash. Yes, I will admit that I wouldn?t think of using Python there, as the overhead would be excessive. Yes if I needed to I could put a bigger processor in there, but it would cost space, dollars, and power, so I don?t. The applications there can deal with just ASCII so I do. I would say that on such a processor that actually trying to really process Unicode would be out of reach, as even as simple of a function as isdigit wouldn?t fit if you wanted a proper Unicode definition, and tolower would be out of the question. > > -- > Steven D'Aprano > "Ever since I learned about confirmation bias, I've been seeing > it everywhere." -- Jon Ronson > > -- > https://mail.python.org/mailman/listinfo/python-list From robin at reportlab.com Tue Jul 17 07:39:44 2018 From: robin at reportlab.com (Robin Becker) Date: Tue, 17 Jul 2018 12:39:44 +0100 Subject: test for absence of infinite loop In-Reply-To: <20180717111630.GA38537@cskk.homeip.net> References: <20180717111630.GA38537@cskk.homeip.net> Message-ID: <3e561b62-599a-bccd-6a41-5011455efe28@chamonix.reportlab.co.uk> On 17/07/2018 12:16, Cameron Simpson wrote: > On 17Jul2018 10:10, Robin Becker wrote: >> A user reported an infinite loop in reportlab. I determined a possible cause and fix and would like to test for absence of the >> loop. Is there any way to check for presence/absence of an infinite loop in python? I imagine we could do something like call an >> external process and see if it takes too long, but that seems a bit flaky. > > While others have kindly pointed you at the halting problem (unsolvable in the general case) you can usually verify that the > specific problem you fixed is fixed. Can you figure out how long the task should run with your fix in a test case? Not as time, > but in loop iterations? Put a counter in the loop and check that its value doesn't exceed that. well I understand the problem about not halting. However as you point out in a fixed case I know that the test should take fractions of a second to complete. I certainly don't want to put instrumentation into the source code. It's relatively easy to imagine polling termination of a separate thread/process, but that's not particularly reliable. I don't know if there is a way to ask a python interpeter how many instructions it has carried out. -- Robin Becker From antoon.pardon at vub.be Tue Jul 17 07:49:37 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 17 Jul 2018 13:49:37 +0200 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <87fu0iw9l5.fsf@elektro.pacujo.net> References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> <87fu0iw9l5.fsf@elektro.pacujo.net> Message-ID: On 17-07-18 10:27, Marko Rauhamaa wrote: > Steven D'Aprano : >> On Mon, 16 Jul 2018 21:48:42 -0400, Richard Damon wrote: >>> Who says there needs to be one. A good engineer will use the >>> definition that is most appropriate to the task at hand. Some things >>> need very solid definitions, and some things don?t. >> The the problem is solved: we have a perfectly good de facto definition >> of character: it is a synonym for "code point", and every single one of >> Marko's objections disappears. > I admit it. Python3 is the perfect medium for your codepoint delivery > needs. > > What you don't seem to understand about my objections is that no > programmer needs codepoints per se. Also, Python2's strings do as good a > job at delivering codepoints as Python3. No they don't. The programs that I work on, need to be able to treat at least german, french, dutch and english text. My experience is that in python3 it is way easier to do things right. Especially if you are working with regular expressions. -- Antoon. From marko at pacujo.net Tue Jul 17 08:22:33 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 15:22:33 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> <87fu0iw9l5.fsf@elektro.pacujo.net> Message-ID: <87pnzmuk52.fsf@elektro.pacujo.net> Antoon Pardon : > On 17-07-18 10:27, Marko Rauhamaa wrote: >> Also, Python2's strings do as good a job at delivering codepoints as >> Python3. > > No they don't. The programs that I work on, need to be able to treat > at least german, french, dutch and english text. My experience is that > in python3 it is way easier to do things right. Especially if you are > working with regular expressions. If you assume that NFC normalizes every letter to a single codepoint (and carefully use NFC everywhere), you are right. But equally likely you may inadvertently be setting yourself up for a surprise. Marko From steve+comp.lang.python at pearwood.info Tue Jul 17 08:30:41 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 17 Jul 2018 12:30:41 +0000 (UTC) Subject: test for absence of infinite loop References: Message-ID: On Tue, 17 Jul 2018 10:10:49 +0100, Robin Becker wrote: > A user reported an infinite loop in reportlab. I determined a possible > cause and fix and would like to test for absence of the loop. Is there > any way to check for presence/absence of an infinite loop in python? I > imagine we could do something like call an external process and see if > it takes too long, but that seems a bit flaky. In general, no, it is impossible to detect infinite loops. https://en.wikipedia.org/wiki/Halting_problem That's not to say that either human readers or the compiler can't detect *some* infinite loops ahead of time: # obviously an infinite loop while True: pass and then there's this: https://www.usenix.org/legacy/publications/library/proceedings/vhll/ full_papers/koenig.a but Python's compiler isn't capable of anything like that. The way I sometimes deal with that sort of thing is to re-write selected potentially-infinite loops: while condition: # condition may never become False do something to something like this: for counter in range(1000): if not condition: break do something else: raise TooManyIterationsError -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rhodri at kynesim.co.uk Tue Jul 17 08:41:07 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 17 Jul 2018 13:41:07 +0100 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <20180717015251.GB16968@bladeshadow.org> References: <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <87fu0j0y1u.fsf@elektro.pacujo.net> <8fd795ac-2264-a835-aab3-ff5ef82ee852@kynesim.co.uk> <20180717015251.GB16968@bladeshadow.org> Message-ID: <9a07458d-00a4-71fd-4a66-442d27af6553@kynesim.co.uk> On 17/07/18 02:52, Python wrote: > On Mon, Jul 16, 2018 at 08:56:11PM +0100, Rhodri James wrote: >> The problem everyone is having with you, Marko, is that you are >> using the terminology incorrectly. [...] When you call UTF-32 a >> variable-width encoding, you are incorrect. > But please don't overlook that the "terminology" is in fact rather > specialized jargon, far less common than even most computer jargon. > Unless you're uncommonly familiar with the subject matter, you simply > don't have this vocabulary. Under the circumstances it seems not > horribly unreasonable to expect such a person to consider the bytes > required to represent a glyph as an encoding's width, and you as > "experts" rightly should expect, let's call them lay people, to make > this mistake and adjust for it, or politely correct it, without the > condescension. If we were talking about lay people, I would unhesitatingly agree with you. However Marko *does* claim expertise in this area, but then uses what I hope has been demonstrated to be quite careful and deliberate terminology in a manner most politely described as "careless". This is... not helpful. -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Tue Jul 17 08:51:35 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 17 Jul 2018 13:51:35 +0100 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <9a07458d-00a4-71fd-4a66-442d27af6553@kynesim.co.uk> References: <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <87fu0j0y1u.fsf@elektro.pacujo.net> <8fd795ac-2264-a835-aab3-ff5ef82ee852@kynesim.co.uk> <20180717015251.GB16968@bladeshadow.org> <9a07458d-00a4-71fd-4a66-442d27af6553@kynesim.co.uk> Message-ID: <3d2f164e-e6bc-1f93-ce8b-f3f066859cfb@kynesim.co.uk> On 17/07/18 13:41, Rhodri James wrote: > On 17/07/18 02:52, Python wrote: >> On Mon, Jul 16, 2018 at 08:56:11PM +0100, Rhodri James wrote: >>> The problem everyone is having with you, Marko, is that you are >>> using the terminology incorrectly. [...] When you call UTF-32 a >>> variable-width encoding, you are incorrect. >> But please don't overlook that the "terminology" is in fact rather >> specialized jargon, far less common than even most computer jargon. >> Unless you're uncommonly familiar with the subject matter, you simply >> don't have this vocabulary.? Under the circumstances it seems not >> horribly unreasonable to expect such a person to consider the bytes >> required to represent a glyph as an encoding's width, and you as >> "experts" rightly should expect, let's call them lay people, to make >> this mistake and adjust for it, or politely correct it, without the >> condescension. > > If we were talking about lay people, I would unhesitatingly agree with > you.? However Marko *does* claim expertise in this area, but then uses > what I hope has been demonstrated to be quite careful and deliberate > terminology in a manner most politely described as "careless".? This > is... not helpful. > Whoops, sorry, that was not meant to go to the list. -- Rhodri James *-* Kynesim Ltd From sandy0511.star at gmail.com Tue Jul 17 08:53:58 2018 From: sandy0511.star at gmail.com (sandy star) Date: Tue, 17 Jul 2018 05:53:58 -0700 (PDT) Subject: Python Training in Chennai Message-ID: <020a4488-48ec-4c14-8163-452bbeb8209e@googlegroups.com> Python Training in Chennai with expert guidance and fully hands-on classes. Python is a high-level programming language sometimes it also denoted as the scripting language as it provides rapid & fast development and easy of use. url : https://www.besanttechnologies.com/training-courses/python-training-institute-in-chennai From rhodri at kynesim.co.uk Tue Jul 17 08:55:25 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 17 Jul 2018 13:55:25 +0100 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: <68c663cb-b553-9a5e-5365-999206d03903@kynesim.co.uk> On 17/07/18 02:17, Steven D'Aprano wrote: > On Mon, 16 Jul 2018 23:50:12 +0200, Roel Schroeven wrote: > >> There are times (encoding/decoding network protocols and other data >> formats) when I have a byte string and I want/need to process it like >> Python 2 does, and that is the one area where I feel Python 3 make >> things a bit more difficult. > > Ah yes, the unfortunate design error that iterating over byte-strings > returns ints rather than single-byte strings. > > That decision seemed to make sense at the time it was made, but turned > out to be an annoyance. It's a wart on Python 3, but fortunately one > which is fairly easily dealt with by a helper function. I don't think I agree with you, but that may just be my heritage as a C programmer. Every time I've iterated over a byte string, I've really meant bytes (as in integers). Those bytes may correspond to ASCII characters, but that's just a detail. -- Rhodri James *-* Kynesim Ltd From marko at pacujo.net Tue Jul 17 09:14:41 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 16:14:41 +0300 Subject: Cult-like behaviour [was Re: Kindness] References: <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> <68c663cb-b553-9a5e-5365-999206d03903@kynesim.co.uk> Message-ID: <87k1puuhq6.fsf@elektro.pacujo.net> Rhodri James : > On 17/07/18 02:17, Steven D'Aprano wrote: >> Ah yes, the unfortunate design error that iterating over byte-strings >> returns ints rather than single-byte strings. >> >> That decision seemed to make sense at the time it was made, but turned >> out to be an annoyance. It's a wart on Python 3, but fortunately one >> which is fairly easily dealt with by a helper function. > > I don't think I agree with you, but that may just be my heritage as a C > programmer. Every time I've iterated over a byte string, I've really > meant bytes (as in integers). Those bytes may correspond to ASCII > characters, but that's just a detail. The practical issue is how you refer to ASCII bytes. What I've resorted to is: if nxt == b":"[0]: ... Alternatively, I *could* write: if nxt in b":": ... What's your favorite way of expressing character constants? Marko From tjol at tjol.eu Tue Jul 17 09:48:51 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 17 Jul 2018 15:48:51 +0200 Subject: Users banned In-Reply-To: References: <5B4B8391.3060808@stoneleaf.us> <877elw2ndr.fsf@elektro.pacujo.net> Message-ID: On 2018-07-16 01:29, Jon Ribbens wrote: > On 2018-07-15, Chris Angelico wrote: >> On Mon, Jul 16, 2018 at 7:35 AM, Marko Rauhamaa wrote: >>> Christian Gollwitzer : >>>> Am 15.07.18 um 19:25 schrieb Ethan Furman: >>>>> The following users are now banned from Python List: >>>>> ... >>>>> BartC >>>> >>>> I don't really think that this is appropriate. Bart may have deviant >>>> optinions, mostly he thinks that his own work is superior to Python - >>>> but he has always argued in a calm and technical manner. >>> >>> +1 >> >> How about we trust the moderators to moderate wisely? > > Do you have any reason to believe the message at the top of the > thread purporting to ban users was genuinely from the moderators? > Because there are obvious reasons to believe otherwise. > Care to elaborate? From __peter__ at web.de Tue Jul 17 10:19:58 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Jul 2018 16:19:58 +0200 Subject: Cult-like behaviour [was Re: Kindness] References: <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> <68c663cb-b553-9a5e-5365-999206d03903@kynesim.co.uk> <87k1puuhq6.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > The practical issue is how you refer to ASCII bytes. What I've resorted > to is: > > if nxt == b":"[0]: > ... You seem to have the compiler's blessing: >>> def f(c): ... return c == b":"[0] ... >>> import dis >>> dis.dis(f) 2 0 LOAD_FAST 0 (c) 3 LOAD_CONST 3 (58) 6 COMPARE_OP 2 (==) 9 RETURN_VALUE > What's your favorite way of expressing character constants? Before I've seen your way I would have written COLON = ord(":") ... if nxt == COLON: ... From __peter__ at web.de Tue Jul 17 10:22:56 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 17 Jul 2018 16:22:56 +0200 Subject: Python 2.7 can find cairo libs but not Python 3.6 References: <72d590d2-d1c6-5e88-6f89-8b7125477154@VybeNetworks.com> <3644c7bd-1e3e-73c7-18cf-24b923be1853@VybeNetworks.com> Message-ID: D'Arcy Cain wrote: > I just realized that my subject was backwards. It's 2.7 that can find > the libs and 3.6 than cannot. Just in case that makes a difference. Not for me, I believed the pasted shell session rather then the subject line. From alister.ware at ntlworld.com Tue Jul 17 10:37:33 2018 From: alister.ware at ntlworld.com (Alister) Date: Tue, 17 Jul 2018 14:37:33 GMT Subject: test for absence of infinite loop References: Message-ID: On Tue, 17 Jul 2018 10:10:49 +0100, Robin Becker wrote: > A user reported an infinite loop in reportlab. I determined a possible > cause and fix and would like to test for absence of the loop. Is there > any way to check for presence/absence of an infinite loop in python? I > imagine we could do something like call an external process and see if > it takes too long, but that seems a bit flaky. google halting problem & you will see that this is an impossible request -- I hate quotations. -- Ralph Waldo Emerson From python.list at tim.thechases.com Tue Jul 17 11:06:52 2018 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 17 Jul 2018 10:06:52 -0500 Subject: Unicode [was Re: Cult-like behaviour] In-Reply-To: <87wotuxw0x.fsf@elektro.pacujo.net> References: <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <35472340-01d9-6efc-3cb7-ae2763cee163@gmail.com> <681e0eb9-9bfb-4858-bf61-58d433a1baa9@gmail.com> <9e3a510c-9b9f-93fb-edf3-9c3517c2f87d@gmail.com> <03d85055-bf5e-f162-dda1-dffd345ed387@gmail.com> <20180716153244.50268123@bigbox.christie.dr> <87tvoyzyk0.fsf@elektro.pacujo.net> <20180716194826.7cf9b53b@bigbox.christie.dr> <87wotuxw0x.fsf@elektro.pacujo.net> Message-ID: <20180717100652.330bbcce@bigbox.christie.dr> On 2018-07-17 08:37, Marko Rauhamaa wrote: > Tim Chase : > > Wait, but now you're talking about vendors. Much of the crux of > > this discussion has been about personal scripts that don't need to > > marshal Unicode strings in and out of various functions/objects. > > In both personal and professional settings, you face the same > issues. But you don't want to build on something that will > disappear from the Linux distros. Right. Distros are moving away from ASCII-only to proper Unicode (however it is encoded) support. Certainly wouldn't want to build on something that's disappearing from distros, so best to build on Py3 and Unicode strings. ;-) -tkc From darcy at VybeNetworks.com Tue Jul 17 11:10:28 2018 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Tue, 17 Jul 2018 11:10:28 -0400 Subject: Python 2.7 can find cairo libs but not Python 3.6 In-Reply-To: References: <72d590d2-d1c6-5e88-6f89-8b7125477154@VybeNetworks.com> <3644c7bd-1e3e-73c7-18cf-24b923be1853@VybeNetworks.com> Message-ID: On 2018-07-17 10:22 AM, Peter Otten wrote: > D'Arcy Cain wrote: > >> I just realized that my subject was backwards. It's 2.7 that can find >> the libs and 3.6 than cannot. Just in case that makes a difference. > > Not for me, I believed the pasted shell session rather then the subject > line. Good plan. :-) So, I rebuilt and reinstalled a bunch of packages and now it works. I don't even know which packages made the difference. I had already reinstalled all of the obvious ones. Still not working for 3.7 on my HEAD system. Need to work on that. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From rhodri at kynesim.co.uk Tue Jul 17 11:21:52 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 17 Jul 2018 16:21:52 +0100 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: <87k1puuhq6.fsf@elektro.pacujo.net> References: <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> <68c663cb-b553-9a5e-5365-999206d03903@kynesim.co.uk> <87k1puuhq6.fsf@elektro.pacujo.net> Message-ID: <103d06ac-f6fe-d1eb-101d-9cfaf7d6e24d@kynesim.co.uk> On 17/07/18 14:14, Marko Rauhamaa wrote: > Rhodri James : >> On 17/07/18 02:17, Steven D'Aprano wrote: >>> Ah yes, the unfortunate design error that iterating over byte-strings >>> returns ints rather than single-byte strings. >>> >>> That decision seemed to make sense at the time it was made, but turned >>> out to be an annoyance. It's a wart on Python 3, but fortunately one >>> which is fairly easily dealt with by a helper function. >> >> I don't think I agree with you, but that may just be my heritage as a C >> programmer. Every time I've iterated over a byte string, I've really >> meant bytes (as in integers). Those bytes may correspond to ASCII >> characters, but that's just a detail. > > The practical issue is how you refer to ASCII bytes. What I've resorted > to is: > > if nxt == b":"[0]: > ... > > Alternatively, I *could* write: > > if nxt in b":": > ... > > What's your favorite way of expressing character constants? If I'm feeling particularly expansive, I'll do what Peter does and define COLON or use ord(":") directly. Most of the time though I'll just use: if next == 0x3a: # colon ... But then, as I said, I am mostly a C programmer who happens to write Python when he gets the chance. -- Rhodri James *-* Kynesim Ltd From neilc at norwich.edu Tue Jul 17 11:43:33 2018 From: neilc at norwich.edu (Neil Cerutti) Date: Tue, 17 Jul 2018 15:43:33 +0000 (UTC) Subject: doubling the number of tests, but not taking twice as long References: Message-ID: On 2018-07-16, Larry Martell wrote: > I had some code that did this: > > meas_regex = '_M\d+_' > meas_re = re.compile(meas_regex) > > if meas_re.search(filename): > stuff1() > else: > stuff2() > > I then had to change it to this: > > if meas_re.search(filename): > if 'MeasDisplay' in filename: > stuff1a() > else: > stuff1() > else: > if 'PatternFov' in filename: > stuff2a() > else: > stuff2() > > This code needs to process many tens of 1000's of files, and it > runs often, so it needs to run very fast. Needless to say, my > change has made it take 2x as long. Can anyone see a way to > improve that? Can you expand/improve the regex pattern so you don't have rescan the string to check for the presence of MeasDisplay and PatternFov? In other words, since you're already using the giant, Swiss Army sledgehammer of the re module, go ahead and use enough features to cover your use case. -- Neil Cerutti From marko at pacujo.net Tue Jul 17 12:58:44 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 19:58:44 +0300 Subject: What "cult-like behavior" meant (was: Re: Glyphs and graphemes References: <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <87bmb70xiz.fsf@elektro.pacujo.net> <871sc2zb3e.fsf@elektro.pacujo.net> <87h8kyxski.fsf@elektro.pacujo.net> <87k1puwb91.fsf@elektro.pacujo.net> <877eluw8yq.fsf@elektro.pacujo.net> Message-ID: <87601dyf23.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Jul 17, 2018 at 6:41 PM, Marko Rauhamaa wrote: >> I can see that the bullying behavior comes from exasperation instead of >> an outright meanness. They sincerely believe they understand the issues >> better than their opponents and are at a loss to get the message across >> without resorting to ad hominems. > > Have you considered the possibility that you're the one who doesn't > understand the issues? Of course. But I hope my argumentation has always been on the topic and never perceived as a personal attack on other participants. > Possible evidence to support this fact includes that many of us have > ACTUAL REAL WORLD EXPERIENCE writing code for different languages' > texts. My actual real world experience is as valid as yours, and Python3's Unicode support might be a better fit for yours than mine. Marko From python at mrabarnett.plus.com Tue Jul 17 13:58:35 2018 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 17 Jul 2018 18:58:35 +0100 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <20180716212520.7d560841@bigbox.christie.dr> References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> <20180716212520.7d560841@bigbox.christie.dr> Message-ID: On 2018-07-17 03:25, Tim Chase wrote: > On 2018-07-17 01:08, Steven D'Aprano wrote: >> In English, I think most people would prefer to use a different >> term for whatever "sh" and "ch" represent than "character". > > The term you may be reaching for is "consonant cluster"? > > https://en.wikipedia.org/wiki/Consonant_cluster > They are digraphs, 2 characters that are treated as a single unit. As it says in the first paragraph: "a consonant cluster, consonant sequence or consonant compound is a group of consonants which have no intervening vowel." "sh" is a single phoneme (sound) that happens to be written in English with 2 letters. "ch" usually represents 2 phonemes, basically the sounds of "t" followed by "sh"; other times it's "k" (e.g. in "echo"); occasionally it's "sh" (e.g. in "champagne"). From marko at pacujo.net Tue Jul 17 14:16:29 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 17 Jul 2018 21:16:29 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> <20180716212520.7d560841@bigbox.christie.dr> Message-ID: <87o9f5www2.fsf@elektro.pacujo.net> MRAB : > "ch" usually represents 2 phonemes, basically the sounds of "t" > followed by "sh"; Traditionally, that sound is considered a single phoneme: Can you hear the difference in these expressions: high chairs height shares height chairs Try them on an English-speaking person. In a restaurant, ask for a "height share" and see if they bring you a high chair. The English "tr" sound can also be considered a single affricate phoneme: Is there a difference between these expressions: rye train right rain right train Marko From breamoreboy at gmail.com Tue Jul 17 14:31:14 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Tue, 17 Jul 2018 19:31:14 +0100 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <87o9f5www2.fsf@elektro.pacujo.net> References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> <20180716212520.7d560841@bigbox.christie.dr> <87o9f5www2.fsf@elektro.pacujo.net> Message-ID: On 17/07/18 19:16, Marko Rauhamaa wrote: > MRAB : >> "ch" usually represents 2 phonemes, basically the sounds of "t" >> followed by "sh"; > > Traditionally, that sound is considered a single phoneme: > > > > Can you hear the difference in these expressions: > > high chairs > > height shares > > height chairs > > Try them on an English-speaking person. In a restaurant, ask for a > "height share" and see if they bring you a high chair. > > The English "tr" sound can also be considered a single affricate > phoneme: > > > > Is there a difference between these expressions: > > rye train > > right rain > > right train > > > Marko > I do not see what this has to do with the Python programming language, neither do I care. Please take this offline, as you've all ready been asked to do by a moderator, Tim Golden. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rhodri at kynesim.co.uk Tue Jul 17 14:46:27 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 17 Jul 2018 19:46:27 +0100 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <87o9f5www2.fsf@elektro.pacujo.net> References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> <20180716212520.7d560841@bigbox.christie.dr> <87o9f5www2.fsf@elektro.pacujo.net> Message-ID: On 17/07/18 19:16, Marko Rauhamaa wrote: > MRAB : >> "ch" usually represents 2 phonemes, basically the sounds of "t" >> followed by "sh"; > > Traditionally, that sound is considered a single phoneme: > > To quote the introduction of that article, "It is often difficult to decide if a stop and fricative form a single phoneme or a consonant pair." I'm afraid your bold assertion is more than a bit arguable. > Can you hear the difference in these expressions: > > high chairs > > height shares > > height chairs Yes, but then I'm a trained singer. > Try them on an English-speaking person. In a restaurant, ask for a > "height share" and see if they bring you a high chair. That's a different effect. Listeners will often subconsciously make small "corrections" to what they hear to bring it into context. It is particularly noticeable in experiments where one person repeats what another says while they are still speaking -- effectively simultaneous translation without the translation part :-) The person repeating will correct small mistakes in what was originally said without ever noticing the error. (Google is being annoying and not supplying me with the information, but I know there have been papers on this.) > > The English "tr" sound can also be considered a single affricate > phoneme: > > > > Is there a difference between these expressions: > > rye train > > right rain > > right train Again, yes. Very much so this time. -- Rhodri James *-* Kynesim Ltd From marcelo.huerta at gmail.com Tue Jul 17 15:37:50 2018 From: marcelo.huerta at gmail.com (MGHSM) Date: Tue, 17 Jul 2018 12:37:50 -0700 (PDT) Subject: Python-List is a tyrannical, one-party dictatorship that hates free speech! In-Reply-To: <766b656b-1aed-42d7-be66-2bd37eaf02f6@googlegroups.com> References: <766b656b-1aed-42d7-be66-2bd37eaf02f6@googlegroups.com> Message-ID: <136b28e6-6d48-4495-8026-ac573cef1488@googlegroups.com> ObXkcd: https://xkcd.com/1357/ From tjreedy at udel.edu Tue Jul 17 16:22:11 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 17 Jul 2018 16:22:11 -0400 Subject: test for absence of infinite loop In-Reply-To: <3e561b62-599a-bccd-6a41-5011455efe28@chamonix.reportlab.co.uk> References: <20180717111630.GA38537@cskk.homeip.net> <3e561b62-599a-bccd-6a41-5011455efe28@chamonix.reportlab.co.uk> Message-ID: On 7/17/2018 7:39 AM, Robin Becker wrote: > well I understand the problem about not halting. However as you point > out in a fixed case I know that the test should take fractions of a > second to complete. If nothing else, you can easily add def test_xyz_completes(self): xyz(args) # Former infinite loop I assume that your test runner has some time limit at some level of granularity. You may be able to add a timeout for a particular test. -- Terry Jan Reedy From jon+usenet at unequivocal.eu Tue Jul 17 18:10:05 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 17 Jul 2018 22:10:05 -0000 (UTC) Subject: Users banned References: <5B4B8391.3060808@stoneleaf.us> <877elw2ndr.fsf@elektro.pacujo.net> Message-ID: On 2018-07-17, Thomas Jollans wrote: > On 2018-07-16 01:29, Jon Ribbens wrote: >> Do you have any reason to believe the message at the top of the >> thread purporting to ban users was genuinely from the moderators? >> Because there are obvious reasons to believe otherwise. > > Care to elaborate? Anyone can trivially forge a message from anyone, so there is no reason to believe the message is genuine. Reasons to believe it is not genuine include the poor formatting, poorly-written content, inconsistent and insulting way the 'banned users' are referred to, and the fact that out of the three people it purports to ban, one was apparently already banned and another appears not to be a current poster anyway. If it is a genuine message from the moderators then they really need to improve their policy to give clear warnings to people before they are banned, and they need to PGP-sign official messages so that they can be recognised. From tjol at tjol.eu Tue Jul 17 18:34:16 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 18 Jul 2018 00:34:16 +0200 Subject: Users banned In-Reply-To: References: <5B4B8391.3060808@stoneleaf.us> <877elw2ndr.fsf@elektro.pacujo.net> Message-ID: On 18/07/18 00:10, Jon Ribbens wrote: > On 2018-07-17, Thomas Jollans wrote: >> On 2018-07-16 01:29, Jon Ribbens wrote: >>> Do you have any reason to believe the message at the top of the >>> thread purporting to ban users was genuinely from the moderators? >>> Because there are obvious reasons to believe otherwise. >> >> Care to elaborate? > > Anyone can trivially forge a message from anyone, so there is no > reason to believe the message is genuine. Reasons to believe it is > not genuine include the poor formatting, poorly-written content, > inconsistent and insulting way the 'banned users' are referred to, > and the fact that out of the three people it purports to ban, one > was apparently already banned and another appears not to be a current > poster anyway. > > If it is a genuine message from the moderators then they really need > to improve their policy to give clear warnings to people before they > are banned, and they need to PGP-sign official messages so that they > can be recognised. > Perhaps, if there were more messages from moderators. On the other hand, headers from mail.python.org indicate that the message came from the right mail server (rather harder to fake), and I'm sure Ethan (who has been active since) or one of the other moderators would have said something if this were fake. As for clear warnings, as Terry said, we don't know what did or didn't happen in private emails. On 15/07/18 23:53, Chris Angelico wrote: > How about we trust the moderators to moderate wisely? From roel at roelschroeven.net Tue Jul 17 18:38:49 2018 From: roel at roelschroeven.net (Roel Schroeven) Date: Wed, 18 Jul 2018 00:38:49 +0200 Subject: Cult-like behaviour [was Re: Kindness] In-Reply-To: References: <87va9h4pyt.fsf@elektro.pacujo.net> <87sh4lqu6u.fsf@nightsong.com> <87d0vp3qds.fsf@elektro.pacujo.net> <87d0vpgcr0.fsf@nightsong.com> <874lh051p9.fsf@elektro.pacujo.net> <305ff411-63cd-ea4c-49d8-cbcb86db8874@gmail.com> <3b6a0137-9ec9-6cb4-2ed9-55bca4c7e5c2@gmail.com> <87y3ec184j.fsf@elektro.pacujo.net> <133a3832-b1b4-ea89-0a45-64e0913abdf3@gmail.com> Message-ID: Chris Angelico schreef op 17/07/2018 0:48: > On Tue, Jul 17, 2018 at 8:41 AM, Roel Schroeven wrote: >> In any case, even though Python 3's byte strings are not quite unlike Python >> 2's strings, they're not exactly like them either. And I feel there are >> cases where that makes things somewhat harder, even though I can't prove it. > > You're absolutely right, and some of those differences were repaired > in different 3.x versions (for instance, the ability to use > percent-formatting with byte strings was reinstated in 3.5). Indeed, and that was very helpful. > Some of the differences are fundamental, but anything else should be > considered fair game for an enhancement request. So next time you go > "ugh, Python 3's byte strings are such a pain because XYZ", post here > or on python-ideas about a possible fix. I'll remember that. > That said, though, the fact that indexing a byte string yields an int > instead of a one-byte string is basically unable to be changed now, > and IMO it'd be better to be consistent with text strings than with > bytearray. I'm not sure how many of the core devs agree that > b'spam'[1] ought to be b'p' rather than 112, but I'd say they all > agree that it's too late to change it. I had expected b'spam'[1] would be b'p', and it took me some to figure out it was 112 and that that was why my code wasn't working anymore when I converted it from Python 2 to Python 3. But that doesn't necessarily mean b'p' would have been better than 112. A case can be made for both. I'm aware of it now, and it's not a big deal anymore. And indeed, too late to change. -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From sleadpc at gmail.com Tue Jul 17 18:48:22 2018 From: sleadpc at gmail.com (S Lea) Date: Tue, 17 Jul 2018 15:48:22 -0700 Subject: can't install/run pip (Latest version of Python) In-Reply-To: <201807162347.11233.gheskett@shentel.net> References: <201807162347.11233.gheskett@shentel.net> Message-ID: nd that leads to a question, where did you get it?, and how long ago? Maybe its an old version? Head scratcher for sure. I have 3.7, downloaded a week ago https://www.python.org/downloads/ Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> Is this what you were suggesting? On Mon, Jul 16, 2018 at 8:47 PM, Gene Heskett wrote: > On Monday 16 July 2018 23:06:19 S Lea wrote: > > > 'pip' not recognized as internal or external command, operable program > > or batch. > > > > And for some reason it's a 32 bit version > > > Huh? My ancient wet ram memory is probably out to lunch, but ISTR reading > about someone else with the same problem at least a year ago on this > list, unfortunately I have a 90 day expiry setup on this list so > searching is just an exercise. My email corpus is nearly 20 gigabytes > now. > > pip has been around since it seems forever, but I would have thought by > now it would have been rebuilt for 64 bit systems. And that leads to a > question, where did you get it?, and how long ago? Maybe its an old > version? Head scratcher for sure. > > > On Mon, Jul 16, 2018 at 8:03 PM, S Lea wrote: > > > Thank you for reaching out. > > > > > > 1) Don't know what do you mean by the traceback. > > What you see in the terminal screen you ran it in. It should a press the > left mouse button and wipe the mouse from beginning to end so its all > highlighted, then position the curser in an email and press the middle > mouse button, which should copy the highlighted text into the email. > > > > 2) In DOS, pip install pandas > > > 3) Yes, in DOS, Win 10 > > > 4) 3.7 > > > 5) Not getting much info > > > > > > On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp > wrote: > > >> On Sun, Jul 15, 2018 at 7:34 PM S Lea wrote: > > >> > I can't seem to install the pips, DOS gives me the syntex i > > >> > invalid, > > >> > > >> any > > >> > > >> > thoughts?? > > >> > > >> You provide insufficient information for anyone to be able to help > > >> you. > > >> > > >> 1) Copy and paste the entire traceback into a plain text email, no > > >> screen shots please. > > >> 2) Copy and paste exactly what you typed that generated the syntax > > >> error. 3) Did you do all of this in cmd.exe in what version of > > >> Windows? Or did you use something else? Hopefully not in the > > >> interactive Python interpreter or IDLE! > > >> 4) What Python version are you using? > > >> 5) Did you try searching for the exact error message and see what > > >> answers might already be out there? > > >> > > >> If you provide these things, or, better, search and find the answer > > >> yourself, I'm sure someone will be happy to assist. > > >> > > >> Good luck! > > >> -- > > >> boB > > >> -- > > >> https://mail.python.org/mailman/listinfo/python-list > > > > -- > Cheers, Gene Heskett > -- > "There are four boxes to be used in defense of liberty: > soap, ballot, jury, and ammo. Please use in that order." > -Ed Howdershelt (Author) > Genes Web page > -- > https://mail.python.org/mailman/listinfo/python-list > From sleadpc at gmail.com Tue Jul 17 19:04:38 2018 From: sleadpc at gmail.com (S Lea) Date: Tue, 17 Jul 2018 16:04:38 -0700 Subject: can't install/run pip (Latest version of Python) In-Reply-To: References: Message-ID: Terry, BLESS YOU!!! The second option worked I installed python 3.7 and then pycharm-community-2018.1.4. I'm following a video course by TTC How To Program: Computer Science Concepts And Python Exercises. The instructor suggested to install pycharm community. I'm also following a few youtube videos on data analyses. Like sentdex, https://www.youtube.com/user/sentdex, but he is pretty advanced, even his basic tutorials. I didn't touch programming from HS about 20yrs ago. Is python a good way to start and learn or use anaconda? This guy from sendex uses IDLE, but after I installed pycharms, I can't bring it up and the background is black, but I started w/ white. Would you suggest resources to learn from? I'm in finance and it seems python is way ahead of excel. Thank you, Stan C:\Users\Precision>py -3.7 -m pip install pandas Collecting pandas Downloading https://files.pythonhosted.org/packages/a9/e8/ ca7637c51767809cd7328dd01e246b8f2ec0fde566c9b7440b91d9a33460 /pandas-0.23.3-cp37-cp37m-win32.whl (6.8MB) 100% |????????????????????????????????| 6.8MB 620kB/s Collecting pytz>=2011k (from pandas) Downloading https://files.pythonhosted.org/packages/30/4e/ 27c34b62430286c6d59177a0842ed90dc789ce5d1ed740887653b898779a /pytz-2018.5-py2.py3-none-any.whl (510kB) 100% |????????????????????????????????| 512kB 810kB/s Collecting python-dateutil>=2.5.0 (from pandas) Downloading https://files.pythonhosted.org/packages/cf/f5/ af2b09c957ace60dcfac112b669c45c8c97e32f94aa8b56da4c6d1682825 /python_dateutil-2.7.3-py2.py3-none-any.whl (211kB) 100% |????????????????????????????????| 215kB 646kB/s Collecting numpy>=1.9.0 (from pandas) Downloading https://files.pythonhosted.org/packages/6c/28/ 010d2433a02bdb7a2d20638953cdb8c6b0324b9c5c431e444a5c5ad40dd7 /numpy-1.14.5-cp37-none-win32.whl (9.8MB) 100% |????????????????????????????????| 9.8MB 661kB/s Collecting six>=1.5 (from python-dateutil>=2.5.0->pandas) Downloading https://files.pythonhosted.org/packages/67/4b/ 141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a /six-1.11.0-py2.py3-none-any.whl Installing collected packages: pytz, six, python-dateutil, numpy, pandas On Tue, Jul 17, 2018 at 12:09 AM, Terry Reedy wrote: > On 7/16/2018 11:03 PM, S Lea wrote: > > Some additional info, which allows me to say the following: > > 1) Don't know what do you mean by the traceback. >> > > >>> 1/o > Traceback (most recent call last): > File "", line 1, in > 1/o > NameError: name 'o' is not defined > > The last four lines > > 2) In DOS, pip install pandas >> > > Try the core-developer recommended way to run modules: > python -m pip install pandas > or, if you installed the py launcher and have multiple python versions > py -3.7 -m pip install pandas > > If you see something about pip not being installed, > python -m ensurepip > > 3) Yes, in DOS, Win 10 >> > > Crucial info. > > 4) 3.7 >> > > Allowed me to specify how to specifically launch 3.7. > > > 5) Not getting much info >> > > -- > Terry Jan Reedy > > -- > https://mail.python.org/mailman/listinfo/python-list > From sleadpc at gmail.com Tue Jul 17 19:24:01 2018 From: sleadpc at gmail.com (S Lea) Date: Tue, 17 Jul 2018 16:24:01 -0700 Subject: can't install/run pip (Latest version of Python) In-Reply-To: References: Message-ID: Also, how does one get a 64 bit version? On Tue, Jul 17, 2018 at 4:04 PM, S Lea wrote: > Terry, > > BLESS YOU!!! > > The second option worked I installed python 3.7 and > then pycharm-community-2018.1.4. I'm following a video course by TTC How > To Program: Computer Science Concepts And Python Exercises. The instructor > suggested to install pycharm community. I'm also following a few youtube > videos on data analyses. Like sentdex, https://www.youtube. > com/user/sentdex, but he is pretty advanced, even his basic tutorials. I > didn't touch programming from HS about 20yrs ago. Is python a good way to > start and learn or use anaconda? This guy from sendex uses IDLE, but after > I installed pycharms, I can't bring it up and the background is black, but > I started w/ white. > Would you suggest resources to learn from? I'm in finance and it seems > python is way ahead of excel. > > Thank you, > Stan > > C:\Users\Precision>py -3.7 -m pip install pandas > Collecting pandas > Downloading https://files.pythonhosted.org/packages/a9/e8/ca7637c5176780 > 9cd7328dd01e246b8f2ec0fde566c9b7440b91d9a33460/pandas-0.23. > 3-cp37-cp37m-win32.whl (6.8MB) > 100% |????????????????????????????????| 6.8MB 620kB/s > Collecting pytz>=2011k (from pandas) > Downloading https://files.pythonhosted.org/packages/30/4e/27c34b62430286 > c6d59177a0842ed90dc789ce5d1ed740887653b898779a/pytz-2018.5- > py2.py3-none-any.whl (510kB) > 100% |????????????????????????????????| 512kB 810kB/s > Collecting python-dateutil>=2.5.0 (from pandas) > Downloading https://files.pythonhosted.org/packages/cf/f5/af2b09c957ace6 > 0dcfac112b669c45c8c97e32f94aa8b56da4c6d1682825/python_ > dateutil-2.7.3-py2.py3-none-any.whl (211kB) > 100% |????????????????????????????????| 215kB 646kB/s > Collecting numpy>=1.9.0 (from pandas) > Downloading https://files.pythonhosted.org/packages/6c/28/010d2433a02bdb > 7a2d20638953cdb8c6b0324b9c5c431e444a5c5ad40dd7/numpy-1.14.5- > cp37-none-win32.whl (9.8MB) > 100% |????????????????????????????????| 9.8MB 661kB/s > Collecting six>=1.5 (from python-dateutil>=2.5.0->pandas) > Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6 > 397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0- > py2.py3-none-any.whl > Installing collected packages: pytz, six, python-dateutil, numpy, pandas > > On Tue, Jul 17, 2018 at 12:09 AM, Terry Reedy wrote: > >> On 7/16/2018 11:03 PM, S Lea wrote: >> >> Some additional info, which allows me to say the following: >> >> 1) Don't know what do you mean by the traceback. >>> >> >> >>> 1/o >> Traceback (most recent call last): >> File "", line 1, in >> 1/o >> NameError: name 'o' is not defined >> >> The last four lines >> >> 2) In DOS, pip install pandas >>> >> >> Try the core-developer recommended way to run modules: >> python -m pip install pandas >> or, if you installed the py launcher and have multiple python versions >> py -3.7 -m pip install pandas >> >> If you see something about pip not being installed, >> python -m ensurepip >> >> 3) Yes, in DOS, Win 10 >>> >> >> Crucial info. >> >> 4) 3.7 >>> >> >> Allowed me to specify how to specifically launch 3.7. >> >> >> 5) Not getting much info >>> >> >> -- >> Terry Jan Reedy >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > From cs at cskk.id.au Tue Jul 17 19:28:10 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 18 Jul 2018 09:28:10 +1000 Subject: test for absence of infinite loop In-Reply-To: <3e561b62-599a-bccd-6a41-5011455efe28@chamonix.reportlab.co.uk> References: <3e561b62-599a-bccd-6a41-5011455efe28@chamonix.reportlab.co.uk> Message-ID: <20180717232810.GA24859@cskk.homeip.net> On 17Jul2018 12:39, Robin Becker wrote: >On 17/07/2018 12:16, Cameron Simpson wrote: >>On 17Jul2018 10:10, Robin Becker wrote: >>>A user reported an infinite loop in reportlab. I determined a >>>possible cause and fix and would like to test for absence of the >>>loop. Is there any way to check for presence/absence of an >>>infinite loop in python? I imagine we could do something like call >>>an external process and see if it takes too long, but that seems a >>>bit flaky. >> >>While others have kindly pointed you at the halting problem >>(unsolvable in the general case) you can usually verify that the >>specific problem you fixed is fixed. Can you figure out how long the >>task should run with your fix in a test case? Not as time, but in >>loop iterations? Put a counter in the loop and check that its value >>doesn't exceed that. > >well I understand the problem about not halting. However as you point >out in a fixed case I know that the test should take fractions of a >second to complete. I certainly don't want to put instrumentation into >the source code. It's relatively easy to imagine polling termination >of a separate thread/process, but that's not particularly reliable. I >don't know if there is a way to ask a python interpeter how many instructions >it has carried out. Hmm. You can set a hard timeout with signal.alarm. Something like: import signal def test_timeout(maxtime): signal.alarm(maxtime) your_looping_function(...) signal.alarm(0) The OS (if UNIX) will send SIGALRM after that number of seconds, which should abort the program by raising an exception. So any test suite will fail the test, or a bare test run will terminate anyway without running forever. Cheers, Cameron Simpson From gheskett at shentel.net Tue Jul 17 20:14:37 2018 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 17 Jul 2018 20:14:37 -0400 Subject: can't install/run pip (Latest version of Python) In-Reply-To: References: <201807162347.11233.gheskett@shentel.net> Message-ID: <201807172014.37759.gheskett@shentel.net> On Tuesday 17 July 2018 18:48:22 S Lea wrote: > nd that leads to a > question, where did you get it?, and how long ago? Maybe its an old > version? Head scratcher for sure. > > I have 3.7, downloaded a week ago > https://www.python.org/downloads/ > > Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 > bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > > Is this what you were suggesting? I wasn't clear enough, I was referring to your 'pip' install. But since this idents the 3.7 as 32 bit, I wonder if there is a 64 bit version there too. Yes, there are 3 of each, and I suspect you need the x86-64 versions. Or I could be full of it, the last windows install I allowed here was XP, and when I found its drivers couldn't run the radio in an HP lappy I had bought for a road machine, the drive got formatted and mandrake installed, which at least tried to run the radio. So other than configuring friends networking on more recent windows installs, I have essentially zero windows expertise. Windows is a disease I try very hard to stay away from. So I'll bow out and let someone more knowledgable step in. > > On Mon, Jul 16, 2018 at 8:47 PM, Gene Heskett wrote: > > On Monday 16 July 2018 23:06:19 S Lea wrote: > > > 'pip' not recognized as internal or external command, operable > > > program or batch. > > > > > > And for some reason it's a 32 bit version > > > > Huh? My ancient wet ram memory is probably out to lunch, but ISTR > > reading about someone else with the same problem at least a year ago > > on this list, unfortunately I have a 90 day expiry setup on this > > list so searching is just an exercise. My email corpus is nearly 20 > > gigabytes now. > > > > pip has been around since it seems forever, but I would have thought > > by now it would have been rebuilt for 64 bit systems. And that > > leads to a question, where did you get it?, and how long ago? Maybe > > its an old version? Head scratcher for sure. > > > > > On Mon, Jul 16, 2018 at 8:03 PM, S Lea wrote: > > > > Thank you for reaching out. > > > > > > > > 1) Don't know what do you mean by the traceback. > > > > What you see in the terminal screen you ran it in. It should a press > > the left mouse button and wipe the mouse from beginning to end so > > its all highlighted, then position the curser in an email and press > > the middle mouse button, which should copy the highlighted text into > > the email. > > > > > > 2) In DOS, pip install pandas > > > > 3) Yes, in DOS, Win 10 > > > > 4) 3.7 > > > > 5) Not getting much info > > > > > > > > On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp > > > > > > > > wrote: > > > >> On Sun, Jul 15, 2018 at 7:34 PM S Lea wrote: > > > >> > I can't seem to install the pips, DOS gives me the syntex i > > > >> > invalid, > > > >> > > > >> any > > > >> > > > >> > thoughts?? > > > >> > > > >> You provide insufficient information for anyone to be able to > > > >> help you. > > > >> > > > >> 1) Copy and paste the entire traceback into a plain text email, > > > >> no screen shots please. > > > >> 2) Copy and paste exactly what you typed that generated the > > > >> syntax error. 3) Did you do all of this in cmd.exe in what > > > >> version of Windows? Or did you use something else? Hopefully > > > >> not in the interactive Python interpreter or IDLE! > > > >> 4) What Python version are you using? > > > >> 5) Did you try searching for the exact error message and see > > > >> what answers might already be out there? > > > >> > > > >> If you provide these things, or, better, search and find the > > > >> answer yourself, I'm sure someone will be happy to assist. > > > >> > > > >> Good luck! > > > >> -- > > > >> boB > > > >> -- > > > >> https://mail.python.org/mailman/listinfo/python-list > > > > -- > > Cheers, Gene Heskett > > -- > > "There are four boxes to be used in defense of liberty: > > soap, ballot, jury, and ammo. Please use in that order." > > -Ed Howdershelt (Author) > > Genes Web page > > -- > > https://mail.python.org/mailman/listinfo/python-list -- Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From sleadpc at gmail.com Tue Jul 17 20:47:04 2018 From: sleadpc at gmail.com (S Lea) Date: Tue, 17 Jul 2018 17:47:04 -0700 Subject: can't install/run pip (Latest version of Python) In-Reply-To: <201807172014.37759.gheskett@shentel.net> References: <201807162347.11233.gheskett@shentel.net> <201807172014.37759.gheskett@shentel.net> Message-ID: What do you use, Gene? It seems most business program run on Windows. On Tue, Jul 17, 2018 at 5:14 PM, Gene Heskett wrote: > On Tuesday 17 July 2018 18:48:22 S Lea wrote: > > > nd that leads to a > > question, where did you get it?, and how long ago? Maybe its an old > > version? Head scratcher for sure. > > > > I have 3.7, downloaded a week ago > > https://www.python.org/downloads/ > > > > Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 > > bit (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > > > > Is this what you were suggesting? > > I wasn't clear enough, I was referring to your 'pip' install. But since > this idents the 3.7 as 32 bit, I wonder if there is a 64 bit version > there too. Yes, there are 3 of each, and I suspect you need the x86-64 > versions. > > Or I could be full of it, the last windows install I allowed here was XP, > and when I found its drivers couldn't run the radio in an HP lappy I had > bought for a road machine, the drive got formatted and mandrake > installed, which at least tried to run the radio. So other than > configuring friends networking on more recent windows installs, I have > essentially zero windows expertise. Windows is a disease I try very hard > to stay away from. > > So I'll bow out and let someone more knowledgable step in. > > > > > On Mon, Jul 16, 2018 at 8:47 PM, Gene Heskett > wrote: > > > On Monday 16 July 2018 23:06:19 S Lea wrote: > > > > 'pip' not recognized as internal or external command, operable > > > > program or batch. > > > > > > > > And for some reason it's a 32 bit version > > > > > > Huh? My ancient wet ram memory is probably out to lunch, but ISTR > > > reading about someone else with the same problem at least a year ago > > > on this list, unfortunately I have a 90 day expiry setup on this > > > list so searching is just an exercise. My email corpus is nearly 20 > > > gigabytes now. > > > > > > pip has been around since it seems forever, but I would have thought > > > by now it would have been rebuilt for 64 bit systems. And that > > > leads to a question, where did you get it?, and how long ago? Maybe > > > its an old version? Head scratcher for sure. > > > > > > > On Mon, Jul 16, 2018 at 8:03 PM, S Lea wrote: > > > > > Thank you for reaching out. > > > > > > > > > > 1) Don't know what do you mean by the traceback. > > > > > > What you see in the terminal screen you ran it in. It should a press > > > the left mouse button and wipe the mouse from beginning to end so > > > its all highlighted, then position the curser in an email and press > > > the middle mouse button, which should copy the highlighted text into > > > the email. > > > > > > > > 2) In DOS, pip install pandas > > > > > 3) Yes, in DOS, Win 10 > > > > > 4) 3.7 > > > > > 5) Not getting much info > > > > > > > > > > On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp > > > > > > > > > > > wrote: > > > > >> On Sun, Jul 15, 2018 at 7:34 PM S Lea wrote: > > > > >> > I can't seem to install the pips, DOS gives me the syntex i > > > > >> > invalid, > > > > >> > > > > >> any > > > > >> > > > > >> > thoughts?? > > > > >> > > > > >> You provide insufficient information for anyone to be able to > > > > >> help you. > > > > >> > > > > >> 1) Copy and paste the entire traceback into a plain text email, > > > > >> no screen shots please. > > > > >> 2) Copy and paste exactly what you typed that generated the > > > > >> syntax error. 3) Did you do all of this in cmd.exe in what > > > > >> version of Windows? Or did you use something else? Hopefully > > > > >> not in the interactive Python interpreter or IDLE! > > > > >> 4) What Python version are you using? > > > > >> 5) Did you try searching for the exact error message and see > > > > >> what answers might already be out there? > > > > >> > > > > >> If you provide these things, or, better, search and find the > > > > >> answer yourself, I'm sure someone will be happy to assist. > > > > >> > > > > >> Good luck! > > > > >> -- > > > > >> boB > > > > >> -- > > > > >> https://mail.python.org/mailman/listinfo/python-list > > > > > > -- > > > Cheers, Gene Heskett > > > -- > > > "There are four boxes to be used in defense of liberty: > > > soap, ballot, jury, and ammo. Please use in that order." > > > -Ed Howdershelt (Author) > > > Genes Web page > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > Cheers, Gene Heskett > -- > "There are four boxes to be used in defense of liberty: > soap, ballot, jury, and ammo. Please use in that order." > -Ed Howdershelt (Author) > Genes Web page > -- > https://mail.python.org/mailman/listinfo/python-list > From dieter at handshake.de Wed Jul 18 00:58:15 2018 From: dieter at handshake.de (dieter) Date: Wed, 18 Jul 2018 06:58:15 +0200 Subject: test for absence of infinite loop References: Message-ID: <87in5d87iw.fsf@handshake.de> Robin Becker writes: > A user reported an infinite loop in reportlab. I determined a possible > cause and fix and would like to test for absence of the loop. Is there > any way to check for presence/absence of an infinite loop in python? I > imagine we could do something like call an external process and see if > it takes too long, but that seems a bit flaky. On some systems (among them Linux), you can limit (some) resources used by a process, among them the CPU time. If a process exceeds the limit, it is killed by the operating system. The "bash" makes this available with the "ulimit" command. On Linux, there is also the "timeout" command (with a similar effect). From antoon.pardon at vub.be Wed Jul 18 03:31:30 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 18 Jul 2018 09:31:30 +0200 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <87pnzmuk52.fsf@elektro.pacujo.net> References: <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> <87fu0iw9l5.fsf@elektro.pacujo.net> <87pnzmuk52.fsf@elektro.pacujo.net> Message-ID: On 17-07-18 14:22, Marko Rauhamaa wrote: > Antoon Pardon : > >> On 17-07-18 10:27, Marko Rauhamaa wrote: >>> Also, Python2's strings do as good a job at delivering codepoints as >>> Python3. >> No they don't. The programs that I work on, need to be able to treat >> at least german, french, dutch and english text. My experience is that >> in python3 it is way easier to do things right. Especially if you are >> working with regular expressions. > If you assume that NFC normalizes every letter to a single codepoint > (and carefully use NFC everywhere), you are right. But equally likely > you may inadvertently be setting yourself up for a surprise. You are moving the goal post. I didn't claim there were no surprises. I only claim that in the end combining regular expressions and working with multiple languages ended up being far easier with python3 strings than with python2 strings. Sure there were some surprises or gotcha's, but the result was still better than doing it in python2 and they were easier to deal with than in python2. -- Antoon. From marko at pacujo.net Wed Jul 18 04:07:54 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 18 Jul 2018 11:07:54 +0300 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> <87fu0iw9l5.fsf@elektro.pacujo.net> <87pnzmuk52.fsf@elektro.pacujo.net> Message-ID: <87fu0huftx.fsf@elektro.pacujo.net> Antoon Pardon : > On 17-07-18 14:22, Marko Rauhamaa wrote: >> If you assume that NFC normalizes every letter to a single codepoint >> (and carefully use NFC everywhere), you are right. But equally likely >> you may inadvertently be setting yourself up for a surprise. > > You are moving the goal post. I didn't claim there were no surprises. > I only claim that in the end combining regular expressions and working > with multiple languages ended up being far easier with python3 strings > than with python2 strings. Fair enough. > Sure there were some surprises or gotcha's, but the result was still > better than doing it in python2 and they were easier to deal with than > in python2. BTW, in those needs, even Python2 has Unicode strings and unicodedata at your disposal. Marko From antoon.pardon at vub.be Wed Jul 18 04:31:52 2018 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 18 Jul 2018 10:31:52 +0200 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: <87fu0huftx.fsf@elektro.pacujo.net> References: <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <2213AD00-C770-48D4-95EF-70BA1A9CB796@Damon-family.org> <7314D93A-F8E5-4CA6-AC46-BD8AF1CDAB06@Damon-family.org> <87fu0iw9l5.fsf@elektro.pacujo.net> <87pnzmuk52.fsf@elektro.pacujo.net> <87fu0huftx.fsf@elektro.pacujo.net> Message-ID: <018bae1d-8fcf-a8d4-9e43-6dfb3147b984@vub.be> On 18-07-18 10:07, Marko Rauhamaa wrote: >> Sure there were some surprises or gotcha's, but the result was still >> better than doing it in python2 and they were easier to deal with than >> in python2. > BTW, in those needs, even Python2 has Unicode strings and unicodedata at > your disposal. Sure, just as there are byte strings at your disposal in python3. I also don't think using u'...' in python2 is less ugly than using b'...' in python3. -- Antoon. From greg.ewing at canterbury.ac.nz Wed Jul 18 05:59:28 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 18 Jul 2018 21:59:28 +1200 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87muut4g77.fsf@elektro.pacujo.net> <878t6c51v7.fsf@elektro.pacujo.net> <87tvp03f2p.fsf@elektro.pacujo.net> <87bmb82np4.fsf@elektro.pacujo.net> <56CF25F1-45E8-45A8-B390-CD265AA93C31@Damon-family.org> <9BAE8836-60C6-4755-83EA-79BE21C714F0@Damon-family.org> <20180716212520.7d560841@bigbox.christie.dr> Message-ID: MRAB wrote: > "ch" usually represents 2 phonemes, basically the sounds of "t" followed > by "sh"; That's debatable. I've never thought of it that way and I'm fairly certain I don't pronounce it that way. My tongue does not do the same thing when I say "ch" as it does when I say "tsh". -- Greg From mal at europython.eu Wed Jul 18 09:07:22 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 18 Jul 2018 15:07:22 +0200 Subject: EuroPython 2018: Introducing Smarkets Message-ID: <0abc7804-b437-03b7-2eb8-917528d7861c@europython.eu> We are very pleased to have Smarkets as Keystone Sponsor for EuroPython 2018. You can visit them at the most central booth in our exhibit area, the Lennox Suite in the EICC, and take the opportunity to chat with their staff or enjoy their escape room. Please find below a hosted blog post from Smarkets. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- Smarkets: where Python and financial trading meet ================================================= Smarkets operates one of the world?s most powerful and innovative event trading exchanges. We have engineered our technology in-house - without using white label products - and Python powers our platform. In fact, our codebase is fully Python3 and is deployed across multiple teams of engineers within our self-managed organisation. We combine financial technology with the startup culture of fast development and frequent releases; the perfect environment to make use of Python?s data science and rapid prototyping capabilities. Python language helps us to remain nimble as it allows us to move from idea to product extremely quickly. Python not only has a solid standard library but also an extensive community which means that packages exist for just about everything you could ever need. Join us at EuroPython where our workshop will show you how Smarkets is using Python to revolutionise sports trading. You will learn more about Python?s implementation on an exchange, how trading bots work and some strategies that can be employed to successfully trade sports. Put this theory in action with access to our API and a skeleton bot, which you will use as a base to create your very own trading bot. The workshop is free people with a conference ticket or training pass. Bring your laptops! Come and check out our booth #10 to learn more about life at Smarkets and what it?s like to work at the UK?s largest self-managed organisation where you get to be your own boss, define the projects you work on and even get to set your own salary. If that?s not tempting enough, we?ve got an actual escape room on our booth as one of the main attractions at EuroPython this year! If you?ve got 30 minutes to spare or simply fancy the challenge, come along and see if you can crack your way out! Successful teams will also automatically be entered into a prize draw that we?ll be running each day. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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/176018861357/europython-2018-introducing-smarkets Tweet: https://twitter.com/europython/status/1019552800785752064 Enjoy, -- EuroPython 2018 Team https://ep2018.europython.eu/ https://www.europython-society.org/ From tjol at tjol.eu Wed Jul 18 10:06:52 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 18 Jul 2018 16:06:52 +0200 Subject: can't install/run pip (Latest version of Python) In-Reply-To: References: <201807162347.11233.gheskett@shentel.net> <201807172014.37759.gheskett@shentel.net> Message-ID: <954deb06-cfbe-0724-ea22-2325892b2657@tjol.eu> On 2018-07-18 02:47, S Lea wrote: > What do you use, Gene? > It seems most business program run on Windows. Many of us here use Linux. Some just rather like it and could use any OS, while for others, software they rely on for work might only work properly, or work better, on Linux. (This might be the case for some software developers, and for some scientists and engineers). For others, Windows has a distinct advantage. Anyway, never mind Gene and his talk of diseases. > Also, how does one get a 64 bit version? When you said you were using a 32 bit version, I wondered how on earth one gets a 32 bit version. It turns out the x86-64 and x86 versions are listed on the same download pages, right below each other. You must have clicked the wrong one. From hpj at urpla.net Wed Jul 18 11:24:30 2018 From: hpj at urpla.net (Hans-Peter Jansen) Date: Wed, 18 Jul 2018 17:24:30 +0200 Subject: PyCA cryptography 2.3 released In-Reply-To: References: Message-ID: <1783944.HJ5WUi88Ja@xrated> Hi Paul, you have a version mismatch in subject and text. Cheers, Pete On Mittwoch, 18. Juli 2018 05:19:27 Paul Kehrer wrote: > PyCA cryptography 2.2.2 has been released to PyPI. cryptography includes > both high level recipes and low level interfaces to common cryptographic > algorithms such as symmetric ciphers, message digests, and key derivation > functions. We support Python 2.7, Python 3.4+, and PyPy. > > Changelog (https://cryptography.io/en/latest/changelog/#v2-3): > > * SECURITY ISSUE: finalize_with_tag() allowed tag truncation by default > which can allow tag forgery in some cases. The method now enforces the > min_tag_length provided to the GCM constructor. > * Added support for Python 3.7. > * Added extract_timestamp() to get the authenticated timestamp of a Fernet > token. > * Support for Python 2.7.x without hmac.compare_digest has been deprecated. > We will require Python 2.7.7 or higher (or 2.7.6 on Ubuntu) in the next > cryptography release. > * Fixed multiple issues preventing cryptography from compiling against > LibreSSL 2.7.x. > * Added get_revoked_certificate_by_serial_number for quick serial number > searches in CRLs. > * The RelativeDistinguishedName class now preserves the order of > attributes. Duplicate attributes now raise an error instead of silently > discarding duplicates. > * aes_key_unwrap() and aes_key_unwrap_with_padding() now raise > InvalidUnwrap if the wrapped key is an invalid length, instead of > ValueError. > > -Paul Kehrer (reaperhulk) From mal at europython.eu Wed Jul 18 12:35:34 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 18 Jul 2018 18:35:34 +0200 Subject: EuroPython 2018: Find a new job at the conference Message-ID: <2ed1bdd8-ead1-d026-6764-711f4fda8b45@europython.eu> We?d like to draw your attention to our job board, with plenty of job ads from our sponsors: * EuroPython 2018 Job Board * https://ep2018.europython.eu/en/sponsor/job-board/ We will also send out job ad emails to attendees who have opt?ed in to receiving these emails. If you are interested, please log in, go to your profile and enable the recruiting email option in the privacy section: https://ep2018.europython.eu/accounts/profile/ Note that we will not give your email addresses to sponsors, but only send out these emails on behalf of them. 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/176025102537/europython-2018-find-a-new-job-at-the-conference Tweet: https://twitter.com/europython/status/1019620582445416450 Enjoy, -- EuroPython 2018 Team https://ep2018.europython.eu/ https://www.europython-society.org/ From no at none.invalid Wed Jul 18 17:16:21 2018 From: no at none.invalid (no at none.invalid) Date: Wed, 18 Jul 2018 17:16:21 -0400 Subject: What is the pattern for this number set? Message-ID: This is a chart I made using BASIC back in the 90s when I could still do math and programming. I would like to have a new print out of this chart but I no longer can figure out programming or math. Anyone care to figure out the pattern and make a new copy of the chart? https://imgur.com/a/thF6U43 From larry.martell at gmail.com Wed Jul 18 17:40:44 2018 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 18 Jul 2018 17:40:44 -0400 Subject: doubling the number of tests, but not taking twice as long In-Reply-To: References: Message-ID: On Tue, Jul 17, 2018 at 11:43 AM, Neil Cerutti wrote: > On 2018-07-16, Larry Martell wrote: >> I had some code that did this: >> >> meas_regex = '_M\d+_' >> meas_re = re.compile(meas_regex) >> >> if meas_re.search(filename): >> stuff1() >> else: >> stuff2() >> >> I then had to change it to this: >> >> if meas_re.search(filename): >> if 'MeasDisplay' in filename: >> stuff1a() >> else: >> stuff1() >> else: >> if 'PatternFov' in filename: >> stuff2a() >> else: >> stuff2() >> >> This code needs to process many tens of 1000's of files, and it >> runs often, so it needs to run very fast. Needless to say, my >> change has made it take 2x as long. Can anyone see a way to >> improve that? > > Can you expand/improve the regex pattern so you don't have rescan > the string to check for the presence of MeasDisplay and > PatternFov? In other words, since you're already using the giant, > Swiss Army sledgehammer of the re module, go ahead and use enough > features to cover your use case. Yeah, that was my first thought, but I haven't been able to come up with a regex that works. There are 4 cases I need to detect: case1 = 'spam_M123_eggs_MeasDisplay_sausage' case2 = 'spam_M123_eggs_sausage_and_spam' case3 = 'spam_spam_spam_PatternFov_eggs_sausage_and_spam' case4 = 'spam_spam_spam_eggs_sausage_and_spam' I thought this regex would work: '(_M\d+_){0,1}.*?(MeasDisplay|PatternFOV){0,1}' And then I could look at the match objects and see which of the 4 cases it was. But try as I might, I could not get it to work. Any regex gurus want to tell me what I am doing wrong here? From rosuav at gmail.com Wed Jul 18 17:43:06 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Jul 2018 07:43:06 +1000 Subject: What is the pattern for this number set? In-Reply-To: References: Message-ID: On Thu, Jul 19, 2018 at 7:16 AM, wrote: > This is a chart I made using BASIC back in the 90s when I could still > do math and programming. > I would like to have a new print out of this chart but I no longer can > figure out programming or math. > Anyone care to figure out the pattern and make a new copy of the > chart? > > https://imgur.com/a/thF6U43 Oh that looks like fun! Some sort of game analysis, I presume. Unfortunately I don't see enough info there to be able to create the table. How do you calculate the values? ChrisA From tjol at tjol.eu Wed Jul 18 17:53:52 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 18 Jul 2018 23:53:52 +0200 Subject: What is the pattern for this number set? In-Reply-To: References: Message-ID: On 18/07/18 23:43, Chris Angelico wrote: > On Thu, Jul 19, 2018 at 7:16 AM, wrote: >> This is a chart I made using BASIC back in the 90s when I could still >> do math and programming. >> I would like to have a new print out of this chart but I no longer can >> figure out programming or math. >> Anyone care to figure out the pattern and make a new copy of the >> chart? >> >> https://imgur.com/a/thF6U43 > > Oh that looks like fun! Some sort of game analysis, I presume. > Unfortunately I don't see enough info there to be able to create the > table. How do you calculate the values? > > ChrisA > Or, at least, what do the numbers mean? What game do they apply to? - Thomas From ian.g.kelly at gmail.com Wed Jul 18 18:06:17 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 18 Jul 2018 16:06:17 -0600 Subject: What is the pattern for this number set? In-Reply-To: References: Message-ID: Rather than go to the effort of reverse-engineering the chart, I wonder if it would be simpler to just run OCR over it and dump it into a spreadsheet. On Wed, Jul 18, 2018 at 4:01 PM Thomas Jollans wrote: > > On 18/07/18 23:43, Chris Angelico wrote: > > On Thu, Jul 19, 2018 at 7:16 AM, wrote: > >> This is a chart I made using BASIC back in the 90s when I could still > >> do math and programming. > >> I would like to have a new print out of this chart but I no longer can > >> figure out programming or math. > >> Anyone care to figure out the pattern and make a new copy of the > >> chart? > >> > >> https://imgur.com/a/thF6U43 > > > > Oh that looks like fun! Some sort of game analysis, I presume. > > Unfortunately I don't see enough info there to be able to create the > > table. How do you calculate the values? > > > > ChrisA > > > > Or, at least, what do the numbers mean? What game do they apply to? > > - Thomas > -- > https://mail.python.org/mailman/listinfo/python-list From tjol at tjol.eu Wed Jul 18 18:28:51 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 19 Jul 2018 00:28:51 +0200 Subject: What is the pattern for this number set? In-Reply-To: References: Message-ID: On 19/07/18 00:06, Ian Kelly wrote: > Rather than go to the effort of reverse-engineering the chart, I > wonder if it would be simpler to just run OCR over it and dump it into > a spreadsheet. Really the easiest and quickest way to make a new printout of this single page is to simply copy it by hand. > On Wed, Jul 18, 2018 at 4:01 PM Thomas Jollans wrote: >> >> On 18/07/18 23:43, Chris Angelico wrote: >>> On Thu, Jul 19, 2018 at 7:16 AM, wrote: >>>> This is a chart I made using BASIC back in the 90s when I could still >>>> do math and programming. >>>> I would like to have a new print out of this chart but I no longer can >>>> figure out programming or math. >>>> Anyone care to figure out the pattern and make a new copy of the >>>> chart? >>>> >>>> https://imgur.com/a/thF6U43 >>> >>> Oh that looks like fun! Some sort of game analysis, I presume. >>> Unfortunately I don't see enough info there to be able to create the >>> table. How do you calculate the values? >>> >>> ChrisA >>> >> >> Or, at least, what do the numbers mean? What game do they apply to? >> >> - Thomas >> -- >> https://mail.python.org/mailman/listinfo/python-list From no at none.invalid Wed Jul 18 18:43:18 2018 From: no at none.invalid (no at none.invalid) Date: Wed, 18 Jul 2018 18:43:18 -0400 Subject: What is the pattern for this number set? References: Message-ID: On Wed, 18 Jul 2018 17:16:21 -0400, no at none.invalid wrote: >This is a chart I made using BASIC back in the 90s when I could still >do math and programming. >I would like to have a new print out of this chart but I no longer can >figure out programming or math. >Anyone care to figure out the pattern and make a new copy of the >chart? > >https://imgur.com/a/thF6U43 I don't remember how I did it. It is from the game Empire. There is a new version of it on Steam called Empire Deluxe Combined Edition. I played the game relentlessly from the 90s until I upgraded to Win7. The Windows version would not run on Win7. The cities have production times in multiples of 3 and then you get a 10% bonus if you keep building the same type unit. 100 percent is never the optimal number but that was a base amount. If you are bored the game cost about 18 bucks on Steam and I like to play multi player. The cities start at a random efficiency amount. If you chose not to build anything the city efficiency goes up by 1 per turn (until 100; after 100 city's efficiency takes more than one turn) so you can prolong production to get a faster build unit later. The chart is what turn is the best city amount after the 10% bonus. So at a 100 percent the armor takes 12 to build and it drops to 10 after the first unit is built. So a city at 85% will yield it's second unit at 12 turns. If you wait until the city is at 87% the second unit will be built at 11 turns. You have to pump production up to 96% to get the second unit at 10 turns. An infantry takes 6 @ 100% A destroyer takes 24 @ 100% A cruiser takes 36 @ 100% A battleship takes 53 @ 100% < not multiple of 3 ? A carrier takes 48 @ 100% That is about all I can remember. From cs at cskk.id.au Wed Jul 18 19:05:40 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 19 Jul 2018 09:05:40 +1000 Subject: doubling the number of tests, but not taking twice as long In-Reply-To: References: Message-ID: <20180718230540.GA86963@cskk.homeip.net> On 18Jul2018 17:40, Larry Martell wrote: >On Tue, Jul 17, 2018 at 11:43 AM, Neil Cerutti wrote: >> On 2018-07-16, Larry Martell wrote: >>> I had some code that did this: >>> >>> meas_regex = '_M\d+_' >>> meas_re = re.compile(meas_regex) >>> >>> if meas_re.search(filename): >>> stuff1() >>> else: >>> stuff2() >>> >>> I then had to change it to this: >>> >>> if meas_re.search(filename): >>> if 'MeasDisplay' in filename: >>> stuff1a() >>> else: >>> stuff1() >>> else: >>> if 'PatternFov' in filename: >>> stuff2a() >>> else: >>> stuff2() >>> >>> This code needs to process many tens of 1000's of files, and it >>> runs often, so it needs to run very fast. Needless to say, my >>> change has made it take 2x as long. Can anyone see a way to >>> improve that? As others have mentioned, your stuff*() function must be doing very little work, because I'd expect the regexp stuff to be fairly quick. >Yeah, that was my first thought, but I haven't been able to come up >with a regex that works. > >There are 4 cases I need to detect: > >case1 = 'spam_M123_eggs_MeasDisplay_sausage' >case2 = 'spam_M123_eggs_sausage_and_spam' >case3 = 'spam_spam_spam_PatternFov_eggs_sausage_and_spam' >case4 = 'spam_spam_spam_eggs_sausage_and_spam' > >I thought this regex would work: > >'(_M\d+_){0,1}.*?(MeasDisplay|PatternFOV){0,1}' Did you try making that a raw string: r'(......}' to avoid mangling the backslashes (which Python will interpret before they get to the regexp parser)? Print meas_regex to check it got past Python intact. Just print(meas_regex). Also, "{0,1}" is usually written "?". >And then I could look at the match objects and see which of the 4 >cases it was. But try as I might, I could not get it to work. Any >regex gurus want to tell me what I am doing wrong here? Backslashes aside, it looks ok to me. So I'd better run it... Code: from __future__ import print_function import re case1 = 'spam_M123_eggs_MeasDisplay_sausage' case2 = 'spam_M123_eggs_sausage_and_spam' case3 = 'spam_spam_spam_PatternFov_eggs_sausage_and_spam' case4 = 'spam_spam_spam_eggs_sausage_and_spam' meas_regex = r'(_M\d+_){0,1}.*?(MeasDisplay|PatternFOV){0,1}' print("meas_regex =", meas_regex) meas_re = re.compile(meas_regex) for case in case1, case2, case3, case4: print(case, end=" ") m = meas_re.search(case) if m: print("MATCH: group1 =", m.group(1), "group2 =", m.group(2)) else: print("NO MATCH") Output: meas_regex = (_M\d+_){0,1}.*?(MeasDisplay|PatternFOV){0,1} spam_M123_eggs_MeasDisplay_sausage MATCH: group1 = None group2 = None spam_M123_eggs_sausage_and_spam MATCH: group1 = None group2 = None spam_spam_spam_PatternFov_eggs_sausage_and_spam MATCH: group1 = None group2 = None spam_spam_spam_eggs_sausage_and_spam MATCH: group1 = None group2 = None Ah, and there's the problem. Though I'm surprised to get the Nones in the .group()s instead of the empty string; possibly that reflects "0 occurences". [...] A little testing with other tweaks to the regexp supports that. No matter. To your problem: When you write "(_M\d+_){0,1}" or anything that is optional like that, it can match the empty string (the "0"). And that _always_ matches. Likewise the second part of the pattern. Because you want to know about _both_ the "M\d+_" _and_ the "MeasDisplay|PatternFOV" you can't put them both in the same pattern: if you make them optional, the pattern always matches the empty string even if the target is later on; if you make them mandatory (no "{0,1}") your pattern will only work when both are present. Similar pitfalls apply for any combination, making one optional and the other mandatory: you can't do all 4 possibilities (niether, just the first, just the second, both) with one regex (== one match/search test). So your code was already optimal. I am surprised that your program took twice a long to run with your doubled test though. These are filenames, yes? So shouldn't the stuff*() functions be openin the file or something: I would expect that to dominate the runtime and your extra name testing to not be the slowdown. What's going on inside the stuff*() functions? Might they also have become more complex with your new cases? Cheers, Cameron Simpson From no at none.invalid Wed Jul 18 19:09:42 2018 From: no at none.invalid (no at none.invalid) Date: Wed, 18 Jul 2018 19:09:42 -0400 Subject: What is the pattern for this number set? References: Message-ID: On Wed, 18 Jul 2018 18:43:18 -0400, no at none.invalid wrote: >On Wed, 18 Jul 2018 17:16:21 -0400, no at none.invalid wrote: > >>This is a chart I made using BASIC back in the 90s when I could still >>do math and programming. >>I would like to have a new print out of this chart but I no longer can >>figure out programming or math. >>Anyone care to figure out the pattern and make a new copy of the >>chart? >> >>https://imgur.com/a/thF6U43 > > >I don't remember how I did it. >It is from the game Empire. There is a new version of it on Steam >called Empire Deluxe Combined Edition. >I played the game relentlessly from the 90s until I upgraded to Win7. >The Windows version would not run on Win7. >The cities have production times in multiples of 3 and then you get a >10% bonus if you keep building the same type unit. 100 percent is >never the optimal number but that was a base amount. > >If you are bored the game cost about 18 bucks on Steam and I like to >play multi player. > > >The cities start at a random efficiency amount. If you chose not to >build anything the city efficiency goes up by 1 per turn (until 100; >after 100 city's efficiency takes more than one turn) so you can >prolong production to get a faster build unit later. > >The chart is what turn is the best city amount after the 10% bonus. > >So at a 100 percent the armor takes 12 to build and it drops to 10 >after the first unit is built. So a city at 85% will yield it's >second unit at 12 turns. If you wait until the city is at 87% the >second unit will be built at 11 turns. You have to pump production up >to 96% to get the second unit at 10 turns. > >An infantry takes 6 @ 100% >A destroyer takes 24 @ 100% >A cruiser takes 36 @ 100% >A battleship takes 53 @ 100% < not multiple of 3 ? Bad number, but they are not all multiples of 3 >A carrier takes 48 @ 100% > > >That is about all I can remember. Here are all the old units and new units from the new game. The chart would be much larger with the new units but I would be happy with just the old numbers. https://imgur.com/a/6mFRaNc From pkpearson at nowhere.invalid Wed Jul 18 19:37:09 2018 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 18 Jul 2018 23:37:09 GMT Subject: What is the pattern for this number set? References: Message-ID: On Wed, 18 Jul 2018 17:16:21 -0400, no at none.invalid wrote: [snip] > Anyone care to figure out the pattern and make a new copy of the > chart? > > https://imgur.com/a/thF6U43 I've only looked at infantry and carrier, but those two seem to be fairly well approximated by y = a + 1/(b*x + c), for a, b, and c being chosen individually for infantry and carrier. -- To email me, substitute nowhere->runbox, invalid->com. From python at mrabarnett.plus.com Wed Jul 18 19:59:42 2018 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 19 Jul 2018 00:59:42 +0100 Subject: doubling the number of tests, but not taking twice as long In-Reply-To: References: Message-ID: On 2018-07-18 22:40, Larry Martell wrote: > On Tue, Jul 17, 2018 at 11:43 AM, Neil Cerutti wrote: >> On 2018-07-16, Larry Martell wrote: >>> I had some code that did this: >>> >>> meas_regex = '_M\d+_' >>> meas_re = re.compile(meas_regex) >>> >>> if meas_re.search(filename): >>> stuff1() >>> else: >>> stuff2() >>> >>> I then had to change it to this: >>> >>> if meas_re.search(filename): >>> if 'MeasDisplay' in filename: >>> stuff1a() >>> else: >>> stuff1() >>> else: >>> if 'PatternFov' in filename: >>> stuff2a() >>> else: >>> stuff2() >>> >>> This code needs to process many tens of 1000's of files, and it >>> runs often, so it needs to run very fast. Needless to say, my >>> change has made it take 2x as long. Can anyone see a way to >>> improve that? >> >> Can you expand/improve the regex pattern so you don't have rescan >> the string to check for the presence of MeasDisplay and >> PatternFov? In other words, since you're already using the giant, >> Swiss Army sledgehammer of the re module, go ahead and use enough >> features to cover your use case. > > Yeah, that was my first thought, but I haven't been able to come up > with a regex that works. > > There are 4 cases I need to detect: > > case1 = 'spam_M123_eggs_MeasDisplay_sausage' > case2 = 'spam_M123_eggs_sausage_and_spam' > case3 = 'spam_spam_spam_PatternFov_eggs_sausage_and_spam' > case4 = 'spam_spam_spam_eggs_sausage_and_spam' > > I thought this regex would work: > > '(_M\d+_){0,1}.*?(MeasDisplay|PatternFOV){0,1}' > > And then I could look at the match objects and see which of the 4 > cases it was. But try as I might, I could not get it to work. Any > regex gurus want to tell me what I am doing wrong here? > The trick to capturing both of the parts when they are both optional is to use a lookahead and make it optional: r'(?=.*?(_M\d+_))?(?=.*?(MeasDisplay|PatternFov))?' From larry.martell at gmail.com Wed Jul 18 20:09:36 2018 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 18 Jul 2018 20:09:36 -0400 Subject: doubling the number of tests, but not taking twice as long In-Reply-To: References: Message-ID: On Wed, Jul 18, 2018 at 7:59 PM, MRAB wrote: > On 2018-07-18 22:40, Larry Martell wrote: >> >> On Tue, Jul 17, 2018 at 11:43 AM, Neil Cerutti wrote: >>> >>> On 2018-07-16, Larry Martell wrote: >>>> >>>> I had some code that did this: >>>> >>>> meas_regex = '_M\d+_' >>>> meas_re = re.compile(meas_regex) >>>> >>>> if meas_re.search(filename): >>>> stuff1() >>>> else: >>>> stuff2() >>>> >>>> I then had to change it to this: >>>> >>>> if meas_re.search(filename): >>>> if 'MeasDisplay' in filename: >>>> stuff1a() >>>> else: >>>> stuff1() >>>> else: >>>> if 'PatternFov' in filename: >>>> stuff2a() >>>> else: >>>> stuff2() >>>> >>>> This code needs to process many tens of 1000's of files, and it >>>> runs often, so it needs to run very fast. Needless to say, my >>>> change has made it take 2x as long. Can anyone see a way to >>>> improve that? >>> >>> >>> Can you expand/improve the regex pattern so you don't have rescan >>> the string to check for the presence of MeasDisplay and >>> PatternFov? In other words, since you're already using the giant, >>> Swiss Army sledgehammer of the re module, go ahead and use enough >>> features to cover your use case. >> >> >> Yeah, that was my first thought, but I haven't been able to come up >> with a regex that works. >> >> There are 4 cases I need to detect: >> >> case1 = 'spam_M123_eggs_MeasDisplay_sausage' >> case2 = 'spam_M123_eggs_sausage_and_spam' >> case3 = 'spam_spam_spam_PatternFov_eggs_sausage_and_spam' >> case4 = 'spam_spam_spam_eggs_sausage_and_spam' >> >> I thought this regex would work: >> >> '(_M\d+_){0,1}.*?(MeasDisplay|PatternFOV){0,1}' >> >> And then I could look at the match objects and see which of the 4 >> cases it was. But try as I might, I could not get it to work. Any >> regex gurus want to tell me what I am doing wrong here? >> > The trick to capturing both of the parts when they are both optional is to > use a lookahead and make it optional: > > r'(?=.*?(_M\d+_))?(?=.*?(MeasDisplay|PatternFov))?' Wow! Thanks so much. This works perfectly. I don't understand it, but I will spend some time dissecting it and I will add another tool to my arsenal. From rosuav at gmail.com Wed Jul 18 22:01:21 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Jul 2018 12:01:21 +1000 Subject: GNU Readline and asyncio Message-ID: Has anyone put together a straight-forward example of using asyncio with readline? For example, suppose you have a command line program that accepts control commands via readline, while accepting socket connections to do its actual work. I can do that in a threaded way fairly easily (spin off a thread for every connection, then leave the main thread managing the console), and it's not too hard to convert to async when using plain vanilla reads from stdin, but I'm not so sure about readline. ChrisA From no at none.invalid Wed Jul 18 23:00:49 2018 From: no at none.invalid (no at none.invalid) Date: Wed, 18 Jul 2018 23:00:49 -0400 Subject: What is the pattern for this number set? References: Message-ID: On Wed, 18 Jul 2018 18:43:18 -0400, no at none.invalid wrote: >On Wed, 18 Jul 2018 17:16:21 -0400, no at none.invalid wrote: > >>This is a chart I made using BASIC back in the 90s when I could still >>do math and programming. >>I would like to have a new print out of this chart but I no longer can >>figure out programming or math. >>Anyone care to figure out the pattern and make a new copy of the >>chart? >> >>https://imgur.com/a/thF6U43 > > >I don't remember how I did it. >It is from the game Empire. There is a new version of it on Steam >called Empire Deluxe Combined Edition. >I played the game relentlessly from the 90s until I upgraded to Win7. >The Windows version would not run on Win7. >The cities have production times in multiples of 3 and then you get a >10% bonus if you keep building the same type unit. 100 percent is >never the optimal number but that was a base amount. > >If you are bored the game cost about 18 bucks on Steam and I like to >play multi player. > > >The cities start at a random efficiency amount. If you chose not to >build anything the city efficiency goes up by 1 per turn (until 100; >after 100 city's efficiency takes more than one turn) so you can >prolong production to get a faster build unit later. > >The chart is what turn is the best city amount after the 10% bonus. > >So at a 100 percent the armor takes 12 to build and it drops to 10 >after the first unit is built. So a city at 85% will yield it's >second unit at 12 turns. If you wait until the city is at 87% the >second unit will be built at 11 turns. You have to pump production up >to 96% to get the second unit at 10 turns. > >An infantry takes 6 @ 100% >A destroyer takes 24 @ 100% >A cruiser takes 36 @ 100% >A battleship takes 53 @ 100% < not multiple of 3 ? >A carrier takes 48 @ 100% > > >That is about all I can remember. I think I was wrong about the 10% The instructions say...... Continue Production Reduction ? For every unit produced in a city there is a timed production cost in turns. With this rule enabled, after the first unit has been produced, if the type remains the same, each additional unit of this type will be produced at a different (traditionally one-sixth lower) rate From greg.ewing at canterbury.ac.nz Thu Jul 19 02:35:53 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 19 Jul 2018 18:35:53 +1200 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87muut4g77.fsf@elektro.pacujo.net> <20180716212520.7d560841@bigbox.christie.dr> Message-ID: Stefan Ram wrote: > Gregory Ewing writes: >>That's debatable. I've never thought of it that way and I'm >>fairly certain I don't pronounce it that way. My tongue does >>not do the same thing when I say "ch" as it does when I >>say "tsh". > > archives ??? k??vz (n) > bachelor ?b?? l? (n) > machine m???in > cash ?k?? > dachshund ??d?ks ?h?nt I'm talking specifically about the "ch" sound in "bachelor", "change", etc. It sounds and feels like a single sound to me. -- Greg From greg.ewing at canterbury.ac.nz Thu Jul 19 02:41:27 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 19 Jul 2018 18:41:27 +1200 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87muut4g77.fsf@elektro.pacujo.net> <20180716212520.7d560841@bigbox.christie.dr> Message-ID: Stefan Ram wrote: > ?assistshop?, Is that a word? (Google doesn't seem to think so -- it asks me whether I meant "assist shop". Although it does offer to translate it into Czech...) -- Greg From rosuav at gmail.com Thu Jul 19 02:48:37 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 19 Jul 2018 16:48:37 +1000 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87muut4g77.fsf@elektro.pacujo.net> <20180716212520.7d560841@bigbox.christie.dr> Message-ID: On Thu, Jul 19, 2018 at 4:41 PM, Gregory Ewing wrote: > Stefan Ram wrote: >> >> ?assistshop?, > > > Is that a word? > > (Google doesn't seem to think so -- it asks me whether > I meant "assist shop". Although it does offer to translate > it into Czech...) > Into or from?? I'm thoroughly confused now! ChrisA From arj.python at gmail.com Thu Jul 19 02:57:16 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 19 Jul 2018 10:57:16 +0400 Subject: PyDocs Arabic Translation Started and Call to Interested Parties viz en-ar Speakers Message-ID: Greetings everybody, i take this opportunity to announce to the python community that Arabic translations for the docs have started at https://github.com/Abdur-rahmaanJ/py-docs-ar as per the PEP written by @JulienPalard and @Mariatta, we are working on the tutorials (for 3.7). you can view details in the docs mailing list archive. coordinator for this project : myself as i have contributed to the french docs, i have cloned the .po french repo for the Arabic one and modified accordingly as per recommedations for coordinators (thanking @Julien for tips) i have been contacting arab-speaking developers for involvement and announcing the project. feedbacks were positive with the likes of ????? ?? ??? ???????? ??????? And thank you for the beautiful initiative ????? ?????? ??? ????? And may Allah/God gives you (literally) thousands of wellness however, i've found out that git is a major barrier for translations as well. many programmers for fun around, they like py, they use it, but few actually have a github account. must search further. nevertheless they are willing to translate as much as i want, i am still pondering an appropriate off-git solution, then merge by me. for the past days we have been convening on the keywords, the starting point of any translation, as, though i know Arabic, i have to cross check with native speakers as to how they really say it as there are words that are left untranslated but written in arabic as well as for similar details that said, i call to python programmers, in any language to contribute to translations, as you will by the way know the docs thoroughly. and in the case of this mail, a special call for arabic-speaking people to get involved this is a huge task (french still at 29%) but i believe that this will help programmers around the world to better access such a sleek, candy, soulful, neat and lovely language, and my way of saying thank you / contributing back to the community your fellow brother in code, Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius From arj.python at gmail.com Thu Jul 19 03:06:44 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 19 Jul 2018 11:06:44 +0400 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87muut4g77.fsf@elektro.pacujo.net> <20180716212520.7d560841@bigbox.christie.dr> Message-ID: it's also thoroughly time to give this thread a well deserved rest RIP Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Into or from?? I'm thoroughly confused now! > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From greg.ewing at canterbury.ac.nz Thu Jul 19 08:50:49 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 20 Jul 2018 00:50:49 +1200 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87muut4g77.fsf@elektro.pacujo.net> <20180716212520.7d560841@bigbox.christie.dr> Message-ID: Chris Angelico wrote: > On Thu, Jul 19, 2018 at 4:41 PM, Gregory Ewing > wrote: > >>(Google doesn't seem to think so -- it asks me whether >>I meant "assist shop". Although it does offer to translate >>it into Czech...) > > Into or from?? I'm thoroughly confused now! Hard to tell. This is what the link said: assistshop - Czech translation - bab.la English-Czech dictionary https://en.bab.la/dictionary/english-czech/assistshop Translation for 'assistshop' in the free English-Czech dictionary and many other Czech translations. -- Greg From mal at europython.eu Thu Jul 19 10:11:38 2018 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 19 Jul 2018 16:11:38 +0200 Subject: EuroPython 2018: Day passes now also valid for Sprints Weekend Message-ID: <12e1d3d3-81f0-b9d4-7ec3-3e22aaf1c7c0@europython.eu> Due to popular demand, we are making it possible to attend the Sprints Weekend (July 28-29), even if you only have a day pass or are considering to buy one and not a regular conference tickets which includes the sprints as well. * EuroPython 2018 Sprints (Hackathons) * https://ep2018.europython.eu/en/events/sprints/ If you have never been to a sprint, you?ll be amazed at how much you can learn from others while working on simple or more complex projects. If you have already run sprints yourself, why not run one at EuroPython and get to know new people for your project ? Please head on to our EuroPython Sprints page for more details. Come and join the sprinters ! 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/176026105657/europython-2018-day-passes-now-also-valid-for Tweet: https://twitter.com/europython/status/1019630424883113985 Enjoy, -- EuroPython 2018 Team https://ep2018.europython.eu/ https://www.europython-society.org/ From guido at python.org Thu Jul 19 11:06:32 2018 From: guido at python.org (Guido van Rossum) Date: Thu, 19 Jul 2018 08:06:32 -0700 Subject: PyDocs Arabic Translation Started and Call to Interested Parties viz en-ar Speakers In-Reply-To: References: Message-ID: Thank you for taking the lead and good luck with the project! On Wed, Jul 18, 2018 at 11:57 PM Abdur-Rahmaan Janhangeer < arj.python at gmail.com> wrote: > Greetings everybody, > > i take this opportunity to announce to the python community that Arabic > translations for the docs have started at > > https://github.com/Abdur-rahmaanJ/py-docs-ar > > as per the PEP written by @JulienPalard and @Mariatta, we are working on > the tutorials (for 3.7). you can view details in the docs mailing list > archive. > > coordinator for this project : myself > > as i have contributed to the french docs, i have cloned the .po french > repo for the Arabic one and modified accordingly > > as per recommedations for coordinators (thanking @Julien for tips) i have > been contacting arab-speaking developers for involvement and announcing the > project. feedbacks were positive with the likes of > > ????? ?? ??? ???????? ??????? > And thank you for the beautiful initiative > > ????? ?????? ??? ????? > And may Allah/God gives you (literally) thousands of wellness > > however, i've found out that git is a major barrier for translations as > well. many programmers for fun around, they like py, they use it, but few > actually have a github account. must search further. nevertheless they are > willing to translate as much as i want, i am still pondering an appropriate > off-git solution, then merge by me. > > for the past days we have been convening on the keywords, the starting > point of any translation, as, though i know Arabic, i have to cross check > with native speakers as to how they really say it as there are words that > are left untranslated but written in arabic as well as for similar details > > that said, i call to python programmers, in any language to contribute to > translations, as you will by the way know the docs thoroughly. > > and in the case of this mail, a special call for arabic-speaking people to > get involved > > this is a huge task (french still at 29%) but i believe that this will > help programmers around the world to better access such a sleek, candy, > soulful, neat and lovely language, and my way of saying thank you / > contributing back to the community > > your fellow brother in code, > > Abdur-Rahmaan Janhangeer > https://github.com/Abdur-rahmaanJ > Mauritius > -- --Guido (mobile) From no at none.invalid Thu Jul 19 11:47:10 2018 From: no at none.invalid (no at none.invalid) Date: Thu, 19 Jul 2018 11:47:10 -0400 Subject: copy and paste with a program called clipboard Message-ID: I just installed Python 3.7 The instructions say to highlight some text and press enter to copy text. You are supposed to just right click with the mouse to paste text. I use a very useful program called Clipmate that captures from the clipboard and keeps a list of clipboard captures and I can menu pick what I want to paste from the clipboard. This doesn't not seem to be working as nothing happens when I try to select text and right click in the command window with the mouse. Ctrl V doesn't work either. Is this a bug? Is there a workaround? From breamoreboy at gmail.com Thu Jul 19 12:00:37 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Thu, 19 Jul 2018 17:00:37 +0100 Subject: PyDocs Arabic Translation Started and Call to Interested Parties viz en-ar Speakers In-Reply-To: References: Message-ID: On 19/07/18 16:06, Guido van Rossum wrote: > Thank you for taking the lead and good luck with the project! Pleased to see that haven't completely disappeared :) > > On Wed, Jul 18, 2018 at 11:57 PM Abdur-Rahmaan Janhangeer < > arj.python at gmail.com> wrote: > >> Greetings everybody, >> >> i take this opportunity to announce to the python community that Arabic >> translations for the docs have started at >> >> https://github.com/Abdur-rahmaanJ/py-docs-ar >> >> as per the PEP written by @JulienPalard and @Mariatta, we are working on >> the tutorials (for 3.7). you can view details in the docs mailing list >> archive. >> >> coordinator for this project : myself >> >> as i have contributed to the french docs, i have cloned the .po french >> repo for the Arabic one and modified accordingly >> >> as per recommedations for coordinators (thanking @Julien for tips) i have >> been contacting arab-speaking developers for involvement and announcing the >> project. feedbacks were positive with the likes of >> >> ????? ?? ??? ???????? ??????? >> And thank you for the beautiful initiative >> >> ????? ?????? ??? ????? >> And may Allah/God gives you (literally) thousands of wellness >> >> however, i've found out that git is a major barrier for translations as >> well. many programmers for fun around, they like py, they use it, but few >> actually have a github account. must search further. nevertheless they are >> willing to translate as much as i want, i am still pondering an appropriate >> off-git solution, then merge by me. >> >> for the past days we have been convening on the keywords, the starting >> point of any translation, as, though i know Arabic, i have to cross check >> with native speakers as to how they really say it as there are words that >> are left untranslated but written in arabic as well as for similar details >> >> that said, i call to python programmers, in any language to contribute to >> translations, as you will by the way know the docs thoroughly. >> >> and in the case of this mail, a special call for arabic-speaking people to >> get involved >> >> this is a huge task (french still at 29%) but i believe that this will >> help programmers around the world to better access such a sleek, candy, >> soulful, neat and lovely language, and my way of saying thank you / >> contributing back to the community >> >> your fellow brother in code, >> >> Abdur-Rahmaan Janhangeer >> https://github.com/Abdur-rahmaanJ >> Mauritius >> Big +1 while I'm here :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From python at mrabarnett.plus.com Thu Jul 19 12:35:24 2018 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 19 Jul 2018 17:35:24 +0100 Subject: copy and paste with a program called clipboard In-Reply-To: References: Message-ID: On 2018-07-19 16:47, no at none.invalid wrote: > I just installed Python 3.7 > The instructions say to highlight some text and press enter to copy > text. > You are supposed to just right click with the mouse to paste text. > > I use a very useful program called Clipmate that captures from the > clipboard and keeps a list of clipboard captures and I can menu pick > what I want to paste from the clipboard. > > This doesn't not seem to be working as nothing happens when I try to > select text and right click in the command window with the mouse. > > Ctrl V doesn't work either. > > Is this a bug? Is there a workaround? > I'm assuming you're using Windows. It might be that the console window's properties need changing: 1. Right-click on the title bar. 2. Click on Properties. 3. In the Options tab, turn on QuickEdit Mode. 4. Click OK. From tjreedy at udel.edu Thu Jul 19 13:42:30 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 19 Jul 2018 13:42:30 -0400 Subject: copy and paste with a program called clipboard In-Reply-To: References: Message-ID: On 7/19/2018 11:47 AM, no at none.invalid wrote: > I just installed Python 3.7 What machine (OS)? How did you install Python? How are you running it? > The instructions say to highlight some text and press enter to copy > text. What instructions? This is not standard, at least not on Windows. > You are supposed to just right click with the mouse to paste text. What happens when you right click depends on the program you are interacting with. When you select and right-click in the current Windows 10 console, used for Command Prompt, PowerShell, Python, and other programs, the selection disappears. I just discovered that it also copies to the clipboard. I also just discovered that right click without a selection pastes the current clipboard contents. (I usually use ^X, ^C, and ^V.) Since the console is in the process of being improved, I have no idea how long this has been true. IDLE's editor-based windows have a context menu with Cut, Copy, and Paste. > I use a very useful program called Clipmate that captures from the > clipboard and keeps a list of clipboard captures and I can menu pick > what I want to paste from the clipboard. If I understand, Clipmate is supposed to get a signal when the clipboard changes to it can grab (copy) the new text and add it to its clipboard history list. > This doesn't not seem to be working as nothing happens when I try to > select text and right click in the command window with the mouse. As before, what OS and commmand window? And at least for Windows, version? > Ctrl V doesn't work either. > > Is this a bug? Is there a workaround? -- Terry Jan Reedy From auriocus at gmx.de Thu Jul 19 14:34:26 2018 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 19 Jul 2018 20:34:26 +0200 Subject: Glyphs and graphemes [was Re: Cult-like behaviour] In-Reply-To: References: <87muut4g77.fsf@elektro.pacujo.net> <20180716212520.7d560841@bigbox.christie.dr> Message-ID: Am 19.07.2018 um 14:50 schrieb Gregory Ewing: > Chris Angelico wrote: >> On Thu, Jul 19, 2018 at 4:41 PM, Gregory Ewing >> wrote: >> >>> (Google doesn't seem to think so -- it asks me whether >>> I meant "assist shop". Although it does offer to translate? >>> it into Czech...) >> >> Into or from?? I'm thoroughly confused now! > > Hard to tell. This is what the link said: > > assistshop - Czech translation - bab.la English-Czech dictionary > https://en.bab.la/dictionary/english-czech/assistshop > Translation for 'assistshop' in the free English-Czech dictionary and" > many other Czech translations. Well that link tries to translate "assistshop" into the czech word "prodava?" which is the usual word for a person in a shop who consults the customers and sells the goods to them; I don't know if "assist shop" in English comes close, as I don't understand it (I'm a native German speaker) Christian From no at none.invalid Thu Jul 19 14:49:00 2018 From: no at none.invalid (no at none.invalid) Date: Thu, 19 Jul 2018 14:49:00 -0400 Subject: copy and paste with a program called clipboard References: Message-ID: On Thu, 19 Jul 2018 17:35:24 +0100, MRAB wrote: >On 2018-07-19 16:47, no at none.invalid wrote: >> I just installed Python 3.7 >> The instructions say to highlight some text and press enter to copy >> text. >> You are supposed to just right click with the mouse to paste text. >> >> I use a very useful program called Clipmate that captures from the >> clipboard and keeps a list of clipboard captures and I can menu pick >> what I want to paste from the clipboard. >> >> This doesn't not seem to be working as nothing happens when I try to >> select text and right click in the command window with the mouse. >> >> Ctrl V doesn't work either. >> >> Is this a bug? Is there a workaround? >> >I'm assuming you're using Windows. > >It might be that the console window's properties need changing: > >1. Right-click on the title bar. > >2. Click on Properties. > >3. In the Options tab, turn on QuickEdit Mode. > >4. Click OK. I am using Windows7. When I run the command line thingy it says.......Python 3.7.0 64 bit. When I try to turn on QuickEdit I get this error message. https://imgur.com/a/kuxiNHv When I installed Python, I picked integrate with shell and add to path. From no at none.invalid Thu Jul 19 15:42:55 2018 From: no at none.invalid (no at none.invalid) Date: Thu, 19 Jul 2018 15:42:55 -0400 Subject: Edit with IDLE pull down menu Message-ID: Edit with IDLE pull down menu has one item. Why would you have nested menu with only one choice? From no at none.invalid Thu Jul 19 16:40:24 2018 From: no at none.invalid (no at none.invalid) Date: Thu, 19 Jul 2018 16:40:24 -0400 Subject: Edit with IDLE pull down menu References: Message-ID: <1nt1ldt70sgo0tomi52597lofl17308es0@4ax.com> On Thu, 19 Jul 2018 13:15:23 -0700 (PDT), Rick Johnson wrote: >n... at none.invalid wrote: >> Edit with IDLE pull down menu has one item. >> Why would you have nested menu with only one choice? > >Oh, i dunno, i'm just riffing here, but... perhaps because the menu's _contents_ depend on _context_??? It says.......Edit with IDLE and the pull down choice is Edit with IDLE. Do you have an example of what else might be in the Edit with IDLE menu? From no at none.invalid Thu Jul 19 17:40:16 2018 From: no at none.invalid (no at none.invalid) Date: Thu, 19 Jul 2018 17:40:16 -0400 Subject: Edit with IDLE pull down menu References: <1nt1ldt70sgo0tomi52597lofl17308es0@4ax.com> <93fff1ec-ab75-4d6f-b830-50ace4e1389b@googlegroups.com> Message-ID: <5212ldl22g906b213o51tn8jmmg13ofuqv@4ax.com> On Thu, 19 Jul 2018 14:00:39 -0700 (PDT), Rick Johnson wrote: >n... at none.invalid wrote: >> Rick Johnson wrote: >> >n... at none.invalid wrote: >> > > >> > > Edit with IDLE pull down menu has one item. Why would you >> > > have nested menu with only one choice? >> > >> > Oh, i dunno, i'm just riffing here, but... perhaps because >> > the menu's _contents_ depend on _context_??? >> >> It says.......Edit with IDLE and the pull down choice is >> Edit with IDLE. Do you have an example of what else might >> be in the Edit with IDLE menu? > >I dunno, as usual you don't offer enough _context_. > > >WORD OF THE DAY, KIDS: "Context". > > >Now, where is this offending "pull-down menu" located? > > * As a "me-right-clicks-a-file-icon" OS menu? > > * An a menu of a specific program like IDLE? > > * On a moon made from blue cheese? > >Can you help us out here? > I keep forgetting that Python is cross platform. I use Windows 7. After installing Python you can right click on a .py file and you get a pull down menu. The option for Edit with IDLE has an expanding menu. The only item in the pull down menu is..........Edit with IDLE. So to run a .py program, you have to right click and select the pull down menu Edit with IDLE and then inside that menu you pick Edit with IDLE. Seems a little redundant. From no at none.invalid Thu Jul 19 17:47:47 2018 From: no at none.invalid (no at none.invalid) Date: Thu, 19 Jul 2018 17:47:47 -0400 Subject: CASESOLUTIONSCENTRE (AT) GMAIL (DOT) COM Message-ID: <3l12ldtmhk72fsm6f2vsblnuqj025lrh8s@4ax.com> Gee. If those spams keep up, you would think that someone might try to turn the tables on the spammer. From breamoreboy at gmail.com Thu Jul 19 18:31:03 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Thu, 19 Jul 2018 23:31:03 +0100 Subject: CASESOLUTIONSCENTRE (AT) GMAIL (DOT) COM In-Reply-To: <3l12ldtmhk72fsm6f2vsblnuqj025lrh8s@4ax.com> References: <3l12ldtmhk72fsm6f2vsblnuqj025lrh8s@4ax.com> Message-ID: On 19/07/18 22:47, no at none.invalid wrote: > Gee. If those spams keep up, you would think that someone might try > to turn the tables on the spammer. > They come from google groups. Google has no intention of doing anything about it. I avoid seeing any of them by subscribing to this forum via gmane. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From no at none.invalid Thu Jul 19 18:31:05 2018 From: no at none.invalid (no at none.invalid) Date: Thu, 19 Jul 2018 18:31:05 -0400 Subject: Edit with IDLE pull down menu References: <1nt1ldt70sgo0tomi52597lofl17308es0@4ax.com> <93fff1ec-ab75-4d6f-b830-50ace4e1389b@googlegroups.com> <5212ldl22g906b213o51tn8jmmg13ofuqv@4ax.com> Message-ID: On Thu, 19 Jul 2018 18:25:41 -0400, Dennis Lee Bieber wrote: >On Thu, 19 Jul 2018 17:40:16 -0400, no at none.invalid declaimed the >following: > >> >>So to run a .py program, you have to right click and select the pull >>down menu Edit with IDLE and then inside that menu you pick Edit with >>IDLE. Seems a little redundant. > > No... In a properly configured system, to RUN a .py program, you just >double-click it. It will likely open a system console for stdout (a .pyw >file is commonly used for Python scripts that do not make use of >stdin/stdout/stderr -- ie; a program written using one of the graphical >toolkits). > > Since I have always used ActiveState builds, my context menu has "Edit >with PythonWin" and does NOT have any mention of IDLE. I wasn't trying to run a Python program. I wanted to Edit it with IDLE. When I said "run the program" I was talking about IDLE. From chema at rinzewind.org Thu Jul 19 18:49:14 2018 From: chema at rinzewind.org (=?iso-8859-1?Q?Jos=E9_Mar=EDa?= Mateos) Date: Thu, 19 Jul 2018 18:49:14 -0400 Subject: send PIL.Image to django server side and get it back In-Reply-To: <654f6297-a091-4ab8-a924-e7ed1987bbe5@googlegroups.com> References: <654f6297-a091-4ab8-a924-e7ed1987bbe5@googlegroups.com> Message-ID: <20180719224914.GB4118@equipaje> On Mon, Jul 16, 2018 at 06:40:45AM -0700, Christos Georgiou - ???????? wrote: > You need first to serialize the object to bytes that can go over the > wire. There is no predefined way to do that, so you can: > > >>> import io > >>> file_like_object = io.BytesIO() > >>> PILImage.save(file_like_object, format='png') > > and then in your POST request send file_like_object.getvalue() as the > image data. You will most probably need to add a Content-Type: > image/png as a header. If you definitely need to send the data as a string, because you want to use a JSON object or similar, I've done this in the past using base64 encoding. https://docs.python.org/2/library/base64.html Cheers, -- Jos? Mar?a (Chema) Mateos https://rinzewind.org/blog-es || https://rinzewind.org/blog-en From steve+comp.lang.python at pearwood.info Thu Jul 19 19:23:36 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 19 Jul 2018 23:23:36 +0000 (UTC) Subject: Glyphs and graphemes [was Re: Cult-like behaviour] References: <87muut4g77.fsf@elektro.pacujo.net> <20180716212520.7d560841@bigbox.christie.dr> Message-ID: On Thu, 19 Jul 2018 20:34:26 +0200, Christian Gollwitzer wrote: > Am 19.07.2018 um 14:50 schrieb Gregory Ewing: >> Chris Angelico wrote: >>> On Thu, Jul 19, 2018 at 4:41 PM, Gregory Ewing >>> wrote: >>> >>>> (Google doesn't seem to think so -- it asks me whether I meant >>>> "assist shop". Although it does offer to translate? it into Czech...) >>> >>> Into or from?? I'm thoroughly confused now! >> >> Hard to tell. This is what the link said: >> >> assistshop - Czech translation - bab.la English-Czech dictionary >> https://en.bab.la/dictionary/english-czech/assistshop Translation for >> 'assistshop' in the free English-Czech dictionary and" many other Czech >> translations. > > Well that link tries to translate "assistshop" into the czech word > "prodava?" which is the usual word for a person in a shop who consults > the customers and sells the goods to them; I don't know if "assist shop" > in English comes close, as I don't understand it (I'm a native German > speaker) In English, that would be "shop assistant". "Assist shop" would be grammatically incorrect: it should be written as "assist the shop", meaning "help the shop". Relevant: https://www.theatlantic.com/technology/archive/2018/01/the-shallowness-of-google-translate/551570/ -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From eryksun at gmail.com Thu Jul 19 19:35:05 2018 From: eryksun at gmail.com (eryk sun) Date: Thu, 19 Jul 2018 23:35:05 +0000 Subject: copy and paste with a program called clipboard In-Reply-To: References: Message-ID: On Thu, Jul 19, 2018 at 6:49 PM, wrote: > On Thu, 19 Jul 2018 17:35:24 +0100, MRAB > wrote: > >>I'm assuming you're using Windows. >> >>It might be that the console window's properties need changing: >> >>1. Right-click on the title bar. >> >>2. Click on Properties. >> >>3. In the Options tab, turn on QuickEdit Mode. >> >>4. Click OK. > > I am using Windows7. When I run the command line thingy It's called a console, which is a special window for command-line and text-interface applications. The Windows API includes functions that allow a process to attach to or allocate a console, read from and write to it for standard input & output (i.e. stdin, stdout, stderr), and low-level functions that allow creating complex text interfaces such as text editors (e.g. nano) and file managers (e.g. Far Manager). In Windows 7+, each console is hosted by an instance of conhost.exe. The console host process runs in the same security context (i.e. user, groups, integrity level, and privileges) as the process that allocates the console. python.exe is a console application, which means that it automatically attaches to the console of the parent process or allocates a new console if the parent doesn't have one. > When I try to turn on QuickEdit I get this error message. The console host failed to modify the shortcut. This is probably because the .LNK file was installed for all users, and the current user only has read & execute access. Administrators should have full access to this file. To run with administrator access, right-click the shortcut and choose "Run as administrator". FYI, the console's default settings for the current user are in the registry key "HKCU\Console". On the control menu, this is what the "Defaults" dialog modifies. The "Properties" dialog modifies the settings for the current window, which override the default settings. The current-window settings are stored based on the initial window title. If an application is run from a .LNK shortcut, the Windows shell sets the initial title in the process startup info as the fully-qualified path to the .LNK file and sets a flag that indicates this. In this case, the console knows that the current properties should be read from and written to the .LNK file. If the application is run directly instead of using a shortcut, then the console stores the properties in the registry key "HKCU\Console\[window title]". A custom window title can be set using CMD's `start` command. If no custom title is set, the default title is the fully-qualified path of the executable, which the console normalizes to make it suitable for use as a registry key (e.g. replace backslash with underscore). From no at none.invalid Thu Jul 19 20:29:53 2018 From: no at none.invalid (no at none.invalid) Date: Thu, 19 Jul 2018 20:29:53 -0400 Subject: copy and paste with a program called clipboard References: Message-ID: On Thu, 19 Jul 2018 23:35:05 +0000, eryk sun wrote: >On Thu, Jul 19, 2018 at 6:49 PM, wrote: >> On Thu, 19 Jul 2018 17:35:24 +0100, MRAB >> wrote: >> >>>I'm assuming you're using Windows. >>> >>>It might be that the console window's properties need changing: >>> >>>1. Right-click on the title bar. >>> >>>2. Click on Properties. >>> >>>3. In the Options tab, turn on QuickEdit Mode. >>> >>>4. Click OK. >> >> I am using Windows7. When I run the command line thingy > >It's called a console, which is a special window for command-line and >text-interface applications. The Windows API includes functions that >allow a process to attach to or allocate a console, read from and >write to it for standard input & output (i.e. stdin, stdout, stderr), >and low-level functions that allow creating complex text interfaces >such as text editors (e.g. nano) and file managers (e.g. Far Manager). >In Windows 7+, each console is hosted by an instance of conhost.exe. >The console host process runs in the same security context (i.e. user, >groups, integrity level, and privileges) as the process that allocates >the console. > >python.exe is a console application, which means that it automatically >attaches to the console of the parent process or allocates a new >console if the parent doesn't have one. > >> When I try to turn on QuickEdit I get this error message. > >The console host failed to modify the shortcut. This is probably >because the .LNK file was installed for all users, and the current >user only has read & execute access. Administrators should have full >access to this file. To run with administrator access, right-click the >shortcut and choose "Run as administrator". > >FYI, the console's default settings for the current user are in the >registry key "HKCU\Console". On the control menu, this is what the >"Defaults" dialog modifies. The "Properties" dialog modifies the >settings for the current window, which override the default settings. >The current-window settings are stored based on the initial window >title. If an application is run from a .LNK shortcut, the Windows >shell sets the initial title in the process startup info as the >fully-qualified path to the .LNK file and sets a flag that indicates >this. In this case, the console knows that the current properties >should be read from and written to the .LNK file. If the application >is run directly instead of using a shortcut, then the console stores >the properties in the registry key "HKCU\Console\[window title]". A >custom window title can be set using CMD's `start` command. If no >custom title is set, the default title is the fully-qualified path of >the executable, which the console normalizes to make it suitable for >use as a registry key (e.g. replace backslash with underscore). I was able to run the program as administrator I changed the setting so I can now copy and paste. Thanks From eryksun at gmail.com Thu Jul 19 21:29:28 2018 From: eryksun at gmail.com (eryk sun) Date: Fri, 20 Jul 2018 01:29:28 +0000 Subject: copy and paste with a program called clipboard In-Reply-To: References: Message-ID: On Thu, Jul 19, 2018 at 5:42 PM, Terry Reedy wrote: > > What happens when you right click depends on the program you are interacting > with. When you select and right-click in the current Windows 10 console, > used for Command Prompt, PowerShell, Python, and other programs, the > selection disappears. I just discovered that it also copies to the > clipboard. I also just discovered that right click without a selection > pastes the current clipboard contents. (I usually use ^X, ^C, and ^V.) > Since the console is in the process of being improved, I have no idea how > long this has been true. Prior to Windows 10, the console uses either "quick-edit" or "mark" mode for text selection. If "QuickEdit Mode" is selected in the console properties, mouse events are consumed internally by the console to support text selection. When text is selected, the enter key or right-click copies it. Other keys, including Ctrl+C, cancel the selection. If no text is selected, then right-click pastes the contents of the clipboard. You can also select "Copy" and "Paste" from the edit menu. Quick-edit mode can cause problems since it's easy to accidentally select text, which causes most console functions (e.g. reading from the input buffer) to block until the selection is copied or cancelled. Quick-edit mode also incompatible with text-interface applications that require mouse input. If quick-edit mode is disabled, by default right-click should display the edit menu, which has a "Mark" command. In mark mode you can use the cursor keys (arrows, home, end, page up/down) to position the cursor, and hold shift plus the cursor keys to select text. You can also use the mouse to select and copy text in mark mode. Windows 10 In the new console, selecting "enable Ctrl key shortcuts" enables special support for control characters. In this mode, the old control characters can still be entered by including the shift key (e.g. Ctrl+Shift+V to get ^V). Without shift, we have, for example, Ctrl+F to find text, Ctrl+M to enter mark mode, Ctrl+A to select all text, and Ctrl+V to paste from the clipboard. Regardless of this setting, if text is selected, Ctrl+C copies it to the clipboard. Otherwise, with the default settings and no text selected, Ctrl+C sends a CTRL_C_EVENT to all processes attached to the console. If "extended text selection keys" is selected, text can be selected starting at the current cursor position using the cursor keys while holding shift. Mouse selection is also supported after you start selecting text with the keyboard. It's like mark mode, except only from the current cursor position. If "enable line wrapping selection" is enabled, text is selected by line and wraps as if the screen buffer were a continuous line. Hold Alt to get the classic rectangle selection. The Alt key actually acts like a toggle here. If "enable line wrapping selection" is not selected, then the default is rectangle mode and holding Alt switches to line mode. From larry at hastings.org Thu Jul 19 22:21:06 2018 From: larry at hastings.org (Larry Hastings) Date: Thu, 19 Jul 2018 19:21:06 -0700 Subject: [RELEASED] Python 3.4.9rc1 and Python 3.5.6rc1 are now available Message-ID: <3cd1fce0-6ce1-1812-d3b5-629d618b4315@hastings.org> On behalf of the Python development community, I'm pleased to announce the availability of Python 3.4.9rc1 and Python 3.5.6rc1. Both Python 3.4 and 3.5 are in "security fixes only" mode.? Both versions only accept security fixes, not conventional bug fixes, and both releases are source-only. You can find Python 3.4.9rc1 here: https://www.python.org/downloads/release/python-349rc1/ And you can find Python 3.5.6rc1 here: https://www.python.org/downloads/release/python-356rc1/ Python's entrenched bureaucracy soldiers on, //arry/ From Cecil at decebal.nl Fri Jul 20 02:04:33 2018 From: Cecil at decebal.nl (Cecil Westerhof) Date: Fri, 20 Jul 2018 08:04:33 +0200 Subject: Getting installed version Message-ID: <87601abfym.fsf@munus.decebal.nl> I can get the installed version of a package with: pip2 show cryptography | awk '/^Version: / { print $2 }' But I was wondering if there is a better way. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From brian.j.oney at googlemail.com Fri Jul 20 02:25:04 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Fri, 20 Jul 2018 08:25:04 +0200 Subject: [OT] Bit twiddling homework Message-ID: <1532067904.1643.1.camel@gmail.com> Dear Python-List, an old dog wants to learn some new tricks. Due to my contact with microcontrollers, I am learning C/C++. I am aware that this is the endearing, helpful, yet chatty python-list. Many of you are competent C-programmers. The allure of C is that I can play directly with memory. For example, bitwise operators are neat (here a shift): C: int res = 1 << 4 ?printf("%d\n", res) 16 Translates to pseudocrap: 0000 0001 -> leftwards bitshift of 4 places -> 0001 0000 I think that is pretty neat. After having imbibed the some of the computational basis for binary digits (X?) a few weeks ago, I learned yesterday about hexadecimals (X??). While in the rabbit hole, I learned about Claude Shannon's and Alan Turing's work on digital logic. I am excited to learn about what kind of computations I can do in these number systems. Therefore, what book or learning course do you recommend? I imagine something that tours or skims the fundamentals of Boolean algebra and digital logic, and then goes to C and some fun homework problems. It may seem to you that the emphasis there is wrongly placed. Thank you for the tips. Cheers, Brian PS: Can I twiddle bits in Python? From rosuav at gmail.com Fri Jul 20 02:29:54 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Jul 2018 16:29:54 +1000 Subject: [OT] Bit twiddling homework In-Reply-To: <1532067904.1643.1.camel@gmail.com> References: <1532067904.1643.1.camel@gmail.com> Message-ID: On Fri, Jul 20, 2018 at 4:25 PM, Brian Oney via Python-list wrote: > PS: Can I twiddle bits in Python? You sure can! With most of the same operators that you would in C. The main difference is that Python's integers don't have word size limits; instead of working with, say, 32-bit integer, you just work with "an integer" and it could be a lot larger. For instance, you can take the integer 1 and shift it by any number of places, thus getting any power of two that you want: >>> 1 << 10 1024 >>> 1 << 20 1048576 >>> 1 << 30 1073741824 >>> 1 << 5000 141246703213942603683520966701614733366889617518454111681368808585711816984270751255808912631671152637335603208431366082764203838069979338335971185726639923431051777851865399011877999645131707069373498212631323752553111215372844035950900535954860733418453405575566736801565587405464699640499050849699472357900905617571376618228216434213181520991556677126498651782204174061830939239176861341383294018240225838692725596147005144243281075275629495339093813198966735633606329691023842454125835888656873133981287240980008838073668221804264432910894030789020219440578198488267339768238872279902157420307247570510423845868872596735891805818727796435753018518086641356012851302546726823009250218328018251907340245449863183265637987862198511046362985461949587281119139907228004385942880953958816554567625296086916885774828934449941362416588675326940332561103664556982622206834474219811081872404929503481991376740379825998791411879802717583885498575115299471743469241117070230398103378615232793710290992656444842895511830355733152020804157920090041811951880456705515468349446182731742327685989277607620709525878318766488368348965015474997864119765441433356928012344111765735336393557879214937004347568208665958717764059293592887514292843557047089164876483116615691886203812997555690171892169733755224469032475078797830901321579940127337210694377283439922280274060798234786740434893458120198341101033812506720046609891160700284002100980452964039788704335302619337597862052192280371481132164147186514169090917191909376 >>> Have fun! ChrisA From steve+comp.lang.python at pearwood.info Fri Jul 20 02:37:11 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 20 Jul 2018 06:37:11 +0000 (UTC) Subject: [OT] Bit twiddling homework References: <1532067904.1643.1.camel@gmail.com> Message-ID: On Fri, 20 Jul 2018 08:25:04 +0200, Brian Oney via Python-list wrote: > PS: Can I twiddle bits in Python? Yes. These operators work on ints: bitwise AND: & bitwise OR: | bitwise XOR: ^ -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From tjreedy at udel.edu Fri Jul 20 03:14:23 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Jul 2018 03:14:23 -0400 Subject: copy and paste with a program called clipboard In-Reply-To: References: Message-ID: On 7/19/2018 9:29 PM, eryk sun wrote: > On Thu, Jul 19, 2018 at 5:42 PM, Terry Reedy wrote: >> >> What happens when you right click depends on the program you are interacting >> with. When you select and right-click in the current Windows 10 console, >> used for Command Prompt, PowerShell, Python, and other programs, the >> selection disappears. I just discovered that it also copies to the >> clipboard. I also just discovered that right click without a selection >> pastes the current clipboard contents. (I usually use ^X, ^C, and ^V.) >> Since the console is in the process of being improved, I have no idea how >> long this has been true. > > Prior to Windows 10, the console uses either "quick-edit" or "mark" > mode for text selection. > > If "QuickEdit Mode" is selected in the console properties, mouse > events are consumed internally by the console to support text > selection. When text is selected, the enter key or right-click copies > it. Other keys, including Ctrl+C, cancel the selection. If no text is > selected, then right-click pastes the contents of the clipboard. You > can also select "Copy" and "Paste" from the edit menu. Quick-edit mode > can cause problems since it's easy to accidentally select text, which > causes most console functions (e.g. reading from the input buffer) to > block until the selection is copied or cancelled. Quick-edit mode also > incompatible with text-interface applications that require mouse > input. > > If quick-edit mode is disabled, by default right-click should display > the edit menu, which has a "Mark" command. In mark mode you can use > the cursor keys (arrows, home, end, page up/down) to position the > cursor, and hold shift plus the cursor keys to select text. You can > also use the mouse to select and copy text in mark mode. > > Windows 10 > > In the new console, selecting "enable Ctrl key shortcuts" enables > special support for control characters. In this mode, the old control > characters can still be entered by including the shift key (e.g. > Ctrl+Shift+V to get ^V). Without shift, we have, for example, Ctrl+F > to find text, Ctrl+M to enter mark mode, Ctrl+A to select all text, > and Ctrl+V to paste from the clipboard. Regardless of this setting, if > text is selected, Ctrl+C copies it to the clipboard. Otherwise, with > the default settings and no text selected, Ctrl+C sends a CTRL_C_EVENT > to all processes attached to the console. > > If "extended text selection keys" is selected, text can be selected > starting at the current cursor position using the cursor keys while > holding shift. Mouse selection is also supported after you start > selecting text with the keyboard. It's like mark mode, except only > from the current cursor position. > > If "enable line wrapping selection" is enabled, text is selected by > line and wraps as if the screen buffer were a continuous line. Hold > Alt to get the classic rectangle selection. The Alt key actually acts > like a toggle here. If "enable line wrapping selection" is not > selected, then the default is rectangle mode and holding Alt switches > to line mode. It would be nice if this info could be access from within the Console itself. -- Terry Jan Reedy From tjreedy at udel.edu Fri Jul 20 03:19:16 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 20 Jul 2018 03:19:16 -0400 Subject: Edit with IDLE pull down menu In-Reply-To: <5212ldl22g906b213o51tn8jmmg13ofuqv@4ax.com> References: <1nt1ldt70sgo0tomi52597lofl17308es0@4ax.com> <93fff1ec-ab75-4d6f-b830-50ace4e1389b@googlegroups.com> <5212ldl22g906b213o51tn8jmmg13ofuqv@4ax.com> Message-ID: On 7/19/2018 5:40 PM, no at none.invalid wrote: > The option for Edit with IDLE has an expanding menu. The only item in > the pull down menu is..........Edit with IDLE. What I see is Edit with IDLE 3.7. There should be an entry for each Python installed. Since that is the reason for the 2nd menu, and used to be the case, it is a bug that there is not. I will later check the tracker and maybe open an issue. > So to run a .py program, you have to right click and select the pull > down menu Edit with IDLE and then inside that menu you pick Edit with > IDLE. Seems a little redundant. -- Terry Jan Reedy From brian.j.oney at googlemail.com Fri Jul 20 05:00:09 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Fri, 20 Jul 2018 11:00:09 +0200 Subject: [OT] Bit twiddling homework In-Reply-To: References: <1532067904.1643.1.camel@gmail.com> Message-ID: <1532077209.4647.2.camel@gmail.com> On Fri, 2018-07-20 at 06:37 +0000, Steven D'Aprano wrote: > On Fri, 20 Jul 2018 08:25:04 +0200, Brian Oney via Python-list wrote: > > > PS: Can I twiddle bits in Python? > > Yes. > > These operators work on ints: > > bitwise AND: & > bitwise OR: | > bitwise XOR: ^ > That's right I had forgotten about that. Thank you for the quick answer.Some fun:$ ipythonPython 2.7.13 (default, Nov 24 2017, 17:33:09)?...In [1]: j = 16; i = 1 In [2]: print(i+j); print(i|j)1717 In [3]: %timeit i+j10000000 loops, best of 3: 65.8 ns per loop In [4]: %timeit i|j10000000 loops, best of 3: 73 ns per loop In [5]: %timeit 16|110000000 loops, best of 3: 28.8 ns per loop In [6]: %timeit 16+110000000 loops, best of 3: 28.8 ns per loop I wonder why the difference between [3] and [4]. My mental ranking of speed of operations tells me it should be the other way around. Are 16|1 and 16+1 internally the same operation (for integers)? From 0xff0x666 at gmail.com Fri Jul 20 05:07:21 2018 From: 0xff0x666 at gmail.com (xffox) Date: Fri, 20 Jul 2018 18:07:21 +0900 Subject: [OT] Bit twiddling homework In-Reply-To: <1532067904.1643.1.camel@gmail.com> References: <1532067904.1643.1.camel@gmail.com> Message-ID: <20180720090721.GB7471@hydrogen> On Fri, Jul 20, 2018 at 08:25:04AM +0200, Brian Oney via Python-list wrote: > Therefore, what book or learning course do you recommend? I imagine something that tours or skims > the fundamentals of Boolean algebra and digital logic, and then goes to C and some fun homework > problems. It may seem to you that the emphasis there is wrongly placed. "Hacker's Delight" (please don't judge by the name): https://en.wikipedia.org/wiki/Hacker's_Delight . It's a collection of bit-level hacks. Figuring out each trick before reading the solution can provide a list of fun homework problems. Hope it helps. From rosuav at gmail.com Fri Jul 20 05:13:44 2018 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 20 Jul 2018 19:13:44 +1000 Subject: [OT] Bit twiddling homework In-Reply-To: <1532077209.4647.2.camel@gmail.com> References: <1532067904.1643.1.camel@gmail.com> <1532077209.4647.2.camel@gmail.com> Message-ID: On Fri, Jul 20, 2018 at 7:00 PM, Brian Oney via Python-list wrote: > On Fri, 2018-07-20 at 06:37 +0000, Steven D'Aprano wrote: >> On Fri, 20 Jul 2018 08:25:04 +0200, Brian Oney via Python-list wrote: >> >> > PS: Can I twiddle bits in Python? >> >> Yes. >> >> These operators work on ints: >> >> bitwise AND: & >> bitwise OR: | >> bitwise XOR: ^ >> > That's right I had forgotten about that. Thank you for the quick answer.Some fun:$ ipythonPython 2.7.13 (default, Nov 24 2017, 17:33:09) ...In [1]: j = 16; i = 1 > In [2]: print(i+j); print(i|j)1717 > In [3]: %timeit i+j10000000 loops, best of 3: 65.8 ns per loop > In [4]: %timeit i|j10000000 loops, best of 3: 73 ns per loop > In [5]: %timeit 16|110000000 loops, best of 3: 28.8 ns per loop > In [6]: %timeit 16+110000000 loops, best of 3: 28.8 ns per loop > I wonder why the difference between [3] and [4]. My mental ranking of speed of operations tells me it should be the other way around. > Are 16|1 and 16+1 internally the same operation (for integers)? What you're seeing is nothing but noise. With numbers this low, you can't really judge anything. In fact, operations 5 and 6 are probably just looking up constants that got calculated once, so they're literally proving nothing at all. Even at the CPU level, you'll generally find that adding two numbers takes the same amount of time as bitwise Or, mainly because both of them take a single clock cycle. (Proving that they actually DON'T take the same amount of time requires a fairly deep understanding of the internal workings of the chip.) Definitely at the Python level, the costs are virtually identical. Don't do bitwise operations for the sake of performance; do them because they clearly and adequately describe what you're doing. :) ChrisA From ben.lists at bsb.me.uk Fri Jul 20 07:38:03 2018 From: ben.lists at bsb.me.uk (Ben Bacarisse) Date: Fri, 20 Jul 2018 12:38:03 +0100 Subject: [OT] Bit twiddling homework References: <1532067904.1643.1.camel@gmail.com> <1532077209.4647.2.camel@gmail.com> Message-ID: <871sbyb0is.fsf@bsb.me.uk> Brian Oney writes: > On Fri, 2018-07-20 at 06:37 +0000, Steven D'Aprano wrote: >> On Fri, 20 Jul 2018 08:25:04 +0200, Brian Oney via Python-list wrote: >> >> > PS: Can I twiddle bits in Python? >> >> Yes. >> >> These operators work on ints: >> >> bitwise AND: & >> bitwise OR: | >> bitwise XOR: ^ >> > That's right I had forgotten about that. There's also ~ for bitwise negation. Rather than explain what this means in a language with an unbounded integer type, you might like to experiment, er, a bit. (Excuse the pun.) -- Ben. From grant.b.edwards at gmail.com Fri Jul 20 11:14:37 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 20 Jul 2018 15:14:37 +0000 (UTC) Subject: [OT] Bit twiddling homework References: <1532067904.1643.1.camel@gmail.com> <1532077209.4647.2.camel@gmail.com> Message-ID: On 2018-07-20, Dennis Lee Bieber wrote: > While I suspect Python isn't micro-optimizing, take into account > that most processors do have an "increment"/"decrement" operation -- > since that is done so much at the low-level. Also, just general > integer addition is common, so the hardware may be optimized for > doing them fast. Boolean operations may not be as well optimized. Boolean operations are also very common at the lowest level, and they involve far simpler logic than does addition. I refuse to believe there's an extant processor in common use where an ADD is faster than an OR unless somebody shows me the processor spec sheet. -- Grant Edwards grant.b.edwards Yow! These PRESERVES should at be FORCE-FED to PENTAGON gmail.com OFFICIALS!! From brian.j.oney at googlemail.com Fri Jul 20 11:16:47 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Fri, 20 Jul 2018 17:16:47 +0200 Subject: [OT] Bit twiddling homework In-Reply-To: <20180720090721.GB7471@hydrogen> References: <1532067904.1643.1.camel@gmail.com> <20180720090721.GB7471@hydrogen> Message-ID: <1532099807.1805.0.camel@gmail.com> On Fri, 2018-07-20 at 18:07 +0900, xffox wrote: > On Fri, Jul 20, 2018 at 08:25:04AM +0200, Brian Oney via Python-list wrote: > > Therefore, what book or learning course do you recommend? I imagine something that tours or skims > > the fundamentals of Boolean algebra and digital logic, and then goes to C and some fun homework > > problems. It may seem to you that the emphasis there is wrongly placed. > > "Hacker's Delight" (please don't judge by the name): > https://en.wikipedia.org/wiki/Hacker's_Delight . It's a collection of > bit-level hacks. Figuring out each trick before reading the solution can > provide a list of fun homework problems. Hope it helps. That's what I am looking for. Thank you so much. Have a nice weekend! From rosuav at gmail.com Fri Jul 20 11:49:13 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Jul 2018 01:49:13 +1000 Subject: [OT] Bit twiddling homework In-Reply-To: References: <1532067904.1643.1.camel@gmail.com> <1532077209.4647.2.camel@gmail.com> Message-ID: On Sat, Jul 21, 2018 at 1:14 AM, Grant Edwards wrote: > On 2018-07-20, Dennis Lee Bieber wrote: > >> While I suspect Python isn't micro-optimizing, take into account >> that most processors do have an "increment"/"decrement" operation -- >> since that is done so much at the low-level. Also, just general >> integer addition is common, so the hardware may be optimized for >> doing them fast. Boolean operations may not be as well optimized. > > Boolean operations are also very common at the lowest level, and they > involve far simpler logic than does addition. I refuse to believe > there's an extant processor in common use where an ADD is faster than > an OR unless somebody shows me the processor spec sheet. > "Faster than"? I'd agree with you. But "as fast as"? I believe that's how most modern CPUs already operate. (Well, mostly.) There are sophisticated methods of daisy-chaining the carry bit that mean the overall addition can be performed remarkably quickly, and the end result is a one-clock ADD operation, same as OR. For most data, most code, and most situations, integer addition is exactly as fast as integer bit shift. ChrisA From brian.j.oney at googlemail.com Fri Jul 20 11:56:41 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Fri, 20 Jul 2018 17:56:41 +0200 Subject: [OT] Bit twiddling homework In-Reply-To: References: <1532067904.1643.1.camel@gmail.com> <1532077209.4647.2.camel@gmail.com> Message-ID: <1532102201.1805.2.camel@gmail.com> On Fri, 2018-07-20 at 10:38 -0400, Dennis Lee Bieber wrote: > On Fri, 20 Jul 2018 11:00:09 +0200, Brian Oney via Python-list > declaimed the following: > > > Are 16|1 and 16+1 internally the same operation (for integers)? > > For those integers the EFFECT/RESULT will be the same. But... > > > > > 17 + 1 > > 18 > > > > 17 | 1 > > 17 Of course. There was a reason I chose those integers and timed them. I am ignorant of how Python stores an integer internally. Either way (2^x bit) the result would be the same regardless. In retrospect, I seem to suggest that Python would have different sets of operations for an integer based on it's value; that's poor wording. Anyways. > {From the original post} > > For example, bitwise operators are neat (here a shift): > > C: > > int res = 1 << 4 > > ?printf("%d\n", res) > > 16 > > > > Translates to pseudocrap: > > 0000 0001 -> leftwards bitshift of 4 places -> 0001 0000 > > > > Python also supports shift... > > > > > 17 << 2 > > 68 > > > > 17 >> 2 > > 4 Nice! Once again Python shines as a prototyping language! > [Side comment, even in C bitwise operators aren't really considered playing > "directly with memory". That would be more something like: > > int * i; // i is a pointer (address) to an integer > i = 0x01FF; // set i to access address 511 > printf("%d\n", *i); // print (as integer) whatever is stored at 511 > > THAT you can not do in Python (at least, not without using something like > the ctypes library).] > Thank you for the explanation. That is a nice example. > Hex is basically just a means of shortening a binary string by > representing runs of 4 bits using a single symbol. Same with Octal (runs of > 3 bits). In both cases, each symbol translates to an integral number of > bits, and position in a multi-symbol value can be translated directly. > > This is not possible when representing binary values in Decimal, as > each place in the decimal representation does not map to an integral number > of bits. > Yup! Wikipedia has the same info scattered about the hexadecimal page. You describe it nicely from the perspective of a computer scientist. > > Therefore, what book or learning course do you recommend? I imagine something that tours or skims > > the fundamentals of Boolean algebra and digital logic, and then goes to C and some fun homework > > problems. It may seem to you that the emphasis there is wrongly placed. > > While Boolean algebra and digital logic are core concepts for > computers, neither really appear in books that teach programming. Boolean > logic is more in the realms of pure math and then feeds to digital logic > (at the gate level -- NAND, NOR, AND, OR gates and combinations to create > things like adders). Consider de Morgan's theorem: > > A & B => not(not A | not B) > A | B => not(not A & not B) > > > > > b = 24 > > > > a = 19 > > > > a & b > > 16 > > > > a | b > > 27 > > > > a ^ b > > 11 > > > > ~(~a & ~b) > > 27 > > > > ~(~a | ~b) > > 16 Thank you for the advice. Those are also some nice examples. Cool, I can do this stuff in Python. I guess this is also why Python is so popular; an instructor can take one language and cover a ton of material without having to saddle students with learning another language. > Can't really help with suggesting books -- The ones from my college > days are likely out-of-print; I haven't really had a need to buy newer > books for such basic concepts. Even simple discrete 74xx chips are so rare > these days that the idea of creating a four-bit ADDER from gates is hard to > find. > > Parallax used to have a slew of educational stuff based on BASIC Stamps > and a logic simulator (and project board), but neither appear to still be > in their catalog (the books used to be available as PDF for most of their > educational stuff). I did find a copy on a third-party site for the Digital > Logic intro > http://rambal.com/index.php?controller=attachment&id_attachment=686&usg=AOvVaw3YI9p_blIFAgardqgB2SBq > > Can't find a download for their logical simulator, but there is something > that might be usable at > https://sourceforge.net/projects/cedarlogic/ > > > Just to put this back on topic for the group... > > Pretty much all of what you ask can be learned in Python (and using the > interactive interpreter is a lot faster than writing a C program, compiling > it, etc. -- as can be seen by the cut&paste examples above). It is only > direct hardware access that is not something Python is really suited for > (although AdaFruit has a few boards which run CircuitPython > [MicroPython+special libraries] if you really want to play with LEDs and > such -- though they still don't access raw memory). If you really want > hardware access -- as in the processor registers, memory, etc. -- you are > probably talking about something like Arduino (AVR for Uno/Mega; ARM for > Due)&look-alikes, TIVA-C Launchpads (ARM) [I don't have experience with the > MSP430 Launchpads -- the MSP430 is much different beast from AVR and ARM > processors], STM, AdaFruit (Metro are ARM&CircuitPython, though firmware > can be replaced to work with Arduino IDE). Note that these are > microcontrollers (the ARM versions use Cortex M-x processors) -- the > BeagleBone Black and Raspberry-Pi, in contrast, are microcomputers (anyone > remember when that term meant something like a TRS-80, Apple-II, Commodore > PET ) running full OS, and hence making low level hardware access more > difficult. > Thank you for all the information. Yes, I am tinkering mainly with Arduinos. You may have heard of MySensors; contributing there will give me a chance to learn, help out, and have some fun. The suggestion 'Hackers Delight' is very well suited. Thanks again for the help! Have a nice weekend! From marko at pacujo.net Fri Jul 20 12:39:21 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 20 Jul 2018 19:39:21 +0300 Subject: [OT] Bit twiddling homework References: <1532067904.1643.1.camel@gmail.com> <1532077209.4647.2.camel@gmail.com> Message-ID: <87r2jxuaiu.fsf@elektro.pacujo.net> Chris Angelico : > On Sat, Jul 21, 2018 at 1:14 AM, Grant Edwards > wrote: >> I refuse to believe there's an extant processor in common use where >> an ADD is faster than an OR unless somebody shows me the processor >> spec sheet. > > "Faster than"? I'd agree with you. But "as fast as"? I believe that's > how most modern CPUs already operate. (Well, mostly.) There are > sophisticated methods of daisy-chaining the carry bit that mean the > overall addition can be performed remarkably quickly, and the end > result is a one-clock ADD operation, same as OR. For most data, most > code, and most situations, integer addition is exactly as fast as > integer bit shift. I'm guessing the clock speed is adjusted for the longest propagation delays. According to the maximal gate delay of a 16-bit carry-lookahead-adder is 8 gate delays. A 64-bit addition results in some more delay: Marko From rosuav at gmail.com Fri Jul 20 12:58:39 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 21 Jul 2018 02:58:39 +1000 Subject: [OT] Bit twiddling homework In-Reply-To: <87r2jxuaiu.fsf@elektro.pacujo.net> References: <1532067904.1643.1.camel@gmail.com> <1532077209.4647.2.camel@gmail.com> <87r2jxuaiu.fsf@elektro.pacujo.net> Message-ID: On Sat, Jul 21, 2018 at 2:39 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sat, Jul 21, 2018 at 1:14 AM, Grant Edwards >> wrote: >>> I refuse to believe there's an extant processor in common use where >>> an ADD is faster than an OR unless somebody shows me the processor >>> spec sheet. >> >> "Faster than"? I'd agree with you. But "as fast as"? I believe that's >> how most modern CPUs already operate. (Well, mostly.) There are >> sophisticated methods of daisy-chaining the carry bit that mean the >> overall addition can be performed remarkably quickly, and the end >> result is a one-clock ADD operation, same as OR. For most data, most >> code, and most situations, integer addition is exactly as fast as >> integer bit shift. > > I'm guessing the clock speed is adjusted for the longest propagation > delays. According to > > tion_details> > > the maximal gate delay of a 16-bit carry-lookahead-adder is 8 gate > delays. A 64-bit addition results in some more delay: > > Right; and since "one clock" is sufficient to propagate through all the gates of a 64-bit snake (err, I mean adder), and since "one clock" is also the shortest time from one instruction to the next, the bitwise operation and the arithmetic operation will generally take the same amount of time. Generally. ChrisA From hi at iwoherka.eu Fri Jul 20 13:05:06 2018 From: hi at iwoherka.eu (Iwo Herka) Date: Fri, 20 Jul 2018 13:05:06 -0400 Subject: Unable to install latest version of a package via pip from PyPI Message-ID: Hello, I do not wish to bother you with boring installation problems; however, I would be obliged if someone could spare a minute or two to take a look at my problem. I've recently uploaded a package on PyPI: pypi.org/project/sexpr/. Latest version is 0.1.6 (for Python 3+). Unfortunately, I cannot install it via pip: $ pip install sexpr==0.1.6 Could not find a version that satisfies the requirement sexpr==0.1.6 (from versions: 0.1.6.linux-x86_64, 0.1.2, 0.1.3, 0.1.4, 0.1.5) No matching distribution found for sexpr==0.1.6 However, package is obviously there: $ pip search sexpr sexpr (0.1.6) - S-expression toolkit for Python INSTALLED: 0.1.5 LATEST: 0.1.6 Package was compiled and uploaded in a standard way: $ python3 setup.py sdist bdist_wheel ... $ twine upload dist/* ... setuptools version is 39.0.1. twine version is 1.11.0. wheel version is 0.31.1. I've tried installing with pip version 8.1.1 and 9.0.1. I'm also able to install the package directly from GitHub without problems. setup.py install works too. I'm using venv and pyenv. Am I missing something obvious? Thank you. Iwo Herka From grant.b.edwards at gmail.com Fri Jul 20 13:21:46 2018 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 20 Jul 2018 17:21:46 +0000 (UTC) Subject: [OT] Bit twiddling homework References: <1532067904.1643.1.camel@gmail.com> <1532077209.4647.2.camel@gmail.com> Message-ID: On 2018-07-20, Chris Angelico wrote: > On Sat, Jul 21, 2018 at 1:14 AM, Grant Edwards wrote: >> On 2018-07-20, Dennis Lee Bieber wrote: >> >>> While I suspect Python isn't micro-optimizing, take into account >>> that most processors do have an "increment"/"decrement" operation -- >>> since that is done so much at the low-level. Also, just general >>> integer addition is common, so the hardware may be optimized for >>> doing them fast. Boolean operations may not be as well optimized. >> >> Boolean operations are also very common at the lowest level, and they >> involve far simpler logic than does addition. I refuse to believe >> there's an extant processor in common use where an ADD is faster than >> an OR unless somebody shows me the processor spec sheet. > > "Faster than"? I'd agree with you. My understanding was that the hypothesis was the Python benchmark discrepency might be due to the CPU ADD operation being faster than the OR operator. > But "as fast as"? I believe that's how most modern CPUs already > operate. (Well, mostly.) There are sophisticated methods of > daisy-chaining the carry bit that mean the overall addition can be > performed remarkably quickly, and the end result is a one-clock ADD > operation, same as OR. Definitely. Any modern CPU capable of running Python will have single cycle add/subtract/or/and/not/xor. Addition is so important for so many things that they will have jumped through the hoops required to build a single cycle word-width adder. And/or/not is so simple there's just no sane way to make it take more than one cycle. > For most data, most code, and most situations, integer addition is > exactly as fast as integer bit shift. Yes. -- Grant Edwards grant.b.edwards Yow! Was my SOY LOAF left at out in th'RAIN? It tastes gmail.com REAL GOOD!! From ganesh1pal at gmail.com Fri Jul 20 13:59:21 2018 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Fri, 20 Jul 2018 23:29:21 +0530 Subject: try except inside a with open Message-ID: Dear python Friends, I need a quick suggestion on the below code. def modify_various_line(f): """ Try modifiying various line """ try: f.write('0123456789abcdef') f.seek(5) # Go to the 6th byte in the file print f.read(1) f.seek(-3, 2) # Go to the 3rd byte before the end print f.read(1) f.write('END') except IOError as e: raise return True def h(): try: with open('/tmp/file.txt', 'r+') as f: try: modify_various_line(f) except Exception as e: print e except IOError as e: print(e) h() gpal-cwerzvd-1# python ganesh1.py 5 d gpal-cwerzvd-1# cat /tmp/file.txt 0123456789abcdefEND# (1) Can we use try and expect in a 'with open' function as shown in the below example code . (2) If I hit any other exceptions say Value-error can I catch them as show below try: with open('/tmp/file.txt', 'r+') as f: try: modify_various_line(f) value_list = [str(value) for value in somedict.values()]] except (ValueError,IOError) as e: print e except IOError as e: PS: I don't want to use other way of opening file say file = open(?testfile.txt?,?w?) and also want to retain modify_various_line(f) function , Regards, Ganesh From jladasky at itu.edu Fri Jul 20 14:15:30 2018 From: jladasky at itu.edu (jladasky at itu.edu) Date: Fri, 20 Jul 2018 11:15:30 -0700 (PDT) Subject: [OT] Bit twiddling homework In-Reply-To: References: <1532067904.1643.1.camel@gmail.com> <1532077209.4647.2.camel@gmail.com> Message-ID: <3b46cd4a-78e4-44ff-a43a-e5219b93f89c@googlegroups.com> On Friday, July 20, 2018 at 2:00:26 AM UTC-7, Brian Oney wrote: > Are 16|1 and 16+1 internally the same operation (for integers)? For 16 and 1, the output of the two operations happen to be the same, but generally a bitwise OR is not the same are addition. There are no carry bits in the bitwise operation! 1 + 1 = 2. But 1 | 1 = 1. From hi at iwoherka.eu Fri Jul 20 14:40:36 2018 From: hi at iwoherka.eu (Iwo Herka) Date: Fri, 20 Jul 2018 14:40:36 -0400 Subject: Unable to install latest version of a package via pip from PyPI In-Reply-To: References: Message-ID: Oh. It took a while for the message to go through. In the meantime I've discovered that the source-code archive was badly formatted. Probably something with venv. I've bumped the patch version and re-uploaded. Sorry and thank you. Iwo Herka -------- Original Message -------- On 20 Jul 2018, 7:05 pm, Iwo Herka wrote: > Hello, > > I do not wish to bother you with boring installation problems; however, > I would be obliged if someone could spare a minute or two to take a look at > my problem. > > I've recently uploaded a package on PyPI: pypi.org/project/sexpr/. Latest > version is 0.1.6 (for Python 3+). Unfortunately, I cannot install it via pip: > > $ pip install sexpr==0.1.6 > > Could not find a version that satisfies the requirement sexpr==0.1.6 (from > versions: 0.1.6.linux-x86_64, 0.1.2, 0.1.3, 0.1.4, 0.1.5) > No matching distribution found for sexpr==0.1.6 > > However, package is obviously there: > > $ pip search sexpr > sexpr (0.1.6) - S-expression toolkit for Python > INSTALLED: 0.1.5 > LATEST: 0.1.6 > > Package was compiled and uploaded in a standard way: > > $ python3 setup.py sdist bdist_wheel > ... > $ twine upload dist/* > ... > > setuptools version is 39.0.1. twine version is 1.11.0. wheel version is 0.31.1. > I've tried installing with pip version 8.1.1 and 9.0.1. I'm also able to > install the package directly from GitHub without problems. setup.py install > works too. I'm using venv and pyenv. > > Am I missing something obvious? Thank you. > > Iwo Herka > -- > https://mail.python.org/mailman/listinfo/python-list From useracct222 at gmail.com Fri Jul 20 15:39:38 2018 From: useracct222 at gmail.com (abc abc) Date: Fri, 20 Jul 2018 12:39:38 -0700 (PDT) Subject: Cookies not showing up in environ Message-ID: <789009c6-c0a2-4d41-a599-465dcb6d1036@googlegroups.com> I am trying the simplest of examples below to set and read a cookie. I am using the Django framework, but I have also tried with vanilla python cookies and os.environ. I have posted elsewhere, but this hasn't gotten much attention, so I'd really appreciate any help. Thinking at this point it may be something to with the server, not python. I have tried uwsgi/nginx, gunicorn/nginx, django development server with no success. view.py: def index(environ, start_response, request): if not 'HTTP_COOKIE' in environ: response = HttpResponse("hello") response.set_cookie('user_agreement', 'cookie text', domain='.mysite.com') return response else: print environ['HTTP_COOKIE'] The webpage just prints 'hello' and never reaches the else not matter how many times I refresh the page. There are no cookies in the browser ever either. Am I missing some middleware? I remember some answers to cookie problems related to the order of their middleware configurations. Here's mine: MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] From cspealma at redhat.com Fri Jul 20 15:46:56 2018 From: cspealma at redhat.com (Calvin Spealman) Date: Fri, 20 Jul 2018 15:46:56 -0400 Subject: Cookies not showing up in environ In-Reply-To: <789009c6-c0a2-4d41-a599-465dcb6d1036@googlegroups.com> References: <789009c6-c0a2-4d41-a599-465dcb6d1036@googlegroups.com> Message-ID: You can read cookies from the request via the request.COOKIES dictionary. See the documentation here: https://docs.djangoproject.com/en/2.0/ref/request-response/#django.http.HttpRequest.COOKIES You won't find them in an environment variable, which is shared process-wide and across all requests, because they are bound to each request. This is not a CGI script, so those HTTP_* environment variables you seem to expect won't be here. On Fri, Jul 20, 2018 at 3:39 PM, abc abc wrote: > I am trying the simplest of examples below to set and read a cookie. I am > using the Django framework, but I have also tried with vanilla python > cookies and os.environ. I have posted elsewhere, but this hasn't gotten > much attention, so I'd really appreciate any help. > > Thinking at this point it may be something to with the server, not python. > I have tried uwsgi/nginx, gunicorn/nginx, django development server with no > success. > > view.py: > > def index(environ, start_response, request): > if not 'HTTP_COOKIE' in environ: > response = HttpResponse("hello") > response.set_cookie('user_agreement', 'cookie text', domain='. > mysite.com') > return response > else: > print environ['HTTP_COOKIE'] > > The webpage just prints 'hello' and never reaches the else not matter how > many times I refresh the page. There are no cookies in the browser ever > either. > > Am I missing some middleware? I remember some answers to cookie problems > related to the order of their middleware configurations. Here's mine: > > MIDDLEWARE = [ > 'django.middleware.security.SecurityMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.middleware.common.CommonMiddleware', > 'django.middleware.csrf.CsrfViewMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.contrib.messages.middleware.MessageMiddleware', > 'django.middleware.clickjacking.XFrameOptionsMiddleware', > ] > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Fri Jul 20 16:27:10 2018 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 20 Jul 2018 21:27:10 +0100 Subject: try except inside a with open In-Reply-To: References: Message-ID: <7de7582e-0f3b-f3cd-bb32-3fe5ed5e52a9@mrabarnett.plus.com> On 2018-07-20 18:59, Ganesh Pal wrote: > Dear python Friends, > > > I need a quick suggestion on the below code. > > def modify_various_line(f): > """ Try modifiying various line """ > try: > f.write('0123456789abcdef') > f.seek(5) # Go to the 6th byte in the file > print f.read(1) > f.seek(-3, 2) # Go to the 3rd byte before the end > print f.read(1) > f.write('END') > except IOError as e: > raise > return True > > def h(): > try: > with open('/tmp/file.txt', 'r+') as f: > try: > modify_various_line(f) > except Exception as e: > print e > except IOError as e: > print(e) > > h() > > gpal-cwerzvd-1# python ganesh1.py > 5 > d > gpal-cwerzvd-1# cat /tmp/file.txt > 0123456789abcdefEND# > > > > (1) Can we use try and expect in a 'with open' function as shown in the > below example code . > Yes. > (2) If I hit any other exceptions say Value-error can I catch them as > show below > > try: > with open('/tmp/file.txt', 'r+') as f: > try: > modify_various_line(f) > value_list = [str(value) for value in somedict.values()]] > except (ValueError,IOError) as e: > print e > except IOError as e: > > PS: I don't want to use other way of opening file say file = > open(?testfile.txt?,?w?) and also want to retain modify_various_line(f) > function , > Yes. From hjp-python at hjp.at Fri Jul 20 16:38:46 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 20 Jul 2018 22:38:46 +0200 Subject: Cookies not showing up in environ In-Reply-To: <789009c6-c0a2-4d41-a599-465dcb6d1036@googlegroups.com> References: <789009c6-c0a2-4d41-a599-465dcb6d1036@googlegroups.com> Message-ID: <20180720203846.6kcning7didfvypg@hjp.at> On 2018-07-20 12:39:38 -0700, abc abc wrote: > I am trying the simplest of examples below to set and read a cookie. I > am using the Django framework, but I have also tried with vanilla > python cookies and os.environ. I have posted elsewhere, but this > hasn't gotten much attention, so I'd really appreciate any help. > > Thinking at this point it may be something to with the server, not > python. I have tried uwsgi/nginx, gunicorn/nginx, django development > server with no success. > > view.py: > > def index(environ, start_response, request): > if not 'HTTP_COOKIE' in environ: The first argument to a Django view function is the request object, not anything one could plausibly name "environ". See the django docs on how to access the fields of a request. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From useracct222 at gmail.com Fri Jul 20 17:27:58 2018 From: useracct222 at gmail.com (abc abc) Date: Fri, 20 Jul 2018 14:27:58 -0700 (PDT) Subject: Cookies not showing up in environ In-Reply-To: References: <789009c6-c0a2-4d41-a599-465dcb6d1036@googlegroups.com> <20180720203846.6kcning7didfvypg@hjp.at> Message-ID: <364162e6-f311-4360-8e12-e9946483c05c@googlegroups.com> Well, I'm so messed up between so many sources and tutorials I don't know which way is up. References to environ variable: https://www.python.org/dev/peps/pep-0333/ https://stackoverflow.com/questions/16774952/wsgi-whats-the-purpose-of-start-response-function I read that I have to have a file project/project/wsgi.py that has a function called 'application' that gets called; still a little fuzzy on whose calling it and passing these parameters. I understood that the cookies should be in HTTP_COOKIES inside the environ hash... they're not. From wsgi.py I call a function in my view which returns a response object. Sorry if my parameters don't quite match up, I've been rearranging things while trying to get this to work; it should just be environ and start_response in wsgi:application(). If I try to access the request object, it is None, and I'm not sure how I would get it if it's not coming form wsgi.py:application... My previous example is bad since they are passing 'status' to the start_response which I don't know how got created. TBH: I've spent days and days on this in different forums and am not getting much help or progress. I think I have made some sort of bad assumption in the beginning which is blocking me now. I don't normally like to ask for handouts, but can you please point me to a dead simple setup with wsgi.py and view.py that can handle cookies... just simply setting them and reading them? From steve+comp.lang.python at pearwood.info Fri Jul 20 20:44:05 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 21 Jul 2018 00:44:05 +0000 (UTC) Subject: try except inside a with open References: Message-ID: On Fri, 20 Jul 2018 23:29:21 +0530, Ganesh Pal wrote: > Dear python Friends, > > > I need a quick suggestion on the below code. > > def modify_various_line(f): > """ Try modifiying various line """ > try: > f.write('0123456789abcdef') > f.seek(5) # Go to the 6th byte in the file > print f.read(1) > f.seek(-3, 2) # Go to the 3rd byte before the end > print f.read(1) > f.write('END') > except IOError as e: > raise > return True (1) Since this function always returns True (if it returns at all), what is the point? There's no point checking the return result, since it's always true, so why bother returning anything? (2) What's the point of catching an exception only to immediately, and always, re-raise it? It seems to me that your code above is better written like this: def modify_various_line(f): """ Try modifying various line """ f.write('0123456789abcdef') f.seek(5) # Go to the 6th byte in the file print f.read(1) f.seek(-3, 2) # Go to the 3rd byte before the end print f.read(1) f.write('END') > def h(): > try: > with open('/tmp/file.txt', 'r+') as f: > try: > modify_various_line(f) > except Exception as e: > print e > except IOError as e: > print(e) Debugging is hard enough without destroying useful debugging information. Tracebacks are not your enemy to be hidden and suppressed (at least not during development) but your greatest friend in the world, one who tells you the embarrassing errors you have made (bugs) so you can fix them. https://realpython.com/the-most-diabolical-python-antipattern/ def h(): with open('/tmp/file.txt', 'r+') as f: modify_various_line(f) is much shorter, easier to read, and if an error occurs, you get the benefit of the full traceback not just the abbreviated error message. Tracebacks are printed to standard error, not standard out, so they can be redirected to a log file more easily. Or you can set an error handler for your entire application, so that in production any uncaught exception can be logged without having to fill your application with boilerplate "try...except...print >>sys.stderr, err". But if you *really* have to catch the exception and suppress the traceback, try this: def h(): try: with open('/tmp/file.txt', 'r+') as f: modify_various_line(f) except IOError as e: print(e) There's no need to nest two except clauses, both of which do the same thing with an exception, and one of which will cover up bugs in your code as well as expected failures. > (1) Can we use try and expect in a 'with open' function as shown in > the below example code . Yes. > (2) If I hit any other exceptions say Value-error can I catch them as > show below If you hit ValueError, that is almost always a bug in your code. That's exactly the sort of thing you *shouldn't* be covering up with an except clause unless you really know what you are doing. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From no at none.invalid Fri Jul 20 22:55:44 2018 From: no at none.invalid (no at none.invalid) Date: Fri, 20 Jul 2018 22:55:44 -0400 Subject: Edit with IDLE pull down menu References: <1nt1ldt70sgo0tomi52597lofl17308es0@4ax.com> <93fff1ec-ab75-4d6f-b830-50ace4e1389b@googlegroups.com> <5212ldl22g906b213o51tn8jmmg13ofuqv@4ax.com> Message-ID: On Fri, 20 Jul 2018 03:19:16 -0400, Terry Reedy wrote: >On 7/19/2018 5:40 PM, no at none.invalid wrote: > >> The option for Edit with IDLE has an expanding menu. The only item in >> the pull down menu is..........Edit with IDLE. > >What I see is Edit with IDLE 3.7. There should be an entry for each >Python installed. Since that is the reason for the 2nd menu, and used >to be the case, it is a bug that there is not. I will later check the >tracker and maybe open an issue. > >> So to run a .py program, you have to right click and select the pull >> down menu Edit with IDLE and then inside that menu you pick Edit with >> IDLE. Seems a little redundant. You seem to be able to directly affect Python development. If that is true, maybe you could remove the pull down redundancy from one menu and add a pull down option to another pull down menu. If Python can modify the pull down menus, it would be nice to be able to right click in a folder (Windows) and have an option to create a new python file with a .py extension like you can create a new text document with a .txt extension. OpenOffice adds this option to create new OO files. From no at none.invalid Fri Jul 20 23:11:18 2018 From: no at none.invalid (no at none.invalid) Date: Fri, 20 Jul 2018 23:11:18 -0400 Subject: PyCharm Message-ID: Win7 I was watching some tutorial videos on Python that recommended I use PyCharm and it worked pretty well until I tried to use input. I found this: https://youtrack.jetbrains.com/issue/PY-27891 It says.......... Pavel Karateev commented 10 Jan 2018 11:57 Hi Calvin Broadus! I am sorry for the inconvenience, this is the problem on PyCharm side, the fix is in progress, should be included in the next minor update 2017.3.3, release candidate build is planned on this week. Since I just installed the program yesterday, I assume that the fix has not been implemented yet. Most of my practice programs I always just enter a set value for inputs instead of taking inputs from the keyboard, but I would like to pause so find out why my program is broken. Is there another way to insert a pause that will work with PyCharm? From rustompmody at gmail.com Fri Jul 20 23:48:14 2018 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 20 Jul 2018 20:48:14 -0700 (PDT) Subject: [RELEASED] Python 3.4.9rc1 and Python 3.5.6rc1 are now available In-Reply-To: References: <3cd1fce0-6ce1-1812-d3b5-629d618b4315@hastings.org> Message-ID: On Friday, July 20, 2018 at 7:51:22 AM UTC+5:30, Larry Hastings wrote: ? > the availability of Python 3.4.9rc1 and Python 3.5.6rc1. > Python's entrenched bureaucracy soldiers on, > //arry/ ? And ?? at 325 posts of customary inanity at the recent events but nary a squeak of regret From michael.vilain at gmail.com Fri Jul 20 23:56:41 2018 From: michael.vilain at gmail.com (Michael Vilain) Date: Fri, 20 Jul 2018 20:56:41 -0700 Subject: PyCharm In-Reply-To: References: Message-ID: I'm running PyCharm Edu (to go through their great tutorial). It's version is 2018.1.3, which I got from the web site. Unless you mistyped the version, this is the current release and yours is very old. -- Michael Vilain 650-322-6755 > On 20-Jul-2018, at 8:11 PM ?, no at none.invalid wrote: > > Win7 > > I was watching some tutorial videos on Python that recommended I use > PyCharm and it worked pretty well until I tried to use input. > > I found this: > https://youtrack.jetbrains.com/issue/PY-27891 > > It says.......... > Pavel Karateev commented 10 Jan 2018 11:57 > Hi Calvin Broadus! I am sorry for the inconvenience, this is the > problem on PyCharm side, the fix is in progress, should be included in > the next minor update 2017.3.3, release candidate build is planned on > this week. > > Since I just installed the program yesterday, I assume that the fix > has not been implemented yet. > > Most of my practice programs I always just enter a set value for > inputs instead of taking inputs from the keyboard, but I would like to > pause so find out why my program is broken. > > Is there another way to insert a pause that will work with PyCharm? > -- > https://mail.python.org/mailman/listinfo/python-list From no at none.invalid Sat Jul 21 00:15:52 2018 From: no at none.invalid (no at none.invalid) Date: Sat, 21 Jul 2018 00:15:52 -0400 Subject: PyCharm References: Message-ID: <9mc5ldtuneuc6m7jvh34t3llhqg2p1pc6h@4ax.com> On Fri, 20 Jul 2018 20:56:41 -0700, Michael Vilain wrote: >I'm running PyCharm Edu (to go through their great tutorial). It's version is 2018.1.3, which I got from the web site. Unless you mistyped the version, this is the current release and yours is very old. The date was just from a message posted back in Jan. My version says: PyCharm 2018.1.4 (Community Edition) Build #PC-181.5087.37, built on May 24, 2018 JRE: 1.8.0_152-release-1136-b39 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 7 6.1 When I try to use an input statment, the program freezes. I have to terminate it. What happens when you try to run code with an input statment? From redstone-cold at 163.com Sat Jul 21 03:19:55 2018 From: redstone-cold at 163.com (iMath) Date: Sat, 21 Jul 2018 00:19:55 -0700 (PDT) Subject: send PIL.Image to django server side and get it back In-Reply-To: References: Message-ID: <08aaeacd-b031-45f6-b6f2-11c5857a0c4c@googlegroups.com> Thanks, I solved it finally stackoverflow.com/a/51453785/1485853 From cl at isbd.net Sat Jul 21 04:07:23 2018 From: cl at isbd.net (Chris Green) Date: Sat, 21 Jul 2018 09:07:23 +0100 Subject: Non-GUI, single processort inter process massaging - how? Message-ID: I have a need to allow short-lived 'client' processes to interrogate a single long-lived 'server' process on a small system (specifically a BeagleBone Black). The server process reads values from external hardware and this needs to be done by a single process to ensure that it works as intended and to allow simple smoothing algorithms to be applied. Using multiple processes to do this would be difficult. I want to be able to interrogate the server process from several client processes, some will interrogate it multiple times, others once only. They are mostly (all?) run from the command line (bash). There is no GUI and all these processes will always be on a single system. A single multi-threaded process doesn't really work because I don't see how one could then run something at command line which could get values from the server process. So - what's the best approach to this? I've done some searching and most/many of the solutions seem rather heavyweight for my needs. Am I overlooking something obvious or should I try rethinking the original requirement and look for another approach? (currently each 'client' simply reads the hardware directly using a Python module I have written, however this hits the hardware more than necessary and makes smoothing and such difficul) -- Chris Green ? From ganesh1pal at gmail.com Sat Jul 21 05:43:26 2018 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sat, 21 Jul 2018 15:13:26 +0530 Subject: try except inside a with open In-Reply-To: References: Message-ID: > > > > (1) Since this function always returns True (if it returns at all), what > is the point? There's no point checking the return result, since it's > always true, so why bother returning anything? > > If I don't return anything from a function it returns None. But would it be better if for the function i.e modify_various_line(f) to atleast catch or handle exceptions and log it for debugging purpose Example: def modify_various_line(f): """ Try modifiying various line """ try: f.write('0123456789abcdef') f.seek(5) # Go to the 6th byte in the file print f.read(1) f.seek(-3, 2) # Go to the 3rd byte before the end print f.read(1) f.write('END') except IOError as e: logging.error("Error: got %s" , % (str(e))) From cs at cskk.id.au Sat Jul 21 06:18:11 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 21 Jul 2018 20:18:11 +1000 Subject: try except inside a with open In-Reply-To: References: Message-ID: <20180721101811.GA40170@cskk.homeip.net> Please try to preserve the attribution lines of previous authors. The inner quote below comes from Steven D'Aprano. On 21Jul2018 15:13, Ganesh Pal wrote: >> (1) Since this function always returns True (if it returns at all), what >> is the point? There's no point checking the return result, since it's >> always true, so why bother returning anything? > >If I don't return anything from a function it returns None. But would it >be better if for the function i.e modify_various_line(f) to atleast catch >or handle exceptions and log it for debugging purpose Usually not. Problems with this approach (catches and logging, and _concealing_ the exception from the caller) include: 1: the primary one is: if you do this, the caller will never know that anything went wrong 2: there isn't necessarily any logging setup anyway - small function should not need to know or care, otherwise they're hard to test and may make a lot of unwanted noise Most functions do not know the larger programme context - it is therefore not possible to decide how to handle all exceptions. So unless the exception is anticipated for some specific situation, it is better to let it excape for the caller to handle (or not). Look at your example function: >Example: > >def modify_various_line(f): > """ Try modifiying various line """ > try: > f.write('0123456789abcdef') > f.seek(5) # Go to the 6th byte in the file > print f.read(1) > f.seek(-3, 2) # Go to the 3rd byte before the end > print f.read(1) > f.write('END') > except IOError as e: > logging.error("Error: got %s" , % (str(e))) This function returns None regardless of success or failure. Generally for a function like this, which doesn't return a "result", you want it to return on success and raise an exception on failure. In that way, the caller can presume things are good if no exception occurred. Here you print an error message to the log and return None anyway. Firstly, your error message has no context: there's just an IOError in the log, so nobody can review the log and know what the error is associate with. If the IOError had been allowed to get out, the caller could have responded appropriately (or not, letting the exception further out to someone who can, or aborting the programme if nobody deals with it). This isn't as bad as it sounds; that abort is a symptom of a genuinely unanticipated error, which should be either understood properly and handled, or the invoker of the program should respond to its termination. In a sense, your whole programme is itself a function - if it didn't work, the person invoking it needs to find out. Secondly, because you catch the error, the caller has no way to know the function did not accomplish what the caller expected. That is "silent failure", and generally a bad thing. Consider this trite function: def get_colour(thing, default='black'): try: colour = thing.colour except AttributeError: colour = default return colour Here we handle the case where a thing has no .colour attribute and return a default. The function is designed for this, and has scope for the caller to specify the default. The general rule in Python is: only catch an exception if you know exactly what to do with it, and your function will complete with a _correct_ result if you do it. Conversely, _don't_ try to handle any other situation. (This makes your task easier, too!) Here's an example: import errno ... # clean up a file... try: os.remove(filename) except OSError as e: if e.errno == errno.ENOENT: # it is ok if the file is already gone pass else: raise Here we're catching all OSErrors, but only handling the specific situation we understand (the file doesn't exist, and in this case that is possible and normal). If there was any other kind of OSError (eg a permission error or anything else really - it is all unknown), we reraise the original exception. There are any number of reasons that things can go wrong, including the code _calling_ your function asking for the wrong thing. Letting the exception out lets these situations get debugged. Cheers, Cameron Simpson From ganesh1pal at gmail.com Sat Jul 21 07:37:04 2018 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sat, 21 Jul 2018 17:07:04 +0530 Subject: Better way / regex to extract values form a dictionary Message-ID: I have one of the dictionary values in the below format '/usr/local/ABCD/EDF/ASASAS/GTH/HELLO/MELLO/test04_Failures.log' '/usr/local/ABCD/EDF/GTH/HEL/OOLO/MELLO/test02_Failures.log' '/usr/local/ABCD/EDF/GTH/BEL/LO/MELLO/test03_Failures.log' I need to extract the file name in the path example, say test04_Failure.log and testcase no i.e test04 Here is my solutions: gpal-cwerzvd-1# vi filename.py import re Common_dict = {} Common_dict['filename'] = '/usr/local/ABCD/EDF/GTH/HELLO/MELLO/test04_Failures.log' def return_filename_test_case(filepath): if filepath: filename = re.findall(r'(test\d{1,4}_\S+)', filepath) if filename: testcase = re.findall(r'(test\d{1,4})', ''.join(filename)) return filename, testcase if Common_dict['filename']: path = Common_dict['filename'] fname, testcase = return_filename_test_case(path) print fname, testcase op: qerzvd-1# python filename.py ['test04_Failures.log'] ['test04'] Please suggest how can this code can be optimized further looks messy , what would be your one liner or a simple solution to return both test-case no and filename I am on Python 2.7 and Linux Regards, Ganesh From p.f.moore at gmail.com Sat Jul 21 08:19:03 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Sat, 21 Jul 2018 13:19:03 +0100 Subject: Better way / regex to extract values form a dictionary In-Reply-To: References: Message-ID: def return_filename_test_case(filepath): filename = os.path.basename(filepath) testcase = filename.partition('_')[0] return filename, testcase On 21 July 2018 at 12:37, Ganesh Pal wrote: > I have one of the dictionary values in the below format > > '/usr/local/ABCD/EDF/ASASAS/GTH/HELLO/MELLO/test04_Failures.log' > '/usr/local/ABCD/EDF/GTH/HEL/OOLO/MELLO/test02_Failures.log' > '/usr/local/ABCD/EDF/GTH/BEL/LO/MELLO/test03_Failures.log' > > I need to extract the file name in the path example, say test04_Failure.log > and testcase no i.e test04 > > > Here is my solutions: > > gpal-cwerzvd-1# vi filename.py > import re > > Common_dict = {} > Common_dict['filename'] = > '/usr/local/ABCD/EDF/GTH/HELLO/MELLO/test04_Failures.log' > > def return_filename_test_case(filepath): > if filepath: > filename = re.findall(r'(test\d{1,4}_\S+)', filepath) > if filename: > testcase = re.findall(r'(test\d{1,4})', ''.join(filename)) > > return filename, testcase > > > if Common_dict['filename']: > path = Common_dict['filename'] > fname, testcase = return_filename_test_case(path) > print fname, testcase > > > op: > qerzvd-1# python filename.py > ['test04_Failures.log'] > ['test04'] > > > Please suggest how can this code can be optimized further looks messy , > what would be your one liner or a simple solution to return both test-case > no and filename > > I am on Python 2.7 and Linux > > > Regards, > Ganesh > -- > https://mail.python.org/mailman/listinfo/python-list From steve+comp.lang.python at pearwood.info Sat Jul 21 08:21:05 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 21 Jul 2018 12:21:05 +0000 (UTC) Subject: Better way / regex to extract values form a dictionary References: Message-ID: On Sat, 21 Jul 2018 17:07:04 +0530, Ganesh Pal wrote: > I have one of the dictionary values in the below format > > '/usr/local/ABCD/EDF/ASASAS/GTH/HELLO/MELLO/test04_Failures.log' > '/usr/local/ABCD/EDF/GTH/HEL/OOLO/MELLO/test02_Failures.log' > '/usr/local/ABCD/EDF/GTH/BEL/LO/MELLO/test03_Failures.log' > > I need to extract the file name in the path example, say > test04_Failure.log and testcase no i.e test04 The dictionary is irrelevant to your question. It doesn't matter whether the path came from a dict, a list, read directly from stdin, an environment variable, extracted from a CSV file, or plucked directly from outer space by the programmer. The process remains the same regardless of where the path came from. import os path = '/usr/local/ABCD/EDF/ASASAS/GTH/HELLO/MELLO/test04_Failures.log' filename = os.path.basename(path) print filename # prints 'test04_Failures.log' testcase, remaining_junk = filename.split('_', 1) print testcase # prints 'test04' -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From ganesh1pal at gmail.com Sat Jul 21 08:39:00 2018 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sat, 21 Jul 2018 18:09:00 +0530 Subject: Better way / regex to extract values form a dictionary In-Reply-To: References: Message-ID: > The dictionary is irrelevant to your question. It doesn't matter whether > the path came from a dict, a list, read directly from stdin, an > environment variable, extracted from a CSV file, or plucked directly from > outer space by the programmer. The process remains the same regardless of > where the path came from. > Thanks I was ignorant about this , your solution looks cool . One last question , does it makes sense to check if the values are not none ( If I plan to use the value for next computation ) if not all(filename, testcase): raise ValueError("Error getting filename or testcase no") Regards, Ganesh From steve+comp.lang.python at pearwood.info Sat Jul 21 08:47:10 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 21 Jul 2018 12:47:10 +0000 (UTC) Subject: Non-GUI, single processort inter process massaging - how? References: Message-ID: On Sat, 21 Jul 2018 09:07:23 +0100, Chris Green wrote: [...] > I want to be able to interrogate the server process from several client > processes, some will interrogate it multiple times, others once only. > They are mostly (all?) run from the command line (bash). This sounds like a good approach for signals. Your server script sets up one or more callbacks that print the desired information to stdout, or writes it to a file, whichever is more convenient, and then you send the appropriate signal to the server process from the client processes. At the bash command line, you use the kill command: see `man kill` for details. Here's a tiny demo: # === cut === import signal, os, time state = 0 def sig1(signum, stack): print(time.strftime('it is %H:%m:%S')) def sig2(signum, stack): print("Current state:", stack.f_globals['state']) # Register signal handlers signal.signal(signal.SIGUSR1, sig1) signal.signal(signal.SIGUSR2, sig2) # Print the process ID. print('My PID is:', os.getpid()) while True: state += 1 time.sleep(0.2) # === cut === Run that in one terminal, and the first thing it does is print the process ID. Let's say it prints 12345, over in another terminal, you can run: kill -USR1 12345 kill -USR2 12345 to send the appropriate signals. To do this programmatically from another Python script, use the os.kill() function. https://docs.python.org/3/library/signal.html https://pymotw.com/3/signal/ -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From jon+usenet at unequivocal.eu Sat Jul 21 09:20:59 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sat, 21 Jul 2018 13:20:59 -0000 (UTC) Subject: Cookies not showing up in environ References: <789009c6-c0a2-4d41-a599-465dcb6d1036@googlegroups.com> <20180720203846.6kcning7didfvypg@hjp.at> <364162e6-f311-4360-8e12-e9946483c05c@googlegroups.com> Message-ID: On 2018-07-20, abc abc wrote: > Well, I'm so messed up between so many sources and tutorials I don't > know which way is up. I think one of the main issues is that you don't seem to have decided whether you're writing a WSGI application or a Django application. WSGI: def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain; charset=utf-8')]) return [environ.get('HTTP_COOKIE', '').encode('utf-8')] Django: views.py: from django.http import HttpResponse def cookies(request): return HttpResponse(repr(request.COOKIES), 'text/plain; charset=utf-8') urls.py: from django.urls import path from . import views urlpatterns = [ path('cookies', views.cookies), ] From aldi.kraja at gmail.com Sat Jul 21 10:20:41 2018 From: aldi.kraja at gmail.com (aldi.kraja at gmail.com) Date: Sat, 21 Jul 2018 07:20:41 -0700 (PDT) Subject: pattern block expression matching Message-ID: Hi, I have a long text, which tells me which files from a database were downloaded and which ones failed. The pattern is as follows (at the end of this post). Wrote a tiny program, but still is raw. I want to find term "ERROR" and go 5 lines above and get the name with suffix XPT, in this first case DRXIFF_F.XPT, but it changes in other cases to some other name with suffix XPT. Thanks, Aldi # reading errors from a file txt import re with open('nohup.out', 'r') as fh: lines = fh.readlines() for line in lines: m1 = re.search("XPT", line) m2 = re.search('ERROR', line) if m1: print(line) if m2: print(line) --2018-07-14 21:26:45-- https://wwwn.cdc.gov/Nchs/Nhanes/2009-2010/DRXIFF_F.XPT Resolving wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 Connecting to wwwn.cdc.gov (wwwn.cdc.gov)|198.246.102.39|:443... connected. HTTP request sent, awaiting response... 404 Not Found 2018-07-14 21:26:46 ERROR 404: Not Found. --2018-07-14 21:26:46-- https://wwwn.cdc.gov/Nchs/Nhanes/2009-2010/DRXTOT_F.XPT Resolving wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 Connecting to wwwn.cdc.gov (wwwn.cdc.gov)|198.246.102.39|:443... connected. HTTP request sent, awaiting response... 404 Not Found 2018-07-14 21:26:46 ERROR 404: Not Found. --2018-07-14 21:26:46-- https://wwwn.cdc.gov/Nchs/Nhanes/2009-2010/DRXFMT_F.XPT Resolving wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 Connecting to wwwn.cdc.gov (wwwn.cdc.gov)|198.246.102.39|:443... connected. HTTP request sent, awaiting response... 404 Not Found 2018-07-14 21:26:46 ERROR 404: Not Found. --2018-07-14 21:26:46-- https://wwwn.cdc.gov/Nchs/Nhanes/2009-2010/DSQ1_F.XPT Resolving wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 Connecting to wwwn.cdc.gov (wwwn.cdc.gov)|198.246.102.39|:443... connected. HTTP request sent, awaiting response... 404 Not Found 2018-07-14 21:26:47 ERROR 404: Not Found. --2018-07-14 21:26:47-- https://wwwn.cdc.gov/Nchs/Nhanes/1999-2000/DSII.XPT Resolving wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 Connecting to wwwn.cdc.gov (wwwn.cdc.gov)|198.246.102.39|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 56060880 (53M) [application/octet-stream] Saving to: ?DSII.XPT? From cl at isbd.net Sat Jul 21 10:33:16 2018 From: cl at isbd.net (Chris Green) Date: Sat, 21 Jul 2018 15:33:16 +0100 Subject: Non-GUI, single processort inter process massaging - how? References: Message-ID: Steven D'Aprano wrote: > On Sat, 21 Jul 2018 09:07:23 +0100, Chris Green wrote: > > [...] > > I want to be able to interrogate the server process from several client > > processes, some will interrogate it multiple times, others once only. > > They are mostly (all?) run from the command line (bash). > > > This sounds like a good approach for signals. Your server script sets up > one or more callbacks that print the desired information to stdout, or > writes it to a file, whichever is more convenient, and then you send the > appropriate signal to the server process from the client processes. > [snip useful sample scripts] Yes, maybe, though I was hoping for something a bit more sophisticated. At the moment it's the 'client' processes which manage the output side of things, pushing it across to the 'server' would mean that the client does nothing except send a signal. As the outputs are to quite a variety of things (e.g. terminal screen, serial connection, LCD display) this would push a lot of code to the server which currently is quite nicely separated into client modules. Communicating by file is a possible approach I had considered though, the server can do its smoothing etc. of results and write them to a file which is then read as required by the client processes. The only issue then is the need for some sort of locking as one doesn't want the client to read while the server is writing. One could overcome this by using a temporary file though, mv/rename is supposed to be atomic. Going back to my original request the clients don't really need to be able to 'interrogate' the server, they just need to be able to access results produced by the server. So maybe simply having the server write the values to file is all that's really needed. -- Chris Green ? From python at mrabarnett.plus.com Sat Jul 21 12:37:00 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 21 Jul 2018 17:37:00 +0100 Subject: pattern block expression matching In-Reply-To: References: Message-ID: On 2018-07-21 15:20, aldi.kraja at gmail.com wrote: > Hi, > I have a long text, which tells me which files from a database were downloaded and which ones failed. The pattern is as follows (at the end of this post). Wrote a tiny program, but still is raw. I want to find term "ERROR" and go 5 lines above and get the name with suffix XPT, in this first case DRXIFF_F.XPT, but it changes in other cases to some other name with suffix XPT. Thanks, Aldi > > # reading errors from a file txt > import re > with open('nohup.out', 'r') as fh: > lines = fh.readlines() > for line in lines: > m1 = re.search("XPT", line) > m2 = re.search('ERROR', line) > if m1: > print(line) > if m2: > print(line) > Firstly, you don't need regex for something has simple has checking for the presence of a string. Secondly, I think it's 4 lines above, not 5. 'enumerate' comes in useful here: with open('nohup.out', 'r') as fh: lines = fh.readlines() for i, line in enumerate(lines): if 'ERROR' in line: print(line) print(lines[i - 4]) > > --2018-07-14 21:26:45-- https://wwwn.cdc.gov/Nchs/Nhanes/2009-2010/DRXIFF_F.XPT > Resolving wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 > Connecting to wwwn.cdc.gov (wwwn.cdc.gov)|198.246.102.39|:443... connected. > HTTP request sent, awaiting response... 404 Not Found > 2018-07-14 21:26:46 ERROR 404: Not Found. > > --2018-07-14 21:26:46-- https://wwwn.cdc.gov/Nchs/Nhanes/2009-2010/DRXTOT_F.XPT > Resolving wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 > Connecting to wwwn.cdc.gov (wwwn.cdc.gov)|198.246.102.39|:443... connected. > HTTP request sent, awaiting response... 404 Not Found > 2018-07-14 21:26:46 ERROR 404: Not Found. > > --2018-07-14 21:26:46-- https://wwwn.cdc.gov/Nchs/Nhanes/2009-2010/DRXFMT_F.XPT > Resolving wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 > Connecting to wwwn.cdc.gov (wwwn.cdc.gov)|198.246.102.39|:443... connected. > HTTP request sent, awaiting response... 404 Not Found > 2018-07-14 21:26:46 ERROR 404: Not Found. > > --2018-07-14 21:26:46-- https://wwwn.cdc.gov/Nchs/Nhanes/2009-2010/DSQ1_F.XPT > Resolving wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 > Connecting to wwwn.cdc.gov (wwwn.cdc.gov)|198.246.102.39|:443... connected. > HTTP request sent, awaiting response... 404 Not Found > 2018-07-14 21:26:47 ERROR 404: Not Found. > > --2018-07-14 21:26:47-- https://wwwn.cdc.gov/Nchs/Nhanes/1999-2000/DSII.XPT > Resolving wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 > Connecting to wwwn.cdc.gov (wwwn.cdc.gov)|198.246.102.39|:443... connected. > HTTP request sent, awaiting response... 200 OK > Length: 56060880 (53M) [application/octet-stream] > Saving to: ?DSII.XPT? > From __peter__ at web.de Sat Jul 21 13:20:01 2018 From: __peter__ at web.de (Peter Otten) Date: Sat, 21 Jul 2018 19:20:01 +0200 Subject: pattern block expression matching References: Message-ID: MRAB wrote: > On 2018-07-21 15:20, aldi.kraja at gmail.com wrote: >> Hi, >> I have a long text, which tells me which files from a database were >> downloaded and which ones failed. The pattern is as follows (at the end >> of this post). Wrote a tiny program, but still is raw. I want to find >> term "ERROR" and go 5 lines above and get the name with suffix XPT, in >> this first case DRXIFF_F.XPT, but it changes in other cases to some other >> name with suffix XPT. Thanks, Aldi >> >> # reading errors from a file txt >> import re >> with open('nohup.out', 'r') as fh: >> lines = fh.readlines() >> for line in lines: >> m1 = re.search("XPT", line) >> m2 = re.search('ERROR', line) >> if m1: >> print(line) >> if m2: >> print(line) >> > Firstly, you don't need regex for something has simple has checking for > the presence of a string. > > Secondly, I think it's 4 lines above, not 5. > > 'enumerate' comes in useful here: > > with open('nohup.out', 'r') as fh: > lines = fh.readlines() > for i, line in enumerate(lines): > if 'ERROR' in line: > print(line) > print(lines[i - 4]) Here's an alternative that works when the file is huge, and reading it into memory is impractical: import itertools def get_url(line): return line.rsplit(None, 1)[-1] def pairs(lines, step=4): a, b = itertools.tee(f) return zip(a, itertools.islice(b, step, None)) with open("nohup.out") as f: for s, t in pairs(f, 4): if "ERROR" in t: assert "XPT" in s print(get_url(s)) And here's yet another way that assumes that (1) the groups are separated by empty lines (2) the first line always contains the file name (3) "ERROR" may occur in any of the lines that follow def groups(lines): return ( group for key, group in itertools.groupby(lines, key=str.isspace) if not key ) with open("nohup.out") as f: for group in groups(f): first = next(group) if any("ERROR" in line for line in group): assert "XPT" in first print(get_url(first)) >> --2018-07-14 21:26:45-- >> https://wwwn.cdc.gov/Nchs/Nhanes/2009-2010/DRXIFF_F.XPT Resolving >> wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 Connecting to wwwn.cdc.gov >> (wwwn.cdc.gov)|198.246.102.39|:443... connected. HTTP request sent, >> awaiting response... 404 Not Found 2018-07-14 21:26:46 ERROR 404: Not >> Found. >> >> --2018-07-14 21:26:46-- >> https://wwwn.cdc.gov/Nchs/Nhanes/2009-2010/DRXTOT_F.XPT Resolving >> wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 Connecting to wwwn.cdc.gov >> (wwwn.cdc.gov)|198.246.102.39|:443... connected. HTTP request sent, >> awaiting response... 404 Not Found 2018-07-14 21:26:46 ERROR 404: Not >> Found. >> >> --2018-07-14 21:26:46-- >> https://wwwn.cdc.gov/Nchs/Nhanes/2009-2010/DRXFMT_F.XPT Resolving >> wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 Connecting to wwwn.cdc.gov >> (wwwn.cdc.gov)|198.246.102.39|:443... connected. HTTP request sent, >> awaiting response... 404 Not Found 2018-07-14 21:26:46 ERROR 404: Not >> Found. >> >> --2018-07-14 21:26:46-- >> https://wwwn.cdc.gov/Nchs/Nhanes/2009-2010/DSQ1_F.XPT Resolving >> wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 Connecting to wwwn.cdc.gov >> (wwwn.cdc.gov)|198.246.102.39|:443... connected. HTTP request sent, >> awaiting response... 404 Not Found 2018-07-14 21:26:47 ERROR 404: Not >> Found. >> >> --2018-07-14 21:26:47-- >> https://wwwn.cdc.gov/Nchs/Nhanes/1999-2000/DSII.XPT Resolving >> wwwn.cdc.gov (wwwn.cdc.gov)... 198.246.102.39 Connecting to wwwn.cdc.gov >> (wwwn.cdc.gov)|198.246.102.39|:443... connected. HTTP request sent, >> awaiting response... 200 OK Length: 56060880 (53M) >> [application/octet-stream] Saving to: ?DSII.XPT? >> > From hjp-python at hjp.at Sat Jul 21 13:30:32 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 21 Jul 2018 19:30:32 +0200 Subject: Getting installed version In-Reply-To: <87601abfym.fsf@munus.decebal.nl> References: <87601abfym.fsf@munus.decebal.nl> Message-ID: <20180721173032.yyzytq4podyfd6xa@hjp.at> On 2018-07-20 08:04:33 +0200, Cecil Westerhof wrote: > I can get the installed version of a package with: > pip2 show cryptography | awk '/^Version: / { print $2 }' > > But I was wondering if there is a better way. Using pip probably is the most reliable way (for packages installed via pip). Most packages have version information embedded, and most of them use the attribute __version__: >>> import chardet >>> chardet.__version__ '2.3.0' >>> import colorama >>> colorama.__version__ '0.3.2' >>> import psycopg2 >>> psycopg2.__version__ '2.5.4 (dt dec pq3 ext)' >>> import numpy >>> numpy.__version__ '1.8.2' But there are exceptions: >>> import xlrd >>> xlrd.__VERSION__ '0.9.2' or even: >>> import django >>> django.get_version() '1.7.11' So you can't rely on that. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From no at none.invalid Sat Jul 21 14:17:04 2018 From: no at none.invalid (no at none.invalid) Date: Sat, 21 Jul 2018 14:17:04 -0400 Subject: Edit with IDLE pull down menu References: <1nt1ldt70sgo0tomi52597lofl17308es0@4ax.com> <93fff1ec-ab75-4d6f-b830-50ace4e1389b@googlegroups.com> <5212ldl22g906b213o51tn8jmmg13ofuqv@4ax.com> <697c16b5-8217-4123-9568-cd8023ccaedf@googlegroups.com> Message-ID: On Sat, 21 Jul 2018 08:52:45 -0700 (PDT), Rick Johnson wrote: >n... at none.invalid wrote: >> Terry Reedy wrote: > >[...] > >> You seem to be able to directly affect Python development. >> If that is true, maybe you could remove the pull down >> redundancy from one menu and add a pull down option to >> another pull down menu. If Python can modify the pull down >> menus, it would be nice to be able to right click in a >> folder (Windows) and have an option to create a new python >> file with a .py extension like you can create a new text >> document with a .txt extension. OpenOffice adds this >> option to create new OO files. > >Hmm, your idea is not terribly awful, but, you should >consider that if a "Make New file.XXX" command was added to >the file system context menu for _every_ possible file-type, >*ZOINKS*, that'd be a frighteningly long list of commands to >scroll through! And then, after creating the empty file in >this manner, you'd still have to open the file for editing. >Thus, a two step process. > >A better solution is to use an IDE. Sure, you may have to >navigate to the appropriate directory, but once you're >there, any new documents created from the interface (aka: >"File->New") will default to the current working directory. I don't remember if OO ever asked for permission, but Winrar did. I would hope that install programs asked for permission before adding something like this. And take it with them when they leave. The reason I find this useful is because most of my practice programs so far "import random". I have a shell file that I keep and I copy it to a blank file to start another practice problem. If I try to just "save as" something else, I forget sometimes. From hjp-python at hjp.at Sat Jul 21 14:17:57 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 21 Jul 2018 20:17:57 +0200 Subject: [OT] Bit twiddling homework In-Reply-To: References: <1532067904.1643.1.camel@gmail.com> <1532077209.4647.2.camel@gmail.com> Message-ID: <20180721181757.osrmtal2b2ztvl6w@hjp.at> On 2018-07-20 19:13:44 +1000, Chris Angelico wrote: > On Fri, Jul 20, 2018 at 7:00 PM, Brian Oney via Python-list > wrote: > > That's right I had forgotten about that. Thank you for the quick answer.Some fun:$ ipythonPython 2.7.13 (default, Nov 24 2017, 17:33:09) ...In [1]: j = 16; i = 1 > > In [2]: print(i+j); print(i|j)1717 > > In [3]: %timeit i+j10000000 loops, best of 3: 65.8 ns per loop > > In [4]: %timeit i|j10000000 loops, best of 3: 73 ns per loop > > In [5]: %timeit 16|110000000 loops, best of 3: 28.8 ns per loop > > In [6]: %timeit 16+110000000 loops, best of 3: 28.8 ns per loop > > I wonder why the difference between [3] and [4]. My mental ranking of speed of operations tells me it should be the other way around. > > Are 16|1 and 16+1 internally the same operation (for integers)? > > What you're seeing is nothing but noise. With numbers this low, you > can't really judge anything. Also, Brian is timing Python operations here, not CPU operations. In order to execute an arithmetic or logical operation, the Python interpreter has to execute dozens or hundreds of CPU operations. So the single ADD or OR somewhere in the middle is swamped by other instructions. It is possible that the code performing a numeric addition is a bit better optimized than the code performing a bitwise or. But looking at the source code that doesn't seem to be the case. Might be just an accident, although the difference is remarkably reproducible. Anybody have a CPU emulator handy to trace this clock by clock? ;-) hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From dan at tombstonezero.net Sat Jul 21 14:40:13 2018 From: dan at tombstonezero.net (Dan Sommers) Date: Sat, 21 Jul 2018 18:40:13 +0000 (UTC) Subject: pattern block expression matching References: Message-ID: On Sat, 21 Jul 2018 17:37:00 +0100, MRAB wrote: > On 2018-07-21 15:20, aldi.kraja at gmail.com wrote: >> Hi, >> I have a long text, which tells me which files from a database were downloaded and which ones failed. The pattern is as follows (at the end of this post). Wrote a tiny program, but still is raw. I want to find term "ERROR" and go 5 lines above and get the name with suffix XPT, in this first case DRXIFF_F.XPT, but it changes in other cases to some other name with suffix XPT. Thanks, Aldi >> >> # reading errors from a file txt >> import re >> with open('nohup.out', 'r') as fh: >> lines = fh.readlines() >> for line in lines: >> m1 = re.search("XPT", line) >> m2 = re.search('ERROR', line) >> if m1: >> print(line) >> if m2: >> print(line) >> > Firstly, you don't need regex for something has simple has checking for > the presence of a string. > > Secondly, I think it's 4 lines above, not 5. > > 'enumerate' comes in useful here: > > with open('nohup.out', 'r') as fh: > lines = fh.readlines() > for i, line in enumerate(lines): > if 'ERROR' in line: > print(line) > print(lines[i - 4]) Where's awk when you need it? import fileinput for line in fileinput.fileinput('nohump.out'): if 'XPT' in line: line_containing_filename = line if 'ERROR' in line: print(line_containing_filename) I think Aldi's original approach is pretty good. From sharan.basappa at gmail.com Sat Jul 21 15:06:08 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 21 Jul 2018 12:06:08 -0700 (PDT) Subject: functions vs methods Message-ID: <0933db4c-0851-4442-83aa-e97bff954400@googlegroups.com> Is there a difference between functions and methods in Python. For example, this is the text from tutorialpoint on Python: Python includes the following list functions - cmp, len etc. Python includes following list methods - append, count A related question. Refer to the following lines: 1) len(list) 2) list.append() The first line passes list to a len function while the second line calls append method in list. So, how to interpret this? In the first case, len is a function that python provides to which list can be passed and in the second case, append is a method within list class? If my interpretation is correct, why not make len also as a part of list class itself? Thanks in advance From aldi.kraja at gmail.com Sat Jul 21 16:24:56 2018 From: aldi.kraja at gmail.com (aldi.kraja at gmail.com) Date: Sat, 21 Jul 2018 13:24:56 -0700 (PDT) Subject: pattern block expression matching In-Reply-To: References: Message-ID: Thank you all for thoughtful excellent updates! Aldi From lele at metapensiero.it Sat Jul 21 17:05:35 2018 From: lele at metapensiero.it (Lele Gaifax) Date: Sat, 21 Jul 2018 23:05:35 +0200 Subject: functions vs methods References: <0933db4c-0851-4442-83aa-e97bff954400@googlegroups.com> Message-ID: <87bmb0ti3k.fsf@metapensiero.it> Sharan Basappa writes: > Refer to the following lines: > 1) len(list) > 2) list.append() > > In the first case, len is a function that python provides to which list can be passed and in the second case, append is a method within list class? > > If my interpretation is correct, why not make len also as a part of list class itself? Yes, that's correct. For the reason, see https://docs.python.org/3/faq/design.html#why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From useracct222 at gmail.com Sat Jul 21 17:09:58 2018 From: useracct222 at gmail.com (abc abc) Date: Sat, 21 Jul 2018 14:09:58 -0700 (PDT) Subject: Cookies not showing up in environ In-Reply-To: References: <789009c6-c0a2-4d41-a599-465dcb6d1036@googlegroups.com> <20180720203846.6kcning7didfvypg@hjp.at> <364162e6-f311-4360-8e12-e9946483c05c@googlegroups.com> Message-ID: <5caa8146-ed0a-475a-b523-06d6ba02de43@googlegroups.com> > I think one of the main issues is that you don't seem to have decided > whether you're writing a WSGI application or a Django application. Yes, I suppose I thought Django had to use wsgi to process requests, I didn't know there were 'two' options here. Does your example represent one or the other? My mistake, I should have mentioned I was using Django 1.11 so I had to use url instead of path in urls.py. Below, I have tried to provide as much information as possible. I tried with just the files you provided with slight modifications: project_folder/app/views.py: from django.http import HttpResponse def cookies(request): return HttpResponse(repr(request.COOKIES), 'text/plain; charset=utf-8') def index(request): print 'INDEX: ' print request.COOKIE return HttpResponse('this is the response') project_folder/app/urls.py: from django.conf.urls import url from . import views urlpatterns = [ url('cookies', views.cookies), url('index', views.index), ] project_folder/app/wsgi.py def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain; charset=utf-8')]) return [environ.get('HTTP_COOKIE', '').encode('utf-8')] >From the project folder, I ran 'python manage.py runserver' Cleared all cookies in the browser, and went to localhost:8000/cookies which loaded with no error in the console or browser. No cookies were created in the browser preferences. I tried refreshing the browser for localhost:8000/index but still no cookies. Also, for views.py, the print statement 'INDEX: ' did not appear in the console, nor did the http response string I returned (in either browser or console). So something is not getting processed right. In my previous attempts (to your example code) I had no issue rendering templates and html. The only thing that didn't seem to work were the cookies. Console Output: Performing system checks... System check identified no issues (0 silenced). July 21, 2018 - 20:47:24 Django version 1.11.13, using settings 'omicron.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. [21/Jul/2018 20:47:34] "GET / HTTP/1.1" 200 0 [21/Jul/2018 20:47:34] "GET /favicon.ico HTTP/1.1" 200 0 [21/Jul/2018 20:47:54] "GET / HTTP/1.1" 200 0 [21/Jul/2018 20:47:58] "GET /cookies HTTP/1.1" 200 0 [21/Jul/2018 20:47:58] "GET /favicon.ico HTTP/1.1" 200 0 [21/Jul/2018 20:48:07] "GET /index HTTP/1.1" 200 0 [21/Jul/2018 20:48:08] "GET /favicon.ico HTTP/1.1" 200 0 From useracct222 at gmail.com Sat Jul 21 17:17:37 2018 From: useracct222 at gmail.com (abc abc) Date: Sat, 21 Jul 2018 14:17:37 -0700 (PDT) Subject: Cookies not showing up in environ In-Reply-To: References: <789009c6-c0a2-4d41-a599-465dcb6d1036@googlegroups.com> <20180720203846.6kcning7didfvypg@hjp.at> <364162e6-f311-4360-8e12-e9946483c05c@googlegroups.com> Message-ID: <986c02b2-62f8-489a-b552-1092bd517cc7@googlegroups.com> > I think one of the main issues is that you don't seem to have decided > whether you're writing a WSGI application or a Django application. Yes, I suppose I thought Django had to use wsgi to process requests, I didn't know there were 'two' options here. Does your example represent one or the other? My mistake, I should have mentioned I was using Django 1.11 so I had to use url instead of path in urls.py. Below, I have tried to provide as much information as possible. I tried with just the files you provided with slight modifications: project_folder/app/views.py: from django.http import HttpResponse def cookies(request): return HttpResponse(repr(request.COOKIES), 'text/plain; charset=utf-8') def index(request): print 'INDEX: ' print request.COOKIE return HttpResponse('this is the response') project_folder/app/urls.py: from django.conf.urls import url from . import views urlpatterns = [ url('cookies', views.cookies), url('index', views.index), ] project_folder/app/wsgi.py def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain; charset=utf-8')]) return [environ.get('HTTP_COOKIE', '').encode('utf-8')] >From the project folder, I ran 'python manage.py runserver' Cleared all cookies in the browser, and went to localhost:8000/cookies which loaded with no error in the console or browser. No cookies were created in the browser preferences. I tried refreshing the browser for localhost:8000/index but still no cookies. Also, for views.py, the print statement 'INDEX: ' did not appear in the console, nor did the http response string I returned (in either browser or console). So something is not getting processed right. In my previous attempts (to your example code) I had no issue rendering templates and html. The only thing that didn't seem to work were the cookies. Console Output: Performing system checks... System check identified no issues (0 silenced). July 21, 2018 - 20:47:24 Django version 1.11.13, using settings 'app.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. [21/Jul/2018 20:47:34] "GET / HTTP/1.1" 200 0 [21/Jul/2018 20:47:34] "GET /favicon.ico HTTP/1.1" 200 0 [21/Jul/2018 20:47:54] "GET / HTTP/1.1" 200 0 [21/Jul/2018 20:47:58] "GET /cookies HTTP/1.1" 200 0 [21/Jul/2018 20:47:58] "GET /favicon.ico HTTP/1.1" 200 0 [21/Jul/2018 20:48:07] "GET /index HTTP/1.1" 200 0 [21/Jul/2018 20:48:08] "GET /favicon.ico HTTP/1.1" 200 0 From no at none.invalid Sat Jul 21 19:44:44 2018 From: no at none.invalid (no at none.invalid) Date: Sat, 21 Jul 2018 19:44:44 -0400 Subject: Edit with IDLE pull down menu References: <1nt1ldt70sgo0tomi52597lofl17308es0@4ax.com> <93fff1ec-ab75-4d6f-b830-50ace4e1389b@googlegroups.com> <5212ldl22g906b213o51tn8jmmg13ofuqv@4ax.com> <697c16b5-8217-4123-9568-cd8023ccaedf@googlegroups.com> Message-ID: On Sat, 21 Jul 2018 14:34:15 -0700 (PDT), Rick Johnson wrote: This is really the code I keep copying. import random from random import randint a = [5, 10, 15, 20, 25, 30, 35, 40] b = ["Rock","Paper","Scissors","Lizard ","Spock"] I am lazy and don't type well, so I leave out some details when posting. I don't know why the program I needed randint for didn't work with just import random, but I moved on without lingering on it. From jon+usenet at unequivocal.eu Sat Jul 21 20:48:07 2018 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 22 Jul 2018 00:48:07 -0000 (UTC) Subject: Cookies not showing up in environ References: <789009c6-c0a2-4d41-a599-465dcb6d1036@googlegroups.com> <20180720203846.6kcning7didfvypg@hjp.at> <364162e6-f311-4360-8e12-e9946483c05c@googlegroups.com> <5caa8146-ed0a-475a-b523-06d6ba02de43@googlegroups.com> Message-ID: On 2018-07-21, abc abc wrote: >> I think one of the main issues is that you don't seem to have decided >> whether you're writing a WSGI application or a Django application. > > Yes, I suppose I thought Django had to use wsgi to process requests, > I didn't know there were 'two' options here. Django does use wsgi to process requests. But if you've written an application in Django, you don't need to then write it again without Django - Django has its own wsgi app that will call the Django app for you. > Does your example represent one or the other? Both - I gave two alternatives, and labelled each. You only need one. > project_folder/app/wsgi.py > > def application(environ, start_response): > start_response('200 OK', > [('Content-Type', 'text/plain; charset=utf-8')]) > return [environ.get('HTTP_COOKIE', '').encode('utf-8')] You should delete that and change it back to whatever 'django startproject' gave you originally for wsgi.py. If you're writing a django app then you don't need to also write a wsgi app. > Cleared all cookies in the browser, and went to > localhost:8000/cookies which loaded with no error in the console or > browser. No cookies were created in the browser preferences. Well, you're not setting any cookies. You'd need to do something like: def cookies(request): response = HttpResponse(repr(request.COOKIES), 'text/plain; charset=utf-8') response.set_cookie('mycookie', 'value') return response From lists at janc.be Sat Jul 21 20:57:09 2018 From: lists at janc.be (Jan Claeys) Date: Sun, 22 Jul 2018 02:57:09 +0200 Subject: Non-GUI, single processort inter process massaging - how? In-Reply-To: References: Message-ID: <100ad7ce499594412764a5d00fc31bc364459f06.camel@janc.be> On Sat, 2018-07-21 at 11:50 -0400, Dennis Lee Bieber wrote: > Each client would use the urllib (various names between v2 > and v3) to submit requests to the server, and process the returned > "page". Or the client could even be a bash script using curl, or any other HTTP client... -- Jan Claeys From python at mrabarnett.plus.com Sat Jul 21 21:31:25 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Jul 2018 02:31:25 +0100 Subject: Edit with IDLE pull down menu In-Reply-To: References: <1nt1ldt70sgo0tomi52597lofl17308es0@4ax.com> <93fff1ec-ab75-4d6f-b830-50ace4e1389b@googlegroups.com> <5212ldl22g906b213o51tn8jmmg13ofuqv@4ax.com> <697c16b5-8217-4123-9568-cd8023ccaedf@googlegroups.com> Message-ID: <0b016206-20f0-1f1d-298b-e319bb21974f@mrabarnett.plus.com> On 2018-07-22 00:44, no at none.invalid wrote: > On Sat, 21 Jul 2018 14:34:15 -0700 (PDT), Rick Johnson > wrote: > > This is really the code I keep copying. > > import random > from random import randint > a = [5, 10, 15, 20, 25, 30, 35, 40] > b = ["Rock","Paper","Scissors","Lizard ","Spock"] > > > I am lazy and don't type well, so I leave out some details when > posting. > > I don't know why the program I needed randint for didn't work with > just import random, but I moved on without lingering on it. > When you import 'random', that name refers to the module itself. You can refer to 'randint', which is defined in that module, by writing "random.randint". Alternatively, as you've done, you can import 'randint' directly from the 'random' module. From arj.python at gmail.com Sat Jul 21 22:43:13 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 22 Jul 2018 06:43:13 +0400 Subject: import in code Message-ID: i have found some reputable books that include import within code with ... import x if ... import y def ... import z according to me they should be placed at the top. but an advantage of it is optimisation where you only load modules if necessary so, import within code can be called unpythonic? Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius From arj.python at gmail.com Sat Jul 21 23:24:28 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 22 Jul 2018 07:24:28 +0400 Subject: Make, Sphinx and Windows Message-ID: normally when you use make with sphinx, it should build and tell you errors (so that reviewers don't have to correct it manually) i have been doing some contribs to french docs translation but my make is a bit crazy : https://www.pythonmembers.club/wp-content/uploads/2018/07/make-win.png any idea? thanks --- Abdur-Rahmaan Janhangeer https://github.com/abdur-rahmaanj Mauritius From sharan.basappa at gmail.com Sat Jul 21 23:41:10 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 21 Jul 2018 20:41:10 -0700 (PDT) Subject: functions vs methods In-Reply-To: <9a44d2b6-5b90-4c71-ab96-5bab31470759@googlegroups.com> References: <0933db4c-0851-4442-83aa-e97bff954400@googlegroups.com> <9a44d2b6-5b90-4c71-ab96-5bab31470759@googlegroups.com> Message-ID: <6167938f-ab23-41f4-a579-edce7fd9f137@googlegroups.com> Thanks a lot. On Sunday, 22 July 2018 04:02:23 UTC+5:30, Rick Johnson wrote: > On Saturday, July 21, 2018 at 2:06:21 PM UTC-5, Sharan Basappa wrote: > > Is there a difference between functions and methods in Python. > > Generally speaking, functions and methods are basically two > words describing the exact same thing: "small packages of > reusable code". > > An easy way to think about it for the > uninitiated is that, functions came first, and methods are a > special kind of function which is owned by what we > programmers call "Objects". > > You can learn more about methods > and objects (and a wholelotta other stuff too) by reading > up on "Object Oriented Programming" (aka: OOP). There are > tons of tutorials and examples on the web. Ask Google. > > "What???" o_O > > "Can you repeat that?..." > > [listening carefully] > > "Her???" > > "No, not _her_!" > > "To your left a bit..." > > "..." > > "No, not _that_ left..." (???)? > > "Your _other_ left!" ?(???) > > "..." > > "Oh... for guido's sake, man..." (???) > > "THE ONE WITH THE _PURPLE_ HAIR!!!" (????)? > > "..." > > "BINGO!!!" :-) > > "Now, ask her..." > > > > [...] > > > > A related question. > > > > Refer to the following lines: > > 1) len(list) > > 2) list.append() > > > > The first line passes list to a len function while the > > second line calls append method in list. So, how to > > interpret this? In the first case, len is a function that > > python provides to which list can be passed and in the > > second case, append is a method within list class? > > > First, get yer terminology correct... > > list _object_. > > Not _class_. > > _Object_!!! > > "Class" refers to the syntactical representation of an OOP > _object_ -- aka: meaning that "class" is all the code > written to _define_ an object -- while _object_, refers to > the "live thing" that actually does stuff. For instance: in > the case of a python list _object_ (1) the _object_ acts as > a container for other "live objects", and (2) the _object_ > exposes an interface so we can call methods that perform > certain predefined tasks. > > > If my interpretation is correct, why not make len also as a > > part of list class itself? > > Simple Answer: because Python is not a _pure_ OOP language. > > Yes, python allows us to write code in the OOP paradigm (and > many others), but unlike languages such as, say, Ruby and > Java (which are pure OOP languages), python decided to go > down a different route. And there are good reasons to _not_ > be a pure OOP language, and of course, there are certain > "unintuitive seeming effects" because of that design choice. > And you've stumbled upon one here. > > Congrats! > > Once you familiarize yourself with Python's multi-paradigm > design, and you study more about OOP and experience the > onerous of purely OOP languages, you will understand why > python's designers decided to go this route. > > Until then, i'd worry about something more important. Like > actually mastering the language. And once you've mastered > the language, then you earn the right to sit around here all > day and complain about everything. Like any good Pythinistas > would do. From sharan.basappa at gmail.com Sun Jul 22 00:33:59 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sat, 21 Jul 2018 21:33:59 -0700 (PDT) Subject: print & string formatting Message-ID: Folks, I get a lot confused while using print functions in Python. For example, I get the same results for the following code: str = "one two three" print str print "%s" %(str) So, what is the need to use the second method which I see being used in many programs I am referring to From cs at cskk.id.au Sun Jul 22 00:45:08 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 22 Jul 2018 14:45:08 +1000 Subject: import in code In-Reply-To: References: Message-ID: <20180722044508.GA36081@cskk.homeip.net> On 22Jul2018 06:43, Abdur-Rahmaan Janhangeer wrote: >i have found some reputable books that include import within code > >with ... > import x > >if ... > import y > >def ... > import z > >according to me they should be placed at the top. but an advantage of it is >optimisation where you only load modules if necessary > >so, import within code can be called unpythonic? It is discouraged, because when the imports are at the top they're really obvious. That is a huge gain for maintenance and readability. Importing a module is _usually_ pretty cheap. There are some reasons to put off imports until the code which needs them runs, but they are all fairly rare: Circular imports: 2 codependent modules. If you have: module A: import B module B: import B That won't work: the second import (whichever it turns out to be) will fail. One workaround is to make one of the modules put off the import. A better approach is usually to redesign things so that they don't do a mutual import (move classses etc around, or merge them). This is always feasible, but often is. External dependencies: if your module only sometimes needs a third party facility, you might put off importing that 3rd party module until it is actually needed. As an example, I have a personal project, not yet released, which has a "mount" command, presenting stuff as a local filesystem using the "llfuse" Python module. Aside from that, everything else is self contained. By making the "mount" command do the "import llfuse", there isn't a general requirement for people to install llfuse unless the particularly want that facility. Another example is probing the local environment for available facilities. You may have code that probes for various database backends, for example, and hooks up those found. This is a runtime thing which can happen in the main import block, but may well live better in some "probing" function lower in the module. Antoher example is a variant on the above: modules like SQLAlchemy will accept "database connection URIs", like "mysql://hostname/...". The supporting module might only be loaded if such a URI is encountered. Serverless or tiny workload situations: when a Python program is invoked very frequently, particularly to perform a tiny task, the fewer imports there are the (slightly) faster it will run. Also, sometimes a module might be expensive to import, itself pulling in a lot of other things. In a serverless architecture, Python gets invoked on every call, so making the setup (imports etc) as cheap as possible is suddenly much more important. All of these situations may benefit from doing conditional or deferred imports. But try to avoid them until you have a specific need. Cheers, Cameron Simpson From cs at cskk.id.au Sun Jul 22 00:49:02 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 22 Jul 2018 14:49:02 +1000 Subject: import in code In-Reply-To: <20180722044508.GA36081@cskk.homeip.net> References: <20180722044508.GA36081@cskk.homeip.net> Message-ID: <20180722044902.GA74415@cskk.homeip.net> On 22Jul2018 14:45, Cameron Simpson wrote: >Circular imports: 2 codependent modules. If you have: > > module A: > import B > > module B: > import B > >That won't work: the second import (whichever it turns out to be) will >fail. One workaround is to make one of the modules put off the >import. A better approach is usually to redesign things so that they >don't do a mutual import (move classses etc around, or merge them). >This is always feasible, but often is. That should be "This _isn't_ always feasible, but often is". Sorry, Cameron Simpson From dieter at handshake.de Sun Jul 22 00:52:46 2018 From: dieter at handshake.de (dieter) Date: Sun, 22 Jul 2018 06:52:46 +0200 Subject: functions vs methods References: <0933db4c-0851-4442-83aa-e97bff954400@googlegroups.com> Message-ID: <87d0vfrhwh.fsf@handshake.de> Sharan Basappa writes: > Is there a difference between functions and methods in Python. Somewhat simplified: a method is a function with the method's associated object implicitly passed as first argument. For a Python defined method "m", you can get the corresponding function via "m.__func__" (this is not necessarily true for methods defined in "C", among them built-in methods). From rosuav at gmail.com Sun Jul 22 00:52:50 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 Jul 2018 14:52:50 +1000 Subject: print & string formatting In-Reply-To: References: Message-ID: On Sun, Jul 22, 2018 at 2:53 PM, Abdur-Rahmaan Janhangeer wrote: > *Folks,I get a lot confused while using print functions in Python.For > example, I get the same results for the following code:str = "one two > three"print strprint "%s" %(str)So, what is the need to use the second > method which I see being used in many programs I am referring to* > > well > 1) that is more convenient than concatenation ""+x+"" > 2) no need for casting > x = 64 > "%d" %(x) > 3) the .format() or f'' makes it simpler and reflects the real spirit of py > "{}".format(y) # no need to specify s or d etc Not sure what you mean by "the real spirit of Python", but you can use %s with literally any object at all, and it'll work - in fact, it'll do the same thing that {} does in a format string. But yes, the point of the formatting operations is to do more than just format a string. ChrisA From arj.python at gmail.com Sun Jul 22 00:53:32 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 22 Jul 2018 08:53:32 +0400 Subject: print & string formatting In-Reply-To: References: Message-ID: *Folks,I get a lot confused while using print functions in Python.For example, I get the same results for the following code:str = "one two three"print strprint "%s" %(str)So, what is the need to use the second method which I see being used in many programs I am referring to* well 1) that is more convenient than concatenation ""+x+"" 2) no need for casting x = 64 "%d" %(x) 3) the .format() or f'' makes it simpler and reflects the real spirit of py "{}".format(y) # no need to specify s or d etc -- Abdur-Rahmaan Janhangeer https://github.com/abdur-rahmaanj Mauritius From cs at cskk.id.au Sun Jul 22 00:54:41 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 22 Jul 2018 14:54:41 +1000 Subject: print & string formatting In-Reply-To: References: Message-ID: <20180722045441.GA77133@cskk.homeip.net> On 21Jul2018 21:33, Sharan Basappa wrote: >I get a lot confused while using print functions in Python. > >For example, I get the same results for the following code: > >str = "one two three" Pleasetry not to name variables after builtin classes ("str" is the name of Python's string class). >print str >print "%s" %(str) > >So, what is the need to use the second method which I see being used in many >programs I am referring to For a bare "%s", one would normally just write str(s) where "s" is your string variable. The % formatting is usually for (a) more complex messages or (b) separating the message format from the values. Example: print("The time is %s and the place is %s." % (when, where)) Instead of the much harder to read and maintain: print("The time is", str(when), "and the place is", str(where), ".") Cheers, Cameron Simpson From dieter at handshake.de Sun Jul 22 00:55:50 2018 From: dieter at handshake.de (dieter) Date: Sun, 22 Jul 2018 06:55:50 +0200 Subject: import in code References: Message-ID: <878t63rhrd.fsf@handshake.de> Abdur-Rahmaan Janhangeer writes: > i have found some reputable books that include import within code > > with ... > import x > > if ... > import y > > def ... > import z > > according to me they should be placed at the top. but an advantage of it is > optimisation where you only load modules if necessary Such "local" imports are sometimes important to avoid circular imports. From arj.python at gmail.com Sun Jul 22 00:56:46 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 22 Jul 2018 08:56:46 +0400 Subject: import in code In-Reply-To: <20180722044902.GA74415@cskk.homeip.net> References: <20180722044508.GA36081@cskk.homeip.net> <20180722044902.GA74415@cskk.homeip.net> Message-ID: On Sun, Jul 22, 2018 at 8:49 AM Cameron Simpson wrote: > On 22Jul2018 14:45, Cameron Simpson wrote: > >Circular imports: 2 codependent modules. apart from circular imports? -- Abdur-Rahmaan Janhangeer https://github.com/abdur-rahmaanj Mauritius From arj.python at gmail.com Sun Jul 22 01:03:21 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 22 Jul 2018 09:03:21 +0400 Subject: import in code In-Reply-To: References: <20180722044508.GA36081@cskk.homeip.net> <20180722044902.GA74415@cskk.homeip.net> Message-ID: > > > apart from circular imports? > sorry your last mail was sent to spam by gmail. now seeing it . thank you ! -- Abdur-Rahmaan Janhangeer https://github.com/abdur-rahmaanj Mauritius From ben+python at benfinney.id.au Sun Jul 22 04:01:40 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 22 Jul 2018 18:01:40 +1000 Subject: functions vs methods References: <0933db4c-0851-4442-83aa-e97bff954400@googlegroups.com> Message-ID: <85wotn7l7f.fsf@benfinney.id.au> Sharan Basappa writes: > Is there a difference between functions and methods in Python. Python's documentation includes a useful Glossary. See the terms . Every method is a function; but there are functions that are not methods. What distinguishes a method is that it is associated with a specific class. A method is always a method *of* some class or object. > For example, this is the text from tutorialpoint on Python: > Python includes the following list functions - cmp, len etc. The functions ?cmp?, ?len?, are not associated with any particular class. They can be called without being bound to any object. > Python includes following list methods - append, count That means the functions it is referring to are each methods of ?list?. Any instance of ?list? has methods ?append? and ?count?, bound to that instance. > In the first case, len is a function that python provides to which > list can be passed and in the second case, append is a method within > list class? Yes, that's correct. > If my interpretation is correct, why not make len also as a part of > list class itself? Because ?len? works with *any* sequence, not only lists. To implement it as a method of each sequence type, it would have to be implemented on each type separately, which is a design that is needlessly more complex. This is common in Python: it uses so-called ?duck typing?, where the way an object behaves is more important than its type. Because ?what is the length of this object? is a question valid for a broad variety of types, the design decision was made to allow it to accept any type for which that query makes sense. Your particular question is itself a FAQ . -- \ ?All progress has resulted from people who took unpopular | `\ positions.? ?Adlai Stevenson | _o__) | Ben Finney From sharan.basappa at gmail.com Sun Jul 22 04:37:51 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 22 Jul 2018 01:37:51 -0700 (PDT) Subject: functions vs methods In-Reply-To: References: <0933db4c-0851-4442-83aa-e97bff954400@googlegroups.com> <85wotn7l7f.fsf@benfinney.id.au> Message-ID: <31a46744-aae6-4817-b781-aba1f4ff283e@googlegroups.com> On Sunday, 22 July 2018 13:32:16 UTC+5:30, Ben Finney wrote: > Sharan Basappa writes: > > > Is there a difference between functions and methods in Python. > > Python's documentation includes a useful Glossary. See the terms > > . > > Every method is a function; but there are functions that are not > methods. > > What distinguishes a method is that it is associated with a specific > class. A method is always a method *of* some class or object. > > > For example, this is the text from tutorialpoint on Python: > > Python includes the following list functions - cmp, len etc. > > The functions ?cmp?, ?len?, are not associated with any particular > class. They can be called without being bound to any object. > > > Python includes following list methods - append, count > > That means the functions it is referring to are each methods of ?list?. > Any instance of ?list? has methods ?append? and ?count?, bound to that > instance. > > > In the first case, len is a function that python provides to which > > list can be passed and in the second case, append is a method within > > list class? > > Yes, that's correct. > > > If my interpretation is correct, why not make len also as a part of > > list class itself? > > Because ?len? works with *any* sequence, not only lists. To implement it > as a method of each sequence type, it would have to be implemented on > each type separately, which is a design that is needlessly more complex. > > This is common in Python: it uses so-called ?duck typing?, where the way > an object behaves is more important than its type. Because ?what is the > length of this object? is a question valid for a broad variety of types, > the design decision was made to allow it to accept any type for which > that query makes sense. > > > > Your particular question is itself a FAQ > . > > -- > \ ?All progress has resulted from people who took unpopular | > `\ positions.? ?Adlai Stevenson | > _o__) | > Ben Finney Thanks, Ben From songofacandy at gmail.com Sun Jul 22 04:51:00 2018 From: songofacandy at gmail.com (INADA Naoki) Date: Sun, 22 Jul 2018 17:51:00 +0900 Subject: functions vs methods In-Reply-To: <85wotn7l7f.fsf@benfinney.id.au> References: <0933db4c-0851-4442-83aa-e97bff954400@googlegroups.com> <85wotn7l7f.fsf@benfinney.id.au> Message-ID: > > Your particular question is itself a FAQ > . > Please don't refer the FAQ entry. See this: https://bugs.python.org/issue27671 -- INADA Naoki From tjol at tjol.eu Sun Jul 22 04:54:26 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 22 Jul 2018 10:54:26 +0200 Subject: print & string formatting In-Reply-To: <20180722045441.GA77133@cskk.homeip.net> References: <20180722045441.GA77133@cskk.homeip.net> Message-ID: On 22/07/18 06:54, Cameron Simpson wrote: > On 21Jul2018 21:33, Sharan Basappa wrote: >> I get a lot confused while using print functions in Python. >> >> For example, I get the same results for the following code: >> >> str = "one two three" > > Pleasetry not to name variables after builtin classes ("str" is the name > of Python's string class). > >> print str >> print "%s" %(str) >> >> So, what is the need to use the second method which I see being used >> in many programs I am referring to > > For a bare "%s", one would normally just write str(s) where "s" is your > string variable. > > The % formatting is usually for (a) more complex messages or (b) > separating the message format from the values. Example: > > ?print("The time is %s and the place is %s." % (when, where)) > > Instead of the much harder to read and maintain: > > ?print("The time is", str(when), "and the place is", str(where), ".") Also, the output is different (there's an extra space before the full stop) > > Cheers, > Cameron Simpson From tjol at tjol.eu Sun Jul 22 04:55:40 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 22 Jul 2018 10:55:40 +0200 Subject: Make, Sphinx and Windows In-Reply-To: References: Message-ID: On 22/07/18 05:24, Abdur-Rahmaan Janhangeer wrote: > normally when you use make with sphinx, it should build and tell you errors > (so that reviewers don't have to correct it manually) i have been doing > some contribs to french docs translation but my make is a bit crazy : > > https://www.pythonmembers.club/wp-content/uploads/2018/07/make-win.png What's crazy about this? From arj.python at gmail.com Sun Jul 22 05:04:48 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 22 Jul 2018 13:04:48 +0400 Subject: Make, Sphinx and Windows In-Reply-To: References: Message-ID: @ThomasJollans was supposed to detect errors in trabslation format such as the famous miss of ?space ins?cable etc, not conformed to sphinx notation e.g. if i put an extra space between the : and ` :meth: `some_meth` Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius From ben+python at benfinney.id.au Sun Jul 22 05:08:13 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 22 Jul 2018 19:08:13 +1000 Subject: functions vs methods References: <0933db4c-0851-4442-83aa-e97bff954400@googlegroups.com> <85wotn7l7f.fsf@benfinney.id.au> Message-ID: <85sh4b7i4i.fsf@benfinney.id.au> INADA Naoki writes: > Please don't refer the FAQ entry. > See this: https://bugs.python.org/issue27671 Interesting. Thanks for raising that bug report. I offer my text as a starting point for a better explanation: Because ?len? works with *any* sequence, not only lists. To implement it as a method of each sequence type, it would have to be implemented on each type separately, which is a design that is needlessly more complex. This is common in Python: it uses so-called ?duck typing? , where the way an object behaves is more important than its type. Because ?what is the length of this object? is a question valid for a broad variety of types, the design decision was made to allow it to accept any type for which that query makes sense. Feel free to use that (or something derived from it) to improve the documentation as you suggest. -- \ ?Come on, if your religion is so vulnerable that a little bit | `\ of disrespect is going to bring it down, it's not worth | _o__) believing in, frankly.? ?Terry Gilliam, 2005-01-18 | Ben Finney From kwpolska at gmail.com Sun Jul 22 05:51:51 2018 From: kwpolska at gmail.com (Chris Warrick) Date: Sun, 22 Jul 2018 11:51:51 +0200 Subject: PyCharm In-Reply-To: References: Message-ID: On Sat, 21 Jul 2018 at 05:17, wrote: > > Win7 > > I was watching some tutorial videos on Python that recommended I use > PyCharm and it worked pretty well until I tried to use input. > > I found this: > https://youtrack.jetbrains.com/issue/PY-27891 > > It says.......... > Pavel Karateev commented 10 Jan 2018 11:57 > Hi Calvin Broadus! I am sorry for the inconvenience, this is the > problem on PyCharm side, the fix is in progress, should be included in > the next minor update 2017.3.3, release candidate build is planned on > this week. > > Since I just installed the program yesterday, I assume that the fix > has not been implemented yet. > > Most of my practice programs I always just enter a set value for > inputs instead of taking inputs from the keyboard, but I would like to > pause so find out why my program is broken. > > Is there another way to insert a pause that will work with PyCharm? > -- > https://mail.python.org/mailman/listinfo/python-list How does it fail? What PyCharm version are you on? -- Chris Warrick PGP: 5EAAEA16 From tjol at tjol.eu Sun Jul 22 06:21:25 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 22 Jul 2018 12:21:25 +0200 Subject: Better way / regex to extract values form a dictionary In-Reply-To: References: Message-ID: <7c303ed8-14b0-cbd1-26ef-b8b481a7a58d@tjol.eu> On 21/07/18 14:39, Ganesh Pal wrote: >> The dictionary is irrelevant to your question. It doesn't matter whether >> the path came from a dict, a list, read directly from stdin, an >> environment variable, extracted from a CSV file, or plucked directly from >> outer space by the programmer. The process remains the same regardless of >> where the path came from. >> > > > Thanks I was ignorant about this , your solution looks cool . One last > question , does it makes sense to check if the values are not none ( If I > plan to use the value for next computation ) No, they won't end up being None. However, if there is no '_' in the file name you'll get an exception. > > if not all(filename, testcase): > raise ValueError("Error getting filename or testcase no") > > > Regards, > Ganesh > From sharan.basappa at gmail.com Sun Jul 22 07:32:47 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 22 Jul 2018 04:32:47 -0700 (PDT) Subject: print & string formatting In-Reply-To: References: <20180722045441.GA77133@cskk.homeip.net> Message-ID: On Sunday, 22 July 2018 10:24:55 UTC+5:30, Cameron Simpson wrote: > On 21Jul2018 21:33, Sharan Basappa wrote: > >I get a lot confused while using print functions in Python. > > > >For example, I get the same results for the following code: > > > >str = "one two three" > > Pleasetry not to name variables after builtin classes ("str" is the name of > Python's string class). > > >print str > >print "%s" %(str) > > > >So, what is the need to use the second method which I see being used in many > >programs I am referring to > > For a bare "%s", one would normally just write str(s) where "s" is your string > variable. > > The % formatting is usually for (a) more complex messages or (b) separating the > message format from the values. Example: > > print("The time is %s and the place is %s." % (when, where)) > > Instead of the much harder to read and maintain: > > print("The time is", str(when), "and the place is", str(where), ".") > > Cheers, > Cameron Simpson Thanks. I thin I understand. From sharan.basappa at gmail.com Sun Jul 22 07:47:33 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 22 Jul 2018 04:47:33 -0700 (PDT) Subject: list of lists Message-ID: <8e261f75-03f7-4f80-a516-8318dd138657@googlegroups.com> I am using a third party module that is returning list of lists. I am using the example below to illustrate. 1 results = [['1', 0.99921393753233001]] 2 k = results[0] 3 print k[0] 4 print k[1] Assume the line 1 is what is returned. I am assigning that to another list (k on line 2) and then accessing the 1st and 2nd element in the list (line 3 and 4). How can I access elements of 1 and 0.99 without assigning it to another list? From hi at iwoherka.eu Sun Jul 22 07:55:16 2018 From: hi at iwoherka.eu (Iwo Herka) Date: Sun, 22 Jul 2018 07:55:16 -0400 Subject: list of lists In-Reply-To: <8e261f75-03f7-4f80-a516-8318dd138657@googlegroups.com> References: <8e261f75-03f7-4f80-a516-8318dd138657@googlegroups.com> Message-ID: You can simply unpack the inner list: a, b = results[0] Iwo Herka ??????? Original Message ??????? On 22 July 2018 11:47 AM, Sharan Basappa wrote: > ?? > > I am using a third party module that is returning list of lists. > > I am using the example below to illustrate. > > 1 results = [['1', 0.99921393753233001]] > > 2 k = results[0] > > 3 print k[0] > > 4 print k[1] > > Assume the line 1 is what is returned. > > I am assigning that to another list (k on line 2) and then accessing the 1st and 2nd element in the list (line 3 and 4). > > How can I access elements of 1 and 0.99 without assigning it to another list? > > > -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > https://mail.python.org/mailman/listinfo/python-list From sharan.basappa at gmail.com Sun Jul 22 08:40:20 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 22 Jul 2018 05:40:20 -0700 (PDT) Subject: list of lists In-Reply-To: References: <8e261f75-03f7-4f80-a516-8318dd138657@googlegroups.com> Message-ID: <7a6a2302-582c-4be7-ad97-444b1b5bdc50@googlegroups.com> Thanks. This works in my example. Can you tell me how this works? > You can simply unpack the inner list: > > a, b = results[0] > > > Iwo Herka > > ??????? Original Message ??????? > > On 22 July 2018 11:47 AM, Sharan Basappa wrote: > > > ?? > > > > I am using a third party module that is returning list of lists. > > > > I am using the example below to illustrate. > > > > 1 results = [['1', 0.99921393753233001]] > > > > 2 k = results[0] > > > > 3 print k[0] > > > > 4 print k[1] > > > > Assume the line 1 is what is returned. > > > > I am assigning that to another list (k on line 2) and then accessing the 1st and 2nd element in the list (line 3 and 4). > > > > How can I access elements of 1 and 0.99 without assigning it to another list? > > > > > > -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > > > https://mail.python.org/mailman/listinfo/python-list Thanks From frank at chagford.com Sun Jul 22 08:44:59 2018 From: frank at chagford.com (Frank Millman) Date: Sun, 22 Jul 2018 14:44:59 +0200 Subject: list of lists In-Reply-To: <8e261f75-03f7-4f80-a516-8318dd138657@googlegroups.com> References: <8e261f75-03f7-4f80-a516-8318dd138657@googlegroups.com> Message-ID: "Sharan Basappa" wrote in message news:8e261f75-03f7-4f80-a516-8318dd138657 at googlegroups.com... > > I am using a third party module that is returning list of lists. > I am using the example below to illustrate. > > 1 results = [['1', 0.99921393753233001]] > 2 k = results[0] > 3 print k[0] > 4 print k[1] > > Assume the line 1 is what is returned. > I am assigning that to another list (k on line 2) and then accessing the > 1st and 2nd element in the list (line 3 and 4). > > How can I access elements of 1 and 0.99 without assigning it to another > list? > As you say, results is a list of lists. results[0] returns the first inner list. There could potentially be more than one, in which case results[1] would return the second one. Use len(results) to find out how many inner lists there are. results[0][0] returns the first element of the first inner list. results[0][1] returns the second element of the first inner list. HTH Frank Millman From sharan.basappa at gmail.com Sun Jul 22 08:48:39 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 22 Jul 2018 05:48:39 -0700 (PDT) Subject: coding style - where to declare variables Message-ID: In other programming languages (e.g. C, C++), as a good practice, variables are declared right at the start of the program, irrespective of where it is normally used. What is the practice in Python? I see that, most of the code, declare variables where it is used and not at the start of the program. From sharan.basappa at gmail.com Sun Jul 22 08:53:16 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 22 Jul 2018 05:53:16 -0700 (PDT) Subject: list of lists In-Reply-To: References: <8e261f75-03f7-4f80-a516-8318dd138657@googlegroups.com> Message-ID: On Sunday, 22 July 2018 18:15:23 UTC+5:30, Frank Millman wrote: > "Sharan Basappa" wrote in message > news:8e261f75-03f7-4f80-a516-8318dd138657 at googlegroups.com... > > > > I am using a third party module that is returning list of lists. > > I am using the example below to illustrate. > > > > 1 results = [['1', 0.99921393753233001]] > > 2 k = results[0] > > 3 print k[0] > > 4 print k[1] > > > > Assume the line 1 is what is returned. > > I am assigning that to another list (k on line 2) and then accessing the > > 1st and 2nd element in the list (line 3 and 4). > > > > How can I access elements of 1 and 0.99 without assigning it to another > > list? > > > > As you say, results is a list of lists. > > results[0] returns the first inner list. There could potentially be more > than one, in which case results[1] would return the second one. Use > len(results) to find out how many inner lists there are. > > results[0][0] returns the first element of the first inner list. > > results[0][1] returns the second element of the first inner list. > > HTH > > Frank Millman Thanks. I initially thought about this but did not know if this is legal syntax. The following is the updated code taking into account what you suggested and the previous posted. results = [['1', 0.99921393753233001]] k = results[0] print k[0] print k[1] a,b = results[0] print a print b x = results[0][0] y = results[0][1] print x print y From hi at iwoherka.eu Sun Jul 22 09:04:21 2018 From: hi at iwoherka.eu (Iwo Herka) Date: Sun, 22 Jul 2018 09:04:21 -0400 Subject: list of lists In-Reply-To: <7a6a2302-582c-4be7-ad97-444b1b5bdc50@googlegroups.com> References: <8e261f75-03f7-4f80-a516-8318dd138657@googlegroups.com> <7a6a2302-582c-4be7-ad97-444b1b5bdc50@googlegroups.com> Message-ID: > Can you tell me how this works? "results[0]" returns a list with two elements. Let's call it "pair" pair = results[0] # ['1', 0.99921393753233001] Now, we can use regular sequence unpacking to retrieve first and second argument: a, b = pair which is equivalent to this: a = pair[0] b = pair[1] If you're not sure how many items you have in a list, you can use an asterisk operator: li = [1, 2, 3, 4] a, b, *c = li which is equivalent to: a = li[0] b = li[1] c = li[2:] ?Iwo Herka https://github.com/IwoHerka? ??????? Original Message ??????? On 22 July 2018 12:40 PM, Sharan Basappa wrote: > ?? > > Thanks. This works in my example. Can you tell me how this works? > > > You can simply unpack the inner list: > > > > a, b = results[0] > > > > > > Iwo Herka > > > > ??????? Original Message ??????? > > > > On 22 July 2018 11:47 AM, Sharan Basappa sharan.basappa at gmail.com wrote: > > > > > I am using a third party module that is returning list of lists. > > > > > > I am using the example below to illustrate. > > > > > > 1 results = [['1', 0.99921393753233001]] > > > > > > 2 k = results[0] > > > > > > 3 print k[0] > > > > > > 4 print k[1] > > > > > > Assume the line 1 is what is returned. > > > > > > I am assigning that to another list (k on line 2) and then accessing the 1st and 2nd element in the list (line 3 and 4). > > > > > > How can I access elements of 1 and 0.99 without assigning it to another list? > > > > > > https://mail.python.org/mailman/listinfo/python-list > > Thanks > > > ---------- > > https://mail.python.org/mailman/listinfo/python-list From ojaskushagra98 at gmail.com Sun Jul 22 09:04:46 2018 From: ojaskushagra98 at gmail.com (ojas gupta) Date: Sun, 22 Jul 2018 18:34:46 +0530 Subject: Error installing scripts in python 37-32 Message-ID: Explaining the whole scenario in detail : I open command prompt and go to C: then I enter "pip install mysqlclient" (Double inverted commas is just for highlights .) After pressing enter key it installs some data and after a while an error comes up saying "import setuptools, tokensize;_file_=" (Tho it is just one line out of all the error displayed . It's too long to type .)... PLEASE HELP !!! Regards , Ojas From sharan.basappa at gmail.com Sun Jul 22 09:19:15 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Sun, 22 Jul 2018 06:19:15 -0700 (PDT) Subject: list of lists In-Reply-To: References: <8e261f75-03f7-4f80-a516-8318dd138657@googlegroups.com> <7a6a2302-582c-4be7-ad97-444b1b5bdc50@googlegroups.com> Message-ID: <77d19b73-d497-48e6-bd1b-1bd81b1cc355@googlegroups.com> On Sunday, 22 July 2018 18:34:41 UTC+5:30, Iwo Herka wrote: > > Can you tell me how this works? > > "results[0]" returns a list with two elements. Let's call it "pair" > > pair = results[0] > # ['1', 0.99921393753233001] > > Now, we can use regular sequence unpacking to retrieve first and second argument: > > a, b = pair > > which is equivalent to this: > > a = pair[0] > b = pair[1] > > If you're not sure how many items you have in a list, you can use an asterisk operator: > > li = [1, 2, 3, 4] > a, b, *c = li > > which is equivalent to: > > a = li[0] > b = li[1] > c = li[2:] > > > ?Iwo Herka > https://github.com/IwoHerka? > > ??????? Original Message ??????? > > On 22 July 2018 12:40 PM, Sharan Basappa wrote: > > > ?? > > > > Thanks. This works in my example. Can you tell me how this works? > > > > > You can simply unpack the inner list: > > > > > > a, b = results[0] > > > > > > > > > Iwo Herka > > > > > > ??????? Original Message ??????? > > > > > > On 22 July 2018 11:47 AM, Sharan Basappa sharan.basappa at gmail.com wrote: > > > > > > > I am using a third party module that is returning list of lists. > > > > > > > > I am using the example below to illustrate. > > > > > > > > 1 results = [['1', 0.99921393753233001]] > > > > > > > > 2 k = results[0] > > > > > > > > 3 print k[0] > > > > > > > > 4 print k[1] > > > > > > > > Assume the line 1 is what is returned. > > > > > > > > I am assigning that to another list (k on line 2) and then accessing the 1st and 2nd element in the list (line 3 and 4). > > > > > > > > How can I access elements of 1 and 0.99 without assigning it to another list? > > > > > > > > https://mail.python.org/mailman/listinfo/python-list > > > > Thanks > > > > > > ---------- > > > > https://mail.python.org/mailman/listinfo/python-list Thanks a lot. I have seen this syntax earlier but did not understand this fully. Thanks a lot. From Richard at Damon-family.org Sun Jul 22 09:36:13 2018 From: Richard at Damon-family.org (Richard Damon) Date: Sun, 22 Jul 2018 09:36:13 -0400 Subject: coding style - where to declare variables In-Reply-To: References: Message-ID: <35961E2E-EE4E-4E99-9DAE-7FFD06002C30@Damon-family.org> > On Jul 22, 2018, at 8:48 AM, Sharan Basappa wrote: > > In other programming languages (e.g. C, C++), as a good practice, variables are declared right at the start of the program, irrespective of where it is normally used. What is the practice in Python? > > I see that, most of the code, declare variables where it is used and not at the start of the program. I would disagree that it is universally considered good practice to declare everything at the front. (There is much disagreement on this, but most consider declare at first use to be preferred, where possible). Last century, C code required this to make things easier on the compiler, and some code bases and examples go back that far, so they use that method out of inertia. From rosuav at gmail.com Sun Jul 22 09:39:02 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 22 Jul 2018 23:39:02 +1000 Subject: coding style - where to declare variables In-Reply-To: References: Message-ID: On Sun, Jul 22, 2018 at 10:48 PM, Sharan Basappa wrote: > In other programming languages (e.g. C, C++), as a good practice, variables are declared right at the start of the program, irrespective of where it is normally used. What is the practice in Python? > > I see that, most of the code, declare variables where it is used and not at the start of the program. Common practice in Python is to never declare your variables, since Python doesn't have variable declarations. ChrisA From arj.python at gmail.com Sun Jul 22 09:51:50 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 22 Jul 2018 17:51:50 +0400 Subject: coding style - where to declare variables In-Reply-To: References: Message-ID: except local vars Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius From breamoreboy at gmail.com Sun Jul 22 10:38:24 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Sun, 22 Jul 2018 15:38:24 +0100 Subject: import in code In-Reply-To: <20180722044508.GA36081@cskk.homeip.net> References: <20180722044508.GA36081@cskk.homeip.net> Message-ID: On 22/07/18 05:45, Cameron Simpson wrote: > On 22Jul2018 06:43, Abdur-Rahmaan Janhangeer wrote: >> i have found some reputable books that include import within code >> >> with ... >> ?? import x >> >> if ... >> ?? import y >> >> def ... >> ??? import z >> >> according to me they should be placed at the top. but an advantage of >> it is >> optimisation where you only load modules if necessary >> >> so, import within code can be called unpythonic? > > It is discouraged, because when the imports are at the top they're > really obvious. That is a huge gain for maintenance and readability. > > Importing a module is _usually_ pretty cheap. There are some reasons to > put off imports until the code which needs them runs, but they are all > fairly rare: > > Circular imports: 2 codependent modules. If you have: > > ?module A: > ?? import B > > ?module B: > ?? import B > > That won't work: the second import (whichever it turns out to be) will > fail. One workaround is to make one of the modules put off the import. A > better approach is usually to redesign things so that they don't do a > mutual import (move classses etc around, or merge them). This is always > feasible, but often is. > I don't ever recall seeing a module try to import itself, but then perhaps you meant module B should be importing module A? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at gmail.com Sun Jul 22 10:42:13 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Sun, 22 Jul 2018 15:42:13 +0100 Subject: Error installing scripts in python 37-32 In-Reply-To: References: Message-ID: On 22/07/18 14:04, ojas gupta wrote: > Explaining the whole scenario in detail : > > I open command prompt and go to C: then I enter "pip install mysqlclient" > (Double inverted commas is just for highlights .) After pressing enter key > it installs some data and after a while an error comes up saying "import > setuptools, tokensize;_file_=" (Tho it is just one line out of all the > error displayed . It's too long to type .)... > > PLEASE HELP !!! > > Regards , > Ojas > Please cut and paste the entire traceback. There are some smart people on this forum but I'm not aware of any mind readers :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From breamoreboy at gmail.com Sun Jul 22 10:46:36 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Sun, 22 Jul 2018 15:46:36 +0100 Subject: coding style - where to declare variables In-Reply-To: References: Message-ID: On 22/07/18 14:51, Abdur-Rahmaan Janhangeer wrote: > except local vars > > Abdur-Rahmaan Janhangeer > https://github.com/Abdur-rahmaanJ > Mauritius > Python doesn't have variables, it has names. Please can we avoid a long meaningless thread on this subject as it's been discussed a trillion times before. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From hjp-python at hjp.at Sun Jul 22 11:28:09 2018 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 22 Jul 2018 17:28:09 +0200 Subject: coding style - where to declare variables In-Reply-To: <35961E2E-EE4E-4E99-9DAE-7FFD06002C30@Damon-family.org> References: <35961E2E-EE4E-4E99-9DAE-7FFD06002C30@Damon-family.org> Message-ID: <20180722152809.3u7axngkfubc2py2@hjp.at> On 2018-07-22 09:36:13 -0400, Richard Damon wrote: > > On Jul 22, 2018, at 8:48 AM, Sharan Basappa wrote: > > > > In other programming languages (e.g. C, C++), as a good practice, > > variables are declared right at the start of the program, There is no "start of the program" in C or C++. I assume that "start of the function" was meant since "start of the compilation unit" would mean that all variables are global (at least within the compilation unit) which hopefully nobody considers a good practice. > > irrespective of where it is normally used. What is the practice in > > Python? > > > > I see that, most of the code, declare variables where it is used and > > not at the start of the program. > > I would disagree that it is universally considered good practice to > declare everything at the front. (There is much disagreement on this, > but most consider declare at first use to be preferred, where > possible). > Last century, C code required this to make things easier on the > compiler, Nope. The language description in the German translation of K&R I (1984) already shows declarations at the beginning of each block, not just each function. The main text doesn't seem to mention this and all examples declare variables at the start of each function, so it is possible that this feature was added between the release of the original (1978) and the German translation. But in any case block scope existed by 1984, well before the turn of the century. So the authors of C considered block scoped variables desirable from the beginning or at least added them quite early. I would therefore assume that they considered declaring variables in a block as good practice. C++ introduced the possibility to declare variables at any point in a block, not just the beginning. C copied this in C99. Again I would argue that Stroustrup introduced the feature because he considered declaring variables for the smallest possible scope as good practice, and that the C committee copied it because they agreed. hp -- _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp at hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From tjol at tjol.eu Sun Jul 22 11:34:39 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Sun, 22 Jul 2018 17:34:39 +0200 Subject: list of lists In-Reply-To: References: <8e261f75-03f7-4f80-a516-8318dd138657@googlegroups.com> Message-ID: On 22/07/18 14:53, Sharan Basappa wrote: > Thanks. I initially thought about this but did not know if this is legal syntax. In this kind of situation ? you think you know how to do something but you're not quite sure if it'll work as intended ? just try it! Start up an interactive interpreter, or write a test script (as you appear to have done). If it doesn't work, that's fine. No harm done. Also, please use Python 3. From python at mrabarnett.plus.com Sun Jul 22 11:49:03 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 22 Jul 2018 16:49:03 +0100 Subject: functions vs methods In-Reply-To: <85sh4b7i4i.fsf@benfinney.id.au> References: <0933db4c-0851-4442-83aa-e97bff954400@googlegroups.com> <85wotn7l7f.fsf@benfinney.id.au> <85sh4b7i4i.fsf@benfinney.id.au> Message-ID: <5b8baa9d-c978-0e7a-2169-1ff212877298@mrabarnett.plus.com> On 2018-07-22 10:08, Ben Finney wrote: > INADA Naoki writes: > >> Please don't refer the FAQ entry. >> See this: https://bugs.python.org/issue27671 > > Interesting. Thanks for raising that bug report. > > I offer my text as a starting point for a better explanation: > > Because ?len? works with *any* sequence, not only lists. To > implement it as a method of each sequence type, it would have to be > implemented on each type separately, which is a design that is > needlessly more complex. > > This is common in Python: it uses so-called ?duck typing? > , > where the way an object behaves is more important than its type. > Because ?what is the length of this object? is a question valid for > a broad variety of types, the design decision was made to allow it > to accept any type for which that query makes sense. > > Feel free to use that (or something derived from it) to improve the > documentation as you suggest. > Doesn't it have to be implemented on each type anyway? The advantage is that it's enforces consistency. In Java (or is it C#?) I seem to remember that some classes have a .Length attribute, some have a .Length() method, and some have a .Count() method. In Python they're all len(...). From no at none.invalid Sun Jul 22 13:19:40 2018 From: no at none.invalid (no at none.invalid) Date: Sun, 22 Jul 2018 13:19:40 -0400 Subject: PyCharm References: Message-ID: On Sun, 22 Jul 2018 11:51:51 +0200, Chris Warrick wrote: >On Sat, 21 Jul 2018 at 05:17, wrote: >> >> Win7 >> >> I was watching some tutorial videos on Python that recommended I use >> PyCharm and it worked pretty well until I tried to use input. >> >> I found this: >> https://youtrack.jetbrains.com/issue/PY-27891 >> >> It says.......... >> Pavel Karateev commented 10 Jan 2018 11:57 >> Hi Calvin Broadus! I am sorry for the inconvenience, this is the >> problem on PyCharm side, the fix is in progress, should be included in >> the next minor update 2017.3.3, release candidate build is planned on >> this week. >> >> Since I just installed the program yesterday, I assume that the fix >> has not been implemented yet. >> >> Most of my practice programs I always just enter a set value for >> inputs instead of taking inputs from the keyboard, but I would like to >> pause so find out why my program is broken. >> >> Is there another way to insert a pause that will work with PyCharm? >> -- >> https://mail.python.org/mailman/listinfo/python-list > >How does it fail? What PyCharm version are you on? I have learned that it is not failing, but it doesn't do what I expected. When I run a program that has an input statement, the cursor doesn't move from the edit code to the place in Pycharm where the input statement is. I have to click my mouse on the end of the input line before entering a value. If I just start typing, the text is inserted in the code and not in the running part of the program. From arj.python at gmail.com Sun Jul 22 15:43:19 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 22 Jul 2018 23:43:19 +0400 Subject: ongoing browser projects Message-ID: apart from grail, any ongoing browser projects? i need an html renderer (one of the most badly missed features of py, PEP anyone?) thanks, Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius From marko at pacujo.net Sun Jul 22 15:50:52 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 22 Jul 2018 22:50:52 +0300 Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> Message-ID: <87r2jvrqw3.fsf@elektro.pacujo.net> ram at zedat.fu-berlin.de (Stefan Ram): >>Rebinding names is near-universal in programming, but usually names >>that are intended to be rebound, such as variables. > > To someone like me who has grown up with a LISP 1 > this is completely natural. > > |>( SETQ A ( LAMBDA () 'ALPHA )) > |(LAMBDA () 'ALPHA) "Setq" is the dirty little secret of LISP. Scheme marks its shameful primitives with an exclamation mark. Thus, its assignment primitive is "set!". I wish people stopped talking about "name binding" and "rebinding," which are simply posh synonyms for variable assignment. Properly, the term "binding" comes from lambda calculus, whose semantics is defined using "bound" and "free" variables. Lambda calculus doesn't have assignment. More about variable binding here: Marko From rosuav at gmail.com Sun Jul 22 16:09:24 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 Jul 2018 06:09:24 +1000 Subject: functions vs methods In-Reply-To: <5b8baa9d-c978-0e7a-2169-1ff212877298@mrabarnett.plus.com> References: <0933db4c-0851-4442-83aa-e97bff954400@googlegroups.com> <85wotn7l7f.fsf@benfinney.id.au> <85sh4b7i4i.fsf@benfinney.id.au> <5b8baa9d-c978-0e7a-2169-1ff212877298@mrabarnett.plus.com> Message-ID: On Mon, Jul 23, 2018 at 1:49 AM, MRAB wrote: > On 2018-07-22 10:08, Ben Finney wrote: >> >> INADA Naoki writes: >> >>> Please don't refer the FAQ entry. >>> See this: https://bugs.python.org/issue27671 >> >> >> Interesting. Thanks for raising that bug report. >> >> I offer my text as a starting point for a better explanation: >> >> Because ?len? works with *any* sequence, not only lists. To >> implement it as a method of each sequence type, it would have to be >> implemented on each type separately, which is a design that is >> needlessly more complex. >> >> This is common in Python: it uses so-called ?duck typing? >> , >> where the way an object behaves is more important than its type. >> Because ?what is the length of this object? is a question valid for >> a broad variety of types, the design decision was made to allow it >> to accept any type for which that query makes sense. >> >> Feel free to use that (or something derived from it) to improve the >> documentation as you suggest. >> > Doesn't it have to be implemented on each type anyway? Not always. If you have an actual protocol like __len__, then yes, but there are many protocols that cover multiple functions. For instance, once you define __add__, you can perform addition with your object - both "x + 1" and "1 + x", and even "x += 1". And once you define __iter__, all manner of things suddenly start working. (That's probably the biggest one.) ChrisA From rosuav at gmail.com Sun Jul 22 16:10:45 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 Jul 2018 06:10:45 +1000 Subject: ongoing browser projects In-Reply-To: References: Message-ID: On Mon, Jul 23, 2018 at 5:43 AM, Abdur-Rahmaan Janhangeer wrote: > apart from grail, any ongoing browser projects? > > i need an html renderer (one of the most badly missed features of py, PEP > anyone?) Have you looked on PyPI? https://pypi.org/ ChrisA From marko at pacujo.net Sun Jul 22 16:14:19 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 22 Jul 2018 23:14:19 +0300 Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> Message-ID: <87muujrpt0.fsf@elektro.pacujo.net> Bart : > If you did need one of those others to be variable, then you just assign > it to a variable the rare times you need to do that. For example: > > def fn1(): pass > def fn2(): pass > > fn = fn1 if cond else fn2 > > fn1, fn2 will always be functions. fn will always be a variable, but one > that can change between referring to fn1, fn2 or anything else. In high-level programming languages, functions are ordinary values. You can perform similar operations on functions as on integers or strings. You can give me two functions, and I can use those two to create a third function: def compose(f1, f2): def composition(x): return f1(f2(x)) return composition Here "compose", "composition", "f1" and "f2" are variables: * "compose" gets assigned when the first, outer "def" statement is executed, * "f1" and "f2" get assigned when the function held by "compose" is called, * "composition" gets assigned when the inner "def" statement is executed. While FORTRAN or C couldn't operate on functions like this, an assembly language program could easily. Simply compose a CPU instruction sequence on the fly, mark it executable and use the "CALL" opcode to transfer control to your constructed function. In the same vein, you could understand the "def" statement as a runtime compiler that takes the function body, compiles it into machine language and assigns the start address to the given variable. In fact, that would be a perfectly working way to implement "def." Whether it would be a smart thing to do is a different question. Key is, though, that "def" always creates a new *data* object that can be called as *executable code*. Marko From Richard at Damon-family.org Sun Jul 22 16:16:37 2018 From: Richard at Damon-family.org (Richard Damon) Date: Sun, 22 Jul 2018 16:16:37 -0400 Subject: coding style - where to declare variables In-Reply-To: <87r2jvrqw3.fsf@elektro.pacujo.net> References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> Message-ID: <86582198-8544-43C0-BC4B-7AE763F9954E@Damon-family.org> > On Jul 22, 2018, at 3:50 PM, Marko Rauhamaa wrote: > I wish people stopped talking about "name binding" and "rebinding," > which are simply posh synonyms for variable assignment. Properly, the > term "binding" comes from lambda calculus, whose semantics is defined > using "bound" and "free" variables. Lambda calculus doesn't have > assignment. > > More about variable binding here: https://en.wikipedia.org/wiki/Free_variables_and_bound_variables> > > > Marko Marko, I think the term binding makes sense in python due to how names work. In python and the following code: X = getit() Y = X X.changeit() In python, presuming getit() returns some form of object (so it has a changeit() member) then X and Y are bound to the same object, and changeit() will thus also affect the object that we see at Y. With a language with more ?classical? variable, the assignment of Y = X would normal make a copy of that object, so the value Y does not get changed by X.changeit(). From rosuav at gmail.com Sun Jul 22 16:38:27 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 Jul 2018 06:38:27 +1000 Subject: coding style - where to declare variables In-Reply-To: <87muujrpt0.fsf@elektro.pacujo.net> References: <%a15D.1738293$LD3.1136776@fx18.am4> <87muujrpt0.fsf@elektro.pacujo.net> Message-ID: On Mon, Jul 23, 2018 at 6:14 AM, Marko Rauhamaa wrote: > While FORTRAN or C couldn't operate on functions like this, an assembly > language program could easily. Simply compose a CPU instruction sequence > on the fly, mark it executable and use the "CALL" opcode to transfer > control to your constructed function. ... right up until the point where you realize that this is a massive security vulnerability, so you get a segmentation fault (or "protection fault" under Windows) for trying to execute a non-executable segment. > In the same vein, you could understand the "def" statement as a runtime > compiler that takes the function body, compiles it into machine language > and assigns the start address to the given variable. In fact, that would > be a perfectly working way to implement "def." Whether it would be a > smart thing to do is a different question. Key is, though, that "def" > always creates a new *data* object that can be called as *executable > code*. Here's a simpler way to describe it: The 'def' statement creates a function and assigns it to the name given. Tada! No need to talk about compilers and addresses and stuff, which are utterly irrelevant in Python. ChrisA From marko at pacujo.net Sun Jul 22 17:08:00 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 23 Jul 2018 00:08:00 +0300 Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> <86582198-8544-43C0-BC4B-7AE763F9954E@Damon-family.org> Message-ID: <87effvrnbj.fsf@elektro.pacujo.net> Richard Damon : >> On Jul 22, 2018, at 3:50 PM, Marko Rauhamaa wrote: >> I wish people stopped talking about "name binding" and "rebinding," >> which are simply posh synonyms for variable assignment. Properly, the >> term "binding" comes from lambda calculus, whose semantics is defined >> using "bound" and "free" variables. Lambda calculus doesn't have >> assignment. > > Marko, I think the term binding makes sense in python due to how names > work. In python and the following code: > > X = getit() > Y = X > X.changeit() > > In python, presuming getit() returns some form of object (so it has a > changeit() member) then X and Y are bound to the same object, and > changeit() will thus also affect the object that we see at Y. Would you call it binding in this case: X[0]["z"] = getit() X[3]["q"] = X[0]["z"] X[0]["z"].changeit() I think what you are talking about is more usually called "referencing." > With a language with more ?classical? variable, the assignment of Y = > X would normal make a copy of that object, so the value Y does not get > changed by X.changeit(). I Java terms, all Python values are boxed. That's a very usual pattern in virtually all programming languages (apart from FORTRAN). Marko From tjol at tjol.eu Sun Jul 22 18:52:21 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 23 Jul 2018 00:52:21 +0200 Subject: ongoing browser projects In-Reply-To: References: Message-ID: On 22/07/18 21:43, Abdur-Rahmaan Janhangeer wrote: > apart from grail, any ongoing browser projects? > > i need an html renderer (one of the most badly missed features of py, PEP > anyone?) Nobody writes browser engines. It's too hard to do what the available open source ones do half as well as they already do it. You can use webkit (of safari/chrome/etc. fame), or you can use gecko (mozilla). Webkit is easy to embed with PyQt or PyGObject/gtk+3. I don't know about gecko. -- Thomas > > thanks, > > Abdur-Rahmaan Janhangeer > https://github.com/Abdur-rahmaanJ > Mauritius > From steve+comp.lang.python at pearwood.info Sun Jul 22 19:43:06 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 22 Jul 2018 23:43:06 +0000 (UTC) Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> Message-ID: On Sun, 22 Jul 2018 22:50:52 +0300, Marko Rauhamaa wrote: > I wish people stopped talking about "name binding" and "rebinding," > which are simply posh synonyms for variable assignment. Properly, the > term "binding" comes from lambda calculus, whose semantics is defined > using "bound" and "free" variables. Lambda calculus doesn't have > assignment. So let me see if I understand your argument... - we should stop using the term "binding", because it means nothing different from assignment; - binding (a.k.a. "assignment") comes from lambda calculus; - which has no assignment (a.k.a. "binding"). Which leads us to the conclusion that lambda calculus both has and doesn't have binding a.k.a. assignment at the same time. Perhaps it is a quantum phenomenon. Are you happy with the contradiction inherent in your statements, or would you prefer to reword your argument? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jul 22 20:09:29 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 23 Jul 2018 00:09:29 +0000 (UTC) Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> <86582198-8544-43C0-BC4B-7AE763F9954E@Damon-family.org> <87effvrnbj.fsf@elektro.pacujo.net> Message-ID: On Mon, 23 Jul 2018 00:08:00 +0300, Marko Rauhamaa wrote: > Would you call it binding in this case: > > X[0]["z"] = getit() > X[3]["q"] = X[0]["z"] > X[0]["z"].changeit() It is a binding, but it is not a *name* binding. Since we are talking about name bindings, and comparing/contrasting them to variable assignment in classical languages, I don't think that binding to slots in hash tables or arrays is relevant except to muddy the waters and make things more complicated than they need be. > I think what you are talking about is more usually called "referencing." I don't think so. Its certainly not a term I've ever heard in this context before. >> With a language with more ?classical? variable, the assignment of Y = X >> would normal make a copy of that object, so the value Y does not get >> changed by X.changeit(). > > I Java terms, all Python values are boxed. Correct. Java mixes two different models of variable assignment: it uses classical C- and Pascal-like variable assignment for primitive values, and Lisp- and Smalltalk-like name binding for boxed values (objects), leading to two distinct sets of behaviour. That makes Java a good lesson in why it is useful to distinguish between two models of name binding. Java is not the only language with the distinction between "value types" (primitive values usually stored on the stack) and "reference types" (usually objects stored in the heap). C# and other .Net languages often make that distinction: http://net-informations.com/faq/general/valuetype-referencetype.htm Swift is another such language. Other languages which use primarily or exclusively value-types (i.e. the "variables are a named box at a fixed memory location" model) include Algol, Pascal, Modula-3, C, C++, C#, Objective C, D, Swift, COBOL, Forth, Ada, PL/I, Rust and many others. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Sun Jul 22 20:16:37 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 23 Jul 2018 00:16:37 +0000 (UTC) Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> <86582198-8544-43C0-BC4B-7AE763F9954E@Damon-family.org> <87effvrnbj.fsf@elektro.pacujo.net> <4nu9ldtsfhm2dbbrn75t7n9b2c6nlh80rv@4ax.com> Message-ID: On Sun, 22 Jul 2018 17:50:06 -0400, Dennis Lee Bieber wrote: > On Mon, 23 Jul 2018 00:08:00 +0300, Marko Rauhamaa > declaimed the following: > >>I Java terms, all Python values are boxed. That's a very usual pattern >>in virtually all programming languages (apart from FORTRAN). >> >> > FORTRAN, C, COBOL, BASIC, Pascal, ALGOL, BCPL, REXX, VMS DCL, > probably R, Matlab, APL. > > I never encountered the term "boxed" until trying to read some of > the O'Reilly books on Java. > > In my world, Java and Python are the ones that are not "common". Indeed. Its not just older languages from the 60s and 70s with value-type variables. Newer languages intended as systems languages, like Rust and Go, do the same. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From vandys at vsta.org Sun Jul 22 20:41:25 2018 From: vandys at vsta.org (Andy Valencia) Date: Sun, 22 Jul 2018 17:41:25 -0700 Subject: PEP 572 implementation for Python Message-ID: <153230648584.19634.1140717086403621509@pacman.vsta.org> Hi, just an FYI (and request for comments). I've coded up PEP 572 on top of "Tauthon" (sometimes in early days known as "Python 2.8"): https://github.com/vandys/tauthon (branch pep572) After reading the PEP, Guido's comments, and looking at the code, I realized that := just wants to be an augmented assignment operator, and that what's really needed is to make all the augmented assignment operators be expressions. I also made them all *just* expressions, with higher precedence than comma, but lower than the rest. Also right associative, so: a := b := c := 1 does what you expect without any special "multi assignment" code, but just because expressions with right association do the right thing anyway. As augmented assignments are now just expressions, you can do: while buf := ob.read(): ... but also: if (self.count += 1) > PROBLEM: ... In the interests of orthogonality, I did *not* add code to disable places where some expressions--but not these new ones--could be used. Go ahead and say: a := 1 at the top level if that's what floats your boat. Regards, Andy Valencia From akkana at shallowsky.com Sun Jul 22 21:43:54 2018 From: akkana at shallowsky.com (Akkana Peck) Date: Sun, 22 Jul 2018 19:43:54 -0600 Subject: ongoing browser projects In-Reply-To: References: Message-ID: <20180723014354.GE1166@shallowsky.com> > On 22/07/18 21:43, Abdur-Rahmaan Janhangeer wrote: > > i need an html renderer (one of the most badly missed features of py, PEP > > anyone?) I think both GTK and Qt have basic HTML rendering widgets, for simple tasks, but if you want something that behaves more like a browser (javascript, link following, events), those probably won't be good enough. Thomas Jollans writes: > Nobody writes browser engines. It's too hard to do what the available > open source ones do half as well as they already do it. > > You can use webkit (of safari/chrome/etc. fame), or you can use gecko > (mozilla). Webkit is easy to embed with PyQt or PyGObject/gtk+3. I don't > know about gecko. More specifically, QtWebEngine under PyQt5 (possibly also PyQt4). The documentation is scanty, and doesn't cover Python at all, only C++, but it works very well, using Blink (the library behind Chromium) so it handles nearly all modern web pages. There used to be a Python-WebKit-GTK2 library that was fairly easy to use and even had documentation, but it's been orphaned for years, and in any case a lot of the modern web no longer works with the old WebKit engine. You'd think there would be something newer (ideally based on Blink) that worked with GTK3/GIO, but I never found anything. I don't know of any way to use Gecko from Python (except, of course, sending remote commands to Firefox). ...Akkana From rosuav at gmail.com Sun Jul 22 21:58:40 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 Jul 2018 11:58:40 +1000 Subject: ongoing browser projects In-Reply-To: <20180723014354.GE1166@shallowsky.com> References: <20180723014354.GE1166@shallowsky.com> Message-ID: On Mon, Jul 23, 2018 at 11:43 AM, Akkana Peck wrote: >> On 22/07/18 21:43, Abdur-Rahmaan Janhangeer wrote: >> > i need an html renderer (one of the most badly missed features of py, PEP >> > anyone?) > > I think both GTK and Qt have basic HTML rendering widgets, for > simple tasks, but if you want something that behaves more like > a browser (javascript, link following, events), those probably > won't be good enough. Don't know about Qt, but the GTK one is more like "a document display widget that happens to use HTML tags to annotate text". It can do colour, for instance. But layout is basically just flowing text; you can't plop down a
and have separate flow layout boxes. It's a far cry from a modern web browser. Even just rendering a static web page (no JS, no links, no events, no CSS) would be a long way beyond it. ChrisA From no at none.invalid Sun Jul 22 23:17:24 2018 From: no at none.invalid (no at none.invalid) Date: Sun, 22 Jul 2018 23:17:24 -0400 Subject: For next loops Message-ID: x = range (5) y = range (5) for ply in x: for com in y: if ply==com: result="Tie" print(ply,com,result) Why is ply always equal to com? 0 0 Tie 0 1 Tie 0 2 Tie 0 3 Tie 0 4 Tie 1 0 Tie 1 1 Tie 1 2 Tie 1 3 Tie 1 4 Tie 2 0 Tie 2 1 Tie 2 2 Tie 2 3 Tie 2 4 Tie 3 0 Tie 3 1 Tie 3 2 Tie 3 3 Tie 3 4 Tie 4 0 Tie 4 1 Tie 4 2 Tie 4 3 Tie 4 4 Tie From no at none.invalid Sun Jul 22 23:23:47 2018 From: no at none.invalid (no at none.invalid) Date: Sun, 22 Jul 2018 23:23:47 -0400 Subject: For next loops References: Message-ID: <1hiald9aopfe39ecl8o3bhm8995vgj9fd0@4ax.com> never mind. x = range (5) y = range (5) for ply in x: for com in y: if ply==com: result="Tie" print(ply,com,result) result = "" On Sun, 22 Jul 2018 23:17:24 -0400, no at none.invalid wrote: >x = range (5) >y = range (5) >for ply in x: > for com in y: > if ply==com: > result="Tie" > print(ply,com,result) > >Why is ply always equal to com? >0 0 Tie >0 1 Tie >0 2 Tie >0 3 Tie >0 4 Tie >1 0 Tie >1 1 Tie >1 2 Tie >1 3 Tie >1 4 Tie >2 0 Tie >2 1 Tie >2 2 Tie >2 3 Tie >2 4 Tie >3 0 Tie >3 1 Tie >3 2 Tie >3 3 Tie >3 4 Tie >4 0 Tie >4 1 Tie >4 2 Tie >4 3 Tie >4 4 Tie From arj.python at gmail.com Sun Jul 22 23:38:21 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Mon, 23 Jul 2018 07:38:21 +0400 Subject: ongoing browser projects In-Reply-To: References: Message-ID: *Have you looked on PyPI?* that's the problem. due to the lack of py support html renderer just gives text-based html renderings there are also qt5 based ones but qt more of an off py project ported to py. if really needed, that i think it's the option i've also viewed C-based ones with python bindings but i wanted py-based ones. too much ado about something simple thanks all for feedback ! Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius From arj.python at gmail.com Mon Jul 23 02:02:26 2018 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Mon, 23 Jul 2018 10:02:26 +0400 Subject: coding style - where to declare variables In-Reply-To: References: Message-ID: variables here refers to the user experience of a var np, just a link to the thread/s would mark the end of it Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius From marko at pacujo.net Mon Jul 23 02:22:55 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 23 Jul 2018 09:22:55 +0300 Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> <86582198-8544-43C0-BC4B-7AE763F9954E@Damon-family.org> <87effvrnbj.fsf@elektro.pacujo.net> <4nu9ldtsfhm2dbbrn75t7n9b2c6nlh80rv@4ax.com> Message-ID: <87sh4aqxmo.fsf@elektro.pacujo.net> Dennis Lee Bieber : > On Mon, 23 Jul 2018 00:08:00 +0300, Marko Rauhamaa > declaimed the following: > >>I Java terms, all Python values are boxed. That's a very usual pattern >>in virtually all programming languages (apart from FORTRAN). > > FORTRAN, C, COBOL, BASIC, Pascal, ALGOL, BCPL, REXX, VMS DCL, probably > R, Matlab, APL. > > I never encountered the term "boxed" until trying to read some of the > O'Reilly books on Java. > > In my world, Java and Python are the ones that are not "common". Yes, "boxed" is a Java term. However, the programming pattern of using dynamic memory and pointers is ubiquitous and ancient: FILE *f = fopen("xyz", "r"); where f holds a pointer, fopen() returns a pointer, and "xyz" and "r" evaluate to pointer values. In Python, every expression evaluates to a pointer and every variable holds a pointer. Marko From ben+python at benfinney.id.au Mon Jul 23 02:50:00 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 23 Jul 2018 16:50:00 +1000 Subject: For next loops References: <1hiald9aopfe39ecl8o3bhm8995vgj9fd0@4ax.com> Message-ID: <85in5678fb.fsf@benfinney.id.au> no at none.invalid writes: > never mind. Congratulations for working out the error. And thank you for returning to show the corrected code :-) -- \ ?If you don't know what your program is supposed to do, you'd | `\ better not start writing it.? ?Edsger W. Dijkstra | _o__) | Ben Finney From ladydaae47 at gmail.com Mon Jul 23 03:00:24 2018 From: ladydaae47 at gmail.com (Lyra) Date: Mon, 23 Jul 2018 00:00:24 -0700 Subject: Python shuts down when I try to run a module Message-ID: <5b557d0a.1c69fb81.c142f.5227@mx.google.com> Hello, I?ve just started to learn Python coding, and downloaded version 3.7.0 from the website.? I?ve written 5 or 6 small programs and saved them, but whenever I try to run them, Python doesn?t work right.? The user answers the first question and presses ENTER, but then the Python window just closes, disappears, and shuts down.? My programs are all written correctly, and work just like they?re supposed to, when I run them in the Shell window instead.? There are no error messages. I went into the original installation file of Python and clicked on ?Repair?.? There was a progress bar, and it said ?Repair completed?, but the problem still occurs. I don?t want to uninstall the whole thing and download a different version until after I hear from someone here who knows more about it than I do. Please respond soon. Thanks. Sent from Mail for Windows 10 From tjol at tjol.eu Mon Jul 23 03:00:54 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 23 Jul 2018 09:00:54 +0200 Subject: ongoing browser projects In-Reply-To: <20180723014354.GE1166@shallowsky.com> References: <20180723014354.GE1166@shallowsky.com> Message-ID: <9590cdc2-ebe3-4724-eea6-be45959ff1d3@tjol.eu> On 23/07/18 03:43, Akkana Peck wrote: > There used to be a Python-WebKit-GTK2 library that was fairly easy > to use and even had documentation, but it's been orphaned for years, > and in any case a lot of the modern web no longer works with the old > WebKit engine. You'd think there would be something newer (ideally > based on Blink) that worked with GTK3/GIO, but I never found anything. This gi-based example looks like Gtk3, right? From tjol at tjol.eu Mon Jul 23 03:12:47 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 23 Jul 2018 09:12:47 +0200 Subject: ongoing browser projects In-Reply-To: <9590cdc2-ebe3-4724-eea6-be45959ff1d3@tjol.eu> References: <20180723014354.GE1166@shallowsky.com> <9590cdc2-ebe3-4724-eea6-be45959ff1d3@tjol.eu> Message-ID: On 23/07/18 09:00, Thomas Jollans wrote: > On 23/07/18 03:43, Akkana Peck wrote: >> There used to be a Python-WebKit-GTK2 library that was fairly easy >> to use and even had documentation, but it's been orphaned for years, >> and in any case a lot of the modern web no longer works with the old >> WebKit engine. You'd think there would be something newer (ideally >> based on Blink) that worked with GTK3/GIO, but I never found anything. > > This gi-based example looks like Gtk3, right? > https://gist.github.com/kklimonda/890640#file-pybrowser-py-L14 sorry forgot to hit ctrl+v From cs at cskk.id.au Mon Jul 23 03:52:10 2018 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 23 Jul 2018 17:52:10 +1000 Subject: import in code In-Reply-To: References: Message-ID: <20180723075210.GA46351@cskk.homeip.net> On 22Jul2018 15:38, Mark Lawrence wrote: >On 22/07/18 05:45, Cameron Simpson wrote: >>Circular imports: 2 codependent modules. If you have: >> >> ?module A: >> ?? import B >> ?module B: >> ?? import B >> >>That won't work: the second import (whichever it turns out to be) >>will fail. One workaround is to make one of the modules put off the >>import. A better approach is usually to redesign things so that they >>don't do a mutual import (move classses etc around, or merge them). >>This is always feasible, but often is. > >I don't ever recall seeing a module try to import itself, but then >perhaps you meant module B should be importing module A? :) Yes, sorry. Poor proof reading. - Cameron From brian.j.oney at googlemail.com Mon Jul 23 03:52:34 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Mon, 23 Jul 2018 09:52:34 +0200 Subject: For next loops In-Reply-To: <1hiald9aopfe39ecl8o3bhm8995vgj9fd0@4ax.com> References: <1hiald9aopfe39ecl8o3bhm8995vgj9fd0@4ax.com> Message-ID: <1532332354.2255.2.camel@gmail.com> What if ply != com in the first (0th) iteration?? It's better to have an 'else:'-statement in your case, I suppose. From greg.ewing at canterbury.ac.nz Mon Jul 23 04:24:30 2018 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 23 Jul 2018 20:24:30 +1200 Subject: coding style - where to declare variables In-Reply-To: References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> Message-ID: Steven D'Aprano wrote: > So let me see if I understand your argument... > > - we should stop using the term "binding", because it means > nothing different from assignment; > - binding (a.k.a. "assignment") comes from lambda calculus; > - which has no assignment (a.k.a. "binding"). No, that's not what Marko is saying at all. He's pointing out that the term "binding" means something completely different in lambda calculus. The terms "bound variable" and "free variable" in lambda calculus mean what in Python we would call a "local variable" vs. a "non-local variable". They have nothing to do with assignment at all. Marko is asking us to stop using the word "binding" to refer to assignment because of the potential confusion with this other meaning. -- Greg From ben+python at benfinney.id.au Mon Jul 23 04:36:16 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 23 Jul 2018 18:36:16 +1000 Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> Message-ID: <85effu73i7.fsf@benfinney.id.au> Gregory Ewing writes: > Marko is asking us to stop using the word "binding" to refer to > assignment because of the potential confusion with this other meaning. That's about as reasonable as my request that we stop using the term ?variable? for what is, in Python, an un-typed reference to an object. I expect both of these requests to meet with little satisfaction. -- \ ?We are all agreed that your theory is crazy. The question that | `\ divides us is whether it is crazy enough to have a chance of | _o__) being correct.? ?Niels Bohr (to Wolfgang Pauli), 1958 | Ben Finney From marko at pacujo.net Mon Jul 23 04:49:37 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 23 Jul 2018 11:49:37 +0300 Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> <85effu73i7.fsf@benfinney.id.au> Message-ID: <87zhyitjz2.fsf@elektro.pacujo.net> Ben Finney : > Gregory Ewing writes: > >> Marko is asking us to stop using the word "binding" to refer to >> assignment because of the potential confusion with this other meaning. > > That's about as reasonable as my request that we stop using the term > ?variable? for what is, in Python, an un-typed reference to an object. > > I expect both of these requests to meet with little satisfaction. I'm actually not asking, only wishing. People new to Python are unnecessarily confused by talking about names and binding when it's really just ordinary variables and assignment. It seems to be mostly some sort of marketing lingo that seeks to create an air of mystique around Python. Marko From frank at chagford.com Mon Jul 23 05:16:08 2018 From: frank at chagford.com (Frank Millman) Date: Mon, 23 Jul 2018 11:16:08 +0200 Subject: coding style - where to declare variables In-Reply-To: <87zhyitjz2.fsf@elektro.pacujo.net> References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> <85effu73i7.fsf@benfinney.id.au> <87zhyitjz2.fsf@elektro.pacujo.net> Message-ID: "Marko Rauhamaa" wrote in message news:87zhyitjz2.fsf at elektro.pacujo.net... > > People new to Python are unnecessarily confused by talking about names > and binding when it's really just ordinary variables and assignment. It > seems to be mostly some sort of marketing lingo that seeks to create an > air of mystique around Python. > I don't think that is a fair comment. I am not qualified to enter the debate itself, but as an 'outsider' I can offer two thoughts - 1. It seems that, whatever terminology we come up with, some other language will use similar terminology, but with a subtly different meaning. Newcomers to Python coming from that other language often get confused because they make certain assumptions, based on their other experience, which turn out to be unfounded in Python. 2. My 'aha' moment came early on when I read somewhere that Python objects have 3 attributes - a type, a value, and a unique id. One thing that they do *not* have is a name. Once I understood that, a lot of things became clearer. Frank Millman From steve+comp.lang.python at pearwood.info Mon Jul 23 06:42:12 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 23 Jul 2018 10:42:12 +0000 (UTC) Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> Message-ID: On Mon, 23 Jul 2018 20:24:30 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> So let me see if I understand your argument... >> >> - we should stop using the term "binding", because it means >> nothing different from assignment; >> - binding (a.k.a. "assignment") comes from lambda calculus; >> - which has no assignment (a.k.a. "binding"). > > No, that's not what Marko is saying at all. He's pointing out that the > term "binding" means something completely different in lambda calculus. Well done in reading Marko's intent. Unfortunately, I'm not as good as inferring meaning as you seem to be, consequently I had to judge by what he wrote, not what he meant. When a writer fails to communicate their intent, that's usually the failure of the writer, not the reader. We aren't mind-readers and writers should not blame the reader when they fail to communicate their intended meaning. > The terms "bound variable" and "free variable" in lambda calculus mean > what in Python we would call a "local variable" vs. a "non-local > variable". Actually, no, they are called "bound variable" and "free variable" in Python too. https://docs.python.org/3/reference/executionmodel.html See also: http://effbot.org/zone/closure.htm Alas, I don't think Fredrik Lundh got it *quite* right. I think that globals (and builtins) in Python are "open free variables", as opposed to nonlocals which are closed. And sadly, the Python glossary currently doesn't define free variables nor bound variables, or even name binding. > They have nothing to do with assignment at all. That's not quite correct either. Lambda calculus has the concept of a binding operator, which is effectively an assignment operator: it takes a variable and a value and binds the value to the variable, changing a free variable to a bound variable. In other words, it assigns the value to the variable, just like assignment does. In Python terms, = is a binary binding operator: it takes a left hand operand, the variable (a name, for the sake of simplicity) and a right hand operand (a value) and binds the value to the name. > Marko is asking us to stop using the word "binding" to refer to > assignment because of the potential confusion with this other meaning. Marko has some idiosyncratic beliefs about Python (and apparently other languages as well) that are difficult to justify. Especially in this case. Anyone who understands lambda calculus is unlikely to be confused by Python using the same terms to mean something *almost identical* to what they mean in lambda calculus. (The only difference I can see is that lambda calculus treats variables as abstract mathematical entities, while Python and other programming languages vivify them and give them a concrete implementation.) If one in ten thousand programmers are even aware of the existence of lambda calculus, I would be surprised. To give up using perfectly good, accurate terminology in favour of worse, less accurate terminology in order to avoid unlikely and transient confusion among a minuscule subset of programmers seems a poor tradeoff to me. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From ben.lists at bsb.me.uk Mon Jul 23 07:19:54 2018 From: ben.lists at bsb.me.uk (Ben Bacarisse) Date: Mon, 23 Jul 2018 12:19:54 +0100 Subject: coding style - where to declare variables References: Message-ID: <87sh4a6vxh.fsf@bsb.me.uk> Mark Lawrence writes: > On 22/07/18 14:51, Abdur-Rahmaan Janhangeer wrote: >> except local vars >> >> Abdur-Rahmaan Janhangeer >> https://github.com/Abdur-rahmaanJ >> Mauritius >> > > Python doesn't have variables, it has names. I think we should cut beginners (and probably everyone) some slack about this. I don't know if work is underway to purge the term from the Python documentation, but until that is done people can be forgiven for thinking that the term is acceptable. For example, https://docs.python.org/3/tutorial/classes.html says "The global statement can be used to indicate that particular variables live in the global scope and should be rebound there; the nonlocal statement indicates that particular variables live in an enclosing scope and should be rebound there." and https://www.python.org/dev/peps/pep-0526/ is titled "Syntax for Variable Annotations". It describes: "This PEP aims at adding syntax to Python for annotating the types of variables (including class variables and instance variables), instead of expressing them through comments" -- Ben. From steve+comp.lang.python at pearwood.info Mon Jul 23 07:26:50 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 23 Jul 2018 11:26:50 +0000 (UTC) Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> <85effu73i7.fsf@benfinney.id.au> <87zhyitjz2.fsf@elektro.pacujo.net> Message-ID: On Mon, 23 Jul 2018 11:49:37 +0300, Marko Rauhamaa wrote: > People new to Python are unnecessarily confused by talking about names > and binding when it's really just ordinary variables and assignment. It really isn't, not to those people who expect ordinary variables and assignment to be the same as that of C, C++, C#, Objective C, Swift, Pascal, Java, Go etc. There are at least two common models for the association between symbolic names and values in programming: 1. variables are named boxes at a statically-allocated, fixed location in memory, usually on the stack ("value types"); 2. variables are names that refer to dynamically-allocated objects in the heap, often movable ("reference types"). It is absolutely true that both are "variables" of a kind, and that "name binding" is abstract enough to refer to both models. But in *practice*, the influence of Algol, C and BASIC especially is so great that many people think of variables and assignment exclusively in the first sense. Since Python uses the second sense, having a distinct name to contrast the two is desirable, and "name binding" seems to fit that need. I no longer believe that we should actively avoid the word "variable" when referring to Python. I think that's an extreme position which isn't justified. But "name binding" is an accurate technical term and not that hard to understand (on a scale of 0 to "monad", it's about 1) and I think it is elitist to claim that "people new to Python"[1] will necessarily be confused and we therefore ought to avoid the term. There are lots of confusing terms and concepts in Python. People learn them. Name binding is no different. [1] What, all of them? Even those with a comp sci PhD and 40 years programming experience in two dozen different languages? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From steve+comp.lang.python at pearwood.info Mon Jul 23 07:39:36 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 23 Jul 2018 11:39:36 +0000 (UTC) Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> <86582198-8544-43C0-BC4B-7AE763F9954E@Damon-family.org> <87effvrnbj.fsf@elektro.pacujo.net> <4nu9ldtsfhm2dbbrn75t7n9b2c6nlh80rv@4ax.com> <87sh4aqxmo.fsf@elektro.pacujo.net> Message-ID: On Mon, 23 Jul 2018 09:22:55 +0300, Marko Rauhamaa wrote: > Dennis Lee Bieber : [...] >> In my world, Java and Python are the ones that are not "common". > > Yes, "boxed" is a Java term. However, the programming pattern of using > dynamic memory and pointers is ubiquitous and ancient: Not that ancient -- the first version(s) of Fortran didn't have dynamic memory allocation or pointers. (Admittedly, Lisp did follow not long afterwards.) But it is certainly not ubiquitous: many languages don't have pointers at all. > FILE *f = fopen("xyz", "r"); > > where f holds a pointer, fopen() returns a pointer, and "xyz" and "r" > evaluate to pointer values. > > In Python, every expression evaluates to a pointer and every variable > holds a pointer. Within the semantics of the Python language, there are no pointer values, no way to get a pointer to a memory location or a pointer to an object. No expression in Python evaluates to a pointer, no variables hold pointers in Python. The Python language is defined in terms of objects: expressions evaluate to objects, and variables are names bound to objects. If you don't believe me, believe the interpreter: # Marko expects a pointer, but unfortunately he gets an int py> type(1 + 2) Marko is making a similar category error as those who insist that Python uses "call by reference" or "call by value" for parameter passing. He mistakes an irrelevant implementation detail used by *some* but not all Python interpreters[1] for entities which exist in the Python computation model. As Fredrick puts it: "Joe, I think our son might be lost in the woods" "Don't worry, I have his social security number" http://effbot.org/zone/call-by-object.htm (The *pointer to an object* used in the implementation is not the same as the object itself.) Evaluating 1 + 2 gives the value (an object) 3, not a pointer to the value 3. Pointers are not merely "not first-class citizens" of Python, they aren't citizens at all: there is nothing we can do in pure Python to get hold of pointers, manipulate pointers, or dereference pointers. https://en.wikipedia.org/wiki/First-class_citizen Pointers are merely one convenient, useful mechanism to implement Python's model of computation in an efficient manner on a digital computer. They are not part of the computation model, and pointers are not values available to the Python programmer[2]. [1] The CPython interpreter uses pointers; the Jython interpreter uses whatever kind of memory indirection the JVM provides; when I emulate a Python interpreter using pencil and paper, there's not a pointer in sight but a lot of copying of values and crossing them out. ("Copy on access" perhaps?) A Python interpreter emulated by a Turing machine would use dots on a long paper tape, and an analog computer emulating Python would use I-have-no-idea. Clockwork? Hydraulics? https://en.wikipedia.org/wiki/MONIAC https://makezine.com/2012/01/24/early-russian-hydraulic-computer/ [2] Except by dropping into ctypes or some other interface to the implementation, and even then the pointers have to be converted to and from int objects as they cross the boundary between the Python realm and the implementation realm. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From marko at pacujo.net Mon Jul 23 07:39:56 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 23 Jul 2018 14:39:56 +0300 Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> Message-ID: <87pnzetc37.fsf@elektro.pacujo.net> Steven D'Aprano : > Lambda calculus has the concept of a binding operator, which is > effectively an assignment operator: it takes a variable and a value > and binds the value to the variable, changing a free variable to a > bound variable. In other words, it assigns the value to the variable, > just like assignment does. In traditional Lambda Calculus semantics, there are no values at all. There are only well-formatted formulas and syntactic transformation rules. You could view it as a macro preprocessing system where you keep transforming the formula until no transformation rule applies. Yes, ? can be viewed as a binding operator although classically, it is simply a dead symbol just like '(', '.' and 'z'. > Especially in this case. Anyone who understands lambda calculus is > unlikely to be confused by Python using the same terms to mean > something *almost identical* to what they mean in lambda calculus. > (The only difference I can see is that lambda calculus treats > variables as abstract mathematical entities, while Python and other > programming languages vivify them and give them a concrete > implementation.) > > If one in ten thousand programmers are even aware of the existence of > lambda calculus, I would be surprised. To give up using perfectly > good, accurate terminology in favour of worse, less accurate > terminology in order to avoid unlikely and transient confusion among a > minuscule subset of programmers seems a poor tradeoff to me. The lambda calculus comment is just an aside. The main point is that you shouldn't lead people to believe that Python has variables that are any different than, say, Pascal's variables (even if you, for whatever reason, want to call them "names"). They are memory slots that hold values until you assign new values to them. It *is* true that Python has a more limited data model than Pascal (all of Python's values are objects in the heap and only accessible through pointers). Also, unlike Pascal, variables can hold (pointers to) values of any type. IOW, Python has the data model of Lisp. Lisp talks about binding and rebinding variables as well: which might be Lambda Calculus legacy, but at least they are not shy to talk about variables and assignment. Marko From rosuav at gmail.com Mon Jul 23 08:02:48 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 23 Jul 2018 22:02:48 +1000 Subject: coding style - where to declare variables In-Reply-To: References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> <86582198-8544-43C0-BC4B-7AE763F9954E@Damon-family.org> <87effvrnbj.fsf@elektro.pacujo.net> <4nu9ldtsfhm2dbbrn75t7n9b2c6nlh80rv@4ax.com> <87sh4aqxmo.fsf@elektro.pacujo.net> Message-ID: On Mon, Jul 23, 2018 at 9:39 PM, Steven D'Aprano wrote: > [1] The CPython interpreter uses pointers; the Jython interpreter uses > whatever kind of memory indirection the JVM provides; when I emulate a > Python interpreter using pencil and paper, there's not a pointer in sight > but a lot of copying of values and crossing them out. ("Copy on access" > perhaps?) A Python interpreter emulated by a Turing machine would use > dots on a long paper tape, and an analog computer emulating Python would > use I-have-no-idea. Clockwork? Hydraulics? I've been known to implement a linked list using a deck of cards, with tetrapod "one teaspoon of sugar" packets for the Next markers, and pens for externally-accessible references (the head of the list, the current node, etc). This therefore proves that a pointer IS a teaspoon of sugar, and vice versa. Would you like your tea with one pointer or two? ChrisA From neilc at norwich.edu Mon Jul 23 09:30:26 2018 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 23 Jul 2018 13:30:26 +0000 (UTC) Subject: For next loops References: <1hiald9aopfe39ecl8o3bhm8995vgj9fd0@4ax.com> Message-ID: On 2018-07-23, no at none.invalid wrote: > never mind. > x = range (5) > y = range (5) > for ply in x: > > for com in y: > if ply==com: > result="Tie" > > print(ply,com,result) > result = "" Something like this is possible. "x", "y" and "result" can be unecessary. for ply in range(5): for com in range(5): print(ply, com, end='') if ply == com: print(" Tie") else: print() -- Neil Cerutti From steve+comp.lang.python at pearwood.info Mon Jul 23 09:41:15 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 23 Jul 2018 13:41:15 +0000 (UTC) Subject: coding style - where to declare variables References: <%a15D.1738293$LD3.1136776@fx18.am4> <87r2jvrqw3.fsf@elektro.pacujo.net> <87pnzetc37.fsf@elektro.pacujo.net> Message-ID: On Mon, 23 Jul 2018 14:39:56 +0300, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Lambda calculus has the concept of a binding operator, which is >> effectively an assignment operator: it takes a variable and a value and >> binds the value to the variable, changing a free variable to a bound >> variable. In other words, it assigns the value to the variable, just >> like assignment does. > > In traditional Lambda Calculus semantics, there are no values at all. It is more common to say "pure lambda calculus" rather than "traditional", and it is not correct to say there are no values at all. Rather, all values are functions (and all functions are values). http://scienceblogs.com/goodmath/2006/08/29/a-lambda-calculus-rerun-1/ and: "As this suggests, functions are just ordinary values, and can be the results of functions or passed as arguments to functions (even to themselves!). Thus, in the lambda calculus, functions are first-class values. Lambda terms serve both as functions and data." http://www.cs.cornell.edu/courses/cs6110/2013sp/lectures/lec02-sp13.pdf And from the same notes: "So, what is a value? In the pure lambda calculus, any abstraction is a value. Remember, an abstraction ?x:e is a function; in the pure lambda calculus, the only values are functions. In an applied lambda calculus with integers and arithmetic operations, values also include integers. Intuitively, a value is an expression that can not be reduced/executed/simplified any further." [...] > The lambda calculus comment is just an aside. The main point is that you > shouldn't lead people to believe that Python has variables that are any > different than, say, Pascal's variables (even if you, for whatever > reason, want to call them "names"). They are memory slots that hold > values until you assign new values to them. Nevertheless, they are still different. My computer has an ethernet slot and a USB slot, and while they are both slots that hold a cable and transmit information in and out of the computer, they are nevertheless different. The differences are just as important as the similarities. > It *is* true that Python has a more limited data model than Pascal (all > of Python's values are objects in the heap and only accessible through > pointers). Calling it "more limited" is an inaccurate and pejorative way of putting it. Rather, I would say it is a more minimalist, *elegant* data model: * a single kind of variable (objects in the heap where the interpreter manages the lifetime of objects for you) as opposed to Pascal's more complex and more difficult model: * two kinds of variables: - first-class variables that the compiler manages for you (allocating and deallocating them on the stack) - second-class variables that the programmer has to manage manually (declaring pointers, allocating memory by hand, tracking the lifetime of the memory block yourself, deallocating it when you are done, and carefully avoiding accessing the pointed-to memory block after deallocation). At least more modern languages with both value-types and reference-types (such as Java, C#, Objective C, Swift) manage to elevate their reference- type variables to first-class citizenship. > Also, unlike Pascal, variables can hold (pointers to) values > of any type. IOW, Python has the data model of Lisp. > > Lisp talks about binding and rebinding variables as well: > > > > which might be Lambda Calculus legacy, but at least they are not shy to > talk about variables and assignment. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From wegge at wegge.dk Mon Jul 23 10:44:44 2018 From: wegge at wegge.dk (Anders Wegge Keller) Date: Mon, 23 Jul 2018 16:44:44 +0200 Subject: Non-GUI, single processort inter process massaging - how? In-Reply-To: References: Message-ID: <20180723164444.04abe347@wegge.dk> P? Sat, 21 Jul 2018 09:07:23 +0100 Chris Green skrev: > So - what's the best approach to this? I've done some searching and > most/many of the solutions seem rather heavyweight for my needs. Am I > overlooking something obvious or should I try rethinking the original > requirement and look for another approach? What do you consider heavyweight? Number of dependencies, memory footprint, amount of code or a fourth thing? Also, which platform will the code eventually run on? If your update frequency is low enough that it wont kill the filesystem and the amount of data is reasonably small, atomic writes to a file is easy to work with: def atomic_write(filename, data): handle, name = tempfile.mkstemp() os.write(handle, data) os.fsync(handle) os.close(handle) os.replace(tmpname, filename) The imports are trivial to deduce, so I removed the clutter. If you have multiple filesystems, you may have to read into the details of calling mkstemp. If you have an update frequency that will kill the filesystem (for instance a RPi on a SD card), or have a larger data set where you only want to do partial updates, the mmap module could be an option. It require some more boilerplate. You will probably also have to consider a semaphore to guarantee that the clients read a consistent result set. -- //Wegge From cspealma at redhat.com Mon Jul 23 11:05:38 2018 From: cspealma at redhat.com (Calvin Spealman) Date: Mon, 23 Jul 2018 11:05:38 -0400 Subject: Python shuts down when I try to run a module In-Reply-To: <5b557d0a.1c69fb81.c142f.5227@mx.google.com> References: <5b557d0a.1c69fb81.c142f.5227@mx.google.com> Message-ID: This is an unfortunate property of running command line programs on Windows. If you run the script directly (like by double clicking on it?) the console window will close when the program is done, so you can't see the final output. To get around this you could run them in the IDLE editor, which comes with Python 3.7 for Windows, or you could open a windows command prompt and run your Python scripts from there. On Mon, Jul 23, 2018 at 3:00 AM, Lyra wrote: > Hello, > I?ve just started to learn Python coding, and downloaded version 3.7.0 > from the website. I?ve written 5 or 6 small programs and saved them, but > whenever I try to run them, Python doesn?t work right. The user answers > the first question and presses ENTER, but then the Python window just > closes, disappears, and shuts down. My programs are all written correctly, > and work just like they?re supposed to, when I run them in the Shell window > instead. There are no error messages. > I went into the original installation file of Python and clicked on > ?Repair?. There was a progress bar, and it said ?Repair completed?, but > the problem still occurs. > I don?t want to uninstall the whole thing and download a different version > until after I hear from someone here who knows more about it than I do. > > Please respond soon. > > Thanks. > > > Sent from Mail for Windows 10 > > -- > https://mail.python.org/mailman/listinfo/python-list > From sharan.basappa at gmail.com Mon Jul 23 11:40:06 2018 From: sharan.basappa at gmail.com (Sharan Basappa) Date: Mon, 23 Jul 2018 08:40:06 -0700 (PDT) Subject: list of lists In-Reply-To: References: <8e261f75-03f7-4f80-a516-8318dd138657@googlegroups.com> Message-ID: On Sunday, 22 July 2018 21:07:17 UTC+5:30, Thomas Jollans wrote: > On 22/07/18 14:53, Sharan Basappa wrote: > > Thanks. I initially thought about this but did not know if this is legal syntax. > > In this kind of situation ? you think you know how to do something but > you're not quite sure if it'll work as intended ? just try it! Start up > an interactive interpreter, or write a test script (as you appear to > have done). If it doesn't work, that's fine. No harm done. > > Also, please use Python 3. Agree. That is one advantage of interpreted language. For quick trial and error, not much overhead and we can print lot of variables once script is run. From rshepard at appl-ecosys.com Mon Jul 23 12:28:32 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 23 Jul 2018 09:28:32 -0700 (PDT) Subject: Python in the news Message-ID: The lead article in science section and technology section of this week's 'The Economist' is about Python: Enjoy, Rich From michael.vilain at gmail.com Mon Jul 23 13:09:57 2018 From: michael.vilain at gmail.com (Michael Vilain) Date: Mon, 23 Jul 2018 10:09:57 -0700 Subject: PyCharm In-Reply-To: <9mc5ldtuneuc6m7jvh34t3llhqg2p1pc6h@4ax.com> References: <9mc5ldtuneuc6m7jvh34t3llhqg2p1pc6h@4ax.com> Message-ID: I used the pycharm edu version from here: https://www.jetbrains.com/pycharm-edu/download/download-thanks.html?platform=mac input works fine on it. YMMV. > On 20-Jul-2018, at 9:15 PM ?, no at none.invalid wrote: > > On Fri, 20 Jul 2018 20:56:41 -0700, Michael Vilain > wrote: > >> I'm running PyCharm Edu (to go through their great tutorial). It's version is 2018.1.3, which I got from the web site. Unless you mistyped the version, this is the current release and yours is very old. > > The date was just from a message posted back in Jan. > > My version says: > PyCharm 2018.1.4 (Community Edition) > Build #PC-181.5087.37, built on May 24, 2018 > JRE: 1.8.0_152-release-1136-b39 amd64 > JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o > Windows 7 6.1 > > When I try to use an input statment, the program freezes. I have to > terminate it. > > What happens when you try to run code with an input statment? > > -- > https://mail.python.org/mailman/listinfo/python-list From neilc at norwich.edu Mon Jul 23 13:34:45 2018 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 23 Jul 2018 17:34:45 +0000 (UTC) Subject: Python shuts down when I try to run a module References: <5b557d0a.1c69fb81.c142f.5227@mx.google.com> Message-ID: On 2018-07-23, Calvin Spealman wrote: > This is an unfortunate property of running command line > programs on Windows. If you run the script directly (like by > double clicking on it?) the console window will close when the > program is done, so you can't see the final output. > > To get around this you could run them in the IDLE editor, which > comes with Python 3.7 for Windows, or you could open a windows > command prompt and run your Python scripts from there. You can also put input("Press [Enter] to exit.") at the end of your program, though unfortunately it doesn't help when an error occurs, requiring you to put it in a finally block to ensure it happens. -- Neil Cerutti From larry.martell at gmail.com Mon Jul 23 13:38:41 2018 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 23 Jul 2018 13:38:41 -0400 Subject: Want to be a rockstar programmer? Message-ID: https://github.com/dylanbeattie/rockstar From brgl at bgdev.pl Mon Jul 23 14:02:13 2018 From: brgl at bgdev.pl (Bartosz Golaszewski) Date: Mon, 23 Jul 2018 20:02:13 +0200 Subject: Tracking a memory leak in C extension - interpreting the output of PYTHONMALLOCSTATS Message-ID: Hi! A user recently reported a memory leak in python bindings (C extension module) to a C library[1] I wrote. I've been trying to fix it since but so far without success. Since I'm probably dealing with a space leak rather than actual memory leak, valgrind didn't help much even when using malloc as allocator. I'm now trying to use PYTHONMALLOCSTATS but need some help on how to interpret the output emitted it's enabled. I'm setting PYTHONMALLOCSTATS=1 & PYTHONMALLOC=pymalloc_debug and then running the script that triggers the leak. The last debug message is as follows: class size num pools blocks in use avail blocks ----- ---- --------- ------------- ------------ 3 32 1 2 124 4 40 2 9 193 5 48 1 3 81 6 56 1 4 68 7 64 11 295 398 8 72 9 260 244 9 80 36 831 969 10 88 79 1542 2092 11 96 131 3262 2240 12 104 70 1903 757 13 112 19 289 395 14 120 11 139 224 15 128 7 88 129 16 136 6 70 104 17 144 5 44 96 18 152 4 47 57 19 160 24 342 258 20 168 4 17 79 21 176 24 360 192 22 184 2 8 36 23 192 2 11 31 24 200 22 227 213 25 208 3 13 44 26 216 3 7 47 27 224 2 13 23 28 232 2 6 28 29 240 3 8 40 30 248 2 10 22 31 256 3 10 35 32 264 2 9 21 33 272 3 11 31 34 280 2 10 18 35 288 1 3 11 36 296 2 9 17 37 304 2 9 17 38 312 2 5 19 39 320 2 5 19 40 328 14 105 63 41 336 2 3 21 42 344 1 3 8 43 352 1 3 8 44 360 2 3 19 45 368 1 3 8 46 376 1 1 9 47 384 2 4 16 48 392 2 6 14 49 400 2 3 17 50 408 1 1 8 51 416 1 3 6 52 424 2 4 14 53 432 50967 458680 23 54 440 3 9 18 55 448 4 15 21 56 456 4 12 20 57 464 3 8 16 58 472 2 5 11 59 480 1 4 4 60 488 1 3 5 61 496 4 11 21 62 504 4 13 19 63 512 2 7 7 # times object malloc called = 2,811,245 # arenas allocated total = 810 # arenas reclaimed = 0 # arenas highwater mark = 810 # arenas allocated current = 810 810 arenas * 262144 bytes/arena = 212,336,640 # bytes in allocated blocks = 199,277,432 # bytes in available blocks = 1,138,472 308 unused pools * 4096 bytes = 1,261,568 # bytes lost to pool headers = 2,473,536 # bytes lost to quantization = 8,185,632 # bytes lost to arena alignment = 0 Total = 212,336,640 The number of pools in arena 53 continuously grows. Its size column says: 432. I couldn't find any documentation on what it means but I assume it's an allocation of 432 bytes. I launched gdb and set the following breakpoint: 'b PyMem_Malloc if size == 432' but the breakpoint was never triggered. I tried the same for PyObject_Malloc and still nothing. How do I use the info produced by PYTHONMALLOCSTATS do get to the culprit of the leak? Is there anything wrong in my reasoning here? Best regards, Bartosz Golaszewski [1] https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/ From tjol at tjol.eu Mon Jul 23 15:51:31 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 23 Jul 2018 21:51:31 +0200 Subject: Tracking a memory leak in C extension - interpreting the output of PYTHONMALLOCSTATS In-Reply-To: References: Message-ID: On 23/07/18 20:02, Bartosz Golaszewski wrote: > Hi! Hey! > A user recently reported a memory leak in python bindings (C extension > module) to a C library[1] I wrote. I've been trying to fix it since > but so far without success. Since I'm probably dealing with a space > leak rather than actual memory leak, valgrind didn't help much even > when using malloc as allocator. I'm now trying to use > PYTHONMALLOCSTATS but need some help on how to interpret the output > emitted it's enabled. Oh dear. > > [snip] > > The number of pools in arena 53 continuously grows. Its size column > says: 432. I couldn't find any documentation on what it means but I > assume it's an allocation of 432 bytes. [...] I had a quick look at the code (because what else does one do for fun); I don't understand much, but what I can tell you is that (a) yes, that is an allocation size in bytes, and (b) as you can see, it uses intervals of 8. This means that pool 53 is used for allocations of 424 < nbytes <= 432 bytes. Maybe your breakpoint needs tweaking. (c) Try breaking on _PyObject_Malloc or pymalloc_alloc. I think they're called by both PyMem_Malloc and PyObject_Malloc. int _PyObject_DebugMallocStats(FILE *out) https://github.com/python/cpython/blob/b18f8bc1a77193c372d79afa79b284028a2842d7/Objects/obmalloc.c#L2435 static int pymalloc_alloc(void *ctx, void **ptr_p, size_t nbytes) https://github.com/python/cpython/blob/b18f8bc1a77193c372d79afa79b284028a2842d7/Objects/obmalloc.c#L1327 Have fun debugging! -- Thomas > > How do I use the info produced by PYTHONMALLOCSTATS do get to the > culprit of the leak? Is there anything wrong in my reasoning here? > > Best regards, > Bartosz Golaszewski > > [1] https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/ > From brian.j.oney at googlemail.com Mon Jul 23 16:15:56 2018 From: brian.j.oney at googlemail.com (Brian Oney) Date: Mon, 23 Jul 2018 22:15:56 +0200 Subject: Want to be a rockstar programmer? In-Reply-To: References: Message-ID: meh, I'm more into 90s and 00s metal rock and punk rock. Oh well, I knew it wasn't meant to be. ;) From cl at isbd.net Mon Jul 23 17:14:22 2018 From: cl at isbd.net (Chris Green) Date: Mon, 23 Jul 2018 22:14:22 +0100 Subject: Non-GUI, single processort inter process massaging - how? References: <20180723164444.04abe347@wegge.dk> Message-ID: Anders Wegge Keller wrote: > P? Sat, 21 Jul 2018 09:07:23 +0100 > Chris Green skrev: > > > So - what's the best approach to this? I've done some searching and > > most/many of the solutions seem rather heavyweight for my needs. Am I > > overlooking something obvious or should I try rethinking the original > > requirement and look for another approach? > > What do you consider heavyweight? Number of dependencies, memory footprint, > amount of code or a fourth thing? Also, which platform will the code > eventually run on? > > If your update frequency is low enough that it wont kill the filesystem and > the amount of data is reasonably small, atomic writes to a file is easy to > work with: > Yes, I think you're right, using a file would seem to be the best answer. Sample rate is only one a second or slower and there's not a huge amount of data involved. Thanks. -- Chris Green ? From johnpote at jptechnical.co.uk Mon Jul 23 18:24:18 2018 From: johnpote at jptechnical.co.uk (John Pote) Date: Mon, 23 Jul 2018 23:24:18 +0100 Subject: curses, ncurses or something else Message-ID: <4da0f266-4e77-2c1d-5e42-3910a4dfaed3@jptechnical.co.uk> I recently wrote a command line app to take a stream of numbers, do some signal processing on them and display the results on the console. There may be several output columns of data so a title line is printed first. But the stream of numbers may be several hundred long and the title line disappears of the top on the console. So I thought it might be quick and easy to do something with curses to keep the title line visable while the numbers roll up the screen. But alas I'm a Windows user and the 'curses' module is not in the Windows standard library for Python. It occured to me that I could create a simple tkinter class but I haven't tinkered for some time and would have to refresh my knowledge of the API. Just wondered if there was any other simple way I could keep the title line on the console, preferably without having to install another library. Ideas invited. From jorge.conrado at cptec.inpe.br Mon Jul 23 18:39:18 2018 From: jorge.conrado at cptec.inpe.br (jorge.conrado at cptec.inpe.br) Date: Mon, 23 Jul 2018 19:39:18 -0300 Subject: Python 2.7.14 and Python 3.6.0 netcdf4 Message-ID: Hi, Please someone can help me with this error message; for Python 2.7.14 I did: from netCDF4 import Dataset and I didn't have no message But, for Python 3.6.0 from netCDF4 import Dataset I had: Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'netCDF4' What can I do to solve this error for Python 3.6.0 Thanks, Conrado From akkana at shallowsky.com Mon Jul 23 18:41:22 2018 From: akkana at shallowsky.com (Akkana Peck) Date: Mon, 23 Jul 2018 16:41:22 -0600 Subject: ongoing browser projects In-Reply-To: References: <20180723014354.GE1166@shallowsky.com> <9590cdc2-ebe3-4724-eea6-be45959ff1d3@tjol.eu> Message-ID: <20180723224122.GB1213@shallowsky.com> > > On 23/07/18 03:43, Akkana Peck wrote: > >> You'd think there would be something newer (ideally > >> based on Blink) that worked with GTK3/GIO, but I never found anything. Thomas Jollans writes: > > This gi-based example looks like Gtk3, right? > > https://gist.github.com/kklimonda/890640#file-pybrowser-py-L14 Sure enough, that works, at least with the webkit in Debian's gir1.2-webkit-3.0 package. It didn't work with gir1.2-webkit2-4.0: File "", line 888, in _find_spec" AttributeError: 'DynamicImporter' object has no attribute 'find_spec' and then various further errors resulting from those; but at least it's possible to make a Python 3, GTK3, webkit 3.0 browser. And it even handles fullscreen events (like from youtube), something I've never managed in QtWebEngine. ...Akkana From torriem at gmail.com Mon Jul 23 18:45:21 2018 From: torriem at gmail.com (Michael Torrie) Date: Mon, 23 Jul 2018 16:45:21 -0600 Subject: Python shuts down when I try to run a module In-Reply-To: <5b557d0a.1c69fb81.c142f.5227@mx.google.com> References: <5b557d0a.1c69fb81.c142f.5227@mx.google.com> Message-ID: <0fb0a316-0ddf-746f-f165-96146b4632d6@gmail.com> On 07/23/2018 01:00 AM, Lyra wrote: > Hello, > I?ve just started to learn Python coding, and downloaded version 3.7.0 from the website.? I?ve written 5 or 6 small programs and saved them, but whenever I try to run them, Python doesn?t work right.? The user answers the first question and presses ENTER, but then the Python window just closes, disappears, and shuts down.? My programs are all written correctly, and work just like they?re supposed to, when I run them in the Shell window instead.? There are no error messages. > I went into the original installation file of Python and clicked on ?Repair?.? There was a progress bar, and it said ?Repair completed?, but the problem still occurs. > I don?t want to uninstall the whole thing and download a different version until after I hear from someone here who knows more about it than I do. This is expected behavior on Windows. Unless your program has a graphical user interface that you've created, the proper way to run an *interactive* python program is from the command prompt. Alternatively you can run it from within IDLE or some other Python IDE like PyCharm. So you're not doing anything wrong. Just don't run them by double clicking; run them from a command prompt instead. From rshepard at appl-ecosys.com Mon Jul 23 18:54:45 2018 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 23 Jul 2018 15:54:45 -0700 (PDT) Subject: curses, ncurses or something else In-Reply-To: <4da0f266-4e77-2c1d-5e42-3910a4dfaed3@jptechnical.co.uk> References: <4da0f266-4e77-2c1d-5e42-3910a4dfaed3@jptechnical.co.uk> Message-ID: On Mon, 23 Jul 2018, John Pote wrote: > So I thought it might be quick and easy to do something with curses to > keep the title line visable while the numbers roll up the screen. But alas > I'm a Windows user and the 'curses' module is not in the Windows standard > library for Python. John, I don't recall if urwid supports windows, but it has more display and UI capabilities than either curses or ncurses. Urwid is a console widget library for python. HTH, Rich From tjol at tjol.eu Mon Jul 23 18:58:38 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 24 Jul 2018 00:58:38 +0200 Subject: curses, ncurses or something else In-Reply-To: <4da0f266-4e77-2c1d-5e42-3910a4dfaed3@jptechnical.co.uk> References: <4da0f266-4e77-2c1d-5e42-3910a4dfaed3@jptechnical.co.uk> Message-ID: <45bd7ebe-1c2a-ce24-8e0f-6d3a877034f3@tjol.eu> On 24/07/18 00:24, John Pote wrote: > Ideas invited. This doesn't answer your question at all, but when I want a small script to produce largish streams of numbers, I write them to a (csv) file and plot them using matplotlib then and there. From dmarv at dop.com Mon Jul 23 18:59:07 2018 From: dmarv at dop.com (Dale Marvin) Date: Mon, 23 Jul 2018 15:59:07 -0700 Subject: curses, ncurses or something else In-Reply-To: <4da0f266-4e77-2c1d-5e42-3910a4dfaed3@jptechnical.co.uk> References: <4da0f266-4e77-2c1d-5e42-3910a4dfaed3@jptechnical.co.uk> Message-ID: On 7/23/18 3:24 PM, John Pote wrote: > I recently wrote a command line app to take a stream of numbers, do some > signal processing on them and display the results on the console. There > may be several output columns of data so a title line is printed first. > But the stream of numbers may be several hundred long and the title line > disappears of the top on the console. > > So I thought it might be quick and easy to do something with curses to > keep the title line visable while the numbers roll up the screen. But > alas I'm a Windows user and the 'curses' module is not in the Windows > standard library for Python. > > It occured to me that I could create a simple tkinter class but I > haven't tinkered for some time and would have to refresh my knowledge of > the API. Just wondered if there was any other simple way I could keep > the title line on the console, preferably without having to install > another library. > > Ideas invited. > > You didn't tell us much about your application but for analysis and display I like Jupiter Notebook. Plus it's easy to add graphs etc. Dale From tjol at tjol.eu Mon Jul 23 19:01:45 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 24 Jul 2018 01:01:45 +0200 Subject: Python 2.7.14 and Python 3.6.0 netcdf4 In-Reply-To: References: Message-ID: On 24/07/18 00:39, jorge.conrado at cptec.inpe.br wrote: > ???? from netCDF4 import Dataset > > ???? I had: > > ???? Traceback (most recent call last): > ???? File "", line 1, in > ???? ModuleNotFoundError: No module named 'netCDF4' > > > ???? What can I do to solve this error for Python 3.6.0 Install netCDF4 in your Python 3.6 environment. Depending on what OS and Python distribution you're using, the thing to do might be py -3 -m pip install netCDF4 or pip3 install netCDF4 (or something involving conda if you use anaconda) From steve+comp.lang.python at pearwood.info Mon Jul 23 20:24:25 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 24 Jul 2018 00:24:25 +0000 (UTC) Subject: Python 2.7.14 and Python 3.6.0 netcdf4 References: Message-ID: On Mon, 23 Jul 2018 19:39:18 -0300, jorge.conrado wrote: > Traceback (most recent call last): > File "", line 1, in > ModuleNotFoundError: No module named 'netCDF4' > > > What can I do to solve this error for Python 3.6.0 Just because you have the Python 2.7 version of the netCDF4 module installed in the Python 2.7 environment, doesn't mean it will magically work for Python 3.6. You have to install the module for 3.6 as well. How did you install it for Python 2.7? -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From python at mrabarnett.plus.com Mon Jul 23 20:27:18 2018 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 24 Jul 2018 01:27:18 +0100 Subject: Python 2.7.14 and Python 3.6.0 netcdf4 In-Reply-To: References: Message-ID: <950da667-7724-8c35-623c-1822282c9831@mrabarnett.plus.com> On 2018-07-23 23:39, jorge.conrado at cptec.inpe.br wrote: > > > Hi, > > Please someone can help me with this error message; > > > for Python 2.7.14 I did: > > from netCDF4 import Dataset > > and I didn't have no message > That's because you've installed netCDF4 for Python 2.7. > > > But, for Python 3.6.0 > > from netCDF4 import Dataset > > I had: > > Traceback (most recent call last): > File "", line 1, in > ModuleNotFoundError: No module named 'netCDF4' > That's because you haven't installed netCDF4 for Python 3.6. > > What can I do to solve this error for Python 3.6.0 > Install that module. Assuming that you're using Windows, try this in a console window: py -3.6 -m pip install netCDF4 From flebber.crue at gmail.com Mon Jul 23 21:52:19 2018 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Mon, 23 Jul 2018 18:52:19 -0700 (PDT) Subject: Format list of list sub elements keeping structure. Message-ID: I have data which is a list of lists of all the full paths in a json document. How can I change the format to be usable when selecting elements? data = [['glossary'], ['glossary', 'title'], ['glossary', 'GlossDiv'], ['glossary', 'GlossDiv', 'title'], ['glossary', 'GlossDiv', 'GlossList'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'ID'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'SortAs'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossTerm'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'Acronym'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'Abbrev'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'para'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'GlossSeeAlso'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'GlossSeeAlso', 0], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'GlossSeeAlso', 1], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossSee']] I am trying to change it to be. [['glossary'], ['glossary']['title'], ['glossary']['GlossDiv'], ....] Currently when I am formatting I am flattening the structure(accidentally). for item in data: for elem in item: out = ("[{0}]").format(elem) print(out) Which gives [glossary] [title] [GlossDiv] [title] [GlossList] [GlossEntry] [ID] [SortAs] [GlossTerm] [Acronym] [Abbrev] [GlossDef] [para] [GlossSeeAlso] [0] [1] [GlossSee] Cheers Sayth From eryksun at gmail.com Mon Jul 23 22:03:53 2018 From: eryksun at gmail.com (eryk sun) Date: Tue, 24 Jul 2018 02:03:53 +0000 Subject: curses, ncurses or something else In-Reply-To: <4da0f266-4e77-2c1d-5e42-3910a4dfaed3@jptechnical.co.uk> References: <4da0f266-4e77-2c1d-5e42-3910a4dfaed3@jptechnical.co.uk> Message-ID: On Mon, Jul 23, 2018 at 10:24 PM, John Pote wrote: > > So I thought it might be quick and easy to do something with curses to keep > the title line visable while the numbers roll up the screen. But alas I'm a > Windows user and the 'curses' module is not in the Windows standard library > for Python. Try this versions, based on PDCurses: https://www.lfd.uci.edu/~gohlke/pythonlibs/#curses From flebber.crue at gmail.com Mon Jul 23 22:33:55 2018 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Mon, 23 Jul 2018 19:33:55 -0700 (PDT) Subject: Format list of list sub elements keeping structure. In-Reply-To: <32a505ae-b48c-43a0-9338-7bda1b628cac@googlegroups.com> References: <32a505ae-b48c-43a0-9338-7bda1b628cac@googlegroups.com> Message-ID: <1deea816-b84b-4195-ae73-29bc6b71d118@googlegroups.com> > > > > for item in data: > > for elem in item: > > out = ("[{0}]").format(elem) > > print(out) > > Hint: print implicitly adds a newline to the output string. So collect all the values of each sublist and print a line-at-time to output, or use the end= argument of Py3's print, or find another solution. Also remember that indention is significant in Python. Thanks Getting closer. answer = [] for item in data: for elem in item: out = ("[{0}]").format(elem) answer.append(out) print(answer) Think I need to bring it in a list not an element of a list and process it. Cheers Sayth From flebber.crue at gmail.com Tue Jul 24 00:15:56 2018 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Mon, 23 Jul 2018 21:15:56 -0700 (PDT) Subject: Format list of list sub elements keeping structure. In-Reply-To: <1deea816-b84b-4195-ae73-29bc6b71d118@googlegroups.com> References: <32a505ae-b48c-43a0-9338-7bda1b628cac@googlegroups.com> <1deea816-b84b-4195-ae73-29bc6b71d118@googlegroups.com> Message-ID: <36411c3e-2089-495e-a9a0-1d02d153bbf0@googlegroups.com> I am very close to the end result. I now have it as Output [ ['[glossary]'], ['[glossary]', '[title]'], ['[glossary]', '[GlossDiv]'], ['[glossary]', '[GlossDiv]', '[title]'], ['[glossary]', '[GlossDiv]', '[GlossList]'], ['[glossary]', '[GlossDiv]', '[GlossList]', '[GlossEntry]'], .........] I used. elements = [['[{0}]'.format(element) for element in elements]for elements in data] Is there a good way to strip the ', ' and make the list a list of 1 element lists? Thoughts on achieving this? So [ ['[glossary]'], ['[glossary][title]'], ....] Cheers Sayth From flebber.crue at gmail.com Tue Jul 24 01:11:49 2018 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Mon, 23 Jul 2018 22:11:49 -0700 (PDT) Subject: Format list of list sub elements keeping structure. In-Reply-To: <3fca95ba-129b-4234-a107-2e9bb3d12432@googlegroups.com> References: <32a505ae-b48c-43a0-9338-7bda1b628cac@googlegroups.com> <1deea816-b84b-4195-ae73-29bc6b71d118@googlegroups.com> <36411c3e-2089-495e-a9a0-1d02d153bbf0@googlegroups.com> <3fca95ba-129b-4234-a107-2e9bb3d12432@googlegroups.com> Message-ID: <7ea5f822-aa65-423a-9471-ba0267eef512@googlegroups.com> On Tuesday, 24 July 2018 14:25:48 UTC+10, Rick Johnson wrote: > Sayth Renshaw wrote: > > > elements = [['[{0}]'.format(element) for element in elements]for elements in data] > > I would suggest you avoid list comprehensions until you master long-form loops. My general issue is that I want to pick up all the elements in each sublist and operate on them to concatenate them together. However, using for loops I get each list then each element of each list. When in my head I want each list then all elements of each list. Sayth From flebber.crue at gmail.com Tue Jul 24 01:41:59 2018 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Mon, 23 Jul 2018 22:41:59 -0700 (PDT) Subject: Format list of list sub elements keeping structure. In-Reply-To: <3fca95ba-129b-4234-a107-2e9bb3d12432@googlegroups.com> References: <32a505ae-b48c-43a0-9338-7bda1b628cac@googlegroups.com> <1deea816-b84b-4195-ae73-29bc6b71d118@googlegroups.com> <36411c3e-2089-495e-a9a0-1d02d153bbf0@googlegroups.com> <3fca95ba-129b-4234-a107-2e9bb3d12432@googlegroups.com> Message-ID: <1b6ef7f8-248f-4f75-8e95-82a96ee6c6f6@googlegroups.com> On Tuesday, 24 July 2018 14:25:48 UTC+10, Rick Johnson wrote: > Sayth Renshaw wrote: > > > elements = [['[{0}]'.format(element) for element in elements]for elements in data] > > I would suggest you avoid list comprehensions until you master long-form loops. I actually have the answer except for a glitch where on list element is an int. My code for item in data: out = '[{0}]'.format("][".join(item)) print(out) which prints out [glossary] [glossary][title] [glossary][GlossDiv] [glossary][GlossDiv][title] [glossary][GlossDiv][GlossList] .... However, in my source I have two lines like this ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'GlossSeeAlso', 0], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'GlossSeeAlso', 1], when it hits these lines I get TypeError: sequence item 6: expected str instance, int found Do I need to do an explicit check for these 2 cases or is there a simpler way? Cheers Sayth From breamoreboy at gmail.com Tue Jul 24 02:25:44 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Tue, 24 Jul 2018 07:25:44 +0100 Subject: Format list of list sub elements keeping structure. In-Reply-To: <1b6ef7f8-248f-4f75-8e95-82a96ee6c6f6@googlegroups.com> References: <32a505ae-b48c-43a0-9338-7bda1b628cac@googlegroups.com> <1deea816-b84b-4195-ae73-29bc6b71d118@googlegroups.com> <36411c3e-2089-495e-a9a0-1d02d153bbf0@googlegroups.com> <3fca95ba-129b-4234-a107-2e9bb3d12432@googlegroups.com> <1b6ef7f8-248f-4f75-8e95-82a96ee6c6f6@googlegroups.com> Message-ID: On 24/07/18 06:41, Sayth Renshaw wrote: > On Tuesday, 24 July 2018 14:25:48 UTC+10, Rick Johnson wrote: >> Sayth Renshaw wrote: >> >>> elements = [['[{0}]'.format(element) for element in elements]for elements in data] >> >> I would suggest you avoid list comprehensions until you master long-form loops. > > I actually have the answer except for a glitch where on list element is an int. > > My code > > for item in data: > out = '[{0}]'.format("][".join(item)) > print(out) > > which prints out > > [glossary] > [glossary][title] > [glossary][GlossDiv] > [glossary][GlossDiv][title] > [glossary][GlossDiv][GlossList] > .... > > However, in my source I have two lines like this > > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'GlossSeeAlso', 0], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'GlossSeeAlso', 1], > > when it hits these lines I get > > TypeError: sequence item 6: expected str instance, int found > > Do I need to do an explicit check for these 2 cases or is there a simpler way? > > Cheers > > Sayth > out = '[{0}]'.format("][".join(str(item))) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From vlastimil.brom at gmail.com Tue Jul 24 04:04:01 2018 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Tue, 24 Jul 2018 10:04:01 +0200 Subject: Format list of list sub elements keeping structure. In-Reply-To: References: Message-ID: 2018-07-24 3:52 GMT+02:00, Sayth Renshaw : > I have data which is a list of lists of all the full paths in a json > document. > > How can I change the format to be usable when selecting elements? > > data = [['glossary'], > ['glossary', 'title'], > ['glossary', 'GlossDiv'], > ['glossary', 'GlossDiv', 'title'], > ['glossary', 'GlossDiv', 'GlossList'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'ID'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'SortAs'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossTerm'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'Acronym'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'Abbrev'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'para'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', > 'GlossSeeAlso'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', > 'GlossSeeAlso', 0], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', > 'GlossSeeAlso', 1], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossSee']] > > I am trying to change it to be. > > [['glossary'], > ['glossary']['title'], > ['glossary']['GlossDiv'], > ....] > > [...] > > > Cheers > > Sayth > -- > https://mail.python.org/mailman/listinfo/python-list > Hi, You may try to experiment with pprint https://docs.python.org/3/library/pprint.html I don't use it very often, but it seems to suit the needs like this. If you increase the default width=80 (intended for reading and source code) to a larger value, the formatting might come close to your specification. For the sample data, the width can be set to a slightly smaller value, than the length of the whole string representation of the nested list, the formatting then follows the next "level" of the nesting, these are formated on separate lines. cf.: >>> import pprint >>> len(str(data)) 957 >>> pprint.pprint(data, width=956, compact=False) [['glossary'], ['glossary', 'title'], ['glossary', 'GlossDiv'], ['glossary', 'GlossDiv', 'title'], ['glossary', 'GlossDiv', 'GlossList'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'ID'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'SortAs'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossTerm'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'Acronym'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'Abbrev'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'para'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'GlossSeeAlso'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'GlossSeeAlso', 0], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'GlossSeeAlso', 1], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossSee']] >>> hth, vbr From tjol at tjol.eu Tue Jul 24 04:05:30 2018 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 24 Jul 2018 10:05:30 +0200 Subject: Format list of list sub elements keeping structure. In-Reply-To: References: <32a505ae-b48c-43a0-9338-7bda1b628cac@googlegroups.com> <1deea816-b84b-4195-ae73-29bc6b71d118@googlegroups.com> <36411c3e-2089-495e-a9a0-1d02d153bbf0@googlegroups.com> <3fca95ba-129b-4234-a107-2e9bb3d12432@googlegroups.com> <1b6ef7f8-248f-4f75-8e95-82a96ee6c6f6@googlegroups.com> Message-ID: <5c666649-fd88-115d-2cb1-3b8fa1720f82@tjol.eu> On 24/07/18 08:25, Mark Lawrence wrote: > On 24/07/18 06:41, Sayth Renshaw wrote: >> On Tuesday, 24 July 2018 14:25:48 UTC+10, Rick Johnson? wrote: >>> Sayth Renshaw wrote: >>> >>>> elements = [['[{0}]'.format(element) for element in elements]for >>>> elements in data] >>> >>> I would suggest you avoid list comprehensions until you master >>> long-form loops. >> >> I actually have the answer except for a glitch where on list element >> is an int. >> >> My code >> >> for item in data: >> ???? out = '[{0}]'.format("][".join(item)) >> ???? print(out) >> >> which prints out >> >> [glossary] >> [glossary][title] >> [glossary][GlossDiv] >> [glossary][GlossDiv][title] >> [glossary][GlossDiv][GlossList] >> .... >> >> However, in my source I have two lines like this >> >> ? ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', >> 'GlossSeeAlso', 0], >> ? ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', >> 'GlossSeeAlso', 1], >> >> when it hits these lines I get >> >> TypeError: sequence item 6: expected str instance, int found >> >> Do I need to do an explicit check for these 2 cases or is there a >> simpler way? >> >> Cheers >> >> Sayth >> > > out = '[{0}]'.format("][".join(str(item))) No. >>> item = ['a', 'b', 1] >>> '[{0}]'.format("][".join(item)) Traceback (most recent call last): File "", line 1, in TypeError: sequence item 2: expected str instance, int found >>> '[{0}]'.format("][".join(str(item))) "[[]['][a]['][,][ ]['][b]['][,][ ][1][]]" >>> You'll want to use map(), a generator comprehension, or a different approach. > From __peter__ at web.de Tue Jul 24 04:19:05 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 24 Jul 2018 10:19:05 +0200 Subject: Format list of list sub elements keeping structure. References: Message-ID: Sayth Renshaw wrote: > I have data which is a list of lists of all the full paths in a json > document. > > How can I change the format to be usable when selecting elements? How do you want to select these elements? myjson = ... path = "['foo']['bar'][42]" print(eval("myjson" + path)) ? Wouldn't it be better to keep 'data' as is and use a helper function like def get_value(myjson, path): for key_or_index in path: myjson = myjson[key_or_index] return myjson path = ['foo', 'bar', 42] print(get_value(myjson, path)) ? > data = [['glossary'], > ['glossary', 'title'], > ['glossary', 'GlossDiv'], > ['glossary', 'GlossDiv', 'title'], > ['glossary', 'GlossDiv', 'GlossList'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'ID'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'SortAs'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossTerm'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'Acronym'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'Abbrev'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', 'para'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossDef', > ['GlossSeeAlso'], 'glossary', 'GlossDiv', 'GlossList', 'GlossEntry', > ['GlossDef', 'GlossSeeAlso', 0], 'glossary', 'GlossDiv', 'GlossList', > ['GlossEntry', 'GlossDef', 'GlossSeeAlso', 1], 'glossary', 'GlossDiv', > ['GlossList', 'GlossEntry', 'GlossSee']] > > I am trying to change it to be. > > [['glossary'], > ['glossary']['title'], > ['glossary']['GlossDiv'], > ....] > > Currently when I am formatting I am flattening the > structure(accidentally). > > for item in data: > for elem in item: > out = ("[{0}]").format(elem) > print(out) > > Which gives > > [glossary] > [title] > [GlossDiv] > [title] > [GlossList] > [GlossEntry] > [ID] > [SortAs] > [GlossTerm] > [Acronym] > [Abbrev] > [GlossDef] > [para] > [GlossSeeAlso] > [0] > [1] > [GlossSee] > > > Cheers > > Sayth From brgl at bgdev.pl Tue Jul 24 06:09:51 2018 From: brgl at bgdev.pl (Bartosz Golaszewski) Date: Tue, 24 Jul 2018 12:09:51 +0200 Subject: Tracking a memory leak in C extension - interpreting the output of PYTHONMALLOCSTATS In-Reply-To: References: Message-ID: 2018-07-23 21:51 GMT+02:00 Thomas Jollans : > On 23/07/18 20:02, Bartosz Golaszewski wrote: >> Hi! > > Hey! > >> A user recently reported a memory leak in python bindings (C extension >> module) to a C library[1] I wrote. I've been trying to fix it since >> but so far without success. Since I'm probably dealing with a space >> leak rather than actual memory leak, valgrind didn't help much even >> when using malloc as allocator. I'm now trying to use >> PYTHONMALLOCSTATS but need some help on how to interpret the output >> emitted it's enabled. > > Oh dear. > >> >> [snip] >> >> The number of pools in arena 53 continuously grows. Its size column >> says: 432. I couldn't find any documentation on what it means but I >> assume it's an allocation of 432 bytes. [...] > > I had a quick look at the code (because what else does one do for fun); > I don't understand much, but what I can tell you is that > (a) yes, that is an allocation size in bytes, and > (b) as you can see, it uses intervals of 8. This means that pool 53 > is used for allocations of 424 < nbytes <= 432 bytes. Maybe your > breakpoint needs tweaking. > (c) Try breaking on _PyObject_Malloc or pymalloc_alloc. I think they're > called by both PyMem_Malloc and PyObject_Malloc. > > int _PyObject_DebugMallocStats(FILE *out) > > https://github.com/python/cpython/blob/b18f8bc1a77193c372d79afa79b284028a2842d7/Objects/obmalloc.c#L2435 > > static int pymalloc_alloc(void *ctx, void **ptr_p, size_t nbytes) > > https://github.com/python/cpython/blob/b18f8bc1a77193c372d79afa79b284028a2842d7/Objects/obmalloc.c#L1327 > > > Have fun debugging! > > -- Thomas > > >> >> How do I use the info produced by PYTHONMALLOCSTATS do get to the >> culprit of the leak? Is there anything wrong in my reasoning here? >> >> Best regards, >> Bartosz Golaszewski >> >> [1] https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/ >> > > -- > https://mail.python.org/mailman/listinfo/python-list Thanks for the hints! I've been able to pinpoint the allocation in question to this line: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/bindings/python/gpiodmodule.c?h=next#n1238 with the following stack trace: #0 _PyObject_Malloc (ctx=0x0, nbytes=432) at Objects/obmalloc.c:1523 #1 0x0000555555614c38 in _PyMem_DebugRawAlloc (ctx=0x555555a3c340 <_PyMem_Debug+96>, nbytes=400, use_calloc=0) at Objects/obmalloc.c:1998 #2 0x00005555556238c5 in PyType_GenericAlloc (type=0x7ffff6e06820 , nitems=0) at Objects/typeobject.c:972 #3 0x0000555555627ba5 in type_call (type=0x7ffff6e06820 , args=0x7ffff6e21910, kwds=0x0) at Objects/typeobject.c:929 #4 0x00005555555cc666 in PyObject_Call (kwargs=0x0, args=, callable=0x7ffff6e06820 ) at Objects/call.c:245 #5 PyEval_CallObjectWithKeywords (kwargs=0x0, args=, callable=0x7ffff6e06820 ) at Objects/call.c:826 #6 PyObject_CallObject (callable=0x7ffff6e06820 , args=) at Objects/call.c:834 #7 0x00007ffff6c008dd in gpiod_LineToLineBulk (line=line at entry=0x7ffff5bbd240) at gpiodmodule.c:1238 #8 0x00007ffff6c009af in gpiod_Line_set_value (self=0x7ffff5bbd240, args=) at gpiodmodule.c:442 #9 0x00005555555c9ef8 in _PyMethodDef_RawFastCallKeywords (method=0x7ffff6e06280 , self=self at entry=0x7ffff5bbd240, args=args at entry=0x555555b15e18, nargs=nargs at entry=1, kwnames=kwnames at entry=0x0) at Objects/call.c:694 #10 0x0000555555754db9 in _PyMethodDescr_FastCallKeywords (descrobj=0x7ffff6e344d0, args=args at entry=0x555555b15e10, nargs=nargs at entry=2, kwnames=kwnames at entry=0x0) at Objects/descrobject.c:288 #11 0x00005555555b7fcd in call_function (kwnames=0x0, oparg=2, pp_stack=) at Python/ceval.c:4581 #12 _PyEval_EvalFrameDefault (f=, throwflag=) at Python/ceval.c:3176 #13 0x0000555555683b7c in PyEval_EvalFrameEx (throwflag=0, f=0x555555b15ca0) at Python/ceval.c:536 #14 _PyEval_EvalCodeWithName (_co=_co at entry=0x7ffff7e50460, globals=globals at entry=0x7ffff7f550e8, locals=locals at entry=0x7ffff7e50460, args=args at entry=0x0, argcount=argcount at entry=0, kwnames=kwnames at entry=0x0, kwargs=0x0, kwcount=0, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at Python/ceval.c:3941 #15 0x0000555555683ca3 in PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0, locals=locals at entry=0x7ffff7e50460, globals=globals at entry=0x7ffff7f550e8, _co=_co at entry=0x7ffff7e50460) at Python/ceval.c:3970 #16 PyEval_EvalCode (co=co at entry=0x7ffff7e50460, globals=globals at entry=0x7ffff7efcc50, locals=locals at entry=0x7ffff7efcc50) at Python/ceval.c:513 #17 0x00005555556bb099 in run_mod (arena=0x7ffff7f550e8, flags=0x7fffffffe1a0, locals=0x7ffff7efcc50, globals=0x7ffff7efcc50, filename=0x7ffff7e5b4c0, mod=0x555555afc2f8) at Python/pythonrun.c:1035 #18 PyRun_FileExFlags (fp=0x555555b26010, filename_str=, start=, globals=0x7ffff7efcc50, locals=0x7ffff7efcc50, closeit=1, flags=0x7fffffffe1a0) at Python/pythonrun.c:988 #19 0x00005555556bb2b5 in PyRun_SimpleFileExFlags (fp=0x555555b26010, filename=, closeit=1, flags=0x7fffffffe1a0) at Python/pythonrun.c:429 #20 0x00005555555bd5ff in pymain_run_file (p_cf=0x7fffffffe1a0, filename=0x555555ab7380 L"./gpio_leak.py", fp=0x555555b26010) at Modules/main.c:426 #21 pymain_run_filename (cf=0x7fffffffe1a0, pymain=0x7fffffffe2a0) at Modules/main.c:1521 #22 pymain_run_python (pymain=0x7fffffffe2a0) at Modules/main.c:2570 #23 pymain_main (pymain=pymain at entry=0x7fffffffe2a0) at Modules/main.c:2712 #24 0x00005555555bda3a in _Py_UnixMain (argc=, argv=) at Modules/main.c:2747 #25 0x00007ffff71322e1 in __libc_start_main (main=0x5555555ae8a0
, argc=2, argv=0x7fffffffe4d8, init=, fini=, rtld_fini=, stack_end=0x7fffffffe4c8) at ../csu/libc-start.c:291 #26 0x00005555555b8dea in _start () Except that I can also see in gdb that the object created here is freed find at https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/bindings/python/gpiodmodule.c?h=next#n454 #0 _PyObject_Free (ctx=0x0, p=0x7ffff6e32d78) at Objects/obmalloc.c:1780 #1 0x00007ffff6c00a6f in gpiod_Line_set_value (self=, args=) at gpiodmodule.c:454 #2 0x00005555555c9ef8 in _PyMethodDef_RawFastCallKeywords (method=0x7ffff6e06280 , self=self at entry=0x7ffff5bbd240, args=args at entry=0x555555b15e18, nargs=nargs at entry=1, kwnames=kwnames at entry=0x0) at Objects/call.c:694 #3 0x0000555555754db9 in _PyMethodDescr_FastCallKeywords (descrobj=0x7ffff6e344d0, args=args at entry=0x555555b15e10, nargs=nargs at entry=2, kwnames=kwnames at entry=0x0) at Objects/descrobject.c:288 #4 0x00005555555b7fcd in call_function (kwnames=0x0, oparg=2, pp_stack=) at Python/ceval.c:4581 #5 _PyEval_EvalFrameDefault (f=, throwflag=) at Python/ceval.c:3176 #6 0x0000555555683b7c in PyEval_EvalFrameEx (throwflag=0, f=0x555555b15ca0) at Python/ceval.c:536 #7 _PyEval_EvalCodeWithName (_co=_co at entry=0x7ffff7e50460, globals=globals at entry=0x7ffff7f550e8, locals=locals at entry=0x7ffff7e50460, args=args at entry=0x0, argcount=argcount at entry=0, kwnames=kwnames at entry=0x0, kwargs=0x0, kwcount=0, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at Python/ceval.c:3941 #8 0x0000555555683ca3 in PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0, locals=locals at entry=0x7ffff7e50460, globals=globals at entry=0x7ffff7f550e8, _co=_co at entry=0x7ffff7e50460) at Python/ceval.c:3970 #9 PyEval_EvalCode (co=co at entry=0x7ffff7e50460, globals=globals at entry=0x7ffff7efcc50, locals=locals at entry=0x7ffff7efcc50) at Python/ceval.c:513 #10 0x00005555556bb099 in run_mod (arena=0x7ffff7f550e8, flags=0x7fffffffe1a0, locals=0x7ffff7efcc50, globals=0x7ffff7efcc50, filename=0x7ffff7e5b4c0, mod=0x555555afc2f8) at Python/pythonrun.c:1035 #11 PyRun_FileExFlags (fp=0x555555b26010, filename_str=, start=, globals=0x7ffff7efcc50, locals=0x7ffff7efcc50, closeit=1, flags=0x7fffffffe1a0) at Python/pythonrun.c:988 #12 0x00005555556bb2b5 in PyRun_SimpleFileExFlags (fp=0x555555b26010, filename=, closeit=1, flags=0x7fffffffe1a0) at Python/pythonrun.c:429 #13 0x00005555555bd5ff in pymain_run_file (p_cf=0x7fffffffe1a0, filename=0x555555ab7380 L"./gpio_leak.py", fp=0x555555b26010) at Modules/main.c:426 #14 pymain_run_filename (cf=0x7fffffffe1a0, pymain=0x7fffffffe2a0) at Modules/main.c:1521 #15 pymain_run_python (pymain=0x7fffffffe2a0) at Modules/main.c:2570 #16 pymain_main (pymain=pymain at entry=0x7fffffffe2a0) at Modules/main.c:2712 #17 0x00005555555bda3a in _Py_UnixMain (argc=, argv=) at Modules/main.c:2747 #18 0x00007ffff71322e1 in __libc_start_main (main=0x5555555ae8a0
, argc=2, argv=0x7fffffffe4d8, init=, fini=, rtld_fini=, stack_end=0x7fffffffe4c8) at ../csu/libc-start.c:291 #19 0x00005555555b8dea in _start () I don't see any other allocation of this size. Can this be some bug in the interpreter? Bart From cl at isbd.net Tue Jul 24 06:25:05 2018 From: cl at isbd.net (Chris Green) Date: Tue, 24 Jul 2018 11:25:05 +0100 Subject: Non-GUI, single processort inter process massaging - how? References: <20180723164444.04abe347@wegge.dk> Message-ID: <1dbj2f-dq8.ln1@esprimo.zbmc.eu> Dennis Lee Bieber wrote: > On Mon, 23 Jul 2018 22:14:22 +0100, Chris Green declaimed the > following: > > >Anders Wegge Keller wrote: > >> > >> If your update frequency is low enough that it wont kill the filesystem and > >> the amount of data is reasonably small, atomic writes to a file is easy to > >> work with: > >> > >Yes, I think you're right, using a file would seem to be the best > >answer. Sample rate is only one a second or slower and there's not a > >huge amount of data involved. > > > > If the data is small enough, putting the file into the small shared > memory (forget if that is /dev/shm or /run/shm on the BBB) would even avoid > wearing out eMMC/SD card. > That is also a very good idea, there's /dev/shm and /run on my BBB, /dev/shm seems to have more space. -- Chris Green ? From flebber.crue at gmail.com Tue Jul 24 06:42:21 2018 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 24 Jul 2018 03:42:21 -0700 (PDT) Subject: Format list of list sub elements keeping structure. In-Reply-To: References: Message-ID: > myjson = ... > path = "['foo']['bar'][42]" > print(eval("myjson" + path)) > > ? > > Wouldn't it be better to keep 'data' as is and use a helper function like > > def get_value(myjson, path): > for key_or_index in path: > myjson = myjson[key_or_index] > return myjson > > path = ['foo', 'bar', 42] > print(get_value(myjson, path)) > > ? Currently I do leave the data I extract the keys out as a full path. If I use pprint as suggested I get close. ['glossary'], ['glossary', 'title'], ['glossary', 'GlossDiv'], ['glossary', 'GlossDiv', 'title'], ['glossary', 'GlossDiv', 'GlossList'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'ID'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'SortAs'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossTerm'], ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'Acronym'], ...] But to select elements from the json I need the format json['elem1']['elem2] . I want to be able to get any json in future and parse it into my function and return a list of all json key elements. Then using this cool answer on SO https://stackoverflow.com/a/14692747/461887 from functools import reduce # forward compatibility for Python 3 import operator def getFromDict(dataDict, mapList): return reduce(operator.getitem, mapList, dataDict) def setInDict(dataDict, mapList, value): getFromDict(dataDict, mapList[:-1])[mapList[-1]] = value Then get the values from the keys >>> getFromDict(dataDict, ["a", "r"]) 1 That would mean I could using my function if I get it write be able to feed it any json, get all the full paths nicely printed and then feed it back to the SO formula and get the values. It would essentially self process itself and let me get a summary of all keys and their data. Thanks Sayth From brgl at bgdev.pl Tue Jul 24 07:30:20 2018 From: brgl at bgdev.pl (Bartosz Golaszewski) Date: Tue, 24 Jul 2018 13:30:20 +0200 Subject: Tracking a memory leak in C extension - interpreting the output of PYTHONMALLOCSTATS In-Reply-To: References: Message-ID: 2018-07-24 12:09 GMT+02:00 Bartosz Golaszewski : > 2018-07-23 21:51 GMT+02:00 Thomas Jollans : >> On 23/07/18 20:02, Bartosz Golaszewski wrote: >>> Hi! >> >> Hey! >> >>> A user recently reported a memory leak in python bindings (C extension >>> module) to a C library[1] I wrote. I've been trying to fix it since >>> but so far without success. Since I'm probably dealing with a space >>> leak rather than actual memory leak, valgrind didn't help much even >>> when using malloc as allocator. I'm now trying to use >>> PYTHONMALLOCSTATS but need some help on how to interpret the output >>> emitted it's enabled. >> >> Oh dear. >> >>> >>> [snip] >>> >>> The number of pools in arena 53 continuously grows. Its size column >>> says: 432. I couldn't find any documentation on what it means but I >>> assume it's an allocation of 432 bytes. [...] >> >> I had a quick look at the code (because what else does one do for fun); >> I don't understand much, but what I can tell you is that >> (a) yes, that is an allocation size in bytes, and >> (b) as you can see, it uses intervals of 8. This means that pool 53 >> is used for allocations of 424 < nbytes <= 432 bytes. Maybe your >> breakpoint needs tweaking. >> (c) Try breaking on _PyObject_Malloc or pymalloc_alloc. I think they're >> called by both PyMem_Malloc and PyObject_Malloc. >> >> int _PyObject_DebugMallocStats(FILE *out) >> >> https://github.com/python/cpython/blob/b18f8bc1a77193c372d79afa79b284028a2842d7/Objects/obmalloc.c#L2435 >> >> static int pymalloc_alloc(void *ctx, void **ptr_p, size_t nbytes) >> >> https://github.com/python/cpython/blob/b18f8bc1a77193c372d79afa79b284028a2842d7/Objects/obmalloc.c#L1327 >> >> >> Have fun debugging! >> >> -- Thomas >> >> [snip!] > > I don't see any other allocation of this size. Can this be some bug in > the interpreter? > > Bart Ok so this is strange: I can fix the leak if I explicitly call PyObject_Free() on the leaking object which is created by "calling" its type. Is this normal? Shouldn't Py_DECREF() be enough? The relevant dealloc callback is called from Py_DECREF() but the object's memory is not freed. Bart From __peter__ at web.de Tue Jul 24 07:40:04 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 24 Jul 2018 13:40:04 +0200 Subject: Format list of list sub elements keeping structure. References: Message-ID: Sayth Renshaw wrote: > >> myjson = ... >> path = "['foo']['bar'][42]" >> print(eval("myjson" + path)) >> >> ? >> >> Wouldn't it be better to keep 'data' as is and use a helper function like >> >> def get_value(myjson, path): >> for key_or_index in path: >> myjson = myjson[key_or_index] >> return myjson >> >> path = ['foo', 'bar', 42] >> print(get_value(myjson, path)) >> >> ? > > Currently I do leave the data I extract the keys out as a full path. > > If I use pprint as suggested I get close. > > ['glossary'], > ['glossary', 'title'], > ['glossary', 'GlossDiv'], > ['glossary', 'GlossDiv', 'title'], > ['glossary', 'GlossDiv', 'GlossList'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'ID'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'SortAs'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'GlossTerm'], > ['glossary', 'GlossDiv', 'GlossList', 'GlossEntry', 'Acronym'], > ...] > > But to select elements from the json I need the format > json['elem1']['elem2] . > > I want to be able to get any json in future and parse it into my function > and return a list of all json key elements. > > Then using this cool answer on SO > https://stackoverflow.com/a/14692747/461887 > > from functools import reduce # forward compatibility for Python 3 > import operator > > def getFromDict(dataDict, mapList): > return reduce(operator.getitem, mapList, dataDict) Note that my -- not so cool ;) -- function >> def get_value(myjson, path): does the same in a way that I expected to be easier to understand than the functional idiom. > def setInDict(dataDict, mapList, value): > getFromDict(dataDict, mapList[:-1])[mapList[-1]] = value > > Then get the values from the keys >>>> getFromDict(dataDict, ["a", "r"]) > 1 > > > That would mean I could using my function if I get it write be able to > feed it any json, get all the full paths nicely printed and then feed it > back to the SO formula and get the values. OK, if this is really just about printing >>> path = ["foo", "bar", 42] >>> print("".join("[{!r}]".format(key) for key in path)) ['foo']['bar'][42] > > It would essentially self process itself and let me get a summary of all > keys and their data. > > Thanks > > Sayth From brgl at bgdev.pl Tue Jul 24 08:05:35 2018 From: brgl at bgdev.pl (Bartosz Golaszewski) Date: Tue, 24 Jul 2018 14:05:35 +0200 Subject: Tracking a memory leak in C extension - interpreting the output of PYTHONMALLOCSTATS In-Reply-To: References: Message-ID: 2018-07-24 13:30 GMT+02:00 Bartosz Golaszewski : > 2018-07-24 12:09 GMT+02:00 Bartosz Golaszewski : >> 2018-07-23 21:51 GMT+02:00 Thomas Jollans : >>> On 23/07/18 20:02, Bartosz Golaszewski wrote: >>>> Hi! >>> >>> Hey! >>> >>>> A user recently reported a memory leak in python bindings (C extension >>>> module) to a C library[1] I wrote. I've been trying to fix it since >>>> but so far without success. Since I'm probably dealing with a space >>>> leak rather than actual memory leak, valgrind didn't help much even >>>> when using malloc as allocator. I'm now trying to use >>>> PYTHONMALLOCSTATS but need some help on how to interpret the output >>>> emitted it's enabled. >>> >>> Oh dear. >>> >>>> >>>> [snip] >>>> >>>> The number of pools in arena 53 continuously grows. Its size column >>>> says: 432. I couldn't find any documentation on what it means but I >>>> assume it's an allocation of 432 bytes. [...] >>> >>> I had a quick look at the code (because what else does one do for fun); >>> I don't understand much, but what I can tell you is that >>> (a) yes, that is an allocation size in bytes, and >>> (b) as you can see, it uses intervals of 8. This means that pool 53 >>> is used for allocations of 424 < nbytes <= 432 bytes. Maybe your >>> breakpoint needs tweaking. >>> (c) Try breaking on _PyObject_Malloc or pymalloc_alloc. I think they're >>> called by both PyMem_Malloc and PyObject_Malloc. >>> >>> int _PyObject_DebugMallocStats(FILE *out) >>> >>> https://github.com/python/cpython/blob/b18f8bc1a77193c372d79afa79b284028a2842d7/Objects/obmalloc.c#L2435 >>> >>> static int pymalloc_alloc(void *ctx, void **ptr_p, size_t nbytes) >>> >>> https://github.com/python/cpython/blob/b18f8bc1a77193c372d79afa79b284028a2842d7/Objects/obmalloc.c#L1327 >>> >>> >>> Have fun debugging! >>> >>> -- Thomas >>> >>> > > [snip!] > >> >> I don't see any other allocation of this size. Can this be some bug in >> the interpreter? >> >> Bart > > Ok so this is strange: I can fix the leak if I explicitly call > PyObject_Free() on the leaking object which is created by "calling" > its type. Is this normal? Shouldn't Py_DECREF() be enough? The > relevant dealloc callback is called from Py_DECREF() but the object's > memory is not freed. > > Bart Ok I've found the problem and it's my fault. From tp_dealloc's documentation: --- The destructor function should free all references which the instance owns, free all memory buffers owned by the instance (using the freeing function corresponding to the allocation function used to allocate the buffer), and finally (as its last action) call the type?s tp_free function. --- I'm not calling the tp_free function... Best regards, Bartosz Golaszewski From pkpearson at nowhere.invalid Tue Jul 24 11:13:36 2018 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 24 Jul 2018 15:13:36 GMT Subject: curses, ncurses or something else References: <4da0f266-4e77-2c1d-5e42-3910a4dfaed3@jptechnical.co.uk> Message-ID: On Mon, 23 Jul 2018 23:24:18 +0100, John Pote wrote: > I recently wrote a command line app to take a stream of numbers, do some > signal processing on them and display the results on the console. There > may be several output columns of data so a title line is printed first. > But the stream of numbers may be several hundred long and the title line > disappears of the top on the console. > > So I thought it might be quick and easy to do something with curses to > keep the title line visable while the numbers roll up the screen. But > alas I'm a Windows user and the 'curses' module is not in the Windows > standard library for Python. > > It occured to me that I could create a simple tkinter class but I > haven't tinkered for some time and would have to refresh my knowledge of > the API. Just wondered if there was any other simple way I could keep > the title line on the console, preferably without having to install > another library. Browsergui is designed to simplify GUI-building by mooching off your web browser. I like it. sudo pip3 install browsergui python3 -m browsergui.examples Enjoy! -- To email me, substitute nowhere->runbox, invalid->com. From john_ladasky at sbcglobal.net Tue Jul 24 14:07:36 2018 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Tue, 24 Jul 2018 11:07:36 -0700 (PDT) Subject: Can pip install packages for all users (on a Linux system)? Message-ID: I've been using "sudo pip3 install" to add packages from the PyPI repository. I have multiple user accounts on the computer in question. My goal is to install packages that are accessible to all user accounts. I know that using the Synaptic Package Manager in Ubuntu will install for all users, but not every Python package is included in the Canonical repository. I hadn't noticed any discrepancies until recently. I upgraded from Ubuntu 17.10 to 18.04. In parallel, I upgraded tensorflow-gpu 1.4.0 to 1.8.0. Everything worked on my main account. However, attempting to import tensorflow from Python on a secondary account failed. Eventually I checked the pip lists in each account, and I found a reference to the old tensorflow 1.4 on the secondary account. Uninstalling that, and reinstalling tensorflow-gpu 1.8 on the secondary account fixed the problem. I believe that I now have tensorflow 1.8 installed twice on my system, once for each user. If anyone can share how to convince pip to behave like Synaptic, I would appreciate it. Thanks. From toby at tobiah.org Tue Jul 24 15:33:27 2018 From: toby at tobiah.org (Tobiah) Date: Tue, 24 Jul 2018 12:33:27 -0700 Subject: Checking whether type is None Message-ID: Consider: >>> type({}) is dict True >>> type(3) is int True >>> type(None) is None False Obvious I guess, since the type object is not None. So what would I compare type(None) to? >>> type(None) >>> type(None) is NoneType Traceback (most recent call last): File "", line 1, in NameError: name 'NoneType' is not defined I know I ask whether: >>> thing is None but I wanted a generic test. I'm trying to get away from things like: >>> type(thing) is type(None) because of something I read somewhere preferring my original test method. Thanks From wolfgang.maier at biologie.uni-freiburg.de Tue Jul 24 15:36:52 2018 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Tue, 24 Jul 2018 21:36:52 +0200 Subject: Can pip install packages for all users (on a Linux system)? In-Reply-To: References: Message-ID: <663db469-b861-c3bb-130d-16283356739f@biologie.uni-freiburg.de> On 24.07.2018 20:07, John Ladasky wrote: > I've been using "sudo pip3 install" to add packages from the PyPI repository. I have multiple user accounts on the computer in question. My goal is to install packages that are accessible to all user accounts. I know that using the Synaptic Package Manager in Ubuntu will install for all users, but not every Python package is included in the Canonical repository. > > I hadn't noticed any discrepancies until recently. I upgraded from Ubuntu 17.10 to 18.04. In parallel, I upgraded tensorflow-gpu 1.4.0 to 1.8.0. Everything worked on my main account. However, attempting to import tensorflow from Python on a secondary account failed. Eventually I checked the pip lists in each account, and I found a reference to the old tensorflow 1.4 on the secondary account. Uninstalling that, and reinstalling tensorflow-gpu 1.8 on the secondary account fixed the problem. > One possible explanation for your finding: user installs normally take precedence over system-wide installs both at import time and for pip (list, uninstall, etc.). So if you, or your users, have installed tensorflow 1.4.0 using pip install --user before, then a system-wide pip install tensorflow 1.8.0 won't override this previous version (though if your admin account has the user install, too, pip would warn you). Otherwise, a pip install without --user is effectively a system-wide install as long as your Python is a system-wide install. > I believe that I now have tensorflow 1.8 installed twice on my system, once for each user. If anyone can share how to convince pip to behave like Synaptic, I would appreciate it. Thanks. > If a user has a user install of tensorflow, it will always shadow the system-wide version. The only solution I know (except manipulating Python's import path list) is to pip uninstall the per-user version. Best, Wolfgang From wolfgang.maier at biologie.uni-freiburg.de Tue Jul 24 15:36:52 2018 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Tue, 24 Jul 2018 21:36:52 +0200 Subject: Can pip install packages for all users (on a Linux system)? In-Reply-To: References: Message-ID: <663db469-b861-c3bb-130d-16283356739f@biologie.uni-freiburg.de> On 24.07.2018 20:07, John Ladasky wrote: > I've been using "sudo pip3 install" to add packages from the PyPI repository. I have multiple user accounts on the computer in question. My goal is to install packages that are accessible to all user accounts. I know that using the Synaptic Package Manager in Ubuntu will install for all users, but not every Python package is included in the Canonical repository. > > I hadn't noticed any discrepancies until recently. I upgraded from Ubuntu 17.10 to 18.04. In parallel, I upgraded tensorflow-gpu 1.4.0 to 1.8.0. Everything worked on my main account. However, attempting to import tensorflow from Python on a secondary account failed. Eventually I checked the pip lists in each account, and I found a reference to the old tensorflow 1.4 on the secondary account. Uninstalling that, and reinstalling tensorflow-gpu 1.8 on the secondary account fixed the problem. > One possible explanation for your finding: user installs normally take precedence over system-wide installs both at import time and for pip (list, uninstall, etc.). So if you, or your users, have installed tensorflow 1.4.0 using pip install --user before, then a system-wide pip install tensorflow 1.8.0 won't override this previous version (though if your admin account has the user install, too, pip would warn you). Otherwise, a pip install without --user is effectively a system-wide install as long as your Python is a system-wide install. > I believe that I now have tensorflow 1.8 installed twice on my system, once for each user. If anyone can share how to convince pip to behave like Synaptic, I would appreciate it. Thanks. > If a user has a user install of tensorflow, it will always shadow the system-wide version. The only solution I know (except manipulating Python's import path list) is to pip uninstall the per-user version. Best, Wolfgang From hi at iwoherka.eu Tue Jul 24 15:41:11 2018 From: hi at iwoherka.eu (Iwo Herka) Date: Tue, 24 Jul 2018 15:41:11 -0400 Subject: Checking whether type is None In-Reply-To: References: Message-ID: In Python 2, you can import NoneType from types module. In Python 3, the best you can do is: NoneType = type(None) ?Iwo Herka https://github.com/IwoHerka? ??????? Original Message ??????? On 24 July 2018 7:33 PM, Tobiah wrote: > ?? > > Consider: > > >>> type({}) is dict > > True > >>> type(3) is int > > True > >>> type(None) is None > > False > > > Obvious I guess, since the type object is not None. > > So what would I compare type(None) to? > > >>> type(None) > > > > >>> type(None) is NoneType > > Traceback (most recent call last): > File "", line 1, in > > NameError: name 'NoneType' is not defined > > > I know I ask whether: > > >>> thing is None > > but I wanted a generic test. > > I'm trying to get away from things like: > > >>> type(thing) is type(None) > > because of something I read somewhere preferring > > my original test method. > > Thanks > > > -------------------------------------------------------------------------------------- > > https://mail.python.org/mailman/listinfo/python-list From David.Raymond at tomtom.com Tue Jul 24 15:56:54 2018 From: David.Raymond at tomtom.com (David Raymond) Date: Tue, 24 Jul 2018 19:56:54 +0000 Subject: Checking whether type is None In-Reply-To: References: Message-ID: https://docs.python.org/3.7/library/constants.html "None The sole value of the type NoneType..." "x is None" and "type(x) is type(None)" are equivalent because of that. I think though that the better way to do the first tests would be to use isinstance https://docs.python.org/3.7/library/functions.html#isinstance isinstance({}, dict) isinstance(3, int) And I suppose if you really wanted: isinstance(None, type(None)) -----Original Message----- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom.com at python.org] On Behalf Of Tobiah Sent: Tuesday, July 24, 2018 3:33 PM To: python-list at python.org Subject: Checking whether type is None Consider: >>> type({}) is dict True >>> type(3) is int True >>> type(None) is None False Obvious I guess, since the type object is not None. So what would I compare type(None) to? >>> type(None) >>> type(None) is NoneType Traceback (most recent call last): File "", line 1, in NameError: name 'NoneType' is not defined I know I ask whether: >>> thing is None but I wanted a generic test. I'm trying to get away from things like: >>> type(thing) is type(None) because of something I read somewhere preferring my original test method. Thanks -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Jul 24 16:07:37 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Jul 2018 06:07:37 +1000 Subject: Checking whether type is None In-Reply-To: References: Message-ID: On Wed, Jul 25, 2018 at 5:33 AM, Tobiah wrote: > Consider: > > >>> type({}) is dict > True > >>> type(3) is int > True > >>> type(None) is None > False > > Obvious I guess, since the type object is not None. > So what would I compare type(None) to? > > >>> type(None) > > >>> type(None) is NoneType > Traceback (most recent call last): > File "", line 1, in > NameError: name 'NoneType' is not defined > > > I know I ask whether: > > >>> thing is None > > but I wanted a generic test. > I'm trying to get away from things like: > > >>> type(thing) is type(None) > > because of something I read somewhere preferring > my original test method. There is nothing more generic in a type test than in simply saying "is None". There are no other instances of NoneType. Don't try type-checking None; just check if the object is None. ChrisA From karate at centurylink.net Tue Jul 24 16:09:45 2018 From: karate at centurylink.net (Daniel Perry) Date: Tue, 24 Jul 2018 16:09:45 -0400 Subject: hello from a very excited and totally blind python programmer and game player Message-ID: <1202DAA12035406D88C59644F2CD671F@Toshiba> Hi there everyone, my name is Daniel Perry and I'm a totally blind new Python user. I've only just recently started picking up python and playing with it and I intend on building some unique audio computer games for the blind. Such things mostly as simulation games like farming, building type games and even eventually a virtual world built completely with audio but building it in such a way that both we as totally blind colonists can live inside of it but also that our fully sighted counterparts could live here as well and not need any sort of guidance from the other group. That is, the blind would not need any help from our sighted counterparts and you in turn would not need any guidance from us as to how to live in the world or grow in it. Of course this virtual world idea is down the road, I've got other game ideas first of all but I would eventually like to get to the point I've just described above. Preferably building my own server on which to park not only my virtual world and games but also my web site that I would most likely need to put these items up to be downloaded. Have a wonderful day to you all and I look forward to your feedback and advice. Also, When I opened up the first message that I had gotten from this list, I got a prompt that popped up asking if I wanted to make windows live mail my default news client and I answered no. From that point on, I've been getting an error message and the message would not open. How must I fix this? or am I able to correct this situation. Have a wonderful day and I look forward to hearing from you soon. From steve+comp.lang.python at pearwood.info Tue Jul 24 19:02:11 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 24 Jul 2018 23:02:11 +0000 (UTC) Subject: Checking whether type is None References: Message-ID: On Tue, 24 Jul 2018 12:33:27 -0700, Tobiah wrote: [...] > So what would I compare type(None) to? Why would you need to? The fastest, easiest, most reliable way to check if something is None is: if something is None > >>> type(None) > > >>> type(None) is NoneType > Traceback (most recent call last): > File "", line 1, in > NameError: name 'NoneType' is not defined You can do: from types import NoneType or if you prefer: NoneType = type(None) but why bother? > I know I ask whether: > > >>> thing is None > > but I wanted a generic test. That *is* a generic test. > I'm trying to get away from things like: > > >>> type(thing) is type(None) That is a good move. > because of something I read somewhere preferring my original test > method. Oh, you read "something" "somewhere"? Then it must be good advice! *wink* Writing code like: type(something) is dict was the standard way to do a type check back in the Python 1.5 days. That's about 20 years ago now. These days, that is rarely what we need now. The usual way to check a type is: isinstance(something, dict) but even that should be rare. If you find yourself doing lots of type checking, using isinstance() or type(), then you're probably writing slow, inconvenient Python code. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rgaddi at highlandtechnology.invalid Tue Jul 24 19:18:18 2018 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Tue, 24 Jul 2018 16:18:18 -0700 Subject: Checking whether type is None In-Reply-To: References: Message-ID: On 07/24/2018 01:07 PM, Chris Angelico wrote: > On Wed, Jul 25, 2018 at 5:33 AM, Tobiah wrote: >> Consider: >> >> >>> type({}) is dict >> True >> >>> type(3) is int >> True >> >>> type(None) is None >> False >> >> Obvious I guess, since the type object is not None. >> So what would I compare type(None) to? >> >> >>> type(None) >> >> >>> type(None) is NoneType >> Traceback (most recent call last): >> File "", line 1, in >> NameError: name 'NoneType' is not defined >> >> >> I know I ask whether: >> >> >>> thing is None >> >> but I wanted a generic test. >> I'm trying to get away from things like: >> >> >>> type(thing) is type(None) >> >> because of something I read somewhere preferring >> my original test method. > > There is nothing more generic in a type test than in simply saying "is > None". There are no other instances of NoneType. Don't try > type-checking None; just check if the object is None. > > ChrisA > I suppose one valid usage would be this sort of thing: fn = { int: dispatchInt, str: dispatchStr, list: dispatchList, type(None): dispatchNone }[type(x)] fn(x) -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From rosuav at gmail.com Tue Jul 24 19:32:27 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 25 Jul 2018 09:32:27 +1000 Subject: Checking whether type is None In-Reply-To: References: Message-ID: On Wed, Jul 25, 2018 at 9:18 AM, Rob Gaddi wrote: > On 07/24/2018 01:07 PM, Chris Angelico wrote: >> >> On Wed, Jul 25, 2018 at 5:33 AM, Tobiah wrote: >>> >>> Consider: >>> >>> >>> type({}) is dict >>> True >>> >>> type(3) is int >>> True >>> >>> type(None) is None >>> False >>> >>> Obvious I guess, since the type object is not None. >>> So what would I compare type(None) to? >>> >>> >>> type(None) >>> >>> >>> type(None) is NoneType >>> Traceback (most recent call last): >>> File "", line 1, in >>> NameError: name 'NoneType' is not defined >>> >>> >>> I know I ask whether: >>> >>> >>> thing is None >>> >>> but I wanted a generic test. >>> I'm trying to get away from things like: >>> >>> >>> type(thing) is type(None) >>> >>> because of something I read somewhere preferring >>> my original test method. >> >> >> There is nothing more generic in a type test than in simply saying "is >> None". There are no other instances of NoneType. Don't try >> type-checking None; just check if the object is None. >> >> ChrisA >> > > I suppose one valid usage would be this sort of thing: > > fn = { > int: dispatchInt, > str: dispatchStr, > list: dispatchList, > type(None): dispatchNone > }[type(x)] > fn(x) > True, but that would be useful only in a very few situations, where you guarantee that you'll never get any subclasses. So if you're walking something that was decoded from JSON, and you know for certain that you'll only ever get those types (add float to the list and it's basically covered), then yes, you might do this; and then I would say that using "type(None)" is the correct spelling of it. ChrisA From flebber.crue at gmail.com Tue Jul 24 19:44:34 2018 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 24 Jul 2018 16:44:34 -0700 (PDT) Subject: Format list of list sub elements keeping structure. In-Reply-To: <607bd600-45b8-429b-bffa-6e000dc8a294@googlegroups.com> References: <607bd600-45b8-429b-bffa-6e000dc8a294@googlegroups.com> Message-ID: <00f5a6a2-8d37-4ea6-896b-60a5bec5d225@googlegroups.com> > > Then using this cool answer on SO [...] > > Oh. I thought you wanted to learn how to solve problems. I had no idea you were auditioning for the James Dean part. My bad. Awesome response burn lol. I am trying to solve problems. Getting tired of dealing with JSON and having to figure out the structure each time. Just want to automate that part so I can move through the munging part and spend more time on higher value tasks. Cheers Sayth From flebber.crue at gmail.com Wed Jul 25 01:22:47 2018 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 24 Jul 2018 22:22:47 -0700 (PDT) Subject: Format list of list sub elements keeping structure. In-Reply-To: References: <607bd600-45b8-429b-bffa-6e000dc8a294@googlegroups.com> <00f5a6a2-8d37-4ea6-896b-60a5bec5d225@googlegroups.com> Message-ID: <984046e6-14b5-4139-a451-f3c403b8cb70@googlegroups.com> > > Well, your code was close. All you needed was a little tweak > to make it work like you requested. So keep working at it, > and if you have a specific question, feel free to ask on the > list. > > Here's a tip. Try to simplify the problem. Instead of > looping over a list of lists, and then attempting to do a > format in the middle of an iteration, a format that you > really don't know how to do in a vacuum (no pressure, > right???), pull one of the sublists out and try to format it > _first_. IOWs: isolate the problem. > > And, when you can format _one_ list the way you want -- > spoiler alert! -- you can format an infinite number of lists > the way you want. Loops are cool like that. Well, most of > the time. > > The key to solving most complex problems is to (1) break > them down into small parts, (2) solve each small part, and > (3) assemble the whole puzzle. This is a skill you must > master. And it's really not difficult. It just requires a > different way of thinking about tasks. Thank you Rick, good advice. I really am enjoying coding at the moment, got myself and life in a good headspace. Cheers Sayth From oliver.schoenborn at gmail.com Wed Jul 25 08:14:59 2018 From: oliver.schoenborn at gmail.com (oliver) Date: Wed, 25 Jul 2018 08:14:59 -0400 Subject: Python in the news In-Reply-To: References: Message-ID: Along the same lines but focused on one of the companies mentioned in the Economist article is one by Bloomberg : https://www.bloomberg.com/news/articles/2018-06-14/citi-wants-analysts-to-add-python-to-list-of-languages-on-resume On Mon, Jul 23, 2018, 12:35 Rich Shepard, wrote: > The lead article in science section and technology section of this > week's > 'The Economist' is about Python: > < > https://www.economist.com/science-and-technology/2018/07/21/python-has-brought-computer-programming-to-a-vast-new-audience > > > > Enjoy, > > Rich > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Oliver Schoenborn || Cloud Application Engineer, Owner || Sentian Software Engineering || Ottawa, ON, Canada || +1-613-552-4466 (mobile) || @schollii2 (Twitter) || schoenborno (Skype) || LinkedIn || StackOverFlow || CodeProject || GitHub From rhodri at kynesim.co.uk Wed Jul 25 08:33:33 2018 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 25 Jul 2018 13:33:33 +0100 Subject: hello from a very excited and totally blind python programmer and game player In-Reply-To: <1202DAA12035406D88C59644F2CD671F@Toshiba> References: <1202DAA12035406D88C59644F2CD671F@Toshiba> Message-ID: On 24/07/18 21:09, Daniel Perry wrote: > Also, When I opened up the first message that I had gotten from this list, I got a prompt that popped up asking if I wanted to make windows live mail my default news client and I answered no. From that point on, I've been getting an error message and the message would not open. How must I fix this? or am I able to correct this situation. Have a wonderful day and I look forward to hearing from you soon. I'm afraid you would have to ask the vendors of the software you used to read the message with in the first place. There is nothing particularly odd about this list that I can think of that might cause problems like that. -- Rhodri James *-* Kynesim Ltd From stephanh42 at gmail.com.invalid Wed Jul 25 10:15:18 2018 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 25 Jul 2018 14:15:18 GMT Subject: Can pip install packages for all users (on a Linux system)? References: Message-ID: Op 2018-07-24, John Ladasky schreef : > I believe that I now have tensorflow 1.8 installed twice on my system, > once for each user. If anyone can share how to convince pip to behave > like Synaptic, I would appreciate it. Thanks. I would recommend against using pip to install packages into the system Python. The reason is that you may get into a conflict with the package manager. You can try to be careful and not install tensorflow using Synaptic, but once you install some other package which happens to depend on tensorflow, you will start getting package manager conflicts. An alternative is to install Python yourself (from source, without the package manager) in, say, /opt/python. You are then in splendid isolation from the package manager and can install any version of Python and tensorflow you desire. Stephan From stephanh42 at gmail.com.invalid Wed Jul 25 10:20:05 2018 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 25 Jul 2018 14:20:05 GMT Subject: Checking whether type is None References: Message-ID: Op 2018-07-24, Chris Angelico schreef : > On Wed, Jul 25, 2018 at 9:18 AM, Rob Gaddi > wrote: >> On 07/24/2018 01:07 PM, Chris Angelico wrote: >> I suppose one valid usage would be this sort of thing: >> >> fn = { >> int: dispatchInt, >> str: dispatchStr, >> list: dispatchList, >> type(None): dispatchNone >> }[type(x)] >> fn(x) >> > > True, but that would be useful only in a very few situations, where > you guarantee that you'll never get any subclasses. So if you're > walking something that was decoded from JSON, and you know for certain > that you'll only ever get those types (add float to the list and it's > basically covered), then yes, you might do this; and then I would say > that using "type(None)" is the correct spelling of it. This is actual code I have: @singledispatch def as_color(color): """Convert object to QColor.""" return QtGui.QColor(color) as_color.register(type(None), lambda x: QtGui.QColor(0, 0, 0, 0)) Stephan From rosuav at gmail.com Wed Jul 25 10:36:50 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Jul 2018 00:36:50 +1000 Subject: Checking whether type is None In-Reply-To: References: Message-ID: On Thu, Jul 26, 2018 at 12:20 AM, Stephan Houben wrote: > Op 2018-07-24, Chris Angelico schreef : >> On Wed, Jul 25, 2018 at 9:18 AM, Rob Gaddi >> wrote: >>> On 07/24/2018 01:07 PM, Chris Angelico wrote: >>> I suppose one valid usage would be this sort of thing: >>> >>> fn = { >>> int: dispatchInt, >>> str: dispatchStr, >>> list: dispatchList, >>> type(None): dispatchNone >>> }[type(x)] >>> fn(x) >>> >> >> True, but that would be useful only in a very few situations, where >> you guarantee that you'll never get any subclasses. So if you're >> walking something that was decoded from JSON, and you know for certain >> that you'll only ever get those types (add float to the list and it's >> basically covered), then yes, you might do this; and then I would say >> that using "type(None)" is the correct spelling of it. > > This is actual code I have: > > @singledispatch > def as_color(color): > """Convert object to QColor.""" > return QtGui.QColor(color) > > as_color.register(type(None), lambda x: QtGui.QColor(0, 0, 0, 0)) > Yep, I would agree with that. If it's type-based dispatch, then type(None) is the cleanest and easiest way to spell it. ChrisA From ian.g.kelly at gmail.com Wed Jul 25 10:49:29 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 25 Jul 2018 08:49:29 -0600 Subject: Checking whether type is None In-Reply-To: References: Message-ID: On Wed, Jul 25, 2018, 8:27 AM Stephan Houben wrote: > Op 2018-07-24, Chris Angelico schreef : > > On Wed, Jul 25, 2018 at 9:18 AM, Rob Gaddi > > wrote: > >> On 07/24/2018 01:07 PM, Chris Angelico wrote: > >> I suppose one valid usage would be this sort of thing: > >> > >> fn = { > >> int: dispatchInt, > >> str: dispatchStr, > >> list: dispatchList, > >> type(None): dispatchNone > >> }[type(x)] > >> fn(x) > >> > > > > True, but that would be useful only in a very few situations, where > > you guarantee that you'll never get any subclasses. So if you're > > walking something that was decoded from JSON, and you know for certain > > that you'll only ever get those types (add float to the list and it's > > basically covered), then yes, you might do this; and then I would say > > that using "type(None)" is the correct spelling of it. > > This is actual code I have: > > @singledispatch > def as_color(color): > """Convert object to QColor.""" > return QtGui.QColor(color) > > as_color.register(type(None), lambda x: QtGui.QColor(0, 0, 0, 0)) > Is there a reason for using singledispatch here rather than a simpler and more readable "if color is None" check? > From mail at timgolden.me.uk Wed Jul 25 12:07:12 2018 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 25 Jul 2018 17:07:12 +0100 Subject: hello from a very excited and totally blind python programmer and game player In-Reply-To: <1202DAA12035406D88C59644F2CD671F@Toshiba> References: <1202DAA12035406D88C59644F2CD671F@Toshiba> Message-ID: <0c0de602-d566-0089-5d92-1b73f3790ef9@timgolden.me.uk> Hi Daniel, I'm unsure how well your support tools will work with quoted emails. I'm going to place my answer below your text according to the convention on this list. On 24/07/2018 21:09, Daniel Perry wrote: > Hi there everyone, my name is Daniel Perry and I'm a totally blind > new Python user. I've only just recently started picking up python > and playing with it and I intend on building some unique audio > computer games for the blind. Such things mostly as simulation games > like farming, building type games and even eventually a virtual world > built completely with audio but building it in such a way that both > we as totally blind colonists can live inside of it but also that our > fully sighted counterparts could live here as well and not need any > sort of guidance from the other group. That is, the blind would not > need any help from our sighted counterparts and you in turn would not > need any guidance from us as to how to live in the world or grow in > it. Of course this virtual world idea is down the road, I've got > other game ideas first of all but I would eventually like to get to > the point I've just described above. Preferably building my own > server on which to park not only my virtual world and games but also > my web site that I would most likely need to put these items up to be > downloaded. Have a wonderful day to you all and I look forward to > your feedback and advice. Also, When I opened up the first message > that I had gotten from this list, I got a prompt that popped up > asking if I wanted to make windows live mail my default news client > and I answered no. From that point on, I've been getting an error > message and the message would not open. How must I fix this? or am I > able to correct this situation. Have a wonderful day and I look > forward to hearing from you soon. > First of all: Hello, and welcome. If you're a beginner to Python (or to programming in general) you might find the tutor list is a better place to start: https://mail.python.org/mailman/listinfo/tutor But feel free to carry on posting here if you prefer. If you want advice you'll probably need to ask a more or less focused question. The sort of thing you outline as an audio computer game sounds interesting and quite ambitious. I'm not clear if you've done any programming at all until now? If not, you'll want to start small and work up from there. I'm not clear what's going on with your Windows Live Mail issue. The only (and obvious) thing I can suggest initially is to ask if someone closer to you can understand what's happening and advise. It's difficult to guess what's happened without getting closer to the problem. Anyway, do post back here or to the Tutor list and ask if you any specific questions. TJG From Joseph.Schachner at Teledyne.com Wed Jul 25 12:14:18 2018 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Wed, 25 Jul 2018 16:14:18 +0000 Subject: Checking whether type is None In-Reply-To: References: Message-ID: <3dd54eb46cc24a5f8182eaa4b9585b81@Teledyne.com> While I appreciate that use of "is" in thing is None, I claim this relies on knowledge of how Python works internally, to know that every None actually is the same ID (the same object) - it is singular. That probably works for 0 and 1 also but you probably wouldn't consider testing thing is 1, at least I hope you wouldn't. thing is None looks just as odd to me. Why not thing == None ? That works. --- Joseph S. -----Original Message----- From: Tobiah Sent: Tuesday, July 24, 2018 3:33 PM To: python-list at python.org Subject: Checking whether type is None Consider: >>> type({}) is dict True >>> type(3) is int True >>> type(None) is None False Obvious I guess, since the type object is not None. So what would I compare type(None) to? >>> type(None) >>> type(None) is NoneType Traceback (most recent call last): File "", line 1, in NameError: name 'NoneType' is not defined I know I ask whether: >>> thing is None but I wanted a generic test. I'm trying to get away from things like: >>> type(thing) is type(None) because of something I read somewhere preferring my original test method. Thanks From johnpote at jptechnical.co.uk Wed Jul 25 17:53:22 2018 From: johnpote at jptechnical.co.uk (John Pote) Date: Wed, 25 Jul 2018 22:53:22 +0100 Subject: curses, ncurses or something else In-Reply-To: References: <4da0f266-4e77-2c1d-5e42-3910a4dfaed3@jptechnical.co.uk> Message-ID: <0f98b26a-4dcc-878b-abac-f8574c1d8f0b@jptechnical.co.uk> On 24/07/2018 16:13, Peter Pearson wrote: > On Mon, 23 Jul 2018 23:24:18 +0100, John Pote wrote: >> I recently wrote a command line app to take a stream of numbers, do some >> signal processing on them and display the results on the console. There >> may be several output columns of data so a title line is printed first. >> But the stream of numbers may be several hundred long and the title line >> disappears of the top on the console. >> >> So I thought it might be quick and easy to do something with curses to >> keep the title line visable while the numbers roll up the screen. But >> alas I'm a Windows user and the 'curses' module is not in the Windows >> standard library for Python. >> >> It occured to me that I could create a simple tkinter class but I >> haven't tinkered for some time and would have to refresh my knowledge of >> the API. Just wondered if there was any other simple way I could keep >> the title line on the console, preferably without having to install >> another library. > Browsergui is designed to simplify GUI-building by mooching off your web > browser. I like it. > > sudo pip3 install browsergui > python3 -m browsergui.examples > > Enjoy! > Thanks everyone for the helpful replies. All were good ideas and I'll follow up on them as personal time permits. Work is a pain at the moment AND without any Pythoning. Best wishes to all. From rosuav at gmail.com Wed Jul 25 17:53:53 2018 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 26 Jul 2018 07:53:53 +1000 Subject: Checking whether type is None In-Reply-To: <3dd54eb46cc24a5f8182eaa4b9585b81@Teledyne.com> References: <3dd54eb46cc24a5f8182eaa4b9585b81@Teledyne.com> Message-ID: On Thu, Jul 26, 2018 at 2:14 AM, Schachner, Joseph wrote: > While I appreciate that use of "is" in thing is None, I claim this relies on knowledge of how Python works internally, to know that every None actually is the same ID (the same object) - it is singular. That's part of the *definition* of None. It is a singleton. There is only one None. > That probably works for 0 and 1 also but you probably wouldn't consider testing thing is 1, at least I hope you wouldn't. thing is None looks just as odd to me. Why not thing == None ? That works. > That's not guaranteed, because integers are not guaranteed to be singletons. They're compared by value. ChrisA From john_ladasky at sbcglobal.net Thu Jul 26 01:44:49 2018 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Wed, 25 Jul 2018 22:44:49 -0700 (PDT) Subject: Can pip install packages for all users (on a Linux system)? In-Reply-To: References: Message-ID: <75723b8e-aafa-4799-9c5c-14c2d825780b@googlegroups.com> On Wednesday, July 25, 2018 at 7:15:35 AM UTC-7, Stephan Houben wrote: > Op 2018-07-24, John Ladasky schreef : > > I believe that I now have tensorflow 1.8 installed twice on my system, > > once for each user. If anyone can share how to convince pip to behave > > like Synaptic, I would appreciate it. Thanks. > > I would recommend against using pip to install packages into the system > Python. The reason is that you may get into a conflict with the package > manager. You can try to be careful and not install tensorflow using > Synaptic, but once you install some other package which happens to > depend on tensorflow, you will start getting package manager conflicts. That won't be a problem. Tensorflow is not available in the Canonical repository, so it cannot be installed through Synaptic unless someone has made a PPA somewhere. I don't know why Tensorflow is not part of Canonical, since it is free, open-source, and popular. I don't (yet) have any that depends on tensorflow. Tensorflow's Python API depends on other software, the NVidia drivers and CUDA for example. But that's the opposite issue. And I did install those manually. > An alternative is to install Python yourself (from source, without the package > manager) in, say, /opt/python. You are then in splendid isolation from > the package manager and can install any version of Python and tensorflow > you desire. That's an interesting strategy, and I will consider it. Two copies of Python are easier to accept than two copies of tensorflow. > Stephan From steve+comp.lang.python at pearwood.info Thu Jul 26 01:53:12 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 26 Jul 2018 05:53:12 +0000 (UTC) Subject: Checking whether type is None References: <3dd54eb46cc24a5f8182eaa4b9585b81@Teledyne.com> Message-ID: On Wed, 25 Jul 2018 16:14:18 +0000, Schachner, Joseph wrote: > While I appreciate that use of "is" in thing is None, I claim this > relies on knowledge of how Python works internally, to know that every > None actually is the same ID (the same object) - it is singular. No, it isn't knowledge of Python's internal working. None is a singleton object is a language guarantee, a promise that will always be true in any Python interpreter. It is no more about "how Python works internally" than knowing that the keyword is spelled "class" rather than Class, or that we use ** for exponentiation rather than ^. > That > probably works for 0 and 1 also but you probably wouldn't consider > testing thing is 1, at least I hope you wouldn't. thing is None looks > just as odd to me. Why not thing == None ? That works. It is wrong (in other words, it doesn't work) because it allows non-None objects to masquerade as None and pretend to be what they are not. If that's your intent, then of course you may do so. But without a comment explaining your intent, don't be surprised if more experienced Python programmers correct your "mistake". -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From useracct222 at gmail.com Thu Jul 26 02:51:36 2018 From: useracct222 at gmail.com (abc abc) Date: Wed, 25 Jul 2018 23:51:36 -0700 (PDT) Subject: Cookies not showing up in environ In-Reply-To: References: <789009c6-c0a2-4d41-a599-465dcb6d1036@googlegroups.com> <20180720203846.6kcning7didfvypg@hjp.at> <364162e6-f311-4360-8e12-e9946483c05c@googlegroups.com> <5caa8146-ed0a-475a-b523-06d6ba02de43@googlegroups.com> Message-ID: <329898a7-c988-48fc-9129-35d2fe54f396@googlegroups.com> Yes, this was the problem. At some point early in my attempts I got the idea that linking up Django to a production web server required writing a separate wsgi.py script. Wrong. Replaced the wsgi.py with the default Django wsgi.py for the project and everything seems resolved. Thank you. From marko at pacujo.net Thu Jul 26 03:48:43 2018 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 26 Jul 2018 10:48:43 +0300 Subject: Checking whether type is None References: <3dd54eb46cc24a5f8182eaa4b9585b81@Teledyne.com> Message-ID: <87zhyeqvxg.fsf@elektro.pacujo.net> Steven D'Aprano : > On Wed, 25 Jul 2018 16:14:18 +0000, Schachner, Joseph wrote: >> thing is None looks just as odd to me. Why not thing == None ? That >> works. > > It is wrong (in other words, it doesn't work) because it allows > non-None objects to masquerade as None and pretend to be what they are > not. > > If that's your intent, then of course you may do so. But without a > comment explaining your intent, don't be surprised if more experienced > Python programmers correct your "mistake". Also, while thing == None would work perfectly in almost all cases in practice, it's unidiomatic and suggests the writer isn't quite comfortable with the workings of the language. Somewhat similarly, this code works perfectly: while (x > 0): y = y * x x = x - 1 # end of while return(y) but it doesn't look like Python. Marko From praveenkumarbeedanal at gmail.com Thu Jul 26 05:41:43 2018 From: praveenkumarbeedanal at gmail.com (praveenkumar beedanal) Date: Thu, 26 Jul 2018 02:41:43 -0700 (PDT) Subject: Python back-end architecture for android application Message-ID: <0216578b-87e9-42b3-942c-a7c15cc48d9e@googlegroups.com> Hello all, I am new to python language. I am planning to create android application, whose back end will be Python. The work of the android application is to visualize the co2 emission information and production quantity of the each resource plants. I have confusion regarding the back end architecture which will provide co2 and production quantity information for every 15 minutes. Here is the architecture what i am thinking, give me your feedback if anything wrong. First i am deploying the python application (Written in Django framework) in the server, in application i will provide the required parameters to fetch the data from the ENTSOE API, which provide response in XML that i will parse for the required data. The request has to sent by the application for every 15 minutes.Then application store the parsed data in the relational database. I am creating the web service(Django rest framework) to make connection between android application and data base. Once android application sent the request to the web service running in different server sends the request to the database to fetch required data. Web service sends the JSON response to the android app which will display the result. https://ibb.co/fdYboo here you find my architecture to better understandings. Thanks in advance From stephanh42 at gmail.com.invalid Thu Jul 26 09:35:29 2018 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 26 Jul 2018 13:35:29 GMT Subject: Checking whether type is None References: Message-ID: Op 2018-07-25, Ian Kelly schreef : > Is there a reason for using singledispatch here rather than a simpler and > more readable "if color is None" check? Yes, the other 20 cases I didn't show. And extensibility. Stephan From python at bdurham.com Thu Jul 26 13:05:20 2018 From: python at bdurham.com (Malcolm Greene) Date: Thu, 26 Jul 2018 11:05:20 -0600 Subject: Anyone using cloud based monitoring/logging services with Python logging module? Message-ID: <1532624720.3267220.1453923360.4FC896CA@webmail.messagingengine.com> Looking for feedback on anyone who's using a cloud based monitoring/logging service with Python's standard lib logging module, eg. services such as Datadog, Loggly, Papertrailapp, Scalyr, LogDNA, Logz.io, Logentries, Loggr, Logstats? Would appreciate hearing your experience, pros, cons, recommendations, etc. Thanks! Malcolm From michael.vilain at gmail.com Thu Jul 26 13:35:26 2018 From: michael.vilain at gmail.com (Michael Vilain) Date: Thu, 26 Jul 2018 10:35:26 -0700 Subject: Anyone using cloud based monitoring/logging services with Python logging module? In-Reply-To: <1532624720.3267220.1453923360.4FC896CA@webmail.messagingengine.com> References: <1532624720.3267220.1453923360.4FC896CA@webmail.messagingengine.com> Message-ID: I used DataDog. At the time, I didn't have any experience with python. I had to depend the company to make patches to things that didn't work. And anything custom, I just did a cron job instead of trying to integrate with their tool. They marketed themselves as a monitoring company but they really collect a boatload of performance info that you can wade though to find out what's going on on the system being monitored. The alert setup and other monitor type things have to be done through the web GUI. I don't think you can code it though an API. You put whatever instrumentation you want on the server to be monitored, then clone those files and any local changes you made to their code. It doesn't play well for setting up as an automated solution like stand alone monitoring packages. It's $15/node, which, if you 5000 nodes, you're talking real money. Go with an on-prem solution rather than something that's cloud based. Those can be configured and deployed painlessly. -- Michael Vilain 650-322-6755 > On 26-Jul-2018, at 10:05 AM ?, Malcolm Greene wrote: > > Looking for feedback on anyone who's using a cloud based > monitoring/logging service with Python's standard lib logging module, > eg. services such as Datadog, Loggly, Papertrailapp, Scalyr, LogDNA, > Logz.io, Logentries, Loggr, Logstats? > Would appreciate hearing your experience, pros, cons, > recommendations, etc. > Thanks! > Malcolm > -- > https://mail.python.org/mailman/listinfo/python-list From jonas at wielicki.name Thu Jul 26 14:37:12 2018 From: jonas at wielicki.name (Jonas Wielicki) Date: Thu, 26 Jul 2018 20:37:12 +0200 Subject: [ANN] aioxmpp 0.10 released Message-ID: <34062600.jtOKpxkoK6@sinistra> Dear subscribers, We are pleased to announce the release of aioxmpp 0.10. The current release can be obtained from GitHub [1] (check out the v0.10.0 tag) or PyPI [2]. The HTML documentation can be found at [3]. Examples can be found in the GitHub repository, in the examples sub directory. aioxmpp is a Python library based on asyncio. It implements the client side of the XMPP protocol (RFC 6120 and others). For a more detailed description of the package, please review the README of the package on GitHub [1] or on PyPI [2]. For more information on XMPP, please see [8]. aioxmpp is licensed under the terms of the GNU Lesser General Public License Version 3.0 or later. Version 0.10 is a feature release. * Support for XEP-0077 (In-Band Registration) was contributed by Sergio Alemany [@gersiete]. * Support for requesting an HTTP upload slot via XEP-0363 (HTTP Upload) and support for requesting and replying to XEP-0092 (Software Version) requests. Aside from these newly supported XEPs, much of the work has been on plumbing. Some of the highlights include: * New timeout logic which should help on links with high latency * Enumification of Stanza and Stream Error Conditions * Streamlinging of the aioxmpp.im interfaces and support for MUC invitations. The full list of new features is, as always, included in the changelog [9] included in the official documentation. Bugs, feature requests, patches and questions can be directed to either the aioxmpp mailing list [4], the GitHub issue tracker [5] or the XMPP Multi-User chat [6], whatever floats your boat. Please direct security-relevant issue reports directly to me (jonas at wielicki.name), preferably encrypted using my GPG public key [7]. best regards and happy-asyncio-ing, The aioxmpp team [1]: https://github.com/horazont/aioxmpp [2]: https://pypi.python.org/pypi/aioxmpp [3]: https://docs.zombofant.net/aioxmpp/0.10/ [4]: https://lists.zombofant.net/mailman/listinfo/aioxmpp-devel [5]: https://github.com/horazont/aioxmpp/issues [6]: aioxmpp at conference.zombofant.net [7]: https://sks-keyservers.net/pks/lookup?op=get&search=0xE5EDE5AC679E300F AA5A 78FF 508D 8CF4 F355 F682 E5ED E5AC 679E 300F [8]: https://xmpp.org/ [9]: https://docs.zombofant.net/aioxmpp/0.10/api/ changelog.html#version-0-10 @gersiete: https://github.com/Gersiete -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: This is a digitally signed message part. URL: From ben+python at benfinney.id.au Thu Jul 26 21:10:59 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 27 Jul 2018 11:10:59 +1000 Subject: Anyone using cloud based monitoring/logging services with Python logging module? References: <1532624720.3267220.1453923360.4FC896CA@webmail.messagingengine.com> Message-ID: <854lgl7aak.fsf@benfinney.id.au> Malcolm Greene writes: > Looking for feedback on anyone who's using a cloud based > monitoring/logging service with Python's standard lib logging module, The free-software Sentry is full-featured, implemented in PYthon, and available to set up on your own hosting or pay someone else to host it. This means you can choose Sentry as your logging service, and that leaves you free to choose (and change your mind later) how Sentry itself gets hosted. You're not tied to some vendor's hosted instance. It integrates very well with logging frameworks of many languages, including Python's ?logging? module. -- \ ?When I turned two I was really anxious, because I'd doubled my | `\ age in a year. I thought, if this keeps up, by the time I'm six | _o__) I'll be ninety.? ?Steven Wright | Ben Finney From ian.g.kelly at gmail.com Fri Jul 27 09:57:18 2018 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 27 Jul 2018 07:57:18 -0600 Subject: Checking whether type is None In-Reply-To: References: Message-ID: On Thu, Jul 26, 2018, 10:00 AM Stephan Houben wrote: > Op 2018-07-25, Ian Kelly schreef : > > > Is there a reason for using singledispatch here rather than a simpler and > > more readable "if color is None" check? > > Yes, the other 20 cases I didn't show. > And extensibility. > That seems like a good use of type(None), then. If it we're just for the None check though, then it would have been disturbing. > From Joseph.Schachner at Teledyne.com Fri Jul 27 12:23:11 2018 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Fri, 27 Jul 2018 16:23:11 +0000 Subject: Guilty as charged Message-ID: <53e875aff2404dbaa3addcdc743ac453@Teledyne.com> Re: "...while thing == None would work perfectly in almost all cases in practice, it's unidiomatic and suggests the writer isn't quite comfortable with the workings of the language" I admit, I've been a C++ programmer for many years and a Python programmer for only about 5 years. But, I did learn something here. I've read books on Python and somehow still did not know that None is guaranteed to be a singleton in all implementations, and that not only does "thing is None" therefore work (guaranteed), but that that is the Pythonic thing to do. ... Maybe I missed it, but I'll remember it now. --- Joseph S. From baratharon at caesar.elte.hu Fri Jul 27 13:13:37 2018 From: baratharon at caesar.elte.hu (Barath Aron) Date: Fri, 27 Jul 2018 19:13:37 +0200 Subject: Using Python on a fork-less POSIX-like OS Message-ID: <35468446-48de-b5d0-bbed-33e7af5f3128@caesar.elte.hu> Hello Python list, I intend to cross-compile Python v3.6.6 to Threos ( https://threos.io ) operating system. Threos is supports a quite large set from POSIX and C89/C99. Unfortunately, Threos lacks fork(2), but provides posix_spawn(3) instead. I already made some local changes in posixmodule.c to compile due to some features are detected as present but actually not supported, like HAVE_FORK -- I blame autotools for this :-). I don't know, however, whether the Python shall cross-compile without issues. My question is that the _posixsubprocess.c can be prepared to use posix_spawn(3) instead of fork(2)? Maybe the UNIX/Linux version can also benefit from it, see: https://salsa.debian.org/ruby-team/ruby-posix-spawn Best regards, Aron From breamoreboy at gmail.com Fri Jul 27 15:30:34 2018 From: breamoreboy at gmail.com (Mark Lawrence) Date: Fri, 27 Jul 2018 20:30:34 +0100 Subject: Guilty as charged In-Reply-To: <53e875aff2404dbaa3addcdc743ac453@Teledyne.com> References: <53e875aff2404dbaa3addcdc743ac453@Teledyne.com> Message-ID: On 27/07/18 17:23, Schachner, Joseph wrote: > Re: "...while > > thing == None > would work perfectly in almost all cases in practice, it's unidiomatic and suggests the writer isn't quite comfortable with the workings of the language" > > I admit, I've been a C++ programmer for many years and a Python programmer for only about 5 years. But, I did learn something here. I've read books on Python and somehow still did not know that None is guaranteed to be a singleton in all implementations, and that not only does "thing is None" therefore work (guaranteed), but that that is the Pythonic thing to do. ... Maybe I missed it, but I'll remember it now. > > --- Joseph S. > Your apology is accepted. Thank you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Sat Jul 28 06:07:27 2018 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 28 Jul 2018 10:07:27 +0000 (UTC) Subject: Checking whether type is None References: Message-ID: On Sat, 28 Jul 2018 09:47:07 +0000, Gilmeh Serda wrote: > On Tue, 24 Jul 2018 12:33:27 -0700, Tobiah wrote: > >> I'm trying to get away from things like: >> >> >>> type(thing) is type(None) > > How about: > > >>> some_thing = None > >>> type(some_thing).__str__(some_thing) > 'None' > > Equally weird, I'd say, but what the heck... class Foo: def __str__(self): return 'None' -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Sat Jul 28 06:20:17 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 28 Jul 2018 20:20:17 +1000 Subject: Checking whether type is None In-Reply-To: References: Message-ID: On Sat, Jul 28, 2018 at 8:07 PM, Steven D'Aprano wrote: > On Sat, 28 Jul 2018 09:47:07 +0000, Gilmeh Serda wrote: > >> On Tue, 24 Jul 2018 12:33:27 -0700, Tobiah wrote: >> >>> I'm trying to get away from things like: >>> >>> >>> type(thing) is type(None) >> >> How about: >> >> >>> some_thing = None >> >>> type(some_thing).__str__(some_thing) >> 'None' >> >> Equally weird, I'd say, but what the heck... > > class Foo: > def __str__(self): > return 'None' >>> object.__str__(some_thing) Problem solved. :) ChrisA From stefan_ml at behnel.de Sat Jul 28 15:53:57 2018 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 28 Jul 2018 20:53:57 +0100 Subject: Tracking a memory leak in C extension - interpreting the output of PYTHONMALLOCSTATS In-Reply-To: References: Message-ID: Bartosz Golaszewski schrieb am 24.07.2018 um 13:05: > Ok I've found the problem and it's my fault. From tp_dealloc's documentation: > > --- > The destructor function should free all references which the instance > owns, free all memory buffers owned by the instance (using the freeing > function corresponding to the allocation function used to allocate the > buffer), and finally (as its last action) call the type?s tp_free > function. > --- > > I'm not calling the tp_free function... If you want to avoid the little traps of the C-API in the future, give Cython a try. It can generate all the glue code safely for you, and probably also generates faster wrapper code than you would write yourself. Stefan From stefand986 at gmail.com Sat Jul 28 17:16:14 2018 From: stefand986 at gmail.com (stefand986 at gmail.com) Date: Sat, 28 Jul 2018 14:16:14 -0700 (PDT) Subject: `import somemodule` does not check all paths in `sys.path` Message-ID: Hi everyone, I am currently investigating an interesting bug in homeassistant which is a bit hard to reproduce. I already dug so deep that I ask here, because I think the root cause has to do with how Python locates and loads modules/packages. The "story" is: In homeassistant (short HA) some modules are installed at runtime during first start ("bootstrapping"), and for some reason loading the modules fails directly after installing the modules. Subsequent starts work fine. The modules that are installed during bootstrapping are installed to `~/.homeassistant/deps/lib/python3.7/site-packages`. Installing the modules happens in a different thread than where the modules are imported. (However as far as I can tell the importing thread waits for the install to finish.) Now the interesting thing is that when I start HA in verbose mode, I can see that Python is trying not all of the paths that are in `sys.path` (in the following snippet I cut out some stuff for brevity. Link to the full log at the end). As one can see the `~/.homeassistant/deps/lib/python3.7/site-packages` location is not tried and hence the import fails: ``` # trying /home/pyuser/.homeassistant/sqlalchemy.cpython-37m-x86_64-linux-gnu.so # trying /home/pyuser/.homeassistant/sqlalchemy.abi3.so # trying /home/pyuser/.homeassistant/sqlalchemy.so # trying /home/pyuser/.homeassistant/sqlalchemy.py # trying /home/pyuser/.homeassistant/sqlalchemy.pyc # trying /home/pyuser/sqlalchemy.cpython-37m-x86_64-linux-gnu.so [...] # trying /usr/local/lib/python3.7/sqlalchemy.cpython-37m-x86_64-linux-gnu.so [...] # trying /usr/local/lib/python3.7/lib-dynload/sqlalchemy.cpython-37m-x86_64-linux-gnu.so [...] # trying /home/pyuser/.local/lib/python3.7/site-packages/sqlalchemy.cpython-37m-x86_64-linux-gnu.so [...] # trying /usr/local/lib/python3.7/site-packages/sqlalchemy.cpython-37m-x86_64-linux-gnu.so [...] Exception in thread Recorder: Traceback (most recent call last): File "/usr/local/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/home/pyuser/.local/lib/python3.7/site-packages/homeassistant/components/recorder/__init__.py", line 187, in run from .models import States, Events File "", line 983, in _find_and_load File "", line 967, in _find_and_load_unlocked File "", line 677, in _load_unlocked File "", line 728, in exec_module File "", line 219, in _call_with_frames_removed File "/home/pyuser/.local/lib/python3.7/site-packages/homeassistant/components/recorder/models.py", line 8, in from sqlalchemy import ( File "", line 983, in _find_and_load File "", line 965, in _find_and_load_unlocked ModuleNotFoundError: No module named 'sqlalchemy' ``` I also checked that this path is also really in `sys.path` at the time the import happens. This is `sys.path` printed out directly before the `import sqlalchemy statement`: ``` ['/home/pyuser/.homeassistant', '/home/pyuser/.homeassistant/deps/lib/python3.7/site-packages', '/home/pyuser', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/home/pyuser/.local/lib/python3.7/site-packages', '/usr/local/lib/python3.7/site-packages'] ``` What I already tried is to do a importlib.invalidate_caches() after installing the modules. However this does not fix it. So what is happening here? Why does the import skip `~/.homeassistant/deps/lib/python3.7/site-packages`? Any tips on how I can investigate further? Link to the full log: https://gist.github.com/StefanD986/fbf08426ceaad657929b973cd5add25a#file-homeassistant_verbose_first_start-txt-L5787 From python at mrabarnett.plus.com Sat Jul 28 19:31:38 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 29 Jul 2018 00:31:38 +0100 Subject: `import somemodule` does not check all paths in `sys.path` In-Reply-To: References: Message-ID: On 2018-07-28 22:16, stefand986 at gmail.com wrote: > Hi everyone, > I am currently investigating an interesting bug in homeassistant which is a bit hard to reproduce. I already dug so deep that I ask here, because I think the root cause has to do with how Python locates and loads modules/packages. > > The "story" is: In homeassistant (short HA) some modules are installed at runtime during first start ("bootstrapping"), and for some reason loading the modules fails directly after installing the modules. Subsequent starts work fine. > > The modules that are installed during bootstrapping are installed to `~/.homeassistant/deps/lib/python3.7/site-packages`. Installing the modules happens in a different thread than where the modules are imported. (However as far as I can tell the importing thread waits for the install to finish.) > > Now the interesting thing is that when I start HA in verbose mode, I can see that Python is trying not all of the paths that are in `sys.path` (in the following snippet I cut out some stuff for brevity. Link to the full log at the end). As one can see the `~/.homeassistant/deps/lib/python3.7/site-packages` location is not tried and hence the import fails: > > ``` > # trying /home/pyuser/.homeassistant/sqlalchemy.cpython-37m-x86_64-linux-gnu.so > # trying /home/pyuser/.homeassistant/sqlalchemy.abi3.so > # trying /home/pyuser/.homeassistant/sqlalchemy.so > # trying /home/pyuser/.homeassistant/sqlalchemy.py > # trying /home/pyuser/.homeassistant/sqlalchemy.pyc > # trying /home/pyuser/sqlalchemy.cpython-37m-x86_64-linux-gnu.so > [...] > # trying /usr/local/lib/python3.7/sqlalchemy.cpython-37m-x86_64-linux-gnu.so > [...] > # trying /usr/local/lib/python3.7/lib-dynload/sqlalchemy.cpython-37m-x86_64-linux-gnu.so > [...] > # trying /home/pyuser/.local/lib/python3.7/site-packages/sqlalchemy.cpython-37m-x86_64-linux-gnu.so > [...] > # trying /usr/local/lib/python3.7/site-packages/sqlalchemy.cpython-37m-x86_64-linux-gnu.so > [...] > Exception in thread Recorder: > Traceback (most recent call last): > File "/usr/local/lib/python3.7/threading.py", line 917, in _bootstrap_inner > self.run() > File "/home/pyuser/.local/lib/python3.7/site-packages/homeassistant/components/recorder/__init__.py", line 187, in run > from .models import States, Events > File "", line 983, in _find_and_load > File "", line 967, in _find_and_load_unlocked > File "", line 677, in _load_unlocked > File "", line 728, in exec_module > File "", line 219, in _call_with_frames_removed > File "/home/pyuser/.local/lib/python3.7/site-packages/homeassistant/components/recorder/models.py", line 8, in > from sqlalchemy import ( > File "", line 983, in _find_and_load > File "", line 965, in _find_and_load_unlocked > ModuleNotFoundError: No module named 'sqlalchemy' > ``` > > I also checked that this path is also really in `sys.path` at the time the import happens. This is `sys.path` printed out directly before the `import sqlalchemy statement`: > > ``` > ['/home/pyuser/.homeassistant', > '/home/pyuser/.homeassistant/deps/lib/python3.7/site-packages', > '/home/pyuser', > '/usr/local/lib/python37.zip', > '/usr/local/lib/python3.7', > '/usr/local/lib/python3.7/lib-dynload', > '/home/pyuser/.local/lib/python3.7/site-packages', > '/usr/local/lib/python3.7/site-packages'] > ``` > > > What I already tried is to do a importlib.invalidate_caches() after installing the modules. However this does not fix it. > > So what is happening here? Why does the import skip `~/.homeassistant/deps/lib/python3.7/site-packages`? Any tips on how I can investigate further? > > Link to the full log: https://gist.github.com/StefanD986/fbf08426ceaad657929b973cd5add25a#file-homeassistant_verbose_first_start-txt-L5787 > The log contains entries that say "Please check your config". To me it looks like it hasn't been installed. Does the path /home/pyuser/.homeassistant/deps/lib/python3.7/site-packages actually exist? From leo at superlel.me Sun Jul 29 06:03:06 2018 From: leo at superlel.me (=?UTF-8?Q?L=c3=a9o_El_Amri?=) Date: Sun, 29 Jul 2018 12:03:06 +0200 Subject: Why is multiprocessing.Queue creating a thread ? Message-ID: <3fa26c2b-9cff-4bc7-60a5-7318d1d50dbc@superlel.me> Hello list, This is a simple question: I wonder what is the reason behind multiprocessing.Queue creating a thread to send objects through a multiprocessing.connection.Connection. I plan to implement an asyncio "aware" Connection class. And while reading the source code of the multiprocessing module, I found that (As outlined in the documentation) Queue is indeed creating a thread. I want to know if I'm missing something. -- Leo From stefand986 at gmail.com Sun Jul 29 06:22:35 2018 From: stefand986 at gmail.com (stefand986 at gmail.com) Date: Sun, 29 Jul 2018 03:22:35 -0700 (PDT) Subject: `import somemodule` does not check all paths in `sys.path` In-Reply-To: References: Message-ID: <9db3ee51-30e7-4ec4-905d-de577503f844@googlegroups.com> Am Sonntag, 29. Juli 2018 01:32:07 UTC+2 schrieb MRAB: That was also my first suspicion, but I checked that the path exists by printing the directory contents out, right before the ?mport ` statement. The "please check your config" message are a result of another package (aiohttp_cors) that is also dynamically installed and then not found when it is imported. > The log contains entries that say "Please check your config". To me it > looks like it hasn't been installed. > > Does the path > /home/pyuser/.homeassistant/deps/lib/python3.7/site-packages actually exist? From rosuav at gmail.com Sun Jul 29 08:21:01 2018 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 29 Jul 2018 22:21:01 +1000 Subject: Why is multiprocessing.Queue creating a thread ? In-Reply-To: <3fa26c2b-9cff-4bc7-60a5-7318d1d50dbc@superlel.me> References: <3fa26c2b-9cff-4bc7-60a5-7318d1d50dbc@superlel.me> Message-ID: On Sun, Jul 29, 2018 at 8:03 PM, L?o El Amri via Python-list wrote: > Hello list, > > This is a simple question: I wonder what is the reason behind > multiprocessing.Queue creating a thread to send objects through a > multiprocessing.connection.Connection. > I plan to implement an asyncio "aware" Connection class. And while > reading the source code of the multiprocessing module, I found that (As > outlined in the documentation) Queue is indeed creating a thread. I want > to know if I'm missing something. I'm not certain, but I suspect it's the simplest way to create a non-blocking feeder. If you want to subclass it and replace that with something that uses your event loop, go ahead; it might end up becoming an additional subclass in the stdlib, alongside SimpleQueue and JoinableQueue. ChrisA From lists at janc.be Sun Jul 29 10:28:16 2018 From: lists at janc.be (Jan Claeys) Date: Sun, 29 Jul 2018 16:28:16 +0200 Subject: Using Python on a fork-less POSIX-like OS In-Reply-To: <35468446-48de-b5d0-bbed-33e7af5f3128@caesar.elte.hu> References: <35468446-48de-b5d0-bbed-33e7af5f3128@caesar.elte.hu> Message-ID: <055f451ff315960c7c4d1b52e2fb693f585a0403.camel@janc.be> On Fri, 2018-07-27 at 19:13 +0200, Barath Aron wrote: > I intend to cross-compile Python v3.6.6 to Threos ( https://threos.io > ) operating system. Threos is supports a quite large set from > POSIX and C89/C99. Unfortunately, Threos lacks fork(2), but > provides posix_spawn(3) instead. I already made some local changes > in posixmodule.c to compile due to some features are detected > as present but actually not supported, like HAVE_FORK -- I blame > autotools for this :-). I don't know, however, whether the Python > shall cross-compile without issues. > > My question is that the _posixsubprocess.c can be prepared to > use posix_spawn(3) instead of fork(2)? Maybe the UNIX/Linux version > can also benefit from it, see: https://salsa.debian.org/ruby- > team/ruby-posix-spawn You might want to ask this on the python-dev mailing list. -- Jan Claeys From albert at brasco.at Sun Jul 29 12:22:51 2018 From: albert at brasco.at (Albert Brandl) Date: Sun, 29 Jul 2018 18:22:51 +0200 Subject: Demo-Mode in IPython broken? Message-ID: Hi! The IPython documentation mentions a demo mode that can be used to execute chunks of a Python file that are separated by special comments (e.g. "# stop"). The annotated Python file can be executed by importing `Demo` from `IPython.lib.demo`, instantiating it using the file name and calling the `Demo` instance: from IPython.lib.demo import Demo d = Demo("some_file.py") d() According to the documentation, all names that are defined in such a chunk are transferred to the global IPython namespace. This would allow me to interactively inspect the names etc. It looks like this feature does not work in the version 6.4.0 of IPython: the global namespace does not change after executing any chunk of a Python file. The Demo instance has a dictionary called `user_ns` that _is_ updated when a chunk is executed, but using it to access the names is quite clumsy ;-). Is this a known bug? Do you have a suggestion how I could emulate the behavior of the demo mode by other means (not necessarily with IPython)? TIA and best regards, Albert From stanimira.s.93 at gmail.com Sun Jul 29 13:56:22 2018 From: stanimira.s.93 at gmail.com (stanimira.s.93 at gmail.com) Date: Sun, 29 Jul 2018 10:56:22 -0700 (PDT) Subject: Python bug in ArcGIS - Urban Network analysis tool Message-ID: <2867cd51-25a2-4d6a-8bba-51b35e929ab3@googlegroups.com> Hi there, I'm trying make reach analyze with Urban network analysis (UNA) tool in ArcGIS. It's based on points for buildings and pedestrian network of acceptability steets. The aim is to show how many people from each building can reach different building in radius of 150 meters (so i can find the density of the pedestrian routes). I run Urban network analysis but It shows similar mistake several times. The UNA tool is free plugin that i downloaded, it's not from the default intalled in ArcGIS packed. It ask for integer data. I checked the type of the attributes, it's all integer. PLus it's all in geo data based file. Unfortunately I don't understand Python, I'm one of those who use ArcGIS as sample customer. This is the mistake: Start Time: Fri Jul 27 14:48:32 2018 Running script Centrality... [started] Copying input buildings [finished] [1 started] Computing adjacency list [1 failed] Not successful Completed script Centrality... Succeeded at Fri Jul 27 14:48:36 2018 (Elapsed Time: 4,56 seconds) Any suggestions? How it's calling these adjaency list? What could be wrong? I even don't know how to get debugger, so it could give me more information. Thank you previously, Mira From python at mrabarnett.plus.com Sun Jul 29 16:37:37 2018 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 29 Jul 2018 21:37:37 +0100 Subject: Python bug in ArcGIS - Urban Network analysis tool In-Reply-To: <2867cd51-25a2-4d6a-8bba-51b35e929ab3@googlegroups.com> References: <2867cd51-25a2-4d6a-8bba-51b35e929ab3@googlegroups.com> Message-ID: On 2018-07-29 18:56, stanimira.s.93 at gmail.com wrote: > Hi there, > > I'm trying make reach analyze with Urban network analysis (UNA) tool in ArcGIS. It's based on points for buildings and pedestrian network of acceptability steets. The aim is to show how many people from each building can reach different building in radius of 150 meters (so i can find the density of the pedestrian routes). > > I run Urban network analysis but It shows similar mistake several times. The UNA tool is free plugin that i downloaded, it's not from the default intalled in ArcGIS packed. It ask for integer data. > I checked the type of the attributes, it's all integer. PLus it's all in geo data based file. > > Unfortunately I don't understand Python, I'm one of those who use ArcGIS as sample customer. > > This is the mistake: > > Start Time: Fri Jul 27 14:48:32 2018 > Running script Centrality... > [started] Copying input buildings > [finished] > [1 started] Computing adjacency list > [1 failed] > Not successful > Completed script Centrality... > Succeeded at Fri Jul 27 14:48:36 2018 (Elapsed Time: 4,56 seconds) > > Any suggestions? How it's calling these adjaency list? What could be wrong? I even don't know how to get debugger, so it could give me more information. > > Thank you previously, > Mira > All you've shown is that says that it was unsuccessful, and it doesn't say why. We'd need a lot more info than that! The best way to debug it is to try it with the minimal amount of test data that should give a result. From stanimira.s.93 at gmail.com Sun Jul 29 17:00:58 2018 From: stanimira.s.93 at gmail.com (=?UTF-8?B?0KHRgtCw0L3QuNC80LjRgNCwINCd0LjQutC+0LvQvtCy0LA=?=) Date: Sun, 29 Jul 2018 14:00:58 -0700 (PDT) Subject: Python bug in ArcGIS - Urban Network analysis tool In-Reply-To: References: <2867cd51-25a2-4d6a-8bba-51b35e929ab3@googlegroups.com> Message-ID: ??????, 29 ??? 2018 ?., 23:41:01 UTC+3, MRAB ??????: > On 2018-07-29 18:56, stanimira.s.93 at gmail.com wrote: > > Hi there, > > > > I'm trying make reach analyze with Urban network analysis (UNA) tool in ArcGIS. It's based on points for buildings and pedestrian network of acceptability steets. The aim is to show how many people from each building can reach different building in radius of 150 meters (so i can find the density of the pedestrian routes). > > > > I run Urban network analysis but It shows similar mistake several times. The UNA tool is free plugin that i downloaded, it's not from the default intalled in ArcGIS packed. It ask for integer data. > > I checked the type of the attributes, it's all integer. PLus it's all in geo data based file. > > > > Unfortunately I don't understand Python, I'm one of those who use ArcGIS as sample customer. > > > > This is the mistake: > > > > Start Time: Fri Jul 27 14:48:32 2018 > > Running script Centrality... > > [started] Copying input buildings > > [finished] > > [1 started] Computing adjacency list > > [1 failed] > > Not successful > > Completed script Centrality... > > Succeeded at Fri Jul 27 14:48:36 2018 (Elapsed Time: 4,56 seconds) > > > > Any suggestions? How it's calling these adjaency list? What could be wrong? I even don't know how to get debugger, so it could give me more information. > > > > Thank you previously, > > Mira > > > All you've shown is that says that it was unsuccessful, and it doesn't > say why. > > We'd need a lot more info than that! > > The best way to debug it is to try it with the minimal amount of test > data that should give a result. I'm sorry. Could someone help me by telling me how to make these test data? (so i could send it to You) I realize the review of the bug is just the customer view. Any chance to help me out with the test of the process? Thank you previously. If there is another forum that i have to write to, i will switch. The fact is that in the Themes for UNA tool or GIS software, almost no one respond. From tjreedy at udel.edu Sun Jul 29 17:55:02 2018 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 29 Jul 2018 17:55:02 -0400 Subject: Using Python on a fork-less POSIX-like OS In-Reply-To: <055f451ff315960c7c4d1b52e2fb693f585a0403.camel@janc.be> References: <35468446-48de-b5d0-bbed-33e7af5f3128@caesar.elte.hu> <055f451ff315960c7c4d1b52e2fb693f585a0403.camel@janc.be> Message-ID: On 7/29/2018 10:28 AM, Jan Claeys wrote: > On Fri, 2018-07-27 at 19:13 +0200, Barath Aron wrote: >> I intend to cross-compile Python v3.6.6 to Threos ( https://threos.io >> ) operating system. Threos is supports a quite large set from >> POSIX and C89/C99. Unfortunately, Threos lacks fork(2), but >> provides posix_spawn(3) instead. I already made some local changes >> in posixmodule.c to compile due to some features are detected >> as present but actually not supported, like HAVE_FORK -- I blame >> autotools for this :-). Then perhaps Threos should be patched to describe itself more accurately or autotools patched to detect more accurately. >> I don't know, however, whether the Python >> shall cross-compile without issues. We generally prefer that it does, but no longer try to officially support (with conditionals in the codebase) every odd-ball OS. You or some Threos group may have to keep a separate patch set, to be update for each Python version. If there is any such thing now, Google does not find it. >> My question is that the _posixsubprocess.c can be prepared to >> use posix_spawn(3) instead of fork(2)? What does the doc for _posixubprocess so it does? If it says 'create a subprocess by forking', then perhaps not. >> Maybe the UNIX/Linux version >> can also benefit from it, see: https://salsa.debian.org/ruby- >> team/ruby-posix-spawn > > You might want to ask this on the python-dev mailing list. multiprocessing module uses 'spawn' rather than 'fork' on Windows and it has an option to use 'spawn' even on *nix. I presume the latter refers to posix_spawn. You might want to check the multiprocessing code to see what *it* is doing 'under the covers'. -- Terry Jan Reedy From python at mrabarnett.plus.com Sun Jul 29 20:29:22 2018 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 30 Jul 2018 01:29:22 +0100 Subject: Python bug in ArcGIS - Urban Network analysis tool In-Reply-To: References: <2867cd51-25a2-4d6a-8bba-51b35e929ab3@googlegroups.com> Message-ID: <5eaa74dd-0f0c-2cf8-325a-014a6911e9cf@mrabarnett.plus.com> On 2018-07-29 22:00, ????????? ???????? wrote: > ??????, 29 ??? 2018 ?., 23:41:01 UTC+3, MRAB ??????: >> On 2018-07-29 18:56, stanimira.s.93 at gmail.com wrote: >> > Hi there, >> > >> > I'm trying make reach analyze with Urban network analysis (UNA) tool in ArcGIS. It's based on points for buildings and pedestrian network of acceptability steets. The aim is to show how many people from each building can reach different building in radius of 150 meters (so i can find the density of the pedestrian routes). >> > >> > I run Urban network analysis but It shows similar mistake several times. The UNA tool is free plugin that i downloaded, it's not from the default intalled in ArcGIS packed. It ask for integer data. >> > I checked the type of the attributes, it's all integer. PLus it's all in geo data based file. >> > >> > Unfortunately I don't understand Python, I'm one of those who use ArcGIS as sample customer. >> > >> > This is the mistake: >> > >> > Start Time: Fri Jul 27 14:48:32 2018 >> > Running script Centrality... >> > [started] Copying input buildings >> > [finished] >> > [1 started] Computing adjacency list >> > [1 failed] >> > Not successful >> > Completed script Centrality... >> > Succeeded at Fri Jul 27 14:48:36 2018 (Elapsed Time: 4,56 seconds) >> > >> > Any suggestions? How it's calling these adjaency list? What could be wrong? I even don't know how to get debugger, so it could give me more information. >> > >> > Thank you previously, >> > Mira >> > >> All you've shown is that says that it was unsuccessful, and it doesn't >> say why. >> >> We'd need a lot more info than that! >> >> The best way to debug it is to try it with the minimal amount of test >> data that should give a result. > > I'm sorry. > Could someone help me by telling me how to make these test data? (so i could send it to You) > > I realize the review of the bug is just the customer view. Any chance to help me out with the test of the process? > > Thank you previously. If there is another forum that i have to write to, i will switch. The fact is that in the Themes for UNA tool or GIS software, almost no one respond. > I'm unfamiliar with ArcGIS, so I doubt I could help. It might have generated a log file somewhere that gives more details. From dieter at handshake.de Mon Jul 30 01:15:41 2018 From: dieter at handshake.de (dieter) Date: Mon, 30 Jul 2018 07:15:41 +0200 Subject: `import somemodule` does not check all paths in `sys.path` References: Message-ID: <87o9epe22q.fsf@handshake.de> stefand986 at gmail.com writes: > ... > The "story" is: In homeassistant (short HA) some modules are installed at runtime during first start ("bootstrapping"), and for some reason loading the modules fails directly after installing the modules. Subsequent starts work fine. > > The modules that are installed during bootstrapping are installed to `~/.homeassistant/deps/lib/python3.7/site-packages`. Installing the modules happens in a different thread than where the modules are imported. (However as far as I can tell the importing thread waits for the install to finish.) > > Now the interesting thing is that when I start HA in verbose mode, I can see that Python is trying not all of the paths that are in `sys.path` (in the following snippet I cut out some stuff for brevity. Link to the full log at the end). As one can see the `~/.homeassistant/deps/lib/python3.7/site-packages` location is not tried and hence the import fails: When I remember right: * Python silently ignores non existent directories in "sys.path" * "~" is not automatically expanded into the home directory. This would suggest, remplace "~/.homeassistent/..." by "/home/pyuser/.homeassistent/..." and try again. From rosuav at gmail.com Mon Jul 30 01:23:28 2018 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 30 Jul 2018 15:23:28 +1000 Subject: `import somemodule` does not check all paths in `sys.path` In-Reply-To: <87o9epe22q.fsf@handshake.de> References: <87o9epe22q.fsf@handshake.de> Message-ID: On Mon, Jul 30, 2018 at 3:15 PM, dieter wrote: > stefand986 at gmail.com writes: >> ... >> The "story" is: In homeassistant (short HA) some modules are installed at runtime during first start ("bootstrapping"), and for some reason loading the modules fails directly after installing the modules. Subsequent starts work fine. >> >> The modules that are installed during bootstrapping are installed to `~/.homeassistant/deps/lib/python3.7/site-packages`. Installing the modules happens in a different thread than where the modules are imported. (However as far as I can tell the importing thread waits for the install to finish.) >> >> Now the interesting thing is that when I start HA in verbose mode, I can see that Python is trying not all of the paths that are in `sys.path` (in the following snippet I cut out some stuff for brevity. Link to the full log at the end). As one can see the `~/.homeassistant/deps/lib/python3.7/site-packages` location is not tried and hence the import fails: > > When I remember right: > > * "~" is not automatically expanded into the home directory. Yes, this would be correct. The expansion of ~ into your home directory is actually a shell feature. You can use os.path.expanduser to do the transformation manually, but it won't happen automatically. Good catch. ChrisA From stanimira.s.93 at gmail.com Mon Jul 30 02:02:45 2018 From: stanimira.s.93 at gmail.com (=?UTF-8?B?0KHRgtCw0L3QuNC80LjRgNCwINCd0LjQutC+0LvQvtCy0LA=?=) Date: Sun, 29 Jul 2018 23:02:45 -0700 (PDT) Subject: Python bug in ArcGIS - Urban Network analysis tool In-Reply-To: References: <2867cd51-25a2-4d6a-8bba-51b35e929ab3@googlegroups.com> <5eaa74dd-0f0c-2cf8-325a-014a6911e9cf@mrabarnett.plus.com> Message-ID: ??????????, 30 ??? 2018 ?., 3:29:44 UTC+3, MRAB ??????: > On 2018-07-29 22:00, ????????? ???????? wrote: > > ??????, 29 ??? 2018 ?., 23:41:01 UTC+3, MRAB ??????: > >> On 2018-07-29 18:56, stanimira.s.93 at gmail.com wrote: > >> > Hi there, > >> > > >> > I'm trying make reach analyze with Urban network analysis (UNA) tool in ArcGIS. It's based on points for buildings and pedestrian network of acceptability steets. The aim is to show how many people from each building can reach different building in radius of 150 meters (so i can find the density of the pedestrian routes). > >> > > >> > I run Urban network analysis but It shows similar mistake several times. The UNA tool is free plugin that i downloaded, it's not from the default intalled in ArcGIS packed. It ask for integer data. > >> > I checked the type of the attributes, it's all integer. PLus it's all in geo data based file. > >> > > >> > Unfortunately I don't understand Python, I'm one of those who use ArcGIS as sample customer. > >> > > >> > This is the mistake: > >> > > >> > Start Time: Fri Jul 27 14:48:32 2018 > >> > Running script Centrality... > >> > [started] Copying input buildings > >> > [finished] > >> > [1 started] Computing adjacency list > >> > [1 failed] > >> > Not successful > >> > Completed script Centrality... > >> > Succeeded at Fri Jul 27 14:48:36 2018 (Elapsed Time: 4,56 seconds) > >> > > >> > Any suggestions? How it's calling these adjaency list? What could be wrong? I even don't know how to get debugger, so it could give me more information. > >> > > >> > Thank you previously, > >> > Mira > >> > > >> All you've shown is that says that it was unsuccessful, and it doesn't > >> say why. > >> > >> We'd need a lot more info than that! > >> > >> The best way to debug it is to try it with the minimal amount of test > >> data that should give a result. > > > > I'm sorry. > > Could someone help me by telling me how to make these test data? (so i could send it to You) > > > > I realize the review of the bug is just the customer view. Any chance to help me out with the test of the process? > > > > Thank you previously. If there is another forum that i have to write to, i will switch. The fact is that in the Themes for UNA tool or GIS software, almost no one respond. > > > I'm unfamiliar with ArcGIS, so I doubt I could help. > > It might have generated a log file somewhere that gives more details. Ok, thank you for the patiance. I installed PyCharm for trying make some tests. I add in a project the .py file for the adjacency list. That's the main from the debuger: pydev debugger: process 8904 is connecting Connected to pydev debugger (build 182.3684.100) Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\pydevd.py", line 1664, in main() File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\pydevd.py", line 1658, in main globals = debugger.run(setup['file'], None, None, is_module) File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\pydevd.py", line 1068, in run pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:/INSTALL/Urban Network Analysis Toolbox 1.01/src/Centrality/Adjacency_List_Computation.py", line 14, in from arcpy import AddField_management ModuleNotFoundError: No module named 'arcpy' May I found the following lines from the code? From stefand986 at gmail.com Mon Jul 30 03:18:49 2018 From: stefand986 at gmail.com (stefand986 at gmail.com) Date: Mon, 30 Jul 2018 00:18:49 -0700 (PDT) Subject: `import somemodule` does not check all paths in `sys.path` In-Reply-To: References: <87o9epe22q.fsf@handshake.de> Message-ID: Note that in the `sys.path`variable the path is given as absolute path (I only wrote it relative to `~` in the in my post, but in the script the absolute path is used everywhere). See line 2: ``` ['/home/pyuser/.homeassistant', '/home/pyuser/.homeassistant/deps/lib/python3.7/site-packages', '/home/pyuser', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/home/pyuser/.local/lib/python3.7/site-packages', '/usr/local/lib/python3.7/site-packages'] ``` Also by the time the import happens, the directory is existing. It is not existing from the beginning, but I also tried calling `importlib.invalidate_caches()` after installing the packages, which should force python to check the directories again. Another interesting thing that I found out is that if I use the (now deprecated) `imp.find_module('sqlalchemy')` it returns the correct path. However if I do the same with `importlib.util.find_spec('sqlalchemy')` the package is not found! (`importlib` is the suggested replacement for `imp`). To me it really looks like a bug in `importlib`. Am Montag, 30. Juli 2018 07:16:01 UTC+2 schrieb dieter: > When I remember right: > > * Python silently ignores non existent directories in "sys.path" > * "~" is not automatically expanded into the home directory. > > This would suggest, remplace "~/.homeassistent/..." by > "/home/pyuser/.homeassistent/..." and try again. From andymac at bullseye.apana.org.au Mon Jul 30 08:10:14 2018 From: andymac at bullseye.apana.org.au (Andrew MacIntyre) Date: Mon, 30 Jul 2018 22:10:14 +1000 Subject: Python bug in ArcGIS - Urban Network analysis tool In-Reply-To: References: <2867cd51-25a2-4d6a-8bba-51b35e929ab3@googlegroups.com> <5eaa74dd-0f0c-2cf8-325a-014a6911e9cf@mrabarnett.plus.com> Message-ID: <378f1ec6-e42d-0159-1cf2-7ec14e0d28e3@pcug.org.au> On 30/07/2018 4:02 PM, ????????? ???????? wrote: >>>>> I run Urban network analysis but It shows similar mistake several times. The UNA tool is free plugin that i downloaded, it's not from the default intalled in ArcGIS packed. It ask for integer data. >>>>> I checked the type of the attributes, it's all integer. PLus it's all in geo data based file. >>>>> >>>>> Unfortunately I don't understand Python, I'm one of those who use ArcGIS as sample customer. >>>>> >>>>> This is the mistake: >>>>> >>>>> Start Time: Fri Jul 27 14:48:32 2018 >>>>> Running script Centrality... >>>>> [started] Copying input buildings >>>>> [finished] >>>>> [1 started] Computing adjacency list >>>>> [1 failed] >>>>> Not successful >>>>> Completed script Centrality... >>>>> Succeeded at Fri Jul 27 14:48:36 2018 (Elapsed Time: 4,56 seconds) >>>>> >>>>> Any suggestions? How it's calling these adjaency list? What could be wrong? I even don't know how to get debugger, so it could give me more information. If it's a third party plugin, contact the author or source. This mailing list sees very little traffic about ArcGIS usage as it is a highly specialised commercial product. > I add in a project the .py file for the adjacency list. > > That's the main from the debuger: > > pydev debugger: process 8904 is connecting > > Connected to pydev debugger (build 182.3684.100) > Traceback (most recent call last): > File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\pydevd.py", line 1664, in > main() > File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\pydevd.py", line 1658, in main > globals = debugger.run(setup['file'], None, None, is_module) > File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\pydevd.py", line 1068, in run > pydev_imports.execfile(file, globals, locals) # execute the script > File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile > exec(compile(contents+"\n", file, 'exec'), glob, loc) > File "D:/INSTALL/Urban Network Analysis Toolbox 1.01/src/Centrality/Adjacency_List_Computation.py", line 14, in > from arcpy import AddField_management > ModuleNotFoundError: No module named 'arcpy' > > May I found the following lines from the code? Is it documented that the file you've attempted to run via PyCharm actually supports being run from outside ArcGIS? Most plugins don't seem to be... This failure is because PyCharm isn't starting the script with the necessary environment (including the arcpy ArcGIS Python module) accessible. The fact that it starts running from within ArcGIS and produces some status messages before bailing out with the failure message strongly suggests to me that the plugin is working properly but the input given is not sufficient to produce the expected output. In the absence of sufficient documentation for you to figure out the required input, my advice above stands: contact the author or the download source. If you or your organisation has a current ArcGIS maintenance agreement, you might also be able to access the community forums that ESRI run to ask for more info about this plugin. -- ------------------------------------------------------------------------- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac at pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia From skip.montanaro at gmail.com Mon Jul 30 09:58:08 2018 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 30 Jul 2018 08:58:08 -0500 Subject: Why did logging not undergo PEP8 API change? Message-ID: In the run-up to Python 3, the threading module's API went from a Java-reminiscent set of names to a PEP-9 set of names, so threading.currentThread became threading.current_thread. Also (though they didn't get a change in case), some of the set/get methods in threading.Thread received the property treatment with admonition in the module documentation to use the property style. Why wasn't the logging package similarly updated? I imagine there might have been some python-dev discussion about this, but have yet to find anything. I found this thread here from 2009: https://mail.python.org/pipermail/python-list/2009-April/thread.html#533823 There was some discussion of the idea (before the thread predictably wandered off into the weeds). I've not found anything else obviously related to the topic. Perhaps it was nothing more than that the threading module had a PEP-8 champion while logging didn't? Skip From David.Raymond at tomtom.com Mon Jul 30 11:12:52 2018 From: David.Raymond at tomtom.com (David Raymond) Date: Mon, 30 Jul 2018 15:12:52 +0000 Subject: Python bug in ArcGIS - Urban Network analysis tool In-Reply-To: References: <2867cd51-25a2-4d6a-8bba-51b35e929ab3@googlegroups.com> <5eaa74dd-0f0c-2cf8-325a-014a6911e9cf@mrabarnett.plus.com> Message-ID: A note that Arc may have installed its own version of Python, which it is using from within its own tools. For example, I've got a full Python installation in C:\Python27\ArcGIS10.2 which Arc installed on top of a preexisting installation in C:\Python27. So you may need to explicitly run it with that version to get it to work and to import arcpy ok. ie instead of just running... pydevd.py or... python pydevd.py You might need to explicitly do... C:\Python27\ArcGIS10.2\python.exe pydevd.py ...or the equivalent of wherever it installed it on your system. -----Original Message----- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom.com at python.org] On Behalf Of ????????? ???????? Sent: Monday, July 30, 2018 2:03 AM To: python-list at python.org Subject: Re: Python bug in ArcGIS - Urban Network analysis tool ??????????, 30 ??? 2018 ?., 3:29:44 UTC+3, MRAB ??????: > On 2018-07-29 22:00, ????????? ???????? wrote: > > ??????, 29 ??? 2018 ?., 23:41:01 UTC+3, MRAB ??????: > >> On 2018-07-29 18:56, stanimira.s.93 at gmail.com wrote: > >> > Hi there, > >> > > >> > I'm trying make reach analyze with Urban network analysis (UNA) tool in ArcGIS. It's based on points for buildings and pedestrian network of acceptability steets. The aim is to show how many people from each building can reach different building in radius of 150 meters (so i can find the density of the pedestrian routes). > >> > > >> > I run Urban network analysis but It shows similar mistake several times. The UNA tool is free plugin that i downloaded, it's not from the default intalled in ArcGIS packed. It ask for integer data. > >> > I checked the type of the attributes, it's all integer. PLus it's all in geo data based file. > >> > > >> > Unfortunately I don't understand Python, I'm one of those who use ArcGIS as sample customer. > >> > > >> > This is the mistake: > >> > > >> > Start Time: Fri Jul 27 14:48:32 2018 > >> > Running script Centrality... > >> > [started] Copying input buildings > >> > [finished] > >> > [1 started] Computing adjacency list > >> > [1 failed] > >> > Not successful > >> > Completed script Centrality... > >> > Succeeded at Fri Jul 27 14:48:36 2018 (Elapsed Time: 4,56 seconds) > >> > > >> > Any suggestions? How it's calling these adjaency list? What could be wrong? I even don't know how to get debugger, so it could give me more information. > >> > > >> > Thank you previously, > >> > Mira > >> > > >> All you've shown is that says that it was unsuccessful, and it doesn't > >> say why. > >> > >> We'd need a lot more info than that! > >> > >> The best way to debug it is to try it with the minimal amount of test > >> data that should give a result. > > > > I'm sorry. > > Could someone help me by telling me how to make these test data? (so i could send it to You) > > > > I realize the review of the bug is just the customer view. Any chance to help me out with the test of the process? > > > > Thank you previously. If there is another forum that i have to write to, i will switch. The fact is that in the Themes for UNA tool or GIS software, almost no one respond. > > > I'm unfamiliar with ArcGIS, so I doubt I could help. > > It might have generated a log file somewhere that gives more details. Ok, thank you for the patiance. I installed PyCharm for trying make some tests. I add in a project the .py file for the adjacency list. That's the main from the debuger: pydev debugger: process 8904 is connecting Connected to pydev debugger (build 182.3684.100) Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\pydevd.py", line 1664, in main() File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\pydevd.py", line 1658, in main globals = debugger.run(setup['file'], None, None, is_module) File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\pydevd.py", line 1068, in run pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:/INSTALL/Urban Network Analysis Toolbox 1.01/src/Centrality/Adjacency_List_Computation.py", line 14, in from arcpy import AddField_management ModuleNotFoundError: No module named 'arcpy' May I found the following lines from the code? -- https://mail.python.org/mailman/listinfo/python-list From cl at isbd.net Mon Jul 30 11:45:16 2018 From: cl at isbd.net (Chris Green) Date: Mon, 30 Jul 2018 16:45:16 +0100 Subject: How to decide (and know) which Python GTK version to use? Message-ID: I want to decide which is the 'best' Python GTK to use on my Linux (xubuntu) systems. There seem to be quite a few versions of Python GTK bindings out there and I'm confused! I wrote a Python GUI program a little while ago that uses Python GTK with:- import gtk I *think* this is probably GTK 2, or something. I can't find the proper documentation for this. Is it old/obsolescent? I'm just starting to write another program now and I seem to be using GTK 3 (maybe!) by doing:- import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk Is this the right/best place to be? I know this is a bit of a "how long is a piece of string" question but some guidance would be very welcome. The stuff I write is purely for my own use and will only ever run on Linux (mostly xubuntu but also some other Debian derived systems such as Rasbian and Debian on Beaglebone). -- Chris Green ? From cl at isbd.net Mon Jul 30 12:38:28 2018 From: cl at isbd.net (Chris Green) Date: Mon, 30 Jul 2018 17:38:28 +0100 Subject: How to decide (and know) which Python GTK version to use? References: Message-ID: <4hr33f-s8c.ln1@esprimo.zbmc.eu> Chris Green wrote: > I want to decide which is the 'best' Python GTK to use on my Linux > (xubuntu) systems. There seem to be quite a few versions of Python > GTK bindings out there and I'm confused! > > I wrote a Python GUI program a little while ago that uses Python GTK > with:- > > import gtk > > I *think* this is probably GTK 2, or something. I can't find the > proper documentation for this. Is it old/obsolescent? > > > I'm just starting to write another program now and I seem to be using > GTK 3 (maybe!) by doing:- > > import gi > gi.require_version('Gtk', '3.0') > from gi.repository import Gtk > > Is this the right/best place to be? > > > I know this is a bit of a "how long is a piece of string" question but > some guidance would be very welcome. The stuff I write is purely for > my own use and will only ever run on Linux (mostly xubuntu but also > some other Debian derived systems such as Rasbian and Debian on > Beaglebone). > Further to the above the following page:- https://docs.python.org/3/library/othergui.html Seems to muddy the water even further as the links don't *seem* to take one to the places one would expect them to go to. The PyGObject link goes to https://wiki.gnome.org/Projects/PyGObject and the PyGtk link goes to https://pygobject.readthedocs.io/en/latest/ which would also appear to be pygobject. -- Chris Green ? From akkana at shallowsky.com Mon Jul 30 13:04:58 2018 From: akkana at shallowsky.com (Akkana Peck) Date: Mon, 30 Jul 2018 11:04:58 -0600 Subject: How to decide (and know) which Python GTK version to use? In-Reply-To: References: Message-ID: <20180730170458.GB1091@shallowsky.com> Chris Green writes: > I wrote a Python GUI program a little while ago that uses Python GTK > with:- > > import gtk > > I *think* this is probably GTK 2, or something. I can't find the > proper documentation for this. Is it old/obsolescent? Yes, it's obsolete, and AFAIK it only works with Python 2, making it even more obsolete; but the documentation is at https://developer.gnome.org/pygtk/stable/ > I'm just starting to write another program now and I seem to be using > GTK 3 (maybe!) by doing:- > > import gi > gi.require_version('Gtk', '3.0') > from gi.repository import Gtk > > Is this the right/best place to be? Yes, this is the future, since it lets you use both GTK3 and Python3. ...Akkana From cl at isbd.net Mon Jul 30 13:31:56 2018 From: cl at isbd.net (Chris Green) Date: Mon, 30 Jul 2018 18:31:56 +0100 Subject: How to decide (and know) which Python GTK version to use? References: <20180730170458.GB1091@shallowsky.com> Message-ID: Akkana Peck wrote: > Chris Green writes: > > I wrote a Python GUI program a little while ago that uses Python GTK > > with:- > > > > import gtk > > > > I *think* this is probably GTK 2, or something. I can't find the > > proper documentation for this. Is it old/obsolescent? > > Yes, it's obsolete, and AFAIK it only works with Python 2, making > it even more obsolete; but the documentation is at > https://developer.gnome.org/pygtk/stable/ > > > I'm just starting to write another program now and I seem to be using > > GTK 3 (maybe!) by doing:- > > > > import gi > > gi.require_version('Gtk', '3.0') > > from gi.repository import Gtk > > > > Is this the right/best place to be? > > Yes, this is the future, since it lets you use both GTK3 and Python3. > OK, thanks, where is its home and full API documentation etc.? -- Chris Green ? From amirouche.boubekki at gmail.com Mon Jul 30 14:33:07 2018 From: amirouche.boubekki at gmail.com (Amirouche Boubekki) Date: Mon, 30 Jul 2018 20:33:07 +0200 Subject: hello from a very excited and totally blind python programmer and game player In-Reply-To: <1202DAA12035406D88C59644F2CD671F@Toshiba> References: <1202DAA12035406D88C59644F2CD671F@Toshiba> Message-ID: Le mar. 24 juil. 2018 ? 22:10, Daniel Perry a ?crit : > Hi there everyone, my name is Daniel Perry Hello! > and I'm a totally blind new Python user. Ok! > I've only just recently started picking up python and playing with it and > I intend on building some unique audio computer games for the blind. That. Is. An. Adventure. If you plan on a multi touch experience I recommend you look into #kivy and #python especially on freenode IRC network. > Such things mostly as simulation games like farming, building type games > and even eventually a virtual world built completely with audio but > building it in such a way that both we as totally blind colonists can live > inside of it but also that our fully sighted counterparts could live here > as well and not need any sort of guidance from the other group. That is, > the blind would not need any help from our sighted counterparts and you in > turn would not need any guidance from us as to how to live in the world or > grow in it. Well, that reads like an real adventure here. I've listening to books and while it's different, you still enjoy the story, so maybe I can enjoy a game made of sounds. > Of course this virtual world idea is down the road, I've got other game > ideas first of all but I would eventually like to get to the point I've > just described above. At some point, you might stop at the point where it pays the bills! > Preferably building my own server on which to park not only my virtual > world and games but also my web site that I would most likely need to put > these items up to be downloaded. I attach a small program that does render jinja2 templates and markdown, I hope you like it. > > Also, When I opened up the first message that I had gotten from this list, > I got a prompt hat popped up asking if I wanted to make windows live mail > my default news client and I answered no. From that point on, I've been > getting an error message and the message would not open. How must I fix > this? or am I able to correct this situation. Have a wonderful day and I > look forward to hearing from you soon. > That's a nast3 behavior. From bengt.tornq at gmail.com Mon Jul 30 14:38:53 2018 From: bengt.tornq at gmail.com (bengt.tornq at gmail.com) Date: Mon, 30 Jul 2018 11:38:53 -0700 (PDT) Subject: How to start gnuradio Message-ID: My gnuradio program does not start in my Mint 17.3 installation. When I invoke the command "gnuradio-companion" I get the following message: ----------------------------- Cannot import gnuradio. Is the python path environment variable set correctly? All OS: PYTHONPATH Is the library path environment variable set correctly? Linux: LD_LIBRARY_PATH Windows: PATH MacOSX: DYLD_LIBRARY_PATH ----------------------------- My exported paths, in the .bashrc file, are: export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/dist-packages export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/bin Grateful for hints on how to find out the reason and to solve the problem. From amirouche.boubekki at gmail.com Mon Jul 30 14:41:22 2018 From: amirouche.boubekki at gmail.com (Amirouche Boubekki) Date: Mon, 30 Jul 2018 20:41:22 +0200 Subject: hello from a very excited and totally blind python programmer and game player References: <1202DAA12035406D88C59644F2CD671F@Toshiba> Message-ID: Of course I forgot the static page generator program read (or listen) direct text of the link at the code follows https://raw.githubusercontent.com/amirouche/xp-maji/master/maji.py xp is for experience :smallsmile: I am a recovering lisp dev, so all my new programs are small. If you want a pure Python webdev try: git clone https://github.com/amirouche/beyondjs Le lun. 30 juil. 2018 ? 20:33, Amirouche Boubekki < amirouche.boubekki at gmail.com> a ?crit : > > > Le mar. 24 juil. 2018 ? 22:10, Daniel Perry a > ?crit : > >> Hi there everyone, my name is Daniel Perry > > > Hello! > > >> and I'm a totally blind new Python user. > > > Ok! > > >> I've only just recently started picking up python and playing with it and >> I intend on building some unique audio computer games for the blind. > > > That. Is. An. Adventure. If you plan on a multi touch experience I > recommend you look into #kivy and #python especially on freenode IRC > network. > > >> Such things mostly as simulation games like farming, building type games >> and even eventually a virtual world built completely with audio but >> building it in such a way that both we as totally blind colonists can live >> inside of it but also that our fully sighted counterparts could live here >> as well and not need any sort of guidance from the other group. That is, >> the blind would not need any help from our sighted counterparts and you in >> turn would not need any guidance from us as to how to live in the world or >> grow in it. > > > Well, that reads like an real adventure here. I've listening to books and > while it's different, you still enjoy the story, so maybe I can enjoy a > game made of sounds. > > >> Of course this virtual world idea is down the road, I've got other game >> ideas first of all but I would eventually like to get to the point I've >> just described above. > > > At some point, you might stop at the point where it pays the bills! > > >> Preferably building my own server on which to park not only my virtual >> world and games but also my web site that I would most likely need to put >> these items up to be downloaded. > > > I attach a small program that does render jinja2 templates and markdown, I > hope you like it. > >> >> Also, When I opened up the first message that I had gotten from this >> list, I got a prompt hat popped up asking if I wanted to make windows live >> mail my default news client and I answered no. From that point on, I've >> been getting an error message and the message would not open. How must I >> fix this? or am I able to correct this situation. Have a wonderful day and >> I look forward to hearing from you soon. >> > > That's a nast3 behavior. > From digitalfantasy.it86559 at digitalfantasy.it Mon Jul 30 17:10:18 2018 From: digitalfantasy.it86559 at digitalfantasy.it (Liste guru) Date: Mon, 30 Jul 2018 23:10:18 +0200 Subject: How to decide (and know) which Python GTK version to use? In-Reply-To: References: <20180730170458.GB1091@shallowsky.com> Message-ID: <9b69f396-772e-58f0-e6ea-f9257f3b7def@digitalfantasy.it> Il 30/07/2018 19:31, Chris Green ha scritto: > OK, thanks, where is its home and full API documentation etc.? > -- Chris Green?-- https://mail.python.org/mailman/listinfo/python-list On the first page of the official docs, http://pygobject.readthedocs.io/en/latest/, there are the links to the Python Gtk3 Tutorial, to the Python GI API Reference and all you need to start to work with Pygobject and Gtk3. Just a side note: Gtk3 uses the gobject-introspection (and, for Python, PyGobect) to 'connect' the library to Python (or with Lua or Vala) but the same introspection system is used also for different library, graphical (GStreamer or Goocanvas) or not (Gio). ??? Daniele Forghieri From ben+python at benfinney.id.au Mon Jul 30 19:33:01 2018 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 31 Jul 2018 09:33:01 +1000 Subject: Why did logging not undergo PEP8 API change? References: Message-ID: <86a7q8b8pe.fsf@benfinney.id.au> Skip Montanaro writes: > There was some discussion of the idea (before the thread predictably > wandered off into the weeds). I've not found anything else obviously > related to the topic. Perhaps it was nothing more than that the > threading module had a PEP-8 champion while logging didn't? Sometimes, even with a champion for improving the API through renames, it doesn't happen. There is still the BDFL (or whatever comes to replace that role) to reckon with . In that case, it was the inertia of the existing body of code using the API names which gave justification to reject renames. I would expect that was significant also in the decision not to change the ?logging? API names. -- \ ?[F]reedom of speech does not entail freedom to have your ideas | `\ accepted by governments and incorporated into law and policy.? | _o__) ?Russell Blackford, 2010-03-06 | Ben Finney From torriem at gmail.com Mon Jul 30 22:36:32 2018 From: torriem at gmail.com (Michael Torrie) Date: Mon, 30 Jul 2018 20:36:32 -0600 Subject: How to decide (and know) which Python GTK version to use? In-Reply-To: <20180730170458.GB1091@shallowsky.com> References: <20180730170458.GB1091@shallowsky.com> Message-ID: On 07/30/2018 11:04 AM, Akkana Peck wrote: > Yes, this is the future, since it lets you use both GTK3 and Python3. Unfortunately the automatically-generated bindings, while fast and complete, are not quite as pythonic as the old PyGTK bindings were. The abstraction layer pygobject provides leaks some of the underlying C-isms through. I can't remember exactly which bits feel the most foreign as it's been a while since I used it. But who am I kidding? PyQt (my preferred toolkit) or PySide aren't terribly Pythonic either; lots of C++ and Qt abstractions leaking through various Qt types when native Python types would be preferable (like lists and dictionaries). From robin at reportlab.com Tue Jul 31 03:40:08 2018 From: robin at reportlab.com (Robin Becker) Date: Tue, 31 Jul 2018 08:40:08 +0100 Subject: Are dicts supposed to raise comparison errors Message-ID: <0f420694-b2e1-fb7f-319a-8399bc8af7dd@chamonix.reportlab.co.uk> A bitbucket user complains that python 3.6.6 with -Wall -b prints warnings for some reportlab code; the example boils down to the following ########## C:\code\hg-repos\reportlab\tmp>cat tb.py if __name__=='__main__': d={'a':1} d[b'a'] = d['a'] ########## C:\code\hg-repos\reportlab\tmp>\python36\python -Wall -b tb.py tb.py:3: BytesWarning: Comparison between bytes and string d[b'a'] = d['a'] I had always assumed that dicts didn't care about the type of keys although some types might cause issue with hashability, but obviously the implementation seems to be comparing b'a' with 'a' (I suppose because they hash to the same chain). Is this code erroneous or is the warning spurious or wrong? -- Robin Becker From p.f.moore at gmail.com Tue Jul 31 04:16:25 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 31 Jul 2018 09:16:25 +0100 Subject: Are dicts supposed to raise comparison errors In-Reply-To: <0f420694-b2e1-fb7f-319a-8399bc8af7dd@chamonix.reportlab.co.uk> References: <0f420694-b2e1-fb7f-319a-8399bc8af7dd@chamonix.reportlab.co.uk> Message-ID: On 31 July 2018 at 08:40, Robin Becker wrote: > A bitbucket user complains that python 3.6.6 with -Wall -b prints warnings > for some reportlab code; the > example boils down to the following > > ########## > C:\code\hg-repos\reportlab\tmp>cat tb.py > if __name__=='__main__': > d={'a':1} > d[b'a'] = d['a'] > ########## > > > C:\code\hg-repos\reportlab\tmp>\python36\python -Wall -b tb.py > tb.py:3: BytesWarning: Comparison between bytes and string > d[b'a'] = d['a'] > > I had always assumed that dicts didn't care about the type of keys although > some types might cause issue with hashability, but obviously the > implementation seems to be comparing b'a' with 'a' (I suppose because they > hash to the same chain). > > Is this code erroneous or is the warning spurious or wrong? The warning seems right to me. Behaviour differs between Python 2 and Python 3: >py -Wall -b Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> b'a' == 'a' __main__:1: BytesWarning: Comparison between bytes and string False >>> ^Z >py -2 Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> b'a' == 'a' True >>> b'a' == u'a' True >>> which is basically the sort of thing that -b should warn about. Specifically the quoted code would end up with a dictionary with 2 entries on Python 3, but 1 entry on Python 2. Paul From robin at reportlab.com Tue Jul 31 04:32:53 2018 From: robin at reportlab.com (Robin Becker) Date: Tue, 31 Jul 2018 09:32:53 +0100 Subject: Are dicts supposed to raise comparison errors In-Reply-To: References: <0f420694-b2e1-fb7f-319a-8399bc8af7dd@chamonix.reportlab.co.uk> Message-ID: <8aa60233-d61e-e3fa-e83f-dc774accc656@chamonix.reportlab.co.uk> On 31/07/2018 09:16, Paul Moore wrote: > On 31 July 2018 at 08:40, Robin Becker wrote: >> A bitbucket user complains that python 3.6.6 with -Wall -b prints warnings >> for some reportlab code; the >> example boils down to the following >> >> ########## >> C:\code\hg-repos\reportlab\tmp>cat tb.py >> if __name__=='__main__': >> d={'a':1} >> d[b'a'] = d['a'] >> ########## >> >.......... > v.1500 64 bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> b'a' == 'a' > True >>>> b'a' == u'a' > True >>>> > > which is basically the sort of thing that -b should warn about. > Specifically the quoted code would end up with a dictionary with 2 > entries on Python 3, but 1 entry on Python 2. > > Paul > yes but I didn't do the compare so this warning seems entirely spurious and wrong. It's not an error to put 1 and 1.0 and 'a' into a dict. Should I get a warning if the hashes of two different types happen to clash so that an int needs to be checked against a string? -- Robin Becker From cl at isbd.net Tue Jul 31 04:44:20 2018 From: cl at isbd.net (Chris Green) Date: Tue, 31 Jul 2018 09:44:20 +0100 Subject: How to decide (and know) which Python GTK version to use? References: <20180730170458.GB1091@shallowsky.com> <9b69f396-772e-58f0-e6ea-f9257f3b7def@digitalfantasy.it> Message-ID: <44k53f-auo.ln1@esprimo.zbmc.eu> Liste guru wrote: > Il 30/07/2018 19:31, Chris Green ha scritto: > > > OK, thanks, where is its home and full API documentation etc.? > > -- Chris Green?-- https://mail.python.org/mailman/listinfo/python-list > > On the first page of the official docs, > http://pygobject.readthedocs.io/en/latest/, there are the links to the > Python Gtk3 Tutorial, to the Python GI API Reference and all you need to > start to work with Pygobject and Gtk3. > Excellent, thank you, it did take me a few seconds to find the links but they are there! It would have been more obvious if they had been repeated in the side bar (but maybe I'm just being obtuse!). > Just a side note: Gtk3 uses the gobject-introspection (and, for Python, > PyGobect) to 'connect' the library to Python (or with Lua or Vala) but > the same introspection system is used also for different library, > graphical (GStreamer or Goocanvas) or not (Gio). > Ah, that's why it's "import gi", thank you some more. :-) -- Chris Green ? From cl at isbd.net Tue Jul 31 04:52:38 2018 From: cl at isbd.net (Chris Green) Date: Tue, 31 Jul 2018 09:52:38 +0100 Subject: How to decide (and know) which Python GTK version to use? References: <20180730170458.GB1091@shallowsky.com> Message-ID: Michael Torrie wrote: > On 07/30/2018 11:04 AM, Akkana Peck wrote: > > Yes, this is the future, since it lets you use both GTK3 and Python3. > > Unfortunately the automatically-generated bindings, while fast and > complete, are not quite as pythonic as the old PyGTK bindings were. The > abstraction layer pygobject provides leaks some of the underlying C-isms > through. I can't remember exactly which bits feel the most foreign as > it's been a while since I used it. But who am I kidding? PyQt (my > preferred toolkit) or PySide aren't terribly Pythonic either; lots of > C++ and Qt abstractions leaking through various Qt types when native > Python types would be preferable (like lists and dictionaries). Yes, this has been some of my problem when starting to use these packages. I'm a retired Software Engineer and I spent much of my career (like the last 40 years or more) writing C/C++, so seeing C-like code isn't 'difficult', but it can be confusing. Some of the bits of 'example' code are actually C/C++ rather than Python which had me very confused for a while! Also there's the oddity of Gtk.Window and Gtk.Window.new (also due to the C/C++ ancestry?). -- Chris Green ? From p.f.moore at gmail.com Tue Jul 31 05:01:11 2018 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 31 Jul 2018 10:01:11 +0100 Subject: Are dicts supposed to raise comparison errors In-Reply-To: <8aa60233-d61e-e3fa-e83f-dc774accc656@chamonix.reportlab.co.uk> References: <0f420694-b2e1-fb7f-319a-8399bc8af7dd@chamonix.reportlab.co.uk> <8aa60233-d61e-e3fa-e83f-dc774accc656@chamonix.reportlab.co.uk> Message-ID: On 31 July 2018 at 09:32, Robin Becker wrote: > On 31/07/2018 09:16, Paul Moore wrote: >> >> On 31 July 2018 at 08:40, Robin Becker wrote: >>> >>> A bitbucket user complains that python 3.6.6 with -Wall -b prints >>> warnings >>> for some reportlab code; the >>> example boils down to the following >>> >>> ########## >>> C:\code\hg-repos\reportlab\tmp>cat tb.py >>> if __name__=='__main__': >>> d={'a':1} >>> d[b'a'] = d['a'] >>> ########## >>> >> .......... >> v.1500 64 bit (AMD64)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> >>>>> b'a' == 'a' >> >> True >>>>> >>>>> b'a' == u'a' >> >> True >>>>> >>>>> >> >> which is basically the sort of thing that -b should warn about. >> Specifically the quoted code would end up with a dictionary with 2 >> entries on Python 3, but 1 entry on Python 2. >> >> Paul >> > yes but I didn't do the compare so this warning seems entirely spurious and > wrong. It's not an error to put 1 and 1.0 and 'a' into a dict. Should I get > a warning if the hashes of two different types happen to clash so that an > int needs to be checked against a string? No, but it does seem reasonable (to me, at least) that you'd get a warning if the behaviour of a[1] = 12 a[1.0] = 99 were to change so that the dict had two separate entries. That's exactly what happened here - Python 3 behaves differently than Python 2, and the -b flag is to enable warnings about such cases. If you feel the warning is spurious then you can simply not use -b. Or suppress the warning, I guess. But it seems to me that it's an opt-in warning of something that could cause problems, so I don't really see why it's such a big problem. Paul From __peter__ at web.de Tue Jul 31 05:07:20 2018 From: __peter__ at web.de (Peter Otten) Date: Tue, 31 Jul 2018 11:07:20 +0200 Subject: Are dicts supposed to raise comparison errors References: <0f420694-b2e1-fb7f-319a-8399bc8af7dd@chamonix.reportlab.co.uk> <8aa60233-d61e-e3fa-e83f-dc774accc656@chamonix.reportlab.co.uk> Message-ID: Robin Becker wrote: > On 31/07/2018 09:16, Paul Moore wrote: >> On 31 July 2018 at 08:40, Robin Becker wrote: >>> A bitbucket user complains that python 3.6.6 with -Wall -b prints >>> warnings for some reportlab code; the >>> example boils down to the following >>> >>> ########## >>> C:\code\hg-repos\reportlab\tmp>cat tb.py >>> if __name__=='__main__': >>> d={'a':1} >>> d[b'a'] = d['a'] >>> ########## >>> >>.......... >> v.1500 64 bit (AMD64)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> b'a' == 'a' >> True >>>>> b'a' == u'a' >> True >>>>> >> >> which is basically the sort of thing that -b should warn about. >> Specifically the quoted code would end up with a dictionary with 2 >> entries on Python 3, but 1 entry on Python 2. >> >> Paul >> > yes but I didn't do the compare so this warning seems entirely spurious > and wrong. I disagree. Going from {"a": 1} in Python 2 to {"a": 1, b"a": 2} in Python3 can certainly be a source of nasty bugs. Also the interpreter cannot magically separate the comparisons directly "done by you" from those you triggered by running other people's code. > It's not an error to put 1 and 1.0 and 'a' into a dict. With these keys you end up with a single entry in both py2 and py3. > Should > I get a warning if the hashes of two different types happen to clash so > that an int needs to be checked against a string? Not the hash, a collision is basically meaningless unless it causes a performance regressen. However, ensuring that all keys have the same type may sometimes be useful. From stanimira.s.93 at gmail.com Tue Jul 31 08:02:46 2018 From: stanimira.s.93 at gmail.com (=?UTF-8?B?0KHRgtCw0L3QuNC80LjRgNCwINCd0LjQutC+0LvQvtCy0LA=?=) Date: Tue, 31 Jul 2018 05:02:46 -0700 (PDT) Subject: Python bug in ArcGIS - Urban Network analysis tool In-Reply-To: References: <2867cd51-25a2-4d6a-8bba-51b35e929ab3@googlegroups.com> <5eaa74dd-0f0c-2cf8-325a-014a6911e9cf@mrabarnett.plus.com> <378f1ec6-e42d-0159-1cf2-7ec14e0d28e3@pcug.org.au> Message-ID: <185725c6-7e05-4291-85d1-f97388a45fd5@googlegroups.com> ??????????, 30 ??? 2018 ?., 15:19:43 UTC+3, Andrew MacIntyre ??????: > On 30/07/2018 4:02 PM, ????????? ???????? wrote: > > >>>>> I run Urban network analysis but It shows similar mistake several times. The UNA tool is free plugin that i downloaded, it's not from the default intalled in ArcGIS packed. It ask for integer data. > >>>>> I checked the type of the attributes, it's all integer. PLus it's all in geo data based file. > >>>>> > >>>>> Unfortunately I don't understand Python, I'm one of those who use ArcGIS as sample customer. > >>>>> > >>>>> This is the mistake: > >>>>> > >>>>> Start Time: Fri Jul 27 14:48:32 2018 > >>>>> Running script Centrality... > >>>>> [started] Copying input buildings > >>>>> [finished] > >>>>> [1 started] Computing adjacency list > >>>>> [1 failed] > >>>>> Not successful > >>>>> Completed script Centrality... > >>>>> Succeeded at Fri Jul 27 14:48:36 2018 (Elapsed Time: 4,56 seconds) > >>>>> > >>>>> Any suggestions? How it's calling these adjaency list? What could be wrong? I even don't know how to get debugger, so it could give me more information. > > If it's a third party plugin, contact the author or source. This > mailing list sees very little traffic about ArcGIS usage as it is a > highly specialised commercial product. > > > I add in a project the .py file for the adjacency list. > > > > That's the main from the debuger: > > > > pydev debugger: process 8904 is connecting > > > > Connected to pydev debugger (build 182.3684.100) > > Traceback (most recent call last): > > File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\pydevd.py", line 1664, in > > main() > > File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\pydevd.py", line 1658, in main > > globals = debugger.run(setup['file'], None, None, is_module) > > File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\pydevd.py", line 1068, in run > > pydev_imports.execfile(file, globals, locals) # execute the script > > File "C:\Program Files\JetBrains\PyCharm 2018.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile > > exec(compile(contents+"\n", file, 'exec'), glob, loc) > > File "D:/INSTALL/Urban Network Analysis Toolbox 1.01/src/Centrality/Adjacency_List_Computation.py", line 14, in > > from arcpy import AddField_management > > ModuleNotFoundError: No module named 'arcpy' > > > > May I found the following lines from the code? > > Is it documented that the file you've attempted to run via PyCharm > actually supports being run from outside ArcGIS? Most plugins don't > seem to be... This failure is because PyCharm isn't starting the script > with the necessary environment (including the arcpy ArcGIS Python > module) accessible. > > The fact that it starts running from within ArcGIS and produces some > status messages before bailing out with the failure message strongly > suggests to me that the plugin is working properly but the input given > is not sufficient to produce the expected output. In the absence of > sufficient documentation for you to figure out the required input, my > advice above stands: contact the author or the download source. > > If you or your organisation has a current ArcGIS maintenance agreement, > you might also be able to access the community forums that ESRI run to > ask for more info about this plugin. > > -- > ------------------------------------------------------------------------- > Andrew I MacIntyre "These thoughts are mine alone..." > E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370 > andymac at pcug.org.au (alt) | Belconnen ACT 2616 > Web: http://www.andymac.org/ | Australia Hi Andrew, Thanks for your reply. I managed to resolve the problem. It seems that just the plugin doesn't found the python paths of it's environments and libraries. As I understood the adj. list is "calling" for functions in the other python files of the plugin (plus functions from ArcGIS). What I've done (me and one IT specialist, actually): - Found the pythonpath of the module arcpy in the folder of default installed ArcGIS - Copied the pythonpath file, for the connection with module arcpy, in the folder with scripts of the plugin (UNA tool) - opened Python 3.7 and called for arcpy of the plugin. There we saw the paths of all enviroments that might use the plugin. The path to the arcpy appeared. After that I got few mistakes of the input data, because I had to make unique ID of all the data points in the folder. And tadamm ? it works. Thanks for all the suggestions. Mira. From stephanh42 at gmail.com.invalid Tue Jul 31 08:14:40 2018 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 31 Jul 2018 12:14:40 GMT Subject: Using Python on a fork-less POSIX-like OS References: <35468446-48de-b5d0-bbed-33e7af5f3128@caesar.elte.hu> <055f451ff315960c7c4d1b52e2fb693f585a0403.camel@janc.be> Message-ID: Op 2018-07-29, Terry Reedy schreef : > multiprocessing module uses 'spawn' rather than 'fork' on Windows and it > has an option to use 'spawn' even on *nix. I presume the latter refers > to posix_spawn. You might want to check the multiprocessing code to see > what *it* is doing 'under the covers'. Actually, the only place posix_spawn is currently used in Python is in some experimental and currently-disabled code in the posix module. `spawn' in multiprocessing only refers to a fork/exec combination (on Posix, at least), as opposed to `fork' which only does a fork. Note that posix_spawn cannot provide full subprocess functionality (obviously preexec_fn, but also not start_new_session). So it's a hard sell to add a posix_spawn special case there, since a generic fork/exec would need to be maintained anyway. (The same reason is also why most shells such as bash, zsh, don't bother with posix_spawn.) Stephan From juraj.papic at bghtechpartner.com Tue Jul 31 10:56:29 2018 From: juraj.papic at bghtechpartner.com (Tcpip) Date: Tue, 31 Jul 2018 07:56:29 -0700 (PDT) Subject: Python Console Menu Message-ID: <9a615b45-af0f-4528-bdbf-8a47f67e7b48@googlegroups.com> Hi all, Im new with python, im working on a Python console Menu, I found some examples on Git, but what I need to understand is how I can call a subprocess. Here is an Example , if choice==1: print "Test SSH Connection (check ssh to all hosts)" ## You can add your code or functions here #print_menu() elif choice==2: print "Menu 2 has been selected" ## You can add your code or functions here elif choice==3: print "Menu 3 has been selected" ## You can add your code or functions here elif choice==4: print "Menu 4 has been selected" ## You can add your code or functions here elif choice==5: print "Menu 5 has been selected" ## You can add your code or function here Thanks. From David.Raymond at tomtom.com Tue Jul 31 11:15:24 2018 From: David.Raymond at tomtom.com (David Raymond) Date: Tue, 31 Jul 2018 15:15:24 +0000 Subject: Python Console Menu In-Reply-To: <9a615b45-af0f-4528-bdbf-8a47f67e7b48@googlegroups.com> References: <9a615b45-af0f-4528-bdbf-8a47f67e7b48@googlegroups.com> Message-ID: Take a look at the subprocess module for how to "spawn new processes, connect to their input/output/error pipes, and obtain their return codes." https://docs.python.org/2/library/subprocess.html -----Original Message----- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom.com at python.org] On Behalf Of Tcpip via Python-list Sent: Tuesday, July 31, 2018 10:56 AM To: python-list at python.org Subject: Python Console Menu Hi all, Im new with python, im working on a Python console Menu, I found some examples on Git, but what I need to understand is how I can call a subprocess. Here is an Example , if choice==1: print "Test SSH Connection (check ssh to all hosts)" ## You can add your code or functions here #print_menu() elif choice==2: print "Menu 2 has been selected" ## You can add your code or functions here elif choice==3: print "Menu 3 has been selected" ## You can add your code or functions here elif choice==4: print "Menu 4 has been selected" ## You can add your code or functions here elif choice==5: print "Menu 5 has been selected" ## You can add your code or function here Thanks. -- https://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Tue Jul 31 11:28:30 2018 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 31 Jul 2018 16:28:30 +0100 Subject: Are dicts supposed to raise comparison errors In-Reply-To: <0f420694-b2e1-fb7f-319a-8399bc8af7dd@chamonix.reportlab.co.uk> References: <0f420694-b2e1-fb7f-319a-8399bc8af7dd@chamonix.reportlab.co.uk> Message-ID: <6cddaf24-2fdd-0b8d-142a-15a5b7368edc@mrabarnett.plus.com> On 2018-07-31 08:40, Robin Becker wrote: > A bitbucket user complains that python 3.6.6 with -Wall -b prints warnings for some reportlab code; the > example boils down to the following > > ########## > C:\code\hg-repos\reportlab\tmp>cat tb.py > if __name__=='__main__': > d={'a':1} > d[b'a'] = d['a'] > ########## > > > C:\code\hg-repos\reportlab\tmp>\python36\python -Wall -b tb.py > tb.py:3: BytesWarning: Comparison between bytes and string > d[b'a'] = d['a'] > > I had always assumed that dicts didn't care about the type of keys although some types might cause issue with hashability, but > obviously the implementation seems to be comparing b'a' with 'a' (I suppose because they hash to the same chain). > > Is this code erroneous or is the warning spurious or wrong? > The warning looks wrong to be. In Python 2, u'a' and b'a' would be treated as the same key, but in Python 3 they are distinct and can co-exist. Something for Python's bug tracker, I think! From rosuav at gmail.com Tue Jul 31 11:52:08 2018 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Aug 2018 01:52:08 +1000 Subject: Are dicts supposed to raise comparison errors In-Reply-To: <6cddaf24-2fdd-0b8d-142a-15a5b7368edc@mrabarnett.plus.com> References: <0f420694-b2e1-fb7f-319a-8399bc8af7dd@chamonix.reportlab.co.uk> <6cddaf24-2fdd-0b8d-142a-15a5b7368edc@mrabarnett.plus.com> Message-ID: On Wed, Aug 1, 2018 at 1:28 AM, MRAB wrote: > On 2018-07-31 08:40, Robin Becker wrote: >> >> A bitbucket user complains that python 3.6.6 with -Wall -b prints warnings >> for some reportlab code; the >> example boils down to the following >> >> ########## >> C:\code\hg-repos\reportlab\tmp>cat tb.py >> if __name__=='__main__': >> d={'a':1} >> d[b'a'] = d['a'] >> ########## >> >> >> C:\code\hg-repos\reportlab\tmp>\python36\python -Wall -b tb.py >> tb.py:3: BytesWarning: Comparison between bytes and string >> d[b'a'] = d['a'] >> >> I had always assumed that dicts didn't care about the type of keys >> although some types might cause issue with hashability, but >> obviously the implementation seems to be comparing b'a' with 'a' (I >> suppose because they hash to the same chain). >> >> Is this code erroneous or is the warning spurious or wrong? >> > The warning looks wrong to be. > > In Python 2, u'a' and b'a' would be treated as the same key, but in Python 3 > they are distinct and can co-exist. > > Something for Python's bug tracker, I think! It's a warning specifically requested by the -b option. The two keys in question have the same hash, which means they have to be compared directly; they will compare unequal, but because of the -b flag, the comparison triggers a warning. If that warning is spurious, *don't use the -b option*. ChrisA From juraj.papic at bghtechpartner.com Tue Jul 31 12:25:20 2018 From: juraj.papic at bghtechpartner.com (juraj.papic at bghtechpartner.com) Date: Tue, 31 Jul 2018 09:25:20 -0700 (PDT) Subject: Python Console Menu In-Reply-To: <9a615b45-af0f-4528-bdbf-8a47f67e7b48@googlegroups.com> References: <9a615b45-af0f-4528-bdbf-8a47f67e7b48@googlegroups.com> Message-ID: <143a23df-3e4a-4362-80cb-0859d19a7f4c@googlegroups.com> El martes, 31 de julio de 2018, 11:56:47 (UTC-3), Tcpip escribi?: > Hi all, > > Im new with python, im working on a Python console Menu, I found some examples on Git, but what I need to understand is how I can call a subprocess. > > Here is an Example , > > if choice==1: > print "Test SSH Connection (check ssh to all hosts)" > ## You can add your code or functions here > #print_menu() > elif choice==2: > print "Menu 2 has been selected" > ## You can add your code or functions here > elif choice==3: > print "Menu 3 has been selected" > ## You can add your code or functions here > elif choice==4: > print "Menu 4 has been selected" > ## You can add your code or functions here > elif choice==5: > print "Menu 5 has been selected" > ## You can add your code or function here > > > Thanks. I will check the links thanks for that tips, is there any page where I can see more examples? Thanks. From malaclypse2 at gmail.com Tue Jul 31 14:36:25 2018 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 31 Jul 2018 14:36:25 -0400 Subject: Python Console Menu In-Reply-To: <143a23df-3e4a-4362-80cb-0859d19a7f4c@googlegroups.com> References: <9a615b45-af0f-4528-bdbf-8a47f67e7b48@googlegroups.com> <143a23df-3e4a-4362-80cb-0859d19a7f4c@googlegroups.com> Message-ID: On Tue, Jul 31, 2018 at 12:31 PM juraj.papic--- via Python-list wrote: > I will check the links thanks for that tips, is there any page where I can see more examples? I like Doug Hellmann's Python Module of the Week site for in-depth looks at particular modules (including subprocess). If you're using python 3, the subprocess module's page is here: https://pymotw.com/3/subprocess/. >From your sample code, you may still be using python 2. If so, the PyMOTW page for that version is here: https://pymotw.com/2/subprocess/. -- Jerry From juraj.papic at bghtechpartner.com Tue Jul 31 14:39:05 2018 From: juraj.papic at bghtechpartner.com (Juraj Papic) Date: Tue, 31 Jul 2018 15:39:05 -0300 Subject: Python Console Menu In-Reply-To: References: <9a615b45-af0f-4528-bdbf-8a47f67e7b48@googlegroups.com> <143a23df-3e4a-4362-80cb-0859d19a7f4c@googlegroups.com> Message-ID: Thanks for the links!!!! [image: cid:D5DA6341-AA78-4808-9639-F19B8AB3CBE8] *Juraj A. Papic* Arquitecto de Soluciones juraj.papic at bghtechpartner.com Arias 1639/41. C1429DWA. Bs. As., Argentina. T. +54 11 5080-7400 M. +54 911 3445-6944 Skype juraj.papic www.bghtechpartner.com 2018-07-31 15:36 GMT-03:00 Jerry Hill : > On Tue, Jul 31, 2018 at 12:31 PM juraj.papic--- via Python-list > wrote: > > I will check the links thanks for that tips, is there any page where I > can see more examples? > > I like Doug Hellmann's Python Module of the Week site for in-depth > looks at particular modules (including subprocess). If you're using > python 3, the subprocess module's page is here: > https://pymotw.com/3/subprocess/. > > From your sample code, you may still be using python 2. If so, the > PyMOTW page for that version is here: > https://pymotw.com/2/subprocess/. > > -- > Jerry > From uri at speedy.net Tue Jul 31 15:35:12 2018 From: uri at speedy.net (Uri Even-Chen) Date: Tue, 31 Jul 2018 22:35:12 +0300 Subject: unittest.TestCase.assertRaisesRegex throws DeprecationWarning Message-ID: Hi, We are using unittest.TestCase.assertRaisesRegex in our Django project (Speedy Net / Speedy Match - https://github.com/urievenchen/speedy-net), and I always prefer calling Python function parameters by name. So we call self.assertRaisesRegex with parameters (keyword arguments) expected_exception, expected_regex and callable - as documented on https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRaisesRegex . You can see our code on https://github.com/urievenchen/speedy-net/blob/master/speedy/core/accounts/tests/test_models.py . When I run tests regularly (with "./manage.py test") they pass, But when I run tests with "python -W error::DeprecationWarning manage.py test", (with Python 3.5.5), I receive errors like this: DeprecationWarning: 'callable' is an invalid keyword argument for this function See the full errors here: https://travis-ci.org/urievenchen/speedy-net/jobs/410482655 (by the way, with Python 3.4.6 the tests pass). Do you know what is the problem and why I receive these deprecation warnings? Thanks, Uri. *Uri Even-Chen* [image: photo] Phone: +972-54-3995700 Email: uri at speedy.net Website: http://www.speedysoftware.com/uri/en/ From info at wingware.com Tue Jul 31 16:00:54 2018 From: info at wingware.com (Wingware) Date: Tue, 31 Jul 2018 16:00:54 -0400 Subject: ANN: Wing Python IDE version 6.1 released Message-ID: <5B60BFF6.6050905@wingware.com> Hi, Wingware has just released Wing 6.1 , which adds PEP 8 reformatting, includes a How-To for Windows Subsystem for Linux, supports the Qt5Agg backend for matplotlib, allows configuring a path for code snippets, supports evaluating generator expressions that use data from the enclosing scope in the Debug Probe, improves auto-completion for pygame, and makes about 45 other minor improvements.For details, see https://wingware.com/pub/wingide/6.1.0/CHANGELOG.txt Download Now About Wing Wing is a family of cross-platform Python IDEs with powerful integrated editing, debugging, unit testing, and project management features. Wing runs on Windows, Linux, and OS X, and can be used to develop any kind of Python code for web, desktop, embedded scripting, and other applications. Wing 101 and Wing Personal omit some features and are free to download and use without a license. Wing Pro requires purchasing or upgrading a license, or obtaining a 30-day trial at startup. Version 6 introduces many new features, including improved multi-selection, much easier remote development , debugging from the Python Shell, recursive debugging, PEP 484 and 526 type hinting, PEP 8 reformatting, support for Python 3.6 and 3.7, Vagrant , Jupyter , Django 1.10+ and 2.0, and Windows Subsystem for Linux, improved mainloop support for matplotlib, easier Raspberry Pi development, optimized debugger, OS X full screen mode, One Dark color palette, Russian localization (thanks to Alexandr Dragukin), expanded free product line, and much more. For details, see What's New in Wing Version 6 . Wing 6 works with Python versions 2.5 through 2.7 and 3.2 through 3.7, including also Anaconda, ActivePython, EPD, Stackless, and others derived from the CPython implementation. For more product information, please visit wingware.com Upgrading You can try Wing 6 without removing older versions. Wing 6 will read and convert your old preferences, settings, and projects. Projects should be saved to a new name since previous versions of Wing cannot read Wing 6 projects. See also Migrating from Older Versions and Upgrading . Links Release notice: https://wingware.com/news/2018-07-30 Downloads and Free Trial: https://wingware.com/downloads Buy: https://wingware.com/store/purchase Upgrade: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at support at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE The Intelligent Development Environment for Python Programmers wingware.com From __peter__ at web.de Tue Jul 31 18:56:53 2018 From: __peter__ at web.de (Peter Otten) Date: Wed, 01 Aug 2018 00:56:53 +0200 Subject: unittest.TestCase.assertRaisesRegex throws DeprecationWarning References: Message-ID: Uri Even-Chen wrote: > Hi, > > We are using unittest.TestCase.assertRaisesRegex in our Django project > (Speedy Net / Speedy Match - https://github.com/urievenchen/speedy-net), > and I always prefer calling Python function parameters by name. So we call > self.assertRaisesRegex with parameters (keyword arguments) > expected_exception, expected_regex and callable - as documented on > https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRaisesRegex > . You can see our code on > https://github.com/urievenchen/speedy-net/blob/master/speedy/core/accounts/tests/test_models.py > . When I run tests regularly (with "./manage.py test") they pass, But when > I run tests with "python -W error::DeprecationWarning manage.py test", > (with Python 3.5.5), I receive errors like this: > > DeprecationWarning: 'callable' is an invalid keyword argument for this > function > > See the full errors here: > https://travis-ci.org/urievenchen/speedy-net/jobs/410482655 (by the way, > with Python 3.4.6 the tests pass). No, the function to be tested is not run at all (it looks like callable was called callable_obj back then): $ cat unittest_regex.py import unittest def foo(*args, **kw): print("RUNNING FOO") class T(unittest.TestCase): def test_baz(self): self.assertRaisesRegex( expected_exception=ValueError, expected_regex="bar", callable=foo ) if __name__ == "__main__": unittest.main() $ python3.4 unittest_regex.py . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK > Do you know what is the problem and why I receive these deprecation > warnings? Apparently they want you to use the context manager ;) Like with self.assertRaisesRegex(ValueError, "bar"): foo() Clean, readable, robust -- but no keyword args. From __peter__ at web.de Tue Jul 31 19:15:51 2018 From: __peter__ at web.de (Peter Otten) Date: Wed, 01 Aug 2018 01:15:51 +0200 Subject: unittest.TestCase.assertRaisesRegex throws DeprecationWarning References: Message-ID: Uri Even-Chen wrote: > Do you know what is the problem and why I receive these deprecation > warnings? I poked around a bit and found https://bugs.python.org/issue24134 Perhaps you can make sense of it (I can't). From 964683112 at qq.com Tue Jul 31 21:18:55 2018 From: 964683112 at qq.com (Coding Kids) Date: Tue, 31 Jul 2018 18:18:55 -0700 (PDT) Subject: i have add mouse motion feature to turtle Message-ID: i have add mouse motion event to turtle i think it's an small but excellent imporovement and made turtle could create more interesting project for kids any possiblity add this feature to offical version?is so what a exciting things! From zhang.lei.fly at gmail.com Tue Jul 31 23:16:00 2018 From: zhang.lei.fly at gmail.com (Jeffrey Zhang) Date: Wed, 1 Aug 2018 11:16:00 +0800 Subject: Confused on git commit tree about Lib/datetime.py Message-ID: I found a interesting issue when checking the Lib/datetime.py implementation in python3 This patch is introduced by cf86e368ebd17e10f68306ebad314eea31daaa1e [0]. But if you check the github page[0], or using git tag --contains, you will find v2.7.x includes this commit too. $ git tag --contains cf86e368ebd17e10f68306ebad314eea31daaa1e 3.2 v2.7.10 v2.7.10rc1 v2.7.11 v2.7.11rc1 ... whereas, if you check the v2.7.x code base, nothing is found $ git log v2.7.4 -- Lib/datetime.py I guess it maybe a git tool bug, or the commit tree is messed up. Is there any guys could explain this situation? [0] https://github.com/python/cpython/commit/cf86e368ebd17e10f68306ebad314eea31daaa1e -- Regards, Jeffrey Zhang Blog: http://xcodest.me