From petef4+usenet at gmail.com Fri Sep 1 02:18:32 2017 From: petef4+usenet at gmail.com (Pete Forman) Date: Fri, 01 Sep 2017 07:18:32 +0100 Subject: Case-insensitive string equality References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> Message-ID: Steven D'Aprano writes: > Three times in the last week the devs where I work accidentally > introduced bugs into our code because of a mistake with case-insensitive > string comparisons. They managed to demonstrate three different failures: > > # 1 > a = something().upper() # normalise string > ... much later on > if a == b.lower(): ... > > > # 2 > a = something().upper() > ... much later on > if a == 'maildir': ... > > > # 3 > a = something() # unnormalised > assert 'foo' in a > ... much later on > pos = a.find('FOO') > > > > Not every two line function needs to be in the standard library, but I've > come to the conclusion that case-insensitive testing and searches should > be. I've made these mistakes myself at times, as I'm sure most people > have, and I'm tired of writing my own case-insensitive function over and > over again. > > > So I'd like to propose some additions to 3.7 or 3.8. If the feedback here > is positive, I'll take it to Python-Ideas for the negative feedback :-) > > > (1) Add a new string method, which performs a case-insensitive equality > test. Here is a potential implementation, written in pure Python: > > > def equal(self, other): > if self is other: > return True > if not isinstance(other, str): > raise TypeError > if len(self) != len(other): > return False > casefold = str.casefold > for a, b in zip(self, other): > if casefold(a) != casefold(b): > return False > return True > > Alternatively: how about a === triple-equals operator to do the same > thing? > > > > (2) Add keyword-only arguments to str.find and str.index: > > casefold=False > > which does nothing if false (the default), and switches to a case- > insensitive search if true. > > > > > Alternatives: > > (i) Do nothing. The status quo wins a stalemate. > > (ii) Instead of str.find or index, use a regular expression. > > This is less discoverable (you need to know regular expressions) and > harder to get right than to just call a string method. Also, I expect > that invoking the re engine just for case insensitivity will be a lot > more expensive than a simple search need be. > > (iii) Not every two line function needs to be in the standard library. > Just add this to the top of every module: > > def equal(s, t): > return s.casefold() == t.casefold() > > > That's the status quo wins again. It's an annoyance. A small > annoyance, but multiplied by the sheer number of times it happens, it > becomes a large annoyance. I believe the annoyance factor of > case-insensitive comparisons outweighs the "two line function" > objection. > > And the two-line "equal" function doesn't solve the problem for find > and index, or for sets dicts, list.index and the `in` operator either. > > > Unsolved problems: > > This proposal doesn't help with sets and dicts, list.index and the `in` > operator either. > > > > Thoughts? This seems to me to be rather similar to sort() and sorted(). How about giving equals() an optional parameter key, and perhaps the older cmp? Using casefold or upper or lower would satisfy many use cases but also allow Unicode or more locale specific normalization to be applied. The shortcircuiting in a character based comparison holds little appeal for me. I generally find that a string is a more useful concept than a collection of characters. +1 for using an affix in the name to represent a normalized version of the input. -- Pete Forman From pavol.lisy at gmail.com Fri Sep 1 03:24:36 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Fri, 1 Sep 2017 09:24:36 +0200 Subject: If you are running 32-bit 3.6 on Windows, please test this In-Reply-To: <2a450525-992c-a417-772f-2eb8eccfe26d@2020fresno.com> References: <2a450525-992c-a417-772f-2eb8eccfe26d@2020fresno.com> Message-ID: On 8/31/17, 20/20 Lab wrote: > > > On 08/31/2017 01:53 AM, Pavol Lisy wrote: [...] > Valid point, fired up a windows 10 machine and worked as well. > > Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit > (Intel)] on win32 > Type "copyright", "credits" or "license()" for more information. > >>> import math > >>> math.sqrt(1.3) > 1.140175425099138 > >>> > > This machine does not have the creators update yet. So there's that. > -- > https://mail.python.org/mailman/listinfo/python-list Thx! :) Could somebody help me? I was trying to call sqrt using ctypes from msvcrt but I am not succesful: import ctypes msc = ctypes.windll.msvcrt def msqrt(arg): s = ctypes.create_string_buffer(100) d = ctypes.c_longdouble(arg) msc.sprintf(s, b'arg = %g', d) print(s.value.decode()) r = msc.sqrt(d) msc.sprintf(s, b'sqrt = %g', r) # r is int so this format is wrong I just like to show my intention print(s.value.decode()) print("r = ", r, r.__class__) >>> msqrt(1.3) arg = 1.3 sqrt = 0 r = 0 >>> msqrt(-1) arg = -1 sqrt = 4.00144e-320 # because wrong format in sprintf r = 8099 And -> >>> msc.sqrt.restype ctypes.c_long >>> msc.sqrt.argtypes is None True How to do it properly? Isn't ctypes broken? From __peter__ at web.de Fri Sep 1 04:23:57 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Sep 2017 10:23:57 +0200 Subject: If you are running 32-bit 3.6 on Windows, please test this References: <2a450525-992c-a417-772f-2eb8eccfe26d@2020fresno.com> Message-ID: Pavol Lisy wrote: > On 8/31/17, 20/20 Lab wrote: >> >> >> On 08/31/2017 01:53 AM, Pavol Lisy wrote: > [...] >> Valid point, fired up a windows 10 machine and worked as well. >> >> Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit >> (Intel)] on win32 >> Type "copyright", "credits" or "license()" for more information. >> >>> import math >> >>> math.sqrt(1.3) >> 1.140175425099138 >> >>> >> >> This machine does not have the creators update yet. So there's that. >> -- >> https://mail.python.org/mailman/listinfo/python-list > > Thx! :) > > Could somebody help me? > > I was trying to call sqrt using ctypes from msvcrt but I am not succesful: > > import ctypes > msc = ctypes.windll.msvcrt > > def msqrt(arg): > s = ctypes.create_string_buffer(100) > d = ctypes.c_longdouble(arg) > msc.sprintf(s, b'arg = %g', d) > print(s.value.decode()) > r = msc.sqrt(d) > msc.sprintf(s, b'sqrt = %g', r) # r is int so this format is > wrong I just like to show my intention > print(s.value.decode()) > print("r = ", r, r.__class__) > >>>> msqrt(1.3) > arg = 1.3 > sqrt = 0 > r = 0 > >>>> msqrt(-1) > arg = -1 > sqrt = 4.00144e-320 # because wrong format in sprintf > r = 8099 > > And -> > >>>> msc.sqrt.restype > ctypes.c_long > >>>> msc.sqrt.argtypes is None > True > > How to do it properly? Isn't ctypes broken? I think you have to specify the types yourself: >>> import ctypes >>> libm = ctypes.cdll.LoadLibrary("libm.so") >>> libm.sqrt(42) 0 >>> libm.sqrt.argtypes = [ctypes.c_double] >>> libm.sqrt.restype = ctypes.c_double >>> libm.sqrt(42) 6.48074069840786 From davidgshi at yahoo.co.uk Fri Sep 1 04:39:00 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Fri, 1 Sep 2017 08:39:00 +0000 (UTC) Subject: rdflib, N-Triples and Pandas References: <692352027.1400237.1504255140431.ref@mail.yahoo.com> Message-ID: <692352027.1400237.1504255140431@mail.yahoo.com> How best to use rdflib to parse N-Triples files and turn them into Pandas tables? Looking forward to hearing from you. Regards, David From estavilloraymart at gmail.com Fri Sep 1 05:50:38 2017 From: estavilloraymart at gmail.com (estavilloraymart at gmail.com) Date: Fri, 1 Sep 2017 02:50:38 -0700 (PDT) Subject: Solutions Manual Test Bank for College Physics 11th Edition by Serway In-Reply-To: References: Message-ID: <063a53da-e701-41cf-bf4e-c8988a31bb9a@googlegroups.com> Can i buy youre solutions manual ? From daiyueweng at gmail.com Fri Sep 1 07:33:45 2017 From: daiyueweng at gmail.com (Daiyue Weng) Date: Fri, 1 Sep 2017 12:33:45 +0100 Subject: how to update mongo using a dataframe for multiple documents Message-ID: Hi, I am trying to batch update mongo using a DataFrame, df_dict = df[['id', 'name']].to_dict(orient='records') [{'name': 'vendor1', 'id': '1'}, {'name': 'vendor2', 'id': '2'}, {'name': 'vendor3', 'id': '3'}, {'name': 'vendor4', 'id': '4'}, {'name': 'vendor5', 'id': '5'}, {'name': 'vendor6', 'id': '6'},] def update_database(update_dicts, table, database): for row_dict in update_dicts: database[table].update_one({'id': row_dict['id']}, {'$set': 'name': row_dict['name']}) when doing updating, pass df_dict to update_database function as the argument for update_dicts; I am wondering is there a way to update mongo in one go that doesn't have to go through the for loop and update_one document at a time. I am thinking if I don't go through the loop, it will be more efficient for updating mongo. I know there a Bulk.find.update() operation, one has to loop through the list of dicts in order to initialize the Bulk() operation for each document (using find) in order to update. cheers From steve+python at pearwood.info Fri Sep 1 09:20:34 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 01 Sep 2017 23:20:34 +1000 Subject: Case-insensitive string equality References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <0f5b6875-03ef-7532-e171-b3fbdbf64d63@kynesim.co.uk> Message-ID: <59a95ea2$0$1603$c3e8da3$5496439d@news.astraweb.com> On Thu, 31 Aug 2017 08:15 pm, Rhodri James wrote: > I'd quibble about the name and the implementation (length is not > preserved under casefolding), Yes, I'd forgotten about that. > but I'd go for this. The number of times > I've written something like this in different languages... [...] > The only way I can think of to get much traction with this is to have a > separate case-insensitive string class. That feels a bit heavyweight, > though. You might be right about that. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Fri Sep 1 09:22:30 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 01 Sep 2017 23:22:30 +1000 Subject: Case-insensitive string equality References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> Message-ID: <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> On Fri, 1 Sep 2017 09:53 am, MRAB wrote: > What would you expect the result would be for: > > "\N{LATIN SMALL LIGATURE FI}".case_insensitive_find("F") > > "\N{LATIN SMALL LIGATURE FI}".case_insensitive_find("I) That's easy. -1 in both cases, since neither "F" nor "I" is found in either string. We can prove this by manually checking: py> for c in "\N{LATIN SMALL LIGATURE FI}": ... print(c, 'F' in c, 'f' in c) ... print(c, 'I' in c, 'i' in c) ... ? False False ? False False If you want some other result, then you're not talking about case sensitivity. If anyone wants to propose "normalisation-insensitive matching", I'll ask you to please start your own thread rather than derailing this one with an unrelated, and much more difficult, problem. The proposal here is *case insensitive* matching, not Unicode normalisation. If you want to decompose the strings, you know how to: py> import unicodedata py> unicodedata.normalize('NFKD', "\N{LATIN SMALL LIGATURE FI}") 'fi' -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From sami.strat at gmail.com Fri Sep 1 09:30:43 2017 From: sami.strat at gmail.com (SS) Date: Fri, 1 Sep 2017 06:30:43 -0700 (PDT) Subject: python logic Message-ID: <1bb9d978-2126-46da-a4c8-5319efac2d09@googlegroups.com> Check out the following simple code: #!/bin/python print "1 - echo 1" print "2 - echo 2" answer = input("Enter your choice - ") if answer == 1: print "1" elif answer == 2: print "2" else: print "Invalid choice!" The else statement noted above works fine for numeric values other then 1 or 2. But if a user types in alphanumeric data (letters) into this, it blows up. Check out the following: [root at ansi ~]$ ./trash 1 - echo 1 2 - echo 2 Enter your choice - 3 Invalid choice! [root at ansi ~]$ ./trash 1 - echo 1 2 - echo 2 Enter your choice - r Traceback (most recent call last): File "./trash", line 6, in answer = input("Enter your choice - ") File "", line 1, in NameError: name 'r' is not defined I would expect the same behavior from both runs. Why does Python differ in the way it treats a character in that program? Finally, how to accomodate for such (how to fix)? TIA From ethernet.zero at gmail.com Fri Sep 1 09:40:13 2017 From: ethernet.zero at gmail.com (eth0) Date: Fri, 1 Sep 2017 13:40:13 -0000 (UTC) Subject: python logic References: <1bb9d978-2126-46da-a4c8-5319efac2d09@googlegroups.com> Message-ID: Era el Fri, 1 Sep 2017 06:30:43 -0700 (PDT) en comp.lang.python, cuando de repente SS dijo lo siguiente acerca de python logic: > Check out the following simple code: > > #!/bin/python > > print "1 - echo 1" > print "2 - echo 2" > > answer = input("Enter your choice - ") > > if answer == 1: > print "1" > elif answer == 2: > print "2" > else: > print "Invalid choice!" > > > The else statement noted above works fine for numeric values other > then 1 or 2. But if a user types in alphanumeric data (letters) into > this, it blows up. Check out the following: > > [root at ansi ~]$ ./trash > 1 - echo 1 > 2 - echo 2 > Enter your choice - 3 > Invalid choice! > > [root at ansi ~]$ ./trash > 1 - echo 1 > 2 - echo 2 > Enter your choice - r > Traceback (most recent call last): > File "./trash", line 6, in > answer = input("Enter your choice - ") > File "", line 1, in > NameError: name 'r' is not defined > > I would expect the same behavior from both runs. Why does Python > differ in the way it treats a character in that program? Finally, > how to accomodate for such (how to fix)? > > TIA In Python 2, the input() function evaluates whatever you enter in the prompt. In your case, Python is trying to evaluate 'r' as if it was a variable or something. Use the raw_input() function instead. However, note that if you ever want to run your script with Python 3 you'll have to switch back to using input(), which does exactly the same as Python 2's raw_input(). From rhodri at kynesim.co.uk Fri Sep 1 10:07:51 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 1 Sep 2017 15:07:51 +0100 Subject: python logic In-Reply-To: <1bb9d978-2126-46da-a4c8-5319efac2d09@googlegroups.com> References: <1bb9d978-2126-46da-a4c8-5319efac2d09@googlegroups.com> Message-ID: On 01/09/17 14:30, SS wrote: > Check out the following simple code: > > #!/bin/python > > print "1 - echo 1" > print "2 - echo 2" > > answer = input("Enter your choice - ") > > if answer == 1: > print "1" > elif answer == 2: > print "2" > else: > print "Invalid choice!" > > > The else statement noted above works fine for numeric values other then 1 or 2. But if a user types in alphanumeric data (letters) into this, it blows up. Check out the following: > > [root at ansi ~]$ ./trash > 1 - echo 1 > 2 - echo 2 > Enter your choice - 3 > Invalid choice! > > [root at ansi ~]$ ./trash > 1 - echo 1 > 2 - echo 2 > Enter your choice - r > Traceback (most recent call last): > File "./trash", line 6, in > answer = input("Enter your choice - ") > File "", line 1, in > NameError: name 'r' is not defined > > I would expect the same behavior from both runs. Why does Python differ in the way it treats a character in that program? Finally, how to accomodate for such (how to fix)? You don't say, but you must be running Python 2.x. If you fire up an interactive session: rhodri at sto-helit ~ $ python Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> help(input) Help on built-in function input in module __builtin__: input(...) input([prompt]) -> value Equivalent to eval(raw_input(prompt)). >>> Now raw_input() just returns the string that you typed in: >>> raw_input("Type a number:") Type a number:3 '3' Notice that this is a string, in quotes, not an integer. What happens when we eval() that? >>> eval('3') 3 This is the integer that you wanted. Great. Now how about that letter you typed instead? >>> raw_input("Type a number:") Type a number:r 'r' >>> eval('r') Traceback (most recent call last): File "", line 1, in File "", line 1, in NameError: name 'r' is not defined In other words, eval() looks for something named "r" but can't find anything, so it can't evaluate the input string. You can prove this by creating something named "r" and trying again: >>> r = 13 >>> eval('r') 13 Going back to your question, what you want to do is to use the function raw_input() and compare the input to the strings "1" and "2" (because that input is a string, remember?). You could use the function int() to convert the string to an integer, but then you would have to catch the cases when the user types something that isn't an integer for yourself! In Python3, it was generally agreed that the fancy behaviour of input() caused more confusion than it was worth. input() in Python3 behaves like raw_input() in Python2, just returning the characters typed in as a string. -- Rhodri James *-* Kynesim Ltd From tristanjanmaat at gmail.com Fri Sep 1 10:38:29 2017 From: tristanjanmaat at gmail.com (The Cat Gamer) Date: Fri, 1 Sep 2017 16:38:29 +0200 Subject: I am not able to run Python in Powershell Message-ID: fter I installed Python I try to open it in Powershell, by typing python/python.exe. It gives me an error: python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + python + ~~~~~~ + CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException This happens with version 3 and version 2. The newest versions and the older versions none of them makes me able to open Python in Windows Powershell. Are you guys aware of a fix? (I already tried the environment fix and that didnt work as well) From steve+python at pearwood.info Fri Sep 1 10:54:03 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 02 Sep 2017 00:54:03 +1000 Subject: python logic References: <1bb9d978-2126-46da-a4c8-5319efac2d09@googlegroups.com> Message-ID: <59a9748c$0$1604$c3e8da3$5496439d@news.astraweb.com> On Fri, 1 Sep 2017 11:30 pm, SS wrote: > Check out the following simple code: [...] Did you read the documentation for the `input` function? In Python 2, `input` should be avoided, because it evaluates whatever the user types. Watch this: py> answer = input('type a number ') type a number 'abcdefg'.find('e') py> print answer 4 What you should use is `raw_input`, but remember that it returns a string, not a number, so if you want a number you have to call int() on the results. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From davidgshi at yahoo.co.uk Fri Sep 1 11:36:49 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Fri, 1 Sep 2017 15:36:49 +0000 (UTC) Subject: Select data in N-Triples References: <1809297039.1861503.1504280209373.ref@mail.yahoo.com> Message-ID: <1809297039.1861503.1504280209373@mail.yahoo.com> in a N-Triples file, there are a lot lines like the following: "Baginton E04009817"@en . "Live" . "E04009817" . What I am interested is to find all lines contains something like "Baginton E04009817". Then, put the name and code into corresponding cells in 2 columns. Maybe, the solution is to find ways to select those lines having rdf-schema#label Is there a good example? Regards, David From rosuav at gmail.com Fri Sep 1 11:41:03 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Sep 2017 01:41:03 +1000 Subject: Case-insensitive string equality In-Reply-To: <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Sep 1, 2017 at 11:22 PM, Steve D'Aprano wrote: > On Fri, 1 Sep 2017 09:53 am, MRAB wrote: > >> What would you expect the result would be for: >> >> "\N{LATIN SMALL LIGATURE FI}".case_insensitive_find("F") >> >> "\N{LATIN SMALL LIGATURE FI}".case_insensitive_find("I) > > That's easy. > > -1 in both cases, since neither "F" nor "I" is found in either string. We can > prove this by manually checking: > > py> for c in "\N{LATIN SMALL LIGATURE FI}": > ... print(c, 'F' in c, 'f' in c) > ... print(c, 'I' in c, 'i' in c) > ... > ? False False > ? False False > > > If you want some other result, then you're not talking about case sensitivity. >>> "\N{LATIN SMALL LIGATURE FI}".upper() 'FI' >>> "\N{LATIN SMALL LIGATURE FI}".lower() '?' >>> "\N{LATIN SMALL LIGATURE FI}".casefold() 'fi' Aside from lower(), which returns the string unchanged, the case conversion rules say that this contains two letters. So "F" exists in the uppercased version of the string, and "f" exists in the casefolded version. So what's the definition of "case insensitive find"? The most simple and obvious form is: def case_insensitive_find(self, other): return self.casefold().find(other.casefold()) which would clearly return 0 and 1 for the two original searches. ChrisA From sami.strat at gmail.com Fri Sep 1 12:55:53 2017 From: sami.strat at gmail.com (SS) Date: Fri, 1 Sep 2017 09:55:53 -0700 (PDT) Subject: python logic In-Reply-To: <1bb9d978-2126-46da-a4c8-5319efac2d09@googlegroups.com> References: <1bb9d978-2126-46da-a4c8-5319efac2d09@googlegroups.com> Message-ID: <0dc63f5b-bf4f-4a83-a1d3-912468664ab4@googlegroups.com> On Friday, September 1, 2017 at 9:32:16 AM UTC-4, SS wrote: > Check out the following simple code: > > #!/bin/python > > print "1 - echo 1" > print "2 - echo 2" > > answer = input("Enter your choice - ") > > if answer == 1: > print "1" > elif answer == 2: > print "2" > else: > print "Invalid choice!" > > > The else statement noted above works fine for numeric values other then 1 or 2. But if a user types in alphanumeric data (letters) into this, it blows up. Check out the following: > > [root at ansi ~]$ ./trash > 1 - echo 1 > 2 - echo 2 > Enter your choice - 3 > Invalid choice! > > [root at ansi ~]$ ./trash > 1 - echo 1 > 2 - echo 2 > Enter your choice - r > Traceback (most recent call last): > File "./trash", line 6, in > answer = input("Enter your choice - ") > File "", line 1, in > NameError: name 'r' is not defined > > I would expect the same behavior from both runs. Why does Python differ in the way it treats a character in that program? Finally, how to accomodate for such (how to fix)? > > TIA raw_input, nice. Thanks!! From ganesh1pal at gmail.com Fri Sep 1 13:13:11 2017 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Fri, 1 Sep 2017 22:43:11 +0530 Subject: Python string replace the values Message-ID: In the fixed length string i.e "a0000",last 4 bits i.e "0000" should be replaced by the user provided value ( the value is between 0001 + f f f f ) . I intend to form final_string using a fixed_string and an user provided user_string Example: fixed_string = "a0000" user_string ='1' final string = fixed_string and user_string Example : "a0000" and "1" => a0001 "a0000" and "aa" => c00aa PS : "and" this is not logical and it's just for example If I concatenation using + or += or it's append the value at the end of the string >>> "a0000" + "1" ===> expected was a0001 'a00001' I am on python 2.7 and Linux , any ideas that you recommend to handle this Regards, Ganesh From python at mrabarnett.plus.com Fri Sep 1 13:44:34 2017 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 1 Sep 2017 18:44:34 +0100 Subject: Python string replace the values In-Reply-To: References: Message-ID: <331fe39a-68d6-6abb-a983-f932ec630f95@mrabarnett.plus.com> On 2017-09-01 18:13, Ganesh Pal wrote: > In the fixed length string i.e "a0000",last 4 bits i.e "0000" should be > replaced by the user provided value ( the value is between 0001 + f f f f ) > . I intend to form final_string using a fixed_string and an user provided > user_string > > > Example: > > fixed_string = "a0000" > user_string ='1' > > final string = fixed_string and user_string > > Example : > > "a0000" and "1" => a0001 > > "a0000" and "aa" => c00aa > > > PS : "and" this is not logical and it's just for example > > If I concatenation using + or += or it's append the value at the end of > the string > >>>> "a0000" + "1" ===> expected was a0001 > 'a00001' > > > > I am on python 2.7 and Linux , any ideas that you recommend to handle > this > How long is user_string? len(user_string) Truncate fixed_string by that many characters: fixed_string[ : -len(user_string)] Then append the user_string: fixed_string[ : -len(user_string)] + user_string Example: >>> fixed_string = "a0000" >>> user_string ='1' >>> len(user_string) 1 >>> fixed_string[ : -len(user_string)] 'a000' >>> fixed_string[ : -len(user_string)] + user_string 'a0001' Note: this won't work properly if len(user_string) == 0, so if that could happen, just skip it. (Appending an empty string has no effect anyway!) From rhodri at kynesim.co.uk Fri Sep 1 13:46:26 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 1 Sep 2017 18:46:26 +0100 Subject: Python string replace the values In-Reply-To: References: Message-ID: <4423d542-e8f8-d595-7b7b-79eb1e547e28@kynesim.co.uk> On 01/09/17 18:13, Ganesh Pal wrote: >>>> "a0000" + "1" ===> expected was a0001 > 'a00001' Why would you expect that? Concatenation means "joining together", so >>> "foo" + "bar" 'foobar' No other mangling of either of your original strings is going to happen; there is no magic going on here. What you want is most easily done using the zfill() string method to pad out the user's string with zeroes: >>> fixed_string = "a" >>> user_string = "1" >>> final_string = fixed_string + user_string.zfill(4) 'a0001' Note you should think VERY CAREFULLY about any user input like this. What are you going to do the user gives you too many digits, too few digits, non-digits? -- Rhodri James *-* Kynesim Ltd From Irv at furrypants.com Fri Sep 1 13:48:20 2017 From: Irv at furrypants.com (Irv Kalb) Date: Fri, 1 Sep 2017 10:48:20 -0700 Subject: Python string replace the values In-Reply-To: References: Message-ID: <29448D37-C241-4F6B-9A18-2B81602B1B70@furrypants.com> > On Sep 1, 2017, at 10:13 AM, Ganesh Pal wrote: > > In the fixed length string i.e "a0000",last 4 bits i.e "0000" should be > replaced by the user provided value ( the value is between 0001 + f f f f ) > . I intend to form final_string using a fixed_string and an user provided > user_string > > > Example: > > fixed_string = "a0000" > user_string ='1' > > final string = fixed_string and user_string > > Example : > > "a0000" and "1" => a0001 > > "a0000" and "aa" => c00aa > > > PS : "and" this is not logical and it's just for example > > If I concatenation using + or += or it's append the value at the end of > the string > >>>> "a0000" + "1" ===> expected was a0001 > 'a00001' > > > > I am on python 2.7 and Linux , any ideas that you recommend to handle > this > > > Regards, > Ganesh > Here's a little function that should it it for you. (I assume that in your example "a0000" and "aa" => c00aa, that really should have been a00aa) This should work for any size fixed_string and user_string (as long as the user_string is not longer than the fixed_string) def mergeStrings(fixed_string, user_string): nCharsInFixedString = len(fixed_string) nCharsInUserString = len(user_string) nCharsToGetFromFixedString = nCharsInFixedString - nCharsInUserString finalString = fixed_string[:nCharsToGetFromFixedString] + user_string return finalString Irv From ganesh1pal at gmail.com Fri Sep 1 14:05:52 2017 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Fri, 1 Sep 2017 23:35:52 +0530 Subject: Python string replace the values In-Reply-To: <29448D37-C241-4F6B-9A18-2B81602B1B70@furrypants.com> References: <29448D37-C241-4F6B-9A18-2B81602B1B70@furrypants.com> Message-ID: > (I assume that in your example "a0000" and "aa" => c00aa, that really should have been a00aa) Yes , thanks for noticing. On Fri, Sep 1, 2017 at 11:18 PM, Irv Kalb wrote: > > > On Sep 1, 2017, at 10:13 AM, Ganesh Pal wrote: > > > > In the fixed length string i.e "a0000",last 4 bits i.e "0000" should be > > replaced by the user provided value ( the value is between 0001 + f f f > f ) > > . I intend to form final_string using a fixed_string and an user > provided > > user_string > > > > > > Example: > > > > fixed_string = "a0000" > > user_string ='1' > > > > final string = fixed_string and user_string > > > > Example : > > > > "a0000" and "1" => a0001 > > > > "a0000" and "aa" => c00aa > > > > > > PS : "and" this is not logical and it's just for example > > > > If I concatenation using + or += or it's append the value at the end of > > the string > > > >>>> "a0000" + "1" ===> expected was a0001 > > 'a00001' > > > > > > > > I am on python 2.7 and Linux , any ideas that you recommend to handle > > this > > > > > > Regards, > > Ganesh > > > > Here's a little function that should it it for you. > > (I assume that in your example "a0000" and "aa" => c00aa, that really > should have been a00aa) > > This should work for any size fixed_string and user_string (as long as the > user_string is not longer than the fixed_string) > > def mergeStrings(fixed_string, user_string): > nCharsInFixedString = len(fixed_string) > nCharsInUserString = len(user_string) > > nCharsToGetFromFixedString = nCharsInFixedString - nCharsInUserString > > finalString = fixed_string[:nCharsToGetFromFixedString] + user_string > > return finalString > > Irv > > -- > https://mail.python.org/mailman/listinfo/python-list > From ganesh1pal at gmail.com Fri Sep 1 14:07:29 2017 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Fri, 1 Sep 2017 23:37:29 +0530 Subject: Python string replace the values In-Reply-To: <4423d542-e8f8-d595-7b7b-79eb1e547e28@kynesim.co.uk> References: <4423d542-e8f8-d595-7b7b-79eb1e547e28@kynesim.co.uk> Message-ID: >Note you should think VERY CAREFULLY about any user input like this. What are you going to do the user gives you too many digits, too few digits, non-digits Thanks the solution i.e using zfill() looks simple :) , we have a check that will take care of user input than's for noticing that On Fri, Sep 1, 2017 at 11:16 PM, Rhodri James wrote: > On 01/09/17 18:13, Ganesh Pal wrote: > >> "a0000" + "1" ===> expected was a0001 >>>>> >>>> 'a00001' >> > > Why would you expect that? Concatenation means "joining together", so > > >>> "foo" + "bar" > 'foobar' > > No other mangling of either of your original strings is going to happen; > there is no magic going on here. > > What you want is most easily done using the zfill() string method to pad > out the user's string with zeroes: > > >>> fixed_string = "a" > >>> user_string = "1" > >>> final_string = fixed_string + user_string.zfill(4) > 'a0001' > > Note you should think VERY CAREFULLY about any user input like this. What > are you going to do the user gives you too many digits, too few digits, > non-digits? > > -- > Rhodri James *-* Kynesim Ltd > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Fri Sep 1 15:49:48 2017 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 1 Sep 2017 20:49:48 +0100 Subject: I am not able to run Python in Powershell In-Reply-To: References: Message-ID: <0e351638-7e4e-5065-cbe4-22a9eea47021@mrabarnett.plus.com> On 2017-09-01 15:38, The Cat Gamer wrote: > fter I installed Python I try to open it in Powershell, by typing > python/python.exe. > It gives me an error: > python : The term 'python' is not recognized as the name of a cmdlet, > function, script file, or operable program. Check the spelling of the name, > or if a path was included, verify that the path is correct and try again. > At line:1 char:1 > + python > + ~~~~~~ > + CategoryInfo : ObjectNotFound: (python:String) [], > CommandNotFoundException > + FullyQualifiedErrorId : CommandNotFoundException > This happens with version 3 and version 2. The newest versions and the > older versions none of them makes me able to open Python in Windows > Powershell. Are you guys aware of a fix? > > (I already tried the environment fix and that didnt work as well) > "python" isn't on the path list, but the Python launcher "py" should be. If you want to start Python 3.6 specifically (assuming it's installed): py -3.6 If you want to start the default python: py From landytips90 at gmail.com Fri Sep 1 16:53:58 2017 From: landytips90 at gmail.com (landytips90 at gmail.com) Date: Fri, 1 Sep 2017 13:53:58 -0700 (PDT) Subject: Solutions Manual Test Bank for McGraw-Hill's Taxation of Business Entities 2018 Edition 9th Edition by Spilker In-Reply-To: <203e940a-f58c-4442-b5df-014527859a11@googlegroups.com> References: <203e940a-f58c-4442-b5df-014527859a11@googlegroups.com> Message-ID: On Saturday, July 1, 2017 at 6:34:07 PM UTC-4, Test Banks wrote: > Greetings, > > You can get Solution Manuals and Test Bank for " McGraw-Hill's Taxation of Business Entities 2018 Edition 9th Edition by Brian Spilker and Benjamin Ayers and John Barrick and Edmund Outslay and John Robinson and Connie Weaver and Ronald Worsham " at very reasonable price. Our team is available 24/7 and 365 days / year to respond your requests. Send us an email at pro.fast(@)hotmail(dot)com > > Place your order at PRO.FAST(@)HOTMAIL(DOT)COM > > ISBN Numbers for this book (ISBN-10: 126000757X and ISBN-13: 9781260007572) > > MCGRAW-HILL'S TAXATION OF BUSINESS ENTITIES 2018 EDITION 9TH EDITION BY SPILKER SOLUTIONS MANUAL TEST BANK > > You can also email for other Taxation books Solutions and Test Bank at low prices and our team will try to get all resources you need. > > Do not post your reply here. Simply send us an email at PRO.FAST (AT) HOTMAIL (DOT) COM > > Cheers, From ross at cgl.ucsf.edu Fri Sep 1 17:39:06 2017 From: ross at cgl.ucsf.edu (ross at cgl.ucsf.edu) Date: Fri, 1 Sep 2017 14:39:06 -0700 (PDT) Subject: virtualenv doesn't see my compiled tensorflow Message-ID: <5e549cdd-56ed-4c8f-9a62-3a3dbd334702@googlegroups.com> With the prebuilt version of tensorflow, I did: virtualenv --system-site-packages ~/tensorflow and somehow got it working with keras. Now I've compiled tensorflow in another shell/directory, where to start with I did: virtualenv --system-site-packages . and I got it running with keras on my net, with a nice speedup. Then I went back to my previous shell, did a deactivate, then virtualenv --system-site-packages ~/tf_compile/tensorflow to point to the dir that was '.' above, but my prompt path did not pick up '(tensorflow)' as before: % virtualenv --system-site-packages ~/tf_compile/tensorflow New python executable in /Users/priot/tf_compile/tensorflow/bin/python Installing setuptools, pip, wheel...done. priot keras% and I get: % python prog.py ... File "/Users/ppp/anaconda/lib/python2.7/site- packages/keras/backend/tensorflow_backend.py", line 1, in import tensorflow as tf ImportError: No module named tensorflow Seems inconsistent. % virtualenv --version 15.1.0 % python --version Python 2.7.10 :: Anaconda custom (x86_64) OS: OSx Darwin From ross at cgl.ucsf.edu Fri Sep 1 17:51:52 2017 From: ross at cgl.ucsf.edu (ross at cgl.ucsf.edu) Date: Fri, 1 Sep 2017 14:51:52 -0700 (PDT) Subject: virtualenv doesn't see my compiled tensorflow In-Reply-To: <5e549cdd-56ed-4c8f-9a62-3a3dbd334702@googlegroups.com> References: <5e549cdd-56ed-4c8f-9a62-3a3dbd334702@googlegroups.com> Message-ID: Solution: remember to run the 'activate' script: % source ~/tf_compile/tensorflow/bin/activate On Friday, September 1, 2017 at 2:39:33 PM UTC-7, ro... at cgl.ucsf.edu wrote: > With the prebuilt version of tensorflow, I did: > > virtualenv --system-site-packages ~/tensorflow > > and somehow got it working with keras. Now I've compiled tensorflow in another shell/directory, where to start with I did: > > virtualenv --system-site-packages . > > and I got it running with keras on my net, with a nice speedup. Then I went back to my previous shell, did a deactivate, then > > virtualenv --system-site-packages ~/tf_compile/tensorflow > > to point to the dir that was '.' above, but my prompt path did not pick up '(tensorflow)' as before: > > % virtualenv --system-site-packages ~/tf_compile/tensorflow > New python executable in /Users/priot/tf_compile/tensorflow/bin/python > Installing setuptools, pip, wheel...done. > priot keras% > > and I get: > > % python prog.py > ... > File "/Users/ppp/anaconda/lib/python2.7/site- > packages/keras/backend/tensorflow_backend.py", line 1, in > import tensorflow as tf > ImportError: No module named tensorflow > > Seems inconsistent. > > % virtualenv --version > 15.1.0 > > % python --version > Python 2.7.10 :: Anaconda custom (x86_64) > > OS: OSx Darwin From eryksun at gmail.com Fri Sep 1 18:06:14 2017 From: eryksun at gmail.com (eryk sun) Date: Fri, 1 Sep 2017 17:06:14 -0500 Subject: If you are running 32-bit 3.6 on Windows, please test this In-Reply-To: References: <2a450525-992c-a417-772f-2eb8eccfe26d@2020fresno.com> Message-ID: On Fri, Sep 1, 2017 at 3:23 AM, Peter Otten <__peter__ at web.de> wrote: > > I think you have to specify the types yourself: > >>>> import ctypes >>>> libm = ctypes.cdll.LoadLibrary("libm.so") >>>> libm.sqrt(42) > 0 >>>> libm.sqrt.argtypes = [ctypes.c_double] >>>> libm.sqrt.restype = ctypes.c_double >>>> libm.sqrt(42) > 6.48074069840786 On POSIX systems, use ctypes.util.find_library('m'), which, for example, resolves to "libm.so.6" in Ubuntu Linux 16.04. On the same system, "libm.so" is an ld script that's used by the compile-time linker. $ cat /usr/lib/x86_64-linux-gnu/libm.so /* GNU ld script */ OUTPUT_FORMAT(elf64-x86-64) GROUP ( /lib/x86_64-linux-gnu/libm.so.6 AS_NEEDED ( /usr/lib/x86_64-linux-gnu/libmvec_nonshared.a /lib/x86_64-linux-gnu/libmvec.so.1 ) ) The runtime linker doesn't know how to handle this script. >>> ctypes.CDLL('libm.so') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.5/ctypes/__init__.py", line 347, in __init__ self._handle = _dlopen(self._name, mode) OSError: /usr/lib/x86_64-linux-gnu/libm.so: invalid ELF header On Windows, Python 3.5+ uses the Universal C Runtime. You can reference it directly as follows: ucrt = ctypes.CDLL('ucrtbase', use_errno=True) But in practice you should use the math API set [1]. For example: >>> crt_math = ctypes.CDLL('api-ms-win-crt-math-l1-1-0', ... use_errno=True) >>> crt_math.sqrt.restype = ctypes.c_double >>> crt_math.sqrt.argtypes = [ctypes.c_double] >>> crt_math.sqrt(1.3) 1.140175425099138 >>> ctypes.get_errno() 0 Note that find_library('c') and find_library('m') both return None under Windows in Python 3.5+. >>> ctypes.util.find_library('c') is None True >>> ctypes.util.find_library('m') is None True [1]: https://msdn.microsoft.com/en-us/library/mt656782#_api-ms-win-crt-math-l1-1-0 From eryksun at gmail.com Fri Sep 1 18:20:29 2017 From: eryksun at gmail.com (eryk sun) Date: Fri, 1 Sep 2017 17:20:29 -0500 Subject: If you are running 32-bit 3.6 on Windows, please test this In-Reply-To: References: <2a450525-992c-a417-772f-2eb8eccfe26d@2020fresno.com> Message-ID: On Fri, Sep 1, 2017 at 2:24 AM, Pavol Lisy wrote: > > I was trying to call sqrt using ctypes from msvcrt but I am not succesful: > > import ctypes > msc = ctypes.windll.msvcrt msvcrt.dll is private to Windows components. It's not intended for applications. See my previous post in this thread for the correct shared library to load for Python 3.5+. Also, WinDLL (or windll) is for stdcall, whereas CRT functions use cdecl (CDLL or cdll). In 64-bit it isn't a problem since cdecl and stdcall are the same in x64, but this will fail in 32-bit x86. From steve+python at pearwood.info Fri Sep 1 20:09:39 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 02 Sep 2017 10:09:39 +1000 Subject: Case-insensitive string equality References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59a9f6c5$0$1609$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Sep 2017 01:41 am, Chris Angelico wrote: > On Fri, Sep 1, 2017 at 11:22 PM, Steve D'Aprano > wrote: >> On Fri, 1 Sep 2017 09:53 am, MRAB wrote: >> >>> What would you expect the result would be for: >>> >>> "\N{LATIN SMALL LIGATURE FI}".case_insensitive_find("F") >>> >>> "\N{LATIN SMALL LIGATURE FI}".case_insensitive_find("I) >> >> That's easy. >> >> -1 in both cases, since neither "F" nor "I" is found in either string. We can >> prove this by manually checking: >> >> py> for c in "\N{LATIN SMALL LIGATURE FI}": >> ... print(c, 'F' in c, 'f' in c) >> ... print(c, 'I' in c, 'i' in c) >> ... >> ? False False >> ? False False >> >> >> If you want some other result, then you're not talking about case >> sensitivity. > >>>> "\N{LATIN SMALL LIGATURE FI}".upper() > 'FI' The question wasn't what "\N{LATIN SMALL LIGATURE FI}".upper() would find, but "\N{LATIN SMALL LIGATURE FI}". Nor did they ask about "\N{LATIN SMALL LIGATURE FI}".replace("\N{LATIN SMALL LIGATURE FI}", "Surprise!") > So what's the definition of "case insensitive find"? The most simple > and obvious form is: > > def case_insensitive_find(self, other): > return self.casefold().find(other.casefold()) That's not the definition, that's an implementation. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Fri Sep 1 20:15:42 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 02 Sep 2017 10:15:42 +1000 Subject: Python string replace the values References: Message-ID: <59a9f830$0$1617$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Sep 2017 03:13 am, Ganesh Pal wrote: > Example : > > "a0000" and "1" => a0001 > > "a0000" and "aa" => c00aa Why does the leading 'a' change to a 'c'? Is that a mistake? I'll assume its a typo. You want string slicing. base = 'a0000' extra = 'ab' print( base[:-len(extra)] + extra ) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Fri Sep 1 20:29:05 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Sep 2017 10:29:05 +1000 Subject: Case-insensitive string equality In-Reply-To: <59a9f6c5$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> <59a9f6c5$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 2, 2017 at 10:09 AM, Steve D'Aprano wrote: > The question wasn't what "\N{LATIN SMALL LIGATURE FI}".upper() would find, > but "\N{LATIN SMALL LIGATURE FI}". > > Nor did they ask about > > "\N{LATIN SMALL LIGATURE FI}".replace("\N{LATIN SMALL LIGATURE > FI}", "Surprise!") > >> So what's the definition of "case insensitive find"? The most simple >> and obvious form is: >> >> def case_insensitive_find(self, other): >> return self.casefold().find(other.casefold()) > > That's not the definition, that's an implementation. It's a reference implementation that defines certain semantics. Obviously you can *actually* implement it using some kind of C-level loop or something, as long as you can define the semantics somehow. So what IS your definition of "case insensitive find"? Do you case-fold both strings or just one? What do you do about length-changing case folding? ChrisA From steve+python at pearwood.info Fri Sep 1 20:31:28 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 02 Sep 2017 10:31:28 +1000 Subject: Case-insensitive string equality References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59a9fbe3$0$1605$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Sep 2017 01:41 am, Chris Angelico wrote: > Aside from lower(), which returns the string unchanged, the case > conversion rules say that this contains two letters. Do you have a reference to that? I mean, where in the Unicode case conversion rules is that stated? You cannot take the behaviour of Python as necessarily correct here -- it may be that the behaviour of Python is erroneous. For what its worth, even under Unicode's own rules, there are always going to be odd corner cases that surprise people. The most obvious cases are: - dotted and dottless i - the German eszett, ?, which has two official[1] uppercase forms: 'SS' and an uppercase eszett - long s, ?, which may or may not be treated as distinct from s - likewise for ligatures -- is ? a ligature, or is it Old English ash? You can't keep everybody happy. Doesn't mean we can't meet 99% of the usescases. After all, what do you think the regex case insensitive matching does? [1] I believe that the German government has now officially recognised the uppercase form of ?. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Fri Sep 1 20:53:32 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Sep 2017 10:53:32 +1000 Subject: Case-insensitive string equality In-Reply-To: <59a9fbe3$0$1605$c3e8da3$5496439d@news.astraweb.com> References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> <59a9fbe3$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 2, 2017 at 10:31 AM, Steve D'Aprano wrote: > On Sat, 2 Sep 2017 01:41 am, Chris Angelico wrote: > >> Aside from lower(), which returns the string unchanged, the case >> conversion rules say that this contains two letters. > > Do you have a reference to that? > > I mean, where in the Unicode case conversion rules is that stated? You cannot > take the behaviour of Python as necessarily correct here -- it may be that the > behaviour of Python is erroneous. Yep! It's all in here. ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt > For what its worth, even under Unicode's own rules, there are always going to be > odd corner cases that surprise people. The most obvious cases are: > > You can't keep everybody happy. Doesn't mean we can't meet 99% of the usescases. > > After all, what do you think the regex case insensitive matching does? Honestly, I don't know what it does without checking. But code is often *wrong* due to backward compatibility concerns. Then you have to decide whether, for a brand new API, it's better to "do the same as the regex module" or to "do what the Unicode consortium says". As it turns out, the Python 're' module doesn't match the letters against the ligature: >>> re.search("F", "\N{LATIN SMALL LIGATURE FI}", re.IGNORECASE) >>> re.search("f", "\N{LATIN SMALL LIGATURE FI}", re.IGNORECASE) >>> re.search("I", "\N{LATIN SMALL LIGATURE FI}", re.IGNORECASE) >>> re.search("i", "\N{LATIN SMALL LIGATURE FI}", re.IGNORECASE) >>> re.search("S", "\N{LATIN SMALL LETTER SHARP S}", re.IGNORECASE) >>> re.search("s", "\N{LATIN SMALL LETTER SHARP S}", re.IGNORECASE) >>> I would consider that code to be incorrect. ChrisA From steve+python at pearwood.info Fri Sep 1 22:21:51 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 02 Sep 2017 12:21:51 +1000 Subject: Case-insensitive string equality References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> Message-ID: <59aa15c0$0$1587$c3e8da3$5496439d@news.astraweb.com> On Fri, 1 Sep 2017 01:29 am, Tim Chase wrote: > On 2017-08-31 07:10, Steven D'Aprano wrote: >> So I'd like to propose some additions to 3.7 or 3.8. > > Adding my "yes, a case-insensitive equality-check would be useful" > with the following concerns: > > I'd want to have an optional parameter to take locale into > consideration. E.g. Does regular case-sensitive equality take the locale into consideration? How do I convince Python to return true for these? 'i'.upper() == '?' 'I'.lower() == '?' I'm 99% sure that these are rhetorical questions where the answers are obviously: - No it doesn't. - And you can't. If regular case-sensitive string comparisons don't support the locale, why should case-insensitive comparisons be required to? We should not confuse "nice to have" for "must have". As far as I'm concerned, the only "must have" is that ASCII letters do the right thing. Everything beyond that is a "quality of implementation" issue. In any case, thanks to everyone for their feedback. Clearly there not enough support for this for me to even bother taking it to Python-Ideas. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Fri Sep 1 22:33:19 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Sep 2017 12:33:19 +1000 Subject: Case-insensitive string equality In-Reply-To: <59aa15c0$0$1587$c3e8da3$5496439d@news.astraweb.com> References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59aa15c0$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 2, 2017 at 12:21 PM, Steve D'Aprano wrote: > On Fri, 1 Sep 2017 01:29 am, Tim Chase wrote: > >> On 2017-08-31 07:10, Steven D'Aprano wrote: >>> So I'd like to propose some additions to 3.7 or 3.8. >> >> Adding my "yes, a case-insensitive equality-check would be useful" >> with the following concerns: >> >> I'd want to have an optional parameter to take locale into >> consideration. E.g. > > Does regular case-sensitive equality take the locale into consideration? > > How do I convince Python to return true for these? > > 'i'.upper() == '?' > 'I'.lower() == '?' > > > I'm 99% sure that these are rhetorical questions where the answers are > obviously: > > - No it doesn't. > - And you can't. > > If regular case-sensitive string comparisons don't support the locale, why > should case-insensitive comparisons be required to? > > We should not confuse "nice to have" for "must have". As far as I'm concerned, > the only "must have" is that ASCII letters do the right thing. Everything > beyond that is a "quality of implementation" issue. The only "must have" is that the locale-independent conversions do the right thing. We already have str.casefold() that correctly handles >99% of situations; the easiest way to craft something like this is to define it in terms of that. > In any case, thanks to everyone for their feedback. Clearly there not enough > support for this for me to even bother taking it to Python-Ideas. Agreed; if this were important enough for someone to want to run the gauntlet of -ideas and -dev, I'd predict that it would be one of those VERY hotly debated topics. ChrisA On Sat, Sep 2, 2017 at 12:21 PM, Steve D'Aprano wrote: > On Fri, 1 Sep 2017 01:29 am, Tim Chase wrote: > >> On 2017-08-31 07:10, Steven D'Aprano wrote: >>> So I'd like to propose some additions to 3.7 or 3.8. >> >> Adding my "yes, a case-insensitive equality-check would be useful" >> with the following concerns: >> >> I'd want to have an optional parameter to take locale into >> consideration. E.g. > > Does regular case-sensitive equality take the locale into consideration? > > How do I convince Python to return true for these? > > 'i'.upper() == '?' > 'I'.lower() == '?' > > > I'm 99% sure that these are rhetorical questions where the answers are > obviously: > > - No it doesn't. > - And you can't. > > If regular case-sensitive string comparisons don't support the locale, why > should case-insensitive comparisons be required to? > > We should not confuse "nice to have" for "must have". As far as I'm concerned, > the only "must have" is that ASCII letters do the right thing. Everything > beyond that is a "quality of implementation" issue. > > > In any case, thanks to everyone for their feedback. Clearly there not enough > support for this for me to even bother taking it to Python-Ideas. > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list From ganesh1pal at gmail.com Sat Sep 2 03:04:34 2017 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sat, 2 Sep 2017 12:34:34 +0530 Subject: Python string replace the values In-Reply-To: <331fe39a-68d6-6abb-a983-f932ec630f95@mrabarnett.plus.com> References: <331fe39a-68d6-6abb-a983-f932ec630f95@mrabarnett.plus.com> Message-ID: MRAB , Thanks for your solution it looks neat and best ! On Fri, Sep 1, 2017 at 11:14 PM, MRAB wrote: > On 2017-09-01 18:13, Ganesh Pal wrote: > >> In the fixed length string i.e "a0000",last 4 bits i.e "0000" should be >> replaced by the user provided value ( the value is between 0001 + f f f f >> ) >> . I intend to form final_string using a fixed_string and an user >> provided >> user_string >> >> >> Example: >> >> fixed_string = "a0000" >> user_string ='1' >> >> final string = fixed_string and user_string >> >> Example : >> >> "a0000" and "1" => a0001 >> >> "a0000" and "aa" => c00aa >> >> >> PS : "and" this is not logical and it's just for example >> >> If I concatenation using + or += or it's append the value at the end of >> the string >> >> "a0000" + "1" ===> expected was a0001 >>>>> >>>> 'a00001' >> >> >> >> I am on python 2.7 and Linux , any ideas that you recommend to handle >> this >> >> How long is user_string? len(user_string) > Truncate fixed_string by that many characters: fixed_string[ : > -len(user_string)] > > Then append the user_string: fixed_string[ : -len(user_string)] + > user_string > > Example: > > >>> fixed_string = "a0000" > >>> user_string ='1' > >>> len(user_string) > 1 > >>> fixed_string[ : -len(user_string)] > 'a000' > >>> fixed_string[ : -len(user_string)] + user_string > 'a0001' > > Note: this won't work properly if len(user_string) == 0, so if that could > happen, just skip it. (Appending an empty string has no effect anyway!) > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Sat Sep 2 03:05:35 2017 From: __peter__ at web.de (Peter Otten) Date: Sat, 02 Sep 2017 09:05:35 +0200 Subject: Python string replace the values References: <59a9f830$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > On Sat, 2 Sep 2017 03:13 am, Ganesh Pal wrote: > >> Example : >> >> "a0000" and "1" => a0001 >> >> "a0000" and "aa" => c00aa > > Why does the leading 'a' change to a 'c'? Is that a mistake? I'll assume > its a typo. > > You want string slicing. > > base = 'a0000' > extra = 'ab' assert len(extra) > print( base[:-len(extra)] + extra ) or base[:-len(extra) or None] + extra if you need to handle the extra = "" case. Another option is a template: >>> "a{:0>4}".format("") 'a0000' >>> "a{:0>4}".format("xy") 'a00xy' >>> "a{:0>4}".format("xyztu") 'axyztu' This can be modified to limit its arg by specifying a precision: >>> "a{:0>4.4}".format("xyztu") 'axyzt' From pavol.lisy at gmail.com Sat Sep 2 05:12:08 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Sat, 2 Sep 2017 11:12:08 +0200 Subject: If you are running 32-bit 3.6 on Windows, please test this In-Reply-To: References: <2a450525-992c-a417-772f-2eb8eccfe26d@2020fresno.com> Message-ID: On 9/2/17, eryk sun wrote: > On Fri, Sep 1, 2017 at 3:23 AM, Peter Otten <__peter__ at web.de> wrote: >> >> I think you have to specify the types yourself: >> >>>>> import ctypes >>>>> libm = ctypes.cdll.LoadLibrary("libm.so") >>>>> libm.sqrt(42) >> 0 >>>>> libm.sqrt.argtypes = [ctypes.c_double] >>>>> libm.sqrt.restype = ctypes.c_double >>>>> libm.sqrt(42) >> 6.48074069840786 > > On POSIX systems, use ctypes.util.find_library('m'), which, for > example, resolves to "libm.so.6" in Ubuntu Linux 16.04. On the same > system, "libm.so" is an ld script that's used by the compile-time > linker. > > $ cat /usr/lib/x86_64-linux-gnu/libm.so > /* GNU ld script > */ > OUTPUT_FORMAT(elf64-x86-64) > GROUP ( /lib/x86_64-linux-gnu/libm.so.6 > AS_NEEDED ( > /usr/lib/x86_64-linux-gnu/libmvec_nonshared.a > /lib/x86_64-linux-gnu/libmvec.so.1 ) ) > > The runtime linker doesn't know how to handle this script. > > >>> ctypes.CDLL('libm.so') > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python3.5/ctypes/__init__.py", > line 347, in __init__ > self._handle = _dlopen(self._name, mode) > OSError: /usr/lib/x86_64-linux-gnu/libm.so: invalid ELF header Peter and Eryk thanks very much! :) BTW julia on ubuntu 16.04 could do it -> julia> result = ccall((:sqrt, "libm"), Cdouble, (Cdouble,), 1.3) 1.140175425099138 but I am afraid that it probably uses some llvm's magic so it could not help to solve this problem in ctypes... From pavol.lisy at gmail.com Sat Sep 2 06:21:32 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Sat, 2 Sep 2017 12:21:32 +0200 Subject: Case-insensitive string equality In-Reply-To: <59aa15c0$0$1587$c3e8da3$5496439d@news.astraweb.com> References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59aa15c0$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/2/17 at 4:21, Steve D'Aprano wrote: > If regular case-sensitive string comparisons don't support the locale, why > should case-insensitive comparisons be required to? I think that Chris answered very good before: On 9/2/17 at 2:53 AM, Chris Angelico wrote: > On Sat, Sep 2, 2017 at 10:31 AM, Steve D'Aprano > But code is often *wrong* due to backward compatibility concerns. Then you have to > decide whether, for a brand new API, it's better to "do the same as > the regex module" or to "do what the Unicode consortium says". But problem is that if somebody like to have stable API it has to be changed to "do what the Unicode consortium said (at X.Y. ZZZZ)" :/ Maybe it is simpler to write intelligent linter to catch wrong comparisions? From steve+python at pearwood.info Sat Sep 2 06:53:27 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 02 Sep 2017 20:53:27 +1000 Subject: Delay a computation in another thread Message-ID: <59aa8daa$0$1605$c3e8da3$5496439d@news.astraweb.com> I want to delay a computation and then print it, in the REPL (interactive interpreter). I have something like this: import time from threading import Timer def do_work(): x = 2 + 2 print("It is", time.asctime(), "and 2+2 is", x) def schedule_work(): Timer(60, do_work, ()).start() # schedule it in one minute Is this the right way to do it? If I do that, it works, mostly. For example: py> schedule_work() py> dir(45) # do other stuff, in the interactive interpreter, for one minute ['bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 'real', 'to_bytes'] py> py> It is Sat Sep 2 20:37:58 2017 and 2+2 is 4 The problem is that after the message is printed, the REPL's prompt is disrupted. This is especially annoying when I'm in the middle of typing a line. This is just a cosmetic flaw, but it would be nice if I could tell Python to redraw the current line. For example, using _ to indicate the position of the cursor, this is what happens now: py> class K: ... attribute =It is Sat Sep 2 20:48:39 2017 and 2+2 is 4 _ This is what I'd prefer: py> class K: ... attribute =It is Sat Sep 2 20:48:39 2017 and 2+2 is 4 ... attribute =_ The other problem is that if I exit the REPL while a Timer is still active, it freezes until the time has run before exiting. I know you can't kill a thread from the main thread, but is there a way for the Timer to see that the interpreter is shutting down and shut itself down? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Sep 2 06:59:35 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 02 Sep 2017 20:59:35 +1000 Subject: Delay a computation in another thread References: <59aa8daa$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59aa8f1a$0$1601$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Sep 2017 08:53 pm, Steve D'Aprano wrote: > I want to delay a computation and then print it, in the REPL (interactive > interpreter). I have something like this: [...] > The other problem is that if I exit the REPL while a Timer is still active, it > freezes until the time has run before exiting. I know you can't kill a thread > from the main thread, but is there a way for the Timer to see that the > interpreter is shutting down and shut itself down? Oh! I see Timer objects have a cancel method. So I just need an atexit callback function that calls cancel to each of the Timer threads. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sat Sep 2 07:16:33 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Sep 2017 21:16:33 +1000 Subject: Delay a computation in another thread In-Reply-To: <59aa8daa$0$1605$c3e8da3$5496439d@news.astraweb.com> References: <59aa8daa$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 2, 2017 at 8:53 PM, Steve D'Aprano wrote: > The problem is that after the message is printed, the REPL's prompt is > disrupted. This is especially annoying when I'm in the middle of typing a line. > This is just a cosmetic flaw, but it would be nice if I could tell Python to > redraw the current line. For example, using _ to indicate the position of the > cursor, this is what happens now: > > py> class K: > ... attribute =It is Sat Sep 2 20:48:39 2017 and 2+2 is 4 > _ > > > This is what I'd prefer: > > py> class K: > ... attribute =It is Sat Sep 2 20:48:39 2017 and 2+2 is 4 > ... attribute =_ > This is a common problem with a lot of programs. I'd like a solution too; the place I'd go looking would be readline, as that's where most of the work is going to be happening. (Also, if it's added as a readline feature, it won't break redirection or anything like that, as it's specifically a human-interaction thing.) There are three parts to the console output: the prompt ("..."), your input ("attribute ="), and the output message. Only readline knows exactly which parts go where. ChrisA From python at mrabarnett.plus.com Sat Sep 2 13:03:25 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 2 Sep 2017 18:03:25 +0100 Subject: Delay a computation in another thread In-Reply-To: <59aa8f1a$0$1601$c3e8da3$5496439d@news.astraweb.com> References: <59aa8daa$0$1605$c3e8da3$5496439d@news.astraweb.com> <59aa8f1a$0$1601$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3efa7837-1e8f-aa66-f438-db89c0457ced@mrabarnett.plus.com> On 2017-09-02 11:59, Steve D'Aprano wrote: > On Sat, 2 Sep 2017 08:53 pm, Steve D'Aprano wrote: > >> I want to delay a computation and then print it, in the REPL (interactive >> interpreter). I have something like this: > [...] >> The other problem is that if I exit the REPL while a Timer is still active, it >> freezes until the time has run before exiting. I know you can't kill a thread >> from the main thread, but is there a way for the Timer to see that the >> interpreter is shutting down and shut itself down? > > Oh! I see Timer objects have a cancel method. So I just need an atexit callback > function that calls cancel to each of the Timer threads. > Timer is a subclass of Thread, so you can set its .daemon attribute. From charleshixsn at earthlink.net Sat Sep 2 13:53:11 2017 From: charleshixsn at earthlink.net (Charles Hixson) Date: Sat, 2 Sep 2017 10:53:11 -0700 Subject: possible bug in while loop test Message-ID: <70ff1712-e65d-2392-efa4-00454409554b@earthlink.net> python3 --version Python 3.5.3 Running on Debian stretch In this code s is a string parameter while (j < k and \ (s[j].isalnum()) or \ (s[j] in seps and s[j+1].isalnum()) ): j = j + 1 print ("i = {0}, j = {1}, k = {2}, len[s] = {3}". \ format(i, j, k, len(s) ) ) Yields the result: i = 25, j = 27, k = 31, len[s] = 32 i = 25, j = 28, k = 31, len[s] = 32 i = 25, j = 29, k = 31, len[s] = 32 i = 25, j = 30, k = 31, len[s] = 32 i = 25, j = 31, k = 31, len[s] = 32 Traceback (most recent call last): File "parse1.py", line 40, in print (parse1("The gostack distimms the doshes.")) File "parse1.py", line 21, in parse1 (s[j] in seps and s[j+1].isalnum()) ): IndexError: string index out of range I hesitate to report this, because I've been wrong so often, but it looks to me like the last iteration should not have happened since j is not less than k. From eryksun at gmail.com Sat Sep 2 14:16:57 2017 From: eryksun at gmail.com (eryk sun) Date: Sat, 2 Sep 2017 13:16:57 -0500 Subject: Delay a computation in another thread In-Reply-To: <59aa8daa$0$1605$c3e8da3$5496439d@news.astraweb.com> References: <59aa8daa$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Sep 2, 2017 at 5:53 AM, Steve D'Aprano wrote: > > The problem is that after the message is printed, the REPL's prompt is > disrupted. This is especially annoying when I'm in the middle of typing a line. > This is just a cosmetic flaw, but it would be nice if I could tell Python to > redraw the current line. This would be difficult on Windows. When the REPL reads from the console, the main thread blocks on a system call, which varies depending on the versions of Python and Windows. This is a remote procedure call to the console host process (e.g. conhost.exe in Windows 7+), which handles the cooked read while Python waits for the result. To get the level of control you're asking for, we'd have to implement readline for the Windows console using low-level console functions such as ReadConsoleInput. pyreadline currently implements this via ctypes, but CPython would need a C extension. From __peter__ at web.de Sat Sep 2 15:36:47 2017 From: __peter__ at web.de (Peter Otten) Date: Sat, 02 Sep 2017 21:36:47 +0200 Subject: possible bug in while loop test References: <70ff1712-e65d-2392-efa4-00454409554b@earthlink.net> Message-ID: Charles Hixson wrote: > python3 --version > Python 3.5.3 > > Running on Debian stretch > > In this code s is a string parameter > > while (j < k and \ > (s[j].isalnum()) or \ > (s[j] in seps and s[j+1].isalnum()) ): > j = j + 1 > print ("i = {0}, j = {1}, k = {2}, len[s] = {3}". \ > format(i, j, k, len(s) ) ) > > Yields the result: > > i = 25, j = 27, k = 31, len[s] = 32 > i = 25, j = 28, k = 31, len[s] = 32 > i = 25, j = 29, k = 31, len[s] = 32 > i = 25, j = 30, k = 31, len[s] = 32 > i = 25, j = 31, k = 31, len[s] = 32 > Traceback (most recent call last): > File "parse1.py", line 40, in > print (parse1("The gostack distimms the doshes.")) > File "parse1.py", line 21, in parse1 > (s[j] in seps and s[j+1].isalnum()) ): > IndexError: string index out of range > > I hesitate to report this, because I've been wrong so often, but it > looks to me like the last iteration should not have happened since j is > not less than k. You have made a bit of a mess of the while condition. Removing random space and newlines: (j < k and (s[j].isalnum()) or (s[j] in seps and s[j+1].isalnum())) The structure is a and b or (c and d) # a: j False as you suspect, but then (c and d) is evalued, and if c succeeds also the expression d aka s[j+1].isalnum() which fails on accessing s[j+1]. From python at mrabarnett.plus.com Sat Sep 2 16:40:22 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 2 Sep 2017 21:40:22 +0100 Subject: possible bug in while loop test In-Reply-To: <70ff1712-e65d-2392-efa4-00454409554b@earthlink.net> References: <70ff1712-e65d-2392-efa4-00454409554b@earthlink.net> Message-ID: On 2017-09-02 18:53, Charles Hixson wrote: > python3 --version > Python 3.5.3 > > Running on Debian stretch > > In this code s is a string parameter > > while (j < k and \ > (s[j].isalnum()) or \ > (s[j] in seps and s[j+1].isalnum()) ): > j = j + 1 > print ("i = {0}, j = {1}, k = {2}, len[s] = {3}". \ > format(i, j, k, len(s) ) ) > > Yields the result: > > i = 25, j = 27, k = 31, len[s] = 32 > i = 25, j = 28, k = 31, len[s] = 32 > i = 25, j = 29, k = 31, len[s] = 32 > i = 25, j = 30, k = 31, len[s] = 32 > i = 25, j = 31, k = 31, len[s] = 32 > Traceback (most recent call last): > File "parse1.py", line 40, in > print (parse1("The gostack distimms the doshes.")) > File "parse1.py", line 21, in parse1 > (s[j] in seps and s[j+1].isalnum()) ): > IndexError: string index out of range > > I hesitate to report this, because I've been wrong so often, but it > looks to me like the last iteration should not have happened since j is > not less than k. > The last iteration happened because j < k when you tested the while loop's condition. You then added 1 to j before printing out j and k. At this print, j >= k. From thecjguy1 at gmail.com Sat Sep 2 18:34:35 2017 From: thecjguy1 at gmail.com (Chris Roberts) Date: Sat, 2 Sep 2017 15:34:35 -0700 (PDT) Subject: Python... feeding an instance as an argument into a new instance. Message-ID: <422617d2-f64f-4c39-975f-bae6debb34a8@googlegroups.com> Perhaps someone here could help me to get this into perspective. Somehow when we start to feed an instance as the argument in a new instance. my head explodes.. in this case... a = Foo() b = Bar(a) So... a is a 'Foo instance' with properties and methods. b is a 'Bar instance' Since b is using the "a" instance as an argument?? b=Bar(a) has what?? Is there an easier way to put into perspective how an instance of one class is used as the argument into the instance of another class? Code below: class Foo(object): bar = "Bar" # Class attribute. def __init__(self): # #^ The first variable is the class instance in methods. # # This is called "self" by convention, but could be any name you want. # ^ double underscore (dunder) methods are usually special. This one # gets called immediately after a new instance is created. self.variable = "Foo" # instance attribute. print self.variable, self.bar # <---self.bar references class attribute self.bar = " Bar is now Baz" # <---self.bar is now an instance attribute print self.variable, self.bar #variable will be a property of "a" and self is the bound variable of a. def method(self, arg1, arg2): # This method has arguments. You would call it like this: instance.method(1, 2) print "in method (args):", arg1, arg2 print "in method (attributes):", self.variable, self.bar a = Foo() # this calls __init__ (indirectly), output: #a is Foo, a has a method called method, and properties such as "variable and bar". # Foo bar # Foo Bar is now Baz print a.variable # Foo a.variable = "bar" a.method(1, 2) # output: # in method (args): 1 2 # in method (attributes): bar Bar is now Baz Foo.method(a, 1, 2) # <--- Same as a.method(1, 2). This makes it a little more explicit what the argument "self" actually is. print "##Above is all the a Foo object, and below is the b Bar object" class Bar(object): def __init__(self, arg): self.arg = arg self.Foo = Foo() #this calls and runs the Foo class again. b = Bar(a) #b is a Bar object, a is a Foo object with properties and methods. then Bar() calls the Foo class again. b.arg.variable = "something" print a.variable # something !(I don't know why "a" prints "something" here.) print b.Foo.variable # Foo #### OUTPUT: Foo Bar Foo Bar is now Baz Foo in method (args): 1 2 in method (attributes): bar Bar is now Baz in method (args): 1 2 in method (attributes): bar Bar is now Baz ##Above is all the a Foo object, and below is the b Bar object Foo Bar Foo Bar is now Baz something Foo #### Thanks in advance... crzzy1 ... From Irv at furrypants.com Sat Sep 2 19:36:37 2017 From: Irv at furrypants.com (Irv Kalb) Date: Sat, 2 Sep 2017 16:36:37 -0700 Subject: Python... feeding an instance as an argument into a new instance. In-Reply-To: <422617d2-f64f-4c39-975f-bae6debb34a8@googlegroups.com> References: <422617d2-f64f-4c39-975f-bae6debb34a8@googlegroups.com> Message-ID: <503FB4E9-CAF9-4BAD-868D-72CED596F530@furrypants.com> > On Sep 2, 2017, at 3:34 PM, Chris Roberts wrote: > > Perhaps someone here could help me to get this into perspective. > Somehow when we start to feed an instance as the argument in a new instance. my head explodes.. > in this case... > a = Foo() > b = Bar(a) > So... > a is a 'Foo instance' with properties and methods. > b is a 'Bar instance' > Since b is using the "a" instance as an argument?? > b=Bar(a) has what?? > Unfortunately, the example that you are using serves to conflate a number of things. For example, You have a class called Bar, a class variable inside the Foo class called bar, that variable has the value "Bar", in the __init__ method there is also self.bar. I can see why you are confused. But to try to answer you question, you are asking what happens when you do: b = Bar(a) That says, create an instance of the class Bar, pass in a as an argument, and assign the returned value to b. When that executes, the __init__ method of Bar runs class Bar(object): def __init__(self, arg): self.arg = arg self.Foo = Foo() #this calls and runs the Foo class again. it assigns the value that is passed in (the instance of the Foo object), to the local parameter "arg". The first assignment statement, says, copy that value into an instance variable called self.arg. So, now self.arg which lives inside the new instance of the Bar class (called b), now has a reference to the a object that was created earlier. That's all fine. In the next line, you are creating a new instance of the Foo class, and assigning the result to a different instance variable called self.Foo. (This is also extremely confusing in terms of names.) Bottom line, after running the code, a refers to an instance of the Foo object. b now has two instance variables, which refer to two different instances of the Foo object. The first one (self.arg) refers to the same instance as a. The second one refers to a second of a Foo object. You can see this if you add print statements: class Bar(object): def __init__(self, arg): self.arg = arg self.Foo = Foo() #this calls and runs the Foo class again. print('self.arg', self.arg) print('self.Foo', self.Foo) If you also print out the value of a right after you create it, you will find that it matches the value of self.arg in b. Two references to the same object. Hope that helps, Irv From tjreedy at udel.edu Sat Sep 2 19:53:01 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 2 Sep 2017 19:53:01 -0400 Subject: Delay a computation in another thread In-Reply-To: <59aa8daa$0$1605$c3e8da3$5496439d@news.astraweb.com> References: <59aa8daa$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/2/2017 6:53 AM, Steve D'Aprano wrote: > I want to delay a computation and then print it, in the REPL (interactive > interpreter). I have something like this: > > > import time > from threading import Timer > > def do_work(): > x = 2 + 2 > print("It is", time.asctime(), "and 2+2 is", x) > > def schedule_work(): > Timer(60, do_work, ()).start() # schedule it in one minute > > > Is this the right way to do it? > > If I do that, it works, mostly. For example: > > py> schedule_work() > py> dir(45) # do other stuff, in the interactive interpreter, for one minute > ['bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 'real', 'to_bytes'] > py> > py> It is Sat Sep 2 20:37:58 2017 and 2+2 is 4 > > > The problem is that after the message is printed, the REPL's prompt is > disrupted. This is especially annoying when I'm in the middle of typing a line. > This is just a cosmetic flaw, but it would be nice if I could tell Python to > redraw the current line. For example, using _ to indicate the position of the > cursor, this is what happens now: > > py> class K: > ... attribute =It is Sat Sep 2 20:48:39 2017 and 2+2 is 4 > _ > > > This is what I'd prefer: > > py> class K: > ... attribute =It is Sat Sep 2 20:48:39 2017 and 2+2 is 4 > ... attribute =_ I loaded your code into IDLE editor, hit F5, then interactively in Shell: >>> schedule_work() >>> It is Sat Sep 2 19:13:44 2017 and 2+2 is 4 "thei is kjlkj jjdkj f jkjkd j" 'thei is kjlkj jjdkj f jkjkd j' With a 10sec delay, I was near the end of typing the statement after the prompt. When the print came, the partial entry was pushed down to a new line. I think that this is even better than what you asked for. I closed the string and hit return and got the normal echo. If one is entering a multiple line statement, the whole statement is pushed down. >>> go() >>> It is Sat Sep 2 19:42:10 2017 and 2+2 is 4 a = ( 12, IDLE usually keeps input blocks, output blocks, and error blocks separated, on separate lines. Response to input(prompt) is an exception. There is also an ocassional bug that I cannot reproduce yet. I consider not moving the prompt down a minor bug. bugs.python.org/issue31331 > The other problem is that if I exit the REPL while a Timer is still active, it > freezes until the time has run before exiting. I know you can't kill a thread > from the main thread, but is there a way for the Timer to see that the > interpreter is shutting down and shut itself down? If you kill a process from another process, it should die. It does with your code run from IDLE. On Windows, the background user-code execution process start at 11.x Mb. In Win 10 task manager, background processes are listed separately from app windows. I restored 60 sec delay and added s = 'a'*10000000 near the top of your code to differentiate a process with your code from the default user process. ======================= RESTART: F:\Python\mypy\tem.py ======================= >>> schedule_work() >>> # Hit Restart Shell =============================== RESTART: Shell =============================== >>> Restart Shell means kill the current user process and start a new one. Watching TackManager while doing so, the 20+Mb process is immediately replaced by a default 10+Mb process. Closing Shell justs kills the 20+Mb process. -- Terry Jan Reedy From cfkaran2 at gmail.com Sat Sep 2 20:44:21 2017 From: cfkaran2 at gmail.com (CFK) Date: Sat, 2 Sep 2017 20:44:21 -0400 Subject: Battle of the garbage collectors, or ARGGHHHHHH!!!! In-Reply-To: <4CB44371-19CA-4463-B576-DDA570F8879E@gmail.com> References: <4CB44371-19CA-4463-B576-DDA570F8879E@gmail.com> Message-ID: On Wed, Apr 26, 2017 at 10:38 PM, Cem Karan wrote: > > On Apr 24, 2017, at 8:54 PM, Jon Ribbens > wrote: > > > On 2017-04-24, CFK wrote: > >> Long version: I'm trying to write bindings for python via ctypes to > control > >> a library written in C that uses the bdwgc garbage collector ( > >> http://www.hboehm.info/gc/). The bindings mostly work, except for when > >> either bdwgc or python's garbage collector decide to get into an > argument > >> over what is garbage and what isn't, in which case I get a segfault > because > >> one or the other collector has already reaped the memory. > > > > Make your Python C objects contain a pointer to a > > GC_MALLOC_UNCOLLECTABLE block that contains a pointer to the > > bwdgc object it's an interface to? And GC_FREE it in tp_dealloc? > > Then bwdgc won't free any C memory that Python is referencing. > > OK, I realized today that there was a miscommunication somewhere. My > python code is all pure python, and the library is pure C, and it is not > designed to be called by python (it's intended to be language neutral, so > if someone wants to call it from a different language, they can). That > means that tp_dealloc (which is part of the python C API) is probably not > going to work. > > I got interrupted (again) so I didn't have a chance to try the next trick > and register the ctypes objects as roots from which to scan in bdwgc, but > I'm hoping that roots aren't removed. If that works, I'll post it to the > list. > > Thanks, > Cem Karan Right, apparently I win at the 'late reply' game. That said, I wanted to give Jon Ribbens credit for his idea, because it was very close to what I used in the end. The only difference is that I also used weakref.finalize() to tie a finalizer to the lifetime of the ctypes pointer that I was using. The finalizer called GC_FREE() to free the uncollectable block, which allowed the C allocator to cleanup memory. The only thing I never figured out was how to get a C block to hold onto python memory. I didn't need it, but it felt like it would make for a nice duality with the method above. Thanks, Cem Karan From steve+python at pearwood.info Sat Sep 2 20:45:03 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 03 Sep 2017 10:45:03 +1000 Subject: Python... feeding an instance as an argument into a new instance. References: <422617d2-f64f-4c39-975f-bae6debb34a8@googlegroups.com> Message-ID: <59ab5092$0$1607$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Sep 2017 08:34 am, Chris Roberts wrote: > Perhaps someone here could help me to get this into perspective. > Somehow when we start to feed an instance as the argument in a new instance. > my head explodes.. in this case... > a = Foo() > b = Bar(a) > So... > a is a 'Foo instance' with properties and methods. > b is a 'Bar instance' > Since b is using the "a" instance as an argument?? > b=Bar(a) has what?? It has attributes and methods, same as any other instance of any other class. I think you are overthinking it. Or perhaps underthinking it. In either case, using generic nonsense classes like Foo and Bar adds no understanding. Suppose you build an Engine class: class Engine: def __init__(self, fuel, capacity): self.sparkplugs = [SparkPlug() for i in range(4)] ... def start(self): ... def stop(self): ... So Engines have methods, and attributes such as capacity, the kind of fuel they run on (petrol/gasoline, diesel or LPG), etc. Some attributes (such as the sparkplugs) are themselves instances of another class. Now we build a car out of other objects: class Car: def __init__(self, colour, engine, chassis, seats, dashboard, wheels, brakes, parkingbrake, airbags, entertainment_system): self.colour = colour self.body = chassis.add_panels() self.engine = engine ... def drive(self): ... def reverse(self): ... def engage_parking_brake(self): ... So Cars have methods, and attributes such as colour, engine, brakes, airbags, etc. Some of those attributes are themselves made of instances of another class. In fact even "primitive" values such as ints, floats, lists, strings, tuples, boolean flags etc are objects in Python. In Python, it is objects all the way down: all values are objects. Does this answer your question? If not, I'm afraid I don't understand your question. Would you like to re-phrase it and explain? Thanks. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From stephanh42 at gmail.com.invalid Sun Sep 3 03:17:44 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 03 Sep 2017 07:17:44 GMT Subject: Case-insensitive string equality References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59aa15c0$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: Op 2017-09-02, Pavol Lisy schreef : > But problem is that if somebody like to have stable API it has to be > changed to "do what the Unicode consortium said (at X.Y. ZZZZ)" :/ It is even more exciting. Presumably a reason to have case-insentivity is to be compatible with existing popular case-insentive systems. So here is, for your entertainment, how some of these systems work. * Windows NTFS case-insensitive file system A NTFS file system contains a hidden table $UpCase which maps characters to their upcase variant. Note: 1. This maps characters in the BMP *only*, so NTFS treats characters outside the BMP as case-insensitive. 2. Every character can in turn only be mapped into a single BMP character, so ? -> SS is not possible. 3. The table is in practice dependent on the language of the Windows system which created it (so a Turkish NTFS partition would contain i -> ?), but in theory can contain any allowed mapping: I can create an NTFS filesystem which maps a -> b. 4. Older Windows versions generated tables which were broken for certain languages (NT 3.51/Georgian). You may still have some NTFS partition with such a table lying around. * macOS case-insensitive file system 1. HFS+ is based on Unicode 3.2; this is fixed in stone because of backward compatibility. 2. APFS is based on Unicode 9.0 and does normalization as well Generally speaking, the more you learn about case normalization, the more attractive case sensitivity looks ;-) Also slim hope to have a single caseInsensitiveCompare function which "Does The Right Thing"?. Stephan From stephanh42 at gmail.com.invalid Sun Sep 3 05:16:13 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 03 Sep 2017 09:16:13 GMT Subject: tkinter keypress events are a mess for numpad keys References: <59a4a532$0$789$e4fe514c@news.xs4all.nl> <59a5a16b$0$752$e4fe514c@news.xs4all.nl> Message-ID: Op 2017-08-29, Irmen de Jong schreef : > I'll have a look at https://www.tcl.tk/man/tcl8.6/TkCmd/keysyms.htm > but I don't have high hopes because I already tried empirically to > figure out the distinguishing attributes of the keypress event object, > on various platforms (Mac OS, Linux, Windows)... I would suggest trying to reproduce the issue in a small Tcl/Tk script. If the issue can be reproduced in Tcl I would suggest filing a bug report at https://core.tcl.tk/tk/reportlist . Stephan From viktorovichandrej at gmail.com Sun Sep 3 07:21:01 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Sun, 3 Sep 2017 04:21:01 -0700 (PDT) Subject: meaning of [ ] Message-ID: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> Hello, Trying to understand command: [p for p in sys.path] It prints array of paths. I suppose p becomes array of strings but what [] means in this statement? From rantingrickjohnson at gmail.com Sun Sep 3 07:31:11 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 3 Sep 2017 04:31:11 -0700 (PDT) Subject: tkinter keypress events are a mess for numpad keys In-Reply-To: <59a4a532$0$789$e4fe514c@news.xs4all.nl> References: <59a4a532$0$789$e4fe514c@news.xs4all.nl> Message-ID: Irmen de Jong wrote: > Using tkinter in python3, I was trying to intercept > individual keypresses (and releases) of keys on the numeric > keypad. I want to use this as a simple joystick simulation. > While you can bind the event, actually doing > something sensible with it in a cross platform way seems > utterly impossible. Personally, none of my applications have needed to differentiate between the "number-keys-on-the-keypad" and the "number-keys-on-the-main-keyboard", so i'm not sure if there is a clean solution here, much less a clean cross- platform solution... And although my initial reaction to your inquiry (assuming there is no clean solution here...) was to lay blame on tkinter for not observing its own cross-platform mandate, the more i think about this, the more i wonder if tkinter _should_ differentiate between these duplicate number keys? Hmm... Considering that (at a very high level) the sole purpose of a keyboard is to send character information to a machine by mapping keypresses to characters -- and not so much concerning itself with key locations or duplicate keys -- i think what you are doing is expecting a keyboard to function in a manner for which it was not intented to function, and while i'm a big fan of multi-purpose tools, i understand also the practical importance of simplistic, single-purpose design. What are your thoughts on this? > The distinguishing attribute of the event object is > different depending on what OS you're using (keysym, > keycode, keysym_num) and on Windows registering some keys > doesn't even seem to work (or they're confused with the > same keys on the normal keyboard area). The keysym > names/values in the documentation are not correct either Barring a clean cross-platform solution, i would suggest one of the following: (1) Appeal to the Tcl/Tk folks to standardize these "event codes". After all, _they_ are the ones who market TK as a cross platform GUI. or (2) Create your own mapping that can translate the keycodes, keysyms, or keysym_nums to something consistent between the platforms. I have a feeling that #2 will be more efficient. The good new is, that if the number keys (0-9) are your only concern, then we're only talking about ten keys over three major platforms here -- so (10 x 3 = 30) mappings -- shouldn't be too difficult. Of course, with solution #2 your code will be at the mercy of future changes that are beyond your control (aka: brittle), however, i doubt these codes would change very much over time, if at all. A simple template might look something like this: evtMap = {...} w.bind("", _evtKeyPress) def _evtTrans(event): ... def _evtKeyPress(event): _evtTrans(event) # Process event here... Sucks to do this, but sometimes you have no choice. PS: If i had nickle for every time i had to take a big hammer and pound dents out of tkinter's hull to achieve a more elegant work flow, well, you know the story. Tkinter may be a rusty old tub, but she gets the job done if you're willing to periodically scrape the barnacles from her belly, patch the holes and apply a new coat of lead paint. As any old salt will testify, she's a labour of love. From __peter__ at web.de Sun Sep 3 07:34:20 2017 From: __peter__ at web.de (Peter Otten) Date: Sun, 03 Sep 2017 13:34:20 +0200 Subject: meaning of [ ] References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> Message-ID: Andrej Viktorovich wrote: > Hello, > > Trying to understand command: > [p for p in sys.path] > > It prints array of paths. I suppose p becomes array of strings but what [] > means in this statement? This is called "list comprehension", and paths = [p for p in sys.path if "foo" in p] is roughly equivalent to paths = [] for p in sys.path: if "foo" in p: paths.append(p) Your original example > [p for p in sys.path] just copies the items from sys.path into a new list. This is usually done with the more concise list(sys.path) From thecjguy1 at gmail.com Sun Sep 3 07:35:52 2017 From: thecjguy1 at gmail.com (Chris Roberts) Date: Sun, 3 Sep 2017 04:35:52 -0700 (PDT) Subject: Python... feeding an instance as an argument into a new instance. In-Reply-To: <422617d2-f64f-4c39-975f-bae6debb34a8@googlegroups.com> References: <422617d2-f64f-4c39-975f-bae6debb34a8@googlegroups.com> Message-ID: On Saturday, September 2, 2017 at 6:34:59 PM UTC-4, Chris Roberts wrote: > Perhaps someone here could help me to get this into perspective. > Somehow when we start to feed an instance as the argument in a new instance. my head explodes.. > in this case... > a = Foo() > b = Bar(a) > So... > a is a 'Foo instance' with properties and methods. > b is a 'Bar instance' > Since b is using the "a" instance as an argument?? > b=Bar(a) has what?? > > Is there an easier way to put into perspective how an instance of one class is used as the argument into the instance of another class? > > Code below: > > class Foo(object): > bar = "Bar" # Class attribute. > > def __init__(self): > # #^ The first variable is the class instance in methods. > # # This is called "self" by convention, but could be any name you want. > # ^ double underscore (dunder) methods are usually special. This one > # gets called immediately after a new instance is created. > > self.variable = "Foo" # instance attribute. > print self.variable, self.bar # <---self.bar references class attribute > self.bar = " Bar is now Baz" # <---self.bar is now an instance attribute > print self.variable, self.bar #variable will be a property of "a" and self is the bound variable of a. > > def method(self, arg1, arg2): > # This method has arguments. You would call it like this: instance.method(1, 2) > print "in method (args):", arg1, arg2 > print "in method (attributes):", self.variable, self.bar > > > a = Foo() # this calls __init__ (indirectly), output: > #a is Foo, a has a method called method, and properties such as "variable and bar". > # Foo bar > # Foo Bar is now Baz > print a.variable # Foo > a.variable = "bar" > a.method(1, 2) # output: > # in method (args): 1 2 > # in method (attributes): bar Bar is now Baz > Foo.method(a, 1, > 2) # <--- Same as a.method(1, 2). This makes it a little more explicit what the argument "self" actually is. > print "##Above is all the a Foo object, and below is the b Bar object" > > class Bar(object): > def __init__(self, arg): > self.arg = arg > self.Foo = Foo() #this calls and runs the Foo class again. > > > b = Bar(a) #b is a Bar object, a is a Foo object with properties and methods. then Bar() calls the Foo class again. > b.arg.variable = "something" > print a.variable # something !(I don't know why "a" prints "something" here.) > print b.Foo.variable # Foo > > #### > OUTPUT: > Foo Bar > Foo Bar is now Baz > Foo > in method (args): 1 2 > in method (attributes): bar Bar is now Baz > in method (args): 1 2 > in method (attributes): bar Bar is now Baz > ##Above is all the a Foo object, and below is the b Bar object > Foo Bar > Foo Bar is now Baz > something > Foo > > #### Thanks in advance... crzzy1 ... Steve and Irv, I see what you mean... I picked up on this example online and then tried to work it out on my own, but after seeing your replies, and looking further into cars examples I found how much more intuitive that makes it... Anyways, now I know where to better redirect my studies and energies. My work is sending me to a semi advanced (Core Python) class, and I am not ready, so trying to work on all my weak spots. Thanks From rantingrickjohnson at gmail.com Sun Sep 3 07:39:51 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 3 Sep 2017 04:39:51 -0700 (PDT) Subject: meaning of [ ] In-Reply-To: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> Message-ID: <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> Andrej Viktorovich wrote: > I suppose p becomes array of strings but what [] means in this statement? Generally, it's an inline form of writing a loop that returns a list. There are other types as well. https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions From rosuav at gmail.com Sun Sep 3 08:07:23 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Sep 2017 22:07:23 +1000 Subject: Case-insensitive string equality In-Reply-To: References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59aa15c0$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Sep 3, 2017 at 5:17 PM, Stephan Houben wrote: > Generally speaking, the more you learn about case normalization, > the more attractive case sensitivity looks ;-) Absolutely agreed. My general recommendation is to have two vastly different concepts: "equality matching" and "searching". Equality is case sensitive and strict; NFC/NFD normalization is about all you can do. Searching, on the other hand, can be case insensitive, do NFKC/NFKD normalization, and can even (in many contexts) strip off diacritical marks altogether, allowing people to search for "resume" and find "r?sum?", or to search for "muller" and find "M?ller". There can be a whole swathe of other transformations done in search normalization too (collapse whitespace, fold punctuation into a few types, etc), though of course you need to be aware of context. But IMO it's far safer to NOT define things in terms of "equality". ChrisA From rantingrickjohnson at gmail.com Sun Sep 3 08:22:42 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 3 Sep 2017 05:22:42 -0700 (PDT) Subject: Python... feeding an instance as an argument into a new instance. In-Reply-To: <59ab5092$0$1607$c3e8da3$5496439d@news.astraweb.com> References: <422617d2-f64f-4c39-975f-bae6debb34a8@googlegroups.com> <59ab5092$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: <226a8292-1b44-4c77-87b0-20f6eb0a2f06@googlegroups.com> On Saturday, September 2, 2017 at 7:45:14 PM UTC-5, Steve D'Aprano wrote: > On Sun, 3 Sep 2017 08:34 am, Chris Roberts wrote: > > > Perhaps someone here could help me to get this into > > perspective. Somehow when we start to feed an instance as > > the argument in a new instance. my head explodes.. in this > > case... > > > > a = Foo() > > b = Bar(a) > > > > So... a is a 'Foo instance' with properties and methods. b > > is a 'Bar instance' Since b is using the "a" instance as > > an argument?? b=Bar(a) has what?? > > It has attributes and methods, same as any other instance > of any other class. I think you are overthinking it. Or > perhaps underthinking it. In either case, using generic > nonsense classes like Foo and Bar adds no understanding. Yes. Even for seasoned programmers, generic names can obfuscate the overall model. And such names have no business in beginner, or even intermediate, coarses. > Suppose you build an Engine class: > > class Engine: > def __init__(self, fuel, capacity): > self.sparkplugs = [SparkPlug() for i in range(4)] Steven, why am i _not_ surprised that you drive a four-banger? ;-) > ... > def start(self): > ... > def stop(self): > ... > > So Engines have methods, and attributes such as capacity, > the kind of fuel they run on (petrol/gasoline, diesel or > LPG), etc. Some attributes (such as the sparkplugs) are > themselves instances of another class. Now we build a car > out of other objects: > > class Car: > def __init__(self, colour, engine, chassis, seats, dashboard, wheels, > brakes, parkingbrake, airbags, entertainment_system): > self.colour = colour > self.body = chassis.add_panels() > self.engine = engine > ... > def drive(self): This should be named "forward", as: (1) such a name meshes semantically against the "reverse" method, and (2) such a name clearly defines an intuitive vector path that is consistent with the car's three dimensional orientation, _orientation_ which is constrained by the mechanical capabilities of the car, and _mechanical_capabilities_, which are further constrained by the laws of physics. "Drive" is just too ambiguous. > ... > def reverse(self): > ... > def engage_parking_brake(self): > ... > > So Cars have methods, and attributes such as colour, > engine, brakes, airbags, etc. Some of those attributes are > themselves made of instances of another class. In fact > even "primitive" values such as ints, floats, lists, > strings, tuples, boolean flags etc are objects in Python. > In Python, it is objects all the way down: all values are > objects. Overall though, a very good introductory example of OOP. Good work Steven! We're going to make an OOP fan out of you yet, and given enough time, heck, you may even begin to appreciate the purity of Java. ;-) From g.morkvenas at gmail.com Sun Sep 3 08:56:54 2017 From: g.morkvenas at gmail.com (g.morkvenas at gmail.com) Date: Sun, 3 Sep 2017 05:56:54 -0700 (PDT) Subject: Run Windows commands from Python console Message-ID: <83ebc433-d457-408b-b43a-4b00a3206728@googlegroups.com> Hello, I run Python console in Windows. Can I run cmd prompt commands there? If I run command dir I have: >>> dir What does it means? If i trying to create file I have error: >>> type NUL > hh.txt File "", line 1 type NUL > hh.txt ^ SyntaxError: invalid syntax What means line below: File "", line 1 I don't have any file. From rantingrickjohnson at gmail.com Sun Sep 3 10:00:01 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 3 Sep 2017 07:00:01 -0700 (PDT) Subject: Run Windows commands from Python console In-Reply-To: <83ebc433-d457-408b-b43a-4b00a3206728@googlegroups.com> References: <83ebc433-d457-408b-b43a-4b00a3206728@googlegroups.com> Message-ID: On Sunday, September 3, 2017 at 7:57:14 AM UTC-5, g.mor... at gmail.com wrote: > Hello, > > I run Python console in Windows. Can I run cmd prompt commands there? > > If I run command dir I have: > > >>> dir > > > What does it means? It means that the expression `dir` (in python's universe) is a symbol for the built-in function named "dir", and when you send a symbol to the python interpreter in interactive mode, all python will do is send back some info about the symbol. In this case, Python is telling you that the symbol `dir` is not only a function object, it is a _built-in_ function object. To actually _invoke_ a python function -- even when the function requires no arguments (as is the case with "dir") -- you must use enclosing parentheses. Try this instead: >>> dir() ['__builtins__', '__doc__', '__name__', '__package__'] Some languages will allow you to omit the parentheses when calling a function that requires no arguments, but python does not work that way; and i'm glad too, because i have a very low tolerance for inconsistency. Just ask anyone here who knows me! O:-) > If i trying to create file I have error: > > >>> type NUL > hh.txt > File "", line 1 > type NUL > hh.txt > ^ > SyntaxError: invalid syntax That's not how you create a file with Python! To read or write files, try using the built-in function named "open": >>> fileObj = open("NEW_OR_EXISTING_FILENAME_HERE", 'w') # Write or >>> fileObj = open("EXISTING_FILENAME_HERE", 'r') # Read > What means line below: > > File "", line 1 > > I don't have any file. Sure you do, it's just not readily apparent. Python provides a "stdin" (aka: Standard Input) for which input can be received, and a "stdout" (aka: Standard Output) so that output can be, well, for lack of better word: "outputted". In fact, the built-in "print function" and built-in "input function" are just wrappers around `sys.stdout.write(...)` and `sys.stdin.readline('...')` respectively, and if you don't believe me, then type this: >>> import sys >>> sys.stdout.write('Python rules!\n') Python rules! >>> value = sys.stdin.readline() this is input! # <-- Type this yourself! >>> value 'this is input!\n' The same result can be achieved using the more powerful and elegant built-in functions: >>> value = input('Type Something Interesting: ') Type Something Interesting: blah >>> value 'blah' >>> print('Python Rules!') Python Rules! You can view these "file streams" by importing the "sys" module and typing `sys.stdin` or `sys.stdout` at the command line, and, depending on where you type these commands, you may receive different results for the streams as they can be captured and redefined by unique interactive environments. Here is session from IDLE (Python's built-in code editor): >>> sys.stdin >>> sys.stdout As you can see, IDLE has captured these streams, so you'll get a different result if you run the commands from a windows prompt in python mode, or a unique environment. You can even capture these streams for yourself, which is helpful for logging purposes. Consult the "sys" module docs for more details.... From g.rodola at gmail.com Sun Sep 3 10:58:35 2017 From: g.rodola at gmail.com (Giampaolo Rodola') Date: Sun, 3 Sep 2017 22:58:35 +0800 Subject: ANN: psutil 5.3.0 with full unicode support is out Message-ID: Hello all, I'm glad to announce the release of psutil 5.3.0: https://github.com/giampaolo/psutil A blogpost describing the main changes is available here: http://grodola.blogspot.com/2017/09/psutil-530-with-full-unicode-support-is.html About ===== psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) in Python. It is useful mainly for system monitoring, profiling and limiting process resources and management of running processes. It implements many functionalities offered by command line tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It currently supports Linux, Windows, OSX, Sun Solaris, FreeBSD, OpenBSD and NetBSD, both 32-bit and 64-bit architectures, with Python versions from 2.6 to 3.5 (users of Python 2.4 and 2.5 may use 2.1.3 version). PyPy is also known to work. What's new ========== **Enhancements** - #802: disk_io_counters() and net_io_counters() numbers no longer wrap (restart from 0). Introduced a new "nowrap" argument. - #928: psutil.net_connections() and psutil.Process.connections() "laddr" and "raddr" are now named tuples. - #1015: swap_memory() now relies on /proc/meminfo instead of sysinfo() syscall so that it can be used in conjunction with PROCFS_PATH in order to retrieve memory info about Linux containers such as Docker and Heroku. - #1022: psutil.users() provides a new "pid" field. - #1025: process_iter() accepts two new parameters in order to invoke Process.as_dict(): "attrs" and "ad_value". With this you can iterate over all processes in one shot without needing to catch NoSuchProcess and do list/dict comprehensions. - #1040: implemented full unicode support. - #1051: disk_usage() on Python 3 is now able to accept bytes. - #1058: test suite now enables all warnings by default. - #1060: source distribution is dynamically generated so that it only includes relevant files. - #1079: [FreeBSD] net_connections()'s fd number is now being set for real (instead of -1). (patch by Gleb Smirnoff) - #1091: [SunOS] implemented Process.environ(). (patch by Oleksii Shevchuk) **Bug fixes** - #989: [Windows] boot_time() may return a negative value. - #1007: [Windows] boot_time() can have a 1 sec fluctuation between calls; the value of the first call is now cached so that boot_time() always returns the same value if fluctuation is <= 1 second. - #1013: [FreeBSD] psutil.net_connections() may return incorrect PID. (patch by Gleb Smirnoff) - #1014: [Linux] Process class can mask legitimate ENOENT exceptions as NoSuchProcess. - #1016: disk_io_counters() raises RuntimeError on a system with no disks. - #1017: net_io_counters() raises RuntimeError on a system with no network cards installed. - #1021: [Linux] open_files() may erroneously raise NoSuchProcess instead of skipping a file which gets deleted while open files are retrieved. - #1029: [OSX, FreeBSD] Process.connections('unix') on Python 3 doesn't properly handle unicode paths and may raise UnicodeDecodeError. - #1033: [OSX, FreeBSD] memory leak for net_connections() and Process.connections() when retrieving UNIX sockets (kind='unix'). - #1040: fixed many unicode related issues such as UnicodeDecodeError on Python 3 + UNIX and invalid encoded data on Windows. - #1042: [FreeBSD] psutil won't compile on FreeBSD 12. - #1044: [OSX] different Process methods incorrectly raise AccessDenied for zombie processes. - #1046: [Windows] disk_partitions() on Windows overrides user's SetErrorMode. - #1047: [Windows] Process username(): memory leak in case exception is thrown. - #1048: [Windows] users()'s host field report an invalid IP address. - #1050: [Windows] Process.memory_maps memory() leaks memory. - #1055: cpu_count() is no longer cached; this is useful on systems such as Linux where CPUs can be disabled at runtime. This also reflects on Process.cpu_percent() which no longer uses the cache. - #1058: fixed Python warnings. - #1062: disk_io_counters() and net_io_counters() raise TypeError if no disks or NICs are installed on the system. - #1063: [NetBSD] net_connections() may list incorrect sockets. - #1064: [NetBSD] swap_memory() may segfault in case of error. - #1065: [OpenBSD] Process.cmdline() may raise SystemError. - #1067: [NetBSD] Process.cmdline() leaks memory if process has terminated. - #1069: [FreeBSD] Process.cpu_num() may return 255 for certain kernel processes. - #1071: [Linux] cpu_freq() may raise IOError on old RedHat distros. - #1074: [FreeBSD] sensors_battery() raises OSError in case of no battery. - #1075: [Windows] net_if_addrs(): inet_ntop() return value is not checked. - #1077: [SunOS] net_if_addrs() shows garbage addresses on SunOS 5.10. (patch by Oleksii Shevchuk) - #1077: [SunOS] net_connections() does not work on SunOS 5.10. (patch by Oleksii Shevchuk) - #1079: [FreeBSD] net_connections() didn't list locally connected sockets. (patch by Gleb Smirnoff) - #1085: cpu_count() return value is now checked and forced to None if <= 1. - #1087: Process.cpu_percent() guard against cpu_count() returning None and assumes 1 instead. - #1093: [SunOS] memory_maps() shows wrong 64 bit addresses. - #1094: [Windows] psutil.pid_exists() may lie. Also, all process APIs relying on OpenProcess Windows API now check whether the PID is actually running. - #1098: [Windows] Process.wait() may erroneously return sooner, when the PID is still alive. - #1099: [Windows] Process.terminate() may raise AccessDenied even if the process already died. - #1101: [Linux] sensors_temperatures() may raise ENODEV. **Porting notes** - #1039: returned types consolidation: - Windows / Process.cpu_times(): fields #3 and #4 were int instead of float - Linux / FreeBSD: connections('unix'): raddr is now set to "" instead of None - OpenBSD: connections('unix'): laddr and raddr are now set to "" instead of None - #1040: all strings are encoded by using OS fs encoding. - #1040: the following Windows APIs on Python 2 now return a string instead of unicode: - Process.memory_maps().path - WindowsService.bin_path() - WindowsService.description() - WindowsService.display_name() - WindowsService.username() *2017-04-10* Links ===== - Home page: https://github.com/giampaolo/psutil - Download: https://pypi.python.org/pypi/psutil - Documentation: http://pythonhosted.org/psutil - What's new: https://github.com/giampaolo/psutil/blob/master/HISTORY.rst -- Giampaolo - http://grodola.blogspot.com From eryksun at gmail.com Sun Sep 3 11:17:30 2017 From: eryksun at gmail.com (eryk sun) Date: Sun, 3 Sep 2017 10:17:30 -0500 Subject: Run Windows commands from Python console In-Reply-To: <83ebc433-d457-408b-b43a-4b00a3206728@googlegroups.com> References: <83ebc433-d457-408b-b43a-4b00a3206728@googlegroups.com> Message-ID: On Sun, Sep 3, 2017 at 7:56 AM, wrote: > > I run Python console in Windows. Can I run cmd prompt commands > there? Python doesn't know the first thing about CMD's "batch" language. Also, Python's shell (i.e. REPL) is not a system administration shell that implicitly runs external commands. You need to use the subprocess module for that. For example: >>> import subprocess >>> subprocess.call(['icacls.exe', 'SomeFile.ext', '/grant', 'JaneDoe:(F)']). If you need to run a CMD command, use shell=True with a command-line string. For example: >>> subprocess.call('icacls SomeFile.ext /grant %USERNAME%:(F)', shell=True) FYI, being attached to a console for standard I/O doesn't mean you're using a "Command Prompt" that can run CMD commands. python.exe is a character (i.e. text user interface or command-line interface) application that creates or inherits a console automatically. You're probably used to running python.exe from cmd.exe and inheriting CMD's console. But you can also run python.exe directly from Explorer, in which case it creates its own console. If Python creates its own console, the window will be destroyed automatically when Python exits -- unless you create child processes that are also attached to the console and remain running. pythonw.exe is graphical or background application, not a character application, so it doesn't create or inherit a console automatically. Typically IDLE runs via pythonw.exe, in which case if you want a console you need to call WinAPI AllocConsole() or AttachConsole(). Once attached to a console, you can open "CON", "CONIN$" , or "CONOUT$". > What means line below: > > File "", line 1 > > I don't have any file. Indeed, on Windows you cannot create a file named "". Python uses this fake name for the code object it compiles when reading from stdin (i.e. the file stream opened for console input). It's not exactly smart about this, either, since whenever an exception is raised in the REPL it will try to open this fake file multiple times, including trying every entry in sys.path. For example, in a typical Python 3.6 all-users installation, it will try opening the following file paths: C:\Program Files\Python36\python36.zip\ C:\Program Files\Python36\python36.zip\ C:\Program Files\Python36\DLLs\ C:\Program Files\Python36\lib\ C:\Program Files\Python36\ C:\Program Files\Python36\lib\site-packages\ ... Of course, all of these attempts to open "" necessarily fail on Windows. On Unix, however, this can actually succeed, which is kind of funny: >>> open('', 'w').write('What the !@#$%^&*?') 18 >>> dit Traceback (most recent call last): File "", line 1, in What the !@#$%^&*? NameError: name 'dit' is not defined From kabalida16 at gmail.com Sun Sep 3 11:31:04 2017 From: kabalida16 at gmail.com (kabalida16 at gmail.com) Date: Sun, 3 Sep 2017 08:31:04 -0700 (PDT) Subject: How to get status of Autoplay video from browser Message-ID: <350d8387-ff72-4dbe-b3b3-7960bed08c9f@googlegroups.com> Hi , I have a URL where Video will start playing after launch (autoplay video) eg:https://techcrunch.com/ Another script will pause the video as soon as it detects a Video is playing. Now I need to verif the video is paused successfully or not. HOw to get the status of video? I am using Python Selenium webdriver, please let me know the solution for the same. From eryksun at gmail.com Sun Sep 3 11:38:12 2017 From: eryksun at gmail.com (eryk sun) Date: Sun, 3 Sep 2017 10:38:12 -0500 Subject: ANN: psutil 5.3.0 with full unicode support is out In-Reply-To: References: Message-ID: On Sun, Sep 3, 2017 at 9:58 AM, Giampaolo Rodola' wrote: > > - #1040: all strings are encoded by using OS fs encoding. > - #1040: the following Windows APIs on Python 2 now return a string instead > of > unicode: > - Process.memory_maps().path > - WindowsService.bin_path() > - WindowsService.description() > - WindowsService.display_name() > - WindowsService.username() This seems wrong. User names, file paths, registry strings, etc are all Unicode in Windows. One cannot in general encode them as the legacy (as in it really should be avoided) 'mbcs' encoding, i.e. ANSI. Using the 'replace' handler will make a mess with best-fit replacements and question marks. For example, _winreg in Python 2 has to return unicode strings and always has, which should be the precedent for psutil. Python 2 code that supports Windows has to be able to handle this. From stephanh42 at gmail.com.invalid Sun Sep 3 14:15:56 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 03 Sep 2017 18:15:56 GMT Subject: A question on modification of a list via a function invocation References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <178b2da3-9240-143b-7c29-1780923d52ad@t-online.de> <36mdnXQc6v8B9A_EnZ2dnUU7-f_NnZ2d@giganews.com> <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> Message-ID: Op 2017-08-17, Rustom Mody schreef : > On Thursday, August 17, 2017 at 6:49:19 AM UTC+5:30, Mok-Kong Shen wrote: >> Am 17.08.2017 um 02:41 schrieb Steve D'Aprano: >> > By reference and by value are not the only two conventions. >> > >> > Perhaps if you go back to the 1950s you might be able to argue that >> > "reference" and "value" are the only two conventions, but >> > alternatives have existed for many decades, since *at least* 1960 >> > when Algol introduced "call by name". I'm a bit late to this discussion, but pelase allow me to add some (to me at least) fascinating history to this. In 1966, a very influential paper was published: P.J. Landin, "The Next 700 Programming Languages" See: https://www.cs.cmu.edu/~crary/819-f09/Landin66.pdf In this paper, Landin decribes a "family of unimplemented computing languages that is intended to span differences of application area by a unified framework". He calls this language (or family of languages) ISWIM. It is a language with Lisp-like semantics but "Algol-like" (i.e. infix) syntax, dynamically typed, and he introduces the novel idea to have "Indentation, used to indicate program structure." Sounds familiar to anybody? Yep, this is basically proto-Python. Anyway, then there is a later paper (from 1974) by G.D. Plotkin, "Call-by-name, call-by-value and the ?-calculus" (see http://www.sciencedirect.com/science/article/pii/0304397575900171 ). In this paper, Plotkin "examines the old question of the relationship between ISWIM and the ?-calculus, using the distinction between call-by-value and call-by-name." Yep, in 1974, what to call the calling convention of proto-Python was already an "old question". In this paper, Plotkin introduces the ?V-calculus, the call-by-value lambda-calculus, to formalize what it is what ISWIM (and Python) are actually doing. This paper is, to the best of my knowledge, the closest thing to an "official" definition of what call-by-value actually means. Needless to say, according to the definition in Plotkin's paper, Python is "call-by-value". Stephan From steve+python at pearwood.info Sun Sep 3 14:19:28 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 04 Sep 2017 04:19:28 +1000 Subject: Case-insensitive string equality References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59aa15c0$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59ac47b2$0$1620$c3e8da3$5496439d@news.astraweb.com> On Sun, 3 Sep 2017 05:17 pm, Stephan Houben wrote: > Generally speaking, the more you learn about case normalization, > the more attractive case sensitivity looks Just because something is hard doesn't mean its not worth doing. And just because you can't please all the people all the time doesn't mean its not worthwhile. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From christopher_reimer at yahoo.com Sun Sep 3 15:31:35 2017 From: christopher_reimer at yahoo.com (Christopher Reimer) Date: Sun, 3 Sep 2017 12:31:35 -0700 Subject: Have do_nothing as default action for dictionary? Message-ID: Greetings, I was playing around this piece of example code (written from memory). def filter_text(key, value): ??? def do_nothing(text): return text ??? return {'this': call_this, ????????????????? 'that': call_that, ????????????????? 'what': do_nothing ???????????????? }[key](value) Is there a way to refactor the code to have the inner do_nothing function be the default action for the dictionary? The original code was a series of if statements. The alternatives include using a lambda to replace the inner function or a try-except block on the dictionary to return value on KeyError exception. What's the most pythonic and fastest? Thank you, Chris R. From pavol.lisy at gmail.com Sun Sep 3 15:58:47 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Sun, 3 Sep 2017 21:58:47 +0200 Subject: Case-insensitive string equality In-Reply-To: <59ac47b2$0$1620$c3e8da3$5496439d@news.astraweb.com> References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59aa15c0$0$1587$c3e8da3$5496439d@news.astraweb.com> <59ac47b2$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 9/3/17, Steve D'Aprano wrote: > On Sun, 3 Sep 2017 05:17 pm, Stephan Houben wrote: > >> Generally speaking, the more you learn about case normalization, >> the more attractive case sensitivity looks > > Just because something is hard doesn't mean its not worth doing. > > And just because you can't please all the people all the time doesn't mean > its > not worthwhile. I was thinking about compare where false positivity is acceptable (and well defined property). For example if somebody has case sensitive FS and wants to publish files and avoid name collision on any case insensitive FS then compare with false positive equals could be useful. Then backward compatibility problem could be (theoretically) simplified to enhancing equivalence classes in future. I mean something like -> equal = lambda a, b: any(f(a) == f(b) for f in C) # where C is enhanceble list of compare equals functions Could you think that such equivalence relation could solve problems which you describe in first mail in this thread? And if trying to "solve" unicode problem why not? -> a ? b a ? L From rosuav at gmail.com Sun Sep 3 16:00:12 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Sep 2017 06:00:12 +1000 Subject: Have do_nothing as default action for dictionary? In-Reply-To: References: Message-ID: On Mon, Sep 4, 2017 at 5:31 AM, Christopher Reimer via Python-list wrote: > Greetings, > > I was playing around this piece of example code (written from memory). > > > def filter_text(key, value): > > def do_nothing(text): return text > > return {'this': call_this, > > 'that': call_that, > > 'what': do_nothing > > }[key](value) > > > Is there a way to refactor the code to have the inner do_nothing function be > the default action for the dictionary? Easy: use the .get() method. return {'this': call_this, 'that': call_that, }.get(key, do_nothing)(value) ChrisA From __peter__ at web.de Sun Sep 3 16:02:08 2017 From: __peter__ at web.de (Peter Otten) Date: Sun, 03 Sep 2017 22:02:08 +0200 Subject: Have do_nothing as default action for dictionary? References: Message-ID: Christopher Reimer via Python-list wrote: > Greetings, > > I was playing around this piece of example code (written from memory). > > > def filter_text(key, value): > > def do_nothing(text): return text > > return {'this': call_this, > > 'that': call_that, > > 'what': do_nothing > > }[key](value) > > > Is there a way to refactor the code to have the inner do_nothing > function be the default action for the dictionary? If it does nothing, why invoke it at all? LOOKUP = {"this": call_this, ...} def filter_text(key, value): > The original code was a series of if statements. The alternatives > include using a lambda to replace the inner function or a try-except > block on the dictionary to return value on KeyError exception. > > What's the most pythonic and fastest? > > Thank you, > > Chris R. > From __peter__ at web.de Sun Sep 3 16:13:28 2017 From: __peter__ at web.de (Peter Otten) Date: Sun, 03 Sep 2017 22:13:28 +0200 Subject: Have do_nothing as default action for dictionary? References: Message-ID: Christopher Reimer via Python-list wrote: > Greetings, > > I was playing around this piece of example code (written from memory). > > > def filter_text(key, value): > > def do_nothing(text): return text > > return {'this': call_this, > > 'that': call_that, > > 'what': do_nothing > > }[key](value) > > > Is there a way to refactor the code to have the inner do_nothing > function be the default action for the dictionary? If it does nothing, why invoke it at all? LOOKUP = {"this": call_this, ...} def filter_text(key, value): if key in LOOKUP: return LOOKUP[key](value) return value If there are much more hits than misses: def filter_text(key, value): try: process = return LOOKUP[key] except KeyError: return value return process(value) If you insist on invoking a noop func: def do_nothing(text): return text def filter_text(key, value): return LOOKUP.get(key, do_nothing)(value) With a collections.defaultdict (will grow to comprise new keys): LOOKUP = defaultdict(LOOKUP, lambda: do_nothing) def filter_key(key, value): return LOOKUP[key](value) > The original code was a series of if statements. The alternatives > include using a lambda to replace the inner function or a try-except > block on the dictionary to return value on KeyError exception. > > What's the most pythonic and fastest? > > Thank you, > > Chris R. > From tjreedy at udel.edu Sun Sep 3 17:09:28 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 3 Sep 2017 17:09:28 -0400 Subject: Run Windows commands from Python console In-Reply-To: References: <83ebc433-d457-408b-b43a-4b00a3206728@googlegroups.com> Message-ID: On 9/3/2017 11:17 AM, eryk sun wrote: > On Sun, Sep 3, 2017 at 7:56 AM, wrote: >> What means line below: >> >> File "", line 1 >> >> I don't have any file. > > Indeed, on Windows you cannot create a file named "". Python > uses this fake name for the code object it compiles when reading from > stdin (i.e. the file stream opened for console input). > > It's not exactly smart about this, either, since whenever an exception > is raised in the REPL it will try to open this fake file multiple > times, including trying every entry in sys.path. For example, in a > typical Python 3.6 all-users installation, it will try opening the > following file paths: > > > > C:\Program Files\Python36\python36.zip\ > C:\Program Files\Python36\python36.zip\ > C:\Program Files\Python36\DLLs\ > C:\Program Files\Python36\lib\ > C:\Program Files\Python36\ > C:\Program Files\Python36\lib\site-packages\ > ... > > Of course, all of these attempts to open "" necessarily fail on > Windows. The result, after doing all the above, is tracebacks like >>> def f(): ... return 1/0 ... >>> f() Traceback (most recent call last): File "", line 1, in File "", line 2, in f ZeroDivisionError: division by zero with source lines missing. Note that 'line 1' is misleading as the 'f()' call is on line 4. It is the first line of the 2nd statement. In IDLE, trackbacks *do* include source lines. >>> def f(): return 1/0 >>> f() Traceback (most recent call last): File "", line 1, in f() File "", line 2, in f return 1/0 ZeroDivisionError: division by zero Each statement is numbered, and treated as a file, so that line numbering starts at 1 for each statement. The secret to doing this is that traceback printing looks in linecache.cache *before* trying to open a file, as described above. When the file is read, it is added to the cache. IDLE stuffs the lines for each statement into the cache and replaces linecache.checkcache with a wrapper that prevents them from being deleted. > On Unix, however, this can actually succeed, which is kind of > funny: > > >>> open('', 'w').write('What the !@#$%^&*?') > 18 > > >>> dit > Traceback (most recent call last): > File "", line 1, in > What the !@#$%^&*? > NameError: name 'dit' is not defined Won't happen with -- Terry Jan Reedy From chris at withers.org Sun Sep 3 17:37:43 2017 From: chris at withers.org (Chris Withers) Date: Sun, 3 Sep 2017 22:37:43 +0100 Subject: testfixtures 5.2.0 released! Message-ID: <59621505-c603-ef9a-d783-0ebf0a1419c4@withers.org> Hi All, I'm pleased to announce the release of testfixtures 5.2.0 featuring the following: * test_datetime and test_time now accept a [1]datetime instance during instantiation to set the initial value. * test_date now accepts a [2]date instance during instantiation to set the initial value. * Relax the restriction on adding, setting or instantiating test_datetime with tzinfo such that if the tzinfo matches the one configured, then it's okay to add. This means that you can now instantiate a test_datetime with an existing [3]datetime instance that has tzinfo set. * testfixtures.django.compare_model() now ignores [4]many to many fields rather than blowing up on them. * Drop official support for Python 3.4, although things should continue to work. The package is on PyPI and a full list of all the links to docs, issue trackers and the like can be found here: [5]https://github.com/Simplistix/testfixtures Any questions, please do ask on the Testing in Python list or on the Simplistix open source mailing list... cheers, Chris References Visible links 1. (in Python v2.7) https://docs.python.org/2/library/datetime.html#datetime.datetime 2. (in Python v2.7) https://docs.python.org/2/library/datetime.html#datetime.date 3. (in Python v2.7) https://docs.python.org/2/library/datetime.html#datetime.datetime 4. (in Django v2.0) http://django.readthedocs.io/en/latest/ref/models/fields.html#django.db.models.ManyToManyField 5. https://github.com/Simplistix/testfixtures From saxri89 at gmail.com Sun Sep 3 18:32:19 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Sun, 3 Sep 2017 15:32:19 -0700 (PDT) Subject: python multiprocessing question Message-ID: hello i have create a 4 function using python(f1,f2,f3,f4) and i have 4 cores in my system. def f1() ............... ............... def f2() ............... ............... def f3() ............... ............... def f4() ............... ............... that functions operate independently of each other but how to use multiprocessing to define the cores to work that functions parallel to win some time ? sorry i am very new and i need some help or some example. From greg.ewing at canterbury.ac.nz Sun Sep 3 19:10:04 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Sep 2017 11:10:04 +1200 Subject: Case-insensitive string equality In-Reply-To: References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> <59a9fbe3$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: Stefan Ram wrote: > But of > course, actually the rules of orthography require "Ma?e" or > "Masse" and do not allow "MASSE" or "MASZE", just as in > English, "English" has to be written "English" and not > "english" or "ENGLISH". While "english" is wrong in English, there's no rule against using "ENGLISH" as an all-caps version. Are you saying that all-caps text is not allowed in German? If so, that's very different from English. -- Greg From christopher_reimer at yahoo.com Sun Sep 3 19:15:28 2017 From: christopher_reimer at yahoo.com (Christopher Reimer) Date: Sun, 3 Sep 2017 16:15:28 -0700 Subject: Have do_nothing as default action for dictionary? In-Reply-To: References: Message-ID: <6f7d4b9a-6ec2-07ac-221e-94760ae77548@yahoo.com> Greetings, After reading everyone's comments and doing a little more research, I re-implemented my function as a callable class. ??? def __call__(self, key, value): ??????? if key not in self._methods: ??????????? return value ??????? return self._methods[key](value) This behaves like my previous function, solved the problem that I had with the dictionary, the dictionary is created only once, a half dozen functions got moved into the new class, and the old class now has less clutter. Thanks everyone! Chris R. From steve+python at pearwood.info Sun Sep 3 21:57:07 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 04 Sep 2017 11:57:07 +1000 Subject: Case-insensitive string equality References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> <59a9fbe3$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59acb2f4$0$1610$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Sep 2017 09:10 am, Gregory Ewing wrote: > Stefan Ram wrote: >> But of >> course, actually the rules of orthography require "Ma?e" or >> "Masse" and do not allow "MASSE" or "MASZE", just as in >> English, "English" has to be written "English" and not >> "english" or "ENGLISH". > > While "english" is wrong in English, there's no rule > against using "ENGLISH" as an all-caps version. It's not always wrong. If you're e.e. cummings, then you're allowed to avoid capitals. (If you're anyone else, you're either a derivative hack, or lazy.) And if you are referring to the spin applied to billiard balls, it is acceptable to write it as english. > Are you saying that all-caps text is not allowed in > German? If so, that's very different from English. Germans use ALLCAPS for headlines, book titles, emphasis etc just as English speakers do. For example: http://www.spiegel.de/politik/index.html -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Sep 3 22:05:01 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 04 Sep 2017 12:05:01 +1000 Subject: A question on modification of a list via a function invocation References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <178b2da3-9240-143b-7c29-1780923d52ad@t-online.de> <36mdnXQc6v8B9A_EnZ2dnUU7-f_NnZ2d@giganews.com> <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> Message-ID: <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Sep 2017 04:15 am, Stephan Houben wrote: > Needless to say, according to the definition in Plotkin's paper, Python > is "call-by-value". According to Plotkin's definition, when you pass a value like a 100MB string: "This is a long string of text..." # continues on for millions more characters does the interpreter make a copy of the 100MB string? If not, then it isn't pass (call) by value. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sun Sep 3 22:20:00 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Sep 2017 12:20:00 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <178b2da3-9240-143b-7c29-1780923d52ad@t-online.de> <36mdnXQc6v8B9A_EnZ2dnUU7-f_NnZ2d@giganews.com> <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Sep 4, 2017 at 12:05 PM, Steve D'Aprano wrote: > On Mon, 4 Sep 2017 04:15 am, Stephan Houben wrote: > >> Needless to say, according to the definition in Plotkin's paper, Python >> is "call-by-value". > > According to Plotkin's definition, when you pass a value like a 100MB string: > > "This is a long string of text..." # continues on for millions more characters > > does the interpreter make a copy of the 100MB string? > > If not, then it isn't pass (call) by value. This is another proof that you can't divide everything into "pass by value" vs "pass by reference", unless you mess around with "passing a reference by value" or other shenanigans. In C, a string is not an entity; it's simply an array of characters. Arrays are never passed by value; yet everything in C is passed by value. So you pass a pointer... by value. What would you define LISP's semantics as? Pass by value? Pass by reference? Pass by name? Pass by immutability? Pass the salt? ChrisA From steve+python at pearwood.info Sun Sep 3 22:28:46 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 04 Sep 2017 12:28:46 +1000 Subject: Capital =?UTF-8?B?w58=?= [was Re: Case-insensitive string equality] References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> <59a9fbe3$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59acba5f$0$1615$c3e8da3$5496439d@news.astraweb.com> On Sat, 2 Sep 2017 01:48 pm, Stefan Ram wrote: > Steve D'Aprano writes: >>[1] I believe that the German government has now officially recognised the >>uppercase form of ?. > > [skip to the last paragraph for some "?" content, > unless you want to read details about German spelling rules.] > > The German language is as free as the English one. It does > not come from a government. Nevertheless, even in English there are de facto rules about what you can and cannot use as text for official purposes. In most countries, you cannot change your name to an unpronounceable "love symbol" as the late Artist Formally Known As Prince did. You can't fill in your tax using Alienese http://futurama.wikia.com/wiki/Alienese or even Vietnamese, Greek or Arabic. In Australia, the Victorian state government Department of Births Deaths and Marriages doesn't even accept such unexceptional and minor variants as Z?e for Zoe. Of course you are free to call yourself Z?e when you sign your emails, but your birth certificate, passport and drivers licence will show it as Zoe. > The 16 states (Bundesl?nder), agreed to a common institution > ("Der Rat f?r deutsche Rechtschreibung") to write down the > rules for their /schools/. The federal government is not > involved. Most publishing houses volunteered to follow those > school rules. Outside of schools or binding contracts, > everyone is free to write as he likes. I'm not suggesting that the Spelling Police will come arrest me in either Germany or the UK/Australia if I were to write my name ??????. Switzerland on the other hand ... *wink* But there are very strong conventions about what is acceptable, and often there are actual laws in place that limit what letters are used in official documentation and records, what is taught in schools, etc. The 1996 spelling reforms, and their legal status, are described here: https://en.wikipedia.org/wiki/German_orthography_reform_of_1996 and Der Rat f?r deutsche Rechtschreibung: https://en.wikipedia.org/wiki/Council_for_German_Orthography (Sorry for not linking to the German versions as well.) > The "?" sometimes has been uppercased to "SS" and sometimes > to "SZ". Historically, some German publishers used a distinct uppercase ?, while others used a ligature of SZ, explicitly stating that this was an interim measure until they decided on a good looking uppercase ?. More about capital ?: https://typography.guru/journal/germanys-new-character/ https://medium.com/@typefacts/the-german-capital-letter-eszett-e0936c1388f8 https://en.wikipedia.org/wiki/Capital_%E1%BA%9E -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Sep 3 22:58:33 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 04 Sep 2017 12:58:33 +1000 Subject: A question on modification of a list via a function invocation References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <178b2da3-9240-143b-7c29-1780923d52ad@t-online.de> <36mdnXQc6v8B9A_EnZ2dnUU7-f_NnZ2d@giganews.com> <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Sep 2017 12:20 pm, Chris Angelico wrote: > This is another proof that you can't divide everything into "pass by > value" vs "pass by reference", unless you mess around with "passing a > reference by value" or other shenanigans. In C, a string is not an > entity; it's simply an array of characters. Arrays are never passed by > value; yet everything in C is passed by value. So you pass a > pointer... by value. Indeed. And we say that in C, arrays are not first-class entities. We might say that in C, arrays (and strings) are not actually values -- only the pointer to the first slot in the array is a value. The difference[1] between C and Python is that *top level Python code* abstracts away the pointer passing that goes on behind the scenes inside the interpreter. Your Python code treats strings and arrays (lists or tuples or even actual arrays) as first class values, while C does not. If you want a Python function to accept a string as argument, you simply declare the parameter (with or without optional type hint), and pass the string as needed. In C (as far as I understand it, correct me if I'm wrong) you cannot. You must declare the parameter as a *pointer* type, and explicitly pass a pointer to the start of the array, not the array itself. That makes arrays (and strings) in C a bit of an odd corner case, and an exception to the usual rules, like unboxed machine types in Java. We should acknowledge them, but as exceptional cases, and we should note that Python has no similar exceptional cases. All values in Python are first-class, and all are passed in precisely the same way. > What would you define LISP's semantics as? Pass by value? Pass by > reference? Pass by name? Pass by immutability? Pass the salt? My understanding is that LISP has more-or-less the same calling mechanism as Python, only it had it long before Barbara Liskov gave a name to it when describing CLU. [1] What, only one? *wink* -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Sun Sep 3 23:11:11 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Sep 2017 20:11:11 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <178b2da3-9240-143b-7c29-1780923d52ad@t-online.de> <36mdnXQc6v8B9A_EnZ2dnUU7-f_NnZ2d@giganews.com> <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <29c67315-6ede-40c0-854b-740ee73eeaf6@googlegroups.com> On Monday, September 4, 2017 at 7:50:22 AM UTC+5:30, Chris Angelico wrote: > On Mon, Sep 4, 2017 at 12:05 PM, Steve D'Aprano wrote: > > On Mon, 4 Sep 2017 04:15 am, Stephan Houben wrote: > > > >> Needless to say, according to the definition in Plotkin's paper, Python > >> is "call-by-value". > > > > According to Plotkin's definition, when you pass a value like a 100MB string: > > > > "This is a long string of text..." # continues on for millions more characters > > > > does the interpreter make a copy of the 100MB string? > > > > If not, then it isn't pass (call) by value. > > This is another proof that you can't divide everything into "pass by > value" vs "pass by reference", unless you mess around with "passing a > reference by value" or other shenanigans. In C, a string is not an > entity; it's simply an array of characters. Arrays are never passed by > value; yet everything in C is passed by value. So you pass a > pointer... by value. > > What would you define LISP's semantics as? Pass by value? Pass by > reference? Pass by name? Pass by immutability? Pass the salt? ?Pass the logic" ?Oops?? ?You slob! You?ve messed my consistency-carpet." Earlier Ben Bacarisse wrote: > The core of the idea is actually what the value-set of Python programs is -- Yes! That!! Parameter-passing models and nomenclature is really a red-herring Its the ?== is id? mess that is at the base of the mess: Simply put: pythonistas have no coherent/consistent sense of what python values are. And the endless parameter-passing-nomenclature arguments are just the fallout of that. Maybe that?s what Ben means by?? > the passing by value just drops out of that. From rustompmody at gmail.com Sun Sep 3 23:36:12 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 3 Sep 2017 20:36:12 -0700 (PDT) Subject: meaning of [ ] In-Reply-To: <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> Message-ID: <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> On Sunday, September 3, 2017 at 5:10:13 PM UTC+5:30, Rick Johnson wrote: > Andrej Viktorovich wrote: > > I suppose p becomes array of strings but what [] means in this statement? > > Generally, it's an inline form of writing a loop that returns a list. There are other types as well. Tsk tsk the confusioning continues Rewrite [p for p in sys.path] as [p | p ? sys.path] Is that clearer? And then as {p | p ? sys.path} And refresh the idea of set-builder notation http://www.mathwords.com/s/set_builder_notation.htm Note the the clunky ascii-fication of (most) programming languages (including python) is a minor distraction The bigger and more real issue is that sets and lists are similar and different Sets have no order, lists are ordered As Peter pointed out this is a no-op ie [p for p in sys.path] could be written as list(sys.path) [Not sure why he didnt say just sys.path] Anyway this is a good example to distinguish [p for p in sys.path] from {p for p in sys.path} Both work in python But the second is probably not correct because path-searching is order dependent From g.rodola at gmail.com Mon Sep 4 00:09:55 2017 From: g.rodola at gmail.com (Giampaolo Rodola') Date: Mon, 4 Sep 2017 12:09:55 +0800 Subject: ANN: psutil 5.3.0 with full unicode support is out In-Reply-To: References: Message-ID: Hello Eryk, it is true that the most correct way to represent strings in Python 2 is by dealing with Unicode but it is also true that the most common scenario in both the stdlib and most third party libs is to return and deal with str (bytes) instead, so this is why I decided to do the same in psutil. Other than _winreg I can't recall other APIs returning Unicode by default unless explicitly asked (e.g os.getcwdu() or os.listdir(u'.')) and I didn't want to duplicate psutil APIs in the same fashion. It must be noted that many stdlib APIs in Python 2 are "broken" when it comes to Unicode, see: http://bugs.python.org/issue18695 ...so the most convenient and definitive "fix" to correctly handle strings in Python is switching to Python 3. With that said, in psutil on Python 2 you are still supposed to be able retrieve the "correct" string by using the "replace" error handler: >>> unicode(proc.exe(), sys.getdefaultencoding(), errors="replace") This is an example which filters processes with a funky name which works with both Python 2 and 3: import psutil, sys PY3 = sys.version_info[0] == 2 LOOKFOR = u"???.exe" for proc in psutil.process_iter(attrs=['name']): name = proc.info['name'] if not PY3: name = unicode(name, sys.getdefaultencoding(), errors="replace") if LOOKFOR == name: print("process %s found" % p) This is IMO the best compromise for a lib which aims to work on both Python 2 and 3. It's either that or returning Unicode all over the place in Python 2, but that's something I considered and rejected because most of the times the string is not supposed to have funky characters, so "practicality beats purity" in this case. On Sun, Sep 3, 2017 at 11:38 PM, eryk sun wrote: > On Sun, Sep 3, 2017 at 9:58 AM, Giampaolo Rodola' > wrote: > > > > - #1040: all strings are encoded by using OS fs encoding. > > - #1040: the following Windows APIs on Python 2 now return a string > instead > > of > > unicode: > > - Process.memory_maps().path > > - WindowsService.bin_path() > > - WindowsService.description() > > - WindowsService.display_name() > > - WindowsService.username() > > This seems wrong. User names, file paths, registry strings, etc are > all Unicode in Windows. One cannot in general encode them as the > legacy (as in it really should be avoided) 'mbcs' encoding, i.e. ANSI. > Using the 'replace' handler will make a mess with best-fit > replacements and question marks. For example, _winreg in Python 2 has > to return unicode strings and always has, which should be the > precedent for psutil. Python 2 code that supports Windows has to be > able to handle this. > -- Giampaolo - http://grodola.blogspot.com From eryksun at gmail.com Mon Sep 4 02:54:57 2017 From: eryksun at gmail.com (eryk sun) Date: Mon, 4 Sep 2017 01:54:57 -0500 Subject: ANN: psutil 5.3.0 with full unicode support is out In-Reply-To: References: Message-ID: On Sun, Sep 3, 2017 at 11:09 PM, Giampaolo Rodola' wrote: > > This is an example which filters processes with a funky name which works > with both Python 2 > and 3: > > import psutil, sys > > PY3 = sys.version_info[0] == 2 > LOOKFOR = u"???.exe" > for proc in psutil.process_iter(attrs=['name']): > name = proc.info['name'] > if not PY3: > name = unicode(name, sys.getdefaultencoding(), errors="replace") > if LOOKFOR == name: > print("process %s found" % p) > > This is IMO the best compromise for a lib which aims to work on both Python > 2 and 3. It's either that or returning Unicode all over the place in Python > 2, but that's something I considered and rejected because most of the times > the string is not supposed to have funky characters, so "practicality beats > purity" in this case. The encoded name for ANSI codepage 1252 is "\x83oo.exe". Python 2's default encoding is ASCII, so the decoded result is u'\ufffdoo.exe'. Even if it should be the filesystem encoding ('mbcs'), the result is u"?oo.exe". Neither equals u"???.exe". Instead, shouldn't it encode LOOKFOR as "mbcs" with errors="replace" before comparing it to proc.info['name']? From jldunn2000 at gmail.com Mon Sep 4 03:30:27 2017 From: jldunn2000 at gmail.com (loial) Date: Mon, 4 Sep 2017 00:30:27 -0700 (PDT) Subject: Permissions issues with zipfile Message-ID: <9d0f2c63-12bf-4f1f-bbe1-81166ebc2692@googlegroups.com> I am getting a permission issue with the following code targetdirectory = '/data/upload' ????????????self.ZIPFileName = targetDirectory + os.sep + "MY.ZIP" ????????????zf = zipfile.ZipFile(self.ZIPFileName, mode='w') [Errno 13] Permission denied: '/data/upload/MY.ZIP' The target directory is an NFS mounted directory. I can manually create a file in that directory with no issues using the same user Any ideas? Python version is 2.7.10. Platform is Centos 7 From viktorovichandrej at gmail.com Mon Sep 4 04:08:19 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Mon, 4 Sep 2017 01:08:19 -0700 (PDT) Subject: Can I use functions while defining paths? Message-ID: Hello, Trying to import my made module to python with helper function: import os.path.join ("D","pyth_nonsens","workspace_python","PyhonTutorial","reader") >>> import os.path.join ("D","pyth_nonsens","workspace_python","PyhonTutorial","reader") File "", line 1 import os.path.join ("D","pyth_nonsens","workspace_python","PyhonTutorial","reader") ^ Can I use functions while defining paths? From jldunn2000 at gmail.com Mon Sep 4 04:12:46 2017 From: jldunn2000 at gmail.com (loial) Date: Mon, 4 Sep 2017 01:12:46 -0700 (PDT) Subject: permission issue with zipfile Message-ID: <0966362e-7917-4b12-8fe2-4b62f498864e@googlegroups.com> I am getting a permission issue with the following code targetDirectory = '/data/upload' self.ZIPFileName = targetDirectory + os.sep + "MY.ZIP" zf = zipfile.ZipFile(self.ZIPFileName, mode='w') [Errno 13] Permission denied: '/data/upload/MY.ZIP' The target directory is an NFS mounted directory. I can manually create a file in that directory with no issues using the same user Any ideas? Python version is 2.7.10. Platform is Centos 7 From greg.ewing at canterbury.ac.nz Mon Sep 4 04:16:39 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Sep 2017 20:16:39 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <178b2da3-9240-143b-7c29-1780923d52ad@t-online.de> <36mdnXQc6v8B9A_EnZ2dnUU7-f_NnZ2d@giganews.com> <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > This is another proof that you can't divide everything into "pass by > value" vs "pass by reference" True, but that doesn't mean you should deny that something is pass-by-value when it actually is. > In C, a string is not an > entity; it's simply an array of characters. Arrays are never passed by > value; I think it's more accurate to say that arrays are never passed at all in C. A better name for pass-by-value would be "pass-by-assignment". Passing a parameter by value is equivalent to assigning it to a local name. > yet everything in C is passed by value. So you pass a > pointer... by value. Yes, because that's what happens when you assign an array in C. If it seems screwy, it's because assignment is screwy in C, not parameter passing. > What would you define LISP's semantics as? Pass by value? Pass by > reference? Pass by name? Pass by immutability? Pass the salt? Let's see... the expression being passed gets evaluated once at the point of call, and the result gets bound to a local name. Looks exactly like pass-by-value to me. > unless you mess around with "passing a > reference by value" or other shenanigans. What on earth are you talking about? I didn't even use the words "value" or "reference" in the previous paragraph. -- Greg From greg.ewing at canterbury.ac.nz Mon Sep 4 04:16:42 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 04 Sep 2017 20:16:42 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: Stefan Ram wrote: > JavaScript and Python do not have references as values Yes, they do. The difference is that they don't have any way of *not* having references as values, so there's less need to use the word explicitly in that way -- most of the time it's just understood. Nevertheless, terms such as "object reference" and "reference to an object" do get used in relation to Python when clarity is needed. -- Greg From cs at cskk.id.au Mon Sep 4 04:24:02 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 4 Sep 2017 18:24:02 +1000 Subject: Permissions issues with zipfile In-Reply-To: <9d0f2c63-12bf-4f1f-bbe1-81166ebc2692@googlegroups.com> References: <9d0f2c63-12bf-4f1f-bbe1-81166ebc2692@googlegroups.com> Message-ID: <20170904082402.GA87232@cskk.homeip.net> On 04Sep2017 00:30, loial wrote: >I am getting a permission issue with the following code > targetdirectory = '/data/upload' >????????????self.ZIPFileName = targetDirectory + os.sep + "MY.ZIP" >????????????zf = zipfile.ZipFile(self.ZIPFileName, mode='w') > [Errno 13] Permission denied: '/data/upload/MY.ZIP' > >The target directory is an NFS mounted directory. > >I can manually create a file in that directory with no issues using the same user > >Any ideas? > >Python version is 2.7.10. Platform is Centos 7 Odd. 1: Does such a zip file already exist, perhaps with different ownership or no write permission? 2: Is the code running as you? Eg do you get this error running the code by hand from the same shell in which you can manually create a file there? 3: You're doing your python and manual check on the same machine (versus some testing on the server and some local or something)? You're on Linux. Install strace and see what: strace python your-program.py shows you. Just in case the zip file's being opened with a funny mode or something. It is always good to be totally sure of exactly what system call is failing. Cheers, Cameron Simpson (formerly cs at zip.com.au) From rosuav at gmail.com Mon Sep 4 04:59:44 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Sep 2017 18:59:44 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <178b2da3-9240-143b-7c29-1780923d52ad@t-online.de> <36mdnXQc6v8B9A_EnZ2dnUU7-f_NnZ2d@giganews.com> <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Sep 4, 2017 at 6:16 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> This is another proof that you can't divide everything into "pass by >> value" vs "pass by reference" > > > True, but that doesn't mean you should deny that something > is pass-by-value when it actually is. > >> In C, a string is not an >> entity; it's simply an array of characters. Arrays are never passed by >> value; > > > I think it's more accurate to say that arrays are never > passed at all in C. This is technically true; however, it's common to describe a function as "accepting a string" as a parameter. What it actually accepts is a pointer to char. Is that "passing an array by reference"? Not quite. Is it "passing a pointer by value"? Technically correct, but useless. Is it "passing a string by "? Technically incorrect, but probably more useful > A better name for pass-by-value would be "pass-by-assignment". > Passing a parameter by value is equivalent to assigning it > to a local name. That's true in Python too though - parameter passing is equivalent to assigning to a local name. And in C++, where you have actual references, a reference parameter is equivalent to initializing a local reference with the same result. I expect that "parameter passing is equivalent to assignment" is true in the bulk of languages. >> yet everything in C is passed by value. So you pass a >> pointer... by value. > > > Yes, because that's what happens when you assign an array > in C. > > If it seems screwy, it's because assignment is screwy in > C, not parameter passing. Sure, if you define "screwy" as "different from Python". But that's the exact problem that got us where we are. >> What would you define LISP's semantics as? Pass by value? Pass by >> reference? Pass by name? Pass by immutability? Pass the salt? > > > Let's see... the expression being passed gets evaluated > once at the point of call, and the result gets bound to > a local name. Looks exactly like pass-by-value to me. Oh, looks exactly like pass-by-name-binding to me, then. Nothing's getting copied, so it can't be pass-by-value. See how non-simple it is? ChrisA From breamoreboy at gmail.com Mon Sep 4 05:15:54 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Mon, 4 Sep 2017 02:15:54 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <178b2da3-9240-143b-7c29-1780923d52ad@t-online.de> <36mdnXQc6v8B9A_EnZ2dnUU7-f_NnZ2d@giganews.com> <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6fb6e753-e38e-41a9-a106-2cd2d06d57e8@googlegroups.com> On Monday, September 4, 2017 at 3:20:22 AM UTC+1, Chris Angelico wrote: > On Mon, Sep 4, 2017 at 12:05 PM, Steve D'Aprano wrote: > > On Mon, 4 Sep 2017 04:15 am, Stephan Houben wrote: > > > >> Needless to say, according to the definition in Plotkin's paper, Python > >> is "call-by-value". > > > > According to Plotkin's definition, when you pass a value like a 100MB string: > > > > "This is a long string of text..." # continues on for millions more characters > > > > does the interpreter make a copy of the 100MB string? > > > > If not, then it isn't pass (call) by value. > > This is another proof that you can't divide everything into "pass by > value" vs "pass by reference", unless you mess around with "passing a > reference by value" or other shenanigans. In C, a string is not an > entity; it's simply an array of characters. Arrays are never passed by > value; yet everything in C is passed by value. So you pass a > pointer... by value. > > What would you define LISP's semantics as? Pass by value? Pass by > reference? Pass by name? Pass by immutability? Pass the salt? > > ChrisA I can't say that I'm too bothered about all this what with "Practicality beats purity" and all that. Still for the definitive guides to Python I always go back to http://effbot.org/zone/call-by-object.htm and https://jeffknupp.com/blog/2012/11/13/is-python-callbyvalue-or-callbyreference-neither/ Kindest regards. Mark Lawrence. From davidgshi at yahoo.co.uk Mon Sep 4 05:23:33 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Mon, 4 Sep 2017 09:23:33 +0000 (UTC) Subject: Looking for Python examples for querying, selecting items in N-Triples References: <1626586891.3745089.1504517013701.ref@mail.yahoo.com> Message-ID: <1626586891.3745089.1504517013701@mail.yahoo.com> I found this is very confusing. I will appreciate if simple examples are given. Regards, David From sambit2005 at gmail.com Mon Sep 4 05:38:10 2017 From: sambit2005 at gmail.com (Sambit Samal) Date: Mon, 4 Sep 2017 02:38:10 -0700 (PDT) Subject: XML Parsing Message-ID: <53c11ea1-0e1d-4345-ac4a-dacacc680f02@googlegroups.com> Hi , Need help in Python Script using xml.etree.ElementTree to update the value of any element in below XML ( e.g SETNPI to be 5 ) based on some constraint ( e.g ) . DRATRN 1 1 0 ORIG CFORIG TERM 1 1 CONTINUE 2 1 0 TERM 1 1 CONTINUE From antoon.pardon at vub.be Mon Sep 4 06:02:12 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 4 Sep 2017 12:02:12 +0200 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> Message-ID: Op 04-09-17 om 00:44 schreef Dennis Lee Bieber: > And is a limited theoretical study, heavy in mathematics and light in > implementation. > > Programming Languages: Design and Implementation (Terrence W Pratt, > 1975, Prentice-Hall) has a whole section (6-9 Subprograms with Parameters: > Parameter Transmission Techniques)... > > """ > Basic parameter Transmission Techniques > > Transmission by Value: ... the actual parameter is evaluated at the point > of call. The /values/ of the actual parameter is then transmitted to the > subprogram and becomes the initial value associated with the corresponding > formal parameter. ... > > Transmission by Reference (Location or Simple Name): In transmission by > reference a pointer is transmitted, usually a pointer to a data location > containing the value. ... Any assignment to Y in SUB will change the value > of X back in the calling program. IMO that depends on the semantics of the assignment statement. In an environment where an assignment copies the value into the object the variable points to, this is correct. However if assignment provides a new object that is now bound to the variable, it is incorrect. The diagram below tries to illustrate the two different assignment semantics: BEFORE +-----+ +-----+ | | | | | 5 | | 7 | | | | | +-----+ +-----+ ^ ^ | | x = y AFTER C style | Python style | +-----+ +-----+ | +-----+ | | | | | | | | 7 | | 7 | | | 7 | | | | | | ---> | | +-----+ +-----+ | / +-----+ / ^ ^ / ^ | | / | -- Antoon Pardon. From rustompmody at gmail.com Mon Sep 4 06:12:46 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Sep 2017 03:12:46 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <735ad478-53e9-42ce-ae63-69a364ca6c8a@googlegroups.com> On Monday, September 4, 2017 at 1:46:55 PM UTC+5:30, Gregory Ewing wrote: > Stefan Ram wrote: > > JavaScript and Python do not have references as values > > Yes, they do. The difference is that they don't have any > way of *not* having references as values, so there's less > need to use the word explicitly in that way -- most of > the time it's just understood. Well then why these long threads that get nowhere ?? > Nevertheless, terms such > as "object reference" and "reference to an object" do > get used in relation to Python when clarity is needed. Its because reference (or pointer or ?) is central to python's semantics that we need to use them to talk/explain/understand. Its because pointers have been de-first-classed (from C say, as a starting point) that the disagreements arise: - One bunch feel that since they've been de-first-classed they've been removed And could/should not be mentioned - The others feel that since the removal is ?-assed we need to talk of them anyway. All thats gone is the '*' which has become implicit from C's explicit From rosuav at gmail.com Mon Sep 4 06:21:36 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Sep 2017 20:21:36 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: <735ad478-53e9-42ce-ae63-69a364ca6c8a@googlegroups.com> References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <735ad478-53e9-42ce-ae63-69a364ca6c8a@googlegroups.com> Message-ID: On Mon, Sep 4, 2017 at 8:12 PM, Rustom Mody wrote: > On Monday, September 4, 2017 at 1:46:55 PM UTC+5:30, Gregory Ewing wrote: >> Stefan Ram wrote: >> > JavaScript and Python do not have references as values >> >> Yes, they do. The difference is that they don't have any >> way of *not* having references as values, so there's less >> need to use the word explicitly in that way -- most of >> the time it's just understood. > > Well then why these long threads that get nowhere ?? Because these threads are populated by people who know other languages. You can explain Python's semantics with pencil and paper (or, as I like to do it, with a deck of cards and some tetrapaks of sugar) to someone who's never used C, and there's no confusion. The concepts of "pass by value" and "pass by reference" are as irrelevant as the precise semantics of decades-old CPUs or the replacement frequency of valves. ChrisA From __peter__ at web.de Mon Sep 4 06:26:12 2017 From: __peter__ at web.de (Peter Otten) Date: Mon, 04 Sep 2017 12:26:12 +0200 Subject: XML Parsing References: <53c11ea1-0e1d-4345-ac4a-dacacc680f02@googlegroups.com> Message-ID: Sambit Samal wrote: > Hi , > > Need help in Python Script using xml.etree.ElementTree to update the > value of any element in below XML ( e.g SETNPI to be 5 ) based on some > constraint ( e.g ) . Something along the lines from xml.etree import ElementTree as ET tree = ET.parse("original.xml") for e in tree.findall(".//ruleset[@id='2']//SETNPI"): e.text = "5" tree.write("modified.xml") might work for you. > > > DRATRN > > > > 1 > > > 1 > > 0 > ORIG > CFORIG > TERM > > > > > 1 > 1 > > CONTINUE > > > > > 2 > > 1 > > 0 > TERM > > > > > 1 > 1 > > CONTINUE > > From rustompmody at gmail.com Mon Sep 4 06:27:49 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Sep 2017 03:27:49 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> Message-ID: <4e5ab8ba-65f7-4da2-9c51-69703421afee@googlegroups.com> On Monday, September 4, 2017 at 3:35:54 PM UTC+5:30, Antoon Pardon wrote: > Op 04-09-17 om 00:44 schreef Dennis Lee Bieber: > > And is a limited theoretical study, heavy in mathematics and light in > > implementation. > > > > Programming Languages: Design and Implementation (Terrence W Pratt, > > 1975, Prentice-Hall) has a whole section (6-9 Subprograms with Parameters: > > Parameter Transmission Techniques)... > > > > """ > > Basic parameter Transmission Techniques > > > > Transmission by Value: ... the actual parameter is evaluated at the point > > of call. The /values/ of the actual parameter is then transmitted to the > > subprogram and becomes the initial value associated with the corresponding > > formal parameter. ... > > > > Transmission by Reference (Location or Simple Name): In transmission by > > reference a pointer is transmitted, usually a pointer to a data location > > containing the value. ... Any assignment to Y in SUB will change the value > > of X back in the calling program. > > IMO that depends on the semantics of the assignment statement. In an environment > where an assignment copies the value into the object the variable points to, this > is correct. However if assignment provides a new object that is now bound to the > variable, it is incorrect. > > The diagram below tries to illustrate the two different assignment semantics: > > BEFORE > +-----+ +-----+ > | | | | > | 5 | | 7 | > | | | | > +-----+ +-----+ > > ^ ^ > | | > > > > x = y > AFTER > > C style | Python style > | > +-----+ +-----+ | +-----+ > | | | | | | | > | 7 | | 7 | | | 7 | > | | | | | ---> | | > +-----+ +-----+ | / +-----+ > / > ^ ^ / ^ > | | / | > That's fine as far as it goes But then you have people (Steven above) who feel that python passing has no exceptions (in parameter passing) Does a poor job AFAIAC of explaining the difference between foo and bar in foll >>> def foo(x): x += 2 >>> def bar(x): x.append(2) >>> a=10 >>> b=[10] >>> foo(a) >>> a 10 >>> bar(b) >>> b [10, 2] >>> From g.rodola at gmail.com Mon Sep 4 06:35:54 2017 From: g.rodola at gmail.com (Giampaolo Rodola') Date: Mon, 4 Sep 2017 18:35:54 +0800 Subject: ANN: psutil 5.3.0 with full unicode support is out In-Reply-To: References: Message-ID: Mmm thanks for pointing this out. I don't have a Windows machine to test this against right now but it seems you're right and there's something wrong in my example (which is what I recommend in the official doc BTW, so it needs to be fixed). That aside, do you think the rest of my reasoning makes sense? I mean returning str all the time and provide a strategy to convert the string to unicode in Python 2? On Mon, Sep 4, 2017 at 2:54 PM, eryk sun wrote: > On Sun, Sep 3, 2017 at 11:09 PM, Giampaolo Rodola' > wrote: > > > > This is an example which filters processes with a funky name which works > > with both Python 2 > > and 3: > > > > import psutil, sys > > > > PY3 = sys.version_info[0] == 2 > > LOOKFOR = u"???.exe" > > for proc in psutil.process_iter(attrs=['name']): > > name = proc.info['name'] > > if not PY3: > > name = unicode(name, sys.getdefaultencoding(), > errors="replace") > > if LOOKFOR == name: > > print("process %s found" % p) > > > > This is IMO the best compromise for a lib which aims to work on both > Python > > 2 and 3. It's either that or returning Unicode all over the place in > Python > > 2, but that's something I considered and rejected because most of the > times > > the string is not supposed to have funky characters, so "practicality > beats > > purity" in this case. > > The encoded name for ANSI codepage 1252 is "\x83oo.exe". Python 2's > default encoding is ASCII, so the decoded result is u'\ufffdoo.exe'. > Even if it should be the filesystem encoding ('mbcs'), the result is > u"?oo.exe". Neither equals u"???.exe". > > Instead, shouldn't it encode LOOKFOR as "mbcs" with errors="replace" > before comparing it to proc.info['name']? > -- Giampaolo - http://grodola.blogspot.com From rosuav at gmail.com Mon Sep 4 06:37:16 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 4 Sep 2017 20:37:16 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: <4e5ab8ba-65f7-4da2-9c51-69703421afee@googlegroups.com> References: <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <4e5ab8ba-65f7-4da2-9c51-69703421afee@googlegroups.com> Message-ID: On Mon, Sep 4, 2017 at 8:27 PM, Rustom Mody wrote: > That's fine as far as it goes > But then you have people (Steven above) who feel that python passing has > no exceptions (in parameter passing) > Does a poor job AFAIAC of explaining the difference between foo and bar in foll > >>>> def foo(x): x += 2 >>>> def bar(x): x.append(2) >>>> a=10 >>>> b=[10] >>>> foo(a) >>>> a > 10 >>>> bar(b) >>>> b > [10, 2] >>>> It's all about assignment. In foo, you have an assignment statement; in bar, you don't. The diagram showed the behaviour of assignment. ChrisA From antoon.pardon at vub.be Mon Sep 4 06:52:11 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 4 Sep 2017 12:52:11 +0200 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <735ad478-53e9-42ce-ae63-69a364ca6c8a@googlegroups.com> Message-ID: Op 04-09-17 om 12:22 schreef Stefan Ram: > Rustom Mody writes: >>> Stefan Ram wrote: >>>> JavaScript and Python do not have references as values >>> Yes, they do. The difference is that they don't have any > ... >> Its because reference (or pointer or ?) is central to python's semantics > If they are so central, then it should be easy to show > quotes from The Python Language Reference to support that > claim. The section about assignment talks about reference counts. -- Antoon Pardon From ned at nedbatchelder.com Mon Sep 4 07:01:40 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 4 Sep 2017 07:01:40 -0400 Subject: Can I use functions while defining paths? In-Reply-To: References: Message-ID: <76046997-68f2-8e77-5fd8-8ac361bbe0dd@nedbatchelder.com> On 9/4/17 4:08 AM, Andrej Viktorovich wrote: > Hello, > > Trying to import my made module to python with helper function: > > import os.path.join ("D","pyth_nonsens","workspace_python","PyhonTutorial","reader") > > > >>>> import os.path.join ("D","pyth_nonsens","workspace_python","PyhonTutorial","reader") > File "", line 1 > import os.path.join ("D","pyth_nonsens","workspace_python","PyhonTutorial","reader") > ^ > > > Can I use functions while defining paths? As others have said, the import statement takes identifiers, not expressions.? More importantly, it's unusual to try to name a specific absolute path in an import statement. The best thing is to install libraries so that you can import them like this: ??? import reader If you can't import them, the next best thing is to use an environment variable to adjust PYTHONPATH so that the library can be found: ??? PYTHONPATH=D:\pyth_nonsens\workspace_python\PyhonTutorial python myprog.py --Ned. From antoon.pardon at vub.be Mon Sep 4 07:19:02 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 4 Sep 2017 13:19:02 +0200 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <735ad478-53e9-42ce-ae63-69a364ca6c8a@googlegroups.com> Message-ID: Op 04-09-17 om 13:08 schreef Stefan Ram: > Antoon Pardon writes: >> Op 04-09-17 om 12:22 schreef Stefan Ram: >>> Rustom Mody writes: >>>>> Stefan Ram wrote: >>>>>> JavaScript and Python do not have references as values >>>>> Yes, they do. The difference is that they don't have any >>>> Its because reference (or pointer or ?) is central to python's semantics >>> If they are so central, then it should be easy to show >>> quotes from The Python Language Reference to support that >>> claim. >> The section about assignment talks about reference counts. > Yes, but this only matters for the garbage-collection > semantics, not for the main semantics of the assignment. Yes it does, because it implies that an assignment works with references. If the assignment didn't work with references but would work by copying over the old value with the new value, you wouldn't have reference counts nor garbage collection. at this level. -- Antoon Pardon From dvl at psu.edu Mon Sep 4 08:01:59 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Mon, 4 Sep 2017 08:01:59 -0400 Subject: A question on modification of a list via a function invocation Message-ID: <1504526518l.11403280l.0l@psu.edu> >Does a poor job AFAIAC of explaining the difference between foo and bar in foll>>>> def foo(x): x += 2 >>>> def bar(x): x.append(2) >>>> a=10 >>>> b=[10] >>>> foo(a) >>>> a >10 >>>> bar(b) >>>> b >[10, 2] >>>> Or with just one function: >>> def baz(x,y): x += y >>> a = 10 >>> b = [10] >>> baz(a,a) >>> a 10 >>> baz(b,b) >>> b[10, 10] From steve+python at pearwood.info Mon Sep 4 08:57:06 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 04 Sep 2017 22:57:06 +1000 Subject: A question on modification of a list via a function invocation References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59ad4da4$0$1588$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Sep 2017 06:16 pm, Gregory Ewing wrote: > Stefan Ram wrote: >> JavaScript and Python do not have references as values > > Yes, they do. No they don't. Python has ints, floats, strings, lists, tuples, dicts, etc as values. It has no "reference" type, nor can you define your own. (You can create a class and call it "reference", but that doesn't make it one.) You cannot get a reference to either an object, or a name, in Python code. The value of x here: x = 1 is the int 1, not a reference to the int 1. Likewise: y = x the value of y is the int 1, not a reference to the name x. Nor does Python have anything like Pascal's "pointer to" operator: x := ^y; or the equivalent in C: x = &y; nor does Python allow you to write functions with output parameters, like this C++ code: void square(int x, int& result) // result is a reference to an int { result = x * x; } square(3, y); // now y has the value 9 Although Python can emulate something close to output parameters by passing a mutable compound object as the pseudo-output, e.g. by using list slice assignment: def square(x, result): assert isinstance(result, list) result[:] = [x*x] Nor does Python allow assignment to a function call, as you can do in C++ with references. Nor can you implement pass-by-reference in Python, as you can do in C++ with references: void f_slow(BigObject x) { /* ... */ } void f_fast(const BigObject& x) { /* ... */ } f_slow implements normal pass-by-value semantics, and makes a copy of the argument passed as x; f_fast implements pass-by-reference semantics, and does not. Python has no values which are references. Perhaps you are talking about the implementation of some Python interpreters, rather than the Python language itself? If so, you should say so. > The difference is that they don't have any > way of *not* having references as values, Of course it does, in the same way it has no way of using unicorns as values. You can't use what doesn't exist. Since Python does not have references as one of its first-class values, or as any value at all, you can't use them as values. All values in Python are objects, not references. > so there's less > need to use the word explicitly in that way -- most of > the time it's just understood. Nevertheless, terms such > as "object reference" and "reference to an object" do > get used in relation to Python when clarity is needed. Certainly they do. That has nothing to do with the question of whether Python has references as values. We use the terms "assignment target", "while loop" and "pass statement" in Python too, but that doesn't make them values. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Mon Sep 4 08:57:58 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 04 Sep 2017 22:57:58 +1000 Subject: meaning of [ ] References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> Message-ID: <59ad4dd8$0$1588$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Sep 2017 01:36 pm, Rustom Mody wrote: > Tsk tsk the confusioning continues Rustom, it is generally considered that we should do our best to *reduce* confusion, not increase it. *wink* > Rewrite > [p for p in sys.path] > as > [p | p ? sys.path] > > Is that clearer? No. What is "|" in that supposed to mean? - a Unix pipe? - bitwise "or"? - logical "or"? - an opening absolute value delimiter, |x|, missing the closing one? - or the other way around? - half of a "parallel" symbol? - half of a bra-ket symbol? - the divides operator? not division, divides, as in "5 divides 10" = 5|10 - Sheffer stroke (nand)? - conditional probability? - the dental click in Khoisan languages? or one of about twenty or thirty other meanings. Which one do you intend, and what makes you believe that the OP would guess the same one? > As Peter pointed out this is a no-op > ie > [p for p in sys.path] > > could be written as > list(sys.path) That's not what "no-op" means. If it returns a result, it isn't a no-op. > [Not sure why he didnt say just sys.path] Because sys.path returns the same list, [p for p in sys.path] returns a new list. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ben.usenet at bsb.me.uk Mon Sep 4 09:05:51 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Mon, 04 Sep 2017 14:05:51 +0100 Subject: meaning of [ ] References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> Message-ID: <87d176fwb4.fsf@bsb.me.uk> Rustom Mody writes: > On Sunday, September 3, 2017 at 5:10:13 PM UTC+5:30, Rick Johnson wrote: >> Andrej Viktorovich wrote: >> > I suppose p becomes array of strings but what [] means in this statement? >> >> Generally, it's an inline form of writing a loop that returns a >> list. There are other types as well. > > Tsk tsk the confusioning continues > > Rewrite > [p for p in sys.path] > as > [p | p ? sys.path] > > Is that clearer? > > And then as > > {p | p ? sys.path} > And refresh the idea of set-builder notation > http://www.mathwords.com/s/set_builder_notation.htm But [p for p in sys.path] is a list and "set-builder" notation is used for sets. Order is crucial for sys.path. You say exactly that below so I don't see how referring to sets helps anyone understand lists. > As Peter pointed out this is a no-op > ie > [p for p in sys.path] > > could be written as > list(sys.path) Both make a copy -- that's not a no-op. It may be a very-little-op but not nothing. > [Not sure why he didnt say just sys.path] Because he wanted code equivalent to [p for p in sys.path]. > Anyway this is a good example to distinguish > > [p for p in sys.path] > from > {p for p in sys.path} > > Both work in python > But the second is probably not correct because path-searching is order > dependent Right. So i'm puzzled why you suggest that [p for p in sys.path] should be understood by reading about set-builder notation. -- Ben. From steve+python at pearwood.info Mon Sep 4 09:24:46 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 04 Sep 2017 23:24:46 +1000 Subject: A question on modification of a list via a function invocation References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <735ad478-53e9-42ce-ae63-69a364ca6c8a@googlegroups.com> Message-ID: <59ad541f$0$1584$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Sep 2017 08:12 pm, Rustom Mody wrote: > Its because reference (or pointer or ?) is central to python's semantics > that we need to use them to talk/explain/understand. References are central to understanding the implementation of Python interpreters. (Perhaps not *all* interpreters, but using references of some sort is the most obvious and easy way to implement Python's semantics.) Dropping down into the implementation level and talking about references is often useful. But it is not essential -- one can explain a lot of code without any reference to "reference" ( pun intended *wink* ) at all. If we're willing to accept a conceptual model where Python objects are capable of being in two or more locations at once, we can explain ALL Python code without needing references. I accept that many people dislike, or do not understand, conceptual models where objects can be in more than one location at once. For many people, dropping into the implementation and talking about references is easier to understand. But that doesn't make it essential. The semantics of Python is that we assign objects to names, not references to objects to names. There's no "get reference" or "address of" operation in Python. We write: x = y not x = &y The interpreter may (or may not) use references or pointers in order to implement Python's object model, but strictly outside of the scope of Python the language. > Its because pointers have been de-first-classed (from C say, as a starting > point) that the disagreements arise: - One bunch feel that since they've been > de-first-classed they've been removed Pointers are not merely second-class values, like functions and procedures in Pascal, or strings in C. They're not values *at all*. Its not just that Python doesn't allow you to return a pointer from a function, or pass a pointer to a function as argument. You cannot dereference a pointer either, or get a pointer to an object at all. (Although you can emulate pointers in Python using objects.) For more about first-class values, see this Stackoverflow thread: https://stackoverflow.com/questions/2578872/about-first-second-and-third-class-value We can quibble whether Pascal functions are first-, second- or first-and-a-half class values, or whether "third-class" even makes sense, but pointers, and references, are not values of *any* class in Python. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Mon Sep 4 09:26:58 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 04 Sep 2017 23:26:58 +1000 Subject: A question on modification of a list via a function invocation References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <735ad478-53e9-42ce-ae63-69a364ca6c8a@googlegroups.com> Message-ID: <59ad54a2$0$1584$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Sep 2017 08:52 pm, Antoon Pardon wrote: > Op 04-09-17 om 12:22 schreef Stefan Ram: >> Rustom Mody writes: >>>> Stefan Ram wrote: >>>>> JavaScript and Python do not have references as values >>>> Yes, they do. The difference is that they don't have any >> ... >>> Its because reference (or pointer or ?) is central to python's semantics >> If they are so central, then it should be easy to show >> quotes from The Python Language Reference to support that >> claim. > > The section about assignment talks about reference counts. Does that mean that IronPython and Jython aren't implementations of Python? They have no reference counts. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From antoon.pardon at vub.be Mon Sep 4 09:30:53 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 4 Sep 2017 15:30:53 +0200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59ad541f$0$1584$c3e8da3$5496439d@news.astraweb.com> References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <735ad478-53e9-42ce-ae63-69a364ca6c8a@googlegroups.com> <59ad541f$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58bec65b-b770-f549-4c50-c471e2b8cf68@vub.be> Op 04-09-17 om 15:24 schreef Steve D'Aprano: > I accept that many people dislike, or do not understand, conceptual models where > objects can be in more than one location at once. For many people, dropping > into the implementation and talking about references is easier to understand. > But that doesn't make it essential. > > The semantics of Python is that we assign objects to names, not references to > objects to names. There's no "get reference" or "address of" operation in > Python. We write: What does that mean assigning objects to names? >> Its because pointers have been de-first-classed (from C say, as a starting >> point) that the disagreements arise: - One bunch feel that since they've been >> de-first-classed they've been removed > Pointers are not merely second-class values, like functions and procedures in > Pascal, or strings in C. They're not values *at all*. > > Its not just that Python doesn't allow you to return a pointer from a function, > or pass a pointer to a function as argument. You cannot dereference a pointer > either, or get a pointer to an object at all. (Although you can emulate > pointers in Python using objects.) > > > For more about first-class values, see this Stackoverflow thread: > > https://stackoverflow.com/questions/2578872/about-first-second-and-third-class-value > > We can quibble whether Pascal functions are first-, second- or first-and-a-half > class values, or whether "third-class" even makes sense, but pointers, and > references, are not values of *any* class in Python. > > > > From steve+python at pearwood.info Mon Sep 4 09:46:19 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 04 Sep 2017 23:46:19 +1000 Subject: A question on modification of a list via a function invocation References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <178b2da3-9240-143b-7c29-1780923d52ad@t-online.de> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Sep 2017 01:31 pm, Stefan Ram wrote: > Steve D'Aprano writes: >>That makes arrays (and strings) in C a bit of an odd corner case, and an >>exception to the usual rules, like unboxed machine types in Java. We should >>acknowledge them, but as exceptional cases, and we should note that Python has >>no similar exceptional cases. All values in Python are first-class, and all >>are passed in precisely the same way. > > I look at the following "generic" (C, Java, Python, ...) > pseudocode program: > > define f( x ): > x = 9; > return; > > ... > > a = 2; > f( a ); > print( a ); > > My definition: When the assignment ?x = 9? has an effect on ?a?, > then it's ?call by reference?. Otherwise, it's call by value. Sorry Stefan, that is the same trap that many others fall into. You are assuming that there are exactly two evaluation conventions: - pass by reference - pass by value and so if a language doesn't do one, it must do the other. This is a false dichotomy! There are many more than just two conventions: - pass by value - pass by reference - pass by name - pass by object reference (object sharing) - pass by need - pass by future - pass by copy-restore and more. https://en.wikipedia.org/wiki/Evaluation_strategy You are right that Python is not pass by reference. You cannot write a general swap procedure in Python: a = 1 b = 2 swap(a, b) assert a == 2 and b == 1 like you can in Pascal: procedure swap(var a:integer, var b: integer); var tmp: integer; begin tmp := a; a := b; b := tmp; end; But that's not enough to prove that Python is pass by value. One way to demonstrate that Python is pass by value is to show that passing an argument to a function makes a copy of it: def is_copy_made(argument, idnumber): """Decide whether the argument was copied or not.""" if id(argument) == idnumber: print('IDs match, no copy was made') else: print('IDs are different, copy was made') value = {} # any object is_copy_made(value, id(value)) Python will ALWAYS print "IDs match" (provided you pass the actual id of the argument -- no cheating by passing some other id, or an arbitrary number). Python doesn't copy values when you pass them to functions. Hence Python is neither pass by reference nor pass by value. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From antoon.pardon at vub.be Mon Sep 4 10:09:14 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 4 Sep 2017 16:09:14 +0200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59ad54a2$0$1584$c3e8da3$5496439d@news.astraweb.com> References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <735ad478-53e9-42ce-ae63-69a364ca6c8a@googlegroups.com> <59ad54a2$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: Op 04-09-17 om 15:26 schreef Steve D'Aprano: > On Mon, 4 Sep 2017 08:52 pm, Antoon Pardon wrote: > >> Op 04-09-17 om 12:22 schreef Stefan Ram: >>> Rustom Mody writes: >>>>> Stefan Ram wrote: >>>>>> JavaScript and Python do not have references as values >>>>> Yes, they do. The difference is that they don't have any >>> ... >>>> Its because reference (or pointer or ?) is central to python's semantics >>> If they are so central, then it should be easy to show >>> quotes from The Python Language Reference to support that >>> claim. >> The section about assignment talks about reference counts. > Does that mean that IronPython and Jython aren't implementations of Python? They > have no reference counts. I am not a lawyer -- Antoon Pardon From steve+python at pearwood.info Mon Sep 4 10:20:25 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 05 Sep 2017 00:20:25 +1000 Subject: A question on modification of a list via a function invocation References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <178b2da3-9240-143b-7c29-1780923d52ad@t-online.de> <36mdnXQc6v8B9A_EnZ2dnUU7-f_NnZ2d@giganews.com> <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <29c67315-6ede-40c0-854b-740ee73eeaf6@googlegroups.com> Message-ID: <59ad612a$0$1609$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Sep 2017 01:11 pm, Rustom Mody wrote: > Earlier > Ben Bacarisse wrote: >> The core of the idea is actually what the value-set of Python programs is -- > > Yes! That!! Indeed. Given the assignment: x = 1 then I think we all agree that the value of x is 1. So far so good. But then, in order to force the round peg of Python's actual behaviour into the square hole of "pass by value", some people insist that while the value of x is indeed 1, as we agreed above, it is also, simultaneously, some invisible, unknowable, implementation-dependent "reference" that we cannot access in any way without leaving the domain of the language itself. (E.g. by hacking the interpreter, using ctypes, or taking advantage of implementation-dependent hooks which are strictly outside of the language itself, such as debugging hooks.) In a way, it is an example of reductionism gone mad, as if a chemist insisted that there are no people, animals or cars in the world, there are only molecules. (Of course this is silly. As all physicists know, there are no people, animals or cars in the world, there are only quarks and electrons.) > Parameter-passing models and nomenclature is really a red-herring No, they are very relevant. They are all connected. But you cannot agree on what the parameter passing models mean if you cannot even agree on what your language's values are. If you want to believe that the value of x above is something other than 1, then you can conclude anything you like. And who knows, maybe you'll even find an implementation of Python where it is true. Personally, I believe that the value of x is actually a series of cytosine, guanine, adenine and thymine nucleobases, and some day when Python runs on a DNA computer I'll be proven right. https://en.wikipedia.org/wiki/DNA_computing *wink* > Its the ?== is id? mess that is at the base of the mess: That is irrelevant. > Simply put: pythonistas have no coherent/consistent sense of what python > values are. And the endless parameter-passing-nomenclature arguments are just > the fallout of that. This is not a dispute unique to the Python community. Similar arguments take place in the Java and Ruby communities, and I daresay many others. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Mon Sep 4 10:27:01 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Sep 2017 07:27:01 -0700 (PDT) Subject: meaning of [ ] In-Reply-To: <87d176fwb4.fsf@bsb.me.uk> References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> Message-ID: On Monday, September 4, 2017 at 6:36:11 PM UTC+5:30, Ben Bacarisse wrote: > Rustom Mody writes: > > > On Sunday, September 3, 2017 at 5:10:13 PM UTC+5:30, Rick Johnson wrote: > >> Andrej Viktorovich wrote: > >> > I suppose p becomes array of strings but what [] means in this statement? > >> > >> Generally, it's an inline form of writing a loop that returns a > >> list. There are other types as well. > > > > Tsk tsk the confusioning continues > > > > Rewrite > > [p for p in sys.path] > > as > > [p | p ? sys.path] > > > > Is that clearer? > > > > And then as > > > > {p | p ? sys.path} > > And refresh the idea of set-builder notation > > http://www.mathwords.com/s/set_builder_notation.htm > > But [p for p in sys.path] is a list and "set-builder" notation is used > for sets. Order is crucial for sys.path. You say exactly that below so > I don't see how referring to sets helps anyone understand lists. Clearly if the question was of *sets* vs *lists* the distinction is at least as crucial, maybe even more so than the similarity. The OP-question here however is one about comprehensions and it appears without the questioner realizing that ? as Peter's answer showed See the very first line of this: https://en.wikipedia.org/wiki/List_comprehension ?List comprehension follows the form of the mathematical set-builder notation (set comprehension)? ie its both historically and structurally linked IOW emphasising the incidental sequential nature of the computation at the cost of the fundamental structure-preserving nature of the concept > > > > As Peter pointed out this is a no-op > > ie > > [p for p in sys.path] > > > > could be written as > > list(sys.path) > > Both make a copy -- that's not a no-op. It may be a very-little-op but > not nothing. Its important? - whether the machine stack grows up or down - whether the bytes are ordered little-endian or big-endian - whether IO is polled or interrupt driven - whether IO ports are memory-mapped or in separate IO space And much else Yet for most people doing most things today in most languages, these questions are irrelevated The question of copying is likewise, from a certain point of view, irrelevant. Of course the further context of the OP may have a mutation on the list And if he does end up changing sys.path, and not intending it, that would be a source of nasty bugs for sure But why assume all that when he does not (yet) know what it is he is writing More importantly thinks its a *command* when its actually an *expression* etc? (IMHO an unfortunate consequence of the confusing overloading of the 'for' keyword) > > > [Not sure why he didnt say just sys.path] > > Because he wanted code equivalent to [p for p in sys.path]. > > > Anyway this is a good example to distinguish > > > > [p for p in sys.path] > > from > > {p for p in sys.path} > > > > Both work in python > > But the second is probably not correct because path-searching is order > > dependent > > Right. So i'm puzzled why you suggest that [p for p in sys.path] should > be understood by reading about set-builder notation. Since "-builder" and "-comprehension" (in this context) are synonymous?? [ https://en.wikipedia.org/wiki/Set-builder_notation ] And I am ready to make a small wager - that the OP knows of these - with math-hat on - And is simply confused by the clunky ASCII syntax From davidgshi at yahoo.co.uk Mon Sep 4 10:28:55 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Mon, 4 Sep 2017 14:28:55 +0000 (UTC) Subject: How best to search and get values of label in N-Triples References: <1476100015.4200465.1504535335238.ref@mail.yahoo.com> Message-ID: <1476100015.4200465.1504535335238@mail.yahoo.com> I have a parsed N-Triples file, having many items like the following. "Baddesley Clinton E04009816"@en . "Live" . "E04009816" . How best to search and get values of label? Regards, David From steve+python at pearwood.info Mon Sep 4 10:30:33 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 05 Sep 2017 00:30:33 +1000 Subject: A question on modification of a list via a function invocation References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <735ad478-53e9-42ce-ae63-69a364ca6c8a@googlegroups.com> <59ad54a2$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59ad638a$0$1604$c3e8da3$5496439d@news.astraweb.com> On Tue, 5 Sep 2017 12:09 am, Antoon Pardon wrote: > Op 04-09-17 om 15:26 schreef Steve D'Aprano: >> On Mon, 4 Sep 2017 08:52 pm, Antoon Pardon wrote: >> >>> Op 04-09-17 om 12:22 schreef Stefan Ram: >>>> Rustom Mody writes: >>>>>> Stefan Ram wrote: >>>>>>> JavaScript and Python do not have references as values >>>>>> Yes, they do. The difference is that they don't have any >>>> ... >>>>> Its because reference (or pointer or ?) is central to python's semantics >>>> If they are so central, then it should be easy to show >>>> quotes from The Python Language Reference to support that >>>> claim. >>> The section about assignment talks about reference counts. >> Does that mean that IronPython and Jython aren't implementations of Python? >> They have no reference counts. > > I am not a lawyer But you are a Python programmer. You should be aware that reference counts are a property of the CPython implementation, not a language feature. Jython and IronPython, at the very least, are valid, conforming implementations of Python the language which have no reference counts. Therefore reference counts cannot be central to Python's semantics, since there are Python interpreters that don't use them. Analogy: we might say that spark plugs are essential, or central, to cars. But since there are electric cars without spark plugs (and, in the early years of automotive technology, steam-powered cars without spark plugs) that would be wrong. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Mon Sep 4 10:34:51 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Sep 2017 07:34:51 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> Message-ID: On Monday, September 4, 2017 at 5:58:18 PM UTC+5:30, ROGER GRAYDON CHRISTMAN wrote: > >Does a poor job AFAIAC of explaining the difference between foo and bar in > foll>>>> def foo(x): x += 2 > >>>> def bar(x): x.append(2) > >>>> a=10 > >>>> b=[10] > >>>> foo(a) > >>>> a > >10 > >>>> bar(b) > >>>> b > >[10, 2] > >>>> > Or with just one function: >>> def baz(x,y): > x += y > >>> a = 10 > >>> b = [10] > >>> baz(a,a) > >>> a > 10 > >>> baz(b,b) > >>> b[10, 10] Ha Ha! Lovely [I was about to ask Chris if he is being serious about relating this to the presence of '=' ] However if you desugar the += into __iadd__ then someone may argue the presence of the = is an optical illusion From steve+python at pearwood.info Mon Sep 4 10:43:41 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 05 Sep 2017 00:43:41 +1000 Subject: A question on modification of a list via a function invocation References: <06682e35-9481-db00-6895-63496a4802f7@nedbatchelder.com> <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <735ad478-53e9-42ce-ae63-69a364ca6c8a@googlegroups.com> <59ad541f$0$1584$c3e8da3$5496439d@news.astraweb.com> <58bec65b-b770-f549-4c50-c471e2b8cf68@vub.be> Message-ID: <59ad669e$0$1611$c3e8da3$5496439d@news.astraweb.com> On Mon, 4 Sep 2017 11:30 pm, Antoon Pardon wrote: > Op 04-09-17 om 15:24 schreef Steve D'Aprano: >> I accept that many people dislike, or do not understand, conceptual models >> where objects can be in more than one location at once. For many people, >> dropping into the implementation and talking about references is easier to >> understand. But that doesn't make it essential. >> >> The semantics of Python is that we assign objects to names, not references to >> objects to names. There's no "get reference" or "address of" operation in >> Python. We write: > > What does that mean assigning objects to names? Would it help if I use the term "bind" instead? All values in Python are objects. Assignment looks like this: target = expression and Python evaluates the expression on the right, producing an object, and then binds it to the target in the left. The target is often a simple name, like: foo = 1 but if you want to be pedantic[1] the target can also be more complicated: func(arg).foo[bar] = 1 The glossary unfortunately doesn't define either name binding or assignment: https://docs.python.org/3/glossary.html but the Language Reference describes name binding: https://docs.python.org/3/reference/executionmodel.html#naming-and-binding and Wikipedia has a good description of it: https://en.wikipedia.org/wiki/Name_binding [1] And why not, I would if I were in your position *wink* -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Mon Sep 4 10:50:49 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Sep 2017 07:50:49 -0700 (PDT) Subject: meaning of [ ] In-Reply-To: References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> Message-ID: <5356b6d5-8084-4866-b68b-be5e1034b31a@googlegroups.com> On Monday, September 4, 2017 at 7:57:23 PM UTC+5:30, Rustom Mody wrote: > On Monday, September 4, 2017 at 6:36:11 PM UTC+5:30, Ben Bacarisse wrote: > > But [p for p in sys.path] is a list and "set-builder" notation is used > > for sets. Order is crucial for sys.path. You say exactly that below so > > I don't see how referring to sets helps anyone understand lists. > > Clearly if the question was of *sets* vs *lists* the distinction is at least as > crucial, maybe even more so than the similarity. > The OP-question here however is one about comprehensions and it appears without > the questioner realizing that ? as Peter's answer showed > > See the very first line of this: > https://en.wikipedia.org/wiki/List_comprehension > ?List comprehension follows the form of the mathematical set-builder notation (set comprehension)? > > ie its both historically and structurally linked > IOW emphasising the incidental sequential nature of the computation > at the cost of the fundamental structure-preserving nature of the concept Incomplete; I meant to say: ie its both historically and structurally linked. IOW emphasising the incidental sequential nature of the computation at the cost of the fundamental structure-preserving nature of the concept seems to be some ()*&^$W# behavior on the part of people instructing python The essential meaning of comprehensions is the following diagrams not the for-loop implementation If l is [x?, x?,? x? ] [f(x) for x in l] means this picture: [x?, x?,? x? ] ? ?? ? [f(x?), f(x?),? f(x?)] Likewise If s is {x?, x?,? x?} {f(x) for x in s} means this picture: {x?, x?, ? x?} ? ? ? ? {f(x?), f(x?),? f(x?)} From rustompmody at gmail.com Mon Sep 4 10:59:58 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Sep 2017 07:59:58 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: <59ad612a$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <178b2da3-9240-143b-7c29-1780923d52ad@t-online.de> <36mdnXQc6v8B9A_EnZ2dnUU7-f_NnZ2d@giganews.com> <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <29c67315-6ede-40c0-854b-740ee73eeaf6@googlegroups.com> <59ad612a$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <55288096-73c1-41c3-92bd-56c2fa72e7d3@googlegroups.com> On Monday, September 4, 2017 at 7:50:39 PM UTC+5:30, Steve D'Aprano wrote: > On Mon, 4 Sep 2017 01:11 pm, Rustom Mody wrote: > > Simply put: pythonistas have no coherent/consistent sense of what python > > values are. And the endless parameter-passing-nomenclature arguments are just > > the fallout of that. > > This is not a dispute unique to the Python community. Similar arguments take > place in the Java and Ruby communities, and I daresay many others. Well good to know we agree on this [I would add lisp to this list since its the progenitor of this model] And it is a primary factor for the desirability of transcending the imperative paradigm From steve+python at pearwood.info Mon Sep 4 11:07:21 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 05 Sep 2017 01:07:21 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> Message-ID: <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> On Tue, 5 Sep 2017 12:34 am, Rustom Mody wrote: > On Monday, September 4, 2017 at 5:58:18 PM UTC+5:30, ROGER GRAYDON CHRISTMAN > wrote: >> Or with just one function: >>> def baz(x,y): >> x += y >> >>> a = 10 >> >>> b = [10] >> >>> baz(a,a) >> >>> a >> 10 >> >>> baz(b,b) >> >>> b[10, 10] > > Ha Ha! Lovely > > [I was about to ask Chris if he is being serious about relating this to the > presence of '=' ] > > However if you desugar the += into __iadd__ then someone may argue > the presence of the = is an optical illusion I'm afraid I can't quite follow what people think this example actually demonstrates. Augmented assignment operators += etc. are explicitly defined as a form of assignment, but objects are permitted to optimize the operation in terms of in-place mutation as well. And that is precisely what lists do. Given lists b and c, as above, b += c is functionally equivalent to: b.extend(c) b = b In this case, the assignment is a no-op, but that is not always the case. The assignment is the cause of a notorious "WAT?" moment in Python: py> t = ([], 0) py> t[0] += [999] Traceback (most recent call last): File "", line 1, in TypeError: 'tuple' object does not support item assignment py> t ([999], 0) In this case, the line t[0] += [999] is desugared into something like: t[0].extend([999]) # succeeds t[0] = t[0] # fails Of course it would be stupid if that were *literally* what Python did. Rather, Python calls the __iadd__ method of the list, which is implemented something like this: def __iadd__(self, other): self.extend(other) return self and attempts to bind the return result to the target: temp = t[0].__iadd__([999]) t[0] = temp The assignment is necessary to support types like tuples, ints, strings etc. which don't perform an in-place modification. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Mon Sep 4 11:17:25 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Sep 2017 08:17:25 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> On Monday, September 4, 2017 at 8:37:45 PM UTC+5:30, Steve D'Aprano wrote: > On Tue, 5 Sep 2017 12:34 am, Rustom Mody wrote: > > > On Monday, September 4, 2017 at 5:58:18 PM UTC+5:30, ROGER GRAYDON CHRISTMAN > > wrote: > >> Or with just one function: >>> def baz(x,y): > >> x += y > >> >>> a = 10 > >> >>> b = [10] > >> >>> baz(a,a) > >> >>> a > >> 10 > >> >>> baz(b,b) > >> >>> b[10, 10] > > > > Ha Ha! Lovely > > > > [I was about to ask Chris if he is being serious about relating this to the > > presence of '=' ] > > > > However if you desugar the += into __iadd__ then someone may argue > > the presence of the = is an optical illusion > > I'm afraid I can't quite follow what people think this example actually > demonstrates. Anton gave a picture explaining why/how references are needed and to be understood I pointed out that while that picture is fine (and necessary) as part of the explanation, it does not properly address the central question of this thread, viz How to understand parameter passing in python. With this example: >>> def foo(x): x += 2 >>> def bar(x): x.append(2) >>> a=10 >>> b=[10] >>> foo(a) >>> a 10 >>> bar(b) >>> b [10, 2] >>> Roger Christman compressed my foo and bar into one baz def baz(x,y): x += y Which leaks or doesnt leak x-modifications depending on its type From steve+python at pearwood.info Mon Sep 4 11:29:18 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 05 Sep 2017 01:29:18 +1000 Subject: A question on modification of a list via a function invocation References: <178b2da3-9240-143b-7c29-1780923d52ad@t-online.de> <36mdnXQc6v8B9A_EnZ2dnUU7-f_NnZ2d@giganews.com> <1f666425-7311-cb6b-44d6-3c5880fa7b26@t-online.de> <5742ab0b-6bc7-cf7a-e003-ca21ca9bb16f@nedbatchelder.com> <305746fb-66cb-7acb-82d4-e0c6987438a6@t-online.de> <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <29c67315-6ede-40c0-854b-740ee73eeaf6@googlegroups.com> <59ad612a$0$1609$c3e8da3$5496439d@news.astraweb.com> <55288096-73c1-41c3-92bd-56c2fa72e7d3@googlegroups.com> Message-ID: <59ad714f$0$1615$c3e8da3$5496439d@news.astraweb.com> On Tue, 5 Sep 2017 12:59 am, Rustom Mody wrote: > On Monday, September 4, 2017 at 7:50:39 PM UTC+5:30, Steve D'Aprano wrote: >> On Mon, 4 Sep 2017 01:11 pm, Rustom Mody wrote: >> > Simply put: pythonistas have no coherent/consistent sense of what python >> > values are. And the endless parameter-passing-nomenclature arguments are >> > just the fallout of that. >> >> This is not a dispute unique to the Python community. Similar arguments take >> place in the Java and Ruby communities, and I daresay many others. > > Well good to know we agree on this [I would add lisp to this list since its > the progenitor of this model] > > And it is a primary factor for the desirability of transcending the imperative > paradigm This is completely unrelated to the imperative paradigm. You just said it yourself: the question of function calling conventions applies to functional languages like Lisp as well. It even applies to purely functional languages like Haskell: https://softwareengineering.stackexchange.com/questions/184586/devising-test-of-haskells-value-reference-semantics I especially love that one of the top-rated answers says that Haskell simultaneously: - doesn't have references; - therefore Haskell is call-by-value; - except that it actually has call-by-reference semantics; - except that it is actually call-by-name; - except that it is actually call-by-need. The imperative paradigm has nothing to do with this. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From davidgshi at yahoo.co.uk Mon Sep 4 11:41:43 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Mon, 4 Sep 2017 15:41:43 +0000 (UTC) Subject: Can some one give examples of how to use graph.label to get data values while dealing with N-Triples files? References: <1333927107.4303566.1504539703987.ref@mail.yahoo.com> Message-ID: <1333927107.4303566.1504539703987@mail.yahoo.com> How to used graph.label to get data values like 'Baddesley Clinton E04009816'? "Baddesley Clinton E04009816"@en . "Live" . "E04009816" . Regards, David From steve+python at pearwood.info Mon Sep 4 11:43:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 05 Sep 2017 01:43:22 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> Message-ID: <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> On Tue, 5 Sep 2017 01:17 am, Rustom Mody wrote: > Anton gave a picture explaining why/how references are needed and to be > understood Antoon gave a picture demonstrating one model of Python's semantics. It's a nice model that has a lot going for it, in particular that it matches the most obvious implementation. But it doesn't describe *Python* semantics, it describes an overlap between Python the language and the implementation of the Python interpreter. In particular, consider the picture of a name binding to a value: +-----+ | | | 5 | | | +-----+ ^ | This picture has three entities, but only two of them exist in Python: - the object 5; - the name "x" (names are not values in Python at runtime, but they are entities which exist in Python source code at compile time). The third entity is the reference linking the name to the object (the arrow). This isn't a runtime value in Python, nor is it a compile time entity that exists in source code. It is pure implementation, and as such, exists outside of the Python domain. I'm not saying that we should never use this model. Its a good model. But we should be clear that it is a model of the implementation, and it describes entities which are not part of the Python language. We cannot do this: +-----+ | | | 5 | | | +-----+ ^ | ^ | or any of the other things we can do in a language with references-as-values, like C or Pascal. [...] > Roger Christman compressed my foo and bar into one baz > > def baz(x,y): > x += y > > Which leaks or doesnt leak x-modifications depending on its type Yes, I see that -- but I don't see the point of it. What conclusion do you draw from that? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Mon Sep 4 12:13:05 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Sep 2017 09:13:05 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <157c2dcb-8d38-4377-8884-f6d049bf7521@googlegroups.com> On Monday, September 4, 2017 at 9:13:43 PM UTC+5:30, Steve D'Aprano wrote: > On Tue, 5 Sep 2017 01:17 am, Rustom Mody wrote: > > > Anton gave a picture explaining why/how references are needed and to be > > understood > > Antoon gave a picture demonstrating one model of Python's semantics. > > It's a nice model that has a lot going for it, in particular that it matches the > most obvious implementation. But it doesn't describe *Python* semantics, it > describes an overlap between Python the language and the implementation of the > Python interpreter. > > In particular, consider the picture of a name binding to a value: > > > +-----+ > | | > | 5 | > | | > +-----+ > ^ > | > > > > This picture has three entities, but only two of them exist in Python: > > - the object 5; > > - the name "x" (names are not values in Python at runtime, but they > are entities which exist in Python source code at compile time). > > The third entity is the reference linking the name to the object (the arrow). > This isn't a runtime value in Python, nor is it a compile time entity that > exists in source code. It is pure implementation, and as such, exists outside > of the Python domain. A common fallacy: https://en.wikipedia.org/wiki/Begging_the_question Python does not have references/pointers/whatever ? Python does not have references (or whatever you want to (not) call it) From rantingrickjohnson at gmail.com Mon Sep 4 12:37:16 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 4 Sep 2017 09:37:16 -0700 (PDT) Subject: Can I use functions while defining paths? In-Reply-To: References: Message-ID: <36c75533-1802-406a-aba9-691e90094b06@googlegroups.com> > Trying to import my made module to python with helper function: > > import os.path.join ("D","pyth_nonsens","workspace_python","PyhonTutorial","reader") There are esoteric methods by which one can import a python module from a filepath, but doing so is not considered good practice, and the import statement was not designed with filepaths in mind. Is there a good reason why you want import from a filepath, as opposed to using the "module identifier"? Did another language teach you to do this? The standard method to share objects between modules is to use the import statement. It seems you understand the first step, but you do not understand how "import" works, nor the limitations of it. Generally speaking, if you intend to borrow the objects from "scriptA.py" and use them in "scriptB.py", then "import scriptA" or "from scriptA import blah" is all you need, *HOWEVER*, in order for these imports to produce desirable results, "scriptA" must be somewhere that Python knows to look. And Python does not adopt the same youthful exuberance observed in christian children on the morning of easter sunday... You cannot just randomly place scripts on your HD and expect that an import request will find them, no, "import" will only look in a few predefined locations for the requested module (and you can investigate these locations for yourself by printing sys.path). So, if you'd like to store your importable modules _outside_ of the scope of the default search path, then you'll need to add the containing directory to python's search path manually. Here's a little info on the search path: https://docs.python.org/3/tutorial/modules.html#the-module-search-path Personaly, i prefer to us a *.pth file to define my custom search path additions, as I can add or remove this customization by adding or removing a single file. Plus, the *.pth file offers an easy method by which to persist these paths through time and across subsequent and diverse installations. It's a practical solution because i no longer concern myself with remembering multiple paths (some of which are quite complex!), no, i only need to copy+paste a single file. I suppose there are some cons to this approach, as python is probably reading this file at every invocation of the interpreter. But do i care that python has to sweat a little more to save me some labour -- *NOPE*!. What good is to be found in slaveownership, if the slaveowner cannot offload the onerous on someone, or something else? From my point of view, the amount of work that Python does is irrelevant to me, so long as the time required to do the work is tolerable to myself and/or my clients. "Premature optimization is the root of all evil (or at least most of it)..." they say. So what's more important: that a program produces a result that is correct, or that a program produces a questionable result in the quickest time? The sane design philosophy is that a program should produce a correct result in the shortest time possible. But the "shortest time possible" does not mean that we sacrifice practical necessity on the alters of speed. If we devote our time to squeezing every drop of speed juice from the lemon, that is time that could have been spent expanding the feature set, or in some other practical pursuit. The blazing fast technology of the modern era has removed optimization as our primary goal, and has shifted our priorities to concentrate on the more practical needs of software development, namely: intuitive interfaces and feature richness. We can always come back later and squeeze a few more drops from that lemon. > >>> import os.path.join ("D","pyth_nonsens","workspace_python","PyhonTutorial","reader") > File "", line 1 > import os.path.join ("D","pyth_nonsens","workspace_python","PyhonTutorial","reader") > ^ I've never understood this proclivity of newbies to cobble multiple irrelevant actions into one test suite, as though they were preparing a fruit cake for the oven, and then, after tossing the whole discombobulated mess at a python interpreter hoping that it will stick, the resulting exception (yeah, big surprise!) causes them to assume there is no easy answer. In this case, the contemptible action is not ignorance, no, it is a poor methodology (ignorance can be forgiven, whereas, a poor methodology cannot). If the OP's intent is to test whether or not the import statement will accept filepaths, and the OP cannot be bothered to read the docs, then it would be behoove the OP to utilize the smallest, non-distracting example that will test this conjecture. There is nothing inherently wrong about assumption, sure, there are more acceptable scientific methods by which we may gain insights into the unknown, but if we are going to just simply _guess_, at least we should do it _wisely_. In this case, a short, hard-coded filepath to a test file that is _known_ to exist, would be the wisest way to guess. Of course, even if the OP adopted a wise methodology, the conjecture is a flop nonetheless, but at least, if we choose a wise methodology, we won't be temporarily blinded by our own superfluity in the process of conducting an experiment, and many times, the simplicity of a properly designed test suite will block the blinding rays of light that prevented us from seeing the solution in the first place. But in the end, sometimes you just have to forsake your ego, and go RTFM. > Can I use functions while defining paths? Your question is as absurd as: "Can i wear tennis shoes while boating?". We cannot provide good help if you do not ask good questions. From rantingrickjohnson at gmail.com Mon Sep 4 13:11:28 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 4 Sep 2017 10:11:28 -0700 (PDT) Subject: meaning of [ ] In-Reply-To: References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> Message-ID: <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> On Monday, September 4, 2017 at 9:27:23 AM UTC-5, Rustom Mody wrote: > On Monday, September 4, 2017 at 6:36:11 PM UTC+5:30, Ben Bacarisse wrote: > > Rustom Mody writes: > > > > > On Sunday, September 3, 2017 at 5:10:13 PM UTC+5:30, Rick Johnson wrote: > > >> Andrej Viktorovich wrote: > > >> > I suppose p becomes array of strings but what [] means in this statement? > > >> > > >> Generally, it's an inline form of writing a loop that returns a > > >> list. There are other types as well. > > > > > > Tsk tsk the confusioning continues > > > > > > Rewrite > > > [p for p in sys.path] > > > as > > > [p | p ? sys.path] > > > > > > Is that clearer? > > > > > > And then as > > > > > > {p | p ? sys.path} > > > And refresh the idea of set-builder notation > > > http://www.mathwords.com/s/set_builder_notation.htm > > > > But [p for p in sys.path] is a list and "set-builder" notation is used > > for sets. Order is crucial for sys.path. You say exactly that below so > > I don't see how referring to sets helps anyone understand lists. > > Clearly if the question was of *sets* vs *lists* the > distinction is at least as crucial, maybe even more so than > the similarity. What made you assume the OP question had anything to do with sets versus lists? I didn't get that impression. Not to say that i could not be wrong, but i see no reason to believe i am. > The OP-question here however is one about comprehensions > and it appears without the questioner realizing that ? as > Peter's answer showed My understanding of the impetus of the OP's question is a simple matter of attempting to intuit the structure of a list comprehension in the realms of Python code. Not a question as to the supposed "impurity" of python list comprehension form compared with set notation form. But again, i could be wrong. > See the very first line of this: > https://en.wikipedia.org/wiki/List_comprehension > ?List comprehension follows the form of the mathematical > set-builder notation (set comprehension)? I'm not sure if we should consider Wikipedia an "official" definition of the Python language, but if it were up to me, i would have chosen my words more carefully, as in: "List comprehension follows _loosely_ the form of the mathematical set-builder notation (set comprehension)?. My understanding that list comprehensions were borrowed from other languages. > ie its both historically and structurally linked IOW > emphasising the incidental sequential nature of the > computation at the cost of the fundamental structure- > preserving nature of the concept > > > > > > > As Peter pointed out this is a no-op > > > ie > > > [p for p in sys.path] > > > > > > could be written as > > > list(sys.path) > > > > Both make a copy -- that's not a no-op. It may be a very-little-op but > > not nothing. > > > Its important? > - whether the machine stack grows up or down > - whether the bytes are ordered little-endian or big-endian > - whether IO is polled or interrupt driven > - whether IO ports are memory-mapped or in separate IO space > And much else > > Yet for most people doing most things today in most languages, > these questions are irrelevated Of course. Just as pointers and memory management are irrelevant... > The question of copying is likewise, from a certain point > of view, irrelevant. > > Of course the further context of the OP may have a mutation > on the list And if he does end up changing sys.path, and > not intending it, that would be a source of nasty bugs for > sure But why assume all that when he does not (yet) know > what it is he is writing More importantly thinks its a > *command* when its actually an *expression* etc? (IMHO an > unfortunate consequence of the confusing overloading of the > 'for' keyword) I agree that if one is to present an "example comprehension", then using sys.path as the target is probably not a good idea. Yes, [p for p in sys.path] is superfluous, but so too is [i for i in range(5)]. But in all my life, i've never heard anyone raise even a slight quibble over the superfluous nature of such academic examples. (if that's what this was?) > > > > > [Not sure why he didnt say just sys.path] > > > > Because he wanted code equivalent to [p for p in sys.path]. > > > > > Anyway this is a good example to distinguish > > > > > > [p for p in sys.path] > > > from > > > {p for p in sys.path} > > > > > > Both work in python > > > But the second is probably not correct because path-searching is order > > > dependent > > > > Right. So i'm puzzled why you suggest that [p for p in sys.path] should > > be understood by reading about set-builder notation. > > Since "-builder" and "-comprehension" (in this context) are synonymous?? > [ https://en.wikipedia.org/wiki/Set-builder_notation ] > > And I am ready to make a small wager > - that the OP knows of these > - with math-hat on > - And is simply confused by the clunky ASCII syntax "clunky ASCII syntax"? WTH??? Oh, i get it! Are you on some sort of "set notation purity" jihad? Heck, and here i am all this time, assuming that functional programming was your only religion... ;-) From rustompmody at gmail.com Mon Sep 4 13:37:37 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Sep 2017 10:37:37 -0700 (PDT) Subject: meaning of [ ] In-Reply-To: <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> Message-ID: On Monday, September 4, 2017 at 10:42:47 PM UTC+5:30, Rick Johnson wrote: > On Monday, September 4, 2017 at 9:27:23 AM UTC-5, Rustom Mody wrote: > > On Monday, September 4, 2017 at 6:36:11 PM UTC+5:30, Ben Bacarisse wrote: > > > Rustom Mody writes: > > > > > > > On Sunday, September 3, 2017 at 5:10:13 PM UTC+5:30, Rick Johnson wrote: > > > >> Andrej Viktorovich wrote: > > > >> > I suppose p becomes array of strings but what [] means in this statement? > > > >> > > > >> Generally, it's an inline form of writing a loop that returns a > > > >> list. There are other types as well. > > > > > > > > Tsk tsk the confusioning continues > > > > > > > > Rewrite > > > > [p for p in sys.path] > > > > as > > > > [p | p ? sys.path] > > > > > > > > Is that clearer? > > > > > > > > And then as > > > > > > > > {p | p ? sys.path} > > > > And refresh the idea of set-builder notation > > > > http://www.mathwords.com/s/set_builder_notation.htm > > > > > > But [p for p in sys.path] is a list and "set-builder" notation is used > > > for sets. Order is crucial for sys.path. You say exactly that below so > > > I don't see how referring to sets helps anyone understand lists. > > > > Clearly if the question was of *sets* vs *lists* the > > distinction is at least as crucial, maybe even more so than > > the similarity. > > What made you assume the OP question had anything to do with > sets versus lists? I didn't get that impression. Not to say > that i could not be wrong, but i see no reason to believe i > am. I assume you are addressing this to Ben Bacarisse. If to me then I am saying mostly what you are (in above para!) > > > The OP-question here however is one about comprehensions > > and it appears without the questioner realizing that ? as > > Peter's answer showed > > My understanding of the impetus of the OP's question is a > simple matter of attempting to intuit the structure of a > list comprehension in the realms of Python code. Not a > question as to the supposed "impurity" of python list > comprehension form compared with set notation form. But > again, i could be wrong. My understanding is that the OP saw a 'for' inside a '[]' and wondered "WTF is this?" > > > See the very first line of this: > > https://en.wikipedia.org/wiki/List_comprehension > > ?List comprehension follows the form of the mathematical > > set-builder notation (set comprehension)? > > I'm not sure if we should consider Wikipedia an "official" > definition of the Python language, but if it were up to me, > i would have chosen my words more carefully, as in: "List > comprehension follows _loosely_ the form of the mathematical > set-builder notation (set comprehension)?. My understanding > that list comprehensions were borrowed from other languages. Wikipedia is probably not the best definer for math either In any case here its a question of how and what is the link between a math concept/notation and its form/semantics in python > > > ie its both historically and structurally linked IOW > > emphasising the incidental sequential nature of the > > computation at the cost of the fundamental structure- > > preserving nature of the concept > > > > > > > > > > As Peter pointed out this is a no-op > > > > ie > > > > [p for p in sys.path] > > > > > > > > could be written as > > > > list(sys.path) > > > > > > Both make a copy -- that's not a no-op. It may be a very-little-op but > > > not nothing. > > > > > > Its important? > > - whether the machine stack grows up or down > > - whether the bytes are ordered little-endian or big-endian > > - whether IO is polled or interrupt driven > > - whether IO ports are memory-mapped or in separate IO space > > And much else > > > > Yet for most people doing most things today in most languages, > > these questions are irrelevated > > Of course. Just as pointers and memory management are > irrelevant... careful! In an ideal world they should be irrelevant Some knotty problems in python cannot be prized apart without talking of these > > > The question of copying is likewise, from a certain point > > of view, irrelevant. > > > > Of course the further context of the OP may have a mutation > > on the list And if he does end up changing sys.path, and > > not intending it, that would be a source of nasty bugs for > > sure But why assume all that when he does not (yet) know > > what it is he is writing More importantly thinks its a > > *command* when its actually an *expression* etc? (IMHO an > > unfortunate consequence of the confusing overloading of the > > 'for' keyword) > > I agree that if one is to present an "example > comprehension", then using sys.path as the target is > probably not a good idea. Yes, [p for p in sys.path] is > superfluous, but so too is [i for i in range(5)]. But in all > my life, i've never heard anyone raise even a slight quibble > over the superfluous nature of such academic examples. (if > that's what this was?) Firstly [i for i in range(5)] is not a no-op in python-3 where range returns a range-object. list(range(5)) may be preferred for succinctness However [i for i in range(5)] may be said to be more general > > > > > > > > [Not sure why he didnt say just sys.path] > > > > > > Because he wanted code equivalent to [p for p in sys.path]. > > > > > > > Anyway this is a good example to distinguish > > > > > > > > [p for p in sys.path] > > > > from > > > > {p for p in sys.path} > > > > > > > > Both work in python > > > > But the second is probably not correct because path-searching is order > > > > dependent > > > > > > Right. So i'm puzzled why you suggest that [p for p in sys.path] should > > > be understood by reading about set-builder notation. > > > > Since "-builder" and "-comprehension" (in this context) are synonymous?? > > [ https://en.wikipedia.org/wiki/Set-builder_notation ] > > > > And I am ready to make a small wager > > - that the OP knows of these > > - with math-hat on > > - And is simply confused by the clunky ASCII syntax > > "clunky ASCII syntax"? > > WTH??? > > Oh, i get it! > > Are you on some sort of "set notation purity" jihad? No purity (Dunno about jihad) Just that when a notation like python's comprehensions are a close replica of a much more widely known older notion/notation from somewhere (in THIS case math) drawing attention to that history can help someone make the link Emacs is a good example of how to do all this wrong. Emacs calls: windows as frames panes as windows Alt as Meta And much else that is gratuitously non-standard May be there for some reason, historical or otherwise But is nonetheless rather off-putting to any noob Likewise here: People prefer to give the implementation of comprehensions rather than giving the connection to its parent notion+notation which in all probability the OP knows and is simply unable to connect because of clunkyness of ASCII-fied syntax From python at mrabarnett.plus.com Mon Sep 4 14:09:57 2017 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 4 Sep 2017 19:09:57 +0100 Subject: =?UTF-8?Q?Re:_Capital_=c3=9f_[was_Re:_Case-insensitive_string_equal?= =?UTF-8?Q?ity]?= In-Reply-To: <59acba5f$0$1615$c3e8da3$5496439d@news.astraweb.com> References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> <59a9fbe3$0$1605$c3e8da3$5496439d@news.astraweb.com> <59acba5f$0$1615$c3e8da3$5496439d@news.astraweb.com> Message-ID: <07bbfbb5-33f3-5d4b-6e34-a00de02e82a6@mrabarnett.plus.com> On 2017-09-04 03:28, Steve D'Aprano wrote: > On Sat, 2 Sep 2017 01:48 pm, Stefan Ram wrote: > >> Steve D'Aprano writes: >>>[1] I believe that the German government has now officially recognised the >>>uppercase form of ?. >> >> [skip to the last paragraph for some "?" content, >> unless you want to read details about German spelling rules.] >> >> The German language is as free as the English one. It does >> not come from a government. > > Nevertheless, even in English there are de facto rules about what you can and > cannot use as text for official purposes. In most countries, you cannot change > your name to an unpronounceable "love symbol" as the late Artist Formally Known > As Prince did. You can't fill in your tax using Alienese > > http://futurama.wikia.com/wiki/Alienese > > or even Vietnamese, Greek or Arabic. > > In Australia, the Victorian state government Department of Births Deaths and > Marriages doesn't even accept such unexceptional and minor variants as Z?e for > Zoe. Of course you are free to call yourself Z?e when you sign your emails, but > your birth certificate, passport and drivers licence will show it as Zoe. > Of course they reject "Z?e": the correct spelling is "Zo?". :-) [snip] From steve+python at pearwood.info Mon Sep 4 14:15:26 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 05 Sep 2017 04:15:26 +1000 Subject: A question on modification of a list via a function invocation References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59ad983f$0$1589$c3e8da3$5496439d@news.astraweb.com> On Tue, 5 Sep 2017 02:51 am, Stefan Ram wrote: > Steve D'Aprano writes: >>Sorry Stefan, that is the same trap that many others fall into. You are >>assuming that there are exactly two evaluation conventions: >>- pass by reference >>- pass by value >>and so if a language doesn't do one, it must do the other. > > I am assuming that there are two argument passing mechanismss > in the languages mentioned by me (C, C++, VBA, C#, Java, > JavaScript, and Python): > > - pass by aliassing (reference) > - pass "as if by assignment" That assumption is wrong. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Mon Sep 4 14:16:02 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Sep 2017 11:16:02 -0700 (PDT) Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> Message-ID: <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> Since these discussions are uselessly abstract and meta Here is some code I (tried) to write in class the other day The basic problem is of generating combinations Using the pascal-identity nCr + nC(r-1) = (n+1)Cr This can be written (Haskell) c :: Int -> Int -> Int c n 0 = 1 c 0 (r+1) = 0 c (n+1) (r+1) = c n r + c n (r+1) But I dont want NUMBER of combinations I want to generate combinations from a given set So change the spec to c :: [a] -> Int -> [[a]] ie n stops being a number but is now a set (here list) length n c n 0 = [[]] c [] (r+1) = [] c (x:xs) (r+1) = [x:l | l <- c xs r] ++ c xs (r+1) Runs ? c [1,2,3,4] 2 [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]] :: [[Int]] All binomials ? [c [1,2,3,4] r | r <- [0..4]] [ [[]], [[1], [2], [3], [4]], [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]], [[1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]], [[1, 2, 3, 4]] ] :: [[[Int]]] Now thats neat as far as it goes but combinations are fundamentally sets not lists So I thought python would do a better job I tried translating it to python and sets but it turned out more annoying than helpful Can someone improve it?? The straightforward translation of the above Which is ok so far def c(n,r): if r == 0: return [[]] elif len(n) == 0: return [] else: return [[n[0]] + l for l in c(n[1:],r-1)] + c(n[1:],r) Now to go from returning list of lists to set of sets: st = frozenset nullset = st([]) def singleton(x): return st([x]) def splitset(s): i = iter(s) e = next(i) new = st(i) return e,new def cs(n,r): """ Set version of c""" if r == 0 : return singleton(nullset) elif len(n) == 0 : return nullset else: x,xs = splitset(n) return st([(singleton(x) | l) for l in cs(xs,r-1)]) | cs(xs,r) def ss0n(fs): """ Shows a simple-set (ie set-0, contains no subsets) nicely""" r = "{" for x in fs: r += repr(x) + ", " return r + "}" def ss1n(fs0): """ Shows a set-of-sets (ie set-1, contents are sets) nicely""" r = "{" for x in fs0: r += ss0n(x) + ", " return r + "}" >>> cs({1,2,3,4}, 2) frozenset([frozenset([2, 4]), frozenset([3, 4]), frozenset([2, 3]), frozenset([1, 3]), frozenset([1, 2]), frozenset([1, 4])]) >>> ss1n(cs({1,2,3,4}, 2)) '{{2, 4, }, {3, 4, }, {2, 3, }, {1, 3, }, {1, 2, }, {1, 4, }, }' >>> ss1n(cs({1,2,3,4}, 2)) '{{2, 4, }, {3, 4, }, {2, 3, }, {1, 3, }, {1, 2, }, {1, 4, }, }' So how could this be done better? Here for reference is an abstract math ideal I would like to approximate c : {t} ? Int ? {{t}} ## t is an arbitrary unspecified type c n 0 = {{}} c {} (r+1) = {} c ({x} ? xs) (r+1) = {{x} ? l | l ? c xs r} ? c xs (r+1) exactly parallel to the pascal identity c n 0 = 1 c 0 (r+1) = 0 c (n+1) (r+1) = c n r + c n (r+1) From steve+python at pearwood.info Mon Sep 4 14:21:11 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 05 Sep 2017 04:21:11 +1000 Subject: meaning of [ ] References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> Message-ID: <59ad9999$0$1620$c3e8da3$5496439d@news.astraweb.com> On Tue, 5 Sep 2017 03:37 am, Rustom Mody wrote: > My understanding is that the OP saw a 'for' inside a '[]' and wondered > "WTF is this?" Rustom, did you not notice that the OP seemed to understood the 'for' perfectly well, but asked what the meaning of the [ ] delimiters is? He explicitly says: "what [] means in this statement?" and it's the subject of the thread! Apart from your own bias against explicit for loops, what made you think that the OP understood the [] but was confused by the "for" when he explicitly said the opposite? [...] > People prefer to give the implementation of comprehensions > rather than giving the connection to its parent notion+notation which in > all probability the OP knows and is simply unable to connect because of > clunkyness of ASCII-fied syntax You have no evidence at all that the OP knows set builder syntax. Most people don't. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From antoon.pardon at rece.vub.ac.be Mon Sep 4 15:42:30 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 4 Sep 2017 21:42:30 +0200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59ad638a$0$1604$c3e8da3$5496439d@news.astraweb.com> References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <735ad478-53e9-42ce-ae63-69a364ca6c8a@googlegroups.com> <59ad54a2$0$1584$c3e8da3$5496439d@news.astraweb.com> <59ad638a$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3ca196db-22e4-18cc-4e46-2564fe84ff1d@rece.vub.ac.be> On 04-09-17 16:30, Steve D'Aprano wrote: > On Tue, 5 Sep 2017 12:09 am, Antoon Pardon wrote: > >> Op 04-09-17 om 15:26 schreef Steve D'Aprano: >>> On Mon, 4 Sep 2017 08:52 pm, Antoon Pardon wrote: >>> >>>> Op 04-09-17 om 12:22 schreef Stefan Ram: >>>>> Rustom Mody writes: >>>>>>> Stefan Ram wrote: >>>>>>>> JavaScript and Python do not have references as values >>>>>>> Yes, they do. The difference is that they don't have any >>>>> ... >>>>>> Its because reference (or pointer or ?) is central to python's semantics >>>>> If they are so central, then it should be easy to show >>>>> quotes from The Python Language Reference to support that >>>>> claim. >>>> The section about assignment talks about reference counts. >>> Does that mean that IronPython and Jython aren't implementations of Python? >>> They have no reference counts. >> >> I am not a lawyer > > But you are a Python programmer. > > You should be aware that reference counts are a property of the CPython > implementation, not a language feature. Jython and IronPython, at the very > least, are valid, conforming implementations of Python the language which have > no reference counts. Therefore reference counts cannot be central to Python's > semantics, since there are Python interpreters that don't use them. It is not my responsibility that reference counts are mentioned in the language referece. In how far mentioning reference counts in the language reference makes IronPython or Jython not python is IMO food for lawyers. I also didn't claim reference counts are essential to python's semantics. -- Antoon Pardon From rosuav at gmail.com Mon Sep 4 15:50:46 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Sep 2017 05:50:46 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: <1ksqqc13n32huoro82u5togkb20c3m641n@4ax.com> References: <5994e62c$0$1603$c3e8da3$5496439d@news.astraweb.com> <7b67047d-7d59-4856-9fd4-5824f0608aff@googlegroups.com> <59acb4ce$0$1622$c3e8da3$5496439d@news.astraweb.com> <29c67315-6ede-40c0-854b-740ee73eeaf6@googlegroups.com> <59ad612a$0$1609$c3e8da3$5496439d@news.astraweb.com> <1ksqqc13n32huoro82u5togkb20c3m641n@4ax.com> Message-ID: On Tue, Sep 5, 2017 at 1:36 AM, Dennis Lee Bieber wrote: > On Tue, 05 Sep 2017 00:20:25 +1000, Steve D'Aprano > declaimed the following: > >>(Of course this is silly. As all physicists know, there are no people, animals >>or cars in the world, there are only quarks and electrons.) > > Quarks and Leptons and Bosons (Oh, my!) > > > {I tend to forget the bosons} Once we get quantum computing as a regular and normal thing, we'll have to redefine duck typing. If it quarks like a duck... ChrisA From ben.usenet at bsb.me.uk Mon Sep 4 16:14:01 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Mon, 04 Sep 2017 21:14:01 +0100 Subject: Please improve these comprehensions (was meaning of [ ]) References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> Message-ID: <873782p6gm.fsf@bsb.me.uk> Rustom Mody writes: > Here is some code I (tried) to write in class the other day > > The basic problem is of generating combinations > Now thats neat as far as it goes but combinations are fundamentally sets > not lists > > So I thought python would do a better job > I tried translating it to python and sets but it turned out more annoying than > helpful > Can someone improve it?? > > The straightforward translation of the above > Which is ok so far > > > def c(n,r): > if r == 0: > return [[]] > elif len(n) == 0: > return [] > else: > return [[n[0]] + l for l in c(n[1:],r-1)] + c(n[1:],r) > > > Now to go from returning list of lists to set of sets: def cs(n, r): if r == 0: return [set()] elif len(n) == 0: return [] else: return [set([n[0]]) | l for l in cs(n[1:], r-1)] + cs(n[1:], r) ? It's not so neat if you also want n to be a set rather than a list because the set equivalents of n[0] and n[1:] are a but more complex but it's not that bad: def css(n,r): if r == 0: return [set()] elif len(n) == 0: return [] else: rest = n.copy() e = rest.pop() return [set([e]) | l for l in css(rest, r-1)] + css(rest, r) -- Ben. From python.list at tim.thechases.com Mon Sep 4 16:27:50 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 4 Sep 2017 15:27:50 -0500 Subject: Case-insensitive string equality In-Reply-To: <59aa15c0$0$1587$c3e8da3$5496439d@news.astraweb.com> References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59aa15c0$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20170904152750.4430797f@bigbox.christie.dr> On 2017-09-02 12:21, Steve D'Aprano wrote: > On Fri, 1 Sep 2017 01:29 am, Tim Chase wrote: > > I'd want to have an optional parameter to take locale into > > consideration. E.g. > > Does regular case-sensitive equality take the locale into > consideration? No. Python says that .casefold() https://docs.python.org/3/library/stdtypes.html#str.casefold implements the Unicode case-folding specification ftp://ftp.unicode.org/Public/UNIDATA/CaseFolding.txt which calls out the additional processing for Turkic languages: # T: special case for uppercase I and dotted uppercase I # - For non-Turkic languages, this mapping is normally not used. # - For Turkic languages (tr, az), this mapping can be used # instead of the normal mapping for these characters. # Note that the Turkic mappings do not maintain canonical # equivalence without additional processing. # See the discussions of case mapping in the Unicode Standard # for more information. So it looks like what Python lacks is that "additional processing", after which .casefold() should solve the problems. According to my reading, if locale doesn't play part in the equation s1.casefold() == s2.casefold() should suffice. Any case-insensitive code using .upper() or .lower() instead of .casefold() becomes a code-smell. > If regular case-sensitive string comparisons don't support the > locale, why should case-insensitive comparisons be required to? Adding new code to Python that just does what is already available is indeed bad justification. But adding *new* functionality that handles the locale-aware-case-insensitive-comparison could be justified. > As far as I'm concerned, the only "must have" is that ASCII letters > do the right thing. Everything beyond that is a "quality of > implementation" issue. But for this use-case, we already have .casefold() which does the job and even extends beyond plain 7-bit ASCII to most of the typical i18n/Unicode use-cases. -tkc From irmen at NOSPAM.xs4all.nl Mon Sep 4 17:29:48 2017 From: irmen at NOSPAM.xs4all.nl (Irmen de Jong) Date: Mon, 4 Sep 2017 23:29:48 +0200 Subject: wrote a commodore-64 emulator using just Python In-Reply-To: <59905943$0$704$e4fe514c@news.xs4all.nl> References: <59905943$0$704$e4fe514c@news.xs4all.nl> Message-ID: <59adc5cc$0$707$e4fe514c@news.xs4all.nl> On 08/13/2017 03:50 PM, Irmen de Jong wrote: > Hi, > > As another experiment with using just tkinter for graphics, this time I created a > Commodore-64 emulator. You can find it here https://github.com/irmen/pyc64 [...] > There's also https://github.com/mnaberez/py65 so... possibilities? Well, I went ahead and integrated that with my emulator. With just a slight modification (that is now merged into the py65 library) I could hook it up to the bytearray that my emulator uses to simulate the C64's RAM. And letting the 'SYS' basic command kick of the 6502 simulator, rather than doing nothing, it suddenly was able to actually run real (although simple) Commodore-64 programs. Speed seems to be around 0.5x real-time on my machine. The py65 library also already provides a simple machine code monitor (assembler/disassembler) that you can use to inspect or write the machine code in the C64's memory. With some effort it should be possible to run it in the emulated screen, but for now, interaction with it is done on the console prompt. It was a great deal of fun integrating this into my project and I found it quite spectacular to see some existing Commodore-64 programs actually running unaltered. Even when they're doing nothing more than changing the screen colors and unpacking an image. At half speed. But still :-) Irmen From breamoreboy at gmail.com Mon Sep 4 17:44:56 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Mon, 4 Sep 2017 14:44:56 -0700 (PDT) Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: <873782p6gm.fsf@bsb.me.uk> References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> Message-ID: <5c4f0fcb-5816-4297-90ef-f338394dd85e@googlegroups.com> On Monday, September 4, 2017 at 9:14:24 PM UTC+1, Ben Bacarisse wrote: > Rustom Mody writes: > > > Here is some code I (tried) to write in class the other day > > > > The basic problem is of generating combinations > > > Now thats neat as far as it goes but combinations are fundamentally sets > > not lists > > > > So I thought python would do a better job > > I tried translating it to python and sets but it turned out more annoying than > > helpful > > Can someone improve it?? > > [lots of code snipped] > -- > Ben. Here's my take https://docs.python.org/3/library/itertools.html#itertools.combinations Kindest regards. Mark Lawrence. From rantingrickjohnson at gmail.com Mon Sep 4 17:50:41 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 4 Sep 2017 14:50:41 -0700 (PDT) Subject: Run Windows commands from Python console In-Reply-To: References: <83ebc433-d457-408b-b43a-4b00a3206728@googlegroups.com> Message-ID: <290ec6d2-81d9-4bf4-b641-fc8568578555@googlegroups.com> Terry Reedy wrote: [...] > In IDLE, trackbacks *do* include source lines. > > >>> def f(): > return 1/0 > > >>> f() > Traceback (most recent call last): > File "", line 1, in > f() > File "", line 2, in f > return 1/0 > ZeroDivisionError: division by zero One of the few things that IDLE did better than Python, which is much more informative than: > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in f > ZeroDivisionError: division by zero I think newbies would find IDLE's explicit messaging to be more intuitive compared to standard Python. Counting lines is never any fun, and even if you're only dealing with a few, it's both annoying and inefficient. When i'm away from an editor (like IDLE, for instance), one of the features i miss most is the ability to right click the line of the exception message (you know, the one that includes the offending line number and offending script filepath), and choose "open script for editing" from a contextual menu, which will open the script and automatically scroll down to the offending line for me. Ahhh, efficient bliss. OTOH, without such a feature, the agonising work-flow goes something like this: (STEP 0): Scan the exception dump for the offending filepath... Okay, got it! Now, (STEP 1) Locate the offending script in the file system... Superficially, such a task seems easy, but if the script is located deep in the abyssal plane of your file system, you'll be typing or clicking for what seems like an eternity to get there... (seconds tick away as rick rapid fires his way through a mountain of nested data structures with the exuberance of a world class X-Box champion gamer (and thankfully for rick, harddrives, like the Universe, are finite spaces!))... Okay, got it! Now, (STEP 2) Open the script for editing... This is not too difficult, but once you've got the script loaded into an editor, you quickly realize that -- RATS! -- in the process of locating the offending _script_ you've forgotten the number of the offending _line_. So alas, you go back to the console window and eyeball parse the exception dump (again!) until you find the offending line number... (a few seconds passes whilst rick speed reads)... Okay, got it! now, (STEP 3) Scroll to offending line number... Now you're back in your editor, but once you've successfully scrolled to the offending line, you quickly realize that -- RATS! -- in the process of eyeball parsing the exception dump to determine the number of the offending line *AND* scrolling to the offending line, you have forgotten the whole reason why you were going here in the first place! (at this point, rick's low tolerance for impracticality causes him to become agitated, but knowing that emotion will not solve his problem, rick begrudgingly goes back to the console window and eyeball parses the exception dump (once more!) for a clue to what the *HELL* has caused him to endure all this trouble)... (a few seconds passes whilst rick speed reads)... Okay, got it! Now, (STEP 4) Return to the running editor; containing the offending script; scrolled to the offending line -- with a _bitter_ resolve to get this bug fixed!!! Oh my! There must be a better way. From irmen at NOSPAM.xs4all.nl Mon Sep 4 18:02:49 2017 From: irmen at NOSPAM.xs4all.nl (Irmen de Jong) Date: Tue, 5 Sep 2017 00:02:49 +0200 Subject: a Boulder Dash clone with retro graphics and sound Message-ID: <59adcd89$0$806$e4fe514c@news.xs4all.nl> Hi, Yet another continuation of my graphics experiments with tkinter. In the previous project I've been using tkinter bitmaps to simulate a commodore-64 screen where I exploited the possibility to change the foreground and background color of the bitmap on the fly. This conveniently matches the way the commodore 64 draws its (character-mode) graphics. This time I switched to a screen filled with hundreds of tkinter's PhotoImage objects, that can display full color images. However continuing in the spirit of the 8 bit era, instead of creating something with high-res full color graphics, I created a Boulder Dash clone using retro graphics. It's a fully functional game. You can get it here: https://github.com/irmen/bouldercaves (if you just want to play it and aren't interested in the code, get the .pyz Python zip app from the releases section) The game contains the 20 levels of the original 1980's Boulder Dash, and also plays music and soundfx. By default it uses a slightly more colorful sprite set than the original, but you can tell it to switch to the limited Commodore-64 color palette. You need Python 3.5+ and pillow and sounddevice/pyaudio to play it. If you disable sound, only pillow is enough. It runs very well at 30hz refresh rate on my Linux box, but seem to have some performance issues on Windows and Mac OS. Your mileage may vary, and you can tweak some parameters on the command line to eventually make it run smoothly. It was a joy to learn about the inner workings of one of my favorite games when I was a kid, and how to translate that into modern software. I haven't been able to finish the game so far! I guess I have to learn again how to actually play this after 30 years. There's just two things missing I think: - high score table - being able to play multiple sounds simultaneously, as the amoeba and magic wall sounds are lacking at the moment. (And the sprite set I used contains a lot more objects and creatures than the original game so it begs for adding extended game logic and levels with new mechanics... who knows...) This project was heavily inspired by: http://codeincomplete.com/posts/javascript-boulderdash/ and http://www.boulder-dash.nl/ Have fun :-) Irmen From rantingrickjohnson at gmail.com Mon Sep 4 18:49:59 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 4 Sep 2017 15:49:59 -0700 (PDT) Subject: Case-insensitive string equality In-Reply-To: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> Message-ID: <55b6b5f4-ecfc-4d1a-a0eb-f333282c6169@googlegroups.com> Steven D'Aprano wrote: [...] > (1) Add a new string method, which performs a case- > insensitive equality test. Here is a potential > implementation, written in pure Python: > > def equal(self, other): > if self is other: > return True > if not isinstance(other, str): > raise TypeError > if len(self) != len(other): > return False > casefold = str.casefold > for a, b in zip(self, other): > if casefold(a) != casefold(b): > return False > return True > > Alternatively: how about a === triple-equals operator to do > the same thing? A good idea. But wouldn't that specific usage be inconsistent (even backwards) with the semantics of "===" as defined in most languages that use "==="? For me -- and this comment will be going beyond the scope of strings, and possibly, beyond the scope of this thread -- i feel that python is missing a pair of equality testing devices (sugared or not; but preferably sugared), that define a universal means by which all types can be tested with either "superficial equality" (aka: ==) or "deep equality" (aka: ===). However, such a design (whist quite intuitive) would break equality testing as it exists today in Python. For instance, it would mean that: (1) Superficial Equality >>> "abc" == "abc" True >>> "abc" == "ABC" True (2) Deep Equality >>> "abc" === "abc" True >>> "abc" === "ABC" False And i don't think even GvR's time machine will be much help here. :-( From steve+python at pearwood.info Mon Sep 4 22:49:23 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 05 Sep 2017 12:49:23 +1000 Subject: A question on modification of a list via a function invocation References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> Dennis, That's an excellent summary of a number of programming languages' calling conventions, thank you. Unfortunately you have the X-No-Archive header set, so it will be lost to prosperity. To prevent that, I'm taking the liberty of quoting you in full below (and top posting). A couple of comments: > I don't have Java textbooks locally (in storage 15 miles away) but from > what I recall, it too has the complication of splitting between "simple > types" and "reference types" ("boxed" I believe is the term used in books). You remember correctly. Java supports machine primitive values like ints and floats, and always treats them as by-value. You can also "box" them in an object, in which case Java has precisely the same semantics as Python, Ruby and many others, pass by object sharing. But the Java community insists on calling it pass by value. Occasionally, when they remember or when pressed, they will admit that what is being passed by value is not the object (the value), but an invisible, unknowable, implementation-dependent reference to the actual value. > The default passing mechanism would be similar to the description of C# > ("boxed" types being implicit copies of references allowing mutation > in-place, but assignment to the parameter itself has no effect on the > caller). Indeed. > I suspect it too has some means to explicitly produce a > by-reference parameter. I've never come across a by-reference mechanism is Java. Scott Stanchfield gives the litmus test for pass-by-reference semantics: can you write a "swap" procedure in the language? He gives examples of a swap() procedure in pseudocode, Pascal and C++, and specifically says "you cannot do this in Java". http://javadude.com/articles/passbyvalue.htm But of course you can simulate (poorly) by-reference output parameters in Java, or Python, using mutation, just as you can simulate (poorly) by-reference output parameters in C with pointers and mutation of the memory location pointed to. Scott describes himself as "a compiler guy at heart", and that leads him to confuse abstraction levels. He is absolutely correct that the Java compiler always passes by value. But that's not the Java language, that is the implementation of the Java language. Here is Scott's category error: [quote] The mistake they make is in the definition of Figure 7: (Java) Defining a Dog pointer Dog d; itself. When you write that definition, you are defining a pointer to a Dog object, not a Dog object itself. [end quote] Here Scott mixes up what the compiler does (creates a pointer to a Dog object, and what the programmer's Java code does (creates a Dog). I expect this is because, as a "compiler guy", Scott probably doesn't really believe that objects are values. Values are small machine primitives, like a 64-bit float, not big, complicated, compound structures of methods and attributes like objects. On category errors: https://en.wikipedia.org/wiki/Category_mistake On Tue, 5 Sep 2017 05:12 am, Dennis Lee Bieber wrote: > On 4 Sep 2017 16:51:45 GMT, ram at zedat.fu-berlin.de (Stefan Ram) declaimed > the following: > >> >> I am assuming that there are two argument passing mechanismss >> in the languages mentioned by me (C, C++, VBA, C#, Java, >> JavaScript, and Python): > > Original (and maybe still) C only has one native passing convention: > pass by value. Arguments go in, but they do not come out. > > C relied upon the /programmer/ to explicitly obtain the address of a > memory location (by using & upon the argument) with the obtained address > now being passed by value. C also relied upon the programmer to explicitly > dereference the parameter in order to access the desired value. > > int afunc(int x, int * y) > { > int z; > z = x + y; /* whoops, forgot to dereference y */ > return (- *y); /* this time remembered */ > } > > ... > int a; > int b; > > z = afunc(a, b); /* whoops, forgot to obtain address of b */ > z2 = afunc(a, &b); /* correct usage */ > > C++ has added a reference declaration in the definition of functions, > thereby making the obtaining/dereferencing automatic. > > int bfunc(int x, int & y) > { > int z; > z = x + y; /* automatic derefence */ > return -y; > } > > z = bfunc(a, b); /* automatic address */ > > > Classic FORTRAN is always pass-by-reference(location) -- though DEC VMS > FORTRAN had compile-time "functions" which could override that: %ref, > %descr, %val (and I think there was a %loc which would return the address > of the argument -- it wasn't used for parameter passing itself). > > Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference > semantics, in that the definition of a function declares how the > argument(s) are passed. > > Pascal and Modula-2 default is by-value, unless the parameter is > declared with "var " > > VB-6 defaulted to by-reference and relied upon the use of "ByVal " in > the declaration to cause a by-value pass. VB.NET (part of the managed > common language runtime [CLR]) and later default to by-value and require > "ByRef " in the declaration to get reference semantics ("ByVal " is still > valid). > > Unless there have been changes I've not been exposed to, VBA was a > subset of VB-6 (I don't know if it is now a subset of VB.NET and CLR) > > Ada has declarations of "IN", "OUT", and "IN OUT"... But these really > define how the parameter may be used within the function, and do not > enforce any particular passing semantics (commonly, numeric types are > pass-by-value for IN declarations, but arrays, strings, etc. will be > pass-by-reference; the compiler generates code to prevent writing to IN > parameters. I believe later Ada standards might mandate that "IN OUT" is > treated as by-reference; Ada 80 may have permitted value-result semantics) > > C# (another CLR language) complicates matters by first having "simple > types" (essentially the basic numeric types) and "reference types" > (strings, arrays, everything else). The default passing mechanism is > call-by-value -- which for "reference types" is a copy of the address of > the object (so you can do in-place mutation of those objects, but you can > not replace the object itself with a new object). But then it supports > "ref" and "out" modifiers for the declaration ("out" allows for the use of > uninitialized names in the caller, with the function providing the first > initialized content). Passing a "reference type" using "ref" means passing > a reference to a reference, and the function can then replace the original > object. > > I don't have Java textbooks locally (in storage 15 miles away) but from > what I recall, it too has the complication of splitting between "simple > types" and "reference types" ("boxed" I believe is the term used in books). > The default passing mechanism would be similar to the description of C# > ("boxed" types being implicit copies of references allowing mutation > in-place, but assignment to the parameter itself has no effect on the > caller). I suspect it too has some means to explicitly produce a > by-reference parameter. > > Python... does not have this dichotomy of "simple" and "reference" > types -- everything is a "reference" type but may be immutable or mutable; > mutable can be modified in-place, immutables can not be modified. > Assignment to a parameter name replaces the object locally, with no effect > on the argument provided by the caller. There is no provision to expose a > reference (to a reference) nor to dereference any thing. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From namenobodywants at gmail.com Mon Sep 4 23:26:14 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Mon, 4 Sep 2017 20:26:14 -0700 (PDT) Subject: tictactoe script - commented - may have pedagogical value Message-ID: """ this program makes an optimal tictactoe move by answering the following questions in their given order until it is told where to put its mark: 1) can you win the game? if so then do it 2) could your opponent win the game if it was his turn? if so then put your own mark where a mark of his would win him the game 3) could you win the game if you had two turns in a row? if so then make a move that leaves you with the largest number of second moves that would win you the game if you could really make them 4) is the center square open? if so then put your mark there 5) are any of the corners open? if so then put your mark on one of them 6) put your mark on any open square """ #) tictactoe; python 3.6.1 count = lambda dictionary, value: list(dictionary.values()).count(value) subdictionary = lambda dictionary, keys: {key: dictionary[key] for key in keys} ex, oh, blank = 'X0 ' indices = list(range(3)) vectors = [(i,j) for i in indices for j in indices] startgrid = {vector: blank for vector in vectors} display = lambda grid: '\n-+-+-\n'.join('|'.join(grid[i,j] for j in indices) for i in indices) iscenter = lambda vector: vector == (1,1) iscorner = lambda vector: vector[0]%2 == vector[1]%2 == 0 horizontal = [[(i,j) for j in indices] for i in indices] vertical = [[(i,j) for i in indices] for j in indices] diagonal = [[(i,i) for i in indices], [(i,2-i) for i in indices]] linear = horizontal + vertical + diagonal getrows = lambda grid: [subdictionary(grid,coordlist) for coordlist in linear] movermark = lambda grid: ex if count(grid,ex) == count(grid,oh) else oh opponent = lambda mark: ex if mark == oh else oh if mark == ex else blank strike = lambda vector, rows, ownmark: int(any(row for row in rows if vector in row and count(row,blank)==1 and count(row,ownmark)==2)) parry = lambda vector, rows, ownmark: int(any(row for row in rows if vector in row and count(row,blank)==1 and count(row,opponent(ownmark))==2)) threaten = lambda vector, rows, ownmark: len([row for row in rows if vector in row and count(row,blank)==2 and count(row,ownmark)==1]) position = lambda vector, rows, ownmark: 2 * int(iscenter(vector)) + int(iscorner(vector)) evaluate = lambda vector, rows, ownmark: [f(vector,rows,ownmark) for f in (strike,parry,threaten,position)] def movevector(grid,ownmark): from random import choice rows = getrows(grid) value = lambda vector: evaluate(vector,rows,ownmark) candidates = [(i,j) for i in indices for j in indices if grid[i,j] == blank] maximum = value(max(candidates,key=value)) if candidates else None coords = [vector for vector in candidates if value(vector) == maximum] return choice(coords) if coords and blank in grid.values() else None def getwinner(grid): rows = getrows(grid) rows = [list(row.values()) for row in rows] return ex if [ex]*3 in rows else oh if [oh]*3 in rows else None def makemove(grid): grid = grid.copy() ownmark = movermark(grid) vector = movevector(grid,ownmark) if vector: grid[vector] = ownmark return grid def getinteger(lower,upper,prompt): integer = None while integer == None: try: integer = int(input(prompt)) assert lower <= integer <= upper except KeyboardInterrupt: raise except: pass return integer def play(mark): grid = startgrid.copy() if mark == ex: grid = makemove(grid) print('\n\n' + display(grid) + '\n\n') winner = None while not winner and blank in grid.values(): cellnumber = getinteger(1,9,'cell number: ') grid[divmod(cellnumber-1,3)] = movermark(grid) winner = getwinner(grid) if not winner: grid = makemove(grid) winner = getwinner(grid) print('\n\n' + display(grid) + '\n\n') message = winner + ' wins' if winner else 'tied game' print(message) From rustompmody at gmail.com Mon Sep 4 23:44:20 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 4 Sep 2017 20:44:20 -0700 (PDT) Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: <873782p6gm.fsf@bsb.me.uk> References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> Message-ID: On Tuesday, September 5, 2017 at 1:44:24 AM UTC+5:30, Ben Bacarisse wrote: > Rustom Mody writes: > > > Here is some code I (tried) to write in class the other day > > > > The basic problem is of generating combinations > > > Now thats neat as far as it goes but combinations are fundamentally sets > > not lists > > > > So I thought python would do a better job > > I tried translating it to python and sets but it turned out more annoying than > > helpful > > Can someone improve it?? > > > > The straightforward translation of the above > > Which is ok so far > > > > > > def c(n,r): > > if r == 0: > > return [[]] > > elif len(n) == 0: > > return [] > > else: > > return [[n[0]] + l for l in c(n[1:],r-1)] + c(n[1:],r) > > > > > > Now to go from returning list of lists to set of sets: > > def cs(n, r): > if r == 0: > return [set()] > elif len(n) == 0: > return [] > else: > return [set([n[0]]) | l for l in cs(n[1:], r-1)] + cs(n[1:], r) > > ? > > It's not so neat if you also want n to be a set rather than a list > because the set equivalents of n[0] and n[1:] are a but more complex but > it's not that bad: > > def css(n,r): > if r == 0: > return [set()] > elif len(n) == 0: > return [] > else: > rest = n.copy() > e = rest.pop() > return [set([e]) | l for l in css(rest, r-1)] + css(rest, r) Trying out your code Ben? >>> css({1,2,3,4}, 2) [set([1, 2]), set([1, 3]), set([1, 4]), set([2, 3]), set([2, 4]), set([3, 4])] >>> type(css({1,2,3,4}, 2)) Whereas with the cs I earlier gave: >>> cs(frozenset([1,2,3,4]), 2) frozenset([frozenset([2, 4]), frozenset([3, 4]), frozenset([2, 3]), frozenset([1, 3]), frozenset([1, 2]), frozenset([1, 4])]) >>> type(cs(frozenset([1,2,3,4]), 2)) So in case I did not make it clear enough earlier, there are three collection types in the spec. A small amount of meta-combinatorics on the combinatorics! Lets say {1,2} : ? Int ## powerset [1,2] : ? Int ## list type constructor There are many others eg ?1,2? : ? Int ## Bag type constructor Not to mention iterators Lets just stay with set and list for simplicity So the combinations enumerator has the general type (schema) [For ? being one of the above collection type constructors] c : ? t ? Int ? ? ? t However each of these ?'s could be different c : ?? t ? Int ? ?? ?? t This gives 8 possibilities (assuming 2 constructors) Your function had type css : ? t ? Int ? ? ? t whereas I wanted cs : ? t ? Int ? ? ? t And this has not yet touched on the difference between set and frozenset! Why do we need frozenset at all? Because the set type wont close in python! ## List of lists... ok >>> [[1,2],[3,4]] [[1, 2], [3, 4]] ## List of sets slightly clunky but still ok >>> [{1,2},{3,4}] [set([1, 2]), set([3, 4])] ## Set of sets??? Sorry!! >>> {{1,2},{3,4}} Traceback (most recent call last): File "", line 1, in TypeError: unhashable type: 'set' From tjreedy at udel.edu Tue Sep 5 02:34:48 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 5 Sep 2017 02:34:48 -0400 Subject: Run Windows commands from Python console In-Reply-To: <290ec6d2-81d9-4bf4-b641-fc8568578555@googlegroups.com> References: <83ebc433-d457-408b-b43a-4b00a3206728@googlegroups.com> <290ec6d2-81d9-4bf4-b641-fc8568578555@googlegroups.com> Message-ID: On 9/4/2017 5:50 PM, Rick Johnson wrote: > Terry Reedy wrote: > > [...] > >> In IDLE, trackbacks *do* include source lines. >> >> >>> def f(): >> return 1/0 >> >> >>> f() >> Traceback (most recent call last): >> File "", line 1, in >> f() >> File "", line 2, in f >> return 1/0 >> ZeroDivisionError: division by zero > > One of the few things that IDLE did better than Python, > which is much more informative than: > >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 2, in f >> ZeroDivisionError: division by zero > > I think newbies would find IDLE's explicit messaging to be > more intuitive compared to standard Python. Counting lines > is never any fun, and even if you're only dealing with a > few, it's both annoying and inefficient. > > When i'm away from an editor (like IDLE, for instance), one > of the features i miss most is the ability to right click > the line of the exception message (you know, the one that > includes the offending line number and offending script > filepath), and choose "open script for editing" from a > contextual menu, which will open the script and > automatically scroll down to the offending line for me. > Ahhh, efficient bliss. 'Goto file/line' also works on the grep/find-in-files Output Window. I must have used this about 30 times in 8 outputs tonight try to track down bugs in a proposed IDLE patch. There were no tracebacks, just thinkgs not working. I plan to make it a bit faster by moving the option to the top of the menu. I have thought about making it even faster by not having to use the context menu -- just click, or maybe double click, and the jump happens. What do you think? -- Terry Jan Reedy From ofekmeister at gmail.com Tue Sep 5 02:47:03 2017 From: ofekmeister at gmail.com (ofekmeister at gmail.com) Date: Mon, 4 Sep 2017 23:47:03 -0700 (PDT) Subject: Hatch - A modern project, package, and virtual env manager Message-ID: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> I just released the first version of https://github.com/ofek/hatch It basically makes what you do most in your dev workflow easier and more configurable. Please provide feedback! From stefan_ml at behnel.de Tue Sep 5 04:05:51 2017 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 5 Sep 2017 10:05:51 +0200 Subject: Case-insensitive string equality In-Reply-To: <59a9fbe3$0$1605$c3e8da3$5496439d@news.astraweb.com> References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> <59a9fbe3$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano schrieb am 02.09.2017 um 02:31: > - the German eszett, ?, which has two official[1] uppercase forms: 'SS' > and an uppercase eszett I wonder if there is an equivalent to Godwin's Law with respect to character case related discussions and the German ?. Stefan From rosuav at gmail.com Tue Sep 5 04:18:59 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Sep 2017 18:18:59 +1000 Subject: Case-insensitive string equality In-Reply-To: References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> <59a9fbe3$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 5, 2017 at 6:05 PM, Stefan Behnel wrote: > Steve D'Aprano schrieb am 02.09.2017 um 02:31: >> - the German eszett, ?, which has two official[1] uppercase forms: 'SS' >> and an uppercase eszett > > I wonder if there is an equivalent to Godwin's Law with respect to > character case related discussions and the German ?. Given that it's such a useful test case, I think it's inevitable (the first part of Godwin's Law), but not a conversation killer (the second part, and not (AFAIK) part of the original statement). Either that, or the Turkish I?/?i. ChrisA From antoon.pardon at vub.be Tue Sep 5 04:50:33 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 5 Sep 2017 10:50:33 +0200 Subject: How do I find what kind of exception is thrown. Message-ID: <8f8365fe-c50a-44f0-f4b2-c93365327d22@vub.be> Python 2.6.4 on a solaris box. I have a program in which all kind of excptions can be thrown and caugth. The main program is something like below: try: do_stuff except Exception: log unexpected trouble Now I found the following in the logs: [Errno 131] Connection reset by peer This is a problem I would like to catch earlier however I have no idea what exception I would have to catch in order to treat this case. -- Antoon Pardon From davidgshi at yahoo.co.uk Tue Sep 5 05:31:47 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Tue, 5 Sep 2017 09:31:47 +0000 (UTC) Subject: How to get values for skos/note, skos/notation and label in N-Triples References: <682340000.5122430.1504603907191.ref@mail.yahoo.com> Message-ID: <682340000.5122430.1504603907191@mail.yahoo.com> "Baginton E04009817"@en . "Live" . "E04009817" . Are there any hello world examples? Regards, David From dpalao.python at gmail.com Tue Sep 5 05:35:54 2017 From: dpalao.python at gmail.com (David Palao) Date: Tue, 5 Sep 2017 11:35:54 +0200 Subject: How do I find what kind of exception is thrown. In-Reply-To: <8f8365fe-c50a-44f0-f4b2-c93365327d22@vub.be> References: <8f8365fe-c50a-44f0-f4b2-c93365327d22@vub.be> Message-ID: Hi, It looks to me like an OSError, can it be? Best 2017-09-05 10:50 GMT+02:00 Antoon Pardon : > Python 2.6.4 on a solaris box. > > I have a program in which all kind of excptions can be thrown and caugth. > The main program is something like below: > > try: > do_stuff > except Exception: > log unexpected trouble > > Now I found the following in the logs: [Errno 131] Connection reset by peer > > This is a problem I would like to catch earlier however I have no idea what > exception I would have to catch in order to treat this case. > > -- > Antoon Pardon > > -- > https://mail.python.org/mailman/listinfo/python-list From cs at cskk.id.au Tue Sep 5 05:44:15 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 5 Sep 2017 19:44:15 +1000 Subject: How do I find what kind of exception is thrown. In-Reply-To: <8f8365fe-c50a-44f0-f4b2-c93365327d22@vub.be> References: <8f8365fe-c50a-44f0-f4b2-c93365327d22@vub.be> Message-ID: <20170905094415.GA26113@cskk.homeip.net> On 05Sep2017 10:50, Antoon Pardon wrote: >Python 2.6.4 on a solaris box. > >I have a program in which all kind of excptions can be thrown and caugth. >The main program is something like below: > >try: > do_stuff >except Exception: > log unexpected trouble > >Now I found the following in the logs: [Errno 131] Connection reset by peer > >This is a problem I would like to catch earlier however I have no idea what >exception I would have to catch in order to treat this case. Almost anything which says "Errno ..." is almost always an OSError (or an IOError as I found the other day). I try to be quite picky about these. So for example: try: fp = open(filename) except OSError as e: if e.errno == errno.ENOENT: # file missing ... act as if the file were empty ... else: # other badness - let the exception escape raise Cheers, Cameron Simpson (formerly cs at zip.com.au) From cs at cskk.id.au Tue Sep 5 05:49:51 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 5 Sep 2017 19:49:51 +1000 Subject: How do I find what kind of exception is thrown. In-Reply-To: <20170905094415.GA26113@cskk.homeip.net> References: <20170905094415.GA26113@cskk.homeip.net> Message-ID: <20170905094951.GA35144@cskk.homeip.net> On 05Sep2017 19:44, Cameron Simpson wrote: >Almost anything which says "Errno ..." is almost always an OSError (or an >IOError as I found the other day). I try to be quite picky about these. So for >example: Oh yes, and on a UNIX host such as Solaris the command "man 2 intro" will normally show you the intro to section 2 (system calls) and include a listing of all the errno values and their meanings. You can probably deduce the system call from the python stack trace, so if it is, say, read, then "man 2 read" should include the relevant error codes and their cuasing circumstances. Cheers, Cameron Simpson (formerly cs at zip.com.au) From __peter__ at web.de Tue Sep 5 06:05:33 2017 From: __peter__ at web.de (Peter Otten) Date: Tue, 05 Sep 2017 12:05:33 +0200 Subject: How do I find what kind of exception is thrown. References: <8f8365fe-c50a-44f0-f4b2-c93365327d22@vub.be> Message-ID: Antoon Pardon wrote: > Python 2.6.4 on a solaris box. > > I have a program in which all kind of excptions can be thrown and caugth. > The main program is something like below: > > try: > do_stuff > except Exception: > log unexpected trouble > > Now I found the following in the logs: [Errno 131] Connection reset by > peer > > This is a problem I would like to catch earlier however I have no idea > what exception I would have to catch in order to treat this case. The logging package in the stdlib provides a way to include the traceback into the logfile: $ cat log_exc.py import logging def do_stuff(): 1/0 logger = logging.getLogger() logging.basicConfig(filename="tmp.log") try: do_stuff() except Exception: logger.exception("unexpected trouble") $ python3 log_exc.py $ cat tmp.log ERROR:root:unexpected trouble Traceback (most recent call last): File "log_exc.py", line 10, in do_stuff() File "log_exc.py", line 4, in do_stuff 1/0 ZeroDivisionError: division by zero $ From steve+python at pearwood.info Tue Sep 5 07:39:18 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 05 Sep 2017 21:39:18 +1000 Subject: How do I find what kind of exception is thrown. References: <8f8365fe-c50a-44f0-f4b2-c93365327d22@vub.be> Message-ID: <59ae8ce9$0$16755$b1db1813$d948b532@news.astraweb.com> On Tue, 5 Sep 2017 06:50 pm, Antoon Pardon wrote: > Python 2.6.4 on a solaris box. > > I have a program in which all kind of excptions can be thrown and caugth. > The main program is something like below: > > try: > do_stuff > except Exception: > log unexpected trouble > > Now I found the following in the logs: [Errno 131] Connection reset by peer > > This is a problem I would like to catch earlier however I have no idea what > exception I would have to catch in order to treat this case. try: do_stuff except Exception as err: print err, type(err) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From greg.ewing at canterbury.ac.nz Tue Sep 5 09:11:37 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Sep 2017 01:11:37 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > The third entity is the reference linking the name to the object (the arrow). > This isn't a runtime value in Python, nor is it a compile time entity that > exists in source code. It is pure implementation, and as such, exists outside > of the Python domain. The fact that there is a connection between the name and the object is very much part of Python's abstract semantics. There are different ways to implement that connection, but *any* implementation of Python has to include *some* representation of it. There are also different words that can be used to describe it. You can say that names are bound to objects, or that names refer to objects, or that names hold references to objects. These are all equally good ways of talking about the exact same abstract concept. To me this argument about whether Python has references or not is like an American person saying that cars have hoods, and a British person saying he's wrong, hoods are an implementation detail and cars actually have bonnets instead. -- Greg From rhodri at kynesim.co.uk Tue Sep 5 09:19:30 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 5 Sep 2017 14:19:30 +0100 Subject: How to get values for skos/note, skos/notation and label in N-Triples In-Reply-To: <682340000.5122430.1504603907191@mail.yahoo.com> References: <682340000.5122430.1504603907191.ref@mail.yahoo.com> <682340000.5122430.1504603907191@mail.yahoo.com> Message-ID: <47894f87-ff89-fa5d-9788-bab510b944f2@kynesim.co.uk> On 05/09/17 10:31, David Shi via Python-list wrote: > "Baginton E04009817"@en . "Live" . "E04009817" . > > Are there any hello world examples? Examples of what? You really must explain yourself clearly or we cannot help you. -- Rhodri James *-* Kynesim Ltd From viradha at hotmail.com Tue Sep 5 09:24:55 2017 From: viradha at hotmail.com (V Vishwanathan) Date: Tue, 5 Sep 2017 13:24:55 +0000 Subject: Installation issue with Python 3.6.2. Message-ID: For the past 8/10 hours I have been trying to install the above version without any success. My O/S is windows 10 free upgrade from win 8.1 Every time I try to install, I simply get a message as per screen grab attached. I did have a version of 3.61 installed prior to upgrade to win 10, but somehow it got corrupted ,and I simply uninstalled, and just not able to install again. When I try the "Modify" option in the screen grab it proceeds and simply hangs at " pre version"?? I will appreciate any help. Than you, Venkat Sent from Mail for Windows 10 From ben.usenet at bsb.me.uk Tue Sep 5 09:28:42 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Tue, 05 Sep 2017 14:28:42 +0100 Subject: Please improve these comprehensions (was meaning of [ ]) References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> Message-ID: <878thtuved.fsf@bsb.me.uk> Rustom Mody writes: > On Tuesday, September 5, 2017 at 1:44:24 AM UTC+5:30, Ben Bacarisse wrote: >> Rustom Mody writes: >> >> > Here is some code I (tried) to write in class the other day >> > >> > The basic problem is of generating combinations >> >> > Now thats neat as far as it goes but combinations are fundamentally sets >> > not lists >> > >> > So I thought python would do a better job >> > I tried translating it to python and sets but it turned out more annoying than >> > helpful >> > Can someone improve it?? >> > >> > The straightforward translation of the above >> > Which is ok so far >> > >> > >> > def c(n,r): >> > if r == 0: >> > return [[]] >> > elif len(n) == 0: >> > return [] >> > else: >> > return [[n[0]] + l for l in c(n[1:],r-1)] + c(n[1:],r) >> > >> > >> > Now to go from returning list of lists to set of sets: >> >> def cs(n, r): >> if r == 0: >> return [set()] >> elif len(n) == 0: >> return [] >> else: >> return [set([n[0]]) | l for l in cs(n[1:], r-1)] + cs(n[1:], r) >> >> ? >> >> It's not so neat if you also want n to be a set rather than a list >> because the set equivalents of n[0] and n[1:] are a but more complex but >> it's not that bad: >> >> def css(n,r): >> if r == 0: >> return [set()] >> elif len(n) == 0: >> return [] >> else: >> rest = n.copy() >> e = rest.pop() >> return [set([e]) | l for l in css(rest, r-1)] + css(rest, r) > > Trying out your code Ben? > >>>> css({1,2,3,4}, 2) > [set([1, 2]), set([1, 3]), set([1, 4]), set([2, 3]), set([2, 4]), set([3, 4])] > >>>> type(css({1,2,3,4}, 2)) > > > Whereas with the cs I earlier gave: >>>> cs(frozenset([1,2,3,4]), 2) > frozenset([frozenset([2, 4]), frozenset([3, 4]), frozenset([2, 3]), > frozenset([1, 3]), frozenset([1, 2]), frozenset([1, 4])]) If you want a (frozen) sets of sets I'd just the code to def css(n, r): if r == 0: return frozenset({frozenset()}) elif len(n) == 0: return frozenset() else: rest = set(n) e = rest.pop() return frozenset([frozenset([e]) | l for l in list(css(rest, r-1))]) | css(rest, r) >>> css(frozenset({1,2,3,4}), 2) frozenset({frozenset({2, 4}), frozenset({3, 4}), frozenset({2, 3}), frozenset({1, 3}), frozenset({1, 2}), frozenset({1, 4})}) The switch from lists (using +) and frozen sets using | is the most obvious change, but if the top-level argument might itself be a frozenset then the copy must be changed to a set constructor so that pop will work. -- Ben. From greg.ewing at canterbury.ac.nz Tue Sep 5 09:37:15 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Sep 2017 01:37:15 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59ad983f$0$1589$c3e8da3$5496439d@news.astraweb.com> References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> <59ad983f$0$1589$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > On Tue, 5 Sep 2017 02:51 am, Stefan Ram wrote: > >> I am assuming that there are two argument passing mechanismss >> in the languages mentioned by me (C, C++, VBA, C#, Java, >> JavaScript, and Python): >> >>- pass by aliassing (reference) >>- pass "as if by assignment" > > That assumption is wrong. How is it wrong? What parameter passing mechanism in any of those languages is not either by aliasing or by assignment? -- Greg From greg.ewing at canterbury.ac.nz Tue Sep 5 09:37:20 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Sep 2017 01:37:20 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: Dennis Lee Bieber wrote: > Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference > semantics, in that the definition of a function declares how the > argument(s) are passed. Well, sort of. In Pascal and Modula, and also VB I think, parameters are the only things that can be declared as having reference semantics, whereas references in C++ are first-class things that can be stored in any variable. > I don't have Java textbooks locally (in storage 15 miles away) but from > what I recall, it too has the complication of splitting between "simple > types" and "reference types" ("boxed" I believe is the term used in books). > The default passing mechanism would be similar to the description of C# > ("boxed" types being implicit copies of references allowing mutation > in-place, but assignment to the parameter itself has no effect on the > caller). I suspect it too has some means to explicitly produce a > by-reference parameter. No, Java doesn't have by-reference parameters, which can be annoying at times when combined with the fact that it doesn't have anything like Python's easy tuple returning and unpacking. -- Greg From rustompmody at gmail.com Tue Sep 5 09:42:34 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Sep 2017 06:42:34 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, September 5, 2017 at 6:42:07 PM UTC+5:30, Gregory Ewing wrote: > Steve D'Aprano wrote: > > The third entity is the reference linking the name to the object (the arrow). > > This isn't a runtime value in Python, nor is it a compile time entity that > > exists in source code. It is pure implementation, and as such, exists outside > > of the Python domain. > > The fact that there is a connection between the name and the > object is very much part of Python's abstract semantics. > > There are different ways to implement that connection, but > *any* implementation of Python has to include *some* > representation of it. > > There are also different words that can be used to describe > it. You can say that names are bound to objects, or that > names refer to objects, or that names hold references to > objects. These are all equally good ways of talking about > the exact same abstract concept. > > To me this argument about whether Python has references > or not is like an American person saying that cars have > hoods, and a British person saying he's wrong, hoods > are an implementation detail and cars actually have > bonnets instead. Also called playing humpty-dumpty I believe there is a germ of value behind all this empty polemics There are 3 equivalence relations: 1. == ? mathematical, too coarse to understand nuances of python semantics 2. is ? machine representation, too fine to be useful 3. graph (or topological) equality which experienced pythonistas have internalized in understanding when two data structures are same or different [Roughly Anton's diagrams that are beyond my drawing capability!] And yet pythonistas need that to understand python data structures >>> a = [1,2] >>> b = [a,a] >>> c = [[1,2],[1,2]] >>> b == c True >>> b is c False >>> p = [1,2] >>> q = [p,p] >>> r = [[1,2],[1,2]] >>> q == r True >>> q is r False >>> b == q True >>> b == r True >>> b is q False >>> b is r False Now the pythonista understands that b and c may be math-= but have different structure Whereas b is graph-equal to q And c is graph-equal to r However there is no available operation to show/see that distinction The trouble is that graph-isomorphism is NP-complete so the crucial operation cannot be reasonably implemented Let the endless threads continue ? From greg.ewing at canterbury.ac.nz Tue Sep 5 09:47:25 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Sep 2017 01:47:25 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > [quoting Scott Stanchfield] > Figure 7: (Java) Defining a Dog pointer > Dog d; > > When you write that definition, you are defining a pointer to a Dog > object, not a Dog object itself. > [end quote] > > Here Scott mixes up what the compiler does (creates a pointer to a Dog object, > and what the programmer's Java code does (creates a Dog). Um, no. The declaration 'Dog d' on its own does NOT create a Dog, in any way, shape or form. It only declares something that can *refer* to a Dog created elsewhere, which is what Scott is quite correctly saying. > I expect this is because, as a "compiler guy", Scott probably doesn't really > believe that objects are values. Please stop insulting Scott's intelligence, and that of other "compiler guys", by suggesting that they don't understand things as well as you do. -- Greg From rustompmody at gmail.com Tue Sep 5 09:49:59 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Sep 2017 06:49:59 -0700 (PDT) Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: <878thtuved.fsf@bsb.me.uk> References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> Message-ID: <2f43c776-4595-445d-92d5-d20ab68be56a@googlegroups.com> On Tuesday, September 5, 2017 at 6:59:11 PM UTC+5:30, Ben Bacarisse wrote: > Rustom Mody writes: > > > On Tuesday, September 5, 2017 at 1:44:24 AM UTC+5:30, Ben Bacarisse wrote: > >> Rustom Mody writes: > >> > >> > Here is some code I (tried) to write in class the other day > >> > > >> > The basic problem is of generating combinations > >> > >> > Now thats neat as far as it goes but combinations are fundamentally sets > >> > not lists > >> > > >> > So I thought python would do a better job > >> > I tried translating it to python and sets but it turned out more annoying than > >> > helpful > >> > Can someone improve it?? > >> > > >> > The straightforward translation of the above > >> > Which is ok so far > >> > > >> > > >> > def c(n,r): > >> > if r == 0: > >> > return [[]] > >> > elif len(n) == 0: > >> > return [] > >> > else: > >> > return [[n[0]] + l for l in c(n[1:],r-1)] + c(n[1:],r) > >> > > >> > > >> > Now to go from returning list of lists to set of sets: > >> > >> def cs(n, r): > >> if r == 0: > >> return [set()] > >> elif len(n) == 0: > >> return [] > >> else: > >> return [set([n[0]]) | l for l in cs(n[1:], r-1)] + cs(n[1:], r) > >> > >> ? > >> > >> It's not so neat if you also want n to be a set rather than a list > >> because the set equivalents of n[0] and n[1:] are a but more complex but > >> it's not that bad: > >> > >> def css(n,r): > >> if r == 0: > >> return [set()] > >> elif len(n) == 0: > >> return [] > >> else: > >> rest = n.copy() > >> e = rest.pop() > >> return [set([e]) | l for l in css(rest, r-1)] + css(rest, r) > > > > Trying out your code Ben? > > > >>>> css({1,2,3,4}, 2) > > [set([1, 2]), set([1, 3]), set([1, 4]), set([2, 3]), set([2, 4]), set([3, 4])] > > > >>>> type(css({1,2,3,4}, 2)) > > > > > > Whereas with the cs I earlier gave: > >>>> cs(frozenset([1,2,3,4]), 2) > > frozenset([frozenset([2, 4]), frozenset([3, 4]), frozenset([2, 3]), > > frozenset([1, 3]), frozenset([1, 2]), frozenset([1, 4])]) > > If you want a (frozen) sets of sets I'd just the code to > > def css(n, r): > if r == 0: > return frozenset({frozenset()}) > elif len(n) == 0: > return frozenset() > else: > rest = set(n) > e = rest.pop() > return frozenset([frozenset([e]) > | l for l in list(css(rest, r-1))]) | css(rest, r) > > >>> css(frozenset({1,2,3,4}), 2) > frozenset({frozenset({2, 4}), frozenset({3, 4}), frozenset({2, 3}), > frozenset({1, 3}), frozenset({1, 2}), frozenset({1, 4})}) > > The switch from lists (using +) and frozen sets using | is the most > obvious change, but if the top-level argument might itself be a > frozenset then the copy must be changed to a set constructor so that pop > will work. Yes? Pop et al wont work with frozen sets Containment wont work with sets ? what mathematicians call 'not closed' All of which amounts to this that python sets are not really pleasant for math-work [Just for context: A teacher may have more important things to teach than python If the niggles get overbearing the vehicle may not be worth it ] Besides I find the name pop ridiculous Stacks imply a stronger order usage-discipline than lists Sets are unordered compared to lists To use a name traditionally reserved for a stack op on sets is quite nonsensical From rosuav at gmail.com Tue Sep 5 10:02:27 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 00:02:27 +1000 Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: <2f43c776-4595-445d-92d5-d20ab68be56a@googlegroups.com> References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> <2f43c776-4595-445d-92d5-d20ab68be56a@googlegroups.com> Message-ID: On Tue, Sep 5, 2017 at 11:49 PM, Rustom Mody wrote: > Pop et al wont work with frozen sets > Containment wont work with sets ? what mathematicians call 'not closed' > All of which amounts to this that python sets are not really pleasant for > math-work Funnily enough, Python has never boasted that it's great for mathematicians. Time and time again I see posts here that try to explain Python from the POV of pure mathematics, and they always seem to end up getting convoluted and awkward. The real world is not so pure... and Python lives happily in the real world. ChrisA From rosuav at gmail.com Tue Sep 5 10:03:13 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 00:03:13 +1000 Subject: How to get values for skos/note, skos/notation and label in N-Triples In-Reply-To: References: <682340000.5122430.1504603907191.ref@mail.yahoo.com> <682340000.5122430.1504603907191@mail.yahoo.com> Message-ID: On Tue, Sep 5, 2017 at 11:40 PM, Dennis Lee Bieber wrote: > > {Post #6 in 6 days} > > On Tue, 5 Sep 2017 09:31:47 +0000 (UTC), David Shi via Python-list > declaimed the following: > >> "Baginton E04009817"@en . "Live" . "E04009817" . >> > >>>> "How to get values for skos/note, skos/notation and label in N-Triples" > > The same way as for the other field as shown in the interactive session > I posted 20 hours ago -- did you read it? It took less than an hour of > experimenting in the interpreter's interactive shell to answer your earlier > post. I think Google must be down for him. ChrisA From tjol at tjol.eu Tue Sep 5 10:05:31 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 5 Sep 2017 16:05:31 +0200 Subject: Installation issue with Python 3.6.2. In-Reply-To: References: Message-ID: On 2017-09-05 15:24, V Vishwanathan wrote: > For the past 8/10 hours I have been trying to install the above version without any success. > > My O/S is windows 10 free upgrade from win 8.1 > > Every time I try to install, I simply get a message as per screen grab attached. This list is text only. There is no attachment. > > I did have a version of 3.61 installed prior to upgrade to win 10, but somehow > > it got corrupted ,and I simply uninstalled, and just not able to install again. > > When I try the "Modify" option in the screen grab it proceeds and simply hangs > > at " pre version"?? > > I will appreciate any help. > > Than you, > > Venkat > > > > Sent from Mail for Windows 10 > > -- Thomas Jollans From rustompmody at gmail.com Tue Sep 5 10:08:56 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Sep 2017 07:08:56 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tuesday, September 5, 2017 at 7:12:48 PM UTC+5:30, Rustom Mody wrote: > On Tuesday, September 5, 2017 at 6:42:07 PM UTC+5:30, Gregory Ewing wrote: > > Steve D'Aprano wrote: > > > The third entity is the reference linking the name to the object (the arrow). > > > This isn't a runtime value in Python, nor is it a compile time entity that > > > exists in source code. It is pure implementation, and as such, exists outside > > > of the Python domain. > > > > The fact that there is a connection between the name and the > > object is very much part of Python's abstract semantics. > > > > There are different ways to implement that connection, but > > *any* implementation of Python has to include *some* > > representation of it. > > > > There are also different words that can be used to describe > > it. You can say that names are bound to objects, or that > > names refer to objects, or that names hold references to > > objects. These are all equally good ways of talking about > > the exact same abstract concept. > > > > To me this argument about whether Python has references > > or not is like an American person saying that cars have > > hoods, and a British person saying he's wrong, hoods > > are an implementation detail and cars actually have > > bonnets instead. > > Also called playing humpty-dumpty > > I believe there is a germ of value behind all this empty polemics > There are 3 equivalence relations: > 1. == ? mathematical, too coarse to understand nuances of python semantics > 2. is ? machine representation, too fine to be useful > 3. graph (or topological) equality which experienced pythonistas have internalized > in understanding when two data structures are same or different > [Roughly Anton's diagrams that are beyond my drawing capability!] > > > And yet pythonistas need that to understand python data structures > > >>> a = [1,2] > >>> b = [a,a] > >>> c = [[1,2],[1,2]] > >>> b == c > True > >>> b is c > False > >>> p = [1,2] > >>> q = [p,p] > >>> r = [[1,2],[1,2]] > >>> q == r > True > >>> q is r > False > >>> b == q > True > >>> b == r > True > >>> b is q > False > >>> b is r > False To make it more clear Suppose ? is graph-equal. The pythonista understands that b ? c ## ? is finer than == Whereas b ? r ie ? is coarser than is Its another matter that the name 'is' makes these discussions much harder in python than in equivalent languages like java, lisp, javascript etc by making the mostly unnecessary and irrelevant "is machine-rep same" sound the same(!) as "is conceptually same" From rosuav at gmail.com Tue Sep 5 10:09:24 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 00:09:24 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Sep 5, 2017 at 11:11 PM, Gregory Ewing wrote: > Steve D'Aprano wrote: >> >> The third entity is the reference linking the name to the object (the >> arrow). >> This isn't a runtime value in Python, nor is it a compile time entity that >> exists in source code. It is pure implementation, and as such, exists >> outside >> of the Python domain. > > > The fact that there is a connection between the name and the > object is very much part of Python's abstract semantics. > > There are different ways to implement that connection, but > *any* implementation of Python has to include *some* > representation of it. Sure. But let's suppose you're building a Python implementation on top of a language that has a perfectly good implementation of dict already built for you. Literally every other namespace can be represented with a dictionary, and the name:value association is that reference. Is the reference *itself* a runtime value? No; you can't pick it up and move it around - all you'll do is dereference it and get the value itself. (Or you'll work with the name, as a string. That can sometimes serve as a pseudo-reference.) Is it a compile time entity? Not directly (assignment statements imply them, but they aren't themselves the references). So Steve's comment is still correct. ChrisA From rustompmody at gmail.com Tue Sep 5 10:19:51 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Sep 2017 07:19:51 -0700 (PDT) Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> <2f43c776-4595-445d-92d5-d20ab68be56a@googlegroups.com> Message-ID: <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> On Tuesday, September 5, 2017 at 7:32:52 PM UTC+5:30, Chris Angelico wrote: > On Tue, Sep 5, 2017 at 11:49 PM, Rustom Mody wrote: > > Pop et al wont work with frozen sets > > Containment wont work with sets ? what mathematicians call 'not closed' > > All of which amounts to this that python sets are not really pleasant for > > math-work > > Funnily enough, Python has never boasted that it's great for > mathematicians. True that > Time and time again I see posts here that try to > explain Python from the POV of pure mathematics, and they always seem > to end up getting convoluted and awkward. Unrelated that. Look at all the fundamental operations here https://docs.python.org/3.6/library/operator.html What percentage of these are unrelated to math? And how do you write even the simplest assignment statement without a (mathematical) expression on the rhs? And a look at history: What *were* Turing, Church, von Neumann, even Knuth by training? Mathematicians or CS-ists? And what *are* the contributions of Turing, Church, von Neumann, Knuth to CS? From rosuav at gmail.com Tue Sep 5 10:25:40 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 00:25:40 +1000 Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> <2f43c776-4595-445d-92d5-d20ab68be56a@googlegroups.com> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> Message-ID: On Wed, Sep 6, 2017 at 12:19 AM, Rustom Mody wrote: > On Tuesday, September 5, 2017 at 7:32:52 PM UTC+5:30, Chris Angelico wrote: >> On Tue, Sep 5, 2017 at 11:49 PM, Rustom Mody wrote: >> > Pop et al wont work with frozen sets >> > Containment wont work with sets ? what mathematicians call 'not closed' >> > All of which amounts to this that python sets are not really pleasant for >> > math-work >> >> Funnily enough, Python has never boasted that it's great for >> mathematicians. > > True that > >> Time and time again I see posts here that try to >> explain Python from the POV of pure mathematics, and they always seem >> to end up getting convoluted and awkward. > > Unrelated that. > Look at all the fundamental operations here > https://docs.python.org/3.6/library/operator.html > > What percentage of these are unrelated to math? > > And how do you write even the simplest assignment statement without a > (mathematical) expression on the rhs? > > And a look at history: > What *were* Turing, Church, von Neumann, even Knuth by training? Mathematicians or CS-ists? > > And what *are* the contributions of Turing, Church, von Neumann, Knuth to CS? Yes, mathematicians have contributed significantly to comp sci. And people in suits have contributed to comp sci, too. Should we all wear suits just because of the massive contributions from decades ago? Or should we do what is best for solving our problems today? ChrisA From viktorovichandrej at gmail.com Tue Sep 5 10:26:23 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Tue, 5 Sep 2017 07:26:23 -0700 (PDT) Subject: Python console's workspace path Message-ID: <57b4b603-21c2-4730-9ea0-a9bc90ac5a11@googlegroups.com> Hello, I run Python 3.6 console under windows 10. Where is default console directory? I run script: >>> tf = open ("aaa.txt", "w") >>> tf.write("aaaa %s" % 123) >>> tf.close() Where file aaa.txt will be created? Can I change default work space location? How? From grant.b.edwards at gmail.com Tue Sep 5 10:27:04 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 5 Sep 2017 14:27:04 +0000 (UTC) Subject: Case-insensitive string equality References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> <59a9fbe3$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2017-09-03, Gregory Ewing wrote: > Stefan Ram wrote: >> But of >> course, actually the rules of orthography require "Ma?e" or >> "Masse" and do not allow "MASSE" or "MASZE", just as in >> English, "English" has to be written "English" and not >> "english" or "ENGLISH". > > While "english" is wrong in English, there's no rule > against using "ENGLISH" as an all-caps version. Perhaps there's no "rule" in your book of rules, but it's almost universally considered bad style and you will lose points with your teacher, editor, etc. On the inter-tubes generally indicates you're shouting, or just a kook. I guess if either of those is true, then it's good style. -- Grant Edwards grant.b.edwards Yow! at BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI- gmail.com From rosuav at gmail.com Tue Sep 5 10:31:41 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 00:31:41 +1000 Subject: Case-insensitive string equality In-Reply-To: References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> <59a9fbe3$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 6, 2017 at 12:27 AM, Grant Edwards wrote: > On 2017-09-03, Gregory Ewing wrote: >> Stefan Ram wrote: >>> But of >>> course, actually the rules of orthography require "Ma?e" or >>> "Masse" and do not allow "MASSE" or "MASZE", just as in >>> English, "English" has to be written "English" and not >>> "english" or "ENGLISH". >> >> While "english" is wrong in English, there's no rule >> against using "ENGLISH" as an all-caps version. > > Perhaps there's no "rule" in your book of rules, but it's almost > universally considered bad style and you will lose points with your > teacher, editor, etc. > > On the inter-tubes generally indicates you're shouting, or just a > kook. I guess if either of those is true, then it's good style. ENGLISH, Doc! *Doc Brown proceeds to explain and/or demonstrate* ChrisA From rustompmody at gmail.com Tue Sep 5 10:36:26 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Sep 2017 07:36:26 -0700 (PDT) Subject: Python console's workspace path In-Reply-To: <57b4b603-21c2-4730-9ea0-a9bc90ac5a11@googlegroups.com> References: <57b4b603-21c2-4730-9ea0-a9bc90ac5a11@googlegroups.com> Message-ID: On Tuesday, September 5, 2017 at 7:58:23 PM UTC+5:30, Andrej Viktorovich wrote: > Hello, > > I run Python 3.6 console under windows 10. Where is default console directory? > > I run script: > >>> tf = open ("aaa.txt", "w") > >>> tf.write("aaaa %s" % 123) > >>> tf.close() > > Where file aaa.txt will be created? Can I change default work space location? How? >>> from os import getcwd >>> getcwd() You'll see where/what python takes as cwd (current working directory) There are other things on windows like rt-click the python executable icon on your desktop and adjust the "open in..." to whatever you want But I dont know too much about this to say ? From rosuav at gmail.com Tue Sep 5 10:38:12 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 00:38:12 +1000 Subject: Python console's workspace path In-Reply-To: <57b4b603-21c2-4730-9ea0-a9bc90ac5a11@googlegroups.com> References: <57b4b603-21c2-4730-9ea0-a9bc90ac5a11@googlegroups.com> Message-ID: On Wed, Sep 6, 2017 at 12:26 AM, Andrej Viktorovich wrote: > Hello, > > I run Python 3.6 console under windows 10. Where is default console directory? > > I run script: >>>> tf = open ("aaa.txt", "w") >>>> tf.write("aaaa %s" % 123) >>>> tf.close() > > Where file aaa.txt will be created? Can I change default work space location? How? Easy way to find out: >>> import os >>> os.getcwd() '/home/rosuav' ChrisA From viktorovichandrej at gmail.com Tue Sep 5 11:14:33 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Tue, 5 Sep 2017 08:14:33 -0700 (PDT) Subject: Run python module from console Message-ID: <067b6060-67c3-4de5-9185-bc7b6ac6e433@googlegroups.com> Hello, I suppose I can run python module by passing module as param for executable: python.exe myscr.py But how to run script when I'm inside of console and have python prompt: >>> From rustompmody at gmail.com Tue Sep 5 11:19:14 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Sep 2017 08:19:14 -0700 (PDT) Subject: Run python module from console In-Reply-To: <067b6060-67c3-4de5-9185-bc7b6ac6e433@googlegroups.com> References: <067b6060-67c3-4de5-9185-bc7b6ac6e433@googlegroups.com> Message-ID: <34fd69f5-ae82-4e8e-84bc-706c8aca1b13@googlegroups.com> On Tuesday, September 5, 2017 at 8:45:00 PM UTC+5:30, Andrej Viktorovich wrote: > Hello, > > I suppose I can run python module by passing module as param for executable: > > python.exe myscr.py > > But how to run script when I'm inside of console and have python prompt: > > >>> >> import myscr # Note no .py extension From python at mrabarnett.plus.com Tue Sep 5 11:44:00 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 5 Sep 2017 16:44:00 +0100 Subject: Python console's workspace path In-Reply-To: References: <57b4b603-21c2-4730-9ea0-a9bc90ac5a11@googlegroups.com> Message-ID: <4f4b9f59-0a52-da5a-973e-1bf76f78d757@mrabarnett.plus.com> On 2017-09-05 15:31, Stefan Ram wrote: > Andrej Viktorovich writes: >>Hello, >>I run Python 3.6 console under windows 10. Where is default console directory? >>I run script: >>>>> tf = open ("aaa.txt", "w") >>>>> tf.write("aaaa %s" % 123) >>>>> tf.close() > > |>>> import os > |>>> os.getcwd() > Also, os.chdir(path) to change it, although it's better to work with absolute paths than change the working directory. From ned at nedbatchelder.com Tue Sep 5 12:03:01 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 5 Sep 2017 12:03:01 -0400 Subject: Run python module from console In-Reply-To: References: <067b6060-67c3-4de5-9185-bc7b6ac6e433@googlegroups.com> Message-ID: <20faf12a-cd79-0aec-aeb8-a7b03005b7bf@nedbatchelder.com> On 9/5/17 11:16 AM, Stefan Ram wrote: > Andrej Viktorovich writes: >> I suppose I can run python module by passing module as param for executable: >> python.exe myscr.py >> But how to run script when I'm inside of console and have python prompt: The Python console isn't meant for ad-hoc execution of random scripts.? It's designed for running one program, from the OS command line.? If you need to run different scripts within one interpreter session, it might be better to reorganize your code, or find a different execution environment. > exec( compile( open( 'myscr.py', 'rb' ).read(), 'myscr.py', 'exec' )) > > . This looks quite complicated, but there are rumors > that Python 4 might have a ?execfile? function, and > one then will be able to write: > > execfile( 'myscr.py' ) It's better to not start rumors about fictitious Python versions. --Ned. From ian.g.kelly at gmail.com Tue Sep 5 12:38:16 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 5 Sep 2017 10:38:16 -0600 Subject: tictactoe script - commented - may have pedagogical value In-Reply-To: References: Message-ID: On Mon, Sep 4, 2017 at 9:26 PM, wrote: > > """ > this program makes an optimal tictactoe move by answering the following questions > in their given order until it is told where to put its mark: > > 1) can you win the game? > if so then do it > 2) could your opponent win the game if it was his turn? > if so then put your own mark where a mark of his would win him the game > 3) could you win the game if you had two turns in a row? > if so then make a move that leaves you with the largest number of second moves > that would win you the game if you could really make them > 4) is the center square open? > if so then put your mark there > 5) are any of the corners open? > if so then put your mark on one of them > 6) put your mark on any open square > """ I'm afraid its play is not optimal. Here's a transcript where the program lost. Usually I've seen Tic Tac Toe implemented using the Minimax algorithm since the decision tree for Tic Tac Toe is quite shallow. py> play(oh) | | -+-+- | | -+-+- | | cell number: 1 X| | -+-+- |0| -+-+- | | cell number: 9 X| |0 -+-+- |0| -+-+- | |X cell number: 7 X| |0 -+-+- |0| -+-+- X|0|X cell number: 4 X| |0 -+-+- X|0| -+-+- X|0|X X wins From rhodri at kynesim.co.uk Tue Sep 5 12:46:29 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 5 Sep 2017 17:46:29 +0100 Subject: Run python module from console In-Reply-To: References: <067b6060-67c3-4de5-9185-bc7b6ac6e433@googlegroups.com> <20faf12a-cd79-0aec-aeb8-a7b03005b7bf@nedbatchelder.com> Message-ID: On 05/09/17 17:11, Stefan Ram wrote: > Ned Batchelder writes: >>> exec( compile( open( 'myscr.py', 'rb' ).read(), 'myscr.py', 'exec' )) >>> . This looks quite complicated, but there are rumors >>> that Python 4 might have a ?execfile? function, and >>> one then will be able to write: >>> execfile( 'myscr.py' ) >> It's better to not start rumors about fictitious Python versions. > > That was an attempt to make a kind of joke. > > The background is: > > Python 2 has ?execfile?, but not Python 3. > > Another background is: > > We recently had this discussion, where Steve wrote: > > |there should be a standard solution, instead of having to > |re-invent the wheel over and over again. Even when the wheel > |is only two or three lines. The difference is that inventing this particular wheel is almost always a mistake. -- Rhodri James *-* Kynesim Ltd From rustompmody at gmail.com Tue Sep 5 13:02:42 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Sep 2017 10:02:42 -0700 (PDT) Subject: Run python module from console In-Reply-To: <067b6060-67c3-4de5-9185-bc7b6ac6e433@googlegroups.com> References: <067b6060-67c3-4de5-9185-bc7b6ac6e433@googlegroups.com> Message-ID: On Tuesday, September 5, 2017 at 8:45:00 PM UTC+5:30, Andrej Viktorovich wrote: > Hello, > > I suppose I can run python module by passing module as param for executable: > > python.exe myscr.py > > But how to run script when I'm inside of console and have python prompt: > > >>> By and large not straightforwardly possible At python prompt you call *functions* At OS prompt you call apps/programs/scripts including python *scripts* They are different with different calling conventions However if you look up on the __name__ == '__main__' trick you can find ways of getting both function call and script call behavior https://stackoverflow.com/questions/419163/what-does-if-name-main-do From steve+python at pearwood.info Tue Sep 5 13:02:57 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Sep 2017 03:02:57 +1000 Subject: A question on modification of a list via a function invocation References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59aed8c3$0$16757$b1db1813$d948b532@news.astraweb.com> On Tue, 5 Sep 2017 11:37 pm, Gregory Ewing wrote: > Dennis Lee Bieber wrote: >> Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference >> semantics, in that the definition of a function declares how the >> argument(s) are passed. > > Well, sort of. In Pascal and Modula, and also VB I think, > parameters are the only things that can be declared as having > reference semantics, whereas references in C++ are first-class > things that can be stored in any variable. No, they aren't first-class. - It is not possible to refer to a reference after it is defined; any occurrence of its name refers directly to the object it references. - Since you cannot refer directly to a reference, but only the object it points to, you cannot have a reference to a reference. - Containers of references are not allowed. - Once a reference to an object is created, it cannot be changed to reference another object ("to be reseated"). The last is only a limitation if you think of references as mutable pointers in the C sense. But if you think of them as objects in the Python sense, that makes them merely immutable. But the inability to refer to the reference itself, the lack of references to references, and the inability to have a container of references, makes them second-class values -- or possibly not values at all. (I don't know enough about C++ to distinguish between the last two opinions, but I'm strongly leaning towards "not values at all".) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Sep 5 13:15:02 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Sep 2017 03:15:02 +1000 Subject: A question on modification of a list via a function invocation References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59aedb98$0$16745$b1db1813$d948b532@news.astraweb.com> On Tue, 5 Sep 2017 11:08 pm, Stefan Ram wrote: > Steve D'Aprano writes: >>[quote] >>The mistake they make is in the definition of >>Figure 7: (Java) Defining a Dog pointer >>Dog d; >>itself. When you write that definition, you are defining a pointer to a Dog >>object, not a Dog object itself. >>[end quote] >>Here Scott mixes up what the compiler does (creates a pointer to a Dog object, >>and what the programmer's Java code does (creates a Dog). > > I have not the whole context in mind, and so I might get > something wrong here, but if > > Dog d; > > is supposed to be interpreted as Java, then it neither > creates a pointer to a Dog object nor it creates a Dog. > > Instead, it declares an unitialized variable d. Thank you Stefan, your correction is noted. I'm not a Java expert like Scott, and I failed to notice the distinction between: Dog d; and Dog d = new Dog(); so I failed to realise that of course d has no value at all in Scott's example. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ned at nedbatchelder.com Tue Sep 5 13:15:25 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 5 Sep 2017 13:15:25 -0400 Subject: A question on modification of a list via a function invocation In-Reply-To: <59aed8c3$0$16757$b1db1813$d948b532@news.astraweb.com> References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> <59aed8c3$0$16757$b1db1813$d948b532@news.astraweb.com> Message-ID: On 9/5/17 1:02 PM, Steve D'Aprano wrote: > On Tue, 5 Sep 2017 11:37 pm, Gregory Ewing wrote: > >> Dennis Lee Bieber wrote: >>> Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference >>> semantics, in that the definition of a function declares how the >>> argument(s) are passed. >> Well, sort of. In Pascal and Modula, and also VB I think, >> parameters are the only things that can be declared as having >> reference semantics, whereas references in C++ are first-class >> things that can be stored in any variable. > No, they aren't first-class. Did you mis-read Gregory's claim? He said, "references *in C++* are first-class things".? You seem to be talking below about Python things. > > - It is not possible to refer to a reference after it is defined; any > occurrence of its name refers directly to the object it references. > > - Since you cannot refer directly to a reference, but only the object > it points to, you cannot have a reference to a reference. > > - Containers of references are not allowed. > > - Once a reference to an object is created, it cannot be changed to > reference another object ("to be reseated"). > > The last is only a limitation if you think of references as mutable pointers in > the C sense. But if you think of them as objects in the Python sense, that > makes them merely immutable. > > But the inability to refer to the reference itself, the lack of references to > references, and the inability to have a container of references, makes them > second-class values -- or possibly not values at all. > > (I don't know enough about C++ to distinguish between the last two opinions, but > I'm strongly leaning towards "not values at all".) > > > From rustompmody at gmail.com Tue Sep 5 13:26:16 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Sep 2017 10:26:16 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> <59aed8c3$0$16757$b1db1813$d948b532@news.astraweb.com> Message-ID: On Tuesday, September 5, 2017 at 10:45:45 PM UTC+5:30, Ned Batchelder wrote: > On 9/5/17 1:02 PM, Steve D'Aprano wrote: > > On Tue, 5 Sep 2017 11:37 pm, Gregory Ewing wrote: > > > >> Dennis Lee Bieber wrote: > >>> Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference > >>> semantics, in that the definition of a function declares how the > >>> argument(s) are passed. > >> Well, sort of. In Pascal and Modula, and also VB I think, > >> parameters are the only things that can be declared as having > >> reference semantics, whereas references in C++ are first-class > >> things that can be stored in any variable. > > No, they aren't first-class. > > Did you mis-read Gregory's claim? He said, "references *in C++* are > first-class things".? You seem to be talking below about Python things. I think its mostly true of C++ And Steven did say: (I don't know enough about C++ to distinguish between the last two opinions, but I'm strongly leaning towards "not values at all".) So he seems to be talking of C++ (as analogous to python??) But I dont see that any of it is relevant Whether references are - first-class (Algol-68, pointers-in-C) or are simply - second class (C++) - invisible (python, lisp, ruby, javascript) has little to do with what we are talking The question is whether we need the *idea* of references (modulo humpty-dumpty-fication) to talk *about* the language; ie it needs to be there in the human/informal ontology, even if the docs play word-games and try to avoid trigger-words in honour of PC. In my view its almost the defining quality of imperative languages that the semantics of the language is not properly/fully comprehensive without (something like) references. [Replace "imperative language" with "assignment and mutation" if you like] From rosuav at gmail.com Tue Sep 5 13:28:10 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 03:28:10 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> <59aed8c3$0$16757$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 6, 2017 at 3:15 AM, Ned Batchelder wrote: > On 9/5/17 1:02 PM, Steve D'Aprano wrote: >> On Tue, 5 Sep 2017 11:37 pm, Gregory Ewing wrote: >> >>> Dennis Lee Bieber wrote: >>>> Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference >>>> semantics, in that the definition of a function declares how the >>>> argument(s) are passed. >>> Well, sort of. In Pascal and Modula, and also VB I think, >>> parameters are the only things that can be declared as having >>> reference semantics, whereas references in C++ are first-class >>> things that can be stored in any variable. >> No, they aren't first-class. > > Did you mis-read Gregory's claim? He said, "references *in C++* are > first-class things". You seem to be talking below about Python things. > And everything Steve said was about C++ references, which are a form of alias. Not a 'thing'. ChrisA From grant.b.edwards at gmail.com Tue Sep 5 13:37:15 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 5 Sep 2017 17:37:15 +0000 (UTC) Subject: Run python module from console References: <067b6060-67c3-4de5-9185-bc7b6ac6e433@googlegroups.com> Message-ID: On 2017-09-05, Andrej Viktorovich wrote: > Hello, > > I suppose I can run python module by passing module as param for executable: > > python.exe myscr.py > > But how to run script when I'm inside of console and have python prompt: > >>>> os.system("python.exe myscr.py") -- Grant Edwards grant.b.edwards Yow! I've read SEVEN at MILLION books!! gmail.com From wrw at mac.com Tue Sep 5 13:54:57 2017 From: wrw at mac.com (William Ray Wing) Date: Tue, 05 Sep 2017 13:54:57 -0400 Subject: How do I find what kind of exception is thrown. In-Reply-To: <8f8365fe-c50a-44f0-f4b2-c93365327d22@vub.be> References: <8f8365fe-c50a-44f0-f4b2-c93365327d22@vub.be> Message-ID: > On Sep 5, 2017, at 4:50 AM, Antoon Pardon wrote: > > Python 2.6.4 on a solaris box. > > I have a program in which all kind of excptions can be thrown and caugth. > The main program is something like below: > > try: > do_stuff > except Exception: > log unexpected trouble > > Now I found the following in the logs: [Errno 131] Connection reset by peer > ?Connection reset by peer? is a network problem. It looks to your program as though the connection has been dropped. > This is a problem I would like to catch earlier however I have no idea what > exception I would have to catch in order to treat this case. > > -- > Antoon Pardon > > -- > https://mail.python.org/mailman/listinfo/python-list From namenobodywants at gmail.com Tue Sep 5 13:56:21 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Tue, 5 Sep 2017 10:56:21 -0700 (PDT) Subject: seeking advice about strategic-game ai Message-ID: <9fb105f8-2f21-4284-9634-31a04b62e0a1@googlegroups.com> i plan to try writing an ai for a strategic game, and i've pretty much narrowed the candidates down to either checkers or reversi. i would prefer to tackle the easier game, so can anybody tell me which one is easier to program decently? (or maybe i'm missing a good candidate - basically all i want is a game that's less trivial than tictactoe). by "decently" i mean that it should make reasonably skillful moves in a reasonable amount of time, but speed and playing strength take a backseat to the simplicity and well-motivatedness of the algorithm. (this isn't supposed to be a professional-caliber ai ... it will be more like a kid's science-fair project). more particularly, can anybody give me some high-level guidance about evaluation functions for either game? (no spoilers please - i want this to be really my own project). as far as reversi goes, my ideas on this matter are based mostly on the "basic diagram" in goro hasegawa's "how to win at othello". (i have a library hold on norvig's "paradigms of ai programming", which devotes an entire chapter to reversi, but the book hasn't come in yet). as for checkers, i was thinking about a weighted sum of three basic measurements ... if "you" and "i" are the players, then i would measure *) (my relative mobility) = (the number of moves i have) - (the number of moves you have) *) (my relative king presence) = (the number of kings i have) - (the number of kings you have) *) (my relative pawn presence) = (the number of pawns i have) - (the number of pawns you have) indeed, i've even wondered whether a viable evaluation could be based on relative mobility alone - that would, after all, work perfectly if there were no limit to the search horizon - but on the other hand i'm also prepared to find out that any viable evaluation needs to be more sophisticated. i wouldn't be surprised, for example, if the approach i'm suggesting could work but only if the weights in the sum are adjusted according to the number of moves made or some other criterion. anyway, that should suffice to give you an idea of where i'm at with this. thanks if you can help peace stm From ned at nedbatchelder.com Tue Sep 5 13:59:31 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 5 Sep 2017 13:59:31 -0400 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> <59aed8c3$0$16757$b1db1813$d948b532@news.astraweb.com> Message-ID: <4731d56c-6c4e-b920-e0af-3d3f47b97a18@nedbatchelder.com> On 9/5/17 1:28 PM, Chris Angelico wrote: > On Wed, Sep 6, 2017 at 3:15 AM, Ned Batchelder wrote: >> On 9/5/17 1:02 PM, Steve D'Aprano wrote: >>> On Tue, 5 Sep 2017 11:37 pm, Gregory Ewing wrote: >>> >>>> Dennis Lee Bieber wrote: >>>>> Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference >>>>> semantics, in that the definition of a function declares how the >>>>> argument(s) are passed. >>>> Well, sort of. In Pascal and Modula, and also VB I think, >>>> parameters are the only things that can be declared as having >>>> reference semantics, whereas references in C++ are first-class >>>> things that can be stored in any variable. >>> No, they aren't first-class. >> Did you mis-read Gregory's claim? He said, "references *in C++* are >> first-class things". You seem to be talking below about Python things. >> > And everything Steve said was about C++ references, which are a form > of alias. Not a 'thing'. I see, I misunderstood. Sorry for the distraction. > > ChrisA From eryksun at gmail.com Tue Sep 5 14:03:30 2017 From: eryksun at gmail.com (eryk sun) Date: Tue, 5 Sep 2017 13:03:30 -0500 Subject: Python console's workspace path In-Reply-To: <57b4b603-21c2-4730-9ea0-a9bc90ac5a11@googlegroups.com> References: <57b4b603-21c2-4730-9ea0-a9bc90ac5a11@googlegroups.com> Message-ID: On Tue, Sep 5, 2017 at 9:26 AM, Andrej Viktorovich wrote: > > I run Python 3.6 console under windows 10. Where is default console directory? The working directory for the console (i.e. conhost.exe) is irrelevant to Python. So I assume you mean the default working directory of the Python shell (i.e. the REPL). There isn't one. It's set by or inherited from the parent process. > Can I change default work space location? For interactive work, set the PYTHONSTARTUP environment variable to the fully-qualified path of a startup script. Set the working directory in this script via os.chdir("fully/qualified/path"). For a script, the working directory should not be used to find private resources. Use the script/package directory for read-only resources and otherwise use a platform-dependent data directory (e.g. on Windows use a subdirectory of %LocalAppData% or %ProgramData%). From antoon.pardon at rece.vub.ac.be Tue Sep 5 14:10:41 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 5 Sep 2017 20:10:41 +0200 Subject: How do I find what kind of exception is thrown. In-Reply-To: <59ae8ce9$0$16755$b1db1813$d948b532@news.astraweb.com> References: <8f8365fe-c50a-44f0-f4b2-c93365327d22@vub.be> <59ae8ce9$0$16755$b1db1813$d948b532@news.astraweb.com> Message-ID: <716cb6c2-b142-9d5c-4b3d-bad39d3a89c9@rece.vub.ac.be> On 05-09-17 13:39, Steve D'Aprano wrote: > On Tue, 5 Sep 2017 06:50 pm, Antoon Pardon wrote: > >> Python 2.6.4 on a solaris box. >> >> I have a program in which all kind of excptions can be thrown and caugth. >> The main program is something like below: >> >> try: >> do_stuff >> except Exception: >> log unexpected trouble >> >> Now I found the following in the logs: [Errno 131] Connection reset by peer >> >> This is a problem I would like to catch earlier however I have no idea what >> exception I would have to catch in order to treat this case. > > > try: > do_stuff > except Exception as err: > print err, type(err) Thabks, I should have thought of that. It turned out to be a socket.error, which wasn't obvious to find since I didn't use the socket module directly. -- Antoon Pardon. From tjreedy at udel.edu Tue Sep 5 14:27:37 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 5 Sep 2017 14:27:37 -0400 Subject: Python console's workspace path In-Reply-To: <57b4b603-21c2-4730-9ea0-a9bc90ac5a11@googlegroups.com> References: <57b4b603-21c2-4730-9ea0-a9bc90ac5a11@googlegroups.com> Message-ID: On 9/5/2017 10:26 AM, Andrej Viktorovich wrote: > Hello, > > I run Python 3.6 console under windows 10. Where is default console directory? It depends on how and where you start it. > I run script: >>>> tf = open ("aaa.txt", "w") >>>> tf.write("aaaa %s" % 123) >>>> tf.close() > > Where file aaa.txt will be created? I have compiled 3.7 as F:\\dev\\3x\\PCbuild\\win32\\python_d.exe. I suspect I originally started it from Explorer, so it started in 'F:\\dev\\3x\\PCbuild\\win32'. I then pinned it to the task bar. Left clicking the icon restarts it in the same directory. If I right click the icon and then right click 'Python', I see Properties, which shows "Start in" and a box with the path above. The Start in value can be edited. If you start python with a console command, instead of an icon, the initial directory is instead the current directory when you issue the command. > Can I change default work space location? How? By editing the icon (Rustom Mody), changing the directory before issuing a startup command, or with os.chdir (MRAB). -- Terry Jan Reedy From namenobodywants at gmail.com Tue Sep 5 14:27:44 2017 From: namenobodywants at gmail.com (namenobodywants at gmail.com) Date: Tue, 5 Sep 2017 11:27:44 -0700 (PDT) Subject: tictactoe script - commented - may have pedagogical value In-Reply-To: References: Message-ID: <47428b58-910a-4d8d-833f-03ca9af926c6@googlegroups.com> good point. this algorithm doesn't take account of the fact that one can make a threat (x's 147) by parrying a threat (o's 357). nevertheless i'm still certain that the components the algorithm is built from are the same components i use myself to play tictactoe, and i'm still certain that my own tictactoe playing is optimal. that's my motivation for doing it this way: i'm trying to formalize the algorithm i use myself. besides, exhaustive minimax search seems like cheating to me, since it doesn't generalize to less-trivial games. anyway, thanks for pointing out the error peace stm From steve+python at pearwood.info Tue Sep 5 15:08:57 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Sep 2017 05:08:57 +1000 Subject: A question on modification of a list via a function invocation References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> On Tue, 5 Sep 2017 11:47 pm, Gregory Ewing wrote: > Steve D'Aprano wrote: >> [quoting Scott Stanchfield] >> Figure 7: (Java) Defining a Dog pointer >> Dog d; >> >> When you write that definition, you are defining a pointer to a Dog >> object, not a Dog object itself. >> [end quote] >> >> Here Scott mixes up what the compiler does (creates a pointer to a Dog >> object, and what the programmer's Java code does (creates a Dog). > > Um, no. The declaration 'Dog d' on its own does NOT create a Dog, > in any way, shape or form. It only declares something that can > *refer* to a Dog created elsewhere, which is what Scott is > quite correctly saying. That's not what he said. I quoted him: he quite clearly states that d defines a pointer to a Dog object. He doesn't say that you're declaring an empty slot that is waiting to be filled with a pointer to a dog. He says it defines a pointer. So which Dog object does this pointer point to? Answer: there isn't one. There may not even be any Dog object existing in the entire program up to this point. Even allowing that there were a Dog to be pointed to, how do we inspect or manipulate that pointer? Answer: you can't, because pointers are not meaningful values in Java. There's no(?) Java code you can write that allows this: Dog d; java.lang.System.out.println( address of variable d ); java.lang.System.out.println( address of the Dog d points to ); Maybe compiler-specific debugging tools? I don't know enough Java to *categorically* rule it out, but if it exists at all, it would be unsafe to rely on the addresses you get. You're right that I made a mistake. I'm not a Java expert like Scott Stanchfield, and I was led astray by his misleading explanation, and failed to notice that d didn't have a value. (What's his excuse for not noticing?) As Stefan already pointed out, the code Scott gives does not define a value, but is just a declaration of a variable name. At that point, d has no value at all, and you get a compile time error if you try to access d. There is no Dog, and no pointer to a Dog. There's just a name (or variable if you prefer). So what's the value of d? It doesn't have one. Scott's explanation is misleading: `Dog d;` does not define *any value at all*, let alone a pointer. I daresay that Scott could attempt to justify his wording. I imagine it might go something like this: Of course d is a pointer to a value. The Java compiler keeps a table mapping variable names to memory addresses, and the name 'd' is mapped to some address in the table. That address must hold some value, even if it is uninitialised memory filled with arbitrary bytes. That address is a (possibly null, possibly invalid) pointer to a Dog object. -- Me, channelling what I think Scott *might* say. Notice how this mixes *three* different abstractions? There's the top-level Java abstraction, where we declare d as a Dog. There's the compiler abstraction, where we talk about mapping variable names to memory addresses, and pointers to Dog objects. And there's an even lower abstraction, where we talk about memory filled with arbitrary bytes. And so long as we keep track of which abstraction we're in, this is fine. It doesn't even have to be explicit: once people gain enough experience, they can effortlessly and implicitly swap between abstractions and not even notice. That's sometimes a good thing, but its a bad thing when we lose track of the abstraction level and confuse others (like me!), or even ourselves, and lead to "Not Even Wrong" questions like this: https://stackoverflow.com/questions/1961146/memory-address-of-variables-in-java (Likewise for people thinking that id() in Python returns a memory address, and ask how to dereference that address.) Not all explanations are equally useful, even if they are correct for some definition of "correct". In Python, the equivalent to Scott's code `Dog d;` would be something like this: # --- %< --- class Dog: pass global x assert isinstance(x, Dog) # --- %< --- except that we get a runtime NameError instead of a compile-time error. Would you like to say that this code "defines a pointer to a Dog"? I should hope not. How is it different from Scott's example of `Dog d;`? >> I expect this is because, as a "compiler guy", Scott probably doesn't really >> believe that objects are values. > > Please stop insulting Scott's intelligence, and that of other > "compiler guys", by suggesting that they don't understand things > as well as you do. Why shouldn't I suggest that Scott got something wrong? What makes him, and other "compiler guys", so special that they are infallible and can't make mistakes? Argument by authority is at best the weakest form of argument, if it isn't an outright fallacy. https://en.wikipedia.org/wiki/Argument_from_authority I'm not questioning his intelligence. I'm questioning his *perspective*, and his failure to distinguish between different levels of abstraction. I'm not questioning his understanding of how the Java compiler works, or what the standard says. In fact, my failure was to question Scott's authority sufficiently: if I were more questioning, I would have realised that his Dog example ("Figure 7" in the quoted text above) is not just the wrong perspective (as I initially thought) but *outright* wrong: d has no value at all, it is an uninitialised variable. (Thanks again Stefan for pointing that out.) Greg, you are really scraping the bottom of the barrel to stoop to falsely accusing me of insulting Scott's intelligence. Your argument here is an argument from outrage: how dare I insult Scott by claiming he is wrong. Scott himself claims that the Java standard makes a mistake to use the term reference when they mean pointer: The problem here is that the folks at Sun made a naming mistake. ... They went so far as to try a different name for the concept, formally calling them "references". A big mistake and it's caused even more confusion in the process. Are you going to accuse Scott of "insulting the intelligence" of James Gosling and the rest of the Sun team? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Tue Sep 5 15:46:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 05:46:11 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: References: Message-ID: On Wed, Sep 6, 2017 at 5:28 AM, Dennis Lee Bieber wrote: > On 5 Sep 2017 17:57:18 GMT, ram at zedat.fu-berlin.de (Stefan Ram) declaimed > the following: > >> But what does "a C++ reference" refer to? >> > > Per Stroustrup (The C++ Programming Language 4th Ed, page 189) > > """ > * ... > * A reference always refers to the object to which it was initialized. > * ... > > A reference is an alternative name for an object, an alias. ... > """ > > {Hmmm, and I see that the syntax can be used outside of parameter > declaration -- which is the only place I'd seen it previously... either > this is a change from earlier standards, or my classes just didn't feel the > need to expose a non-parameter reference -- since, based upon the above > book, you can not declare a bare reference "variable"; it MUST be > initialized with a real object.} Outside of parameters, there's very little practical reason for aliases. Their primary value is that an internal name can be an alias for an external object, which is achieved with reference parameters. ChrisA From python at mrabarnett.plus.com Tue Sep 5 15:56:46 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 5 Sep 2017 20:56:46 +0100 Subject: A question on modification of a list via a function invocation In-Reply-To: <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> Message-ID: <6edf3079-4942-95ad-dff7-881203489b61@mrabarnett.plus.com> On 2017-09-05 20:08, Steve D'Aprano wrote: > On Tue, 5 Sep 2017 11:47 pm, Gregory Ewing wrote: > >> Steve D'Aprano wrote: >>> [quoting Scott Stanchfield] >>> Figure 7: (Java) Defining a Dog pointer >>> Dog d; >>> >>> When you write that definition, you are defining a pointer to a Dog >>> object, not a Dog object itself. >>> [end quote] >>> >>> Here Scott mixes up what the compiler does (creates a pointer to a Dog >>> object, and what the programmer's Java code does (creates a Dog). >> >> Um, no. The declaration 'Dog d' on its own does NOT create a Dog, >> in any way, shape or form. It only declares something that can >> *refer* to a Dog created elsewhere, which is what Scott is >> quite correctly saying. > > That's not what he said. I quoted him: he quite clearly states that d defines a > pointer to a Dog object. He doesn't say that you're declaring an empty slot > that is waiting to be filled with a pointer to a dog. He says it defines a > pointer. > > So which Dog object does this pointer point to? Answer: there isn't one. There > may not even be any Dog object existing in the entire program up to this point. > > Even allowing that there were a Dog to be pointed to, how do we inspect or > manipulate that pointer? Answer: you can't, because pointers are not meaningful > values in Java. > > There's no(?) Java code you can write that allows this: > > Dog d; > java.lang.System.out.println( address of variable d ); > java.lang.System.out.println( address of the Dog d points to ); > > Maybe compiler-specific debugging tools? I don't know enough Java to > *categorically* rule it out, but if it exists at all, it would be unsafe to > rely on the addresses you get. > d is initialised to null. You can check for null: if (d == null) java.lang.System.out.println("There's no dog."); else d.bark(); From ofekmeister at gmail.com Tue Sep 5 16:13:14 2017 From: ofekmeister at gmail.com (ofekmeister at gmail.com) Date: Tue, 5 Sep 2017 13:13:14 -0700 (PDT) Subject: Hatch - A modern project, package, and virtual env manager In-Reply-To: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> References: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> Message-ID: <339de464-15f9-4b12-9cd7-5e76987ced30@googlegroups.com> 0.4.0 is out now! From rosuav at gmail.com Tue Sep 5 16:24:34 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 06:24:34 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 6, 2017 at 5:48 AM, Stefan Ram wrote: > Depends on the meaning of "meaningful". In Java, one can > inspect and manipulate pointers like in this program for > example: > [chomp code] That shows that the Java '==' operator is like the Python 'is' operator, and checks for object identity. You haven't manipulated pointers at all. In contrast, here's a C program that actually MANIPULATES pointers: #include void do_stuff(int *x) { printf("x (%p) points to %d\n", x, *x); x += 2; printf("Now x (%p) points to %d\n", x, *x); } int main() { int x[3] = {28, 42, 79}; do_stuff(x); /* or do_stuff(&x[0]); */ return 0; } You can't do this with Python, since pointer arithmetic fundamentally doesn't exist. You can in C. Can you in Java? ChrisA From rosuav at gmail.com Tue Sep 5 16:52:28 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 06:52:28 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 6, 2017 at 6:42 AM, Stefan Ram wrote: > Chris Angelico writes: >>here's a C program that actually MANIPULATES pointers: > ... >>x += 2; > ... >>You can in C. Can you in Java? > > ?dog = null? in Java would correspond to ?x = 0? in C. > > It seems, to you, an assignment of ?x + 2? to ?x? is > "manipulation", while an assignment of ?0? to ?x? is not. > > Well, if you define the term "manipulation" to get the > results you intend, no one can prove you wrong, but your > words might be harder to understand when they do not use > the English meanings of words (like "manipulate") but your > ad-hoc meanings. > dog = null in Java corresponds to x = None in Python. It's a null reference, but that's still a specific "thing". A fully compliant Python implementation could use a NULL pointer to represent the None object, as long as it correspondingly interprets such a pointer as representing None. In all of your Java examples, you're causing a name to refer to either an object or null, and everything you do can be explained in terms of name bindings Python-style. ChrisA From jessicayates59 at gmail.com Tue Sep 5 17:21:48 2017 From: jessicayates59 at gmail.com (jessicayates59 at gmail.com) Date: Tue, 5 Sep 2017 14:21:48 -0700 (PDT) Subject: bussiness python Message-ID: <78c8019d-3160-4573-b32c-b5a4fdafa13f@googlegroups.com> Here's a code that I have, i'm getting an error in line 5 and i'm not sure why, # future value of annuity p = 1000 r = 2/100 n = 5 FV= p * ((1+r) ** n - 1/r) print(FV) #FV of annuity- continuous compounding CF= 1000 r = 6/100/12 t = 12 import math FV= CF * ((1 + (r/n)) ** (n*t)) print (FV) #Annuity (FV)- solve for n import math FV= 19600 r = 5/100 p = 1000 n = math.log(1 + FV*r / p) / math.log(1+r) print(n) # annuity payments PV= 100000 # how much r = 5/100 # interest rate n = 10 #how many years p = r * (PV) / ((1 + r) ** n - 1) print(p) a = [1,2,3] # a list is just like an array, a list is mutable ( the objects can change) b = a # b is pointing at the same list as a print (type (a), id(a)) print (type(b), id(b)) the output is supposed to be 5204.0401600000005 12336.416801016496 14.000708059400562 12350.45749654566 From marko at pacujo.net Tue Sep 5 18:04:17 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 06 Sep 2017 01:04:17 +0300 Subject: A question on modification of a list via a function invocation References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> Message-ID: <878ths3iqm.fsf@elektro.pacujo.net> Chris Angelico : > That shows that the Java '==' operator is like the Python 'is' > operator, and checks for object identity. You haven't manipulated > pointers at all. In contrast, here's a C program that actually > MANIPULATES pointers: > > [...] > > You can't do this with Python, since pointer arithmetic fundamentally > doesn't exist. You can in C. Can you in Java? You can't do it in Pascal, either, but Pascal definitely has pointers. Pointer arithmetics is not an essential part of C. One could argue that it was a mistake to include it in the language. Marko From grant.b.edwards at gmail.com Tue Sep 5 18:29:45 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 5 Sep 2017 22:29:45 +0000 (UTC) Subject: A question on modification of a list via a function invocation References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> <878ths3iqm.fsf@elektro.pacujo.net> Message-ID: On 2017-09-05, Marko Rauhamaa wrote: > Pointer arithmetics is not an essential part of C. One could argue that > it was a mistake to include it in the language. One may argue that it was a mistake, but I remember at least one implementation where pointer arithmetic was hugely more efficient than indexing into arrays. Incrementing a pointer through an array was way, way faster than indexing through the array by incrementing an array subscript. But, that was 25 years ago on an 8-bit CPU where where integer multiplies were expensive. The last time I compare the two methods with a recent GCC on a 32-bit CPU, it generated pretty much the same code either way... -- Grant Edwards grant.b.edwards Yow! Someone in DAYTON, at Ohio is selling USED gmail.com CARPETS to a SERBO-CROATIAN From ben+python at benfinney.id.au Tue Sep 5 18:59:36 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 06 Sep 2017 08:59:36 +1000 Subject: How do I find what kind of exception is thrown. References: <8f8365fe-c50a-44f0-f4b2-c93365327d22@vub.be> Message-ID: <85fuc0bvl3.fsf@benfinney.id.au> Antoon Pardon writes: > Python 2.6.4 on a solaris box. > > I have a program in which all kind of excptions can be thrown and caugth. > The main program is something like below: > > try: > do_stuff > except Exception: > log unexpected trouble You're throwing away the exception object, with the information you need. Instead:: try: do_stuff() except Exception as exc: log_unexpected_trouble(exc) > Now I found the following in the logs: [Errno 131] Connection reset by peer That doesn't have the exception type in it. Probably because you are logging only ?str(exc)?, which returns the exception message. If you *also* want the exception type to be logged, you'll need to get at it. You could use ?"{0.__class__.__name__}: {0}".format(exc)?. > This is a problem I would like to catch earlier however I have no idea > what exception I would have to catch in order to treat this case. Start by logging what exceptions actually occur, complete with their types. Then, when you have more data, decide which ones you need to handle specially and which ones can propagate normally. -- \ ?An idea isn't responsible for the people who believe in it.? | `\ ?Donald Robert Perry Marquis | _o__) | Ben Finney From python at mrabarnett.plus.com Tue Sep 5 20:27:46 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 6 Sep 2017 01:27:46 +0100 Subject: bussiness python In-Reply-To: <78c8019d-3160-4573-b32c-b5a4fdafa13f@googlegroups.com> References: <78c8019d-3160-4573-b32c-b5a4fdafa13f@googlegroups.com> Message-ID: <3a55d0b2-9929-bfb1-e8fd-1f684d8cc68a@mrabarnett.plus.com> On 2017-09-05 22:21, jessicayates59 at gmail.com wrote: > Here's a code that I have, i'm getting an error in line 5 and i'm not sure why, > > > # future value of annuity > p = 1000 > r = 2/100 > n = 5 > FV= p * ((1+r) ** n - 1/r) > print(FV) > [snip] > the output is supposed to be > 5204.0401600000005 [snip] Your formula is wrong. The second closing parenthesis is in the wrong place. That line should be: FV = p * ((1 + r) ** n - 1) / r From timetowalk11 at gmail.com Tue Sep 5 20:40:49 2017 From: timetowalk11 at gmail.com (timetowalk) Date: Tue, 5 Sep 2017 17:40:49 -0700 (PDT) Subject: bussiness python In-Reply-To: References: <78c8019d-3160-4573-b32c-b5a4fdafa13f@googlegroups.com> <3a55d0b2-9929-bfb1-e8fd-1f684d8cc68a@mrabarnett.plus.com> Message-ID: On Tuesday, September 5, 2017 at 8:28:00 PM UTC-4, MRAB wrote: > On 2017-09-05 22:21, jessicayates59 at gmail.com wrote: > > Here's a code that I have, i'm getting an error in line 5 and i'm not sure why, > > > > > > # future value of annuity > > p = 1000 > > r = 2/100 > > n = 5 > > FV= p * ((1+r) ** n - 1/r) > > print(FV) > > > [snip] > > > the output is supposed to be > > 5204.0401600000005 > [snip] > > Your formula is wrong. The second closing parenthesis is in the wrong place. > > That line should be: > > FV = p * ((1 + r) ** n - 1) / r For line #3, r = 2/100 is zero. For line #5, 1/r will cause an exception From steve+python at pearwood.info Tue Sep 5 20:56:54 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Sep 2017 10:56:54 +1000 Subject: Please improve these comprehensions (was meaning of [ ]) References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> <2f43c776-4595-445d-92d5-d20ab68be56a@googlegroups.com> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> Message-ID: <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Sep 2017 12:19 am, Rustom Mody wrote: > And how do you write even the simplest assignment statement without a > (mathematical) expression on the rhs? name = other_name is not a mathematical expression. Its giving something a new name. name = obj.attribute is not a mathematical expression. (That's not a dot product.) > What were Turing, Church, von Neumann, even Knuth by training? Mathematicians > or CS-ists? > > And what are the contributions of Turing, Church, von Neumann, Knuth to CS? Who cares? We're talking about Python, not Computer Science. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Tue Sep 5 21:01:59 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Sep 2017 18:01:59 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: <878ths3iqm.fsf@elektro.pacujo.net> References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> <878ths3iqm.fsf@elektro.pacujo.net> Message-ID: <595154cc-7d85-4ff1-8f34-8ea0bde5dc8f@googlegroups.com> On Wednesday, September 6, 2017 at 3:34:41 AM UTC+5:30, Marko Rauhamaa wrote: > Chris Angelico : > > > That shows that the Java '==' operator is like the Python 'is' > > operator, and checks for object identity. You haven't manipulated > > pointers at all. In contrast, here's a C program that actually > > MANIPULATES pointers: > > > > [...] > > > > You can't do this with Python, since pointer arithmetic fundamentally > > doesn't exist. You can in C. Can you in Java? > > You can't do it in Pascal, either, but Pascal definitely has pointers. > > Pointer arithmetics is not an essential part of C. One could argue that > it was a mistake to include it in the language. This is subjective of course? but still I wonder where you are coming from? You of course know that writing Unix was the genesis and raison d'?tre for C right? And what is an OS but a thin layer of abstraction on top of bare ISP? ie is not a Linux-OS just an x86 hw + some new ?instructions? called system-calls? Which is to say IMHO being able to punch holes into the hi-level-language abstraction seems to be a sine qua non for being suitable as a language for writing OSes. Do you think its reasonable/feasible to do that without easy access to all the machine resources eg memory, IO, interrupts etc accessible in the OS-writing language? [BTW I think Microsoft has done a better job than classic C of repeating this with C# ? C# is almost as high-level as python, lisp etc and as low (or lower) than C; ie it is effectively two languages, called ?safe? and ?unsafe? parts ] From python at mrabarnett.plus.com Tue Sep 5 21:03:42 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 6 Sep 2017 02:03:42 +0100 Subject: bussiness python In-Reply-To: References: <78c8019d-3160-4573-b32c-b5a4fdafa13f@googlegroups.com> <3a55d0b2-9929-bfb1-e8fd-1f684d8cc68a@mrabarnett.plus.com> Message-ID: On 2017-09-06 01:40, timetowalk wrote: > On Tuesday, September 5, 2017 at 8:28:00 PM UTC-4, MRAB wrote: >> On 2017-09-05 22:21, jessicayates59 at gmail.com wrote: >> > Here's a code that I have, i'm getting an error in line 5 and i'm not sure why, >> > >> > >> > # future value of annuity >> > p = 1000 >> > r = 2/100 >> > n = 5 >> > FV= p * ((1+r) ** n - 1/r) >> > print(FV) >> > >> [snip] >> >> > the output is supposed to be >> > 5204.0401600000005 >> [snip] >> >> Your formula is wrong. The second closing parenthesis is in the wrong place. >> >> That line should be: >> >> FV = p * ((1 + r) ** n - 1) / r > > > > For line #3, r = 2/100 is zero. > For line #5, 1/r will cause an exception > The error wasn't specified. The print lines have parentheses, which is suggestive of Python 3. If it was Python 2, those lines probably wouldn't have the parentheses. From steve+python at pearwood.info Tue Sep 5 21:11:07 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Sep 2017 11:11:07 +1000 Subject: Case-insensitive string equality References: <59a7b652$0$2920$c3e8da3$76491128@news.astraweb.com> <20170831102929.556bf28e@bigbox.christie.dr> <59a95f17$0$1586$c3e8da3$5496439d@news.astraweb.com> <59a9fbe3$0$1605$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59af4b2c$0$16743$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Sep 2017 12:27 am, Grant Edwards wrote: > On 2017-09-03, Gregory Ewing wrote: >> Stefan Ram wrote: >>> But of >>> course, actually the rules of orthography require "Ma?e" or >>> "Masse" and do not allow "MASSE" or "MASZE", just as in >>> English, "English" has to be written "English" and not >>> "english" or "ENGLISH". >> >> While "english" is wrong in English, there's no rule >> against using "ENGLISH" as an all-caps version. > > Perhaps there's no "rule" in your book of rules, but it's almost > universally considered bad style and you will lose points with your > teacher, editor, etc. And yet editors frequently use ALL CAPS for book titles and sometimes even chapter headings, as well as the author's name. I have a shelf full of books by STEPHEN KING behind me. Likewise for movie titles on DVDs, album titles on CDs, address labels (I'm looking at a letter addressed to MR S DAPRANO right now), labels on food and medication. The late and much-lamented English humourist Sir Terry Pratchett wrote almost forty books including the character of Death, who SPEAKS IN CAPITALS. (And his superior, Azrael, does the same in letters almost the size of the entire page. Fortunately he says only a single word in the entire series.) Many government forms and databases require all caps, presumably because it is easier for handwriting recognition, or maybe its just a left over from the days of type writers. > On the inter-tubes generally indicates you're shouting, or just a > kook. I guess if either of those is true, then it's good style. It is true that in general we don't write ordinary prose in all caps, there are plenty of non-kook uses for it. But speaking of capitals on the Internet: HI EVERYBODY!!!!!!!!!! try pressing the the Caps Lock key O THANKS!!! ITS SO MUCH EASIER TO WRITE NOW!!!!!!! fuck me http://bash.org/?835030 -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Tue Sep 5 21:28:02 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Sep 2017 18:28:02 -0700 (PDT) Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> <2f43c776-4595-445d-92d5-d20ab68be56a@googlegroups.com> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wednesday, September 6, 2017 at 6:27:24 AM UTC+5:30, Steve D'Aprano wrote: > On Wed, 6 Sep 2017 12:19 am, Rustom Mody wrote: > > > And how do you write even the simplest assignment statement without a > > (mathematical) expression on the rhs? > > name = other_name > > is not a mathematical expression. Its giving something a new name. > > name = obj.attribute > > is not a mathematical expression. (That's not a dot product.) > Ok you win (that) [And I see your stocks of straw are overflowing. Wholesale prices?] > > > > What were Turing, Church, von Neumann, even Knuth by training? Mathematicians > > or CS-ists? > > > > And what are the contributions of Turing, Church, von Neumann, Knuth to CS? > > Who cares? We're talking about Python, not Computer Science. He who forgets history is doomed to repeat it. Start with your own statement: ?Lisp is a functional language? And see the history a little bit more http://blog.languager.org/2015/04/cs-history-1.html 1960 : McCarthy got the idea of functional programming from an earlier invention of a certain Backus called 'The Formula Translator' which would later shorten to ForTran 1980s: The functional programming community was decrying lisp: "Success of lisp set back the development of functional programming by 10 years" And most significant: ?McCarthy did not consider Lisp to be a functional language? Of course nothing to be surprised here: You know more java than old java-heads And more lisp than John McCarthy ? From ben+python at benfinney.id.au Tue Sep 5 21:53:17 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 06 Sep 2017 11:53:17 +1000 Subject: Please improve these comprehensions (was meaning of [ ]) References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> Message-ID: <8560cwbnjm.fsf@benfinney.id.au> ram at zedat.fu-berlin.de (Stefan Ram) writes: > In mathematics, every author is free to give his own > definitions to concepts and create his own notation. In one trivial sense that is true. Anyone can define any term to mean whatever they like. This is a perfectly sherbert thing to do. In a more useful sense: No, that is not true. The freedom to redefine terms to mean whatever one likes, is constrained by the inherent barrier that poses to clear communication. Authors are not free to give personal definition to concepts, because the transmission of those definitions is not free. The other parties in the communication are not empty vessels waiting for the thoughts of the author. Or, in other words: For established terms in the field, an author has freedom to redefine those terms only to the extent that the author discards clear communication with those who already use the established meanings. > >Who cares? We're talking about Python, not Computer Science. > > Yes. To this I agree! I try not to be the first poster who mentions > C++, Java, or mathematics in a thread. But sometimes I can't resist > to answer when someone else mentions these topics. The ?=? symbol in Python is well established, with a meaning that is *not* a declaration of equality. Using the ?=? in a forum to discuss the Python language, is not a mention of ? nor an invitation to invoke ? mathematics, nor C++, nor Java. -- \ ?If nothing changes, everything will remain the same.? ?Barne's | `\ Law | _o__) | Ben Finney From rustompmody at gmail.com Tue Sep 5 22:07:32 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Sep 2017 19:07:32 -0700 (PDT) Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> <2f43c776-4595-445d-92d5-d20ab68be56a@googlegroups.com> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> Message-ID: <4f514dc5-5568-4783-9f5f-7473a6424f5b@googlegroups.com> On Wednesday, September 6, 2017 at 6:58:29 AM UTC+5:30, Rustom Mody wrote: > On Wednesday, September 6, 2017 at 6:27:24 AM UTC+5:30, Steve D'Aprano wrote: > > On Wed, 6 Sep 2017 12:19 am, Rustom Mody wrote: > > > What were Turing, Church, von Neumann, even Knuth by training? Mathematicians > > > or CS-ists? > > > > > > And what are the contributions of Turing, Church, von Neumann, Knuth to CS? > > > > Who cares? We're talking about Python, not Computer Science. > Of course nothing to be surprised here: You know more java than old java-heads > And more lisp than John McCarthy ? Also noteworthy here: You know more about list comprehensions than their inventor ? Greg Ewing [No I normally would not call Greg their inventor but in this case following through your logic that python exists in a historical, contextual vacuum] From no.email at nospam.invalid Tue Sep 5 22:21:21 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 05 Sep 2017 19:21:21 -0700 Subject: How do I find what kind of exception is thrown. References: <8f8365fe-c50a-44f0-f4b2-c93365327d22@vub.be> Message-ID: <87r2vklg7y.fsf@nightsong.com> Antoon Pardon writes: > Now I found the following in the logs: [Errno 131] Connection reset by peer > This is a problem I would like to catch earlier I'd expect that's an IOError thrown by the socket library. You could just let it go uncaught and see what you get in the crash dump. From rantingrickjohnson at gmail.com Tue Sep 5 22:48:24 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 5 Sep 2017 19:48:24 -0700 (PDT) Subject: Run Windows commands from Python console In-Reply-To: References: <83ebc433-d457-408b-b43a-4b00a3206728@googlegroups.com> <290ec6d2-81d9-4bf4-b641-fc8568578555@googlegroups.com> Message-ID: <7515e893-b1c7-42ff-926d-e482e1eca9ae@googlegroups.com> Terry Reedy wrote: > Rick Johnson wrote: [...] > > When i'm away from an editor (like IDLE, for instance), > > one of the features i miss most is the ability to right > > click the line of the exception message (you know, the one > > that includes the offending line number and offending > > script filepath), and choose "open script for editing" > > from a contextual menu, which will open the script and > > automatically scroll down to the offending line for me. > > Ahhh, efficient bliss. > > 'Goto file/line' also works on the grep/find-in-files > Output Window. I must have used this about 30 times in 8 > outputs tonight try to track down bugs in a proposed IDLE > patch. There were no tracebacks, just thinkgs not working. Yes, the find-in-files feature gets a lot of usage from me as well, when i'm "IDLE'ing" ;-) > I plan to make it a bit faster by moving the option to the > top of the menu. Speaking of "end-user interface customizations"... one feature that i have yet to find, in any modern GUI, is the ability to move menu commands around at mere whim. I find that many times, devs don't put enough thought into these things. Another menuing feature that might be helpful, is a "recent commands" listing, that will list a handful of the most recently used commands, and keep them handy for quick access. One of the nice (current) features of Tkinter menus (that i sometimes miss on my windows box!) is the ability to "tear- off" a menu cascade and use it as a sort of "pseudo tool bar". Of course, the tear-off feature may be limited, as you are confined to dealing with textual commands, as opposed to space-saving icons, but for those who have an aversion to Rachmaninoff-style key chording, a helpful feature nonetheless! > I have thought about making it even faster by not having to > use the context menu -- just click, or maybe double click, > and the jump happens. What do you think? I think that would be a great idea for the find-in-files output window, since after all, it is a single purpose tool. I myself have a stand-alone grep tool with a "double click to edit" event bound, and i do find the click (one step) to be far more efficient than a contextual menu (two steps). Since, when you open a contextual menu, there is that moment of distraction while you search for the correct command. However, i'm not sure if dynamic mouse events in IDLE's pyshell (aka: "REPL window") are a good idea, as an accidental click in an exception dump would cause surprise windows to pop up, and could be confusing to noobs. What is your opinion on this? Additionally, in the find-in-files window, it might be helpful to also add a short message (using a tk.Label perhaps?) above the "output area" (which i assume is a tk.Text?), informing the user to "Double-click a path to edit with IDLE" -- or something informative like that. From steve+python at pearwood.info Tue Sep 5 22:51:48 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Sep 2017 12:51:48 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59af62c5$0$16756$b1db1813$d948b532@news.astraweb.com> On Tue, 5 Sep 2017 11:11 pm, Gregory Ewing wrote: > Steve D'Aprano wrote: >> The third entity is the reference linking the name to the object (the arrow). >> This isn't a runtime value in Python, nor is it a compile time entity that >> exists in source code. It is pure implementation, and as such, exists outside >> of the Python domain. > > The fact that there is a connection between the name and the > object is very much part of Python's abstract semantics. > > There are different ways to implement that connection, but > *any* implementation of Python has to include *some* > representation of it. Any *what* of Python? Oh, that's right, you said any *implementation* of Python. Isn't that what I said? That references are a property of the implementation, not of the language. You are inadvertently agreeing with me. - You can't bind a reference to a name in Python. Names are always bound to objects. - You can't have a list or set of references, only lists or sets of objects. - You can't form a reference to a reference. - You can't use references to implement pass-by-reference semantics. - You can't view or inspect references in Python (maybe in ctypes, or in a debugger, but those aren't part of the Python language, they are implementation-specific interfaces to the interpreter). So in what sense are references part of the Python language? My answer is that they are not. They're a part of the implementation, which makes them different from values (ints, floats, strings, lists, and other objects, whether built-in or not). It makes them different from other conceptual entities in Python like for-loops, comprehensions, try...except blocks etc, which aren't values but they are properties of the program (at least of the source code, if not the byte code). > There are also different words that can be used to describe > it. You can say that names are bound to objects, or that > names refer to objects, or that names hold references to > objects. As they used to say in Sesame Street, "One of these things is not like the others..." The first two describe a *relationship* between two entities, the name and the object: being bound to, referring to, are verbs which indicate a relationship. The third introduces a third entity. There's now two relationships: - names hold (are bound to, point to) references; - references refer to (are bound to, point to) objects. That's an example of reification, "making real", taking an abstract concept or relationship or verb and treating it as a thing. We often do that in poetic language: we talk of death or hunger stalking the streets. In this case, its a bit more complicated because *in a sense* you are right. Inside the interpreter, there really is a data structure which we might call a reference: in CPython its a pointer. So you are not entirely being poetic here. Inside the interpreter, you (probably?) could print out the value of the pointer, or manipulate it in some fashion. But at the level of Python code, you are reifying a relationship into a thing. In Python code, names are bound to objects, and the implementation of that binding is not part of the language itself. References aren't things, any more than fatherhood or treason are things (they are states of being that describe a certain relationships). That's because Python describes a virtual machine which is abstracted further away from the machine than C. Part of that abstraction is to remove pointers (references) from the set of values available to Python code to manipulate. > These are all equally good ways of talking about > the exact same abstract concept. No they aren't equally good, not if they lead to confusion and terminology abuse. Earlier I linked to a Stackoverflow question about Java, asking how to find the address of variables. It must be easy, right, because Java variables hold pointers to some address. (Actually, no they don't.) In Python, we still have people asking from time to time how to dereference pointers (references), or how to pass an int by reference, or a list by value (making a copy). It must be possible, because Python is pass-by-value for some values and pass-by-reference for others, right? (No.) I'm not opposed to the "reference" concept in general. I just want people to be more clear about what level of abstraction you are talking about when you use it. I don't want people to say that Python (the language) has references or pointers, because it doesn't. I don't have any objection to people saying that the interpreter has references or pointers, and that's how name binding works behind the scenes, or under the hood. And I categorically *hate* explanations of Python's argument parsing that require people to simultaneously believe that the value of x following x=1 is: 1 (the meaning of "value" they actually use in practice), and: some invisible, unknown, unknowable, implementation-dependent reference to the actual value (the meaning they insist they believe in, purely so that they can justify their abuse of terminology). > To me this argument about whether Python has references > or not is like an American person saying that cars have > hoods, and a British person saying he's wrong, hoods > are an implementation detail and cars actually have > bonnets instead. No, this isn't a mere argument about the name we give a thing. It is an argument about: - the level of abstraction in which we talk; - in any specific level of abstraction, what counts as a thing or not; - the importance of not misleading people by inappropriate or careless mixing of entities from different abstractions. I don't care whether you want to call it a reference or a pointer or a woozle, so long as your explanation is clear that it exists in the interpreter's implementation, not in the Python language. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Tue Sep 5 23:51:45 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 13:51:45 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59af62c5$0$16756$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 6, 2017 at 1:42 PM, Stefan Ram wrote: > Steve D'Aprano writes: >>So in what sense are references part of the Python language? > > It would be possible to describe Python using a concept > called "reference", it's just that the The Python Language > Reference, Release 3.6.0 (PRL) does /not/ do this. > And programming language experts usually use the terms that > the language specification uses with the meaning that the > language specification is giving them. And this is why I say > that JavaScript and Python do not have references. > (Except "attribute references".) > >>Inside the interpreter, you (probably?) could print out the value of the >>pointer, or manipulate it in some fashion. > > Well, this /is/ from the PRL: > > ?An object's identity never changes once it has been created; > you may think of it as the object's address in memory.?. > ?????????????????????????????? > - The Python Language Reference, Release 3.6.0; > 3.1 Objects, values and types > > It's not called "reference", it's called "identity". But it > might agree with your idea of a pointer of an implementation. > And you /can/ print it. > >>>> print( id( 'abc' )) > 4163144 Printing out an address is only half the point (pun intended) of a pointer - and the useless half. Given a pointer, you need to be able to dereference it. How can you, given the id of a Python object, access the object itself? The nearest I've ever seen is a function that searches every object it can find, looking for one with the same id. I *might* be able to accept the argument that pointer arithmetic isn't important (though I'm still of the opinion that without arithmetic, they're just references/name bindings), but if you want to say that the id() of a Python object is its pointer, you MUST demonstrate this more basic feature. ChrisA From rustompmody at gmail.com Wed Sep 6 00:17:30 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Sep 2017 21:17:30 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59af62c5$0$16756$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wednesday, September 6, 2017 at 9:22:15 AM UTC+5:30, Chris Angelico wrote: > On Wed, Sep 6, 2017 at 1:42 PM, Stefan Ram wrote: > > Steve D'Aprano writes: > >>So in what sense are references part of the Python language? > > > > It would be possible to describe Python using a concept > > called "reference", it's just that the The Python Language > > Reference, Release 3.6.0 (PRL) does /not/ do this. > > And programming language experts usually use the terms that > > the language specification uses with the meaning that the > > language specification is giving them. And this is why I say > > that JavaScript and Python do not have references. > > (Except "attribute references".) > > > >>Inside the interpreter, you (probably?) could print out the value of the > >>pointer, or manipulate it in some fashion. > > > > Well, this /is/ from the PRL: > > > > ?An object's identity never changes once it has been created; > > you may think of it as the object's address in memory.?. > > ?????????????????????????????? > > - The Python Language Reference, Release 3.6.0; > > 3.1 Objects, values and types > > > > It's not called "reference", it's called "identity". But it > > might agree with your idea of a pointer of an implementation. > > And you /can/ print it. > > > >>>> print( id( 'abc' )) > > 4163144 > > Printing out an address is only half the point (pun intended) of a > pointer - and the useless half. Given a pointer, you need to be able > to dereference it. How can you, given the id of a Python object, > access the object itself? The nearest I've ever seen is a function > that searches every object it can find, looking for one with the same > id. Well ? the point of pointers may be printing them out ? which even in a language with 1st class pointers like C is rarely done/needed Another ? is dereferencing, pointer-arithmetic etc... the various manifestations of 1st-class pointers And the third ? is to provide explanations to people asking authentic questions [like the OP of this thread] Sure you can say with Steven that this can be 'explained' by saying an object can be in two places at one time. Others would then say 'Humpty-dumpty!' since you have removed the most basic intuition of objects and you are in effect saying that a python object means what you ordain it means without further ado/explanation Since you believe a reference-less dictionary can be a model for such explanations, why not provide that? From rosuav at gmail.com Wed Sep 6 00:24:40 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 14:24:40 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59af62c5$0$16756$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 6, 2017 at 2:17 PM, Rustom Mody wrote: > Well ? the point of pointers may be printing them out ? which even in a language > with 1st class pointers like C is rarely done/needed But still the useless part. You don't actually *achieve* anything by printing out the pointer. > Another ? is dereferencing, pointer-arithmetic etc... the various manifestations > of 1st-class pointers This is the part that matters. > And the third ? is to provide explanations to people asking authentic questions > [like the OP of this thread] Only questions that actually relate to one of the previous parts. > Sure you can say with Steven that this can be 'explained' by saying an object > can be in two places at one time. > Others would then say 'Humpty-dumpty!' since you have removed the most basic > intuition of objects and you are in effect saying that a python object > means what you ordain it means without further ado/explanation > > Since you believe a reference-less dictionary can be a model for such explanations, > why not provide that? A piece of paper works just fine. However, it's hard to use that method of explanation in an email. ChrisA From rustompmody at gmail.com Wed Sep 6 00:37:15 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 5 Sep 2017 21:37:15 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59af62c5$0$16756$b1db1813$d948b532@news.astraweb.com> Message-ID: <0415df30-2233-4ef3-b17e-0cde1369a710@googlegroups.com> On Wednesday, September 6, 2017 at 9:55:10 AM UTC+5:30, Chris Angelico wrote: > On Wed, Sep 6, 2017 at 2:17 PM, Rustom Mody wrote: > > Well ? the point of pointers may be printing them out ? which even in a language > > with 1st class pointers like C is rarely done/needed > > But still the useless part. You don't actually *achieve* anything by > printing out the pointer. > > > Another ? is dereferencing, pointer-arithmetic etc... the various manifestations > > of 1st-class pointers > > This is the part that matters. > > > And the third ? is to provide explanations to people asking authentic questions > > [like the OP of this thread] > > Only questions that actually relate to one of the previous parts. [dangling pointer ???? ] > > > Sure you can say with Steven that this can be 'explained' by saying an object > > can be in two places at one time. > > Others would then say 'Humpty-dumpty!' since you have removed the most basic > > intuition of objects and you are in effect saying that a python object > > means what you ordain it means without further ado/explanation > > > > Since you believe a reference-less dictionary can be a model for such explanations, > > why not provide that? > > A piece of paper works just fine. However, it's hard to use that > method of explanation in an email. I am ready to bet that if ASCII is insufficient then you are drawing pictures You can call them whatever you like - pointers, references - data structure diagrams - graphs vertices, edges - I think I'll call them Antoon-art in honor of Antoon Pardon who has the patience to draw them I believe it was Marko Rauhamaa who have another half dozen metaphors: - doggies and pussies er.. sorry leashes Whatever you use, you will have to reify in your explanation the idea of pointer/graph-edge/etc even and especially because, the language disallows such a reification From steve+comp.lang.python at pearwood.info Wed Sep 6 01:41:19 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2017 05:41:19 GMT Subject: Please improve these comprehensions (was meaning of [ ]) References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> <2f43c776-4595-445d-92d5-d20ab68be56a@googlegroups.com> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> Message-ID: <59af8a7f$0$16632$b1db1813$d948b532@news.astraweb.com> On Tue, 05 Sep 2017 18:28:02 -0700, Rustom Mody wrote: > On Wednesday, September 6, 2017 at 6:27:24 AM UTC+5:30, Steve D'Aprano > wrote: >> On Wed, 6 Sep 2017 12:19 am, Rustom Mody wrote: >> >> > And how do you write even the simplest assignment statement without a >> > (mathematical) expression on the rhs? >> >> name = other_name >> >> is not a mathematical expression. Its giving something a new name. >> >> name = obj.attribute >> >> is not a mathematical expression. (That's not a dot product.) >> >> > Ok you win (that) > [And I see your stocks of straw are overflowing. Wholesale prices?] A strawman fallacy is not another way of saying "Dammit, you just made a counter-argument that I cannot argue against." On the other hand, false accusations of "strawman" are a form of poisoning the well. As the old legal saying goes: "When the facts are on your side, argue the facts. When the law is on your side, argue the law. When neither are on your side, pound the table." And when you can't pound the table, accuse your opponent of committing the strawman fallacy. >> > What were Turing, Church, von Neumann, even Knuth by training? >> > Mathematicians or CS-ists? >> > >> > And what are the contributions of Turing, Church, von Neumann, Knuth >> > to CS? >> >> Who cares? We're talking about Python, not Computer Science. > > He who forgets history is doomed to repeat it. I don't forget history, I just know when it is relevant and when it isn't. Rustom, I don't care if you want to compare Python to mathematics. We already know the conclusion: Python is not mathematically pure. That doesn't make it wrong. In fact, I would argue the opposite: by knowing when to bend, or break, mathematical purity in favour of more accessible idioms, Python is a better language for the majority of people. > Start with your own statement: ?Lisp is a functional language? [...] > And most significant: ?McCarthy did not consider Lisp to be a functional > language? I didn't say it was a *pure* functional language, or a *good* one. > Of course nothing to be surprised here: You know more java than old > java-heads And more lisp than John McCarthy ? Attacking the man, instead of the argument. Is that the best you've got? If you're going to cast aspersions on my character, do it properly: I'm an arrogant, ignorant boob who dares to questions the Great Ones who clearly are infallible and cannot make a mistake. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From steve+comp.lang.python at pearwood.info Wed Sep 6 01:45:23 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2017 05:45:23 GMT Subject: Please improve these comprehensions (was meaning of [ ]) References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> Message-ID: <59af8b72$0$16632$b1db1813$d948b532@news.astraweb.com> On Wed, 06 Sep 2017 01:31:56 +0000, Stefan Ram wrote: > Steve D'Aprano writes: >>On Wed, 6 Sep 2017 12:19 am, Rustom Mody wrote: >>>And how do you write even the simplest assignment statement without a >>>(mathematical) expression on the rhs? >>name = other_name is not a mathematical expression. Its giving something >>a new name. > > In mathematics, every author is free to give his own definitions to > concepts and create his own notation. [...] > Of course, definitions of the form > > x := 2 y := x Indeed they do. Perhaps I should have said that the Python assignment name = other_name is not *necessarily* a mathematical expression, but can also be used to give an object a new name. We can argue whether mathematics has assignment at all, or merely has definitions. That's a level of hair-splitting where I'm happy to sit on the fence and not give an opinion as to whether the mathematical definition: y = 2 is or is not the same as the Python assignment: y = 2 -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From steve+comp.lang.python at pearwood.info Wed Sep 6 01:51:35 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2017 05:51:35 GMT Subject: Please improve these comprehensions (was meaning of [ ]) References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> <2f43c776-4595-445d-92d5-d20ab68be56a@googlegroups.com> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> <4f514dc5-5568-4783-9f5f-7473a6424f5b@googlegroups.com> Message-ID: <59af8ce6$0$16632$b1db1813$d948b532@news.astraweb.com> On Tue, 05 Sep 2017 19:07:32 -0700, Rustom Mody wrote: > Also noteworthy here: You know more about list comprehensions than their > inventor ? Greg Ewing And many people know more about General Relativity than Albert Einstein. What's your point? > [No I normally would not call Greg their inventor You shouldn't, because he didn't invent them. They existed in Haskell, which is where Greg learned about them, and even Haskell did not invent them. In fact, Greg merely *proposed* that they be added to Python. He didn't write the PEP that specified their behaviour, and the PEP specifies behaviour which Greg does not approve of. Namely that comprehensions are *explicitly* intended as semantically equivalent to a for-loop, plus accumulator. Greg may have been the first to propose comprehensions in Python, but that doesn't give him any special insight into their behaviour, and it certainly doesn't make him their inventor. > but in this case following through your logic that python exists in a > historical, contextual vacuum] I never said that. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From marko at pacujo.net Wed Sep 6 01:54:55 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 06 Sep 2017 08:54:55 +0300 Subject: A question on modification of a list via a function invocation References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> <878ths3iqm.fsf@elektro.pacujo.net> <595154cc-7d85-4ff1-8f34-8ea0bde5dc8f@googlegroups.com> Message-ID: <878ths1ids.fsf@elektro.pacujo.net> Rustom Mody : > On Wednesday, September 6, 2017 at 3:34:41 AM UTC+5:30, Marko Rauhamaa wrote: >> Pointer arithmetics is not an essential part of C. One could argue that >> it was a mistake to include it in the language. > > This is subjective of course? but still I wonder where you are coming from? > > You of course know that writing Unix was the genesis and raison d'?tre > for C right? > > And what is an OS but a thin layer of abstraction on top of bare ISP? > ie is not a Linux-OS just an x86 hw + some new ?instructions? called > system-calls? BASIC doesn't have any pointers at all, but it has PEEK and POKE. Marko From steve+comp.lang.python at pearwood.info Wed Sep 6 02:02:11 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2017 06:02:11 GMT Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59af62c5$0$16756$b1db1813$d948b532@news.astraweb.com> Message-ID: <59af8f63$0$16632$b1db1813$d948b532@news.astraweb.com> On Wed, 06 Sep 2017 03:42:31 +0000, Stefan Ram wrote: > Well, this /is/ from the PRL: > > ?An object's identity never changes once it has been created; > you may think of it as the object's address in memory.?. > ?????????????????????????????? > - The Python Language Reference, Release 3.6.0; > 3.1 Objects, values and types > > It's not called "reference", it's called "identity". But it might > agree with your idea of a pointer of an implementation. > And you /can/ print it. > >>>> print( id( 'abc' )) > 4163144 I just tried that in my handy Python interpreter: steve at runes:~$ jython Jython 2.5.3 (, Jun 21 2017, 18:05:17) [OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_151 Type "help", "copyright", "credits" or "license" for more information. >>> print id("abcd") 2 >>> print id("abcd") 3 >>> print id(None) 4 Do they look like pointers or references to you? They don't to me. I'm not aware of any machine where pointers can point to odd numbers (although there probably are some) and I'm certainly not aware of any where consecutive pointers differ by 1. I think the manual is badly worded. It is true that we *can* think of IDs as the address of objects in memory, we *shouldn't* because that's misleading and tempts the reader to draw the wrong conclusion. IDs in Python are arbitrary integers. They have no meaning except to be distinct for any two objects existing at the same time. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From steve+comp.lang.python at pearwood.info Wed Sep 6 02:21:10 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2017 06:21:10 GMT Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59af62c5$0$16756$b1db1813$d948b532@news.astraweb.com> Message-ID: <59af93d5$0$16632$b1db1813$d948b532@news.astraweb.com> On Tue, 05 Sep 2017 21:17:30 -0700, Rustom Mody wrote: > Sure you can say with Steven that this can be 'explained' by saying an > object can be in two places at one time. > Others would then say 'Humpty-dumpty!' since you have removed the most > basic intuition of objects and you are in effect saying that a python > object means what you ordain it means without further ado/explanation I have previously agreed that the "multiple places at once" metaphor is not to everyone's liking. But many (perhaps even most) people have no problem dealing with location as a metaphor, where being in two places (metaphorically) is no problem at all: - I am in love, in trouble and in denial all at once. Even when the location is not a state of being but an actual physical place, we can be in multiple places at once: - I am in my home, in Melbourne, and in Australia all at once. Being in two places at once is a common trope in both fantasy and science fiction (often involving time travel). These are not niche genres: they are *extremely* popular. One of the Harry Potter movies involved Harry, Ron and Hermoine travelling backwards in time a few minutes to watch themselves. It's a moderately common trope in stories like Doctor Who, where the Doctor frequently interacts with his past (or future) self. I recently saw an episode of Dark Matter that used the trope. Robert Heinlein, one of the greats of SF, wrote a number of classic time travel stories involving people being in multiple places at once. (In one of them, the protagonist has a sex change and becomes *both* his own grandfather and grandmother.) An object being inside itself is rarer, but its been done at least twice that I know of in Doctor Who. Don't underestimate people's ability to stretch the location metaphor beyond actual physical location. We do it all the time for virtual locations like IRC channels: - I'm in #python, #ruby and #javascript all at once. But if the metaphor isn't for you, I'm not saying you have to use it. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From steve+comp.lang.python at pearwood.info Wed Sep 6 02:30:37 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 06 Sep 2017 06:30:37 GMT Subject: A question on modification of a list via a function invocation References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> <878ths3iqm.fsf@elektro.pacujo.net> Message-ID: <59af960c$0$16632$b1db1813$d948b532@news.astraweb.com> On Wed, 06 Sep 2017 01:04:17 +0300, Marko Rauhamaa wrote: > Chris Angelico : > >> That shows that the Java '==' operator is like the Python 'is' >> operator, and checks for object identity. You haven't manipulated >> pointers at all. In contrast, here's a C program that actually >> MANIPULATES pointers: >> >> [...] >> >> You can't do this with Python, since pointer arithmetic fundamentally >> doesn't exist. You can in C. Can you in Java? A necessary (but not sufficient) condition to be able to do pointer arithmetic is to actually have pointers as a data type. Pointers are not a data type in either Python or Java, so of course you can't do pointer arithmetic on them. If you don't have a pointer, you can't do arithmetic on it. Pointer arithmetic itself is not the issue. Java could have been like standard Pascal, and allow pointers as a first class data type (you can assign them to variables, pass them to functions, return them, have pointers to pointers, etc) without allowing pointer arithmetic. But they didn't -- Java the language doesn't include pointers as a value at all. > You can't do it in Pascal, either, but Pascal definitely has pointers. Not in standard Pascal, but most actual Pascal compilers let you perform pointer arithmetic. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From antoon.pardon at vub.be Wed Sep 6 03:12:37 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 6 Sep 2017 09:12:37 +0200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5e1d04de-c509-babd-5123-eebfaabf1ab9@vub.be> Op 04-09-17 om 17:43 schreef Steve D'Aprano: > On Tue, 5 Sep 2017 01:17 am, Rustom Mody wrote: > >> Anton gave a picture explaining why/how references are needed and to be >> understood > Antoon gave a picture demonstrating one model of Python's semantics. > > It's a nice model that has a lot going for it, in particular that it matches the > most obvious implementation. But it doesn't describe *Python* semantics, it > describes an overlap between Python the language and the implementation of the > Python interpreter. > > In particular, consider the picture of a name binding to a value: > > > +-----+ > | | > | 5 | > | | > +-----+ > ^ > | > > > > This picture has three entities, but only two of them exist in Python: > > - the object 5; > > - the name "x" (names are not values in Python at runtime, but they > are entities which exist in Python source code at compile time). > > The third entity is the reference linking the name to the object (the arrow). > This isn't a runtime value in Python, nor is it a compile time entity that > exists in source code. It is pure implementation, and as such, exists outside > of the Python domain. > > I'm not saying that we should never use this model. Its a good model. But we > should be clear that it is a model of the implementation, and it describes > entities which are not part of the Python language. We cannot do this: > > > +-----+ > | | > | 5 | > | | > +-----+ > ^ > | > > ^ > | > > > > or any of the other things we can do in a language with references-as-values, > like C or Pascal. I don't agree that the above is an accurate picture of C or Pascal. It is more like the following: +-----+ +-----+ | | | | | 5 |<----+--* | | | | | +-----+ +-----+ ^ ^ | | And in case of a VAR parameter in Pascal like procedure f(VAR x); f(y) one could use the following, which is the same as after an assignment in python. +-----+ | | | 7 | ---> | | / +-----+ / / ^ / | -- Antoon Pardon From greg.ewing at canterbury.ac.nz Wed Sep 6 03:21:08 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Sep 2017 19:21:08 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: Rustom Mody wrote: > 2. is ? machine representation, too fine to be useful Disagree - "is" in Python has an abstract definition that doesn't depend on machine representation. -- Greg From marko at pacujo.net Wed Sep 6 03:37:42 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 06 Sep 2017 10:37:42 +0300 Subject: Please improve these comprehensions (was meaning of [ ]) References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> <8560cwbnjm.fsf@benfinney.id.au> Message-ID: <8760cwnupl.fsf@elektro.pacujo.net> Ben Finney : > ram at zedat.fu-berlin.de (Stefan Ram) writes: > >> In mathematics, every author is free to give his own definitions to >> concepts and create his own notation. > > [...] > > For established terms in the field, an author has freedom to redefine > those terms only to the extent that the author discards clear > communication with those who already use the established meanings. In mathematics, it is quite common to define even established terms. First, that's done because slight terminology variants are in use so definitions are necessary for clear communication. Secondly, commonly used symbols are taken into new uses. For example, Boolean algebra "hijacks" + so that 1 + 1 = 1. Which reminds me of this puzzle I saw a couple of days ago: 1 + 4 = 5 2 + 5 = 12 3 + 6 = 21 8 + 11 = ? A mathematician immediately comes up with a "wrong" answer. Marko From anthra.norell at bluewin.ch Wed Sep 6 04:14:18 2017 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Wed, 6 Sep 2017 10:14:18 +0200 Subject: execfile and import not working Message-ID: Hi, I am setting up Python 2.7 after an upgrade to Ubuntu 16.04, a thorough one, leaving no survivors. Everything is fine, IDLE opens, ready to go. Alas, execfile and import commands don't do my bidding, but hang IDLE. All I can do is kill the process named "python" from a bash terminal. IDLE then is still open, says "=== RESTART: Shell ===" and is again ready for action. It works interactively, but no imports . . . What could be the problem? Thanks for ideas Frederic From viktorovichandrej at gmail.com Wed Sep 6 04:30:29 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Wed, 6 Sep 2017 01:30:29 -0700 (PDT) Subject: cant't use package internals Message-ID: Hello, I have Python package tst in my workspace. tst has files: __init__.py tst.py content of __init__.py: print("importing Tst") content of tst.py: class Tst: def __init__(self): print("init Tst") I run python console in workspace directory. I do >>>import tst Run without errors. I was expected "importing Tst" to be printed, but nothing happened. Why? I run t=tst.tst.Tst() and got error: Traceback (most recent call last): File "", line 1, in AttributeError: module 'tst' has no attribute 'tst' Wh it not finds Tst class? From __peter__ at web.de Wed Sep 6 04:52:12 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Sep 2017 10:52:12 +0200 Subject: execfile and import not working References: Message-ID: Friedrich Rentsch wrote: > Hi, I am setting up Python 2.7 after an upgrade to Ubuntu 16.04, a > thorough one, leaving no survivors. Everything is fine, IDLE opens, > ready to go. Alas, execfile and import commands don't do my bidding, but > hang IDLE. All I can do is kill the process named "python" from a bash > terminal. IDLE then is still open, says "=== RESTART: Shell ===" and is > again ready for action. It works interactively, but no imports . . . > What could be the problem? Close idle completely (or kill the idle process), then start it from the command line, with an empty PYTHONPATH variable and from an empty directory. $ killall idle idle: no process found $ mkdir empty $ cd empty $ PYTHONPATH= idle Does the problem persist? From greg.ewing at canterbury.ac.nz Wed Sep 6 04:52:13 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Sep 2017 20:52:13 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59aed8c3$0$16757$b1db1813$d948b532@news.astraweb.com> References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59acc15a$0$1614$c3e8da3$5496439d@news.astraweb.com> <59ad592c$0$1593$c3e8da3$5496439d@news.astraweb.com> <59aed8c3$0$16757$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > No, they aren't first-class. Maybe not fully, but you can do a lot more with them than you can in Pascal or Modula-2. > - Containers of references are not allowed. You can't have arrays of references, but struct and class members can be references, so you can certainly build data structures that contain them. (A quick experiment suggests that you can even have arrays of structs that contain references, so I'm not sure why they're not allowed in arrays directly.) > - Once a reference to an object is created, it cannot be changed to > reference another object ("to be reseated"). Actually there is a way to do that, but you have to be sneaky about it. Greg From tjol at tjol.eu Wed Sep 6 04:55:20 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 6 Sep 2017 10:55:20 +0200 Subject: execfile and import not working In-Reply-To: References: Message-ID: <4cd61e9e-db5b-f76e-ced1-3feaee126617@tjol.eu> On 2017-09-06 10:14, Friedrich Rentsch wrote: > Hi, I am setting up Python 2.7 after an upgrade to Ubuntu 16.04, a > thorough one, leaving no survivors. Everything is fine, IDLE opens, > ready to go. Alas, execfile and import commands don't do my bidding, but > hang IDLE. All I can do is kill the process named "python" from a bash > terminal. IDLE then is still open, says "=== RESTART: Shell ===" and is > again ready for action. It works interactively, but no imports . . . > What could be the problem? Some debugging ideas: - Do imports work if you start "python" from the terminal, rather than using IDLE? If not, is there an error message? - If python (in the terminal) hangs, and you press Ctrl+C, what happens? - If you start idle from the terminal and do what you've been doing so far, are there any error messages? - What if you kill idle instead of python? -- Thomas Jollans From greg.ewing at canterbury.ac.nz Wed Sep 6 05:01:34 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Sep 2017 21:01:34 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> Message-ID: Chris Angelico wrote: > You can't do this with Python, since pointer arithmetic fundamentally > doesn't exist. Pointer arithmetic doesn't exist in Pascal either, yet Pascal most definitely has pointers as a distinct data type. Insisting that only pointer arithmetic counts as "manipulating" pointers seems a strange way of defining the word. -- Greg From __peter__ at web.de Wed Sep 6 05:12:34 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Sep 2017 11:12:34 +0200 Subject: cant't use package internals References: Message-ID: Andrej Viktorovich wrote: > Hello, > > I have Python package tst in my workspace. > > tst has files: > __init__.py > tst.py > > > content of __init__.py: > print("importing Tst") > > > content of tst.py: > class Tst: > def __init__(self): > print("init Tst") > > > I run python console in workspace directory. I do >>>>import tst > Run without errors. I was expected "importing Tst" to be printed, but > nothing happened. Why? You may have a second tst.py, e. g. in your working directory, that is found first and thus shadows the tst package. A variant of that explanation would be that the tst folder is your working directory and you are importing the tst submodule directly instead as part of a package. In the interactive interpreter you can use the tst.__file__ attribute to find out what is actually going on. To make things a bit clearer I recommend that you give package and submodule different names, at least while you are experimenting. > I run > t=tst.tst.Tst() > > and got error: > > Traceback (most recent call last): > File "", line 1, in > AttributeError: module 'tst' has no attribute 'tst' > > Wh it not finds Tst class? Submodules of a package are not imported automatically. You need import tst.tst t = tst.tst.Tst() From rustompmody at gmail.com Wed Sep 6 05:13:44 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 6 Sep 2017 02:13:44 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, September 6, 2017 at 12:51:25 PM UTC+5:30, Gregory Ewing wrote: > Rustom Mody wrote: > > 2. is ? machine representation, too fine to be useful > > Disagree - "is" in Python has an abstract definition that > doesn't depend on machine representation. > > -- > Greg There is this (AFAIAC sophistry) in the docs describing the data model https://docs.python.org/3/reference/datamodel.html | Every object has an identity, a type and a value. An object?s identity never | changes once it has been created; you may think of it as the object?s address | in memory. The ?is? operator compares the identity of two objects; the id() | function returns an integer representing its identity. | CPython implementation detail: For CPython, id(x) is the memory address where | x is stored. Can you explain what "id" and "is" without talking of memory? In fact we have got so used to the term 'memory' that it actually seems strange when someone like Dijkstra grumbles at the anthropomorphism and asks why its not called 'store'. From rosuav at gmail.com Wed Sep 6 05:20:10 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 19:20:10 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 6, 2017 at 7:01 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> You can't do this with Python, since pointer arithmetic fundamentally >> doesn't exist. > > > Pointer arithmetic doesn't exist in Pascal either, yet > Pascal most definitely has pointers as a distinct data > type. > > Insisting that only pointer arithmetic counts as > "manipulating" pointers seems a strange way of defining > the word. Understood. I'm withdrawing the assertion that pointer arithmetic is essential, weakening the demand to the ability to: 1) Take the address of an object (yielding a pointer) 2) Move the pointer around as its own thing, eg pass it as a function parameter 3) Dereference the pointer, to read or write the original object But you have to be able to prove that #2 is actually looking at the pointer as its own entity. This has to be distinct from passing around the object itself in some way. ChrisA From kryptxy at protonmail.com Wed Sep 6 05:30:59 2017 From: kryptxy at protonmail.com (Kryptxy) Date: Wed, 06 Sep 2017 05:30:59 -0400 Subject: Using __init__.py Message-ID: <3FFRsp2jZ-lKnj2CdGZvAshKWRgfoaVWfMd1hTt0zOyFh2ez6e-g0IG7VUMvXzSryW1hL_8ByT2hDLKoJajt-Y__HhsbYsflTlp8UgNFDcg=@protonmail.com> I am working on a (cross-platform) project. On linux system, the imprts work fine, but in windows I get imort error (I have no idea why. I tried searching everywhere, but couldn't get it to work). Anyways, the issue seem to be resolved by adding project directory to sys.path(). I wanted to know that can I use __init__.py file for adding a project directory to sys.path (sys.path.insert(0, directory))? From rosuav at gmail.com Wed Sep 6 05:33:03 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 19:33:03 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Sep 6, 2017 at 7:13 PM, Rustom Mody wrote: > On Wednesday, September 6, 2017 at 12:51:25 PM UTC+5:30, Gregory Ewing wrote: >> Rustom Mody wrote: >> > 2. is ? machine representation, too fine to be useful >> >> Disagree - "is" in Python has an abstract definition that >> doesn't depend on machine representation. >> >> -- >> Greg > > There is this (AFAIAC sophistry) in the docs describing the data model > https://docs.python.org/3/reference/datamodel.html > > | Every object has an identity, a type and a value. An object?s identity never > | changes once it has been created; you may think of it as the object?s address > | in memory. The ?is? operator compares the identity of two objects; the id() > | function returns an integer representing its identity. > > | CPython implementation detail: For CPython, id(x) is the memory address where > | x is stored. > > Can you explain what "id" and "is" without talking of memory? Yes, easily. Just delete the "CPython implementation detail" section and the "you may think of it" part from that quote and let the rest stand alone. None of the rest of that document depends on memory addresses. ChrisA From dvl at psu.edu Wed Sep 6 05:59:25 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Wed, 6 Sep 2017 05:59:25 -0400 Subject: A question on modification of a list via a function invocation In-Reply-To: mailman.1111.1504662834.2732.python-list@python.org References: Message-ID: <1504691965l.28442624l.0l@psu.edu> On 5 Sep 2017 14:28:44, wlfraed at ix.netcom.com (Dennis Lee Bier) wrote: > On 5 Sep 2017 17:57:18 GMT, ram at zedat.fu-berlin.de (Stefan Ram) > declaimed the following: >> But what does "a C++ reference" refer to? >> > Per Stroustrup (The C++ Programming Language 4th Ed, page 189) > """ > * ...> * A reference always refers to the object to which it was initialized. > * ... > A reference is an alternative name for an object, an alias. ... > """ > {Hmmm, and I see that the syntax can be used outside of parameter > declaration -- which is the only place I'd seen it previously... either > this is a change from earlier standards, or my classes just didn't feel the > need to expose a non-parameter reference -- since, based upon the above > book, you can not declare a bare reference "variable"; it MUST be > initialized with a real object.} I think I can say something about this, having been a teacherof the classes you refer to. I intentionally avoided reference variables. IMO, the 'good' use for declaring a new reference variable (i.e. not parameter)would be when (1) the object to which you refer to is time-consuming to access(2) you plan to refer to this object more then once, and don't want to repeatthat time-consuming process, and (3) you really want a reference, and not a copy. The first two years of programming courses really do not have a purposethat meets all three, so can "didn't feel the need" is probably applicable. I intentionally avoided them because reference variables simply compoundthe problem of aliasing, so unless you really limit your reference variableto a very tight sandbox, you could be causing more headache than you save. I do admit to occasionally defining a method that returned a reference,such as one that overloads the [] operator. But even so, I would generallybe reluctant to giving an outside client a direct access to my database'sinternal structures. (Thank you Python for separating __getitem__ and __setitem__) Python doesn't eliminate aliasing, of course, since most assignment operationscreate aliases. But at least it's nice to know that aliasing immutable valuesis harmless. Hence my unit on building recursive data structures entirelyout of tuples. Roger ChristmanPennsylvania Sate University From anthra.norell at bluewin.ch Wed Sep 6 06:28:56 2017 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Wed, 6 Sep 2017 12:28:56 +0200 Subject: execfile and import not working In-Reply-To: References: Message-ID: <8e621877-9910-b5ec-6c04-85ae017c8dbf@bluewin.ch> On 06.09.2017 10:52, Peter Otten wrote: > Friedrich Rentsch wrote: > >> Hi, I am setting up Python 2.7 after an upgrade to Ubuntu 16.04, a >> thorough one, leaving no survivors. Everything is fine, IDLE opens, >> ready to go. Alas, execfile and import commands don't do my bidding, but >> hang IDLE. All I can do is kill the process named "python" from a bash >> terminal. IDLE then is still open, says "=== RESTART: Shell ===" and is >> again ready for action. It works interactively, but no imports . . . >> What could be the problem? > Close idle completely (or kill the idle process), then start it from the > command line, with an empty PYTHONPATH variable and from an empty directory. > > $ killall idle > idle: no process found > $ mkdir empty > $ cd empty > $ PYTHONPATH= idle > > Does the problem persist? > No, it doesn't. It's okay this way. Can you advise me how to set up the launcher? Frederic From rhodri at kynesim.co.uk Wed Sep 6 06:45:52 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 6 Sep 2017 11:45:52 +0100 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> <878ths3iqm.fsf@elektro.pacujo.net> Message-ID: <8683e247-8d01-74e3-968b-27bec3135f67@kynesim.co.uk> On 05/09/17 23:29, Grant Edwards wrote: > On 2017-09-05, Marko Rauhamaa wrote: > >> Pointer arithmetics is not an essential part of C. One could argue that >> it was a mistake to include it in the language. > One may argue that it was a mistake, but I remember at least one > implementation where pointer arithmetic was hugely more efficient than > indexing into arrays. Incrementing a pointer through an array was > way, way faster than indexing through the array by incrementing an > array subscript. > > But, that was 25 years ago on an 8-bit CPU where where integer > multiplies were expensive. The last time I compare the two methods > with a recent GCC on a 32-bit CPU, it generated pretty much the same > code either way... That's the optimiser at work, turning what you wrote into the best fit to the processor architecture. On an ARM, for example, that would likely still be incrementing a pointer through an array. -- Rhodri James *-* Kynesim Ltd From greg.ewing at canterbury.ac.nz Wed Sep 6 06:49:08 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Sep 2017 22:49:08 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59af93d5$0$16632$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59af62c5$0$16756$b1db1813$d948b532@news.astraweb.com> <59af93d5$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > But many (perhaps even most) people have no problem dealing with location > as a metaphor, where being in two places (metaphorically) is no problem > at all: > > - I am in love, in trouble and in denial all at once. Sometimes the word "in" implies physical location, sometimes it doesn't. Being a member of more than one list is a familiar enough concept, for example, although one would probably say "on a list" rather than "in a list". However, "on a list" doesn't really conjure up an image of physical location. We wouldn't picture ourselves standing on a piece of paper; rather, we would imagine our name or other piece of identifying information being written on the paper. Dare I say... we would think of a *reference* to us being on the list? :-) > > Even when the location is not a state of being but an actual physical > place, we can be in multiple places at once: > > - I am in my home, in Melbourne, and in Australia all at once. That's only non-weird because there is a nesting relationship between those locations. It doesn't extend to more general topologies. For example, if your home is in Melbourne, then being in your home and Australia but *not* in Melbourne would be an interesting trick. > > Being in two places at once is a common trope in both fantasy and science > fiction (often involving time travel). And they're interesting plot devices precisely because they defy our physical intuition so much. If you're trying to deconfuse someone about Python semantics, tying their brain up in knots doesn't seem like a very productive approach! -- Greg From greg.ewing at canterbury.ac.nz Wed Sep 6 06:56:06 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Sep 2017 22:56:06 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59af960c$0$16632$b1db1813$d948b532@news.astraweb.com> References: <89e6cacb-90f1-e6dc-7376-56aadcda607b@nedbatchelder.com> <59ae10b4$0$1604$c3e8da3$5496439d@news.astraweb.com> <59aef64a$0$16753$b1db1813$d948b532@news.astraweb.com> <878ths3iqm.fsf@elektro.pacujo.net> <59af960c$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Not in standard Pascal, but most actual Pascal compilers let you perform > pointer arithmetic. Well, sort of. In the ones I've seen, it's more like being able to cast a pointer to an integer, do arithmetic on that and then cast it back. The results are about as implementation-dependent as that suggests. C, on the other hand, allows arithmetic operations on pointers directly and defines their semantics (up to a point, you can fall off into undefined territory fairly easily). -- Greg From greg.ewing at canterbury.ac.nz Wed Sep 6 06:59:37 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 06 Sep 2017 22:59:37 +1200 Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: <878thtuved.fsf@bsb.me.uk> References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> Message-ID: Seems to me you're making life difficult for yourself (and very inefficient) by insisting on doing the whole computation with sets. If you want a set as a result, it's easy enough to construct one from the list at the end. -- Greg From anthra.norell at bluewin.ch Wed Sep 6 07:04:02 2017 From: anthra.norell at bluewin.ch (Friedrich Rentsch) Date: Wed, 6 Sep 2017 13:04:02 +0200 Subject: execfile and import not working In-Reply-To: <4cd61e9e-db5b-f76e-ced1-3feaee126617@tjol.eu> References: <4cd61e9e-db5b-f76e-ced1-3feaee126617@tjol.eu> Message-ID: <888052b1-e278-997a-6dbf-e38e748c92b2@bluewin.ch> On 06.09.2017 10:55, Thomas Jollans wrote: > On 2017-09-06 10:14, Friedrich Rentsch wrote: >> Hi, I am setting up Python 2.7 after an upgrade to Ubuntu 16.04, a >> thorough one, leaving no survivors. Everything is fine, IDLE opens, >> ready to go. Alas, execfile and import commands don't do my bidding, but >> hang IDLE. All I can do is kill the process named "python" from a bash >> terminal. IDLE then is still open, says "=== RESTART: Shell ===" and is >> again ready for action. It works interactively, but no imports . . . >> What could be the problem? > Some debugging ideas: > > - Do imports work if you start "python" from the terminal, rather than > using IDLE? If not, is there an error message? > - If python (in the terminal) hangs, and you press Ctrl+C, what happens? > - If you start idle from the terminal and do what you've been doing so > far, are there any error messages? > - What if you kill idle instead of python? > > It works now! Even from the launcher. Looks like the new installation sets PYTHONPATH to something wrong. I set it to nothing on Peter's advice and that may have cured the problem. I didn't read the setting before I erased it. So I don't know what it was. Next I'll have to find out which configuration file needs to be edited. Thank you all for your help Frederic From steve+python at pearwood.info Wed Sep 6 07:37:54 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Sep 2017 21:37:54 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Sep 2017 07:13 pm, Rustom Mody wrote: > Can you explain what "id" and "is" without talking of memory? Yes. id() returns an abstract ID number which is guaranteed to be an integer, and guaranteed to be distinct for all objects which exist at the same time. When an object ceases to exist, its ID number may be re-used. `is` compares the two operands for identity. If the two operands are the same object, `is` returns True, if they are distinct objects, `is` returns False. > In fact we have got so used to the term 'memory' that it actually seems > strange when someone like Dijkstra grumbles at the anthropomorphism and asks > why its not called 'store'. And if it were called "store" (grocery store? shoe store? clothes store?) Dijkstra would have grumbled at the metaphor and asked why it wasn't called "memory". -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 6 07:42:00 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Sep 2017 21:42:00 +1000 Subject: Using __init__.py References: <3FFRsp2jZ-lKnj2CdGZvAshKWRgfoaVWfMd1hTt0zOyFh2ez6e-g0IG7VUMvXzSryW1hL_8ByT2hDLKoJajt-Y__HhsbYsflTlp8UgNFDcg=@protonmail.com> Message-ID: <59afdf0a$0$16729$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Sep 2017 07:30 pm, Kryptxy wrote: > I am working on a (cross-platform) project. On linux system, the imprts work > fine, but in windows I get imort error (I have no idea why. I tried searching > everywhere, but couldn't get it to work). Anyways, the issue seem to be > resolved by adding project directory to sys.path(). > > I wanted to know that can I use __init__.py file for adding a project > directory to sys.path (sys.path.insert(0, directory))? That is the wrong way to fix this problem. It might work, for a little while, but then something will change, or you will do something just a tiny bit different, and it will break again. The first step is to debug why you are getting the import error. You cannot fix a problem until you know what it is: what you fix by accident will break by accident. Start by telling us the full path to your project directory, and the full contents of sys.path. Do not try to retype them from memory. Accuracy is essential: copy and paste the paths so that they are accurate. Thank you. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From __peter__ at web.de Wed Sep 6 07:54:31 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 06 Sep 2017 13:54:31 +0200 Subject: execfile and import not working References: <8e621877-9910-b5ec-6c04-85ae017c8dbf@bluewin.ch> Message-ID: Friedrich Rentsch wrote: > > > On 06.09.2017 10:52, Peter Otten wrote: >> Friedrich Rentsch wrote: >> >>> Hi, I am setting up Python 2.7 after an upgrade to Ubuntu 16.04, a >>> thorough one, leaving no survivors. Everything is fine, IDLE opens, >>> ready to go. Alas, execfile and import commands don't do my bidding, but >>> hang IDLE. All I can do is kill the process named "python" from a bash >>> terminal. IDLE then is still open, says "=== RESTART: Shell ===" and is >>> again ready for action. It works interactively, but no imports . . . >>> What could be the problem? >> Close idle completely (or kill the idle process), then start it from the >> command line, with an empty PYTHONPATH variable and from an empty >> directory. >> >> $ killall idle >> idle: no process found >> $ mkdir empty >> $ cd empty >> $ PYTHONPATH= idle >> >> Does the problem persist? >> > No, it doesn't. It's okay this way. Can you advise me how to set up the > launcher? There may be a module in your system path that shades one of the modules needed by idle. When you start idle with the GUI the working directory is probably your home directory. (If you can import os use os.getcwd() to verify) This is just guessing, but the first thing I'd try is to remove all Python files from that directory (and also the *.pyc/*.pyo). From rustompmody at gmail.com Wed Sep 6 08:00:47 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 6 Sep 2017 05:00:47 -0700 (PDT) Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> Message-ID: <23f65d1e-6fa5-463c-9e6f-9818fd0f2fd8@googlegroups.com> On Wednesday, September 6, 2017 at 4:29:56 PM UTC+5:30, Gregory Ewing wrote: > Seems to me you're making life difficult for yourself (and > very inefficient) by insisting on doing the whole computation > with sets. If you want a set as a result, it's easy enough > to construct one from the list at the end. Sure with programmer hat firmly on that is the sensible view. But there are equally legitimate other hats to consider: Learning combinatorics for example. And from that point of view Python (or Haskell or whatever) should be mostly irrelevant. Whereas what should be relevant is what SICP calls ?procedural epistemology?: https://mitpress.mit.edu/sicp/front/node3.html | Underlying our approach to this subject is our conviction that "computer | science" is not a science and that its significance has little to do with | computers. The computer revolution is a revolution in the way we think and in | the way we express what we think. The essence of this change is the emergence | of what might best be called procedural epistemology ? the study of the | structure of knowledge from an imperative point of view, as opposed to the | more declarative point of view taken by classical mathematical subjects. | Mathematics provides a framework for dealing precisely with notions of "what | is." Computation provides a framework for dealing precisely with notions of | "how to." Coming to the details in this case, the important difference between permutations and combinations is not the numbers nPr and nCr but that a permutation is a list and a combination is a set. So this definition of permutations is fine (almost): def perms(l): if not l: return [[]] x, xs = l[0], l[1:] return [p[:i] + [x] + p[i:] for p in perms(xs) for i in range(0,len(l))] >>> perms([1,2,3]) [[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]] Because the abstract idea of a permutation is a list (sequence) And the implementation here is faithful to that [The outer being a list is a mild annoyance... We can let it pass] However in this: def c(n,r): if r == 0: return [[]] elif len(n) == 0: return [] else: return [[n[0]] + l for l in c(n[1:],r-1)] + c(n[1:],r) the [n[0]] + l is misguidingly overspecific, ie it suggests an order which has no relevance or connection to the problem. Note that *as a programmer* this may be fine >From the pov of studying math, its wrong Now if you want to agree with Chris in saying that python is unsuitable for doing math, that's fine. [I am tending to agree myself] I posted it because I genuinely thought I had missed some obvious way of splitting a set into an (arbitrary) element and a rest without jumping through hoops. Evidently not From rustompmody at gmail.com Wed Sep 6 08:11:57 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 6 Sep 2017 05:11:57 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> Message-ID: <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> On Wednesday, September 6, 2017 at 5:08:20 PM UTC+5:30, Steve D'Aprano wrote: > On Wed, 6 Sep 2017 07:13 pm, Rustom Mody wrote: > > > > Can you explain what "id" and "is" without talking of memory? > > Yes. > > id() returns an abstract ID number which is guaranteed to be an integer, and > guaranteed to be distinct for all objects which exist at the same time. When an > object ceases to exist, its ID number may be re-used. > > `is` compares the two operands for identity. If the two operands are the same > object, `is` returns True, if they are distinct objects, `is` returns False. >>> a = (1,2) >>> b = (1,2) >>> a is b False >>> x = 1 >>> y = 1 >>> x is y True a seems to be as 'same' to b as x is to y Python seems to think otherwise Evidently your ?same? is not the same as mine?? > > > In fact we have got so used to the term 'memory' that it actually seems > > strange when someone like Dijkstra grumbles at the anthropomorphism and asks > > why its not called 'store'. > > And if it were called "store" (grocery store? shoe store? clothes store?) > Dijkstra would have grumbled at the metaphor and asked why it wasn't > called "memory". Memory is an old (middle-English) word. Until say 1945 it could be used in sentences like the following ?I have memories of walking in the woods with my dad? ?Where are the eggs?? ?Oops! Totally slipped my memory? Sorry" ?The Dalai Lama has memories of his past lives? Are you using ?memory? in this kind of way? From rosuav at gmail.com Wed Sep 6 08:18:13 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 22:18:13 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> Message-ID: On Wed, Sep 6, 2017 at 10:11 PM, Rustom Mody wrote: > On Wednesday, September 6, 2017 at 5:08:20 PM UTC+5:30, Steve D'Aprano wrote: >> On Wed, 6 Sep 2017 07:13 pm, Rustom Mody wrote: >> >> >> > Can you explain what "id" and "is" without talking of memory? >> >> Yes. >> >> id() returns an abstract ID number which is guaranteed to be an integer, and >> guaranteed to be distinct for all objects which exist at the same time. When an >> object ceases to exist, its ID number may be re-used. >> >> `is` compares the two operands for identity. If the two operands are the same >> object, `is` returns True, if they are distinct objects, `is` returns False. > >>>> a = (1,2) >>>> b = (1,2) >>>> a is b > False >>>> x = 1 >>>> y = 1 >>>> x is y > True > > a seems to be as 'same' to b as x is to y > Python seems to think otherwise > > Evidently your ?same? is not the same as mine?? *facepalm* I got nothing to say to you. Have you been on this list all this time and still don't understand that Python sometimes optimizes immutables? ChrisA From rustompmody at gmail.com Wed Sep 6 08:25:43 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 6 Sep 2017 05:25:43 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504691965l.28442624l.0l@psu.edu> Message-ID: On Wednesday, September 6, 2017 at 4:03:40 PM UTC+5:30, ROGER GRAYDON CHRISTMAN wrote: > On 5 Sep 2017 14:28:44, (Dennis Lee Bier) wrote: > > On 5 Sep 2017 17:57:18 GMT, > >> But what does "a C++ reference" refer to? > >> > > > Per Stroustrup (The C++ Programming Language 4th Ed, page 189) > > > """ > > * ...> * A reference always refers to the object to which it was initialized. > > * ... > > > A reference is an alternative name for an object, an alias. ... > > """ > > > {Hmmm, and I see that the syntax can be used outside of parameter > > declaration -- which is the only place I'd seen it previously... either > > this is a change from earlier standards, or my classes just didn't feel the > > need to expose a non-parameter reference -- since, based upon the above > > book, you can not declare a bare reference "variable"; it MUST be > > initialized with a real object.} > > I think I can say something about this, having been a teacherof the classes you refer to. I intentionally avoided reference variables. > IMO, the 'good' use for declaring a new reference variable (i.e. not parameter)would be when (1) the object to which you refer to is time-consuming to access(2) you plan to refer to this object more then once, and don't want to repeatthat time-consuming process, and (3) you really want a reference, and not a copy. > The first two years of programming courses really do not have a purposethat meets all three, so can "didn't feel the need" is probably applicable. > I intentionally avoided them because reference variables simply compoundthe problem of aliasing, so unless you really limit your reference variableto a very tight sandbox, you could be causing more headache than you save. > I do admit to occasionally defining a method that returned a reference,such as one that overloads the [] operator. But even so, I would generallybe reluctant to giving an outside client a direct access to my database'sinternal structures. (Thank you Python for separating __getitem__ and __setitem__) > Python doesn't eliminate aliasing, of course, since most assignment operationscreate aliases. But at least it's nice to know that aliasing immutable valuesis harmless. Hence my unit on building recursive data structures entirelyout of tuples. The realization that immutability is a significant virtue is now beginning to percolate mainstream programming Ive seen it in recent C# books as a definite recommendation? Something like - Use value types - Use getters but no setters And you have a good design Python makes this hard by giving less status to immutable types than mutable ones - set comprehensions exist not frozenset comprehensions - Likewise tuples and lists From nopsidy at gmail.com Wed Sep 6 08:28:28 2017 From: nopsidy at gmail.com (nopsidy) Date: Wed, 6 Sep 2017 19:28:28 +0700 Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> <23f65d1e-6fa5-463c-9e6f-9818fd0f2fd8@googlegroups.com> Message-ID: https://www.youtube.com/watch?v=pNe1wWeaHOU&list=PLYI8318YYdkCsZ7dsYV01n6TZhXA6Wf9i&index=1 Thank you, -Alex Goretoy http://launchpad.net/~a1g On Wed, Sep 6, 2017 at 7:22 PM, Stefan Ram wrote: > Rustom Mody writes: >>Because the abstract idea of a permutation is a list (sequence) > > Traditional mathematical books (which are not influenced by > computer programming terminology) often use "n-tuple" > (or "sequence") instead of "list" IIRC. > > It is important to note that - according to me - a Python > data structure with the same /name/ as a mathematical concept > does not always have to be the best way to implement that > mathematical concept. E.g., sometimes a Python list might be > the best way to implement a mathematical tuple, or a Python > tuple may be the best way to implement a mathematical set. > > -- > https://mail.python.org/mailman/listinfo/python-list From nopsidy at gmail.com Wed Sep 6 08:28:46 2017 From: nopsidy at gmail.com (nopsidy) Date: Wed, 6 Sep 2017 19:28:46 +0700 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> Message-ID: https://www.youtube.com/watch?v=pNe1wWeaHOU&list=PLYI8318YYdkCsZ7dsYV01n6TZhXA6Wf9i&index=1 Thank you, -Alex Goretoy http://launchpad.net/~a1g On Wed, Sep 6, 2017 at 7:18 PM, Chris Angelico wrote: > On Wed, Sep 6, 2017 at 10:11 PM, Rustom Mody wrote: >> On Wednesday, September 6, 2017 at 5:08:20 PM UTC+5:30, Steve D'Aprano wrote: >>> On Wed, 6 Sep 2017 07:13 pm, Rustom Mody wrote: >>> >>> >>> > Can you explain what "id" and "is" without talking of memory? >>> >>> Yes. >>> >>> id() returns an abstract ID number which is guaranteed to be an integer, and >>> guaranteed to be distinct for all objects which exist at the same time. When an >>> object ceases to exist, its ID number may be re-used. >>> >>> `is` compares the two operands for identity. If the two operands are the same >>> object, `is` returns True, if they are distinct objects, `is` returns False. >> >>>>> a = (1,2) >>>>> b = (1,2) >>>>> a is b >> False >>>>> x = 1 >>>>> y = 1 >>>>> x is y >> True >> >> a seems to be as 'same' to b as x is to y >> Python seems to think otherwise >> >> Evidently your ?same? is not the same as mine?? > > *facepalm* > > I got nothing to say to you. Have you been on this list all this time > and still don't understand that Python sometimes optimizes immutables? > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From nopsidy at gmail.com Wed Sep 6 08:31:05 2017 From: nopsidy at gmail.com (nopsidy) Date: Wed, 6 Sep 2017 19:31:05 +0700 Subject: execfile and import not working In-Reply-To: References: Message-ID: https://www.youtube.com/watch?v=pNe1wWeaHOU&list=PLYI8318YYdkCsZ7dsYV01n6TZhXA6Wf9i&index=1 On Wed, Sep 6, 2017 at 6:57 PM, Stefan Ram wrote: > Friedrich Rentsch writes: >>ready to go. Alas, execfile and import commands don't do my bidding, but >>hang IDLE. All I can do is kill the process named "python" from a bash > > AFAIK ?exefile( 'myscr.py' )? is > > exec( compile( open( 'myscr.py', 'rb' ).read(), 'myscr.py', 'exec' )) > > (at least, that line is reported to work in Python 3). > Now you can do each step in isolation (untested): > > a = open( 'myscr.py', 'rb' ) > b = a.read() > c = compile( b, 'myscr.py', 'exec' ) > d = exec( c ) > > to find the step where it hangs. Then maybe you can do this > analysis recursively with this step until you have found the > exact elementary statement or expression where it hangs. > > -- > https://mail.python.org/mailman/listinfo/python-list From nopsidy at gmail.com Wed Sep 6 08:32:28 2017 From: nopsidy at gmail.com (nopsidy) Date: Wed, 6 Sep 2017 19:32:28 +0700 Subject: Using __init__.py In-Reply-To: <59afdf0a$0$16729$b1db1813$d948b532@news.astraweb.com> References: <3FFRsp2jZ-lKnj2CdGZvAshKWRgfoaVWfMd1hTt0zOyFh2ez6e-g0IG7VUMvXzSryW1hL_8ByT2hDLKoJajt-Y__HhsbYsflTlp8UgNFDcg=@protonmail.com> <59afdf0a$0$16729$b1db1813$d948b532@news.astraweb.com> Message-ID: https://www.youtube.com/watch?v=pNe1wWeaHOU&list=PLYI8318YYdkCsZ7dsYV01n6TZhXA6Wf9i&index=1 Thank you, -Alex Goretoy http://launchpad.net/~a1g On Wed, Sep 6, 2017 at 6:42 PM, Steve D'Aprano wrote: > On Wed, 6 Sep 2017 07:30 pm, Kryptxy wrote: > >> I am working on a (cross-platform) project. On linux system, the imprts work >> fine, but in windows I get imort error (I have no idea why. I tried searching >> everywhere, but couldn't get it to work). Anyways, the issue seem to be >> resolved by adding project directory to sys.path(). >> >> I wanted to know that can I use __init__.py file for adding a project >> directory to sys.path (sys.path.insert(0, directory))? > > That is the wrong way to fix this problem. It might work, for a little while, > but then something will change, or you will do something just a tiny bit > different, and it will break again. > > The first step is to debug why you are getting the import error. You cannot fix > a problem until you know what it is: what you fix by accident will break by > accident. > > Start by telling us the full path to your project directory, and the full > contents of sys.path. > > Do not try to retype them from memory. Accuracy is essential: copy and paste the > paths so that they are accurate. > > > Thank you. > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list From viktorovichandrej at gmail.com Wed Sep 6 08:41:31 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Wed, 6 Sep 2017 05:41:31 -0700 (PDT) Subject: No importlib in Python 3 64 bit ? Message-ID: Hello, I have 32Bit and 64Bit installations on my Windows 10 machine. I do import importlib in both of them. 32bit works fine while 64bit prints error: >>> import importlib Traceback (most recent call last): File "", line 1, in File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\importlib\__init__.py", line 57, in import types File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\types.py", line 171, in import functools as _functools File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\functools.py", line 23, in from weakref import WeakKeyDictionary File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\weakref.py", line 12, in from _weakref import ( ImportError: cannot import name '_remove_dead_weakref' Why and how to solve this problem? From rustompmody at gmail.com Wed Sep 6 08:44:13 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 6 Sep 2017 05:44:13 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> Message-ID: <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> On Wednesday, September 6, 2017 at 5:48:48 PM UTC+5:30, Chris Angelico wrote: > On Wed, Sep 6, 2017 at 10:11 PM, Rustom Mody wrote: > > On Wednesday, September 6, 2017 at 5:08:20 PM UTC+5:30, Steve D'Aprano wrote: > >> On Wed, 6 Sep 2017 07:13 pm, Rustom Mody wrote: > >> > >> > >> > Can you explain what "id" and "is" without talking of memory? > >> > >> Yes. > >> > >> id() returns an abstract ID number which is guaranteed to be an integer, and > >> guaranteed to be distinct for all objects which exist at the same time. When an > >> object ceases to exist, its ID number may be re-used. > >> > >> `is` compares the two operands for identity. If the two operands are the same > >> object, `is` returns True, if they are distinct objects, `is` returns False. > > > >>>> a = (1,2) > >>>> b = (1,2) > >>>> a is b > > False > >>>> x = 1 > >>>> y = 1 > >>>> x is y > > True > > > > a seems to be as 'same' to b as x is to y > > Python seems to think otherwise > > > > Evidently your ?same? is not the same as mine?? > > *facepalm* > > I got nothing to say to you. Have you been on this list all this time > and still don't understand that Python sometimes optimizes immutables? Losing 'memory' of context Chris? Let me erm? remind: I said 'is' refers to "same in machine representation" Greg disagreed: ? "is" in Python has an abstract definition that doesn't depend on machine representation.? I said: In that case please restate the definition of 'is' from the manual which invokes the notion of 'memory' without bringing in memory. Steven gave his explanation by dropping 'memory' and gave a definition Which I showed does not match expected common sense Sure you can bring in the notion (now!) of optimization if you like But you cant have it both ways - 'is' is a fundamental conceptual notion of sameness - 'is' is a machine/implementation specific notion of sameness which changes depending on machine/implementation specific decisions Of course you can have a third hand? Its usually called sophistry The trouble with sophistrizing is that you get caught in your own net: You (and Steven) claim that references (and aliases such as pointers) can be expunged from the language semantics. If you do that the term 'memory' remains standalone without any semantics. And when you make a bogus expulsion of that as well, extant behavior becomes unexplainable? Except with a? (which I share) *facepalm* From rosuav at gmail.com Wed Sep 6 08:57:29 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 22:57:29 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> Message-ID: On Wed, Sep 6, 2017 at 10:44 PM, Rustom Mody wrote: > On Wednesday, September 6, 2017 at 5:48:48 PM UTC+5:30, Chris Angelico wrote: >> On Wed, Sep 6, 2017 at 10:11 PM, Rustom Mody wrote: >> >>>> a = (1,2) >> >>>> b = (1,2) >> >>>> a is b >> > False >> >>>> x = 1 >> >>>> y = 1 >> >>>> x is y >> > True >> > >> > a seems to be as 'same' to b as x is to y >> > Python seems to think otherwise >> > >> > Evidently your ?same? is not the same as mine?? >> >> *facepalm* >> >> I got nothing to say to you. Have you been on this list all this time >> and still don't understand that Python sometimes optimizes immutables? > > Losing 'memory' of context Chris? > Let me erm? remind: > > I said 'is' refers to "same in machine representation" > > Greg disagreed: ? "is" in Python has an abstract definition that > doesn't depend on machine representation.? > > I said: In that case please restate the definition of 'is' from the manual which > invokes the notion of 'memory' without bringing in memory. > > Steven gave his explanation by dropping 'memory' and gave a definition > > Which I showed does not match expected common sense > > Sure you can bring in the notion (now!) of optimization if you like > But you cant have it both ways > - 'is' is a fundamental conceptual notion of sameness > - 'is' is a machine/implementation specific notion of sameness which changes > depending on machine/implementation specific decisions Okay. Lemme spell it out for you real easy. The 'is' operator tests if two things are the same thing. Okay? With me so far? Good. No mention of memory. Next, we have an optimization: Sometimes, Python uses the same object more than once. You can't distinguish one integer 1 from another other than by their ids, so Python is free to use the same integer object for both uses of 1. Clear? Still no mention of memory anywhere. And it doesn't violate any conceptual notion of sameness. ChrisA From steve+python at pearwood.info Wed Sep 6 08:58:59 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 06 Sep 2017 22:58:59 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <5e1d04de-c509-babd-5123-eebfaabf1ab9@vub.be> Message-ID: <59aff115$0$16748$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Sep 2017 05:12 pm, Antoon Pardon wrote: [...] >> I'm not saying that we should never use this model. Its a good model. But we >> should be clear that it is a model of the implementation, and it describes >> entities which are not part of the Python language. We cannot do this: >> >> >> +-----+ >> | | >> | 5 | >> | | >> +-----+ >> ^ >> | >> >> ^ >> | >> >> >> >> or any of the other things we can do in a language with references-as-values, >> like C or Pascal. > > I don't agree that the above is an accurate picture of C or Pascal. I'm surprised. You can do this in Pascal: type intpointer = ^integer; var x: intpointer; y: ^intpointer; begin new(x); {reserve memory in the heap for an integer, and point x at it} x^ := 5; y := @x; {y points to the pointer x} end. which would translate to the diagram above. If you don't like the fact that I'm using the "address of" operator @ which is non-standard Pascal, I can write this instead: type intpointer = ^integer; var y: ^intpointer; begin new(y); {reserve memory in the heap for an intpointer, and point y at it} new(y^); {reserve memory in the heap for an integer, and point y^ at it} y^^ := 5; end. I would be shocked if C were less powerful in this regard than Pascal. > It is more > like the following: > > +-----+ +-----+ > | | | | > | 5 |<----+--* | > | | | | > +-----+ +-----+ > ^ ^ > | | > That would be equivalent to a different piece of code: type intpointer = ^integer; var x: intpointer; y: ^intpointer; begin new(x); {reserve memory in the heap for an integer, and point x at it} x^ := 5; new(y); {reserve memory in the heap for an intpointer, and point y at it} y^ := x; {assignment copies; y^ now points to the same thing as x} end. These two are not the same thing. > And in case of a VAR parameter in Pascal like > > procedure f(VAR x); > f(y) > > one could use the following, which is the same > as after an assignment in python. > > > +-----+ > | | > | 7 | > ---> | | > / +-----+ > / > / ^ > / | > No no no! Pascal VAR parameters are not the same as Python assignment! You cannot write a Pascal swap procedure in Python! Pascal VAR parameters are, in a sense, syntactic sugar for pointer manipulation. (I'm not sure just how far we can take this analogy, but I think its pretty far.) That's probably why C didn't bother with VAR parameters: anything you can do with a VAR parameter, you can do with explicit pointers. I think that these two increment procedures will be (more or less?) equivalent: type intpointer = ^integer; procedure increment(var n: integer); begin n := n + 1 end; procedure increment2(p: intpointer); begin p^ := p^ + 1 end; var a: integer; b: integer; begin a := 99; increment(a); writeln(a); {will print 100} b := 99; increment2(@b); writeln(b); {will print 100} end. If there's a difference, its a subtle one which I haven't found in a short amount of testing. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Wed Sep 6 09:00:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 23:00:48 +1000 Subject: No importlib in Python 3 64 bit ? In-Reply-To: References: Message-ID: On Wed, Sep 6, 2017 at 10:41 PM, Andrej Viktorovich wrote: > Hello, > > I have 32Bit and 64Bit installations on my Windows 10 machine. I do import importlib in both of them. > > 32bit works fine while 64bit prints error: > >>>> import importlib > Traceback (most recent call last): > File "", line 1, in > File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\importlib\__init__.py", line 57, in > import types > File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\types.py", line 171, in > import functools as _functools > File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\functools.py", line 23, in > from weakref import WeakKeyDictionary > File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\weakref.py", line 12, in > from _weakref import ( > ImportError: cannot import name '_remove_dead_weakref' It appears that your 64-bit binary is trying to load up the libraries from the 32-bit installation. How did you go about installing each one? I'm not 100% sure, but I think that having two different versions of CPython X.Y isn't supported on Windows. ChrisA From rustompmody at gmail.com Wed Sep 6 09:08:48 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 6 Sep 2017 06:08:48 -0700 (PDT) Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> <23f65d1e-6fa5-463c-9e6f-9818fd0f2fd8@googlegroups.com> Message-ID: On Wednesday, September 6, 2017 at 5:59:17 PM UTC+5:30, nopsidy wrote: > https://www.youtube.com/watch?v=pNe1wWeaHOU&list=PLYI8318YYdkCsZ7dsYV01n6TZhXA6Wf9i&index=1 > Thank you, > -Alex Goretoy > http://launchpad.net/~a1g You (Alex) are top-posting. I am not fussy. But others here can be In any case thanks for quoting Stefan's post which I would not see otherwise > > > On Wed, Sep 6, 2017 at 7:22 PM, Stefan Ram wrote: > > Rustom Mody writes: > >>Because the abstract idea of a permutation is a list (sequence) > > > > Traditional mathematical books (which are not influenced by > > computer programming terminology) often use "n-tuple" > > (or "sequence") instead of "list" IIRC. > > > > It is important to note that - according to me - a Python > > data structure with the same /name/ as a mathematical concept > > does not always have to be the best way to implement that > > mathematical concept. E.g., sometimes a Python list might be > > the best way to implement a mathematical tuple, or a Python > > tuple may be the best way to implement a mathematical set. I came to the conclusion and said more or less what you are saying Stefan? when programmer hat is on. viz that the simplest solution (all lists) is probably the way to go. I've taught this (with the simple list-solution) many times over decade(s) Then this time I thought: "Hey! Python now has sets. And even set- comprehensions! Maybe the solution could be more sparkling clean if I switch from lists to sets?" However every effort of mine was clumsy and unsatisfactory. So thought of asking if I am missing something? Evidently not - the set data type does not nest ? {1,2} possible {{1,2},{3,4}} not - the frozenset datatype is (pragmatically) incomplete ? no clean way to separate an element from a (frozen)set So all in all too many hoops to jump through [Greg talked of efficiency ? not my primary concern (here)] PS As said I do not see your posts (Stefan) unless someone quotes them From rosuav at gmail.com Wed Sep 6 09:16:36 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Sep 2017 23:16:36 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> Message-ID: On Wed, Sep 6, 2017 at 11:02 PM, Stefan Ram wrote: > Chris Angelico writes: >>The 'is' operator tests if two things are the same thing. > > ?Roughly speaking, to say of two things that they are > identical is nonsense, and to say of one thing that it > is identical with itself is to say nothing at all.? > > Ludwig Wittgenstein, Tractatus Logico-Philosophicus (5.5303) Yes, and the expression "x is x" is indeed saying nothing at all. But it's perfectly reasonable, in English, to make statements like: "Talldad is my father." "This is my box." (It's not purrfect, but it's mine. [1]) "The President of the US is FD Roosevelt." Each one corresponds to a Python statement of identity: print(talldad is self.father) print(self is chii.box) print(usa.president is fdr) In the case of Talldad, one side is absolute and the other side is relative. (Yes, my father is my relative. Whodathunk?) For a given 'self', the statement will always be consistent. In the case of the president of the US, it's an attribute that gets reassigned periodically, so the statement may be true one day and false another. But it's still fully reasonable to have an absolute identifier for a specific person, and to ask if that refers to the same individual as some relative or time-dependent identifier/alias. ChrisA [1] https://www.redbubble.com/people/devicatoutlet/works/27806715-this-is-my-box From viktorovichandrej at gmail.com Wed Sep 6 09:39:56 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Wed, 6 Sep 2017 06:39:56 -0700 (PDT) Subject: No importlib in Python 3 64 bit ? In-Reply-To: References: Message-ID: <5542c8be-cc80-463c-8574-fe580f2cd3fc@googlegroups.com> Found that pythons have different paths. It might be related? 64 bit C:\Users\me\AppData\Local\Programs\Python\Python36-32 C:\Users\me\AppData\Local\Programs\Python\Python36-32\DLLs C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib C:\Program Files\Python36\python36.zip C:\Program Files\Python36\DLLs C:\Program Files\Python36\lib C:\Program Files\Python36 C:\Program Files\Python36\lib\site-packages 32bit C:\Users\me\AppData\Local\Programs\Python\Python36-32 C:\Users\me\AppData\Local\Programs\Python\Python36-32\DLLs C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib C:\Users\me\AppData\Local\Programs\Python\Python36-32\python36.zip C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packages From rhodri at kynesim.co.uk Wed Sep 6 09:53:07 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 6 Sep 2017 14:53:07 +0100 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> Message-ID: <9aecb8fc-ae8a-5e69-ac61-644a257880e3@kynesim.co.uk> On 06/09/17 14:02, Stefan Ram wrote: > Chris Angelico writes: >> The 'is' operator tests if two things are the same thing. > > ?Roughly speaking, to say of two things that they are > identical is nonsense, and to say of one thing that it > is identical with itself is to say nothing at all.? > > Ludwig Wittgenstein, Tractatus Logico-Philosophicus (5.5303) Irrelevant. We are talking about identity, not identicallity (to coin a word). Or in plainer English, asking if two things are the same thing is not the same as asking if two things are identical. -- Rhodri James *-* Kynesim Ltd From pippoluschippo at aol.com Wed Sep 6 09:56:45 2017 From: pippoluschippo at aol.com (VERMECRIMINALISSIMO CLAUDIO CERASA TWITTER-ILFOGLIO) Date: Wed, 6 Sep 2017 06:56:45 -0700 (PDT) Subject: =?UTF-8?Q?Re=3A_CHI_=C3=88_IL_PEDOFILO_INCULA_BAMBINI_PAOLO_CARDENA=27?= =?UTF-8?Q?_DEL_BLOG_CRIMINALE_VINCITORI_E_VINTI=3F_RAGLIA_CHE_FA_IL_=22PRI?= =?UTF-8?Q?VATE_BANKER=22=2E_MA_NON_DICE_CHE_UNICI_SUOI_CLIENTI_SONO_I_MAFI?= =?UTF-8?Q?OSI_CRISAFULLI_DI_MILANO=21_1_DELLE_FAMIGLIE_DI_COSA_NOSTRA_PI?= =?UTF-8?Q?U=27_ASSASSINE_DI?= In-Reply-To: <90942585-f416-4e26-bd82-8e02f5966f26@googlegroups.com> References: <90942585-f416-4e26-bd82-8e02f5966f26@googlegroups.com> Message-ID: ^MASSONE^ PEDOFILO INCULA BAMBINI: CLAUDIO CERASA (TWITTER & IL FOGLIO..FOGLIO..SI..MA DA USARSI X PULIRE IL CULO SE SENZA CARTA IGIENICA..BUT OCHO..E' PIENO DI NAZISMO E MAFIA)! PEDERASTA DI PALERMO AFFILIATO A COSA NOSTRA! FAMIGLIA KILLER: CIMINNA! MANDAMENTO CACCAMO! SI, ABBIAMO LE PROVE, E' PEDOFILO IL FIGLIO DI PUTTANA, SEMPRE FALSISSIMO A FINI DI DELEGITTIMAZIONE FILO NAZISTA, CLAUDIO CERASA DI TWITTER ED IL FOGLIO ( IL FOGLIO, SI, MA SOLO ED ESCLUSIVAMENTE DA USARE X PULIRSI IL CULO SE SENZA CARTA IGIENICA..E ATTENZIONE, SI, ATTENZIONE... E' FOGLIO INFETTATO DI CRIMINI DI ESTREMISSIMA DESTRA, E' FOGLIO INFETTATO DI P2, E' FOGLIO INFETTATO DI MAFIA). ABBIAMO VARIE FOTO A PROPOSITO. D'ALTRONDE... SCRISSE PURE UN LIBRO PER DEFENDERE I NOTI PEDOFILI DI RIGNANO, I NOTI PEDOFILI DI MAURIZIO COSTANZO, I NOTI PEDOFILI DI CANALE 5... TUTTI PEDOFILI COME IL LORO KAPO': LO SCHIFOSISSIMAMENTE PEDOFILO E SPAPPOLA MAGISTRATI, SILVIO BERLUSCONI! VERME PEDERASTA CLAUDIO CERASA. TUTT'UNO CON UN NOTO AVVOCATO ALTRETTANTO PEDOFILO, NAZISTA ED PARTE DI COSA NOSTRA, COME IL CITATO VERME CLAUDIO CERASA: DANIELE MINOTTI DI RAPALLO ( E SANTA MARGHERITA LIGURE, A DIRE DI FACEBOOK)! A PROPOSITO DEL CRIMINALISSIMO QUALE.. UNA RACCOMANDAZIONE DAVVERO IMPORTANTISSIMA! NON MOSTRATE MAI I VOSTRI FIGLI AL PEDOFIL-O-MOSESSUALE ASSASSINO DANIELE MINOTTI (AVVOCATO PERICOLOSISSIMAMENTE PEDERASTA DI GENOVA E RAPALLO, PURE SU FACEBOOK: OLTRE CHE MEGA LAVA CASH MAFIOSO, NAZIRAZZISTA, AGENTE SEGRETO IN COPERTO DI TIPO OMICIDA)! FACEVA PARTE DI SETTA DI SATANISTI INCULA BAMBINI CON I DEPRAVATISSIMI LUCIFERINI PAZZI GIULIANO FERRARA ED ANSELMA DEL'OLIO ( " PAZZI MA NON SCEMI", COME SI USAN DEFINIRE). OLTRE CHE CON L'ARRESTATO REGISTA PEDOFILO GIUSEPPE LAZZARI. IL GIA' TRE VOLTE IN GALERA PAOLO BARRAI DEL BLOG MERCATO "MERDATO" LIBERO. ED IL PARIMENTI NOTO PEDOFIL-O-MOSESSUALE CLAUDIO CERASA DI TWITTER ED IL FOGLIO... FOGLIO, SI, MA DA USARSI SOLO E SEMPRE PER PULIRSI IL DI DIETRO SE SENZA CARTA IGIENICA IN CASA ( BUT OCHO..E' INFETTATO DI COSA NOSTRA, CAMORRA, NDRANGHETA, NAZISMO E NUOVA P2)! E VISTO CHE ABBIAMO CITATO COSA NOSTRA.. DETTO PEDERASTA PALERMITANO DI CLAUDIO CERASA E' AFFILIATO DA ANNI A COSA NOSTRA: FAMIGLIA CIMINNA, MANDAMENTO DI CACCAMO! INCULA TANTI BAMBINI L?AVVOCATO PEDOFILO E NAZISTA DANIELE MINOTTI DI RAPALLO (PURE SU FACEBOOK)! NON MOSTRATEGLI MAI I VOSTRI FIGLI! RICICLA ANCHE MOLTI SOLDI MAFIOSI! E? PURE UN AGENTE SEGRETO IN COPERTO DI TIPO ASSASSINO! VICINO AI PUZZONI TERRORISTI DI ESTREMA DESTRA, CREANTI NUOVE OVRA E GESTAPO, DI CARATTERE TECNOLOGICO E MILITARE, SCHIFOSI MASSONI NAZISTI, SCHIFOSI MASSO-NA-ZISTI UBALDO LIVOLSI, GIULIO OCCHIONERO E FRANCESCA OCCHIONERO (IL PRIMO DI CRIMINALISSIME LIVOLSI-IAQUINTA & PARTNERS E LIVOLSI AND PARTNERS... GLI ULTIMI DUE, ORA, IN GATTABUIA, SPERIAMO, AL PIU' PRESTO, RAGGIUNTI ANCHE DAL PRIMO, CHE HA IN GOPPA, NON PER NIENTE, GIA' UNA MEGA CONDANNA A GALERA PER IL FALLIMENTO FINPART http://www.romacapitale.net/politica/34-politica/14277-cyberspionaggio-da-renzi-a-monti-a-draghi.html http://www.pmli.it/articoli/2017/20170118_03L_Occhionero.html https://interestingpress.blogspot.pt/2017/01/lingegnere-e-la-maratoneta-la-rete-di.html http://www.ilpost.it/2017/01/11/inchiesta-cyberspionaggio-occhionero-roma/ http://jenkins-ci.361315.n4.nabble.com/VERME-SCHIFOSO-UBALDO-LIVOLSI-OCCHIONERO-FININVEST-DOVREBBE-ESSERE-IN-GALERA-ORA-A-CIUCCIARE-IL-CAZZ-td4895912.html ) COMPLIMENTI VIVISSIMI AL VERO UOMO DI STATO, ROBERTO DI LEGAMI, CHE DAL SCHIFOSISSIMAMENTE NAZISTA E PRO COSA NOSTRA, NONCHE' PARTE DI VERMINOSA NUOVA P2, POLIZIOTTO VOMITEVOLMENTE BERLU-S-MAZZETTATO E BERLUS-C-ORROTTO FRANCO GABRIELLI, E' STATO DESTITUITO DAL PROPRIO LAVORO, IN QUANTO "SI E' AZZARDATO" A SALVARE LA DEMOCRAZIA!!! http://notizie.tiscali.it/cronaca/articoli/occhionero-massoneria-gabrielli/ http://m.dagospia.com/il-capo-della-polizia-gabrielli-rimuove-roberto-di-legami-direttore-della-polizia-postale-139083 VERGOGNA, VERGOGNA E STRA VERGOGNA, TRATTASI DI ENNESIMO SGOZZAMENTO DI VALORI CHE PUZZA TANTISSIMO DI SPAPPOLA GIOVANNI FALCONE E PAOLO BOSELLINO, COMPRATORE DI GIUDICI A GOGO, PERVERTITISSIMO PEDOFILO SILVIO BERLUSCONI (CHE DA ANNI, NON PER NIENTE, ORGANIZZA NUOVE OVRA E GESTAPO ASSASSINE, PRIMA COI PORCI KILLER GAETANO SAYA E RICCARDO SINDOCA, POI COI PORCI KILLER GIULIANO TAVAROLI ED EMANUELE CIPRIANI, POI COI PORCI KILLER "POMPINARO" PIO POMPA, NICOLO' POLLARI E MARCO MANCINI... CHE, MAI DA DIMENTICARE, INTENDEVANO AMMAZZARE CHI "OSASSE" ESSERE NON BERLUSCONICCHIO, VIA "DISARTICOLAZIONI EFFETTUATTE ATTRAVERSO TRAUMI ... KILLER" http://www.veritagiustizia.it/old_rassegna_stampa/la_stampa_piano_traumatico_contro_la_sinistra.php http://www.societacivile.it/focus/articoli_focus/sismi4.html http://www.pmli.it/sismicolpivanemiciberlusconi.htm ... ED ULTIMAMENTE COI PORCI KILLER UBALDO LIVOLSI, PAOLO BARRAI, DANIELE MINOTTI, FRANCESCA OCCHIONERO E GIULIO OCCHIONERO.... ULTIMI DUE, ORA, IN CARCERE, SPERIAMO AL PIU' PRESTO, IN COMPAGNIA DI TUTTO IL RESTO CITATO DI NAZIGANG)! TORNIAMO IN OGNI CASO, ALL'EFFERATO ASSASSINO DANIELE MINOTTI, NOW AND STRA RIGHT NOW, PLEASE! AVVOCATO PEDOFILO DI GENOVA E RAPALLO, PURE SU FACEBOOK! SUA LA SETTA DI SATANISTI, ANZI, SUA LA SETTA DI SATA-N-AZISTI STUPRA BAMBINI, CON DENTRO IL PARI PEDERASTA GIULIANO FERRARA! E SPECIALMENTE IL PARI PEDERASTA CLAUDIO CERASA, NATO A PALERMO, AFFILIATO MAFIOSO DA ANNI (AFFILIATO MAFIOSO DA ANNI E PER QUESTO POSTO IN GOPPA AL FOGLIO..FOGLIO DA USARE PER PULIRSI IL CULO..BUT OCHO..E' INFESTATO DI NEONAZISMO, P2 E MAFIE DI MEZZO MONDO.. POSTO IN GOPPA AL FOGLIO DALL'EDITORE DI COSA NOSTRA NUMERO UNO AL MONDO, SILVIO BERLUSCONI... IL VISCIDO TOPO DI FOGNA E NOTO PEDOFILO CALUDIO CERASA, E' PARTE, E DA UN DECENNIO, DELLA FAMIGLIA MAFIOSA MEG-A-SSASSINA DEI CIMINNA, MANDAMENTO DI CACCAMO..POSTO IN GOPPA AL FOGLIO, POI, IN QUANTO AMANTE OMOSESSUALE DI GIULIANO FERRARA..E ABBIAMO ANCHE PARECCHIE FOTO A PROPOSITO). COME PURE, IL PARI PEDERASTA PAOLO BARRAI DI CRIMINALISSIMA BLOCKCHAIN INVEST, CRIMINALISSIMA BIGBIT, CRIMINALISSIMA WMO SAGL LUGANO, CRIMINALISSIMA WORLD MAN OPPORTUNITIES LUGANO, CRIMINALISSIMA WMO SA PANAMA, CRIMINALISSIMA BSI ITALIA SRL DI VIA SOCRATE 26 A MILANO, CRIMINALISSIMO BLOG MERCATO LIBERO ALIAS "MERDATO" LIBERO (SU CUI TROVATE TUTTO, QUI https://it-it.facebook.com/public/Truffati-Da-Paolo-Barrai). ED IL PARI PEDERASTA STEFANO BASSI DI TORINO E DE IL GRANDE BLUFF. https://it-it.facebook.com/stefano.bassi.758 TUTT'UNO CON LA NDRANGHETA E DA DECENNI. CINTURA FRA LA ASSASSINI CALABRESI BASATI IN PIEMONTE, BEN NOTO SPAPPOLA MAGISTRATI E PEDOFILO SILVIO BERLUSCONI, OLTRE CHE LEGA LADRONA. LAVATRICE FINANZIARIA DEI KILLER NDRANGHETISTI CROTONESI DELLE FAMIGLIE VRENNA E MEGNA, VERI E PROPRI PADRONI DI TORINO. PER NON PARLARE DEL PARI PEDERASTA E MEGA RICICLA SOLDI MAFIOSI PAOLO CARDENA' DI CRIMINALISSIMO BLOG VINCITORI E VINTI (SEMPRE A LAVARE CASH ASSASSINO, SPECIE DEI MAFIOSI CRISAFULLI DI MILANO, MA NON SOLO) https://it.linkedin.com/in/paolo-carden%C3%A0-6a610827 IL PARI PEDERASTA E MEGA RICICLA SOLDI NDRANGHETISTISSIMI, ROCCO TRIPODI CRIMINALISSIMA DI HYPO TIROL BANK PARMA..E DI NAZISTA CASA POUND, http://it.viadeo.com/it/profile/rocco.tripodi https://www.facebook.com/Rocco-Tripodi-1537588826544365/ CHE INSIEME AL PARI PEDERASTA E MEGA RICICLA SOLDI NDRANGHETISTISSIMI NICOLA VACCARI DI INBITCOIN TRENTO. E' TUTT'UNO CON LA IMMENSAMENTE ASSASSINA COSCA PESCE DI GIOIA TAURO, CHE DA GIOIA TAURO SBARCA TONNELLATE DI COCAINA OGNI MESE https://it.linkedin.com/in/nicolavaccari (A LITTLE JOKE.. CHE PERO' E' SCIOCCANTISIMA REALTA', PIU' CHE A LITTLE JOKE: SONO OMOSESSUALI DI TIPO DEPRAVATISSIMO, ROCCO TRIPODI DI HYPO HYPO TIROL BANK PARMA ED IL VERME CRIMINALE NICOLA VACCARI DI INBITCOIN TRENTO.. QUINDI.. PIU' CHE PER LA COSCA DEL LORO AMATISSIMO "PESCE"..PER CHI POTEVANO "TRABAGGHIARI, AAAA"?!?!?)!!! DI STA TOPAIA FASCIOMAFIOSA FACEVAN PARTE IN PIENO E STRA PIENO, IL PEDERASTA E MEGA RICICLA SOLDI DI STIDDA E COSA NOSTRA, RICCARDO CASATTA DI CRIMINALISSIME ETERNITY WALL E BLOCKCHAINLAB https://it.linkedin.com/in/riccardocasatta ED IL, NOTO A LONDRA COME " THE CRIMINAL BEAST", PORCO CRIMINALISSIMO THOMAS BERTANI DI ORACLIZE https://uk.linkedin.com/in/thomasbertani UNA DELLE PRINCIPALI LAVATRICI DI CASH KILLER DI MAFIA, CAMORRA, NDRANGHETA, MALAVITE DI MEZZO MONDO NELLA CITY LONDINESE (I DUE PONGONO A DISPOSIZIONE AD ASSASSINI SU ASSASSINI DI TUTTO IL PIANETA TERRA, I MEGA LAVA CASH MAFIOSO SISTEMI BLOCKCHAIN E BITCOIN http://www.ilsole24ore.com/art/commenti-e-idee/2017-01-24/bitcoin-riciclaggio-invisibile-mafie-e-terrorismo-internazionale-164825.shtml?uuid=AEISiAH https://www.theguardian.com/technology/2016/jan/20/bitcoin-netherlands-arrests-cars-cash-ecstasy) PARTE DELLA NAZIGANG E' IN STRA PIENO IL BASTARDO FASCIORAZZISTA E MEGA RICICLA SOLDI MAFIOSI, GIACOMO ZUCCO DI CRIMINALISSIMA BHB-BLOCKCHAINLAB, BLOCKCHAINLABIT, ASSOB.IT E WMO SA PANAMA (OLTRE CHE DI CITATI KU KLUK KLANISTI TEA PARTIES). TRATTASI DI ALTRO CIUCCIA CAZZI MORTI DI SILVIO BERLUSCONI, CHE, PER LO STESSO PEDOFILO SPAPPOLA MAGISTRATI SILVIO BERLUSCONI, MEGA RICICLA SOLDI KILLER DI BEN 7 NDRINE BASATE NEL MILANESE (FRA CUI LA MEGA SANGUINARIA NDRINA DI SANTO PASQUALE MORABITO). COME DELL'EFFERATO KILLER CAMORRISTA SALVATORE POTENZA! AND THEN AGAIN AND AGAIN AND AGAIN... FAN PARTE DI QUESTA GANG NAZINDRANGHETISTA, IL PARI PEDERASTA MAURIZIO BARBERO DI TECHNOSKY MONTESETTEPANI https://it.linkedin.com/in/maurizio-barbero-a521978 (CHE ERA CIO' CHE UNIVA IL BASTARDO HITLERIANO GIULIO OCCHIONERO AD ENAV http://www.ilfattoquotidiano.it/2017/01/13/giulio-occhionero-un-cyberspione-che-piu-maldestro-non-si-puo/3312745/ http://www.repubblica.it/cronaca/2017/01/10/news/cyberspionaggio_inchiesta-155753314/ DI CUI, NON PER NIENTE, TECHNOSKY MONTESETTEPANI, SOCIETA' CONTROLLATA DA SERVIZI SEGRETI DI ESTREMA DESTRA, SPESSISSIMO ANCHE ASSASSINI, E' IN PIENO, PARTE). IL NOTO RICICLA SOLDI MAFIOSI MATTEO PARDU DI CRIMINALISSIMO STUDIO DI COMMERCIALISTI DEL SOLDATO DI LA SPEZIA! https://it.linkedin.com/in/matteo-pardu-90658820 LA NOTISSIMA PEDOFILA ELISA COGNO DI FRUIMEX SAS ALBA E TORINO. http://www.impresaitalia.info/mstdb80753147/fruimex-di-cogno-elisa-e-c-sas/alba.aspx http://jenkins-ci.361315.n4.nabble.com/SBORRATA-TUTTA-NEL-CULO-ELISA-COGNO-FRUIMEX-ALBA-TORINO-BLOGSPOT-TROIA-SATA-N-AZISTA-CHE-DIFFAMA-SUL-td4895643.html LA NOTISSIMA PEDOFILA, TANTO QUANTO, PIERA CLERICO DI FRUIMEX SAS ALBA E TORINO. http://jenkins-ci.361315.n4.nabble.com/BASTARDISSIMA-TROIA-PIERA-CLERICO-FRUIMEX-A-CAPO-ANZI-A-quot-KAPO-quot-DI-TANTE-SETTE-SATANISTE-ANZI-td4897000.html AND THERE WE GO AGAIN AND AGAIN: IL PARI PEDERASTA AZZERA RISPARMI FEDERICO IZZI DETTO ZIO ROMOLO ( MEGA RICICLA CASH MALAVITOSO DEI GIRI LERCI DI MAFIA CAPITALE E DI CAMORRISTI PRESENTI NEL BASSO LAZIO https://meloniclaudio.wordpress.com/2016/12/30/la-camorra-a-roma-e-nel-lazio/ http://www.adnkronos.com/fatti/cronaca/2016/03/04/blitz-contro-camorra-nel-casertano-nel-basso-lazio-arresti_Ee3CRNYmUmhxiTgmJJK3kI.html ). IL PARI PEDERASTA E MEGA RICICLA SOLDI MAFIOSI ANDREA SCARSI DI BANCA IFIGEST MILANO https://it.linkedin.com/in/andrea-scarsi-67a04a9 https://www.yatedo.com/p/Andrea+Scarsi/normal/1849658805458f948a8d95eb518850a4 IN PASSATO PURE A TRAFFICARE IN MONTE PASCHI AL FINE DI EFFETTUARE LA MEGA RUBERIA MASSONICO-NAZIFASCISTA POSTA IN ESSERE DAL PORCO GIUSEPPE MUSSARI http://www.ilfattoquotidiano.it/2016/10/01/mps-processo-milano-ex-vertici-giuseppe-mussari-antonio-vigni-e-gianluca-baldassarri/3069322/ FIGLIO DI NOTISSIMO GINECOLOGO SATANISTA E PEDOFILO ALESSANDRO SCARSI DI LATINA, CHE UCCIDEVA BAMBINI PER LEVARGLI ORGANI DA VENDERE, CHE STUPRAVA E FACEVA ABORTIRE PROSITUTE MINORENNI ALBANESI A GOGO E CHE PER TUTTO QUESTO E' FINITO IN GALERA http://www.telefree.it/news.php?op=view&id=2285 https://groups.google.com/forum/#!topic/it.hobby.fai-da-te/V_4dMdeCZQA PER NON PARLARE DEI PRIMA CITATI: NOTA PEDOFILA ANSELMA DEL'OLIO (SPOSATA COL VICE KAPO' E VICE CAPO DEI VERMI PRIMA CITATI: GIULIANO FERRARA). ED IL GIA' ARRESTATO PER AVER STUPRATO BAMBINI DI 11 ANNI, REGISTA BRESCIANO PEDERASTA GIUSEPPE LAZZARI!!! http://milano.repubblica.it/cronaca/2016/08/09/news/pedofilia-145677361/ NON PER NIENTE... FRA ANSELMA DELL'OLIO E GIUSEPPE LAZZARI, VI FURONO MOLTE SLINGUATE "PEDOFILESCO-MEDIATICHE", NEGLI ULTIMI ANNI, TIPO QUESTA http://video.corriere.it/sesso-11enne-arrestato-regista-giuseppe-lazzari-l-intervista-rai/4287e44c-5e41-11e6-bfed-33aa6b5e1635 MA ORA... COME CANTAVA LA GRANDISSIMA LYNN COLLINS, PRODOTTA DALL'ANCORA PIU' GRANDE JAMES BROWN... "AGAIN AND AGAIN AND AGAIN"!!! https://www.youtube.com/watch?v=wB5KgOXHcxc NASCONDETE I VOSTRI FIGLI, PLEASE, DA NOTO AVVOCATO PEDOFIL-O-MOSESSUALE DANIELE MINOTTI (FACEBOOK)! NOTISSIMO AVVOCATO PEDERASTA INCULA BAMBINI DANIELE MINOTTI DI RAPALLO E GENOVA (DA ANNI ED ANNI ISCRITTO PRESSO GLI ANIMALI PAZZI CHE STUPRANO ADOLESCENTI E BIMBI, OSSIA I PORCI DEPRAVATISSIMI DI " ORGOGLIO PEDOFILO" https://en.wikipedia.org/wiki/North_American_Man/Boy_Love_Association)! E' SUA LA SETTA DI SATANISTI STUPRA BIMBI CON DENTRO IL REGISTA, PURE PEDOFILO, GIUSEPPE LAZZARI (ARRESTATO), LA NOTA PEDOFILA TANTO QUANTO, ANSELMA DELL'OLIO ( CHE, COME AVETE VISTO E RI VEDRETE IN UN VIDEO QUI A SEGUITO, DA' DEL GENIO, DA' DEL FENOMENO, DI CONTINUO, AL SUO COMPARE DI ORGE SODOMIZZA RAGAZZINI: GIUSEPPE LAZZARI). ED IL, NOTORIAMENTE, DA SEMPRE PEDOFIL-O-MOSESSUALE GIULIANO FERRARA! COME IL PEDERASTA AFFILIATO A COSA NOSTRA, IL VISCIDO VERME CLAUDIO CERASA, NATO A PALERMO IL 7.5.1982, PARTE DELLA FAMIGLIA MEGASSASSINA CIMINNA DI CACCAMO. E PROPRIO IN QUANTO PARTE DI COSA NOSTRA E DA VARI ANNI, POSTO DAI, DA SEMPRE EDITORI MAFIOSI UBER ALLES, SILVIO BERLUSCONI E GIULIANO FERRARA, IN GOPPA AL FOGLIO (DA USARE SEMPRE E SOLO QUANDO FINISCE LA CARTA IGIENICA, MA CON ACCORTEZZA, PLEASE: E' UN FOGLIO INFETTATO DA CRIMINI DI OGNI, NON SOLO MEDIATICI, NON SOLO FRUTTO DELLE PIU' DELINQUENZIALI FAKE NEWS, MA ANCHE CRIMINI ASSASSINI, TERRORISTICI DI ESTREMA DESTRA, NAZIFASCISTI, MAFIOSI, CAMORRISTI, NDRANGHETISTI)! SI, E' PROPRIO TUTTO COSI': LO HANNO BECCATO UN'ALTRA VOLTA A STO SCHIFOSO SATANISTA, ANZI, A STO SCHIFOSO SATA-N-AZISTA PEDOFIL-O-MOSESSUALE DI DANIELE MINOTTI, AVVOCATO CRIMINALISSIMO DI RAPALLO E GENOVA ( GIA' AI TEMPI A FARE ORGE PEDOFIL-O-MOSESSUALI CON DON RICCARDO SEPPIA http://grokbase.com/t/python/python-list/148jckyh1w/avvocato-pedofilomosessuale-ed-assassino-daniele-minotti-facebook-oltre-che-nazi-megalava-euro-mafiosi-e-come-detto-mandante-di-omicidi-o-suicidate-stalker-di-eroe-civile-michele-nista-su-ordine-di-tiranno-fasciocamorrista-silvio-berlusconi STUDIO DI CRIMINALISSIMO PEDERASTA DANIELE MINOTTI Sede di Rapallo (GE) Via della Libert?, 4/10 ? 16035 RAPALLO (GE) Tel. +39 0185 57880 Sede di Genova Via XX Settembre 3/13 16121 ? GENOVA) CHE EFFETTUA ANCHE, DA SEMPRE, TANTO RICICLAGGIO DI DENARO MAFIOSO, COME PURE ROVINA O TERMINA LA VITA DI GENTE PER BENISSIMO (ANCHE ORDINANDO OMICIDI), ATTRAVERSO COMPLOTTI MASSO-N-AZIFASCISTI, OSSIA, DI LOGGE SATANICHE DI ESTREMISSIMA DESTRA. STO VERME SCHIFOSO DI DANIELE MINOTTI FACEVA PARTE DI UNA SETTA DI PEDERASTA BERLUSCONICCHI! IL CUI CAPO-KAPO' E' OVVIAMENTE LO SBAUSCIA TROIE BAMBINE MAROCCHINE, NONCHE' SPAPPOLA MAGISTRATI, PEDOFILO NUMERO UNO AL MONDO: SILVIO BERLUSCONI! SUO CAROGNESCO MANDANTE DI MILLE CRIMINALITA' E STALKING VIA WEB! ASSOLUTA METASTASI ASSASSINA E MONDIALE DI DEMOCRAZIA, LIBERTA' E GIUSTIZIA! http://www.huffingtonpost.it/2015/03/26/intervista-gianni-boncompagni_n_6945522.html http://www.cappittomihai.com/tag/pedofilo/ http://www.ibtimes.co.uk/silvio-berlusconi-paid-10m-bribes-bunga-bunga-girls-paedophile-prostitution-trial-1508692 http://www.magicrules.pw/2013/Jul/18/16000.html SEGUITO A RUOTA DAL MEGA SACCO STRA COLMO DI ESCREMENTI, NOTISSIMO PEDOFIL-O-MOSESSUALE TANTO QUANTO, GIULIANO FERRARA ( LUI STESSO CONSIGLIA IL FARSI SODOMIZZARE, QUI http://www.blitzquotidiano.it/politica-italiana/giuliano-ferrara-omosessualita-giochetto-consiglio-contro-natura-1483446/ GIULIANO FERRARA E' DA SEMPRE UN PPP ..PPP PUZZONE PORCO PERVERTITO PEDOFILO PEDERASTA PIDUISTONE PAZZO CHE AMA PARTECIPARE AD ORGE OMOSESSUALI A GO GO.. QUESTE FOTO E QUESTO LIBRO LO STRA CHIARISCONO http://cdn-static.dagospia.com/img/patch/archivio/d0/ferrara_nudo_Visto_exc.jpg https://www.ibs.it/arcitaliano-ferrara-giuliano-biografia-di-libro-pino-nicotri/e/9788879531337 ). RI SEGUITO A RUOTA DAL NOTO FIGLIO DI PUTTANA CALUDIO CERASA ( TWITTER & IL FOGLIO... DA USARE SOLO E SEMPRE PER PULIRSI IL CULO QUANDO FINISCE LA CARTA GIENICA, BUT BIG BIG STRA BIG OCHO: E' INFETTATO DI MAFIA, P2 E NAZISMO). NATO A PALERMO. MASSONE CRIMINALISSIMO PARTE DI COSA NOSTRA. FAMIGLIA CIMINNA, MANDAMENTO DI CACCAMO. http://jenkins-ci.361315.n4.nabble.com/PEDOFILO-CIUCCIA-CAZZI-CLAUDIO-CERASA-TWITTER-E-IL-FOGLIO-DA-USARE-PER-PULIRSI-IL-CULO-SE-FINISCE-LA-td4896516.html VERMINOSO PEDOFIL--O-MOSESSUALE CLAUDIO CERASA DI TWITTER ED IL FOGLIO, NON PER NIENTE, STRENUO DIFENSORE DEI SUOI COMPATI PEDOFILI DI RIGNANO FLAMINIO, COME DEI PARI PEDOFILI MAURIZIO COSTANZO, GIANFRANCO SCANCARELLO E SILVIO BERLUSCONI! http://www.gay.it/community/forums/topic/il-pedofilo-satanista-e-lautore-di-buona-domenica-di-maur SATANAZISTI PEDOFILI DANIELE MINOTTI, GIULIANO FERRARA, CLAUDIO CERASA... ED IL GIA' TRE VOLTE IN GALERA PAOLO BARRAI, NATO A MILANO IL 28.6.1965, DI CRIMINALISSIMA BIGBIT, CRIMINALISSIMA BLOCKCHAIN INVEST, CRIMINALISSIMA WORLD MAN OPPORTUNITES LUGANO, CRIMINALISSIMA WMO SAGL LUGANO, CRIMINALISSIMA WMO SA PANAMA, CRIMINALISSIMA BSI ITALIA SRL MILANO, VIA SOCRATE 26 E CRIMINALISSIMO BLOG MERCATO LIBERO ALIAS ?MERDATO? LIBERO. DI CUI TROVATE "NON POCHE" NOTIZIE ( CHE PRESTO SARANNO AMPLIATE ALL'INFINITO) QUI https://it-it.facebook.com/public/Truffati-Da-Paolo-Barrai ). PARTE DELLA SETTA INCULA BAMBINI SU BAMBINI ERA IN PIENO ANCHE L' APPENA ARRESTATO PER PEDOFILIA, REGISTA GIUSEPPE LAZZARI ( PEDOFILO E NON PER NIENTE, DA SEMPRE BERLUSCONIANISSIMO... OO CHE CASO, OO)! http://www.bresciaoggi.it/territori/citt%C3%A0/abusi-su-un-undicenne-arrestato-lazzari-1.5058394 http://www.giornaledibrescia.it/brescia-e-hinterland/i-poliziotti-lazzari-minacciava-la-madre-del-ragazzino-1.3110508 CHE QUI SLINGUA PERVERTITISSIMAMENTE, IDEOLOGICAMENTE E MEDIATICAMENTE, CON LA PARIMENTI STUPRA BIMBI E STUPRA BIMBE, DA SEMPRE PEDOFILA LESBICA ANSELMA DELL'OLIO. CHE, NON PER NIENTE, NEL VIDEO CHE QUI SEGUE, DA' ALL'ACCERTATO PEDERASTA GIUSEPPE LAZZARI, DEL GENIO, A GO GO (ULLALA' CHE COINCIDENZUZZA BEDDA, ULLALA')! http://video.corriere.it/sesso-11enne-arrestato-regista-giuseppe-lazzari-l-intervista-rai/4287e44c-5e41-11e6-bfed-33aa6b5e1635 OVVIAMENTE, IN QUANTO PARTE DELLA STESSA SETTA SATANISTA E PEDOFILESCA DI SILVIO BERLUSCONI, GIULIANO FERRARA, VERME CLAUDIO CERASA, GIA' 3 VOLTE IN GALERA PAOLO BARRAI ED IL CITATO NOTO AVVOCATO PEDERASTA SODOMIZZA BAMBINI: DANIELE MINOTTI DI GENOVA E RAPALLO. PURE AGENTE SEGRETO IN COPERTO, DI TIPO ASSASSINO. SI, ASSASSINO, PER OVRA E GESTAPO PUBBLICHE E PRIVATE DI SILVIO BERLUSCONI! VOLETE ALTRE PROVE ED INIDIZI? IAMM BELL, IA'....GUARDATE QUESTI LINKS CHE SEGUONO, PLEASE.... GUARDATE COME STO PEDERASTA INCULA BAMBINI DI DANIELE MINOTTI, AVVOCATO CRIMINALISSIMO DI RAPALLO E GENOVA, SEMPRE DIFENDA SUOI DEPRAVATI "COLLEGHI", OSSIA VOMITEVOLI PEDOFILI COME LUI! O COME DIFENDA STUPRATORI SESSUALI! O IL FARE SESSO CON POCO PIU' CHE BAMBINI, IN GENERALE! http://www.lettera43.it/cronaca/adescava-minorenni-sul-web-miltare-a-processo_43675123449.htm http://genova.repubblica.it/cronaca/2014/02/26/news/sesso_virtuale_in_cambio_di_soldi_per_videogame-79717213/ http://www.primocanale.it/notizie/accusato-di-adescare-minori-su-web-condanna-4-anni-e-4-mesi-142040.html http://www.ilsecoloxix.it/p/genova/2008/08/14/ALZmws0B-denuncio_badante_sgozzata.shtml http://www.ansa.it/liguria/notizie/2014/06/20/adescava-minori-sul-web-condannato_36c57304-90aa-4c7f-8463-c7d610ed10dd.html http://iltirreno.gelocal.it/massa/cronaca/2013/04/19/news/casolare-a-luci-rosse-il-pm-7-anni-e-mezzo-all-ex-dipendente-nca-1.6917147 E QUI A SEGUITO, LEGGETE, SEMPRE, PLEASE, LA TESTIMONIANZA DI STEFAN CUMESCU! CHE APPENA A 14 ANNI FU PRIMA DROGATO, POI STUPRATO, POI SODOMIZZATO A SANGUE, POI SODOMIZZATO QUASI A MORTE, DAL BASTARDO NAZIPEDERASTA DANIELE MINOTTI, MASSONE NEO PIDUISTA, AVVOCATO INCULA RAGAZZINI, AVVOCATO INCULA BAMBINI, COME COSI' AVVOCATO DI MAFIOSI MEGA KILLER E/O CRIMINALI DI OGNI.... http://www.nyg-forum.xyz/2014/Oct/26/357297.html http://www.macportables.pw/2014/Oct/07/43480.html ). ED ECCO VARI TESTI CHE CHIARISCONO QUANTO IL REPELLENTE PEDOFILO INCULA BAMBINI, DANIELE MINOTTI STESSO, DA SEMPRE, RICICLI PURE SOLDI ASSASSINI DI COSA NOSTRA, CAMORRA E NDRANGHETA! A GO GO!! https://lists.gt.net/python/python/1270814 http://grokbase.com/t/python/python-list/148jckyh1w/avvocato-pedofilomosessuale-ed-assassino-daniele-minotti-facebook-oltre-che-nazi-megalava-euro-mafiosi-e-come-detto-mandante-di-omicidi-o-suicidate-stalker-di-eroe-civile-michele-nista-su-ordine-di-tiranno-fasciocamorrista-silvio-berlusconi http://www.perl-tk.pw/2014/Sep/19/12201.html http://www.hardwaresystems.pw/2014/Sep/17/5.html http://jenkins-ci.361315.n4.nabble.com/FIGLIO-DI-PUTTANA-DANIELE-MINOTTI-AVVOCATO-PEDOFILO-DI-RAPALLO-PURE-SU-FACEBOOK-NAZI-LAVA-CASH-MAFIO-td4896126.html http://jenkins-ci.361315.n4.nabble.com/FIGLIO-DI-PUTTANAZZA-DANIELE-MINOTTI-AVVOCATO-PEDOFILO-DI-RAPALLO-SU-FACEBOOK-LAVA-CASH-MAFIOSO-NAZI-td4896381.html E.. DI NUOVO... AGAIN AND AGAIN AND AGAIN.. COME LA CANTAVA LA GRANDISSIMA LYNN COLLINS PRODOTTA DALL'ANCORA PIU' GRANDE JAMES BROWN " ..... AGAIN... AND...AGAIN... AND...AGAIN...AND..AGAIN" https://www.youtube.com/watch?v=bmlAYrKRmuQ A VOI, ORA, GLI INTERI TESTI, (A) DEL POVERO EX BAMBINO STEFAN CUMESCU, SODOMIZZATO QUASI A MORTE, DAL VERMINOSO BASTARDO PEDERASTA AVVOCATO DANIELE MINOTTI, E (B) DI COME LO STESSO RICICLI CASH ASSASSINO, DI COSA NOSTRA, CAMORRA E NDRANGHETA DA SEMPRE. SOON BACK!!! TEXT A Ciao tuti e scusate de mio italiano. Io sono rumeno e non me nascondo: me chiamo Stefan Cumescu e sono stato sodomizzato con violenza da avvocato assassino Daniele Minotti di Rapallo e Genova, esatamente nel estate 2009! Infati, io ora tengo 19 anni. Quindi, 5 anni e pasa fa tenevo 14 anni. E bene, 5 anni fa avvocato di giri nazifascisti misti a Cosa Nostra, Camorra, Ndrangheta, Daniele Minotti di Rapallo e Ganova, mi diede tre grammi di cocaina da vendere misti a qualcosa che te fa perdere sensi... mi fece svenire apposta e mentre ero mas di morto che vivo, me sodomizzo'. Vi era anche pancione pieno di merda Giuliano Ferrara de Il Foglio a guardare, ridere, cercare de masturbarse invano esendo noto impotente da sempre. Vi era anche il banchero immensamente pedofilo Gabriele Silvagni di Banca Carim Rimini, e sua moglie, notia prostituta pedofila tante quanto, Raffaella Vaccari, sempre de Rimini. Il filio de putana avvocato Daniele Minotti, criminalissimo avvocato di Rapallo e Genova me sodomizzo' insieme ad altri sei di suoi giri fascisti e mafiosi. Ho anche prove di tuto questo. Io, ora, Stefan Cumescu di Genova, quartiere Caruggi, facio il muratore, basta droga, basta prostituirsi (como doveti de fare a seguito di questo stupro, per poter rimanere vivo, per non venire amazato, e doveti de prostituirmi proprie su ordine de Mafia Berlusconiana e Fascismo Berlusconiano, a Genova, rapresentati da questo bastardo sodomizza bambini de avvocato Daniele Minotti). Guadanio un decimo di quanto guadaniavo prima e lavoro il triplo di quanto prima. Ma preferisco di questo, sento la mia vita uno poco di maggiore securo. Ma avvocato di Hitler, Vallanzasca e Satana, avvocato filio de putana di Silvio Berlusconi e Giuliano Ferrara, nazista e mafioso pederasta Daniele Minotti di Genova e Rapallo, davvero fa parte di setta di maniaci sessuali omosessuali molto pericolosi. Ciao. Stefan. Posti De Scrito Io vedevo in giro uno belo testo che parlava di tuto questo...anche de orge depravatissime fate da incula bambini Daniele Minotti con Don Riccardo Seppia, ma ora non vedo tanto di piu' in giro de lo steso testo. Alora sai cosa facio? Di mia iniciativa, lo cerchio, ops, intende dire lo cerco, facio cut and copy e provo di riproporlo io da tute parti e pe tuta mi vita. Ciao da Stefan e ri scusa di mio italiano... ma presto volio di fare corsi di sera di miliorarlo. Ciao. TEXT B - OCHO AD AVVOCATO "BERLUSCONIANISSIMAMENTE", MEGA RICICLA CASH MAFIOSO, NAZIFASCISTA, ASSASSINO E PEDOFILOMOSESSUALE: DANIELE MINOTTI ( PURE SU FACEBOOK) DI RAPALLO E GENOVA! TUTTI SANNO DI SUE "FESTE" SATANISTISSIME "ATTE A SODOMIZZARE ZINGARELLI DI 6-8 ANNI (A SANREMO, CON DON RICCARDO SEPPIA E COL TANTE VOLTE CONDANNATO A GALERA, PAOLO BARRAI DEL CRIMINALISSIMO BLOG MERCATO "MERDATO" LIBERO.. MA NON SOLO... E FRA POCO.. TUTTI I NOMI E COGNOMI)!!! OCCHIO, PLS, ALL'AVVOCATO PIU' INFIMAMENTE NAZISTA, MEGA LAVA CASH MAFIOSO, MANDANTE DI OMICIDI E "SUICIDATE", E COME SE NON BASTASSE, ACCLARATO PEDOFILOMOSESSUALE, CHE ESISTA ( IL VOMITO VA' SULLA PARTE "PEDOFILO", PIU' CHE OMOSESSUALE, ANCHE SE IL MEGA SODOMIZZATORE DI BAMBINI, DANIELE MINOTTI, LO E' ENTRAMBE LE COSE; OLTRE AD ESSERE UN VERMINOSO CODARDO: METTEVA DELLE SUE FOTO CON FACCE DA ASSOLUTO PERICOLOSISSIMO MANICACO SESSUALE, SU TUTTA INTERNET... ED OVVIAMENTE, ORA, DOPO CHE LE ABBIAM FATTE NOTARE SU MIGLIAIA DI SITI, DA TOPO DI FOGNA, DETTE FOTO LE HA FATTE SUBITO IMBOSCARE)! COME SE NON BASTASSE, PURE FREQUENTISSIMO MANDANTE DI "SUICIDATE" ED OMICIDI: DANIELE MINOTTI DI GENOVA E RAPALLO. Criminalissimo Studio Legale pro Mafia, Camorra, Ndrangheta e Neonazisti assassini, di noto pedofilomosessuale Daniele Minotti :: Genova - Rapallo Via della Libert?, 4/10 - 16035 - Rapallo (GE) (Tribunale di Chiavari) Via XX Settembre, 3/13 - 16121 - Genova RICICLANTE DA ANNI CASH KILLER DEGLI EMANUELLO DI COSA NOSTRA, BASATI A GENOVA http://www.ilsecoloxix.it/p/genova/2011/05/19/AOJ0cAV-rischio_gronda_arresti.shtml O DEI FEROCI SICARI DELLA NDRANGHETA: I RAMPINO. SEMPRE BASATI A GENOVA http://www.ilsecoloxix.it/p/genova/2013/06/05/APjJUSgF-ndrangheta_terra_liguria.shtml BASTARDO VERO, PEDERASTA PERVERTITO DANIELE MINOTTI DI GENOVA E RAPALLO: TUTTI SANNO DELLE ORGE PEDOFILE CHE FACEVA CON DON RICCARDO SEPPIA A SANREMO. FRA SIMBOLI DEMONIACI E TERRIFICANTI SODOMIZZAZIONI DI BAMBINI DI 6-8 ANNI ( E AHIME.. FATEMI SDRAMMATIZZARE, PLS... ANCHE 6-8 ANI). BAMBINI ZINGARELLI! D'ALTRONDE, TOPI DI FOGNA CODARDI E SPIETATI COME IL CRIMINALISSIMO AVVOCATO DANIELE MINOTTI DI GENOVA CHE ALTRO AVREBBERO POTUTO RACCATTARE? IL TUTTO FRA CHILI DI COCAINA, MEGA CASH MAFIOSO, E SCIOCCANTISSIMAMENTE, DOZZINE DI TESSERE FASCIOCAMORRISTE DI FORZA ITALIA, FRATELLI D'ITALIA, CASA POUND, FIAMMA TRICOLORE E LEGA NORD. IL DAVVERO "AVVOCATO DEL DIAVOLO", IL BASTARDO MASSONE NAZISTA, IL VERME MASSO-NAZISTA ( MERDA ASSASSINA P2ISTICA PER INTENDERCI), MEGA LAVA CASH MAFIOSO, MANDANTE DI "SUICIDATE" ED OMICIDI A RAFFICA, SEMPRE INC.LANTE BAMBINI O POCO PIU' CHE BAMBINI, DANIELE MINOTTI DI GENOVA E RAPALLO, D'ALTRONDE, I PEDOFILOMOSESSUALI O PEDOFILI IN GENERE LI AMA, SE NE SENTE STRA PARTE, LI DIFENDE. NON CI CREDETE??? VOLETE FARE GLI STRUZZI, CHE PER FRATELLANZA MASSO-N-AZIFASCISTA, PREFERISCONO METTERE LA TESTA DOVE GIRANO I VERMI, SOTTO TERRA??? GIVE A LOOK RIGHT NOW, THEN, PLS: http://www.ansa.it/liguria/notizie/2014/06/20/adescava-minori-sul-web-condannato_36c57304-90aa-4c7f-8463-c7d610ed10dd.html http://iltirreno.gelocal.it/massa/cronaca/2013/04/19/news/casolare-a-luci-rosse-il-pm-7-anni-e-mezzo-all-ex-dipendente-nca-1.6917147 E SE GOOGLATE " DANIELE MINOTTI PEDOPORNOGRAFIA" VEDRETE CHE IN TUTTI I SUOI ARTICOLI, SOTTILISSIMAMENTE ( E MANCO TANTO, SOTTILISSIMAMENTE) DIFENDE I PEDOFILI, MINIMIZZA O ELUDE LE LORO ABERRANTI, SPEZZA VITE, COLPE! LI SUPPORTA: OVVIO, E' UN VERME SODOMIZZA BAMBINI LUI IN PRIMO! DA RINCHIUDERE IN GALERA O MANICOMIO CRIMINALE SUBITO: AVRA' GIA' UCCISO E FATTO SCOMPARIRE QUALCHE BIMBO CHE HA INCULATO! O PRESTO LO FARA'! QUI SALVIAMO VITE DI PICCOLISSIME CREATURE CON QUESTI SCRITTI!!! SALVIAMO IL MONDO!!! PER FINIRE, ANYWAY, ORA TORNIAMO A STO, PURE TERRORISTA NERO ( ED IN NERO), COME CITATO, FREQUENTE MANDANTE DI OMICIDI, "SUICIDATE" O TERRIFICANTI ISTIGAZIONI AL SUICIDIO: DANIELE MINOTTI DI RAPALLO E GENOVA. INCITA I VERMI DI ESTREMISSIMA DESTRA COME LUI, DI TUTTO IL MONDO, I KAMERADEN KILLER DEI TEA PARTIES, AD AMMAZZARE, NELLA MERDA BASTARDAMENTE DITTATORIALE DI "RENZUSCONIA" (O OVUNQUE SIANO NEL GLOBO), CHIUNQUE CRITICHI "TROPPO" I SUO LIDER MAXIMI, E LIDER MAXIMI IN TUTTO, SPECIE IN PEDOFILIA, FASCIOCAMORRA ED ORDINI DI UCCISIONI E STRAGI: SILVIO BERLUSCONI E LICIO GELLI (CITATI NAZIMAFIOSI DEI TEA PARTIES DI CUI E' STRA PARTE, INSIEME AD ALTRO VERME BERLUSCONAZISTA E CRIMINALISSIMO: GIACOMO ZUCCO, OVVIAMENTE, PURE LUI, MEGA LAVA SOLDI DI COSA NOSTRA, CAMORRA E NDRANGHETA, SPECIE VIA BITCOINS, E PURE LUI NOTO PEDOFILOMOSESSUALE TANTO QUANTO)! CON IL QUALE CONDIVIDE PURE, UNA, DA VOMITARE ANCHE LA BILE, TESSERA DEI PEDERASTA CHE "SON ORGOGLIOSI DI FAR SESSO CON BAMBINI", QUELLA DELL'ORGOGLIO PEDOFILO, OSSIA QUELLA DEI ? "North American Man-Boy Amore Association" https://en.wikipedia.org/wiki/North_American_Man/Boy_Love_Association http://www.today.it/rassegna/giornata-orgoglio-pedofilo.html STO PUTRIDISSIMO TOPO DI FOGNA DI DANIELE MINOTTI DEL FORO DI CHIAVARI (ALTRA SDRAMMATIZZAZIONE, PLS.. CHIAVARI SI.. E' DI CERTO LA COSA PIU' BELLA AL MONDO, MA ANCHE LA PIU' BRUTTA, QUANDO LO SI FA DEPRAVATISSIMAMENTE CON I BAMBINI, COME FA SEMPRE STO ESCREMENTOSO PEDOFIL-O-MOSESSUALE DI DANIELE MINOTTI DI RAPALLO E GENOVA) E' OVVIAMENTE PURE UN BASTARDO RAZZISTA. AUSPICA LA MORTE SOCIALE, " MA ANCHE NON SOLO.. ANCHE TOTALISSIMA", DI CHIUNQUE NATO SOTTO LA SUA BASTARDAMENTE NAZI-MAFIOSA PIDUISTISSIMA AREZZO!! From antoon.pardon at vub.be Wed Sep 6 10:11:57 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 6 Sep 2017 16:11:57 +0200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59aff115$0$16748$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <5e1d04de-c509-babd-5123-eebfaabf1ab9@vub.be> <59aff115$0$16748$b1db1813$d948b532@news.astraweb.com> Message-ID: <2c60a7a8-0ad6-21f7-40e6-6b9c6e44a5cd@vub.be> Op 06-09-17 om 14:58 schreef Steve D'Aprano: > On Wed, 6 Sep 2017 05:12 pm, Antoon Pardon wrote: > > [...] >>> I'm not saying that we should never use this model. Its a good model. But we >>> should be clear that it is a model of the implementation, and it describes >>> entities which are not part of the Python language. We cannot do this: >>> >>> >>> +-----+ >>> | | >>> | 5 | >>> | | >>> +-----+ >>> ^ >>> | >>> >>> ^ >>> | >>> >>> >>> >>> or any of the other things we can do in a language with references-as-values, >>> like C or Pascal. >> I don't agree that the above is an accurate picture of C or Pascal. > I'm surprised. You can do this in Pascal: > > type > intpointer = ^integer; > var > x: intpointer; > y: ^intpointer; > begin > new(x); {reserve memory in the heap for an integer, and point x at it} > x^ := 5; > y := @x; {y points to the pointer x} > end. > > which would translate to the diagram above. If you don't like the fact that I'm > using the "address of" operator @ which is non-standard Pascal, I can write > this instead: No it would not translate to the above diagram. It would translate to my diagram. All variables in pascal refer to some object (in memory), they don't refer to other variables. If you have a pointer variable, you have a variable that refers to an object that itself refers to an other object. This later object can be one that is refered to directly by another variable, like code as above. > > > type > intpointer = ^integer; > var > y: ^intpointer; > begin > new(y); {reserve memory in the heap for an intpointer, and point y at it} > new(y^); {reserve memory in the heap for an integer, and point y^ at it} > y^^ := 5; > end. > > I would be shocked if C were less powerful in this regard than Pascal. That would be result in the following diagram. +-----+ +-----+ +-----+ | | | | | | | *--+---->| *--+----->| 5 | | | | | | | +-----+ +-----+ +-----+ ^ | >> And in case of a VAR parameter in Pascal like >> >> procedure f(VAR x); >> f(y) >> >> one could use the following, which is the same >> as after an assignment in python. >> >> >> +-----+ >> | | >> | 7 | >> ---> | | >> / +-----+ >> / >> / ^ >> / | >> > No no no! Pascal VAR parameters are not the same as Python assignment! You > cannot write a Pascal swap procedure in Python! Yes it is. Pascal VAR parameters are exactly like Python a assignment. The fact that you can't write a swap procedure in Python is because the semantics of the Python assignment differs from the semantics of the Pascal assignment. Not because the VAR parameter semantics in Pascal differ from the parameter or assignment semantics in Python. The semantics of the VAR parameter in Pascal and the sematics of Python assignment are both creating a new alias for the same object or however you want to phrase it. -- Antoon Pardon From fetchinson at googlemail.com Wed Sep 6 10:14:12 2017 From: fetchinson at googlemail.com (Fetchinson .) Date: Wed, 6 Sep 2017 16:14:12 +0200 Subject: non-standard glibc location Message-ID: Hi folks, I'm trying to install a binary package (tensorflow) which contains some binary C extensions. Now my system glibc is 2.15 but the binaries in the C extensions were created (apparently) with glibc 2.17. So I thought no problemo I installed glibc 2.17 to a custom location, built python2.7 from source (hopefully using my custom glibc) and installed pip and everything else using this custom built python. But still when I try to import tensorflow I get: ImportError: /lib64/libc.so.6: version `GLIBC_2.17' not found (required by /home/nogradi/fetch/custom/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so) So apparently it's trying to use my system glibc, not the custom one. How do I tell this extension to use the custom glibc? Is it even possible? But maybe I have an even more basic issue: how do I link python not with the system glibc but with my custom glibc? Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From breamoreboy at gmail.com Wed Sep 6 10:17:34 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Wed, 6 Sep 2017 07:17:34 -0700 (PDT) Subject: No importlib in Python 3 64 bit ? In-Reply-To: <5542c8be-cc80-463c-8574-fe580f2cd3fc@googlegroups.com> References: <5542c8be-cc80-463c-8574-fe580f2cd3fc@googlegroups.com> Message-ID: On Wednesday, September 6, 2017 at 2:42:06 PM UTC+1, Andrej Viktorovich wrote: > Found that pythons have different paths. It might be related? Definitely :) > > 64 bit > > C:\Users\me\AppData\Local\Programs\Python\Python36-32 > C:\Users\me\AppData\Local\Programs\Python\Python36-32\DLLs > C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib > C:\Program Files\Python36\python36.zip > C:\Program Files\Python36\DLLs > C:\Program Files\Python36\lib > C:\Program Files\Python36 > C:\Program Files\Python36\lib\site-packages The "C:\Program..." indicates installed for all users, but you're also pulling in the 32 bit libs. Remove them from the path and you're good to go. > > 32bit > > C:\Users\me\AppData\Local\Programs\Python\Python36-32 > C:\Users\me\AppData\Local\Programs\Python\Python36-32\DLLs > C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib > C:\Users\me\AppData\Local\Programs\Python\Python36-32\python36.zip > C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\site-packages This is a good install for a single user. Kindest regards. Mark Lawrence. From ian.g.kelly at gmail.com Wed Sep 6 10:19:43 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Sep 2017 08:19:43 -0600 Subject: tictactoe script - commented - may have pedagogical value In-Reply-To: References: Message-ID: On Tue, Sep 5, 2017 at 6:15 PM, Stefan Ram wrote: > Ian Kelly writes: >>Usually I've seen Tic Tac Toe implemented using the Minimax algorithm >>since the decision tree for Tic Tac Toe is quite shallow. > > This thread made me want to write a tic-tac-toe game. > > I am na?ve in this field. I don't know what "Minimax" is. http://neverstopbuilding.com/minimax > So I just did this: I try to evaluate every possible move > and then choose the best one. > > To evaluate a move: > If I win with this move: +1 > If I lose with this move: -1 > If there are several possible continuations: > If this is not a recursive call and one of > the possible next moves of the opponent > makes me lose: -1 > Otherwise, return the average of the values > of the possible continuations > If there is no possible move: None I didn't read through your code in depth, but it sounds like you implemented Minimax. We want to maximize our score, and we assume that on the opponent's turn they will act to minimize our score, so the goal is to find the highest possible minimum score. Tic Tac Toe is great for demonstrating Minimax because the entire game tree is limited to at most 9! = 362880 possible games without doing any pruning at all. In reality it's fewer because some games end before 9 moves have been played. That makes it feasible to traverse the entire tree on an interactive time frame. For more complex games like Chess it isn't usually feasible to look all the way ahead to the end of the game, so they have to apply additional strategies like alpha-beta pruning, stored opening and endgame books, and incomplete positional evaluation. From info at wingware.com Wed Sep 6 10:33:23 2017 From: info at wingware.com (Wingware) Date: Wed, 06 Sep 2017 10:33:23 -0400 Subject: ANN: Wing Python IDE 6.0.7 released Message-ID: <59B00733.3050003@wingware.com> Hi, We've just released Wing 6.0.7, a minor release that further improves and documents remote development, adds default file encoding to remote host configuration, supports syntax highlighting for .json files, and makes about 30 other minor improvements. For details, see https://wingware.com/pub/wingide/6.0.7/CHANGELOG.txt Wing 6 is the latest major release in Wingware's family of Python IDEs, including Wing Pro, Wing Personal, and Wing 101. Wing 6 adds many new features, introduces a new annual license option for Wing Pro, and makes Wing Personal free. New Features in Wing 6 * Improved Multiple Selections: Quickly add selections and edit them all at once * Easy Remote Development: Work seamlessly on remote Linux, OS X, and Raspberry Pi systems * Debugging in the Python Shell: Reach breakpoints and exceptions in (and from) the Python Shell * Recursive Debugging: Debug code invoked in the context of stack frames that are already being debugged * PEP 484 and PEP 526 Type Hinting: Inform Wing's static analysis engine of types it cannot infer * Support for Python 3.6 and Stackless 3.4: Use async and other new language features * Optimized debugger: Run faster, particularly in multi-process and multi-threaded code * Support for OS X full screen mode: Zoom to a virtual screen, with auto-hiding menu bar * Added a new One Dark color palette: Enjoy the best dark display style yet * Updated French and German localizations: Thanks to Jean Sanchez, Laurent Fasnacht, and Christoph Heitkam For a more detailed overview of new features see the release notice at https://wingware.com/news/2017-09-05 Annual License Option Wing 6 adds the option of purchasing a lower-cost expiring annual license for Wing Pro. An annual license includes access to all available Wing Pro versions while it is valid, and then ceases to function until it is renewed. Pricing for annual licenses is US$ 179/user for Commercial Use and US$ 69/user for Non-Commercial Use. Perpetual licenses for Wing Pro will continue to be available at the same pricing. The cost of extending Support+Upgrades subscriptions on Non-Commercial Use perpetual licenses for Wing Pro has also been dropped from US$ 89 to US$ 39 per user. For details, see https://wingware.com/store/ Wing Personal is Free Wing Personal is now free and no longer requires a license to run. It now also includes the Source Browser, PyLint, and OS Commands tools, and supports the scripting API and Perspectives. However, Wing Personal does not include Wing Pro's advanced editing, debugging, testing and code management features, such as remote development, refactoring, find uses, version control, unit testing, interactive debug probe, multi-process and child process debugging, move program counter, conditional breakpoints, debug watch, framework-specific support (for Jupyter, Django, and others), find symbol in project, and other features. Links Release notice: https://wingware.com/news/2017-09-05 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 breamoreboy at gmail.com Wed Sep 6 10:36:34 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Wed, 6 Sep 2017 07:36:34 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> Message-ID: <0e5f546b-7ed8-45cd-9920-6239fdeea58f@googlegroups.com> On Wednesday, September 6, 2017 at 1:12:22 PM UTC+1, Rustom Mody wrote: > On Wednesday, September 6, 2017 at 5:08:20 PM UTC+5:30, Steve D'Aprano wrote: > > On Wed, 6 Sep 2017 07:13 pm, Rustom Mody wrote: > > > > > > > Can you explain what "id" and "is" without talking of memory? > > > > Yes. > > > > id() returns an abstract ID number which is guaranteed to be an integer, and > > guaranteed to be distinct for all objects which exist at the same time. When an > > object ceases to exist, its ID number may be re-used. > > > > `is` compares the two operands for identity. If the two operands are the same > > object, `is` returns True, if they are distinct objects, `is` returns False. > > >>> a = (1,2) > >>> b = (1,2) > >>> a is b > False > >>> x = 1 > >>> y = 1 > >>> x is y > True > > a seems to be as 'same' to b as x is to y > Python seems to think otherwise > > Evidently your ?same? is not the same as mine?? > This shows your complete ignorance of Python. One would often suggest putting the shovel down, but it is far too late for that. Kindest regards. Mark Lawrence. From ian.g.kelly at gmail.com Wed Sep 6 11:31:19 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 6 Sep 2017 09:31:19 -0600 Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: <8760cwnupl.fsf@elektro.pacujo.net> References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> <8560cwbnjm.fsf@benfinney.id.au> <8760cwnupl.fsf@elektro.pacujo.net> Message-ID: On Wed, Sep 6, 2017 at 1:37 AM, Marko Rauhamaa wrote: > > Which reminds me of this puzzle I saw a couple of days ago: > > 1 + 4 = 5 > 2 + 5 = 12 > 3 + 6 = 21 > 8 + 11 = ? > > A mathematician immediately comes up with a "wrong" answer. There are no "wrong" answers with these kinds of puzzles. There are only answers with varying degrees of parsimony with the known facts. I say the answer is clearly "banana" because the key to the puzzle is that everything matches a line from the following look-up table: 5 => 5 7 => 12 9 => 21 19 => banana From zhangyangyu0614 at gmail.com Wed Sep 6 12:11:27 2017 From: zhangyangyu0614 at gmail.com (Xiang Zhang) Date: Wed, 6 Sep 2017 09:11:27 -0700 (PDT) Subject: tool interface in Python Message-ID: <25ea4163-84fe-4bdb-8010-ea4cb6bde1ec@googlegroups.com> Is there any project in Python about tool interface? In Java, it gets JVMTI which allows users easily build tools upon it. For example, for an APM framework, it allows you use Java agent to dynamically trace functions in your application. And you don't have to modify or restart your application. Applications like VisualVM could inspect Java VM dynamically. But in Python, although I know it's already very reflective, but during work sometimes I wanna inspect the memory our Python VM uses, detect the hotspot of our application, monitoring some API call chains, I always have to restart the VM, modify the code(monkey_patch or directly introduce probes in application). So is there any project exploring the possibility in this direction? Or maybe I have missed any common strategies to achieve these functionalities? From python at mrabarnett.plus.com Wed Sep 6 12:17:52 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 6 Sep 2017 17:17:52 +0100 Subject: No importlib in Python 3 64 bit ? In-Reply-To: References: Message-ID: On 2017-09-06 14:00, Chris Angelico wrote: > On Wed, Sep 6, 2017 at 10:41 PM, Andrej Viktorovich > wrote: >> Hello, >> >> I have 32Bit and 64Bit installations on my Windows 10 machine. I do import importlib in both of them. >> >> 32bit works fine while 64bit prints error: >> >>>>> import importlib >> Traceback (most recent call last): >> File "", line 1, in >> File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\importlib\__init__.py", line 57, in >> import types >> File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\types.py", line 171, in >> import functools as _functools >> File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\functools.py", line 23, in >> from weakref import WeakKeyDictionary >> File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\weakref.py", line 12, in >> from _weakref import ( >> ImportError: cannot import name '_remove_dead_weakref' > > It appears that your 64-bit binary is trying to load up the libraries > from the 32-bit installation. How did you go about installing each > one? > > I'm not 100% sure, but I think that having two different versions of > CPython X.Y isn't supported on Windows. > I have both 64-bit and 32-bit Python 3.6 installed on Windows 10, as well as older versions. They all work without a problem. From lists at vanderhoff.org Wed Sep 6 12:18:25 2017 From: lists at vanderhoff.org (Tony van der Hoff) Date: Wed, 6 Sep 2017 17:18:25 +0100 Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> <8560cwbnjm.fsf@benfinney.id.au> <8760cwnupl.fsf@elektro.pacujo.net> Message-ID: On 06/09/17 16:31, Ian Kelly wrote: > On Wed, Sep 6, 2017 at 1:37 AM, Marko Rauhamaa wrote: >> Which reminds me of this puzzle I saw a couple of days ago: >> >> 1 + 4 = 5 >> 2 + 5 = 12 >> 3 + 6 = 21 >> 8 + 11 = ? >> >> A mathematician immediately comes up with a "wrong" answer. > There are no "wrong" answers with these kinds of puzzles. There are > only answers with varying degrees of parsimony with the known facts. > > I say the answer is clearly "banana" because the key to the puzzle is > that everything matches a line from the following look-up table: > > 5 => 5 > 7 => 12 > 9 => 21 > 19 => banana 40 From rosuav at gmail.com Wed Sep 6 12:30:31 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Sep 2017 02:30:31 +1000 Subject: No importlib in Python 3 64 bit ? In-Reply-To: References: Message-ID: On Thu, Sep 7, 2017 at 2:17 AM, MRAB wrote: > On 2017-09-06 14:00, Chris Angelico wrote: >> >> On Wed, Sep 6, 2017 at 10:41 PM, Andrej Viktorovich >> wrote: >>> >>> Hello, >>> >>> I have 32Bit and 64Bit installations on my Windows 10 machine. I do >>> import importlib in both of them. >>> >>> 32bit works fine while 64bit prints error: >>> >>>>>> import importlib >>> >>> Traceback (most recent call last): >>> File "", line 1, in >>> File >>> "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\importlib\__init__.py", >>> line 57, in >>> import types >>> File >>> "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\types.py", line >>> 171, in >>> import functools as _functools >>> File >>> "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\functools.py", >>> line 23, in >>> from weakref import WeakKeyDictionary >>> File >>> "C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib\weakref.py", line >>> 12, in >>> from _weakref import ( >>> ImportError: cannot import name '_remove_dead_weakref' >> >> >> It appears that your 64-bit binary is trying to load up the libraries >> from the 32-bit installation. How did you go about installing each >> one? >> >> I'm not 100% sure, but I think that having two different versions of >> CPython X.Y isn't supported on Windows. >> > I have both 64-bit and 32-bit Python 3.6 installed on Windows 10, as well as > older versions. They all work without a problem. Ah, that's good to know, thanks. (I knew it was fine to have 3.6 and 3.5 installed at once, just the question of two 3.6es.) ChrisA From antoon.pardon at rece.vub.ac.be Wed Sep 6 12:35:33 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Wed, 6 Sep 2017 18:35:33 +0200 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06-09-17 15:14, Stefan Ram wrote: > Steve D'Aprano writes: >> or any of the other things we can do in a language with references-as-values, >> like C or Pascal. > > I have always taken the stance that one has to use the words > as the language specification of the language one talks > about does. > But that makes it difficult to point to similar semantics in two languages, when those languages use different wording to express those semantics. -- Antoon Pardon. From tjol at tjol.eu Wed Sep 6 13:11:53 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 6 Sep 2017 19:11:53 +0200 Subject: Run python module from console In-Reply-To: <067b6060-67c3-4de5-9185-bc7b6ac6e433@googlegroups.com> References: <067b6060-67c3-4de5-9185-bc7b6ac6e433@googlegroups.com> Message-ID: <277929b7-268c-227b-f90b-6e3317dd0540@tjol.eu> On 05/09/17 17:14, Andrej Viktorovich wrote: > Hello, > > I suppose I can run python module by passing module as param for executable: > > python.exe myscr.py > > But how to run script when I'm inside of console and have python prompt: > The runpy module can help you do this. https://docs.python.org/3/library/runpy.html However, as others have hinted, if you want to run bits of Python from Python, then it's probably better to use functions. -- Thomas From rhodri at kynesim.co.uk Wed Sep 6 13:53:57 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Wed, 6 Sep 2017 18:53:57 +0100 Subject: tictactoe script - commented - may have pedagogical value In-Reply-To: References: Message-ID: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> On 06/09/17 18:16, Stefan Ram wrote: > Dennis Lee Bieber writes: >> Not to mention there are four rotations of the board, along with >> reflections... One could, internally, keep track of the rotation needed to >> normalize the first moves (eg: if a corner was the first move, rotate the >> board as needed to make that corner the top-left; evaluate all moves from >> there, and "de-rotate" the response). > > Whenever someone yells at me, ?HTML is not a programming language!?, > I show them the interactive tic-tac-toe by Flo Kreidler, written in > pure HTML: > > web.archive.org/web/20040428174214/http://www.geocities.com/flo_kreidler/tictactoe.html Presumably they stop taking you seriously at that point? -- Rhodri James *-* Kynesim Ltd From rosuav at gmail.com Wed Sep 6 13:56:42 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Sep 2017 03:56:42 +1000 Subject: tictactoe script - commented - may have pedagogical value In-Reply-To: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> References: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> Message-ID: On Thu, Sep 7, 2017 at 3:53 AM, Rhodri James wrote: > On 06/09/17 18:16, Stefan Ram wrote: >> >> Dennis Lee Bieber writes: >>> >>> Not to mention there are four rotations of the board, along with >>> reflections... One could, internally, keep track of the rotation needed >>> to >>> normalize the first moves (eg: if a corner was the first move, rotate the >>> board as needed to make that corner the top-left; evaluate all moves from >>> there, and "de-rotate" the response). >> >> >> Whenever someone yells at me, ?HTML is not a programming language!?, >> I show them the interactive tic-tac-toe by Flo Kreidler, written in >> pure HTML: >> >> >> web.archive.org/web/20040428174214/http://www.geocities.com/flo_kreidler/tictactoe.html > > > Presumably they stop taking you seriously at that point? Yes, in the same way that people stopped taking me seriously when I implemented Fizz Buzz in CSS. Though they were rather amused... ChrisA From geojitmailus at gmail.com Wed Sep 6 16:32:27 2017 From: geojitmailus at gmail.com (geojitmailus at gmail.com) Date: Wed, 6 Sep 2017 13:32:27 -0700 (PDT) Subject: Changing filenames from Greeklish => Greek (subprocess complain) In-Reply-To: <2c425f2b-99de-4453-964e-c585f2043f71@googlegroups.com> References: <2c425f2b-99de-4453-964e-c585f2043f71@googlegroups.com> Message-ID: On Saturday, June 1, 2013 at 9:14:36 PM UTC+5:30, ???????? ?????? wrote: > /home/nikos/public_html/cgi-bin/metrites.py in () > 217 template = htmldata + counter > 218 elif page.endswith('.py'): > => 219 htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' + page ) > 220 template = htmldata.decode('utf-8').replace( 'Content-type: text/html; charset=utf-8', '' ) + counter > 221 > htmldata undefined, subprocess = , subprocess.check_output = , page = 'files.py' > /opt/python3/lib/python3.3/subprocess.py in check_output(timeout=None, *popenargs=('/home/nikos/public_html/cgi-bin/files.py',), **kwargs={}) > 584 retcode = process.poll() > 585 if retcode: > => 586 raise CalledProcessError(retcode, process.args, output=output) > 587 return output > 588 > global CalledProcessError = , retcode = 1, process = , process.args = '/home/nikos/public_html/cgi-bin/files.py', output = b'Content-type: text/html; charset=utf-8\n\n\n\n' > CalledProcessError: Command '/home/nikos/public_html/cgi-bin/files.py' returned non-zero exit status 1 > args = (1, '/home/nikos/public_html/cgi-bin/files.py') > cmd = '/home/nikos/public_html/cgi-bin/files.py' > output = b'Content-type: text/html; charset=utf-8\n\n\n\n' > returncode = 1 > with_traceback = > > > The above error message happened when i tried to reanme one of my filenames from > > its greeklish name to greek charcters. > > files.py is a script that allows users to downlaod fiels form my server. > But i wish to presnt filename sin Greek and not in Greeklish > > http://superhost.gr/?page=files.py > as it is now. > > What can i do to make pth script accept greek filenames too? > Why does subprocess is complaining? From irmen.NOSPAM at xs4all.nl Wed Sep 6 17:17:17 2017 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 6 Sep 2017 23:17:17 +0200 Subject: a Boulder Dash clone with retro graphics and sound In-Reply-To: <59adcd89$0$806$e4fe514c@news.xs4all.nl> References: <59adcd89$0$806$e4fe514c@news.xs4all.nl> Message-ID: <59b065dd$0$824$e4fe514c@news.xs4all.nl> On 05/09/2017 00:02, Irmen de Jong wrote: https://github.com/irmen/bouldercaves > There's just two things missing I think: > - high score table > - being able to play multiple sounds simultaneously, as the amoeba and > magic wall sounds are lacking at the moment. In version 1.2 sound mixing is implemented so the game can now play multiple samples simultaneously, and is able to play sounds in a loop. This means it now properly plays the title screen music, and the amoeba and magic wall sounds are now also in the game. (and I fixed a magic wall behavior bug as well) Saving and displaying high scores are left as an exercise for the reader :) Irmen From ben.usenet at bsb.me.uk Wed Sep 6 18:26:10 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 06 Sep 2017 23:26:10 +0100 Subject: Please improve these comprehensions (was meaning of [ ]) References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> Message-ID: <87lglrlb0d.fsf@bsb.me.uk> Gregory Ewing writes: > Seems to me you're making life difficult for yourself (and > very inefficient) by insisting on doing the whole computation > with sets. If you want a set as a result, it's easy enough > to construct one from the list at the end. Yes, but my intent was to show that the pattern -- derived from counting choices -- transfers to the construction of choices, even when sets are used in place of lists. I was responding to what I thought was the idea that you can't work with sets in the same way. And I see I messed a place where I should have used a set but that's just stylistic. Converting the list-of-list version to a set of (frozen) sets is about twice as fast. -- Ben. From ben.usenet at bsb.me.uk Wed Sep 6 18:27:22 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 06 Sep 2017 23:27:22 +0100 Subject: Please improve these comprehensions (was meaning of [ ]) References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> <23f65d1e-6fa5-463c-9e6f-9818fd0f2fd8@googlegroups.com> Message-ID: <87a827layd.fsf@bsb.me.uk> Rustom Mody writes: > I posted it because I genuinely thought I had missed some obvious way > of splitting a set into an (arbitrary) element and a rest without > jumping through hoops. Evidently not Curious, because I posted because I thought you had. Anyway, for speed you probably just want def cs(n, r): return frozenset({frozenset(s) for s in c(n, r)}) as suggested. -- Ben. From tjreedy at udel.edu Wed Sep 6 18:42:17 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Sep 2017 18:42:17 -0400 Subject: No importlib in Python 3 64 bit ? In-Reply-To: References: Message-ID: On 9/6/2017 12:30 PM, Chris Angelico wrote: > On Thu, Sep 7, 2017 at 2:17 AM, MRAB wrote: >> On 2017-09-06 14:00, Chris Angelico wrote: >>> I'm not 100% sure, but I think that having two different versions of >>> CPython X.Y isn't supported on Windows. >>> >> I have both 64-bit and 32-bit Python 3.6 installed on Windows 10, as well as >> older versions. They all work without a problem. > > Ah, that's good to know, thanks. (I knew it was fine to have 3.6 and > 3.5 installed at once, just the question of two 3.6es.) The py launcher lets you choose py -3.6 py -3.6-32 -- Terry Jan Reedy From nad at python.org Wed Sep 6 19:52:21 2017 From: nad at python.org (Ned Deily) Date: Wed, 6 Sep 2017 16:52:21 -0700 Subject: Python 3.3.7rc1 now available prior to Python 3.3 end-of-life Message-ID: <3B07469D-32E6-4C3B-90CD-14EA0A94575D@python.org> On behalf of the Python development community and the Python 3.3 release teams, I would like to announce the availability of Python 3.3.7rc1, the release candidate of Python 3.3.7. It is a security-fix source-only release. Python 3.3.0 was released 5 years ago on 2012-09-29 and has been in security-fix-only mode since 2014-03-08. Per project policy, all support for the 3.3 series of releases ends on 2017-09-29, five years after the initial release. Therefore, Python 3.3.7 is expected to be the final release of any kind for the 3.3 series. After 2017-09-29, **we will no longer accept bug reports nor provide fixes of any kind for Python 3.3.x**; of course, third-party distributors of Python 3.3.x may choose to offer their own extended support. Because 3.3.x has long been in security-fix mode, 3.3.7 may no longer build correctly on all current operating system releases and some tests may fail. If you are still using Python 3.3.x, we **strongly** encourage you to upgrade to a more recent, fully supported version of Python 3; see https://www.python.org/downloads/. If you are still using your own build of Python 3.3.x , please report any critical issues with 3.3.7rc1 to the Python bug tracker prior to 2017-09-18, the expected release date for Python 3.3.7 final. Even better, use the time to upgrade to Python 3.6.x! Thank you to everyone who has contributed to the success of Python 3.3.x over the past years! You can find Python 3.3.7rc1 here: https://www.python.org/downloads/release/python-337rc1/ -- Ned Deily nad at python.org -- [] From steve+python at pearwood.info Wed Sep 6 20:49:29 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Sep 2017 10:49:29 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> Message-ID: <59b0979c$0$16743$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Sep 2017 10:11 pm, Rustom Mody wrote: > On Wednesday, September 6, 2017 at 5:08:20 PM UTC+5:30, Steve D'Aprano wrote: >> On Wed, 6 Sep 2017 07:13 pm, Rustom Mody wrote: >> >> >> > Can you explain what "id" and "is" without talking of memory? >> >> Yes. >> >> id() returns an abstract ID number which is guaranteed to be an integer, and >> guaranteed to be distinct for all objects which exist at the same time. When >> an object ceases to exist, its ID number may be re-used. >> >> `is` compares the two operands for identity. If the two operands are the same >> object, `is` returns True, if they are distinct objects, `is` returns False. > >>>> a = (1,2) >>>> b = (1,2) >>>> a is b > False >>>> x = 1 >>>> y = 1 >>>> x is y > True > > a seems to be as 'same' to b as x is to y > Python seems to think otherwise > > Evidently your ?same? is not the same as mine?? You are (intentionally, I think) being obtuse. I am confident that you know very well that "the same" as a general English term has many meanings, including: - same in identity ("the same man I saw yesterday"); - closely similar ("the curtains are the same colour as the carpets"); - equal ("I gave the children the same number of lollies each"); - unchanged ("his attitude is the same as ever"); - of like kind ("you are exactly the same as your mother"); while "the same object" has specifically the first meaning. How do you know that two objects are the same object? It isn't because they are equal, or that they look vaguely the same. "Equal" is not equivalent to "the same object": py> a, b = [], [] # they sure look the same... py> a == b True py> a.append(None) # insert None into a py> None in b # but they aren't the same object False The only way to find out if two objects are the same object is to ask Python -- and Python is under no obligation to comply with your na?ve intuitions about objects. As you are well aware, because we've told you many times, Python often caches objects so that they are reused rather than being recreated from scratch when needed -- and it is free to do so in implementation and version dependent ways. >> > In fact we have got so used to the term 'memory' that it actually seems >> > strange when someone like Dijkstra grumbles at the anthropomorphism and >> > asks why its not called 'store'. >> >> And if it were called "store" (grocery store? shoe store? clothes store?) >> Dijkstra would have grumbled at the metaphor and asked why it wasn't >> called "memory". > > Memory is an old (middle-English) word. > Until say 1945 it could be used in sentences like the following > ?I have memories of walking in the woods with my dad? > ?Where are the eggs?? ?Oops! Totally slipped my memory? Sorry" > ?The Dalai Lama has memories of his past lives? I don't understand why you say "until 1945". You can still use memory in those ways even today. > Are you using ?memory? in this kind of way? Yes. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 6 21:18:51 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Sep 2017 11:18:51 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> Message-ID: <59b09e7c$0$16734$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Sep 2017 11:02 pm, Stefan Ram wrote: > Chris Angelico writes: >>The 'is' operator tests if two things are the same thing. > > ?Roughly speaking, to say of two things that they are > identical is nonsense, and to say of one thing that it > is identical with itself is to say nothing at all.? > > Ludwig Wittgenstein, Tractatus Logico-Philosophicus (5.5303) "Roughly speaking". But to be more precise, it is meaningful. "Was that you yourself I saw yesterday walking down the street, or your doppelg?nger?" Or to put it another way... Was the person I saw yesterday identical (in the identity sense) to the person I am speaking to now? We don't really use "is identical" (in the identity sense) to compare "two distinct things" versus "one thing" -- we use it to compare two *operands* and don't know which situation applies until after we get the answer. If we already knew they were identical, we wouldn't need to ask. The same applies to when we are making statements rather than asking questions (making assertions about identity rather than questioning it). The point of making the assertion is to pass on information that would otherwise by ambiguous: "There is that same (identity) cat again (not merely one that looks like it)." -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 6 21:23:44 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Sep 2017 11:23:44 +1000 Subject: Please improve these comprehensions (was meaning of [ ]) References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <4c0826d4-3aef-43fc-ac0f-332af6bc783d@googlegroups.com> <176ed543-de2d-4a23-b4f1-e22bb425c03a@googlegroups.com> <873782p6gm.fsf@bsb.me.uk> <878thtuved.fsf@bsb.me.uk> <23f65d1e-6fa5-463c-9e6f-9818fd0f2fd8@googlegroups.com> Message-ID: <59b09fa0$0$16734$b1db1813$d948b532@news.astraweb.com> On Wed, 6 Sep 2017 11:08 pm, Rustom Mody wrote: > On Wednesday, September 6, 2017 at 5:59:17 PM UTC+5:30, nopsidy wrote: >> https://www.youtube.com/watch?v= [...] >> Thank you, >> -Alex Goretoy >> [...] Please don't quote nopsidy's spam. He is spamming the list with multiple links to the same video on Youtube, one which claims to prove that the world is not a moving sphere. List admins, can you please remove nopsidy's spam posts, and unsubscribe him if possible? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 6 21:27:00 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Sep 2017 11:27:00 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <5e1d04de-c509-babd-5123-eebfaabf1ab9@vub.be> <59aff115$0$16748$b1db1813$d948b532@news.astraweb.com> <2c60a7a8-0ad6-21f7-40e6-6b9c6e44a5cd@vub.be> Message-ID: <59b0a064$0$16751$b1db1813$d948b532@news.astraweb.com> On Thu, 7 Sep 2017 12:11 am, Antoon Pardon wrote: [...] > No it would not translate to the above diagram. It would translate to my > diagram. All variables in pascal refer to some object (in memory), they don't > refer to other variables. If you have a pointer variable, you have a variable > that refers to an object that itself refers to an other object. This later > object can be one that is refered to directly by another variable, like code > as above. I'm afraid that I have no idea what you are talking about -- your explanation is unclear to me. [...] > Yes it is. Pascal VAR parameters are exactly like Python a assignment. Proof by assertion? "It is true, because I say it is true!" -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 6 21:28:55 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Sep 2017 11:28:55 +1000 Subject: Please improve these comprehensions (was meaning of [ ]) References: <8fcac5ec-5b9d-4062-af8d-67a3574843be@googlegroups.com> <19fc6f41-ed73-4bf3-ac1b-c60fefaa8e96@googlegroups.com> <40dd4a62-87e4-4e8d-ac3b-0c000482ff1a@googlegroups.com> <87d176fwb4.fsf@bsb.me.uk> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> <8560cwbnjm.fsf@benfinney.id.au> <8760cwnupl.fsf@elektro.pacujo.net> Message-ID: <59b0a0d7$0$16751$b1db1813$d948b532@news.astraweb.com> On Thu, 7 Sep 2017 01:31 am, Ian Kelly wrote: > On Wed, Sep 6, 2017 at 1:37 AM, Marko Rauhamaa wrote: >> >> Which reminds me of this puzzle I saw a couple of days ago: >> >> 1 + 4 = 5 >> 2 + 5 = 12 >> 3 + 6 = 21 >> 8 + 11 = ? >> >> A mathematician immediately comes up with a "wrong" answer. > > There are no "wrong" answers with these kinds of puzzles. There are > only answers with varying degrees of parsimony with the known facts. > > I say the answer is clearly "banana" because the key to the puzzle is > that everything matches a line from the following look-up table: > > 5 => 5 > 7 => 12 > 9 => 21 > 19 => banana Well played sir! -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 6 21:32:59 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Sep 2017 11:32:59 +1000 Subject: tictactoe script - commented - may have pedagogical value References: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> Message-ID: <59b0a1cb$0$16743$b1db1813$d948b532@news.astraweb.com> On Thu, 7 Sep 2017 03:56 am, Chris Angelico wrote: > On Thu, Sep 7, 2017 at 3:53 AM, Rhodri James wrote: >> On 06/09/17 18:16, Stefan Ram wrote: [...] >>> Whenever someone yells at me, ?HTML is not a programming language!?, >>> I show them the interactive tic-tac-toe by Flo Kreidler, written in >>> pure HTML: >>> >>> >>> web.archive.org/web/20040428174214/http://www.geocities.com/flo_kreidler/tictactoe.html >> >> >> Presumably they stop taking you seriously at that point? > > Yes, in the same way that people stopped taking me seriously when I > implemented Fizz Buzz in CSS. > > Though they were rather amused... CSS is Turing complete. If they stopped taking you seriously, that speaks volumes about *them* rather than either you or CSS. I am intrigued by the (alleged?) HTML version of tic-tac-toe. Can somebody explain what it is doing and how it works? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Wed Sep 6 21:40:32 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Sep 2017 11:40:32 +1000 Subject: tictactoe script - commented - may have pedagogical value In-Reply-To: <59b0a1cb$0$16743$b1db1813$d948b532@news.astraweb.com> References: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> <59b0a1cb$0$16743$b1db1813$d948b532@news.astraweb.com> Message-ID: On Thu, Sep 7, 2017 at 11:32 AM, Steve D'Aprano wrote: > On Thu, 7 Sep 2017 03:56 am, Chris Angelico wrote: > >> On Thu, Sep 7, 2017 at 3:53 AM, Rhodri James wrote: >>> On 06/09/17 18:16, Stefan Ram wrote: > [...] >>>> Whenever someone yells at me, ?HTML is not a programming language!?, >>>> I show them the interactive tic-tac-toe by Flo Kreidler, written in >>>> pure HTML: >>>> >>>> >>>> > web.archive.org/web/20040428174214/http://www.geocities.com/flo_kreidler/tictactoe.html >>> >>> >>> Presumably they stop taking you seriously at that point? >> >> Yes, in the same way that people stopped taking me seriously when I >> implemented Fizz Buzz in CSS. >> >> Though they were rather amused... > > CSS is Turing complete. If they stopped taking you seriously, that speaks > volumes about *them* rather than either you or CSS. In terms of "how do we teach JavaScript to our students", a demonstration that you can solve the programming challenge without JS isn't *quite* the point. The point of it was proof of concept and amusement, so it's done its job even when people weren't taking the suggestion seriously. > I am intrigued by the (alleged?) HTML version of tic-tac-toe. Can somebody > explain what it is doing and how it works? Basically it's all fragment links. You click on a cell and the page jumps down or up to the board that looks like that. If you scale everything to the window size, you can make it look pretty smooth. IMO it's probably best to generate the HTML with a script. ChrisA From christopher_reimer at yahoo.com Wed Sep 6 22:24:40 2017 From: christopher_reimer at yahoo.com (Christopher Reimer) Date: Wed, 6 Sep 2017 19:24:40 -0700 Subject: Setting property for current class from property in an different class... Message-ID: <6aaa4136-cc87-8c6d-646e-3b696c5209d8@yahoo.com> Greetings, My web scraper program has a top-level class for managing the other classes. I went to set up a property for the top-level class that changes the corresponding property in a different class. class Scraper(object): ??? def __init__(self, user_id, user_name): ??????? self.requestor = Requestor(user_id, user_name) ??? @property ??? def page_start(self): ??????? return self.requestor.page_start ??? @page_start.setter ??? def page_start(self, number): ??????? self.requestor.page_start = number I get the following error for @page_start.setter when I try to run the code. ??? AttributeError: 'Scraper' object has no attribute 'requestor' That's either a bug or I'm doing it wrong. Or maybe both? Thank you, Chris R. From ofekmeister at gmail.com Wed Sep 6 22:42:37 2017 From: ofekmeister at gmail.com (ofekmeister at gmail.com) Date: Wed, 6 Sep 2017 19:42:37 -0700 (PDT) Subject: Hatch - A modern project, package, and virtual env manager In-Reply-To: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> References: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> Message-ID: <79ad5454-dd52-4906-806a-ddb6ca0dc20b@googlegroups.com> Just released https://github.com/ofek/hatch#060 From christopher_reimer at yahoo.com Thu Sep 7 00:01:41 2017 From: christopher_reimer at yahoo.com (Christopher Reimer) Date: Wed, 6 Sep 2017 21:01:41 -0700 Subject: Setting property for current class from property in an different class... In-Reply-To: References: <6aaa4136-cc87-8c6d-646e-3b696c5209d8@yahoo.com> Message-ID: <94a96abc-a2b7-756b-0ffd-bd8d38a5ebd5@yahoo.com> On 9/6/2017 7:41 PM, Stefan Ram wrote: > The following code runs here: Your code runs but that's not how I have mine code set up. Here's the revised code: class Requestor(object): ??? def __init__(self, user_id, user_name ): ??????? self._page_start = -1 ??? @property ??? def page_start(self): ??????? return self._page_start ??? @page_start.setter ??? def page_start(self, number): ??????? self._page_start = number class Scraper(object): ???? def __init__(self, user_id, user_name): ???????? self.requestor = Requestor(user_id, user_name) ???? @property ???? def page_start(self): ???????? return self.requestor.page_start ???? @page_start.setter ???? def page_start(self, number): ???????? self.requestor.page_start = number >>> test = Scraper(1, 1) >>> test.page_start Traceback (most recent call last): ? File "", line 1, in ? File "", line 20, in page_start AttributeError: 'Requestor' object has no attribute 'page_start' That's a slightly different error than what I got my code, where the Scraper object didn't have the attribute. Could it be that @property item can't call another @property item? Thank you, Chris R. From christopher_reimer at icloud.com Thu Sep 7 00:26:45 2017 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 06 Sep 2017 21:26:45 -0700 Subject: Setting property for current class from property in an different class... In-Reply-To: References: <6aaa4136-cc87-8c6d-646e-3b696c5209d8@yahoo.com> <94a96abc-a2b7-756b-0ffd-bd8d38a5ebd5@yahoo.com> Message-ID: > On Sep 6, 2017, at 9:14 PM, Stefan Ram wrote: > > I can run this (your code) without an error here (Python 3.6.0), > from a file named "Scraper1.py": I'll check tomorrow. I recently switched from 3.5.x to 3.6.1 in the PyCharm IDE. It's probably FUBAR in some obscure way. Thanks, Chris R. From viktorovichandrej at gmail.com Thu Sep 7 02:14:31 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Wed, 6 Sep 2017 23:14:31 -0700 (PDT) Subject: print without () Message-ID: <8062796f-d111-44d5-a343-658a2f7937f5@googlegroups.com> Hello, Sometimes I find code with strange print function usage. String is passed without brackets. #!/usr/bin/python list = ['physics', 'chemistry', 1997, 2000]; print "Value available at index 2 : " print list[2] list[2] = 2001; print "New value available at index 2 : " print list[2] If I use command print "aaa" in console I get error. So, why this is allowed in sample? Sample from: https://www.tutorialspoint.com/python/python_lists.htm From lists at mostrom.pp.se Thu Sep 7 02:22:04 2017 From: lists at mostrom.pp.se (Jan Erik =?utf-8?q?Mostr=C3=B6m?=) Date: Thu, 07 Sep 2017 08:22:04 +0200 Subject: print without () In-Reply-To: <8062796f-d111-44d5-a343-658a2f7937f5@googlegroups.com> References: <8062796f-d111-44d5-a343-658a2f7937f5@googlegroups.com> Message-ID: On 7 Sep 2017, at 8:14, Andrej Viktorovich wrote: > If I use command print "aaa" in console I get error. So, why this is > allowed in sample? You're probably using Python 2 for the listed script and Python 3 when you try in the console. = jem From zondo42 at gmail.com Thu Sep 7 02:26:12 2017 From: zondo42 at gmail.com (Glenn Hutchings) Date: Wed, 6 Sep 2017 23:26:12 -0700 (PDT) Subject: print without () In-Reply-To: <8062796f-d111-44d5-a343-658a2f7937f5@googlegroups.com> References: <8062796f-d111-44d5-a343-658a2f7937f5@googlegroups.com> Message-ID: <35f1afb7-d88c-4f6a-adfb-d19a0be2ca51@googlegroups.com> On Thursday, 7 September 2017 07:14:57 UTC+1, Andrej Viktorovich wrote: > Sometimes I find code with strange print function usage. String is passed without brackets. > > #!/usr/bin/python > list = ['physics', 'chemistry', 1997, 2000]; > print "Value available at index 2 : " > print list[2] > list[2] = 2001; > print "New value available at index 2 : " > print list[2] > > If I use command print "aaa" in console I get error. So, why this is allowed in sample? > > Sample from: > https://www.tutorialspoint.com/python/python_lists.htm That's because of a difference between python 2 and python 3. In python 3, print is a function (which requires brackets). In python 2 it was a keyword. The tutorial you're looking at is from python 2. From viktorovichandrej at gmail.com Thu Sep 7 02:39:31 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Wed, 6 Sep 2017 23:39:31 -0700 (PDT) Subject: remove path forever Message-ID: <13b650ad-a295-496c-8fbc-5b0c1ff886c6@googlegroups.com> Hello, I have 64 bit python on my windows 10 machine. Install contains 32 bit python libs in path and I would like to remove them. I do imprt sys sys.path.remove("C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python36-32") It works for current python instance, but paths appears in new one. How to remove paths forever? From steve+comp.lang.python at pearwood.info Thu Sep 7 03:11:37 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 07 Sep 2017 07:11:37 GMT Subject: tictactoe script - commented - may have pedagogical value References: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> <59b0a1cb$0$16743$b1db1813$d948b532@news.astraweb.com> Message-ID: <59b0f128$0$16632$b1db1813$d948b532@news.astraweb.com> On Thu, 07 Sep 2017 01:45:01 +0000, Stefan Ram wrote: > Steve D'Aprano writes: >>web.archive.org/web/20040428174214/http://www.geocities.com/ flo_kreidler/tictactoe.html >>I am intrigued by the (alleged?) HTML version of tic-tac-toe. Can >>somebody explain what it is doing and how it works? > > If you have Web access, you can paste the above archive-org URI ending > into the address bar of your Web browser to play the game and then > read the source code. > > To be clear, what you would have to paste into the address bar of a > Web browser is this line: > > web.archive.org/web/20040428174214/http://www.geocities.com/ flo_kreidler/tictactoe.html > > (If this is not possible or not working, please let me know. > I then would also be willing to explain it in the Usenet.) Thank you for the explanation Stefan, but I do know how to use a browser. What I didn't know is how the HTML works. I thought it was actually doing some computation, but it seems like its just jumping to pre-rendered tic- tac-toe grids. So if we start with the following empty grid (best viewed with a monospaced font): ?????????? ? ? ? ? ?????????? ? ? ? ? ?????????? ? ? ? ? ?????????? and you click in the centre square, it jumps to the pre-rendered ?????????? ?X ? ? ? ?????????? ?O ?O ?X ? ?????????? ? ? ? ? ?????????? I don't know why it places *two* pairs of crosses and naughts instead of one. Maybe the page is broken. But anyway... it doesn't seem to me that the page is doing any computation using HTML. It's more like a book listing a table of primes. The book hasn't done any computation, and we wouldn't say that this is proof that pieces of paper are capable of programming. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From dieter at handshake.de Thu Sep 7 03:14:46 2017 From: dieter at handshake.de (dieter) Date: Thu, 07 Sep 2017 09:14:46 +0200 Subject: non-standard glibc location References: Message-ID: <87zia7q8t5.fsf@handshake.de> "Fetchinson . via Python-list" writes: > I'm trying to install a binary package (tensorflow) which contains > some binary C extensions. Now my system glibc is 2.15 but the binaries > in the C extensions were created (apparently) with glibc 2.17. So I > thought no problemo I installed glibc 2.17 to a custom location, built > python2.7 from source (hopefully using my custom glibc) and installed > pip and everything else using this custom built python. But still when > I try to import tensorflow I get: > > ImportError: /lib64/libc.so.6: version `GLIBC_2.17' not found > (required by /home/nogradi/fetch/custom/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so) > > So apparently it's trying to use my system glibc, not the custom one. > > How do I tell this extension to use the custom glibc? Is it even possible? When you import a C extension, a variant of the linker ("ld") is used to make the linkage between the open references in the C extension and its (now) embedding environment. You can use the envvar "LD_LIBRARY_PATH" (using the typical path syntax) to tell the linker where it can look for general shared objects (such as "glibc.so"). There is also a linker command line option to tell such information when the shared object (corresponding to the C extension) is build. > But maybe I have an even more basic issue: how do I link python not > with the system glibc but with my custom glibc? Again, you could use the "LD_LIBRARY_PATH" envvar. There may be a way to specify the information also for the "configure" (generating the makefiles for the Python build process). From viktorovichandrej at gmail.com Thu Sep 7 03:48:34 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Thu, 7 Sep 2017 00:48:34 -0700 (PDT) Subject: what is payload Message-ID: <4ad4fa0e-cd61-412d-8c8f-9f5be2bad3db@googlegroups.com> Hello, Have working sample with strange property - payload: class ExampleClass(object): def __init__(self,value): print("Initialising instance...") self.payload = value exampleInstance = ExampleClass(42) print(exampleInstance.payload) Is it some default field that all objects has? What it is used for? From marko at pacujo.net Thu Sep 7 03:55:01 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 07 Sep 2017 10:55:01 +0300 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> Message-ID: <87k21blz8q.fsf@elektro.pacujo.net> Chris Angelico : > *facepalm* > > I got nothing to say to you. Then why say anything? Marko From ethernet.+NOSPAM+zero at gmail.com Thu Sep 7 03:57:54 2017 From: ethernet.+NOSPAM+zero at gmail.com (eth0) Date: Thu, 7 Sep 2017 07:57:54 -0000 (UTC) Subject: what is payload References: <4ad4fa0e-cd61-412d-8c8f-9f5be2bad3db@googlegroups.com> Message-ID: Era el Thu, 7 Sep 2017 00:48:34 -0700 (PDT) en comp.lang.python, cuando de repente Andrej Viktorovich dijo lo siguiente acerca de what is payload: > Hello, > > Have working sample with strange property - payload: > > class ExampleClass(object): > def __init__(self,value): > print("Initialising instance...") > self.payload = value > > exampleInstance = ExampleClass(42) > print(exampleInstance.payload) > > > Is it some default field that all objects has? What it is used for? > > No, it's just that Python lets you add members to your instance at runtime. In this case, that code is adding an instance variable called payload, but it's not some special property or anything. From antoon.pardon at vub.be Thu Sep 7 03:57:57 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 7 Sep 2017 09:57:57 +0200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59b0a064$0$16751$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <5e1d04de-c509-babd-5123-eebfaabf1ab9@vub.be> <59aff115$0$16748$b1db1813$d948b532@news.astraweb.com> <2c60a7a8-0ad6-21f7-40e6-6b9c6e44a5cd@vub.be> <59b0a064$0$16751$b1db1813$d948b532@news.astraweb.com> Message-ID: <2b7d1de2-1bf8-eca5-efcc-a220684f280e@vub.be> Op 07-09-17 om 03:27 schreef Steve D'Aprano: > >> Yes it is. Pascal VAR parameters are exactly like Python a assignment. > Proof by assertion? > > "It is true, because I say it is true!" I didn't just assert, I also explained. That you choose to ignore the explanation doesn't make it a proof by assertion. Calling a function/procedure with a VAR parameter in Pascal, makes the parameter an alias of the argument. Just like a python assignment makes an alias. This can be shown by the fact that if one mutates the enity through one alias, the effect can be seen through the other alias. Now the counter argument is that if you assign to the parameter in the function, this change doesn't effect the argument with which the function was called in Python. But this ignores the fact that the assignment in python doesn't mutate the entity it refers to or is bound to or whatever you want to call it. Instead it makes the parameter now refer/bound to something else. Expecting that one should be able to write a swap function should the parameters in python be like VAR parameters in Pascal is ignoring how assignment semantics in python differ from the assignment semantics in Pascal. This can be shown by writing a swap function for lists because we can simulate a mutating assignment with lists. def swap(lp1, lp2): tmp = list(lp1) lp1[:] = lp2 lp2[:] = tmp ls1 = [1, 3, 5, 7] ls2 = [0, 2, 4, 6] print(id(ls1), ls1) print(id(ls2), ls2) print("========") swap(ls1, ls2) print(id(ls1), ls1) print(id(ls2), ls2) Which on my computer produces: 140178186781768 [1, 3, 5, 7] 140178186794632 [0, 2, 4, 6] ======== 140178186781768 [0, 2, 4, 6] 140178186794632 [1, 3, 5, 7] -- Antoon Pardon. From marko at pacujo.net Thu Sep 7 03:59:38 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 07 Sep 2017 10:59:38 +0300 Subject: Please improve these comprehensions (was meaning of [ ]) References: <87d176fwb4.fsf@bsb.me.uk> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> <8560cwbnjm.fsf@benfinney.id.au> <8760cwnupl.fsf@elektro.pacujo.net> Message-ID: <87fubzlz11.fsf@elektro.pacujo.net> Dennis Lee Bieber : > On Wed, 06 Sep 2017 10:37:42 +0300, Marko Rauhamaa > declaimed the following: > >> >>Which reminds me of this puzzle I saw a couple of days ago: >> >> 1 + 4 = 5 >> 2 + 5 = 12 >> 3 + 6 = 21 >> 8 + 11 = ? >> >>A mathematician immediately comes up with a "wrong" answer. >> > > I'm coming up with "96", on the basis that the "+" is a > placeholder for a non-standard operation That's a mathematician's "wrong" answer. Stefan Ram's answer is the intended one. Marko From rosuav at gmail.com Thu Sep 7 04:05:18 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Sep 2017 18:05:18 +1000 Subject: tictactoe script - commented - may have pedagogical value In-Reply-To: <59b0f128$0$16632$b1db1813$d948b532@news.astraweb.com> References: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> <59b0a1cb$0$16743$b1db1813$d948b532@news.astraweb.com> <59b0f128$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: On Thu, Sep 7, 2017 at 5:11 PM, Steven D'Aprano wrote: > Thank you for the explanation Stefan, but I do know how to use a browser. > > What I didn't know is how the HTML works. I thought it was actually doing > some computation, but it seems like its just jumping to pre-rendered tic- > tac-toe grids. That's all HTML is capable of. Without assistance, HTML is nothing more than layouts. > > I don't know why it places *two* pairs of crosses and naughts instead of > one. Maybe the page is broken. I think it is, as part of being on the Internet Archive. To get a working version of the game, you may need to download it locally and clean it up a bit. > But anyway... it doesn't seem to me that the page is doing any > computation using HTML. It's more like a book listing a table of primes. > The book hasn't done any computation, and we wouldn't say that this is > proof that pieces of paper are capable of programming. Correct; however, with something this small, the difference isn't significant. What, ultimately, is the difference between a live-rendered image and a static photo? For the ability to brag that a fully-playable game requires nothing more than HTML, I think this minor cheat is worth it. It's gimmicky and cute, rather than being any sort of "hey look, HTML is a programming language" thing. ChrisA From rosuav at gmail.com Thu Sep 7 04:07:39 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Sep 2017 18:07:39 +1000 Subject: Please improve these comprehensions (was meaning of [ ]) In-Reply-To: <87fubzlz11.fsf@elektro.pacujo.net> References: <87d176fwb4.fsf@bsb.me.uk> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> <8560cwbnjm.fsf@benfinney.id.au> <8760cwnupl.fsf@elektro.pacujo.net> <87fubzlz11.fsf@elektro.pacujo.net> Message-ID: On Thu, Sep 7, 2017 at 5:59 PM, Marko Rauhamaa wrote: > Dennis Lee Bieber : > >> On Wed, 06 Sep 2017 10:37:42 +0300, Marko Rauhamaa >> declaimed the following: >> >>> >>>Which reminds me of this puzzle I saw a couple of days ago: >>> >>> 1 + 4 = 5 >>> 2 + 5 = 12 >>> 3 + 6 = 21 >>> 8 + 11 = ? >>> >>>A mathematician immediately comes up with a "wrong" answer. >>> >> >> I'm coming up with "96", on the basis that the "+" is a >> placeholder for a non-standard operation > > That's a mathematician's "wrong" answer. Stefan Ram's answer is the > intended one. Ian's answer has better justification. I'm going to support "banana". ChrisA From frank at chagford.com Thu Sep 7 04:09:17 2017 From: frank at chagford.com (Frank Millman) Date: Thu, 7 Sep 2017 10:09:17 +0200 Subject: what is payload In-Reply-To: <4ad4fa0e-cd61-412d-8c8f-9f5be2bad3db@googlegroups.com> References: <4ad4fa0e-cd61-412d-8c8f-9f5be2bad3db@googlegroups.com> Message-ID: "Andrej Viktorovich" wrote in message news:4ad4fa0e-cd61-412d-8c8f-9f5be2bad3db at googlegroups.com... > > Hello, > > Have working sample with strange property - payload: > > class ExampleClass(object): > def __init__(self,value): > print("Initialising instance...") > self.payload = value > > exampleInstance = ExampleClass(42) > print(exampleInstance.payload) > > Is it some default field that all objects has? What it is used for? > It is not a default field. It is explicitly created in the line 'self.payload = value' I think they are trying to show you that when you create your own class, you can give it any attributes you like, and call them whatever you like. If you changed 'payload' in the above to 'xyz', it would work exactly the same. Frank Millman From leamhall at gmail.com Thu Sep 7 05:20:56 2017 From: leamhall at gmail.com (Leam Hall) Date: Thu, 7 Sep 2017 05:20:56 -0400 Subject: Design: method in class or general function? Message-ID: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> OOP newbie on Python 2.6. I create instances of Character class with an attribute dict of 'skills'. The 'skills' dict has the name of a skill as the key and an int as a value. The code adds or modifies skills before outputting the Character. Is it better design to have a Character.method that takes a 'skill' key and optional value or to have a general function that takes an instance, a dict, a key, and an optional value? From viktorovichandrej at gmail.com Thu Sep 7 06:57:20 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Thu, 7 Sep 2017 03:57:20 -0700 (PDT) Subject: Why do we nned both - __init__() and __new__() Message-ID: <437bea63-c8a3-49fb-a6b1-31961ba5e8c7@googlegroups.com> Hello For my understanding both - __init__() and __new__() works like constructors. And __new__() looks is closer to constructor. __init__() is more for variable initialization. Why I can't just initialize in __init__() ? class ExampleClass(object): def __new__(cls,value): print("creating new instance with val %s" % (value,) ) instance = super(ExampleClass,cls).__new__(cls) return instance def __init__(self, value): print("Initialising instance... with val %s" % (value,)) self.payload = value exampleInstance = ExampleClass(42) print(exampleInstance.payload) From ben.usenet at bsb.me.uk Thu Sep 7 06:59:10 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Thu, 07 Sep 2017 11:59:10 +0100 Subject: Please improve these comprehensions (was meaning of [ ]) References: <87d176fwb4.fsf@bsb.me.uk> <3a1be1e0-22fc-4f72-8922-c2dab10fbcf4@googlegroups.com> <59af47d8$0$16728$b1db1813$d948b532@news.astraweb.com> <8560cwbnjm.fsf@benfinney.id.au> <8760cwnupl.fsf@elektro.pacujo.net> <87fubzlz11.fsf@elektro.pacujo.net> Message-ID: <87y3pqkc5d.fsf@bsb.me.uk> Chris Angelico writes: > On Thu, Sep 7, 2017 at 5:59 PM, Marko Rauhamaa wrote: >> Dennis Lee Bieber : >> >>> On Wed, 06 Sep 2017 10:37:42 +0300, Marko Rauhamaa >>> declaimed the following: >>> >>>> >>>>Which reminds me of this puzzle I saw a couple of days ago: >>>> >>>> 1 + 4 = 5 >>>> 2 + 5 = 12 >>>> 3 + 6 = 21 >>>> 8 + 11 = ? >>>> >>>>A mathematician immediately comes up with a "wrong" answer. >>> >>> I'm coming up with "96", on the basis that the "+" is a >>> placeholder for a non-standard operation >> >> That's a mathematician's "wrong" answer. Stefan Ram's answer is the >> intended one. > > Ian's answer has better justification. I'm going to support "banana". Solving puzzles like this should come with a pleasing "ah!" moment which usually comes from finding a simple rule or explanation. An arbitrary answer is always possible, but it is rarely a rule, and although arbitrary rules are also possible, they will rarely be simple. (On average a rule will need at least as many symbols to be described as the puzzle itself[1].) The trouble with this puzzle is that has at least two answers that are simple rules and, to my mind, neither has a pleasing "ah!" associated with it. [1] Obviously this is not formal but it could be made so by reference to algorithmic complexity. -- Ben. From rustompmody at gmail.com Thu Sep 7 07:09:04 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 7 Sep 2017 04:09:04 -0700 (PDT) Subject: Why do we nned both - __init__() and __new__() In-Reply-To: <437bea63-c8a3-49fb-a6b1-31961ba5e8c7@googlegroups.com> References: <437bea63-c8a3-49fb-a6b1-31961ba5e8c7@googlegroups.com> Message-ID: On Thursday, September 7, 2017 at 4:27:48 PM UTC+5:30, Andrej Viktorovich wrote: > Hello > > For my understanding both - __init__() and __new__() works like constructors. And __new__() looks is closer to constructor. __init__() is more for variable initialization. Why I can't just initialize in __init__() ? > > class ExampleClass(object): > def __new__(cls,value): > print("creating new instance with val %s" % (value,) ) > instance = super(ExampleClass,cls).__new__(cls) > return instance > def __init__(self, value): > print("Initialising instance... with val %s" % (value,)) > self.payload = value > > exampleInstance = ExampleClass(42) > print(exampleInstance.payload) If you are not sure, forget about __new__ __init__ is the one you need mostly [Ive never used new (in Python); C++ is a different case altogether] See https://mail.python.org/pipermail/tutor/2008-April/061424.html and further thread From eryksun at gmail.com Thu Sep 7 07:34:47 2017 From: eryksun at gmail.com (eryk sun) Date: Thu, 7 Sep 2017 06:34:47 -0500 Subject: remove path forever In-Reply-To: <13b650ad-a295-496c-8fbc-5b0c1ff886c6@googlegroups.com> References: <13b650ad-a295-496c-8fbc-5b0c1ff886c6@googlegroups.com> Message-ID: On Thu, Sep 7, 2017 at 1:39 AM, Andrej Viktorovich wrote: > > I have 64 bit python on my windows 10 machine. Install contains 32 bit python libs in path > and I would like to remove them. > > I do > imprt sys > sys.path.remove("C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python36-32") > > It works for current python instance, but paths appears in new one. How to remove paths forever? Probably you have the Python36-32 directories set in PYTHONPATH. For some reason some people think they need to add standard directories to this environment variable, which is something you should never do. From steve+python at pearwood.info Thu Sep 7 08:07:38 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Sep 2017 22:07:38 +1000 Subject: tictactoe script - commented - may have pedagogical value References: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> <59b0a1cb$0$16743$b1db1813$d948b532@news.astraweb.com> <59b0f128$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: <59b1368c$0$16725$b1db1813$d948b532@news.astraweb.com> On Thu, 7 Sep 2017 06:05 pm, Chris Angelico wrote: > On Thu, Sep 7, 2017 at 5:11 PM, Steven D'Aprano > wrote: >> Thank you for the explanation Stefan, but I do know how to use a browser. >> >> What I didn't know is how the HTML works. I thought it was actually doing >> some computation, but it seems like its just jumping to pre-rendered tic- >> tac-toe grids. > > That's all HTML is capable of. Without assistance, HTML is nothing > more than layouts. That's what I thought, but then Stefan introduced this as if it were a refutation: "Whenever someone yells at me, ?HTML is not a programming language!?, I show them the interactive tic-tac-toe by Flo Kreidler, written in pure HTML" but it turns out it isn't a refutation, its just a simple trick. [...] >> But anyway... it doesn't seem to me that the page is doing any >> computation using HTML. It's more like a book listing a table of primes. >> The book hasn't done any computation, and we wouldn't say that this is >> proof that pieces of paper are capable of programming. > > Correct; however, with something this small, the difference isn't > significant. What, ultimately, is the difference between a > live-rendered image and a static photo? A lot. That's why it took significantly more than a century of technological development to go from the first static photos to systems able to render photo-realistic images. And we still can't do that rendering in real-time, except for the simplest, least realistic images. (The oldest surviving permanent photographic image dates back to 1827 or so.) As a practical technique, naturally using a lookup table of pre-computed values is a good solution to many problems. But you cannot say you are performing general computation if *all* you do is a lookup. > For the ability to brag that a > fully-playable game requires nothing more than HTML, I think this > minor cheat is worth it. It's gimmicky and cute, rather than being any > sort of "hey look, HTML is a programming language" thing. Which is what I thought it was. I thought I had learned something new, but it turned out I was right again :-( -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Sep 7 08:16:07 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Sep 2017 22:16:07 +1000 Subject: Design: method in class or general function? References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> Message-ID: <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> On Thu, 7 Sep 2017 07:20 pm, Leam Hall wrote: > OOP newbie on Python 2.6. Python 2.6 is ancient, and is missing many nice features. You should consider using the latest version, 3.6. > I create instances of Character class with an attribute dict of > 'skills'. The 'skills' dict has the name of a skill as the key and an > int as a value. The code adds or modifies skills before outputting the > Character. > > Is it better design to have a Character.method that takes a 'skill' key > and optional value or to have a general function that takes an instance, > a dict, a key, and an optional value? I'm afraid your example is too generic for me to give an opinion. Do you literally mean a method called "method"? What does it do? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Sep 7 08:19:00 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 07 Sep 2017 22:19:00 +1000 Subject: Why do we nned both - __init__() and __new__() References: <437bea63-c8a3-49fb-a6b1-31961ba5e8c7@googlegroups.com> Message-ID: <59b13936$0$16747$b1db1813$d948b532@news.astraweb.com> On Thu, 7 Sep 2017 08:57 pm, Andrej Viktorovich wrote: > Hello > > For my understanding both - __init__() and __new__() works like constructors. > And __new__() looks is closer to constructor. __init__() is more for variable > initialization. Why I can't just initialize in __init__() ? Because if your object is immutable, by the time __init__ is called, the object is already frozen and you cannot initialise it. Most of the time, just use __init__. You will soon realise when you need __new__, and then you can worry about it. I've been using Python for two decades, and I think I can count the number of times I've used __new__ on the fingers of one hand. Maybe two hands. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Thu Sep 7 08:21:58 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Sep 2017 22:21:58 +1000 Subject: tictactoe script - commented - may have pedagogical value In-Reply-To: <59b1368c$0$16725$b1db1813$d948b532@news.astraweb.com> References: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> <59b0a1cb$0$16743$b1db1813$d948b532@news.astraweb.com> <59b0f128$0$16632$b1db1813$d948b532@news.astraweb.com> <59b1368c$0$16725$b1db1813$d948b532@news.astraweb.com> Message-ID: On Thu, Sep 7, 2017 at 10:07 PM, Steve D'Aprano wrote: > On Thu, 7 Sep 2017 06:05 pm, Chris Angelico wrote: > >> On Thu, Sep 7, 2017 at 5:11 PM, Steven D'Aprano >> wrote: >>> Thank you for the explanation Stefan, but I do know how to use a browser. >>> >>> What I didn't know is how the HTML works. I thought it was actually doing >>> some computation, but it seems like its just jumping to pre-rendered tic- >>> tac-toe grids. >> >> That's all HTML is capable of. Without assistance, HTML is nothing >> more than layouts. > > That's what I thought, but then Stefan introduced this as if it were a > refutation: > > "Whenever someone yells at me, ?HTML is not a programming language!?, > I show them the interactive tic-tac-toe by Flo Kreidler, written in > pure HTML" > > > but it turns out it isn't a refutation, its just a simple trick. Oh right. Yep. You're absolutely right that it's not a refutation - though it is somewhat cool, like when I first met some of the HTML5 and CSS3 features that take over jobs that traditionally have been done with JavaScript. And there's still more to do in that area - check out "position: sticky", for instance. >> Correct; however, with something this small, the difference isn't >> significant. What, ultimately, is the difference between a >> live-rendered image and a static photo? > > A lot. > > That's why it took significantly more than a century of technological > development to go from the first static photos to systems able to render > photo-realistic images. And we still can't do that rendering in real-time, > except for the simplest, least realistic images. > > (The oldest surviving permanent photographic image dates back to 1827 or so.) > > As a practical technique, naturally using a lookup table of pre-computed values > is a good solution to many problems. But you cannot say you are performing > general computation if *all* you do is a lookup. Right, exactly - but my point is that the end result is often indistinguishable. How do you calculate the sine of an angle? You evaluate an infinite series until you're satisfied with your accuracy... or you look up a table of sines. I learned how to use a four-figure table in my school years, but learning how to actually calculate them was never important. >> For the ability to brag that a >> fully-playable game requires nothing more than HTML, I think this >> minor cheat is worth it. It's gimmicky and cute, rather than being any >> sort of "hey look, HTML is a programming language" thing. > > Which is what I thought it was. I thought I had learned something new, but it > turned out I was right again :-( Yep. :-( ChrisA From ben+python at benfinney.id.au Thu Sep 7 08:29:38 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 07 Sep 2017 22:29:38 +1000 Subject: Why do we nned both - __init__() and __new__() References: <437bea63-c8a3-49fb-a6b1-31961ba5e8c7@googlegroups.com> Message-ID: <858thqadzh.fsf@benfinney.id.au> Andrej Viktorovich writes: > For my understanding both - __init__() and __new__() works like > constructors. Not true, they work quite differently and have very different jobs. > And __new__() looks is closer to constructor. __init__() is more for > variable initialization. That's right. The class's ?__new__? method ? note that it is a class method, it takes the class as its first parameter ? is the constructor. It constructs a new instance, and its return value is that instance. The instance's ?__init__? method ? note that it is an instance method, it takes the already-constructed instance as its first parameter ? is the initialiser. It acts on the existing instance, setting it up for its initial state, and its return value is None. > Why I can't just initialize in __init__() ? You can. You should. What leads you to believe otherwise? > class ExampleClass(object): > def __new__(cls,value): > print("creating new instance with val %s" % (value,) ) > instance = super(ExampleClass,cls).__new__(cls) > return instance > def __init__(self, value): > print("Initialising instance... with val %s" % (value,)) > self.payload = value Yes, those look fine (but for new code you should be using Python 3, which allows you to write ?instance = super().__new__()?). -- \ ?Our urge to trust our senses overpowers what our measuring | `\ devices tell us about the actual nature of reality.? ?Ann | _o__) Druyan, _Cosmos_, 2014 | Ben Finney From ben+python at benfinney.id.au Thu Sep 7 08:34:21 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 07 Sep 2017 22:34:21 +1000 Subject: Design: method in class or general function? References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> Message-ID: <854lseadrm.fsf@benfinney.id.au> Steve D'Aprano writes: > On Thu, 7 Sep 2017 07:20 pm, Leam Hall wrote: > > > OOP newbie on Python 2.6. > > Python 2.6 is ancient, and is missing many nice features. You should > consider using the latest version, 3.6. Another, more compelling, reason to follow that advice: Python 2 is in maintenance-only mode and will receive no support at all in a few years. It is a dead end. Python 3 is actively developed and will be supported indefinitely. Beginners today should prefer Python 3 unless they know that they must remain on older versions, and even then should correct whatever is keeping them from moving to the actively-developed language. -- \ ?Dvorak users of the world flgkd!? ?Kirsten Chevalier, | `\ rec.humor.oracle.d | _o__) | Ben Finney From marko at pacujo.net Thu Sep 7 08:41:42 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 07 Sep 2017 15:41:42 +0300 Subject: Design: method in class or general function? References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <854lseadrm.fsf@benfinney.id.au> Message-ID: <87mv66llyx.fsf@elektro.pacujo.net> Ben Finney : > Another, more compelling, reason to follow that advice: Python 2 is in > maintenance-only mode and will receive no support at all in a few > years. It is a dead end. > > Python 3 is actively developed and will be supported indefinitely. This reminds me of the Biblical story of the major refactoring of humanity at Noah's time. God ended up regretting the upheaval and promised never to make such a backward-incompatible change again: and the Lord said in his heart, I will not again curse the ground any more for man's sake; for the imagination of man's heart is evil from his youth; neither will I again smite any more every thing living, as I have done. Marko From leamhall at gmail.com Thu Sep 7 09:18:09 2017 From: leamhall at gmail.com (leam hall) Date: Thu, 7 Sep 2017 09:18:09 -0400 Subject: Design: method in class or general function? In-Reply-To: <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> Message-ID: On Thu, Sep 7, 2017 at 8:16 AM, Steve D'Aprano wrote: > On Thu, 7 Sep 2017 07:20 pm, Leam Hall wrote: > > > OOP newbie on Python 2.6. > > Python 2.6 is ancient, and is missing many nice features. You should > consider > using the latest version, 3.6. > I've wrestled with that discussion for a while and Python 3 loses every time. There's literally no good reason for me to move to Python 3 earlier than mid-2020's. Please accept the fact that there are hundreds of thousands of servers, if not millions, running Python 2.x. Whether or not Python 3 has any neat cool stuff is irrelevant to those of us seeking to use Python to get today's work done. > I create instances of Character class with an attribute dict of > > 'skills'. The 'skills' dict has the name of a skill as the key and an > > int as a value. The code adds or modifies skills before outputting the > > Character. > > > > Is it better design to have a Character.method that takes a 'skill' key > > and optional value or to have a general function that takes an instance, > > a dict, a key, and an optional value? > > I'm afraid your example is too generic for me to give an opinion. Do you > literally mean a method called "method"? What does it do? > Using this: https://github.com/makhidkarun/py_tools/blob/master/lib/character.py Line 19 sets "self.skills" either from the passed in data or from https://github.com/makhidkarun/py_tools/blob/master/lib/character_tools.py#L34-L48 So Character.skills is a dict with a string key and an int value. I need to be able to add skills and my first attempt is a function: https://github.com/makhidkarun/py_tools/blob/master/lib/character_tools.py#L52-L56 Should the "add_skills" function be a method in the character class or be made a more generic function to add/modify a key/value pair in a dict that is an attribute of an instance? Other tasks will require the add/modify functionality but coding that increases complexity. At least for me, anyway. Sorry about being unclear earlier, coffee was still kicking in and I'm still a newbie that mixes up terms. Leam From greg.ewing at canterbury.ac.nz Thu Sep 7 09:21:36 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Sep 2017 01:21:36 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> Message-ID: Rustom Mody wrote: > I said: In that case please restate the definition of 'is' from the manual which > invokes the notion of 'memory' without bringing in memory. I don't know whether it's in the manual, but at least for mutable objects, there is a way to define the notion of "same object" that doesn't require talking about "memory": Two names refer to the same object if and only if mutations made through one are visible through the other. Python has definite rules concerning when mutable objects will be the same or not, and every correct implementation must conform to them. In that sense it's a fundamental concept that doesn't depend on implementation. There is more leeway when it comes to immutable objects; implementations are free to cache and re-use them, so well-written code avoids depending on the result of "is" for immutable objects. -- Greg From majamani007 at gmail.com Thu Sep 7 09:28:50 2017 From: majamani007 at gmail.com (Rockzers) Date: Thu, 7 Sep 2017 06:28:50 -0700 (PDT) Subject: In ports of a log file, how to detect if the ports are dangerous using python? Message-ID: <23139f56-b1a2-48db-8a5b-7740a4e640e7@googlegroups.com> I know basic python and I have a log file, also I have print the output of ports from the log file which there are so many ports in the output. I want to know how to take only the dangerous ports from the printed ports - Also I need to take the IP addresses from the dangerous ports - Finally how to know if the IP addresses are local IP or global IP import os from collections import Counter asc_order = [] def openfile(filename): if os.path.exists(filename): return open(filename, "r").read() else: return None def parselog(logline): c = logline.split(" ") r = {} i = -1 for var in c: i += 1 if i == 1: a = var.split("\t") for el in a: if el.startswith("date="): r["date"] = el.split("=")[1] elif i > 1: v = var.split("=", 1) try: r[v[0]] = v[1].strip("\"") except: pass return r def splitline(logall): c = logall.split("\n") r = [] for el in c: r.append(el.strip("\r")) return r def main(): f = openfile("/Users/angelin/Desktop/new sec/2017-04-18_010.082.012.003.txt") if f is None: print("File not found") return s = splitline(f) counts = {} for el in s: if len(el) > 50: p = parselog(el) if "dstport" in p: # increment counter if p["dstport"] in counts: counts[str(p["dstport"])] += 1 else: counts[str(p["dstport"])] = 1 asc_order.append(p["dstport"]) ascending = map(int, asc_order) ascending.sort() for port in ascending: print ("Dest Port : %d" % port) print "" k = map(int, counts.keys()) k.sort() sorted(k, key=counts.get) y = sorted(counts.items(), key=lambda x: x[1], reverse=True) for x, z in y: print ('Dest Port %s Count: %s' % (x, z)) if __name__ == "__main__": main() example log file 2017-04-17 00:00:00 Local7.Info 10.82.12.3 date=2017-04-16 time=23:59:59 devname=IDS-DC14-001 devid=FGT90D3Z15018997 logid=1059028704 type=utm subtype=app-ctrl eventtype=app-ctrl-all level=information vd=root appid=27946 user="" srcip=10.80.10.249 srcport=9170 srcintf="wan1" dstip=208.91.112.198 dstport=53 dstintf="wan1" profiletype="applist" proto=17 service="DNS" policyid=3 sessionid=39717767 applist="sniffer-profile" appcat="Cloud.IT" app="Fortiguard.Search" action=pass msg="Cloud.IT: Fortiguard.Search," apprisk=medium From ben+python at benfinney.id.au Thu Sep 7 09:31:00 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 07 Sep 2017 23:31:00 +1000 Subject: Design: method in class or general function? References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> Message-ID: <85zia68wkr.fsf@benfinney.id.au> leam hall writes: > I've wrestled with that discussion for a while and Python 3 loses every > time. The context of the thread you started was that you are a *newcomer* to Python. Now you say you've considered Python 2 versus Python 3 many times? What explains that apparent contradiction? > There's literally no good reason for me to move to Python 3 earlier > than mid-2020's. Please accept the fact that there are hundreds of > thousands of servers, if not millions, running Python 2.x. The servers can continue to run Python 2.x to support existing programs. That doesn't go against the advice given. The advice is that Python 3 is today the best choice for a Python *newcomer*, and for writing *new* code such as in the example which started this thread. > Whether or not Python 3 has any neat cool stuff is irrelevant to those > of us seeking to use Python to get today's work done. If today's work *only* involves maintaining existing Python 2 legacy programs, go right ahead. That role will only shrink, though, so it's not a good thing to learn today. For people learning Python, or for writing new programs in Python, it is best to avoid the dead-end Python 2 altogether and use the current version of Python 3. -- \ ?My interest is in the future, as I am going to spend the rest | `\ of my life there.? ?Charles F. Kettering | _o__) | Ben Finney From greg.ewing at canterbury.ac.nz Thu Sep 7 09:37:25 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Sep 2017 01:37:25 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59aff115$0$16748$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <5e1d04de-c509-babd-5123-eebfaabf1ab9@vub.be> <59aff115$0$16748$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > I think that these two increment procedures will be (more or less?) equivalent: > > procedure increment(var n: integer); > begin > n := n + 1 > end; > > procedure increment2(p: intpointer); > begin > p^ := p^ + 1 > end; They are, with the proviso that, in standard Pascal, increment2 can only be applied to a heap-allocated instance of intpointer, whereas increment can be applied to any variable of type integer. -- Greg From ian.g.kelly at gmail.com Thu Sep 7 10:00:44 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Sep 2017 08:00:44 -0600 Subject: tictactoe script - commented - may have pedagogical value In-Reply-To: References: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> <59b0a1cb$0$16743$b1db1813$d948b532@news.astraweb.com> <59b0f128$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: On Thu, Sep 7, 2017 at 2:05 AM, Chris Angelico wrote: > On Thu, Sep 7, 2017 at 5:11 PM, Steven D'Aprano >> I don't know why it places *two* pairs of crosses and naughts instead of >> one. Maybe the page is broken. > > I think it is, as part of being on the Internet Archive. To get a > working version of the game, you may need to download it locally and > clean it up a bit. I was also very confused at first. I found that you need to hide the Internet Archive header because it covers the current board. It is also surprising in that the player's move is recorded with 'O' despite going first, which is contrary to the conventions of the game. From ian.g.kelly at gmail.com Thu Sep 7 10:16:31 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 7 Sep 2017 08:16:31 -0600 Subject: tictactoe script - commented - may have pedagogical value In-Reply-To: References: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> <59b0a1cb$0$16743$b1db1813$d948b532@news.astraweb.com> <59b0f128$0$16632$b1db1813$d948b532@news.astraweb.com> <59b1368c$0$16725$b1db1813$d948b532@news.astraweb.com> Message-ID: On Thu, Sep 7, 2017 at 6:21 AM, Chris Angelico wrote: > On Thu, Sep 7, 2017 at 10:07 PM, Steve D'Aprano > wrote: >> As a practical technique, naturally using a lookup table of pre-computed values >> is a good solution to many problems. But you cannot say you are performing >> general computation if *all* you do is a lookup. > > Right, exactly - but my point is that the end result is often > indistinguishable. How do you calculate the sine of an angle? You > evaluate an infinite series until you're satisfied with your > accuracy... or you look up a table of sines. I learned how to use a > four-figure table in my school years, but learning how to actually > calculate them was never important. If this were a Python program using a tree of pre-computed states and merely selecting between child nodes based on player input as opposed to actively determining the best move for the current state, would you also argue that that is not programmed? I'm reminded of a fully analog dogfight simulator I once played. All there was to it was a red book and a blue book for the two players. Each player takes one of the books and turns to page 1, which shows an illustration of a heads-up display with the enemy jet somewhere in view and a radar display and other pertinent information. Each player decides how they will react, and then the system tells each player which page to turn to. Effectively, it's a two-player choose your own adventure; or from another perspective, a state machine with two inputs. On paper, would you assert that this state machine is not programmed, yet put it too into a Python program and suddenly it is? Nobody would claim that Babbage's difference engine was capable of general computation, yet we can still talk about "programming" it in its operation. It seems to me that HTML is in a similar position. From anubhav.yadav at gmx.com Thu Sep 7 10:20:50 2017 From: anubhav.yadav at gmx.com (Anubhav Yadav) Date: Thu, 7 Sep 2017 19:50:50 +0530 Subject: How to create an object in database only if the database is not there? Message-ID: Hi, I am using `pony` orm to write a simple class as my model. Here is the class. ``` from pony.orm import Database from pony.orm import Required, Optional from pony.orm import db_session from pony.orm import select, commit DB_PATH = ?db.sqlite? db = Database() class Course(db.Entity): """ A class to represent a course """ title = Required(str, unique=True) url = Optional(str, unique=True) thumbnail = Optional(str) processed = Optional(bool, default=False) db.bind(provider='sqlite', filename=DB_PATH, create_db=True) db.generate_mapping(create_tables=True) ``` Now when I create a Course object like this: >>> Course(title=?A new course?) An object is create in the database. I don?t want to have this behaviour, but what I want to be doing is create a Course object and then only commit in the database if the course is not already available in the database. If the course is already in the database, the orm should just return the same object. I have implemented the requirement as follows: ``` class Course(db.Entity): """ A class to represent a course """ title = Required(str, unique=True) url = Optional(str, unique=True) thumbnail = Optional(str) processed = Optional(bool, default=False) @staticmethod @db_session def new(title, url=None, thumbnail=None, processed=False): """Return a Course either new or from database""" course = select(c for c in Course if c.title == title)[:] if course: return course[0] return Course(title=title, url=url, thumbnail=thumbnail, processed=processed) db.bind(provider='sqlite', filename=DB_PATH, create_db=True) db.generate_mapping(create_tables=True) ``` Can there be a better method of doing that? Please let me know. Thanks. ? You are not born knowing everything. You go on learning? - Anubhav Yadav From grant.b.edwards at gmail.com Thu Sep 7 10:22:54 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 7 Sep 2017 14:22:54 +0000 (UTC) Subject: tictactoe script - commented - may have pedagogical value References: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> <59b0a1cb$0$16743$b1db1813$d948b532@news.astraweb.com> <59b0f128$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-09-07, Ian Kelly wrote: > On Thu, Sep 7, 2017 at 2:05 AM, Chris Angelico wrote: >> On Thu, Sep 7, 2017 at 5:11 PM, Steven D'Aprano >>> I don't know why it places *two* pairs of crosses and naughts instead of >>> one. Maybe the page is broken. >> >> I think it is, as part of being on the Internet Archive. To get a >> working version of the game, you may need to download it locally and >> clean it up a bit. > > I was also very confused at first. I found that you need to hide the > Internet Archive header because it covers the current board. Yea, that. Embarassingly, I played with it for a couple minutes yesterday and thought it was broken because I didn't realize that popup was covering the only board I was supposed to pay attention to. > It is also surprising in that the player's move is recorded with 'O' > despite going first, which is contrary to the conventions of the > game. I assumed that was a regional thing. -- Grant Edwards grant.b.edwards Yow! You mean you don't at want to watch WRESTLING gmail.com from ATLANTA? From viktorovichandrej at gmail.com Thu Sep 7 10:25:22 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Thu, 7 Sep 2017 07:25:22 -0700 (PDT) Subject: remove path forever In-Reply-To: References: <13b650ad-a295-496c-8fbc-5b0c1ff886c6@googlegroups.com> Message-ID: On Thursday, 7 September 2017 14:35:58 UTC+3, eryk sun wrote: > On Thu, Sep 7, 2017 at 1:39 AM, Andrej Viktorovich > wrote: > > > > I have 64 bit python on my windows 10 machine. Install contains 32 bit python libs in path > > and I would like to remove them. > > > > I do > > imprt sys > > sys.path.remove("C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python36-32") > > > > It works for current python instance, but paths appears in new one. How to remove paths forever? > > Probably you have the Python36-32 directories set in PYTHONPATH. For > some reason some people think they need to add standard directories to > this environment variable, which is something you should never do. Yes, my PYTHONPATH looks like: C:\Users\me\AppData\Local\Programs\Python\Python36-32 C:\Users\me\AppData\Local\Programs\Python\Python36-32\DLLs C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib Should I remove them? I suppose installer did so. But why 64 bit installer skiped this? From rosuav at gmail.com Thu Sep 7 10:28:27 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Sep 2017 00:28:27 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> Message-ID: On Thu, Sep 7, 2017 at 11:21 PM, Gregory Ewing wrote: > Rustom Mody wrote: > >> I said: In that case please restate the definition of 'is' from the manual >> which invokes the notion of 'memory' without bringing in memory. > > > I don't know whether it's in the manual, but at least for > mutable objects, there is a way to define the notion of > "same object" that doesn't require talking about "memory": > > Two names refer to the same object if and only if mutations > made through one are visible through the other. > > Python has definite rules concerning when mutable objects > will be the same or not, and every correct implementation > must conform to them. In that sense it's a fundamental > concept that doesn't depend on implementation. Yep. I'd call this a litmus test rather than a definition, but it's absolutely true - and it's why languages without mutable objects don't really care whether they're pass-by-X or pass-by-Y. ChrisA From tjol at tjol.eu Thu Sep 7 10:44:00 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 7 Sep 2017 16:44:00 +0200 Subject: remove path forever In-Reply-To: References: <13b650ad-a295-496c-8fbc-5b0c1ff886c6@googlegroups.com> Message-ID: On 2017-09-07 16:25, Andrej Viktorovich wrote: > On Thursday, 7 September 2017 14:35:58 UTC+3, eryk sun wrote: >> On Thu, Sep 7, 2017 at 1:39 AM, Andrej Viktorovich >> wrote: >>> >>> I have 64 bit python on my windows 10 machine. Install contains 32 bit python libs in path >>> and I would like to remove them. >>> >>> I do >>> imprt sys >>> sys.path.remove("C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python36-32") >>> >>> It works for current python instance, but paths appears in new one. How to remove paths forever? >> >> Probably you have the Python36-32 directories set in PYTHONPATH. For >> some reason some people think they need to add standard directories to >> this environment variable, which is something you should never do. > > Yes, my PYTHONPATH looks like: > C:\Users\me\AppData\Local\Programs\Python\Python36-32 > C:\Users\me\AppData\Local\Programs\Python\Python36-32\DLLs > C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib > > Should I remove them? I suppose installer did so. But why 64 bit installer skiped this? Remove them and then check that your 32-bit python installation still works. -- Thomas From tjol at tjol.eu Thu Sep 7 11:17:22 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 7 Sep 2017 17:17:22 +0200 Subject: non-standard glibc location In-Reply-To: References: Message-ID: <949d4c0c-37d1-c160-5a3c-e5d45632dbf5@tjol.eu> On 2017-09-06 16:14, Fetchinson . via Python-list wrote: > Hi folks, > > I'm trying to install a binary package (tensorflow) which contains > some binary C extensions. Now my system glibc is 2.15 but the binaries > in the C extensions were created (apparently) with glibc 2.17. So I > thought no problemo I installed glibc 2.17 to a custom location, built > python2.7 from source (hopefully using my custom glibc) and installed > pip and everything else using this custom built python. But still when > I try to import tensorflow I get: > > ImportError: /lib64/libc.so.6: version `GLIBC_2.17' not found > (required by /home/nogradi/fetch/custom/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so) > > So apparently it's trying to use my system glibc, not the custom one. > > How do I tell this extension to use the custom glibc? Is it even possible? It's going to use the same libc as python, so first of all check which libc your python interpreter is actually linked to. Maybe your custom build didn't do quite what you wanted. ldd `which python` # or something like that Once you've convinced yourself that python has the correct libc, you could try building tensorflow from source rather than installing the binaries. Maybe something in here helps: https://github.com/tensorflow/tensorflow/issues/53 > > But maybe I have an even more basic issue: how do I link python not > with the system glibc but with my custom glibc? > > Cheers, > Daniel > > > -- Thomas Jollans From steve+python at pearwood.info Thu Sep 7 11:30:56 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 08 Sep 2017 01:30:56 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> Message-ID: <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Sep 2017 12:28 am, Chris Angelico wrote: > languages without mutable objects don't > really care whether they're pass-by-X or pass-by-Y. Only if you don't care about efficiency. Believe me, the first time you pass a five gigabyte array to a function using pass-by-value, on a machine with only six gigabytes of memory, you'll care. Preventing that sort of thing is probably why arrays aren't first-class values in C, and you cannot pass an array as argument, only a pointer to an array. But Pascal will happily assume you know what you're doing if you declare an array parameter without "var", and copy the whole array. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From toby at tobiah.org Thu Sep 7 11:33:39 2017 From: toby at tobiah.org (Tobiah) Date: Thu, 7 Sep 2017 08:33:39 -0700 Subject: Midi output timing? Message-ID: I'd like to use a python program to send out MIDI events to another program. I've done in the past by generating scores for csound which would do the MIDI output. The apparent hurdle is the timing bit. I've seen packages that allow the creation of MIDI events, but given a list of events of arbitrary start time, how can I schedule the triggering of each event? Csound runs in sync with the audio device output which is desirable if not necessary. Thanks From rosuav at gmail.com Thu Sep 7 12:24:16 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Sep 2017 02:24:16 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> Message-ID: On Fri, Sep 8, 2017 at 1:30 AM, Steve D'Aprano wrote: > On Fri, 8 Sep 2017 12:28 am, Chris Angelico wrote: > >> languages without mutable objects don't >> really care whether they're pass-by-X or pass-by-Y. > > Only if you don't care about efficiency. > > Believe me, the first time you pass a five gigabyte array to a function using > pass-by-value, on a machine with only six gigabytes of memory, you'll care. > > Preventing that sort of thing is probably why arrays aren't first-class values > in C, and you cannot pass an array as argument, only a pointer to an array. But > Pascal will happily assume you know what you're doing if you declare an array > parameter without "var", and copy the whole array. Right - but sharing (in whatever form) is a pure optimization, with no visible semantics. ChrisA From eryksun at gmail.com Thu Sep 7 12:39:52 2017 From: eryksun at gmail.com (eryk sun) Date: Thu, 7 Sep 2017 11:39:52 -0500 Subject: remove path forever In-Reply-To: References: <13b650ad-a295-496c-8fbc-5b0c1ff886c6@googlegroups.com> Message-ID: On Thu, Sep 7, 2017 at 9:25 AM, Andrej Viktorovich wrote: > On Thursday, 7 September 2017 14:35:58 UTC+3, eryk sun wrote: >> On Thu, Sep 7, 2017 at 1:39 AM, Andrej Viktorovich >> wrote: >> > >> > I have 64 bit python on my windows 10 machine. Install contains 32 bit python libs in path >> > and I would like to remove them. >> > >> > I do >> > imprt sys >> > sys.path.remove("C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python36-32") >> > >> > It works for current python instance, but paths appears in new one. How to remove paths forever? >> >> Probably you have the Python36-32 directories set in PYTHONPATH. For >> some reason some people think they need to add standard directories to >> this environment variable, which is something you should never do. > > Yes, my PYTHONPATH looks like: > C:\Users\me\AppData\Local\Programs\Python\Python36-32 > C:\Users\me\AppData\Local\Programs\Python\Python36-32\DLLs > C:\Users\me\AppData\Local\Programs\Python\Python36-32\Lib > > Should I remove them? I suppose installer did so. But why 64 bit installer skiped this? Yes, remove them. I don't know what added them, but the installer did not -- assuming it's a standard installer from python.org. Those entries are not necessary and are guaranteed to break other installations of Python. Typically they get added manually by users who are desperate to resolve some path issue, which is often a completely unrelated system PATH issue. From steve+python at pearwood.info Thu Sep 7 13:22:40 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 08 Sep 2017 03:22:40 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> Message-ID: <59b18061$0$16726$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Sep 2017 02:24 am, Chris Angelico wrote: > On Fri, Sep 8, 2017 at 1:30 AM, Steve D'Aprano > wrote: >> On Fri, 8 Sep 2017 12:28 am, Chris Angelico wrote: >> >>> languages without mutable objects don't >>> really care whether they're pass-by-X or pass-by-Y. >> >> Only if you don't care about efficiency. >> >> Believe me, the first time you pass a five gigabyte array to a function using >> pass-by-value, on a machine with only six gigabytes of memory, you'll care. [...] > Right - but sharing (in whatever form) is a pure optimization, with no > visible semantics. Apart from the disk activity light on your PC, as it starts thrashing :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jmeile at hotmail.com Thu Sep 7 13:49:27 2017 From: jmeile at hotmail.com (Josef Meile) Date: Thu, 7 Sep 2017 17:49:27 +0000 Subject: Need to pass a class instance to a gettext fallback Message-ID: Hi I'm working with gettext and need to define a language Fallback. I got this working, but with a global variable. I don't really like this and I would like to pass this variable to the gettext Fallback's contructor, but I don't know how. For simplicity, I won't put the whole code here, just the important parts. Before you look at it, I want to ask you: how can I pass the variable: "my_plugin" to the constructor of the "MissingTranslationsFallback" class? If you see, an instance of this class will be created automatically by gettext. I don't create it. When calling the " add_fallback" method of the gettext.GNUTranslations class, you have to pass a class and not an instance. #Defining a global dict, which is ugly, I know MY_GLOBALS = {} class TranslationService(object): """...__init__ and other methods are defined here""" def install(self): """...some code goes here...""" #Now the ugly part :-( MY_GLOBALS['py_plugin'] = self._py_plugin current_catalog = gettext.translation(plugin_name, localedir = locale_folder, class_= MissingTranslationsFallback, languages = [current_language]) current_catalog.install() class MissingTranslationsFallback(gettext.GNUTranslations, object): def __init__(self, *args, **kwargs): super(MissingTranslationsFallback, self).__init__(*args, **kwargs) #And here is where I need to access py_plugin :-( py_plugin = MY_GLOBALS['py_plugin'] i18n_service = py_plugin.get_i18n_service() #Adds an instance to the class that will handle the missing translations self.add_fallback(MissingTranslationsLogger(i18n_service.get_language())) class MissingTranslationsLogger(gettext.NullTranslations): def __init__(self, language): self._language = language self._missing = set() def gettext(self, message): if (message not in self._missing): self._missing.add(message) print "Missing message: " + message + " current language: " + self._language return message Any help would be appreciated. Best regards Josef From rustompmody at gmail.com Thu Sep 7 14:02:37 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 7 Sep 2017 11:02:37 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: <59b18061$0$16726$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> <59b18061$0$16726$b1db1813$d948b532@news.astraweb.com> Message-ID: <66a603dd-ff6e-47f3-a4ea-c4562b980efd@googlegroups.com> On 06/09/17 14:02, Stefan Ram wrote: > Chris Angelico writes: >> The 'is' operator tests if two things are the same thing. > > ?Roughly speaking, to say of two things that they are > identical is nonsense, and to say of one thing that it > is identical with itself is to say nothing at all.? > > Ludwig Wittgenstein, Tractatus Logico-Philosophicus (5.5303) Someone who is philosophically literate in technical forum: a rare treat! Nice!! Wittgenstein is a favorite of mine and I often reserve one lecture for his: ?Limits of my language are the limits of my world? Then amplified by Roman Jacobson?s ?Languages differ not in what we can say but what we must say? And finally with Whorf's evidence that words can set buildings on fire https://web.stanford.edu/dept/SUL/library/extra4/sloan/mousesite/Secondary/Whorfframe2.html [Today it would be send countries to war] However Wittgenstein's quote above on identity is too terse to properly grasp the real difficulty https://plato.stanford.edu/entries/identity/ shows at some (verbose!) length that identity is and can only be a hopelessly circular definition. A problem which has little to do with python, programming languages, or CS in general; it is a fundamental universal problem From rosuav at gmail.com Thu Sep 7 14:04:08 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Sep 2017 04:04:08 +1000 Subject: In ports of a log file, how to detect if the ports are dangerous using python? In-Reply-To: <23139f56-b1a2-48db-8a5b-7740a4e640e7@googlegroups.com> References: <23139f56-b1a2-48db-8a5b-7740a4e640e7@googlegroups.com> Message-ID: On Thu, Sep 7, 2017 at 11:28 PM, Rockzers wrote: > I know basic python and I have a log file, also I have print the output of ports from the log file which there are so many ports in the output. > I want to know how to take only the dangerous ports from the printed ports - Also I need to take the IP addresses from the dangerous ports - Finally how to know if the IP addresses are local IP or global IP > Ports are not dangerous. It's what you do with them. I think you're going to need to understand a lot more about how TCP/IP networking (and UDP, by the look of your example) works before you can dig into this in detail. ChrisA From rustompmody at gmail.com Thu Sep 7 14:24:01 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 7 Sep 2017 11:24:01 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> Message-ID: On Thursday, September 7, 2017 at 6:52:04 PM UTC+5:30, Gregory Ewing wrote: > Rustom Mody wrote: > > > I said: In that case please restate the definition of 'is' from the manual which > > invokes the notion of 'memory' without bringing in memory. > > I don't know whether it's in the manual, but at least for > mutable objects, there is a way to define the notion of > "same object" that doesn't require talking about "memory": > > Two names refer to the same object if and only if mutations > made through one are visible through the other. Seems a sensible comment! [Aside from the fact that 'visible' is likely ill or circularly defined ? my other comment to Stefan. But lets just ignore that for now and assume that 'visible' has no grey/dispute areas] > > Python has definite rules concerning when mutable objects > will be the same or not, and every correct implementation > must conform to them. In that sense it's a fundamental > concept that doesn't depend on implementation. I'd like to know what these rules are > > There is more leeway when it comes to immutable objects; > implementations are free to cache and re-use them, so > well-written code avoids depending on the result of > "is" for immutable objects. Which sounds like saying that 'isness' of immutables is ill/un-defined Not that I object if this is said My objection is to the claim that the isness of python's is and the isness of 'conceptually-same' are the same. I believe that your definition of same and the one I earlier gave are similar (same?? Not sure) Repeating here for ease: (with some clarifications) We say equivalence relation R is coarser than S is xSy ? xRy So x is y ? x == y but not (necessarily) vice versa However there are not 2 but 3 equivalence relations: 1. == ? mathematical, too coarse to understand nuances of python semantics 2. is ? machine representation, too fine to be useful 3. graph (or topological) equality which experienced pythonistas have internalized in understanding when two data structures are same or different [Roughly Anton's diagrams that are beyond my drawing capability!] And yet pythonistas need 3 to understand python data structures ie 3 captures pythonistas intuition of same better than 1 or 2 >>> a = [1,2] >>> b = [a,a] >>> c = [[1,2],[1,2]] >>> b == c True >>> b is c False >>> p = [1,2] >>> q = [p,p] >>> r = [[1,2],[1,2]] >>> q == r True >>> q is r False >>> b == q True >>> b == r True >>> b is q False >>> b is r False Now the pythonista understands that b and c may be math-= but have different structure Whereas b is graph-equal to q And c is graph-equal to r However there is no available operation to show/see that distinction The trouble is that graph-isomorphism is NP-complete so the crucial operation cannot be reasonably implemented To make it more clear ? is graph-equal, ie 2. The pythonista understands that b ? c ## ? is finer than == Whereas b ? r ie ? is coarser than is And b and r are python-equivalent without any memory relation in the sense that no sequence of valid operations applied to b and to r will tell them apart ? sometimes called 'trace-equivalence' From chris at simplistix.co.uk Thu Sep 7 18:18:49 2017 From: chris at simplistix.co.uk (Chris Withers) Date: Thu, 7 Sep 2017 23:18:49 +0100 Subject: mush 2.7 released! - Type-based dependency injection for scripts Message-ID: Hi All, I'm very happy to announce the a new release of Mush, a light weight dependency injection framework aimed at enabling the easy testing and re-use of chunks of code that make up scripts. This release includes: - Add support for using Python 3 type annotations to specify requirements and returned resources. - Add support for arg names being used as requirements when there is no other configuration. - Add an explicit way of ignoring the return value of a callable. - Add an update_wrapper() helper that extends the standard library version but also preserves Mush's annotations. For a worked example of how to use Mush to reduce the copy'n'paste in your scripts, please see here: http://mush.readthedocs.io/en/latest/examples.html Full docs are here: http://mush.readthedocs.io/en/latest/index.html Downloads are here: https://pypi.python.org/pypi/mush Compatible with Python 2.7, 3.4+ on Linux, Mac OS X and Windows. Any problems, please give me a shout on the simplistix at googlegroups.com list! cheers, Chris From ofekmeister at gmail.com Thu Sep 7 21:11:39 2017 From: ofekmeister at gmail.com (ofekmeister at gmail.com) Date: Thu, 7 Sep 2017 18:11:39 -0700 (PDT) Subject: Hatch - A modern project, package, and virtual env manager In-Reply-To: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> References: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> Message-ID: <0bffd60c-9f70-473d-8889-f152329bde4b@googlegroups.com> Big quality of life improvements in 0.7.0! https://github.com/ofek/hatch#070 From fetchinson at googlemail.com Thu Sep 7 21:15:41 2017 From: fetchinson at googlemail.com (Fetchinson .) Date: Fri, 8 Sep 2017 03:15:41 +0200 Subject: non-standard glibc location In-Reply-To: <949d4c0c-37d1-c160-5a3c-e5d45632dbf5@tjol.eu> References: <949d4c0c-37d1-c160-5a3c-e5d45632dbf5@tjol.eu> Message-ID: On 9/7/17, Thomas Jollans wrote: > On 2017-09-06 16:14, Fetchinson . via Python-list wrote: >> Hi folks, >> >> I'm trying to install a binary package (tensorflow) which contains >> some binary C extensions. Now my system glibc is 2.15 but the binaries >> in the C extensions were created (apparently) with glibc 2.17. So I >> thought no problemo I installed glibc 2.17 to a custom location, built >> python2.7 from source (hopefully using my custom glibc) and installed >> pip and everything else using this custom built python. But still when >> I try to import tensorflow I get: >> >> ImportError: /lib64/libc.so.6: version `GLIBC_2.17' not found >> (required by >> /home/nogradi/fetch/custom/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow_internal.so) >> >> So apparently it's trying to use my system glibc, not the custom one. >> >> How do I tell this extension to use the custom glibc? Is it even >> possible? > > It's going to use the same libc as python, so first of all check which > libc your python interpreter is actually linked to. Maybe your custom > build didn't do quite what you wanted. > > ldd `which python` # or something like that > > Once you've convinced yourself that python has the correct libc, you > could try building tensorflow from source rather than installing the > binaries. > > Maybe something in here helps: > https://github.com/tensorflow/tensorflow/issues/53 Thanks a lot for all the comments, my problem was indeed that the compiled python was still using the system glibc. The solution was to set the environment variables p=/path/to/custom/glibc export CFLAGS=-I${p}/include export LDFLAGS="-Wl,--rpath=${p}/lib -Wl,--dynamic-linker=${p}/lib/ld-linux-x86-64.so.2" And then the compiled python was using the new glibc. Side note 1 on tensorflow: the compiled tensorflow binary uses unicode ucs4, so for python I had to ./configure --enable-unicode=ucs4 because the default is ucs2 Side note 2 on tensorflow: it also depends on libstdc++ and my version was too old for that as well. Instead of compiling gcc from source (which includes libstdc++) I copied a binary libstdc++ from a newer linux distro and it was working fine. And the reason, if anyone cares, I had to go through the above is that I couldn't compile tensorflow from source. Thanks again, Daniel > >> >> But maybe I have an even more basic issue: how do I link python not >> with the system glibc but with my custom glibc? >> >> Cheers, >> Daniel >> >> >> > > > -- > Thomas Jollans > -- > https://mail.python.org/mailman/listinfo/python-list > -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From steve+python at pearwood.info Thu Sep 7 21:59:08 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 08 Sep 2017 11:59:08 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> <59b18061$0$16726$b1db1813$d948b532@news.astraweb.com> <66a603dd-ff6e-47f3-a4ea-c4562b980efd@googlegroups.com> Message-ID: <59b1f96d$0$16737$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Sep 2017 05:15 am, Stefan Ram wrote: > It computing newsgroups, for example, people > ask about how to compute the number of digits > of a number, when, actually, only numerals > (representations of numbers in a particular > numeral system) have digits. Um, yes? That's implicit in the question -- and generally the numeral system in question is implied to be 10. Context is important. But for what it's worth, if you take a random number from the Reals, then the answer will be "infinite digits" for Almost All[1] numbers, no matter what number base you are using. A harder question is, what if you take a random number from the Integers? How many digits will it have in (say) base 10? I don't have a good answer to that. I think it may be ill-defined. [1] https://en.wikipedia.org/wiki/Almost_all -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Sep 7 22:09:25 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 08 Sep 2017 12:09:25 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> Message-ID: <59b1fbd6$0$16728$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Sep 2017 04:24 am, Rustom Mody wrote: > On Thursday, September 7, 2017 at 6:52:04 PM UTC+5:30, Gregory Ewing wrote: >> Rustom Mody wrote: >> >> > I said: In that case please restate the definition of 'is' from the manual >> > which invokes the notion of 'memory' without bringing in memory. >> >> I don't know whether it's in the manual, but at least for >> mutable objects, there is a way to define the notion of >> "same object" that doesn't require talking about "memory": >> >> Two names refer to the same object if and only if mutations >> made through one are visible through the other. > > Seems a sensible comment! Except that it is wrong, or at least over-generalised. It is trivially easy to show false positives: py> class K: # defines an object ... def __init__(self, x): ... self.x = x ... def append(self, value): ... self.x.append(value) ... py> a = [] py> b = K(a) py> a is b # these are not the same object (they're different types) False py> b.append(99) # but modifying b modifies a py> a [99] Rustom, I've already given you the definitive answer to your question about how to define `is` without talking about memory. You haven't replied or acknowledged it, so here is it again: `is` compares the two operands for identity. If the two operands are the same object, `is` returns True, if they are distinct objects, `is` returns False. This does require that we agree on "same object", which as you point out is (in its full generality) a difficult thing to define. E.g. in the past I've raised the paradox of My Grandfather's Axe. But the intuitive, common-sense notion of "same object" is, I think, sufficient here. If you want to argue that it is *not* sufficient, I think it's up to you to demonstrate a problem with the definition. Can you show an actual false positive (two distinct objects for which `is` returns True) or false negative (the same object given as both operands for `is` nevertheless returns False)? In the absence of any actual bugs in the definition, I maintain that it is sufficient. And if there are still philosophical problems with the concept of "the same object", they either don't apply to Python objects, or they apply equally to all objects in the universe and there's nothing we can do about it. Either way, the problem of defining the Python `is` operator without referring to memory is solved. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From christopher_reimer at yahoo.com Thu Sep 7 22:51:22 2017 From: christopher_reimer at yahoo.com (Christopher Reimer) Date: Thu, 7 Sep 2017 19:51:22 -0700 Subject: Setting property for current class from property in an different class... In-Reply-To: References: <6aaa4136-cc87-8c6d-646e-3b696c5209d8@yahoo.com> <94a96abc-a2b7-756b-0ffd-bd8d38a5ebd5@yahoo.com> Message-ID: <1f591047-e2fa-d7e6-4b11-60d222be6343@yahoo.com> On 9/6/2017 9:26 PM, Christopher Reimer wrote: >> On Sep 6, 2017, at 9:14 PM, Stefan Ram wrote: >> >> I can run this (your code) without an error here (Python 3.6.0), >> from a file named "Scraper1.py": > I'll check tomorrow. I recently switched from 3.5.x to 3.6.1 in the PyCharm IDE. It's probably FUBAR in some obscure way. I uninstalled Python 3.6.0 (32-bit) and Python 3.6.1 (64-bit), installed Python 3.6.2 (64-bit), and everything now works. Thanks, Chris R. From rustompmody at gmail.com Thu Sep 7 23:01:06 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 7 Sep 2017 20:01:06 -0700 (PDT) Subject: A question on modification of a list via a function invocation In-Reply-To: <59b1fbd6$0$16728$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b1fbd6$0$16728$b1db1813$d948b532@news.astraweb.com> Message-ID: <588a0643-28ea-4938-bf79-77ae66c0eaab@googlegroups.com> On Friday, September 8, 2017 at 7:39:38 AM UTC+5:30, Steve D'Aprano wrote: > On Fri, 8 Sep 2017 04:24 am, Rustom Mody wrote: > > > On Thursday, September 7, 2017 at 6:52:04 PM UTC+5:30, Gregory Ewing wrote: > >> Rustom Mody wrote: > >> > >> > I said: In that case please restate the definition of 'is' from the manual > >> > which invokes the notion of 'memory' without bringing in memory. > >> > >> I don't know whether it's in the manual, but at least for > >> mutable objects, there is a way to define the notion of > >> "same object" that doesn't require talking about "memory": > >> > >> Two names refer to the same object if and only if mutations > >> made through one are visible through the other. > > > > Seems a sensible comment! > > > Except that it is wrong, or at least over-generalised. It is trivially easy to > show false positives: > > py> class K: # defines an object > ... def __init__(self, x): > ... self.x = x > ... def append(self, value): > ... self.x.append(value) > ... > py> a = [] > py> b = K(a) > py> a is b # these are not the same object (they're different types) > False > py> b.append(99) # but modifying b modifies a > py> a > [99] > > > Rustom, I've already given you the definitive answer to your question about how > to define `is` without talking about memory. You haven't replied or > acknowledged it, so here is it again: > > `is` compares the two operands for identity. Preamble? so far so good > If the two operands are the same > object, `is` returns True, if they are distinct objects, `is` returns False. restated a is b iff a is b A more than usually egregious demo of the circularity of defining isness/sameness Models are needed Math is one possible model Machines are another Paper and pen ? which Chris keeps referring to ? is another Remove all models and you have frank hopeless circularity > > > This does require that we agree on "same object", which as you point out is (in > its full generality) a difficult thing to define. More than difficult, impossible in the fully abstract philosophical case When concretized to specific models not necessarily the fundamental circularity then pushed out to the model 1 + 2 = 3 Are these '3's on your and my screen same? Same font? Same time? E.g. in the past I've raised > the paradox of My Grandfather's Axe. Dont see the relevance (here) > > But the intuitive, common-sense notion of "same object" is, I think, sufficient > here. If you want to argue that it is *not* sufficient, I think it's up to you > to demonstrate a problem with the definition. > Its not that you cant raise philosophical problems if you want But when concretized to (basic) math, there are no disputes so the argument becomes obtuseness to no point In the case of python data model every single interminable thread like this one, obviously started by a noob asking something genuinely and indicating a real confusion disproves your claim to obvious intuition and common sense Just to reiterate: Someone asked a question Its not clear what (s)he understood from what we have going on and on about for 100s of posts > Can you show an actual false positive (two distinct objects for which `is` > returns True) or false negative (the same object given as both operands for > `is` nevertheless returns False)? In the absence of any actual bugs in the > definition, I maintain that it is sufficient. You are not paying attention ? the example above I gave in which python arbitrarily hi-handedly, inconsistently manifests different behavior between integer 1 and tuple (1,2) I am now dropping off this thread [more important things to do] with this observation: There are these strange wondrous things in the world called 'mothers' They take bawling shiing peeing pieces of fleshy exasperation called 'babies' And convert them into intelligent human beings Dunno how they do it? More easily: if I, knowing English, read a German-English dictionary its ok, a well-founded action ? learning unknown-German via known-English But reading a 'normal' English-English dictionary like Webster, Oxford etc is borderline infinite recursion? And occasionally fails ? ambiguities, grey areas Still it mostly works? with enough good faith However bootstrapping the whole process from absolute zero ? the mothers' task ? is frankly beyond my ken Bare (pure-philosophical, model-less) identity/sameness is analogous So? what you think is obvious and trivially intuitive ? the bald fact of semantics and comprehension ? is to me quite miraculous From rosuav at gmail.com Thu Sep 7 23:11:51 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Sep 2017 13:11:51 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: <588a0643-28ea-4938-bf79-77ae66c0eaab@googlegroups.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b1fbd6$0$16728$b1db1813$d948b532@news.astraweb.com> <588a0643-28ea-4938-bf79-77ae66c0eaab@googlegroups.com> Message-ID: On Fri, Sep 8, 2017 at 1:01 PM, Rustom Mody wrote: > >> Can you show an actual false positive (two distinct objects for which `is` >> returns True) or false negative (the same object given as both operands for >> `is` nevertheless returns False)? In the absence of any actual bugs in the >> definition, I maintain that it is sufficient. > > You are not paying attention ? the example above I gave in which > python arbitrarily hi-handedly, inconsistently manifests different behavior > between integer 1 and tuple (1,2) You started with the assumption that the tuple (1,2) is the same as the tuple (1,2). This is a false assumption; they are equal, but they are not identical. How does your mathematical model cope with this? >>> x = 1 >>> y = 1.0 >>> x == y True >>> x is y False There is no way that a compliant Python implementation can give any other results for these expressions. These values are equal but not identical. It's the same with the integers and tuples in your example, except that there, Python is permitted to optimize by using the same object. Stop thinking about mathematics and assuming that (a) it is the perfect way to explain software, and (b) we all have the same basis you do. Start thinking about programming languages from a different basis... you might actually learn something. Or just read what Steve and I have been saying. ChrisA From golf4carson at yahoo.com Thu Sep 7 23:36:25 2017 From: golf4carson at yahoo.com (Carson McDaniel) Date: Thu, 7 Sep 2017 21:36:25 -0600 Subject: My Issues Message-ID: <59065F64-409B-4497-8CC3-864B3571DC54@yahoo.com> Hello, I am an extreme beginner at this so forgive me if I've done something simple wrong, but every time I try to open Python (3.6.2), I get an error message that says the program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing from my computer. It says to try reinstalling the program and I have once and tried repairing it a bunch of time but the message still appears. Do I need to download something else and where do I find it? Thanks for the help, Carson McDaniel Sent from my iPhone From formisc at gmail.com Fri Sep 8 00:04:58 2017 From: formisc at gmail.com (Andrew Z) Date: Thu, 7 Sep 2017 21:04:58 -0700 (PDT) Subject: async. How to wait for async function to complete Message-ID: <4732c74f-d93e-4bf1-9e30-9674f61c3b6b@googlegroups.com> Hello, i need to wait for the callback function (contractDetailsEnd) to finish before i can continue with the logic ( in subscribe) further. For that i check the flag (ContractsUpdatedEnd) in the "while" loop. Here is the simplified code: import asyncio import ibapi from tws_async import TWSClient class TWS(TWSClient): def __init__( self ): TWSClient.__init__(self) self.Contracts = {} self.ContractsUpdatedEnd = False def sleep(self, secs): loop = asyncio.get_event_loop() loop.run_until_complete(asyncio.sleep(secs)) def subscribe( self ): for forex in ['EURUSD', 'USDJPY', 'GBPUSD']: self.reqContractDetails(reqId ,c) while not self.ContractsUpdatedEnd: self.sleep(0.1) self.reqMktData(reqId, c, genericTickList = '', snapshot = False, regulatorySnapshot = False, mktDataOptions = []) def contractDetails(self, reqId, contractDetails): self.Contracts[reqId]= contractDetails.summary print("Contract is {}".format(contractDetails.summary)) def contractDetailsEnd(self, reqId): print("End for contract details") self.ContractsUpdatedEnd = True if __name__ == '__main__': tws = TWS() tws.connect(host = '127.0.0.1', port = 7497, clientId = 1) tws.subscribe() loop = asyncio.get_event_loop() loop.run_forever() Unfortunately, this throws the : File "/usr/lib64/python3.5/asyncio/base_events.py", line 408, in run_forever raise RuntimeError('This event loop is already running') RuntimeError: This event loop is already running will greatly appreciate your advise. From marko at pacujo.net Fri Sep 8 02:04:26 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 08 Sep 2017 09:04:26 +0300 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> Message-ID: <87wp5ajytb.fsf@elektro.pacujo.net> Gregory Ewing : > There is more leeway when it comes to immutable objects; > implementations are free to cache and re-use them, so well-written > code avoids depending on the result of "is" for immutable objects. I definitely trust that: a = b assert a is b even when b holds an immutable object. Assignment, argument passing, return value passing and yield (to name a few) must preserve identity. Marko From __peter__ at web.de Fri Sep 8 02:15:14 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 08 Sep 2017 08:15:14 +0200 Subject: Need to pass a class instance to a gettext fallback References: Message-ID: Josef Meile wrote: > Hi > > I'm working with gettext and need to define a language Fallback. I got > this working, but with a global variable. I don't really like this and I > would like to pass this variable to the gettext Fallback's contructor, but > I don't know how. For simplicity, I won't put the whole code here, just > the important parts. > > Before you look at it, I want to ask you: how can I pass the variable: > "my_plugin" to the constructor of the "MissingTranslationsFallback" class? > If you see, an instance of this class will be created automatically by > gettext. I don't create it. When calling the " add_fallback" method of the > gettext.GNUTranslations class, you have to pass a class and not an > instance. Provided the class_ argument to gettext.translation() accepts an arbitrary callable the following may work: import functools > #Defining a global dict, which is ugly, I know > MY_GLOBALS = {} > > class TranslationService(object): > """...__init__ and other methods are defined here""" > > def install(self): > """...some code goes here...""" current_catalog = gettext.translation( plugin_name, localedir=locale_folder, class_=functools.partial( MissingTranslationsFallback, py_plugin=self._py_plugin ), languages=[current_language] ) > current_catalog.install() > > class MissingTranslationsFallback(gettext.GNUTranslations, object): > def __init__(self, *args, **kwargs): py_plugin = kwargs.pop("py_plugin") > super(MissingTranslationsFallback, self).__init__(*args, **kwargs) > i18n_service = py_plugin.get_i18n_service() > #Adds an instance to the class that will handle the missing > #translations > self.add_fallback(MissingTranslationsLogger(i18n_service.get_language())) From greg.ewing at canterbury.ac.nz Fri Sep 8 02:58:28 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Sep 2017 18:58:28 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> Message-ID: Rustom Mody wrote: > 2. is ? machine representation, too fine to be useful No, it's *not* machine representation. As I pointed out before, it's part of the abstract semantics of Python. And it's not "too fine to be useful". On the contrary, being aware of which objects are the same and which aren't is vital to writing Python programs that behave in the intended way. > 3. graph (or topological) equality > 3 captures pythonistas intuition of same better than 1 or 2 I don't think so, see below. >>>>a = [1,2] >>>>b = [a,a] >>>>c = [[1,2],[1,2]] >>>>p = [1,2] >>>>q = [p,p] >>>>r = [[1,2],[1,2]] > Now the pythonista understands that b and c may be math-= but have different structure > Whereas b is graph-equal to q > And c is graph-equal to r > > However there is no available operation to show/see that distinction Because usually it's not particularly important to know whether two separate structures have the same topology. On the other hand, it *is* important to know things such as 'b[0] is b[1]' but 'c[0] is not c[1]', because it makes a difference to what happens if you mutate any of those. > The trouble is that graph-isomorphism is NP-complete so the crucial operation > cannot be reasonably implemented We're fortunate that it's not actually a crucial operation, then. :-) -- Greg From __peter__ at web.de Fri Sep 8 03:06:40 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 08 Sep 2017 09:06:40 +0200 Subject: Design: method in class or general function? References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> Message-ID: leam hall wrote: > On Thu, Sep 7, 2017 at 8:16 AM, Steve D'Aprano > wrote: > >> On Thu, 7 Sep 2017 07:20 pm, Leam Hall wrote: >> >> > OOP newbie on Python 2.6. >> >> Python 2.6 is ancient, and is missing many nice features. You should >> consider >> using the latest version, 3.6. >> > > I've wrestled with that discussion for a while and Python 3 loses every > time. There's literally no good reason for me to move to Python 3 earlier > than mid-2020's. Please accept the fact that there are hundreds of > thousands of servers, if not millions, running Python 2.x. Whether or not > Python 3 has any neat cool stuff is irrelevant to those of us seeking to > use Python to get today's work done. > >> I create instances of Character class with an attribute dict of >> > 'skills'. The 'skills' dict has the name of a skill as the key and an >> > int as a value. The code adds or modifies skills before outputting the >> > Character. >> > >> > Is it better design to have a Character.method that takes a 'skill' key >> > and optional value or to have a general function that takes an >> > instance, a dict, a key, and an optional value? >> >> I'm afraid your example is too generic for me to give an opinion. Do you >> literally mean a method called "method"? What does it do? >> > > > Using this: > https://github.com/makhidkarun/py_tools/blob/master/lib/character.py > > Line 19 sets "self.skills" either from the passed in data or from > https://github.com/makhidkarun/py_tools/blob/master/lib/character_tools.py > #L34-L48 > > So Character.skills is a dict with a string key and an int value. I need > to be able to add skills and my first attempt is a function: > https://github.com/makhidkarun/py_tools/blob/master/lib/character_tools.py > #L52-L56 > > Should the "add_skills" function be a method in the character class or be > made a more generic function to add/modify a key/value pair in a dict that > is an attribute of an instance? Other tasks will require the add/modify > functionality but coding that increases complexity. At least for me, > anyway. > > Sorry about being unclear earlier, coffee was still kicking in and I'm > still a newbie that mixes up terms. I'm pleading "method" as it allows per-class implementation. Say you use per-career subclasses of a general Character class. There are default per-career skill sets, but usually a Character can acquire a skill that is not needed in his career -- with the exception that Rogues cannot tap dance ;) Below is a way to implement that with a specialised add_skill() method: $ cat basic_oo.py from __future__ import print_function import random from collections import defaultdict class Character(object): DEFAULT_SKILLS = ['Blade', 'GunCbt', 'Admin', 'Streetwise'] def __init__(self): self.skills = defaultdict(int) def add_random_skills(self, terms): skillnames = self.DEFAULT_SKILLS for _ in range(2*terms): self.add_skill(random.choice(skillnames)) def add_skill(self, name, amount=1): self.skills[name] += amount def __str__(self): skills = ", ".join( "{}={}".format(name, amount) for name, amount in sorted(self.skills.items()) if amount != 0 ) return "{}({})".format(self.__class__.__name__, skills) class Rogue(Character): def add_skill(self, name, amount=1): if name == "TapDance": raise ValueError("Sorry, this rogue will never tap dance") super(Rogue, self).add_skill(name, amount) class Marine(Character): DEFAULT_SKILLS = ['GunCbt', 'VaccSuit', 'Leadership', 'Vehicle'] def main(): NUM_CHARACTERS = 5 CHARACTERS = [Marine, Rogue] characters = [ random.choice(CHARACTERS)() for _ in range(NUM_CHARACTERS) ] for c in characters: c.add_random_skills(5) c.add_skill("RepairBicycles", random.randrange(3)) try: c.add_skill("TapDance", 3) except ValueError as err: print(err) for c in characters: print(c) if __name__ == "__main__": main() $ python basic_oo.py Sorry, this rogue will never tap dance Sorry, this rogue will never tap dance Sorry, this rogue will never tap dance Rogue(Admin=3, Blade=4, GunCbt=2, Streetwise=1) Marine(GunCbt=5, Leadership=4, TapDance=3, VaccSuit=1) Rogue(Blade=3, GunCbt=2, RepairBicycles=2, Streetwise=5) Rogue(Admin=1, Blade=2, GunCbt=5, RepairBicycles=1, Streetwise=2) Marine(GunCbt=1, Leadership=3, RepairBicycles=2, TapDance=3, VaccSuit=2, Vehicle=4) From dieter at handshake.de Fri Sep 8 03:07:31 2017 From: dieter at handshake.de (dieter) Date: Fri, 08 Sep 2017 09:07:31 +0200 Subject: Why do we nned both - __init__() and __new__() References: <437bea63-c8a3-49fb-a6b1-31961ba5e8c7@googlegroups.com> Message-ID: <87d1718y8c.fsf@handshake.de> Andrej Viktorovich writes: > For my understanding both - __init__() and __new__() works like constructors. And __new__() looks is closer to constructor. __init__() is more for variable initialization. Why I can't just initialize in __init__() ? > > class ExampleClass(object): > def __new__(cls,value): > print("creating new instance with val %s" % (value,) ) > instance = super(ExampleClass,cls).__new__(cls) > return instance > def __init__(self, value): > print("Initialising instance... with val %s" % (value,)) > self.payload = value > > exampleInstance = ExampleClass(42) > print(exampleInstance.payload) In this special case (as others already explained, it is quite common), you do not need "__new__". In the general case, constructing an object can be split into two subtasks: obtain a raw piece of storage able to manage the object's state; initialize the object's state. The first subtask is handled by "__new__", the second by "__init__". Python has defaults for both subtasks -- and as others already pointed out, the default "__new__" is almost always sufficient. From greg.ewing at canterbury.ac.nz Fri Sep 8 03:48:27 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Sep 2017 19:48:27 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59b1f96d$0$16737$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> <59b18061$0$16726$b1db1813$d948b532@news.astraweb.com> <66a603dd-ff6e-47f3-a4ea-c4562b980efd@googlegroups.com> <59b1f96d$0$16737$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > A harder question is, what if you take a random number from the Integers? How > many digits will it have in (say) base 10? I don't have a good answer to that. > I think it may be ill-defined. I think the answer is that on average it has infinitely many digits -- despite every actual integer only having finitely many digits! We can prove this by contradiction. Suppose the answer were some finite number N. There are only finitely many integers with N or fewer digits, but there are infinitely many with more than N digits, so including them in the average must make it bigger than N. So N cannot be finite. -- Greg From greg.ewing at canterbury.ac.nz Fri Sep 8 03:54:28 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Sep 2017 19:54:28 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59b1fbd6$0$16728$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b1fbd6$0$16728$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > py> class K: # defines an object > ... def __init__(self, x): > ... self.x = x > ... def append(self, value): > ... self.x.append(value) > ... > py> a = [] > py> b = K(a) > py> a is b # these are not the same object (they're different types) > False > py> b.append(99) # but modifying b modifies a > py> a > [99] You didn't mutate the object bound to b there, you mutated the one bound to b.x, which is also bound to a. All you've shown is that just because a method is named "append" doesn't mean it mutates the object it's a method of. :-) -- Greg From greg.ewing at canterbury.ac.nz Fri Sep 8 03:58:56 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Sep 2017 19:58:56 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> Message-ID: Rustom Mody wrote: > I'd like to know what these rules are I can't give you a complete list of them off the top of my head, but some examples of the kind of rules I have in mind are: * After the assigment a = b a and b refer to the same object. * After x = [e1, e2, e3, ...] x refers to a new object that's not the same as any other object. -- Greg From viktorovichandrej at gmail.com Fri Sep 8 04:17:49 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Fri, 8 Sep 2017 01:17:49 -0700 (PDT) Subject: class inheritance when not defined Message-ID: <73824550-e5e2-4292-85dc-795ed75f12f0@googlegroups.com> Hello I found several class creation samples: class ExampleClass1: class ExampleClass2(object): What is difference between them? Who is the father of ExampleClass1 ? From jmeile at hotmail.com Fri Sep 8 04:22:14 2017 From: jmeile at hotmail.com (Josef Meile) Date: Fri, 8 Sep 2017 08:22:14 +0000 Subject: Need to pass a class instance to a gettext fallback In-Reply-To: References: Message-ID: Hi Peter Your code worked, but I did some changes. First of all: I decided that I don't really needed to pass the py_plugin instance. I only needed an attribute called: self._language. Anyway, if I passed it without doing anything else, I got: TypeError: __init__() got an unexpected keyword argument 'language' In this call inside the MissingTranslationsFallback class. super(MissingTranslationsFallback, self).__init__(*args, **kwargs) The error is clear, the constructor of: "gettext.GNUTranslations" isn't expecting an argument called: 'language', so, I removed it before doing the call: language = kwargs['language'] del kwargs['language'] super(MissingTranslationsFallback, self).__init__(*args, **kwargs) And it worked. Thanks a lot for your help. Now it looks nice without those nasty global variables :-) Here the resulting code: class TranslationService(object): """...__init__ and other methods are defined here""" def install(self): """...some code goes here...""" current_catalog = gettext.translation(plugin_name, localedir = locale_folder, class_= functools.partial( MissingTranslationsFallback, language = self._language ), languages = [current_language] ) current_catalog.install() class MissingTranslationsFallback(gettext.GNUTranslations, object): def __init__(self, *args, **kwargs): language = kwargs['language'] del kwargs['language'] super(MissingTranslationsFallback, self).__init__(*args, **kwargs) self.add_fallback(MissingTranslationsLogger(language)) Best regards Josef -----Original Message----- From: Python-list [mailto:python-list-bounces+jmeile=hotmail.com at python.org] On Behalf Of Peter Otten Sent: Freitag, 8. September 2017 08:15 To: python-list at python.org Subject: Re: Need to pass a class instance to a gettext fallback Josef Meile wrote: > Hi > > I'm working with gettext and need to define a language Fallback. I got > this working, but with a global variable. I don't really like this and > I would like to pass this variable to the gettext Fallback's > contructor, but I don't know how. For simplicity, I won't put the > whole code here, just the important parts. > > Before you look at it, I want to ask you: how can I pass the variable: > "my_plugin" to the constructor of the "MissingTranslationsFallback" class? > If you see, an instance of this class will be created automatically by > gettext. I don't create it. When calling the " add_fallback" method of > the gettext.GNUTranslations class, you have to pass a class and not an > instance. Provided the class_ argument to gettext.translation() accepts an arbitrary callable the following may work: import functools > #Defining a global dict, which is ugly, I know MY_GLOBALS = {} > > class TranslationService(object): > """...__init__ and other methods are defined here""" > > def install(self): > """...some code goes here...""" current_catalog = gettext.translation( plugin_name, localedir=locale_folder, class_=functools.partial( MissingTranslationsFallback, py_plugin=self._py_plugin ), languages=[current_language] ) > current_catalog.install() > > class MissingTranslationsFallback(gettext.GNUTranslations, object): > def __init__(self, *args, **kwargs): py_plugin = kwargs.pop("py_plugin") > super(MissingTranslationsFallback, self).__init__(*args, **kwargs) > i18n_service = py_plugin.get_i18n_service() > #Adds an instance to the class that will handle the missing > #translations > self.add_fallback(MissingTranslationsLogger(i18n_service.get_language())) -- https://mail.python.org/mailman/listinfo/python-list From greg.ewing at canterbury.ac.nz Fri Sep 8 04:45:36 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Sep 2017 20:45:36 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <588a0643-28ea-4938-bf79-77ae66c0eaab@googlegroups.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b1fbd6$0$16728$b1db1813$d948b532@news.astraweb.com> <588a0643-28ea-4938-bf79-77ae66c0eaab@googlegroups.com> Message-ID: Rustom Mody wrote: > Models are needed > Math is one possible model > Machines are another I'm not sure there's any real distinction between "math" and "machines". A Turing machine, for example, is an idealised mathematical model of computation. Maybe the distiction you're trying to get at is "stateless" vs. "stateful" models of computation? With lambda calculus being an example of a stateless model, and a Turing machine a stateful one. However, I suspect that the reason you're having trouble with the concept of "same object" in a mathematical setting is that you're failing to consider the identity of an object to be a piece of information in its own right that needs to be included in the model. If you see something like this from a Python session: >>> a [1, 2] >>> b [1, 2] you *can't tell* just by looking at that whether a and b are bound to the same object. That's an extra piece of information that isn't shown in those textual representations. This is why we have things like the "is" operator and the id() function -- they provide ways of probing that hidden information. If you want to model Python computation purely mathematically, you need to come up with a way to make that extra information explicit. There are many ways that can be done. One way is to draw a graph. Another might be to assign id numbers to objects and represent objects as (id, value) tuples. But the information needs to be there in some form, otherwise you're not modelling Python. -- Greg From tjol at tjol.eu Fri Sep 8 04:47:54 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 8 Sep 2017 10:47:54 +0200 Subject: class inheritance when not defined In-Reply-To: <73824550-e5e2-4292-85dc-795ed75f12f0@googlegroups.com> References: <73824550-e5e2-4292-85dc-795ed75f12f0@googlegroups.com> Message-ID: <7f3fe271-9061-dca2-758b-ed939a7b5986@tjol.eu> On 2017-09-08 10:17, Andrej Viktorovich wrote: > Hello > > I found several class creation samples: > > class ExampleClass1: > > class ExampleClass2(object): > > > What is difference between them? Who is the father of ExampleClass1 ? > In Python 3, unless you've redefined "object", these are the same. Python 2 had, for historical reasons, a distinction between "old-style" and "new-style" classes. It normally doesn't matter much, but explicitly inheriting from object makes a class new-style. -- Thomas Jollans From greg.ewing at canterbury.ac.nz Fri Sep 8 05:00:32 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Sep 2017 21:00:32 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <87wp5ajytb.fsf@elektro.pacujo.net> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <87wp5ajytb.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > I definitely trust that: > > a = b > assert a is b > > even when b holds an immutable object. That's true, but there's rarely a good use case for that fact that isn't better addressed with an equality comparison rather than an 'is' test. As an example, back in the days of string exceptions, the established idiom was MyException = "MyException" try: ... raise MyException ... except MyException: ... Which worked, but it was error-prone. Writing except "MyException": instead would *probably* work, but wasn't guaranteed. If the implementation had matched string exceptions by equality rather than identity, that wouldn't have been an issue. -- Greg From ben+python at benfinney.id.au Fri Sep 8 05:03:45 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 08 Sep 2017 19:03:45 +1000 Subject: class inheritance when not defined References: <73824550-e5e2-4292-85dc-795ed75f12f0@googlegroups.com> Message-ID: <85r2vh8sum.fsf@benfinney.id.au> Andrej Viktorovich writes: > I found several class creation samples: > > class ExampleClass1: > > class ExampleClass2(object): > > > What is difference between them? Very little difference. In Python 3, both create classes that inherit from one other class, ?object?. In Python 2, the first creates ?ExampleClass1? that has no parent class, and doesn't work in the standard type hierarchy. The ?ExampleClass2? class inherits from ?object? and does participate in the standard type hierarchy. This is, broadly, one of the good reasons to abandon Python 2: you can forget about the special case of classes that don't inherit from ?object?. In Python 3, they don't exist because every class inherits ultimately from ?object?. > Who is the father of ExampleClass1 ? No-one, since classes do not have gender. (The convention is to use the gender-neutral ?parent? to refer to that relationship.) -- \ ?We cannot solve our problems with the same thinking we used | `\ when we created them.? ?Albert Einstein | _o__) | Ben Finney From marko at pacujo.net Fri Sep 8 05:33:05 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 08 Sep 2017 12:33:05 +0300 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <87wp5ajytb.fsf@elektro.pacujo.net> Message-ID: <87mv65k01a.fsf@elektro.pacujo.net> Gregory Ewing : > Marko Rauhamaa wrote: >> I definitely trust that: >> >> a = b >> assert a is b >> >> even when b holds an immutable object. > > That's true, but there's rarely a good use case for that > fact that isn't better addressed with an equality comparison > rather than an 'is' test. I use the principle in sentinel objects. I don't care about equality but identity. > As an example, back in the days of string exceptions, > the established idiom was > > MyException = "MyException" > > try: > ... > raise MyException > ... > except MyException: > ... > > Which worked, but it was error-prone. Writing > > except "MyException": > > instead would *probably* work, but wasn't guaranteed. > If the implementation had matched string exceptions > by equality rather than identity, that wouldn't have > been an issue. I would never have thought of doing that. However, strings are as good sentinel objects as any (they are trivially printable). Whatever sentinel object you choose, identity is the name of the game, not equality. Marko From rosuav at gmail.com Fri Sep 8 05:45:54 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Sep 2017 19:45:54 +1000 Subject: Design: method in class or general function? In-Reply-To: <85zia68wkr.fsf@benfinney.id.au> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> Message-ID: On Thu, Sep 7, 2017 at 11:31 PM, Ben Finney wrote: > leam hall writes: > >> I've wrestled with that discussion for a while and Python 3 loses every >> time. > > > The context of the thread you started was that you are a *newcomer* to > Python. Now you say you've considered Python 2 versus Python 3 many > times? What explains that apparent contradiction? The original comment was "OOP newbie". My reading is that s/he has used Py2 for years but never actually created a class - which is a perfectly reasonable thing in Python, unlike some languages. That said, though: even if you're not going to move to Python 3, I *strongly* recommend moving to 2.7. Python 2.6 is ancient and not in support; Python 2.7 is still old, but is in support (for a few more years with python.org, and then possibly after that if you have pay-for support eg with Red Hat). There should be very few reasons for sticking with 2.6. Those millions of servers running Python 2? You'd be surprised how many of them are now actually running Python 3 - but the rest of them NEED to be on 2.7 if they want bug fixes and security patches. Don't wait for a major problem. ChrisA From leamhall at gmail.com Fri Sep 8 05:59:52 2017 From: leamhall at gmail.com (Leam Hall) Date: Fri, 8 Sep 2017 05:59:52 -0400 Subject: Design: method in class or general function? In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> Message-ID: <9dd11726-212d-5046-7ead-562c21d2d729@gmail.com> On 09/08/2017 03:06 AM, Peter Otten wrote: > I'm pleading "method" as it allows per-class implementation. Peter, as always you are a wealth of information! I have some extra time today to digest your notes and visualize tap dancing Marines. Thank you! From leamhall at gmail.com Fri Sep 8 06:12:51 2017 From: leamhall at gmail.com (Leam Hall) Date: Fri, 8 Sep 2017 06:12:51 -0400 Subject: Using Python 2 (was: Design: method in class or general function?) In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> Message-ID: On 09/08/2017 05:45 AM, Chris Angelico wrote: > On Thu, Sep 7, 2017 at 11:31 PM, Ben Finney wrote: >> leam hall writes: >> >>> I've wrestled with that discussion for a while and Python 3 loses every >>> time. >> >> >> The context of the thread you started was that you are a *newcomer* to >> Python. Now you say you've considered Python 2 versus Python 3 many >> times? What explains that apparent contradiction? > > The original comment was "OOP newbie". My reading is that s/he has > used Py2 for years but never actually created a class - which is a > perfectly reasonable thing in Python, unlike some languages. > > That said, though: even if you're not going to move to Python 3, I > *strongly* recommend moving to 2.7. Python 2.6 is ancient and not in > support; Python 2.7 is still old, but is in support (for a few more > years with python.org, and then possibly after that if you have > pay-for support eg with Red Hat). There should be very few reasons for > sticking with 2.6. > > Those millions of servers running Python 2? You'd be surprised how > many of them are now actually running Python 3 - but the rest of them > NEED to be on 2.7 if they want bug fixes and security patches. Don't > wait for a major problem. > > ChrisA > Chris, there's a big part of me that agrees with you. However, those millions of servers are running Python 2.6 and a smaller number running 2.7. At least in the US market since Red Hat Enterprise Linux and its derivatives run 2.6.6 (RHEL 6) or 2.7.5 (RHEL 7). Not sure what Python SuSE uses but they seem to have a fairly large European footprint. RHEL 7 goes out the active support door (End of Production Phase 3) mid-2024. I've read comments about Python 3 moving from the Zen of Python. I'm a "plain and simple" person myself. Complexity to support what CompSci folks want, which was used to describe some of the Python 3 changes, doesn't help me get work done. That said, if the next job I go to is 100% Python 3 then I guess I'm doing a lot more Python 3. From ben.usenet at bsb.me.uk Fri Sep 8 06:20:32 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Fri, 08 Sep 2017 11:20:32 +0100 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> Message-ID: <87pob1h4pb.fsf@bsb.me.uk> Steve D'Aprano writes: > On Fri, 8 Sep 2017 12:28 am, Chris Angelico wrote: > >> languages without mutable objects don't >> really care whether they're pass-by-X or pass-by-Y. > > Only if you don't care about efficiency. > > Believe me, the first time you pass a five gigabyte array to a function using > pass-by-value, on a machine with only six gigabytes of memory, you'll care. I think your general idea to separate language semantics from implementation details is a good one, but you've dropped it here. A language with call-by-value semantics need not copy large objects when passing them to a function. The program must behave *as if* there is a copy but there need not actually be one. -- Ben. From greg.ewing at canterbury.ac.nz Fri Sep 8 06:25:25 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 08 Sep 2017 22:25:25 +1200 Subject: tictactoe script - commented - may have pedagogical value In-Reply-To: <59b0f128$0$16632$b1db1813$d948b532@news.astraweb.com> References: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> <59b0a1cb$0$16743$b1db1813$d948b532@news.astraweb.com> <59b0f128$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > But anyway... it doesn't seem to me that the page is doing any > computation using HTML. It's more like a book listing a table of primes. It's a "Choose Your Own Game Of Tic-Tac-Toe" book! -- Greg From ben+python at benfinney.id.au Fri Sep 8 06:30:25 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 08 Sep 2017 20:30:25 +1000 Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> Message-ID: <85mv658ou6.fsf@benfinney.id.au> Leam Hall writes: > I've read comments about Python 3 moving from the Zen of Python. For what it's worth: I have done successful conversions of numerous code bases from Python 2 to Python 3, and that characterisation does not fit at all. The resulting code base is much more Pythonic. > I'm a "plain and simple" person myself. Complexity to support what > CompSci folks want, which was used to describe some of the Python 3 > changes, doesn't help me get work done. Exactly so. You should ignore the far too academic debates that flourish here, and concentrate only on the practical differences going from Python 2 to Python 3. Those alone make it worthwhile to learn Python 3. -- \ ?Life does not cease to be funny when people die any more than | `\ it ceases to be serious when people laugh.? ?George Bernard Shaw | _o__) | Ben Finney From marko at pacujo.net Fri Sep 8 06:40:47 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 08 Sep 2017 13:40:47 +0300 Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> Message-ID: <87efrhjwwg.fsf@elektro.pacujo.net> Leam Hall : > However, those millions of servers are running Python 2.6 and a > smaller number running 2.7. At least in the US market since Red Hat > Enterprise Linux and its derivatives run 2.6.6 (RHEL 6) or 2.7.5 (RHEL > 7). Not sure what Python SuSE uses but they seem to have a fairly > large European footprint. RHEL 7 goes out the active support door (End > of Production Phase 3) mid-2024. Ok, the owners of those millions of servers have a problem in their hands. What you are saying is that there will be a bonanza next year for Python 2-to-3 consultants. It will also involve a forced upgrade to RHEL 8 (which is nowhere in sight yet). Marko From leamhall at gmail.com Fri Sep 8 07:12:36 2017 From: leamhall at gmail.com (Leam Hall) Date: Fri, 8 Sep 2017 07:12:36 -0400 Subject: Using Python 2 In-Reply-To: <87efrhjwwg.fsf@elektro.pacujo.net> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <87efrhjwwg.fsf@elektro.pacujo.net> Message-ID: <465a7b05-a6ff-649f-c0b0-dbb1f432da9d@gmail.com> On 09/08/2017 06:40 AM, Marko Rauhamaa wrote: > Leam Hall : >> However, those millions of servers are running Python 2.6 and a >> smaller number running 2.7. At least in the US market since Red Hat >> Enterprise Linux and its derivatives run 2.6.6 (RHEL 6) or 2.7.5 (RHEL >> 7). Not sure what Python SuSE uses but they seem to have a fairly >> large European footprint. RHEL 7 goes out the active support door (End >> of Production Phase 3) mid-2024. > > Ok, the owners of those millions of servers have a problem in their > hands. > > What you are saying is that there will be a bonanza next year for Python > 2-to-3 consultants. It will also involve a forced upgrade to RHEL 8 > (which is nowhere in sight yet). Not really, though a growing market is good. The OS system tools are in Python 2 so that's what is installed. Nothing prevents an application from installing Python 3, it just can't overwrite the OS python. Application developers can put Python 3 in /usr/local or can use one of the probably older python3 rpm stacks. My dev box has both the OS Python 2.6.6 and Python 3.6.2 called as python3. From steve+python at pearwood.info Fri Sep 8 08:05:06 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 08 Sep 2017 22:05:06 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> <59b18061$0$16726$b1db1813$d948b532@news.astraweb.com> <66a603dd-ff6e-47f3-a4ea-c4562b980efd@googlegroups.com> <59b1f96d$0$16737$b1db1813$d948b532@news.astraweb.com> Message-ID: <59b28775$0$16753$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Sep 2017 05:48 pm, Gregory Ewing wrote: > Steve D'Aprano wrote: >> A harder question is, what if you take a random number from the Integers? How >> many digits will it have in (say) base 10? I don't have a good answer to >> that. I think it may be ill-defined. > > I think the answer is that on average it has infinitely many > digits -- despite every actual integer only having finitely > many digits! I don't think that talking about the average integer is meaningful. Assuming we are talking about the arithmetic mean, we're dealing with a divergent sum that depends on the way you do the summation: 0 + 1 + -1 + 2 + -2 + 3 + -3 + ... = 0 0 + 1 + 2 + 3 + 4 + ... + (-1 - 2 - 3 - 4 - ...) = ? - ? which is undefined. (Other means have similar problems, they're just harder to write or less familiar.) There's even a (legitimate!) argument to be made that the sum of all positive integers is -1/12. http://www.slate.com/blogs/bad_astronomy/2014/01/18/follow_up_the_infinite_series_and_the_mind_blowing_result.html More here: https://en.wikipedia.org/wiki/1_%2B_2_%2B_3_%2B_4_%2B_%E2%8B%AF Not to mention the inconvenient fact that we're dividing by infinity: (sum of all integers (whatever it is!))/? I don't think there is any way to select a random integer with equal probability, but even if we had one, there's no guarantee that the sample means would converge to the population mean. This is rather like the Cauchy distribution, where the mean is not defined, and the sample means oscillate more and more wildly as you sample more values. So I think that any answer that requires talking about the mean or average is ill-defined. At least unless we include significantly more rigour than I am capable of. If we instead say, "pick a random integer between 0 and N", and then let N increase without limit, we see that the average number of digits also increases without limit. But that's not the same as saying that the average number of digits is infinite! We *can* say that about choosing a random Real, because the irrational numbers outnumber the rationals by so much that any random Real we pick is Almost Always irrational. And irrationals don't have a finite expansion in any integer base. Hence we can argue that we're almost certain to choose an irrational number, and irrationals have infinite digits in their expansion. But we can't say the same thing for integers. As you point out, all integers have a finite number of digits, so we're on shaky ground to say that the average integer has infinite digits. That implies that the average is bigger than all the elements making up the average! Trying to make sense of divergent series is fraught with traps. Many very simple sounding questions involving divergent series don't have an answer at all. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Fri Sep 8 08:32:03 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Sep 2017 22:32:03 +1000 Subject: Using Python 2 (was: Design: method in class or general function?) In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> Message-ID: On Fri, Sep 8, 2017 at 8:12 PM, Leam Hall wrote: > However, those millions of servers are running Python 2.6 and a smaller > number running 2.7. At least in the US market since Red Hat Enterprise Linux > and its derivatives run 2.6.6 (RHEL 6) or 2.7.5 (RHEL 7). Not sure what > Python SuSE uses but they seem to have a fairly large European footprint. > RHEL 7 goes out the active support door (End of Production Phase 3) > mid-2024. How many servers are still running RHEL 6 and can't upgrade to RHEL 7 (or later) before 2020? If you absolutely cannot upgrade to Python 3, at least upgrade to 2.7. But as others have said, upgrading to 3.4+ is not as hard as many people fear, and your code generally improves as a result - for example, you often get improvements in internationalization support from the text/bytes split. ChrisA From falcone.giuseppe at gmail.com Fri Sep 8 08:34:57 2017 From: falcone.giuseppe at gmail.com (falcone.giuseppe at gmail.com) Date: Fri, 8 Sep 2017 05:34:57 -0700 (PDT) Subject: python gdal error Message-ID: Hi to all, I'm new to python program and I have a problem with the following code. I'm unable to read field_data variable in retrieve_model_params function. In debug, execution ends immediately without a message. Anyone have some idea about that? If the for cycle in retrieve_model_params is moved to read_data_from_shape function, everything works perfectly ... Thanks a lot. Giuseppe import os from osgeo import ogr def read_data_from_shape(): "This function load data from a shapefile" shp_driver = ogr.GetDriverByName("ESRI Shapefile") data_source = shp_driver.Open("../shape.shp", 0) layer = data_source.GetLayer() feature_count = layer.GetFeatureCount() print("Number of features:: %d" % (feature_count)) return layer def retrieve_model_params(): # load data field_data = read_data_from_shape() for feature in field_data: vol = feature.GetField('VolHa') print(vol) def main(): retrieve_model_params() if __name__ == '__main__': main() From rosuav at gmail.com Fri Sep 8 08:42:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Sep 2017 22:42:11 +1000 Subject: A question on modification of a list via a function invocation In-Reply-To: <59b28775$0$16753$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> <59b18061$0$16726$b1db1813$d948b532@news.astraweb.com> <66a603dd-ff6e-47f3-a4ea-c4562b980efd@googlegroups.com> <59b1f96d$0$16737$b1db1813$d948b532@news.astraweb.com> <59b28775$0$16753$b1db1813$d948b532@news.astraweb.com> Message-ID: On Fri, Sep 8, 2017 at 10:05 PM, Steve D'Aprano wrote: > On Fri, 8 Sep 2017 05:48 pm, Gregory Ewing wrote: > >> Steve D'Aprano wrote: >>> A harder question is, what if you take a random number from the Integers? How >>> many digits will it have in (say) base 10? I don't have a good answer to >>> that. I think it may be ill-defined. >> >> I think the answer is that on average it has infinitely many >> digits -- despite every actual integer only having finitely >> many digits! > > I don't think that talking about the average integer is meaningful. Assuming we > are talking about the arithmetic mean, we're dealing with a divergent sum that > depends on the way you do the summation: > > 0 + 1 + -1 + 2 + -2 + 3 + -3 + ... = 0 > > 0 + 1 + 2 + 3 + 4 + ... + (-1 - 2 - 3 - 4 - ...) = ? - ? which is undefined. > > (Other means have similar problems, they're just harder to write or less > familiar.) Here's a different take on the problem. The first integer (zero) has, let's say, no digits. Then the next 18 (1 through 9 and -1 through -9) have one digit. The next 180 have two digits (getting us to 99 and -99). Etcetera. Multiply each digit count by how many numbers have it, and divide by the grand total: (0 * 1 + 1 * 18 + 2 * 18 * 10 + 3 * 18 * 100 ...) / (1 + 18 + 18*10 + 18*100 ...) As you add terms, the earlier terms become diminishingly significant to the result, and the final term approaches digits/1.1 (in this example, 3 * 1800 / (1800+180+18+1)). Since digits is tending towards +?, so is the sum. ChrisA From marko at pacujo.net Fri Sep 8 08:42:58 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 08 Sep 2017 15:42:58 +0300 Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> Message-ID: <878thpjr8t.fsf@elektro.pacujo.net> Chris Angelico : > But as others have said, upgrading to 3.4+ is not as hard as many > people fear, and your code generally improves as a result That's somewhat irrelevant. Point is, Python 2 will quickly become a pariah in many corporations during or after 2018, and we are going to see emergency measures similar to the Y2K craze twenty years ago. The risk to Python will be whether the occasion is exploited by fanboys of competing programming languages. The migration from Python 2 might be to something else than Python 3 in some circles. Marko From larry.martell at gmail.com Fri Sep 8 08:50:03 2017 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 8 Sep 2017 08:50:03 -0400 Subject: Using Python 2 In-Reply-To: <878thpjr8t.fsf@elektro.pacujo.net> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <878thpjr8t.fsf@elektro.pacujo.net> Message-ID: On Fri, Sep 8, 2017 at 8:42 AM, Marko Rauhamaa wrote: > Chris Angelico : >> But as others have said, upgrading to 3.4+ is not as hard as many >> people fear, and your code generally improves as a result > > That's somewhat irrelevant. Point is, Python 2 will quickly become a > pariah in many corporations during or after 2018, and we are going to > see emergency measures similar to the Y2K craze twenty years ago. > > The risk to Python will be whether the occasion is exploited by fanboys > of competing programming languages. The migration from Python 2 might be > to something else than Python 3 in some circles. A lot of companies I work for say they don't have the time and/or money and/or they don't want to risk breaking things. If python 2 ever is not available I guess then they will have to find the time and money. From rosuav at gmail.com Fri Sep 8 08:51:08 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Sep 2017 22:51:08 +1000 Subject: Using Python 2 In-Reply-To: <878thpjr8t.fsf@elektro.pacujo.net> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <878thpjr8t.fsf@elektro.pacujo.net> Message-ID: On Fri, Sep 8, 2017 at 10:42 PM, Marko Rauhamaa wrote: > Chris Angelico : >> But as others have said, upgrading to 3.4+ is not as hard as many >> people fear, and your code generally improves as a result > > That's somewhat irrelevant. Point is, Python 2 will quickly become a > pariah in many corporations during or after 2018, and we are going to > see emergency measures similar to the Y2K craze twenty years ago. > > The risk to Python will be whether the occasion is exploited by fanboys > of competing programming languages. The migration from Python 2 might be > to something else than Python 3 in some circles. And the sky is going to fall on Chicken Little's head, any day now. Let's see. You can port your code from Python 2.7 to Python 3.6 by running a script and then checking the results for bytes/text problems. You can port your code from Python 2.7 to Ruby by paying developers big bucks for a good while. Advantage: Ruby, obviously, because it's easier to change languages than to audit your code for places where you had lurking bugs that you didn't know about. ChrisA From rhodri at kynesim.co.uk Fri Sep 8 09:01:43 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 8 Sep 2017 14:01:43 +0100 Subject: A question on modification of a list via a function invocation In-Reply-To: References: <1504526518l.11403280l.0l@psu.edu> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> <59b18061$0$16726$b1db1813$d948b532@news.astraweb.com> <66a603dd-ff6e-47f3-a4ea-c4562b980efd@googlegroups.com> <59b1f96d$0$16737$b1db1813$d948b532@news.astraweb.com> Message-ID: <7f9a3602-d304-742d-3bfa-cb5e07028019@kynesim.co.uk> On 08/09/17 13:45, Stefan Ram wrote: > Gregory Ewing writes: > [a random integer will on average have ] >> infinitely many >> digits -- despite every actual integer only having finitely >> many digits! > This is not possible because every integer has > a finite number of digits (in base 10). Surely an infinitely large integer has an infinite number of digits? -- Rhodri James *-* Kynesim Ltd From steve+python at pearwood.info Fri Sep 8 09:33:33 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 08 Sep 2017 23:33:33 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b1fbd6$0$16728$b1db1813$d948b532@news.astraweb.com> Message-ID: <59b29c2e$0$16722$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Sep 2017 05:54 pm, Gregory Ewing wrote: > Steve D'Aprano wrote: >> py> class K: # defines an object >> ... def __init__(self, x): >> ... self.x = x >> ... def append(self, value): >> ... self.x.append(value) >> ... >> py> a = [] >> py> b = K(a) >> py> a is b # these are not the same object (they're different types) >> False >> py> b.append(99) # but modifying b modifies a >> py> a >> [99] > > You didn't mutate the object bound to b there, > you mutated the one bound to b.x, which is > also bound to a. Of course I do -- I've mutated one of the parts of the whole, therefore the whole is mutated too. Would you argue that if I took a hammer to your computer's motherboard, smashing it to bits, that I haven't damaged your computer? My class K is just a minimal sketch of a class that uses dependency injection and composition, but that's not critical. Any compound object which has publicly visible mutable parts is subject to the same sort of false positive: book = Book() assert book.annotations == [] page = book.pages[15] assert book is not page # the whole is not the same as the part page.annotate( 'Is this the right room for an argument?') # but if you mutate the part assert book.annotations == [15] # the whole mutates too -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ned at nedbatchelder.com Fri Sep 8 09:57:28 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 8 Sep 2017 09:57:28 -0400 Subject: Using Python 2 In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> Message-ID: <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> On 9/8/17 6:12 AM, Leam Hall wrote: > I've read comments about Python 3 moving from the Zen of Python. I'm a > "plain and simple" person myself. Complexity to support what CompSci > folks want, which was used to describe some of the Python 3 changes, > doesn't help me get work done. I've heard a lot of FUD about the Python 3 transition, but this one is new to me.? What is it that CompSci folks want that developers don't want, that ruined Python 3? --Ned. From marko at pacujo.net Fri Sep 8 10:20:52 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 08 Sep 2017 17:20:52 +0300 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <87wp5ajytb.fsf@elektro.pacujo.net> Message-ID: <874lsdjmpn.fsf@elektro.pacujo.net> ram at zedat.fu-berlin.de (Stefan Ram): > Marko Rauhamaa writes: >>I definitely trust that: >>a = b >>assert a is b >>even when b holds an immutable object. > > |Python 3.6.0 ... > |>>> x = 21568 > |>>> x is 21568 > |False I wasn't talking about x or 21568. I was talking about a and b. Marko From antoon.pardon at vub.be Fri Sep 8 10:21:32 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 8 Sep 2017 16:21:32 +0200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59b1fbd6$0$16728$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b1fbd6$0$16728$b1db1813$d948b532@news.astraweb.com> Message-ID: Op 08-09-17 om 04:09 schreef Steve D'Aprano: > On Fri, 8 Sep 2017 04:24 am, Rustom Mody wrote: > >> On Thursday, September 7, 2017 at 6:52:04 PM UTC+5:30, Gregory Ewing wrote: >>> Rustom Mody wrote: >>> >>>> I said: In that case please restate the definition of 'is' from the manual >>>> which invokes the notion of 'memory' without bringing in memory. >>> I don't know whether it's in the manual, but at least for >>> mutable objects, there is a way to define the notion of >>> "same object" that doesn't require talking about "memory": >>> >>> Two names refer to the same object if and only if mutations >>> made through one are visible through the other. >> Seems a sensible comment! > > Except that it is wrong, or at least over-generalised. It is trivially easy to > show false positives: > > py> class K: # defines an object > ... def __init__(self, x): > ... self.x = x > ... def append(self, value): > ... self.x.append(value) > ... > py> a = [] > py> b = K(a) > py> a is b # these are not the same object (they're different types) > False > py> b.append(99) # but modifying b modifies a > py> a > [99] I don't know if this is a False positive. Yes you have shown a mutation to one that also shows up in the other. But it is possible to mutate b in ways that doesn't show up in a. It seems you have interpreted the phrase: "if and only if mutations made through one are visible through the other." as if it said: "if and only if *some* mutations made through one are visible through the other." while it seems more natural to me to understand it as: "if and only if *all* mutations made through one are visible through the other." So since it is possible to mutate b in ways that are not reflected in a, I can't really see this as a false positive. -- Antoon Pardon From leamhall at gmail.com Fri Sep 8 10:23:01 2017 From: leamhall at gmail.com (Leam Hall) Date: Fri, 8 Sep 2017 10:23:01 -0400 Subject: Using Python 2 In-Reply-To: <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> Message-ID: <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> Various responses in no particular order: On 09/08/2017 09:57 AM, Ned Batchelder wrote: > I've heard a lot of FUD about the Python 3 transition, but this one is > new to me.? What is it that CompSci folks want that developers don't > want, that ruined Python 3? It's not FUD if it's true. Calling it FUD without checking is, um, FUD. The phrase was "many of the changes in Python 3 are theoretically based, cleaning up of how Python does things to make them fit with what Computer Science teaches." On 09/08/2017 08:51 AM, Chris Angelico wrote: > Let's see. You can port your code from Python 2.7 to Python 3.6 by > running a script and then checking the results for bytes/text > problems. I ran 2to3 on some code that worked under 2.6.6. and 3.6.2. 2to3 broke it for both versions and it was a fairly trivial script. On 09/08/2017 08:42 AM, Marko Rauhamaa wrote: > That's somewhat irrelevant. Point is, Python 2 will quickly become a > pariah in many corporations during or after 2018, and we are going to > see emergency measures similar to the Y2K craze twenty years ago. > > The risk to Python will be whether the occasion is exploited by > fanboys of competing programming languages. The migration from Python2 > might be to something else than Python 3 in some circles. To me this is where the Python community comes in. Moving 3,000 servers from RHEL 6 to something that uses Python 3 isn't a trivial task when most of those servers are not homogenous HPC nodes. If Python 2 has bugs that aren't going to be fixed, then let's ask the question. If Python 3 was a total re-write that is not backwards compatible then it likely has some of the same bugs (due to same coders) plus new ones. If Python 3 is not a total re-write then why break compatibility? To say Python 2 is old is true. What does it matter though? Unless Python 3 provides a business value for spending lots of time and money to change then "old" doesn't matter. You're right that people may migrate to something besides Python. For me that question is real and some of the fuel is how the community can't understand that I work on servers that only have an old version of python. So far one person has answered the original design question. Everyone else has tried to convince me of something that is financially and professionally impossible and completely useless. If you want to encourage people to move from Python 2 to 3 then continue to help answer questions when they are Python 2 based. Over time an individuals preference will be to move to Python 3 since 90% of the skill is already there. From a purely "is python a good language for many use cases" perspective the answer is yes. Welcome people and let their task needs and passions drive the change. Leam From steve+python at pearwood.info Fri Sep 8 10:38:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 09 Sep 2017 00:38:22 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> <87pob1h4pb.fsf@bsb.me.uk> Message-ID: <59b2ab5f$0$16734$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Sep 2017 08:20 pm, Ben Bacarisse wrote: > Steve D'Aprano writes: > >> On Fri, 8 Sep 2017 12:28 am, Chris Angelico wrote: >> >>> languages without mutable objects don't >>> really care whether they're pass-by-X or pass-by-Y. >> >> Only if you don't care about efficiency. >> >> Believe me, the first time you pass a five gigabyte array to a function using >> pass-by-value, on a machine with only six gigabytes of memory, you'll care. > > I think your general idea to separate language semantics from > implementation details is a good one, but you've dropped it here. A > language with call-by-value semantics need not copy large objects when > passing them to a function. The program must behave *as if* there is a > copy but there need not actually be one. You're right: I didn't think of the case where a language simulates pass-by-value semantics without actually copying. I was thinking only of actual pass-by-value implementations. Why would any compiler for a language with immutable arrays actually copy them when passing them to a function? *shrug* Call it a quality of implementation issue. Lots of compilers have sub-optimal implementations. One counter-example might be to implement copy-on-write, in which case the copying can be delayed until the array is written to. (Although Chris did specify languages with immutable data structures, so that's out.) But the larger point that I'm making is that we're not actually doing computation in some abstract, Platonic space of pure mathematics, we're using real computers that have to shunt actual electrons through wires and semiconductors at high speed to do anything. Computation has real costs. We can try to ignore them, but they exist. And even absent mutation, the way you pass arguments has costs to: - the overhead of passing arguments to functions adds up; even a tiny difference in efficiency can make a big difference to the overall speed of the implementation; - as well as the memory consumption; - the amount of work the CPU does, hence your electricity bill; - to say nothing of the Greenhouse gases, the electronic failure rate, etc; - let's not forget the complexity of the compiler and the possibility of bugs. See: https://en.wikipedia.org/wiki/Man_or_boy_test Unless pass-by-X and pass-by-Y have the same costs, somebody somewhere is going to care about the difference. That was my point. I tried to express it humorously rather than pedantically. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Fri Sep 8 10:41:39 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Sep 2017 00:41:39 +1000 Subject: Using Python 2 In-Reply-To: <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> Message-ID: On Sat, Sep 9, 2017 at 12:23 AM, Leam Hall wrote: > Various responses in no particular order: > > On 09/08/2017 09:57 AM, Ned Batchelder wrote: >> >> I've heard a lot of FUD about the Python 3 transition, but this one is >> new to me. What is it that CompSci folks want that developers don't >> want, that ruined Python 3? > > It's not FUD if it's true. Calling it FUD without checking is, um, FUD. The > phrase was "many of the changes in Python 3 are theoretically based, > cleaning up of how Python does things to make them fit with what Computer > Science teaches." Please give examples. Otherwise it is FUD. > On 09/08/2017 08:51 AM, Chris Angelico wrote: >> Let's see. You can port your code from Python 2.7 to Python 3.6 by >> running a script and then checking the results for bytes/text >> problems. > > I ran 2to3 on some code that worked under 2.6.6. and 3.6.2. 2to3 broke it > for both versions and it was a fairly trivial script. Show the code that it broke? I've never seen this, unless it's something like "now you need to install third-party package X in Python 3". The 2to3 transformations are fine for everything in the stdlib. > On 09/08/2017 08:42 AM, Marko Rauhamaa wrote: >> That's somewhat irrelevant. Point is, Python 2 will quickly become a >> pariah in many corporations during or after 2018, and we are going to >> see emergency measures similar to the Y2K craze twenty years ago. >> >> The risk to Python will be whether the occasion is exploited by >> fanboys of competing programming languages. The migration from Python2 > >> might be to something else than Python 3 in some circles. > > To me this is where the Python community comes in. Moving 3,000 servers from > RHEL 6 to something that uses Python 3 isn't a trivial task when most of > those servers are not homogenous HPC nodes. Of course, but moving ONE server from RHEL 6 to RHEL 7 must surely be a supported operation. And then moving one more, and one more after that. The Red Hat folks aren't going to tell you to stay on RHEL 6 for the rest of time. > If Python 2 has bugs that aren't going to be fixed, then let's ask the > question. If Python 3 was a total re-write that is not backwards compatible > then it likely has some of the same bugs (due to same coders) plus new ones. > If Python 3 is not a total re-write then why break compatibility? False dichotomy. It's not a total rewrite, but it fixes certain long-standing issues. Compatibility had to be broken in order to change certain behaviours. > To say Python 2 is old is true. What does it matter though? Unless Python 3 > provides a business value for spending lots of time and money to change then > "old" doesn't matter. Of course. And the biggest business value, in a lot of cases, is that suddenly now your application works for ALL the world's people. A lot of Python 2 programs, like the equivalents in many other languages, work fine until someone uses "funny characters". And then their authors either forbid them, or fiddle around with lots of encoding and decoding, basically playing whack-a-mole until the problems disappear. With Python 3, it's completely straight-forward: you know what is bytes and what is text, and you convert at the boundaries. That's just one of the advantages of Python 3. A few others, in no particular order: * Much better support for asynchronous I/O, allowing higher per-process throughput for network servers * Faster Decimal handling * A much faster way to traverse directory trees * Several new standard-library modules that do things that formerly required third-party support > You're right that people may migrate to something besides Python. For me > that question is real and some of the fuel is how the community can't > understand that I work on servers that only have an old version of python. > So far one person has answered the original design question. Everyone else > has tried to convince me of something that is financially and professionally > impossible and completely useless. > > If you want to encourage people to move from Python 2 to 3 then continue to > help answer questions when they are Python 2 based. Over time an individuals > preference will be to move to Python 3 since 90% of the skill is already > there. From a purely "is python a good language for many use cases" > perspective the answer is yes. Welcome people and let their task needs and > passions drive the change. If we pretend that Python 3 doesn't exist, how will that encourage people to move from Py2 to Py3? Be honest now. Also, be completely honest here: how much work would it take for you to move your "millions of servers" from Python 2 to, say, PHP? or Ruby? or C? or JavaScript? Is any of those (or any write-in answer you wish) actually easier than porting to Python 3? We've heard the old story of "the Python 3 migration will drive people away from Python" many, MANY times before. I don't know of any success stories where someone brags about how easy it was to port their entire codebase to a different language, and I've read quite a few stories about people being surprised how easily they could switch to Python 3. More facts, less FUD, please. ChrisA From steve+python at pearwood.info Fri Sep 8 10:45:05 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 09 Sep 2017 00:45:05 +1000 Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <87efrhjwwg.fsf@elektro.pacujo.net> Message-ID: <59b2acf2$0$16748$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Sep 2017 08:40 pm, Marko Rauhamaa wrote: > Leam Hall : >> However, those millions of servers are running Python 2.6 and a >> smaller number running 2.7. At least in the US market since Red Hat >> Enterprise Linux and its derivatives run 2.6.6 (RHEL 6) or 2.7.5 (RHEL >> 7). Not sure what Python SuSE uses but they seem to have a fairly >> large European footprint. RHEL 7 goes out the active support door (End >> of Production Phase 3) mid-2024. > > Ok, the owners of those millions of servers have a problem in their > hands. > > What you are saying is that there will be a bonanza next year for Python > 2-to-3 consultants. It will also involve a forced upgrade to RHEL 8 > (which is nowhere in sight yet). Next year is 2018, not 2024. And there's always the possibility of paying Red Hat for extended support. (By the way, RHEL 6 goes out of Production Phase 3 in 2020.) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Fri Sep 8 10:49:34 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 09 Sep 2017 00:49:34 +1000 Subject: Delay a computation in another thread References: <59aa8daa$0$1605$c3e8da3$5496439d@news.astraweb.com> <59aa8f1a$0$1601$c3e8da3$5496439d@news.astraweb.com> <3efa7837-1e8f-aa66-f438-db89c0457ced@mrabarnett.plus.com> Message-ID: <59b2adff$0$16748$b1db1813$d948b532@news.astraweb.com> On Sun, 3 Sep 2017 03:03 am, MRAB wrote: > On 2017-09-02 11:59, Steve D'Aprano wrote: >> On Sat, 2 Sep 2017 08:53 pm, Steve D'Aprano wrote: >> >>> I want to delay a computation and then print it, in the REPL (interactive >>> interpreter). I have something like this: >> [...] >>> The other problem is that if I exit the REPL while a Timer is still active, >>> it freezes until the time has run before exiting. I know you can't kill a >>> thread from the main thread, but is there a way for the Timer to see that >>> the interpreter is shutting down and shut itself down? >> >> Oh! I see Timer objects have a cancel method. So I just need an atexit >> callback function that calls cancel to each of the Timer threads. >> > Timer is a subclass of Thread, so you can set its .daemon attribute. Sorry for the long delay in replying to this, but if I set its daemon attribute, won't that mean it will live on after the interpreter shuts down? Also, what happens if it tries to print after the interpreter shuts down? Where does output go? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From tjol at tjol.eu Fri Sep 8 11:03:13 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 8 Sep 2017 17:03:13 +0200 Subject: Delay a computation in another thread In-Reply-To: <59b2adff$0$16748$b1db1813$d948b532@news.astraweb.com> References: <59aa8daa$0$1605$c3e8da3$5496439d@news.astraweb.com> <59aa8f1a$0$1601$c3e8da3$5496439d@news.astraweb.com> <3efa7837-1e8f-aa66-f438-db89c0457ced@mrabarnett.plus.com> <59b2adff$0$16748$b1db1813$d948b532@news.astraweb.com> Message-ID: <0fb7e4b7-3cf3-f8c8-7344-990721e9078e@tjol.eu> On 2017-09-08 16:49, Steve D'Aprano wrote: > On Sun, 3 Sep 2017 03:03 am, MRAB wrote: > >> On 2017-09-02 11:59, Steve D'Aprano wrote: >>> On Sat, 2 Sep 2017 08:53 pm, Steve D'Aprano wrote: >>> >>>> I want to delay a computation and then print it, in the REPL (interactive >>>> interpreter). I have something like this: >>> [...] >>>> The other problem is that if I exit the REPL while a Timer is still active, >>>> it freezes until the time has run before exiting. I know you can't kill a >>>> thread from the main thread, but is there a way for the Timer to see that >>>> the interpreter is shutting down and shut itself down? >>> >>> Oh! I see Timer objects have a cancel method. So I just need an atexit >>> callback function that calls cancel to each of the Timer threads. >>> >> Timer is a subclass of Thread, so you can set its .daemon attribute. > > > Sorry for the long delay in replying to this, but if I set its daemon attribute, > won't that mean it will live on after the interpreter shuts down? > > Also, what happens if it tries to print after the interpreter shuts down? Where > does output go? On Linux, I think it would go to the same virtual terminal as it did before, if that still exists. (Otherwise, to /dev/null). This is how processes that started out attached to a terminal and then went into the background normally behave. No idea what happens on Windows, but if I had to guess, I'd say "not that". -- Thomas Jollans From stephanh42 at gmail.com.invalid Fri Sep 8 11:10:15 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 08 Sep 2017 15:10:15 GMT Subject: asyncio.gather cancellation behaviour Message-ID: Hi all, I am a bit mystified about the rationale of the cancellation behaviour of asyncio.gather. Case 1: "If the outer Future is cancelled, all children (that have not completed yet) are also cancelled." Case 2: "If any child is cancelled, this is treated as if it raised CancelledError ? the outer Future is not cancelled in this case. (THIS IS TO PREVENT THE CANCELLATION OF ONE CHILD TO CAUSE OTHER CHILDREN TO BE CANCELLED.)" [capitalization mine] Indeed I can observe this behavior. However, I would like to further understand the reasoning for not cancelling in case 2. Outside asyncio.gather, cancelling an "outer future" does NOT cancel the "inner future" on which the outer future is currently await-ing, while cancelling the "inner future" will raise a CancelledError which will cancel the outer future. Example: import asyncio f1 = asyncio.Future() async def make_f2(): await f1 f2 = asyncio.ensure_future(make_f2()) f2.cancel() # cancelling f1 instead will cancel BOTH f1 and f2 loop = asyncio.get_event_loop() try: loop.run_until_complete(f2) except asyncio.CancelledError: print("got CancelledError") print("f1 cancelled: ", f1.cancelled()) # prints False print("f2 cancelled: ", f2.cancelled()) # prints True So cancellation "normally" proceeds from inner future -> outer future. It seems somebody worked hard to reverse the direction in case of asyncio.gather. Why? Stephan From steve+python at pearwood.info Fri Sep 8 11:15:18 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 09 Sep 2017 01:15:18 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b1fbd6$0$16728$b1db1813$d948b532@news.astraweb.com> <588a0643-28ea-4938-bf79-77ae66c0eaab@googlegroups.com> Message-ID: <59b2b408$0$16753$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Sep 2017 01:01 pm, Rustom Mody wrote: > On Friday, September 8, 2017 at 7:39:38 AM UTC+5:30, Steve D'Aprano wrote: >> Rustom, I've already given you the definitive answer to your question about >> how to define `is` without talking about memory. You haven't replied or >> acknowledged it, so here is it again: >> >> `is` compares the two operands for identity. > > Preamble? so far so good > >> If the two operands are the same >> object, `is` returns True, if they are distinct objects, `is` returns False. > > restated > a is b iff a is b I hope you are not seriously claiming this is a circular argument. The first half of your restatement, before the "iff", represents *Python code*, not natural language, and needs to be quoted[1] to make sense. If you don't quote it, you are just stating a tautology: a is b iff a is b, which is true by definition, no matter what meaning we assign to the word "is". But that's not what I'm saying, and you are wrong to accuse me of giving a tautology. I'm referring to the Python expression (which is source code in a programming language which merely looks a bit like English), and explaining it in English terms. The "is" in the first half is not the same as the "is" in the second, which makes the sentence non-circular. This would be more obvious if we were having this discussion in (say) Hindi, Latin, Swahili, or German: `A is B` ob und nur wenn A ist B (Or should that be "ob und nur ob"? Google Translate prefers the first, but I have my doubts.) If Python used a mathematical symbol instead of the word "is" as the operator, it also would obviously be non-circular: `A ? B` if and only if A is B The mere happenstance that: (1) Python uses the English word "is" as the operator, rather than some other symbol like `?` or `===` or `?` or `.ist.`; and (2) we happen to be writing in English, rather than (say) Japanese or Russian or Esperanto or the Black Speech of Mordor; does not make my argument circular. You have been lead astray by the mere contingent fact that Python uses `is` for the operator, instead of some other symbol. Don't be fooled: the operator `is` is not the same as the English word "is". But you know that, so I'm not sure why you are trying to misrepresent my argument as circular. So let us start repairing your restatement by adding quotation marks. I use `` rather than "" because that's the convention used in Markdown for displaying inline code, and I'm quoting the code: `a is b` if and only if a is b is not circular, but it's not very clear[2]. I intentionally avoided using the English word "is" (not to be confused with the Python operator `is`) in my explanation, because I knew it would confuse people and lead them astray. So let us use a better explanation, one which is less likely to give a misleading impression: `a is b` if and only if the two operands are the same object which is closer to what I actually said and avoids giving the mistaken impression of circular reasoning. Now if you want to argue about the definition of "same", I have already stated my position: the commonsense or intuitive meaning of "the same thing" is sufficient here. If you disagree, then it is up to you to demonstrate a problem with the commonsense meaning in this context. >> This does require that we agree on "same object", which as you point out is >> (in its full generality) a difficult thing to define. > > More than difficult, impossible in the fully abstract philosophical case Fortunately, the fully abstract philosophical case is irrelevant here. [...] > E.g. in the past I've raised >> the paradox of My Grandfather's Axe. > > Dont see the relevance (here) The paradox of the axe is one illustration of the difficulty in defining "the same" in full generality. When objects persist through time and are subject to change, there are questions raised about what it means to say that something is the same when all its component bits have been replaced. So I'm agreeing with you[2] that "the same" in its full generality is difficult to define in a non-paradoxical way. >> But the intuitive, common-sense notion of "same object" is, I think, >> sufficient here. If you want to argue that it is *not* sufficient, I think >> it's up to you to demonstrate a problem with the definition. >> > > Its not that you cant raise philosophical problems if you want > But when concretized to (basic) math, there are no disputes > so the argument becomes obtuseness to no point I'm afraid I have no idea what you think you are saying here. > In the case of python data model every single interminable thread like this > one, obviously started by a noob asking something genuinely and indicating > a real confusion disproves your claim to obvious intuition and common sense The Original Poster wasn't confused by "sameness". The OP was confusing by scoping and mutation. You have to go back to 15 August to find the beginning of the thread, but the OP was having problems reconciling his expectations of how he thought Python behaved with how it actually behaved. If I understood his initial questions correctly, he expected that given: def test(alist): alist=[3, 6, 9] def test1(alist): alist[0] = 3 blist = [1, 2, 3] test(blist) test1(blist) one of two things would happen: (1) Either alist inside the function test() would alias the global variable blist (like call by reference), and *both* test() and test1() would change the value of blist; (2) Or alist would be a copy of blist (like call by value), and *neither* test() nor test1() would change the value of blist. He was confused that *only* test1() changed the value of blist, not about the question of `is` or "same object". > Just to reiterate: Someone asked a question > Its not clear what (s)he understood from what we have going on and on about > for 100s of posts I believe that the OP got their answer long before you started raising philosophical questions about the nature of "is" and "identity". The OP's last comment was on the 17th August; your first comment was nearly 12 hours later, and it was eighteen days later that you claimed: "Its the ?== is id? mess that is at the base of the mess" I don't know how you reached that conclusion. It seems irrelevant to the OP's problem. >> Can you show an actual false positive (two distinct objects for which `is` >> returns True) or false negative (the same object given as both operands for >> `is` nevertheless returns False)? In the absence of any actual bugs in the >> definition, I maintain that it is sufficient. > > You are not paying attention ? the example above I gave in which > python arbitrarily hi-handedly, inconsistently manifests different behavior > between integer 1 and tuple (1,2) I don't see the relevance. As you have been told an uncountably infinite number of times now[3], Python is under no obligation to meet your intuitions about which immutable objects it caches. > I am now dropping off this thread [more important things to do] > with this observation: I don't know whether to be relieved or disappointed. [1] The convention in English at least, is to distinguish between uses of a phrase and mentions of a phrase by quoting or italics. Here quoting is more convenient. An example of the USE-MENTION distinction is this quine: "Is a sentence fragment" is a sentence fragment. Without the quotation marks, it isn't even grammatical, let alone correct. [2] Try not to faint, and I'll try not to let it happen again *wink* [3] Not that I would ever exaggerate. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ned at nedbatchelder.com Fri Sep 8 11:16:26 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 8 Sep 2017 11:16:26 -0400 Subject: Using Python 2 In-Reply-To: <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> Message-ID: <79e18079-7db6-5f5c-e49d-3619e30e79cf@nedbatchelder.com> On 9/8/17 10:23 AM, Leam Hall wrote: > On 09/08/2017 09:57 AM, Ned Batchelder wrote: >> I've heard a lot of FUD about the Python 3 transition, but this one is >> new to me.? What is it that CompSci folks want that developers don't >> want, that ruined Python 3? > > > It's not FUD if it's true. Calling it FUD without checking is, um, > FUD. The phrase was "many of the changes in Python 3 are theoretically > based, cleaning up of how Python does things to make them fit with > what Computer Science teaches." I tried to check, but Google doesn't find me that quote, so I'm not sure if there was further elaboration. I still don't know which of the Python 3 changes were foisted on us by those bothersome theoretical Computer Science people. --Ned. From steve+python at pearwood.info Fri Sep 8 11:22:24 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 09 Sep 2017 01:22:24 +1000 Subject: class inheritance when not defined References: <73824550-e5e2-4292-85dc-795ed75f12f0@googlegroups.com> <85r2vh8sum.fsf@benfinney.id.au> Message-ID: <59b2b5b1$0$16721$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Sep 2017 07:03 pm, Ben Finney wrote: >> Who is the father of ExampleClass1 ? > > No-one, since classes do not have gender. (The convention is to use the > gender-neutral ?parent? to refer to that relationship.) Possibly not the case in Russia. Besides, words have gender in many languages. While I have no problem with correcting people's English when it is relevant, there's a good way and a bad way to do it. Good way: Foreigner speaking English as their second language: "Who is the father of this class?" Native English speaker: "The father is 'object', but in English we would normally ask 'what is the parent?' instead." Bad way: Foreigner: "Who is the father of this class?" Native: "No one, you ignorant heathen foreigner!" Worse way: Foreigner: "Who is the father of this class?" Native: *PLONK* I'll leave you to guess where I think your response fits in this scale :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Fri Sep 8 11:29:36 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 09 Sep 2017 01:29:36 +1000 Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <878thpjr8t.fsf@elektro.pacujo.net> Message-ID: <59b2b762$0$16753$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Sep 2017 10:50 pm, Larry Martell wrote: > If python 2 ever > is not available I guess then they will have to find the time and > money. Python 2 is open source, it will always be available so long as we still have computers capable of running present day software. (Presumably by the year 3000 nobody will still be able to run Linux or Windows... but few companies plan their activities a thousand years in advance.) Grab a VM of your OS and Python 2, and you'll be able to run it forever. You just won't get free support or security upgrades. (And eventually, you won't even get *paid* support.) I know of a couple of companies still running Python 1.5 apps. They work, they're not connected to the Internet, they don't care about bug fixes or security upgrades, so they have no reason to upgrade. But they're sure not writing *new* apps in Python 1.5. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ethan at stoneleaf.us Fri Sep 8 11:36:35 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 08 Sep 2017 08:36:35 -0700 Subject: Delay a computation in another thread In-Reply-To: <59b2adff$0$16748$b1db1813$d948b532@news.astraweb.com> References: <59aa8daa$0$1605$c3e8da3$5496439d@news.astraweb.com> <59aa8f1a$0$1601$c3e8da3$5496439d@news.astraweb.com> <3efa7837-1e8f-aa66-f438-db89c0457ced@mrabarnett.plus.com> <59b2adff$0$16748$b1db1813$d948b532@news.astraweb.com> Message-ID: <59B2B903.9010500@stoneleaf.us> On 09/08/2017 07:49 AM, Steve D'Aprano wrote: > On Sun, 3 Sep 2017 03:03 am, MRAB wrote: >> Timer is a subclass of Thread, so you can set its .daemon attribute. > > Sorry for the long delay in replying to this, but if I set its daemon attribute, > won't that mean it will live on after the interpreter shuts down? From the docs*: Note Daemon threads are abruptly stopped at shutdown. Their resources (such as open files, database transactions, etc.) may not be released properly. If you want your threads to stop gracefully, make them non-daemonic and use a suitable signalling mechanism such as an Event. -- ~Ethan~ * https://docs.python.org/3/library/threading.html From steve+python at pearwood.info Fri Sep 8 11:42:23 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 09 Sep 2017 01:42:23 +1000 Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <878thpjr8t.fsf@elektro.pacujo.net> Message-ID: <59b2ba60$0$16721$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Sep 2017 10:51 pm, Chris Angelico wrote: > On Fri, Sep 8, 2017 at 10:42 PM, Marko Rauhamaa wrote: >> Chris Angelico : >>> But as others have said, upgrading to 3.4+ is not as hard as many >>> people fear, and your code generally improves as a result >> >> That's somewhat irrelevant. Point is, Python 2 will quickly become a >> pariah in many corporations during or after 2018, and we are going to >> see emergency measures similar to the Y2K craze twenty years ago. >> >> The risk to Python will be whether the occasion is exploited by fanboys >> of competing programming languages. The migration from Python 2 might be >> to something else than Python 3 in some circles. > > And the sky is going to fall on Chicken Little's head, any day now. > > Let's see. You can port your code from Python 2.7 to Python 3.6 by > running a script and then checking the results for bytes/text > problems. > > You can port your code from Python 2.7 to Ruby by paying developers > big bucks for a good while. > > Advantage: Ruby, obviously, because it's easier to change languages > than to audit your code for places where you had lurking bugs that you > didn't know about. People do irrational things all the time. When faced with the likelihood of a relatively easy migration from Python 2 to 3, with a small[1] chance of it blowing out, versus re-implementing the entire app in a completely different language, we know that a certain percentage of people will swap languages even if it makes no economic sense. They will underestimate the cost of re-implementation, and overestimate the risk of a blow-out, because this is really just an excuse to do what they've wanted to do all along: use a different language. Or because somebody in management heard from somebody on LinkedIn that they heard on Facebook about something they read in some trade magazine about some company that lost billions porting their Python 2.9 app to Python 3.0 and besides everyone knows that Python 3 is a failure and Ruby on NodeJS is the new hot thing that everyone is using. To be perfectly rational, we *should* consider at least three alternatives: (1) Stick with Python 2 and pay for support; (2) Migrate to Python 3; (3) Re-implement in some other language; and make a dispassionate choice according to which one has the best cost/benefit ratio. And that choice won't always be #2. [1] Depends on the code base, and the developers. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From __peter__ at web.de Fri Sep 8 11:45:50 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 08 Sep 2017 17:45:50 +0200 Subject: Need to pass a class instance to a gettext fallback References: Message-ID: Josef Meile wrote: > language = kwargs['language'] > del kwargs['language'] Not really important, but there's a method for that: language = kwargs.pop("language") > def __init__(self, *args, **kwargs): > language = kwargs['language'] > del kwargs['language'] In Python 3 this can also be spelt with a keyword-only language argument: def __init__(self, *args, language, **kwargs): ... # no pop() or del From rosuav at gmail.com Fri Sep 8 11:48:36 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Sep 2017 01:48:36 +1000 Subject: Using Python 2 In-Reply-To: <59b2ba60$0$16721$b1db1813$d948b532@news.astraweb.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <878thpjr8t.fsf@elektro.pacujo.net> <59b2ba60$0$16721$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sat, Sep 9, 2017 at 1:42 AM, Steve D'Aprano wrote: > ... because this is > really just an excuse to do what they've wanted to do all along: use a > different language. > > Or because somebody in management heard from somebody on LinkedIn that they > heard on Facebook about something they read in some trade magazine about some > company that lost billions porting their Python 2.9 app to Python 3.0 and > besides everyone knows that Python 3 is a failure and Ruby on NodeJS is the new > hot thing that everyone is using. Yes, these are two all-too-common reasons. I have to confess that I dismissed both of them as irrational, but the truth is that they're both very real-world reasons. I stand corrected. ChrisA From steve+python at pearwood.info Fri Sep 8 11:51:30 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 09 Sep 2017 01:51:30 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> <59b18061$0$16726$b1db1813$d948b532@news.astraweb.com> <66a603dd-ff6e-47f3-a4ea-c4562b980efd@googlegroups.com> <59b1f96d$0$16737$b1db1813$d948b532@news.astraweb.com> <7f9a3602-d304-742d-3bfa-cb5e07028019@kynesim.co.uk> Message-ID: <59b2bc83$0$16760$b1db1813$d948b532@news.astraweb.com> On Fri, 8 Sep 2017 11:01 pm, Rhodri James wrote: > On 08/09/17 13:45, Stefan Ram wrote: >> Gregory Ewing writes: >> [a random integer will on average have ] >>> infinitely many >>> digits -- despite every actual integer only having finitely >>> many digits! >> This is not possible because every integer has >> a finite number of digits (in base 10). > > Surely an infinitely large integer has an infinite number of digits? There are no infinitely large integers. All integers are finite. We can say that there is no largest integer, that they go on forever -- but no individual integer is infinite. We soon run out of notation to write them. There are numbers so inconceivably huge that ordinary exponential notation isn't big enough, like Graham's Number, and we can invent numbers even bigger: let G = Graham's Number let H = G^^G^^G^^ ... ^^G # tower of a Graham's Number G's, where ^^ is the tetration (double arrow) operator: x^^y = x^x^x^...^x # tower of y x's but even those inconceivably huge numbers are finite. That's the thing about infinity. No matter how huge the number is, it is still falls infinitely short of infinite. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From stephanh42 at gmail.com.invalid Fri Sep 8 11:56:21 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 08 Sep 2017 15:56:21 GMT Subject: Run Windows commands from Python console References: <83ebc433-d457-408b-b43a-4b00a3206728@googlegroups.com> <290ec6d2-81d9-4bf4-b641-fc8568578555@googlegroups.com> <7515e893-b1c7-42ff-926d-e482e1eca9ae@googlegroups.com> Message-ID: Op 2017-09-06, Rick Johnson schreef : > One of the nice (current) features of Tkinter menus (that i > sometimes miss on my windows box!) is the ability to "tear- > off" a menu cascade and use it as a sort of "pseudo tool > bar". I was under the impression that Tk also supported tear-off menus under Windows (but not under macOS). However, many applications apparently explicitly suppress this functionality by doing Menu(..., tearoff=0) Stephan From steve+python at pearwood.info Fri Sep 8 12:19:08 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 09 Sep 2017 02:19:08 +1000 Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> Message-ID: <59b2c2fe$0$16758$b1db1813$d948b532@news.astraweb.com> On Sat, 9 Sep 2017 12:41 am, Chris Angelico wrote: >> I ran 2to3 on some code that worked under 2.6.6. and 3.6.2. 2to3 broke it >> for both versions and it was a fairly trivial script. > > Show the code that it broke? I've never seen this, unless it's > something like "now you need to install third-party package X in > Python 3". The 2to3 transformations are fine for everything in the > stdlib. Chris, I don't think it is controversial that 2to3 occasionally breaks code, or fails to translate every feature. Even today, there are still the occasional bug report or feature request for 2to3. Even human beings can't always translate 2 to 3 flawlessly, and there are some code bases that actually are tricky to migrate to 3. We shouldn't expect an automated tool to handle *all* code bases perfectly without human review. One thing which is notoriously tricky to migrate is mixed bytes/Latin1 text using Python 2 strings, say you're manipulating file formats that mix text with binary bytes. These mixed binary/text files are sometimes badly suited to the new Unicode/bytes model. (There was some discussion on Python-Ideas about easing the transition. One concrete change that came out of that was to add % formatting to bytes in 3.5, but the rest of the discussion seems to have fizzled out due to lack of interest.) While 2to3 is still an awesome tool, remember that the core developers have changed their recommendation from: # don't do this write your code in Python 2, and use 2to3 to translate to Python 3, keeping two code bases; instead now recommending: # do this instead write a single code base that works in both Python 2.7 and Python 3. >> If you want to encourage people to move from Python 2 to 3 then continue to >> help answer questions when they are Python 2 based. We do. Hell, if somebody wants to ask a question about Python 1.5, I've got a working copy and can probably answer it! But some of us can't resist the temptation to evangelise about Python 3 :-) > Also, be completely honest here: how much work would it take for you > to move your "millions of servers" from Python 2 to, say, PHP? or > Ruby? or C? or JavaScript? Is any of those (or any write-in answer you > wish) actually easier than porting to Python 3? Maybe not easier, but maybe there's some other payoff: - some poor, benighted folks just like Javascript or Ruby better than Python (perhaps they were dropped on the head as babies a few too many times *wink*) - maybe some companies have a glut of cheap PHP code-monkeys they can throw at a problem, and shortage of expensive Python rockstars who make unreasonable demands like "decent working conditions" and "life-work balance"; - perhaps it is worth the increased cost of re-writing your app to get better performance or reliability (or at least somebody thinks so...) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From tjreedy at udel.edu Fri Sep 8 12:23:11 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 8 Sep 2017 12:23:11 -0400 Subject: Using Python 2 In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> Message-ID: On 9/8/2017 6:12 AM, Leam Hall wrote: > I've read comments about Python 3 moving from the Zen of Python. Comments about Python 3 range from factual to opinionated to fake. > I'm a "plain and simple" person myself. Many of the changes in Python3 were simplifications -- removing a semi-deprecated 'old way' in favor of a new way that was already in Python 2 and widely used. A major example was dropping old-style classes. This had little impact because by 2.6, people were mostly using new-style classes or were mostly using old-style classes in a way compatible with new-style classes. > Complexity to support what CompSci folks want, I was part of the Python 3 design discussions. I don't remember ever hearing anything like "we should do it this more complex way because that is what CompSci folks want". > which was used to describe some of the Python 3 changes, I presume by people trying to persuade you to avoid Python 3. That does not make it true. This claim is nonsensical in that 3.0 introduced very little that was new. Unicode was added in 2.0, a decade before. -- Terry Jan Reedy From steve+python at pearwood.info Fri Sep 8 12:27:44 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 09 Sep 2017 02:27:44 +1000 Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> Message-ID: <59b2c502$0$16752$b1db1813$d948b532@news.astraweb.com> On Sat, 9 Sep 2017 12:23 am, Leam Hall wrote: > Various responses in no particular order: > > On 09/08/2017 09:57 AM, Ned Batchelder wrote: >> I've heard a lot of FUD about the Python 3 transition, but this one is >> new to me.? What is it that CompSci folks want that developers don't >> want, that ruined Python 3? > > > It's not FUD if it's true. Calling it FUD without checking is, um, FUD. > The phrase was "many of the changes in Python 3 are theoretically based, > cleaning up of how Python does things to make them fit with what > Computer Science teaches." Such as what? Got any examples of these changes driven by Comp-Sci theory? [...] > If Python 2 has bugs that aren't going to be fixed, Eventually, when Python 2.7 is end-of-lifed. > then let's ask the > question. If Python 3 was a total re-write that is not backwards > compatible then it likely has some of the same bugs (due to same coders) No, that doesn't follow. For starters, much of the code base is different, so bugs in one may not exist in the other. Also, Python 3 will continue to get bug fixes for many years to come, long after 2.7 is end-of-lifed. > plus new ones. If Python 3 is not a total re-write then why break > compatibility? To avoid building up excess cruft in the language. To fix design mistakes which cannot be fixed without a backwards-incompatible change. > To say Python 2 is old is true. What does it matter though? Unless > Python 3 provides a business value for spending lots of time and money > to change then "old" doesn't matter. Indeed you are correct. I know of companies still using Python 1.5. > If you want to encourage people to move from Python 2 to 3 then continue > to help answer questions when they are Python 2 based. As we do. Even if some of us can't help evangelising for Python 3 when they do so :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Fri Sep 8 12:40:33 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Sep 2017 02:40:33 +1000 Subject: Using Python 2 In-Reply-To: <59b2c2fe$0$16758$b1db1813$d948b532@news.astraweb.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> <59b2c2fe$0$16758$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sat, Sep 9, 2017 at 2:19 AM, Steve D'Aprano wrote: > On Sat, 9 Sep 2017 12:41 am, Chris Angelico wrote: > >>> I ran 2to3 on some code that worked under 2.6.6. and 3.6.2. 2to3 broke it >>> for both versions and it was a fairly trivial script. >> >> Show the code that it broke? I've never seen this, unless it's >> something like "now you need to install third-party package X in >> Python 3". The 2to3 transformations are fine for everything in the >> stdlib. > > Chris, I don't think it is controversial that 2to3 occasionally breaks code, or > fails to translate every feature. Even today, there are still the occasional > bug report or feature request for 2to3. For "a fairly trivial script", I would like to see how it breaks it. The only thing I've seen that frequently causes trouble is the bytes/text distinction (which, if we're honest, is really just exposing a problem that was already there), and that's only if you have a boundary that can't be trivially resolved eg by adding encoding="utf-8" to your file open calls. > One thing which is notoriously tricky to migrate is mixed bytes/Latin1 text > using Python 2 strings, say you're manipulating file formats that mix text with > binary bytes. These mixed binary/text files are sometimes badly suited to the > new Unicode/bytes model. Yes - but I don't expect to see a true mixture of binary and textual data in "a fairly trivial script". That sort of thing comes up when you develop parsers for certain network protocols or file formats, but I don't call those "trivial". I should have been more clear about my comment there - that it was specific to the complaint that 2to3 broke a trivial script. ChrisA From breamoreboy at gmail.com Fri Sep 8 12:45:23 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Fri, 8 Sep 2017 09:45:23 -0700 (PDT) Subject: Using Python 2 (was: Design: method in class or general function?) In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> Message-ID: <1159cf22-2175-4e50-bb03-b2d78fb3fc01@googlegroups.com> On Friday, September 8, 2017 at 11:12:50 AM UTC+1, Leam Hall wrote: > > I've read comments about Python 3 moving from the Zen of Python. I'm a > "plain and simple" person myself. Complexity to support what CompSci > folks want, which was used to describe some of the Python 3 changes, > doesn't help me get work done. > Here https://mail.python.org/pipermail/python-3000/ are the bulk of the discussions regarding the move to Python 3. Which specifics do you disagree with and why? Kindest regards. Mark Lawrence. From breamoreboy at gmail.com Fri Sep 8 12:53:59 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Fri, 8 Sep 2017 09:53:59 -0700 (PDT) Subject: Using Python 2 In-Reply-To: <59b2c2fe$0$16758$b1db1813$d948b532@news.astraweb.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> <59b2c2fe$0$16758$b1db1813$d948b532@news.astraweb.com> Message-ID: <72dd0a5b-351d-4437-9b86-e9c93c97105d@googlegroups.com> On Friday, September 8, 2017 at 5:19:36 PM UTC+1, Steve D'Aprano wrote: > On Sat, 9 Sep 2017 12:41 am, Chris Angelico wrote: > > >> I ran 2to3 on some code that worked under 2.6.6. and 3.6.2. 2to3 broke it > >> for both versions and it was a fairly trivial script. > > > > Show the code that it broke? I've never seen this, unless it's > > something like "now you need to install third-party package X in > > Python 3". The 2to3 transformations are fine for everything in the > > stdlib. > > Chris, I don't think it is controversial that 2to3 occasionally breaks code, or > fails to translate every feature. Even today, there are still the occasional > bug report or feature request for 2to3. > > Even human beings can't always translate 2 to 3 flawlessly, and there are some > code bases that actually are tricky to migrate to 3. We shouldn't expect an > automated tool to handle *all* code bases perfectly without human review. > I asked earlier this year why there were still so many 2to3 bug reports outstanding. Regrettably the vast majority are edge cases for which there is no simple solution that will keep everybody happy, so I doubt that they will ever get fixed. I do not believe that to be too important as some of the reports are over six years old, so I suspect that workarounds have been found with the aid of the MkI eyeball :-) Kindest regards. Mark Lawrence. From grant.b.edwards at gmail.com Fri Sep 8 12:56:45 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 8 Sep 2017 16:56:45 +0000 (UTC) Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> <59b2c2fe$0$16758$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-09-08, Steve D'Aprano wrote: > One thing which is notoriously tricky to migrate is mixed > bytes/Latin1 text using Python 2 strings, say you're manipulating > file formats that mix text with binary bytes. These mixed > binary/text files are sometimes badly suited to the new > Unicode/bytes model. Definitely. I maintain a lot of apps that do low-level serial and network protocol stuff, and porting them to 3 is sometimes painful. The equivalence of text and bytes in 2.7 meant that there was often an easy, obvious way to do things that can't be readily translated into Python 3. Even writing 2/3 compatible code from scratch isn't easy, since the 'bytes' type in 2 is way different than the 'bytes' type in 3. If only Python 2 had 'from future import bytes'... In hindsite, I probably should have sat down years ago and written a 'bytes' class for Python2 that would be compatible with Python3. -- Grant Edwards grant.b.edwards Yow! Uh-oh!! I forgot at to submit to COMPULSORY gmail.com URINALYSIS! From Stephen.Michell at maurya.on.ca Fri Sep 8 13:34:24 2017 From: Stephen.Michell at maurya.on.ca (Stephen Michell) Date: Fri, 8 Sep 2017 13:34:24 -0400 Subject: Python programming language vulnerabilities Message-ID: <9573BEFB-B5EB-4814-8C8D-AF18C7DB8BD3@maurya.on.ca> I chair ISO/IEC/JTC1/SC22/WG23 Programming Language Vulnerabilities. We publish an international technical report, ISO IEC TR 24772 Guide to avoiding programming language vulnerabilities through language selection use. Annex D in this document addresses vulnerabilities in Python. This document is freely available from ISO and IEC. We are updating this technical report, adding a few vulnerabilities and updating language applicability as programming languages evolve. We are also subdividing the document by making the language-specific annexes each their own technical report. For the Python Part, the major portions are written, but we have about 6 potential vulnerabilities left to complete. We need help in finishing the Python TR. We are looking for a few Python experts that have experience in implementing Python language systems, or experts in implementing significant systems in Python (for technical level, persons that provide technical supervision to implementers, or that write and maintain organizational Python coding standards. If you are interested in helping, please reply to this posting. Thank you Stephen Michell Convenor, ISO/IEC/JTC 1/SC 22/WG 23 Programming Language Vulnerabilities From logonveera at gmail.com Fri Sep 8 14:39:10 2017 From: logonveera at gmail.com (logonveera at gmail.com) Date: Fri, 8 Sep 2017 11:39:10 -0700 (PDT) Subject: Best way to insert sorted in a list In-Reply-To: References: Message-ID: On Saturday, June 18, 2011 at 2:23:10 AM UTC+5:30, SherjilOzair wrote: > There are basically two ways to go about this. > One is, to append the new value, and then sort the list. > Another is to traverse the list, and insert the new value at the > appropriate position. > > The second one's complexity is O(N), while the first one's is O(N * > log N). > > Still, the second one works much better, because C code is being used > instead of pythons. > > Still, being a programmer, using the first way (a.insert(x); > a.sort()), does not feel right. > > What has the community to say about this ? What is the best (fastest) > way to insert sorted in a list ? a = [] num = int(input('How many numbers: ')) for n in range(num): numbers = int(input('Enter values:')) a.append(numbers) b = sorted(a) print(b) c = int(input("enter value:")) for i in range(len(b)): if b[i] > c: index = i break d = b[:i] + [c] + b[i:] print(d) From steve+python at pearwood.info Fri Sep 8 15:00:25 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 09 Sep 2017 05:00:25 +1000 Subject: Best way to insert sorted in a list References: Message-ID: <59b2e8cb$0$16722$b1db1813$d948b532@news.astraweb.com> On Sat, 9 Sep 2017 04:39 am, logonveera at gmail.com wrote: > On Saturday, June 18, 2011 at 2:23:10 AM UTC+5:30, SherjilOzair wrote: .......................^^^^^^ You're replying to something six years old. Its doubtful the original poster is still reading. >> What has the community to say about this ? What is the best (fastest) >> way to insert sorted in a list ? > > a = [] > num = int(input('How many numbers: ')) > for n in range(num): > numbers = int(input('Enter values:')) > a.append(numbers) > > b = sorted(a) > print(b) > c = int(input("enter value:")) > for i in range(len(b)): > if b[i] > c: > index = i > break > d = b[:i] + [c] + b[i:] > print(d) Doing a linear search, followed by slicing and list concatenation, is not likely to be the fastest method. If you think it is fast, that's because you have only tested it on small lists. Try a list with (say) a million items. Probably the best way is to use the bisect module to insert into a sorted list. Or append to the end, then sort in place. Python's sort is *very* efficient with almost sorted data. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From stephanh42 at gmail.com.invalid Fri Sep 8 15:08:56 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 08 Sep 2017 19:08:56 GMT Subject: Best way to insert sorted in a list References: Message-ID: Op 2017-09-08, logonveera at gmail.com schreef : > On Saturday, June 18, 2011 at 2:23:10 AM UTC+5:30, SherjilOzair wrote: >> There are basically two ways to go about this. >> One is, to append the new value, and then sort the list. >> Another is to traverse the list, and insert the new value at the >> appropriate position. >> >> The second one's complexity is O(N), while the first one's is O(N * >> log N). >> >> Still, the second one works much better, because C code is being used >> instead of pythons. Python uses the Timsort ( https://en.wikipedia.org/wiki/Timsort ) algorithm. Timsort is O(N) in the special case of a list of N elements where the first N-1 are already sorted and the last one is arbitrary. So appending the value and then calling sort() is in fact O(N) in Python (hence asymptotically optimal), and also practically fast since the sort() is implemented in C. Stephan From stephanh42 at gmail.com.invalid Fri Sep 8 15:17:35 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 08 Sep 2017 19:17:35 GMT Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> Message-ID: Op 2017-09-08, Stefan Ram schreef : > OTOH, there are those killjoys who complain about > "too many parentheses" in programs written in the > "simple language". Which is clearly nonsense since it is easy to show that any working program in said simple language contains *precisely enough* parentheses. ;-) (Fortunate that I commented out the unbalanced closing parenthesis.) Stephan From accessnewbie at gmail.com Fri Sep 8 16:21:20 2017 From: accessnewbie at gmail.com (accessnewbie at gmail.com) Date: Fri, 8 Sep 2017 13:21:20 -0700 (PDT) Subject: Merge pdf files using information from two files Message-ID: <3092fd53-5d3d-4fb6-be02-d1bf75924307@googlegroups.com> I have two files (right now they are spreadsheets but I can export them to any format). File1 has StoreID (unique) in one column and a pdf map location in the second column. (Names not really sequenced numerically) 1 C:/maps/map1.pdf 2 C:/maps/map2.pdf 3 C:/maps/map3.pdf 4 C:/maps/map4.pdf File2 has 3 columns. Column1 is the County name (unique), Column2 are the store IDs that fall in that county separated by commas, and Column3 is warehouse that services the store. County1 1,2 Warehouse1 County2 1,3 Warehouse1 County3 3 Warehouse4 County4 2,4 Warehouse3 Is it possible to compare both files and append the maps that belong in each county and naming it by the county_warehouse.pdf? Output would be something like this: C:\maps\final\County1_Warehouse1.pdf (pdf file is map1.pdf and map2.pdf) C:\maps\final\County2_Warehouse1.pdf (pdf file is map1.pdf and map3.pdf) C:\maps\final\County3_Warehouse4.pdf (pdf file is map3.pdf) C:\maps\final\County4_Warehouse1.pdf (pdf file is map2.pdf and map4.pdf) I could spend some time reorganizing the second file to look like this if it makes it easier: County1 1 Warehouse1 County1 2 Warehouse1 County2 1 Warehouse1 County2 3 Warehouse1 County3 3 Warehouse4 County4 2 Warehouse3 County4 4 Warehouse3 Ideas as to how to accomplish this? From ian.g.kelly at gmail.com Fri Sep 8 16:46:16 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Sep 2017 14:46:16 -0600 Subject: detaching comprehensions In-Reply-To: References: Message-ID: On Fri, Sep 8, 2017 at 2:24 PM, Stefan Ram wrote: > Maybe you all know this, but to me this is something new. > I learnt it by trial and error in the Python 3.6.0 console. > > Most will know list comprehensions: > > |>>> [ i for i in range( 3, 5 )] > |[3, 4] > > I found out that the comprehension can be detached from the list: > > |>>> k =( i for i in range( 3, 5 )) > > but one must use an extra pair of parentheses around it in the > assignment. You don't need an *extra* pair of parentheses per se. The generator expression simply must be enclosed in parentheses. This is perfectly valid: py> sum(i for i in range(3, 5)) > Now I can insert the "generator" ?k? into a function call, > but a spread operator should cannot be used there. If you mean the * syntax, certainly it can. > |>>> sum( k ) > |7 But you don't want it in this case, because that would do the wrong thing. > ?sum? expects exactly two arguments, and this is what ?k? > provides. Not exactly. sum(k) is only providing the first argument to sum. The first argument is required to be an iterable, which is what k is. The second argument, "start", takes its default value of 0. This is effectively equivalent to calling sum([3, 4]). sum(*k) on the other hand would spread the values of k over the arguments of sum and would be equivalent to calling sum(3, 4), which raises a TypeError because 3 is not iterable. > But to insert it again into the place where it was "taken > from", a spread operator is required! > > |>>> k =( i for i in range( 3, 5 )) > |>>> [ *k ] > |[3, 4] Alternatively: py> list(k) [3, 4] As a final aside, storing a generator in a temporary variable is usually bad style because it sets up an expectation that the contents of the variable could be used more than once, when in fact a generator can only be iterated over once. From __peter__ at web.de Fri Sep 8 17:03:47 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 08 Sep 2017 23:03:47 +0200 Subject: detaching comprehensions References: Message-ID: Stefan Ram wrote: > Maybe you all know this, but to me this is something new. > I learnt it by trial and error in the Python 3.6.0 console. > > Most will know list comprehensions: > > |>>> [ i for i in range( 3, 5 )] > |[3, 4] > > I found out that the comprehension can be detached from the list: > > |>>> k =( i for i in range( 3, 5 )) > > but one must use an extra pair of parentheses around it in the > assignment. That is called "generator expression". When it does not modify the values one usually creates the iterator with k = iter(range(3, 5)). > Now I can insert the "generator" ?k? into a function call, > but a spread operator should cannot be used there. > > |>>> sum( k ) > |7 > > ?sum? expects exactly two arguments, and this is what ?k? > provides. No. sum() requires one iterable and accepts an optional start value. You are passing the iterable only, as may be verified with >>> k = (x for x in [["a"], ["b"]]) >>> sum(k) Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'list' versus >>> k = (x for x in [["a"], ["b"]]) >>> sum(k, []) ['a', 'b'] As with iterators in general once they are exhausted they stay exhausted: >>> k = (i for i in range(3, 5)) >>> sum(k) 7 >>> sum(k) 0 (you can but shouldn't make your own that doesn't follow that convention) > But to insert it again into the place where it was "taken > from", a spread operator is required! > > |>>> k =( i for i in range( 3, 5 )) > |>>> [ *k ] > |[3, 4] I have not seen that, I think. The common way is probably >>> list("foo") ['f', 'o', 'o'] rather than >>> [*"foo"] ['f', 'o', 'o'] and >>> tuple("bar") ('b', 'a', 'r') rather than >>> *"bar", ('b', 'a', 'r') As demonstrated this works with arbitrary iterables, not just generator expressions. From bgailer at gmail.com Fri Sep 8 17:06:25 2017 From: bgailer at gmail.com (bob gailer) Date: Fri, 8 Sep 2017 17:06:25 -0400 Subject: detaching comprehensions In-Reply-To: References: Message-ID: <87174d9e-530a-44f3-15eb-8378a5ccb4db@gmail.com> I don't know whether you wanted a reply, since you did not ask for one. I am not even sure what your point is. See other comments below. On 9/8/2017 4:24 PM, Stefan Ram wrote: > Maybe you all know this, but to me this is something new. > I learnt it by trial and error in the Python 3.6.0 console. > > Most will know list comprehensions: > > |>>> [ i for i in range( 3, 5 )] > |[3, 4] > > I found out that the comprehension can be detached from the list: > > |>>> k =( i for i in range( 3, 5 )) > > but one must use an extra pair of parentheses around it in the > assignment. > > Now I can insert the "generator" ?k? into a function call, > but a spread operator should cannot be used there. > > |>>> sum( k ) > |7 > > ?sum? expects exactly two arguments, and this is what ?k? > provides. Where did you get that idea. If you look at the docs you will see: "sum(iterable[, start]) Sums start and the items of an iterable from left to right and returns the total. start defaults to 0." sum expects 1 or 2 arguments; when you write sum(k) you are providing 1 argument. > > But to insert it again into the place where it was "taken > from", a spread operator is required! > > |>>> k =( i for i in range( 3, 5 )) > |>>> [ *k ] > |[3, 4] "taken from"?? k is a generator object. Clear? Bob Gailer From ian.g.kelly at gmail.com Fri Sep 8 17:15:59 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Sep 2017 15:15:59 -0600 Subject: detaching comprehensions In-Reply-To: References: Message-ID: On Fri, Sep 8, 2017 at 3:03 PM, Peter Otten <__peter__ at web.de> wrote: >>>> *"bar", > ('b', 'a', 'r') Now that just makes my eyes hurt. From leamhall at gmail.com Fri Sep 8 17:18:45 2017 From: leamhall at gmail.com (Leam Hall) Date: Fri, 8 Sep 2017 17:18:45 -0400 Subject: Not appending ("lib") to sys.path breaks tests. Message-ID: <86d3e500-56e2-3fab-5bdb-879d5ceb8734@gmail.com> A kind soul pointed out that my code uses a sys.path.append("lib") to get files to be imported: sys.path.append("lib") from character_tools import * He noted that having an __init__.py in lib and using: from .character_tools import * Should be sufficient for "please don't comment yet about 'import *'" levels of sufficient. :P The code works under python 2.6.6 and 3.6.2. However, py.test (python 2) and pytest (python 3) fails. Besides my usual clue, what am I missing? ### py.test (python 2) ========================================= test session starts ========================================= platform linux2 -- Python 2.6.6 -- pytest-2.3.5 collected 0 items / 3 errors =============================================== ERRORS ================================================ ______________________________ ERROR collecting tests/test_base_tools.py ______________________________ tests/test_base_tools.py:6: in > import lib.base_tools E ImportError: No module named lib.base_tools ______________________________ ERROR collecting tests/test_character.py _______________________________ /usr/lib/python2.6/site-packages/_pytest/python.py:352: in _importtestmodule > mod = self.fspath.pyimport(ensuresyspath=True) /usr/lib/python2.6/site-packages/py/_path/local.py:621: in pyimport > __import__(modname) E File "/home/leam/lang/git/makhidkarun/py_tools/tests/test_character.py", line 6 E import .lib.character E ^ E SyntaxError: invalid syntax ___________________________ ERROR collecting tests/test_character_tools.py ____________________________ tests/test_character_tools.py:6: in > from ..lib.character_tools import * E ValueError: Attempted relative import in non-package ======================================= 3 error in 0.05 seconds ======================================= ### pytest (python 3) ========================================= test session starts ========================================= platform linux -- Python 3.6.2, pytest-3.2.2, py-1.4.34, pluggy-0.4.0 rootdir: /home/leam/lang/git/makhidkarun/py_tools, inifile: collected 0 items / 3 errors =============================================== ERRORS ================================================ ______________________________ ERROR collecting tests/test_base_tools.py ______________________________ ImportError while importing test module '/home/leam/lang/git/makhidkarun/py_tools/tests/test_base_tools.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: tests/test_base_tools.py:6: in import lib.base_tools E ModuleNotFoundError: No module named 'lib' ______________________________ ERROR collecting tests/test_character.py _______________________________ /usr/local/lib/python3.6/site-packages/_pytest/python.py:395: in _importtestmodule mod = self.fspath.pyimport(ensuresyspath=importmode) /usr/local/lib/python3.6/site-packages/py/_path/local.py:662: in pyimport __import__(modname) E File "/home/leam/lang/git/makhidkarun/py_tools/tests/test_character.py", line 6 E import .lib.character E ^ E SyntaxError: invalid syntax ___________________________ ERROR collecting tests/test_character_tools.py ____________________________ tests/test_character_tools.py:6: in from ..lib.character_tools import * E ValueError: attempted relative import beyond top-level package !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ======================================= 3 error in 0.22 seconds ======================================= From eryksun at gmail.com Fri Sep 8 17:33:19 2017 From: eryksun at gmail.com (eryk sun) Date: Fri, 8 Sep 2017 16:33:19 -0500 Subject: Delay a computation in another thread In-Reply-To: <0fb7e4b7-3cf3-f8c8-7344-990721e9078e@tjol.eu> References: <59aa8daa$0$1605$c3e8da3$5496439d@news.astraweb.com> <59aa8f1a$0$1601$c3e8da3$5496439d@news.astraweb.com> <3efa7837-1e8f-aa66-f438-db89c0457ced@mrabarnett.plus.com> <59b2adff$0$16748$b1db1813$d948b532@news.astraweb.com> <0fb7e4b7-3cf3-f8c8-7344-990721e9078e@tjol.eu> Message-ID: On Fri, Sep 8, 2017 at 10:03 AM, Thomas Jollans wrote: > On 2017-09-08 16:49, Steve D'Aprano wrote: > >> Sorry for the long delay in replying to this, but if I set its daemon attribute, >> won't that mean it will live on after the interpreter shuts down? >> >> Also, what happens if it tries to print after the interpreter shuts down? Where >> does output go? > > On Linux, I think it would go to the same virtual terminal as it did > before, if that still exists. (Otherwise, to /dev/null). This is how > processes that started out attached to a terminal and then went into the > background normally behave. In the normal case, when the interpreter shuts down, the process exits along with all threads. On the other hand, when Python is embedded, daemon threads may persist if the interpreter is finalized without exiting the process. Such threads shouldn't be able to do anything because they'll block trying to acquire the GIL. > No idea what happens on Windows, but if I had to guess, I'd say "not that". The Windows console system (i.e. condrv.sys driver, conhost.exe host, and csrss.exe session server) doesn't have full support for Unix-style process groups. They're supported for targeting Ctrl+C and Ctrl+Break. Also, Ctrl+C is disabled for new process groups. But there's no notion of foreground and background process groups. Thus it can't implement the Unix feature that suspends a background process that tries to read from console input. (Usually background processes in Unix are allowed to write to the terminal, but that can be disallowed as well.) In the CMD shell, the closest you can do for running a process in the background is via "start /b [...] References: <1504526518l.11403280l.0l@psu.edu> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> <59b18061$0$16726$b1db1813$d948b532@news.astraweb.com> <66a603dd-ff6e-47f3-a4ea-c4562b980efd@googlegroups.com> <59b1f96d$0$16737$b1db1813$d948b532@news.astraweb.com> Message-ID: On 9/8/17, Gregory Ewing wrote: > Steve D'Aprano wrote: >> A harder question is, what if you take a random number from the Integers? >> How >> many digits will it have in (say) base 10? I don't have a good answer to >> that. >> I think it may be ill-defined. > > I think the answer is that on average it has infinitely many > digits -- despite every actual integer only having finitely > many digits! > > We can prove this by contradiction. Suppose the answer were > some finite number N. There are only finitely many integers > with N or fewer digits, but there are infinitely many with > more than N digits, so including them in the average must > make it bigger than N. So N cannot be finite. Sorry that my english is so poor that I could only draft ideas. :/ I think that it probably depends on distribution. Think something like: def numbers(e=0.999): ''' random numbers from integers ''' while 1: r = random.random() yield int(1/(1-r)**e) and see: https://www.wolframalpha.com/input/?i=area+between+y+%3D+1%2Fx%5E0.999+and+y+%3D+0+between+x+%3D+0+and+1 and unbounded (for e==1) -> https://www.wolframalpha.com/input/?i=area+between+y+%3D+1%2Fx+and+y+%3D+0+between+x+%3D+0+and+1 # if somebody likes to test hipothesis -> def avg(N=10000000): return sum(itertools.islice(numbers(), 0,N,1))/N From ian.g.kelly at gmail.com Fri Sep 8 17:41:26 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Sep 2017 15:41:26 -0600 Subject: Not appending ("lib") to sys.path breaks tests. In-Reply-To: <86d3e500-56e2-3fab-5bdb-879d5ceb8734@gmail.com> References: <86d3e500-56e2-3fab-5bdb-879d5ceb8734@gmail.com> Message-ID: On Fri, Sep 8, 2017 at 3:18 PM, Leam Hall wrote: > A kind soul pointed out that my code uses a sys.path.append("lib") to get > files to be imported: > > sys.path.append("lib") > from character_tools import * > > He noted that having an __init__.py in lib and using: > > from .character_tools import * > > Should be sufficient for "please don't comment yet about 'import *'" levels > of sufficient. :P I'm confused about where the character_tools import is made. If that's within a module in the lib package, it should be fine. > The code works under python 2.6.6 and 3.6.2. However, py.test (python 2) and > pytest (python 3) fails. Besides my usual clue, what am I missing? > > > > ### py.test (python 2) > ========================================= test session starts > ========================================= > platform linux2 -- Python 2.6.6 -- pytest-2.3.5 > collected 0 items / 3 errors > > =============================================== ERRORS > ================================================ > ______________________________ ERROR collecting tests/test_base_tools.py > ______________________________ > tests/test_base_tools.py:6: in >> import lib.base_tools > E ImportError: No module named lib.base_tools It looks like it's failing to find the lib package. Since you removed the "lib" directory from sys.path, does its parent directory exist in sys.path? > ______________________________ ERROR collecting tests/test_character.py > _______________________________ > /usr/lib/python2.6/site-packages/_pytest/python.py:352: in _importtestmodule >> mod = self.fspath.pyimport(ensuresyspath=True) > /usr/lib/python2.6/site-packages/py/_path/local.py:621: in pyimport >> __import__(modname) > E File > "/home/leam/lang/git/makhidkarun/py_tools/tests/test_character.py", line 6 > E import .lib.character > E ^ > E SyntaxError: invalid syntax Relative imports are only allowed with the "from .foo import bar" syntax. However if you fix that, I suspect you're then going to run into the next error below here. I think you actually just want an absolute import like "import lib.character" here. > ___________________________ ERROR collecting tests/test_character_tools.py > ____________________________ > tests/test_character_tools.py:6: in >> from ..lib.character_tools import * > E ValueError: Attempted relative import in non-package Packages and directories are not the same thing. This is saying that the tests directory is not a package, so you can't do a relative import within it. You probably just want "from lib.character_tools import *". The Python 3 errors are the same as the above. From leamhall at gmail.com Fri Sep 8 17:54:56 2017 From: leamhall at gmail.com (Leam Hall) Date: Fri, 8 Sep 2017 17:54:56 -0400 Subject: Not appending ("lib") to sys.path breaks tests. In-Reply-To: References: <86d3e500-56e2-3fab-5bdb-879d5ceb8734@gmail.com> Message-ID: <38617b43-45a3-df73-6b35-02f3d2e68b27@gmail.com> On 09/08/2017 05:41 PM, Ian Kelly wrote: > I'm confused about where the character_tools import is made. If that's > within a module in the lib package, it should be fine. > It looks like it's failing to find the lib package. Since you removed > the "lib" directory from sys.path, does its parent directory exist in > sys.path? The path is not in the modules path or in sys.path. Hence the append. I thought I could add the local "lib" path via "." or "lib.", but it seems not. import lib.character fails in the tests/ directory. > > Relative imports are only allowed with the "from .foo import bar" syntax. > > However if you fix that, I suspect you're then going to run into the > next error below here. I think you actually just want an absolute > import like "import lib.character" here. > > > Packages and directories are not the same thing. This is saying that > the tests directory is not a package, so you can't do a relative > import within it. You probably just want "from lib.character_tools > import *". > > The Python 3 errors are the same as the above. > From accessnewbie at gmail.com Fri Sep 8 18:28:56 2017 From: accessnewbie at gmail.com (accessnewbie at gmail.com) Date: Fri, 8 Sep 2017 15:28:56 -0700 (PDT) Subject: Merging pdf files based on a value in a field Message-ID: <42e1a363-c2f1-41a8-8ec5-96dcdc47e0b1@googlegroups.com> The StoreID (unique) is in Column1, a pdf map location in Column2, and the file name is "Warehouse1" (this will vary). (names not really sequenced numerically) County1 C:/maps/map1.pdf County1 C:/maps/map2.pdf County2 C:/maps/map1.pdf County2 C:/maps/map3.pdf County3 C:/maps/map3.pdf County4 C:/maps/map2.pdf County4 C:/maps/map4.pdf Is it possible to append the pdf maps with the same county and naming the new pdf file grouped by the value in the county field and the file name? Output would be something like this: C:\maps\final\County1_Warehouse1.pdf (pdf file is map1.pdf and map2.pdf) C:\maps\final\County2_Warehouse1.pdf (pdf file is map1.pdf and map3.pdf) C:\maps\final\County3_Warehouse1.pdf (pdf file is map3.pdf) C:\maps\final\County4_Warehouse1.pdf (pdf file is map2.pdf and map4.pdf) Right now the data is in a database but I can export this info into any format needed. Ideas as to how to do this? From christopher_reimer at icloud.com Fri Sep 8 18:35:22 2017 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Fri, 08 Sep 2017 15:35:22 -0700 Subject: Using Python 2 In-Reply-To: <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> Message-ID: <5AE4ED08-52E2-4DA8-B851-EE53828660D3@icloud.com> > On Sep 8, 2017, at 6:57 AM, Ned Batchelder wrote: > > What is it that CompSci folks want that developers don't > want, that ruined Python 3? Long-winded debates about obscure language features that left the layman programmers in the bit bucket about 50+ comments ago. While some of this can be informative and enlightening, it can also be a bit tedious to read. Just saying... Chris R. From leamhall at gmail.com Fri Sep 8 18:48:53 2017 From: leamhall at gmail.com (leam hall) Date: Fri, 8 Sep 2017 18:48:53 -0400 Subject: Using Python 2 In-Reply-To: <5AE4ED08-52E2-4DA8-B851-EE53828660D3@icloud.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <5AE4ED08-52E2-4DA8-B851-EE53828660D3@icloud.com> Message-ID: On Fri, Sep 8, 2017 at 6:35 PM, Christopher Reimer < christopher_reimer at icloud.com> wrote: > > On Sep 8, 2017, at 6:57 AM, Ned Batchelder > wrote: > > > > What is it that CompSci folks want that developers don't > > want, that ruined Python 3? > > Long-winded debates about obscure language features that left the layman > programmers in the bit bucket about 50+ comments ago. > > While some of this can be informative and enlightening, it can also be a > bit tedious to read. Just saying... > Chris; Ned and I have had a great chat off-line. Hopefully the layman programmers are coming out of the bucket soon. :) Leam From christopher_reimer at icloud.com Fri Sep 8 19:17:04 2017 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Fri, 08 Sep 2017 16:17:04 -0700 Subject: Merge pdf files using information from two files In-Reply-To: <3092fd53-5d3d-4fb6-be02-d1bf75924307@googlegroups.com> References: <3092fd53-5d3d-4fb6-be02-d1bf75924307@googlegroups.com> Message-ID: > On Sep 8, 2017, at 1:21 PM, accessnewbie at gmail.com wrote: > Ideas as to how to accomplish this? Export your spreadsheets as Comma Separated Values (CSV) files and use the CSV module to read/write those files. https://docs.python.org/3/library/csv.html Chris R. From greg.ewing at canterbury.ac.nz Fri Sep 8 20:07:28 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 09 Sep 2017 12:07:28 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59b28775$0$16753$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59b16632$0$16758$b1db1813$d948b532@news.astraweb.com> <59b18061$0$16726$b1db1813$d948b532@news.astraweb.com> <66a603dd-ff6e-47f3-a4ea-c4562b980efd@googlegroups.com> <59b1f96d$0$16737$b1db1813$d948b532@news.astraweb.com> <59b28775$0$16753$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > I don't think that talking about the average integer is meaningful. We're not averaging the integers, we're averaging their numbers of digits, which are natural numbers. To do this rigorously you could write down an expression for the average length of integers up to some finite N, and then take the limit as N -> infinity. I haven't worked through that, but I'd expect the sum to diverge. -- Greg From greg.ewing at canterbury.ac.nz Fri Sep 8 20:34:54 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 09 Sep 2017 12:34:54 +1200 Subject: A question on modification of a list via a function invocation In-Reply-To: <59b2b408$0$16753$b1db1813$d948b532@news.astraweb.com> References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b1fbd6$0$16728$b1db1813$d948b532@news.astraweb.com> <588a0643-28ea-4938-bf79-77ae66c0eaab@googlegroups.com> <59b2b408$0$16753$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > The paradox of the axe is one illustration of the difficulty in defining "the > same" in full generality. The axe situation doesn't arise in Python, because "same object" in Python is a concept that only applies to objects existing at the same time. There's no way to even ask a question like "does a refer to the same object that b did a second ago", because the only way to test object identity is to use the 'is' operator, which takes two expressions evaluated at the same time. -- Greg From mrjean1 at gmail.com Fri Sep 8 20:56:27 2017 From: mrjean1 at gmail.com (MrJean1) Date: Fri, 8 Sep 2017 17:56:27 -0700 (PDT) Subject: Merging pdf files based on a value in a field In-Reply-To: <42e1a363-c2f1-41a8-8ec5-96dcdc47e0b1@googlegroups.com> References: <42e1a363-c2f1-41a8-8ec5-96dcdc47e0b1@googlegroups.com> Message-ID: Try PyPDF2, see the merge example. /Jean From ben+python at benfinney.id.au Fri Sep 8 21:01:32 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 09 Sep 2017 11:01:32 +1000 Subject: class inheritance when not defined References: <73824550-e5e2-4292-85dc-795ed75f12f0@googlegroups.com> <85r2vh8sum.fsf@benfinney.id.au> <59b2b5b1$0$16721$b1db1813$d948b532@news.astraweb.com> Message-ID: <85ings8z2r.fsf@benfinney.id.au> Steve D'Aprano writes: > Good way: > > Foreigner speaking English as their second language: > "Who is the father of this class?" > > Native English speaker: > "The father is 'object', but in English we would normally ask > 'what is the parent?' instead." Of the three scenarios you presented, this is clearly the closest. I gave the correct answer, I offered a correction to English usage, and I gave no insult to the questioner. -- \ ?Nothing exists except atoms and empty space; everything else | `\ is opinion.? ?Democritus | _o__) | Ben Finney From greg.ewing at canterbury.ac.nz Fri Sep 8 21:19:51 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 09 Sep 2017 13:19:51 +1200 Subject: Why do we nned both - __init__() and __new__() In-Reply-To: References: <437bea63-c8a3-49fb-a6b1-31961ba5e8c7@googlegroups.com> <87d1718y8c.fsf@handshake.de> Message-ID: dieter wrote: > In the general case, constructing an object can be split into two > subtasks: obtain a raw piece of storage able to manage the object's state; > initialize the object's state. The first subtask is handled by "__new__", > the second by "__init__". Except that's not quite correct, because the cases where you need to override __new__ are ones where it does *more* than just allocate storage. -- Greg From steve+python at pearwood.info Fri Sep 8 22:17:26 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 09 Sep 2017 12:17:26 +1000 Subject: A question on modification of a list via a function invocation References: <1504526518l.11403280l.0l@psu.edu> <59ad6c2a$0$1585$c3e8da3$5496439d@news.astraweb.com> <4799a35b-e1aa-4ef8-bd43-19e0d54928b0@googlegroups.com> <59ad749c$0$1609$c3e8da3$5496439d@news.astraweb.com> <59afde14$0$16729$b1db1813$d948b532@news.astraweb.com> <3d2cf077-8b4a-48dc-af03-3b679d301550@googlegroups.com> <7719693e-2f2b-42bb-b711-ba9a00a9b2d6@googlegroups.com> <59b1fbd6$0$16728$b1db1813$d948b532@news.astraweb.com> <588a0643-28ea-4938-bf79-77ae66c0eaab@googlegroups.com> <59b2b408$0$16753$b1db1813$d948b532@news.astraweb.com> Message-ID: <59b34f37$0$16751$b1db1813$d948b532@news.astraweb.com> On Sat, 9 Sep 2017 10:34 am, Gregory Ewing wrote: > Steve D'Aprano wrote: >> The paradox of the axe is one illustration of the difficulty in defining "the >> same" in full generality. > > The axe situation doesn't arise in Python, because "same > object" in Python is a concept that only applies to objects > existing at the same time. Indeed. That's why in an earlier post I mentioned that it wasn't relevant to the question of `is`. I only mentioned it again because Rustom claimed to not understand why I mentioned it. I mentioned it because I was *agreeing with him* about the notion of sameness being hard to define vigorously in FULL GENERALITY. Which is irrelevant to the question of "same object". Either the paradoxes of "sameness" don't apply to Python objects, in which the paradoxes don't matter, or they apply to everything, in which case we're stuck with them and shouldn't let them prevent us using the common sense meaning of "same object" when discussing Python `is`. > There's no way to even ask a question like "does a refer > to the same object that b did a second ago", because > the only way to test object identity is to use the > 'is' operator, which takes two expressions evaluated > at the same time. I wouldn't quite go that far. We could, for example, record the ID, type, and some representation of the object (repr? str?), and compare them to those of the existing object. If any of them differ, then we know they aren't (weren't?) the same object. If all three are the same, we cannot draw any conclusions. "Is this list I have now identical to the tuple I had five minutes ago?" "Obviously not, because lists aren't tuples." But apart from tricks like that, I agree: objects that existed in the past but no longer exist don't have a meaningful identity in Python. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From viradha at hotmail.com Fri Sep 8 22:35:20 2017 From: viradha at hotmail.com (V Vishwanathan) Date: Sat, 9 Sep 2017 02:35:20 +0000 Subject: Questions. Message-ID: Hi, From what I see in the recent 4/5 digests, this forum seems to be for advanced and professional programmers. So wondering if a newbie can post some questions to understand errors in his code or will it look silly? Thanks, Venkat From torriem at gmail.com Fri Sep 8 22:54:58 2017 From: torriem at gmail.com (Michael Torrie) Date: Fri, 8 Sep 2017 20:54:58 -0600 Subject: Questions. In-Reply-To: References: Message-ID: <47eaa902-5244-0b29-c029-e90708577691@gmail.com> On 09/08/2017 08:35 PM, V Vishwanathan wrote: > Hi, From what I see in the recent 4/5 digests, this forum seems to be for advanced > > and professional programmers. > > So wondering if a newbie can post some questions to understand errors in his code > > or will it look silly? Yes you may indeed post here. There's also a beginners list called python-help, which may seem less intimidating. If you do post with a question, be sure to copy and paste a complete traceback of any exceptions your program is raising. Also if you can, post a small but runnable code snippet that demonstrates the problem you are having. This list does tend to run off into the weeds fairly quickly on many threads, but usually you can get some good assistance before that happens. From skip.montanaro at gmail.com Fri Sep 8 23:02:07 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Fri, 8 Sep 2017 22:02:07 -0500 Subject: Questions. In-Reply-To: References: Message-ID: > Hi, From what I see in the recent 4/5 digests, this forum seems to be for advanced and professional programmers. > > So wondering if a newbie can post some questions to understand errors in his code or will it look silly? While there are professional programmers here, and some questions explore various dark corners of the language and its libraries, the experience level runs the gamut, from people just learning the language to core developers. So, fire away. It does help if you don't ask us to do your homework for you. :-) Skip From robertvstepp at gmail.com Fri Sep 8 23:09:05 2017 From: robertvstepp at gmail.com (boB Stepp) Date: Fri, 8 Sep 2017 22:09:05 -0500 Subject: Questions. In-Reply-To: <47eaa902-5244-0b29-c029-e90708577691@gmail.com> References: <47eaa902-5244-0b29-c029-e90708577691@gmail.com> Message-ID: On Fri, Sep 8, 2017 at 9:54 PM, Michael Torrie wrote: > On 09/08/2017 08:35 PM, V Vishwanathan wrote: >> Hi, From what I see in the recent 4/5 digests, this forum seems to be for advanced >> >> and professional programmers. >> >> So wondering if a newbie can post some questions to understand errors in his code >> >> or will it look silly? > > Yes you may indeed post here. There's also a beginners list called > python-help, which may seem less intimidating. That would be Python Tutor. Subscription information may be found at https://mail.python.org/mailman/listinfo/tutor It is a moderated list, so there may be a short delay before your first post(s) may come through. -- boB From ian.g.kelly at gmail.com Fri Sep 8 23:25:20 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 8 Sep 2017 21:25:20 -0600 Subject: Not appending ("lib") to sys.path breaks tests. In-Reply-To: <38617b43-45a3-df73-6b35-02f3d2e68b27@gmail.com> References: <86d3e500-56e2-3fab-5bdb-879d5ceb8734@gmail.com> <38617b43-45a3-df73-6b35-02f3d2e68b27@gmail.com> Message-ID: On Fri, Sep 8, 2017 at 3:54 PM, Leam Hall wrote: > On 09/08/2017 05:41 PM, Ian Kelly wrote: > >> I'm confused about where the character_tools import is made. If that's >> within a module in the lib package, it should be fine. > > >> It looks like it's failing to find the lib package. Since you removed >> the "lib" directory from sys.path, does its parent directory exist in >> sys.path? > > > The path is not in the modules path or in sys.path. Hence the append. I > thought I could add the local "lib" path via "." or "lib.", but it seems > not. > > import lib.character fails in the tests/ directory. Certainly not "lib.". The paths in sys.path need to be valid filesystem paths for your OS. However, "." works for me: (xenial)ikelly at localhost:~$ mkdir lib (xenial)ikelly at localhost:~$ touch lib/__init__.py (xenial)ikelly at localhost:~$ touch lib/character.py (xenial)ikelly at localhost:~$ python3 Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import lib.character >>> (xenial)ikelly at localhost:~$ mkdir tests (xenial)ikelly at localhost:~$ echo "import lib.character" > tests/test_character.py (xenial)ikelly at localhost:~$ python3 tests/test_character.py Traceback (most recent call last): File "tests/test_character.py", line 1, in import lib.character ImportError: No module named 'lib' (xenial)ikelly at localhost:~$ export PYTHONPATH=. (xenial)ikelly at localhost:~$ python3 tests/test_character.py (xenial)ikelly at localhost:~$ The only thing I can think of is to question what the CWD is when you're running the test. If it's not the parent directory of lib, then of course "." wouldn't work. Note from the transcript that when running interactively, '' (which is equivalent to '.') is automatically prepended to sys.path, whereas when running a script, the absolute path of the directory containing the script is prepended instead. That's why PYTHONPATH needed to be set for the second test but not the first. From tjreedy at udel.edu Fri Sep 8 23:47:20 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 8 Sep 2017 23:47:20 -0400 Subject: Using Python 2 In-Reply-To: <59b2c502$0$16752$b1db1813$d948b532@news.astraweb.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> <59b2c502$0$16752$b1db1813$d948b532@news.astraweb.com> Message-ID: On 9/8/2017 12:27 PM, Steve D'Aprano wrote: > On Sat, 9 Sep 2017 12:23 am, Leam Hall wrote: >> If Python 3 is not a total re-write then why break >> compatibility? > > To avoid building up excess cruft in the language. > > To fix design mistakes which cannot be fixed without a backwards-incompatible > change. One of the semi-myths about 3.0 is that is was somehow unique in breaking backward compatibility. Python has always (for last 2 decades, anyway) has a procedure of deprecation and removal of old stuff. What happened is that about 2.4, or whenever planning for 3.0 became serious, removals were mostly delayed until 3.0. For instance, the original proposal for changing 1/2 from being 0 to being .5 proposed doing it in 2.5. Instead it was delayed to 3.0. Without the prospect of 3.0, it would have happened sooner. One change during 2.x that was not delayed was the removal of string exceptions. So far during 3.x, at least a few modules have been deprecated and scheduled to be removed. But when support for 2.7 was extended another 5 years, we decided to delay such removals until after 2.7 support ends, in order to ease porting. -- Terry Jan Reedy From viradha at hotmail.com Sat Sep 9 01:58:36 2017 From: viradha at hotmail.com (V Vishwanathan) Date: Sat, 9 Sep 2017 05:58:36 +0000 Subject: Key Error: "city" Message-ID: (1) Trying to convert concatenated string to .format method (2) concatenated string >> [#todo rewrite this line to use the format method rather than string concatenation alert = "Today's forecast for " + city + ": The temperature will range from " + str(low_temperature) + " to " + str(high_temperature) + " " + temperature_unit + ". Conditions will be " + weather_conditions + "."] (3) My code: city = "Seoul" high_temperature = 18 low_temperature = 9 temperature_unit = "degrees Celsius" weather_conditions = "light rain" alert = "Today's forecast for {city}: The temperature will range from{low_temperature} "" to ""{high_temperature}{temperature_unit}Conditions will be {weather_conditions}".format(city,low_temperature,high_temperature,temperature_unit,weather_conditions) print(alert) (4) output: Traceback (most recent call last): File "D:\python exercises\uda format1.py", line 6, in alert = "Today's forecast for {city}: The temperature will range from{low_temperature} "" to ""{high_temperature}{temperature_unit}Conditions will be {weather_conditions}".format(city,low_temperature,high_temperature,temperature_unit,weather_conditions) KeyError: 'city' (5) Tried Google but not much help. So would appreciate any help. Thanks, Venkat From ben+python at benfinney.id.au Sat Sep 9 02:20:00 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 09 Sep 2017 16:20:00 +1000 Subject: Key Error: "city" References: Message-ID: <85d1708kbz.fsf@benfinney.id.au> V Vishwanathan writes: > alert = "Today's forecast for {city}: The temperature will range from{low_temperature} "" to ""{high_temperature}{temperature_unit}Conditions will be {weather_conditions}".format(city,low_temperature,high_temperature,temperature_unit,weather_conditions) > print(alert) The ?str.format? method accepts positional arguments and keyword arguments. When you want to refer to the arguments by name, the method must know their names; that means passing them to the method as keyword arguments. > Traceback (most recent call last): > File "D:\python exercises\uda format1.py", line 6, in > alert = "Today's forecast for {city}: The temperature will range from{low_temperature} "" to ""{high_temperature}{temperature_unit}Conditions will be {weather_conditions}".format(city,low_temperature,high_temperature,temperature_unit,weather_conditions) > KeyError: 'city' Your format string refers to keys (names) that are not found in the dictionary of keyword arguments ? because you passed no keyword arguments. Instead, give a keyword argument for each name you want to refer to in the format string. -- \ ?There's a certain part of the contented majority who love | `\ anybody who is worth a billion dollars.? ?John Kenneth | _o__) Galbraith, 1992-05-23 | Ben Finney From ofekmeister at gmail.com Sat Sep 9 02:21:43 2017 From: ofekmeister at gmail.com (ofekmeister at gmail.com) Date: Fri, 8 Sep 2017 23:21:43 -0700 (PDT) Subject: Hatch - A modern project, package, and virtual env manager In-Reply-To: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> References: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> Message-ID: <8be0d236-76f4-4da2-b6df-682d0841c944@googlegroups.com> Temporary venvs support and terminal colors in 0.8.0! https://github.com/ofek/hatch#080 From sonamdemapuku at gmail.com Sat Sep 9 02:23:40 2017 From: sonamdemapuku at gmail.com (sonamdemapuku at gmail.com) Date: Fri, 8 Sep 2017 23:23:40 -0700 (PDT) Subject: Case Solution: Doing Business in Sierra Leone Graeme Hossie at London Mining (A) by Brian C. Pinkham, Ken Mark In-Reply-To: <353d9194-6a2b-4b4b-875b-4f71d59feba5@googlegroups.com> References: <353d9194-6a2b-4b4b-875b-4f71d59feba5@googlegroups.com> Message-ID: <82ac1682-9d27-43bc-bdfb-292bd7489c5a@googlegroups.com> What priorities should hossie consider? What are some of the concerns around enforcement of the contract? How should hossie carry out negotiations? From viktorovichandrej at gmail.com Sat Sep 9 02:43:17 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Fri, 8 Sep 2017 23:43:17 -0700 (PDT) Subject: Hat difference between "" and '' in string definition Message-ID: Hello, What is difference between string definitions: s="aaa" and s='bbb' From dieter at handshake.de Sat Sep 9 02:49:12 2017 From: dieter at handshake.de (dieter) Date: Sat, 09 Sep 2017 08:49:12 +0200 Subject: Merge pdf files using information from two files References: <3092fd53-5d3d-4fb6-be02-d1bf75924307@googlegroups.com> Message-ID: <87y3pol63b.fsf@handshake.de> accessnewbie at gmail.com writes: > I have two files (right now they are spreadsheets but I can export them to any format). > > File1 has StoreID (unique) in one column and a pdf map location in the second column. (Names not really sequenced numerically) > > 1 C:/maps/map1.pdf > 2 C:/maps/map2.pdf > 3 C:/maps/map3.pdf > 4 C:/maps/map4.pdf > > File2 has 3 columns. Column1 is the County name (unique), Column2 are the store IDs that fall in that county separated by commas, and Column3 is warehouse that services the store. > > County1 1,2 Warehouse1 > County2 1,3 Warehouse1 > County3 3 Warehouse4 > County4 2,4 Warehouse3 > > Is it possible to compare both files and append the maps that belong in each county and naming it by the county_warehouse.pdf? This will not be easy: PDF is a page layout oriented format, not a format to facilitate the processing of general structural data (such as e.g. XML). You could use a package like "pdfminer" to get at the text content of a PDF file. You will then need specialized code (developed by yourself) to reconstruct the column information. You could then use a PDF generating package such as "reportlab" to generate a new PDF file. From __peter__ at web.de Sat Sep 9 02:58:52 2017 From: __peter__ at web.de (Peter Otten) Date: Sat, 09 Sep 2017 08:58:52 +0200 Subject: Hat difference between "" and '' in string definition References: Message-ID: Andrej Viktorovich wrote: > What is difference between string definitions: > s="aaa" > and > s='bbb' There's no difference. It helps you avoid explicit escapes, i. e. >>> "What's up?" "What's up?" is a tad more readable than >>> 'What\'s up' "What's up" Likewise, multiline strings are easier to read when written as >>> """foo ... bar ... baz ... """ 'foo\nbar\nbaz\n' than >>> "foo\nbar\nbaz\n" 'foo\nbar\nbaz\n' If you do not want to mess up indentation implicit string concatenation is sometimes useful. With that >>> if True: ... """foo ... bar ... baz ... """ ... 'foo\nbar\nbaz\n' may be rewritten as >>> if True: ... ( ... "foo\n" ... "bar\n" ... "baz\n" ... ) ... 'foo\nbar\nbaz\n' From tjol at tjol.eu Sat Sep 9 05:15:45 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Sat, 9 Sep 2017 11:15:45 +0200 Subject: Key Error: "city" In-Reply-To: References: Message-ID: <18c58574-7e42-83ff-45e0-66ae967f4cba@tjol.eu> On 09/09/17 07:58, V Vishwanathan wrote: > alert = "Today's forecast for {city}: The temperature will range from{low_temperature} "" to ""{high_temperature}{temperature_unit}Conditions will be {weather_conditions}".format(city,low_temperature,high_temperature,temperature_unit,weather_conditions) The reason this doesn't (and can't) work is that when you call "...".format(city, ...), the format method has no idea that you called the variable "city" rather than something else. You can tell format() the names of your variables by using keyword arguments: alert = ("Today's forecast for {city}: The temperature will range from {low_temperature} " " to {high_temperature}{temperature_unit} Conditions will be {weather_conditions}" .format(city=city, low_temperature=low_temperature, high_temperature=high_temperature, temperature_unit=temperature_unit, weather_conditions=weather_conditions)) Now that looks a bit silly. It's shorter, but maybe not quite as clear, to not use names at all: alert = ("Today's forecast for {}: The temperature will range from {} " " to {}{} Conditions will be {}" .format(city, low_temperature, high_temperature, temperature_unit, weather_conditions)) If you are using Python 3.6 or newer, there's a third way that, in this case, makes your code far more elegant: a formatted string literal alert = (f"Today's forecast for {city}: The temperature will range from {low_temperature} " f" to {high_temperature}{temperature_unit} Conditions will be {weather_conditions}") -- Thomas From breamoreboy at gmail.com Sat Sep 9 05:23:32 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sat, 9 Sep 2017 02:23:32 -0700 (PDT) Subject: Questions. In-Reply-To: References: <47eaa902-5244-0b29-c029-e90708577691@gmail.com> Message-ID: On Saturday, September 9, 2017 at 4:09:24 AM UTC+1, boB Stepp wrote: > On Fri, Sep 8, 2017 at 9:54 PM, Michael Torrie wrote: > > On 09/08/2017 08:35 PM, V Vishwanathan wrote: > >> Hi, From what I see in the recent 4/5 digests, this forum seems to be for advanced > >> > >> and professional programmers. > >> > >> So wondering if a newbie can post some questions to understand errors in his code > >> > >> or will it look silly? > > > > Yes you may indeed post here. There's also a beginners list called > > python-help, which may seem less intimidating. > > That would be Python Tutor. Subscription information may be found at > > https://mail.python.org/mailman/listinfo/tutor > > It is a moderated list, so there may be a short delay before your > first post(s) may come through. > > -- > boB No, there is a help list at https://mail.python.org/mailman/listinfo/python-help Kindest regards. Mark Lawrence. From radhika.rainee76 at gmail.com Sat Sep 9 06:10:06 2017 From: radhika.rainee76 at gmail.com (radhika.rainee76 at gmail.com) Date: Sat, 9 Sep 2017 03:10:06 -0700 (PDT) Subject: Case Solution: Doing Business in Sierra Leone Graeme Hossie at London Mining (A) by Brian C. Pinkham, Ken Mark In-Reply-To: <353d9194-6a2b-4b4b-875b-4f71d59feba5@googlegroups.com> References: <353d9194-6a2b-4b4b-875b-4f71d59feba5@googlegroups.com> Message-ID: <265572ee-98c9-4739-8579-0063374cee14@googlegroups.com> Solutions of this case study From pavol.lisy at gmail.com Sat Sep 9 06:31:46 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Sat, 9 Sep 2017 12:31:46 +0200 Subject: The Incredible Growth of Python (stackoverflow.blog) Message-ID: Interesting reading: https://stackoverflow.blog/2017/09/06/incredible-growth-python/?cb=1 From jmeile at hotmail.com Sat Sep 9 07:03:50 2017 From: jmeile at hotmail.com (Josef Meile) Date: Sat, 9 Sep 2017 11:03:50 +0000 Subject: Need to pass a class instance to a gettext fallback In-Reply-To: References: Message-ID: Hi Peter >> language = kwargs['language'] >> del kwargs['language'] > >Not really important, but there's a method for that: > >language = kwargs.pop("language") Thanks, this looks better and I indeed think it is important. The "del ..." line looks ugly. >> def __init__(self, *args, **kwargs): >> language = kwargs['language'] >> del kwargs['language'] > >In Python 3 this can also be spelt with a keyword-only language argument: > >def __init__(self, *args, language, **kwargs): > ... # no pop() or del I'm using Python 2.7.10, but this also works there, so, I replace it with your suggestion. And before you tell me that python 2.7 is old, the thing is that I'm writing a pluging for Gimp and this is the version they distribute :-( Thanks for your valuable help Best regards Josef From tjreedy at udel.edu Sat Sep 9 14:57:41 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 9 Sep 2017 14:57:41 -0400 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: Message-ID: On 9/9/2017 6:31 AM, Pavol Lisy wrote: > Interesting reading: > https://stackoverflow.blog/2017/09/06/incredible-growth-python/?cb=1 So much for Python 3 having killed python ;-) -- Terry Jan Reedy From python at mrabarnett.plus.com Sat Sep 9 14:59:26 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 9 Sep 2017 19:59:26 +0100 Subject: Hat difference between "" and '' in string definition In-Reply-To: References: Message-ID: <28fb73f9-22f8-d607-1577-29b00db3f531@mrabarnett.plus.com> On 2017-09-09 07:43, Andrej Viktorovich wrote: > Hello, > > What is difference between string definitions: > s="aaa" > and > s='bbb' > There's no difference. From gerlando.falauto at gmail.com Sat Sep 9 17:23:38 2017 From: gerlando.falauto at gmail.com (iurly) Date: Sat, 9 Sep 2017 14:23:38 -0700 (PDT) Subject: array.array()'s memory shared with multiprocessing.Process() Message-ID: <27b84429-2a3f-4bfd-921e-13ede1f3d383@googlegroups.com> Hi, I'm writing a multiprocessing program whose behavior I don't understand. Essentially, the main process collects data and then passes it to a consumer process. For performance reasons I'm using a "static" circular buffer created through array.array(), and then passing it "as-is" by pushing it onto a queue. According to: https://docs.python.org/3/library/multiprocessing.html#pipes-and-queues I would expect the array to be pickled by the sending process and then unpickled at the other end (i.e. no memory would be shared among the two processes). Thus, overwriting data on the buffer should be safe in my understanding. What happens instead is that the consumer thread may indeed receive a corrupted array, in that some elements might have already been overwritten by the producer. I did somehow overcome this limitation by just passing a copy.copy() of the buffer, but I really don't understand why this would be necessary at all. Could someone please shed some light on this? Thank you! Here's the example code: --- import multiprocessing as mp import array import time def consumer_process(queue): while True: ts_buffer = queue.get() #time.sleep(.1) i = 0 for idx in range(1, len(ts_buffer)): diff = ts_buffer[idx] - ts_buffer[idx-1] if diff < 0: print("error: idx = ", idx, " diff =", diff, ":", ts_buffer[idx-1], " -> ", ts_buffer[idx]) queue = mp.Queue(100) p = mp.Process(name="consumer", target=consumer_process, args=(queue,)) p.daemon = True # can't use daemon as kwargs when using multiprocessing.dummy p.start() samples_dump = 20000 ts_buffer = array.array('f', bytearray(4 * (samples_dump))) i = 0 while True: for idx in range(0,len(ts_buffer)): ts_buffer[idx] = i i += 1 queue.put(ts_buffer) # enable this to make the error go away #time.sleep(.1) --- error: idx = 18372 diff = -19999.0 : 38371.0 -> 18372.0 error: idx = 17011 diff = -19999.0 : 97010.0 -> 77011.0 error: idx = 15670 diff = -19999.0 : 135669.0 -> 115670.0 error: idx = 14914 diff = -19999.0 : 154913.0 -> 134914.0 error: idx = 19405 diff = -19999.0 : 179404.0 -> 159405.0 error: idx = 17160 diff = -19999.0 : 197159.0 -> 177160.0 error: idx = 19130 diff = -19999.0 : 219129.0 -> 199130.0 error: idx = 14298 diff = -19999.0 : 254297.0 -> 234298.0 error: idx = 9307 diff = -19999.0 : 289306.0 -> 269307.0 error: idx = 15815 diff = -19999.0 : 315814.0 -> 295815.0 error: idx = 11587 diff = -19999.0 : 331586.0 -> 311587.0 --- $ python3 --version Python 3.5.2 From steve+python at pearwood.info Sat Sep 9 20:07:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 10 Sep 2017 10:07:22 +1000 Subject: Hat difference between "" and '' in string definition References: Message-ID: <59b4823b$0$16724$b1db1813$d948b532@news.astraweb.com> On Sun, 10 Sep 2017 05:47 am, Stefan Ram wrote: > Andrej Viktorovich writes: >>What is difference between string definitions: >>s="aaa" >>and >>s='bbb' > > These two assignment statements differ in their > last five characters. > > Their difference can be calculated thus: > > |>>> int.from_bytes \ > |... ( bytearray( 's="aaa"', 'us-ascii' ), \ > |... byteorder='big', signed=False )- \ > |... int.from_bytes \ > |... ( bytearray( "s='bbb'", 'us-ascii' ), \ > |... byteorder='big', signed=False ) > |-21491679493 > > . And they say Germans have no sense of humour :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From python at mrabarnett.plus.com Sat Sep 9 20:15:51 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 10 Sep 2017 01:15:51 +0100 Subject: array.array()'s memory shared with multiprocessing.Process() In-Reply-To: <27b84429-2a3f-4bfd-921e-13ede1f3d383@googlegroups.com> References: <27b84429-2a3f-4bfd-921e-13ede1f3d383@googlegroups.com> Message-ID: <25368303-5a50-e35a-dbe0-04de800e94f3@mrabarnett.plus.com> On 2017-09-09 22:23, iurly wrote: > Hi, > > I'm writing a multiprocessing program whose behavior I don't understand. > Essentially, the main process collects data and then passes it to a consumer process. > For performance reasons I'm using a "static" circular buffer created through array.array(), and then passing it "as-is" by pushing it onto a queue. > > According to: > https://docs.python.org/3/library/multiprocessing.html#pipes-and-queues > > I would expect the array to be pickled by the sending process and then unpickled at the other end (i.e. no memory would be shared among the two processes). > Thus, overwriting data on the buffer should be safe in my understanding. > > What happens instead is that the consumer thread may indeed receive a corrupted array, in that some elements might have already been overwritten by the producer. > I did somehow overcome this limitation by just passing a copy.copy() of the buffer, but I really don't understand why this would be necessary at all. > > Could someone please shed some light on this? > Thank you! > [snip] I suspect it's down to timing. What you're putting into the queue is a reference to the array, and it's only some time later that the array itself is pickled and then sent (the work being done in the 'background'). Modifying the array before (or while) it's actually being sent would explain the problem you're seeing. From rantingrickjohnson at gmail.com Sat Sep 9 21:37:24 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Sep 2017 18:37:24 -0700 (PDT) Subject: Design: method in class or general function? In-Reply-To: <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> Message-ID: <7abf1b18-b712-4414-baa1-fe83e50e9580@googlegroups.com> On Thursday, September 7, 2017 at 7:16:25 AM UTC-5, Steve D'Aprano wrote: > Python 2.6 is ancient, Enough with your hyperbole! Python 2.6 is no where near being ancient. Python 2.6 is a stable version that gets the job done for many folks in this community. Folks who actually spend their time getting things done, instead of polishing GvR's knob and spending every waking hour in the echo chamber of Python-dev and Python-ideas. > and is missing many nice features. Says you. Beauty is in the eye of the beholder. And what is practical for you will not always be practical for everyone else. > You should consider using the latest version, 3.6. The OP should consider using whatever version of Python that suits the OP. From greg.ewing at canterbury.ac.nz Sat Sep 9 21:41:44 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 10 Sep 2017 13:41:44 +1200 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: Message-ID: Pavol Lisy wrote: > Interesting reading: > https://stackoverflow.blog/2017/09/06/incredible-growth-python/?cb=1 So, Python's rate of expansion is accelerating, like the universe. Does that mean there's some kind of dark energy fuelling its growth? -- Greg From rosuav at gmail.com Sat Sep 9 21:48:16 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Sep 2017 11:48:16 +1000 Subject: Design: method in class or general function? In-Reply-To: <7abf1b18-b712-4414-baa1-fe83e50e9580@googlegroups.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <7abf1b18-b712-4414-baa1-fe83e50e9580@googlegroups.com> Message-ID: On Sun, Sep 10, 2017 at 11:37 AM, Rick Johnson wrote: > On Thursday, September 7, 2017 at 7:16:25 AM UTC-5, Steve D'Aprano wrote: >> Python 2.6 is ancient, > > Enough with your hyperbole! Python 2.6 is no where near > being ancient. Python 2.6 is a stable version that gets the > job done for many folks in this community. Folks who > actually spend their time getting things done, instead of > polishing GvR's knob and spending every waking hour in the > echo chamber of Python-dev and Python-ideas. Python 2.6.9 is the final security-only source-only maintenance release of the Python 2.6 series. With its release on October 29, 2013, all official support for Python 2.6 has ended. Python 2.6 is no longer being maintained for any purpose. -- PEP 361 Python 2.6 went out of support four years ago, or earlier if you depend on published binaries. If by "stable" you mean that it's utterly static, then go use Python 1.5 - it's been stable for longer. I'm with Steve on this. Python 2.6 is ancient. ChrisA From rosuav at gmail.com Sat Sep 9 21:48:44 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Sep 2017 11:48:44 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: Message-ID: On Sun, Sep 10, 2017 at 11:41 AM, Gregory Ewing wrote: > Pavol Lisy wrote: >> >> Interesting reading: >> https://stackoverflow.blog/2017/09/06/incredible-growth-python/?cb=1 > > > So, Python's rate of expansion is accelerating, like > the universe. Does that mean there's some kind of dark > energy fuelling its growth? The Python Secret Underground emphatically does not exist. ChrisA From rantingrickjohnson at gmail.com Sat Sep 9 21:49:57 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Sep 2017 18:49:57 -0700 (PDT) Subject: Design: method in class or general function? In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <854lseadrm.fsf@benfinney.id.au> Message-ID: On Thursday, September 7, 2017 at 7:35:45 AM UTC-5, Ben Finney wrote: > Another, more compelling, reason to follow [Steven's] > advice: Python 2 is in maintenance-only mode and will > receive no support at all in a few years. So what? The OP may not be the type who needs to have his diaper changed. Believe it, or not, there are people in this world who are actually self-reliant. I know. It's difficult to believe. But it's true! > It is a dead end. Says you. > Python 3 is actively developed and will be supported indefinitely. "indefinitely"? Such a word hardly inspires a feeling of confidence in me! > Beginners today should prefer Python 3 unless they know > that they must remain on older versions, and even then > should correct whatever is keeping them from moving to the > actively-developed language. And are you willing to volunteer your time to migrate the OP's libraries? Talk is cheap. Sometimes, practicality beats purity... (hmm, i just know i heard that somewhere!) From rantingrickjohnson at gmail.com Sat Sep 9 21:59:29 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Sep 2017 18:59:29 -0700 (PDT) Subject: Design: method in class or general function? In-Reply-To: <87mv66llyx.fsf@elektro.pacujo.net> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <854lseadrm.fsf@benfinney.id.au> <87mv66llyx.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Ben Finney wrote: > > Another, more compelling, reason to follow that advice: > > Python 2 is in maintenance-only mode and will receive no > > support at all in a few years. It is a dead end. Python 3 > > is actively developed and will be supported indefinitely. > > This reminds me of the Biblical story of the major > refactoring of humanity at Noah's time. God ended up > regretting the upheaval and promised never to make such a > backward-incompatible change again: Yep, even mythical tales of cosmic monsters can teach valuable lessons. There is no doubt that Python3 is mutating in ways that are violating the core philosophy of the langauge. A language should "evolve" _slowly_ over time, not become a grotesque mutant _overnight_, as a result of swan- diving into a toxic waste dump! From rantingrickjohnson at gmail.com Sat Sep 9 22:23:43 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Sep 2017 19:23:43 -0700 (PDT) Subject: Design: method in class or general function? In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> Message-ID: <1378089d-35df-4ab7-9f11-9bae7973730b@googlegroups.com> Ben Finney wrote: > leam hall writes: > > > > I've wrestled with that discussion for a while and Python > > 3 loses every time. > > The context of the thread you started was that you are a > *newcomer* to Python. Now you say you've considered Python > 2 versus Python 3 many times? What explains that apparent > contradiction? The OP said: "OOP newbie on Python 2.6" and "Sorry about being unclear earlier, coffee was still kicking in and I'm still a newbie that mixes up terms." From my POV, both quotes are referring to OOP, not Python. > > There's literally no good reason for me to move to Python > > 3 earlier than mid-2020's. Please accept the fact that > > there are hundreds of thousands of servers, if not > > millions, running Python 2.x. > > The servers can continue to run Python 2.x to support > existing programs. That doesn't go against the advice > given. The advice is that Python 3 is today the best > choice for a Python *newcomer*, and for writing *new* code > such as in the example which started this thread. Not all "new code" requires the features of Python3. Are lazy iterators going to make or break "new code"? Is the print function going to make or break "new code"? Is the removal of some little used modules or features from Python2 going to make or break "new code"? Possibly! > > Whether or not Python 3 has any neat cool stuff is > > irrelevant to those of us seeking to use Python to get > > today's work done. *EXACTLY*! > If today's work *only* involves maintaining existing Python > 2 legacy programs, go right ahead. That role will only > shrink, though, so it's not a good thing to learn today. Total BS. There is nothing about Python2.x that is preventing a programmer from writing good, modern code. Python is nothing but a tool, and only a poor craftsman blames his tools for his own incompetence. > For people learning Python, or for writing new programs in > Python, it is best to avoid the dead-end Python 2 > altogether and use the current version of Python 3. Just because you and Steven have decided to follow the Python3 religion, does not mean everyone else should follow along blindly. You have made your emotional appeal for Python3 and the OP has rejected your appeal, and now it's time for you and Steven to accept the reality that people have the freedom to choose whichever tool works best for _them_, not for _you_. From rustompmody at gmail.com Sat Sep 9 22:42:25 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 9 Sep 2017 19:42:25 -0700 (PDT) Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: Message-ID: <67881f33-3425-4520-a5fc-9059a5ff7c72@googlegroups.com> On Sunday, September 10, 2017 at 7:12:10 AM UTC+5:30, Gregory Ewing wrote: > Pavol Lisy wrote: > > Interesting reading: > > https://stackoverflow.blog/2017/09/06/incredible-growth-python/?cb=1 > > So, Python's rate of expansion is accelerating, like > the universe. Does that mean there's some kind of dark > energy fuelling its growth? Something to do with the small Hamming-distance between "God" and "Guido" ? From rantingrickjohnson at gmail.com Sat Sep 9 23:08:09 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Sep 2017 20:08:09 -0700 (PDT) Subject: Using Python 2 In-Reply-To: <878thpjr8t.fsf@elektro.pacujo.net> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <878thpjr8t.fsf@elektro.pacujo.net> Message-ID: <276e8910-6128-419b-b262-d0152053d752@googlegroups.com> Marko Rauhamaa wrote: > The risk to Python will be whether the occasion is > exploited by fanboys of competing programming languages. > The migration from Python 2 might be to something else than > Python 3 in some circles. That has been my observation as well. Python-dev and Python- ideas have become echo chambers that ignore the majority of Python users for the sake of a hand-full of squeaky wheels, squeaky wheels that are all squeaking to the same tune. Sure, many of the "everyday users" for which i speak don't care to defile themselves in the bitter politics that runs rampant on these lists, but, by rejecting the majority, the language itself looses many loyal supporters. So why bother migrating to Python3, when we can migrate to another language that does not suffer the same fundamental flaws, and who does not forcefully reject those who dare to question the new found religion of Python3? New is not always "better", you know... But that's what the Python3 jihadis want us to believe. You see folks, a long time ago (and not so long as you may think!), the same people who now despise Python2, were singing its praises. Oh yes, Python2 had just replaced Python1, and then we were told that Python2 was the best thing since sliced bread. And this was the chant of the pymonks for many years, until Python3 came on the scene. Then, all of a sudden, Python2 (yes, the same Python2 that had been a quality tool only a day earlier!), suddenly transformed into a despised and ancient thing. From rantingrickjohnson at gmail.com Sat Sep 9 23:25:38 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Sep 2017 20:25:38 -0700 (PDT) Subject: Using Python 2 In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <878thpjr8t.fsf@elektro.pacujo.net> Message-ID: <635408ad-9f30-413b-a9c0-3e9df8ca4284@googlegroups.com> Chris Angelico wrote: > And the sky is going to fall on Chicken Little's head, any > day now. Let's see. You can port your code from Python 2.7 > to Python 3.6 by running a script and then checking the > results for bytes/text problems. This is an argument i find interesting: First, the Python3 jihadis claim that we should all migrate to Python3 because Python2 is so useless and ancient, and that if we write code in Python2, all of our efforts will be a total waste -- But then! -- they gush about how easy migrating from Python2 to Python3 is. LOL! To me, this sounds a lot like what is undermining ObamaCare: specifically, the mandate that insurance companies cannot deny persons with pre-existing conditions. Of course, with such a mandate, people won't buy insurance until they get sick! You see folks, that's what happens when you become blinded by emotion. And there is a lot of emotion surrounding this Python3 religion. > You can port your code from Python 2.7 to Ruby by paying > developers big bucks for a good while. Yep, because, in your deluded reality, migrating from Python2 to Python3 cost nothing. :-\ > Advantage: Ruby, obviously, because it's easier to change > languages than to audit your code for places where you had > lurking bugs that you didn't know about. Pretending that Python2 code is somehow "riddled with bugs", simply because it does not execute cleanly in Python3, is laughable. But why am i surprised that a jihadi would attempt to demonize the opposition? From rantingrickjohnson at gmail.com Sat Sep 9 23:26:29 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Sep 2017 20:26:29 -0700 (PDT) Subject: Using Python 2 In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> Message-ID: On Friday, September 8, 2017 at 8:57:56 AM UTC-5, Ned Batchelder wrote: > On 9/8/17 6:12 AM, Leam Hall wrote: > > I've read comments about Python 3 moving from the Zen of Python. I'm a > > "plain and simple" person myself. Complexity to support what CompSci > > folks want, which was used to describe some of the Python 3 changes, > > doesn't help me get work done. > > I've heard a lot of FUD about the Python 3 transition, but this one is > new to me.? What is it that CompSci folks want that developers don't > want, that ruined Python 3? TWO WORDS: "Type" and "Hints" From rantingrickjohnson at gmail.com Sat Sep 9 23:48:22 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Sep 2017 20:48:22 -0700 (PDT) Subject: Using Python 2 In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> Message-ID: On Friday, September 8, 2017 at 9:22:52 AM UTC-5, leam hall wrote: > To say Python 2 is old is true. Old? Yes. Ancient? BS! > What does it matter though? Unless Python 3 provides a > business value for spending lots of time and money to > change then "old" doesn't matter. If the code performs the function it was intended to perform, and does so in a time-frame that is acceptable to you and your clients, then migrating it is absolute foolishness. Old code is less buggy than new code, and migration will only create new bugs where none existed before. Don't listen to these religious fanatics. New is not always better, nor preferred. Anecdote: My ex-GF would run out and buy a new phone, a new computer, or some other stupid gadget or another every time a slick advert told her to do so, and i would try to explain to her: "Listen babe, it's just a new shade of lipstick on a pig!" -- but she wouldn't listen. She had to have the new thing just because it was _new_. And they wonder how Microsoft made billions! #_o From gheskett at shentel.net Sat Sep 9 23:50:22 2017 From: gheskett at shentel.net (Gene Heskett) Date: Sat, 9 Sep 2017 23:50:22 -0400 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: Message-ID: <201709092350.22610.gheskett@shentel.net> On Saturday 09 September 2017 21:48:44 Chris Angelico wrote: > On Sun, Sep 10, 2017 at 11:41 AM, Gregory Ewing > > wrote: > > Pavol Lisy wrote: > >> Interesting reading: > >> https://stackoverflow.blog/2017/09/06/incredible-growth-python/?cb= > >>1 > > > > So, Python's rate of expansion is accelerating, like > > the universe. Does that mean there's some kind of dark > > energy fuelling its growth? > > The Python Secret Underground emphatically does not exist. > > ChrisA Humm. here all this time I thought you were a charter member. :) 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 rantingrickjohnson at gmail.com Sun Sep 10 00:04:52 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Sep 2017 21:04:52 -0700 (PDT) Subject: Using Python 2 In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> Message-ID: <86bb1d56-9282-4d61-97ff-ab7c68c94a66@googlegroups.com> On Friday, September 8, 2017 at 9:41:55 AM UTC-5, Chris Angelico wrote: > False dichotomy. [Python3 was] not a total rewrite, but it > fixes certain long-standing issues. Compatibility had to be > broken in order to change certain behaviours. Namely: maintenance programmers who dared to take a break! > > To say Python 2 is old is true. What does it matter > > though? Unless Python 3 provides a business value for > > spending lots of time and money to change then "old" > > doesn't matter. > > Of course. And the biggest business value, in a lot of > cases, is that suddenly now your application works for ALL > the world's people. Oh please! As if all problems in computing can be reduced to mere localization issues. > We've heard the old story of "the Python 3 migration will > drive people away from Python" many, MANY times before. I > don't know of any success stories where someone brags about > how easy it was to port their entire codebase to a > different language, They don't port their entire code base, no, they keep the old Python2 code base and write the new stuff in some other language. Why would any rational person put themselves in a position to experience the same backwards incompatibility crappola when Python4 is thrust upon them? Remind me again: what's the definition of insanity? Can you imagine the rage that someone will feel after climbing up the migration hill from Python2 to Python3, and then suddenly, hearing the announcement that it's now time to migrate to Python4? The Python language cannot survive two confrontations with the absurd. One was difficult enough, and the community is still reeling from it. Introduce a second, and, well, it's over. From rantingrickjohnson at gmail.com Sun Sep 10 00:10:19 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Sep 2017 21:10:19 -0700 (PDT) Subject: Using Python 2 In-Reply-To: <59b2ba60$0$16721$b1db1813$d948b532@news.astraweb.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <878thpjr8t.fsf@elektro.pacujo.net> <59b2ba60$0$16721$b1db1813$d948b532@news.astraweb.com> Message-ID: <7f827228-30ec-4196-b9bc-232082eba70c@googlegroups.com> On Friday, September 8, 2017 at 10:42:44 AM UTC-5, Steve D'Aprano wrote: > To be perfectly rational, we *should* consider at least > three alternatives: > > (1) Stick with Python 2 and pay for support; > > (2) Migrate to Python 3; > > (3) Re-implement in some other language; > > and make a dispassionate choice according to which one has > the best cost/benefit ratio. And that choice won't always > be #2. Finally! A reasonable response. From rantingrickjohnson at gmail.com Sun Sep 10 00:22:10 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 9 Sep 2017 21:22:10 -0700 (PDT) Subject: Using Python 2 In-Reply-To: <59b2c2fe$0$16758$b1db1813$d948b532@news.astraweb.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> <59b2c2fe$0$16758$b1db1813$d948b532@news.astraweb.com> Message-ID: <2da7af11-d78b-4d22-9ff9-25de47fb3235@googlegroups.com> Steve D'Aprano wrote: > Chris Angelico wrote: > But some of us can't resist the temptation to evangelise > about Python 3 :-) An error that did not pass silently. Even when explicitly requested. > > Also, be completely honest here: how much work would it > > take for you to move your "millions of servers" from > > Python 2 to, say, PHP? or Ruby? or C? or JavaScript? Is > > any of those (or any write-in answer you wish) actually > > easier than porting to Python 3? > > Maybe not easier, but maybe there's some other payoff: > > - some poor, benighted folks just like Javascript or Ruby > better than Python (perhaps they were dropped on the head > as babies a few too many times *wink*) > > - maybe some companies have a glut of cheap PHP code- > monkeys they can throw at a problem, and shortage of > expensive Python rockstars who make unreasonable demands > like "decent working conditions" and "life-work balance"; I wonder what will happen if we replace "PHP code monkeys" with "immigrants", and "Python rockstars" with "Americans"? Hmm. Interesting. A Freudian Slip perhaps? From ben+python at benfinney.id.au Sun Sep 10 01:06:00 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 10 Sep 2017 15:06:00 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) References: <201709092350.22610.gheskett@shentel.net> Message-ID: <854lsb87nr.fsf@benfinney.id.au> Gene Heskett writes: > On Saturday 09 September 2017 21:48:44 Chris Angelico wrote: > > > The Python Secret Underground emphatically does not exist. > > Humm. here all this time I thought you were a charter member. :) With all the authority vested in me as a charter member, I can categorically say the Python Secret Underground does not exist. -- \ ?Pinky, are you pondering what I'm pondering?? ?Well, I think | `\ so, Brain, but first you'd have to take that whole bridge | _o__) apart, wouldn't you?? ?_Pinky and The Brain_ | Ben Finney From steve+python at pearwood.info Sun Sep 10 01:21:12 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 10 Sep 2017 15:21:12 +1000 Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> <86bb1d56-9282-4d61-97ff-ab7c68c94a66@googlegroups.com> Message-ID: <59b4cbca$0$16757$b1db1813$d948b532@news.astraweb.com> On Sun, 10 Sep 2017 02:04 pm, Rick Johnson wrote: > Can you imagine the rage that someone will feel after > climbing up the migration hill from Python2 to Python3, and > then suddenly, hearing the announcement that it's now time > to migrate to Python4? Guido has ruled that Python 4 will not be a major compatibility break, it will be more like the Python 1 to 2 transition. But you already know that, because we've had this discussion before. Multiple times. You can stop spreading this FUD now. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Sep 10 01:23:44 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 10 Sep 2017 15:23:44 +1000 Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <878thpjr8t.fsf@elektro.pacujo.net> <276e8910-6128-419b-b262-d0152053d752@googlegroups.com> Message-ID: <59b4cc62$0$16757$b1db1813$d948b532@news.astraweb.com> On Sun, 10 Sep 2017 01:08 pm, Rick Johnson wrote: > Marko Rauhamaa wrote: >> The risk to Python will be whether the occasion is >> exploited by fanboys of competing programming languages. >> The migration from Python 2 might be to something else than >> Python 3 in some circles. > > That has been my observation as well. It certainly has been. I still remember your panicked, "the sky is falling" posts terrified that unless we re-defined Python to your specifications, the entire Python community would rush to Ruby. That was, oh, ten or twelve years ago, if I remember correctly. How did that prediction work out for you? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From songofacandy at gmail.com Sun Sep 10 03:05:46 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Sun, 10 Sep 2017 16:05:46 +0900 Subject: People choosing Python 3 Message-ID: I saw encouraging tweet from Kenneth Reitz. https://twitter.com/kennethreitz/status/902028601893294081/photo/1 On Heroku, most people choose Python 3! I know, it's because Python 3 is the default Python on Heroku. I can't wait Python 3 is the default Python of Red Hat, and "python" command means Python 3 on Debian and Ubuntu. Regards, INADA Naoki From marko at pacujo.net Sun Sep 10 03:27:15 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Sep 2017 10:27:15 +0300 Subject: The Incredible Growth of Python (stackoverflow.blog) References: Message-ID: <87a823m2ss.fsf@elektro.pacujo.net> Terry Reedy : > On 9/9/2017 6:31 AM, Pavol Lisy wrote: >> Interesting reading: >> https://stackoverflow.blog/2017/09/06/incredible-growth-python/?cb=1 > > So much for Python 3 having killed python ;-) Hasn't yet, but it would have been interesting to see the 2/3 divide in the stats. One shouldn't get complacent. Ten years ago Nokia had a 40% global market share in cell phones. Now they're gone. The clouds I see looming over Python's head are: * 2-to-3 migration * static type annotation * asyncio with its a-dialect Marko From marko at pacujo.net Sun Sep 10 03:30:54 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Sep 2017 10:30:54 +0300 Subject: People choosing Python 3 References: Message-ID: <8760crm2mp.fsf@elektro.pacujo.net> INADA Naoki : > I can't wait Python 3 is the default Python of Red Hat, and "python" > command means Python 3 on Debian and Ubuntu. I can't wait till Python 3 is available on Red Hat. Marko From rosuav at gmail.com Sun Sep 10 03:59:41 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Sep 2017 17:59:41 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <87a823m2ss.fsf@elektro.pacujo.net> References: <87a823m2ss.fsf@elektro.pacujo.net> Message-ID: On Sun, Sep 10, 2017 at 5:27 PM, Marko Rauhamaa wrote: > Terry Reedy : > >> On 9/9/2017 6:31 AM, Pavol Lisy wrote: >>> Interesting reading: >>> https://stackoverflow.blog/2017/09/06/incredible-growth-python/?cb=1 >> >> So much for Python 3 having killed python ;-) > > Hasn't yet, but it would have been interesting to see the 2/3 divide in > the stats. > > One shouldn't get complacent. Ten years ago Nokia had a 40% global > market share in cell phones. Now they're gone. > > The clouds I see looming over Python's head are: > > * 2-to-3 migration If that was going to kill Python, it would have had some impact by now. There are students learning Python *today* who are never going to have to worry about the migration, because they're learning Python 3. > * static type annotation I'm not seeing very much of this in the wild yet, but honestly, it's not that big a deal. You can ignore it if you want to. > * asyncio with its a-dialect Actually, I think this one is a huge enough feature that it's going to be a big thing to *drive* the uptake of Python. ChrisA From kwpolska at gmail.com Sun Sep 10 04:19:36 2017 From: kwpolska at gmail.com (Chris Warrick) Date: Sun, 10 Sep 2017 10:19:36 +0200 Subject: People choosing Python 3 In-Reply-To: <8760crm2mp.fsf@elektro.pacujo.net> References: <8760crm2mp.fsf@elektro.pacujo.net> Message-ID: On 10 September 2017 at 09:30, Marko Rauhamaa wrote: > INADA Naoki : > >> I can't wait Python 3 is the default Python of Red Hat, and "python" >> command means Python 3 on Debian and Ubuntu. > > I can't wait till Python 3 is available on Red Hat. Python 3.4 is available in EPEL. RHEL 8 will switch to Python 3 as the main Python interpreter (assuming dnf replaces yum, as it did in Fedora a while back). -- Chris Warrick PGP: 5EAAEA16 From leamhall at gmail.com Sun Sep 10 05:25:51 2017 From: leamhall at gmail.com (Leam Hall) Date: Sun, 10 Sep 2017 05:25:51 -0400 Subject: People choosing Python 3 In-Reply-To: References: <8760crm2mp.fsf@elektro.pacujo.net> Message-ID: <3026bbec-495b-5451-19f6-d3255ba39307@gmail.com> On 09/10/2017 04:19 AM, Chris Warrick wrote: > On 10 September 2017 at 09:30, Marko Rauhamaa wrote: >> INADA Naoki : >> >>> I can't wait Python 3 is the default Python of Red Hat, and "python" >>> command means Python 3 on Debian and Ubuntu. >> >> I can't wait till Python 3 is available on Red Hat. > > Python 3.4 is available in EPEL. RHEL 8 will switch to Python 3 as the > main Python interpreter (assuming dnf replaces yum, as it did in > Fedora a while back). I'm not sure that RHEL 8 will be Python 3 for the OS tools. Even if it is, which version? From a non-rpm perspective Python 3.6.2 compiles nicely on CentOS 6. Once compiled it seems easy to use pip3 to install stuff without trampling on the OS's Python 2 install. Just have to make sure your PATH is set right. By putting /usr/local/bin after /usr/bin I can use "py.test" to run tests under Python 2 and "pytest" for Python 3. Leam p.s. Sorry Chris, meant to send this to the list. You get it twice. From marko at pacujo.net Sun Sep 10 05:34:05 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Sep 2017 12:34:05 +0300 Subject: People choosing Python 3 References: <8760crm2mp.fsf@elektro.pacujo.net> Message-ID: <871snevqwi.fsf@elektro.pacujo.net> Chris Warrick : > On 10 September 2017 at 09:30, Marko Rauhamaa wrote: >> I can't wait till Python 3 is available on Red Hat. > > Python 3.4 is available in EPEL. As an application developer, I can't make the customers depend on EPEL. It's Python2 until the distro comes with Python3. > RHEL 8 will switch to Python 3 as the main Python interpreter > (assuming dnf replaces yum, as it did in Fedora a while back). No sign of RHEL 8 anywhere. My guess it will happen in late 2018. What I'm asking myself is why Red Hat isn't adding Python3 to RHEL 7. I was very disappointed when 7.4 didn't have it. Marko From kwpolska at gmail.com Sun Sep 10 05:42:15 2017 From: kwpolska at gmail.com (Chris Warrick) Date: Sun, 10 Sep 2017 11:42:15 +0200 Subject: People choosing Python 3 In-Reply-To: References: <8760crm2mp.fsf@elektro.pacujo.net> Message-ID: On 10 September 2017 at 11:24, Leam Hall wrote: > On 09/10/2017 04:19 AM, Chris Warrick wrote: >> >> On 10 September 2017 at 09:30, Marko Rauhamaa wrote: >>> >>> INADA Naoki : >>> >>>> I can't wait Python 3 is the default Python of Red Hat, and "python" >>>> command means Python 3 on Debian and Ubuntu. >>> >>> >>> I can't wait till Python 3 is available on Red Hat. >> >> >> Python 3.4 is available in EPEL. RHEL 8 will switch to Python 3 as the >> main Python interpreter (assuming dnf replaces yum, as it did in >> Fedora a while back). >> > > I'm not sure that RHEL 8 will be Python 3 for the OS tools. Even if it is, > which version? RHEL?s release process starts at forking a recent Fedora release. It wouldn?t make much sense for them to undo the Python 3 progress that happened over the past few years in Fedora ? including dnf, an improved package manager written in Python 3. If the fork happened today, the base release would be Fedora 26, which includes Python 3.6, and some install options don?t include Python 2. -- Chris Warrick PGP: 5EAAEA16 From skip.montanaro at gmail.com Sun Sep 10 05:45:09 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 10 Sep 2017 04:45:09 -0500 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <87a823m2ss.fsf@elektro.pacujo.net> References: <87a823m2ss.fsf@elektro.pacujo.net> Message-ID: > * asyncio with its a-dialect What is a/the "a-dialect"? S From rustompmody at gmail.com Sun Sep 10 05:49:31 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Sep 2017 02:49:31 -0700 (PDT) Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> Message-ID: On Sunday, September 10, 2017 at 3:15:32 PM UTC+5:30, Skip Montanaro wrote: > > * asyncio with its a-dialect > > What is a/the "a-dialect"? > > S I'd guess its the async/await (semi)keyworded python Compre with the (IMHO) better suggestion for codef/cocall https://lists.gt.net/python/dev/1197316?do=post_view_threaded From rosuav at gmail.com Sun Sep 10 06:01:37 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Sep 2017 20:01:37 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> Message-ID: On Sun, Sep 10, 2017 at 7:45 PM, Skip Montanaro wrote: >> * asyncio with its a-dialect > > What is a/the "a-dialect"? Want to make something iterable? Define __iter__. Want to make it async-iterable (with "async for")? Define __aiter__. It's a bit clunky if you want the same object to be iterable both ways, but I don't know of any real-world situations where that's the case. ChrisA From gheskett at shentel.net Sun Sep 10 06:01:39 2017 From: gheskett at shentel.net (Gene Heskett) Date: Sun, 10 Sep 2017 06:01:39 -0400 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <854lsb87nr.fsf@benfinney.id.au> References: <201709092350.22610.gheskett@shentel.net> <854lsb87nr.fsf@benfinney.id.au> Message-ID: <201709100601.39218.gheskett@shentel.net> On Sunday 10 September 2017 01:06:00 Ben Finney wrote: > Gene Heskett writes: > > On Saturday 09 September 2017 21:48:44 Chris Angelico wrote: > > > The Python Secret Underground emphatically does not exist. > > > > Humm. here all this time I thought you were a charter member. :) > > With all the authority vested in me as a charter member, I can > categorically say the Python Secret Underground does not exist. > Chuckle. But this is far out in the puckerbrush, and I'm out of string for my weed-eater. And we got here in record time. ;-) > -- > \ ?Pinky, are you pondering what I'm pondering?? ?Well, I think > | `\ so, Brain, but first you'd have to take that whole bridge > | _o__) apart, wouldn't you?? ?_Pinky and The > Brain_ | Ben Finney 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 Sun Sep 10 06:08:30 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Sep 2017 13:08:30 +0300 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: (Skip Montanaro's message of "Sun, 10 Sep 2017 04:45:09 -0500") References: <87a823m2ss.fsf@elektro.pacujo.net> Message-ID: <87vakquaqp.fsf@elektro.pacujo.net> Skip Montanaro : >> * asyncio with its a-dialect > > What is a/the "a-dialect"? await async def async for __aiter__ __anext__ async with __aenter__ __aexit__ What's more, when you turn a function into an async, you need to refactor a large part of your program. Marko From leamhall at gmail.com Sun Sep 10 06:21:30 2017 From: leamhall at gmail.com (Leam Hall) Date: Sun, 10 Sep 2017 06:21:30 -0400 Subject: Python in Perspective Message-ID: <75e60eab-a095-812b-bf02-312dbf76b4ca@gmail.com> y'all, My god-kids and their proginators lost most everything because of Harvey. I spent much of yesterday worrying about a friend who had gone quiet as he evacuated his family ahead of Irma. Please keep Python in perspective. Whether we use 1.5 or 4rc1 is a lot less critical than using Python to work together well and solving big problems as friends. In years gone by I spent time on the soapbox but never came away cleaner or with stronger friendships. I just ranted and spent years wondering why nothing actually changed. Please don't make my mistake; come up with your own. Together. As friends. Leam From stephanh42 at gmail.com.invalid Sun Sep 10 06:21:58 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 10 Sep 2017 10:21:58 GMT Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> Message-ID: Op 2017-09-10, Chris Angelico schreef : > Want to make something iterable? Define __iter__. Want to make it > async-iterable (with "async for")? Define __aiter__. It's a bit clunky > if you want the same object to be iterable both ways, but I don't know > of any real-world situations where that's the case. Would we not eventually want a file object to deliver its lines asynchronously (with non-blocking reads under the hood) if iterated over with "async for", while preserving the current blocking behavior in the "for" case? Stephan From gheskett at shentel.net Sun Sep 10 06:24:29 2017 From: gheskett at shentel.net (Gene Heskett) Date: Sun, 10 Sep 2017 06:24:29 -0400 Subject: People choosing Python 3 In-Reply-To: <3026bbec-495b-5451-19f6-d3255ba39307@gmail.com> References: <3026bbec-495b-5451-19f6-d3255ba39307@gmail.com> Message-ID: <201709100624.30239.gheskett@shentel.net> On Sunday 10 September 2017 05:25:51 Leam Hall wrote: > On 09/10/2017 04:19 AM, Chris Warrick wrote: > > On 10 September 2017 at 09:30, Marko Rauhamaa wrote: > >> INADA Naoki : > >>> I can't wait Python 3 is the default Python of Red Hat, and > >>> "python" command means Python 3 on Debian and Ubuntu. > >> > >> I can't wait till Python 3 is available on Red Hat. > > > > Python 3.4 is available in EPEL. RHEL 8 will switch to Python 3 as > > the main Python interpreter (assuming dnf replaces yum, as it did in > > Fedora a while back). > > I'm not sure that RHEL 8 will be Python 3 for the OS tools. Even if it > is, which version? > > From a non-rpm perspective Python 3.6.2 compiles nicely on CentOS 6. > Once compiled it seems easy to use pip3 to install stuff without > trampling on the OS's Python 2 install. > > Just have to make sure your PATH is set right. By putting > /usr/local/bin after /usr/bin I can use "py.test" to run tests under > Python 2 and "pytest" for Python 3. > > Leam But that is contrary to the usual practice, fixed so that stuff built and installed locally, with identical names to the distro's /usr/bin contents, is found first in /usr/local/bin and the newer version is used. That "usual practice" is going to be a very high hill to climb. I personally would never consider it as a solution to this p2 vs p3 problem. > p.s. Sorry Chris, meant to send this to the list. You get it twice. 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 stephanh42 at gmail.com.invalid Sun Sep 10 06:31:54 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 10 Sep 2017 10:31:54 GMT Subject: People choosing Python 3 References: <8760crm2mp.fsf@elektro.pacujo.net> <871snevqwi.fsf@elektro.pacujo.net> Message-ID: Op 2017-09-10, Marko Rauhamaa schreef : > As an application developer, I can't make the customers depend on EPEL. > It's Python2 until the distro comes with Python3. Why not bundle the Python interpreter with your application? It seems to work for Windows developers... Stephan From deavmi at disroot.org Sun Sep 10 07:05:09 2017 From: deavmi at disroot.org (Tristan B. Kildaire) Date: Sun, 10 Sep 2017 13:05:09 +0200 Subject: Python in Perspective References: <75e60eab-a095-812b-bf02-312dbf76b4ca@gmail.com> Message-ID: On 2017-09-10 12:21 PM, Leam Hall wrote: > y'all, > > My god-kids and their proginators lost most everything because of > Harvey. I spent much of yesterday worrying about a friend who had gone > quiet as he evacuated his family ahead of Irma. > > Please keep Python in perspective. Whether we use 1.5 or 4rc1 is a lot > less critical than using Python to work together well and solving big > problems as friends. > > In years gone by I spent time on the soapbox but never came away cleaner > or with stronger friendships. I just ranted and spent years wondering > why nothing actually changed. Please don't make my mistake; come up with > your own. > > Together. As friends. > > Leam I agree. Don't get too caught up in these things. :) Hope all goes well mate and that things get better for you and your reletives and friends. From gerlando.falauto at gmail.com Sun Sep 10 07:40:49 2017 From: gerlando.falauto at gmail.com (gerlando.falauto at gmail.com) Date: Sun, 10 Sep 2017 04:40:49 -0700 (PDT) Subject: array.array()'s memory shared with multiprocessing.Process() In-Reply-To: References: <27b84429-2a3f-4bfd-921e-13ede1f3d383@googlegroups.com> <25368303-5a50-e35a-dbe0-04de800e94f3@mrabarnett.plus.com> Message-ID: <8cfebb15-38db-48ee-9090-8961974ba6e0@googlegroups.com> > > I suspect it's down to timing. > > What you're putting into the queue is a reference to the array, and it's > only some time later that the array itself is pickled and then sent (the > work being done in the 'background'). > > Modifying the array before (or while) it's actually being sent would > explain the problem you're seeing. That would also have been my guess. However, according to documentation: > When an object is put on a queue, the object is pickled and a background > thread later flushes the pickled data to an underlying pipe. In my understanding this means the object is pickled *before* the background thread takes care of flushing the data to the pipe. Is that a mistake in the documentation then? Any suggestion for a way to work around this limitation? Or perhaps a different approach altogether I could use to reduce CPU load? What the main thread actually does is dequeue data from a high-speed USB-to-serial (2.000.000 bps), that's why I came up with the array.array() solution to store collected data, hoping for the smallest possible overhead. Thanks! From marko at pacujo.net Sun Sep 10 08:15:19 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Sep 2017 15:15:19 +0300 Subject: People choosing Python 3 References: <8760crm2mp.fsf@elektro.pacujo.net> <871snevqwi.fsf@elektro.pacujo.net> Message-ID: <87h8wau4vc.fsf@elektro.pacujo.net> Stephan Houben : > Op 2017-09-10, Marko Rauhamaa schreef : >> As an application developer, I can't make the customers depend on EPEL. >> It's Python2 until the distro comes with Python3. > > Why not bundle the Python interpreter with your application? > It seems to work for Windows developers... I've seen that done for Python and other technologies. It is an expensive route to take. Also, it can be insecure. When vulnerabilities are found, they are communicated to the maintainers of, say, Python. When Python is fixed and released, the vulnerability is revealed, but the version bundled with your product is still broken. You have to be prepared perform an emergency release of your product and hope you don't mess things up. Marko From marko at pacujo.net Sun Sep 10 08:33:50 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Sep 2017 15:33:50 +0300 Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> Message-ID: <877ex6u40h.fsf@elektro.pacujo.net> Stephan Houben : > Op 2017-09-10, Chris Angelico schreef : >> Want to make something iterable? Define __iter__. Want to make it >> async-iterable (with "async for")? Define __aiter__. It's a bit clunky >> if you want the same object to be iterable both ways, but I don't know >> of any real-world situations where that's the case. > > Would we not eventually want a file object to deliver its lines > asynchronously (with non-blocking reads under the hood) if > iterated over with "async for", while preserving the current > blocking behavior in the "for" case? I'm not exactly sure what your point is. "async for" is needed to allow a for loop to iterate over a sequence that is generated asynchronously. If you accidentally use a regular "for" (and chances are you will), you will experience weird behavior. As for file objects supporting asynchronous iterators, I agree they should. Linux is not quite ready for nonblocking file access yet (the kernel developers are busy trying to make it happen). Note that you will not only need an async version of a file iterator but also versions for the "open()" function, directory walking etc. Marko From mohmmedmohmmedalagmyabdalrhman at gmail.com Sun Sep 10 09:18:51 2017 From: mohmmedmohmmedalagmyabdalrhman at gmail.com (mohmmedmohmmedalagmyabdalrhman at gmail.com) Date: Sun, 10 Sep 2017 06:18:51 -0700 (PDT) Subject: =?UTF-8?B?2KfZitis2Ykg2YjZiNix2YTYrw==?= Message-ID: <02750fa1-6259-426c-80b0-af4d8a726bb0@googlegroups.com> ???? ????? http://egyworld.bid From breamoreboy at gmail.com Sun Sep 10 09:36:51 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sun, 10 Sep 2017 06:36:51 -0700 (PDT) Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <201709092350.22610.gheskett@shentel.net> <854lsb87nr.fsf@benfinney.id.au> Message-ID: <642ac807-4d4b-4459-b5da-d388c0e66142@googlegroups.com> On Sunday, September 10, 2017 at 6:07:00 AM UTC+1, Ben Finney wrote: > Gene Heskett writes: > > > On Saturday 09 September 2017 21:48:44 Chris Angelico wrote: > > > > > The Python Secret Underground emphatically does not exist. > > > > Humm. here all this time I thought you were a charter member. :) > > With all the authority vested in me as a charter member, I can > categorically say the Python Secret Underground does not exist. > > -- > \ ?Pinky, are you pondering what I'm pondering?? ?Well, I think | > `\ so, Brain, but first you'd have to take that whole bridge | > _o__) apart, wouldn't you?? ?_Pinky and The Brain_ | > Ben Finney How has Python managed world domination without the aid of Pinky and the Brain? -- Kindest regards. Mark Lawrence. From ian.g.kelly at gmail.com Sun Sep 10 09:59:35 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 10 Sep 2017 07:59:35 -0600 Subject: Using Python 2 In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> Message-ID: On Sat, Sep 9, 2017 at 9:26 PM, Rick Johnson wrote: > On Friday, September 8, 2017 at 8:57:56 AM UTC-5, Ned Batchelder wrote: >> On 9/8/17 6:12 AM, Leam Hall wrote: >> > I've read comments about Python 3 moving from the Zen of Python. I'm a >> > "plain and simple" person myself. Complexity to support what CompSci >> > folks want, which was used to describe some of the Python 3 changes, >> > doesn't help me get work done. >> >> I've heard a lot of FUD about the Python 3 transition, but this one is >> new to me. What is it that CompSci folks want that developers don't >> want, that ruined Python 3? > > TWO WORDS: "Type" and "Hints" Fail. 1. Type hints were only added in 3.5, not Python 3.0, so this does not support the claim that Python 3 changes were made to support CS. 2. Type hints are completely optional, so this does not support the claim that Python 3 added complexity that is counter-productive to "simple" users. If you want to keep your program simple, you can: just don't use them. 3. Type hints are practical. You may not need or desire them for pet projects, but large-scale projects with a large team of developers require a large degree of testing. Static typing supports this. This is a feature for enterprise users, not theorists. From rosuav at gmail.com Sun Sep 10 10:08:02 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Sep 2017 00:08:02 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <87vakquaqp.fsf@elektro.pacujo.net> References: <87a823m2ss.fsf@elektro.pacujo.net> <87vakquaqp.fsf@elektro.pacujo.net> Message-ID: On Sun, Sep 10, 2017 at 8:08 PM, Marko Rauhamaa wrote: > Skip Montanaro : > >>> * asyncio with its a-dialect >> >> What is a/the "a-dialect"? > > What's more, when you turn a function into an async, you need to > refactor a large part of your program. That's not Python-specific. If you're going to change your program from single-threaded single-process synchronous to any of multi-threaded, multi-process, or asynchronous (all of which involve multiple pieces running concurrently or interleaved), you have to build your program with that in mind. It's best NOT to try to convert, but to build it that way from the start. Give threaded socket servers a try - you'll learn a lot. It's really not hard. ChrisA From storchaka at gmail.com Sun Sep 10 10:25:43 2017 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sun, 10 Sep 2017 17:25:43 +0300 Subject: Python programming language vulnerabilities In-Reply-To: <9573BEFB-B5EB-4814-8C8D-AF18C7DB8BD3@maurya.on.ca> References: <9573BEFB-B5EB-4814-8C8D-AF18C7DB8BD3@maurya.on.ca> Message-ID: 08.09.17 20:34, Stephen Michell ????: > I chair ISO/IEC/JTC1/SC22/WG23 Programming Language Vulnerabilities. We publish an international technical report, ISO IEC TR 24772 Guide to avoiding programming language vulnerabilities through language selection use. Annex D in this document addresses vulnerabilities in Python. This document is freely available from ISO and IEC. > > We are updating this technical report, adding a few vulnerabilities and updating language applicability as programming languages evolve. We are also subdividing the document by making the language-specific annexes each their own technical report. For the Python Part, the major portions are written, but we have about 6 potential vulnerabilities left to complete. > > We need help in finishing the Python TR. We are looking for a few Python experts that have experience in implementing Python language systems, or experts in implementing significant systems in Python (for technical level, persons that provide technical supervision to implementers, or that write and maintain organizational Python coding standards. Any links? There are a lot of documents on http://www.open-std.org/JTC1/SC22/WG23/docs/documents, but some links are dead, and I have no found Annex D in http://www.open-std.org/JTC1/SC22/WG23/docs/ISO-IECJTC1-SC22-WG23_N0742-tr24772-1-after-meeting-50-20170817.pdf. Maybe https://python-security.readthedocs.io/ can be useful to you. From rantingrickjohnson at gmail.com Sun Sep 10 10:46:28 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Sep 2017 07:46:28 -0700 (PDT) Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> Message-ID: <3dc36af4-a609-40b9-9250-230df93a9685@googlegroups.com> Chris Angelico wrote: > Marko Rauhamaa wrote: [...] > > The clouds I see looming over Python's head are: > > > > * 2-to-3 migration > > If that was going to kill Python, it would have had some > impact by now. There are students learning Python *today* > who are never going to have to worry about the migration, > because they're learning Python 3. > > > * static type annotation > > I'm not seeing very much of this in the wild yet, but > honestly, it's not that big a deal. You can ignore it if > you want to. Kinda difficult to ignore type annotations when they are intermixed with the code! I never really had a problem with the idea of Python having type-hints, so long as the ugly annotations were kept _separated_ from the .py[w] files, but for some reason, the devs decided that mucking up Python's clean syntax for the sake of (what you claim is) a small minority of type-hint fanboys, was okay... The fanboys of type-hints claim that we will never (or hardly ever) see these annotations in the wild, but again, if that is the case, *IF* usage of this feature is really that rare, then why should it be given such power to undermine the readability of Python code? It is not too late! We are still in the very early stages of type-hints, and we can undo the damage that this "feature" will cause if we remove the hints from the .py[w] files entirely. Let the burden be on those who want this feature, not on those who don't want it. Futhermore, if we consider the damage that small changes (like the print statement versus print function and raw_input versus input) have caused, how can we expect (short of a self delusion) that type-hints will have no negative effects? There is one aspect of the internet that will never change, namely: persistance, and from now, and until Python disappears from the universe, there will always be a need to explain why `print` was changed from a statement to a function, along with an explanation of the subtle differences between python2's raw_input() and input() versus Python3's input(), not to mention the age old ramblings about classic classes versus new classes. And as much as we'd all like for these confusions to go away, they won't, because there is no way to "clean" the internet of every Python2 tutorial, blog or website that mentions these bygone features. The stain of Python3's violent and radical changes to the core philosophy of the language may never be washed clean, and although we might have survived Python3 _eventually_, type-hints is like a wooden stake driven into the heart of this community. It's almost like they _want_ to destroy this language. From marko at pacujo.net Sun Sep 10 11:20:25 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Sep 2017 18:20:25 +0300 Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> Message-ID: <87tw0asiis.fsf@elektro.pacujo.net> Ian Kelly : > 2. Type hints are completely optional, so this does not support the > claim that Python 3 added complexity that is counter-productive to > "simple" users. If you want to keep your program simple, you can: just > don't use them. We'll see about that. I'm afraid type hints will become ubiquitous and turn Python into another Java. > 3. Type hints are practical. You may not need or desire them for pet > projects, but large-scale projects with a large team of developers > require a large degree of testing. Static typing supports this. This > is a feature for enterprise users, not theorists. Ah, the *enterprise*, where the holy grail is to guarantee that junior programmers can't make mistakes. Been there. I'm afraid this is not a joke: Python, COBOL for the next generation. Marko From marko at pacujo.net Sun Sep 10 11:20:36 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Sep 2017 18:20:36 +0300 Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> <87vakquaqp.fsf@elektro.pacujo.net> Message-ID: <87y3pmsiua.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Sep 10, 2017 at 8:08 PM, Marko Rauhamaa wrote: >> What's more, when you turn a function into an async, you need to >> refactor a large part of your program. > > That's not Python-specific. If you're going to change your program > from single-threaded single-process synchronous to any of > multi-threaded, multi-process, or asynchronous (all of which involve > multiple pieces running concurrently or interleaved), you have to > build your program with that in mind. It's best NOT to try to convert, > but to build it that way from the start. Give threaded socket servers > a try - you'll learn a lot. It's really not hard. It's not Python-specific but it *is* async-specific. Multithreading, multiprocessing and callback hell don't result in similar cascading effects. Even otherwise, I'm not at all convinced by the whole coroutine concept. Marko From rantingrickjohnson at gmail.com Sun Sep 10 11:40:11 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Sep 2017 08:40:11 -0700 (PDT) Subject: Using Python 2 In-Reply-To: <59b4cc62$0$16757$b1db1813$d948b532@news.astraweb.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <878thpjr8t.fsf@elektro.pacujo.net> <276e8910-6128-419b-b262-d0152053d752@googlegroups.com> <59b4cc62$0$16757$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > Rick Johnson wrote: > > Marko Rauhamaa wrote: > > > > > > The risk to Python will be whether the occasion is > > > exploited by fanboys of competing programming languages. > > > The migration from Python 2 might be to something else > > > than Python 3 in some circles. > > > > That has been my observation as well. > > It certainly has been. I still remember your panicked, "the > sky is falling" posts terrified that unless we re-defined > Python to your specifications, the entire Python community > would rush to Ruby. You exaggerate. I do remember waging a "PyWarts" campaign some years back, but those posts were an appeal to remedy _real_ problems i discovered in a few specific stdlib modules, namely: IDLE, Tkinter, re, os.path, zipfile, tarfile, and possibly others i have since forgotten about... > That was, oh, ten or twelve years ago, if I remember > correctly. How did that prediction work out for you? Well, i would say that when i first arrived on the "python scene" (roughy about the time Python3 was released, possibly a year or two before), the community was (thanks to the maturity and stability of Python2) far more cohesive and vibrant. Since then, we have been hemorrhaging python loyalist and the core devs have become evermore isolated from the broader community, even clannish. If you remember, that was back in the naive days when the TIOBE index was all the rage. Heck, when is the last time GvR participated in any discussion outside the hermetic bubble of Python-Dev or Python-Ideas? Certainly he has not bothered to participate in any fashion on this open forum, and perhaps, many of the posts here are not worthy of his time, but some certainly are. Such behavior leads many of us to believe that we are second class citizens. OTOH, in one of the few occasions that i participated in the Ruby forums, Yukihiro "Matz" Matsumoto responded positively to one of my posts (which i believe, but i may have misremembered, was an appeal for consistency of function call syntax, as Ruby allowed the parenthesis to be omitted when no arguments were passed, naturally, i prefered consistency, and Matz agreed. And the fact that he took the time to respond to a lurker proved that he is a man of the people, which sadly, is not the case for "our dear leader". From rantingrickjohnson at gmail.com Sun Sep 10 12:06:39 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Sep 2017 09:06:39 -0700 (PDT) Subject: Using Python 2 In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> Message-ID: <714cbdab-42b4-4601-b961-a8c804ef0821@googlegroups.com> Ian wrote: > Rick Johnson wrote: > > Ned Batchelder wrote: > > > Leam Hall wrote: > > > > > > > > I've read comments about Python 3 moving from the Zen of > > > > Python. I'm a "plain and simple" person myself. > > > > Complexity to support what CompSci folks want, which was > > > > used to describe some of the Python 3 changes, doesn't > > > > help me get work done. > > > > > > I've heard a lot of FUD about the Python 3 transition, > > > but this one is new to me. What is it that CompSci folks > > > want that developers don't want, that ruined Python 3? > > > > TWO WORDS: "Type" and "Hints" > > Fail. > > 1. Type hints were only added in 3.5, not Python 3.0, so > this does not support the claim that Python 3 changes were > made to support CS. But it is true that CS purist want type annotations while 99% of the everyday Python programmers can live happily without them. "Practicality beats purity". > 2. Type hints are completely optional, so this does not > support the claim that Python 3 added complexity that is > counter-productive to "simple" users. If you want to keep > your program simple, you can: just don't use them. True, individual programmers can choose to omit type-hints from their own code, but they cannot choose to omit type- hints from the code they are forced to read. Once type annotations start propagating in the wild, the syntactical noise of statically typed languages will be ever-present in Python code, only problem is, we will get *NONE* of the advantages of _real_ statically typed languages, namely: executables, compiler optimizations, and enhanced execution speed. Heck, all we get in return for our painful eyeball parsings are (maybe) better linters. Which is not an ROI worthy of my sweat equity. > 3. Type hints are practical. You may not need or desire > them for pet projects, but large-scale projects with a > large team of developers require a large degree of testing. > Static typing supports this. This is a feature for > enterprise users, not theorists. I was never against Python having a type annotation feature, no, i am only against the inclusion of this syntacticly noisy feature in the .py[w] files. Mandating that type annotations be defined in _external_ stub files places the onerous on those who care about type annotations (a micro minority of CS purist), and removes it from those who don't (the remaining majority of Python programmers). I'm telling you, we can still prevent this feature from destroying the language, *IF* we act quickly. From rantingrickjohnson at gmail.com Sun Sep 10 12:39:09 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Sep 2017 09:39:09 -0700 (PDT) Subject: Run Windows commands from Python console In-Reply-To: References: <83ebc433-d457-408b-b43a-4b00a3206728@googlegroups.com> <290ec6d2-81d9-4bf4-b641-fc8568578555@googlegroups.com> <7515e893-b1c7-42ff-926d-e482e1eca9ae@googlegroups.com> Message-ID: <44d79423-bb42-4f8d-9d08-07f77a9a16c7@googlegroups.com> Stephan Houben wrote: > Rick Johnson schreef: > > > One of the nice (current) features of Tkinter menus (that > > i sometimes miss on my windows box!) is the ability to > > "tear- off" a menu cascade and use it as a sort of "pseudo > > tool bar". > > I was under the impression that Tk also supported tear-off > menus under Windows (but not under macOS). And it does. I was only complaining that the Microsoft Windows GUI does not have this feature, not that it is unavailable on Windows + Python + Tkinter. Sorry for the confusion. > However, many applications apparently explicitly suppress > this functionality by doing > > Menu(..., tearoff=0) Yes, which is unfortunate, as the decision should be made by the enduser, not the dev. I myself have been guilty of suppressing this feature in my own applications, which is evidence that these usability features should bypass the developer entirely, and be controlled exclusively by the end user. We devs have a tendency to think that we know what is best for our users (*cough* pydev!), but even modest experience with modern software would prove that assertion to be wrong. It seems to me the best solution is for the TCL/Tk folks to provide a configuration utility that stores user preferences in the registry, or some other OS provided mechanism, as to have these settings reset on every invocation of the application would be inefficient from an enduser perspective. I suppose we could implement such a configuration utility exclusively for Tkinter, if we wanted, and perhaps it would serve as a model for the Tk folks... From python at mrabarnett.plus.com Sun Sep 10 12:39:11 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 10 Sep 2017 17:39:11 +0100 Subject: Python in Perspective In-Reply-To: <75e60eab-a095-812b-bf02-312dbf76b4ca@gmail.com> References: <75e60eab-a095-812b-bf02-312dbf76b4ca@gmail.com> Message-ID: <7ba1491d-d524-47f8-5ef7-2031e73cfe7c@mrabarnett.plus.com> On 2017-09-10 11:21, Leam Hall wrote: > y'all, > > My god-kids and their proginators lost most everything because of > Harvey. I spent much of yesterday worrying about a friend who had gone > quiet as he evacuated his family ahead of Irma. > > Please keep Python in perspective. Whether we use 1.5 or 4rc1 is a lot > less critical than using Python to work together well and solving big > problems as friends. > > In years gone by I spent time on the soapbox but never came away cleaner > or with stronger friendships. I just ranted and spent years wondering > why nothing actually changed. Please don't make my mistake; come up with > your own. > > Together. As friends. > > Leam > That reminds me of this quote about football (soccer): "Some people think football is a matter of life and death. I assure you, it's much more serious than that." - Bill Shankly From python at mrabarnett.plus.com Sun Sep 10 12:53:13 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 10 Sep 2017 17:53:13 +0100 Subject: array.array()'s memory shared with multiprocessing.Process() In-Reply-To: <8cfebb15-38db-48ee-9090-8961974ba6e0@googlegroups.com> References: <27b84429-2a3f-4bfd-921e-13ede1f3d383@googlegroups.com> <25368303-5a50-e35a-dbe0-04de800e94f3@mrabarnett.plus.com> <8cfebb15-38db-48ee-9090-8961974ba6e0@googlegroups.com> Message-ID: <5fb8977c-e0e3-7d95-6d23-ba133806500f@mrabarnett.plus.com> On 2017-09-10 12:40, gerlando.falauto at gmail.com wrote: >> >> I suspect it's down to timing. >> >> What you're putting into the queue is a reference to the array, and it's >> only some time later that the array itself is pickled and then sent (the >> work being done in the 'background'). >> >> Modifying the array before (or while) it's actually being sent would >> explain the problem you're seeing. > > That would also have been my guess. However, according to documentation: > >> When an object is put on a queue, the object is pickled and a background >> thread later flushes the pickled data to an underlying pipe. > > In my understanding this means the object is pickled *before* the background thread takes care of flushing the data to the pipe. Is that a mistake in the documentation then? > > Any suggestion for a way to work around this limitation? > Or perhaps a different approach altogether I could use to reduce CPU load? > What the main thread actually does is dequeue data from a high-speed USB-to-serial (2.000.000 bps), that's why I came up with the array.array() solution to store collected data, hoping for the smallest possible overhead. > Thanks! > I've had a quick look at the source code. When an object is put into the queue, it's actually put into an internal buffer (a deque), and then the method returns. An internal thread works through the buffer and pickles the objects. Therefore, just because the method has returned, it doesn't mean that it's now safe to modify the object. From marko at pacujo.net Sun Sep 10 13:14:05 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 10 Sep 2017 20:14:05 +0300 Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> <87vakquaqp.fsf@elektro.pacujo.net> <87y3pmsiua.fsf@elektro.pacujo.net> Message-ID: <87wp56qxwi.fsf@elektro.pacujo.net> Dennis Lee Bieber : > In contrast, every sample I've seen of the async library comes > across as "magic happens here -- at some point in time". That magic can be learned, in principle. I'm afraid few programmers will be willing/able to get over the hump, and there are a number of tricky aspects to be extra careful about. The situation *did* get significantly better with "async" replacing "@coroutine" and "await" replacing "yield from". However, it is easy to accidentally forget to place the "await" keyword where it belongs and quite a bit of troubleshooting can go into locating the mistake because the faulty program runs without an (immediate) exception. Marko From ned at nedbatchelder.com Sun Sep 10 13:36:13 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 10 Sep 2017 13:36:13 -0400 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <3dc36af4-a609-40b9-9250-230df93a9685@googlegroups.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <3dc36af4-a609-40b9-9250-230df93a9685@googlegroups.com> Message-ID: <3a2172af-43b8-d7e4-f968-9e01f69ac670@nedbatchelder.com> On 9/10/17 10:46 AM, Rick Johnson wrote: > The stain of Python3's violent and radical changes to the > core philosophy of the language may never be washed clean, > and although we might have survived Python3 _eventually_, > type-hints is like a wooden stake driven into the heart of > this community. It's almost like they _want_ to destroy this > language. Given the recent Stack Overflow blog post about Python's accelerating growth, and TIOBE rating it #1, you'd think the sky-is-falling doom-sayers would get tired of being wrong all the time. I guess not. --Ned. From irmen.NOSPAM at xs4all.nl Sun Sep 10 14:07:02 2017 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 10 Sep 2017 20:07:02 +0200 Subject: v2.0 released of: a Boulder Dash clone with retro graphics and sound In-Reply-To: <59b065dd$0$824$e4fe514c@news.xs4all.nl> References: <59adcd89$0$806$e4fe514c@news.xs4all.nl> <59b065dd$0$824$e4fe514c@news.xs4all.nl> Message-ID: <59b57f47$0$808$e4fe514c@news.xs4all.nl> On 06/09/2017 23:17, Irmen de Jong wrote: > > https://github.com/irmen/bouldercaves > My Boulder Dash clone is now at version 2.0 because a few important things that were lacking are now implemented: * authentic mode: The game is now displayed in a small screen that scrolls smoothly over the level, like the original game. It also has the retro c-64 color palette enabled. You enable this via a command line option. * pre-recorded demo: If you press F9 or wait a while at the title screen, the game plays back a prerecorded demo of cave A, like the original game. * synthesized sounds: Instead of using sampled sounds you can now run the game with a software sound synthesizer that creates the sounds in real time, including the title music. I've tried to simulate the sounds of the original game but ended up with slightly different ones. Maybe I'll tweak the synth to make them closer to the original, but there's a charm to the variation as well I think. All in all I am very pleased with the results. I didn't expect it to be possible creating a decently performing arcade game using just the bare essentials: - default tkinter to draw everything on the screen - pillow to load images - sounddevice to play sounds (optional). I posted this update because I now consider it a full game [1] and I think it's interesting to see that this can be realized in Python without any of the specialized 'game libraries' (pygame, etc) being used. While tkinter sometimes has troubles updating the screen at 30 hz, the Python code itself is barely breaking a sweat, even the sound synth. Have fun Irmen de Jong [1] full game: errr... there's still no highscore table. Sorry :) From leamhall at gmail.com Sun Sep 10 14:14:12 2017 From: leamhall at gmail.com (leam hall) Date: Sun, 10 Sep 2017 14:14:12 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> Message-ID: I will add my +1 to the careful editing of code. Python's use of white space is pretty good once you get used to it. My Ruby code looks a lot like my Python code. :) Leam From Stephen.Michell at maurya.on.ca Sun Sep 10 14:45:43 2017 From: Stephen.Michell at maurya.on.ca (Stephen Michell) Date: Sun, 10 Sep 2017 14:45:43 -0400 Subject: Python programming language vulnerabilities Message-ID: <0E9A606A-C786-4F12-A35F-5649054C9128@maurya.on.ca> My apologies. I maintain that website. There should have been no broken links. I will fix that. The previous version of TR 24772 had annexes for language-specific material. We have split those out, so the main document (Tr 24772-1) only has language independent material. The last Python document is N0702 at open-std.org/sc22/wg23//docs/documents.html. This document was one that Serihy could not access. That link is fixed, so it can be accessed now. From gerlando.falauto at gmail.com Sun Sep 10 17:05:22 2017 From: gerlando.falauto at gmail.com (iurly) Date: Sun, 10 Sep 2017 14:05:22 -0700 (PDT) Subject: array.array()'s memory shared with multiprocessing.Process() In-Reply-To: References: <27b84429-2a3f-4bfd-921e-13ede1f3d383@googlegroups.com> <25368303-5a50-e35a-dbe0-04de800e94f3@mrabarnett.plus.com> <8cfebb15-38db-48ee-9090-8961974ba6e0@googlegroups.com> <5fb8977c-e0e3-7d95-6d23-ba133806500f@mrabarnett.plus.com> Message-ID: <03ac60ca-4906-48aa-b6e8-8c5913dcfe19@googlegroups.com> Il giorno domenica 10 settembre 2017 18:53:33 UTC+2, MRAB ha scritto: > On 2017-09-10 12:40, gerlando.falauto at gmail.com wrote: > >> > >> I suspect it's down to timing. > >> > >> What you're putting into the queue is a reference to the array, and it's > >> only some time later that the array itself is pickled and then sent (the > >> work being done in the 'background'). > >> > >> Modifying the array before (or while) it's actually being sent would > >> explain the problem you're seeing. > > > > That would also have been my guess. However, according to documentation: > > > >> When an object is put on a queue, the object is pickled and a background > >> thread later flushes the pickled data to an underlying pipe. > > > > In my understanding this means the object is pickled *before* the background thread takes care of flushing the data to the pipe. Is that a mistake in the documentation then? > > > > Any suggestion for a way to work around this limitation? > > Or perhaps a different approach altogether I could use to reduce CPU load? > > What the main thread actually does is dequeue data from a high-speed USB-to-serial (2.000.000 bps), that's why I came up with the array.array() solution to store collected data, hoping for the smallest possible overhead. > > Thanks! > > > I've had a quick look at the source code. > > When an object is put into the queue, it's actually put into an internal > buffer (a deque), and then the method returns. > > An internal thread works through the buffer and pickles the objects. > > Therefore, just because the method has returned, it doesn't mean that > it's now safe to modify the object. I see. So that explains everything. However, I wonder if that's the intended behavior and/or that should be documented somehow. As far as I'm concerned, I'm probably better off using double buffers to avoid this kind of issues. Thanks a lot for your help! From skip.montanaro at gmail.com Sun Sep 10 17:14:16 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 10 Sep 2017 16:14:16 -0500 Subject: Python programming language vulnerabilities In-Reply-To: <0E9A606A-C786-4F12-A35F-5649054C9128@maurya.on.ca> References: <0E9A606A-C786-4F12-A35F-5649054C9128@maurya.on.ca> Message-ID: That link's not working for me, even after changing the double slash to a single slash. Skip On Sun, Sep 10, 2017 at 1:45 PM, Stephen Michell wrote: > My apologies. I maintain that website. > > There should have been no broken links. I will fix that. > > The previous version of TR 24772 had annexes for language-specific material. We have split those out, so the main document (Tr 24772-1) only has language independent material. The last Python document is N0702 at open-std.org/sc22/wg23//docs/documents.html. This document was one that Serihy could not access. That link is fixed, so it can be accessed now. > > > -- > https://mail.python.org/mailman/listinfo/python-list From skip.montanaro at gmail.com Sun Sep 10 17:18:08 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 10 Sep 2017 16:18:08 -0500 Subject: Python programming language vulnerabilities In-Reply-To: References: <0E9A606A-C786-4F12-A35F-5649054C9128@maurya.on.ca> Message-ID: These links work: * http://open-std.org/JTC1/SC22/WG23/docs/ISO-IECJTC1-SC22-WG23_N0702-tr24772-4-draft-python-before-mtg-48-2017-03-10.pdf * http://open-std.org/JTC1/SC22/WG23/docs/ISO-IECJTC1-SC22-WG23_N0702-tr24772-4-draft-python-before-mtg-48-2017-03-10.docx Skip On Sun, Sep 10, 2017 at 4:14 PM, Skip Montanaro wrote: > That link's not working for me, even after changing the double slash > to a single slash. > > Skip > > On Sun, Sep 10, 2017 at 1:45 PM, Stephen Michell > wrote: >> My apologies. I maintain that website. >> >> There should have been no broken links. I will fix that. >> >> The previous version of TR 24772 had annexes for language-specific material. We have split those out, so the main document (Tr 24772-1) only has language independent material. The last Python document is N0702 at open-std.org/sc22/wg23//docs/documents.html. This document was one that Serihy could not access. That link is fixed, so it can be accessed now. >> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list From greg.ewing at canterbury.ac.nz Sun Sep 10 19:54:22 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 11 Sep 2017 11:54:22 +1200 Subject: Using Python 2 In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <878thpjr8t.fsf@elektro.pacujo.net> <276e8910-6128-419b-b262-d0152053d752@googlegroups.com> <59b4cc62$0$16757$b1db1813$d948b532@news.astraweb.com> Message-ID: Rick Johnson wrote: > Heck, when is the last time GvR participated in any > discussion outside the hermetic bubble of Python-Dev or > Python-Ideas? I'd hardly call python-ideas "hermetic". Anyone is free to post there and participate in discussions. Python-dev is open to anyone too, the only difference is that python-dev intended for things that are actually being worked on, whereas python-ideas is for any idea that may or may not come to fruition. If you want to interact with Guido, you need to go to a list he frequents. You can't expect him to personally reply to every issue on every python-related list and group. That would be more than a full-time job for anyone. -- Greg From rantingrickjohnson at gmail.com Sun Sep 10 19:56:35 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Sep 2017 16:56:35 -0700 (PDT) Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> <3dc36af4-a609-40b9-9250-230df93a9685@googlegroups.com> <3a2172af-43b8-d7e4-f968-9e01f69ac670@nedbatchelder.com> Message-ID: <661a67c9-b98a-4471-9b95-24501ca1e207@googlegroups.com> On Sunday, September 10, 2017 at 12:36:52 PM UTC-5, Ned Batchelder wrote: > On 9/10/17 10:46 AM, Rick Johnson wrote: > > The stain of Python3's violent and radical changes to the > > core philosophy of the language may never be washed clean, > > and although we might have survived Python3 _eventually_, > > type-hints is like a wooden stake driven into the heart of > > this community. It's almost like they _want_ to destroy > > this language. > > Given the recent Stack Overflow blog post about Python's > accelerating growth, and TIOBE rating it #1, you'd think > the sky-is-falling doom-sayers would get tired of being > wrong all the time. You mean the same TIOBE index[1] that ranks programming languages based on search engine queries? You mean the same TIOBE index[2] that currently ranks Python as 5th in 2017; 7th in 2012; 6th in 2007; 11th in 2002; and 27th in 1997? Hey, when you're at the bottom, the only direction you can go is up! When has Python ever been #1 on the TIOBE index? It is Java who has reigned supreme! TIOBE is junk science, and sorry to burst your bubble, but Stack Overflow blog posts are just opinion pieces. In fact, it seems the most informative part of the article can be found in the comment section, and in a single paragraph, a bright lad outlines the dangers of picking low hanging fruit from statistical fairy trees: """ An interesting analysis, but one problem with statistical analysis is assigning a causation to a correlation. So, the correlation is one of number of views. The causation assumption is because of the number of users. However, there are other potential causation theories, such as lack of documentation, inexperience of users/viewers, source of viewership (e.g. students versus professionals), etc.""" -- Sid1138 So the "request for help" has more to do with noobs than actual usage, and while Python may indeed be "popular", and yes, that "popularity" has risen significantly over the last few decades, we must ask ourselves: what group is Python most popular with? If the answer is first year CS students, then Python is merely an incidental rung on the ascension up an academic ladder, soon to be forgotten in the professional lives of these CS students, and replaced by the more enterprise friendly langauges of Java and/or C. Python (at least historically) was a great introductory language because of the clean syntax and the batteries included stdlib, which spared first year students the misery of abstract syntaxes, rigid structural orthodoxy, and tyrannical purist methodologies of more asinine languages. And while many of us here share a great fondness for the Python language, we must not delude ourselves into thinking that Python is going to be some "new wave of the future". Python is a toy language that is great for teaching, and loads of fun to write, but it'll never compete at an enterprise level with long established languages like Java or C. And if the Grand Poobah believes that type-hints will magically elevate the highly dynamic Python to enterprise level, urm, well, then... as my good friend Nietzsche informs me, a confrontation with the absurd may be in his near future. The future belongs to compiled, statically typed languages who combine the low level necessities with the higher level practicalities. The Go language is a step in that direction, but with such an abysmal stdlib, it has yet to "go" very far. [1] https://en.wikipedia.org/wiki/TIOBE_index [2] https://www.tiobe.com/tiobe-index/ From leamhall at gmail.com Sun Sep 10 20:16:18 2017 From: leamhall at gmail.com (Leam Hall) Date: Sun, 10 Sep 2017 20:16:18 -0400 Subject: Design: method in class or general function? In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> Message-ID: On 09/08/2017 03:06 AM, Peter Otten wrote: > leam hall wrote: > >> On Thu, Sep 7, 2017 at 8:16 AM, Steve D'Aprano >> wrote: >> >>> On Thu, 7 Sep 2017 07:20 pm, Leam Hall wrote: >>> >>>> OOP newbie on Python 2.6. >>> >>> Python 2.6 is ancient, and is missing many nice features. You should >>> consider >>> using the latest version, 3.6. >>> >> >> I've wrestled with that discussion for a while and Python 3 loses every >> time. There's literally no good reason for me to move to Python 3 earlier >> than mid-2020's. Please accept the fact that there are hundreds of >> thousands of servers, if not millions, running Python 2.x. Whether or not >> Python 3 has any neat cool stuff is irrelevant to those of us seeking to >> use Python to get today's work done. >> >>> I create instances of Character class with an attribute dict of >>>> 'skills'. The 'skills' dict has the name of a skill as the key and an >>>> int as a value. The code adds or modifies skills before outputting the >>>> Character. >>>> >>>> Is it better design to have a Character.method that takes a 'skill' key >>>> and optional value or to have a general function that takes an >>>> instance, a dict, a key, and an optional value? >>> >>> I'm afraid your example is too generic for me to give an opinion. Do you >>> literally mean a method called "method"? What does it do? >>> >> >> >> Using this: >> https://github.com/makhidkarun/py_tools/blob/master/lib/character.py >> >> Line 19 sets "self.skills" either from the passed in data or from >> https://github.com/makhidkarun/py_tools/blob/master/lib/character_tools.py >> #L34-L48 >> >> So Character.skills is a dict with a string key and an int value. I need >> to be able to add skills and my first attempt is a function: >> https://github.com/makhidkarun/py_tools/blob/master/lib/character_tools.py >> #L52-L56 >> >> Should the "add_skills" function be a method in the character class or be >> made a more generic function to add/modify a key/value pair in a dict that >> is an attribute of an instance? Other tasks will require the add/modify >> functionality but coding that increases complexity. At least for me, >> anyway. >> >> Sorry about being unclear earlier, coffee was still kicking in and I'm >> still a newbie that mixes up terms. > > I'm pleading "method" as it allows per-class implementation. > > Say you use per-career subclasses of a general Character class. There are > default per-career skill sets, but usually a Character can acquire a skill > that is not needed in his career -- with the exception that Rogues cannot > tap dance ;) > > Below is a way to implement that with a specialised add_skill() method: > > $ cat basic_oo.py > from __future__ import print_function > import random > from collections import defaultdict > > > class Character(object): > DEFAULT_SKILLS = ['Blade', 'GunCbt', 'Admin', 'Streetwise'] > > def __init__(self): > self.skills = defaultdict(int) > > def add_random_skills(self, terms): > skillnames = self.DEFAULT_SKILLS > for _ in range(2*terms): > self.add_skill(random.choice(skillnames)) > > def add_skill(self, name, amount=1): > self.skills[name] += amount > > def __str__(self): > skills = ", ".join( > "{}={}".format(name, amount) > for name, amount in sorted(self.skills.items()) > if amount != 0 > ) > return "{}({})".format(self.__class__.__name__, skills) > > > class Rogue(Character): > def add_skill(self, name, amount=1): > if name == "TapDance": > raise ValueError("Sorry, this rogue will never tap dance") > super(Rogue, self).add_skill(name, amount) > > > class Marine(Character): > DEFAULT_SKILLS = ['GunCbt', 'VaccSuit', 'Leadership', 'Vehicle'] > > > def main(): > NUM_CHARACTERS = 5 > CHARACTERS = [Marine, Rogue] > > characters = [ > random.choice(CHARACTERS)() for _ in range(NUM_CHARACTERS) > ] > > for c in characters: > c.add_random_skills(5) > c.add_skill("RepairBicycles", random.randrange(3)) > try: > c.add_skill("TapDance", 3) > except ValueError as err: > print(err) > > for c in characters: > print(c) > > > if __name__ == "__main__": > main() > > $ python basic_oo.py > Sorry, this rogue will never tap dance > Sorry, this rogue will never tap dance > Sorry, this rogue will never tap dance > Rogue(Admin=3, Blade=4, GunCbt=2, Streetwise=1) > Marine(GunCbt=5, Leadership=4, TapDance=3, VaccSuit=1) > Rogue(Blade=3, GunCbt=2, RepairBicycles=2, Streetwise=5) > Rogue(Admin=1, Blade=2, GunCbt=5, RepairBicycles=1, Streetwise=2) > Marine(GunCbt=1, Leadership=3, RepairBicycles=2, TapDance=3, VaccSuit=2, > Vehicle=4) Okay Peter, I took your idea and mangled it beyond recognition. There's a design constraint I hadn't mentioned: an instance of Character should be able to have multiple careers. Also, an instance can be created from scratch, created from a full set of data, or created from a partial set of data. Here's my current code, focusing on creating a lot of merchants: https://github.com/makhidkarun/py_tools/blob/merchant/lib/character.py#L60-L61 python chargen.py Toby Verstraeten 564775 [M] Age: 41 Merchant (5 terms) Computer-2 Engineering-5 Navigation-2 Pilot-1 Captain Ian Domici 789987 [M] Age: 24 Firster (3 terms) Merchant (3 terms) Noble (2 terms) Broker-2 GunCbt-1 Streetwise-2 Rosa 66495B [F] Age: 24 Merchant (1 terms) Computer-1 Navigation-1 As you can see, lots to work on. However, with a very loose definition of "work", this works. The goal is to have a set of Career classes. The program will allow a user to select one or more Careers. The program will create a basic character and then modify the character by the selected Career class(es). If the Career does not exist in a file then the character gets assigned a generic Career based on social status. Careers are each in their own file and the program builds the list of available careers by slurping up those file names. Adding a Career should just be adding a properly formatted file. Import happens when a Career is selected to modify the character I've done this in Ruby so my guess is it can be done in Python. Even Python 2. :D The Career seems to be a "Decorator" pattern given my limited understanding of design patterns. Concur? If so I'll go study that some more. Do you feel this path should still make a Career a class? Thanks! Leam From llanitedave at birdandflower.com Sun Sep 10 20:55:44 2017 From: llanitedave at birdandflower.com (llanitedave) Date: Sun, 10 Sep 2017 17:55:44 -0700 (PDT) Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <3dc36af4-a609-40b9-9250-230df93a9685@googlegroups.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <3dc36af4-a609-40b9-9250-230df93a9685@googlegroups.com> Message-ID: And not one mention of Unicode. I consider this progress. On Sunday, September 10, 2017 at 7:46:54 AM UTC-7, Rick Johnson wrote: > Chris Angelico wrote: > > Marko Rauhamaa wrote: > > [...] > > > > The clouds I see looming over Python's head are: > > > > > > * 2-to-3 migration > > > > If that was going to kill Python, it would have had some > > impact by now. There are students learning Python *today* > > who are never going to have to worry about the migration, > > because they're learning Python 3. > > > > > * static type annotation > > > > I'm not seeing very much of this in the wild yet, but > > honestly, it's not that big a deal. You can ignore it if > > you want to. > > Kinda difficult to ignore type annotations when they are > intermixed with the code! > > I never really had a problem with the idea of Python having > type-hints, so long as the ugly annotations were kept > _separated_ from the .py[w] files, but for some reason, the > devs decided that mucking up Python's clean syntax for the > sake of (what you claim is) a small minority of type-hint > fanboys, was okay... > > The fanboys of type-hints claim that we will never (or > hardly ever) see these annotations in the wild, but again, > if that is the case, *IF* usage of this feature is really > that rare, then why should it be given such power to > undermine the readability of Python code? It is not too > late! We are still in the very early stages of type-hints, > and we can undo the damage that this "feature" will cause if > we remove the hints from the .py[w] files entirely. Let the > burden be on those who want this feature, not on those who > don't want it. > > Futhermore, if we consider the damage that small changes > (like the print statement versus print function and > raw_input versus input) have caused, how can we expect > (short of a self delusion) that type-hints will have no > negative effects? > > There is one aspect of the internet that will never change, > namely: persistance, and from now, and until Python > disappears from the universe, there will always be a need to > explain why `print` was changed from a statement to a > function, along with an explanation of the subtle > differences between python2's raw_input() and input() versus > Python3's input(), not to mention the age old ramblings > about classic classes versus new classes. And as much as > we'd all like for these confusions to go away, they won't, > because there is no way to "clean" the internet of every > Python2 tutorial, blog or website that mentions these bygone > features. > > The stain of Python3's violent and radical changes to the > core philosophy of the language may never be washed clean, > and although we might have survived Python3 _eventually_, > type-hints is like a wooden stake driven into the heart of > this community. It's almost like they _want_ to destroy this > language. From rantingrickjohnson at gmail.com Sun Sep 10 21:29:29 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 10 Sep 2017 18:29:29 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> Message-ID: <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> On Sunday, September 10, 2017 at 1:14:40 PM UTC-5, leam hall wrote: > I will add my +1 to the careful editing of code. Python's > use of white space is pretty good once you get used to it. Python's mandate that all blocks must use whitespace is by far my favorite feature. A clean code structure is very important to me, but consistency is most important of all. > My Ruby code looks a lot like my Python code. :) Nothing wrong with that! Ruby adopts the "Tim Toady"[1] approach to coding, as opposed to Python's loosely followed: "There should be one-- and preferably only one --obvious way to do it." And while your Ruby code may look similar to your Python code, if you examine random Ruby scripts in the wild, you will find a wide variety of structures and multiple forms of doing the same thing that on superficial examination, at least, may not be readily apparent. For instance, in Python, there is only one way to write a "for loop": for var on iterable: # do something However, Ruby allows multiple forms, the first of which almost exactly mimics Python syntax (except for the `end` keyword and the mising colon): for var in iterable # do something end But Ruby offers a second form using a method of the "iterable object", with the block denoted by 'do' and `end` keywords: iterable.each do |var| # do something end And futhermore, Ruby offers a third form using a method of the "iterable object" (as before), except, this time, using braces to denote the block: iterable.each{|var| # do something } Whew! Now how's that for a meet and greet with Tim Toady? As for me, when i write a "for loop" in Ruby, i choose the second form, because: (1) I won't use braces to denote my blocks unless i can write the entire construct on a single line, as in: iterable.each{|var| # do something} (2) When i use the first form (you know, the one that resembles Python code), i sometimes become confused and forget that i'm writing Ruby code altogether, and then i get slammed with syntax errors later. Most of the time, it's because i instinctively placed a colon at the end of the first line of a "for loop" structure -- Damn you Python! :-) At one point, i became so sick of repeating this simple mistake, i was forced to write a script that would search for misplaced colons and hilight them for me, which unsurprisingly, greatly increased my workflow! Ruby is a neat language, and while Python will probably always be my favorite little scripting language, Ruby has some advantages over Python. ============================================================ EXAMPLE 1: ============================================================ Firstly, method chaining in Ruby follows a naturally intuitive left-to-right progression. Consider a contrived example where we have an array of floats, and we need to determine how many unique integers can be derived from these floats. Ruby: farray = [1.5, 1.9, 2.0, 1.0] uniqueIntegers = farray.map{|f| f.to_i()}.uniq.length Python: flist = [1.5, 1.9, 2.0, 1.0] uniqueIntegers = len(set(map(lambda f:int(f), flist))) Holy Buhjeebus! Was that Lisp or Python code? o_O Obviously Ruby is superior in this test, as the python code is nothing but an unintuitive and nested mess. "Flat is better than nested"... ============================================================ EXAMPLE 2: ============================================================ (oops, looks like i'm being cut short. I'll get back to this Pepsi challenge ASAP. So stay tuned...) [1] https://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it From rosuav at gmail.com Sun Sep 10 21:58:15 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Sep 2017 11:58:15 +1000 Subject: [Tutor] beginning to code In-Reply-To: <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: On Mon, Sep 11, 2017 at 11:29 AM, Rick Johnson wrote: > Ruby: > farray = [1.5, 1.9, 2.0, 1.0] > uniqueIntegers = farray.map{|f| f.to_i()}.uniq.length > > Python: > flist = [1.5, 1.9, 2.0, 1.0] > uniqueIntegers = len(set(map(lambda f:int(f), flist))) Python: floats = [1.5, 1.9, 2.0, 1.0] unique_integers = len(set(int(f) for f in floats)) or: unique_integers = len(set(map(int, floats)) If you're going to use Python, at least use it right. ChrisA From torriem at gmail.com Sun Sep 10 22:43:41 2017 From: torriem at gmail.com (Michael Torrie) Date: Sun, 10 Sep 2017 20:43:41 -0600 Subject: Using Python 2 In-Reply-To: <87tw0asiis.fsf@elektro.pacujo.net> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <87tw0asiis.fsf@elektro.pacujo.net> Message-ID: On 09/10/2017 09:20 AM, Marko Rauhamaa wrote: > Been there. I'm afraid this is not a joke: > > Wow that's pretty amazing! Thanks for sharing that link. > Python, COBOL for the next generation. I guess we'll have to see. COBOL did pretty well for a long time. From torriem at gmail.com Sun Sep 10 22:49:12 2017 From: torriem at gmail.com (Michael Torrie) Date: Sun, 10 Sep 2017 20:49:12 -0600 Subject: Design: method in class or general function? In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> Message-ID: <6e88a0d6-91f1-beb6-361f-a3321f840124@gmail.com> On 09/10/2017 06:16 PM, Leam Hall wrote: > The Career seems to be a "Decorator" pattern given my limited > understanding of design patterns. Concur? If so I'll go study that some > more. A career seems to be something one "has." So a classic "has a" characteristic, which means it should be an attribute of an instance, rather than involved in inheritance of the class itself. > Do you feel this path should still make a Career a class? Career certainly could be a class, instances of which can be stored in a character's instance as attributes? Not having read the whole thread, it seems like yes, making Career a class would allow you flexibility to implement the multiple careers per character easily. A particular career is definite the "is a" relationship (a professional programming career is a career), which means inheritance can work for it. I could be wrong, though! From steve+python at pearwood.info Sun Sep 10 23:08:57 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 11 Sep 2017 13:08:57 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> <3dc36af4-a609-40b9-9250-230df93a9685@googlegroups.com> Message-ID: <59b5fe4a$0$16737$b1db1813$d948b532@news.astraweb.com> On Mon, 11 Sep 2017 12:46 am, Rick Johnson wrote: > if we consider the damage that small changes > (like the print statement versus print function and > raw_input versus input) have caused The word for negative damage is "improvement". -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Sep 10 23:12:17 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 11 Sep 2017 13:12:17 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> <87vakquaqp.fsf@elektro.pacujo.net> <87y3pmsiua.fsf@elektro.pacujo.net> <87wp56qxwi.fsf@elektro.pacujo.net> Message-ID: <59b5ff12$0$16737$b1db1813$d948b532@news.astraweb.com> On Mon, 11 Sep 2017 03:14 am, Marko Rauhamaa wrote: > Dennis Lee Bieber : > >> In contrast, every sample I've seen of the async library comes >> across as "magic happens here -- at some point in time". > > That magic can be learned, in principle. I'm afraid few programmers will > be willing/able to get over the hump, and there are a number of tricky > aspects to be extra careful about. The huge popularity of asynchronous routines in the Javascript and Node.JS community is evidence that it won't be "few programmers" but a whole lot of them. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Sun Sep 10 23:15:42 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 10 Sep 2017 20:15:42 -0700 (PDT) Subject: Python in Perspective In-Reply-To: <9478df86-532c-4233-b1b1-aecc97c87135@googlegroups.com> References: <75e60eab-a095-812b-bf02-312dbf76b4ca@gmail.com> <9478df86-532c-4233-b1b1-aecc97c87135@googlegroups.com> Message-ID: <7dbcabef-71fb-4153-a129-8a59614daec1@googlegroups.com> On Monday, September 11, 2017 at 3:08:51 AM UTC+5:30, bream... at gmail.com wrote: > On Sunday, September 10, 2017 at 11:21:26 AM UTC+1, Leam Hall wrote: > > y'all, > > > > My god-kids and their proginators lost most everything because of > > Harvey. I spent much of yesterday worrying about a friend who had gone > > quiet as he evacuated his family ahead of Irma. > > > > Please keep Python in perspective. Whether we use 1.5 or 4rc1 is a lot > > less critical than using Python to work together well and solving big > > problems as friends. > > > > In years gone by I spent time on the soapbox but never came away cleaner > > or with stronger friendships. I just ranted and spent years wondering > > why nothing actually changed. Please don't make my mistake; come up with > > your own. > > > > Together. As friends. > > > > Leam > > What do you have to say about the people who die every year in the monsoon, as they are dying right now, as opposed to the occasional hurricane that hits the richest nation in the world? Will Trump the Chump cure all the worlds ills, or is he too busy looking after his highly paid mates in the oil and gas industries, who are actively paying for the education system in some US states to the detriment of facts, as in there is no man made global warming? Dont know whether to laugh or to weep http://time.com/4935117/hurricane-irma-guns-florida/ From steve+python at pearwood.info Sun Sep 10 23:15:46 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 11 Sep 2017 13:15:46 +1000 Subject: [Tutor] beginning to code References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> Message-ID: <59b5ffe3$0$16754$b1db1813$d948b532@news.astraweb.com> On Mon, 11 Sep 2017 04:14 am, leam hall wrote: > I will add my +1 to the careful editing of code. Python's use of white > space is pretty good once you get used to it. My Ruby code looks a lot like > my Python code. :) I believe you've replied to the wrong list. I think you meant to reply to the Tutor list. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sun Sep 10 23:22:17 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Sep 2017 13:22:17 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <59b5ff12$0$16737$b1db1813$d948b532@news.astraweb.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87vakquaqp.fsf@elektro.pacujo.net> <87y3pmsiua.fsf@elektro.pacujo.net> <87wp56qxwi.fsf@elektro.pacujo.net> <59b5ff12$0$16737$b1db1813$d948b532@news.astraweb.com> Message-ID: On Mon, Sep 11, 2017 at 1:12 PM, Steve D'Aprano wrote: > On Mon, 11 Sep 2017 03:14 am, Marko Rauhamaa wrote: > >> Dennis Lee Bieber : >> >>> In contrast, every sample I've seen of the async library comes >>> across as "magic happens here -- at some point in time". >> >> That magic can be learned, in principle. I'm afraid few programmers will >> be willing/able to get over the hump, and there are a number of tricky >> aspects to be extra careful about. > > The huge popularity of asynchronous routines in the Javascript and Node.JS > community is evidence that it won't be "few programmers" but a whole lot of > them. I agree, but the comparison isn't completely fair. Async functions in JS are an alternative to callback hell; most people consider async functions in Python to be an alternative to synchronous functions. (They might also be considered an alternative to threading or multiprocessing.) So the uptake is going to be driven less by "hey look how clean this is now" and more by "you can now improve throughput by doing more than one thing at a time" or by "you don't need the hassles of threading/multiprocessing". ChrisA From tjreedy at udel.edu Sun Sep 10 23:44:44 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 10 Sep 2017 23:44:44 -0400 Subject: array.array()'s memory shared with multiprocessing.Process() In-Reply-To: <03ac60ca-4906-48aa-b6e8-8c5913dcfe19@googlegroups.com> References: <27b84429-2a3f-4bfd-921e-13ede1f3d383@googlegroups.com> <25368303-5a50-e35a-dbe0-04de800e94f3@mrabarnett.plus.com> <8cfebb15-38db-48ee-9090-8961974ba6e0@googlegroups.com> <5fb8977c-e0e3-7d95-6d23-ba133806500f@mrabarnett.plus.com> <03ac60ca-4906-48aa-b6e8-8c5913dcfe19@googlegroups.com> Message-ID: On 9/10/2017 5:05 PM, iurly wrote: > Il giorno domenica 10 settembre 2017 18:53:33 UTC+2, MRAB ha scritto: >> I've had a quick look at the source code. >> >> When an object is put into the queue, it's actually put into an internal >> buffer (a deque), and then the method returns. >> >> An internal thread works through the buffer and pickles the objects. >> >> Therefore, just because the method has returned, it doesn't mean that >> it's now safe to modify the object. > > I see. So that explains everything. However, I wonder if that's the intended behavior and/or that should be documented somehow. We are still improving the docs. Reread the docs and if you think something is needed, open an issue, preferably the the new wording you would like. -- Terry Jan Reedy From gengyangcai at gmail.com Mon Sep 11 00:51:14 2017 From: gengyangcai at gmail.com (Cai Gengyang) Date: Sun, 10 Sep 2017 21:51:14 -0700 (PDT) Subject: CodeAcademy Python Tip Calculator Message-ID: <4f0b8023-d958-4eb6-ac79-3eec76862f58@googlegroups.com> So, I?m on section (3. The Tip) ? Instructions 1. Set the variable tip to decimal value of 15% on line 5. This was my input: You?re almost there! Assign the tip variable on line 5. meal = 44.50 tax = 6.75 / 100 tip = 15.0 But, when I tried to run the program, I don?t get any output at all. Nada, nothing zilch. Nothing happens, how come ? From ofekmeister at gmail.com Mon Sep 11 02:06:38 2017 From: ofekmeister at gmail.com (ofekmeister at gmail.com) Date: Sun, 10 Sep 2017 23:06:38 -0700 (PDT) Subject: Hatch - A modern project, package, and virtual env manager In-Reply-To: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> References: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> Message-ID: <442d1cf5-40f0-419f-8f33-1b91e2cdcfe5@googlegroups.com> Hatch now supports all major shells!!! https://github.com/ofek/hatch#090 From ian.g.kelly at gmail.com Mon Sep 11 02:07:15 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Sep 2017 00:07:15 -0600 Subject: Using Python 2 In-Reply-To: <714cbdab-42b4-4601-b961-a8c804ef0821@googlegroups.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <714cbdab-42b4-4601-b961-a8c804ef0821@googlegroups.com> Message-ID: On Sun, Sep 10, 2017 at 10:06 AM, Rick Johnson wrote: > Ian wrote: >> Rick Johnson wrote: >> > Ned Batchelder wrote: >> > > Leam Hall wrote: >> > > > >> > > > I've read comments about Python 3 moving from the Zen of >> > > > Python. I'm a "plain and simple" person myself. >> > > > Complexity to support what CompSci folks want, which was >> > > > used to describe some of the Python 3 changes, doesn't >> > > > help me get work done. >> > > >> > > I've heard a lot of FUD about the Python 3 transition, >> > > but this one is new to me. What is it that CompSci folks >> > > want that developers don't want, that ruined Python 3? >> > >> > TWO WORDS: "Type" and "Hints" >> >> Fail. >> >> 1. Type hints were only added in 3.5, not Python 3.0, so >> this does not support the claim that Python 3 changes were >> made to support CS. > > But it is true that CS purist want type annotations Citation needed. > "Practicality beats purity". That's an odd mantra to use when you're arguing against a practical feature in favor of keeping the language "pure". >> 2. Type hints are completely optional, so this does not >> support the claim that Python 3 added complexity that is >> counter-productive to "simple" users. If you want to keep >> your program simple, you can: just don't use them. > > True, individual programmers can choose to omit type-hints > from their own code, but they cannot choose to omit type- > hints from the code they are forced to read. Once type > annotations start propagating in the wild, the syntactical > noise of statically typed languages will be ever-present in > Python code, only problem is, we will get *NONE* of the > advantages of _real_ statically typed languages, namely: > executables, compiler optimizations, and enhanced execution > speed. Heck, all we get in return for our painful eyeball > parsings are (maybe) better linters. Which is not an ROI > worthy of my sweat equity. Type hints aren't just for compilers, in the same way that comments are not for compilers, well-named variables are not for compilers, and readable code in general is not for the benefit of compilers. >> 3. Type hints are practical. You may not need or desire >> them for pet projects, but large-scale projects with a >> large team of developers require a large degree of testing. >> Static typing supports this. This is a feature for >> enterprise users, not theorists. > > I was never against Python having a type annotation feature, > no, i am only against the inclusion of this syntacticly noisy > feature in the .py[w] files. Mandating that type annotations > be defined in _external_ stub files places the onerous on > those who care about type annotations (a micro minority of > CS purist), and removes it from those who don't (the > remaining majority of Python programmers). If you're trying to actually understand the code that you're reading, then having the type hints swept off in another file to be "out of sight, out of mind" does not excuse you from the responsibility of knowing and understanding what the type expectations of the code are. You can guess, or you can read the author's explicit intentions. I know which one I prefer. Stub files exist for cases where it's not practical to type-hint the actual code, such as third-party libraries that you want type hints for but that you're not the maintainer of. Keeping type hints together with the actual code is always preferable. You don't have to care about type annotations, but when they happen to be present, then everybody should care, because they're useful. By the way, "onerous" is an adjective, not a noun. From BILL_NOSPAM at whoknows.net Mon Sep 11 02:16:28 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Mon, 11 Sep 2017 02:16:28 -0400 Subject: CodeAcademy Python Tip Calculator In-Reply-To: <4f0b8023-d958-4eb6-ac79-3eec76862f58@googlegroups.com> References: <4f0b8023-d958-4eb6-ac79-3eec76862f58@googlegroups.com> Message-ID: Cai Gengyang wrote: > So, I?m on section (3. The Tip) ? > > Instructions > > 1. > Set the variable tip to decimal value of 15% on line 5. > > This was my input: > You?re almost there! Assign the tip variable on line 5. > meal = 44.50 > tax = 6.75 / 100 > tip = 15.0 > > But, when I tried to run the program, I don?t get any output at all. Nada, nothing zilch. Nothing happens, how come ? Not a big enough tip? You must be running the program as a script if no output is being printed to the screen. From kryptxy at protonmail.com Mon Sep 11 02:28:21 2017 From: kryptxy at protonmail.com (Kryptxy) Date: Mon, 11 Sep 2017 02:28:21 -0400 Subject: Torrench - Torrent search made simple Message-ID: Torrench: Command-line torrent search program (cross-platform). Torrent search made quick and simple. GitHub: https://github.com/kryptxy/torrench Suggestions/feedbacks are highly appreciated. From shlyoko at gmail.com Mon Sep 11 02:51:57 2017 From: shlyoko at gmail.com (Emil Natan) Date: Mon, 11 Sep 2017 09:51:57 +0300 Subject: CodeAcademy Python Tip Calculator In-Reply-To: <4f0b8023-d958-4eb6-ac79-3eec76862f58@googlegroups.com> References: <4f0b8023-d958-4eb6-ac79-3eec76862f58@googlegroups.com> Message-ID: To see output you should use function that prints to the output, for example print(). You also do not calculate correctly the tax and tip, it is percentage from the meal cost, so the tax to be added to the total meal cost is meal * tax / 100. meal = 44.50 tax = 6.75 tip = 15.0 tax_amount = meal * tax / 100 tip_amount = meal * tip / 100 print('Meal total: %.2f' % (meal + tax_amount + tip_amount)) If I remember correctly, you receive the above values as input to your script. Use the input() and float() functions to accept value as input and convert it to float. On Mon, Sep 11, 2017 at 7:51 AM, Cai Gengyang wrote: > So, I?m on section (3. The Tip) ? > > Instructions > > 1. > Set the variable tip to decimal value of 15% on line 5. > > This was my input: > You?re almost there! Assign the tip variable on line 5. > meal = 44.50 > tax = 6.75 / 100 > tip = 15.0 > > But, when I tried to run the program, I don?t get any output at all. Nada, > nothing zilch. Nothing happens, how come ? > -- > https://mail.python.org/mailman/listinfo/python-list > From greg.ewing at canterbury.ac.nz Mon Sep 11 03:21:32 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 11 Sep 2017 19:21:32 +1200 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> <87vakquaqp.fsf@elektro.pacujo.net> <87y3pmsiua.fsf@elektro.pacujo.net> <87wp56qxwi.fsf@elektro.pacujo.net> <59b5ff12$0$16737$b1db1813$d948b532@news.astraweb.com> Message-ID: Chris Angelico wrote: > Async functions in > JS are an alternative to callback hell; most people consider async > functions in Python to be an alternative to synchronous functions. What do you base that on? Seems to me async is an alternative to callback-based frameworks such as Twisted. Calling async functions an alternative to sync functions doesn't make sense, because if sync functions will do what you want, there's no need to use async ones. -- Greg From antoon.pardon at vub.be Mon Sep 11 03:23:10 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 11 Sep 2017 09:23:10 +0200 Subject: mutiprocessing gui Message-ID: When one wants to combine multithreading and gui programming all sorts of issues arise. So I wonder how one might combine multiprocessing with gui programming. gui libraries typically have some registration mechanisme, where you can register a call back for when data is available on a network connection. Could one write a wrapper so that the multiprocessing.Queue or multiprocessing.Pipe could be usable like that? -- Antoon Pardon From __peter__ at web.de Mon Sep 11 03:30:12 2017 From: __peter__ at web.de (Peter Otten) Date: Mon, 11 Sep 2017 09:30:12 +0200 Subject: Design: method in class or general function? References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> Message-ID: Leam Hall wrote: > On 09/08/2017 03:06 AM, Peter Otten wrote: >> leam hall wrote: >> >>> On Thu, Sep 7, 2017 at 8:16 AM, Steve D'Aprano >>> wrote: >>> >>>> On Thu, 7 Sep 2017 07:20 pm, Leam Hall wrote: >>>> >>>>> OOP newbie on Python 2.6. >>>> >>>> Python 2.6 is ancient, and is missing many nice features. You should >>>> consider >>>> using the latest version, 3.6. >>>> >>> >>> I've wrestled with that discussion for a while and Python 3 loses every >>> time. There's literally no good reason for me to move to Python 3 >>> earlier than mid-2020's. Please accept the fact that there are hundreds >>> of thousands of servers, if not millions, running Python 2.x. Whether or >>> not Python 3 has any neat cool stuff is irrelevant to those of us >>> seeking to use Python to get today's work done. >>> >>>> I create instances of Character class with an attribute dict of >>>>> 'skills'. The 'skills' dict has the name of a skill as the key and an >>>>> int as a value. The code adds or modifies skills before outputting the >>>>> Character. >>>>> >>>>> Is it better design to have a Character.method that takes a 'skill' >>>>> key and optional value or to have a general function that takes an >>>>> instance, a dict, a key, and an optional value? >>>> >>>> I'm afraid your example is too generic for me to give an opinion. Do >>>> you literally mean a method called "method"? What does it do? >>>> >>> >>> >>> Using this: >>> https://github.com/makhidkarun/py_tools/blob/master/lib/character.py >>> >>> Line 19 sets "self.skills" either from the passed in data or from >>> https://github.com/makhidkarun/py_tools/blob/master/lib/character_tools.py >>> #L34-L48 >>> >>> So Character.skills is a dict with a string key and an int value. I need >>> to be able to add skills and my first attempt is a function: >>> https://github.com/makhidkarun/py_tools/blob/master/lib/character_tools.py >>> #L52-L56 >>> >>> Should the "add_skills" function be a method in the character class or >>> be made a more generic function to add/modify a key/value pair in a dict >>> that is an attribute of an instance? Other tasks will require the >>> add/modify functionality but coding that increases complexity. At least >>> for me, anyway. >>> >>> Sorry about being unclear earlier, coffee was still kicking in and I'm >>> still a newbie that mixes up terms. >> >> I'm pleading "method" as it allows per-class implementation. >> >> Say you use per-career subclasses of a general Character class. There are >> default per-career skill sets, but usually a Character can acquire a >> skill that is not needed in his career -- with the exception that Rogues >> cannot tap dance ;) >> >> Below is a way to implement that with a specialised add_skill() method: >> >> $ cat basic_oo.py >> from __future__ import print_function >> import random >> from collections import defaultdict >> >> >> class Character(object): >> DEFAULT_SKILLS = ['Blade', 'GunCbt', 'Admin', 'Streetwise'] >> >> def __init__(self): >> self.skills = defaultdict(int) >> >> def add_random_skills(self, terms): >> skillnames = self.DEFAULT_SKILLS >> for _ in range(2*terms): >> self.add_skill(random.choice(skillnames)) >> >> def add_skill(self, name, amount=1): >> self.skills[name] += amount >> >> def __str__(self): >> skills = ", ".join( >> "{}={}".format(name, amount) >> for name, amount in sorted(self.skills.items()) >> if amount != 0 >> ) >> return "{}({})".format(self.__class__.__name__, skills) >> >> >> class Rogue(Character): >> def add_skill(self, name, amount=1): >> if name == "TapDance": >> raise ValueError("Sorry, this rogue will never tap dance") >> super(Rogue, self).add_skill(name, amount) >> >> >> class Marine(Character): >> DEFAULT_SKILLS = ['GunCbt', 'VaccSuit', 'Leadership', 'Vehicle'] >> >> >> def main(): >> NUM_CHARACTERS = 5 >> CHARACTERS = [Marine, Rogue] >> >> characters = [ >> random.choice(CHARACTERS)() for _ in range(NUM_CHARACTERS) >> ] >> >> for c in characters: >> c.add_random_skills(5) >> c.add_skill("RepairBicycles", random.randrange(3)) >> try: >> c.add_skill("TapDance", 3) >> except ValueError as err: >> print(err) >> >> for c in characters: >> print(c) >> >> >> if __name__ == "__main__": >> main() >> >> $ python basic_oo.py >> Sorry, this rogue will never tap dance >> Sorry, this rogue will never tap dance >> Sorry, this rogue will never tap dance >> Rogue(Admin=3, Blade=4, GunCbt=2, Streetwise=1) >> Marine(GunCbt=5, Leadership=4, TapDance=3, VaccSuit=1) >> Rogue(Blade=3, GunCbt=2, RepairBicycles=2, Streetwise=5) >> Rogue(Admin=1, Blade=2, GunCbt=5, RepairBicycles=1, Streetwise=2) >> Marine(GunCbt=1, Leadership=3, RepairBicycles=2, TapDance=3, VaccSuit=2, >> Vehicle=4) > > > Okay Peter, I took your idea and mangled it beyond recognition. There's > a design constraint I hadn't mentioned: an instance of Character should > be able to have multiple careers. > > Also, an instance can be created from scratch, created from a full set > of data, or created from a partial set of data. > > Here's my current code, focusing on creating a lot of merchants: > https://github.com/makhidkarun/py_tools/blob/merchant/lib/character.py#L60-L61 > > python chargen.py > Toby Verstraeten 564775 [M] Age: 41 > Merchant (5 terms) > Computer-2 Engineering-5 Navigation-2 Pilot-1 > > Captain Ian Domici 789987 [M] Age: 24 > Firster (3 terms) Merchant (3 terms) Noble (2 terms) > Broker-2 GunCbt-1 Streetwise-2 > > Rosa 66495B [F] Age: 24 > Merchant (1 terms) > Computer-1 Navigation-1 > > > As you can see, lots to work on. However, with a very loose definition > of "work", this works. > > The goal is to have a set of Career classes. The program will allow a > user to select one or more Careers. The program will create a basic > character and then modify the character by the selected Career class(es). > > If the Career does not exist in a file then the character gets assigned > a generic Career based on social status. > > Careers are each in their own file and the program builds the list of > available careers by slurping up those file names. > Adding a Career should just be adding a properly formatted file. > Import happens when a Career is selected to modify the character > > I've done this in Ruby so my guess is it can be done in Python. Even > Python 2. :D > > The Career seems to be a "Decorator" pattern given my limited > understanding of design patterns. Concur? If so I'll go study that some > more. The first thought that triggered was @decorator, and only then, because that didn't make sense, the focus changed on "design patterns". While I would tend to "composite" rather than "decorator" it's been some time since I read the book... > Do you feel this path should still make a Career a class? As long as it's only a dictionary entry self.character.careers['Merchant'] = self.terms and the addition of some skills a function would work fine, too. If you expect that you will later add other features which vary over careers you should consider a Career base class that you can subclass as needed. If you use a class it's worthwhile to keep the instance around self.character.careers['Merchant'] = self # a careers set # would work, too. (If you want to avoid the reference cycle do not store the character as an attribute.) From rustompmody at gmail.com Mon Sep 11 03:32:12 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 11 Sep 2017 00:32:12 -0700 (PDT) Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> <87vakquaqp.fsf@elektro.pacujo.net> <87y3pmsiua.fsf@elektro.pacujo.net> <87wp56qxwi.fsf@elektro.pacujo.net> <59b5ff12$0$16737$b1db1813$d948b532@news.astraweb.com> Message-ID: <99c9a44e-5206-48e6-86f2-2fa00c7e16f4@googlegroups.com> On Monday, September 11, 2017 at 12:51:59 PM UTC+5:30, Gregory Ewing wrote: > Chris Angelico wrote: > > Async functions in > > JS are an alternative to callback hell; most people consider async > > functions in Python to be an alternative to synchronous functions. > > What do you base that on? Seems to me async is an alternative > to callback-based frameworks such as Twisted. > > Calling async functions an alternative to sync functions > doesn't make sense, because if sync functions will do what > you want, there's no need to use async ones. The choice usually is: sync-functions-in-threads with lock-race-hell vs callback-hell From steve+comp.lang.python at pearwood.info Mon Sep 11 03:34:03 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 11 Sep 2017 07:34:03 GMT Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <714cbdab-42b4-4601-b961-a8c804ef0821@googlegroups.com> Message-ID: <59b63c6a$0$16632$b1db1813$d948b532@news.astraweb.com> On Mon, 11 Sep 2017 00:07:15 -0600, Ian Kelly wrote: > On Sun, Sep 10, 2017 at 10:06 AM, Rick Johnson > wrote: >> Ian wrote: >>> Rick Johnson wrote: >>> > Ned Batchelder wrote: >>> > > Leam Hall wrote: >>> > > > >>> > > > I've read comments about Python 3 moving from the Zen of Python. >>> > > > I'm a "plain and simple" person myself. Complexity to support >>> > > > what CompSci folks want, which was used to describe some of the >>> > > > Python 3 changes, doesn't help me get work done. >>> > > >>> > > I've heard a lot of FUD about the Python 3 transition, but this >>> > > one is new to me. What is it that CompSci folks want that >>> > > developers don't want, that ruined Python 3? >>> > >>> > TWO WORDS: "Type" and "Hints" >>> >>> Fail. >>> >>> 1. Type hints were only added in 3.5, not Python 3.0, so this does not >>> support the claim that Python 3 changes were made to support CS. >> >> But it is true that CS purist want type annotations > > Citation needed. Ironically, many CS purists don't like type hinting and gradual typing because they aren't pure enough. Type hints are only a *hint*, the interpreter can and does ignore them, unlike type declarations in statically typed languages like Java and Haskell. (And yes, I'm aware that Haskell does type inference. But when there's not enough information for the compiler to infer a type, you can declare one.) [...] >> True, individual programmers can choose to omit type-hints from their >> own code, but they cannot choose to omit type- hints from the code they >> are forced to read. Once type annotations start propagating in the >> wild, the syntactical noise of statically typed languages will be >> ever-present in Python code, only problem is, we will get *NONE* of the >> advantages of _real_ statically typed languages, namely: executables, >> compiler optimizations, and enhanced execution speed. Heck, all we get >> in return for our painful eyeball parsings are (maybe) better linters. Better linters, smarter editors with autocomplete, better code documentation, and most importantly, early detection of at least some bugs. >> Which is not an ROI worthy of my sweat equity. > > Type hints aren't just for compilers, in the same way that comments are > not for compilers, well-named variables are not for compilers, and > readable code in general is not for the benefit of compilers. Indeed. [...] >> I was never against Python having a type annotation feature, no, i am >> only against the inclusion of this syntacticly noisy feature in the >> .py[w] files. Mandating that type annotations be defined in _external_ >> stub files places the onerous on those who care about type annotations >> (a micro minority of CS purist), and removes it from those who don't >> (the remaining majority of Python programmers). > > If you're trying to actually understand the code that you're reading, > then having the type hints swept off in another file to be "out of > sight, out of mind" does not excuse you from the responsibility of > knowing and understanding what the type expectations of the code are. > You can guess, or you can read the author's explicit intentions. I know > which one I prefer. Indeed. C has separate header files for declarations and source code files, and that's widely acknowledged to be a mistake. In a programming ecosystem where many languages tend to slavishly follow C conventions, it is remarkable how few languages (I can't think of any) have copied the convention of separating the declaration (or hint) and the source code. > Stub files exist for cases where it's not practical to type-hint the > actual code, such as third-party libraries that you want type hints for > but that you're not the maintainer of. Keeping type hints together with > the actual code is always preferable. You don't have to care about type > annotations, but when they happen to be present, then everybody should > care, because they're useful. If nothing else, even if you have no linter and don't run mypy and are editing the code with Notepad, at least the annotation tells you what the author of the code expects the variable to be. > By the way, "onerous" is an adjective, not a noun. "Onerosity" or "onertude" would be the correct grammatical forms for the noun. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From stephanh42 at gmail.com.invalid Mon Sep 11 03:47:27 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 11 Sep 2017 07:47:27 GMT Subject: People choosing Python 3 References: <8760crm2mp.fsf@elektro.pacujo.net> <871snevqwi.fsf@elektro.pacujo.net> <87h8wau4vc.fsf@elektro.pacujo.net> Message-ID: Op 2017-09-10, Marko Rauhamaa schreef : > Stephan Houben : >> >> Why not bundle the Python interpreter with your application? >> It seems to work for Windows developers... > > I've seen that done for Python and other technologies. It is an > expensive route to take. Also, it can be insecure. When vulnerabilities > are found, they are communicated to the maintainers of, say, Python. > When Python is fixed and released, the vulnerability is revealed, but > the version bundled with your product is still broken. You have to be > prepared perform an emergency release of your product and hope you don't > mess things up. To each his own, but this is not different from any other third-party package your application depends on. Stephan From stephanh42 at gmail.com.invalid Mon Sep 11 03:54:53 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 11 Sep 2017 07:54:53 GMT Subject: Run Windows commands from Python console References: <83ebc433-d457-408b-b43a-4b00a3206728@googlegroups.com> <290ec6d2-81d9-4bf4-b641-fc8568578555@googlegroups.com> <7515e893-b1c7-42ff-926d-e482e1eca9ae@googlegroups.com> <44d79423-bb42-4f8d-9d08-07f77a9a16c7@googlegroups.com> Message-ID: Op 2017-09-10, Rick Johnson schreef : > It seems to me the best solution is for the TCL/Tk folks to > provide a configuration utility that stores user preferences > in the registry, or some other OS provided mechanism, as to > have these settings reset on every invocation of the > application would be inefficient from an enduser > perspective. You mean, like the existing .Xdefaults mechanism (yes Tk also supports that on Windows), and the "option" mechanism? https://www.tcl.tk/man/tcl8.6/TkCmd/option.htm Stephan From marko at pacujo.net Mon Sep 11 03:58:10 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 11 Sep 2017 10:58:10 +0300 Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> <87vakquaqp.fsf@elektro.pacujo.net> <87y3pmsiua.fsf@elektro.pacujo.net> <87wp56qxwi.fsf@elektro.pacujo.net> <59b5ff12$0$16737$b1db1813$d948b532@news.astraweb.com> Message-ID: <87shftoeel.fsf@elektro.pacujo.net> Gregory Ewing : > Chris Angelico wrote: >> Async functions in >> JS are an alternative to callback hell; most people consider async >> functions in Python to be an alternative to synchronous functions. > > What do you base that on? Seems to me async is an alternative > to callback-based frameworks such as Twisted. > > Calling async functions an alternative to sync functions > doesn't make sense, because if sync functions will do what > you want, there's no need to use async ones. Asyncio makes it possible to write a single-threaded program in multithreading style. The multithreading style means entwining the state of a finite state machine in the form of the source code. While a callback-based program will use one or more variables (object attributes) to store the state -- or leave it implicit -- an asyncio program marks each state with the "await" keyword. The multithreading style is convenient in cases where each state is blocked on a single possible event. Trouble is, most state machines I run into (and that's my bread and butter), each state is blocked on several or even numerous alternative events. Marko From stephanh42 at gmail.com.invalid Mon Sep 11 04:12:11 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 11 Sep 2017 08:12:11 GMT Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> <877ex6u40h.fsf@elektro.pacujo.net> Message-ID: Op 2017-09-10, Marko Rauhamaa schreef : > Stephan Houben : > >> Would we not eventually want a file object to deliver its lines >> asynchronously (with non-blocking reads under the hood) if >> iterated over with "async for", while preserving the current >> blocking behavior in the "for" case? > > I'm not exactly sure what your point is. I mean that I would imagine that 1. functionality as is today available in `aiofiles' would at some point be integrated into the standard library, and 2. that this might be done in such a way that there is no distinction anymore between a normal file object and an "aiofiles" file object, unlike today. > As for file objects supporting asynchronous iterators, I agree they > should. OK, that is essentially my point 2, above. > Linux is not quite ready for nonblocking file access yet (the > kernel developers are busy trying to make it happen). > > Note that you will not only need an async version of a file iterator but > also versions for the "open()" function, directory walking etc. open() already supports non-blocking mode (as does read() and write(), of course). readdir() is indeed currently always blocking. Stephan From stephanh42 at gmail.com.invalid Mon Sep 11 04:20:03 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 11 Sep 2017 08:20:03 GMT Subject: mutiprocessing gui References: Message-ID: Op 2017-09-11, Antoon Pardon schreef : > When one wants to combine multithreading and gui programming > all sorts of issues arise. So I wonder how one might combine > multiprocessing with gui programming. > > gui libraries typically have some registration mechanisme, > where you can register a call back for when data is available > on a network connection. Could one write a wrapper so that > the multiprocessing.Queue or multiprocessing.Pipe could be > usable like that? Are you aware of Quamash? This allows you to combine a Qt GUI with asyncio-style code for, say, handing network connections. https://github.com/harvimt/quamash Stephan From marko at pacujo.net Mon Sep 11 04:22:17 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 11 Sep 2017 11:22:17 +0300 Subject: People choosing Python 3 References: <8760crm2mp.fsf@elektro.pacujo.net> <871snevqwi.fsf@elektro.pacujo.net> <87h8wau4vc.fsf@elektro.pacujo.net> Message-ID: <87fubtodae.fsf@elektro.pacujo.net> Stephan Houben : > Op 2017-09-10, Marko Rauhamaa schreef : >> I've seen that done for Python and other technologies. It is an >> expensive route to take. Also, it can be insecure. When >> vulnerabilities are found, they are communicated to the maintainers >> of, say, Python. When Python is fixed and released, the vulnerability >> is revealed, but the version bundled with your product is still >> broken. You have to be prepared perform an emergency release of your >> product and hope you don't mess things up. > > To each his own, but this is not different from any other third-party > package your application depends on. And that is an argument to minimize the number of 3rd-party dependencies in a product. However, programming languages are particularly problematic because they have huge attack surfaces. For example, we need to rerelease our product four times a year because of Java. No other 3rd-party package gives us such trouble. (BTW, a former employer of mine chose to package Python with the application so they could ship the application in a .pyc format.) Marko From rosuav at gmail.com Mon Sep 11 04:30:39 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Sep 2017 18:30:39 +1000 Subject: Using Python 2 In-Reply-To: <59b63c6a$0$16632$b1db1813$d948b532@news.astraweb.com> References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <714cbdab-42b4-4601-b961-a8c804ef0821@googlegroups.com> <59b63c6a$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: On Mon, Sep 11, 2017 at 5:34 PM, Steven D'Aprano wrote: >> By the way, "onerous" is an adjective, not a noun. > > "Onerosity" or "onertude" would be the correct grammatical forms for the > noun. More likely, "onus" was intended. ChrisA From rosuav at gmail.com Mon Sep 11 04:35:02 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Sep 2017 18:35:02 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> <87vakquaqp.fsf@elektro.pacujo.net> <87y3pmsiua.fsf@elektro.pacujo.net> <87wp56qxwi.fsf@elektro.pacujo.net> <59b5ff12$0$16737$b1db1813$d948b532@news.astraweb.com> Message-ID: On Mon, Sep 11, 2017 at 5:21 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> Async functions in >> JS are an alternative to callback hell; most people consider async >> functions in Python to be an alternative to synchronous functions. > > > What do you base that on? Seems to me async is an alternative > to callback-based frameworks such as Twisted. > > Calling async functions an alternative to sync functions > doesn't make sense, because if sync functions will do what > you want, there's no need to use async ones. Do a quick poll here on the list. Who sees async functions as an alternative to Twisted? Who here has even *used* Twisted? (How many even know what it is?) Personally, I think of them as an alternative to threading. Basically they're a way to use the code style of threaded I/O (functions that block when they need to read from a socket etc) with the light-weight efficiency of doing everything in one thread. I have never used Twisted. ChrisA From tjol at tjol.eu Mon Sep 11 05:25:03 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 11 Sep 2017 11:25:03 +0200 Subject: People choosing Python 3 In-Reply-To: References: Message-ID: <69695eae-e264-dbf5-292a-31403b65b52e@tjol.eu> On 2017-09-10 09:05, INADA Naoki wrote: > I saw encouraging tweet from Kenneth Reitz. > > https://twitter.com/kennethreitz/status/902028601893294081/photo/1 > > On Heroku, most people choose Python 3! > I know, it's because Python 3 is the default Python on Heroku. > > I can't wait Python 3 is the default Python of Red Hat, and "python" > command means Python 3 on Debian and Ubuntu. https://www.python.org/dev/peps/pep-0394/ Debian follows PEP 394, which recommends that "python" point to python2, and I don't see that changing any time soon (certainly not before RHEL includes python3 by default. > > Regards, > > INADA Naoki > -- Thomas Jollans From anubhav.yadav at gmx.com Mon Sep 11 05:49:17 2017 From: anubhav.yadav at gmx.com (GMX) Date: Mon, 11 Sep 2017 15:19:17 +0530 Subject: How to create an object in database only if the object is not already there? Message-ID: Hi,? Reposting again to the list as I had made a silly mistake in typing the subject line last week.? I am using `pony` orm to write a simple class as my model. Here is the class.? ``` from pony.orm import Database from pony.orm import Required, Optional from pony.orm import db_session from pony.orm import select, commit DB_PATH = ?db.sqlite? db = Database() class Course(db.Entity): ? ? """ ? ? A class to represent a course ? ? """ ? ? title = Required(str, unique=True) ? ? url = Optional(str, unique=True) ? ? thumbnail = Optional(str) ? ? processed = Optional(bool, default=False) db.bind(provider='sqlite', filename=DB_PATH, create_db=True) db.generate_mapping(create_tables=True) ``` Now when I create a Course object like this: ? ? >>> Course(title=?A new course?) An object is create in the database. I don?t want to have this behaviour, but what I want to be doing is create a Course object and then only commit in the database if the course is not already available in the database. If the course is already in the database,? the orm should just return the same object. I have implemented the requirement as follows: ``` class Course(db.Entity): ? ? """ ? ? A class to represent a course ? ? """ ? ? title = Required(str, unique=True) ? ? url = Optional(str, unique=True) ? ? thumbnail = Optional(str) ? ? processed = Optional(bool, default=False) ? ? @staticmethod ? ? @db_session ? ? def new(title, url=None, thumbnail=None, processed=False): ? ? ? ? """Return a Course either new or from database""" ? ? ? ? course = select(c for c in Course if c.title == title)[:] ? ? ? ? if course: ? ? ? ? ? ? return course[0] ? ? ? ? return Course(title=title, url=url, thumbnail=thumbnail, processed=processed) db.bind(provider='sqlite', filename=DB_PATH, create_db=True) db.generate_mapping(create_tables=True) ``` Can there be a better method of doing that? Please let me know.? Thanks.? ? You are not born knowing everything. You go on learning?? - Anubhav Yadav From leamhall at gmail.com Mon Sep 11 06:15:47 2017 From: leamhall at gmail.com (Leam Hall) Date: Mon, 11 Sep 2017 06:15:47 -0400 Subject: Design: method in class or general function? In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> Message-ID: <8df05022-6707-f711-3174-17d030e69e52@gmail.com> On 09/11/2017 03:30 AM, Peter Otten wrote: > Leam Hall wrote: >> Okay Peter, I took your idea and mangled it beyond recognition. There's >> a design constraint I hadn't mentioned: an instance of Character should >> be able to have multiple careers. >> >> Also, an instance can be created from scratch, created from a full set >> of data, or created from a partial set of data. >> >> Here's my current code, focusing on creating a lot of merchants: >> > https://github.com/makhidkarun/py_tools/blob/merchant/lib/character.py#L60-L61 >> >> python chargen.py >> Toby Verstraeten 564775 [M] Age: 41 >> Merchant (5 terms) >> Computer-2 Engineering-5 Navigation-2 Pilot-1 >> >> Captain Ian Domici 789987 [M] Age: 24 >> Firster (3 terms) Merchant (3 terms) Noble (2 terms) >> Broker-2 GunCbt-1 Streetwise-2 >> >> Rosa 66495B [F] Age: 24 >> Merchant (1 terms) >> Computer-1 Navigation-1 >> >> >> As you can see, lots to work on. However, with a very loose definition >> of "work", this works. >> >> The goal is to have a set of Career classes. The program will allow a >> user to select one or more Careers. The program will create a basic >> character and then modify the character by the selected Career class(es). >> >> If the Career does not exist in a file then the character gets assigned >> a generic Career based on social status. >> >> Careers are each in their own file and the program builds the list of >> available careers by slurping up those file names. >> Adding a Career should just be adding a properly formatted file. >> Import happens when a Career is selected to modify the character >> >> I've done this in Ruby so my guess is it can be done in Python. Even >> Python 2. :D >> >> The Career seems to be a "Decorator" pattern given my limited >> understanding of design patterns. Concur? If so I'll go study that some >> more. > > The first thought that triggered was @decorator, and only then, because that > didn't make sense, the focus changed on "design patterns". While I would > tend to "composite" rather than "decorator" it's been some time since I read > the book... > >> Do you feel this path should still make a Career a class? > > As long as it's only a dictionary entry > > self.character.careers['Merchant'] = self.terms > > and the addition of some skills a function would work fine, too. > If you expect that you will later add other features which vary over careers > you should consider a Career base class that you can subclass as needed. If > you use a class it's worthwhile to keep the instance around > > self.character.careers['Merchant'] = self # a careers set > # would work, too. > > (If you want to avoid the reference cycle do not store the character as an > attribute.) > Haven't read the GoF book. Last time I checked it said "this is only useful if you know Java", and I don't. Is there a good Python 2 compatible reference? I just picked up an old copy of "Programming Python" and haven't gotten far into it yet. My goal isn't to use patterns for the pattern's sake, but to use a decently right tool for the job. There will be a Career class that gets sub-classed. There are enough differences between the careers to need that. I do not understand your last sentence about reference cycle. That may be where I'm struggling. A character is an instance of class Character. All characters have base attributes: upp, name, gender. A character will usually have a career. A character may have more than one career. A career modifies the character in one or more of the following: attribute skills attribute careers attribute age attribute stuff attribute background_info Should the "run_career()" process be a method of character, with parameters of career and terms? Or a composite-ing class that created the character and then run them through the careers? The composite model might work better as a future step will be to offer different ways to output the character; text to screen, json, sql, etc. Hmm...thinking about the composite seems useful. That way users could add extra composite steps for their needs without flooding class Character with extra methods for each use case. From tjol at tjol.eu Mon Sep 11 06:19:04 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 11 Sep 2017 12:19:04 +0200 Subject: array.array()'s memory shared with multiprocessing.Process() In-Reply-To: <03ac60ca-4906-48aa-b6e8-8c5913dcfe19@googlegroups.com> References: <27b84429-2a3f-4bfd-921e-13ede1f3d383@googlegroups.com> <25368303-5a50-e35a-dbe0-04de800e94f3@mrabarnett.plus.com> <8cfebb15-38db-48ee-9090-8961974ba6e0@googlegroups.com> <5fb8977c-e0e3-7d95-6d23-ba133806500f@mrabarnett.plus.com> <03ac60ca-4906-48aa-b6e8-8c5913dcfe19@googlegroups.com> Message-ID: <4d718833-1f89-497a-3844-1e26c592b232@tjol.eu> On 2017-09-10 23:05, iurly wrote: > As far as I'm concerned, I'm probably better off using double buffers to avoid this kind of issues. > Thanks a lot for your help! > That should work. Some other things to consider, if both processes are on the same machine, are a series of memory-mapped files to pass the data without pickling, or, if your code is only going to run on Unix, something involving shared memory through multiprocessing.Array. -- Thomas Jollans From p.f.moore at gmail.com Mon Sep 11 06:58:51 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 11 Sep 2017 11:58:51 +0100 Subject: Simple board game GUI framework Message-ID: I'm doing some training for a colleague on Python, and I want to look at a bit of object orientation. For that, I'm thinking of a small project to write a series of classes simulating objects moving round on a chess-style board of squares. I want to concentrate on writing the classes and their behaviour, and not on display issues, but I would like it if the resulting program was reasonably interesting. To that end, I was thinking of putting together a frontend that displayed the objects moving round on a board (rather than, for example, just printing out lists of co-ordinates). I'd build the frontend, then my student could write the object classes and drop them into the framework. My problem is that I've never written any sort of game code for Python, which is basically what this is. And I don't have a lot of time to develop something. So I was wondering - are there any ready-made examples of the sort of driver I'm thinking of? Something like a framework for a Chess or Othello game, but with the actual game logic isolated so I could easily rip it out and replace it with my own. I've done some searching around, but most of the examples I've seen seem to have the display and game logic intermingled (at least to my untrained eye). Any suggestions? If not, I guess I'll just have to write my own. I'm sure I could - it's just that I don't want my training to be messed up because of bugs in my code... Thanks, Paul From pavol.lisy at gmail.com Mon Sep 11 08:00:40 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Mon, 11 Sep 2017 14:00:40 +0200 Subject: People choosing Python 3 In-Reply-To: <69695eae-e264-dbf5-292a-31403b65b52e@tjol.eu> References: <69695eae-e264-dbf5-292a-31403b65b52e@tjol.eu> Message-ID: On 9/11/17, Thomas Jollans wrote: > On 2017-09-10 09:05, INADA Naoki wrote: >> I saw encouraging tweet from Kenneth Reitz. >> >> https://twitter.com/kennethreitz/status/902028601893294081/photo/1 >> >> On Heroku, most people choose Python 3! >> I know, it's because Python 3 is the default Python on Heroku. >> >> I can't wait Python 3 is the default Python of Red Hat, and "python" >> command means Python 3 on Debian and Ubuntu. > > https://www.python.org/dev/peps/pep-0394/ > > Debian follows PEP 394, which recommends that "python" point to python2, > and I don't see that changing any time soon (certainly not before RHEL > includes python3 by default. Which part of third party ecosystem surrounding Python 3 is not (and could not be any time soon) sufficiently mature? From leamhall at gmail.com Mon Sep 11 08:03:02 2017 From: leamhall at gmail.com (leam hall) Date: Mon, 11 Sep 2017 08:03:02 -0400 Subject: People choosing Python 3 In-Reply-To: References: <69695eae-e264-dbf5-292a-31403b65b52e@tjol.eu> Message-ID: On Mon, Sep 11, 2017 at 8:00 AM, Pavol Lisy wrote: > > > Which part of third party ecosystem surrounding Python 3 is not (and > could not be any time soon) sufficiently mature? > -- > > yum, twisted. From leamhall at gmail.com Mon Sep 11 08:03:38 2017 From: leamhall at gmail.com (leam hall) Date: Mon, 11 Sep 2017 08:03:38 -0400 Subject: Design: method in class or general function? In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <8df05022-6707-f711-3174-17d030e69e52@gmail.com> Message-ID: On Mon, Sep 11, 2017 at 7:48 AM, Stefan Ram wrote: > Leam Hall writes: > >Haven't read the GoF book. Last time I checked it said "this is only > >useful if you know Java" > > In the edition of 1997, some design patterns are accompanied > with examples in C++ or Smalltalk, but the majority of the > patterns is language agnostic (often UML diagrams are used). > Also, I may have been thinking of the "Head First Design Patterns" book. Looks like I need to talk to my good buddy Amazon... From rosuav at gmail.com Mon Sep 11 08:07:31 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Sep 2017 22:07:31 +1000 Subject: People choosing Python 3 In-Reply-To: References: <69695eae-e264-dbf5-292a-31403b65b52e@tjol.eu> Message-ID: On Mon, Sep 11, 2017 at 10:00 PM, Pavol Lisy wrote: > On 9/11/17, Thomas Jollans wrote: >> On 2017-09-10 09:05, INADA Naoki wrote: >>> I saw encouraging tweet from Kenneth Reitz. >>> >>> https://twitter.com/kennethreitz/status/902028601893294081/photo/1 >>> >>> On Heroku, most people choose Python 3! >>> I know, it's because Python 3 is the default Python on Heroku. >>> >>> I can't wait Python 3 is the default Python of Red Hat, and "python" >>> command means Python 3 on Debian and Ubuntu. >> >> https://www.python.org/dev/peps/pep-0394/ >> >> Debian follows PEP 394, which recommends that "python" point to python2, >> and I don't see that changing any time soon (certainly not before RHEL >> includes python3 by default. > > Which part of third party ecosystem surrounding Python 3 is not (and > could not be any time soon) sufficiently mature? That isn't the problem; the problem is one of ambiguity. If the command "python" sometimes means Py2 and sometimes Py3, it's hard to write cross-platform scripts. The current recommendation is to have "python2" always mean Python 2.x and "python3" always mean Python 3.x; cross-platform scripts should always use one of those, unless they are 2/3 compatible (and can therefore run on either). But until virtually every current OS is shipping Py3 by default and not depending on Py2, changing the meaning of "python" would be problematic. Fortunately, it's not that hard to type "python3" all the time. OS distributions can progressively shift to using that name, and then eventually not ship a Py2 until/unless something depends on it, all without losing backward compatibility. ChrisA From p.f.moore at gmail.com Mon Sep 11 08:40:53 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 11 Sep 2017 13:40:53 +0100 Subject: People choosing Python 3 In-Reply-To: References: <69695eae-e264-dbf5-292a-31403b65b52e@tjol.eu> Message-ID: On 11 September 2017 at 13:07, Chris Angelico wrote: > Fortunately, it's not that hard to type "python3" all the time. OS > distributions can progressively shift to using that name, and then > eventually not ship a Py2 until/unless something depends on it, all > without losing backward compatibility. My main objections to needing to type "python3" are: * It perpetuates the illusion that Python 3 isn't the "real" Python, and creates a feedback loop that makes it harder to persuade people that we're ready to make Python 3 the default. * It makes it harder to write cross-platform instructions that encompass Windows, which doesn't have a "python3" executable. But both of these are weak arguments and as usual, practicality beats purity. Paul From rosuav at gmail.com Mon Sep 11 08:43:08 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Sep 2017 22:43:08 +1000 Subject: People choosing Python 3 In-Reply-To: References: <69695eae-e264-dbf5-292a-31403b65b52e@tjol.eu> Message-ID: On Mon, Sep 11, 2017 at 10:40 PM, Paul Moore wrote: > On 11 September 2017 at 13:07, Chris Angelico wrote: >> Fortunately, it's not that hard to type "python3" all the time. OS >> distributions can progressively shift to using that name, and then >> eventually not ship a Py2 until/unless something depends on it, all >> without losing backward compatibility. > > My main objections to needing to type "python3" are: > > * It perpetuates the illusion that Python 3 isn't the "real" Python, > and creates a feedback loop that makes it harder to persuade people > that we're ready to make Python 3 the default. > * It makes it harder to write cross-platform instructions that > encompass Windows, which doesn't have a "python3" executable. > > But both of these are weak arguments and as usual, practicality beats purity. Windows doesn't have a "python" executable either (at least, not in PATH), so that's same-same. And people should be being trained to type "python2" vs "python3", not "python" vs "python3", so it's going to be the same there too. Notably, SOME platforms already have "python" aliased to "python3", so cross-platform scripts MUST be explicit if they want Py2. ChrisA From p.f.moore at gmail.com Mon Sep 11 08:59:01 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 11 Sep 2017 13:59:01 +0100 Subject: Simple board game GUI framework In-Reply-To: References: Message-ID: On 11 September 2017 at 13:13, Stefan Ram wrote: > Paul Moore writes: >>write a series of classes simulating objects > > I'd say "write classes for objects". Yeah, that's just me not being precise in my mail. Sorry. >>objects moving round on a chess-style board of squares > > This seems to follow the recommendation to model > objects after real-world entities. > > I prefer another approach when I do not have experience with > a type of program: I start to write the program "procedurally". We've been doing that - the issue is that we don't have sufficiently large real-world examples to make transitioning to objects a natural requirement. And yes, I know you're going to say "don't teach stuff the student doesn't actually need yet", but in this particular context I'm specifically being asked by the student (it's a one-to-one environment) to explain classes and objects, because he's encountering the ideas in other places. And I want to do so in a practical context, even if that practical context is artificial. >> but I would like it if the resulting program >>was reasonably interesting. > > ?Interesting?, for me, is too vague and subjective. OK. Replace that with "I think my student would find it motivating to see a GUI style of behaviour, even if he had to take the implementation of that part of the program on faith". He's used to the idea of writing plugin code that fits into a framework, so this would be a familiar idea to him. >>I'd build the frontend, then my student could write the object classes >>and drop them into the framework. > > When the students are not yet able to write the whole > program themselves, it might make sense to write a part of > the program for them (the frontend) and have them supply the > rest. > > But the frontend is a teacher-supplied library (TSL), and to > write the rest of the program, the students have to learn the > interface of the TSL and then write code for the TSL. Agreed - but as I say, in my specific context I don't think this will be a problem (and I'm confident in my ability to clearly explain the difference between "you need to do this because that's what the framework expects" and "you need to do this because this is how you write a class"). > In my teaching, I avoid providing TSLs for my course > participants and have them learn the TSLs because I believe > that the standard distribution of Python (or Tkinter or > Pygame if you use on of those) alreadu has more than enough > libraries in them, and students should learn the standard > libraries and not additional teacher-supplied libraries. My student has told me that he would like to understand classes so that he can better understand the logic behind the class-based features in the stdlib. That's why I'm trying to find a useful, understandable, example to work with. >>My problem is that I've never written any sort of game code for >>Python, which is basically what this is. > > Get proficient first, then teach. I'll assume you don't mean that to be as critical of me as it sounds. I have no intention of trying to teach anyone "how to write a GUI program" or "how to use pygame". Any more than I'm trying to teach how the Python interpreter works. I'm simply trying to find (or build) an environment that helps me explain the concepts that I *am* trying to teach better than a command line REPL can do. > And as I said, I would prefer to teach the standard > frameworks and libraries that are distributed with the > standard distribution of Python before I teach additional > frameworks. As I said, I've been doing that, but need to help the student understand classes to give them a better understanding of why the stdlib is designed the way it is. > Ok, if you teach at a gaming academy of when the title > of the class contains the word "game", then you might have > to teach game programming, but in this case you should > really become proficient in it first. Well, obviously. I'm not sure why you think I'd consider it otherwise :-( Thank you for your comments, but clearly you have a very different environment and/or set of students than I have. Paul From mail at timgolden.me.uk Mon Sep 11 09:06:58 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 11 Sep 2017 14:06:58 +0100 Subject: Simple board game GUI framework In-Reply-To: References: Message-ID: <63c26071-c6b7-7d4d-a11b-0bb0c27facaf@timgolden.me.uk> On 11/09/2017 11:58, Paul Moore wrote: > I'm doing some training for a colleague on Python, and I want to look > at a bit of object orientation. For that, I'm thinking of a small > project to write a series of classes simulating objects moving round > on a chess-style board of squares. Don't know if you've already thought of looking there, but have you tried poking around the Pygame examples pages, eg: http://www.pygame.org/tags/demos (Obviously I hope that someone else will come forward with a specific example, but in case they don't...) TJG From __peter__ at web.de Mon Sep 11 09:16:25 2017 From: __peter__ at web.de (Peter Otten) Date: Mon, 11 Sep 2017 15:16:25 +0200 Subject: Design: method in class or general function? References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <8df05022-6707-f711-3174-17d030e69e52@gmail.com> Message-ID: Leam Hall wrote: > I do not understand your last sentence about reference cycle. Currently you have - create Career instance which stores character as an attribute - make modifications to character - forget about Career instance My suggestion - create Career instance which stores character as an attribute - make modifications to character, among those - enter career into the character.careers dict Then the cycle goes character --> careers dict --> career instance --> character Such a cycle isn't too bad, I just thought I'd mention it for the gallery ;) It means that reference count will never go to 0: >>> class A: ... def __del__(self): print("A says bye!") ... >>> class B: ... def __del__(self): print("B says bye!") ... Case 1, a --> b, no cycle: >>> a = A(); a.b = B() >>> del a A says bye! B says bye! Case 2, a --> b --> a, reference cycle: >>> a = A(); a.b = B(); a.b.a = a >>> del a At that point we can neither access a nor b, but as a holds a reference to b and b holds a reference to a the reference count of both stays above 0 and they live forever after -- or until the garbage collector kicks in. Triggering it manually, for demonstration purposes: >>> import gc; gc.collect() A says bye! B says bye! 4 That's for Python 3, in Python 2 the output will be >>> import gc; gc.collect() 4 The objects will still be released, it's only that you don't see it because their __del__() methods aren't invoked. From mruffalo at cs.cmu.edu Mon Sep 11 09:19:48 2017 From: mruffalo at cs.cmu.edu (Matt Ruffalo) Date: Mon, 11 Sep 2017 09:19:48 -0400 Subject: People choosing Python 3 In-Reply-To: References: <8760crm2mp.fsf@elektro.pacujo.net> Message-ID: <4e75f40b-4887-6998-223f-37664f72baca@cs.cmu.edu> On 2017-09-10 05:42, Chris Warrick wrote: > > RHEL?s release process starts at forking a recent Fedora release. It > wouldn?t make much sense for them to undo the Python 3 progress that > happened over the past few years in Fedora ? including dnf, an > improved package manager written in Python 3. If the fork happened > today, the base release would be Fedora 26, which includes Python 3.6, > and some install options don?t include Python 2. > It wouldn't make much sense for Red Hat to undo the Python 3 progress that has been made in the Fedora project, but this is exactly what happened with RHEL 7. That version is based on Fedora 19, which includes Python 3.3 in the base install, but 3.3 is not only missing from the default install of RHEL/CentOS 7, it's not even available in default package repositories. I was rather surprised and annoyed about this, and can't wait until "Python 3 isn't part of the base install of RHEL" to not be a valid complaint/excuse anymore. MMR... -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 829 bytes Desc: OpenPGP digital signature URL: From christopher_reimer at icloud.com Mon Sep 11 09:52:22 2017 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Mon, 11 Sep 2017 06:52:22 -0700 Subject: Simple board game GUI framework In-Reply-To: References: Message-ID: > On Sep 11, 2017, at 3:58 AM, Paul Moore wrote: > > I'm doing some training for a colleague on Python, and I want to look > at a bit of object orientation. For that, I'm thinking of a small > project to write a series of classes simulating objects moving round > on a chess-style board of squares. > > I want to concentrate on writing the classes and their behaviour, and > not on display issues, but I would like it if the resulting program > was reasonably interesting. To that end, I was thinking of putting > together a frontend that displayed the objects moving round on a board > (rather than, for example, just printing out lists of co-ordinates). > I'd build the frontend, then my student could write the object classes > and drop them into the framework. > > My problem is that I've never written any sort of game code for > Python, which is basically what this is. And I don't have a lot of > time to develop something. So I was wondering - are there any > ready-made examples of the sort of driver I'm thinking of? Something > like a framework for a Chess or Othello game, but with the actual game > logic isolated so I could easily rip it out and replace it with my > own. I've done some searching around, but most of the examples I've > seen seem to have the display and game logic intermingled (at least to > my untrained eye). > > Any suggestions? If not, I guess I'll just have to write my own. I'm > sure I could - it's just that I don't want my training to be messed up > because of bugs in my code... > > Thanks, > Paul > -- > https://mail.python.org/mailman/listinfo/python-list I started something similar to this and didn't get far. I wrote a base class called Piece that had common attributes (I.e., color and position) and abstract methods (i.e., move). From the base class I derived all the piece types. That's the easy part. The board is a bit tricky, depending on how you set it up. The board of 64 squares could be a list, a dictionary or a class. I went with a Board class that used a coordinate system (i.e., bottom row first square was (0, 0) and top row last square (7, 7)) and kept track of everything on the board. The furthest I got with this was a simple text display and interface to move pawns and bishops forward. Chess may look straight forward but it can get complicated in a hurry. If you look at the computing literature, chess has been a never ending rabbit hole for 50+ years. Chris R. From p.f.moore at gmail.com Mon Sep 11 10:12:25 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 11 Sep 2017 15:12:25 +0100 Subject: Simple board game GUI framework In-Reply-To: References: Message-ID: On 11 September 2017 at 14:52, Christopher Reimer wrote: >> On Sep 11, 2017, at 3:58 AM, Paul Moore wrote: >> >> I'm doing some training for a colleague on Python, and I want to look >> at a bit of object orientation. For that, I'm thinking of a small >> project to write a series of classes simulating objects moving round >> on a chess-style board of squares. > > I started something similar to this and didn't get far. I wrote a base class called Piece that had common attributes (I.e., color and position) and abstract methods (i.e., move). From the base class I derived all the piece types. That's the easy part. > > The board is a bit tricky, depending on how you set it up. The board of 64 squares could be a list, a dictionary or a class. I went with a Board class that used a coordinate system (i.e., bottom row first square was (0, 0) and top row last square (7, 7)) and kept track of everything on the board. Thanks for the information. That's more or less the sort of thing I was thinking of. In fact, from a bit more browsing, I found another way of approaching the problem - rather than using pygame, it turns out to be pretty easy to do this in tkinter. The following code is basically the core of what I need: import tkinter as tk def create_board(root): board = {} for r in range(8): for c in range(8): lbl = tk.Button(bg="white", text=" ", font=("Consolas", 12)) lbl.grid(row=r, column=c) board[r,c] = lbl return board root = tk.Tk() board = create_board(root) root.mainloop() That creates an 8x8 grid of white buttons. With this, I can make a button red simply by doing board[3,2]["bg"] = "red" That's really all I need. With that I can place objects on the grid by asking them for their colour and x/y co-ordinates. Add a bit of driver logic, and I have a display system. We can then spend the time working on how we add business logic to the classes (movement, collision detection, etc...) I really need to spend some time looking into tkinter. I very rarely think of it when developing code, and yet whenever I do it's amazingly easy to put together a solution quickly and easily. Paul From p.f.moore at gmail.com Mon Sep 11 11:08:01 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 11 Sep 2017 16:08:01 +0100 Subject: People choosing Python 3 In-Reply-To: <368drcltggd0ir3gj85qaornjkaqilrhr1@4ax.com> References: <69695eae-e264-dbf5-292a-31403b65b52e@tjol.eu> <368drcltggd0ir3gj85qaornjkaqilrhr1@4ax.com> Message-ID: On 11 September 2017 at 15:53, Dennis Lee Bieber wrote: > > As for Windows itself... I use the ActiveState installers and see: > > Directory of c:\Python35 > > > 06/26/2017 07:22 PM 41,240 python.exe > 06/26/2017 07:22 PM 41,240 python3.5.exe > 06/26/2017 07:18 PM 50,688 python3.dll > 06/26/2017 07:22 PM 41,240 python3.exe > 06/26/2017 07:18 PM 3,935,744 python35.dll > 06/26/2017 07:50 PM 24,344 pythonservice.exe > 06/26/2017 07:22 PM 41,240 pythonw.exe Interesting. I didn't realise ActiveState did that. The python.org installers don't ship with python3.exe or python3.5.exe. And yes, I know that the Windows installers don't put Python on PATH by default. I'm assuming the user has added Python to his PATH (people using command line languages on Windows usually know how to do that). And I also know that a better option on Windows is to use the "py" launcher anyway. I did say it was a weak argument :-) Paul From robin at reportlab.com Mon Sep 11 11:29:09 2017 From: robin at reportlab.com (Robin Becker) Date: Mon, 11 Sep 2017 16:29:09 +0100 Subject: windows 8 versus urllib2 certificate verify Message-ID: <2a26c97e-14ca-4c5d-e8c4-c3e3c7bcb2cb@chamonix.reportlab.co.uk> I have an application built on 32 bit windows 7 with python 2.7.10. The application runs fine on windows 7 and older windows machines, but it is failing to connect properly using urllib2 when run on windows 8. The error CERTIFICATE_VERIFY_FAILED indcates this is some issue with urllib2 not being able to verify the remote certificate. This is pyinstaller so the python and python library seem to be constant. I thought I understood that python uses its own cert path, but obviously I am wrong. Googling sort of implies I might need certifi to be installed, but is that true? Why does this fail only on windows 8? -- Robin Becker From stephen.michell at maurya.on.ca Mon Sep 11 11:44:09 2017 From: stephen.michell at maurya.on.ca (Stephen Michell) Date: Mon, 11 Sep 2017 11:44:09 -0400 Subject: Python programming language vulnerabilities Message-ID: <87EFFE20-D95D-4EAD-BCBE-1459987CD69E@maurya.on.ca> CORRECTION. My sincere apologies to anyone that tried the link that I posted. The actual link is www.open-std.org/jtc1/sc22/wg23 follow the link to documents, or go directly there via www.open-std.org/jtc1/sc22/wg23/docs/documents.html I was informed that there are some broken links to documents. I believe that they are all fixed now. From dvl at psu.edu Mon Sep 11 12:36:55 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Mon, 11 Sep 2017 12:36:55 -0400 Subject: Simple game board GUI framework In-Reply-To: mailman.24.1505145604.28914.python-list@python.org References: Message-ID: <1505147815l.11534406l.0l@psu.edu> I would echo the recommendation of teaching something you are already familiar with doing. Perhaps you can find a different class hierarchy to work with. I remember that the first time I really began to grok OOP was in a text-based MUD environment. In the application area, clearly everything was an object (sword, bag, apple, etc.) Some objects were living (like player charaters and NPCs). Many objects also served as containers (bags had contents, rooms had contents, players had an inventory). And the polymorphism that came with OOP allowed me to even simulate a ship, which was one object whose inventory included several rooms, so as the ship moved, so did everything on board. And there was no GUI required for it -- so no issues there. It's been a couple decades or so, but that interpreted object-oriented language LPC might still be out there somewhere. Roger ChristmanPennsylvania State University On Mon, Sep 11, 2017 12:00 PM, Paul Moore wrote: > >My student has told me that he would like to understand classes so >that he can better understand the logic behind the class-based >features in the stdlib. That's why I'm trying to find a useful, >understandable, example to work with. > >>My problem is that I've never written any sort of game code for >>Python, which is basically what this is. >> >> Get proficient first, then teach. > >I'll assume you don't mean that to be as critical of me as it sounds. >I have no intention of trying to teach anyone "how to write a GUI >program" or "how to use pygame". Any more than I'm trying to >teach how >the Python interpreter works. I'm simply trying to find (or build) an >environment that helps me explain the concepts that I *am* trying to >teach better than a command line REPL can do. > >> And as I said, I would prefer to teach the standard >> frameworks and libraries that are distributed with the >> standard distribution of Python before I teach additional >> frameworks. > >As I said, I've been doing that, but need to help the student >understand classes to give them a better understanding of why the >stdlib is designed the way it is. > >> Ok, if you teach at a gaming academy of when the title >> of the class contains the word "game", then you might have >> to teach game programming, but in this case you should >> really become proficient in it first. > >Well, obviously. I'm not sure why you think I'd consider it otherwise :-( > >Thank you for your comments, but clearly you have a very different >environment and/or set of students than I have. > >Paul > > From p.f.moore at gmail.com Mon Sep 11 12:56:48 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 11 Sep 2017 17:56:48 +0100 Subject: Simple board game GUI framework In-Reply-To: References: Message-ID: On 11 September 2017 at 16:32, Dennis Lee Bieber wrote: > This leads to a subtle question... If the focus strictly on OOP, or do > you intend to supply some precursor OOAD stuff. OOP is just implementation > and usage, but without some understanding of OOAD the concepts may come > across as just magic. > > IE: classes are templates from which one instantiates objects; > instances of a class share methods, but each instance has its own state. > > Just doesn't help in figuring out what qualifies for a class vs instance, > what should be a method, and what is state. That's a very good point - and not one I'd really thought about (this isn't a formal training course, more of a set of mentoring and knowledge sharing sessions where I'm helping this guy get into "actual" programming rather than just hacking the odd VBA macro etc). I'll make sure I cover some of the design aspects in my discussion. >>OK. Replace that with "I think my student would find it motivating to >>see a GUI style of behaviour, even if he had to take the >>implementation of that part of the program on faith". He's used to the >>idea of writing plugin code that fits into a framework, so this would >>be a familiar idea to him. >> > Unless the "game" is going to be playing Chess (in which case you are > looking at way more than an intro to OOP), the GUI comes down to a grid of > squares, sprites/icons for the pieces, and a way to select/move the > piece... Yep, that's about it. But the point is, that's the framework, not what I actually want to get him implementing. > And the only logic left to implement would be validation of the > moves, and tests for capture when one moves into an occupied square. Not > really that much left for the student. I'm not looking at actually implementing chess. The idea was prompted by a programming exercise my son was given, that was about programming a series of classes modelling robots that know their position on a grid, and when told to move, can do so according to certain rules. One moves in a straight line till it hits the edge, one moves in a random direction, some bounce when they hit an obstacle and some just stop, etc. The idea is to demonstrate classes and inheritance to model common behaviours and objects holding state that the behaviour acts on. The original exercise (which used Java) just had the program print out the objects' co-ordinates at each step. I thought that visualising the results by actually showing the objects moving would be better. (And a quick discussion/demo with the guy I'm training showed me I'm right - his reaction was "wow, that looks really impressive" :-)) > Again, it sounds more like you need a language agnostic discussion of > OOAD -- not language specific OOP. Mostly agreed. But we have a tendency to spiral off into pure theory far too easily - and then my student doesn't remember what we covered because it wasn't grounded in anything practical. So I want to have a practical (and better still, visual) example to keep us focused. Thanks for the comments, Paul From tjreedy at udel.edu Mon Sep 11 13:12:49 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Sep 2017 13:12:49 -0400 Subject: Simple board game GUI framework In-Reply-To: References: Message-ID: On 9/11/2017 10:12 AM, Paul Moore wrote: > Thanks for the information. That's more or less the sort of thing I > was thinking of. In fact, from a bit more browsing, I found another > way of approaching the problem - rather than using pygame, it turns > out to be pretty easy to do this in tkinter. I was going to suggest tkinter. > The following code is basically the core of what I need: > > import tkinter as tk > > def create_board(root): > board = {} > for r in range(8): > for c in range(8): > lbl = tk.Button(bg="white", text=" ", font=("Consolas", 12)) > lbl.grid(row=r, column=c) > board[r,c] = lbl > return board > > root = tk.Tk() > board = create_board(root) > root.mainloop() Mainloop is a blocking call, and while it is running, one can only interact with the data and gui in ways that one has already programmed. If you run the above with python -i, or equivalently, from an IDLE editor, you will not see a >>> prompt until you close the tk windows, at which point there is nothing left to interact with. > That creates an 8x8 grid of white buttons. With this, I can make a > button red simply by doing > > board[3,2]["bg"] = "red" However, if you run the code above from an IDLE editor, you can omit or comment out the mainloop call and still see the board, because IDLE's run code calls tk's update in a non-blocking manner about 20 times a second. Without mainloop running, you immediately get a >>> prompt and can interact with the gui in a live exploratory fashion. You can enter statements like the color assignment above, and the background updates will make them quickly take effect. (I just opened https://bugs.python.org/issue31421 to document this.) > That's really all I need. With that I can place objects on the grid by > asking them for their colour and x/y co-ordinates. Add a bit of driver > logic, and I have a display system. We can then spend the time working > on how we add business logic to the classes (movement, collision > detection, etc...) > > I really need to spend some time looking into tkinter. I very rarely > think of it when developing code, and yet whenever I do it's amazingly > easy to put together a solution quickly and easily. -- Terry Jan Reedy From tjreedy at udel.edu Mon Sep 11 14:09:25 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Sep 2017 14:09:25 -0400 Subject: Simple board game GUI framework In-Reply-To: References: Message-ID: On 9/11/2017 12:56 PM, Paul Moore wrote: > I'm not looking at actually implementing chess. The idea was prompted > by a programming exercise my son was given, that was about programming > a series of classes modelling robots that know their position on a > grid, and when told to move, can do so according to certain rules. One > moves in a straight line till it hits the edge, one moves in a random > direction, some bounce when they hit an obstacle and some just stop, > etc. The idea is to demonstrate classes and inheritance to model > common behaviours and objects holding state that the behaviour acts > on. > > The original exercise (which used Java) just had the program print out > the objects' co-ordinates at each step. I thought that visualising the > results by actually showing the objects moving would be better. (And a > quick discussion/demo with the guy I'm training showed me I'm right - > his reaction was "wow, that looks really impressive" :-)) Once you have a tkinter board, it is pretty easy to add an animated 'sprite'. The key is understanding root.after loops. This example has multiple animated warp-around robots, moving at different speeds and different movement patterns. ------------ import random import tkinter as tk def create_board(root): board = {} for r in range(8): for c in range(8): lbl = tk.Button(bg="white", text=" ", font=("Consolas", 12)) lbl.grid(row=r, column=c) board[c,r] = lbl return board class Robot(): def __init__(self, color, x, y, dt, strategy): self.color = color self.x = x self.y = y self.dt = dt self.strategy = strategy board[x, y]['bg'] = color root.after(dt, self.move) def move(self): dx, dy = self.strategy() if dx or dy: x, y = self.x, self.y board[x, y]['bg'] = 'white' x, y = (x+dx) % 8, (y+dy) % 8 board[x, y]['bg'] = self.color self.x, self.y = x, y root.after(self.dt, self.move) def ranmove(): return random.choice((-1, 0, 1)), random.choice((-1, 0, 1)) def upperleft(): return -1, -1 def lowerright(): return 1, 1 root = tk.Tk() board = create_board(root) yellow = Robot('yellow', 1, 1, 50, ranmove) red = Robot('red', 3, 5, 100, ranmove) blue = Robot('blue', 5, 3, 150, ranmove) green = Robot('green', 2, 7, 300, lowerright) black= Robot('black', 7, 1, 350, upperleft) #root.mainloop() # Uncomment if not run from IDLE editor. ----------- If one want a time resolution finer than 50 milliseconds, then one would need to active mainloop even in IDLE. -- Terry Jan Reedy From skip.montanaro at gmail.com Mon Sep 11 14:48:54 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 11 Sep 2017 13:48:54 -0500 Subject: Totally OT - Looking for someone to translate some Japanese Message-ID: I have a scan of a few pages of an obscure book written in Japanese about an obscure French derailleur produced in the early 1960s. (I recently happened into an early 1960s Italian bike with just this derailleur.) I don't read a single lick of Japanese. I'm hoping that perhaps someone around here can. I don't think I can feed these to Google Translate in any obvious way, though perhaps there is a free OCR program which can successfully extract the raw text. There can't be more than 10-15 sentences total. Each page is dominated by four photos. I put the pages up on my Google Drive. If you think you might be able to help (and are willing :-), let me know (offline) and I'll send you the links. Thanks, Skip From ian.g.kelly at gmail.com Mon Sep 11 17:03:20 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Sep 2017 15:03:20 -0600 Subject: Simple game board GUI framework In-Reply-To: <1505147815l.11534406l.0l@psu.edu> References: <1505147815l.11534406l.0l@psu.edu> Message-ID: On Mon, Sep 11, 2017 at 10:36 AM, ROGER GRAYDON CHRISTMAN wrote: > I would echo the recommendation of teaching something you are already > familiar with doing. Perhaps you can find a different class hierarchy to work > with. > > I remember that the first time I really began to grok OOP was in a > text-based MUD environment. In the application area, clearly > everything was an object (sword, bag, apple, etc.) Some objects > were living (like player charaters and NPCs). Many objects also > served as containers (bags had contents, rooms had contents, > players had an inventory). And the polymorphism that came with > OOP allowed me to even simulate a ship, which was one object > whose inventory included several rooms, so as the ship moved, > so did everything on board. > > And there was no GUI required for it -- so no issues there. > > It's been a couple decades or so, but that interpreted object-oriented > language LPC might still be out there somewhere. There are still plenty of MUDs that use LPC. There is also a general-purpose language Pike that is descended from LPC. From rosuav at gmail.com Mon Sep 11 17:09:43 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Sep 2017 07:09:43 +1000 Subject: Simple game board GUI framework In-Reply-To: References: <1505147815l.11534406l.0l@psu.edu> Message-ID: On Tue, Sep 12, 2017 at 7:03 AM, Ian Kelly wrote: > On Mon, Sep 11, 2017 at 10:36 AM, ROGER GRAYDON CHRISTMAN wrote: >> I would echo the recommendation of teaching something you are already >> familiar with doing. Perhaps you can find a different class hierarchy to work >> with. >> >> I remember that the first time I really began to grok OOP was in a >> text-based MUD environment. In the application area, clearly >> everything was an object (sword, bag, apple, etc.) Some objects >> were living (like player charaters and NPCs). Many objects also >> served as containers (bags had contents, rooms had contents, >> players had an inventory). And the polymorphism that came with >> OOP allowed me to even simulate a ship, which was one object >> whose inventory included several rooms, so as the ship moved, >> so did everything on board. >> >> And there was no GUI required for it -- so no issues there. >> >> It's been a couple decades or so, but that interpreted object-oriented >> language LPC might still be out there somewhere. > > There are still plenty of MUDs that use LPC. There is also a > general-purpose language Pike that is descended from LPC. Yep. I play an LPC MUD that's been running (and commercially viable) for two decades, and I run a few servers built in Pike. And I love that you did the ship as "object with rooms as inventory" - I once did the same kind of thing with a bicycle, making it simultaneously a room and an object. OOP is beautiful. ChrisA From tjreedy at udel.edu Mon Sep 11 17:26:34 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Sep 2017 17:26:34 -0400 Subject: IEEE Spectrum ranks Python at top, along with C Message-ID: https://spectrum.ieee.org/static/interactive-the-top-programming-languages-2017 -- Terry Jan Reedy From best_lay at yahoo.com Mon Sep 11 22:42:17 2017 From: best_lay at yahoo.com (Wildman) Date: Mon, 11 Sep 2017 21:42:17 -0500 Subject: ttk.Notebook Tabs Question Message-ID: I am working on a program that has a ttk.Notebook with 12 tabs. Is there a way to determine the total width of the tabs in pixels. Just to be clear I am not talking about width of the nb container. I am talking about tabs themselves that contain the text. I want the program to be resizable but I don't want to allow the window width to fall below that of the tabs which would hide them. Since I can find no way to have more than one row of tabs, this appears to be my only option. Any suggestions would be appreciated. -- GNU/Linux user #557453 May the Source be with you. From zmshaikh at gmail.com Mon Sep 11 22:49:42 2017 From: zmshaikh at gmail.com (Zubair Shaikh) Date: Mon, 11 Sep 2017 22:49:42 -0400 Subject: version of Python to install Windows 7 professional 64 bit, intel core i5 Message-ID: <03EFC159-E9FC-435F-BDAA-A193CD2DD8EC@gmail.com> What version of Python to install Windows 7 professional 64 bit, intel core i5 From torriem at gmail.com Mon Sep 11 22:59:18 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 11 Sep 2017 20:59:18 -0600 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> <87vakquaqp.fsf@elektro.pacujo.net> <87y3pmsiua.fsf@elektro.pacujo.net> <87wp56qxwi.fsf@elektro.pacujo.net> <59b5ff12$0$16737$b1db1813$d948b532@news.astraweb.com> Message-ID: <741ec8a4-3f82-f1bc-c588-b8bec63d544a@gmail.com> On 09/11/2017 02:35 AM, Chris Angelico wrote: > Do a quick poll here on the list. Who sees async functions as an > alternative to Twisted? Who here has even *used* Twisted? (How many > even know what it is?) /me raises hand, slowly, cautiously looking around. I don't think of twisted so much as an alternative to threading, but rather a way of doing event-driven programming with I/O, which does work well as an alternative to threading. This model actually fits really well with protocol implementations. For example in http, each request can be an "event" that the Twisted stack can process. When using the LDAP protocol adapter, each request type can be an event (ADD, MODIFY, DELETE, etc). As I understand it, Twisted now runs in conjunction with the new async stuff. Apparently you can use both traditional callback style Twisted programming and the new async stuff together in one program. And rather than replace Twisted, the new async core in Python can actually drive Twisted. The problem with Twisted is it's really, really hard for a beginner to mentally trace the execution of code, particularly when you're using an existing protocol adapter class as your base. Took me about two weeks to fully understand the Twisted LDAP server example. Does the new Async facility in Python make it easier to trace program flow and logic? > Personally, I think of them as an alternative to threading. Basically > they're a way to use the code style of threaded I/O (functions that > block when they need to read from a socket etc) with the light-weight > efficiency of doing everything in one thread. I have never used > Twisted. If you ever want to do I/O and run a GUI at the same time, Twisted is probably going to remain your best bet since it integrates tightly with the major GUIs' event loops. From torriem at gmail.com Mon Sep 11 23:03:49 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 11 Sep 2017 21:03:49 -0600 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <6i7drc90ojf5j3tr3dhmreu30478ephasc@4ax.com> References: <87y3pmsiua.fsf@elektro.pacujo.net> <87wp56qxwi.fsf@elektro.pacujo.net> <59b5ff12$0$16737$b1db1813$d948b532@news.astraweb.com> <6i7drc90ojf5j3tr3dhmreu30478ephasc@4ax.com> Message-ID: <1c3c145d-34b1-e14c-61aa-528a1c3a60f1@gmail.com> On 09/11/2017 08:36 AM, Dennis Lee Bieber wrote: > On Mon, 11 Sep 2017 18:35:02 +1000, Chris Angelico > declaimed the following: > >> >> Do a quick poll here on the list. Who sees async functions as an >> alternative to Twisted? Who here has even *used* Twisted? (How many >> even know what it is?) >> > Tried to read the Twisted documentation back when it was the new > mousetrap... Couldn't get my head to understand it then, never looked back. > Threading has worked well for everything I've done (granted, the most > recent "major" effort involved two threads each reading Wireshark captures, > parsing out specific packets, and forwarding them to a third thread via > Queues, so the third thread could match sent vs rcvd and compute time > differences, writing results to SQLite3). I know the feeling. However once it clicks, Twisted isn't that hard to understand in abstract. Data event happens, data is passed to a chain of callbacks. The output of one handler is passed as input to the next. Think of it a bit like chaining generator functions. If an exception occurs along the way, execution shifts from the callback chain to an error handling callback chain. The bit that was hard for me to understand is that somewhere, somehow, the something has to trigger the event. That's the magic/hidden part often, buried in layers of inheritance in the Twisted core. From torriem at gmail.com Mon Sep 11 23:05:29 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 11 Sep 2017 21:05:29 -0600 Subject: Using Python 2 In-Reply-To: References: <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <87tw0asiis.fsf@elektro.pacujo.net> Message-ID: <2999fed5-b5fc-cd70-eba1-59dbff647012@gmail.com> On 09/10/2017 09:38 PM, Dennis Lee Bieber wrote: > It ain't dead yet... Fujitsu still has a COBOL compiler/IDE for Windows > and/or .NET (and maybe even other systems)... (I should see if Win10 can > install the Fujitsu COBOL 4 that came with my Y2K era text books... WinXP > could not install it for some reason). Included GUI application builders. > Current pricing is via email only. > > Raincode also has a "legacy" compiler (no IDE) meant to allow porting > mainframe applications to Windows... No GUI obviously, since it is meant > for IBM style batch programs. Was a "registration" type download. And someone wrote some GTK2 bindings for Cobol years back. All we need now is a javascript to cobol transpiler. Then the journey to the dark side would truly be complete. From ian.g.kelly at gmail.com Mon Sep 11 23:33:23 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 11 Sep 2017 21:33:23 -0600 Subject: Simple game board GUI framework In-Reply-To: References: <1505147815l.11534406l.0l@psu.edu> Message-ID: On Mon, Sep 11, 2017 at 6:26 PM, Dennis Lee Bieber wrote: > I used to have a character on Furtoonia whose "tail" was described as > having a naked singularity at the tip (the tail was an object that > automatically followed the character around) -- the character's "home" was > inside said tail... Is that distinct from FurryMUCK? I spent a little bit of time on there, but mostly I tooled around on TinyTIM back in the day. From no.email at nospam.invalid Mon Sep 11 23:42:14 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 11 Sep 2017 20:42:14 -0700 Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> Message-ID: <87poawa8h5.fsf@nightsong.com> Chris Angelico writes: > students learning Python *today* ... they're learning Python 3. I'm not so sure of that. I do know a few people currently learning Python, and they're using Python 2. >> * static type annotation Seems like a big win if you ask me. >> * asyncio with its a-dialect > Actually, I think this one is a huge enough feature that it's going to > be a big thing to *drive* the uptake of Python. God I hope not, it's perverse. I'd like to see a Python that's more like Erlang in its approach to concurrency. From no.email at nospam.invalid Mon Sep 11 23:43:32 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Mon, 11 Sep 2017 20:43:32 -0700 Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <923d8cdf-745a-7249-36b1-09d18482f4b3@nedbatchelder.com> <7ce36248-6f93-edee-f80e-ebabf6e0fb07@gmail.com> <86bb1d56-9282-4d61-97ff-ab7c68c94a66@googlegroups.com> <59b4cbca$0$16757$b1db1813$d948b532@news.astraweb.com> Message-ID: <87lglka8ez.fsf@nightsong.com> Steve D'Aprano writes: > Guido has ruled that Python 4 will not be a major compatibility break Looking forward to Python 5 then ;-). From rustompmody at gmail.com Tue Sep 12 00:14:44 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 11 Sep 2017 21:14:44 -0700 (PDT) Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <87shftoeel.fsf@elektro.pacujo.net> References: <87a823m2ss.fsf@elektro.pacujo.net> <87vakquaqp.fsf@elektro.pacujo.net> <87y3pmsiua.fsf@elektro.pacujo.net> <87wp56qxwi.fsf@elektro.pacujo.net> <59b5ff12$0$16737$b1db1813$d948b532@news.astraweb.com> <87shftoeel.fsf@elektro.pacujo.net> Message-ID: On Monday, September 11, 2017 at 1:28:24 PM UTC+5:30, Marko Rauhamaa wrote: > Gregory Ewing: > > > Chris Angelico wrote: > >> Async functions in > >> JS are an alternative to callback hell; most people consider async > >> functions in Python to be an alternative to synchronous functions. > > > > What do you base that on? Seems to me async is an alternative > > to callback-based frameworks such as Twisted. > > > > Calling async functions an alternative to sync functions > > doesn't make sense, because if sync functions will do what > > you want, there's no need to use async ones. > > Asyncio makes it possible to write a single-threaded program in > multithreading style. > > The multithreading style means entwining the state of a finite state > machine in the form of the source code. While a callback-based program > will use one or more variables (object attributes) to store the state -- > or leave it implicit -- an asyncio program marks each state with the > "await" keyword. > > The multithreading style is convenient in cases where each state is > blocked on a single possible event. Trouble is, most state machines I > run into (and that's my bread and butter), each state is blocked on > several or even numerous alternative events. Do you have some reading material suggestions for grokking the a-world? From BILL_NOSPAM at whoknows.net Tue Sep 12 00:29:14 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Tue, 12 Sep 2017 00:29:14 -0400 Subject: version of Python to install Windows 7 professional 64 bit, intel core i5 In-Reply-To: References: <03EFC159-E9FC-435F-BDAA-A193CD2DD8EC@gmail.com> Message-ID: Zubair Shaikh wrote: > What version of Python to install Windows 7 professional 64 bit, intel core i5 You're joking, right? What is your budget? From rosuav at gmail.com Tue Sep 12 00:29:41 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Sep 2017 14:29:41 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <87poawa8h5.fsf@nightsong.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> Message-ID: On Tue, Sep 12, 2017 at 1:42 PM, Paul Rubin wrote: > Chris Angelico writes: >> students learning Python *today* ... they're learning Python 3. > > I'm not so sure of that. I do know a few people currently learning > Python, and they're using Python 2. Why? Unless they're going to be maintaining a Py2 codebase, why should they learn the older version with less features? At Thinkful (shameless plug[1]), students learn Python 3 almost exclusively (we do have a data science course in which students learn either or both, but in the web dev course, it's definitely Py3). I haven't had anyone run into difficulties with annotations/type hints (we don't teach them, so how would they be bothered?), print being a function (everything else is a function so it's no surprise that print is too), etc, and even the text/bytes split is only a problem when students are working with non-ASCII data files provided by third parties, at which point they have to learn about encoding="...". Now, I just need to convince people to stop putting "first name" and "surname" fields on their web forms [2], and things will be about perfect... ChrisA [1] I teach via www.thinkful.com. My views are my own, not that of my employer. [2] http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ From tjreedy at udel.edu Tue Sep 12 00:38:00 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 12 Sep 2017 00:38:00 -0400 Subject: version of Python to install Windows 7 professional 64 bit, intel core i5 In-Reply-To: <03EFC159-E9FC-435F-BDAA-A193CD2DD8EC@gmail.com> References: <03EFC159-E9FC-435F-BDAA-A193CD2DD8EC@gmail.com> Message-ID: On 9/11/2017 10:49 PM, Zubair Shaikh wrote: > What version of Python to install Windows 7 professional 64 bit, intel core i5 Whatever version you want. If you have no idea, goto https://www.python.org/downloads/release/python-362/ and click Windows-x86-64 executable installer. -- Terry Jan Reedy From dieter at handshake.de Tue Sep 12 03:25:05 2017 From: dieter at handshake.de (dieter) Date: Tue, 12 Sep 2017 09:25:05 +0200 Subject: mutiprocessing gui References: Message-ID: <87a8201ir2.fsf@handshake.de> Antoon Pardon writes: > When one wants to combine multithreading and gui programming > all sorts of issues arise. So I wonder how one might combine > multiprocessing with gui programming. > > gui libraries typically have some registration mechanisme, > where you can register a call back for when data is available > on a network connection. Could one write a wrapper so that > the multiprocessing.Queue or multiprocessing.Pipe could be > usable like that? The Zope application server has a similar problem. Though not a GUI application framework, it is using a similar architecture: a main thread with an event loop and a set of "worker"s. when a worker has finished its work, it usually must wake up the event loop (in this case to distribute the result). It does this by using short messages on a socket (the event loop in this case is an IO based event loop; thus, has means to recognize if IO is available). From dieter at handshake.de Tue Sep 12 03:35:42 2017 From: dieter at handshake.de (dieter) Date: Tue, 12 Sep 2017 09:35:42 +0200 Subject: windows 8 versus urllib2 certificate verify References: <2a26c97e-14ca-4c5d-e8c4-c3e3c7bcb2cb@chamonix.reportlab.co.uk> Message-ID: <8760co1i9d.fsf@handshake.de> Robin Becker writes: > I have an application built on 32 bit windows 7 with python 2.7.10. > The application runs fine on windows 7 and older windows machines, but > it is failing to connect properly using urllib2 when run on windows 8. > > The error CERTIFICATE_VERIFY_FAILED indcates this is some issue with > urllib2 not being able to verify the remote certificate. > > This is pyinstaller so the python and python library seem to be > constant. I thought I understood that python uses its own cert path, > but obviously I am wrong. > > Googling sort of implies I might need certifi to be installed, but is that true? > > Why does this fail only on windows 8? Certificate verification generally depends on local configuration: specifically, the set of installed trusted root certificates. I do not know about Windows, but often the root certificates installed for other packages, e.g. the browser, are used. And different versions of the same package may install different sets of trusted certificates. It might also be that your new environment lacks one of the packages from your old environment - and it has provided the required root certificate. Of course, the problem might also be caused by a general problem. Try to access a "common" https site via urllib2, one you do not have any problems to connect with a browser (or another "http" utility like "wget" or "curl") from the same machines. If this works, the problem is assiciated with the specific certificate. From wolfgang.maier at biologie.uni-freiburg.de Tue Sep 12 03:46:23 2017 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Tue, 12 Sep 2017 09:46:23 +0200 Subject: Simple board game GUI framework In-Reply-To: References: Message-ID: <02e12fe9-713a-637c-cf24-d7db6d3c12e8@biologie.uni-freiburg.de> On 11.09.2017 12:58, Paul Moore wrote: > I'm doing some training for a colleague on Python, and I want to look > at a bit of object orientation. For that, I'm thinking of a small > project to write a series of classes simulating objects moving round > on a chess-style board of squares. > > I want to concentrate on writing the classes and their behaviour, and > not on display issues, but I would like it if the resulting program > was reasonably interesting. To that end, I was thinking of putting > together a frontend that displayed the objects moving round on a board > (rather than, for example, just printing out lists of co-ordinates). > I'd build the frontend, then my student could write the object classes > and drop them into the framework. > Maybe not exactly what you are asking for, but something I thought about for a Python class earlier this year: There are several Minecraft mods that let you interact with the game from Python. Of course, Minecraft itself is Java code, but it's a prime example of OOP and you are getting a very sophisticated and fully tested display engine for free. It's a bit complicated to get started with (which eventually made me postpone this experiment to next year's class), but I think it may be a lot of fun, especially if you've played Minecraft before. Here's a link to get you started: http://www.instructables.com/id/Python-coding-for-Minecraft/ Best, Wolfgang From rdb.mb at juno.com Tue Sep 12 03:46:47 2017 From: rdb.mb at juno.com (rdb.mb at juno.com) Date: Tue, 12 Sep 2017 07:46:47 GMT Subject: Fw: Problems Installing Python36 Message-ID: <20170912.034647.1218.0@webmail04.vgs.untd.com> I have subscribed to the Python List as directed.Below is my information request re-submitted. Thank you. ---------- Forwarded Message ---------- From: "rdb.mb at juno.com" To: python-list at python.org Subject: Problems Installing Python36 Date: Tue, 12 Sep 2017 01:35:11 GMT I am having difficulty executing Python-3.6.2-amd64.exe. I am able to install it successfully, but each time Python36 fails to execute. The error message returned is: “The program can’t start because api-ms-win-crt-runtime-|1-1-0.dll is missing from your computer. Try reinstalling the program to fix this problem." I have tried repeatedly to install various Python versions (32-bit or 64-bit), but the same error occurs. Is it possibly related to either Windows Paths or to conflicts with other Python compilers/interpreters embedded in programs such as OpenOffice 3 and GNU Gimp 2? I am using an ASUS laptop with an Intel Pentium CPU B970 @ 2.30 Hz, dual 64-bit cores, running Windows 7 Home Premium, Service Pack 1. Each time I ran the Installer as the System Administrator and I checked the boxes labeled: “Install launcher for all users,” and “Add Python 3.6 to PATH,” which appear to have been incorporated properly. With the material from Python.org about “get-pip.py” and the “Virtual Environment,” I succeeded in activating/deactivating “venv,” but not “get-pip.py” because Python36 will not execute. Can you please tell me what I am doing wrong. I would appreciate any help that you can give me in getting Python installed. Thank you for your assistance in this matter. Respectively yours, Randolph Bracey Myrtle Beach, SC ____________________________________________________________ Doctor Reveals 3 "Death Foods" You Need To Avoid This Summer Nucific http://thirdpartyoffers.juno.com/TGL3131/59b7912c5c17d112c4c04st03vuc From gerlando.falauto at gmail.com Tue Sep 12 04:21:10 2017 From: gerlando.falauto at gmail.com (gerlando.falauto at gmail.com) Date: Tue, 12 Sep 2017 01:21:10 -0700 (PDT) Subject: array.array()'s memory shared with multiprocessing.Process() In-Reply-To: References: <27b84429-2a3f-4bfd-921e-13ede1f3d383@googlegroups.com> <25368303-5a50-e35a-dbe0-04de800e94f3@mrabarnett.plus.com> <8cfebb15-38db-48ee-9090-8961974ba6e0@googlegroups.com> <5fb8977c-e0e3-7d95-6d23-ba133806500f@mrabarnett.plus.com> <03ac60ca-4906-48aa-b6e8-8c5913dcfe19@googlegroups.com> <4d718833-1f89-497a-3844-1e26c592b232@tjol.eu> Message-ID: Il giorno luned? 11 settembre 2017 12:19:27 UTC+2, Thomas Jollans ha scritto: > On 2017-09-10 23:05, iurly wrote: > > As far as I'm concerned, I'm probably better off using double buffers to avoid this kind of issues. > > Thanks a lot for your help! > > > > > That should work. Some other things to consider, if both processes are > on the same machine, are a series of memory-mapped files to pass the > data without pickling, or, if your code is only going to run on Unix, > something involving shared memory through multiprocessing.Array. Oh, I see, multiprocessing.Array() sounds like a pretty good idea, thanks! It's simple enough and actually already compatible with what I'm doing. That would involve double buffers which I would have to use as the first optimization step anyway. Notice however how I'd have to create those Arrays dynamically in the producer thread. Would I then be able to pass them to the consumer by putting a reference in a queue? I wouldn't want them to be pickled at all in that case, of course. Also, why do you say it only works on Unix? I couldn't find any reference to such limitation in the documentation. Thank you so much again! From tjol at tjol.eu Tue Sep 12 04:47:22 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 12 Sep 2017 10:47:22 +0200 Subject: array.array()'s memory shared with multiprocessing.Process() In-Reply-To: References: <27b84429-2a3f-4bfd-921e-13ede1f3d383@googlegroups.com> <25368303-5a50-e35a-dbe0-04de800e94f3@mrabarnett.plus.com> <8cfebb15-38db-48ee-9090-8961974ba6e0@googlegroups.com> <5fb8977c-e0e3-7d95-6d23-ba133806500f@mrabarnett.plus.com> <03ac60ca-4906-48aa-b6e8-8c5913dcfe19@googlegroups.com> <4d718833-1f89-497a-3844-1e26c592b232@tjol.eu> Message-ID: <80692024-9ac4-fcb8-54bd-5899751ee0c6@tjol.eu> On 12/09/17 10:21, gerlando.falauto at gmail.com wrote: > Il giorno luned? 11 settembre 2017 12:19:27 UTC+2, Thomas Jollans ha scritto: >> On 2017-09-10 23:05, iurly wrote: >>> As far as I'm concerned, I'm probably better off using double buffers to avoid this kind of issues. >>> Thanks a lot for your help! >>> >> >> That should work. Some other things to consider, if both processes are >> on the same machine, are a series of memory-mapped files to pass the >> data without pickling, or, if your code is only going to run on Unix, >> something involving shared memory through multiprocessing.Array. > Oh, I see, multiprocessing.Array() sounds like a pretty good idea, thanks! > It's simple enough and actually already compatible with what I'm doing. > That would involve double buffers which I would have to use as the first optimization step anyway. > > Notice however how I'd have to create those Arrays dynamically in the producer thread. Would I then be able to pass them to the consumer by putting a reference in a queue? I wouldn't want them to be pickled at all in that case, of course. > > Also, why do you say it only works on Unix? I couldn't find any reference to such limitation in the documentation. I'm not sure actually. Maybe someone else here can help. I have a hunch that on Windows the memory might not be shared in the same way that it would on Linux/Unix, since Windows simply doesn't have the same process forking capabilities as Unix. This stack overflow question appears to be in agree with that hunch, but I can't judge whether something else isn't going wrong there: https://stackoverflow.com/questions/35239168/multiprocessing-shared-array-variable-windows-is-not-updated-in-the-process If the consumer process is always working from the same shared buffer, then you don't have to pass any data through the queue at all! (Or, if you have a small number of shared buffers, just tell the consumer which one to look at) You do have to somehow guarantee that the producer thread doesn't overwrite the buffer while it is being processed, of course. I'll let you be the judge of how well this kind of scheme would work for your data processing and acquisition rates. > > Thank you so much again! -- Thomas Jollans From stephanh42 at gmail.com.invalid Tue Sep 12 04:50:46 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 12 Sep 2017 08:50:46 GMT Subject: array.array()'s memory shared with multiprocessing.Process() References: <27b84429-2a3f-4bfd-921e-13ede1f3d383@googlegroups.com> <25368303-5a50-e35a-dbe0-04de800e94f3@mrabarnett.plus.com> <8cfebb15-38db-48ee-9090-8961974ba6e0@googlegroups.com> <5fb8977c-e0e3-7d95-6d23-ba133806500f@mrabarnett.plus.com> <03ac60ca-4906-48aa-b6e8-8c5913dcfe19@googlegroups.com> <4d718833-1f89-497a-3844-1e26c592b232@tjol.eu> Message-ID: Op 2017-09-12, gerlando.falauto at gmail.com schreef : > Notice however how I'd have to create those Arrays dynamically in the > producer thread. Would I then be able to pass them to the consumer by > putting a reference in a queue? Yes. > I wouldn't want them to be pickled at all in that case, of course. Essentially only an address pointing into a piece of shared memory is pickled and transmitted then. > Also, why do you say it only works on Unix? I couldn't find any > reference to such limitation in the documentation. There is no such limitation. It's supposed to work on all platforms (including Windows). Stephan From tjol at tjol.eu Tue Sep 12 05:05:25 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 12 Sep 2017 11:05:25 +0200 Subject: Fw: Problems Installing Python36 In-Reply-To: <20170912.034647.1218.0@webmail04.vgs.untd.com> References: <20170912.034647.1218.0@webmail04.vgs.untd.com> Message-ID: <6278c207-2744-5603-b983-6d73c451714f@tjol.eu> On 12/09/17 09:46, rdb.mb at juno.com wrote: > I have subscribed to the Python List as directed.Below is my information request re-submitted. Thank you. > ---------- Forwarded Message ---------- > From: "rdb.mb at juno.com" > To: python-list at python.org > Subject: Problems Installing Python36 > Date: Tue, 12 Sep 2017 01:35:11 GMT > > > I am having difficulty executing Python-3.6.2-amd64.exe. > > I am able to install it successfully, but each time Python36 fails to execute. The error message returned is: > > “The program can’t start because api-ms-win-crt-runtime-|1-1-0.dll is missing from your computer. Try reinstalling the program to fix this problem." > Are you up-to-date with Windows Updates? If not, installing all available updates might help. In any case, I think installing https://support.microsoft.com/en-us/help/2999226/update-for-universal-c-runtime-in-windows should do the trick. (But this should be really installed from Windows Update!) Other people on this list: This isn't the first time I've someone with this issue here. It's probably putting off plenty of potential new users who don't make as much effort to find a solution. I can't say I understand the ins and outs of installing things on Windows... is there anything that can be done? Best, Thomas > I have tried repeatedly to install various Python versions (32-bit or 64-bit), but the same error occurs. Is it possibly related to either Windows Paths or to conflicts with other Python compilers/interpreters embedded in programs such as OpenOffice 3 and GNU Gimp 2? > > I am using an ASUS laptop with an Intel Pentium CPU B970 @ 2.30 Hz, dual 64-bit cores, running Windows 7 Home Premium, Service Pack 1. > > Each time I ran the Installer as the System Administrator and I checked the boxes labeled: “Install launcher for all users,” and “Add Python 3.6 to PATH,” which appear to have been incorporated properly. > > With the material from Python.org about “get-pip.py” and the “Virtual Environment,” I succeeded in activating/deactivating “venv,” but not “get-pip.py” because Python36 will not execute. > > Can you please tell me what I am doing wrong. I would appreciate any help that you can give me in getting Python installed. > > Thank you for your assistance in this matter. > > > Respectively yours, > > Randolph Bracey > Myrtle Beach, SC > > > ____________________________________________________________ > Doctor Reveals 3 "Death Foods" You Need To Avoid This Summer > Nucific > http://thirdpartyoffers.juno.com/TGL3131/59b7912c5c17d112c4c04st03vuc -- Thomas Jollans From lkrupp at nospam.pssw.com.invalid Tue Sep 12 05:44:28 2017 From: lkrupp at nospam.pssw.com.invalid (Louis Krupp) Date: Tue, 12 Sep 2017 03:44:28 -0600 Subject: Fw: Problems Installing Python36 References: <20170912.034647.1218.0@webmail04.vgs.untd.com> Message-ID: On Tue, 12 Sep 2017 07:46:47 GMT, "rdb.mb at juno.com" wrote: >I have subscribed to the Python List as directed.Below is my information request re-submitted. Thank you. >---------- Forwarded Message ---------- >From: "rdb.mb at juno.com" >To: python-list at python.org >Subject: Problems Installing Python36 >Date: Tue, 12 Sep 2017 01:35:11 GMT > > >I am having difficulty executing Python-3.6.2-amd64.exe. > >I am able to install it successfully, but each time Python36 fails to execute. The error message returned is: > >“The program can’t start because api-ms-win-crt-runtime-|1-1-0.dll is missing from your computer. Try reinstalling the program to fix this problem." > >I have tried repeatedly to install various Python versions (32-bit or 64-bit), but the same error occurs. Is it possibly related to either Windows Paths or to conflicts with other Python compilers/interpreters embedded in programs such as OpenOffice 3 and GNU Gimp 2? > >I am using an ASUS laptop with an Intel Pentium CPU B970 @ 2.30 Hz, dual 64-bit cores, running Windows 7 Home Premium, Service Pack 1. > >Each time I ran the Installer as the System Administrator and I checked the boxes labeled: “Install launcher for all users,” and “Add Python 3.6 to PATH,” which appear to have been incorporated properly. > >With the material from Python.org about “get-pip.py” and the “Virtual Environment,” I succeeded in activating/deactivating “venv,” but not “get-pip.py” because Python36 will not execute. > >Can you please tell me what I am doing wrong. I would appreciate any help that you can give me in getting Python installed. > >Thank you for your assistance in this matter. A Google search for "api-ms-win-crt-runtime-l1-1-0.dll missing" turned up a bunch of resuts. One of those might help you. Louis From stephanh42 at gmail.com.invalid Tue Sep 12 06:06:59 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 12 Sep 2017 10:06:59 GMT Subject: array.array()'s memory shared with multiprocessing.Process() References: <27b84429-2a3f-4bfd-921e-13ede1f3d383@googlegroups.com> <25368303-5a50-e35a-dbe0-04de800e94f3@mrabarnett.plus.com> <8cfebb15-38db-48ee-9090-8961974ba6e0@googlegroups.com> <5fb8977c-e0e3-7d95-6d23-ba133806500f@mrabarnett.plus.com> <03ac60ca-4906-48aa-b6e8-8c5913dcfe19@googlegroups.com> <4d718833-1f89-497a-3844-1e26c592b232@tjol.eu> <80692024-9ac4-fcb8-54bd-5899751ee0c6@tjol.eu> Message-ID: Op 2017-09-12, Thomas Jollans schreef : > I'm not sure actually. Maybe someone else here can help. I have a hunch > that on Windows the memory might not be shared in the same way that it > would on Linux/Unix, since Windows simply doesn't have the same process > forking capabilities as Unix. `multiprocessing` is not relying on the POSIX "inherit an anonymous mmap()" semantics to get a piece of memory shared across processes. 1. On Windows, it uses the Windows-specific functionality to associate a tagname with an mmap and open the specific mmap by tagname. 2. On Posix platforms, it creates a file which is opened and immediately unlink()-ed, and the file descriptor is communicated to the child process using a UNIX-domain socket. Stephan From leamhall at gmail.com Tue Sep 12 07:20:34 2017 From: leamhall at gmail.com (Leam Hall) Date: Tue, 12 Sep 2017 07:20:34 -0400 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> Message-ID: <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> On 09/12/2017 12:29 AM, Chris Angelico wrote: > On Tue, Sep 12, 2017 at 1:42 PM, Paul Rubin wrote: >> Chris Angelico writes: >>> students learning Python *today* ... they're learning Python 3. >> >> I'm not so sure of that. I do know a few people currently learning >> Python, and they're using Python 2. > > Why? Unless they're going to be maintaining a Py2 codebase, why should > they learn the older version with less features? > > At Thinkful (shameless plug[1]), students learn Python 3 almost > exclusively (we do have a data science course in which students learn > either or both, but in the web dev course, it's definitely Py3). I > haven't had anyone run into difficulties with annotations/type hints > (we don't teach them, so how would they be bothered?), print being a > function (everything else is a function so it's no surprise that print > is too), etc, and even the text/bytes split is only a problem when > students are working with non-ASCII data files provided by third > parties, at which point they have to learn about encoding="...". Now, > I just need to convince people to stop putting "first name" and > "surname" fields on their web forms [2], and things will be about > perfect... > > ChrisA > > [1] I teach via www.thinkful.com. My views are my own, not that of my employer. > [2] http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ > Hey Chris, This is an area the Python community can improve on. Even I would encourage someone new to Python and wanting to do webdev to use Python 3. But if someone comes onto the list, or IRC, and says they need to stay on Python 2 then please drop the dozens of e-mails and comments about upgrading. Help the person learn; that makes them happier with Python and when the time comes to switch to Python 3 they probably will. My recent experience with some people's inability to take "Sorry, I can't" for an answer has been a real turn-off. I have requirements that dictate Python. If this was a personal venture I'd already be elsewhere purely because the Python community on the list and IRC is so unwelcoming. I encourage those of you who are Python experts, trainers, or authors: lead by example. Help people learn Python. Grow the community. Just because TIOBE and IEEE say Python is top dog today doesn't mean those stats can't change. The community will drive the success of Python, not the technical features. Leam From rosuav at gmail.com Tue Sep 12 07:27:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Sep 2017 21:27:11 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> Message-ID: On Tue, Sep 12, 2017 at 9:20 PM, Leam Hall wrote: > Hey Chris, > > This is an area the Python community can improve on. Even I would encourage > someone new to Python and wanting to do webdev to use Python 3. > > But if someone comes onto the list, or IRC, and says they need to stay on > Python 2 then please drop the dozens of e-mails and comments about > upgrading. Help the person learn; that makes them happier with Python and > when the time comes to switch to Python 3 they probably will. If you read back in my emails, you may find that I actually wasn't telling you to upgrade to Python 3 - just to Python 2.7, which is an easy upgrade from 2.6, and gives you the security fixes and other improvements that come from using a supported version of the language. Is it "hostile" to tell people to upgrade like that? If someone is using Python 3.2 today, I'm going to strongly recommend upgrading to the latest 3.x. If someone's using Windows 98, I'm not going to say "well, here's how to get everything working under Win98", I'm going to say "upgrade to a better OS". If that's hostile, I am not sorry to be hostile. At some point, you have to either get onto something supported, or do all the support work yourself. ChrisA From leamhall at gmail.com Tue Sep 12 07:34:16 2017 From: leamhall at gmail.com (Leam Hall) Date: Tue, 12 Sep 2017 07:34:16 -0400 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> Message-ID: On 09/12/2017 07:27 AM, Chris Angelico wrote: > On Tue, Sep 12, 2017 at 9:20 PM, Leam Hall wrote: >> Hey Chris, >> >> This is an area the Python community can improve on. Even I would encourage >> someone new to Python and wanting to do webdev to use Python 3. >> >> But if someone comes onto the list, or IRC, and says they need to stay on >> Python 2 then please drop the dozens of e-mails and comments about >> upgrading. Help the person learn; that makes them happier with Python and >> when the time comes to switch to Python 3 they probably will. > > If you read back in my emails, you may find that I actually wasn't > telling you to upgrade to Python 3 - just to Python 2.7, which is an > easy upgrade from 2.6, and gives you the security fixes and other > improvements that come from using a supported version of the language. > Is it "hostile" to tell people to upgrade like that? If someone is > using Python 3.2 today, I'm going to strongly recommend upgrading to > the latest 3.x. If someone's using Windows 98, I'm not going to say > "well, here's how to get everything working under Win98", I'm going to > say "upgrade to a better OS". > > If that's hostile, I am not sorry to be hostile. At some point, you > have to either get onto something supported, or do all the support > work yourself. > > ChrisA > Hey Chris; only some folks were overtly hostile. :) Yet look at your answer; "upgrade". For a person working on a server there's usually no economic choice to do. The OS python must stay in place and the newly installed upgrade must be personally maintained, updated, and tested when security patches come out. For one desktop that's not an issue. For dozens, or hundreds, or thousands, its not likely to happen. I stand by my position; accept the "no" and move forward. Let "no" mean "no". Leam From rosuav at gmail.com Tue Sep 12 07:40:30 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Sep 2017 21:40:30 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> Message-ID: On Tue, Sep 12, 2017 at 9:34 PM, Leam Hall wrote: > On 09/12/2017 07:27 AM, Chris Angelico wrote: >> >> On Tue, Sep 12, 2017 at 9:20 PM, Leam Hall wrote: >>> >>> Hey Chris, >>> >>> This is an area the Python community can improve on. Even I would >>> encourage >>> someone new to Python and wanting to do webdev to use Python 3. >>> >>> But if someone comes onto the list, or IRC, and says they need to stay on >>> Python 2 then please drop the dozens of e-mails and comments about >>> upgrading. Help the person learn; that makes them happier with Python and >>> when the time comes to switch to Python 3 they probably will. >> >> >> If you read back in my emails, you may find that I actually wasn't >> telling you to upgrade to Python 3 - just to Python 2.7, which is an >> easy upgrade from 2.6, and gives you the security fixes and other >> improvements that come from using a supported version of the language. >> Is it "hostile" to tell people to upgrade like that? If someone is >> using Python 3.2 today, I'm going to strongly recommend upgrading to >> the latest 3.x. If someone's using Windows 98, I'm not going to say >> "well, here's how to get everything working under Win98", I'm going to >> say "upgrade to a better OS". >> >> If that's hostile, I am not sorry to be hostile. At some point, you >> have to either get onto something supported, or do all the support >> work yourself. >> >> ChrisA >> > > Hey Chris; only some folks were overtly hostile. :) > > Yet look at your answer; "upgrade". For a person working on a server there's > usually no economic choice to do. The OS python must stay in place and the > newly installed upgrade must be personally maintained, updated, and tested > when security patches come out. For one desktop that's not an issue. For > dozens, or hundreds, or thousands, its not likely to happen. Until you get hit by a vulnerability that was patched four years ago, but you didn't get the update. Now your server is down - or, worse, has been compromised. What's the economic cost of that? You might choose to accept that risk, but you have to at least be aware that you're playing with fire. Laziness is not the cheap option in the long run. ChrisA From stephanh42 at gmail.com.invalid Tue Sep 12 08:04:37 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 12 Sep 2017 12:04:37 GMT Subject: Fw: Problems Installing Python36 References: <20170912.034647.1218.0@webmail04.vgs.untd.com> <6278c207-2744-5603-b983-6d73c451714f@tjol.eu> Message-ID: Op 2017-09-12, Thomas Jollans schreef : > This isn't the first time I've someone with this issue here. It's > probably putting off plenty of potential new users who don't make as > much effort to find a solution. I can't say I understand the ins and > outs of installing things on Windows... is there anything that can be done? I just added issue 31427 on the Python bug tracker proposing adding this to the Windows FAQ. Stephan From steve+python at pearwood.info Tue Sep 12 08:07:21 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 12 Sep 2017 22:07:21 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> Message-ID: <59b7cdfe$0$16759$b1db1813$d948b532@news.astraweb.com> On Tue, 12 Sep 2017 09:40 pm, Chris Angelico wrote: [...] >> Yet look at your answer; "upgrade". For a person working on a server there's >> usually no economic choice to do. The OS python must stay in place and the >> newly installed upgrade must be personally maintained, updated, and tested >> when security patches come out. For one desktop that's not an issue. For >> dozens, or hundreds, or thousands, its not likely to happen. > > Until you get hit by a vulnerability that was patched four years ago, > but you didn't get the update. Now your server is down - or, worse, > has been compromised. What's the economic cost of that? Chris, that's what your subscription to RHEL pays for: backports of security fixes that the free Python 2.6 doesn't contain. You'll probably get them on Centos and Fedora too, the community editions of RHEL. You *won't* get them from the Python website. That's the whole point of the ten year support for RHEL (longer if you pay more). > You might choose to accept that risk, but you have to at least be > aware that you're playing with fire. Laziness is not the cheap option > in the long run. You're making unjustified assumptions about the attack surface here. Maybe any attacker has to break through three firewalls *and* get root on the server before they can attack the Python app -- in which case they've got bigger problems than the Python vulnerability. It's one thing to mention in a friendly way the advantages of upgrading. It's another to continue to brow-beat the poster about the (supposed) necessity to give up their paid RHEL support and security patches in favour of taking their chances with the free, but more recent, version where they have to monitor the Python website or mailing lists themselves and manually upgrade each time there's an security patch. Feel free to continue to talk in general terms about the costs and benefits of upgrading, but stop badgering Leam. Not everyone values being on the bleeding edge, and Red Hat customers as a rule value stability and long term support over the latest shiny new features. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From leamhall at gmail.com Tue Sep 12 08:16:18 2017 From: leamhall at gmail.com (Leam Hall) Date: Tue, 12 Sep 2017 08:16:18 -0400 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <59b7cdfe$0$16759$b1db1813$d948b532@news.astraweb.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> <59b7cdfe$0$16759$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve, Thank you very much. I appreciate your wisdom and support. Leam From ned at nedbatchelder.com Tue Sep 12 08:21:49 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 12 Sep 2017 08:21:49 -0400 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> Message-ID: <8edc0f13-5b38-a334-d6f6-308ee14f70c2@nedbatchelder.com> On 9/12/17 7:40 AM, Chris Angelico wrote: > On Tue, Sep 12, 2017 at 9:34 PM, Leam Hall wrote: >> On 09/12/2017 07:27 AM, Chris Angelico wrote: >>> On Tue, Sep 12, 2017 at 9:20 PM, Leam Hall wrote: >>>> Hey Chris, >>>> >>>> This is an area the Python community can improve on. Even I would >>>> encourage >>>> someone new to Python and wanting to do webdev to use Python 3. >>>> >>>> But if someone comes onto the list, or IRC, and says they need to stay on >>>> Python 2 then please drop the dozens of e-mails and comments about >>>> upgrading. Help the person learn; that makes them happier with Python and >>>> when the time comes to switch to Python 3 they probably will. >>> >>> If you read back in my emails, you may find that I actually wasn't >>> telling you to upgrade to Python 3 - just to Python 2.7, which is an >>> easy upgrade from 2.6, and gives you the security fixes and other >>> improvements that come from using a supported version of the language. >>> Is it "hostile" to tell people to upgrade like that? If someone is >>> using Python 3.2 today, I'm going to strongly recommend upgrading to >>> the latest 3.x. If someone's using Windows 98, I'm not going to say >>> "well, here's how to get everything working under Win98", I'm going to >>> say "upgrade to a better OS". >>> >>> If that's hostile, I am not sorry to be hostile. At some point, you >>> have to either get onto something supported, or do all the support >>> work yourself. >>> >>> ChrisA >>> >> Hey Chris; only some folks were overtly hostile. :) >> >> Yet look at your answer; "upgrade". For a person working on a server there's >> usually no economic choice to do. The OS python must stay in place and the >> newly installed upgrade must be personally maintained, updated, and tested >> when security patches come out. For one desktop that's not an issue. For >> dozens, or hundreds, or thousands, its not likely to happen. > Until you get hit by a vulnerability that was patched four years ago, > but you didn't get the update. Now your server is down - or, worse, > has been compromised. What's the economic cost of that? > > You might choose to accept that risk, but you have to at least be > aware that you're playing with fire. Laziness is not the cheap option > in the long run. > > ChrisA Leam has done us the favor of explaining how this list feels to people coming into it. We should take his point of view seriously.? You are still arguing about whether software should be upgraded.? Maybe it should be, but it wasn't was the OP was asking about.? The OP probably also isn't saving enough for retirement, and it's good advice to save more, but it's not what they were asking about.? How far afield from the actual question is it OK to offer unsolicited advice before it comes off as hostile? Apparently we crossed the line on this question. --Ned. --Ned. From rosuav at gmail.com Tue Sep 12 08:26:17 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Sep 2017 22:26:17 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <8edc0f13-5b38-a334-d6f6-308ee14f70c2@nedbatchelder.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> <8edc0f13-5b38-a334-d6f6-308ee14f70c2@nedbatchelder.com> Message-ID: On Tue, Sep 12, 2017 at 10:21 PM, Ned Batchelder wrote: > On 9/12/17 7:40 AM, Chris Angelico wrote: >> On Tue, Sep 12, 2017 at 9:34 PM, Leam Hall wrote: >>> On 09/12/2017 07:27 AM, Chris Angelico wrote: >>>> On Tue, Sep 12, 2017 at 9:20 PM, Leam Hall wrote: >>>>> Hey Chris, >>>>> >>>>> This is an area the Python community can improve on. Even I would >>>>> encourage >>>>> someone new to Python and wanting to do webdev to use Python 3. >>>>> >>>>> But if someone comes onto the list, or IRC, and says they need to stay on >>>>> Python 2 then please drop the dozens of e-mails and comments about >>>>> upgrading. Help the person learn; that makes them happier with Python and >>>>> when the time comes to switch to Python 3 they probably will. >>>> >>>> If you read back in my emails, you may find that I actually wasn't >>>> telling you to upgrade to Python 3 - just to Python 2.7, which is an >>>> easy upgrade from 2.6, and gives you the security fixes and other >>>> improvements that come from using a supported version of the language. >>>> Is it "hostile" to tell people to upgrade like that? If someone is >>>> using Python 3.2 today, I'm going to strongly recommend upgrading to >>>> the latest 3.x. If someone's using Windows 98, I'm not going to say >>>> "well, here's how to get everything working under Win98", I'm going to >>>> say "upgrade to a better OS". >>>> >>>> If that's hostile, I am not sorry to be hostile. At some point, you >>>> have to either get onto something supported, or do all the support >>>> work yourself. >>>> >>>> ChrisA >>>> >>> Hey Chris; only some folks were overtly hostile. :) >>> >>> Yet look at your answer; "upgrade". For a person working on a server there's >>> usually no economic choice to do. The OS python must stay in place and the >>> newly installed upgrade must be personally maintained, updated, and tested >>> when security patches come out. For one desktop that's not an issue. For >>> dozens, or hundreds, or thousands, its not likely to happen. >> Until you get hit by a vulnerability that was patched four years ago, >> but you didn't get the update. Now your server is down - or, worse, >> has been compromised. What's the economic cost of that? >> >> You might choose to accept that risk, but you have to at least be >> aware that you're playing with fire. Laziness is not the cheap option >> in the long run. >> >> ChrisA > > Leam has done us the favor of explaining how this list feels to people > coming into it. We should take his point of view seriously. You are > still arguing about whether software should be upgraded. Maybe it > should be, but it wasn't was the OP was asking about. > > The OP probably also isn't saving enough for retirement, and it's good > advice to save more, but it's not what they were asking about. How far > afield from the actual question is it OK to offer unsolicited advice > before it comes off as hostile? Apparently we crossed the line on this > question. > Okay, I get the picture. Fine. You can stay on a version as old as you like - but I'm not going to help you with 2.6-specific issues. Fair? ChrisA From steve+python at pearwood.info Tue Sep 12 08:28:06 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 12 Sep 2017 22:28:06 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> Message-ID: <59b7d2d9$0$16748$b1db1813$d948b532@news.astraweb.com> On Tue, 12 Sep 2017 09:20 pm, Leam Hall wrote: > But if someone comes onto the list, or IRC, and says they need to stay > on Python 2 then please drop the dozens of e-mails and comments about > upgrading. [...] > My recent experience with some people's inability to take "Sorry, I > can't" for an answer has been a real turn-off. I have requirements that > dictate Python. If this was a personal venture I'd already be elsewhere > purely because the Python community on the list and IRC is so unwelcoming. Leam, I've defended people choosing to remain on older versions of Python, even as old as 1.5. The most recent was just a couple of minutes ago, in my response to Chris. It's not nice or friendly of you to tar the entire community with a reputation because of one or two people saying something you don't want to debate. But it isn't all about you. Just because you started this thread -- oh wait, you didn't *wink* -- doesn't mean you control its direction. If people want to discuss the pros and cons of upgrading, without specifically badgering you, you should remember that *it isn't about you* and don't take it personally. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From mail at timgolden.me.uk Tue Sep 12 08:28:19 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 12 Sep 2017 13:28:19 +0100 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> Message-ID: On 12/09/2017 12:20, Leam Hall wrote: > This is an area the Python community can improve on. Even I would > encourage someone new to Python and wanting to do webdev to use Python 3. > > But if someone comes onto the list, or IRC, and says they need to stay > on Python 2 then please drop the dozens of e-mails and comments about > upgrading. Help the person learn; that makes them happier with Python > and when the time comes to switch to Python 3 they probably will. > > My recent experience with some people's inability to take "Sorry, I > can't" for an answer has been a real turn-off. I have requirements that > dictate Python. If this was a personal venture I'd already be elsewhere > purely because the Python community on the list and IRC is so unwelcoming. I agree. Except for the unusual case where someone's mistakenly chosen to use, eg, Python 2.4 because they're using an old text book which mentions it as the current version, most people are using the version which suits them for one reason or another. And, if I may put my 2.5p-worth in here, they're probably using the operating system which suits them. (Maybe because their employer has said so, or because they're familiar or whatever). So saying, as people occasionally do, "Upgrade to Linux", even with half-a-wink, is not really that funny or helpful. That said, my experience of this list and other Python forums is that we don't do *too* badly at being friendly. However, what we do suffer from is an excess of technical helpfulness. In principle it's a good thing, but it can give rise to solving a problem with the OP doesn't have. One example of which is: over-egging the advantages of Python 3. ("How do I do X in Python 2.7?" "Why aren't you using Python 3"). Another might be: suggesting a toolkit they're not using. ("How do I use Tkinter to do blah?" "Use Pygame; it's much better"). Of course, such advice can certainly be helpful, eg pointing out the advantages of requests over urllib2 etc. But trying to answer their question as well as pointing out possible alternatives is probably more friendly. TJG From mail at timgolden.me.uk Tue Sep 12 08:39:41 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 12 Sep 2017 13:39:41 +0100 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> Message-ID: <8616f66f-b55a-d76a-8e45-f210d5b7c71f@timgolden.me.uk> On 12/09/2017 12:20, Leam Hall wrote: > But if someone comes onto the list, or IRC, and says they need to stay > on Python 2 then please drop the dozens of e-mails and comments about > upgrading. (Just spotted this quoted by Steven D'Aprano). Another factor of course is that people are reading and interacting with the list/newsgroup in many different ways, and so what appears as a pile-on almost certainly isn't (as such). It's the common reaction of a number of probably unconnected people with a similar mindset. Obviously Leam's point is still valid: it looks like a wall of unwanted advice. But I wanted to defend "The List" (or "The Newsgroup") which of course is just a load of different people. TJG From leamhall at gmail.com Tue Sep 12 08:47:59 2017 From: leamhall at gmail.com (Leam Hall) Date: Tue, 12 Sep 2017 08:47:59 -0400 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <59b7d2d9$0$16748$b1db1813$d948b532@news.astraweb.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> <59b7d2d9$0$16748$b1db1813$d948b532@news.astraweb.com> Message-ID: On 09/12/2017 08:28 AM, Steve D'Aprano wrote: > On Tue, 12 Sep 2017 09:20 pm, Leam Hall wrote: > >> But if someone comes onto the list, or IRC, and says they need to stay >> on Python 2 then please drop the dozens of e-mails and comments about >> upgrading. > [...] >> My recent experience with some people's inability to take "Sorry, I >> can't" for an answer has been a real turn-off. I have requirements that >> dictate Python. If this was a personal venture I'd already be elsewhere >> purely because the Python community on the list and IRC is so unwelcoming. > > Leam, I've defended people choosing to remain on older versions of Python, even > as old as 1.5. The most recent was just a couple of minutes ago, in my response > to Chris. It's not nice or friendly of you to tar the entire community with a > reputation because of one or two people saying something you don't want to > debate. > > But it isn't all about you. Just because you started this thread -- oh wait, you > didn't *wink* -- doesn't mean you control its direction. If people want to > discuss the pros and cons of upgrading, without specifically badgering you, you > should remember that *it isn't about you* and don't take it personally. WHAT?!?!?! It isn't all about me? Dang... Steve, you're right; sorry for painting with such a broad brush. Even the people who occasionally post something that seems problematic (to me) are usually helpful. A few months ago my manager asked about what direction I recommended for the team. I'm the opinionated old guy who is new to this team. At the time I was really enjoying Ruby; just so dang fun! I told my manager that we should use python. It is the best choice for the team since we're on RHEL 6. Ruby wasn't on the machines but Python 2.6.6 is. Any code I write that is python 2.6.6 compatible should run on every machine. My answer meant I had to re-direct personal time and attention so I could help the team move forward. There are certain things I can do; learn to code better, write more tests, and figure out OOP. Some things I can't do; changing the supported python version is on that list. Python is the right choice for a lot of use cases. Python 3 is the right choice for a large sub-set of those use cases. Python 2 is the best choice for a much smaller subset. From stephanh42 at gmail.com.invalid Tue Sep 12 08:55:55 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 12 Sep 2017 12:55:55 GMT Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> Message-ID: Op 2017-09-12, Tim Golden schreef : > I agree. Except for the unusual case where someone's mistakenly chosen > to use, eg, Python 2.4 because they're using an old text book which > mentions it as the current version, most people are using the version > which suits them for one reason or another. If it is not clear from the original post that they are consciously using an old version, I will often try to politely suggest they use the latest version (i.e. "If there is no particular reason for you to use Python 1.5.2, may I suggest that you use 3.6 instead?"). The reason is that: * On many operating systems, just typing "python" will give you Python2.7 at best (e.g. macOS!). And the OP may not be aware that there are more recent versions. * In businesses, it is especially common to run on some RHEL version $ANCIENT; not so long ago I had a machine where typing "python" presented me with Python 2.3! I agree that *badgering* them about it (as opposed to suggesting it *once*) is a bad idea. > And, if I may put my 2.5p-worth in here, they're probably using the > operating system which suits them. (Maybe because their employer has > said so, or because they're familiar or whatever). So saying, as people > occasionally do, "Upgrade to Linux", even with half-a-wink, is not > really that funny or helpful. It's not really the same, though. Changing the OS is a big undertaking and affects all their programs, just installing version 3.6 of Python as a private user shouldn't affect anything else. You can install python in your home directory on your ancient RHEL box and leave the system Python happily at 2.3. I nowadays typically never bother with the system Python for my own development and just install a recent version of my choice locally. It saves a lot of headaches. The system Python is there to run system programs. Stephan From robin at reportlab.com Tue Sep 12 09:05:33 2017 From: robin at reportlab.com (Robin Becker) Date: Tue, 12 Sep 2017 14:05:33 +0100 Subject: windows 8 versus urllib2 certificate verify In-Reply-To: <8760co1i9d.fsf@handshake.de> References: <2a26c97e-14ca-4c5d-e8c4-c3e3c7bcb2cb@chamonix.reportlab.co.uk> <8760co1i9d.fsf@handshake.de> Message-ID: <03715f54-08d8-3d64-0597-2ff61a5e46ce@chamonix.reportlab.co.uk> On 12/09/2017 08:35, dieter wrote: > Robin Becker writes: > Certificate verification generally depends on local configuration: > specifically, the set of installed trusted root certificates. > > I do not know about Windows, but often the root certificates installed > for other packages, e.g. the browser, are used. And different > versions of the same package may install different sets of trusted > certificates. It might also be that your new environment lacks > one of the packages from your old environment - and it has provided > the required root certificate. > > > Of course, the problem might also be caused by a general problem. > Try to access a "common" https site via urllib2, one you do not have > any problems to connect with a browser (or another "http" utility > like "wget" or "curl") from the same machines. > If this works, the problem is assiciated with the specific certificate. > The certs are fine at least in all the browsers I have access to. It's pretty hard to use the python that's built in to a pyinstaller exe so I have used the certifi method and passed certifi.where() into the urlopen calls. That seems to work, but obviously if the compiled in root certs become too old problems will recur. -- Robin Becker From p.f.moore at gmail.com Tue Sep 12 09:20:56 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 12 Sep 2017 14:20:56 +0100 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> <59b7d2d9$0$16748$b1db1813$d948b532@news.astraweb.com> Message-ID: On 12 September 2017 at 13:47, Leam Hall wrote: > A few months ago my manager asked about what direction I recommended for the > team. I'm the opinionated old guy who is new to this team. At the time I was > really enjoying Ruby; just so dang fun! > > I told my manager that we should use python. It is the best choice for the > team since we're on RHEL 6. Ruby wasn't on the machines but Python 2.6.6 is. > Any code I write that is python 2.6.6 compatible should run on every > machine. > > My answer meant I had to re-direct personal time and attention so I could > help the team move forward. There are certain things I can do; learn to code > better, write more tests, and figure out OOP. Some things I can't do; > changing the supported python version is on that list. > > Python is the right choice for a lot of use cases. Python 3 is the right > choice for a large sub-set of those use cases. Python 2 is the best choice > for a much smaller subset. Sounds like a very reasonable decision - I'm in a similar situation at times, and I agree with your recommendation. Python's a great tool, and if you like Ruby you should find it really easy to get into. As you say, if Ruby isn't available on the machines you're working with, the hurdle of getting it installed is likely a real blocker. Having Python installed makes it a good choice - and sticking with the installed version is definitely correct, otherwise you're no better off than you were with a language that's not installed by default. One thing you will have to deal with is that there's a lot less support available for Python 2.6 these days - most developers working with Python 2 will use 2.7, and new developers will typically pick Python 3 if at all possible. For a lot of things, you're relying on community support, which does mean you are "stuck" with what people are enthusiastic about. But the good news is that most advice you'll get is transferrable back to Python 2.6 (with a little care, particularly if it was originally for Python 3). And it's important to remember that community support is just that - individuals, offering help simply because they love Python. And those individuals are typically (in most communities, not just Python) early adopters, and strongly prefer working with the latest versions. The biggest hurdle you may hit is that 3rd party libraries are starting to drop support of Python 2.6. I don't know if you expect to use libraries from PyPI - in my environment, the systems that are locked to Python 2.6 are typically not connected to the internet, so non-stdlib code is generally not accessible - if that's the case for you this won't be an issue. Unfortunately, there's not much you can do about that - it's just one of the issues of working with older, unsupported versions. But a big plus with Python is that the stdlib is very comprehensive (less so with 2.6 than 3.6, but still very good in 2.6). So where you'd need to rely on external libraries for other languages, you can do an awful lot with a base 2.6 install. That's a big selling point in a locked down environment. Anyway, I'm not sure there's much specific here. But thanks for taking the time to explain your situation, which hopefully will act as a reminder that not everyone trying to promote Python has a clean slate to work with. Paul From rantingrickjohnson at gmail.com Tue Sep 12 10:11:04 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Sep 2017 07:11:04 -0700 (PDT) Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <59b7cdfe$0$16759$b1db1813$d948b532@news.astraweb.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> <59b7cdfe$0$16759$b1db1813$d948b532@news.astraweb.com> Message-ID: <5ad165e7-7900-4b14-8691-e49c812ddf01@googlegroups.com> Steve D'Aprano wrote: > Chris Angelico wrote: > > [...] > > > > > > Yet look at your answer; "upgrade". For a person working > > > on a server there's usually no economic choice to do. The > > > OS python must stay in place and the newly installed > > > upgrade must be personally maintained, updated, and > > > tested when security patches come out. For one desktop > > > that's not an issue. For dozens, or hundreds, or > > > thousands, its not likely to happen. > > > > Until you get hit by a vulnerability that was patched four > > years ago, but you didn't get the update. Now your server > > is down - or, worse, has been compromised. What's the > > economic cost of that? > > Chris, that's what your subscription to RHEL pays for: > backports of security fixes that the free Python 2.6 > doesn't contain. You'll probably get them on Centos and > Fedora too, the community editions of RHEL. You *won't* get > them from the Python website. That's the whole point of the > ten year support for RHEL (longer if you pay more). > > > > > You might choose to accept that risk, but you have to at > > least be aware that you're playing with fire. Laziness is > > not the cheap option in the long run. > > You're making unjustified assumptions about the attack > surface here. Maybe any attacker has to break through three > firewalls *and* get root on the server before they can > attack the Python app -- in which case they've got bigger > problems than the Python vulnerability. It's one thing to > mention in a friendly way the advantages of upgrading. > It's another to continue to brow-beat the poster about the > (supposed) necessity to give up their paid RHEL support and > security patches in favour of taking their chances with the > free, but more recent, version where they have to monitor > the Python website or mailing lists themselves and manually > upgrade each time there's an security patch. Feel free to > continue to talk in general terms about the costs and > benefits of upgrading, but stop badgering Leam. Not > everyone values being on the bleeding edge, and Red Hat > customers as a rule value stability and long term support > over the latest shiny new features. Great reply! And nice to know that not every Pythonista here has gone tin-foil-hat crazy over Python3. From rantingrickjohnson at gmail.com Tue Sep 12 10:19:36 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Sep 2017 07:19:36 -0700 (PDT) Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> <8edc0f13-5b38-a334-d6f6-308ee14f70c2@nedbatchelder.com> Message-ID: On Tuesday, September 12, 2017 at 7:26:40 AM UTC-5, Chris Angelico wrote: [...] > Okay, I get the picture. Fine. You can stay on a version as > old as you like - but I'm not going to help you with > 2.6-specific issues. Fair? Chris, now you're just being a jerk. And while the decision whether or not to help Leam is totally yours, there is no need to broadcast your selfishness to the ends of the known universe. If you want to take your ball and go home, you certainly have that right, "Eric Theodore Cartman", but there is no need for you to throw verbal spears on the way out the door. From leamhall at gmail.com Tue Sep 12 10:41:38 2017 From: leamhall at gmail.com (leam hall) Date: Tue, 12 Sep 2017 10:41:38 -0400 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <59b7d2d9$0$16748$b1db1813$d948b532@news.astraweb.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> <59b7d2d9$0$16748$b1db1813$d948b532@news.astraweb.com> Message-ID: On Tue, Sep 12, 2017 at 8:28 AM, Steve D'Aprano wrote: > On Tue, 12 Sep 2017 09:20 pm, Leam Hall wrote: > > > But if someone comes onto the list, or IRC, and says they need to stay > > on Python 2 then please drop the dozens of e-mails and comments about > > upgrading. > [...] > > My recent experience with some people's inability to take "Sorry, I > > can't" for an answer has been a real turn-off. I have requirements that > > dictate Python. If this was a personal venture I'd already be elsewhere > > purely because the Python community on the list and IRC is so > unwelcoming. > > Leam, I've defended people choosing to remain on older versions of Python, > even > as old as 1.5. The most recent was just a couple of minutes ago, in my > response > to Chris. It's not nice or friendly of you to tar the entire community > with a > reputation because of one or two people saying something you don't want to > debate. > > But it isn't all about you. Just because you started this thread -- oh > wait, you > didn't *wink* -- doesn't mean you control its direction. If people want to > discuss the pros and cons of upgrading, without specifically badgering > you, you > should remember that *it isn't about you* and don't take it personally. > Steve, just a quick follow-up. Thank you for calling me out on this! It's wrong for me to do something I complain about others doing. Feel free to reach through the ether and smack me if I do this again. Leam From rantingrickjohnson at gmail.com Tue Sep 12 10:45:36 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Sep 2017 07:45:36 -0700 (PDT) Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <59b7d2d9$0$16748$b1db1813$d948b532@news.astraweb.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <09f7186a-427b-8d97-722b-ffc759908576@gmail.com> <59b7d2d9$0$16748$b1db1813$d948b532@news.astraweb.com> Message-ID: <6ab2480a-0df9-4e83-9f88-ff29345581f1@googlegroups.com> Steve D'Aprano wrote: > Leam Hall wrote: > > > But if someone comes onto the list, or IRC, and says they > > need to stay on Python 2 then please drop the dozens of > > e-mails and comments about upgrading. > [...] > > My recent experience with some people's inability to take > > "Sorry, I can't" for an answer has been a real turn-off. I > > have requirements that dictate Python. If this was a > > personal venture I'd already be elsewhere purely because > > the Python community on the list and IRC is so > > unwelcoming. > > Leam, I've defended people choosing to remain on older > versions of Python, even as old as 1.5. The most recent was > just a couple of minutes ago, in my response to Chris. It's > not nice or friendly of you to tar the entire community > with a reputation because of one or two people saying > something you don't want to debate. It is easy to forget that the attack dogs on this list (and over at Python-ideas) do not represent the opinion of the entire Python community. The majority of Python programmers never even participate on these forums, and the majority of those who _do_ participate, tend to follow along with the one-sided politics out of fear of loosing access to help. So i am not surprised that Leam has formed this opinion of the entire community based on the behavior of a small, but highly vocal and aggressive, minority. Chris is usually very knowledgable and helpful when he sticks to technical issues, but Python3 has flipped an emotional switch in his brain, and now he's on some sort of religious crusade, considering anyone who refuse to adopt Python3, as his mortal enemy. > But it isn't all about you. Just because you started this > thread -- oh wait, you didn't *wink* -- doesn't mean you > control its direction. If people want to discuss the pros > and cons of upgrading, without specifically badgering you, > you should remember that *it isn't about you* and don't > take it personally. True, but it would be more considerate to start a new thread titled: "Pros and Cons of Upgrading to Python3", at least that way, Leam wouldn't get the feeling that everyone has turned their backs and are talking about him while still in the same "room". Plus, there is the whole "stay on topic" thing to consider... From rantingrickjohnson at gmail.com Tue Sep 12 11:03:58 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Sep 2017 08:03:58 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: Chris Angelico wrote: > Rick Johnson wrote: > > Ruby: > > farray = [1.5, 1.9, 2.0, 1.0] > > uniqueIntegers = farray.map{|f| f.to_i()}.uniq.length > > > > Python: > > flist = [1.5, 1.9, 2.0, 1.0] > > uniqueIntegers = len(set(map(lambda f:int(f), flist))) > > Python: > > floats = [1.5, 1.9, 2.0, 1.0] > unique_integers = len(set(int(f) for f in floats)) > > or: > > unique_integers = len(set(map(int, floats)) > > If you're going to use Python, at least use it right. Okay, you've replaced my map function with an implicit list comprehension (aka: generator expression)... so how is either more "right" than the other? What is your justification that your example is "right", and mine is not? (1) Is is a speed issue? Then prove it. (2) Is it a readability issue? If so, then that's an opinion _you_ get to have. (3) Is a matter of "python purity"? If so, then map should be removed from the language. And don't forget to remove reduce and filter while you're at it. And then, you may want to grab a shield, because the functional fanboys will be all over you like white on rice! (4) Something else...? From rosuav at gmail.com Tue Sep 12 11:17:59 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Sep 2017 01:17:59 +1000 Subject: [Tutor] beginning to code In-Reply-To: References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: On Wed, Sep 13, 2017 at 1:03 AM, Rick Johnson wrote: > Chris Angelico wrote: >> Rick Johnson wrote: >> > Ruby: >> > farray = [1.5, 1.9, 2.0, 1.0] >> > uniqueIntegers = farray.map{|f| f.to_i()}.uniq.length >> > >> > Python: >> > flist = [1.5, 1.9, 2.0, 1.0] >> > uniqueIntegers = len(set(map(lambda f:int(f), flist))) >> >> Python: >> >> floats = [1.5, 1.9, 2.0, 1.0] >> unique_integers = len(set(int(f) for f in floats)) >> >> or: >> >> unique_integers = len(set(map(int, floats)) >> >> If you're going to use Python, at least use it right. > > Okay, you've replaced my map function with an implicit list > comprehension (aka: generator expression)... so how is > either more "right" than the other? What is your > justification that your example is "right", and mine is not? > You had: uniqueIntegers = len(set(map(lambda f:int(f), flist))) I replaced it with: unique_integers = len(set(map(int, floats)) Aside from the variable names, the significant difference here is that I pass int to map directly, where you wrap it up in a useless lambda function: lambda f: int(f) Of course Python is going to look worse if you add stuff like that to your code. ChrisA From p.f.moore at gmail.com Tue Sep 12 11:18:42 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 12 Sep 2017 16:18:42 +0100 Subject: [Tutor] beginning to code In-Reply-To: References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: On 12 September 2017 at 16:03, Rick Johnson wrote: > Chris Angelico wrote: >> Rick Johnson wrote: >> > Ruby: >> > farray = [1.5, 1.9, 2.0, 1.0] >> > uniqueIntegers = farray.map{|f| f.to_i()}.uniq.length >> > >> > Python: >> > flist = [1.5, 1.9, 2.0, 1.0] >> > uniqueIntegers = len(set(map(lambda f:int(f), flist))) >> >> Python: >> >> floats = [1.5, 1.9, 2.0, 1.0] >> unique_integers = len(set(int(f) for f in floats)) >> >> or: >> >> unique_integers = len(set(map(int, floats)) >> >> If you're going to use Python, at least use it right. > > Okay, you've replaced my map function with an implicit list > comprehension (aka: generator expression)... so how is > either more "right" than the other? What is your > justification that your example is "right", and mine is not? > > (1) Is is a speed issue? Then prove it. > > (2) Is it a readability issue? If so, then that's an opinion > _you_ get to have. > > (3) Is a matter of "python purity"? If so, then map should be > removed from the language. And don't forget to remove reduce > and filter while you're at it. And then, you may want to > grab a shield, because the functional fanboys will be all > over you like white on rice! > > (4) Something else...? Ignoring stylistic choices (variable naming, map vs generator) then for me the key distinction here is "lambda f: int(f)" vs just "int". Python's callables (of which the integer constructor int is one) are first class objects, so you should just pass them directly. Creating an anonymous function using lambda that just calls int is slower, harder to read, and less natural. The lambda is a direct translation of the Ruby "|f| f.to_i()" - I don't know if Ruby lacks a built in "convert to integer" function - maybe it does because it takes the "everything is an object" philosophy much further than Python does, but that's where "this code was translated from another language" shows. Using map vs comprehensions is mostly a stylistic choice. Python programmers will typically choose a comprehension, so that style looks more idiomatic, but the map is not wrong. I haven't tested which is faster - I can't imagine it would make much practical difference in a real program. Readability is certainly a personal choice - but writing code that looks natural to other users of the language is an element of readability (not the only one, but it is one). Paul From songofacandy at gmail.com Tue Sep 12 11:28:39 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Wed, 13 Sep 2017 00:28:39 +0900 Subject: [Tutor] beginning to code In-Reply-To: References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: > floats = [1.5, 1.9, 2.0, 1.0] > unique_integers = len(set(int(f) for f in floats)) And it can be written with set comprehension too. >>> floats = [1.5, 1.9, 2.0, 1.0] >>> len({int(x) for x in floats}) 2 As my personal recommendation, map is OK only when first argument is predefined. In other words, I strongly prefer comprehension to map+lambda. Regards, INADA Naoki From dfnsonfsduifb at gmx.de Tue Sep 12 11:36:50 2017 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Tue, 12 Sep 2017 17:36:50 +0200 Subject: Brainstorming on recursive class definitions Message-ID: Hi group, so I'm having a problem that I'd like to solve *nicely*. I know plenty of ways to solve it, but am curious if there's a solution that allows me to write the solution in a way that is most comfortable for the user. I'm trying to map registers of a processor. So assume you have a n bit address space, the processor might have duplicate units of identical functionality mapped at different places in memory. For example, assume there's a GPIO unit that has registers FOO, BAR and KOO and two GPIO ports GPIOA and GPIOB. I'd like to write code along the lines of this: class GpioMap(BaseRegisterMap): FOO = 0x0 BAR = 0x4 KOO = 0x8 class CPURegisterMap(BaseRegisterMap): GPIOA = GpioMap(0x10000) GPIOB = GpioMap(0x20000) cpu = CPURegisterMap(0x80000000) assert(cpu.addr == 0x80000000) assert(cpu.GPIOA.addr == 0x80000000 + 0x10000) assert(cpu.GPIOB.addr == 0x80000000 + 0x20000) assert(cpu.GPIOA.FOO.addr == 0x80000000 + 0x10000 + 0x0) assert(cpu.GPIOA.KOO.addr == 0x80000000 + 0x10000 + 0x8) assert(cpu.GPIOB.BAR.addr == 0x80000000 + 0x20000 + 0x4) So, obviously, FOO, BAR and KOO are of type "int" without any "addr" property, so there would need to be some magic there. Additionally, through some way the instanciation of GpioMap() would need the knowledge of its parent base, which I'm not sure is even possible. Maybe (that's what I'm currently trying to get right) the __getattribute__ would propagate the information about the accumulated parent's base address to the child during lookup. Anyways, I'm looking for your ideas on how to solve such a thing "nicely". Note that "BaseRegisterMap" is allowed to do dirty things as long as the definition code has a clean look & feel. Cheers, Joe -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From alister.ware at ntlworld.com Tue Sep 12 11:47:06 2017 From: alister.ware at ntlworld.com (alister) Date: Tue, 12 Sep 2017 15:47:06 GMT Subject: [Tutor] beginning to code References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: <_jTtB.1036718$py6.514910@fx22.am4> On Tue, 12 Sep 2017 08:03:58 -0700, Rick Johnson wrote: > Chris Angelico wrote: >> Rick Johnson wrote: >> > Ruby: >> > farray = [1.5, 1.9, 2.0, 1.0] >> > uniqueIntegers = farray.map{|f| f.to_i()}.uniq.length >> > >> > Python: >> > flist = [1.5, 1.9, 2.0, 1.0] >> > uniqueIntegers = len(set(map(lambda f:int(f), flist))) >> >> Python: >> >> floats = [1.5, 1.9, 2.0, 1.0] >> unique_integers = len(set(int(f) for f in floats)) >> >> or: >> >> unique_integers = len(set(map(int, floats)) >> >> If you're going to use Python, at least use it right. > > Okay, you've replaced my map function with an implicit list > comprehension (aka: generator expression)... so how is either more > "right" than the other? What is your justification that your example is > "right", and mine is not? > > (1) Is is a speed issue? Then prove it. > > (2) Is it a readability issue? If so, then that's an opinion _you_ get > to have. > > (3) Is a matter of "python purity"? If so, then map should be removed > from the language. And don't forget to remove reduce and filter while > you're at it. And then, you may want to grab a shield, because the > functional fanboys will be all over you like white on rice! > > (4) Something else...? for me the fact that you have had to resort to a lambda when the other solutions show it is unnecessary do it for me. I guess that falls into option 2 but it is an opinion that I can at least offer some justification for, especially considering you were using it as an example of how ruby was cleaner than python. were i to be less generous I would suggest that you had deliberately picked the worst python method you could think of to make the point -- "jackpot: you may have an unneccessary change record" -- message from "diff" From dfnsonfsduifb at gmx.de Tue Sep 12 11:53:47 2017 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Tue, 12 Sep 2017 17:53:47 +0200 Subject: Brainstorming on recursive class definitions In-Reply-To: References: Message-ID: By the way, here's my work in progress: https://gist.github.com/johndoe31415/7e432b4f47f0030f0903dbd6a401e5dc I really really love the look & feel, but am unsure if there's a better way for this? Cheers, Joe -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From larry.martell at gmail.com Tue Sep 12 12:16:51 2017 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 12 Sep 2017 12:16:51 -0400 Subject: Python dress Message-ID: Not too many females here, but anyway: https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress (And if any guys want to wear this, there's nothing wrong with that.) From moogyd at yahoo.co.uk Tue Sep 12 12:30:56 2017 From: moogyd at yahoo.co.uk (moogyd at yahoo.co.uk) Date: Tue, 12 Sep 2017 09:30:56 -0700 (PDT) Subject: Brainstorming on recursive class definitions In-Reply-To: References: Message-ID: <11a17768-39ef-4028-8a77-3338079645b5@googlegroups.com> On Tuesday, September 12, 2017 at 5:37:31 PM UTC+2, Johannes Bauer wrote: > Hi group, > > so I'm having a problem that I'd like to solve *nicely*. I know plenty > of ways to solve it, but am curious if there's a solution that allows me > to write the solution in a way that is most comfortable for the user. > > I'm trying to map registers of a processor. So assume you have a n bit > address space, the processor might have duplicate units of identical > functionality mapped at different places in memory. For example, assume > there's a GPIO unit that has registers FOO, BAR and KOO and two GPIO > ports GPIOA and GPIOB. I'd like to write code along the lines of this: > > class GpioMap(BaseRegisterMap): > FOO = 0x0 > BAR = 0x4 > KOO = 0x8 > > class CPURegisterMap(BaseRegisterMap): > GPIOA = GpioMap(0x10000) > GPIOB = GpioMap(0x20000) > > cpu = CPURegisterMap(0x80000000) > > assert(cpu.addr == 0x80000000) > assert(cpu.GPIOA.addr == 0x80000000 + 0x10000) > assert(cpu.GPIOB.addr == 0x80000000 + 0x20000) > assert(cpu.GPIOA.FOO.addr == 0x80000000 + 0x10000 + 0x0) > assert(cpu.GPIOA.KOO.addr == 0x80000000 + 0x10000 + 0x8) > assert(cpu.GPIOB.BAR.addr == 0x80000000 + 0x20000 + 0x4) > > So, obviously, FOO, BAR and KOO are of type "int" without any "addr" > property, so there would need to be some magic there. Additionally, > through some way the instanciation of GpioMap() would need the knowledge > of its parent base, which I'm not sure is even possible. Maybe (that's > what I'm currently trying to get right) the __getattribute__ would > propagate the information about the accumulated parent's base address to > the child during lookup. > > Anyways, I'm looking for your ideas on how to solve such a thing > "nicely". Note that "BaseRegisterMap" is allowed to do dirty things as > long as the definition code has a clean look & feel. > > Cheers, > Joe > > > -- > >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > > Zumindest nicht ?ffentlich! > Ah, der neueste und bis heute genialste Streich unsere gro?en > Kosmologen: Die Geheim-Vorhersage. > - Karl Kaos ?ber R?diger Thomas in dsa A child (e.g. instance of GpioMap) should not have any knowledge of it's own base address. This is a function of the GPIORegisyerMap only. i.e. The GPIORegisyerMap would do the selection of particular instance. It may be worth looking at some of the IP-XACT documentation, which defines some common terms (IIRC register, address map, address space etc). Having a consistent definition here will definitely help moving forward Although it may seem OTT at the moment, it is something you should consider at the outset. e.g. A single GPIO register may occur at two different addresses, depending on the bus master (CPU Core, Debugger, External SPI access). Steven From rantingrickjohnson at gmail.com Tue Sep 12 12:44:06 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Sep 2017 09:44:06 -0700 (PDT) Subject: Run Windows commands from Python console In-Reply-To: References: <83ebc433-d457-408b-b43a-4b00a3206728@googlegroups.com> <290ec6d2-81d9-4bf4-b641-fc8568578555@googlegroups.com> <7515e893-b1c7-42ff-926d-e482e1eca9ae@googlegroups.com> <44d79423-bb42-4f8d-9d08-07f77a9a16c7@googlegroups.com> Message-ID: Stephan Houben wrote: > Rick Johnson schreef: > > It seems to me the best solution is for the TCL/Tk folks > > to provide a configuration utility that stores user > > preferences in the registry, or some other OS provided > > mechanism, as to have these settings reset on every > > invocation of the application would be inefficient from an > > enduser perspective. > > You mean, like the existing .Xdefaults mechanism (yes Tk > also supports that on Windows), and the "option" mechanism? Not "exactly" (see footnotes [1] and [2]). Those features are only available to the programmer. What i'm talking about is an "interface configuration utility" that _bypasses_ the programmer and allows the _enduser_ to reshape or reorder the interface widgets. For instance: (IMO) it is appropriate for a programmer to define the initial interface commands (be they menu commands or keyboard shortcuts, or other..), but it is not appropriate for the programmer to limit the placement of these menu commands (either by purposeful action or outright neglect), nor to prevent the redefining of keyboard shortcuts. Furthermore, many devs refuse to employ the resizable container widgets such as "tk.PanedWindow". I would argue that _all_ containers should be user-resizable, coupled with an application level: "reset all frames to default size" command. Typically, most software developers will provide a configuration dialog so that users can redefine keyboard shortcuts, however, this feature will only be available *IF* the developer decides to make it available. Even more rare, is the ability to re-order the menu commands as the user sees fit. Some large softwares like Eclipse and Open Office offer this feature, but again, the configuration power the end user is given remains at the discretion of the developer, and many times, the decision to omit these important configuration features is not a matter of discretion at all, it's just pure laziness. Realizing the ubiquitous nature of poor GUI interface design, and realizing the impossibility of hardcoding a single interface that will satisfy all users, i have come to the conclusion that an enduser configuration utility must be made available by the GUI library _itself_, thereby bypassing the prejudice and incompetence of developers entirely, and giving the endusers the ultimate power to reshape the interface as the endusers see fit. [1] I had read somewhere once, and my knowledge in this area is admittingly limited as i have not yet migrated to Python3's tkinter module, that the Option Database of legacy Tkinter (python2) was being deprecated in favor of the new ttk.widget styling defined in tkinter (python3). My understanding is that the legacy Option Database (which i have not utilized much myself) was merely a means by which certain widget attributes (typically: styling attributes) could be propagated throughout an interface -- so i doubt (but i could be wrong) that this feature would provide a _persistent_ means by which a user can reconfigure the interface outside of simple stylings. [2] However, if .Xdefaults provides a cross-platform _persistent_ storage mechanism, then all one would need do is wrap it in a friendly dialog that would be made available to every [Tt]kinter enduser (perhaps through a small button added to every tk.Tk window). And although Tk itself does not provide a built-in method for moving around menu commands, one could be implemented fairly easily using the methods of the existing menu components. From jonaazizaj at gmail.com Tue Sep 12 13:10:26 2017 From: jonaazizaj at gmail.com (Jona Azizaj) Date: Tue, 12 Sep 2017 17:10:26 +0000 (UTC) Subject: Python dress In-Reply-To: References: Message-ID: <0967d523-42a7-2541-2a42-e7c1716f6957@gmail.com> It looks very nice, thanks for sharing :) On 09/12/2017 06:16 PM, Larry Martell wrote: > Not too many females here, but anyway: > > https://u4999934.ct.sendgrid.net/wf/click?upn=PEGtk34F2vzY-2FdDEgdADyR5WgaJXp3kK7yjjfCP4LBGKF2bSjvTFWCFYRlwVAQZ5HEeMdCPRw1tUKRf8HLGvHzOQQS1VCWAz-2FXnHFw36zPHseeHhMMPaOQoGFSuR98b4_-2Bhtkm6SDKcrqjRFK9GSlahGOHKvvNKRPEMAZ1tASX-2BnljYyh-2BoqYVc1h6KEMOxobwDxM8Dr0Jy9ZrPUamH2ONoCofjMh1-2F1ZTp8vs28IRq9-2FV-2BKG81NQ1WNnZqms0swnJ63OL0Ai78Q-2FoPsl-2B1T4gBR3ASVhYWQVYVs5TlijuEpg79GoCU7Mxh4SuDwC2QJQ4zf51XQJ-2BcNmZPwKUzr6oO6UidvYAoYDYNMp4HWhnC4-3D > > (And if any guys want to wear this, there's nothing wrong with that.) From rantingrickjohnson at gmail.com Tue Sep 12 13:22:25 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Sep 2017 10:22:25 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: Chris Angelico wrote: > Rick Johnson wrote: > > Chris Angelico wrote: > > > Rick Johnson wrote: > > > > > > > > Ruby: > > > > farray = [1.5, 1.9, 2.0, 1.0] > > > > uniqueIntegers = farray.map{|f| f.to_i()}.uniq.length > > > > > > > > Python: > > > > flist = [1.5, 1.9, 2.0, 1.0] > > > > uniqueIntegers = len(set(map(lambda f:int(f), flist))) > > > > > > Python: > > > > > > floats = [1.5, 1.9, 2.0, 1.0] > > > unique_integers = len(set(int(f) for f in floats)) > > > > > > or: > > > > > > unique_integers = len(set(map(int, floats)) > > > > > > If you're going to use Python, at least use it right. > > > > Okay, you've replaced my map function with an implicit > > list comprehension (aka: generator expression)... so how > > is either more "right" than the other? What is your > > justification that your example is "right", and mine is > > not? > > You had: > > uniqueIntegers = len(set(map(lambda f:int(f), flist))) > > I replaced it with: > > unique_integers = len(set(map(int, floats)) > > Aside from the variable names, the significant difference > here is that I pass int to map directly, where you wrap it > up in a useless lambda function: > > lambda f: int(f) Oops! Yes, i did put a superfluous anonymous function in there, my bad O:-) Although, to my defense, (and although i never use this style in real code, but i'm trying to save face here #_o, so bear with me...) the lambda does make the call to map a "little" more clearer. For instance, when we juxtapose: map(int, flist) with: map(lambda f:int(f), flist) We get a little more insight into the internal workings of map in the second example, specifically, that each `f` in `flist` is being cast to integer. Which, incidentally, is why some folks prefer the explicit generator expressions and list comprehensions over the implicit nature of map. But along with your correction of my superfluous lambda, you offered this additional generator expression form: unique_integers = len(set(int(f) for f in floats)) And this was the form for which my four questions were directed (ignoring my superfluous lambda, of course). So i resubmit my map form as: flist = [1.5, 1.9, 2.0, 1.0] uniqueIntegers = len(set(map(int, flist))) and then we juxtapose your generator expression (with variable names normalized free of charge ;-): flist = [1.5, 1.9, 2.0, 1.0] unique_integers = len(set(int(f) for f in flist)) So, what are your answers to my four questions: (1) Is it a speed issue? Then prove it. (2) Is it a readability issue? If so, then that's an opinion _you_ get to have. (3) Is it a matter of "python purity"? If so, then map should be removed from the language, and don't forget to remove reduce and filter while you're at it, and then, you may want to grab a shield because the functional fanboys will be all over you like white on rice! (psst: here comes Rustom Mody now!!!) (4) Something else...? > Of course Python is going to look worse if you add stuff > like that to your code. The lambda was an accident, perhaps even a happy accident, but my four questions and my original intent stands valid even in light of my simple mistake. Now dammit, answer the questions! :-) From rosuav at gmail.com Tue Sep 12 13:28:32 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Sep 2017 03:28:32 +1000 Subject: [Tutor] beginning to code In-Reply-To: References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: On Wed, Sep 13, 2017 at 3:22 AM, Rick Johnson wrote: > Oops! Yes, i did put a superfluous anonymous function in > there, my bad O:-) Although, to my defense, (and although i > never use this style in real code, but i'm trying to save > face here #_o, so bear with me...) the lambda does make the > call to map a "little" more clearer. For instance, when we > juxtapose: > > map(int, flist) > > with: > > map(lambda f:int(f), flist) > > We get a little more insight into the internal workings of > map in the second example, specifically, that each `f` in > `flist` is being cast to integer. The point of map() is to map a function over a collection. Its inner workings are no more exposed by the use of a pass-through lambda function than without. > So, what are your answers to my four questions: > > (1) Is it a speed issue? Then prove it. > > (2) Is it a readability issue? If so, then that's an > opinion _you_ get to have. > > (3) Is it a matter of "python purity"? If so, then map > should be removed from the language, and don't forget to > remove reduce and filter while you're at it, and then, > you may want to grab a shield because the functional > fanboys will be all over you like white on rice! (psst: > here comes Rustom Mody now!!!) > > (4) Something else...? > >> Of course Python is going to look worse if you add stuff >> like that to your code. > > The lambda was an accident, perhaps even a happy accident, > but my four questions and my original intent stands valid > even in light of my simple mistake. Now dammit, answer the > questions! :-) > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Sep 12 13:34:39 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Sep 2017 03:34:39 +1000 Subject: [Tutor] beginning to code In-Reply-To: References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: On Wed, Sep 13, 2017 at 3:22 AM, Rick Johnson wrote: > So, what are your answers to my four questions: > > (1) Is it a speed issue? Then prove it. > > (2) Is it a readability issue? If so, then that's an > opinion _you_ get to have. > > (3) Is it a matter of "python purity"? If so, then map > should be removed from the language, and don't forget to > remove reduce and filter while you're at it, and then, > you may want to grab a shield because the functional > fanboys will be all over you like white on rice! (psst: > here comes Rustom Mody now!!!) > > (4) Something else...? (Oops, premature send.) #1 is almost certainly true, since non-code is invariably faster than code (either way, int() gets called). But that's not the point. #2 is part of the point. But not the main point. #3 - if you mean that map violates purity in some way, then (a) I never said to remove it, and (b) Python never brags that purity is its goal. #4. Catch-all, I guess. Do you write: if x: or do you write: if bool(x): or maybe: if bool(x) is True: or perhaps: if (bool(x) is True) is True: or even: if (bool(x) is True) == (True is not False): Redundant code does not belong. ChrisA From rantingrickjohnson at gmail.com Tue Sep 12 13:52:01 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Sep 2017 10:52:01 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: <59000915-8723-476d-bc2f-350d3d71e61c@googlegroups.com> Paul Moore wrote: [...] > Ignoring stylistic choices (variable naming, map vs > generator) then for me the key distinction here is "lambda > f: int(f)" vs just "int". Python's callables (of which the > integer constructor int is one) are first class objects, so > you should just pass them directly. Creating an anonymous > function using lambda that just calls int is slower, harder > to read, and less natural. The lambda is a direct > translation of the Ruby "|f| f.to_i()" - I don't know if > Ruby lacks a built in "convert to integer" function - maybe > it does because it takes the "everything is an object" > philosophy much further than Python does, but that's where > "this code was translated from another language" shows. I was wondering why i put that lambda in there, and that's probably why i did it, superficially, to more accurately compare the syntax of both languages, at the expense of writing concise Python code. In any event, i believe my point -- that complex statements in Ruby follow a more intuitive left-to-right comprehension flow, whereas Python, which due to a reliance on built-in functions as opposed to Object methods is directly responsible for our code being littered with these less intuitive nested function calls -- remains a valid point. > Using map vs comprehensions is mostly a stylistic choice. > Python programmers will typically choose a comprehension, > so that style looks more idiomatic, but the map is not > wrong. I haven't tested which is faster - I can't imagine > it would make much practical difference in a real program. > Readability is certainly a personal choice - but writing > code that looks natural to other users of the language is > an element of readability (not the only one, but it is > one). I would agree on all points. From rantingrickjohnson at gmail.com Tue Sep 12 13:58:14 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Sep 2017 10:58:14 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: <_jTtB.1036718$py6.514910@fx22.am4> References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> <_jTtB.1036718$py6.514910@fx22.am4> Message-ID: alister wrote: > [...] > were i to be less generous I would suggest that you had > deliberately picked the worst python method you could think > of to make the point Feel free to offer a better solution if you like. INADA Naoki offered a good solution for Python3 folks, but AFAIK, set comprehensions are not avialable as a backported "future feature" for Python2 folks. And surely not for Python1 folks. From stephanh42 at gmail.com.invalid Tue Sep 12 15:15:49 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 12 Sep 2017 19:15:49 GMT Subject: Python dress References: <0967d523-42a7-2541-2a42-e7c1716f6957@gmail.com> Message-ID: Op 2017-09-12, Jona Azizaj schreef : > It looks very nice, thanks for sharing :) print(insertionSort) It's even Python3-compliant! Stephan From kwpolska at gmail.com Tue Sep 12 15:24:58 2017 From: kwpolska at gmail.com (Chris Warrick) Date: Tue, 12 Sep 2017 21:24:58 +0200 Subject: Python dress In-Reply-To: References: <0967d523-42a7-2541-2a42-e7c1716f6957@gmail.com> Message-ID: On 12 September 2017 at 21:15, Stephan Houben wrote: > Op 2017-09-12, Jona Azizaj schreef : >> It looks very nice, thanks for sharing :) > > print(insertionSort) > > It's even Python3-compliant! > > Stephan > -- > https://mail.python.org/mailman/listinfo/python-list Meh. That should be a return statement, the thing is not PEP 8-compliant, and Courier is an ugly font. -- Chris Warrick PGP: 5EAAEA16 From ben+python at benfinney.id.au Tue Sep 12 16:00:03 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 13 Sep 2017 06:00:03 +1000 Subject: Python dress References: Message-ID: <85zi9z7kn0.fsf@benfinney.id.au> Larry Martell writes: > https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress > (And if any guys want to wear this, there's nothing wrong with that.) Boo, the code is not PEP 8 conformant :-) If it weren't for the bad code style, I might consider it. The dress looks good! -- \ ?Contentment is a pearl of great price, and whosoever procures | `\ it at the expense of ten thousand desires makes a wise and | _o__) happy purchase.? ?J. Balguy | Ben Finney From leamhall at gmail.com Tue Sep 12 17:38:04 2017 From: leamhall at gmail.com (Leam Hall) Date: Tue, 12 Sep 2017 17:38:04 -0400 Subject: Python dress In-Reply-To: <85zi9z7kn0.fsf@benfinney.id.au> References: <85zi9z7kn0.fsf@benfinney.id.au> Message-ID: On 09/12/2017 04:00 PM, Ben Finney wrote: > Larry Martell writes: > >> https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress >> (And if any guys want to wear this, there's nothing wrong with that.) > > Boo, the code is not PEP 8 conformant :-) > > If it weren't for the bad code style, I might consider it. The dress > looks good! > Note that a google search of "python muscle shirt" didn't seem to come up with any code. Wonder why? :P From ofekmeister at gmail.com Tue Sep 12 17:47:21 2017 From: ofekmeister at gmail.com (ofekmeister at gmail.com) Date: Tue, 12 Sep 2017 14:47:21 -0700 (PDT) Subject: Hatch - A modern project, package, and virtual env manager In-Reply-To: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> References: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> Message-ID: <57bf2339-e75b-4d49-8d8f-812262cc08c1@googlegroups.com> 0.10.0 features environment-aware testing, full Xonsh shell support, and more colors! https://github.com/ofek/hatch#0100 From p.f.moore at gmail.com Tue Sep 12 18:14:23 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 12 Sep 2017 23:14:23 +0100 Subject: [Tutor] beginning to code In-Reply-To: <59000915-8723-476d-bc2f-350d3d71e61c@googlegroups.com> References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> <59000915-8723-476d-bc2f-350d3d71e61c@googlegroups.com> Message-ID: On 12 September 2017 at 18:52, Rick Johnson wrote: > In any event, i believe my point -- that complex statements > in Ruby follow a more intuitive left-to-right comprehension > flow, whereas Python, which due to a reliance on built-in > functions as opposed to Object methods is directly > responsible for our code being littered with these less > intuitive nested function calls -- remains a valid point. Hardly. As you said to Chris, that's an opinion that you get to have - but trying to claim that your opinion is anything other than that (just an opinion) is pointless. > Feel free to offer a better solution if you like. INADA > Naoki offered a good solution for Python3 folks, but AFAIK, > set comprehensions are not avialable as a backported "future > feature" for Python2 folks. And surely not for Python1 > folks. So what? What's the point in comparing Ruby with years-out-of-date Python? At this point you're clearly just looking for an argument, so I'll give up on this thread. Paul From steve+python at pearwood.info Tue Sep 12 19:32:06 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 13 Sep 2017 09:32:06 +1000 Subject: Python dress References: Message-ID: <59b86e79$0$16743$b1db1813$d948b532@news.astraweb.com> On Wed, 13 Sep 2017 02:16 am, Larry Martell wrote: > Not too many females here, but anyway: > > https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress Was expecting a dress in a snake-skin pattern. Was pleasantly surprised to see Insertion Sort in Python on a dress! > (And if any guys want to wear this, there's nothing wrong with that.) Assuming they can fit in the offered sizes :-) Here in Australia, we're having an expensive, divisive, non-binding exercise in political propaganda, a postal survey on whether or not to continue allowing discrimination in marriage. The pro-discrimination side has run a TV advertisement claiming that equal rights for marriage is just the first step that will end with our sons being told they can wear dresses to school (and possibly even lions and lambs lying down together in the field). Apparently that's meant to be the end of the world as we know it, or something. The amusing thing to my mind is that the pro-discrimination, anti-equality faction also tend to be the most conservative[1] pro-monarchy faction. I don't recall seeing them go into paroxysms of gender confusion when Prince Charles, Duke of Edinburgh, appears in public wearing a kilt. [1] Gosh, that's a shocker. Bet you didn't see that coming. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Sep 12 19:45:15 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 13 Sep 2017 09:45:15 +1000 Subject: [Tutor] beginning to code References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: <59b8718d$0$16721$b1db1813$d948b532@news.astraweb.com> On Wed, 13 Sep 2017 01:18 am, Paul Moore wrote: > Using map vs comprehensions is mostly a stylistic choice. Python > programmers will typically choose a comprehension, so that style looks > more idiomatic, but the map is not wrong. I haven't tested which is > faster - I can't imagine it would make much practical difference in a > real program. Last time I tested it: map(f, values) # Python 2 version of map [f(x) for x in values] were equally fast when f was some function, but the comprehension: [2*x + y for x in values] # for example is considerably faster than the map solution using lambda: map(lambda x: 2*x + y, values) The lesson is: calling a function isn't free. If you can in-line an expression rather than call a function to evaluate the expression, you gain. (Although the more expensive the expression, the less significant the function call overhead becomes.) The implication is that the more superfluous function wrappers you have, the slower your code. If our aim is to have slow, unreadable code, we can take the obvious: map(int, values) and progressively slow it down: map(lambda x: int(x), values) map(lambda y: (lambda x: int(x))(y), values) map(lambda z: (lambda y: (lambda x: int(x))(y))(z), values) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From songofacandy at gmail.com Tue Sep 12 19:46:16 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Wed, 13 Sep 2017 08:46:16 +0900 Subject: [Tutor] beginning to code In-Reply-To: References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> <_jTtB.1036718$py6.514910@fx22.am4> Message-ID: 2017/09/13 ??3:04 "Rick Johnson" : alister wrote: > [...] > were i to be less generous I would suggest that you had > deliberately picked the worst python method you could think > of to make the point Feel free to offer a better solution if you like. INADA Naoki offered a good solution for Python3 folks, but AFAIK, set comprehensions are not avialable as a backported "future feature" for Python2 folks. And surely not for Python1 folks. FYI, it was backported to Python 2.7. https://docs.python.org/2/tutorial/datastructures.html#sets As a OSS maintainer, I and many common libraries drop Python 2.6 support already. So I can use it even when I can't drop Python 2 supprt yet. Regards, From greg.ewing at canterbury.ac.nz Tue Sep 12 19:59:05 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 13 Sep 2017 11:59:05 +1200 Subject: Python dress In-Reply-To: References: Message-ID: Larry Martell wrote: > https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress The only disadvantage might be the GIL interfering with parallel processing using multiple machines in a laundromat. -- Greg From python at mrabarnett.plus.com Tue Sep 12 20:12:25 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 13 Sep 2017 01:12:25 +0100 Subject: Python dress In-Reply-To: <59b86e79$0$16743$b1db1813$d948b532@news.astraweb.com> References: <59b86e79$0$16743$b1db1813$d948b532@news.astraweb.com> Message-ID: <99ed6ab4-7270-f62f-45e4-fdd1202fee3e@mrabarnett.plus.com> On 2017-09-13 00:32, Steve D'Aprano wrote: > On Wed, 13 Sep 2017 02:16 am, Larry Martell wrote: > >> Not too many females here, but anyway: >> >> > https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress > > Was expecting a dress in a snake-skin pattern. > > Was pleasantly surprised to see Insertion Sort in Python on a dress! > > >> (And if any guys want to wear this, there's nothing wrong with that.) > > Assuming they can fit in the offered sizes :-) > > Here in Australia, we're having an expensive, divisive, non-binding exercise in > political propaganda, a postal survey on whether or not to continue allowing > discrimination in marriage. The pro-discrimination side has run a TV > advertisement claiming that equal rights for marriage is just the first step > that will end with our sons being told they can wear dresses to school (and > possibly even lions and lambs lying down together in the field). > Co-incidentally, there was a story in the news today about a couple in the UK who have stopped sending their son to a school that's allowing another child to dress as both a boy and a girl. They did the same thing with their eldest son at the same school two years ago. > Apparently that's meant to be the end of the world as we know it, or something. > > The amusing thing to my mind is that the pro-discrimination, anti-equality > faction also tend to be the most conservative[1] pro-monarchy faction. I don't > recall seeing them go into paroxysms of gender confusion when Prince Charles, > Duke of Edinburgh, appears in public wearing a kilt. > You do know that Prince Charles is the Prince of Wales and that the Duke of Edinburgh is his father, don't you? :-) > > > > > [1] Gosh, that's a shocker. Bet you didn't see that coming. > From rantingrickjohnson at gmail.com Tue Sep 12 20:54:19 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Sep 2017 17:54:19 -0700 (PDT) Subject: Python dress In-Reply-To: References: Message-ID: <73885088-e749-4011-9902-37aa57a19d6b@googlegroups.com> On Tuesday, September 12, 2017 at 6:59:32 PM UTC-5, Gregory Ewing wrote: > Larry Martell wrote: > > https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress > > The only disadvantage might be the GIL interfering with > parallel processing using multiple machines in a > laundromat. Oh, not the only disadvantage: being that 5 of the machines are running Python3, and 4 are running Python2, and one is still stubbornly running Python1, and being that the owner forgot to mark them, if we put the dress in the wrong machine -- *BOOM* -- exceptions all over the floor. Can anyone think of a way to version-test these machines without wasting a quarter, or requiring the services of a clean-up crew? From rantingrickjohnson at gmail.com Tue Sep 12 23:01:52 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Sep 2017 20:01:52 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: Chris Angelico wrote: > Rick Johnson wrote: > > So, what are your answers to my four questions: > > > > (1) Is it a speed issue? Then prove it. > > > > (2) Is it a readability issue? If so, then that's an > > opinion _you_ get to have. > > > > (3) Is it a matter of "python purity"? If so, then map > > should be removed from the language, and don't forget to > > remove reduce and filter while you're at it, and then, > > you may want to grab a shield because the functional > > fanboys will be all over you like white on rice! (psst: > > here comes Rustom Mody now!!!) > > > > (4) Something else...? > > > (Oops, premature send.) It's okay Chris, it happens. Sometimes we get a little too excited and loose all control over our bodily functions. O:-) > #1 is almost certainly true, since non-code is invariably > faster than code (either way, int() gets called). But > that's not the point. I told you to forget about the superfluous lambda, but alas, you cannot :-( > #2 is part of the point. But not the main point. > > #3 - if you mean that map violates purity in some way, then > (a) I never said to remove it, and (b) Python never brags > that purity is its goal. If you wanted to say no, you could have just said it... > #4. Catch-all, I guess. > > Do you write: > if x: > > or do you write: > if bool(x): > > or maybe: > if bool(x) is True: > > or perhaps: > if (bool(x) is True) is True: > > or even: > if (bool(x) is True) == (True is not False): > > Redundant code does not belong. Just as writing overly implicit code is harmful, so too is writing overly explicit code. When we read overly implicit code, we are distracted by the need to interpret the enormous amount of meaning hiding behind a single symbol. Regular expressions are an example of overly implicit code, but regular expressions are a special purpose tool, and they are designed with the idea of packing a lot of functionality into the fewest symbols. OTOH, when we read overly explicit code, we are distracted by the excessive symbols. So a balance must be found between these two extremes. For instance, i have always considered this "Python custom" to be far too implicit: if x: # do something What are we testing about `x`? Obviously, most programmers, especially Python programmers, will know what is going on here because they have been trained, and just like any child who has been trained to ride a bicycle, riding a bicycle becomes _reflexive_, and the rider, who was once terrified of riding, becomes cocky, as to them the task now seems simple. But just because we have been trained that the implicit `if x:` is shorthand for the reasonable `if bool(x) == True:`, does not mean the implicit syntax is "correct". No. You, just as the child who learned to ride a bicycle now believes that `if x` is right, and not because of some deep objective analysis, no, but because it is "reflexive" for you to say so. Your failure here is obvious: you're conflating Pavlovian conditioning with moral principals. What are the moral principals of language design? A tough question to answer objectively, i admit, however, if we can manage to see beyond their own subjective interpretations of reality, most of which that have been molded by years of obedience training (aka: "Oh, that's soooooo easy because my master said so, and peer pressure demands it"), then we might find the objective compromise between two extremes. In this case, the compromise is: if bool(x) is True: # do something... In this example, we strike a balance between implicit and explicit code, because in this example, we don't need to assume what aspect of `x` that we are "testing", no, because the test is now made crystal clear. We can even expand the code to English intuitively, as: if the boolean value of x is True: # do something... Now, some quippy person will no doubt complain that: `if bool(x) is True` will be slower than `if x`. And that's true! But the reason it's slower is not because it's a bad idea, no, it's because the language designers have decided (via emotion, not logic!) that `if x` is the better way to go, and so they've optimized `if x`. I assure you that, `if bool(x) is True` can be made to execute exactly as fast as `if x`, and anybody who claims otherwise is a flat out liar. There is absolutely no correlation between the length of a statement and the time required to execute that statement once it has been "interpreted". Heck, if we wanted to be silly, we could expand the statement to: if the boolean value of x is True\ and python is absolutely one hundred percent positive that it is True\ and furthermore there is not even a snowballs chance in hell that it could be False\ and the earth is roundish\ and water is wet\ and OJ is not looking for the true killer because he would rather play golf\ and mass media is a tool of corporate america\ and most people are a tool of corporate america\ and being a tool is totally not cool\ and reality TV is totally scripted\ and politicians will say anything to get elected\ and money has corrupted our elections\ and money has corrupted all of us\ and iphones are made in sweat shops\ and so are our name brand tennis shoes\ and Fakebook really is spying on us\ and so is Google\ and if we call either one out they will only deny it\ and use it as an excuse to institutionalize us\ and then we will meet nurse Ratchet\ and she will torment us with her microphone\ and then we will be asphyxiated by Big Chief\ and then Chief will escape the nest of cookoos\ and the BDFL once claimed he would ride in a plane controlled by a python script\ and he meant it\ and no i am not joking: # # WHEW! Okay, then i guess you can do something... # ...and the byte compiled code would execute at the same speed as `if x`. And if it doesn't, then the devs are incompetent or they're sabotaging the interpreter for political reasons. And as far as your other examples are concerned: > or perhaps: > if (bool(x) is True) is True: > > or even: > if (bool(x) is True) == (True is not False): they're just reductio ad absurdum. From rosuav at gmail.com Tue Sep 12 23:20:40 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Sep 2017 13:20:40 +1000 Subject: [Tutor] beginning to code In-Reply-To: References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: On Wed, Sep 13, 2017 at 1:01 PM, Rick Johnson wrote: > Chris Angelico wrote: >> Rick Johnson wrote: >> > So, what are your answers to my four questions: >> > > > I told you to forget about the superfluous lambda, but > alas, you cannot :-( You told me to forget about the key thing I was making my point about, and yet insisted on answers to your four questions? > So a balance must be found between these two extremes. For > instance, i have always considered this "Python custom" to > be far too implicit: > > if x: > # do something > > What are we testing about `x`? > Obviously, most programmers, especially Python programmers, > will know what is going on here because they have been > trained, and just like any child who has been trained to > ride a bicycle, riding a bicycle becomes _reflexive_, and > the rider, who was once terrified of riding, becomes cocky, > as to them the task now seems simple. > > But just because we have been trained that the implicit `if > x:` is shorthand for the reasonable `if bool(x) == True:`, > does not mean the implicit syntax is "correct". The statement "if x:" is not shorthand for any sort of equality comparison. If you want to say that it's shorthand for "if bool(x):", then sure, but the "== True" part is entirely superfluous. > What are the moral principals of language design? PEP 20. > A tough question to answer objectively, i admit, however, if > we can manage to see beyond their own subjective > interpretations of reality, most of which that have been > molded by years of obedience training (aka: "Oh, that's > soooooo easy because my master said so, and peer pressure > demands it"), then we might find the objective compromise > between two extremes. In this case, the compromise is: > > if bool(x) is True: > # do something... > > In this example, we strike a balance between implicit and > explicit code, because in this example, we don't need to > assume what aspect of `x` that we are "testing", no, because > the test is now made crystal clear. We can even expand the > code to English intuitively, as: > > if the boolean value of x is True: > # do something... "Anything on that list?" is far more idiomatic English than "Is the boolean value of that list identical to the constant True?". > Now, some quippy person will no doubt complain that: `if > bool(x) is True` will be slower than `if x`. And that's > true! But the reason it's slower is not because it's a bad > idea, no, it's because the language designers have decided > (via emotion, not logic!) that `if x` is the better way to > go, and so they've optimized `if x`. I assure you that, `if > bool(x) is True` can be made to execute exactly as fast as > `if x`, and anybody who claims otherwise is a flat out liar. Actually, you're absolutely correct. You can make them execute just as quickly. Here: class X: def __bool__(self): while True is not False: pass x = X() Easy. > There is absolutely no correlation between the length of a > statement and the time required to execute that statement > once it has been "interpreted". > [chomp] > ...and the byte compiled code would execute at the same > speed as `if x`. And if it doesn't, then the devs are > incompetent or they're sabotaging the interpreter for > political reasons. So you start with the assumption that "if bool(x) is True" and "if x" have absolutely identical semantics, and then say that they should be the same thing. Great! Well, when they do, you can remind someone to improve the peephole optimizer. Turns out, "bool(x)" is slower because it has different semantics. What an enormous surprise. > And as far as your other examples are concerned: > >> or perhaps: >> if (bool(x) is True) is True: >> >> or even: >> if (bool(x) is True) == (True is not False): > > they're just reductio ad absurdum. Yep. So, where are you going to draw the line between "absurd" and "correct"? I'm going to put it just after "if x:", on the basis that all superfluous code is bad. Justify the amount of superfluous code that you want. ChrisA From rantingrickjohnson at gmail.com Tue Sep 12 23:22:30 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Sep 2017 20:22:30 -0700 (PDT) Subject: Using Python 2 In-Reply-To: References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <878thpjr8t.fsf@elektro.pacujo.net> <276e8910-6128-419b-b262-d0152053d752@googlegroups.com> <59b4cc62$0$16757$b1db1813$d948b532@news.astraweb.com> Message-ID: Gregory Ewing wrote: > Rick Johnson wrote: > > Heck, when is the last time GvR participated in any > > discussion outside the hermetic bubble of Python-Dev or > > Python-Ideas? > > I'd hardly call python-ideas "hermetic". Anyone is free to > post there and participate in discussions. Python-dev is > open to anyone too, the only difference is that python-dev > intended for things that are actually being worked on, > whereas python-ideas is for any idea that may or may not > come to fruition. I dunno, my experiences in that group have been less than welcoming, but i won't beat a dead horse... > If you want to interact with Guido, you need to go to > a list he frequents. You can't expect him to personally > reply to every issue on every python-related list and > group. That would be more than a full-time job for > anyone. I'm not so much interested in talking with Guido personally, i would just like to see him participate in more areas of this community instead of keeping himself all couped-up in those "members only" forums. I see no need for the Python community to be purposefully stratified into social classes. But i cannot help but feel that some folks in this community have declared themselves members of an aristocracy. From steve+comp.lang.python at pearwood.info Wed Sep 13 00:12:52 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Sep 2017 04:12:52 GMT Subject: Using Python 2 References: <430c7436-a6bf-f278-8441-cc9c8afb3983@gmail.com> <59b13889$0$16726$b1db1813$d948b532@news.astraweb.com> <85zia68wkr.fsf@benfinney.id.au> <878thpjr8t.fsf@elektro.pacujo.net> <276e8910-6128-419b-b262-d0152053d752@googlegroups.com> <59b4cc62$0$16757$b1db1813$d948b532@news.astraweb.com> Message-ID: <59b8b043$0$16632$b1db1813$d948b532@news.astraweb.com> On Tue, 12 Sep 2017 20:22:30 -0700, Rick Johnson wrote: > Gregory Ewing wrote: >> Rick Johnson wrote: >> > Heck, when is the last time GvR participated in any discussion >> > outside the hermetic bubble of Python-Dev or Python-Ideas? >> >> I'd hardly call python-ideas "hermetic". Anyone is free to post there >> and participate in discussions. Python-dev is open to anyone too, the >> only difference is that python-dev intended for things that are >> actually being worked on, whereas python-ideas is for any idea that may >> or may not come to fruition. > > I dunno, my experiences in that group have been less than welcoming, but > i won't beat a dead horse... Why ever not? You beat all the other dead horses. "Python is doomed if you don't listen to me." "Python is doomed because of type hinting." "Python is doomed because of async." "Python is doomed because of Python 3." "Python is doomed because watermelon colourless sleep kumquat." >> If you want to interact with Guido, you need to go to a list he >> frequents. You can't expect him to personally reply to every issue on >> every python-related list and group. That would be more than a >> full-time job for anyone. > > I'm not so much interested in talking with Guido personally, i would > just like to see him participate in more areas of this community instead > of keeping himself all couped-up in those "members only" forums. Python-Dev and Python-Ideas are no more "members only" than Python-List (this forum). As you know, because you subscribed to at least one of them some time ago. The only difference is that those forums have less patience towards bullshit. As you know, because you soon left. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From steve+comp.lang.python at pearwood.info Wed Sep 13 00:15:26 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Sep 2017 04:15:26 GMT Subject: Python dress References: <59b86e79$0$16743$b1db1813$d948b532@news.astraweb.com> <99ed6ab4-7270-f62f-45e4-fdd1202fee3e@mrabarnett.plus.com> Message-ID: <59b8b0dd$0$16632$b1db1813$d948b532@news.astraweb.com> On Wed, 13 Sep 2017 01:12:25 +0100, MRAB wrote: >> I don't recall seeing them go into paroxysms of >> gender confusion when Prince Charles, >> Duke of Edinburgh, appears in public wearing a kilt. > > You do know that Prince Charles is the Prince of Wales and that the Duke > of Edinburgh is his father, don't you? :-) Ah, yes, thanks for the correction. Of course I was thinking about Prince Philip, not Charles. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From rantingrickjohnson at gmail.com Wed Sep 13 00:39:56 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Sep 2017 21:39:56 -0700 (PDT) Subject: Simple board game GUI framework In-Reply-To: References: Message-ID: <01750f89-1c91-4bee-89dc-0fc531f5e345@googlegroups.com> Terry Reedy wrote: > Paul Moore said: [...] > I was going to suggest tkinter. I would second Terry's advice here. If a low barrier and simplicity are what you want, then i would suggest tkinter first and Pygame second. You can do a lot with a tk.Canvas widget, and for proper image support make sure to install the third party PIL library. If neither of those are interesting to you, then you can try any of the third party GUI or game libraries all the way down to PyOpenGL, where you get ultimate control, for the small price of your sanity. (insert maniacal laugh track here) > > The following code is basically the core of what I need: > > > > import tkinter as tk > > > > def create_board(root): > > board = {} > > for r in range(8): > > for c in range(8): > > lbl = tk.Button(bg="white", text=" ", font=("Consolas", 12)) > > lbl.grid(row=r, column=c) > > board[r,c] = lbl Dude, that tuple is naked! And nudity in public places is not cool; unless of course your code is a Ms. America model, or it resides in a nudist colony (Hey, don't forget your "sitting towel"!), which obviously is not true in either case. ;-) Try this instead: board[(r,c)] = lbl There. And now, and in more ways than one, we have defined some bondaries. From steve+comp.lang.python at pearwood.info Wed Sep 13 00:58:56 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Sep 2017 04:58:56 GMT Subject: [Tutor] beginning to code References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> Message-ID: <59b8bb0f$0$16632$b1db1813$d948b532@news.astraweb.com> On Tue, 12 Sep 2017 20:01:52 -0700, Rick Johnson wrote: > But just because we have been trained that the implicit `if x:` is > shorthand for the reasonable `if bool(x) == True:` That's not reasonable. bool(x) already returns a True or False flag, comparing it to True is superfluous. (Regardless of whether you use `is` or a slower equality test.) It is excessively redundantly surplus. And where do you stop? If you don't believe `bool(x)` is a flag, then you can't believe `bool(x) == True` either, leading you into an infinite regress of superfluous redundancy: if (bool(x) == True) == True: if ((bool(x) == True) == True) == True: if (((bool(x) == True) == True) == True) == True: if ((((bool(x) == True) == True) == True) == True) == True: if (((((bool(x) == True) == True) == True) == True) == True) == True: # help, I don't know how to stop!!!! The *only* reasonable place to stop is right at the beginning: if bool(x): at least for languages like Pascal and Java where `if` requires a specific boolean type. And assuming x is not already a bool. If it is a bool, you of course wouldn't redundantly call bool on it repeatedly again and again redundantly: if bool(bool(bool(bool(bool( ... (x)))))))...) # help, I don't know where to stop!!! If x is already a flag, then it would be silly to waste time calling bool even once. You wouldn't write this: a = int(25) b = int(30) c = int( (int(a) + int(b))*int(2) ) values = list([1, 2, 3]) x = list(values)[int(c)] No, its quite obvious that anyone who would call bool() on something which is already a bool, let alone the even more excessively superfluous `if bool(x) is True`, is a cargo-cult programmer who isn't fluent enough in the Python language to know what they're doing. And of course the beauty of duck-typing in Python is that *everything* is a bool, or at least quacks like a bool and swims like a bool. [...] > they're just reductio ad absurdum. I see that your understanding of logical fallacies is as penetrating and profound as your understanding of Python's design. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From rantingrickjohnson at gmail.com Wed Sep 13 02:20:21 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 12 Sep 2017 23:20:21 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: <59b8bb0f$0$16632$b1db1813$d948b532@news.astraweb.com> References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> <59b8bb0f$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Rick Johnson wrote: > > > > > But just because we have been trained that the implicit > > `if x:` is shorthand for the reasonable `if bool(x) == > > True:` > > That's not reasonable. bool(x) already returns a True or > False flag, comparing it to True is superfluous. So what? That's a simple matter of translating source code to byte code and has nothing to do with your inability to grasp that byte code and source code are not a one-to-one translation. Although the byte code and the source code of a program carry the same _general_ information about how a program will execute, the byte code is optimized for machine communication whereas the source code is optimizes (or should be!) for human communication. Byte code is meant to be as concise and optimized as possible, whereas source code is meant to be more elaborate. Humans are not machines, and machines are not humans. We communicate in different ways. Source code must be intuitive, and `if x` is not intuitive, and if you don't believe me, then ask a non-programmer to intuit what `if x` means. A neophyte may know enough about basic logic to guess that the `if` is testing for some kind True/False value, but the same noob will never guess that the boolean value of an object can change based on such abstract notions as "empty versus not empty" or "zero versus more than zero". So, uhh, good luck with that little survey! Your flaw is to judge the "if x" statement on the purely abstract byte-compiled machine level, whereas i am judging the statement on an intuitive human level. We can define what happens on the abstract level all we want, but we cannot define intuition. Neither can we define practicality. Either a statement is intuitive, or it is not. Either an action is practical, or it is not. Do you also understand that we can translate *ANY* source code into any byte code we want? There are no laws in the universe that prevent Python from translating the source code of "if bool(x) is True" to the same byte code that is currently created by "if x". So stop lying, or prove that such a translation is impossible. > (Regardless of whether you use `is` or a slower equality > test.) It is excessively redundantly surplus. And where do > you stop? If you don't believe `bool(x)` is a flag, then > you can't believe `bool(x) == True` either, leading you > into an infinite regress of superfluous redundancy: > > [snip: hyperbole] > > The *only* reasonable place to stop is right at the beginning: > > if bool(x): > > at least for languages like Pascal and Java where `if` > requires a specific boolean type. Well, i should at least consider this a small victory. Again, i must stress, that what Python sees is a matter of the byte code translation, not a matter of what *WE*, as programmers, see. So your argument is ignoring the real issue. From no.email at nospam.invalid Wed Sep 13 02:44:57 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 12 Sep 2017 23:44:57 -0700 Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> Message-ID: <87h8w79jx2.fsf@nightsong.com> Chris Angelico writes: > Why? Unless they're going to be maintaining a Py2 codebase, why should > they learn the older version with less features? Are there actually Py3 codebases? I guess there must be, even though I've never seen one. Every Python codebase of any size that I know of is Py2. So yes, of course they're working on a Py2 codebase. That's the only kind there is, as far as I know. From auriocus at gmx.de Wed Sep 13 03:16:24 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 13 Sep 2017 09:16:24 +0200 Subject: Simple board game GUI framework In-Reply-To: References: Message-ID: Am 11.09.17 um 16:12 schrieb Paul Moore: > Thanks for the information. That's more or less the sort of thing I > was thinking of. In fact, from a bit more browsing, I found another > way of approaching the problem - rather than using pygame, it turns > out to be pretty easy to do this in tkinter. That is good advice. Actually, I was going to suggest to look into GUI frameworks to understand OO and classes. GUI is one of the topics where OO really fits well and has practical applications. For example, derive from an entry widget to implement a greyish "hint" value which vanishes when you type in something new. That thing is a class and there can be more than one of it in program, there you have instances. Or an entry which does autocompletion on a list of predefined values when you hit tab or enter. Useful, and obviously you need different instances for different input fields, hence objects. In some other more statically compiled languages, OO is shoehorned into everything ("abstract factory" and that stuff), because virtual calls are the only way to get dynamic behaviour / late binding. In Python you use OO only in places where it really makes sense. Christian From tjol at tjol.eu Wed Sep 13 04:15:48 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 13 Sep 2017 10:15:48 +0200 Subject: Python dress In-Reply-To: <99ed6ab4-7270-f62f-45e4-fdd1202fee3e@mrabarnett.plus.com> References: <59b86e79$0$16743$b1db1813$d948b532@news.astraweb.com> <99ed6ab4-7270-f62f-45e4-fdd1202fee3e@mrabarnett.plus.com> Message-ID: <916da9e4-0ef0-d8c1-bdfd-fb940ea54a49@tjol.eu> On 2017-09-13 02:12, MRAB wrote: > On 2017-09-13 00:32, Steve D'Aprano wrote: >> The amusing thing to my mind is that the pro-discrimination, >> anti-equality >> faction also tend to be the most conservative[1] pro-monarchy faction. >> I don't >> recall seeing them go into paroxysms of gender confusion when Prince >> Charles, >> Duke of Edinburgh, appears in public wearing a kilt. >> > You do know that Prince Charles is the Prince of Wales and that the Duke > of Edinburgh is his father, don't you? :-) Big difference. One will never be king, the other should never be king. -- Thomas Jollans From steve+comp.lang.python at pearwood.info Wed Sep 13 04:16:55 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Sep 2017 08:16:55 GMT Subject: [Tutor] beginning to code References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> <59b8bb0f$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: <59b8e977$0$16632$b1db1813$d948b532@news.astraweb.com> On Tue, 12 Sep 2017 23:20:21 -0700, Rick Johnson wrote: > Steven D'Aprano wrote: >> Rick Johnson wrote: >> >> >> > But just because we have been trained that the implicit `if x:` is >> > shorthand for the reasonable `if bool(x) == True:` >> >> That's not reasonable. bool(x) already returns a True or False flag, >> comparing it to True is superfluous. > > So what? That's a simple matter of translating source code to byte code Who cares about the byte code? We don't read or write byte code. The *source code* you wrote is dumb. It displays an appalling lack of understanding of Python's semantics, and poor reasoning about even the simplest logical tests. Here's another person's comments: "When I see someBool == true, I can't help but feel like the programmer hasn't internalized the idea of evaluation, which is a pretty fundamental deficiency." https://softwareengineering.stackexchange.com/posts/12828/revisions You might as well write: if (x is True) and (True is True): # just in case True is False In plain English terms, you are doing the equivalent of saying: "Is (is that true?) true?" Who talks like that? Why should we write code like that? -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From tjol at tjol.eu Wed Sep 13 04:19:24 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 13 Sep 2017 10:19:24 +0200 Subject: Python dress In-Reply-To: <73885088-e749-4011-9902-37aa57a19d6b@googlegroups.com> References: <73885088-e749-4011-9902-37aa57a19d6b@googlegroups.com> Message-ID: <929970be-f665-af1d-a5ab-14e137c68852@tjol.eu> On 2017-09-13 02:54, Rick Johnson wrote: > On Tuesday, September 12, 2017 at 6:59:32 PM UTC-5, Gregory Ewing wrote: >> Larry Martell wrote: >>> https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress >> >> The only disadvantage might be the GIL interfering with >> parallel processing using multiple machines in a >> laundromat. > > Oh, not the only disadvantage: being that 5 of the machines > are running Python3, and 4 are running Python2, and one is > still stubbornly running Python1, and being that the owner > forgot to mark them, if we put the dress in the wrong > machine -- *BOOM* -- exceptions all over the floor. > > Can anyone think of a way to version-test these machines > without wasting a quarter, or requiring the services of a > clean-up crew? > Should "yield" at the machine in a menacing, regal voice. if it yields, it is Python 2.3 or newer. -- Thomas Jollans From leamhall at gmail.com Wed Sep 13 08:33:32 2017 From: leamhall at gmail.com (leam hall) Date: Wed, 13 Sep 2017 08:33:32 -0400 Subject: "tkinter" In-Reply-To: References: Message-ID: On Wed, Sep 13, 2017 at 8:28 AM, Stefan Ram wrote: > I presume that "tkinter" is intended to be pronounced > "logically": > > T K inter (tee kay inter /ti keI In t%/) > > . But it would be faster to pronounce it > > T kinter (tee kinter /ti kIn t%/) > > . So far I've only ever read it, never heard it. > But while I am aware that the logical pronunciation should > be the correct one, I actually like the faster one. > > I heard a speaker mention GvR by name and it took me a bit, and IRC, to find out the Dutch pronunciation is different from the American. I've seen his name lots, hadn't heard it. Leam From tjol at tjol.eu Wed Sep 13 08:58:50 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 13 Sep 2017 14:58:50 +0200 Subject: "tkinter" In-Reply-To: References: Message-ID: <227c1515-cae3-88fd-9043-b85f6c6eabde@tjol.eu> On 2017-09-13 14:33, leam hall wrote: > On Wed, Sep 13, 2017 at 8:28 AM, Stefan Ram wrote: > >> I presume that "tkinter" is intended to be pronounced >> "logically": >> >> T K inter (tee kay inter /ti keI In t%/) >> >> . But it would be faster to pronounce it >> >> T kinter (tee kinter /ti kIn t%/) >> >> . So far I've only ever read it, never heard it. >> But while I am aware that the logical pronunciation should >> be the correct one, I actually like the faster one. >> >> > I heard a speaker mention GvR by name and it took me a bit, and IRC, to > find out the Dutch pronunciation is different from the American. I've seen > his name lots, hadn't heard it. I found it very distressing the first time I heard some American pronounce Guido something along the lines of "GoowEEdough"... Pronouncing the BDFL's name the Italian way is reasonable; pronouncing the "u" is not. From darinc at gmail.com Wed Sep 13 09:08:41 2017 From: darinc at gmail.com (Darin Gordon) Date: Wed, 13 Sep 2017 09:08:41 -0400 Subject: the core values of the Python "platform" Message-ID: Bryan Cantrill gave an interesting talk recently at a Node conference about "platform values" [1]. The talk lead me to think about what the core values of the Python "platform" are and I thought it would be good to ask this question of the community. What would you consider the top (<= 5) core values? Regards Darin [1] http://www.nodesummit.com/videos/?the-video-node2017=45 From larry.martell at gmail.com Wed Sep 13 09:08:46 2017 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 13 Sep 2017 09:08:46 -0400 Subject: trace not working with rpy2 Message-ID: When I invoke my script with trace it fails with: /usr/local/lib/python2.7/site-packages/rpy2/rinterface/__init__.py:186: RRuntimeWarning: Fatal error: unable to open the base package and the trace file has: __init__.py(1): __init__.py(19): from rpy2.robjects.robject import RObjectMixin, RObject cannot find system Renviron I have tried running trace with both of these options, but I still get the same error. --ignore-module=rpy2 --ignore-dir=/usr/local/lib/python2.7/site-packages/rpy2 Anyone know how I can get around this error so I can use trace? From christopher_reimer at icloud.com Wed Sep 13 09:12:41 2017 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 13 Sep 2017 06:12:41 -0700 Subject: "tkinter" In-Reply-To: References: Message-ID: <57AF4E2B-3C05-4961-8730-2EC36521BF4D@icloud.com> > On Sep 13, 2017, at 5:28 AM, Stefan Ram wrote: > > I presume that "tkinter" is intended to be pronounced > "logically": > > T K inter (tee kay inter /ti keI In t%/) > > . But it would be faster to pronounce it > > T kinter (tee kinter /ti kIn t%/) > > . So far I've only ever read it, never heard it. > But while I am aware that the logical pronunciation should > be the correct one, I actually like the faster one. > > -- > https://mail.python.org/mailman/listinfo/python-list When I started my technical career 20+ years ago, tcl/tk was pronounced "tickle" by the engineers. Not sure if that was correct then or now. Chris R. From tjol at tjol.eu Wed Sep 13 09:13:37 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 13 Sep 2017 15:13:37 +0200 Subject: the core values of the Python "platform" In-Reply-To: References: Message-ID: <27b25bd6-da51-7106-3a84-37bdb7c56260@tjol.eu> On 2017-09-13 15:08, Darin Gordon wrote: > Bryan Cantrill gave an interesting talk recently at a Node conference about > "platform values" [1]. The talk lead me to think about what the core values > of the Python "platform" are and I thought it would be good to ask this > question of the community. What would you consider the top (<= 5) core > values? >>> import this > > Regards > > > Darin > > [1] http://www.nodesummit.com/videos/?the-video-node2017=45 > -- Thomas Jollans From leamhall at gmail.com Wed Sep 13 09:16:43 2017 From: leamhall at gmail.com (leam hall) Date: Wed, 13 Sep 2017 09:16:43 -0400 Subject: the core values of the Python "platform" In-Reply-To: References: Message-ID: On Wed, Sep 13, 2017 at 9:08 AM, Darin Gordon wrote: > Bryan Cantrill gave an interesting talk recently at a Node conference about > "platform values" [1]. The talk lead me to think about what the core values > of the Python "platform" are and I thought it would be good to ask this > question of the community. What would you consider the top (<= 5) core > values? > > Would that be close to the Zen of Python? From viktorovichandrej at gmail.com Wed Sep 13 09:25:08 2017 From: viktorovichandrej at gmail.com (Andrej Viktorovich) Date: Wed, 13 Sep 2017 06:25:08 -0700 (PDT) Subject: += and =+ Message-ID: Hello, I have done mistake while trying to increment int i=1 i=+ this left i unchangeable and I got no error. But what =+ means at all? From bc at freeuk.com Wed Sep 13 10:00:47 2017 From: bc at freeuk.com (bartc) Date: Wed, 13 Sep 2017 15:00:47 +0100 Subject: += and =+ In-Reply-To: References: Message-ID: <7SauB.336342$yz.245294@fx34.am4> On 13/09/2017 14:25, Andrej Viktorovich wrote: > Hello, > > I have done mistake while trying to increment int > > i=1 > i=+ > > this left i unchangeable and I got no error. But what =+ means at all? Did you mean i=+1 ? This means i is set to the value +1. Usually just written 1. Try: i=88 i=+1 and see if i now changes. -- bartc From grant.b.edwards at gmail.com Wed Sep 13 10:15:45 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 13 Sep 2017 14:15:45 +0000 (UTC) Subject: "tkinter" References: <57AF4E2B-3C05-4961-8730-2EC36521BF4D@icloud.com> Message-ID: On 2017-09-13, Christopher Reimer wrote: > When I started my technical career 20+ years ago, tcl/tk was > pronounced "tickle" by the engineers. Not sure if that was correct > then or now. I've always heard "tickle" as the pronounciation for "TCL". I've never heard anybody try to pronounce TCL/Tk. -- Grant Edwards grant.b.edwards Yow! Now we can become at alcoholics! gmail.com From grant.b.edwards at gmail.com Wed Sep 13 10:17:55 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 13 Sep 2017 14:17:55 +0000 (UTC) Subject: += and =+ References: Message-ID: On 2017-09-13, Andrej Viktorovich wrote: > I have done mistake while trying to increment int > > i=1 > i=+ > > this left i unchangeable and I got no error. I doubt it. Python 2.7.12 (default, Jan 3 2017, 10:08:10) [GCC 4.9.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> i=1 >>> i=+ File "", line 1 i=+ ^ SyntaxError: invalid syntax Python 3.4.5 (default, Jan 3 2017, 10:09:58) [GCC 4.9.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> i=1 >>> i=+ File "", line 1 i=+ ^ SyntaxError: invalid syntax >>> -- Grant Edwards grant.b.edwards Yow! It's NO USE ... I've at gone to "CLUB MED"!! gmail.com From rantingrickjohnson at gmail.com Wed Sep 13 10:47:41 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 13 Sep 2017 07:47:41 -0700 (PDT) Subject: "tkinter" In-Reply-To: References: Message-ID: leam hall wrote: >Stefan Ram wrote: > > > I presume that "tkinter" is intended to be pronounced > > "logically": > > > > T K inter (tee kay inter /ti keI In t%/) > > > > . But it would be faster to pronounce it > > > > T kinter (tee kinter /ti kIn t%/) Since [Tt]kinter is a wrapper around "Tcl" (the programming language)'s GUI library named "Tk", then i say it is important to emphasize the {TEE-KAY} part. So {TEE-KAY- ENTER} would be the most appropriate pronunciation, IMO. From rantingrickjohnson at gmail.com Wed Sep 13 10:50:17 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 13 Sep 2017 07:50:17 -0700 (PDT) Subject: "tkinter" In-Reply-To: References: <57AF4E2B-3C05-4961-8730-2EC36521BF4D@icloud.com> Message-ID: <3cff801e-0b05-4953-9642-486d3967a976@googlegroups.com> Grant Edwards wrote: > I've always heard "tickle" as the pronounciation for "TCL". I've > never heard anybody try to pronounce TCL/Tk. Oh that's easy: {TICKLE-TEE-KAY}. (insert giggle track here) From tjol at tjol.eu Wed Sep 13 10:58:01 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 13 Sep 2017 16:58:01 +0200 Subject: "tkinter" In-Reply-To: References: Message-ID: <22db49d6-30a0-3593-daa4-b5863cdd6673@tjol.eu> On 2017-09-13 16:47, Rick Johnson wrote: > leam hall wrote: > {TEE-KAY-ENTER} enter? not inter? -- Thomas Jollans From rantingrickjohnson at gmail.com Wed Sep 13 11:10:41 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 13 Sep 2017 08:10:41 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: <59b8e977$0$16632$b1db1813$d948b532@news.astraweb.com> References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <679713fa-03d3-4cae-ae4e-642391ea0e4e@googlegroups.com> <59b8bb0f$0$16632$b1db1813$d948b532@news.astraweb.com> <59b8e977$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: <08d256e2-a51b-45c0-92fb-07337e1b36d2@googlegroups.com> Steven D'Aprano wrote: > Rick Johnson wrote: > > Steven D'Aprano wrote: > >> Rick Johnson wrote: > > > > > > > > But just because we have been trained that the implicit > > > > `if x:` is shorthand for the reasonable `if bool(x) == > > > > True:` > > > > > > That's not reasonable. bool(x) already returns a True or > > > False flag, comparing it to True is superfluous. > > > > So what? That's a simple matter of translating source code > > to byte code > > Who cares about the byte code? We don't read or write byte > code. That was my point! Are you really this dense or just trolling me? > The *source code* you wrote is dumb. It displays an > appalling lack of understanding of Python's semantics, No, it is the Python semantics that are dumb, not my code. > and poor reasoning about even the simplest logical tests. Code is read more often than it is written, so if we must invest a few more keystrokes into a statement so that the _intent_ is _clear_, then so be it. And if such clarity produces sub-optimal byte code, well, that is a simple matter of redefining Python's translation procedure for the benefit of the _human_, not for the benefit of the _machine_, and certainly not for the sake of arbitrarily designed evaluation rules. Your priorities are all screwed- up, D'Aprano. > Here's another person's comments: > > "When I see someBool == true, I can't help but feel like > the programmer hasn't internalized the idea of evaluation, > which is a pretty fundamental deficiency." Like a canine, this "other person" has been trained for blind obedience, and obviously has no idea that source code is meant for human communication, and evaluation is arbitrarily defined. > You might as well write: [snip: absurd ramblings] From ndagis at gmail.com Wed Sep 13 11:34:27 2017 From: ndagis at gmail.com (Ndagi Stanley) Date: Wed, 13 Sep 2017 15:34:27 +0000 Subject: Vue-Django Message-ID: I extended the VueJS CLI to allow me get a *Django* project with VueJS up and running for any project or my next hackathon project with one command. https://github.com/NdagiStanley/vue-django I was impressed by the manner in which the Github stars increased in the forked repo and judging that it was of value to other devs besides myself, I'd appreciate your views in terms of possible features, other use-cases this can extend to and what I can think about doing :) Collaboration, Advice From auriocus at gmx.de Wed Sep 13 11:35:26 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 13 Sep 2017 17:35:26 +0200 Subject: "tkinter" In-Reply-To: References: <57AF4E2B-3C05-4961-8730-2EC36521BF4D@icloud.com> Message-ID: Am 13.09.17 um 16:15 schrieb Grant Edwards: > On 2017-09-13, Christopher Reimer wrote: > >> When I started my technical career 20+ years ago, tcl/tk was >> pronounced "tickle" by the engineers. Not sure if that was correct >> then or now. > > I've always heard "tickle" as the pronounciation for "TCL". I've > never heard anybody try to pronounce TCL/Tk. > It's indeed usually pronounced "tickle" T K in the Tcl community. The feather icon alludes to the "tickle" part, and "TK" is an acronym for "toolkit". Somtimes people prefer spelling "T C L", but most use "tickle". Reference: I've been at some EuroTcl conferences. The talks are on youtube, too: https://www.youtube.com/playlist?list=PLHNnTryxvDncfQbxbzfE4XMogoTa6pknP Christian From ian.g.kelly at gmail.com Wed Sep 13 12:05:45 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 13 Sep 2017 10:05:45 -0600 Subject: Simple board game GUI framework In-Reply-To: <01750f89-1c91-4bee-89dc-0fc531f5e345@googlegroups.com> References: <01750f89-1c91-4bee-89dc-0fc531f5e345@googlegroups.com> Message-ID: On Tue, Sep 12, 2017 at 10:39 PM, Rick Johnson wrote: >> > board[r,c] = lbl > > Dude, that tuple is naked! And nudity in public places is > not cool; unless of course your code is a Ms. America model, > or it resides in a nudist colony (Hey, don't forget your > "sitting towel"!), which obviously is not true in either > case. ;-) Try this instead: > > board[(r,c)] = lbl > > There. And now, and in more ways than one, we have defined some > bondaries. It's not naked. It has the square brackets around it, making the parentheses clearly redundant. I use constructions like "board[r, c]" all the time and I don't see a style problem with it. Now, as to not having a space after the comma, that's just sinful. From dvl at psu.edu Wed Sep 13 12:18:06 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Wed, 13 Sep 2017 12:18:06 -0400 Subject: [Tutor] beginning to code In-Reply-To: mailman.1813.1505308438.15582.python-list@python.org References: Message-ID: <1505319485l.29425864l.0l@psu.edu> I have not yet mastered how to respond to a particular note in a threadwith the mailer that I use, so this is not in response to anyone in particular,but just to some of the sentiments as a whole. > if x:> # do something Completely out of context, I would dislike it just because it is far too vague.Is it testing for zero? for an empty list? or for some object's completelyarbitrary definition of truthiness? x.._bool__() seems to me to be just as efficient, but we don't like calling dunders.bool(x) should mean the same thing, perhaps with an extra function invocationto look for the dunder. But even so, nothing here sheds light on what that Boolean outcome means. I would agree that testing any of those for '== True' or the like is pointlessredundancy, which may or may not be slower, depending on optimization issues. ------ but in context is another thing entirely. was x assigned to recently? is the type of x obvious so its truthiness is also obvious?Then fine -- if it is clear that x is a list, I'm happy to use this to test for an empty list.But if x is some other creation, like a user defined type, I would really prefer to seesomething analogous to: if not x.is_empty() or x.exists() or x.has_brain() And most definitely if x is assigned outside my control, I would definitely wantsome way to test or verify x's type before I start using it, lest my randomnumber generator with its (A + B * C) % D finds itself concatenating strings and formatting data. Roger Christman From walters.justin01 at gmail.com Wed Sep 13 12:19:20 2017 From: walters.justin01 at gmail.com (justin walters) Date: Wed, 13 Sep 2017 09:19:20 -0700 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <87h8w79jx2.fsf@nightsong.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <87h8w79jx2.fsf@nightsong.com> Message-ID: On Tue, Sep 12, 2017 at 11:44 PM, Paul Rubin wrote: > Chris Angelico writes: > > Why? Unless they're going to be maintaining a Py2 codebase, why should > > they learn the older version with less features? > > Are there actually Py3 codebases? I guess there must be, even though > I've never seen one. Every Python codebase of any size that I know of > is Py2. So yes, of course they're working on a Py2 codebase. That's > the only kind there is, as far as I know. > -- > https://mail.python.org/mailman/listinfo/python-list > This is Zed Shaw levels of willful ignorance here. The codebase I work on at my job is entirely Python 3. I'm sure the same is true for anyone building a new piece of software with Python since at least 2015. Not everyone gets paid to maintain legacy software in "enterprise" corporations. Some of us are contractors or work for startups. From p.f.moore at gmail.com Wed Sep 13 13:40:52 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 13 Sep 2017 18:40:52 +0100 Subject: Simple board game GUI framework In-Reply-To: References: <01750f89-1c91-4bee-89dc-0fc531f5e345@googlegroups.com> Message-ID: On 13 September 2017 at 17:05, Ian Kelly wrote: > On Tue, Sep 12, 2017 at 10:39 PM, Rick Johnson > wrote: >>> > board[r,c] = lbl >> >> Dude, that tuple is naked! And nudity in public places is >> not cool; unless of course your code is a Ms. America model, >> or it resides in a nudist colony (Hey, don't forget your >> "sitting towel"!), which obviously is not true in either >> case. ;-) Try this instead: >> >> board[(r,c)] = lbl >> >> There. And now, and in more ways than one, we have defined some >> bondaries. > > It's not naked. It has the square brackets around it, making the > parentheses clearly redundant. I use constructions like "board[r, c]" > all the time and I don't see a style problem with it. > > Now, as to not having a space after the comma, that's just sinful. Ha, by including that line I managed to distract everyone from how bad the *rest* of the code was! My plan worked! Bwahahaha :-) Paul From alister.ware at ntlworld.com Wed Sep 13 13:58:10 2017 From: alister.ware at ntlworld.com (alister) Date: Wed, 13 Sep 2017 17:58:10 GMT Subject: Python dress Message-ID: On Wed, 13 Sep 2017 04:15:26 +0000, Steven D'Aprano wrote: > On Wed, 13 Sep 2017 01:12:25 +0100, MRAB wrote: > >>> I don't recall seeing them go into paroxysms of gender confusion when >>> Prince Charles, >>> Duke of Edinburgh, appears in public wearing a kilt. >> >> You do know that Prince Charles is the Prince of Wales and that the >> Duke of Edinburgh is his father, don't you? :-) > > Ah, yes, thanks for the correction. Of course I was thinking about > Prince Philip, not Charles. but they both wear kilts so your statement could have said when prince charles OR the duke of edinburgh... -- Madness takes its toll. From alister.ware at ntlworld.com Wed Sep 13 13:59:59 2017 From: alister.ware at ntlworld.com (alister) Date: Wed, 13 Sep 2017 17:59:59 GMT Subject: Python dress Message-ID: On Wed, 13 Sep 2017 10:15:48 +0200, Thomas Jollans wrote: > On 2017-09-13 02:12, MRAB wrote: >> On 2017-09-13 00:32, Steve D'Aprano wrote: >>> The amusing thing to my mind is that the pro-discrimination, >>> anti-equality faction also tend to be the most conservative[1] >>> pro-monarchy faction. >>> I don't recall seeing them go into paroxysms of gender confusion when >>> Prince Charles, >>> Duke of Edinburgh, appears in public wearing a kilt. >>> >> You do know that Prince Charles is the Prince of Wales and that the >> Duke of Edinburgh is his father, don't you? :-) > > Big difference. One will never be king, the other should never be king. The other will quite correctly be King there is no constitutional reason why not (or are you another one of the many who try to hide from their own part in the death of Diana by blaming the royals). -- Mystics always hope that science will some day overtake them. -- Booth Tarkington From larry.martell at gmail.com Wed Sep 13 15:05:02 2017 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 13 Sep 2017 15:05:02 -0400 Subject: rmtree message Message-ID: I have a script that creates a tmp dir, create a lot of files in it, and when done, does a rmtree on the dir. When it does that I get this message: shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory But no exception is thrown. How can I determine why I get this message? From grant.b.edwards at gmail.com Wed Sep 13 15:09:40 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 13 Sep 2017 19:09:40 +0000 (UTC) Subject: "tkinter" References: <22db49d6-30a0-3593-daa4-b5863cdd6673@tjol.eu> <9otirc9s1g8hkvmcffn58pdtu4oo2dbefh@4ax.com> Message-ID: On 2017-09-13, Dennis Lee Bieber wrote: > On Wed, 13 Sep 2017 16:58:01 +0200, Thomas Jollans declaimed > the following: > >>On 2017-09-13 16:47, Rick Johnson wrote: >>> leam hall wrote: >>> {TEE-KAY-ENTER} >> >>enter? not inter? > > Well... we aren't planning on burying it, are we? I tried to write a small (but non-trivial) Tcl app once[1], and would happily vote to bury Tcl and then might even dance on its grave. Tkinter, OTOH, is great for small, simple GUI apps -- with a few caveats: 1. You have to grit your teeth because you know there's a Tcl interpreter buried in the details. 2. When you package up a trivial Tkinter application using something like py2exe, it balloons up to a ginormous size (way larger than the equivalent app written using wxPython). I assume this is caused largely by 1. 3. No matter how hard you try, Tkinter apps always look a bit foreign. I've just given up trying to them to look like native apps: it doesn't work, and it annoys the mule. [1] After wasting several days fighting with TCL's quoting sematics, I gave up and wrote the app in Scheme (and was done in a couple hours). -- Grant Edwards grant.b.edwards Yow! hubub, hubub, HUBUB, at hubub, hubub, hubub, HUBUB, gmail.com hubub, hubub, hubub. From marko at pacujo.net Wed Sep 13 15:54:49 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 13 Sep 2017 22:54:49 +0300 Subject: "tkinter" References: <22db49d6-30a0-3593-daa4-b5863cdd6673@tjol.eu> Message-ID: <87ingm74s6.fsf@elektro.pacujo.net> Thomas Jollans : > On 2017-09-13 16:47, Rick Johnson wrote: >> leam hall wrote: >> {TEE-KAY-ENTER} > > enter? not inter? Maybe a third of Americans make no distinction between -e- and -i- in front of a nasal sound: Most of my coworkers in Southern California pronounced "pin" and "pen" identically even though the map doesn't reveal that. Same with "Linux" and "Lennox", and "hymn" and "hem". Marko From ivanjankovic777777 at gmail.com Wed Sep 13 16:09:47 2017 From: ivanjankovic777777 at gmail.com (ivan77) Date: Wed, 13 Sep 2017 13:09:47 -0700 (PDT) Subject: Creating a python client for an external service advice Message-ID: Hi All, I would like to create a Python module/client library for a data visualization service that I use (and will be using more) as my first larger contribution to open source Python. I have not come across any best practices for this, and am wondering whether there are some resources that you may know of. Aside from looking at other client libraries I use/have used, is there something more that I can use as a reference? Thanks, Ivan From ivanjankovic777777 at gmail.com Wed Sep 13 16:17:10 2017 From: ivanjankovic777777 at gmail.com (ivan77) Date: Wed, 13 Sep 2017 13:17:10 -0700 (PDT) Subject: rmtree message In-Reply-To: References: Message-ID: As a start, have you done this: Before the rmtree command, find out which directory you end up in after all of your commands, and they figure out whether you have access to the directory you are trying to delete from there. From ivan at linebox.ca Wed Sep 13 17:37:25 2017 From: ivan at linebox.ca (ivan at linebox.ca) Date: Wed, 13 Sep 2017 14:37:25 -0700 (PDT) Subject: My Issues In-Reply-To: References: <59065F64-409B-4497-8CC3-864B3571DC54@yahoo.com> Message-ID: <7117b21c-5d89-4bc5-a806-7b333ad41654@googlegroups.com> Hi Carson, If you are having big troubles installing Python on Windows (it really should be a click install from the Python download page here https://www.python.org/downloads/) you can use Anaconda to install, which usually makes installing python on problematic windows machines much easier. Follow this tutorial https://medium.com/@GalarnykMichael/install-python-on-windows-anaconda-c63c7c3d1444 Use this download page: https://www.anaconda.com/download/ Don't get discouraged. Sometimes getting up and running is a bit of a pain, but it will be smooth sailing after you get it in there the first time. Ivan From sean.dizazzo at gmail.com Wed Sep 13 17:39:56 2017 From: sean.dizazzo at gmail.com (Sean DiZazzo) Date: Wed, 13 Sep 2017 14:39:56 -0700 (PDT) Subject: rmtree message In-Reply-To: References: Message-ID: <42fd9284-ec50-45ae-ae7b-876139d89318@googlegroups.com> On Wednesday, September 13, 2017 at 12:06:20 PM UTC-7, Larry.... at gmail.com wrote: > I have a script that creates a tmp dir, create a lot of files in it, > and when done, does a rmtree on the dir. When it does that I get this > message: > > shell-init: error retrieving current directory: getcwd: cannot access > parent directories: No such file or directory > > But no exception is thrown. How can I determine why I get this message? I usually see that message when I am in a directory in the shell but it has already been deleted by another process. Make sure the directory exists. Is another part of your script deleting the root directory while rmtree is running? Or something of the like. From sean.dizazzo at gmail.com Wed Sep 13 17:43:25 2017 From: sean.dizazzo at gmail.com (Sean DiZazzo) Date: Wed, 13 Sep 2017 14:43:25 -0700 (PDT) Subject: Python dress In-Reply-To: References: Message-ID: <08fe3cee-c85c-4e8e-8d32-88e947a1f5c0@googlegroups.com> On Tuesday, September 12, 2017 at 9:18:12 AM UTC-7, Larry.... at gmail.com wrote: > Not too many females here, but anyway: > > https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress > > (And if any guys want to wear this, there's nothing wrong with that.) I'm going to buy it for my girl wear it to all of my work parties. :) From breamoreboy at gmail.com Wed Sep 13 18:02:02 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Wed, 13 Sep 2017 15:02:02 -0700 (PDT) Subject: Python dress In-Reply-To: <08fe3cee-c85c-4e8e-8d32-88e947a1f5c0@googlegroups.com> References: <08fe3cee-c85c-4e8e-8d32-88e947a1f5c0@googlegroups.com> Message-ID: <66196f96-10a1-4e7a-8d6c-d83b508d5c51@googlegroups.com> On Wednesday, September 13, 2017 at 10:43:47 PM UTC+1, Sean DiZazzo wrote: > On Tuesday, September 12, 2017 at 9:18:12 AM UTC-7, Larry.... at gmail.com wrote: > > Not too many females here, but anyway: > > > > https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress > > > > (And if any guys want to wear this, there's nothing wrong with that.) > > I'm going to buy it for my girl wear it to all of my work parties. :) What is she going to wear? :) -- Kindest regards. Mark Lawrence. From ben+python at benfinney.id.au Wed Sep 13 18:46:46 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 14 Sep 2017 08:46:46 +1000 Subject: "tkinter" References: Message-ID: <85vakm6wtl.fsf@benfinney.id.au> ram at zedat.fu-berlin.de (Stefan Ram) writes: > I presume that "tkinter" is intended to be pronounced > "logically": > > T K inter (tee kay inter /ti keI In t%/) This is how I've always pronounced it. The toolkit in question is named ?tk?, which I have only ever known to be pronounced ?tee kay?. The rest of the word is an abbreviation of ?interface?. So, to me ?Tkinter? is pronounced ?tee kay inter?. > . But it would be faster to pronounce it Speed at the expense of clarity is a goal difficult to justify in programming, and is even harder to justify in human speech. So, that basis doesn't convince me of a useful pronunciation. -- \ ?[R]ightful liberty is unobstructed action, according to our | `\ will, within limits drawn around us by the equal rights of | _o__) others.? ?Thomas Jefferson, 1819 | Ben Finney From sean.dizazzo at gmail.com Wed Sep 13 20:18:48 2017 From: sean.dizazzo at gmail.com (Sean DiZazzo) Date: Wed, 13 Sep 2017 17:18:48 -0700 (PDT) Subject: Python dress In-Reply-To: <66196f96-10a1-4e7a-8d6c-d83b508d5c51@googlegroups.com> References: <08fe3cee-c85c-4e8e-8d32-88e947a1f5c0@googlegroups.com> <66196f96-10a1-4e7a-8d6c-d83b508d5c51@googlegroups.com> Message-ID: <7dbe3620-6dc9-433c-8cd0-b3d7c0f5dc9e@googlegroups.com> On Wednesday, September 13, 2017 at 3:02:18 PM UTC-7, bream... at gmail.com wrote: > On Wednesday, September 13, 2017 at 10:43:47 PM UTC+1, Sean DiZazzo wrote: > > On Tuesday, September 12, 2017 at 9:18:12 AM UTC-7, Larry.... at gmail.com wrote: > > > Not too many females here, but anyway: > > > > > > https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress > > > > > > (And if any guys want to wear this, there's nothing wrong with that.) > > > > I'm going to buy it for my girl wear it to all of my work parties. :) > > What is she going to wear? :) > > -- > Kindest regards. > > Mark Lawrence. She's gonna wear the geek dress with pride! She knows. There's a nice little Coco Chanel I have picked out for myself. :P From ben.usenet at bsb.me.uk Wed Sep 13 20:31:52 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Thu, 14 Sep 2017 01:31:52 +0100 Subject: tictactoe script - commented - may have pedagogical value References: <1f13ef83-c570-1966-4ba6-df66ee24864c@kynesim.co.uk> <59b0a1cb$0$16743$b1db1813$d948b532@news.astraweb.com> <59b0f128$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: <87zi9yce87.fsf@bsb.me.uk> Ian Kelly writes: > On Thu, Sep 7, 2017 at 2:05 AM, Chris Angelico wrote: >> On Thu, Sep 7, 2017 at 5:11 PM, Steven D'Aprano >>> I don't know why it places *two* pairs of crosses and naughts instead of >>> one. Maybe the page is broken. >> >> I think it is, as part of being on the Internet Archive. To get a >> working version of the game, you may need to download it locally and >> clean it up a bit. > > I was also very confused at first. I found that you need to hide the > Internet Archive header because it covers the current board. It is > also surprising in that the player's move is recorded with 'O' despite > going first, which is contrary to the conventions of the game. Yes, the fact that it's archived is annoying. I thought it was a neat-enough idea to be worth doing cleanly, so I had a go: http://bsb.me.uk/ttt/ The HTML is obviously generated by a program, and one can generate lots of variations (even ones that will loose some games) but that can't be done in HTML -- the complete, fixed, tree of accessible positions must be there in the page before play starts. (I know this is an old thread now, but Real Life got in the way of programming as it so annoyingly does sometimes.) -- Ben. From leonardoafonso at gmail.com Wed Sep 13 21:49:25 2017 From: leonardoafonso at gmail.com (Leo) Date: Wed, 13 Sep 2017 18:49:25 -0700 (PDT) Subject: Algorithm of ordering in Python using recursion Message-ID: <9102d749-6d76-4fbd-bad4-903360ed8f0b@googlegroups.com> Can anyone help me find the error of this implementation in Python what am I doing with this TBiS algorithm? Algorithm: Function b = TBiSort(a, n, k, dir) if n == 1 then b = a; else h1 = TBiSort(a(1:n/2), n/2, k, dir); h2 = TBiSort(a(n/2+1:n),n/2,k, -dir); b = TBiMerge( [h1,h2], n, k, dir) Function b = TBiMerge(hh, n, k, dir) [hmin, hmax] = minmax(hh(1:n/2),hh(1+n/2:n)); bmin= TBiMerge(hmin, n2, k, dir); if n == 2k then b = bmin; else bmax = TBiMerge(hmax, n/2, k, dir); if dir == 'up' then b = [bmin,bmax]; else b = [bmax,bmin]; For conceptual clarity we present the algorithm in recursion fashion. Wecomment on the truncation. The TBiSort recursion goes downward first portioning the initial data list a all the way to the base level (sublist length 1), then goes upward with monotonic merges. In TBiMerge, the min max function renders the minimal and maximal between each element pair on the two input lists. The truncation begins at, and continues from, the point where the monotonic sublists reach in size to k. At each merge step, bmax, the upper part of the merged list is purged, and the total data is reduce d by half. By TBiMerge, the merged sublists never exceed k in size. Implementation: def TBiSort(a, n, k, direction): if n == 1: b = a else: h1 = TBiSort(a[0:n/2], n/2, k, direction) h2 = TBiSort(a[n/2:n], n/2, k, -direction) print h1 print h2 b = TBiMerge(h1 + h2, n, k, direction) return b def TBiMerge(hh, n, k, direction): p1 = [ min(hh[0:n/2]), max(hh[0:n/2]) ] print p1 p2 = [ min(hh[n/2:n+1]), max(hh[n/2:n+1]) ] print p2 bmin = TBiMerge(p1, n/2, k, direction) if n == 2 * k: b = bmin else: bmax = TBiMerge(p2, n/2, k, direction) if direction == 1: b = bmin + bmax else: b = bmax + bmin return b a = [3,7,4,8,6,2,1,5] k = 4 direction = 1 teste = TBiSort(a, len(a), k, direction) print teste From orgnut at yahoo.com Wed Sep 13 21:58:59 2017 From: orgnut at yahoo.com (Larry Hudson) Date: Wed, 13 Sep 2017 18:58:59 -0700 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> Message-ID: On 09/13/2017 09:18 AM, ROGER GRAYDON CHRISTMAN wrote: > I have not yet mastered how to respond to a particular note in a threadwith the > mailer that I use, so this is not in response to anyone in particular,but just > to some of the sentiments as a whole. >> if x:> # do something > Completely out of context, I would dislike it just because it is far too > vague.Is it testing for zero? for an empty list? or for some object's > completelyarbitrary definition of truthiness? It is absolutely NOT vague, and the answer is Yes for all of the above. It is well defined that ALL values can be used in a boolean sense. Quoting the on-line Standard Library reference: ------------ 4.1. Truth Value Testing Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean operations below. By default, an object is considered true unless its class defines either a __bool__() method that returns False or a __len__() method that returns zero, when called with the object. [1] Here are most of the built-in objects considered false: constants defined to be false: None and False. zero of any numeric type: 0, 0.0, 0j, Decimal(0), Fraction(0, 1) empty sequences and collections: '', (), [], {}, set(), range(0) Operations and built-in functions that have a Boolean result always return 0 or False for false and 1 or True for true, unless otherwise stated. (Important exception: the Boolean operations or and and always return one of their operands.) ------------- > but in context is another thing entirely. > was x assigned to recently? Irrelevant, it uses whatever the current value is. > is the type of x obvious so its truthiness is > also obvious?Then fine -- if it is clear that x is a list, I'm happy to use > this to test for an empty list.But if x is some other creation, like a user > defined type, I would really prefer to seesomething analogous to: > if not x.is_empty() or x.exists() or x.has_brain() > And most definitely if x is assigned outside my control, I would definitely > wantsome way to test or verify x's type before I start using it, lest my > randomnumber generator with its > (A + B * C) % D > finds itself concatenating strings and formatting data. Again irrelevant. That's the beauty/bane of duck typing. Learn to use it to your advantage and only check data types when it is absolutely necessary ? which is rarely! > Roger Christman > -- -=- Larry -=- From ben+python at benfinney.id.au Wed Sep 13 22:04:04 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 14 Sep 2017 12:04:04 +1000 Subject: the core values of the Python "platform" References: <27b25bd6-da51-7106-3a84-37bdb7c56260@tjol.eu> Message-ID: <85r2va6nor.fsf@benfinney.id.au> ram at zedat.fu-berlin.de (Stefan Ram) writes: > Thomas Jollans writes: > >>>> import this > > It says ?Flat is better than nested.?, which would > mean that > > x.f().g().h() > > is better than > > h( g( f( x ))) That's quite a stretch. Why would ?flat is better than nested? mean that specifically, rather than other possible interpretations? I could try to argue, for example, that ?flat is better than nested? means that ?no indentation is better than indentation?. But why should anyone take that interpretation seriously? As I understand it, ?flat is better than nested? is talking about *hierarchies* in a code base. It's not IIUC referring to anything about the difference between expressions like you wrote. -- \ ?If society were bound to invent technologies which could only | `\ be used entirely within the law, then we would still be sitting | _o__) in caves sucking our feet.? ?Gene Kan, creator of Gnutella | Ben Finney From ben+python at benfinney.id.au Wed Sep 13 22:10:32 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 14 Sep 2017 12:10:32 +1000 Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <87h8w79jx2.fsf@nightsong.com> Message-ID: <85k2126ndz.fsf@benfinney.id.au> Paul Rubin writes: > Are there actually Py3 codebases? I guess there must be, even though > I've never seen one. You also know it to be the case, unless you think *every* person is a liar who has told you in the past that they are working on a Python 3 code base. > Every Python codebase of any size that I know of is Py2. So yes, of > course they're working on a Py2 codebase. The obvious lesson there is: Don't take the limits of your own immediate experience as limiting the totality of all experience. > That's the only kind there is, as far as I know. That simply isn't true, unless you think it more likely everyone who discusses their Python 3 code base is lying. -- \ ?I think it would be a good idea.? ?Mohandas K. Gandhi (when | `\ asked what he thought of Western civilization) | _o__) | Ben Finney From steve+python at pearwood.info Wed Sep 13 22:20:03 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 14 Sep 2017 12:20:03 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> Message-ID: <59b9e755$0$16732$b1db1813$d948b532@news.astraweb.com> Hi Roger, My responses below yours, interleaved with your comments. On Thu, 14 Sep 2017 02:18 am, ROGER GRAYDON CHRISTMAN wrote: > I have not yet mastered how to respond to a particular note in a threadwith > the mailer that I use, Without knowing your mailer "Penn State WebMail", I would expect that the right process would be to click on the post and select "Reply To List" (if available) or "Reply All" (as a fall back). But seeing that your university appears to have invented their own mailer, instead of allowing people to use their own, standard, mailer like Outlook or Thunderbird, I wouldn't be surprised if it were "Aubergine Foxtrot" or "Xuswbdpemaq". > so this is not in response to anyone in particular,but > just to some of the sentiments as a whole. >> if x:> # do something While we all make the odd typo or two, it is difficult to understand your intention when you write something which is meant to be source code but it contains typos. If you meant what you *literally* wrote, you would get a syntax error. If you meant if x > : then again you would get a syntax error. If you meant if x > 1: (say) then the intent is clear: x is a number being tested to see if it is greater than 1. But if you meant simply: if x: then the answer is, you are testing for truthiness. The specific definition of "truthiness" depends on the type of x, but the general convention in Python is to distinguish between "something" and "nothing": Values that in some sense are "nothing" are false: - zero - the empty string - None - empty containers (lists, dicts, sets, etc.) - and of course False itself Values that in some sense are "something" are true: - nonzero numbers - nonempty strings - nonempty containers - any other object (by default) - and of course True itself. True and False are merely the canonical boolean values, they otherwise have no special status as boolean true/false flags. > Completely out of context, I would dislike it just because it is far too > vague.Is it testing for zero? for an empty list? or for some object's > completelyarbitrary definition of truthiness? "x" is, of course, a poor name for a variable, and I trust that you wouldn't actually write "if x" in a real program. (Apart from purely mathematical functions, where x is intended as a real-valued number, but then you would be unlikely to write "if x" in such a function.) And of course it is rare that we read a single if clause out of context. Normally we would have a good idea of what x actually was: x = list(values) # terrible choice of names... if x: # but at least we can see what x is first = x[0] last = x[-1] > x.._bool__() seems to me to be just as efficient, but we don't like calling > dunders.bool(x) should mean the same thing, perhaps with an extra function > invocationto look for the dunder. No. bool() does more than just look up a dunder method and call it. In general the reason we don't call dunder methods directly is not just for the aesthetics of it but because dunder methods are implementation, not interface. The interface can be far more involved than the implementation in the dunder method. bool is an especially simple example: # pseudocode for bool(obj) if hasattr(type(obj), '__bool__'): flag = type(obj).__boo__(obj) if flag is neither True nor False: raise TypeError elif hasattr(type(obj), '__len__'): flag = (type(obj).__len__(obj) != 0) else: flag = True return flag The interface for other dunder methods like __add__ and __mul__ are significantly more complex! So in general we should not call obj.__bool__, not just because it is ugly or because it is not idiomatic, but because it is *wrong*. (There are occasional exceptions. As always, if you know what you are doing, you know when to break the rules.) > But even so, nothing here sheds light on what that Boolean outcome means. *shrug* This same objection applies to any use of operator overloading or duck-typing. You are either comfortable with some "theoretical" uncertainly, or you are not. Without context, we cannot know what: (width + length)*2 will return, since either or both variable might have overloaded the + operator to do something weird. The solution is: don't do that. Truth testing in Python follows the same principles as nearly everything else: - duck-typing is preferred over type testing (within limits) - delegate the implementation to the object in question So rather than insist on an exact True or False object, Python accepts any object, and interrogates it: "are you truthy or falsey?" > I would agree that testing any of those for '== True' or the like is > pointlessredundancy, which may or may not be slower, depending on optimization > issues. > ------ > but in context is another thing entirely. > was x assigned to recently? is the type of x obvious so its truthiness is > also obvious?Then fine -- if it is clear that x is a list, I'm happy to use > this to test for an empty list.But if x is some other creation, like a user > defined type, I would really prefer to seesomething analogous to: > if not x.is_empty() or x.exists() or x.has_brain() > And most definitely if x is assigned outside my control, I would definitely > wantsome way to test or verify x's type before I start using it, lest my > randomnumber generator with its > (A + B * C) % D > finds itself concatenating strings and formatting data. You don't have to protect yourself from the caller's stupidity. You should think of Python functions having something like "Design By Contract" semantics: if you pass something that the function is not equipped to handle, then the (informal) contract is broken and the function can do anything it likes. Of course we would prefer that the function would (in order of highest to lowest preference): - raise a clear TypeError or ValueError stating the failure; - raise some implementation-dependent exception inside the body of the function; - return some obviously invalid result; rather than return something which *looks* valid but is wrong, but don't feel that it is *necessarily* your responsibility to guard against the caller's stupidity. "We're all adults here" and if the caller chooses to shoot themselves in the foot by passing a bad argument, they'll get what's coming to them. (Defensive programming is not only the receiving function's responsibility. The caller should program defensively to ensure they don't pass the wrong arguments too.) In fact, there's a fine line between guarding against bad input, and guarding against input which in fact is perfectly fine, but merely is something you didn't think of. (By the way, I really, really hope you aren't actually using such a poor quality pseudo-random generator when the Python standard library includes a world-class implementation.) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From grant.b.edwards at gmail.com Wed Sep 13 22:20:52 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 14 Sep 2017 02:20:52 +0000 (UTC) Subject: "tkinter" References: <85vakm6wtl.fsf@benfinney.id.au> Message-ID: On 2017-09-13, Ben Finney wrote: > The toolkit in question is named ?tk?, which I have only ever known to > be pronounced ?tee kay?. > > The rest of the word is an abbreviation of ?interface?. > > So, to me ?Tkinter? is pronounced ?tee kay inter?. Same here. Though I've probably said it aloud less than a half-dozen times in the past twenty-whatever years. -- Grant From orgnut at yahoo.com Wed Sep 13 22:25:56 2017 From: orgnut at yahoo.com (Larry Hudson) Date: Wed, 13 Sep 2017 19:25:56 -0700 Subject: "tkinter" In-Reply-To: References: Message-ID: On 09/13/2017 05:33 AM, leam hall wrote: > On Wed, Sep 13, 2017 at 8:28 AM, Stefan Ram wrote: > >> I presume that "tkinter" is intended to be pronounced >> "logically": >> >> T K inter (tee kay inter /ti keI In t%/) >> >> . But it would be faster to pronounce it >> >> T kinter (tee kinter /ti kIn t%/) >> >> . So far I've only ever read it, never heard it. >> But while I am aware that the logical pronunciation should >> be the correct one, I actually like the faster one. >> >> > I heard a speaker mention GvR by name and it took me a bit, and IRC, to > find out the Dutch pronunciation is different from the American. I've seen > his name lots, hadn't heard it. > > Leam > Somewhat OT, but... There is a will-known(?) audio clip of Linus Torvalds pronouncing his name. One source is: http://www.paul.sladen.org/pronunciation/ Click on the MP3 Format or OGG Format links to hear it directly, or the WAV or AU formats to download the audio clips. -- -=- Larry -=- From ben+python at benfinney.id.au Wed Sep 13 22:32:45 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 14 Sep 2017 12:32:45 +1000 Subject: the core values of the Python "platform" References: <27b25bd6-da51-7106-3a84-37bdb7c56260@tjol.eu> <85r2va6nor.fsf@benfinney.id.au> Message-ID: <85fubq6mcy.fsf@benfinney.id.au> ram at zedat.fu-berlin.de (Stefan Ram) writes: > I have read ?import this? again, after reading the above, > but there was no indication whatsoever in it that says that > it was talking about "*hierarchies* in a code base" only. Then you have no basis for claiming that the Zen of Python means what you say it means :-) -- \ ?I spent a lot of money on wine and women, and like a fool I | `\ squandered the rest.? ?Benny Hill | _o__) | Ben Finney From formisc at gmail.com Wed Sep 13 22:52:17 2017 From: formisc at gmail.com (Andrew Zyman) Date: Wed, 13 Sep 2017 22:52:17 -0400 Subject: A good way to unpack a matrix Message-ID: hello, is there a better approach to populating a function in this situation? res = self.DB.getPrice(): # returns array of 3x2 always. symbol_id, symbol, price. var1 = self.AFunction(symbols=res[0][2] + '.' + res[1][2], conid1= self.Contracts[res[0][0]].conId, conid2=self.Contracts[res[1][0]].conId, price1= res[0][2], price2= res[1][2]) Thank you. From sean.dizazzo at gmail.com Wed Sep 13 23:28:53 2017 From: sean.dizazzo at gmail.com (Sean DiZazzo) Date: Wed, 13 Sep 2017 20:28:53 -0700 (PDT) Subject: A good way to unpack a matrix In-Reply-To: References: Message-ID: <91048091-d888-4788-907b-fd73dad646d1@googlegroups.com> On Wednesday, September 13, 2017 at 7:53:25 PM UTC-7, Andrew Zyman wrote: > hello, > is there a better approach to populating a function in this situation? > > res = self.DB.getPrice(): # returns array of 3x2 always. symbol_id, > symbol, price. > > var1 = self.AFunction(symbols=res[0][2] + '.' + res[1][2], conid1= > self.Contracts[res[0][0]].conId, > > conid2=self.Contracts[res[1][0]].conId, price1= res[0][2], price2= > res[1][2]) > > > Thank you. OOP? From sean.dizazzo at gmail.com Wed Sep 13 23:36:39 2017 From: sean.dizazzo at gmail.com (Sean DiZazzo) Date: Wed, 13 Sep 2017 20:36:39 -0700 (PDT) Subject: the core values of the Python "platform" In-Reply-To: References: Message-ID: On Wednesday, September 13, 2017 at 6:16:58 AM UTC-7, leam hall wrote: > On Wed, Sep 13, 2017 at 9:08 AM, Darin Gordon wrote: > > > Bryan Cantrill gave an interesting talk recently at a Node conference about > > "platform values" [1]. The talk lead me to think about what the core values > > of the Python "platform" are and I thought it would be good to ask this > > question of the community. What would you consider the top (<= 5) core > > values? > > > > > Would that be close to the Zen of Python? The Zen of Python says it all. There might be some that argue with intricacies, but the core values are expressed clearly in it. Some people just like to argue. From sean.dizazzo at gmail.com Wed Sep 13 23:39:30 2017 From: sean.dizazzo at gmail.com (Sean DiZazzo) Date: Wed, 13 Sep 2017 20:39:30 -0700 (PDT) Subject: "tkinter" In-Reply-To: References: <85vakm6wtl.fsf@benfinney.id.au> Message-ID: <60d7c9bd-207f-49c1-881a-96bf8e48101f@googlegroups.com> On Wednesday, September 13, 2017 at 7:21:25 PM UTC-7, Grant Edwards wrote: > On 2017-09-13, Ben Finney wrote: > > > The toolkit in question is named ?tk?, which I have only ever known to > > be pronounced ?tee kay?. > > > > The rest of the word is an abbreviation of ?interface?. > > > > So, to me ?Tkinter? is pronounced ?tee kay inter?. > > Same here. Though I've probably said it aloud less than a half-dozen > times in the past twenty-whatever years. > > -- > Grant I usually just say "tinker", since it's easy...knowing that it's wrong. I agree with the "tee-kay" folks on correct pronunciation. From torriem at gmail.com Wed Sep 13 23:46:19 2017 From: torriem at gmail.com (Michael Torrie) Date: Wed, 13 Sep 2017 21:46:19 -0600 Subject: Fw: Problems Installing Python36 In-Reply-To: <6278c207-2744-5603-b983-6d73c451714f@tjol.eu> References: <20170912.034647.1218.0@webmail04.vgs.untd.com> <6278c207-2744-5603-b983-6d73c451714f@tjol.eu> Message-ID: <2e23c425-0ddf-8cc7-25ac-20f4568941c9@gmail.com> On 09/12/2017 03:05 AM, Thomas Jollans wrote: > Other people on this list: > This isn't the first time I've someone with this issue here. It's > probably putting off plenty of potential new users who don't make as > much effort to find a solution. I can't say I understand the ins and > outs of installing things on Windows... is there anything that can be done? Last time I brought this up, someone mentioned that the Python installer is supposed to automatically install this runtime library if it's not installed already. If so, why are so many people having this problem? From torriem at gmail.com Wed Sep 13 23:52:56 2017 From: torriem at gmail.com (Michael Torrie) Date: Wed, 13 Sep 2017 21:52:56 -0600 Subject: People choosing Python 3 In-Reply-To: <3026bbec-495b-5451-19f6-d3255ba39307@gmail.com> References: <8760crm2mp.fsf@elektro.pacujo.net> <3026bbec-495b-5451-19f6-d3255ba39307@gmail.com> Message-ID: On 09/10/2017 03:25 AM, Leam Hall wrote: > From a non-rpm perspective Python 3.6.2 compiles nicely on CentOS 6. > Once compiled it seems easy to use pip3 to install stuff without > trampling on the OS's Python 2 install. In the last place I worked, our servers usually did not have compilers installed (per policy), and installing from a non-RPM source was strongly discouraged. The reason for this is security and configuration management. We allowed certain repositories, such as EPEL. And for custom software we'd build our own RPMs for distribution to the servers. Looking forward, snap or flatpak may well come into play in the next version of RHEL. Also deploying apps in docker images also is becoming standard in the enterprise. All of these things make it much easier to run a newer version of Python to support an application or server process, in a manage-able way. From torriem at gmail.com Thu Sep 14 00:00:54 2017 From: torriem at gmail.com (Michael Torrie) Date: Wed, 13 Sep 2017 22:00:54 -0600 Subject: People choosing Python 3 In-Reply-To: References: <8760crm2mp.fsf@elektro.pacujo.net> <871snevqwi.fsf@elektro.pacujo.net> <87h8wau4vc.fsf@elektro.pacujo.net> Message-ID: <15da3cff-1560-c337-ef57-f45b83070352@gmail.com> On 09/11/2017 01:47 AM, Stephan Houben wrote: > Op 2017-09-10, Marko Rauhamaa schreef : >> Stephan Houben : >>> >>> Why not bundle the Python interpreter with your application? >>> It seems to work for Windows developers... >> >> I've seen that done for Python and other technologies. It is an >> expensive route to take. Also, it can be insecure. When vulnerabilities >> are found, they are communicated to the maintainers of, say, Python. >> When Python is fixed and released, the vulnerability is revealed, but >> the version bundled with your product is still broken. You have to be >> prepared perform an emergency release of your product and hope you don't >> mess things up. > > To each his own, but this is not different from any other > third-party package your application depends on. Actually, no it's completely different. Except for compiled modules, third-party packages (vetted and approved of course) can be bundled in your app's python file tree as simple python files, all trackable via a single git repository or some other change management tool. Not so for binary installations that include various libraries, config files, and binaries. The biggest issue is configuration management. As I mentioned in my other post, we used to have a policy for our servers that installation from source was strongly discouraged, and in some cases simply not allowed. This wasn't just for security; it was for managing configuration of the servers. When everything is packaged up nicely, it's trivial to deploy to new machines. Even our own software would often be wrapped up in RPMs. That said, requiring a dependency on EPEL is, in my opinion completely valid for your enterprise customers. In all likelihood EPEL is already in use anyway. Docker is another possibility as more and more enterprises are using it to deploy software to machines dynamically. Of course this has the same problem Marko mentioned earlier. If the docker container maintainer isn't constantly keeping it up to date, security flaws in the docker image will be a problem. From torriem at gmail.com Thu Sep 14 00:08:07 2017 From: torriem at gmail.com (Michael Torrie) Date: Wed, 13 Sep 2017 22:08:07 -0600 Subject: People choosing Python 3 In-Reply-To: References: <69695eae-e264-dbf5-292a-31403b65b52e@tjol.eu> Message-ID: <671a6aee-ae0e-ae34-4a66-eb6400e34677@gmail.com> On 09/11/2017 06:00 AM, Pavol Lisy wrote: >> Debian follows PEP 394, which recommends that "python" point to python2, >> and I don't see that changing any time soon (certainly not before RHEL >> includes python3 by default. > > Which part of third party ecosystem surrounding Python 3 is not (and > could not be any time soon) sufficiently mature? I don't believe it's a matter of maturity. Python 3 is mature now. It's a matter of when python 2 disappears entirely as it's about versioning and backwards compatibility. Although, I'm not sure I ever want to see /usr/bin/python point to python3, or python4, or python5. Maybe better to deprecate /usr/bin/python altogether and transition to explicit python2, python3, python4, python5. Another possibility would be to make /usr/bin/python be a dispatcher, and require the #! invocation to tell it which version of python the script requires. Alternatively a special comment could, similar to how source file encoding is specified, tell the interpreter which version of the python language the script uses. Certainly I don't want to go through the whole question of, "which version is /usr/bin/python?" every time we get a new major version number. From arj.python at gmail.com Thu Sep 14 00:16:50 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 14 Sep 2017 08:16:50 +0400 Subject: "tkinter" In-Reply-To: References: Message-ID: yes ! me i like i was always pronouncing tinker though until a nice book pointed it out ! Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 13 Sep 2017 16:30, "Stefan Ram" wrote: I presume that "tkinter" is intended to be pronounced "logically": T K inter (tee kay inter /ti keI In t%/) . But it would be faster to pronounce it T kinter (tee kinter /ti kIn t%/) . So far I've only ever read it, never heard it. But while I am aware that the logical pronunciation should be the correct one, I actually like the faster one. -- https://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Thu Sep 14 00:37:50 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Sep 2017 00:37:50 -0400 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <87h8w79jx2.fsf@nightsong.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <87h8w79jx2.fsf@nightsong.com> Message-ID: On 9/13/2017 2:44 AM, Paul Rubin wrote: > Are there actually Py3 codebases? Let's think a bit. There is the Python half of the Python3 codebase, perhaps 400K. But we can discount that. Then there are all the Py compatible modules on PyPI, which is to say, most of the major one. How could not not notice those? One of them is a little project call Django. I believe that this is the one slated to be 3.x only in its 2.0 version. I believe at least one linux distribution uses Py 3 for its system python. A year ago, a producers of a Unicode-based app sold internationallly announce that their next version would be Py 3 only. When 3.3 came out with the new Unicode implementation, they developed a 3.3 version of the app. By 3.5, they realized that 3.3+ unicode made things much easier, wile maintaining the 2.7 version was painful by comparison. They asked their (non-programmer) customers if they already used the 3.x version or could install 3.x to run the 3.x version. 95% said yes to one of these. So they decided that the next version, early this year, would be 3.x only. Have you ever hear of a little startup called 'Instagram'? Earlier this year, they announce that they had about finished an 18 month process of switching most of their Python code to 3.x. They described in fair detail how they did it. Really impressive. -- Terry Jan Reedy From tjreedy at udel.edu Thu Sep 14 00:42:55 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Sep 2017 00:42:55 -0400 Subject: "tkinter" In-Reply-To: References: <22db49d6-30a0-3593-daa4-b5863cdd6673@tjol.eu> <9otirc9s1g8hkvmcffn58pdtu4oo2dbefh@4ax.com> Message-ID: On 9/13/2017 3:09 PM, Grant Edwards wrote: > I tried to write a small (but non-trivial) Tcl app once[1], and would > happily vote to bury Tcl and then might even dance on its grave. > Tkinter, OTOH, is great for small, simple GUI apps -- with a few > caveats: > > 1. You have to grit your teeth because you know there's a Tcl > interpreter buried in the details. > > 2. When you package up a trivial Tkinter application using something > like py2exe, it balloons up to a ginormous size (way larger than > the equivalent app written using wxPython). I assume this is > caused largely by 1. > > 3. No matter how hard you try, Tkinter apps always look a bit > foreign. I've just given up trying to them to look like native > apps: it doesn't work, and it annoys the mule. Relative to past Windows, Win 10 looks a bit foreign. On Windows, tk pretty much uses native widgets. The ttk versions are a bit better on Windows, definitely better on linux, and apparently even more better on Mac. Did you use them? > [1] After wasting several days fighting with TCL's quoting sematics, I > gave up and wrote the app in Scheme (and was done in a couple > hours). -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Thu Sep 14 01:02:27 2017 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 14 Sep 2017 06:02:27 +0100 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <87h8w79jx2.fsf@nightsong.com> Message-ID: On 14/09/2017 05:37, Terry Reedy wrote: > On 9/13/2017 2:44 AM, Paul Rubin wrote: > >> Are there actually Py3 codebases? > > Let's think a bit.? There is the Python half of the Python3 codebase, > perhaps 400K.? But we can discount that. > > Then there are all the Py compatible modules on PyPI, which is to say, > most of the major one.? How could not not notice those? > > One of them is a little project call Django.? I believe that this is the > one slated to be 3.x only in its 2.0 version. > > I believe at least one linux distribution uses Py 3 for its system python. > > A year ago, a producers of a Unicode-based app sold internationallly > announce that their next version would be Py 3 only.? When 3.3 came out > with the new Unicode implementation, they developed a 3.3 version of the > app.? By 3.5, they realized that 3.3+ unicode made things much easier, > wile maintaining the 2.7 version was painful by comparison.? They asked > their (non-programmer) customers if they already used the 3.x version or > could install 3.x to run the 3.x version.? 95% said yes to one of these. > ?So they decided that the next version, early this year, would be 3.x > only. > > Have you ever hear of a little startup called 'Instagram'?? Earlier this > year, they announce that they had about finished an 18 month process of > switching most of their Python code to 3.x.? They described in fair > detail how they did it.? Really impressive. > Not quite there yet but according to this https://www.reddit.com/r/Python/comments/6z6wst/twisted_is_93_ported_to_python_3/ a little project called Twisted is 93% ported to Python 3. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email has been checked for viruses by AVG. http://www.avg.com From tjreedy at udel.edu Thu Sep 14 01:10:03 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 14 Sep 2017 01:10:03 -0400 Subject: "tkinter" In-Reply-To: <85vakm6wtl.fsf@benfinney.id.au> References: <85vakm6wtl.fsf@benfinney.id.au> Message-ID: On 9/13/2017 6:46 PM, Ben Finney wrote: > ram at zedat.fu-berlin.de (Stefan Ram) writes: > >> I presume that "tkinter" is intended to be pronounced >> "logically": >> >> T K inter (tee kay inter /ti keI In t%/) > > This is how I've always pronounced it. > > The toolkit in question is named ?tk?, which I have only ever known to > be pronounced ?tee kay?. > > The rest of the word is an abbreviation of ?interface?. > > So, to me ?Tkinter? is pronounced ?tee kay inter?. > >> . But it would be faster to pronounce it > > Speed at the expense of clarity is a goal difficult to justify in > programming, and is even harder to justify in human speech. So, that > basis doesn't convince me of a useful pronunciation. I program in tkinter more or less daily and now, at least,I think it 'tee-kinter'. I believe I have said it that way also, though to a somewhat naive listener. Now I know that some would think it strange ;-). I said the same thing back in 2002 on this list: https://mail.python.org/pipermail/python-list/2002-December/139508.html Mike C. Fletcher: mostly t k inter, sometimes t kinter, accent on t. Dennis Lee Bieber: t kinter, slurred at tick inter. then thread veered off onto Poles and consonants. What do haphazerdly selected public Python speakers say? t k inter Russell Keith-Magee, https://www.youtube.com/watch?v=yI7NYgP54sw t k inter Jeff Armstrong https://www.youtube.com/watch?v=6isuF_bBiXs t kinter Zach King https://www.youtube.com/watch?v=N6aEc6Qu2vM t'kinter 'sentdex', https://www.youtube.com/watch?v=Ccct5D2AyNM t k inter Bryson Tyrrell, https://www.youtube.com/watch?v=Wb1YFgHqUZ8 t k inter Derek Banas https://www.youtube.com/watch?v=-tbWoZSi3LU I am perhaps in a minorit -- Terry Jan Reedy From no.email at nospam.invalid Thu Sep 14 01:12:12 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 13 Sep 2017 22:12:12 -0700 Subject: The Incredible Growth of Python (stackoverflow.blog) References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <87h8w79jx2.fsf@nightsong.com> <85k2126ndz.fsf@benfinney.id.au> Message-ID: <87vaklhnir.fsf@nightsong.com> Ben Finney writes: >> I've never seen one. > who has told you... they are working on a Python 3 code base. Just because they've told me about it doesn't mean I saw it personally. The ones I've seen, including new ones, are Python 2. Some people here use Py3 but I haven't heard (or don't remember) enough about what they're working on, to know if those are py3 codebases of any size. If they say yes, I'll take their word for it, but this is a self-selected group of course. > That simply isn't true, unless you think it more likely everyone who > discusses their Python 3 code base is lying. People discuss Python language issues here a lot, but don't discuss as much about code bases. I know when I install a new OS (currently Debian 9 which was released a month or so ago) and type "python" on the command line, I get Py2. From greg.ewing at canterbury.ac.nz Thu Sep 14 01:54:37 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 14 Sep 2017 17:54:37 +1200 Subject: "tkinter" In-Reply-To: <60d7c9bd-207f-49c1-881a-96bf8e48101f@googlegroups.com> References: <85vakm6wtl.fsf@benfinney.id.au> <60d7c9bd-207f-49c1-881a-96bf8e48101f@googlegroups.com> Message-ID: Sean DiZazzo wrote: > I usually just say "tinker", since it's easy... +1. All we need now are modules called talior, sodlier and psye. Should I write a PEP? -- Greg From steve+comp.lang.python at pearwood.info Thu Sep 14 02:14:52 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2017 06:14:52 GMT Subject: "tkinter" References: <85vakm6wtl.fsf@benfinney.id.au> <60d7c9bd-207f-49c1-881a-96bf8e48101f@googlegroups.com> Message-ID: <59ba1e5c$0$16632$b1db1813$d948b532@news.astraweb.com> On Thu, 14 Sep 2017 17:54:37 +1200, Gregory Ewing wrote: > Sean DiZazzo wrote: >> I usually just say "tinker", since it's easy... > > +1. All we need now are modules called talior, sodlier and psye. > Should I write a PEP? Oooh yes please :-) -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From steve+comp.lang.python at pearwood.info Thu Sep 14 02:25:27 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2017 06:25:27 GMT Subject: "tkinter" References: Message-ID: <59ba20d6$0$16632$b1db1813$d948b532@news.astraweb.com> On Wed, 13 Sep 2017 12:28:01 +0000, Stefan Ram wrote: > I presume that "tkinter" is intended to be pronounced > "logically": > > T K inter (tee kay inter /ti keI In t%/) > > . But it would be faster to pronounce it > > T kinter (tee kinter /ti kIn t%/) > > . So far I've only ever read it, never heard it. > But while I am aware that the logical pronunciation should be the > correct one, I actually like the faster one. I won't comment on "logically" except to say that little in English is logical. https://en.wikipedia.org/wiki/Ghoti But I agree with "t'kinter" as pronunciation. "tk" is not, so far as I am aware, a valid sound in English, so we have three reasonable choices: (1) Separate T K and INTER syllables. But the problem with that is that there's very little (but not none whatsoever) precedence for sounding out letters individually in English words. Hence that should really be spelled: Teekayinter which looks hideous. (2) Pretend there's an apostrophe or hyphen between the T and the KINTER: t'kinter t-kinter That both reads and sounds like the most English-like solution. But maybe I'm biased due to my name.[1] (3) Pretend that the K is silent, as in KNIGHT. t(k)inter I suppose that's not unreasonable, but personally I don't like it. [1] Ironically, I actually pronounce my name DA PRANO. So do my Italian relatives. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From john_ladasky at sbcglobal.net Thu Sep 14 02:27:03 2017 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Wed, 13 Sep 2017 23:27:03 -0700 (PDT) Subject: My Issues In-Reply-To: <7117b21c-5d89-4bc5-a806-7b333ad41654@googlegroups.com> References: <59065F64-409B-4497-8CC3-864B3571DC54@yahoo.com> <7117b21c-5d89-4bc5-a806-7b333ad41654@googlegroups.com> Message-ID: <4f6d157e-4d12-4411-9ce1-c18579c1c285@googlegroups.com> On Wednesday, September 13, 2017 at 2:37:48 PM UTC-7, iv... at linebox.ca wrote: > Hi Carson, > > If you are having big troubles installing Python on Windows (it really should be a click install from the Python download page here https://www.python.org/downloads/) you can use Anaconda to install, which usually makes installing python on problematic windows machines much easier. > > Follow this tutorial > https://medium.com/@GalarnykMichael/install-python-on-windows-anaconda-c63c7c3d1444 > > Use this download page: > > https://www.anaconda.com/download/ > > Don't get discouraged. Sometimes getting up and running is a bit of a pain, but it will be smooth sailing after you get it in there the first time. > > Ivan One of my students reached for Anaconda to install Python on a Windows machine, and ended up with Py 2.7. If you want Py3, make sure that you pay attention to which version of Anaconda you install. From steve+comp.lang.python at pearwood.info Thu Sep 14 02:28:12 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2017 06:28:12 GMT Subject: [Tutor] beginning to code References: <9c1d431e-3276-79d1-436f-343ded9511f1@gmx.at> <59b8bb0f$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: <59ba217c$0$16632$b1db1813$d948b532@news.astraweb.com> On Wed, 13 Sep 2017 11:05:37 +0000, Stefan Ram wrote: > Steven D'Aprano writes: >>The *only* reasonable place to stop is right at the beginning: if >>bool(x): >>at least for languages like Pascal and Java where `if` requires a >>specific boolean type. > > In Java, not only does the if-statement require a boolean expression, > but one also cannot convert other types into boolean! Thanks for the clarification. I didn't mean to imply that literally "bool(x)" would be valid Java, or Pascal. If I remember correctly, in Pascal the name of the type is "boolean". -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From BILL_NOSPAM at whoknows.net Thu Sep 14 02:42:16 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Thu, 14 Sep 2017 02:42:16 -0400 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <87vaklhnir.fsf@nightsong.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <87h8w79jx2.fsf@nightsong.com> <85k2126ndz.fsf@benfinney.id.au> <87vaklhnir.fsf@nightsong.com> Message-ID: Paul Rubin wrote: > Ben Finney writes: >>> I've never seen one. >> who has told you... they are working on a Python 3 code base. > Just because they've told me about it doesn't mean I saw it personally. > The ones I've seen, including new ones, are Python 2. > > Some people here use Py3 but I haven't heard (or don't remember) enough > about what they're working on, to know if those are py3 codebases of any > size. If they say yes, I'll take their word for it, but this is a > self-selected group of course. > >> That simply isn't true, unless you think it more likely everyone who >> discusses their Python 3 code base is lying. > People discuss Python language issues here a lot, but don't discuss as > much about code bases. > > I know when I install a new OS (currently Debian 9 which was released > a month or so ago) and type "python" on the command line, I get Py2. Try typing python3. It's in some distributions of Linux. From BILL_NOSPAM at whoknows.net Thu Sep 14 02:51:20 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Thu, 14 Sep 2017 02:51:20 -0400 Subject: the core values of the Python "platform" In-Reply-To: <59ba25dc$0$16632$b1db1813$d948b532@news.astraweb.com> References: <59ba25dc$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Wed, 13 Sep 2017 09:08:41 -0400, Darin Gordon wrote: > >> Bryan Cantrill gave an interesting talk recently at a Node conference >> about "platform values" [1]. > For those of us who don't have the time or inclination to watch a video, > or who are unable to, could you summarise these platform values? > > >> The talk lead me to think about what the >> core values of the Python "platform" are and I thought it would be good >> to ask this question of the community. What would you consider the top >> (<= 5) core values? > > In no particular order: > > - The Zen of Python ("import this" at the interactive interpreter). > > - "We're all adults here." We tend to be more relaxed about theoretical > errors, and push some of the responsibility for defensive programming > onto the caller, not just the callee. If the caller breaks my function's > contract by providing bad arguments, or messes with my class' internals, > they deserve whatever bad things happen. > > - "We're all adults here." The flip side of that is that if I choose to > mess with your private methods or functions, you shouldn't take > extraordinary steps to try to prevent me. I'm an adult, and if I've got > good reason to call your private method (say, I'm debugging, or I'm > simply exploring the capabilities at the interactive interpreter) then I > should be allowed. If I want to shoot myself in the foot, it isn't your > responsibility to prevent me. > > - All else being equal, it is better to ask forgiveness than permission. > In general, we prefer try...except and catching exceptions than to look > before you leap. It is often faster, but more importantly, it avoids > "Time Of Check To Time Of Use" bugs. > > - Python is in one sense a pure Object Oriented language (all values, > even integers, are objects) Even classes are objects. > but in another sense Python is a multiparadigm > language. Not everything needs to be a class. Top-level functions are > often better. We can, and do, write code using four of the big five > programming paradigms: procedural, OOP, functional, imperative. And mix > and match them within a single code base. > > (Only deductive/logic programming has little support in Python.) > > > And if I may be allowed a sixth: > > - Not every two line function needs to be a built-in. > > > From songofacandy at gmail.com Thu Sep 14 02:53:04 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Thu, 14 Sep 2017 15:53:04 +0900 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <87vaklhnir.fsf@nightsong.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <87h8w79jx2.fsf@nightsong.com> <85k2126ndz.fsf@benfinney.id.au> <87vaklhnir.fsf@nightsong.com> Message-ID: > I know when I install a new OS (currently Debian 9 which was released > a month or so ago) and type "python" on the command line, I get Py2. It's to keep compatibility for Python 2 only scripts. It doesn't mean Python 2 is default Python. Debian and Ubuntu working hard to move Python 3 as default. Most packages depends on Python 3, not 2. When installing Ubuntu, there are no "python" command. Python 3 is installed as default, but Python 2 not. Regards, INADA Naoki From ben+python at benfinney.id.au Thu Sep 14 03:01:30 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 14 Sep 2017 17:01:30 +1000 Subject: "tkinter" References: <59ba20d6$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: <85bmmd7ohh.fsf@benfinney.id.au> Steven D'Aprano writes: > (1) Separate T K and INTER syllables. > > But the problem with that is that there's very little (but not none > whatsoever) precedence for sounding out letters individually in > English words. It's not an English word. Yet we are still called upon to pronounce it. > Hence that should really be spelled: > > Teekayinter > > which looks hideous. There is plenty of precedent for pronouncing other initialisms. When they don't make a nice word (i.e. when they are not an acronym), we tend to spell them out for clear communication. That's IMO support for ?tee kay inter? pronunciation of ?Tkinter?. -- \ ?Remember: every member of your ?target audience? also owns a | `\ broadcasting station. These ?targets? can shoot back.? ?Michael | _o__) Rathbun to advertisers, news.admin.net-abuse.email | Ben Finney From dieter at handshake.de Thu Sep 14 03:02:27 2017 From: dieter at handshake.de (dieter) Date: Thu, 14 Sep 2017 09:02:27 +0200 Subject: Creating a python client for an external service advice References: Message-ID: <871sn9pxto.fsf@handshake.de> ivan77 writes: > I would like to create a Python module/client library for a data visualization service that I use (and will be using more) as my first larger contribution to open source Python. What kind of service is this "data visualization service"? Is it a library, destined to be linked to an application? Is it a web service, accessed via an internet protocol? Which one? > I have not come across any best practices for this, and am wondering whether there are some resources that you may know of. This highly depends on the kind of service and how its API is described. If it is a library, you make be able to use one of the many tools that create a binding from C/C++ header files. If it is a WSDL described web service, you can use a SOAP/WSDL client library (e.g. "suds") to directly access the service. etc... From steve+comp.lang.python at pearwood.info Thu Sep 14 03:42:43 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 14 Sep 2017 07:42:43 GMT Subject: "tkinter" References: <59ba20d6$0$16632$b1db1813$d948b532@news.astraweb.com> <85bmmd7ohh.fsf@benfinney.id.au> Message-ID: <59ba32f3$0$16632$b1db1813$d948b532@news.astraweb.com> On Thu, 14 Sep 2017 17:01:30 +1000, Ben Finney wrote: > Steven D'Aprano writes: > >> (1) Separate T K and INTER syllables. >> >> But the problem with that is that there's very little (but not none >> whatsoever) precedence for sounding out letters individually in English >> words. > > It's not an English word. Yet we are still called upon to pronounce it. This is the first time I've heard an English language jargon word described as "not English". If it is not English, what is it? You wouldn't typeset it in italics as a foreign word, would you? The "tk" part comes from a pair of initialisms: Tcl ("Tool Command Language") Tk ("Tool Kit") and the "inter" is an abbreviation for "interface". That makes it as English as any other jargon used by English speakers. >> Hence that should really be spelled: >> >> Teekayinter >> >> which looks hideous. > > There is plenty of precedent for pronouncing other initialisms. When > they don't make a nice word (i.e. when they are not an acronym), we tend > to spell them out for clear communication. By definition, if an acronym doesn't make a nice word, its an initialism. (In other words, all initialisms are acronyms, but not all acronyms are initialisms.) http://www.quickanddirtytips.com/education/grammar/abbreviations-acronyms- and-initialisms On the other hand... there are initialisms which are never, or hardly ever, spelled out letter by letter either. I don't know anyone who spells out "N S W" for NSW (New South Wales), or "Q L D" for Queensland, for example. They always expand the acronym and pronounce the full words. > That's IMO support for ?tee kay inter? pronunciation of ?Tkinter?. I don't mind you saying "tee kay inter" so long as you don't mind me saying "N A Sa". *wink* -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From rhodri at kynesim.co.uk Thu Sep 14 06:49:43 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 14 Sep 2017 11:49:43 +0100 Subject: the core values of the Python "platform" In-Reply-To: References: <27b25bd6-da51-7106-3a84-37bdb7c56260@tjol.eu> <85r2va6nor.fsf@benfinney.id.au> Message-ID: On 14/09/17 03:22, Stefan Ram wrote: > Ben Finney writes (special characters edited): >> As I understand it, "flat is better than nested" is talking about >> *hierarchies* in a code base. It's not IIUC referring to anything about >> the difference between expressions like you wrote. > > I have read ?import this? again, after reading the above, > but there was no indication whatsoever in it that says that > it was talking about "*hierarchies* in a code base" only. In any short, pithy commentary like the Zen, a great deal of what is said is implicit. Given your very literalist interpretations, I would suggest that trying to make deductions based on the Zen is a waste of time. -- Rhodri James *-* Kynesim Ltd From christopher_reimer at icloud.com Thu Sep 14 09:27:15 2017 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Thu, 14 Sep 2017 06:27:15 -0700 Subject: The Incredible Growth of Python (stackoverflow.blog) In-Reply-To: <87vaklhnir.fsf@nightsong.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <87h8w79jx2.fsf@nightsong.com> <85k2126ndz.fsf@benfinney.id.au> <87vaklhnir.fsf@nightsong.com> Message-ID: <2D90DDD4-5231-43B9-A8D2-4A7FFDCAA734@icloud.com> > On Sep 13, 2017, at 10:12 PM, Paul Rubin wrote: > > Ben Finney writes: >>> I've never seen one. >> who has told you... they are working on a Python 3 code base. > > Just because they've told me about it doesn't mean I saw it personally. > The ones I've seen, including new ones, are Python 2. > > Some people here use Py3 but I haven't heard (or don't remember) enough > about what they're working on, to know if those are py3 codebases of any > size. If they say yes, I'll take their word for it, but this is a > self-selected group of course. > >> That simply isn't true, unless you think it more likely everyone who >> discusses their Python 3 code base is lying. > > People discuss Python language issues here a lot, but don't discuss as > much about code bases. > > I know when I install a new OS (currently Debian 9 which was released > a month or so ago) and type "python" on the command line, I get Py2. > -- > https://mail.python.org/mailman/listinfo/python-list FreeNAS 11 (based on FreeBSD) has Python 3.6.1 installed and uses Django for the web interface. Chris R. From kryptxy at protonmail.com Thu Sep 14 13:22:33 2017 From: kryptxy at protonmail.com (Kryptxy) Date: Thu, 14 Sep 2017 13:22:33 -0400 Subject: Change project licence? Message-ID: Hi, I have an opensource (python) project under GPL3 licence. I wish switch to MIT licence so as to make it more permissive. I know how to change the licence, but I want to know is it fine and wise to change the licence at this point? (The project already has 19 clones, 250+ GitHub stars. Here: https://github.com/kryptxy/torrench) Thank you. From rosuav at gmail.com Thu Sep 14 13:56:59 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Sep 2017 03:56:59 +1000 Subject: Change project licence? In-Reply-To: References: Message-ID: On Fri, Sep 15, 2017 at 3:22 AM, Kryptxy via Python-list wrote: > Hi, > I have an opensource (python) project under GPL3 licence. I wish switch to MIT licence so as to make it more permissive. > I know how to change the licence, but I want to know is it fine and wise to change the licence at this point? > (The project already has 19 clones, 250+ GitHub stars. Here: https://github.com/kryptxy/torrench) > > Thank you. Only if every contributor says it's okay. Anything that you create (and own copyright on), you can license under any terms you like; if anyone else has contributed anything to the project, you have to get their permission to relicense it. For solo projects, that's simple. For huge things like the CPython interpreter, it's virtually impossible. ChrisA From torriem at gmail.com Thu Sep 14 16:04:14 2017 From: torriem at gmail.com (Michael Torrie) Date: Thu, 14 Sep 2017 14:04:14 -0600 Subject: Change project licence? In-Reply-To: References: Message-ID: <89c1d7a2-c72a-4e75-d406-ddfcda9531ec@gmail.com> On 09/14/2017 11:22 AM, Kryptxy via Python-list wrote: > Hi, > I have an opensource (python) project under GPL3 licence. I wish > switch to MIT licence so as to make it more permissive. I know how to > change the licence, but I want to know is it fine and wise to change > the licence at this point? (The project already has 19 clones, 250+ > GitHub stars. Here: https://github.com/kryptxy/torrench) If you are the sole copyright holder on the project, and haven't taken in any contributions from anyone else, then you can change the license however you like, regardless of clones/forks, with the caveat below. If you've integrated pull's from other people, then they now own a piece of the copyright and you would have to talk to each person and get permission to relicense their code contribution. Note that clone of your repo does not constitute a contribution. I'm talking about a pull request or patch that was contributed to your mainline repo. Finally, even if you are the sole copyright holder, while you can change the license on your code at any time to any terms, you cannot change the license on code that has already been forked under your original GPLv3 license. In other words, if someone clones your project before the license change, they can continue under original license, as per its terms. You can't retroactively change the license on code that's already been distributed, at least under the terms of the GPLv3. (I'm sure there's some license somewhere that expressly states the terms can be retroactively modified. But not the GPLv3.) From rosuav at gmail.com Thu Sep 14 16:28:42 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Sep 2017 06:28:42 +1000 Subject: Change project licence? In-Reply-To: <89c1d7a2-c72a-4e75-d406-ddfcda9531ec@gmail.com> References: <89c1d7a2-c72a-4e75-d406-ddfcda9531ec@gmail.com> Message-ID: On Fri, Sep 15, 2017 at 6:04 AM, Michael Torrie wrote: > Finally, even if you are the sole copyright holder, while you can change > the license on your code at any time to any terms, you cannot change the > license on code that has already been forked under your original GPLv3 > license. In other words, if someone clones your project before the > license change, they can continue under original license, as per its > terms. You can't retroactively change the license on code that's > already been distributed, at least under the terms of the GPLv3. (I'm > sure there's some license somewhere that expressly states the terms can > be retroactively modified. But not the GPLv3.) This is true; however the choice of license makes this moot. Code licensed MIT can be used in anything, so it can be GPL3'd to go into another project or anything. But yes, the old versions will still be available under the terms of the GPL3; you can make them *also* available under another license, but you aren't revoking the previous one. ChrisA From ben+python at benfinney.id.au Thu Sep 14 20:11:06 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 15 Sep 2017 10:11:06 +1000 Subject: "tkinter" References: <59ba20d6$0$16632$b1db1813$d948b532@news.astraweb.com> <85bmmd7ohh.fsf@benfinney.id.au> <59ba32f3$0$16632$b1db1813$d948b532@news.astraweb.com> Message-ID: <857ex07rdx.fsf@benfinney.id.au> Steven D'Aprano writes: > On Thu, 14 Sep 2017 17:01:30 +1000, Ben Finney wrote: > > > [?Tkinter? is] not an English word. Yet we are still called upon to > > pronounce it. > > This is the first time I've heard an English language jargon word > described as "not English". If it is not English, what is it? > [?] > That makes it as English as any other jargon used by English speakers. Yes, I agree. ?Tkinter? is as English-language as ?lxml?. That is, you can trace its roots to English-language words; but *as a word* it is not English language, it is an abbreviation jargon term that was created in writing, not speech. So its pronunciation follows very different rules from English-language words. Such as, you would be ill advised to try blurting it out as one or two syllables. It's not an English-language word. The sense in which I mean ?not an English-language word? here, is the same sense as ?English-language? in your ?very little precedent for spelling out the letters when pronouncing English-language words?. That is true for English-language words, but the precedent for those words doesn't necessarily apply when we're trying to pronounce an initialism jargon word born in writing and not speech. > On the other hand... there are initialisms which are never, or hardly > ever, spelled out letter by letter either. I don't know anyone who > spells out "N S W" for NSW (New South Wales), or "Q L D" for > Queensland, for example. They always expand the acronym and pronounce > the full words. Which is another way of saying, those people don't attempt to pronounce ?NSW? or ?Qld? as words. They pronounce something else instead, not even attempting to pronounce those initialisms. And I do the same. I don't usually try to pronounce the words ?NSW? or ?Qld?, unless I'm trying very hard to distinguish the words from which they're abbreviated versus the particular spelling I mean. In other words, when I'm trying to convey a particular term that is not typically intended for speech. So that would only be relevant to the discussion about ?Tkinter? pronunciation, if you were advocating that nobody should even attempt to pronounce that and should instead always replace it in speech with the phrase ?Tool kit interface?, with no regard for conveying the particular spelling ?Tkinter?. Are you advocating that? If not, I don't see the relevance of ?NSW? or ?Qld? in this context. -- \ ?For every complex problem, there is a solution that is simple, | `\ neat, and wrong.? ?Henry L. Mencken | _o__) | Ben Finney From ben+python at benfinney.id.au Thu Sep 14 20:17:58 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 15 Sep 2017 10:17:58 +1000 Subject: Change project licence? References: Message-ID: <85377o7r2h.fsf@benfinney.id.au> Kryptxy via Python-list writes: > I have an opensource (python) project under GPL3 licence. Is the license ?GNU GPLv3 only?, or ?GNU GPL v3 or later?, or something else? It doesn't materially affect the question, but it will make the discussion easier if we know what is the actual license grant. I will assume the grant of license is ?GNU GPLv3 or later?. > I wish switch to MIT licence You may wish that. Who else holds copyright in that work? Their contributions ? whether prior to or concurrent with or later than your contributions ? are presumably licensed to you only under the GNU GPLv3-or-later. > so as to make it more permissive. So, it is a deliberate feature of that license grant that no-one who redistributes the work, whether modified or not, can restrict the freedoms granted by that license. How do you know that every other copyright holder wishes to abandon that feature now? > I know how to change the licence, but I want to know is it fine and > wise to change the licence at this point? (The project already has 19 > clones, 250+ GitHub stars. Here: https://github.com/kryptxy/torrench) Those represent a whole lot of recipients, who received GPLv3-or-later license grant, guaranteeing the freedom of the work for all recipients in all modified forms. I would consider it poor form to allow non-free redistribution at this point. -- \ ?[W]hoever is able to make you absurd is able to make you | `\ unjust.? ?Voltaire | _o__) | Ben Finney From rosuav at gmail.com Thu Sep 14 20:24:47 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Sep 2017 10:24:47 +1000 Subject: Change project licence? In-Reply-To: <85377o7r2h.fsf@benfinney.id.au> References: <85377o7r2h.fsf@benfinney.id.au> Message-ID: On Fri, Sep 15, 2017 at 10:17 AM, Ben Finney wrote: >> I know how to change the licence, but I want to know is it fine and >> wise to change the licence at this point? (The project already has 19 >> clones, 250+ GitHub stars. Here: https://github.com/kryptxy/torrench) > > Those represent a whole lot of recipients, who received GPLv3-or-later > license grant, guaranteeing the freedom of the work for all recipients > in all modified forms. I would consider it poor form to allow non-free > redistribution at this point. Those recipients can still do everything they previously could, *including redistributing the code under the GPLv3*. They have lost nothing. ChrisA From arj.python at gmail.com Thu Sep 14 22:04:59 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 15 Sep 2017 06:04:59 +0400 Subject: version of Python to install Windows 7 professional 64 bit, intel core i5 In-Reply-To: <03EFC159-E9FC-435F-BDAA-A193CD2DD8EC@gmail.com> References: <03EFC159-E9FC-435F-BDAA-A193CD2DD8EC@gmail.com> Message-ID: i'd recommend 3.4 or 3.6 python version is chosen more for python functionality rather than hardware type. Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 12 Sep 2017 07:38, "Zubair Shaikh" wrote: > What version of Python to install Windows 7 professional 64 bit, intel > core i5 > -- > https://mail.python.org/mailman/listinfo/python-list > From arj.python at gmail.com Thu Sep 14 22:09:21 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 15 Sep 2017 06:09:21 +0400 Subject: ttk.Notebook Tabs Question In-Reply-To: References: Message-ID: try widget["width"] it returns string then mult by no. of tabs Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 12 Sep 2017 06:45, "Wildman via Python-list" wrote: > I am working on a program that has a ttk.Notebook with > 12 tabs. Is there a way to determine the total width > of the tabs in pixels. Just to be clear I am not talking > about width of the nb container. I am talking about > tabs themselves that contain the text. > > I want the program to be resizable but I don't want to > allow the window width to fall below that of the tabs > which would hide them. Since I can find no way to have > more than one row of tabs, this appears to be my only > option. Any suggestions would be appreciated. > > -- > GNU/Linux user #557453 > May the Source be with you. > -- > https://mail.python.org/mailman/listinfo/python-list > From vincent.vande.vyvre at telenet.be Fri Sep 15 00:09:46 2017 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Fri, 15 Sep 2017 06:09:46 +0200 Subject: The Incredible Growth of Python (stackoverflow.blog)(kdnuggets) In-Reply-To: <2D90DDD4-5231-43B9-A8D2-4A7FFDCAA734@icloud.com> References: <87a823m2ss.fsf@elektro.pacujo.net> <87poawa8h5.fsf@nightsong.com> <87h8w79jx2.fsf@nightsong.com> <85k2126ndz.fsf@benfinney.id.au> <87vaklhnir.fsf@nightsong.com> <2D90DDD4-5231-43B9-A8D2-4A7FFDCAA734@icloud.com> Message-ID: Again an other review: http://www.kdnuggets.com/2017/08/python-overtakes-r-leader-analytics-data-science.html Vincent From santosh.yelamarthi at gmail.com Fri Sep 15 02:01:20 2017 From: santosh.yelamarthi at gmail.com (santosh.yelamarthi at gmail.com) Date: Thu, 14 Sep 2017 23:01:20 -0700 (PDT) Subject: String to Dictionary conversion in python Message-ID: Hi, Can anyone help me in the below issue. I need to convert string to dictionary string = " 'msisdn': '7382432382', 'action': 'select', 'sessionId': '123', 'recipient': '7382432382', 'language': 'english'" Can anyone help me with the code From BILL_NOSPAM at whoknows.net Fri Sep 15 02:13:32 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Fri, 15 Sep 2017 02:13:32 -0400 Subject: String to Dictionary conversion in python In-Reply-To: References: Message-ID: santosh.yelamarthi at gmail.com wrote: > Hi, > > Can anyone help me in the below issue. > > I need to convert string to dictionary > > string = " 'msisdn': '7382432382', 'action': 'select', 'sessionId': '123', 'recipient': '7382432382', 'language': 'english'" > > Can anyone help me with the code I'm new to Python too, but it looks like you need to "split" it about the commas. Right? From ian.g.kelly at gmail.com Fri Sep 15 02:32:45 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 15 Sep 2017 00:32:45 -0600 Subject: String to Dictionary conversion in python In-Reply-To: References: Message-ID: On Fri, Sep 15, 2017 at 12:01 AM, wrote: > Hi, > > Can anyone help me in the below issue. > > I need to convert string to dictionary > > string = " 'msisdn': '7382432382', 'action': 'select', 'sessionId': '123', 'recipient': '7382432382', 'language': 'english'" > > Can anyone help me with the code It looks like this might do what you need: py> import ast py> string = " 'msisdn': '7382432382', 'action': 'select', 'sessionId': '123', 'recipient': '7382432382', 'language': 'english'" py> ast.literal_eval('{%s}' % string) {'sessionId': '123', 'recipient': '7382432382', 'msisdn': '7382432382', 'action': 'select', 'language': 'english'} From best_lay at yahoo.com Fri Sep 15 11:24:59 2017 From: best_lay at yahoo.com (Wildman) Date: Fri, 15 Sep 2017 10:24:59 -0500 Subject: ttk.Notebook Tabs Question References: Message-ID: On Fri, 15 Sep 2017 06:09:21 +0400, Abdur-Rahmaan Janhangeer wrote: > try > widget["width"] it returns string > then mult by no. of tabs Since the tabs are displaying text, I believe the width would be returned as characters or letters like a Button or Text widget. I need pixels. Another problem is that the tabs are different widths. I am going to experiment with the possibility of using images in place of the text. Then I believe the width would be returned in pixels. Thanks for the reply. -- GNU/Linux user #557453 The cow died so I don't need your bull! From ganesh1pal at gmail.com Fri Sep 15 11:43:16 2017 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Fri, 15 Sep 2017 21:13:16 +0530 Subject: How do I check all variables returned buy the functions exists Message-ID: I have a function that return's x variables How do I check if all the the values returned are not None/False/0/'' Here is the same program to demonstrate this , but I felt this can be better any suggestions ? # vi file.py import random import string def return_x_values(): " returns x strings for further processing" value1 = random.choice(string.ascii_letters) value2 = random.choice(string.ascii_letters) value3 = random.choice(string.ascii_letters) return (value1, value2, value3) #unpack them value1, value2 , value3 = return_x_values() # check if its not none # I think this can be better if value1 and value2 and value3 : print "continue with the program" else: print "Exting the program" # python file.py continue with the program I am a Linux user with Python 2.7 Regards, Ganesh From toby at tobiah.org Fri Sep 15 12:03:04 2017 From: toby at tobiah.org (Tobiah) Date: Fri, 15 Sep 2017 09:03:04 -0700 Subject: Question about modules documentation Message-ID: In this doc: https://docs.python.org/2/tutorial/modules.html Near the top it states: Modules can import other modules. It is customary but not required to place all import statements at the beginning of a module (or script, for that matter). The imported module names are placed in the importing module?s global symbol table. When it refers to 'the imported module names' it sounds as though it is referring to the top level variables and functions in the imported module. This is not the case as far as I can tell. If bar.py has a function bar() and in foo.py I do: import bar bar() of course this fails. I have to do: import bar bar.bar() I know it would work if I went: from bar import * bar() but that feature is only introduced in the next section of the doc. It seems that if the statement read: the imported module's name (singular) is placed in the importing module's global symbol table. That it would be more accurate. From accessnewbie at gmail.com Fri Sep 15 12:06:18 2017 From: accessnewbie at gmail.com (accessnewbie at gmail.com) Date: Fri, 15 Sep 2017 09:06:18 -0700 (PDT) Subject: Merging pdf files based on a value in a field In-Reply-To: <42e1a363-c2f1-41a8-8ec5-96dcdc47e0b1@googlegroups.com> References: <42e1a363-c2f1-41a8-8ec5-96dcdc47e0b1@googlegroups.com> Message-ID: <6abf947a-ee09-4213-8c6b-2e8213ba38c8@googlegroups.com> Suggestions to use pyPDF2 to append files did not pan out. I had to go with the arcpy module. pyPDF2 does NOT merge correctly when trying to output multiple files based on a a similar value or key (essentially the group by concept). import csv import arcpy from arcpy import env import shutil, os, glob # clear out files from destination directory files = glob.glob(r'C:\maps\JoinedMaps\*') for f in files: os.remove(f) # open csv file f = open("C:\maps\Maps.csv", "r+") ff = csv.reader(f) # set variable to establish previous row of csv file (for comaprrison) pre_line = ff.next() # Iterate through csv file for cur_line in ff: # new file name and location based on value in column (county name) newPdfFile = (r'C:\maps\JoinedMaps\County-' + cur_line[0] +'.pdf') # establish pdf files to be appended joinFile = pre_line[1] appendFile = cur_line[1] # If columns in both rows match if pre_line[0] == cur_line[0]: # <-- compare first column # If destnation file already exists, append file referenced in current row if os.path.exists(newPdfFile): tempPdfDoc = arcpy.mapping.PDFDocumentOpen(newPdfFile) tempPdfDoc.appendPages(appendFile) # Otherwise create destination and append files reference in both the previous and current row else: tempPdfDoc = arcpy.mapping.PDFDocumentCreate(newPdfFile) tempPdfDoc.appendPages(joinFile) tempPdfDoc.appendPages(appendFile) # save and delete temp file tempPdfDoc.saveAndClose() del tempPdfDoc else: # if no match, do not merge, just copy shutil.copyfile(appendFile,newPdfFile) # reset variable pre_line = cur_line Final output looked like this: County-County1 (2 pages - Map1 and Map2) County-County2 (2 pages - Map1 and Map3) County-County3 (1 page - Map3) County-County2 (3 pages - Map2, Map3, and Map4) From rgaddi at highlandtechnology.invalid Fri Sep 15 12:08:16 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 15 Sep 2017 09:08:16 -0700 Subject: How do I check all variables returned buy the functions exists In-Reply-To: References: Message-ID: On 09/15/2017 08:43 AM, Ganesh Pal wrote: > I have a function that return's x variables How do I check if all the the > values returned are not None/False/0/'' > > Here is the same program to demonstrate this , but I felt this can be > better any suggestions ? > > > # vi file.py > import random > import string > > > def return_x_values(): > " returns x strings for further processing" > value1 = random.choice(string.ascii_letters) > value2 = random.choice(string.ascii_letters) > value3 = random.choice(string.ascii_letters) > return (value1, value2, value3) > > > #unpack them > > value1, value2 , value3 = return_x_values() > > > # check if its not none > > # I think this can be better > if value1 and value2 and value3 : > print "continue with the program" > > else: > print "Exting the program" > > > # python file.py > continue with the program > > I am a Linux user with Python 2.7 > > Regards, > Ganesh > Don't unpack them yet, you still want them to be aggregated. vals = return_x_values() if all(vals): v1, v2, v3 = vals print "all values true" else: print "at least one false value" -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From toby at tobiah.org Fri Sep 15 12:08:42 2017 From: toby at tobiah.org (Tobiah) Date: Fri, 15 Sep 2017 09:08:42 -0700 Subject: Question about modules documentation References: Message-ID: Re-reading I guess the plural refers to the multiple modules referenced in the first sentence. It was probably written that way before someone inserted the bit about the customary placement, which greatly clouds the connection. On 09/15/2017 09:03 AM, Tobiah wrote: > In this doc: > > https://docs.python.org/2/tutorial/modules.html > > Near the top it states: > > Modules can import other modules. It is customary but not > required to place all import statements at the beginning > of a module (or script, for that matter). The imported > module names are placed in the importing module?s global > symbol table. > > When it refers to 'the imported module names' it sounds as though > it is referring to the top level variables and functions in the > imported module. This is not the case as far as I can tell. > > > If bar.py has a function bar() and in foo.py I do: > > import bar > bar() > > of course this fails. I have to do: > > import bar > bar.bar() > > I know it would work if I went: > > from bar import * > bar() > > but that feature is only introduced in the next section > of the doc. > > It seems that if the statement read: > > the imported module's name (singular) is placed in the > importing module's global symbol table. > > That it would be more accurate. > > > > From rosuav at gmail.com Fri Sep 15 12:09:13 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Sep 2017 02:09:13 +1000 Subject: Question about modules documentation In-Reply-To: References: Message-ID: On Sat, Sep 16, 2017 at 2:03 AM, Tobiah wrote: > It seems that if the statement read: > > the imported module's name (singular) is placed in the > importing module's global symbol table. > > That it would be more accurate. That implies that you only import one module. Consider: import sys import os import math import random The imported module names ("sys", "os", "math", and "random") are all then available as global names. That's why it's in the plural. ChrisA From toby at tobiah.org Fri Sep 15 13:05:31 2017 From: toby at tobiah.org (Tobiah) Date: Fri, 15 Sep 2017 10:05:31 -0700 Subject: Question about modules documentation References: Message-ID: On 09/15/2017 09:25 AM, Stefan Ram wrote:> Tobiah writes: >> Modules can import other modules. It is customary but not >> required to place all import statements at the beginning >> of a module (or script, for that matter). The imported >> module names are placed > .. >> When it refers to 'the imported module names' it sounds as though >> it is referring to the top level variables and functions in the >> imported module. > > A "module name" usually is the name of a module. > > When someone uses "module name(s)" it does /not/ sound as > if he is using it to mean "the top level variables and > functions in the named module(s)". > > Since the preceding sentence uses the plural "import statements", > the next sentence has to use the plural "module names". > 'next sentence' is the operative piece. I think that if the bit about placement was moved to the end of the paragraph the whole thing would be more readable and I wouldn't have stumbled on it. From rhodri at kynesim.co.uk Fri Sep 15 13:56:57 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 15 Sep 2017 18:56:57 +0100 Subject: Question about modules documentation In-Reply-To: References: Message-ID: On 15/09/17 18:05, Tobiah wrote: > On 09/15/2017 09:25 AM, Stefan Ram wrote:> Tobiah writes: >>> Modules can import other modules. It is customary but not >>> required to place all import statements at the beginning >>> of a module (or script, for that matter). The imported >>> module names are placed >> .. >>> When it refers to 'the imported module names' it sounds as though >>> it is referring to the top level variables and functions in the >>> imported module. >> >> A "module name" usually is the name of a module. >> >> When someone uses "module name(s)" it does /not/ sound as >> if he is using it to mean "the top level variables and >> functions in the named module(s)". >> >> Since the preceding sentence uses the plural "import statements", >> the next sentence has to use the plural "module names". >> > > 'next sentence' is the operative piece. I think that if the bit > about placement was moved to the end of the paragraph the whole thing would > be more readable and I wouldn't have stumbled on it. If it had meant "the imported module's names" or indeed "the imported modules' names", I would hope it would have said so. -- Rhodri James *-* Kynesim Ltd From rosuav at gmail.com Fri Sep 15 14:24:31 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Sep 2017 04:24:31 +1000 Subject: Which database system? In-Reply-To: References: Message-ID: On Sat, Sep 16, 2017 at 4:04 AM, Stefan Ram wrote: > When one is building an in-memory database that has a single > table that is built at the start of the program and then one > writes some complex queries to the table, what can be expected > to be faster: > > - implementing the table as a builtins.list of builtins.tuples > with builtins.dicts as indexes for faster lookups and > additional sorted builtins.lists for sorted "views" on the > table > > - implementing the table as a database table in sqlite3 > (":memory:") and using SQL commands for insertion and > queries? You're gonna get that dreaded response... It depends. To decide whether it's better to use built-in objects or an in-memory SQLite3 database, I would decide more on the basis of desired semantics and simplicity than pure performance. Can you do everything with *just* dict lookups? If so, there's no point going for SQLite3. Are you going to be wanting complex queries where you filter by multiple columns? Then the dict is going to be a lot of hassle, so SQL is well worth it. Might you, in the future, want to drop your data to disk? Then *definitely* go SQLite3, because it's trivial to switch from :memory: to a file, but switching your dict/list system to be disk-backed is a lot harder. In terms of pure performance, I would generally expect that anything where the above rules say "go with dict/list" will also be faster with a dict/list system than it would be with SQLite3. In the cases where I'd prefer SQLite3, the performance could go either way, but honestly, it matters less than the massive code maintenance cost of rolling your own query system. ChrisA From torriem at gmail.com Fri Sep 15 14:26:57 2017 From: torriem at gmail.com (Michael Torrie) Date: Fri, 15 Sep 2017 12:26:57 -0600 Subject: Which database system? In-Reply-To: References: Message-ID: <651df0ce-b7a1-fc23-e3ef-bba10ed9eb2f@gmail.com> On 09/15/2017 12:04 PM, Stefan Ram wrote: > When one is building an in-memory database that has a single > table that is built at the start of the program and then one > writes some complex queries to the table, what can be expected ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ How do you plan to code these queries? That really is what's going to dictate the answer. Basically with the first of your solutions below you'll be manually creating the query code, doing all the selects, projects, and joins manually (essentially an ad-hoc implementation of relational algebra). If you want to use SQL for composing such queries, and not do the work yourself, then the second option is ideal. In other languages like C#, there's the LINQ syntax which lets you compose queries to a variety of data stores including things like lists. There is a project to bring LINQ-type queries to Python: https://pypi.python.org/pypi/py-linq/0.4.0 . that may work well with your first option below. > to be faster: > > - implementing the table as a builtins.list of builtins.tuples > with builtins.dicts as indexes for faster lookups and > additional sorted builtins.lists for sorted "views" on the > table > > - implementing the table as a database table in sqlite3 > (":memory:") and using SQL commands for insertion and > queries? > From toby at tobiah.org Fri Sep 15 14:37:17 2017 From: toby at tobiah.org (Tobiah) Date: Fri, 15 Sep 2017 11:37:17 -0700 Subject: Question about modules documentation References: Message-ID: >> 'next sentence' is the operative piece. I think that if the bit >> about placement was moved to the end of the paragraph the whole >> thing would be more readable and I wouldn't have stumbled on it. > > If it had meant "the imported module's names" or indeed "the imported > modules' names", I would hope it would have said so. > Fair enough. From andrey.estrada2 at gmail.com Fri Sep 15 15:30:40 2017 From: andrey.estrada2 at gmail.com (andrey.estrada2 at gmail.com) Date: Fri, 15 Sep 2017 12:30:40 -0700 (PDT) Subject: Test Bank for Governing Texas, 3rd Edition by Champagne Harpham In-Reply-To: <4a0b43e5-c374-435f-a73b-9fc017caf027@googlegroups.com> References: <4a0b43e5-c374-435f-a73b-9fc017caf027@googlegroups.com> Message-ID: <8ae16aea-5049-4a24-b3b2-d29cdead41db@googlegroups.com> On Sunday, July 9, 2017 at 5:58:45 AM UTC-6, Test Banks wrote: > Greetings, > > You can get Test Bank for " Governing Texas, 3rd Edition by Anthony Champagne, Edward J. Harpham, Jason P. Casellas " at very reasonable price. Our team is available 24/7 and 365 days / year to respond your requests. Send us an email at pro.fast(@)hotmail(dot)com > > Place your order at PRO.FAST(@)HOTMAIL(DOT)COM > > ISBN Numbers for this book (ISBN-10: 0393283674 and ISBN-13: 9780393283679) > > GOVERNING TEXAS, 3RD EDITION BY CHAMPAGNE HARPHAM TEST BANK > > You can also email for other Political Science books Solutions and Test Bank at low prices and our team will try to get all resources you need. > > Do not post your reply here. Simply send us an email at PRO.FAST (AT) HOTMAIL (DOT) COM > > Cheers I am interested in the testbank for this book. What is the price ? From python.list at tim.thechases.com Fri Sep 15 15:36:11 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 15 Sep 2017 14:36:11 -0500 Subject: Standard for dict-contants with duplicate keys? Message-ID: <20170915143611.0f59ec5b@bigbox.christie.dr> Looking through docs, I was unable to tease out whether there's a prescribed behavior for the results of defining a dictionary with the same keys multiple times d = { "a": 0, "a": 1, "a": 2, } In my limited testing, it appears to always take the last one, resulting in {"a": 2} as if it iterated over the items, adding them to the dict, tromping atop any previous matching keys in code-order. Is this guaranteed by the language spec, or do I have a long weekend of data-cleaning ahead of me? (this comes from an unwitting coworker creating such dicts that mung customer data, and I am trying to determine the extent of the damage...whether it's a consistent issue or is at the arbitrary whims of the parser) Thanks, -tkc From python at mrabarnett.plus.com Fri Sep 15 15:45:20 2017 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 15 Sep 2017 20:45:20 +0100 Subject: ttk.Notebook Tabs Question In-Reply-To: References: Message-ID: On 2017-09-15 16:24, Wildman via Python-list wrote: > On Fri, 15 Sep 2017 06:09:21 +0400, Abdur-Rahmaan Janhangeer wrote: > >> try >> widget["width"] it returns string >> then mult by no. of tabs > > Since the tabs are displaying text, I believe the width > would be returned as characters or letters like a Button > or Text widget. I need pixels. > Why assume that the width is returned as characters? Why not try it? > Another problem is that the tabs are different widths. > > I am going to experiment with the possibility of using > images in place of the text. Then I believe the width > would be returned in pixels. > > Thanks for the reply. > From geoffrey.eisenbarth at gmail.com Fri Sep 15 16:33:44 2017 From: geoffrey.eisenbarth at gmail.com (geoffrey.eisenbarth at gmail.com) Date: Fri, 15 Sep 2017 13:33:44 -0700 (PDT) Subject: Basic Lotus 1-2-3 worksheet creation class for Python In-Reply-To: <4ffl46$6vf@pcnet1.pcnet.com> References: <4ffl46$6vf@pcnet1.pcnet.com> Message-ID: <3d639e00-1566-4521-8d6b-7a35bcb7d9d5@googlegroups.com> I just wanted to let you now that as someone whose boss prefers to use WK1 in 2017, this is going to save my life. Thanks :) About to try this out, if I have to do anything to get it to work with Python3 I'll post the changes here later. From jladasky at itu.edu Fri Sep 15 16:34:16 2017 From: jladasky at itu.edu (jladasky at itu.edu) Date: Fri, 15 Sep 2017 13:34:16 -0700 (PDT) Subject: String to Dictionary conversion in python In-Reply-To: References: Message-ID: <17e874a2-7225-4048-a00c-3aaf04cf504b@googlegroups.com> On Thursday, September 14, 2017 at 11:33:56 PM UTC-7, Ian wrote: > On Fri, Sep 15, 2017 at 12:01 AM, wrote: > > Hi, > > > > Can anyone help me in the below issue. > > > > I need to convert string to dictionary > > > > string = " 'msisdn': '7382432382', 'action': 'select', 'sessionId': '123', 'recipient': '7382432382', 'language': 'english'" > > > > Can anyone help me with the code > > It looks like this might do what you need: > > py> import ast > py> string = " 'msisdn': '7382432382', 'action': 'select', > 'sessionId': '123', 'recipient': '7382432382', 'language': 'english'" > py> ast.literal_eval('{%s}' % string) > {'sessionId': '123', 'recipient': '7382432382', 'msisdn': > '7382432382', 'action': 'select', 'language': 'english'} Very clever! And definitely not an answer that would be acceptable for a homework assignment. From tjreedy at udel.edu Fri Sep 15 17:45:22 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 15 Sep 2017 17:45:22 -0400 Subject: Standard for dict-contants with duplicate keys? In-Reply-To: <20170915143611.0f59ec5b@bigbox.christie.dr> References: <20170915143611.0f59ec5b@bigbox.christie.dr> Message-ID: On 9/15/2017 3:36 PM, Tim Chase wrote: > Looking through docs, I was unable to tease out whether there's a > prescribed behavior for the results of defining a dictionary with the > same keys multiple times > > d = { > "a": 0, > "a": 1, > "a": 2, > } > > In my limited testing, it appears to always take the last one, > resulting in > > {"a": 2} > > as if it iterated over the items, adding them to the dict, tromping > atop any previous matching keys in code-order. > > Is this guaranteed by the language spec, https://docs.python.org/3/reference/expressions.html#dictionary-displays If a comma-separated sequence of key/datum pairs is given, they are evaluated from left to right to define the entries of the dictionary: each key object is used as a key into the dictionary to store the corresponding datum. This means that you can specify the same key multiple times in the key/datum list, and the final dictionary?s value for that key will be the last one given. or do I have a long weekend > of data-cleaning ahead of me? (this comes from an unwitting coworker > creating such dicts that mung customer data, and I am trying to > determine the extent of the damage...whether it's a consistent issue > or is at the arbitrary whims of the parser) > > Thanks, > > -tkc > > > > -- Terry Jan Reedy From __peter__ at web.de Fri Sep 15 17:47:00 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 15 Sep 2017 23:47 +0200 Subject: Standard for dict-contants with duplicate keys? References: <20170915143611.0f59ec5b@bigbox.christie.dr> Message-ID: Tim Chase wrote: > Looking through docs, I was unable to tease out whether there's a > prescribed behavior for the results of defining a dictionary with the > same keys multiple times > > d = { > "a": 0, > "a": 1, > "a": 2, > } > > In my limited testing, it appears to always take the last one, > resulting in > > {"a": 2} > > as if it iterated over the items, adding them to the dict, tromping > atop any previous matching keys in code-order. > > Is this guaranteed by the language spec, or do I have a long weekend > of data-cleaning ahead of me? (this comes from an unwitting coworker > creating such dicts that mung customer data, and I am trying to > determine the extent of the damage...whether it's a consistent issue > or is at the arbitrary whims of the parser) Google finds stackoverflow quotes """ If a comma-separated sequence of key/datum pairs is given, they are evaluated from left to right to define the entries of the dictionary: each key object is used as a key into the dictionary to store the corresponding datum. This means that you can specify the same key multiple times in the key/datum list, and the final dictionary?s value for that key will be the last one given. """ https://docs.python.org/3/reference/expressions.html#dictionary-displays From best_lay at yahoo.com Fri Sep 15 18:16:04 2017 From: best_lay at yahoo.com (Wildman) Date: Fri, 15 Sep 2017 17:16:04 -0500 Subject: ttk.Notebook Tabs Question References: Message-ID: On Fri, 15 Sep 2017 20:45:20 +0100, MRAB wrote: > On 2017-09-15 16:24, Wildman via Python-list wrote: >> On Fri, 15 Sep 2017 06:09:21 +0400, Abdur-Rahmaan Janhangeer wrote: >> >>> try >>> widget["width"] it returns string >>> then mult by no. of tabs >> >> Since the tabs are displaying text, I believe the width >> would be returned as characters or letters like a Button >> or Text widget. I need pixels. >> > Why assume that the width is returned as characters? Why not try it? If I set the width of the tabs, the width is in characters so I expected it to be the same. style = ttk.Style() style.theme_create( "MyStyle", parent="alt", settings={ "TNotebook": {"configure": {"tabmargins": [2, 5, 2, 0] } }, "TNotebook.Tab": {"configure": {"padding": [0,0], "width": [7]}, }}) style.theme_use("MyStyle") Also, I tried "widget["width"] and it returns 0. Same for height. -- GNU/Linux user #557453 The cow died so I don't need your bull! From storchaka at gmail.com Fri Sep 15 18:42:56 2017 From: storchaka at gmail.com (Serhiy Storchaka) Date: Sat, 16 Sep 2017 01:42:56 +0300 Subject: Standard for dict-contants with duplicate keys? In-Reply-To: References: <20170915143611.0f59ec5b@bigbox.christie.dr> Message-ID: 16.09.17 00:45, Terry Reedy ????: > On 9/15/2017 3:36 PM, Tim Chase wrote: >> Looking through docs, I was unable to tease out whether there's a >> prescribed behavior for the results of defining a dictionary with the >> same keys multiple times >> >> d = { >> "a": 0, >> "a": 1, >> "a": 2, >> } >> >> In my limited testing, it appears to always take the last one, >> resulting in >> >> {"a": 2} >> >> as if it iterated over the items, adding them to the dict, tromping >> atop any previous matching keys in code-order. >> >> Is this guaranteed by the language spec, > > https://docs.python.org/3/reference/expressions.html#dictionary-displays > If a comma-separated sequence of key/datum pairs is given, they are > evaluated from left to right to define the entries of the dictionary: > each key object is used as a key into the dictionary to store the > corresponding datum. This means that you can specify the same key > multiple times in the key/datum list, and the final dictionary?s value > for that key will be the last one given. Note that resulting dict can contain key/datum pairs not identical to any key/datum pair in a sequence. >>> {1: 2, True: 3} {1: 3} From steve+python at pearwood.info Fri Sep 15 20:58:06 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 16 Sep 2017 10:58:06 +1000 Subject: How do I check all variables returned buy the functions exists References: Message-ID: <59bc7720$0$16749$b1db1813$d948b532@news.astraweb.com> On Sat, 16 Sep 2017 01:43 am, Ganesh Pal wrote: > I have a function that return's x variables How do I check if all the the > values returned are not None/False/0/'' [...] > value1, value2 , value3 = return_x_values() > > > # check if its not none > > # I think this can be better > if value1 and value2 and value3 : > print "continue with the program" values = return_x_values() if all(values): print "continue" else: print "at least one value was falsey" If you want to test for None specifically: if any(v is None for v in values): print "at least one value was None" -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From python.list at tim.thechases.com Fri Sep 15 21:12:15 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 15 Sep 2017 20:12:15 -0500 Subject: Standard for dict-contants with duplicate keys? In-Reply-To: References: <20170915143611.0f59ec5b@bigbox.christie.dr> Message-ID: <20170915201215.6c5387f7@bigbox.christie.dr> On 2017-09-15 17:45, Terry Reedy wrote: > On 9/15/2017 3:36 PM, Tim Chase wrote: > > d = { > > "a": 0, > > "a": 1, > > "a": 2, > > } > > > > In my limited testing, it appears to always take the last one, > > resulting in > > > > {"a": 2} > > > > Is this guaranteed by the language spec > > https://docs.python.org/3/reference/expressions.html#dictionary-displays > If a comma-separated sequence of key/datum pairs is given, they are > evaluated from left to right to define the entries of the > dictionary: each key object is used as a key into the dictionary to > store the corresponding datum. This means that you can specify the > same key multiple times in the key/datum list, and the final > dictionary?s value for that key will be the last one given. Ah, I'd checked the "Data Structures" and "Built-in types" pages, but missed the "expressions" page. At least that means that the botched data in our system is at least *consistently* botched which eases my work a bit. Many thanks, -tkc From rustompmody at gmail.com Fri Sep 15 21:29:20 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 15 Sep 2017 18:29:20 -0700 (PDT) Subject: String to Dictionary conversion in python In-Reply-To: <17e874a2-7225-4048-a00c-3aaf04cf504b@googlegroups.com> References: <17e874a2-7225-4048-a00c-3aaf04cf504b@googlegroups.com> Message-ID: On Saturday, September 16, 2017 at 2:04:39 AM UTC+5:30, jlad... at itu.edu wrote: > On Thursday, September 14, 2017 at 11:33:56 PM UTC-7, Ian wrote: > > On Fri, Sep 15, 2017 at 12:01 AM, wrote: > > > Hi, > > > > > > Can anyone help me in the below issue. > > > > > > I need to convert string to dictionary > > > > > > string = " 'msisdn': '7382432382', 'action': 'select', 'sessionId': '123', 'recipient': '7382432382', 'language': 'english'" > > > > > > Can anyone help me with the code > > > > It looks like this might do what you need: > > > > py> import ast > > py> string = " 'msisdn': '7382432382', 'action': 'select', > > 'sessionId': '123', 'recipient': '7382432382', 'language': 'english'" > > py> ast.literal_eval('{%s}' % string) > > {'sessionId': '123', 'recipient': '7382432382', 'msisdn': > > '7382432382', 'action': 'select', 'language': 'english'} > > Very clever! Yeah? I used to think thus But literal_eval has excessive crud in its error messages: >>> from ast import literal_eval >>> literal_eval("{'x':1}") {'x': 1} Ok? >>> literal_eval("{x:1}") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/ast.py", line 80, in literal_eval return _convert(node_or_string) File "/usr/lib/python2.7/ast.py", line 63, in _convert in zip(node.keys, node.values)) File "/usr/lib/python2.7/ast.py", line 62, in return dict((_convert(k), _convert(v)) for k, v File "/usr/lib/python2.7/ast.py", line 79, in _convert raise ValueError('malformed string') ValueError: malformed string >>> literal_eval("'x':1") Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/ast.py", line 49, in literal_eval node_or_string = parse(node_or_string, mode='eval') File "/usr/lib/python2.7/ast.py", line 37, in parse return compile(source, filename, mode, PyCF_ONLY_AST) File "", line 1 'x':1 ^ SyntaxError: invalid syntax > And definitely not an answer that would be acceptable for a homework assignment. ? From steve+python at pearwood.info Fri Sep 15 21:37:23 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 16 Sep 2017 11:37:23 +1000 Subject: Which database system? References: Message-ID: <59bc8054$0$16740$b1db1813$d948b532@news.astraweb.com> On Sat, 16 Sep 2017 04:24 am, Chris Angelico wrote: > but switching your dict/list system to be > disk-backed is a lot harder. import shelve :-) Now you have two problems :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From torriem at gmail.com Fri Sep 15 21:44:07 2017 From: torriem at gmail.com (Michael Torrie) Date: Fri, 15 Sep 2017 19:44:07 -0600 Subject: Which database system? In-Reply-To: References: <651df0ce-b7a1-fc23-e3ef-bba10ed9eb2f@gmail.com> Message-ID: <064498a3-6a2e-e54a-58ba-ed557014edf4@gmail.com> On 09/15/2017 03:10 PM, Dennis Lee Bieber wrote: > "single table" so no join logic needed. And I suspect the relational > algebra "project" would be considered the same as SQL "select" by most > folks As Stefan has said, it's sometimes useful to join a table with itself, though I have never done that myself. As for select and project, both are distinct operations and both required. In fact both operations are a part of the SQL "SELECT" command. The first bit, the list of fields, is the project part, and the "WHERE" part is the select part, as well as the join part. Guess SQL blurs the lines between the operations. And my point was if he needs those things then he's already reinvented the SQL SELECT, so he may as well just use SQL. Alternatively, use a LINQ-like library that implements the relational algebra for him. Sorry I was unclear. From rosuav at gmail.com Fri Sep 15 22:18:12 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Sep 2017 12:18:12 +1000 Subject: Which database system? In-Reply-To: <59bc8054$0$16740$b1db1813$d948b532@news.astraweb.com> References: <59bc8054$0$16740$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sat, Sep 16, 2017 at 11:37 AM, Steve D'Aprano wrote: > On Sat, 16 Sep 2017 04:24 am, Chris Angelico wrote: > >> but switching your dict/list system to be >> disk-backed is a lot harder. > > import shelve > > :-) > > > > Now you have two problems :-) > Yeah, like: How do you do a query (anything more complicated than direct lookup) without loading everything into memory? Though I had forgotten about shelve. It's not something I use often... actually I don't think I've ever used it more than "hello world". ChrisA From steve+python at pearwood.info Sat Sep 16 01:38:31 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 16 Sep 2017 15:38:31 +1000 Subject: Old Man Yells At Cloud Message-ID: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> /rant on So apparently everyone who disagrees that Python should be more like Javascript is an old greybeard fuddy-duddy yelling "Get off my lawn!" to the cool kids -- and is also too stupid to know how dumb they are. "Hi, I've been programming in Python for what seems like days now, and here's all the things that you guys are doing wrong. I insist that you fix them immediately, it doesn't matter how much code it will break, that's not important. What is important is that Javascript programmers like me shouldn't be expected to learn anything new or different when they program with Python." /rant off And no, for once it wasn't Ranting Rick. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From piet-l at vanoostrum.org Sat Sep 16 05:42:13 2017 From: piet-l at vanoostrum.org (Piet van Oostrum) Date: Sat, 16 Sep 2017 11:42:13 +0200 Subject: String to Dictionary conversion in python References: <17e874a2-7225-4048-a00c-3aaf04cf504b@googlegroups.com> Message-ID: Rustom Mody writes: > On Saturday, September 16, 2017 at 2:04:39 AM UTC+5:30, jlad... at itu.edu wrote: > Yeah? I used to think thus > But literal_eval has excessive crud in its error messages: > >>>> from ast import literal_eval > >>>> literal_eval("{'x':1}") > {'x': 1} > > Ok? > >>>> literal_eval("{x:1}") > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.7/ast.py", line 80, in literal_eval > return _convert(node_or_string) > File "/usr/lib/python2.7/ast.py", line 63, in _convert > in zip(node.keys, node.values)) > File "/usr/lib/python2.7/ast.py", line 62, in > return dict((_convert(k), _convert(v)) for k, v > File "/usr/lib/python2.7/ast.py", line 79, in _convert > raise ValueError('malformed string') > ValueError: malformed string > You can catch the exception and print a nice error message: from ast import literal_eval def literal(s): try: return literal_eval('{'+s+'}') except Exception as e: print "%s: %s" % (type(e).__name__, ', '.join(e.args)) >>> literal("'x':1") {'x': 1} >>> literal("x:1") ValueError: malformed string But in non-interactive use you probably want to propagate the exception. -- Piet van Oostrum WWW: http://piet.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From steve+python at pearwood.info Sat Sep 16 08:37:28 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 16 Sep 2017 22:37:28 +1000 Subject: String to Dictionary conversion in python References: <17e874a2-7225-4048-a00c-3aaf04cf504b@googlegroups.com> Message-ID: <59bd1b0b$0$16752$b1db1813$d948b532@news.astraweb.com> On Sat, 16 Sep 2017 11:29 am, Rustom Mody wrote: >> > py> import ast >> > py> string = " 'msisdn': '7382432382', 'action': 'select', >> > 'sessionId': '123', 'recipient': '7382432382', 'language': 'english'" >> > py> ast.literal_eval('{%s}' % string) >> > {'sessionId': '123', 'recipient': '7382432382', 'msisdn': >> > '7382432382', 'action': 'select', 'language': 'english'} >> >> Very clever! > Yeah? I used to think thus > But literal_eval has excessive crud in its error messages: > >>>> from ast import literal_eval > >>>> literal_eval("{'x':1}") > {'x': 1} > > Ok? > >>>> literal_eval("{x:1}") > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python2.7/ast.py", line 80, in literal_eval > return _convert(node_or_string) > File "/usr/lib/python2.7/ast.py", line 63, in _convert > in zip(node.keys, node.values)) > File "/usr/lib/python2.7/ast.py", line 62, in > return dict((_convert(k), _convert(v)) for k, v > File "/usr/lib/python2.7/ast.py", line 79, in _convert > raise ValueError('malformed string') > ValueError: malformed string Here's the bug tracker: make a feature request for literal_eval to be more concise in its traceback and provide a more useful and detailed error message. https://bugs.python.org/ -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From __peter__ at web.de Sat Sep 16 10:54:38 2017 From: __peter__ at web.de (Peter Otten) Date: Sat, 16 Sep 2017 16:54:38 +0200 Subject: Which database system? References: <651df0ce-b7a1-fc23-e3ef-bba10ed9eb2f@gmail.com> Message-ID: Stefan Ram wrote: > Michael Torrie writes: >>On 09/15/2017 12:04 PM, Stefan Ram wrote: >>>writes some complex queries to the table, what can be expected >>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >>How do you plan to code these queries? > > I did a quick prototype. I am aware that the code > is very quick and very dirty. But since you ask: > > The table is filled after ?# fill table? below. > > An example ad-hoc query then follows after > ?# query table? below. > > This code was not intended to be read by someone else, > the next thing to do is a clean up of the code. "import builtins", lines ending on ';', both extra and missing spaces, come on ;) Do yourself a favour, and steer your style a bit more into the direction of PEP 8. > So you have been warned! > > The output should be: > > |abend > | - Beispiel = Montag abend > |Abend > | - Beispiel = des Abends > |?hnlich > | - Beispiel = dem Hause ?hnlich Based on the example I wonder if you really want a table, or whether something tree-like would be more appropriate: from collections import OrderedDict, defaultdict data = { "abend": { "Beispiel": {"Montag abend"}, "Kategorie": {"Deutsches W?rterbuch", "Gro?- und Kleinschreibung"} }, "Abend": { "Beispiel": {"des Abends"}, "Kategorie": {"Deutsches W?rterbuch", "Getrennt -und Zusammenschreibung"} }, "Montag abend": { "Kategorie": {"Getrennt -und Zusammenschreibung"} }, "?hnlich": { "Kategorie": {"Deutsches W?rterbuch"}, "Beispiel": {"dem Hause ?hnlich"} }, } data = OrderedDict(sorted( ((k, defaultdict(set, v)) for k, v in data.items()), key=lambda kv: (kv[0].casefold(), kv[0]))) for key, value in data.items(): if "Deutsches W?rterbuch" in value["Kategorie"]: print(key) for example in value["Beispiel"]: print(" -", example) If this turns out to be too slow just throw more lookup tables at it: by_relation = defaultdict(list) for key, value in data.items(): for k, v in value.items(): for vv in v: by_relation[k, vv].append(key) Then you can rewrite the print loops to avoid iterating over the whole table: for key in by_relation["Kategorie", "Deutsches W?rterbuch"]: print(key) for example in data[key]["Beispiel"]: print(" -", example) From info at tundraware.com Sat Sep 16 10:59:43 2017 From: info at tundraware.com (Tim Daneliuk) Date: Sat, 16 Sep 2017 09:59:43 -0500 Subject: Old Man Yells At Cloud In-Reply-To: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: On 09/16/2017 12:38 AM, Steve D'Aprano wrote: > /rant on > > So apparently everyone who disagrees that Python should be more like Javascript > is an old greybeard fuddy-duddy yelling "Get off my lawn!" to the cool kids -- > and is also too stupid to know how dumb they are. > > "Hi, I've been programming in Python for what seems like days now, and here's > all the things that you guys are doing wrong. I insist that you fix them > immediately, it doesn't matter how much code it will break, that's not > important. What is important is that Javascript programmers like me shouldn't > be expected to learn anything new or different when they program with Python." > > /rant off > > And no, for once it wasn't Ranting Rick. > > > > Well, the whole integer floor division thing years ago was the beginning of the end - Python was doomed ... From info at tundraware.com Sat Sep 16 11:00:00 2017 From: info at tundraware.com (Tim Daneliuk) Date: Sat, 16 Sep 2017 10:00:00 -0500 Subject: Old Man Yells At Cloud In-Reply-To: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: On 09/16/2017 12:38 AM, Steve D'Aprano wrote: > /rant on > > So apparently everyone who disagrees that Python should be more like Javascript > is an old greybeard fuddy-duddy yelling "Get off my lawn!" to the cool kids -- > and is also too stupid to know how dumb they are. > > "Hi, I've been programming in Python for what seems like days now, and here's > all the things that you guys are doing wrong. I insist that you fix them > immediately, it doesn't matter how much code it will break, that's not > important. What is important is that Javascript programmers like me shouldn't > be expected to learn anything new or different when they program with Python." > > /rant off > > And no, for once it wasn't Ranting Rick. > > > > Well, the whole integer floor division thing years ago was the beginning of the end - Python was doomed ... From breamoreboy at gmail.com Sat Sep 16 15:30:07 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sat, 16 Sep 2017 12:30:07 -0700 (PDT) Subject: CPython has hit 100,000 commits Message-ID: Looks as if people have been busy over the years. Read all about it https://github.com/python/cpython -- Kindest regards. Mark Lawrence. From benjamin at python.org Sat Sep 16 18:05:32 2017 From: benjamin at python.org (Benjamin Peterson) Date: Sat, 16 Sep 2017 15:05:32 -0700 Subject: [RELEASE] Python 2.7.14 Message-ID: <1505599532.1460496.1108442448.264843EC@webmail.messagingengine.com> I'm happy to announce to the immediate availability of Python 2.7.14, yet another bug fix release in the Python 2.7 series. 2.7.14 includes 9 months of conservative bug fixes from the 3.x branch. Downloads of source code and binaries are at: https://www.python.org/downloads/release/python-2714/ Bugs may be reported at https://bugs.python.org/ Warmly, Benjamin 2.7 release manager (on behalf of all of 2.7's contributors) From breamoreboy at gmail.com Sat Sep 16 19:04:03 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sat, 16 Sep 2017 16:04:03 -0700 (PDT) Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" Message-ID: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> I thought some might find this https://sites.google.com/view/energy-efficiency-languages/ interesting. -- Kindest regards. Mark Lawrence. From johnpote at jptechnical.co.uk Sat Sep 16 20:15:41 2017 From: johnpote at jptechnical.co.uk (John Pote) Date: Sun, 17 Sep 2017 01:15:41 +0100 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: <47d390c1-b1fc-6d4e-67e8-2dc70a7d8458@jptechnical.co.uk> On 16/09/2017 19:00, Stefan Ram wrote: > Steve D'Aprano writes: >> "Hi, I've been programming in Python for what seems like days now, and here's >> all the things that you guys are doing wrong. > I never ever have written a line of Python 2. I started with > Python 3.6.0. Yet a very frequent mistake of mine is the > imission of parentheses after ?print?. > > WRT my other common errors, It thought of writing > a program that autocorrects my source code as follows: > > Whenever the next line is indented more, add a colon: > > abd def ghi > jkl mno pqr I've used Komodo in the past and that editor works other way round, type a ':' at the end of a line and the next line is indented. I would presume other language aware editors take the same approach. print """ Your idea would require considerable inteligence in the editor, 1. Otherwise the previous line would print with a ':' 2. That would frustrate me..... """ > > ---------------------> > > abd def ghi: > jkl mno pqr > > Whenever the next line is indented more, add "def" to > what looks like a call (and does not start with ?class? > or ?def?; > > f( x ): > return x * x > > ---------------------> > > def f( x ): > return x * x > > Whenever a line starts with "print" and no parentheses > are following, add them: > > print x, 2 Strangely I find it irksome to have to write print as a function call in Python 3. Must reflect those long ago days when I started to program (oops, I mean code - programming came later). Come to think of it there's something irksome about every language I've ever used. Python probably the least..... > > ---------------------> > > print( x, 2 ) > > Implementing algorithms from "The Art of Computer > Programming" might sometimes be difficult in Python, since > those algorithms IIRC often use ?goto?. Good point. I also have a copy of that work of art (and the fascicles - I must get out more). Sadly little work these days requires diving into them. In fairness to Knuth his pseudo code is a high level assembler fully described in Vol:1 and done as such so folk from any high level language background could follow the algorithms. Back then many like myself, or indeed most coders, had a hardware background and well used to assembler. The nearest thing most silicon has to structured programming is call and return, gotos are everywhere. I always think one of the reasons Basic became so popular was its /goto /statement. The other was the run command, no need to compile. See /http://entrian.com/goto// for a Python implementation from many years ago. No idea if it still works. To be honist never needed it - Python has exceptions. Also there was a interesting thread '/"Goto" statement in Python/' in April this year (not the 1st). Although mainly interesting for its references to gotos in 'C' which I use daily now. err 'C' that is. . . . . . Used to wind up colleagues by saying loudly "Great, I can use a /*goto */here.....". This attracted considerable verbal abuse from purists in earshot and instruction from the boss NOT TO which I pretended to ignore. After all Python programming is supposed to be fun! > From steve+python at pearwood.info Sat Sep 16 21:00:42 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 17 Sep 2017 11:00:42 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> On Sun, 17 Sep 2017 02:52 am, Dennis Lee Bieber wrote: > Yes -- that would give me fits if I were using Python3 currently... > Since so many of the languages I've learned over the past years use the > concept integer / integer => integer_result That would be C, and C derived languages, perhaps? Pascal uses integer / integer => float (except Pascal calls it "Real"). If you want integer division, use "div". I think so did Algol. > Come to think of it -- wasn't there a post from someone (seems to > expired or been filtered from my client) asking for help with some sorting > program... I'm pretty sure the partitioning logic would croak on Python3 > due to floating point results in the slice indices: > > pA = part[:n/2] > pB = part[n/2:] If you want integer division, you have to use integer division :-) pA = part[:n//2] -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Sep 16 21:09:18 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 17 Sep 2017 11:09:18 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> On Sun, 17 Sep 2017 04:00 am, Stefan Ram wrote: > Steve D'Aprano writes: >>"Hi, I've been programming in Python for what seems like days now, and here's >>all the things that you guys are doing wrong. > > I never ever have written a line of Python 2. I started with > Python 3.6.0. Yet a very frequent mistake of mine is the > imission of parentheses after ?print?. That's remarkable. Do you also forget the parentheses around `len`, and `iter`, and `math.sin()`? If not, what's so special about print? Javascript (at least the Rhino interpreter, if not others) includes a print function. It too requires parentheses: js> print 21 js: "", line 5: missing ; before statement js: print 21 js: .......^ js> print(21) 21 > WRT my other common errors, It thought of writing > a program that autocorrects my source code as follows: [...] > Whenever the next line is indented more, add "def" to > what looks like a call (and does not start with ?class? > or ?def?; > > f( x ): > return x * x Seriously Stefan, forgetting colons is one thing, but if you regularly forget to start function definitions with "def", I fear that you're just not paying attention to what you are doing. Do you occasionally find yourself halfway down the street after leaving home when you realise you're not wearing any pants? :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From python at mrabarnett.plus.com Sat Sep 16 21:28:37 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 17 Sep 2017 02:28:37 +0100 Subject: Old Man Yells At Cloud In-Reply-To: <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-09-17 02:00, Steve D'Aprano wrote: > On Sun, 17 Sep 2017 02:52 am, Dennis Lee Bieber wrote: > > >> Yes -- that would give me fits if I were using Python3 currently... >> Since so many of the languages I've learned over the past years use the >> concept integer / integer => integer_result > > That would be C, and C derived languages, perhaps? > Or Fortran. [snip] From rosuav at gmail.com Sat Sep 16 21:42:05 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Sep 2017 11:42:05 +1000 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sun, Sep 17, 2017 at 11:28 AM, MRAB wrote: > On 2017-09-17 02:00, Steve D'Aprano wrote: >> >> On Sun, 17 Sep 2017 02:52 am, Dennis Lee Bieber wrote: >> >> >>> Yes -- that would give me fits if I were using Python3 currently... >>> Since so many of the languages I've learned over the past years use the >>> concept integer / integer => integer_result >> >> >> That would be C, and C derived languages, perhaps? >> > Or Fortran. Or machine code on every CPU I've ever worked with. Dividing integers yields an integer. ChrisA From rosuav at gmail.com Sat Sep 16 21:42:22 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Sep 2017 11:42:22 +1000 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sun, Sep 17, 2017 at 11:42 AM, Chris Angelico wrote: > On Sun, Sep 17, 2017 at 11:28 AM, MRAB wrote: >> On 2017-09-17 02:00, Steve D'Aprano wrote: >>> >>> On Sun, 17 Sep 2017 02:52 am, Dennis Lee Bieber wrote: >>> >>> >>>> Yes -- that would give me fits if I were using Python3 currently... >>>> Since so many of the languages I've learned over the past years use the >>>> concept integer / integer => integer_result >>> >>> >>> That would be C, and C derived languages, perhaps? >>> >> Or Fortran. > > Or machine code on every CPU I've ever worked with. Dividing integers > yields an integer. (Or more technically, yields two integers - div/mod) ChrisA From steve+python at pearwood.info Sat Sep 16 22:01:25 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 17 Sep 2017 12:01:25 +1000 Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> Message-ID: <59bdd776$0$16734$b1db1813$d948b532@news.astraweb.com> On Sun, 17 Sep 2017 09:04 am, breamoreboy at gmail.com wrote: > I thought some might find this > https://sites.google.com/view/energy-efficiency-languages/ interesting. "Made with the new Google Sites, an effortless way to create beautiful sites." More like an effortless way to create a complete dog's breakfast. Once upon a time, web sites would degrade gracefully. If something interrupted the page loading, or something wasn't quite right, or you'd still get something usable. Now, if the tiniest thing goes wrong, you get a junk. I've tried to see the results, but I just get a bunch of broken images :-( On the linked page, starting from the top and scrolling down, I see: - about two screens worth of black white space; - followed by three giant black horizontal bars, each one about an inch high; - more white space; - what looks like something that was intended to be a side-bar, containing: SLE'17 Home Results Setup More - a giant down-pointing arrowhead, about three inches tall, which turns grey when you mouse-over it but doesn't do anything when clicked; - three more links: Home Results Setup which disappear when you mouse-over them; - finally some content! The tools and graphical data pointed by this page are included in the research paper "Energy Efficiency across Programming Languages: How does Energy, Time and Memory Relate?", accepted at the International Conference on Software Language Engineering (SLE) [1] Measuring Framework & Benchmarks [2] Complete Set of Results [3] Setup [4] Paper where the last four bits are links; - the smug, self-congratulatory comment quoted above about "beautiful sites"; - a button "Create a site" - What was presumably intended to be a link, but is actually just a piece of plain text: "Report abuse"; - more whitespace; - and finally a giant blue "i", pointed at the bottom, and slanted at 45 degrees. Presumably a logo for somebody or something. And yes, I am allowing scripts from Google and Gstatic to run, and the page is still broken. Including the hyperlinks, that's about 700 bytes of actual content. Let's double it for the overhead of HTML over plain text, so somewhat less than 1.5 KiB of content. The actual page is 27285 bytes or over 26 KiB. That gives us something with a useful content to bloat factor of 1:17, and *the page still doesn't work.* And that's not even counting any additional files the page requires, like CSS, external javascript files, images, ads, web-bugs, etc. You want to know why browsing the web today on full ADSL or faster speeds is *slower* than using a dial up modem in the 1990s? This is why. www.antipope.org/charlie/blog-static/2008/05/why_your_internet_experience_i.html Nine years later, and the problem is worse, not better. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From no.email at nospam.invalid Sun Sep 17 00:07:57 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 16 Sep 2017 21:07:57 -0700 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> Message-ID: <87r2v6ge76.fsf@nightsong.com> Steve D'Aprano writes: >> concept integer / integer => integer_result > That would be C, and C derived languages, perhaps? Certainly not. Fortran, machine languages, etc. all do that too. Haskell does the right thing and makes int/int a compile time type error. Its integer division functions are div and quot. Python 2 does something reasonable and Python 3 does something that is also debatably reasonable. Switching from one reasonable thing to another without a very good reason is called fixing things that weren't broken. Python 2 wasn't broken in that area and didn't need to be fixed. From ian.g.kelly at gmail.com Sun Sep 17 00:22:32 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 16 Sep 2017 22:22:32 -0600 Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" In-Reply-To: <59bdd776$0$16734$b1db1813$d948b532@news.astraweb.com> References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <59bdd776$0$16734$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sat, Sep 16, 2017 at 8:01 PM, Steve D'Aprano wrote: > On Sun, 17 Sep 2017 09:04 am, breamoreboy at gmail.com wrote: > >> I thought some might find this >> https://sites.google.com/view/energy-efficiency-languages/ interesting. > > "Made with the new Google Sites, an effortless way to create beautiful sites." > > More like an effortless way to create a complete dog's breakfast. Once upon a > time, web sites would degrade gracefully. If something interrupted the page > loading, or something wasn't quite right, or you'd still get something usable. > Now, if the tiniest thing goes wrong, you get a junk. > > I've tried to see the results, but I just get a bunch of broken images :-( > > > On the linked page, starting from the top and scrolling down, I see: > > - about two screens worth of black white space; > > - followed by three giant black horizontal bars, each one about an inch high; > > - more white space; > > - what looks like something that was intended to be a side-bar, containing: > > SLE'17 > Home > Results > Setup > More > > - a giant down-pointing arrowhead, about three inches tall, which turns > grey when you mouse-over it but doesn't do anything when clicked; > > - three more links: > > Home > Results > Setup > > which disappear when you mouse-over them; > > - finally some content! > > The tools and graphical data pointed by this page are included in the > research paper "Energy Efficiency across Programming Languages: How does > Energy, Time and Memory Relate?", accepted at the International Conference > on Software Language Engineering (SLE) > > [1] Measuring Framework & Benchmarks > [2] Complete Set of Results > [3] Setup > [4] Paper > > > where the last four bits are links; > > - the smug, self-congratulatory comment quoted above about "beautiful sites"; > > - a button "Create a site" > > - What was presumably intended to be a link, but is actually just a piece of > plain text: "Report abuse"; > > - more whitespace; > > - and finally a giant blue "i", pointed at the bottom, and slanted at 45 > degrees. Presumably a logo for somebody or something. > > > And yes, I am allowing scripts from Google and Gstatic to run, and the page is > still broken. It looks fine to me. > Including the hyperlinks, that's about 700 bytes of actual content. Let's double > it for the overhead of HTML over plain text, so somewhat less than 1.5 KiB of > content. > > The actual page is 27285 bytes or over 26 KiB. That gives us something with a > useful content to bloat factor of 1:17, and *the page still doesn't work.* > > And that's not even counting any additional files the page requires, like CSS, > external javascript files, images, ads, web-bugs, etc. You want to know why > browsing the web today on full ADSL or faster speeds is *slower* than using a > dial up modem in the 1990s? This is why. > > www.antipope.org/charlie/blog-static/2008/05/why_your_internet_experience_i.html > > Nine years later, and the problem is worse, not better. If you're using a cell phone over 2G, then I tentatively agree. But on my laptop over WiFi, this page that you're complaining about loaded in 783 ms when I tried it. From arj.python at gmail.com Sun Sep 17 00:45:27 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 17 Sep 2017 08:45:27 +0400 Subject: ttk.Notebook Tabs Question In-Reply-To: References: Message-ID: by widget["width"] i meant replace widget with your widget Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 12 Sep 2017 06:45, "Wildman via Python-list" wrote: > I am working on a program that has a ttk.Notebook with > 12 tabs. Is there a way to determine the total width > of the tabs in pixels. Just to be clear I am not talking > about width of the nb container. I am talking about > tabs themselves that contain the text. > > I want the program to be resizable but I don't want to > allow the window width to fall below that of the tabs > which would hide them. Since I can find no way to have > more than one row of tabs, this appears to be my only > option. Any suggestions would be appreciated. > > -- > GNU/Linux user #557453 > May the Source be with you. > -- > https://mail.python.org/mailman/listinfo/python-list > From tjreedy at udel.edu Sun Sep 17 02:00:25 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 17 Sep 2017 02:00:25 -0400 Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" In-Reply-To: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> Message-ID: On 9/16/2017 7:04 PM, breamoreboy at gmail.com wrote: > I thought some might find this https://sites.google.com/view/energy-efficiency-languages/ interesting. By 'energy', they only mean electricity, not food calories. This is the email I sent to the authors. ----------- As a two-decade user of Python, I was interested to read your paper. Unfortunately, it is deeply flawed with respect to Python in the sense that your conclusions are inapplicable to real-world usage of Python. The problem is your use of the Computer Language Benchmark Game. As the name says, it is a *game*. As a game, it has artificial rules dictated by the game masters. It uses toy problems, and for Python, the rules dictate unrealistic toy solutions. In particular, it appears to disallow use of 'import' with 3rd-party modules, whereas real-world Python is expected to use them, and nearly always does. The particular crippler for CLBG problems is the non-use of numpy in numerical calculations, such as the n-body problem. Numerical python extensions are over two decades old and give Python code access to optimized, compiled BLAS, LinPack, FFTPack, and so on. The current one, numpy, is the third of the series. It is both a historical accident and a continuing administrative convenience that numpy is not part of the Python stdlib. However, it is easily installed from the PSF-maintained repository (python -m pip install numpy), and is included with most third-party distributions of Python. The numerical extensions have been quasi-official in the sense that at least 3 language enhancements have been make for their use. Nearly all real-world scientific, financial, and neural-network Python programs are build on top of numpy. When a Python program spend 95% of the time in the optimized compiled C routines, it is nearly as fast as a 100% C solution. The reason people use Python instead of C for the other 5% is to save human time. Even when it come to executing the pure Python solutions, the CLBG rules apparently require the slowest execution possible. Execution would be at least 2 to 5 times faster if compilation to machine code were allowed, either before or during execution. But the point of the game is to provide a 'level' playing field for competition between Python programmers, even if the cost is to cripple comparison with other language solution. Terry Jan Reedy -- Terry Jan Reedy From rosuav at gmail.com Sun Sep 17 02:04:32 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Sep 2017 16:04:32 +1000 Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" In-Reply-To: References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> Message-ID: On Sun, Sep 17, 2017 at 4:00 PM, Terry Reedy wrote: > The numerical extensions have been quasi-official in the sense that at least > 3 language enhancements have been make for their use. I know about the matrix multiplication operator. What are the other two (or more)? ChrisA From tjreedy at udel.edu Sun Sep 17 02:16:42 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 17 Sep 2017 02:16:42 -0400 Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" In-Reply-To: References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> Message-ID: On 9/17/2017 2:04 AM, Chris Angelico wrote: > On Sun, Sep 17, 2017 at 4:00 PM, Terry Reedy wrote: >> The numerical extensions have been quasi-official in the sense that at least >> 3 language enhancements have been make for their use. > > I know about the matrix multiplication operator. What are the other > two (or more)? Stride slicing, which later became valid in regular code, and Ellipsis. (I could be wrong on the latter.) -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Sun Sep 17 02:19:59 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 17 Sep 2017 18:19:59 +1200 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> Message-ID: Chris Angelico wrote: > Or machine code on every CPU I've ever worked with. Dividing integers > yields an integer. Every machine language I've used has different sets of instructions for int and float arithmetic, so there's no chance of confusion. -- Greg From greg.ewing at canterbury.ac.nz Sun Sep 17 02:27:37 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sun, 17 Sep 2017 18:27:37 +1200 Subject: Old Man Yells At Cloud In-Reply-To: <87r2v6ge76.fsf@nightsong.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> Message-ID: Paul Rubin wrote: > Python 2 does something reasonable I don't agree. It might be reasonable in a statically-typed language, but in a dynamically-typed language where you're encouraged to use ints as stand-ins for integer-valued floats, it's an invitation for trouble. There are good reasons it was changed in Python 3. -- Greg From none at invalid.com Sun Sep 17 02:56:39 2017 From: none at invalid.com (mm0fmf) Date: Sun, 17 Sep 2017 07:56:39 +0100 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: On 16/09/2017 17:52, Dennis Lee Bieber wrote: > On Sat, 16 Sep 2017 09:59:43 -0500, Tim Daneliuk > declaimed the following: > > > >> Well, the whole integer floor division thing years ago was the beginning >> of the end - Python was doomed ... > > Yes -- that would give me fits if I were using Python3 currently... > Since so many of the languages I've learned over the past years use the > concept integer / integer => integer_result > > Come to think of it -- wasn't there a post from someone (seems to > expired or been filtered from my client) asking for help with some sorting > program... I'm pretty sure the partitioning logic would croak on Python3 > due to floating point results in the slice indices: > > pA = part[:n/2] > pB = part[n/2:] > What does 2to3 do when fed code involving division? I've only used it once and did good job on the code I fed it. But it would not have been too hard to manually convert the Python2 code in that case. From steve+python at pearwood.info Sun Sep 17 03:54:24 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 17 Sep 2017 17:54:24 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> Message-ID: <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> On Sun, 17 Sep 2017 02:07 pm, Paul Rubin wrote: > Steve D'Aprano writes: >>> concept integer / integer => integer_result >> That would be C, and C derived languages, perhaps? > > Certainly not. Fortran, machine languages, etc. all do that too. > > Haskell does the right thing and makes int/int a compile time type > error. Its not the right thing. Pascal did the right thing: int/int returns a floating point value. Python does the right thing. Pocket calculators do the right thing. Haskell is great in many ways, but it is also obnoxiously pedantic about type safety. At the point that the compiler won't even automatically coerce ints to floats, but requires you to sign a release form that you take all responsibility for it, er I mean manually do the coercion yourself, that's excessive. There's no reason why they couldn't have allowed int/int to return a float of some sort, or a fraction if they want to be exact. In my arrogant opinion, its just obnoxious, pretentious purity-beyond-all-sense to make "int / int" an error. Its not like division on integers is undefined, its just not closed, but lots of operations in Haskell aren't closed. The Haskell equivalent of len(some_string) does not return a string. To even *know* that there are branches of maths where int/int isn't defined, you need to have learned aspects of mathematics that aren't even taught in most undergrad maths degrees. (I have a degree in maths, and if we ever covered areas where int/int was undefined, it was only briefly, and I've long since forgotten it.) There's a perfectly good, almost intuitive, understanding of int/int giving some sort of rational value. Why don't they use it? They go so far as to provide two pairs of division/remainder functions, differing only in their treatment of negative values: (x ?quot? y)?y + (x ?rem? y) == x (x ?div? y)?y + (x ?mod? y) == x but can't provide an operator to do ordinary rational-valued division. > Its integer division functions are div and quot. quot is "integer division truncated toward zero", div is "integer division truncated toward negative infinity". > Python 2 does something reasonable Except that it isn't. It's surprising, and error prone, and was changed because it was a bug magnet. > and Python 3 does something that is > also debatably reasonable. Switching from one reasonable thing to > another without a very good reason is called fixing things that weren't > broken. Python 2 wasn't broken in that area and didn't need to be > fixed. Python 2 was badly broken in this area. The / operator doing integer division on integers and true division on everything else was a constant source of pain and silent errors. You would write a perfectly reasonable maths expression: y = math.sin((2*x - 1)/(3*x + 1)) and test it with floats and it would work perfectly, then some day someone slips an integer into x and you silently get garbage output, which you would probably never even realise. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Sep 17 04:14:37 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 17 Sep 2017 18:14:37 +1000 Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> Message-ID: <59be2eef$0$16750$b1db1813$d948b532@news.astraweb.com> On Sun, 17 Sep 2017 04:16 pm, Terry Reedy wrote: > On 9/17/2017 2:04 AM, Chris Angelico wrote: >> On Sun, Sep 17, 2017 at 4:00 PM, Terry Reedy wrote: >>> The numerical extensions have been quasi-official in the sense that at least >>> 3 language enhancements have been make for their use. >> >> I know about the matrix multiplication operator. What are the other >> two (or more)? > > Stride slicing, which later became valid in regular code, and Ellipsis. > (I could be wrong on the latter.) Nope, both are correct. Slice strides were first supported in Python 1.4, but used exclusively by Numerical Python (numpy's ancient predecessor), and didn't finally get supported by Python builtins until as late as version 2.3! https://docs.python.org/2.3/whatsnew/section-slices.html Ellipsis was used for multi-dimensional slicing, and was added for Numerical Python. It wasn't until recently (Python 3.4 perhaps?) that it finally became legal to write '...' instead of 'Ellipsis' outside of slice notation. Here's Peter Otten talking about it way back in 2004: http://grokbase.com/t/python/python-list/042jd5y60n/ellipsis-usage -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From amirouche.boubekki at gmail.com Sun Sep 17 04:21:21 2017 From: amirouche.boubekki at gmail.com (Amirouche Boubekki) Date: Sun, 17 Sep 2017 01:21:21 -0700 Subject: Which database system? In-Reply-To: References: Message-ID: Le 15 sept. 2017 20:05, "Stefan Ram" a ?crit : When one is building an in-memory database that has a single table that is built at the start of the program and then one writes some complex queries to the table, what can be expected to be faster: - implementing the table as a builtins.list of builtins.tuples with builtins.dicts as indexes for faster lookups and additional sorted builtins.lists for sorted "views" on the table - implementing the table as a database table in sqlite3 (":memory:") and using SQL commands for insertion There is other solutions like shelve mentioned previously or plyvel (easy api) or my preferred wiredtiger. But the issue with maintenance costs is still valid. Choose the later if nothing else works. From alain at universite-de-strasbourg.fr.invalid Sun Sep 17 04:37:24 2017 From: alain at universite-de-strasbourg.fr.invalid (Alain Ketterlin) Date: Sun, 17 Sep 2017 10:37:24 +0200 Subject: Typo-squatting PyPi Message-ID: <877ewxpvp7.fsf@universite-de-strasbourg.fr.invalid> In case you haven't heard about this: https://developers.slashdot.org/story/17/09/16/2030229/pythons-official-repository-included-10-malicious-typo-squatting-modules Here is the Slashdot summary: | The Slovak National Security Office (NBU) has identified ten malicious | Python libraries uploaded on PyPI -- Python Package Index -- the | official third-party software repository for the Python programming | language. NBU experts say attackers used a technique known as | typosquatting to upload Python libraries with names similar to | legitimate packages -- e.g.: "urlib" instead of "urllib." The PyPI | repository does not perform any types of security checks or audits | when developers upload new libraries to its index, so attackers had no | difficulty in uploading the modules online. | | Developers who mistyped the package name loaded the malicious | libraries in their software's setup scripts. "These packages contain | the exact same code as their upstream package thus their functionality | is the same, but the installation script, setup.py, is modified to | include a malicious (but relatively benign) code," NBU explained. | Experts say the malicious code only collected information on infected | hosts, such as name and version of the fake package, the username of | the user who installed the package, and the user's computer hostname. | Collected data, which looked like "Y:urllib-1.21.1 admin testmachine", | was uploaded to a Chinese IP address. NBU officials contacted PyPI | administrators last week who removed the packages before officials | published a security advisory on Saturday." -- Alain. From arj.python at gmail.com Sun Sep 17 06:02:47 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 17 Sep 2017 14:02:47 +0400 Subject: Old Man Yells At Cloud In-Reply-To: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: as someone who really dislike js, i have to admit : python's globals are really really bad ! js is a charm at that a real charm ! Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 16 Sep 2017 09:40, "Steve D'Aprano" wrote: > /rant on > > So apparently everyone who disagrees that Python should be more like > Javascript > is an old greybeard fuddy-duddy yelling "Get off my lawn!" to the cool > kids -- > and is also too stupid to know how dumb they are. > > "Hi, I've been programming in Python for what seems like days now, and > here's > all the things that you guys are doing wrong. I insist that you fix them > immediately, it doesn't matter how much code it will break, that's not > important. What is important is that Javascript programmers like me > shouldn't > be expected to learn anything new or different when they program with > Python." > > /rant off > > And no, for once it wasn't Ranting Rick. > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list > From leamhall at gmail.com Sun Sep 17 06:03:16 2017 From: leamhall at gmail.com (Leam Hall) Date: Sun, 17 Sep 2017 06:03:16 -0400 Subject: Old Man Yells At Cloud In-Reply-To: <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> Message-ID: <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> Different view, I guess. I'm glad all the young Javascripters have that issue. As an old guy trying to re-learn more python it gives me an advantage. I'm usually interested in the best thislanguage-native way to do something. Doing so makes me learn the language faster and tends to generate better code. That said, I'll often steal what I've learned before to understand the new. Some helpful folks on IRC asked why I was using getopt instead of argparse. Mostly because I come from a bash background. Looking at Python's argparse would have stumped me if I hadn't already done the same thing with Ruby's argparse. I'm still trying to figure out how to convert a string to unicode in Python 2. I've done it in Ruby 1.8.7 so I assume Python 2 can do it and that I'm just a bit slow. Leam From pizzapython at gmx.com Sun Sep 17 06:11:44 2017 From: pizzapython at gmx.com (pizza python) Date: Sun, 17 Sep 2017 12:11:44 +0200 Subject: speech_to_text python command not working Message-ID: Hello all. I'm on Linux Mint 18.2 Cinnamon 64-bit. I am trying to get IBM Watson BlueMix Speech-To-Text to transcribe my spoken-word audio files. Because I'm not a coder, I tried to find the simplest way to use BlueMix Speech-to-Text. And what I found is [1]https://github.com/rmotr/speech-to-text It's in PyPi Libary: https://pypi.python.org/pypi/speech-to-text/0.0.1 Step 1: "pip install speech-to-text". I ran it with sudo to make it work. Step 2: I then ran: speech_to_text -u myUserNameGoesHere -p myPasswordGoesHere -f html -i voice2.ogg transcript.html Starting Upload. [=========================================================================] 100% Upload finished. Waiting for Transcript Traceback (most recent call last): File "/usr/local/bin/speech_to_text", line 11, in sys.exit(speech_to_text()) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__ return self.main(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/speech_to_text/command.py", line 60, in speech_to_text formatted_output = FormatterClass().format(result) File "/usr/local/lib/python2.7/dist-packages/speech_to_text/formatters.py", line 36, in format for obj in self._parse(data)) File "/usr/local/lib/python2.7/dist-packages/speech_to_text/formatters.py", line 10, in _parse for obj in data[`results']) KeyError: `results' __________ I was expecting an html with the transcript. So why did I get the errors above? python Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 __________________________________ dpkg -l python Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-==============-============-============-================================= ii python 2.7.11-1 amd64 interactive high-level object-ori ____________________________________ python3 Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux ____________________________________ dpkg -l python3 Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad) ||/ Name Version Architecture Description +++-==============-============-============-================================= ii python3 3.5.1-3 amd64 interactive high-level object-ori References Visible links 1. https://github.com/rmotr/speech-to-text From leamhall at gmail.com Sun Sep 17 06:22:34 2017 From: leamhall at gmail.com (Leam Hall) Date: Sun, 17 Sep 2017 06:22:34 -0400 Subject: Old Man Yells At Cloud In-Reply-To: <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> Message-ID: <5145c928-956f-dc67-8a5b-0e10975a4304@gmail.com> Hmm... scratch the "young" and "Javascripters". Why lump them together since I bet it's just a vocal few? Better to have said "people who don't want to really learn the new language". On 09/17/2017 06:03 AM, Leam Hall wrote: > Different view, I guess. I'm glad all the young Javascripters have that > issue. As an old guy trying to re-learn more python it gives me an > advantage. I'm usually interested in the best thislanguage-native way to > do something. Doing so makes me learn the language faster and tends to > generate better code. > > That said, I'll often steal what I've learned before to understand the > new. Some helpful folks on IRC asked why I was using getopt instead of > argparse. Mostly because I come from a bash background. Looking at > Python's argparse would have stumped me if I hadn't already done the > same thing with Ruby's argparse. > > I'm still trying to figure out how to convert a string to unicode in > Python 2. I've done it in Ruby 1.8.7 so I assume Python 2 can do it and > that I'm just a bit slow. > > Leam From rosuav at gmail.com Sun Sep 17 06:43:02 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Sep 2017 20:43:02 +1000 Subject: Old Man Yells At Cloud In-Reply-To: <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sun, Sep 17, 2017 at 5:54 PM, Steve D'Aprano wrote: > To even *know* that there are branches of maths where int/int isn't defined, you > need to have learned aspects of mathematics that aren't even taught in most > undergrad maths degrees. (I have a degree in maths, and if we ever covered > areas where int/int was undefined, it was only briefly, and I've long since > forgotten it.) How about this: >>> (1<<10000)/2 Traceback (most recent call last): File "", line 1, in OverflowError: integer division result too large for a float int/int is now undefined. In Py2, it perfectly correctly returns another integer (technically a long), but in Py3, it can't return a float, so it errors out. This is nothing to do with the mathematical notion of a "real", which is a superset of the mathematical notion of an "integer"; it's all to do with the Python notion of a "float", which is NOT a superset of the Python notion of an "integer". In Python 2, an ASCII string could be implicitly promoted to a Unicode string: >>> user_input = u"Real Soon Now?" >>> print("> " + user_input + " <") > Real Soon Now? < In Python 2 and 3, a small integer can be implicitly promoted to float: >>> user_input = 3.14159 >>> print(user_input + 1) 4.14159 Both conversions can cause data-dependent failures when used with arbitrary input, but are unlikely to cause problems when you're promoting literals. Both conversions require proximity to the other type. As long as you're explicit about the data type used for user input, you can short-hand your literals and get away with it: >>> # more likely, input came as text >>> user_input = float("1.234") >>> print(user_input + 1) 2.234 >>> # and hey, it works with other types too! >>> user_input = decimal.Decimal("1.234") >>> print(user_input + 1) 2.234 >>> user_input = fractions.Fraction("1.234") >>> print(user_input + 1) 1117/500 The trouble only comes when you take two pieces of user input in different types, and try to combine them: >>> user_1 = float("1.234") >>> user_2 = int("9"*999) # imagine someone typed it >>> user_1 + user_2 Traceback (most recent call last): File "", line 1, in OverflowError: int too large to convert to float Solution? Always use the right data types for user input. Easy enough. Python 3 introduces a completely different way to get failure, though. You can be 100% consistent with your data types, but then get data-dependent failures if, and only if, you divide. (Technically, not completely new in Py3; you can get this in Py2 with exponentiation - "2**-1" will yield a float. Far less likely to be hit, but could potentially cause the same problems.) I don't know of any exploits that involve this, but I can imagine that you could attack a Python script by forcing it to go floating-point, then either crashing it with a huge integer, or exploiting round-off, depending on whether the program is assuming floats or assuming ints. Python 3 *removed* one of these data-dependent distinctions, by making bytes+text into an error: >>> b"asdf" + u"qwer" u'asdfqwer' >>> b"asdf" + u"qwer" Traceback (most recent call last): File "", line 1, in TypeError: can't concat str to bytes But it added a different one, by allowing a common and normal operation to change a data type. Is it better to make things convenient for the case of small integers (the ones that are perfectly representable as floats), while potentially able to have problems on larger ones? Considering how large a "small integer" can be, most programmers won't think to test for overflow - just as many programmers won't test non-ASCII data. Thanks to Python 3, the "non-ASCII data" one isn't a problem, because you'll get the same exception with ASCII data as with any other; but the "small integer" one now is. Data-dependent type errors don't seem like a smart thing to me. ChrisA From steve+python at pearwood.info Sun Sep 17 06:54:51 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 17 Sep 2017 20:54:51 +1000 Subject: Python built-ins versus Javascript [was Re: Old Man Yells At Cloud] References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: <59be547c$0$16751$b1db1813$d948b532@news.astraweb.com> On Sun, 17 Sep 2017 08:02 pm, Abdur-Rahmaan Janhangeer wrote: > as someone who really dislike js, i have to admit : python's globals are > really really bad ! > > js is a charm at that a real charm ! Can you explain what you think is so bad about them, and why Javascript's are better? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Sep 17 07:25:21 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 17 Sep 2017 21:25:21 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> Message-ID: <59be5ba4$0$16728$b1db1813$d948b532@news.astraweb.com> On Sun, 17 Sep 2017 08:03 pm, Leam Hall wrote: > I'm still trying to figure out how to convert a string to unicode in > Python 2. A Python 2 string is a string of bytes, so you need to know what encoding they are in. Let's assume you got them from a source using UTF-8. Then you would do: mystring.decode('utf-8') and it will return a Unicode string of "code points" (think: more or less characters). -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From leamhall at gmail.com Sun Sep 17 07:38:35 2017 From: leamhall at gmail.com (Leam Hall) Date: Sun, 17 Sep 2017 07:38:35 -0400 Subject: Unicode (was: Old Man Yells At Cloud) In-Reply-To: <59be5ba4$0$16728$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> <59be5ba4$0$16728$b1db1813$d948b532@news.astraweb.com> Message-ID: <70394aee-5dc1-04c7-b5eb-73b2d71feefe@gmail.com> On 09/17/2017 07:25 AM, Steve D'Aprano wrote: > On Sun, 17 Sep 2017 08:03 pm, Leam Hall wrote: > >> I'm still trying to figure out how to convert a string to unicode in >> Python 2. > > > A Python 2 string is a string of bytes, so you need to know what encoding they > are in. Let's assume you got them from a source using UTF-8. Then you would do: > > mystring.decode('utf-8') > > and it will return a Unicode string of "code points" (think: more or less > characters). Still trying to keep this Py2 and Py3 compatible. The Py2 error is: UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 8: ordinal not in range(128) even when the string is manually converted: name = unicode(self.name) Same sort of issue with: name = self.name.decode('utf-8') Py3 doesn't like either version. From p.f.moore at gmail.com Sun Sep 17 07:51:21 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 17 Sep 2017 12:51:21 +0100 Subject: Unicode (was: Old Man Yells At Cloud) In-Reply-To: <70394aee-5dc1-04c7-b5eb-73b2d71feefe@gmail.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> <59be5ba4$0$16728$b1db1813$d948b532@news.astraweb.com> <70394aee-5dc1-04c7-b5eb-73b2d71feefe@gmail.com> Message-ID: On 17 September 2017 at 12:38, Leam Hall wrote: > On 09/17/2017 07:25 AM, Steve D'Aprano wrote: >> >> On Sun, 17 Sep 2017 08:03 pm, Leam Hall wrote: >> >>> I'm still trying to figure out how to convert a string to unicode in >>> Python 2. >> >> >> >> A Python 2 string is a string of bytes, so you need to know what encoding >> they >> are in. Let's assume you got them from a source using UTF-8. Then you >> would do: >> >> mystring.decode('utf-8') >> >> and it will return a Unicode string of "code points" (think: more or less >> characters). > > > > Still trying to keep this Py2 and Py3 compatible. > > The Py2 error is: > UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' > in position 8: ordinal not in range(128) > > even when the string is manually converted: > name = unicode(self.name) > > Same sort of issue with: > name = self.name.decode('utf-8') > > > Py3 doesn't like either version. Your string is likely not UTF-8 with a character \xf6 in it. Maybe it's latin-1? The key here is there's no way for Python (or any program) to know the encoding of the byte string, so you have to tell it. Paul From rosuav at gmail.com Sun Sep 17 08:30:26 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Sep 2017 22:30:26 +1000 Subject: Unicode (was: Old Man Yells At Cloud) In-Reply-To: <70394aee-5dc1-04c7-b5eb-73b2d71feefe@gmail.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> <59be5ba4$0$16728$b1db1813$d948b532@news.astraweb.com> <70394aee-5dc1-04c7-b5eb-73b2d71feefe@gmail.com> Message-ID: On Sun, Sep 17, 2017 at 9:38 PM, Leam Hall wrote: > Still trying to keep this Py2 and Py3 compatible. > > The Py2 error is: > UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' > in position 8: ordinal not in range(128) > > even when the string is manually converted: > name = unicode(self.name) > > Same sort of issue with: > name = self.name.decode('utf-8') > > > Py3 doesn't like either version. You got a Unicode *EN*code error when you tried to *DE* code. That's a quirk of Py2's coercion behaviours, so the error's a bit obscure, but it means that you (most likely) actually have a Unicode string already. Check what type(self.name) is, and see if the problem is actually somewhere else. (It's hard to give more specific advice based on this tiny snippet, sorry.) ChrisA From leamhall at gmail.com Sun Sep 17 08:44:24 2017 From: leamhall at gmail.com (Leam Hall) Date: Sun, 17 Sep 2017 08:44:24 -0400 Subject: Unicode In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> <59be5ba4$0$16728$b1db1813$d948b532@news.astraweb.com> <70394aee-5dc1-04c7-b5eb-73b2d71feefe@gmail.com> Message-ID: <4dcbc060-8fe5-fe4a-b42e-7e3a24ac5e72@gmail.com> On 09/17/2017 08:30 AM, Chris Angelico wrote: > On Sun, Sep 17, 2017 at 9:38 PM, Leam Hall wrote: >> Still trying to keep this Py2 and Py3 compatible. >> >> The Py2 error is: >> UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' >> in position 8: ordinal not in range(128) >> >> even when the string is manually converted: >> name = unicode(self.name) >> >> Same sort of issue with: >> name = self.name.decode('utf-8') >> >> >> Py3 doesn't like either version. > > You got a Unicode *EN*code error when you tried to *DE* code. That's a > quirk of Py2's coercion behaviours, so the error's a bit obscure, but > it means that you (most likely) actually have a Unicode string > already. Check what type(self.name) is, and see if the problem is > actually somewhere else. > > (It's hard to give more specific advice based on this tiny snippet, sorry.) > > ChrisA > Chris, thanks! I see what you mean. The string source is a SQLite3 database with a bunch of names. Some have non-ASCII characters. The database is using varchar which seems to be utf-8, utf-16be or utf-16le. I probably need to purge the data. What I find interesting is that utf-8 works in the Ruby script that pulls from the same database. That's what makes me think it's utf-8. I've tried different things in lines 45 and 61. https://gist.github.com/LeamHall/054f9915af17dc1b1a33597b9b45d2da Leam From steve+python at pearwood.info Sun Sep 17 09:03:36 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 17 Sep 2017 23:03:36 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> Message-ID: <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> On Sun, 17 Sep 2017 08:43 pm, Chris Angelico wrote: > On Sun, Sep 17, 2017 at 5:54 PM, Steve D'Aprano > wrote: >> To even *know* that there are branches of maths where int/int isn't defined, >> you need to have learned aspects of mathematics that aren't even taught in >> most undergrad maths degrees. (I have a degree in maths, and if we ever >> covered areas where int/int was undefined, it was only briefly, and I've long >> since forgotten it.) > > How about this: > >>>> (1<<10000)/2 > Traceback (most recent call last): > File "", line 1, in > OverflowError: integer division result too large for a float > > int/int is now undefined. No, it's perfectly defined: you get an overflow error if the arguments are too big to convert, or an underflow error if the denominator is too small, or a divide by zero error if you divide by zero... What do you make of this? py> float(1<<10000)/2.0 Traceback (most recent call last): File "", line 1, in OverflowError: int too large to convert to float Would you like to argue that this shows that coercing ints to floats is "undefined"? Overflow and underflow errors are limitations of the float data type. We could fix that in a couple of ways: - silently underflow to zero (as Python already does!) or infinity, as needed; - use a bigger ~~boat~~ float; - or even an arbitrary precision float; - or return a rational number (fraction or similar); - or introduce a float context that allows you to specify the behaviour that you want, as the decimal module does. There may be other solutions I haven't thought of. But these will do. The distinction between Python floats and real numbers ? is a red-herring. It isn't relevant. > In Py2, it perfectly correctly returns > another integer (technically a long), but in Py3, it can't return a > float, so it errors out. Apart from your "correctly", which I disagree with, that's a reasonable description. The problem is that your example returns the correct result by accident. Forget such ludicrously large values, and try something more common: 1/2 Most people aren't expecting integer division, but true division, and silently returning the wrong result (0 instead of 0.5) is a silent source of bugs. This isn't some theoretical problem that might, maybe, perhaps, be an issue for some people sometimes. It was a regular source of actual bugs leading to code silently returning garbage. > This is nothing to do with the mathematical > notion of a "real", I don't believe I ever mentioned Reals. I was pretty careful not to. > which is a superset of the mathematical notion of > an "integer"; it's all to do with the Python notion of a "float", > which is NOT a superset of the Python notion of an "integer". So? Operations don't *have* to return values from their operands' type. len('abc') doesn't return a string. alist.find(1) doesn't have to return either a list or an int. And 1/2 doesn't have to return an int. Why is this such a big deal? > In Python 2, an ASCII string could be implicitly promoted to a Unicode string: > >>>> user_input = u"Real Soon Now?" >>>> print("> " + user_input + " <") >> Real Soon Now? < And that was a bug magnet, like using / for integer division sometimes and true division other times was a big magnet. So Python 3 got rid of both bad design decisions. > In Python 2 and 3, a small integer can be implicitly promoted to float: > >>>> user_input = 3.14159 >>>> print(user_input + 1) > 4.14159 Yes, as it should. Why force the user to call float() on one argument when the interpreter can do it? What advantage is there? Can you demonstrate any failure of dividing two ints n/m which wouldn't equally fail if you called float(n)/float(m)? I don't believe that there is any such failure mode. Forcing the user to manually coerce to floats doesn't add any protection. > Both conversions can cause data-dependent failures when used with > arbitrary input, There's a difference: - with automatic promotion of bytes to Unicode, you get errors that pass silently and garbage results; - with automatic promotion of bytes to Unicode, you get errors that pass silently and garbage results; - but with true division, if int/int cannot be performed using floats, you get an explicit error. Silently returning the wrong result was a very common consequence of the int/int behaviour in Python 2. Is there any evidence of common, real-world bugs caused by true division? Beginners who make assumptions that Python is C (or any other language) and use / when they should use // don't count: that's no different from somebody using ^ for exponentiation. [...] > The trouble only comes when you take two pieces of user input in > different types, and try to combine them: > >>>> user_1 = float("1.234") >>>> user_2 = int("9"*999) # imagine someone typed it >>>> user_1 + user_2 > Traceback (most recent call last): > File "", line 1, in > OverflowError: int too large to convert to float I'm sorry, I fail to see why you think this is "trouble". It's just normal Python behaviour in the face of errors: raise an exception. If you pass a bad value, you get an exception of some kind. Are these "trouble" too? py> ''[5] Traceback (most recent call last): File "", line 1, in IndexError: string index out of range py> int('xyz') Traceback (most recent call last): File "", line 1, in ValueError: invalid literal for int() with base 10: 'xyz' Getting an explicit exception on error is the right thing to do. Silently returning garbage is not. If you want to argue that int/int should return infinity, or a NAN, on overflow, that's possibly defensible. But arguing that somehow the division operator is uniquely or specifically "trouble" because it raises an exception when given bad data, well, that's just weird. > Python 3 introduces a completely different way to get failure, though. > You can be 100% consistent with your data types, but then get > data-dependent failures if, and only if, you divide. Its true that most operations on integers will succeed. But not all. Try (1<<10000)**(1<<10000) if you really think that integer ops are guaranteed to succeed. (I'm scared to try it myself, because I've had bad experiences in the past with unreasonably large ints.) But then, what of it? All that means is that division can fail. But even integer division can fail: py> 1//0 Traceback (most recent call last): File "", line 1, in ZeroDivisionError: integer division or modulo by zero [...] > I don't know of any exploits > that involve this, but I can imagine that you could attack a Python > script by forcing it to go floating-point, then either crashing it > with a huge integer, or exploiting round-off, depending on whether the > program is assuming floats or assuming ints. You're not seriously arguing that true division is a security vulnerability? In any case, the error here is an exception, not silent failures. "I find it amusing when novice programmers believe their main job is preventing programs from crashing. ... More experienced programmers realize that correct code is great, code that crashes could use improvement, but incorrect code that doesn?t crash is a horrible nightmare." -- Chris Smith Using / for integer division, if and only if both arguments are integers, was exactly that horrible nightmare. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From __peter__ at web.de Sun Sep 17 09:13:09 2017 From: __peter__ at web.de (Peter Otten) Date: Sun, 17 Sep 2017 15:13:09 +0200 Subject: Unicode References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> <59be5ba4$0$16728$b1db1813$d948b532@news.astraweb.com> <70394aee-5dc1-04c7-b5eb-73b2d71feefe@gmail.com> <4dcbc060-8fe5-fe4a-b42e-7e3a24ac5e72@gmail.com> Message-ID: Leam Hall wrote: > On 09/17/2017 08:30 AM, Chris Angelico wrote: >> On Sun, Sep 17, 2017 at 9:38 PM, Leam Hall wrote: >>> Still trying to keep this Py2 and Py3 compatible. >>> >>> The Py2 error is: >>> UnicodeEncodeError: 'ascii' codec can't encode character >>> u'\xf6' in position 8: ordinal not in range(128) >>> >>> even when the string is manually converted: >>> name = unicode(self.name) >>> >>> Same sort of issue with: >>> name = self.name.decode('utf-8') >>> >>> >>> Py3 doesn't like either version. >> >> You got a Unicode *EN*code error when you tried to *DE* code. That's a >> quirk of Py2's coercion behaviours, so the error's a bit obscure, but >> it means that you (most likely) actually have a Unicode string >> already. Check what type(self.name) is, and see if the problem is >> actually somewhere else. >> >> (It's hard to give more specific advice based on this tiny snippet, >> sorry.) >> >> ChrisA >> > > Chris, thanks! I see what you mean. I don't think so. You get a unicode from the database, $ python Python 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> db = sqlite3.connect(":memory:") >>> cs = db.cursor() >>> cs.execute("select 'foo';").fetchone() (u'foo',) >>> and when you try to decode it (which is superfluous as you already have unicode!) Python does what you ask for. But to be able to decode it has to encode first and by default it uses the ascii codec for that attempt. For an all-ascii string u"foo".encode("ascii") --> "foo" and thus u"foo".decode("utf-8) implemented as u"foo".encode("ascii").decode("utf-8") --> u"foo" is basically a noop. However u"???".encode("ascii") --> raises UnicodeENCODEError and thus u"???".decode("utf-8") fails with that. Unfortunately nobody realizes that the encoding failed and thus will unsuccessfully try and specify other encodings for the decoding step u"???".decode("latin1") # also fails Solution: if you already have unicode, leave it alone. > The string source is a SQLite3 database with a bunch of names. Some have > non-ASCII characters. The database is using varchar which seems to be > utf-8, utf-16be or utf-16le. I probably need to purge the data. > > What I find interesting is that utf-8 works in the Ruby script that > pulls from the same database. That's what makes me think it's utf-8. > > I've tried different things in lines 45 and 61. > > https://gist.github.com/LeamHall/054f9915af17dc1b1a33597b9b45d2da > > Leam From bc at freeuk.com Sun Sep 17 09:16:39 2017 From: bc at freeuk.com (bartc) Date: Sun, 17 Sep 2017 14:16:39 +0100 Subject: Old Man Yells At Cloud In-Reply-To: <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> Message-ID: On 17/09/2017 02:09, Steve D'Aprano wrote: > On Sun, 17 Sep 2017 04:00 am, Stefan Ram wrote: > >> Steve D'Aprano writes: >>> "Hi, I've been programming in Python for what seems like days now, and here's >>> all the things that you guys are doing wrong. >> >> I never ever have written a line of Python 2. I started with >> Python 3.6.0. Yet a very frequent mistake of mine is the >> imission of parentheses after ?print?. > > That's remarkable. > > Do you also forget the parentheses around `len`, and `iter`, and `math.sin()`? > If not, what's so special about print? It was thought of as a statement or command, not a function where you you give it one value and it returns another. print() is used for its side-effects; what relevant value does it return? print can also be used for debugging, when it might be written, deleted and added again hundreds of times. So writing all those brackets becomes irksome. 'print' needs to be easy to write. > Javascript (at least the Rhino interpreter, if not others) includes a print > function. It too requires parentheses: > > js> print 21 > js: "", line 5: missing ; before statement > js: print 21 > js: .......^ > js> print(21) Javascript I believe uses C-like syntax. C syntax is also fond of unnecessary punctuation, and its 'printf' requires a format string full of format codes. Even more of a nuisance. -- bartc From breamoreboy at gmail.com Sun Sep 17 09:34:58 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sun, 17 Sep 2017 06:34:58 -0700 (PDT) Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> Message-ID: <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> On Sunday, September 17, 2017 at 2:16:48 PM UTC+1, bartc wrote: > > print can also be used for debugging, when it might be written, deleted > and added again hundreds of times. So writing all those brackets becomes > irksome. 'print' needs to be easy to write. > > -- > bartc Experienced Python programmers use the logging module for debugging, write once, delete (maybe) never. -- Kindest regards. Mark Lawrence. From larry.martell at gmail.com Sun Sep 17 09:41:29 2017 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 17 Sep 2017 09:41:29 -0400 Subject: Old Man Yells At Cloud In-Reply-To: <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> Message-ID: On Sun, Sep 17, 2017 at 9:34 AM, wrote: > Experienced Python programmers use the logging module for debugging, write once, delete (maybe) never. I use pdb for debugging (but I also log a lot which helps with prod system when users report a problem). From arj.python at gmail.com Sun Sep 17 09:45:33 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 17 Sep 2017 17:45:33 +0400 Subject: Python built-ins versus Javascript [was Re: Old Man Yells At Cloud] In-Reply-To: <59be547c$0$16751$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59be547c$0$16751$b1db1813$d948b532@news.astraweb.com> Message-ID: i use langages that uses py with so you have to wrap things in a function so that it will be called i'm tired telling beginners : hey don't forget to declare your globals don't forget don't forget .... and most of the time there are many ... well they just can't declare it in the func as they have to keep track js is good on this aspect. well you have to be careful but it is very nice. Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 17 Sep 2017 14:55, "Steve D'Aprano" wrote: > On Sun, 17 Sep 2017 08:02 pm, Abdur-Rahmaan Janhangeer wrote: > > > as someone who really dislike js, i have to admit : python's globals are > > really really bad ! > > > > js is a charm at that a real charm ! > > Can you explain what you think is so bad about them, and why Javascript's > are > better? > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list > From mail at timgolden.me.uk Sun Sep 17 09:51:12 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Sun, 17 Sep 2017 14:51:12 +0100 Subject: Old Man Yells At Cloud In-Reply-To: <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> Message-ID: On 17/09/2017 14:34, breamoreboy at gmail.com wrote: > On Sunday, September 17, 2017 at 2:16:48 PM UTC+1, bartc wrote: >> >> print can also be used for debugging, when it might be written, deleted >> and added again hundreds of times. So writing all those brackets becomes >> irksome. 'print' needs to be easy to write. >> >> -- >> bartc > > Experienced Python programmers use the logging module for debugging, write once, delete (maybe) never. FWIW I'm with Bart on this one. Print-as-a-function removed one small simplicity which I appreciated in Python as I first encountered it. And I'm entirely unconvinced that the benefit is worth it. That was my view when Python 3 was launched and several years of happily using Python 3 have not made a difference to my opinion on this particular point: I simply grin and bear it. Funnily enough, the two arguments most often advanced for print-as-function seem to me to cancel each other out. Argument 1 is "this way you can redefine print to be, eg, write_to_this_log"; and Argument 2 is "but no-one uses print in real code anyway" -- more or less what Mark offered just now. Well if no-one uses it in real code, then its ability to be redefined is moot. (Or, rather, the strength of that argument is diminished). In my own code I'm obviously quite capable of defining a function p() which does whatever I want in terms of printing etc. But where this bites me the most is in the interactive interpreter. Yes, I'm aware I can add things to site.py etc. etc. My point would still be that I'm working around a change which appears to be solving a problem I didn't have! TJG From arj.python at gmail.com Sun Sep 17 09:52:38 2017 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 17 Sep 2017 17:52:38 +0400 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> Message-ID: ah the only thing i miss in py2 very sad and it was a well heralded arg in favour of py print "i miss you simple print" Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 17 Sep 2017 17:50, "Tim Golden" wrote: > > > On 17/09/2017 14:34, breamoreboy at gmail.com wrote: > >> On Sunday, September 17, 2017 at 2:16:48 PM UTC+1, bartc wrote: >> >>> >>> print can also be used for debugging, when it might be written, deleted >>> and added again hundreds of times. So writing all those brackets becomes >>> irksome. 'print' needs to be easy to write. >>> >>> -- >>> bartc >>> >> >> Experienced Python programmers use the logging module for debugging, >> write once, delete (maybe) never. >> > > FWIW I'm with Bart on this one. Print-as-a-function removed one small > simplicity which I appreciated in Python as I first encountered it. And I'm > entirely unconvinced that the benefit is worth it. That was my view when > Python 3 was launched and several years of happily using Python 3 have not > made a difference to my opinion on this particular point: I simply grin and > bear it. > > Funnily enough, the two arguments most often advanced for > print-as-function seem to me to cancel each other out. Argument 1 is "this > way you can redefine print to be, eg, write_to_this_log"; and Argument 2 is > "but no-one uses print in real code anyway" -- more or less what Mark > offered just now. > > Well if no-one uses it in real code, then its ability to be redefined is > moot. (Or, rather, the strength of that argument is diminished). > > In my own code I'm obviously quite capable of defining a function p() > which does whatever I want in terms of printing etc. But where this bites > me the most is in the interactive interpreter. Yes, I'm aware I can add > things to site.py etc. etc. My point would still be that I'm working around > a change which appears to be solving a problem I didn't have! > > TJG > -- > https://mail.python.org/mailman/listinfo/python-list > From alister.ware at ntlworld.com Sun Sep 17 09:54:49 2017 From: alister.ware at ntlworld.com (alister) Date: Sun, 17 Sep 2017 13:54:49 GMT Subject: Test Bank for Governing Texas, 3rd Edition by Champagne Harpham References: <4a0b43e5-c374-435f-a73b-9fc017caf027@googlegroups.com> <8ae16aea-5049-4a24-b3b2-d29cdead41db@googlegroups.com> Message-ID: > > > I am interested in the testbank for this book. What is the price ? Don't encourage spammers -- California, n.: From Latin "calor", meaning "heat" (as in English "calorie" or Spanish "caliente"); and "fornia'" for "sexual intercourse" or "fornication." Hence: Tierra de California, "the land of hot sex." -- Ed Moran From songofacandy at gmail.com Sun Sep 17 10:18:55 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Sun, 17 Sep 2017 14:18:55 +0000 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> Message-ID: print >>sys.stderr, 'learn special syntax only for print?' print('you can use keword argument not only print', file=sys.stderr) p = functools.partial(print, file=sys.stderr) p('you can use other mechanizms for function') I never want to teach >> syntax for new people. On 2017?9?17?(?) 22:55 Abdur-Rahmaan Janhangeer wrote: > ah the only thing i miss in py2 very sad and it was a well heralded arg in > favour of py > > print "i miss you simple print" > > Abdur-Rahmaan Janhangeer, > Mauritius > abdurrahmaanjanhangeer.wordpress.com > > On 17 Sep 2017 17:50, "Tim Golden" wrote: > > > > > > > On 17/09/2017 14:34, breamoreboy at gmail.com wrote: > > > >> On Sunday, September 17, 2017 at 2:16:48 PM UTC+1, bartc wrote: > >> > >>> > >>> print can also be used for debugging, when it might be written, deleted > >>> and added again hundreds of times. So writing all those brackets > becomes > >>> irksome. 'print' needs to be easy to write. > >>> > >>> -- > >>> bartc > >>> > >> > >> Experienced Python programmers use the logging module for debugging, > >> write once, delete (maybe) never. > >> > > > > FWIW I'm with Bart on this one. Print-as-a-function removed one small > > simplicity which I appreciated in Python as I first encountered it. And > I'm > > entirely unconvinced that the benefit is worth it. That was my view when > > Python 3 was launched and several years of happily using Python 3 have > not > > made a difference to my opinion on this particular point: I simply grin > and > > bear it. > > > > Funnily enough, the two arguments most often advanced for > > print-as-function seem to me to cancel each other out. Argument 1 is > "this > > way you can redefine print to be, eg, write_to_this_log"; and Argument 2 > is > > "but no-one uses print in real code anyway" -- more or less what Mark > > offered just now. > > > > Well if no-one uses it in real code, then its ability to be redefined is > > moot. (Or, rather, the strength of that argument is diminished). > > > > In my own code I'm obviously quite capable of defining a function p() > > which does whatever I want in terms of printing etc. But where this bites > > me the most is in the interactive interpreter. Yes, I'm aware I can add > > things to site.py etc. etc. My point would still be that I'm working > around > > a change which appears to be solving a problem I didn't have! > > > > TJG > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Inada Naoki From steve+python at pearwood.info Sun Sep 17 10:42:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 18 Sep 2017 00:42:22 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> Message-ID: <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> On Sun, 17 Sep 2017 11:51 pm, Tim Golden wrote: > Print-as-a-function removed one small simplicity Presumably you've never wanted to print to something other than std.out. The syntax in Python 2 is horrid: print >>sys.stderr, args Presumably you've never wanted to print using a separator other than space. You simply can't do it at all in Python 2. Presumably you've never wanted to print and suppress the newline at the end of the line. The Python 2 syntax is obscure, error-prone, and easy to miss: print a, b, c, d, # WOT? Presumably you've never wanted to pass print to something as a function. It can't be done in Python 2: something.register(callback=print) # SyntaxError Presumably you've never wanted to control when the output buffer is flushed. That's another thing you can't do in Python 2. Presumably you've never wanted to monkey-patch an existing function that used print by shadowing the built-in. You can't do that in Python 2, since print isn't a regular name, it can't be mocked or shadowed or replaced. I've wanted to do all those things, and more. I love the new print function. For the cost of one extra character, the closing bracket, it gives you much, much more than the old print statement ever did. print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) No more cryptic and ugly syntax for printing to a file. Setting the argument separator is easy. Instead of an obscure and easy to miss trick to suppress the end of line, you use an obvious and self-explanatory keyword argument. The function is easy to extend in the future with extra keyword arguments. It is trivial to pass around, like any other function, and easy to mock or shadow. The print statement was only good for the most simple uses. The print function is a powerful, useful and first-class component of your programming toolbox. [...] > Funnily enough, the two arguments most often advanced for > print-as-function seem to me to cancel each other out. Arguments by whom? There's a whole raft of things wrong with print as a statement. Arguably, none of them *alone* are sufficient to condemn it, but overall, it makes the print statement substandard. > Argument 1 is > "this way you can redefine print to be, eg, write_to_this_log"; and > Argument 2 is "but no-one uses print in real code anyway" -- more or > less what Mark offered just now. That second one is neither an argument in favour of changing print, nor correct. People do use print in real code, but even if they didn't, that's not in and of itself a reason to change print. > Well if no-one uses it in real code, then its ability to be redefined is > moot. (Or, rather, the strength of that argument is diminished). > > In my own code I'm obviously quite capable of defining a function p() > which does whatever I want in terms of printing etc. Sure you can. But where the ability to mock print shines is when you're dealing with an already existing function that you cannot change and that already uses print. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From bc at freeuk.com Sun Sep 17 11:33:26 2017 From: bc at freeuk.com (bartc) Date: Sun, 17 Sep 2017 16:33:26 +0100 Subject: Old Man Yells At Cloud In-Reply-To: <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> Message-ID: <9BwvB.855148$284.816395@fx20.am4> On 17/09/2017 15:42, Steve D'Aprano wrote: > On Sun, 17 Sep 2017 11:51 pm, Tim Golden wrote: > >> Print-as-a-function removed one small simplicity > > Presumably you've never wanted to print to something other than std.out. Actually, no. (stderror is either a Unix-ism or C-ism, or some combination). The > syntax in Python 2 is horrid: > > print >>sys.stderr, args But I have wanted to print to a file. I wasn't aware of Py2 syntax for it, but that's not so different to what I normally use which is "@" in place of "<<". And the @, which used to be #, I think came from '#' in Basic or somewhere. I understand from your example below that in Py3, the file is specified somewhere in a list of keyword parameters. But since the print destination is quite important, it benefits from being stated up-front rather than buried somewhere near the end of all the main print operands. > Presumably you've never wanted to print using a separator other than space. You > simply can't do it at all in Python 2. > > Presumably you've never wanted to print and suppress the newline at the end of > the line. With the languages I normally use, newline isn't automatically written in the first place! (I'd write either print or println.) However controlling the separator between items has been and still is a nuisance (if not using a formatting string, but this is about being able to write quick, throwaway prints). Py3's 'sep' parameter is usable, mainly by requesting no separator and adding them manually as required. So if (a,b,c,d,e) have the values ("(",10,20,30,")") and you wanted output of '(10 20 30)' I guess you would write: print (a,b," ",c," ",d,e, sep="") (The scheme I currently use is to always add a space unless suppressed with ',,', so the same requirement is written as: println a,,b,c,d,,e But they're /both/ ugly!) > Presumably you've never wanted to pass print to something as a function. It > can't be done in Python 2: > > something.register(callback=print) # SyntaxError And again, no. It has happened, and this was not in Python, that I wanted to print to a string (appending to one), or to the current location in a window or image. Then, you need a clear way specifying such a destination. > Presumably you've never wanted to control when the output buffer is flushed. > That's another thing you can't do in Python 2. Once more, no. I suppose it would be necessary to call a separate function, which is handier in not cluttering up the main print. > Presumably you've never wanted to monkey-patch an existing function that used > print by shadowing the built-in. You can't do that in Python 2, since print > isn't a regular name, it can't be mocked or shadowed or replaced. Sorry, no. > I've wanted to do all those things, and more. I love the new print function. For > the cost of one extra character, the closing bracket, it gives you much, much > more than the old print statement ever did. > > print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) OK, in that case why not have both? Of course they would need to be given different names to make things easier. Then there wouldn't be any argument. > No more cryptic and ugly syntax for printing to a file. Setting the argument > separator is easy. Instead of an obscure and easy to miss trick to suppress the > end of line, you use an obvious and self-explanatory keyword argument. movedata(a, b, action='copy', depth='shallow') Self-explanatory keyword arguments, tick; as simple as just writing: a = b probably not! -- bartc From larry.martell at gmail.com Sun Sep 17 11:50:12 2017 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 17 Sep 2017 11:50:12 -0400 Subject: Old Man Yells At Cloud In-Reply-To: <285trclvbg6o72u96ftgl0e32nerb1jpiq@4ax.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <285trclvbg6o72u96ftgl0e32nerb1jpiq@4ax.com> Message-ID: On Sun, Sep 17, 2017 at 11:44 AM, Dennis Lee Bieber wrote: > The only pocket calculators I know of that have "integers" are those > with a "programmer's mode" -- ie; binary (displayed in > binary/octal/decimal/hex) but needing to be converted back to "normal" if > one wants to use them with non-binary values. See nearly any of the more > capable HP units. Binary division stays binary (integer). I have a HP-41C that I bought in 1976 for $300. It's sitting on my desk right next to my keyboard. Still use it today. It's awesome. From leamhall at gmail.com Sun Sep 17 12:20:08 2017 From: leamhall at gmail.com (leam hall) Date: Sun, 17 Sep 2017 12:20:08 -0400 Subject: Unicode In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> <59be5ba4$0$16728$b1db1813$d948b532@news.astraweb.com> <70394aee-5dc1-04c7-b5eb-73b2d71feefe@gmail.com> <4dcbc060-8fe5-fe4a-b42e-7e3a24ac5e72@gmail.com> Message-ID: On Sun, Sep 17, 2017 at 9:13 AM, Peter Otten <__peter__ at web.de> wrote: > Leam Hall wrote: > > > On 09/17/2017 08:30 AM, Chris Angelico wrote: > >> On Sun, Sep 17, 2017 at 9:38 PM, Leam Hall wrote: > >>> Still trying to keep this Py2 and Py3 compatible. > >>> > >>> The Py2 error is: > >>> UnicodeEncodeError: 'ascii' codec can't encode character > >>> u'\xf6' in position 8: ordinal not in range(128) > >>> > >>> even when the string is manually converted: > >>> name = unicode(self.name) > >>> > >>> Same sort of issue with: > >>> name = self.name.decode('utf-8') > >>> > >>> > >>> Py3 doesn't like either version. > >> > >> You got a Unicode *EN*code error when you tried to *DE* code. That's a > >> quirk of Py2's coercion behaviours, so the error's a bit obscure, but > >> it means that you (most likely) actually have a Unicode string > >> already. Check what type(self.name) is, and see if the problem is > >> actually somewhere else. > >> > >> (It's hard to give more specific advice based on this tiny snippet, > >> sorry.) > >> > >> ChrisA > >> > > > > Chris, thanks! I see what you mean. > > I don't think so. You get a unicode from the database, > > $ python > Python 2.7.6 (default, Oct 26 2016, 20:30:19) > [GCC 4.8.4] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sqlite3 > >>> db = sqlite3.connect(":memory:") > >>> cs = db.cursor() > >>> cs.execute("select 'foo';").fetchone() > (u'foo',) > >>> > > and when you try to decode it (which is superfluous as you already have > unicode!) Python does what you ask for. But to be able to decode it has to > encode first and by default it uses the ascii codec for that attempt. For > an > all-ascii string > > u"foo".encode("ascii") --> "foo" > > and thus > > u"foo".decode("utf-8) > > implemented as > > u"foo".encode("ascii").decode("utf-8") --> u"foo" > > is basically a noop. However > > u"???".encode("ascii") --> raises UnicodeENCODEError > > and thus > > u"???".decode("utf-8") > > fails with that. Unfortunately nobody realizes that the encoding failed and > thus will unsuccessfully try and specify other encodings for the decoding > step > > u"???".decode("latin1") # also fails > > Solution: if you already have unicode, leave it alone. > Doesn't seem to work. The failing code takes the strings as is from the database. it will occasionally fail when a name comes up that uses a non-ascii character. Lines 44, 60, 66, 67. https://github.com/makhidkarun/py_tools/blob/master/lib/character.py Leam From rosuav at gmail.com Sun Sep 17 13:00:21 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Sep 2017 03:00:21 +1000 Subject: Old Man Yells At Cloud In-Reply-To: <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sun, Sep 17, 2017 at 11:03 PM, Steve D'Aprano wrote: > On Sun, 17 Sep 2017 08:43 pm, Chris Angelico wrote: > >> On Sun, Sep 17, 2017 at 5:54 PM, Steve D'Aprano >> wrote: >>> To even *know* that there are branches of maths where int/int isn't defined, >>> you need to have learned aspects of mathematics that aren't even taught in >>> most undergrad maths degrees. (I have a degree in maths, and if we ever >>> covered areas where int/int was undefined, it was only briefly, and I've long >>> since forgotten it.) >> >> How about this: >> >>>>> (1<<10000)/2 >> Traceback (most recent call last): >> File "", line 1, in >> OverflowError: integer division result too large for a float >> >> int/int is now undefined. > > No, it's perfectly defined: you get an overflow error if the arguments are too > big to convert, or an underflow error if the denominator is too small, or a > divide by zero error if you divide by zero... > > > What do you make of this? > > py> float(1<<10000)/2.0 > Traceback (most recent call last): > File "", line 1, in > OverflowError: int too large to convert to float > > > Would you like to argue that this shows that coercing ints to floats > is "undefined"? > > > Overflow and underflow errors are limitations of the float data type. We could > fix that in a couple of ways: > > - silently underflow to zero (as Python already does!) or infinity, as needed; > > - use a bigger ~~boat~~ float; > > - or even an arbitrary precision float; > > - or return a rational number (fraction or similar); > > - or introduce a float context that allows you to specify the behaviour > that you want, as the decimal module does. > > There may be other solutions I haven't thought of. But these will do. > > The distinction between Python floats and real numbers ? is a red-herring. It > isn't relevant. You said: >>> (I have a degree in maths, and if we ever >>> covered areas where int/int was undefined, it was only briefly, and I've long >>> since forgotten it.) So what do YOU mean by "int/int" being "undefined"? And I referred to real numbers because YOU referred to a degree in maths. >> In Py2, it perfectly correctly returns >> another integer (technically a long), but in Py3, it can't return a >> float, so it errors out. > > Apart from your "correctly", which I disagree with, that's a reasonable > description. The problem is that your example returns the correct result by > accident. Forget such ludicrously large values, and try something more common: > > 1/2 > > Most people aren't expecting integer division, but true division, and silently > returning the wrong result (0 instead of 0.5) is a silent source of bugs. > > This isn't some theoretical problem that might, maybe, perhaps, be an issue for > some people sometimes. It was a regular source of actual bugs leading to code > silently returning garbage. So why doesn't it return a fractions.Fraction instead? That way, you still get "one half" instead of zero, but it's guaranteed to be accurate. And having 1/3 be a literal meaning "one third" would avoid all the problems of "1/3 + 1/3 + 1/3 != 3/3". What is the justification for int/int => float and not rational? >> In Python 2 and 3, a small integer can be implicitly promoted to float: >> >>>>> user_input = 3.14159 >>>>> print(user_input + 1) >> 4.14159 > > Yes, as it should. Why force the user to call float() on one argument when the > interpreter can do it? What advantage is there? > > Can you demonstrate any failure of dividing two ints n/m which wouldn't equally > fail if you called float(n)/float(m)? I don't believe that there is any such > failure mode. Forcing the user to manually coerce to floats doesn't add any > protection. I don't think there is either, but by forcing people to coerce to float, you force them to accept the consequences of floats. Again, rationals (fractions.Fraction), implemented with a pair of arbitrary-precision integers, are a superset of integers, so you can genuinely upcast. Upcasting from one type to a non-superset of that type is problematic. Upcasting to a perfect superset isn't. ChrisA From python.list at tim.thechases.com Sun Sep 17 13:24:15 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 17 Sep 2017 12:24:15 -0500 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> Message-ID: <20170917122415.2174b332@bigbox.christie.dr> On 2017-09-17 14:16, bartc wrote: > print() is used for its side-effects; what relevant value does it > return? depending on the sink, errors can be returned (at least for the printf(3) C function). The biggest one I've encountered is writing to a full disk. The return value is how many characters were written. In an ideal world, data = "Hello" * 1000 results = print(data) assert len(results) == len(data) but if your disk is nearly full and you're redirecting data to it: $ python myprog.py > output.txt it's feasible that you instruct print() to send 5000 characters but only 4000 of them get written to the disk. You might want to check that condition and handle it in some more graceful way. -tkc From rosuav at gmail.com Sun Sep 17 13:27:35 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Sep 2017 03:27:35 +1000 Subject: Unicode In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> <59be5ba4$0$16728$b1db1813$d948b532@news.astraweb.com> <70394aee-5dc1-04c7-b5eb-73b2d71feefe@gmail.com> <4dcbc060-8fe5-fe4a-b42e-7e3a24ac5e72@gmail.com> Message-ID: On Mon, Sep 18, 2017 at 2:20 AM, leam hall wrote: > On Sun, Sep 17, 2017 at 9:13 AM, Peter Otten <__peter__ at web.de> wrote: > >> Leam Hall wrote: >> >> > On 09/17/2017 08:30 AM, Chris Angelico wrote: >> >> On Sun, Sep 17, 2017 at 9:38 PM, Leam Hall wrote: >> >>> Still trying to keep this Py2 and Py3 compatible. >> >>> >> >>> The Py2 error is: >> >>> UnicodeEncodeError: 'ascii' codec can't encode character >> >>> u'\xf6' in position 8: ordinal not in range(128) >> >>> >> >>> even when the string is manually converted: >> >>> name = unicode(self.name) >> >>> >> >>> Same sort of issue with: >> >>> name = self.name.decode('utf-8') >> >>> >> >>> >> >>> Py3 doesn't like either version. >> >> >> >> You got a Unicode *EN*code error when you tried to *DE* code. That's a >> >> quirk of Py2's coercion behaviours, so the error's a bit obscure, but >> >> it means that you (most likely) actually have a Unicode string >> >> already. Check what type(self.name) is, and see if the problem is >> >> actually somewhere else. >> >> >> >> (It's hard to give more specific advice based on this tiny snippet, >> >> sorry.) >> >> >> >> ChrisA >> >> >> > >> > Chris, thanks! I see what you mean. >> >> I don't think so. You get a unicode from the database, >> >> $ python >> Python 2.7.6 (default, Oct 26 2016, 20:30:19) >> [GCC 4.8.4] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import sqlite3 >> >>> db = sqlite3.connect(":memory:") >> >>> cs = db.cursor() >> >>> cs.execute("select 'foo';").fetchone() >> (u'foo',) >> >>> >> >> and when you try to decode it (which is superfluous as you already have >> unicode!) Python does what you ask for. But to be able to decode it has to >> encode first and by default it uses the ascii codec for that attempt. For >> an >> all-ascii string >> >> u"foo".encode("ascii") --> "foo" >> >> and thus >> >> u"foo".decode("utf-8) >> >> implemented as >> >> u"foo".encode("ascii").decode("utf-8") --> u"foo" >> >> is basically a noop. However >> >> u"???".encode("ascii") --> raises UnicodeENCODEError >> >> and thus >> >> u"???".decode("utf-8") >> >> fails with that. Unfortunately nobody realizes that the encoding failed and >> thus will unsuccessfully try and specify other encodings for the decoding >> step >> >> u"???".decode("latin1") # also fails >> >> Solution: if you already have unicode, leave it alone. >> > > Doesn't seem to work. The failing code takes the strings as is from the > database. it will occasionally fail when a name comes up that uses > a non-ascii character. > > Lines 44, 60, 66, 67. > > https://github.com/makhidkarun/py_tools/blob/master/lib/character.py This doesn't make it easy: https://github.com/makhidkarun/py_tools/blob/master/lib/character_tools.py#L40 Whatever exception occurs, you go to your fallback method. So if something's going wrong, it's harder to figure out. But the thing to do would be to check the types of everything that's involved. You probably still have a mixture of text and bytes. It's hard to pin down without actually running all the code, and with all your "from X import *" lines, it's not easy to track down all the code; I *think* that you will get different behaviour from SQLite3 vs the list_from_file function, but I can't be certain. As always, print is your friend. In this case, print(type(...)) will be helpful. ChrisA From python.list at tim.thechases.com Sun Sep 17 14:09:23 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 17 Sep 2017 13:09:23 -0500 Subject: Old Man Yells At Cloud In-Reply-To: <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> Message-ID: <20170917130923.35b535e9@bigbox.christie.dr> On 2017-09-18 00:42, Steve D'Aprano wrote: > On Sun, 17 Sep 2017 11:51 pm, Tim Golden wrote: > Presumably you've never wanted to print to something other than > std.out. The syntax in Python 2 is horrid: > > print >>sys.stderr, args For those cases, the old syntax was sufficiently horrid that indeed I didn't use it, but rather used print "Normal output" sys.stderr.write("error output!\n") Yes, adding the \n manually is a minor annoyance, but it wasn't much of an issue. > Presumably you've never wanted to print using a separator other > than space. You simply can't do it at all in Python 2. Would just assemble the string I wanted to print and then print that: print "|".join(my_list) print ", ".join(["hello", "world", "from", "william", "shatner"]) > Presumably you've never wanted to print and suppress the newline at > the end of the line. The Python 2 syntax is obscure, error-prone, > and easy to miss: > > print a, b, c, d, # WOT? Very rarely wanted to do this, but in those rare cases, I'd usually use sys.stdout.write() > Presumably you've never wanted to pass print to something as a > function. It can't be done in Python 2: > > something.register(callback=print) # SyntaxError In these cases, I almost never wanted raw print() to be passed, but something that did argument formatting: def p(*args, **kwargs): print fmt_string % args return SUCCESS ? something.register(callback=p) > Presumably you've never wanted to control when the output buffer is > flushed. That's another thing you can't do in Python 2. Can use sys.stdout.flush() just fine in Python 2. I've never really had a need/want to have it buffer when it would otherwise auto-flush (such as writing to pipes). > Presumably you've never wanted to monkey-patch an existing function > that used print by shadowing the built-in. You can't do that in > Python 2, since print isn't a regular name, it can't be mocked or > shadowed or replaced. I've never really had the want in production. Though again, I've reassigned sys.stdout on a couple occasions >>> import sys >>> f = file('delme.txt', 'w') >>> sys.stdout = f >>> print "Hello" >>> f.close() > I've wanted to do all those things, and more. I love the new print > function. For the cost of one extra character, the closing bracket, > it gives you much, much more than the old print statement ever did. That said, I'm neither here nor there when it comes to using print-as-a-statement vs print-as-a-function. I like the consistency it brings to the language, but miss the simplicity that Py2 had for new users. I'd almost want to get it back as a feature of the REPL, even if it wasn't part of the language itself, akin to how pdb can override certain things in certain contexts: (Pdb) l 1 j = 42 2 x = 31 3 import pdb; pdb.set_trace() 4 -> j = 15 5 x = 99 [EOF] (Pdb) x 31 (Pdb) j 1 > /home/tkc/runme.py(1)() -> j = 42 (Pdb) j *** The 'jump' command requires a line number So, while I'm +0 on the move to print-as-a-function in actual code, I find it most annoying in a pdb/REPL context where I would prefer to still have the old print-as-a-statement for simplicity. -tkc From best_lay at yahoo.com Sun Sep 17 14:32:51 2017 From: best_lay at yahoo.com (Wildman) Date: Sun, 17 Sep 2017 13:32:51 -0500 Subject: ttk.Notebook Tabs Question References: Message-ID: On Sun, 17 Sep 2017 08:45:27 +0400, Abdur-Rahmaan Janhangeer wrote: > by widget["width"] i meant replace widget with your widget Yes, that is what I did. It returned 0. -- GNU/Linux user #557453 The cow died so I don't need your bull! From steve+python at pearwood.info Sun Sep 17 14:35:45 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 18 Sep 2017 04:35:45 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> Message-ID: <59bec083$0$14934$b1db1813$d948b532@news.astraweb.com> On Mon, 18 Sep 2017 03:00 am, Chris Angelico wrote: >> The distinction between Python floats and real numbers ? is a red-herring. It >> isn't relevant. > > You said: > >>>> (I have a degree in maths, and if we ever >>>> covered areas where int/int was undefined, it was only briefly, and I've >>>> long since forgotten it.) > > So what do YOU mean by "int/int" being "undefined"? And I referred to > real numbers because YOU referred to a degree in maths. Yes, I referred to a maths degree. I referred to lots of things. And real numbers are still irrelevant. The problem with Python 2 division is not because of the difference between mathematically pure reals and actual Python floats. It is because a/b would do two *different* things depending on whether both a and b were floats or not. To answer your question, what do I mean by int/int being undefined, I'd have to dig into areas of maths that either weren't taught in the undergrad courses I did, or that I've long since forgotten about. Something about... fields? The reals and the rationals are both fields, and they're closed under division. Ints *aren't* a field, because the integers aren't closed under division. ("Closed" means that dividing a rational number by another rational number gives a rational number, for example.) This is a pretty specialised area of maths. You won't learn anything about it in high school. And possibly not undergrad maths degrees. I seem to vaguely recall just barely touching on groups, but not rings or fields. It's perfectly possibly for somebody to do a post-grad degree in maths and not touch this stuff. Hell, I don't even know if I'm right to say that int/int division is "undefined". It's could be that even mathematicians who work in this area will say "of course its defined, you just don't always get an int". Or that they'll say "the question isn't even wrong". If you read the Wikipedia page on it: https://en.wikipedia.org/wiki/Algebraic_structure you'll see reference to category theory, and monoids, things which Haskell loves and most other people run screaming from. The bottom line is, before you can sensibly justify making int/int an illegal operation (a compile-time error in Haskell) you need to be thinking about some pretty hairy areas of maths. To say that 11/2 cannot be calculated and isn't 5.5, you're thinking in areas that most mathematically educated people don't even know exist, let alone care about. [...] >> This isn't some theoretical problem that might, maybe, perhaps, be an issue >> for some people sometimes. It was a regular source of actual bugs leading to >> code silently returning garbage. > > So why doesn't it return a fractions.Fraction instead? That way, you > still get "one half" instead of zero, but it's guaranteed to be > accurate. And having 1/3 be a literal meaning "one third" would avoid > all the problems of "1/3 + 1/3 + 1/3 != 3/3". What is the > justification for int/int => float and not rational? (1) Guido doesn't like fractions for the built-in maths operators, because of his experience with ABC where quite simple calculations would end up with bloody enormous fractions with millions of digits in both the numerator and denominator, running slower and slower, for a number where the actual precision was maybe three or four decimal places. (2) Fractions didn't exist in the standard library when true division was introduced. (3) Fractions are slow to work with. They were even slower until a few years ago when Python got a C accelerated version. Floats are much faster. (4) For many purposes, the arbitrary precision of fractions is *spurious* precision. Like the old saw says: "Measure with micrometer, mark with chalk, cut with axe." You're taking physical quantities which are typically measured to a precision of three or four decimal places, if not less, then doing calculations on them to a precision of potentially millions of decimal places. There may be a few places where that is justified, but as the default behaviour, its spurious precision and such overkill as to be ludicrous. For most purposes, calculating with C doubles is more precision than you'll ever need in a lifetime, and for the exceptions, well, if you're dealing with use-cases that Double isn't enough for, you probably know enough to take alternative steps. (5) Most people are used to dealing with floating point numbers, from other languages, from calculators, from school maths. Floats are quirky but familiar. (6) Fractions are surprising and hard to deal with. Quickly now, without using a calculator or Python, how big is this number? 2523720122311461/140737488355328 Is it more or less than 50? Which would you rather see, the above fraction or its decimal equivalent, 17.93211? But hey, if some languages (Lisp? Scheme?) want to use rationals instead of floats as their default numeric type, more power to them. >> Can you demonstrate any failure of dividing two ints n/m which wouldn't >> equally fail if you called float(n)/float(m)? I don't believe that there is >> any such failure mode. Forcing the user to manually coerce to floats doesn't >> add any protection. > > I don't think there is either, but by forcing people to coerce to > float, you force them to accept the consequences of floats. And by implicitly coercing to floats, you also force them to accept the consequences of floats. [...] > Upcasting from one type to a non-superset of that type is problematic. So you say, but you've failed to demonstrate any practical, real world consequences that are problematic. You've even agreed that forcing the user to do their own coercion doesn't add any protection, and that float(n)/float(b) will fail in exactly the same ways as n/b with true division. And even if you are right that true division is "problematic", it certainly is nowhere near as big a problem as the mess that we had when x/y would do *different operations* according to the types of x and y. I'm not talking about relatively benign issues with DSLs and custom classes that defined __div__ and __rdiv__ to do whatever wacky thing it they like, like path objects that used / to concatenate path elements. I'm talking about two of the most commonly used numeric types, which people expect to be able to interchange safely for the purposes of numerical calculations. Most people have two dozen years of schooling, or more, and potentially many more years of experience with calculators and the like, teaching them that 1/2 and 1.0/2.0 are the same thing. Here's a real practical consequence. You have the price of an item, including GST, and you want to calculate the ex-GST price: def ex_GST(inc_GST): return 10*inc_GST/11 Looks perfectly reasonable. But it isn't. With true division, it is correct: py> ex_GST(122) # with true division 110.9090909090909 which of course you would round to $110.91. But without true division, it silently fails, and you lose almost a dollar: py> ex_GST(122) # with Python 2 integer division 110 (Don't hassle me about using binary floats instead of Decimals. The decimal module didn't exist yet, and even if it did, sometimes using binary floats is simply good enough, e.g. when using Python as a calculator.) The problem is that before the swap to true division, that code *actually* meant something like this: def ex_GST(inc_GST): if isinstance(inc_GST, int): return divmod(10*inc_GST, 11)[0] # throw away any remainder else: return 10*inc_GST/11 # include the remainder which is not what anyone wanted. And because this was a silent error, giving garbage results instead of a clean exception, this sort of bug could hide deep in the middle of calculations for a long time. I got burned by this, many times, as did many other people. It was an awful bug magnet and a bad design. Compared to that, even Haskell's "purity over practicality" decision to ban integer / operator completely is sensible. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Sep 17 14:49:35 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 18 Sep 2017 04:49:35 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> Message-ID: <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> On Mon, 18 Sep 2017 04:09 am, Tim Chase wrote: > On 2017-09-18 00:42, Steve D'Aprano wrote: >> On Sun, 17 Sep 2017 11:51 pm, Tim Golden wrote: >> Presumably you've never wanted to print to something other than >> std.out. The syntax in Python 2 is horrid: >> >> print >>sys.stderr, args > > For those cases, the old syntax was sufficiently horrid that indeed I > didn't use it, but rather used > > print "Normal output" > sys.stderr.write("error output!\n") > > Yes, adding the \n manually is a minor annoyance, but it wasn't much > of an issue. So, you don't like the extra parentheses with print. But you don't mind the parentheses in sys.stderr.write (16 chars, versus five for print) or having to manually concatenate the strings and manually add a newline at the end. Because apparently using print and sys.stderr.write is simpler than print with parens. [...] > That said, I'm neither here nor there when it comes to using > print-as-a-statement vs print-as-a-function. I like the consistency > it brings to the language, but miss the simplicity that Py2 had for > new users. What simplicity? It adds complexity, not simplicity: do you need brackets or not? Why is print special? When do I use print and when do I use sys.stdout.write? Decisions decisions. print(len mylist, "items in the list") > I'd almost want to get it back as a feature of the REPL, Oh yes, that's an excellent idea: make it even harder for beginners to learn when they do and don't need parentheses :-( -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sun Sep 17 14:59:30 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Sep 2017 04:59:30 +1000 Subject: Old Man Yells At Cloud In-Reply-To: <59bec083$0$14934$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <59bec083$0$14934$b1db1813$d948b532@news.astraweb.com> Message-ID: On Mon, Sep 18, 2017 at 4:35 AM, Steve D'Aprano wrote: >> So why doesn't it return a fractions.Fraction instead? That way, you >> still get "one half" instead of zero, but it's guaranteed to be >> accurate. And having 1/3 be a literal meaning "one third" would avoid >> all the problems of "1/3 + 1/3 + 1/3 != 3/3". What is the >> justification for int/int => float and not rational? > > (1) Guido doesn't like fractions for the built-in maths operators, because of > his experience with ABC where quite simple calculations would end up with > bloody enormous fractions with millions of digits in both the numerator and > denominator, running slower and slower, for a number where the actual precision > was maybe three or four decimal places. Okay, that's reasonable. A counter-argument is that if you want reduced accuracy to improve performance, you can always ask for it (by casting to float), but I do see the disadvantage of slow rationals by default. > (2) Fractions didn't exist in the standard library when true division was > introduced. Really? When was true division added? I thought the fractions module had been there for several 2.x versions. > (3) Fractions are slow to work with. They were even slower until a few years ago > when Python got a C accelerated version. Floats are much faster. Yes, they are. And byte strings are probably faster to work with than Unicode text. Python doesn't use performance as a primary definition of semantics. > (4) For many purposes, the arbitrary precision of fractions is *spurious* > precision. Like the old saw says: > > "Measure with micrometer, mark with chalk, cut with axe." > > You're taking physical quantities which are typically measured to a precision of > three or four decimal places, if not less, then doing calculations on them to a > precision of potentially millions of decimal places. There may be a few places > where that is justified, but as the default behaviour, its spurious precision > and such overkill as to be ludicrous. And printing "one eleventh" to a dozen decimal places is just as spurious. Or when you do arithmetic of any kind on decimals. It's not a problem unique to rationals. But I agree, sometimes you'll have more precision than you want. > (5) Most people are used to dealing with floating point numbers, from other > languages, from calculators, from school maths. Floats are quirky but familiar. > > (6) Fractions are surprising and hard to deal with. Quickly now, without using a > calculator or Python, how big is this number? > > 2523720122311461/140737488355328 > > Is it more or less than 50? > > Which would you rather see, the above fraction or its decimal equivalent, > 17.93211? If int/int yielded rational, you would have two ways you could work: 1) Fractions: 2523720122311461/140737488355328 2) Floats: 2523720122311461.0/140737488355328 And if you want to know if it's more or less than 50, you could simply compare: >>> f = fractions.Fraction('2523720122311461/140737488355328') >>> f Fraction(2523720122311461, 140737488355328) >>> f < 50 True >>> f > 50 False Sure, it's harder to eyeball. But comparisons are certainly possible. Basically, you trade one set of weirdnesses for another. ChrisA From info at tundraware.com Sun Sep 17 15:02:09 2017 From: info at tundraware.com (Tim Daneliuk) Date: Sun, 17 Sep 2017 14:02:09 -0500 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: On 09/16/2017 09:59 AM, Tim Daneliuk wrote: > On 09/16/2017 12:38 AM, Steve D'Aprano wrote: >> /rant on >> >> So apparently everyone who disagrees that Python should be more like Javascript >> is an old greybeard fuddy-duddy yelling "Get off my lawn!" to the cool kids -- >> and is also too stupid to know how dumb they are. >> >> "Hi, I've been programming in Python for what seems like days now, and here's >> all the things that you guys are doing wrong. I insist that you fix them >> immediately, it doesn't matter how much code it will break, that's not >> important. What is important is that Javascript programmers like me shouldn't >> be expected to learn anything new or different when they program with Python." >> >> /rant off >> >> And no, for once it wasn't Ranting Rick. >> >> >> >> > > Well, the whole integer floor division thing years ago was the beginning > of the end - Python was doomed ... > Ummm .... I was KIDDING via hyperbole ... sheesh ... From python at mrabarnett.plus.com Sun Sep 17 15:22:07 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 17 Sep 2017 20:22:07 +0100 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <59bec083$0$14934$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-09-17 19:59, Chris Angelico wrote: > On Mon, Sep 18, 2017 at 4:35 AM, Steve D'Aprano > wrote: >>> So why doesn't it return a fractions.Fraction instead? That way, you >>> still get "one half" instead of zero, but it's guaranteed to be >>> accurate. And having 1/3 be a literal meaning "one third" would avoid >>> all the problems of "1/3 + 1/3 + 1/3 != 3/3". What is the >>> justification for int/int => float and not rational? >> >> (1) Guido doesn't like fractions for the built-in maths operators, because of >> his experience with ABC where quite simple calculations would end up with >> bloody enormous fractions with millions of digits in both the numerator and >> denominator, running slower and slower, for a number where the actual precision >> was maybe three or four decimal places. > > Okay, that's reasonable. A counter-argument is that if you want > reduced accuracy to improve performance, you can always ask for it (by > casting to float), but I do see the disadvantage of slow rationals by > default. > >> (2) Fractions didn't exist in the standard library when true division was >> introduced. > > Really? When was true division added? I thought the fractions module > had been there for several 2.x versions. > The fractions module was introduced in Python 2.6. [snip] From __peter__ at web.de Sun Sep 17 15:27:11 2017 From: __peter__ at web.de (Peter Otten) Date: Sun, 17 Sep 2017 21:27:11 +0200 Subject: Unicode References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> <59be5ba4$0$16728$b1db1813$d948b532@news.astraweb.com> <70394aee-5dc1-04c7-b5eb-73b2d71feefe@gmail.com> <4dcbc060-8fe5-fe4a-b42e-7e3a24ac5e72@gmail.com> Message-ID: leam hall wrote: > Doesn't seem to work. The failing code takes the strings as is from the > database. it will occasionally fail when a name comes up that uses > a non-ascii character. Your problem in nuce: the Python 2 __str__() method must not return unicode. >>> class Character: ... def __str__(self): return u"Br?sel" ... >>> print(Character()) Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 2: ordinal not in range(128) While you may define a __unicode__ method it has to be called explicitly: >>> class Character: ... def __unicode__(self): return u"Br?sel" ... >>> print(Character()) <__main__.Character instance at 0x7fc10020f5a8> >>> print(unicode(Character())) Br?sel Another alternative is to convert explicitly, to some encoding, and hope it works in the actual environment: >>> class Character: ... def __unicode__(self): return u"Br?sel" ... def __str__(self): return unicode(self).encode("utf-8") ... >>> print(Character()) Br?sel The more you think about it the more attractive a switch to Python 3 will appear. From rantingrickjohnson at gmail.com Sun Sep 17 16:39:21 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Sep 2017 13:39:21 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> Message-ID: Larry Hudson wrote: > ROGER GRAYDON CHRISTMAN wrote: [Note: RODGER's reply is slightly modified for clarity] > > I have not yet mastered how to respond to a particular > > note in a thread with the mailer that I use, so this is not > > in response to anyone in particular, but just to some of > > the sentiments as a whole. > > > > if x: > > # do something > > > > Completely out of context, I would dislike it just because > > it is far too vague. Is it testing for zero? for an empty > > list? or for some object's completely arbitrary > > definition of truthiness? > > It is absolutely NOT vague, Hmm, and neither are regular expressions, that is, once you've been "trained" to decipher them. But ask a noob what this simple Python regexp means: r"^([a-zA-Z]{3})(\d{3})$" Even though the answer is as easy as "aBc" and "123" (a la Jackson Five!), they'll just give you a look of bewilderment. And even if we expand the digit-group to a more "intuitive" character set, the student will still be overwhelmed by the syntax: r"^([a-zA-Z]{3})([0-9]{3})$" > and the answer is Yes for all of the above. It is well > defined that ALL values can be used in a boolean sense. And likewise, it is well defined what the symbols in that regexp mean, but the meaning is not _obvious_. My point is that Python source code was meant to be "executable pseudo code" (Python devs' words not mine!), and while regular expressions are meant to be cryptic, Python source code was not. From ned at nedbatchelder.com Sun Sep 17 17:19:20 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 17 Sep 2017 17:19:20 -0400 Subject: Old Man Yells At Cloud In-Reply-To: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: <27ede39c-d9ac-26cb-67ee-fce5a812808d@nedbatchelder.com> On 9/16/17 1:38 AM, Steve D'Aprano wrote: > /rant on > > So apparently everyone who disagrees that Python should be more like Javascript > is an old greybeard fuddy-duddy yelling "Get off my lawn!" to the cool kids -- > and is also too stupid to know how dumb they are. > > "Hi, I've been programming in Python for what seems like days now, and here's > all the things that you guys are doing wrong. I insist that you fix them > immediately, it doesn't matter how much code it will break, that's not > important. What is important is that Javascript programmers like me shouldn't > be expected to learn anything new or different when they program with Python." > > /rant off > > And no, for once it wasn't Ranting Rick. The thing that struck me about the interaction (on Python-Ideas, btw) was that Javascript actually is adding new language features at an impressive pace, and many of them seem very Pythonic.? But they sometimes choose different syntax. For example, their "spread" operator is ..., where Python uses *: ??? new_list = [new_start, *old_list, new_end] vs: ??? new_array = [new_start, ...old_array, new_end] Making Python more like Javascript (in this case) would have required breaking existing Python programs. Javascript could have use * as the spread operator without breaking anyone. But they didn't, and I wonder if anyone petitioned them to keep compatibility with Python to easy the plight of the multi-lingual programmer. --Ned. From leamhall at gmail.com Sun Sep 17 17:27:03 2017 From: leamhall at gmail.com (leam hall) Date: Sun, 17 Sep 2017 17:27:03 -0400 Subject: Unicode In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> <59be5ba4$0$16728$b1db1813$d948b532@news.astraweb.com> <70394aee-5dc1-04c7-b5eb-73b2d71feefe@gmail.com> <4dcbc060-8fe5-fe4a-b42e-7e3a24ac5e72@gmail.com> Message-ID: On Sun, Sep 17, 2017 at 3:27 PM, Peter Otten <__peter__ at web.de> wrote: > leam hall wrote: > > > Doesn't seem to work. The failing code takes the strings as is from the > > database. it will occasionally fail when a name comes up that uses > > a non-ascii character. > > Your problem in nuce: the Python 2 __str__() method must not return > unicode. > > >>> class Character: > ... def __str__(self): return u"Br?sel" > ... > >>> print(Character()) > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in > position > 2: ordinal not in range(128) > > While you may define a __unicode__ method it has to be called explicitly: > > >>> class Character: > ... def __unicode__(self): return u"Br?sel" > ... > >>> print(Character()) > <__main__.Character instance at 0x7fc10020f5a8> > >>> print(unicode(Character())) > Br?sel > > Another alternative is to convert explicitly, to some encoding, and hope it > works in the actual environment: > > >>> class Character: > ... def __unicode__(self): return u"Br?sel" > ... def __str__(self): return unicode(self).encode("utf-8") > ... > >>> print(Character()) > Br?sel > Ah! So this works in Py2: def __str__(self): name = self.name.encode("utf-8") It completely fails in Py3: PVT b'Lakeisha F\xc3\xa1bi\xc3\xa1n' 7966A4 [F] Age: 22 Note that moving __str__() to display() gets the same results. Not sure it is an issue with __str__. > The more you think about it the more attractive a switch to Python 3 will > appear. > Not for me, actually. I'm trying to learn better OOP and coding in general. I'm using Python because there's a work related use case for Py2. There isn't one for Py3. If the work use case it removed then there are lots of languages to try out. From rantingrickjohnson at gmail.com Sun Sep 17 17:37:01 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Sep 2017 14:37:01 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> Message-ID: ROGER GRAYDON CHRISTMAN wrote: [Note: RODGER's words have been edited for clarity, and hopefully he won't mind.] > I have not yet mastered how to respond to a particular note > in a thread with the mailer that I use, so this is not in > response to anyone in particular, but just to some of the > sentiments as a whole. > > if x: > # do something > > Completely out of context, I would dislike it just because > it is far too vague. Is it testing for zero? [F]or an empty > list? [O]r for some object's completely arbitrary > definition of truthiness? > > x.._bool__() seems to me to be just as efficient, but we > don't like calling dunders.bool(x) should mean the same > thing, perhaps with an extra function invocation to look > for the dunder. But even so, nothing here sheds light on > what that Boolean outcome means. > > I would agree that testing any of those for '== True' or > the like is pointless redundancy, But what's wrong with syntactical redundancy when it brings _clarity_ to the source code? And why can't Python be smart? Consider the collowing code: if bool(someObject) == True: # Do something Yes, from a "byte-code perspective", this source code is superfluous, but, from a source code perspective, this code is perfectly balanced between explicit and implicit. So what should Python do when such intuitive, but not so much efficient, code is encountered? Easy! Python should optimize it! Observe: FROM: "if bool(someObject) == True:" TO: "if someObject:" FROM: "if bool(someObject) == False:" TO: "if not someObject:" Why is "source code optimization" such a difficult concept for some people in this community to grasp? In this case, Python doesn't even need to know anything about these objects, no, the solution is just a simple matter of string substitution. > which may or may not be slower, depending on optimization > issues. Slower only the first time the source code is _byte_compiled_. After that, source code containing explicit statements like: "if bool(someObject) == True:" will run just as fast as the implicit statement of: "if someObject:". Well, that is, if the devs are wise... From larry.martell at gmail.com Sun Sep 17 17:49:13 2017 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 17 Sep 2017 17:49:13 -0400 Subject: rmtree message In-Reply-To: <42fd9284-ec50-45ae-ae7b-876139d89318@googlegroups.com> References: <42fd9284-ec50-45ae-ae7b-876139d89318@googlegroups.com> Message-ID: On Wed, Sep 13, 2017 at 5:39 PM, Sean DiZazzo wrote: > On Wednesday, September 13, 2017 at 12:06:20 PM UTC-7, Larry.... at gmail.com wrote: >> I have a script that creates a tmp dir, create a lot of files in it, >> and when done, does a rmtree on the dir. When it does that I get this >> message: >> >> shell-init: error retrieving current directory: getcwd: cannot access >> parent directories: No such file or directory >> >> But no exception is thrown. How can I determine why I get this message? > > I usually see that message when I am in a directory in the shell but it has already been deleted by another process. > > Make sure the directory exists. Is another part of your script deleting the root directory while rmtree is running? Or something of the like. Turned out the script's cwd was in a dir that was being removed. I chdir'ed out of there and that resolved the issue. Thanks to all who responded. From rantingrickjohnson at gmail.com Sun Sep 17 18:35:25 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Sep 2017 15:35:25 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: <59b9e755$0$16732$b1db1813$d948b532@news.astraweb.com> References: <1505319485l.29425864l.0l@psu.edu> <59b9e755$0$16732$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > ROGER GRAYDON CHRISTMAN wrote: [...] > > And most definitely if x is assigned outside my control, I > > would definitely want some way to test or verify x's type > > before I start using it, lest my random number generator > > with its (A + B * C) % D finds itself concatenating > > strings and formatting data. > > You don't have to protect yourself from the caller's > stupidity. You should think of Python functions having > something like "Design By Contract" semantics: if you pass > something that the function is not equipped to handle, then > the (informal) contract "Informal Contracts" are not worth the paper they are printed on. Like laws with no teeth, people don't follow them. And then we end up with doc-strings that don't get used, and contracts that are never created, much less respected! > is broken and the function can do anything it likes. Of > course we would prefer that the function would (in order of > highest to lowest preference): > > - raise a clear TypeError or ValueError stating the failure; > > - raise some implementation-dependent exception inside the body of the function; > > - return some obviously invalid result; > > rather than return something which *looks* valid but is > wrong, but don't feel that it is *necessarily* your > responsibility to guard against the caller's stupidity. > "We're all adults here" and if the caller chooses to shoot > themselves in the foot by passing a bad argument, they'll > get what's coming to them. But how is the caller to know what is a "bad" argument and what is a "good" argument unless there is an explicit contract, or at least, an informative doc-string? You know as well as i do that (1) doc-strings are an under-utilized feature, and (2) when they are utilized, they often times neglected and eventually become out-of-sync with the code. > (Defensive programming is not only the receiving function's > responsibility. The caller should program defensively to > ensure they don't pass the wrong arguments too.) Well, congrats, that has the worst advice i ever heard! Obviously, only the author of said interface knows best how to defend against bad input, which is best achieved by type checking. Heck, even the best documentation in the Universe can't defend against bad input, therefore, type checking is the only practical defense. The worse thing a program can do is continue to run (as though everything is normal) after receiving bogus input. Such has been the impetus of the Mandelbug, and in extreme cases, the dreaded Heisenbug! > In fact, there's a fine line between guarding against bad > input, and guarding against input which in fact is > perfectly fine, but merely is something you didn't think > of. And why am i not surprised to discover that your software design philosophy relies heavily on "happy accidents"? From rantingrickjohnson at gmail.com Sun Sep 17 19:15:32 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Sep 2017 16:15:32 -0700 (PDT) Subject: Old Man Yells At Cloud In-Reply-To: <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sunday, September 17, 2017 at 9:42:34 AM UTC-5, Steve D'Aprano wrote: > On Sun, 17 Sep 2017 11:51 pm, Tim Golden wrote: > > [Snip: Reasons why print function is better than print statement] > > I've wanted to do all those things, and more. I love the > new print function. For the cost of one extra character, > the closing bracket, Oops, _two_ characters! What about the opening "bracket"? > [...] > The print statement was only good for the most simple uses. > The print function is a powerful, useful and first-class > component of your programming toolbox. I agree that the new print function is better than the old print statement, but the best solution would have been to keep both. I (like TJG), become frustrated when i forget to type the parenthesis and get a syntax error. And most times, i didn't need the extended functionality of a print function anyway, i just needed a finger-friendly print statement. > > [...] > > Funnily enough, the two arguments most often advanced for > > print-as-function seem to me to cancel each other out. > > Arguments by whom? There's a whole raft of things wrong > with print as a statement. The print statement lacks the intuitive features of a function, but most times, you don't need these features. "PRACTICALITY BEATS PURITY" From mruffalo at cs.cmu.edu Sun Sep 17 19:18:34 2017 From: mruffalo at cs.cmu.edu (Matt Ruffalo) Date: Sun, 17 Sep 2017 19:18:34 -0400 Subject: Unicode In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> <59be5ba4$0$16728$b1db1813$d948b532@news.astraweb.com> <70394aee-5dc1-04c7-b5eb-73b2d71feefe@gmail.com> <4dcbc060-8fe5-fe4a-b42e-7e3a24ac5e72@gmail.com> Message-ID: On 2017-09-17 17:27, leam hall wrote: > > Ah! So this works in Py2: > def __str__(self): > name = self.name.encode("utf-8") > > > It completely fails in Py3: > PVT b'Lakeisha F\xc3\xa1bi\xc3\xa1n' 7966A4 [F] Age: 22 > > > Note that moving __str__() to display() gets the same results. Not sure it > is an issue with __str__. > > > >> The more you think about it the more attractive a switch to Python 3 will >> appear. >> > Not for me, actually. I'm trying to learn better OOP and coding in general. > I'm using Python because there's a work related use case for Py2. There > isn't one for Py3. If the work use case it removed then there are lots of > languages to try out. Hi Leam- Targeting Python 2.6 for deployment on RHEL/CentOS 6 is a perfectly valid use case, and after the recent discussions in multiple threads (your "Design: method in class or general function?" and INADA Naoki's "People choosing Python 3"), I doubt it would be very useful to reiterate the same points. I can't speak for Peter Otten, but I suspect he was making a very narrow statement about one of the large backwards-incompatible changes in Python 3: strict separation between text (str) and binary data (bytes). This stricter distinction eliminates the conceptual problems you described, in terms of ensuring that you need to use the right type at the right time in the right place, and would probably have prevented your problem entirely. Additionally, your note of "this works in Python 2 but fails in Python 3" shows some text-related confusion that is quite common when dealing with the text model in Python 2. It is always the case that the `__str__` method should return a `str` object under whichever version of Python you're using, and your attempt of `self.name.encode("utf-8")` returns the wrong type under Python 3. *Encoding* Unicode text (class `unicode` under Python 2, `str` under 3) produces binary data (class `str` under Python 2, `bytes` under 3). As such, you're returning a `bytes` object from `__str__` in Python 3, which is incorrect. It would be appropriate to do something like """ def __str__(self): ??? if sys.version_info[0] < 3: ??????? return self.name.encode("utf-8") ??? return self.name """ Django provides a `python_2_unicode_compatible` decorator that allows always returning text (class `unicode` under Python 2, `str` under 3) from `__str__`, and automatically rewrites a class' methods under Python 2. That decorator renames `__str__` to `__unicode__`, and creates a new `__str__` method that essentially returns `self.__unicode__().encode('utf-8')`. (Hopefully this is clear enough, but I intended this message to be practical advice for your current task and mental model of what's going on, *not* as Python 3 evangelism.) MMR... -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 829 bytes Desc: OpenPGP digital signature URL: From rantingrickjohnson at gmail.com Sun Sep 17 19:38:52 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Sep 2017 16:38:52 -0700 (PDT) Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> Message-ID: Tim Chase wrote: > Steve D'Aprano wrote: > > Tim Golden wrote: > > Presumably you've never wanted to print to something other > > than std.out. The syntax in Python 2 is horrid: > > > > print >>sys.stderr, args > > For those cases, the old syntax was sufficiently horrid > that indeed I didn't use it, but rather used > > print "Normal output" > sys.stderr.write("error output!\n") > > Yes, adding the \n manually is a minor annoyance, but it > wasn't much of an issue. A backwards compatible stderr.writeln() method would fix that minor annoyance. [...] > That said, I'm neither here nor there when it comes to > using print-as-a-statement vs print-as-a-function. I like > the consistency it brings to the language, but miss the > simplicity that Py2 had for new users. I'd almost want to > get it back as a feature of the REPL, even if it wasn't > part of the language itself, Agreed on that point. At least bring it back in the REPL. The removal of the finger friendly print statement has caused more tension in this community than any feature of such small stature should ever cause. From leamhall at gmail.com Sun Sep 17 19:48:11 2017 From: leamhall at gmail.com (leam hall) Date: Sun, 17 Sep 2017 19:48:11 -0400 Subject: Unicode In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <654f897c-edee-49c2-6c88-c8ac9987bb4e@gmail.com> <59be5ba4$0$16728$b1db1813$d948b532@news.astraweb.com> <70394aee-5dc1-04c7-b5eb-73b2d71feefe@gmail.com> <4dcbc060-8fe5-fe4a-b42e-7e3a24ac5e72@gmail.com> Message-ID: Matt wrote: Hi Leam- > > Targeting Python 2.6 for deployment on RHEL/CentOS 6 is a perfectly > valid use case, and after the recent discussions in multiple threads > (your "Design: method in class or general function?" and INADA Naoki's > "People choosing Python 3"), I doubt it would be very useful to > reiterate the same points. > > I can't speak for Peter Otten, but I suspect he was making a very narrow > statement about one of the large backwards-incompatible changes in > Python 3: strict separation between text (str) and binary data (bytes). > This stricter distinction eliminates the conceptual problems you > described, in terms of ensuring that you need to use the right type at > the right time in the right place, and would probably have prevented > your problem entirely. > > Additionally, your note of "this works in Python 2 but fails in Python > 3" shows some text-related confusion that is quite common when dealing > with the text model in Python 2. It is always the case that the > `__str__` method should return a `str` object under whichever version of > Python you're using, and your attempt of `self.name.encode("utf-8")` > returns the wrong type under Python 3. *Encoding* Unicode text (class > `unicode` under Python 2, `str` under 3) produces binary data (class > `str` under Python 2, `bytes` under 3). As such, you're returning a > `bytes` object from `__str__` in Python 3, which is incorrect. It would > be appropriate to do something like > > """ > def __str__(self): > if sys.version_info[0] < 3: > return self.name.encode("utf-8") > return self.name > """ > > Django provides a `python_2_unicode_compatible` decorator that allows > always returning text (class `unicode` under Python 2, `str` under 3) > from `__str__`, and automatically rewrites a class' methods under Python > 2. That decorator renames `__str__` to `__unicode__`, and creates a new > `__str__` method that essentially returns > `self.__unicode__().encode('utf-8')`. > > (Hopefully this is clear enough, but I intended this message to be > practical advice for your current task and mental model of what's going > on, *not* as Python 3 evangelism.) > > MMR... > > Matt, thanks! I figured there was a way to get the python major version, just hadn't gotten there yet. Your code passes user typing and testing. Peter has earned a lot of leeway due to his expert help and reasonable manner. I took his comment as a friendly note and, like yours, not Py3 evangelism. Most of my frustration isn't with the community though I think it has come off that way. I'm not a good enough coder to get a job with pay close to what I make as a Linux guy. I just have to deal with the pay check coming from where I am and not where the rest of the gang is. :( Leam From rantingrickjohnson at gmail.com Sun Sep 17 19:54:25 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Sep 2017 16:54:25 -0700 (PDT) Subject: Old Man Yells At Cloud In-Reply-To: <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: <8ad63451-f09b-40d5-9ba7-1105c7b8bbf2@googlegroups.com> Steve D'Aprano wrote: > Tim Chase wrote: > > > On 2017-09-18 00:42, Steve D'Aprano wrote: > > > On Sun, 17 Sep 2017 11:51 pm, Tim Golden wrote: > > > Presumably you've never wanted to print to something > > > other than std.out. The syntax in Python 2 is horrid: > > > > > > print >>sys.stderr, args > > > > For those cases, the old syntax was sufficiently horrid > > that indeed I didn't use it, but rather used > > > > print "Normal output" > > sys.stderr.write("error output!\n") > > > > Yes, adding the \n manually is a minor annoyance, but it > > wasn't much of an issue. > > So, you don't like the extra parentheses with print. But > you don't mind the parentheses in sys.stderr.write (16 > chars, versus five for print) or having to manually > concatenate the strings and manually add a newline at the > end. Because apparently using print and sys.stderr.write is > simpler than print with parens. It seems odd, but i have a custom function i created for my own REPL named "pLine()", and i never have a problem remembering to type the "(" and the ")", but for `print`, i always forget, or when i do remember, it feels so "unnatural". This can only mean one thing: old habits die hard. And anyone with experience in Python<3 has typed the old print statement so many times that the syntax has become reflexive. And try as i may, i cannot overcome this habit. I always get frustrated and go back to the warm fuzzies of my Python2 interpreter. O:-) "You wanna go where everybody spells print the same..." Cheers! From tjreedy at udel.edu Sun Sep 17 20:12:11 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 17 Sep 2017 20:12:11 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> Message-ID: On 9/17/2017 4:39 PM, Rick Johnson wrote: > My point is > that Python source code was meant to be "executable pseudo > code" (Python devs' words not mine!), The coinage 'Executable pseudocode' was my description of Python on comp.lang.python, mirrored to this list, in April 1997, long before I became a Python (core) dev. Guido did say things like 'human readable' before that. To the extent that my description implies a higher standard, you cannot imput it to Guido ;-). > and while regular expressions are meant to be cryptic, > Python source code was not. That I agree with. -- Terry Jan Reedy From python.list at tim.thechases.com Sun Sep 17 20:22:02 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 17 Sep 2017 19:22:02 -0500 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> Message-ID: <20170917192202.1967087d@bigbox.christie.dr> On 2017-09-17 16:15, Rick Johnson wrote: > > I've wanted to do all those things, and more. I love the > > new print function. For the cost of one extra character, > > the closing bracket, > > Oops, _two_ characters! What about the opening "bracket"? >>> print(len('print "hello"')) 13 >>> print(len('print("hello")')) 14 Plus two parens, minus one space = net +1 character. -tkc From python at mrabarnett.plus.com Sun Sep 17 20:22:47 2017 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 18 Sep 2017 01:22:47 +0100 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-09-18 00:15, Rick Johnson wrote: > On Sunday, September 17, 2017 at 9:42:34 AM UTC-5, Steve D'Aprano wrote: >> On Sun, 17 Sep 2017 11:51 pm, Tim Golden wrote: >> >> [Snip: Reasons why print function is better than print statement] >> >> I've wanted to do all those things, and more. I love the >> new print function. For the cost of one extra character, >> the closing bracket, > > Oops, _two_ characters! What about the opening "bracket"? > What about the space that usually comes after 'print' in Python 2, but not in Python 3? [snip] From christopher_reimer at icloud.com Sun Sep 17 21:09:11 2017 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Sun, 17 Sep 2017 18:09:11 -0700 Subject: Old Man Yells At Cloud In-Reply-To: <27ede39c-d9ac-26cb-67ee-fce5a812808d@nedbatchelder.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <27ede39c-d9ac-26cb-67ee-fce5a812808d@nedbatchelder.com> Message-ID: <5AA4D01F-7EAF-4D5E-B6B0-5D97954885DF@icloud.com> > On Sep 17, 2017, at 2:19 PM, Ned Batchelder wrote: > >> On 9/16/17 1:38 AM, Steve D'Aprano wrote: >> /rant on >> >> So apparently everyone who disagrees that Python should be more like Javascript >> is an old greybeard fuddy-duddy yelling "Get off my lawn!" to the cool kids -- >> and is also too stupid to know how dumb they are. >> >> "Hi, I've been programming in Python for what seems like days now, and here's >> all the things that you guys are doing wrong. I insist that you fix them >> immediately, it doesn't matter how much code it will break, that's not >> important. What is important is that Javascript programmers like me shouldn't >> be expected to learn anything new or different when they program with Python." >> >> /rant off >> >> And no, for once it wasn't Ranting Rick. > > The thing that struck me about the interaction (on Python-Ideas, btw) was that Javascript actually is adding new language features at an impressive pace, and many of them seem very Pythonic. But they sometimes choose different syntax. > > For example, their "spread" operator is ..., where Python uses *: > > new_list = [new_start, *old_list, new_end] > > vs: > > new_array = [new_start, ...old_array, new_end] > > Making Python more like Javascript (in this case) would have required breaking existing Python programs. Javascript could have use * as the spread operator without breaking anyone. But they didn't, and I wonder if anyone petitioned them to keep compatibility with Python to easy the plight of the multi-lingual programmer. > > --Ned. > -- > https://mail.python.org/mailman/listinfo/python-list I came across a blog post that pointed out that those who advocate for a particular JavaScript framework probably know enough JavaScript for the framework but not enough JavaScript to figure out a problem with the framework. Since frameworks are an abstraction of JavaScript, you really need to know JavaScript to avoid getting stuck with a framework. I know enough JavaScript to get the JQuery eye candy to work and I'm confused by all the frameworks available. I picked up a JavaScript ebook to familiarize myself with the language. This isn't the same JavaScript that I learned in the early 2000's. Chris R. From rantingrickjohnson at gmail.com Sun Sep 17 21:11:15 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sun, 17 Sep 2017 18:11:15 -0700 (PDT) Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> Message-ID: MRAB wrote: > Rick Johnson wrote: > > Steve D'Aprano wrote: > >> Tim Golden wrote: > > > > > > [Snip: Reasons why print function is better than print statement] > > > > > > I've wanted to do all those things, and more. I love the > > > new print function. For the cost of one extra character, > > > the closing bracket, > > > > Oops, _two_ characters! What about the opening "bracket"? > > > What about the space that usually comes after 'print' in > Python 2, but not in Python 3? True. But let's not forget that spaces are one keystroke whereas an open round-bracket is ^9 and a closing round- bracket is ^0. Speaking in _keystrokes_, and that's what really matters here, a print function is always three more keystrokes than a print statement. From steve+python at pearwood.info Sun Sep 17 21:39:55 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 18 Sep 2017 11:39:55 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> Message-ID: <59bf23eb$0$14953$b1db1813$d948b532@news.astraweb.com> On Mon, 18 Sep 2017 09:15 am, Rick Johnson wrote: > On Sunday, September 17, 2017 at 9:42:34 AM UTC-5, Steve D'Aprano wrote: >> On Sun, 17 Sep 2017 11:51 pm, Tim Golden wrote: >> >> [Snip: Reasons why print function is better than print statement] >> >> I've wanted to do all those things, and more. I love the >> new print function. For the cost of one extra character, >> the closing bracket, > > Oops, _two_ characters! What about the opening "bracket"? It replaces the space separating print from the arguments. print spam, eggs, cheese print(spam, eggs, cheese) One extra character. See? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From songofacandy at gmail.com Sun Sep 17 21:41:05 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Mon, 18 Sep 2017 01:41:05 +0000 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> Message-ID: > > > > That said, I'm neither here nor there when it comes to > > using print-as-a-statement vs print-as-a-function. I like > > the consistency it brings to the language, but miss the > > simplicity that Py2 had for new users. I'd almost want to > > get it back as a feature of the REPL, even if it wasn't > > part of the language itself, > > Agreed on that point. At least bring it back in the REPL. > The removal of the finger friendly print statement has > caused more tension in this community than any feature of > such small stature should ever cause. > > >>> x = 42 >>> x 42 x (1 keystroke) is easy to type than `print x` (7 keystrokes). While sometimes print(x) is different x (which uses repr), it's enough for most cases. So I can't agree it's REPL unfriendly. BTW, IPython is nice REPL and it has parenthee free function call. I recommend you to use it if you're not happy with builtin REPL. Regards, -- Inada Naoki From songofacandy at gmail.com Sun Sep 17 21:50:59 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Mon, 18 Sep 2017 01:50:59 +0000 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> Message-ID: > > > > > I would agree that testing any of those for '== True' or > > the like is pointless redundancy, > > But what's wrong with syntactical redundancy when it brings > _clarity_ to the source code? And why can't Python be smart? > Consider the collowing code: > > if bool(someObject) == True: > # Do something > > Yes, from a "byte-code perspective", this source code is > superfluous, but, from a source code perspective, this code > is perfectly balanced between explicit and implicit. I can't agree with you. It's too redundant. It doesn't provide any information about what coder think. While PEP 8 recommends `if x:`, I accept `if x > 0` or `if len(x) > 0` when I review code in my company. While it is redundant in most case, it express what writer thinking. But I never permit `if bool(x) == True`. It only express `if x is truthy value`in complicated way. `if x` is best way to express `if x is truthy value`. > So what > should Python do when such intuitive, but not so much > efficient, code is encountered? Easy! Python should optimize > it! Observe: > > FROM: "if bool(someObject) == True:" > TO: "if someObject:" > > FROM: "if bool(someObject) == False:" > TO: "if not someObject:" > > Why is "source code optimization" such a difficult concept > for some people in this community to grasp? In this case, > Python doesn't even need to know anything about these > objects, no, the solution is just a simple matter of string > substitution. > > While such type of optimization is possible, it's not easy as you think. You can overwrite `bool`. def bool(x): return !x if 0: print("not shown") if bool(0) == True: print("shown") But my point is only readability. I don't agree `if bool(x) == True:` is clear than `if x:`. Regards, -- Inada Naoki From steve+python at pearwood.info Sun Sep 17 22:03:08 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 18 Sep 2017 12:03:08 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> Message-ID: <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> On Mon, 18 Sep 2017 07:37 am, Rick Johnson wrote: > Consider the collowing code: > > if bool(someObject) == True: > # Do something > > Yes, from a "byte-code perspective", this source code is > superfluous, This is bad code because it is bad SOURCE CODE. The byte code is irrelevant. You wouldn't write this: if (len(mystring) == 1) == True: because that's just stupid, the equality comparison returns a bool so testing against True is redundant and adds no clarity, just noise. Nor would you write: if (numchars > 2) == True: because the greater than comparison returns a bool and so testing against True is redundant and adds no clarity, just noise. And you wouldn't write: if (argument is None) == True: because the `is` comparison returns a bool and testing it against True is redundant and adds no clarity, just noise. Nor would you write: condition = some_string.startswith('x') == True result = process(args, flag=(condition == True)) because in both lines you already have a bool and comparing a bool to True is just redundant and adds noise. And surely you wouldn't write: results = sorted(values, reverse=(False==True)) Or would you? Maybe you would do all these things, in which case you're an even worse programmer than I thought. Your example of if bool(someObject) == True: is no different from any of these examples. bool(someObject) returns a bool; comparing it to True adds redundancy and noise, not clarity. Your insistence on adding the entirely superfluous, unnecessary and distracting "== True" at the end of something which is already True or False demonstrates a lack of fluency in the language and difficulty in reasoning about boolean logic. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From python.list at tim.thechases.com Sun Sep 17 22:51:51 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 17 Sep 2017 21:51:51 -0500 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> Message-ID: <20170917215151.21ea78cf@bigbox.christie.dr> On 2017-09-18 01:41, INADA Naoki wrote: > > > That said, I'm neither here nor there when it comes to > > > using print-as-a-statement vs print-as-a-function. I like > > > the consistency it brings to the language, but miss the > > > simplicity that Py2 had for new users. I'd almost want to > > > get it back as a feature of the REPL, even if it wasn't > > > part of the language itself, > > > > Agreed on that point. At least bring it back in the REPL. > > The removal of the finger friendly print statement has > > caused more tension in this community than any feature of > > such small stature should ever cause. > > > > > >>> x = 42 > >>> x > 42 > > x (1 keystroke) is easy to type than `print x` (7 keystrokes). > While sometimes print(x) is different x (which uses repr), it's > enough for most cases. > So I can't agree it's REPL unfriendly. Compare PDB for things that are PDB commands. (Pdb) list 1 j = 42 2 x = 31 3 import pdb; pdb.set_trace() 4 -> j = 15 5 x = 99 [EOF] (Pdb) x 31 (Pdb) j *** The 'jump' command requires a line number (Pdb) print j *** SyntaxError: Missing parentheses in call to 'print' (Pdb) j 1 > /home/tkc/test.py(1)() -> j = 42 (Pdb) j(2) *** The 'jump' command requires a line number You (obstinate interpreter) know what I want, know what I mean, can't possibly interpret it as some other command. Yet insist on pedantic parens when you (interpreter) know full well the intended parsing, accepting "j 1" to jump to line one instead of making me type "j(1)". :grumble: old-man-shaking-his-fist-at-the-sky'ly yers, -tkc From steve+python at pearwood.info Sun Sep 17 23:23:09 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 18 Sep 2017 13:23:09 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> Message-ID: <59bf3c1f$0$14941$b1db1813$d948b532@news.astraweb.com> On Mon, 18 Sep 2017 11:11 am, Rick Johnson wrote: > Speaking in _keystrokes_, and that's what really matters > here, a print function is always three more keystrokes than > a print statement. Keystrokes only matter if you are hunt'n'peck typing and need to pause between holding down the shift key and pressing the 9 key. Otherwise typing ( is little different than typing 9, its pretty much all the same regardless of what character you type. For an even half-arsed typist like myself, hitting the shift and 9 keys happens almost simultaneously. Technically it might involve two fingers but its effectively a single movement. If you micro-analyse this, not all keystrokes are equivalent. They use different fingers, different hands, the movements are different. The fact that some characters need two simultaneous keypresses is not so important. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sun Sep 17 23:46:06 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Sep 2017 13:46:06 +1000 Subject: Old Man Yells At Cloud In-Reply-To: <59bf3c1f$0$14941$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <59bf3c1f$0$14941$b1db1813$d948b532@news.astraweb.com> Message-ID: On Mon, Sep 18, 2017 at 1:23 PM, Steve D'Aprano wrote: > On Mon, 18 Sep 2017 11:11 am, Rick Johnson wrote: > >> Speaking in _keystrokes_, and that's what really matters >> here, a print function is always three more keystrokes than >> a print statement. > > Keystrokes only matter if you are hunt'n'peck typing and need to pause between > holding down the shift key and pressing the 9 key. Otherwise typing ( is little > different than typing 9, its pretty much all the same regardless of what > character you type. For an even half-arsed typist like myself, hitting the > shift and 9 keys happens almost simultaneously. Technically it might involve > two fingers but its effectively a single movement. > > If you micro-analyse this, not all keystrokes are equivalent. They use different > fingers, different hands, the movements are different. The fact that some > characters need two simultaneous keypresses is not so important. The easiest non-micro analysis is that a *repeated* key is significantly slower than virtually any pair of keystrokes. Consequently, the slowest part of programming is the part where you realize that you got something wrong, and hammer the Backspace key. It's just logical! ChrisA From lingmaaki at gmail.com Mon Sep 18 02:47:45 2017 From: lingmaaki at gmail.com (lingmaaki at gmail.com) Date: Sun, 17 Sep 2017 23:47:45 -0700 (PDT) Subject: What use of string module? In-Reply-To: References: Message-ID: This will help you.... http://net-informations.com/python/basics/string.htm From kimvais at gmail.com Mon Sep 18 03:16:27 2017 From: kimvais at gmail.com (kimvais at gmail.com) Date: Mon, 18 Sep 2017 00:16:27 -0700 (PDT) Subject: Attribute error for NoneType Message-ID: <4fdd9325-ebb5-43bf-a0ec-95150392215b@googlegroups.com> Hi, A common source of confusion for newbies is the `AttributeError: NoneType has no attribute ...` Also, one of my pet peeves for violating EAFP is the common `if something is not None:` ... Both of these could be "fixed" by having a new exception (that subclasses AttributeError) e.g. `IsNoneError` (for the lack of better name) that is raised whenever `None`'s attributes are accessed. Of course, one can already write `try: .. except AttributError` - but that catches also whenever something else than `None` is being accessed. Do you guys think that this might be PEP-worthy idea? << K From dieter at handshake.de Mon Sep 18 03:31:49 2017 From: dieter at handshake.de (dieter) Date: Mon, 18 Sep 2017 09:31:49 +0200 Subject: speech_to_text python command not working References: Message-ID: <877eww1mze.fsf@handshake.de> "pizza python" writes: > I'm on Linux Mint 18.2 Cinnamon 64-bit. > > I am trying to get IBM Watson BlueMix Speech-To-Text to transcribe my > spoken-word audio files. Because I'm not a coder, I tried to find the > simplest way to use BlueMix Speech-to-Text. And what I found > is [1]https://github.com/rmotr/speech-to-text > ... Traceback (most recent call last): > ... > speech_to_text formatted_output = FormatterClass().format(result) File > "/usr/local/lib/python2.7/dist-packages/speech_to_text/formatters.py", line 36, > in format for obj in self._parse(data)) File > "/usr/local/lib/python2.7/dist-packages/speech_to_text/formatters.py", line 10, > in _parse for obj in data[`results']) KeyError: `results' > ... > __________ > > I was expecting an html with the transcript. So why did I get the errors > above? Speech to text conversion is not a pure Python solution. It must be based on some kind of "external service". From the details you have provided, it looks like some web service. Your error occurs because what the "external service" has delivered it not what "speech-to-text" has expected. More precisely, "speech-to-text" has excepted as result a dict with a "results" key -- but this is missing (likely because some input is wrong or there is a version mismatch between your "speech-to-text" and the "external service"). I expect that the "data" mentioned in the traceback above contains some clues for what went wrong. I would use the Python debugger to investigate along these lines. As you are not yourself a Python programmer, find one in your region to support you. From pizzapython at gmx.com Mon Sep 18 04:03:34 2017 From: pizzapython at gmx.com (pizza python) Date: Mon, 18 Sep 2017 10:03:34 +0200 Subject: speech_to_text python command not working In-Reply-To: <877eww1mze.fsf@handshake.de> References: <877eww1mze.fsf@handshake.de> Message-ID: Speech to text conversion is not a pure Python solution. It must be based on some kind of "external service". From the details you have provided, it looks like some web service. Yes, you are right. It's based on IBM Watson's web/cloud service. Your error occurs because what the "external service" has delivered it not what "speech-to-text" has expected. More precisely, "speech-to-text" has excepted as result a dict with a "results" key -- but this is missing (likely because some input is wrong or there is a version mismatch between your "speech-to-text" and the "external service"). Someone else also thought there is a version mismatch between the "speech-to-text" and the "external service". The external service has been update four times since the "speech-to-text" library was put together. I expect that the "data" mentioned in the traceback above contains some clues for what went wrong. I would use the Python debugger to investigate along these lines. As you are not yourself a Python programmer, find one in your region to support you. Could someone kindly advise how to use "the Python debugger"? From p.f.moore at gmail.com Mon Sep 18 04:11:01 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 18 Sep 2017 09:11:01 +0100 Subject: speech_to_text python command not working In-Reply-To: References: <877eww1mze.fsf@handshake.de> Message-ID: On 18 September 2017 at 09:03, pizza python wrote: > Your error occurs because what the "external service" has delivered > it not what "speech-to-text" has expected. More precisely, > "speech-to-text" has excepted as result a dict with a "results" key -- > but this is missing (likely because some input is wrong or there > is a version mismatch between your "speech-to-text" and the "external > service"). > > > Someone else also thought there is a version mismatch between the > "speech-to-text" and the "external service". The external service has been > update four times since the "speech-to-text" library was put together. So it's pretty likely you need a new version of the "speech-to-text" library. > I expect that the "data" mentioned in the traceback above contains > some clues for what went wrong. I would use the Python debugger > to investigate along these lines. As you are not yourself a Python > programmer, find one in your region to support you. > > > Could someone kindly advise how to use "the Python debugger"? https://docs.python.org/3.6/library/pdb.html - but I would reiterate the advice that if you're not a programmer, you should get someone who is to assist you with this, as the debugger will not be easy to use without programming experience (and fixing the problem even more so). Paul From pizzapython at gmx.com Mon Sep 18 04:34:04 2017 From: pizzapython at gmx.com (pizza python) Date: Mon, 18 Sep 2017 10:34:04 +0200 Subject: speech_to_text python command not working In-Reply-To: References: <877eww1mze.fsf@handshake.de> Message-ID: On Mon, Sep 18, 2017 at 1:11 AM, Paul wrote: On 18 September 2017 at 09:03, pizza python wrote: > Your error occurs because what the "external service" has delivered > it not what "speech-to-text" has expected. More precisely, > "speech-to-text" has excepted as result a dict with a "results" key -- > but this is missing (likely because some input is wrong or there > is a version mismatch between your "speech-to-text" and the "external > service"). > > > Someone else also thought there is a version mismatch between the > "speech-to-text" and the "external service". The external service has been > update four times since the "speech-to-text" library was put together. So it's pretty likely you need a new version of the "speech-to-text" library. Hi, Paul. Thanks for your reply. Appreciate it a lot. I've informed the developer of this issue on both his blog and his github. Hope he can update his "speech-to-text" library to make it work with IBM Watson. It was so good when it was working that the lead of the "developer advocacy team" at IBM Watson reached out to him! > I expect that the "data" mentioned in the traceback above contains > some clues for what went wrong. I would use the Python debugger > to investigate along these lines. As you are not yourself a Python > programmer, find one in your region to support you. > > > Could someone kindly advise how to use "the Python debugger"? [1]https://docs.python.org/3.6/library/pdb.html - but I would reiterate the advice that if you're not a programmer, you should get someone who is to assist you with this, as the debugger will not be easy to use without programming experience (and fixing the problem even more so). Thanks for your sound advice. As I'm already quite overwhelmed with this error as it is, I'll recognize my current limitations and seek help from the more experienced. Thanks References Visible links 1. https://docs.python.org/3.6/library/pdb.html From pizzapython at gmx.com Mon Sep 18 05:09:57 2017 From: pizzapython at gmx.com (pizza python) Date: Mon, 18 Sep 2017 11:09:57 +0200 Subject: speech_to_text python command not working In-Reply-To: References: <877eww1mze.fsf@handshake.de> Message-ID: Hi all. I tried the same command with a different, smaller file. This file is a 90-kilobyte ogg file. The other one was a 26-megabyte ogg file. Wtih this smaller file, there was no error. speech_to_text -u myUsername -p myPassword -f html -i audio-file.ogg transcript.html Starting Upload. [===============================================================================================================================================================================================] 100% Upload finished. Waiting for Transcript Speech > Text finished. In the same folder as the ogg file was an html file with the transcript. So I guess the python command works some times. I'm still not sure if it just doesn't work on large files. From p.f.moore at gmail.com Mon Sep 18 05:17:33 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 18 Sep 2017 10:17:33 +0100 Subject: speech_to_text python command not working In-Reply-To: References: <877eww1mze.fsf@handshake.de> Message-ID: With that information, my guess would be that the way the web service reports errors has changed, and the Python library is failing to handle errors nicely for you, but the basic functionality still works. So that's somewhat good news, as you can at least handle anything that *would* work, even if it's going to be hard to understand the reason for failures without a friendly message like "File too big"... On 18 September 2017 at 10:09, pizza python wrote: > Hi all. I tried the same command with a different, smaller file. This file > is a 90-kilobyte ogg file. The other one was a 26-megabyte ogg file. > > Wtih this smaller file, there was no error. > > > speech_to_text -u myUsername -p myPassword -f html -i audio-file.ogg > transcript.html > Starting Upload. > [===============================================================================================================================================================================================] > 100% > Upload finished. Waiting for Transcript > Speech > Text finished. > > > In the same folder as the ogg file was an html file with the transcript. > So I guess the python command works some times. I'm still not sure if it > just doesn't work on large files. > -- > https://mail.python.org/mailman/listinfo/python-list From leamhall at gmail.com Mon Sep 18 06:21:40 2017 From: leamhall at gmail.com (Leam Hall) Date: Mon, 18 Sep 2017 06:21:40 -0400 Subject: The Python-List community Message-ID: <86569b24-2de7-42f2-200a-69b0eb61a48e@gmail.com> A few days ago I pointed out that this list's community had "opportunities to improve". While we still have lots of those opportunities, it is good to see several community members raise the bar in welcoming new folks into the community. Thank you for your help and positive attitude! Leam From bc at freeuk.com Mon Sep 18 06:26:41 2017 From: bc at freeuk.com (bartc) Date: Mon, 18 Sep 2017 11:26:41 +0100 Subject: Old Man Yells At Cloud In-Reply-To: <59bf3c1f$0$14941$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <59bf3c1f$0$14941$b1db1813$d948b532@news.astraweb.com> Message-ID: On 18/09/2017 04:23, Steve D'Aprano wrote: > On Mon, 18 Sep 2017 11:11 am, Rick Johnson wrote: > >> Speaking in _keystrokes_, and that's what really matters >> here, a print function is always three more keystrokes than >> a print statement. > > Keystrokes only matter if you are hunt'n'peck typing and need to pause between > holding down the shift key and pressing the 9 key. Otherwise typing ( is little > different than typing 9, its pretty much all the same regardless of what > character you type. For an even half-arsed typist like myself, hitting the > shift and 9 keys happens almost simultaneously. Technically it might involve > two fingers but its effectively a single movement. > > If you micro-analyse this, not all keystrokes are equivalent. They use different > fingers, different hands, the movements are different. The fact that some > characters need two simultaneous keypresses is not so important. I don't hunt&peck but my typing accuracy is very poor. Shifted keys are harder (in having poorer success outcomes) because two keys are involved, the keys are somewhat outside the Qwerty zone so need a longer reach, and some synchronisation is needed (the shift must be pressed before the '('). It's not as bad as it sounds but just means that unnecessary shifted punctuation is more of a PITA than if it wasn't necessary. It's a lot worse doing this in C however; compare: print a with: printf ("%d\n",a); 8 extra punctuation characters, of which half are shifted (on my keyboard). /And/ you have to select a suitable format code. Suddenly, having to type: print (a) doesn't seem so bad. -- bartc From rantingrickjohnson at gmail.com Mon Sep 18 07:07:11 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Sep 2017 04:07:11 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> Message-ID: <9c7a7512-d7fa-4c28-b1f5-da8486982fb0@googlegroups.com> On Sunday, September 17, 2017 at 7:12:46 PM UTC-5, Terry Reedy wrote: > The coinage 'Executable pseudocode' was my description of Python on > comp.lang.python, mirrored to this list, in April 1997, long before > I became a Python (core) dev. Guido did say things like 'human > readable' before that. To the extent that my description implies a > higher standard, you cannot imput it to Guido ;-). I can neither confirm or deny that claim, so until i can, i will accept your claim as valid. Although, i seem to remember GvR using "executable pseudocode" in one of his early interviews. In any event, there is no doubt that GvR's original intent was to create a language with a clear syntax (something that ABC tried to do, but failed miserably), so whether he used the exact words 'executable pseudocode' or 'human readable', the meaning is the same. "A horse of a different color is still a horse; of course, of course." :-) From rantingrickjohnson at gmail.com Mon Sep 18 07:53:32 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Sep 2017 04:53:32 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> Message-ID: <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> On Sunday, September 17, 2017 at 8:51:38 PM UTC-5, INADA Naoki wrote: > > > > > > > > I would agree that testing any of those for '== True' or > > > the like is pointless redundancy, > > > > But what's wrong with syntactical redundancy when it brings > > _clarity_ to the source code? And why can't Python be smart? > > Consider the collowing code: > > > > if bool(someObject) == True: > > # Do something > > > > Yes, from a "byte-code perspective", this source code is > > superfluous, but, from a source code perspective, this code > > is perfectly balanced between explicit and implicit. > > I can't agree with you. It's too redundant. It doesn't > provide any information about what coder think. It's not about what the "coder thinks", many times what the coder thinks is wrong, it's about writing code that is intuitive to as wide an audience as possible. > While PEP 8 recommends `if x:`, I accept `if x > 0` or `if > len(x) > 0` when I review code in my company. So when `x` is an iterable, as in: if len(x) > 0: # blah You're okay with the explicit test. Or when `x` is a numeric, as in: if x > 0: # blah You're okay with the explicit test. So, from a standpoint of consistency, you /should/ be okay with this: if bool(x) == True: # blah But you're not! :-). Even though "== True" is just as much a part of the explicit test as "> 0" is, and likewise, "bool(x)" is just as important as "len(x)" to call the proper dunder method. So what is your justification for making a special case out of the last example, but having no problem with the first two forms? Because, as we know: "SPECIAL CASES ARE NOT SPECIAL ENOUGH TO BREAK THE RULES". *wink* IMO, you're ignoring the importance of consistency. If you want to be consistent, either you must accept _all_ forms, or _none_ of them. > While it is redundant in most case, it express what writer > thinking. But I never permit `if bool(x) == True`. It only > express `if x is truthy value` in complicated way. `if x` > is best way to express `if x is truthy value`. Tell you what: test your hypothesis on non-programmers and report back here. > > So what > > should Python do when such intuitive, but not so much > > efficient, code is encountered? Easy! Python should optimize > > it! Observe: > > > > FROM: "if bool(someObject) == True:" > > TO: "if someObject:" > > > > FROM: "if bool(someObject) == False:" > > TO: "if not someObject:" > > > > Why is "source code optimization" such a difficult concept > > for some people in this community to grasp? In this case, > > Python doesn't even need to know anything about these > > objects, no, the solution is just a simple matter of string > > substitution. > > > > > While such type of optimization is possible, it's not easy > as you think. You can overwrite `bool`. > > def bool(x): > return !x Oops. That looks like a syntax error. Ruby uses the "!" as a logical not operator, _not_ Python. > if 0: > print("not shown") > > if bool(0) == True: > print("shown") > But i get your point. Although, your point -- "that a programmer can shoot [him/her]self in the foot" -- is really moot, since there are literally countless ways in which code can be broken by doing dumb things. For example, i can hit my computer with a big hammer and cause all sorts of bad things to happen, but using the: "coder might strike the computer with big hammer so we should prepare for that by doing X, Y and Z..." excuse as a design philosophy is just not practical. In the end, we can't stop a coder from smashing the computer with a big hammer, but we can demand that the code is written in an explicit (enough) manner. Forcing whitespace usage to denote Python blocks is one way that Python forces us to write clean code, and all i'm suggesting is an extrapolation of that philosophy into the realms of conditional logic. > But my point is only readability. I don't agree `if > bool(x) == True:` is clear than `if x:`. You certainly have a right to your opinion. And i do appreciate you presenting this argument in a respectful manner. I'm thinking of writing a linter (or pre-parser, call it what you like) that will enforce the explicit forms that i have outlined above. Possibly with the ability to fine tune it in a way that best suits the programmer. For instance, if you wanted "if NUMERIC > 0" and "if len(ITERABLE) > 0", but you didn't want "if bool(x) == BOOLEAN_LITERAL", then it would ignore the last form. What do you think of this? From rantingrickjohnson at gmail.com Mon Sep 18 08:42:40 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Sep 2017 05:42:40 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> Message-ID: <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> Steve D'Aprano wrote: > [snip: offensive statements] > > Your insistence on adding the entirely superfluous, unnecessary Please acquaint yourself with the definition of superfluous, as in most i have seen, the actual word "unnecessary" is part of the definition. > and distracting "== True" at the end of something which is > already True or False demonstrates a lack of fluency in the > language and difficulty in reasoning about boolean logic. Steve, it one thing for you to disagree with me (even to the point of passionate appeals), but it is quite another to suggest that my "fluency of the Python language" or my "reasoning about boolean logic" is flawed. Python is a programming language, not a formal logic, and i can assure you, i understand Python semantics and formal logic just fine. My complaint that Python's conditional logic forms: (1) implicitly cast objects to boolean, and (2) and rely on an underlying and unintuitive design which has arbitrarily assigned boolean values to objects -- is not a result of a misunderstanding on my part, no, it a result of my utter distaste for implicit conditional logic forms. Consider the currently accepted form of conditional logic: if someObject: # do something In this implicit code example, Python is doing two "magical" things: (1) Python3 is implicitly casting `someObject` to a boolean value by silently calling `someObject.__bool__()`. Of course, in Python<3 there was no __bool__ dunder method, so you'd have to define __nonzero__ or __len__ to achieve the same thing. And for those who don't know about this difference, consider the following Python 2.x code: >>> class FalseFoo(object): ... def __len__(self): ... return 0 >>> falseFoo = FalseFoo() >>> bool(falseFoo) False >>> class TrueFoo(object): ... def __len__(self): ... return 1 >>> trueFoo = TrueFoo() >>> bool(trueFoo) True Hmm, in light of this revelation, one could argue that __bool__ was only introduced to correct a semantical inconsistency that existed between the bool() function and the dunder method it called, namely: __nonzero__ or __len__ (depending on which was defined). All other builtin functions (i can think of) map perfectly to intuitively named dunder methods (len -> __len__, dir -> __dir__, etc...). So, obviously, the devs are concerned about "source code semantics", or they would have not have introduced __bool__. (2) Python is, in essence, converting the source code syntax of: if someObject: to: if BOOLEAN_VALUE_OF_SOMEOBJECT: Which, although the result of such a conversion (a Boolean) will be perfectly symmetrical with formal logic statements, the conversion is not obvious, because it happens behind the curtains. So with that simple statement, two magical and unobvious actions are occuring behind the curtain. IMO, such non- obvious conversions are a violation of the "human readable" goal of Python source code. Magic is not obvious. And implicit conditional logic is not "human readable". From rustompmody at gmail.com Mon Sep 18 08:54:46 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 18 Sep 2017 05:54:46 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: <403e2c01-66d5-43e9-ae50-cde8fc14e564@googlegroups.com> On Monday, September 18, 2017 at 5:23:49 PM UTC+5:30, Rick Johnson wrote: > On Sunday, September 17, 2017 at 8:51:38 PM UTC-5, INADA Naoki wrote: > > > > > > > > > > > I would agree that testing any of those for '== True' or > > > > the like is pointless redundancy, > > > > > > But what's wrong with syntactical redundancy when it brings > > > _clarity_ to the source code? And why can't Python be smart? > > > Consider the collowing code: > > > > > > if bool(someObject) == True: > > > # Do something > > > > > > Yes, from a "byte-code perspective", this source code is > > > superfluous, but, from a source code perspective, this code > > > is perfectly balanced between explicit and implicit. > > > > I can't agree with you. It's too redundant. It doesn't > > provide any information about what coder think. > > It's not about what the "coder thinks", many times what the > coder thinks is wrong, it's about writing code that is > intuitive to as wide an audience as possible. > > > While PEP 8 recommends `if x:`, I accept `if x > 0` or `if > > len(x) > 0` when I review code in my company. > > So when `x` is an iterable, as in: > > if len(x) > 0: > # blah > > You're okay with the explicit test. Or when `x` is a > numeric, as in: > > if x > 0: > # blah > > You're okay with the explicit test. So, from a standpoint of > consistency, you /should/ be okay with this: > > if bool(x) == True: > # blah > > But you're not! :-). I have a feeling Rick that you are mixing up two unrelated things: - the bool(x) part - the ... == True part The operation x == True for true(!)/proper booleans x is a no-op because True == True is True and False == True is False And there are no other (proper) booleans However because anything else can be bool-ish even though not boolean you need the bool(x) to effect the mapping: {None, 0, "" {}, []} ? False Everything_else ? True This mapping is neither obvious nor trivial And one could argue that leaving python to implicitly make [] (say) into False should be documented So if you drop the hangup with the red-herring ...==True you have a point in asking for the bool(...) From rosuav at gmail.com Mon Sep 18 08:58:22 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Sep 2017 22:58:22 +1000 Subject: [Tutor] beginning to code In-Reply-To: <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> Message-ID: On Mon, Sep 18, 2017 at 10:42 PM, Rick Johnson wrote: > (2) Python is, in essence, converting the source code > syntax of: > > if someObject: > > to: > > if BOOLEAN_VALUE_OF_SOMEOBJECT: > > Which, although the result of such a conversion (a > Boolean) will be perfectly symmetrical with formal logic > statements, the conversion is not obvious, because it > happens behind the curtains. What a surprise. In the context of a statement that has exactly two possible courses of action (either you go into the 'if' block, or you go into the 'else' block (if any)), you use the boolean value of an object. What part of this is not obvious? Do you prefer languages that: 1) Require the use of an actual Boolean type? You still don't have to compare the bool against True - "if bool(some_object)" would work. 2) Have no data types, but require that you use "1" or "0" (the strings) to represent true and false? 3) Treat any nonzero value as false, and zero as true? All of those exist. Are they somehow intrinsically better than the Python model? Are they "more explicit"? ChrisA From steve+python at pearwood.info Mon Sep 18 09:00:37 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 18 Sep 2017 23:00:37 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: <59bfc378$0$14954$b1db1813$d948b532@news.astraweb.com> On Mon, 18 Sep 2017 09:53 pm, Rick Johnson wrote: > Tell you what: test your hypothesis on non-programmers and > report back here. Why would someone do that? The purpose of source code is not to communicate with non-programmers. It is to communicate with other programmers. (If the code is executable by a computer as well, that's even better.) I wouldn't ask a non-programmer to critique my source code any more than I would ask a non-English reader to critique my English prose, or a non-musician to read my musical score[1]. It would annoy the non-programmer and provide no useful results. > all i'm > suggesting is an extrapolation of that philosophy into the > realms of conditional logic. By writing True == True when you actually mean just True. > I'm thinking of writing a linter (or pre-parser, call it > what you like) that will enforce the explicit forms that i > have outlined above. That's an excellent idea. And just like I promised all those many, many years ago when you announced you were re-writing Python to implement all your other brilliant ideas, I'll beta test it for you. If and when you actually write some code and make it publicly available. [1] Always supposing I could write a musical score. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rustompmody at gmail.com Mon Sep 18 09:00:55 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 18 Sep 2017 06:00:55 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: <403e2c01-66d5-43e9-ae50-cde8fc14e564@googlegroups.com> References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> <403e2c01-66d5-43e9-ae50-cde8fc14e564@googlegroups.com> Message-ID: <716969d9-15aa-4966-a8ea-559e14c3dcf6@googlegroups.com> On Monday, September 18, 2017 at 6:25:09 PM UTC+5:30, Rustom Mody wrote: > On Monday, September 18, 2017 at 5:23:49 PM UTC+5:30, Rick Johnson wrote: > > On Sunday, September 17, 2017 at 8:51:38 PM UTC-5, INADA Naoki wrote: > > > > > > > > > > > > > > I would agree that testing any of those for '== True' or > > > > > the like is pointless redundancy, > > > > > > > > But what's wrong with syntactical redundancy when it brings > > > > _clarity_ to the source code? And why can't Python be smart? > > > > Consider the collowing code: > > > > > > > > if bool(someObject) == True: > > > > # Do something > > > > > > > > Yes, from a "byte-code perspective", this source code is > > > > superfluous, but, from a source code perspective, this code > > > > is perfectly balanced between explicit and implicit. > > > > > > I can't agree with you. It's too redundant. It doesn't > > > provide any information about what coder think. > > > > It's not about what the "coder thinks", many times what the > > coder thinks is wrong, it's about writing code that is > > intuitive to as wide an audience as possible. > > > > > While PEP 8 recommends `if x:`, I accept `if x > 0` or `if > > > len(x) > 0` when I review code in my company. > > > > So when `x` is an iterable, as in: > > > > if len(x) > 0: > > # blah > > > > You're okay with the explicit test. Or when `x` is a > > numeric, as in: > > > > if x > 0: > > # blah > > > > You're okay with the explicit test. So, from a standpoint of > > consistency, you /should/ be okay with this: > > > > if bool(x) == True: > > # blah > > > > But you're not! :-). > > I have a feeling Rick that you are mixing up two unrelated things: > - the bool(x) part > - the ... == True part > > The operation > x == True > for true(!)/proper booleans x is a no-op > because True == True is True > and False == True is False > And there are no other (proper) booleans > > However because anything else can be bool-ish even though not boolean > you need the bool(x) to effect the mapping: > > {None, 0, "" {}, []} ? False > Everything_else ? True > > This mapping is neither obvious nor trivial Sufficiently non-obvious that I missed the key element: {None, 0, "" {}, [], False} ? False From tjol at tjol.eu Mon Sep 18 09:24:32 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 18 Sep 2017 15:24:32 +0200 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> Message-ID: <6094e162-4557-951c-7897-4064b8742af1@tjol.eu> On 2017-09-18 03:11, Rick Johnson wrote: > MRAB wrote: >> Rick Johnson wrote: >>> Steve D'Aprano wrote: >>>> Tim Golden wrote: >>>> >>>> [Snip: Reasons why print function is better than print statement] >>>> >>>> I've wanted to do all those things, and more. I love the >>>> new print function. For the cost of one extra character, >>>> the closing bracket, >>> >>> Oops, _two_ characters! What about the opening "bracket"? >>> >> What about the space that usually comes after 'print' in >> Python 2, but not in Python 3? > > True. But let's not forget that spaces are one keystroke > whereas an open round-bracket is ^9 and a closing round- > bracket is ^0. Let's absolutely forget it! The fact that you happen to use {insert favourite keyboard layout here} is not a valid consideration for language design. (What characters are likely to be easily accessible on most programmers' keyboards around the world is. The details of your keyboard aren't.) > > Speaking in _keystrokes_, and that's what really matters > here, a print function is always three more keystrokes than > a print statement. Or perhaps, in analogy to playing a guitar, a keystroke can involve multiple (partially or practically simultaneous) keypresses. In which case, no. -- Thomas Jollans From antoon.pardon at vub.be Mon Sep 18 09:30:03 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 18 Sep 2017 15:30:03 +0200 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> Message-ID: Op 18-09-17 om 14:58 schreef Chris Angelico: > On Mon, Sep 18, 2017 at 10:42 PM, Rick Johnson > wrote: >> (2) Python is, in essence, converting the source code >> syntax of: >> >> if someObject: >> >> to: >> >> if BOOLEAN_VALUE_OF_SOMEOBJECT: >> >> Which, although the result of such a conversion (a >> Boolean) will be perfectly symmetrical with formal logic >> statements, the conversion is not obvious, because it >> happens behind the curtains. > What a surprise. In the context of a statement that has exactly two > possible courses of action (either you go into the 'if' block, or you > go into the 'else' block (if any)), you use the boolean value of an > object. What part of this is not obvious? Well that you reduce an object to a boolean value is not obvious to begin with. A TypeError because you are treating a non-boolean as a boolean would have been more obvious to me. A second thought is that it isn't obvious that empty strings, lists ... should be thought of as falsy. Sometimes I am treating a stream of values/objects and when I ask for the next available items, i get a string/list. An empty string/list in that context would mean that nothing was available, but it is possible that more will be available later and so could be treated just like a non-empty list/string. But then, I can't mix this kind of interface with the io module because a read from classes in that module will produce an empty (byte)string to indicate the end of the stream. Once you understand how python does things, you can work with it, but IMO the way python does things is IMO not at all that obvious as people would like us to think. -- Antoon Pardon. From p.f.moore at gmail.com Mon Sep 18 09:47:44 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 18 Sep 2017 14:47:44 +0100 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> Message-ID: On 18 September 2017 at 14:30, Antoon Pardon wrote: > Well that you reduce an object to a boolean value is not obvious to > begin with. A TypeError because you are treating a non-boolean as > a boolean would have been more obvious to me. More obvious, possibly - that's essentially a matter of what people are used to, and a measure of personal opinion. More useful? Unlikely. The practical examples I've seen of languages like Python that implicitly convert non-boolean values to boolean, and languages that don't (and raise an error if a non-boolean is supplied to an if statement) suggest to me that implicit conversion is highly useful. I certainly use it in my code (although in my view it's perfectly "obvious", so I may use constructs that you would find non-obvious). > A second thought is that it isn't obvious that empty strings, lists ... > should be thought of as falsy. Sometimes I am treating a stream of > values/objects and when I ask for the next available items, i get > a string/list. An empty string/list in that context would mean that > nothing was available, but it is possible that more will be available > later and so could be treated just like a non-empty list/string. We can argue over the precise rules as to *what* boolean values Python chooses to take particular non-boolean values as meaning. I'm not going to have a blazing row over whether an empty string should be true or false. But equally, I'm not going to mount a campaign to change it. It's just not that important to me. If you want an argument worth having, go argue with the Perl people about the fact that "0" (the 1-character string containing a zero) is false in Perl: > perl -e "print qq'a non-empty string that is false\n' if not '0';" a non-empty string that is false Given this sort of silliness, I'm perfectly OK with the choices Python made :-) Paul From rosuav at gmail.com Mon Sep 18 09:58:42 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 18 Sep 2017 23:58:42 +1000 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> Message-ID: On Mon, Sep 18, 2017 at 11:30 PM, Antoon Pardon wrote: > Op 18-09-17 om 14:58 schreef Chris Angelico: >> On Mon, Sep 18, 2017 at 10:42 PM, Rick Johnson >> wrote: >>> (2) Python is, in essence, converting the source code >>> syntax of: >>> >>> if someObject: >>> >>> to: >>> >>> if BOOLEAN_VALUE_OF_SOMEOBJECT: >>> >>> Which, although the result of such a conversion (a >>> Boolean) will be perfectly symmetrical with formal logic >>> statements, the conversion is not obvious, because it >>> happens behind the curtains. >> What a surprise. In the context of a statement that has exactly two >> possible courses of action (either you go into the 'if' block, or you >> go into the 'else' block (if any)), you use the boolean value of an >> object. What part of this is not obvious? > > Well that you reduce an object to a boolean value is not obvious to > begin with. A TypeError because you are treating a non-boolean as > a boolean would have been more obvious to me. Sure, but those are basically your only two options. Either you have a way of interpreting some/all objects as booleans, or you require an explicit conversion. In Python syntax: # Interpret all objects as boolean: if x: pass # Require explicit conversion or comparison: if bool(x): pass if x == True: pass But not BOTH of the above: if bool(x) == True: pass That's pointless. It's not "more explicit". It's just more redundant. > A second thought is that it isn't obvious that empty strings, lists ... > should be thought of as falsy. Sometimes I am treating a stream of > values/objects and when I ask for the next available items, i get > a string/list. An empty string/list in that context would mean that > nothing was available, but it is possible that more will be available > later and so could be treated just like a non-empty list/string. Yep. That's a philosophical choice; Python has decided that a container with nothing in it is falsy, on the assumption that you're more likely to be contrasting [1,2,3] against [] than either of the above against None. Other languages have made other choices. Python is 100% consistent within its native data types - including that, unless otherwise specified, an object is truthy and the absence of an object (eg None) is falsy. One notable violation of that rule was that a datetime.time() representing midnight used to be considered false, but that was treated as a bug and corrected, since a time of midnight is not equivalent to a number of zero, but to a point on a clock. > Once you understand how python does things, you can work with it, but > IMO the way python does things is IMO not at all that obvious as people > would like us to think. Understood - but it's not arbitrary, and you *can* get to know the rules. ChrisA From greg.ewing at canterbury.ac.nz Mon Sep 18 10:04:46 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 19 Sep 2017 02:04:46 +1200 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> Message-ID: Dennis Lee Bieber wrote: > Pascal > provides print()/println() [okay, not /statements/ but /procedures/] Actually write/writeln, and although they used parens like procedures, they had special syntax for output formatting that wasn't available to user-defined procedures, so they were at least as special as the py2 print, maybe more so. Wirth got rid of them in Modula-2, so he seemed to be thinking along the same lines as py3. -- Greg From ben.usenet at bsb.me.uk Mon Sep 18 10:31:13 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Mon, 18 Sep 2017 15:31:13 +0100 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> Message-ID: <8760cgqdse.fsf@bsb.me.uk> Steve D'Aprano writes: > [...] try something more common: > > 1/2 > > Most people aren't expecting integer division, but true division, and silently > returning the wrong result (0 instead of 0.5) is a silent source of > bugs. I'm the sure that expectation depends on their background and previous programming experience, and since I don't know much about most people when they first write 1/2 in Python, I must conceded that you may be right. But is that really the point? Was the result of 1/2 determined by a poll to find out what most people expected? If so, who were these people -- the result would depend very largely on the selection? But there is a stronger claim (which I think you also made) that a floating point result is the correct one. However, some people with little experience of floating point arithmetic (I certainly can't say most but it must be quite few) will expect 1/10 to return a tenth. For /them/, the floating point result is silently wrong and a source of bugs. If I were aiming a language at beginners, I'd make 1/10 be a rational or a type error. However, I don't think that is Python's main demographic, so 1/10 giving something not quite one tenth may well be the correct design choice. > And 1/2 doesn't have to return an int. Why is this such a big deal? I'm sure it's not deliberate, but 1/2 is a bad example because it can be exactly represented in the most common implementations. To get a more fruitful exchange of views, a division like 1/3 or 1/10 might be a better example. -- Ben. From bc at freeuk.com Mon Sep 18 10:54:49 2017 From: bc at freeuk.com (bartc) Date: Mon, 18 Sep 2017 15:54:49 +0100 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> Message-ID: On 18/09/2017 15:04, Gregory Ewing wrote: > Dennis Lee Bieber wrote: >> Pascal >> provides print()/println() [okay, not /statements/ but /procedures/] > > Actually write/writeln, and although they used parens like > procedures, they had special syntax for output formatting > that wasn't available to user-defined procedures, so they > were at least as special as the py2 print, maybe more so. They HAD to be special, because that language was statically typed. You couldn't define a user-code procedure or function that took all possible types. That doesn't apply in Python, but it is still useful for print to be a little special. -- bartc From songofacandy at gmail.com Mon Sep 18 11:22:54 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Mon, 18 Sep 2017 15:22:54 +0000 Subject: [Tutor] beginning to code In-Reply-To: <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: > > > > > I can't agree with you. It's too redundant. It doesn't > > provide any information about what coder think. > > It's not about what the "coder thinks", many times what the > coder thinks is wrong, it's about writing code that is > intuitive to as wide an audience as possible. > My point is not "what the coder thinks", but "express what the coder thinks". It's very important point about readability. When I talk about readability, it's defined in "The Art of Readable Code". http://shop.oreilly.com/product/9780596802301.do It means; How long average leveled programmer understand the code deep enough, to modify the code or fix bug in the code. It not means "intuitive to as wide an audience as possible." > > > While PEP 8 recommends `if x:`, I accept `if x > 0` or `if > > len(x) > 0` when I review code in my company. > > So when `x` is an iterable, as in: > > if len(x) > 0: > # blah > > You're okay with the explicit test. Yes, you know "this code is assuming x is container" from redundant `len(x) > 0`. It's valuable information. As a bonus, len(x) raises TypeError and program stops, (and transaction will be rolled back) when x is None. Or when `x` is a numeric, as in: > if x > 0: > # blah > > You're okay with the explicit test. Yes, you know this code assumes x is numeric. `if x:` doesn't tell the information to you. As a bonus, if x is None, `x > 0` raises TypeError on Python 3. > So, from a standpoint of > consistency, you /should/ be okay with this: > > if bool(x) == True: > # blah > > But you're not! :-). > I don't accept it because `if bool(x) == True` doesn't give any information than `if x:`. Both mean just `if x is truthy`. No more information. Redundant code is just a noise. > > Even though "== True" is just as much a part of the explicit > test as "> 0" is, and likewise, "bool(x)" is just as important > as "len(x)" to call the proper dunder method. So what is > your justification for making a special case out of the last > example, but having no problem with the first two forms? > Already described above. Give more information to reader who is average leveled Pythonista or not. > > Because, as we know: "SPECIAL CASES ARE NOT SPECIAL ENOUGH > TO BREAK THE RULES". *wink* > That's why I don't write such code in CPython stdlib. I allow such code only in my company or OSS project I maintain. > > IMO, you're ignoring the importance of consistency. If you > want to be consistent, either you must accept _all_ forms, > or _none_ of them. > As I already describe, I'm very consistent. Redundant code is meaningful only when it gives valuable information to reader. Otherwise, it's noise. It should be removed. > > > While it is redundant in most case, it express what writer > > thinking. But I never permit `if bool(x) == True`. It only > > express `if x is truthy value` in complicated way. `if x` > > is best way to express `if x is truthy value`. > > Tell you what: test your hypothesis on non-programmers and > report back here. > I can't agree with you here. And who agree with you in this thread? > While such type of optimization is possible, it's not easy > > as you think. You can overwrite `bool`. > > > > def bool(x): > > return !x > > Oops. That looks like a syntax error. Ruby uses the "!" as a > logical not operator, _not_ Python. > > Sorry. Writing Python in gmail textarea is bad experience. > Although, your point -- "that a programmer can shoot > [him/her]self in the foot" -- is really moot, No, it's not my point. My point is just optimizing `bool(x) == True` is not easy as static language. Optimizer must be very very conservative about changing language behavior. > But my point is only readability. I don't agree `if > > bool(x) == True:` is clear than `if x:`. > > You certainly have a right to your opinion. And i do > appreciate you presenting this argument in a respectful > manner. > > I'm thinking of writing a linter (or pre-parser, call it > what you like) that will enforce the explicit forms that i > have outlined above. Possibly with the ability to fine tune > it in a way that best suits the programmer. For instance, if > you wanted "if NUMERIC > 0" and "if len(ITERABLE) > 0", but > you didn't want "if bool(x) == BOOLEAN_LITERAL", then it > would ignore the last form. > > What do you think of this? > I don't want it. I don't reject "if x > 0:` when codereview. But I don't recommend it too. Regards, -- Inada Naoki From ben.usenet at bsb.me.uk Mon Sep 18 11:29:49 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Mon, 18 Sep 2017 16:29:49 +0100 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <59bec083$0$14934$b1db1813$d948b532@news.astraweb.com> Message-ID: <871sn4qb2q.fsf@bsb.me.uk> Steve D'Aprano writes: > To answer your question, what do I mean by int/int being undefined, I'd have to > dig into areas of maths that either weren't taught in the undergrad courses I > did, or that I've long since forgotten about. Something > about... fields? > This is a pretty specialised area of maths. You won't learn anything > about it in high school. And possibly not undergrad maths degrees. I > seem to vaguely recall just barely touching on groups, but not rings > or fields. When you said before that you thought that undefined division was rather obscure I was going to mention that it's the basic difference between a ring and a field; the intent being that you'd go "oh, yes, of course it's not obscure at all". I'm glad I didn't now, because you would not have seen it as the simple notion I expected! Teaching rings and fields is (or at least was 30 or so years ago) 1st year undergraduate maths here in the UK. Maybe it's changed. BTW, I don't think this has anything to do with what 1/3 should be in Python. Python as no interest in rings and fields -- it's purely a pragmatic decision. -- Ben. From steve+python at pearwood.info Mon Sep 18 11:42:06 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 19 Sep 2017 01:42:06 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> Message-ID: <59bfe951$0$14927$b1db1813$d948b532@news.astraweb.com> On Mon, 18 Sep 2017 10:42 pm, Rick Johnson wrote: > Steve D'Aprano wrote: > >> [snip: offensive statements] >> >> Your insistence on adding the entirely superfluous, unnecessary > > Please acquaint yourself with the definition of superfluous, > as in most i have seen, the actual word "unnecessary" is > part of the definition. That whooshing noise you are hearing is the point flying over your head. Did you really not observe, notice or see that I have been intentionally, deliberately, purposely and by design using redundant, superfluous, unnecessary phrases and expressions to drive home the point that redundantly comparing a bool to True was redundant and unnecessary? I thought it was blatantly obvious. The difference is that in English, we can sometimes use redundancy for emphasis, as in "blatantly obvious" or "critically important". There are also some common phrases which are technically redundant but long use has turned them into idioms, stock phrases and sometimes even cliches: - prior experience (all experience is technically prior); - plan ahead, or plan for the future (you can't plan for the past); - moment in time (you can't have a moment in space); - mental attitude (attitude is always mental). But most of the time redundancy is just poor use of language: - enter into: to enter is to go into, so you are going into into; - current status quo: the status quo is the current state of affairs, so it is the current current state; - joint cooperation: if it isn't done jointly, it isn't cooperation; - manually by hand: manually literally means "by hand". And so it is with `if True == True`. It is poor use of language. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Mon Sep 18 11:58:07 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 19 Sep 2017 01:58:07 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> <403e2c01-66d5-43e9-ae50-cde8fc14e564@googlegroups.com> Message-ID: <59bfed11$0$14928$b1db1813$d948b532@news.astraweb.com> On Mon, 18 Sep 2017 10:54 pm, Rustom Mody wrote: > The operation > x == True > for true(!)/proper booleans x is a no-op > because True == True is True > and False == True is False > And there are no other (proper) booleans Yes, this exactly! > However because anything else can be bool-ish even though not boolean > you need the bool(x) to effect the mapping: You don't need to explicitly call bool() since Python does it for you. All you're doing is what Python does anyway. One might as well write: print(str(x)) '%s' % str(x) tuple((1, 2)) int(1) str("redundancy") integers = map(lambda x: int(x), values) # instead of just map(int, values) and other signs of the programmer who lacks fluency in the language. I've made nearly all of those errors, but I've learned from other, better coders and recognised my mistakes. I'm sure I still have plenty of mistakes remaining, but at least I've stopped writing map(lambda x: int(x), values) and other rookie errors. > {None, 0, "" {}, []} ? False > Everything_else ? True Your list of false-like ("falsey") values is incomplete. By very strong convention, all empty containers should compare false. That includes those you show, plus sets, frozensets, tuples, arrays, bytearrays, various Abstract Base Classes in the collections.abc module, etc. Likewise other zero values: 0.0, 0j, Decimal(0), Fraction(0), etc. There may be others. > This mapping is neither obvious nor trivial By convention, it is. Of course you can design your class' __bool__ any way you like, and make it as non-obvious and confusing as they like. But you shouldn't. Empty sequences and collections should be false. Non-empty sequences and collections should be true. Values which represent "nothing" in some sense -- zero, empty strings, empty collections, None -- should be falsey. Values which represent "something" -- non-zero numbers, non-empty strings, non-empty collections, arbitrary objects -- should be truthy. Of all people, Rustom, you should appreciate this. There's a whole field of mathematics that builds up arithmetic starting from the empty set, defining it as equivalent to zero, and the set of empty sets as one. (I simplify, of course, but I'm sure you know that.) > And one could argue that leaving python to implicitly make [] (say) into False > should be documented As it is. https://docs.python.org/2/reference/expressions.html#boolean-operations https://docs.python.org/2/reference/compound_stmts.html#the-if-statement https://docs.python.org/2/reference/datamodel.html#object.__nonzero__ https://docs.python.org/3/reference/expressions.html#boolean-operations https://docs.python.org/3/reference/compound_stmts.html#the-if-statement https://docs.python.org/3/reference/datamodel.html#object.__bool__ -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From roel at roelschroeven.net Mon Sep 18 15:46:24 2017 From: roel at roelschroeven.net (Roel Schroeven) Date: Mon, 18 Sep 2017 21:46:24 +0200 Subject: Old Man Yells At Cloud In-Reply-To: <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano schreef op 17/09/2017 3:09: > On Sun, 17 Sep 2017 04:00 am, Stefan Ram wrote: > >> Steve D'Aprano writes: >>> "Hi, I've been programming in Python for what seems like days now, and here's >>> all the things that you guys are doing wrong. >> I never ever have written a line of Python 2. I started with >> Python 3.6.0. Yet a very frequent mistake of mine is the >> imission of parentheses after ?print?. > > That's remarkable. > > Do you also forget the parentheses around `len`, and `iter`, and `math.sin()`? > If not, what's so special about print? I don't know, but I also frequently forget the parentheses around `print`. I do have Python 2 experience so maybe it's just a habit that I've been unable to grow out of yet. OTOH I also regulary use `printf()` and friends in C and C++ and sometimes even PHP, and there I never forget the parentheses. I don't know how, I don't know why, it just happens. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From roel at roelschroeven.net Mon Sep 18 15:56:16 2017 From: roel at roelschroeven.net (Roel Schroeven) Date: Mon, 18 Sep 2017 21:56:16 +0200 Subject: Old Man Yells At Cloud In-Reply-To: <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano schreef op 17/09/2017 20:49: > On Mon, 18 Sep 2017 04:09 am, Tim Chase wrote: > So, you don't like the extra parentheses with print. But you don't mind the > parentheses in sys.stderr.write (16 chars, versus five for print) or having to > manually concatenate the strings and manually add a newline at the end. Because > apparently using print and sys.stderr.write is simpler than print with parens. Actually I think Tim has a point. I did the same in Python 2: use simple easy-to-use `print` for the simple cases, and `sys.stdout.write()` or sometimes `sys.stderr.write()` when simple `print` wasn't enough. I do prefer Python 3's print-as-a-function because "special cases aren't special enough to break the rules", but I feel there's a case to be made for Python 2's print-as-a-statement because "(although) practicality beats purity" sometimes. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From ben.usenet at bsb.me.uk Mon Sep 18 16:39:24 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Mon, 18 Sep 2017 21:39:24 +0100 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> Message-ID: <87k20vpwqr.fsf@bsb.me.uk> bartc writes: > On 18/09/2017 15:04, Gregory Ewing wrote: >> Dennis Lee Bieber wrote: >>> Pascal >>> provides print()/println() [okay, not /statements/ but /procedures/] >> >> Actually write/writeln, and although they used parens like >> procedures, they had special syntax for output formatting >> that wasn't available to user-defined procedures, so they >> were at least as special as the py2 print, maybe more so. > > They HAD to be special, because that language was statically > typed. You couldn't define a user-code procedure or function that took > all possible types. That's not right. It's true of Pascal's specific type system, but you /can/ have a strong, statically-checked type system /and/ a user-written generic print function. There will be compromises and complexities (in both the language design and in the print function) that might, in the end, be considered unacceptable, but the static nature of the typing does not, on its own, preclude it. A former colleague's PhD thesis (about 1978 I think) was about types in programming language design. The central question that was repeatedly asked was whether a universal print function could be written in this or that language. -- Ben. From bill at baddogconsulting.com Mon Sep 18 16:48:09 2017 From: bill at baddogconsulting.com (Bill Deegan) Date: Mon, 18 Sep 2017 16:48:09 -0400 Subject: SCons 3.0.0 release Message-ID: SCons - a software construction tool Release Notes This is SCons, a tool for building software (and other files). SCons is implemented in Python, and its "configuration files" are actually Python scripts, allowing you to use the full power of a real scripting language to solve build problems. You do not, however, need to know Python to use SCons effectively. Please go to http://scons.org/pages/download.html to get the latest production release of SCons. If you have current pip and virtualenv versions, you can install scons into a virtualenv using: pip install scons (For the time being installing outside a virtualenv via pip may fail as we have some oustanding issues related to such installs.) So that everyone using SCons can help each other learn how to use it more effectively, please go to http://scons.org/lists.html#users to sign up for the scons-users mailing list. RELEASE 3.0.0 - Mon, 18 Sep 2017 08:32:04 -0700 Please consult the RELEASE.txt file for a summary of changes since the last release and consult the CHANGES.txt file for complete a list of changes since last release. This announcement highlights only the important changes. Please note the following important changes since release 2.5.1: This is the initial release supporting both python 3.5+ and 2.7.x and pypy There are some important changes: - Any print statements must now use python 3 syntax of "print()" - All node content should be in bytes. This is the default in python 2.7.x, in Python 3 all strings are by default unicode. byte and/or bytearray should be used if you construct content for return by a custom node type's get_content() method. - There are some (as yet unresolved issue) using Literal()'s in some context with Python 3 - pypy should be supported, please report any issues to the user's mailing list. - Currently if you switch back and forth between python 2.7.x and 3.5+ you will need to remove your sconsign file. This should be resolves shortly, but regardless switching between python 2.7.x and 3.5+ will not use compatible sconsigns and as such incremental builds should be expected to rebuild anything changed since the previous scons run with the same version of python. - It is likely that migrating from 2.5.1 -> 3.0.0 alpha will cause rebuilds due to the significant number of changes in the codebase. - Removed deprecated tools CVS, Perforce, BitKeeper, RCS, SCCS, Subversion. - Removed deprecated module SCons.Sig - See CHANGES.txt for more details on other changes - 3.0.0 should be slightly faster than 2.5.1. Changes yielded a 15% speed up for null incremental builds. - Updated D language scanner support to latest: 2.071.1. - python -m SCons should now run SCons if it's installed PYTHONPATH From john_ladasky at sbcglobal.net Mon Sep 18 17:21:31 2017 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Mon, 18 Sep 2017 14:21:31 -0700 (PDT) Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" In-Reply-To: References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> Message-ID: <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> On Saturday, September 16, 2017 at 11:01:03 PM UTC-7, Terry Reedy wrote: > On 9/16/2017 7:04 PM, b... at g...com wrote: > The particular crippler for CLBG problems is the non-use of numpy in > numerical calculations, such as the n-body problem. Numerical python > extensions are over two decades old and give Python code access to > optimized, compiled BLAS, LinPack, FFTPack, and so on. The current one, > numpy, is the third of the series. It is both a historical accident and > a continuing administrative convenience that numpy is not part of the > Python stdlib. OK, I found this statement intriguing. Honestly, I can't function without Numpy, but I have always assumed that many Python programmers do so. Meanwhile: most of the time, I have no use for urllib, but that module is in the standard library. I noticed the adoption of the @ operation for matrix multiplication. I have yet to use it myself. So is there a fraction of the Python community that thinks that Numpy should in fact become part of the Python stdlib? What is the "administrative convenience" to which you refer? From breamoreboy at gmail.com Mon Sep 18 18:08:23 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Mon, 18 Sep 2017 15:08:23 -0700 (PDT) Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" In-Reply-To: <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> Message-ID: On Monday, September 18, 2017 at 10:21:55 PM UTC+1, John Ladasky wrote: > On Saturday, September 16, 2017 at 11:01:03 PM UTC-7, Terry Reedy wrote: > > On 9/16/2017 7:04 PM, b... at g...com wrote: > > > The particular crippler for CLBG problems is the non-use of numpy in > > numerical calculations, such as the n-body problem. Numerical python > > extensions are over two decades old and give Python code access to > > optimized, compiled BLAS, LinPack, FFTPack, and so on. The current one, > > numpy, is the third of the series. It is both a historical accident and > > a continuing administrative convenience that numpy is not part of the > > Python stdlib. > > OK, I found this statement intriguing. Honestly, I can't function without Numpy, but I have always assumed that many Python programmers do so. Meanwhile: most of the time, I have no use for urllib, but that module is in the standard library. > > I noticed the adoption of the @ operation for matrix multiplication. I have yet to use it myself. > > So is there a fraction of the Python community that thinks that Numpy should in fact become part of the Python stdlib? What is the "administrative convenience" to which you refer? My very opinionated personnal opinion is that many third party libraries are much better off outside of the stdlib, numpy particulary so as it's one of the most used, if not the most used, such libraries. My rationale is simple, the authors of the libraries are not tied into the (c)Python release cycle, the PEP process or anything else, they can just get on with it. Consider my approach many blue moons ago when I was asking when the "new" regex module was going to be incorporated into Python, and getting a bit miffed in my normal XXXL size hat autistic way when it didn't happen. I am now convinved that back then I was very firmly wrong, and that staying out of the stdlib has been the best thing that could have happened to regex. No doubt MRAB will disagree :) -- Kindest regards. Mark Lawrence. From tjreedy at udel.edu Mon Sep 18 18:12:45 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 18 Sep 2017 18:12:45 -0400 Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" In-Reply-To: <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> Message-ID: On 9/18/2017 5:21 PM, John Ladasky wrote: > On Saturday, September 16, 2017 at 11:01:03 PM UTC-7, Terry Reedy wrote: >> On 9/16/2017 7:04 PM, b... at g...com wrote: > >> The particular crippler for CLBG problems is the non-use of numpy in >> numerical calculations, such as the n-body problem. Numerical python >> extensions are over two decades old and give Python code access to >> optimized, compiled BLAS, LinPack, FFTPack, and so on. The current one, >> numpy, is the third of the series. It is both a historical accident and >> a continuing administrative convenience that numpy is not part of the >> Python stdlib. > > OK, I found this statement intriguing. Honestly, I can't function without Numpy, but I have always assumed that many Python programmers do so. True. Very few websites need numpy. Ditto for some other categories. > Meanwhile: most of the time, I have no use for urllib, but that module is in the standard library. Urllib is comparable in scope to, say, BLAS, or even to the math + statistics module. And it is less dependent on particular systems. Django and associated modules, which is comparable, in its own way, to numpy + scipy, is also not in the stdlib, and should not be. > I noticed the adoption of the @ operation for matrix multiplication. I have yet to use it myself. > > So is there a fraction of the Python community that thinks that Numpy should in fact become part of the Python stdlib? Only naive beginners, I should think. > What is the "administrative convenience" to which you refer? Numerical analysis is quite different from compiler construction and communication protocols. So numpy needs its own set of developers, policies, decision process, release schedule, etc. It took an expert in the field to persuade the numerical and numarray people to join together to produce numpy. PSF provides the infrastructure that makes 'pip install numpy' or 'pip install django' possible. Separate groups provide the content. Does this make sense? -- Terry Jan Reedy From ofekmeister at gmail.com Mon Sep 18 18:26:03 2017 From: ofekmeister at gmail.com (ofekmeister at gmail.com) Date: Mon, 18 Sep 2017 15:26:03 -0700 (PDT) Subject: Hatch - A modern project, package, and virtual env manager In-Reply-To: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> References: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> Message-ID: <7fa29e61-cbbe-40ef-ba7c-bcca9cf6d9bb@googlegroups.com> Hatch now supports per-project package management! https://github.com/ofek/hatch/blob/master/HISTORY.rst#0140 From ethan at stoneleaf.us Mon Sep 18 18:29:46 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 18 Sep 2017 15:29:46 -0700 Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" In-Reply-To: <59be2eef$0$16750$b1db1813$d948b532@news.astraweb.com> References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <59be2eef$0$16750$b1db1813$d948b532@news.astraweb.com> Message-ID: <59C048DA.6030607@stoneleaf.us> On 09/17/2017 01:14 AM, Steve D'Aprano wrote: > On Sun, 17 Sep 2017 04:16 pm, Terry Reedy wrote: > >> On 9/17/2017 2:04 AM, Chris Angelico wrote: >>> On Sun, Sep 17, 2017 at 4:00 PM, Terry Reedy wrote: >>>> The numerical extensions have been quasi-official in the sense that at least >>>> 3 language enhancements have been make for their use. >>> >>> I know about the matrix multiplication operator. What are the other >>> two (or more)? >> >> Stride slicing, which later became valid in regular code, and Ellipsis. >> (I could be wrong on the latter.) > > > Nope, both are correct. Weren't the rich comparison operators* also motivated by the numerical/scientific community? -- ~Ethan~ * __le__, __gt__, etc. From python at mrabarnett.plus.com Mon Sep 18 20:13:23 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 19 Sep 2017 01:13:23 +0100 Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" In-Reply-To: References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> Message-ID: On 2017-09-18 23:08, breamoreboy at gmail.com wrote: > On Monday, September 18, 2017 at 10:21:55 PM UTC+1, John Ladasky wrote: >> On Saturday, September 16, 2017 at 11:01:03 PM UTC-7, Terry Reedy wrote: >> > On 9/16/2017 7:04 PM, b... at g...com wrote: >> >> > The particular crippler for CLBG problems is the non-use of numpy in >> > numerical calculations, such as the n-body problem. Numerical python >> > extensions are over two decades old and give Python code access to >> > optimized, compiled BLAS, LinPack, FFTPack, and so on. The current one, >> > numpy, is the third of the series. It is both a historical accident and >> > a continuing administrative convenience that numpy is not part of the >> > Python stdlib. >> >> OK, I found this statement intriguing. Honestly, I can't function without Numpy, but I have always assumed that many Python programmers do so. Meanwhile: most of the time, I have no use for urllib, but that module is in the standard library. >> >> I noticed the adoption of the @ operation for matrix multiplication. I have yet to use it myself. >> >> So is there a fraction of the Python community that thinks that Numpy should in fact become part of the Python stdlib? What is the "administrative convenience" to which you refer? > > My very opinionated personnal opinion is that many third party libraries are much better off outside of the stdlib, numpy particulary so as it's one of the most used, if not the most used, such libraries. > > My rationale is simple, the authors of the libraries are not tied into the (c)Python release cycle, the PEP process or anything else, they can just get on with it. > > Consider my approach many blue moons ago when I was asking when the "new" regex module was going to be incorporated into Python, and getting a bit miffed in my normal XXXL size hat autistic way when it didn't happen. I am now convinved that back then I was very firmly wrong, and that staying out of the stdlib has been the best thing that could have happened to regex. No doubt MRAB will disagree :) > I was, at one time, in favour of including it in the stdlib, but then I changed my mind. Being outside the stdlib _does_ give me more flexibility. I can, as you said, just get on with it. I even have it on a Raspberry Pi. "pip install regex" is all it took. No need for it to be in the stdlib. :-) From steve+python at pearwood.info Mon Sep 18 20:19:47 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 19 Sep 2017 10:19:47 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> <403e2c01-66d5-43e9-ae50-cde8fc14e564@googlegroups.com> <716969d9-15aa-4966-a8ea-559e14c3dcf6@googlegroups.com> Message-ID: <59c062a5$0$14959$b1db1813$d948b532@news.astraweb.com> On Mon, 18 Sep 2017 11:00 pm, Rustom Mody wrote: >> {None, 0, "" {}, []} ? False >> Everything_else ? True >> >> This mapping is neither obvious nor trivial > > Sufficiently non-obvious that I missed the key element: > {None, 0, "" {}, [], False} ? False I thought it was intentional, because there's nothing more obvious than that False is false. Unless you're a pedant and completist like me, why even bother mentioning that False is falsey? Especially since you left out so many more obvious values. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rantingrickjohnson at gmail.com Mon Sep 18 20:23:12 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 18 Sep 2017 17:23:12 -0700 (PDT) Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" In-Reply-To: <59bdd776$0$16734$b1db1813$d948b532@news.astraweb.com> References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <59bdd776$0$16734$b1db1813$d948b532@news.astraweb.com> Message-ID: On Saturday, September 16, 2017 at 9:01:41 PM UTC-5, Steve D'Aprano wrote: > [...] > - a giant down-pointing arrowhead, about three inches tall, > which turns grey when you mouse-over it but doesn't do > anything when clicked; Oh, it does something, just not an _obvious_ something. LOL. I tried to warn you about the dangers of implicitness, but alas, you had to learn the hard way! Steven, you should know better than to click on giant arrow buttons. At this moment, some Russian hacker is sifting through your browser history. Might be a good idea to cancel your credit cards... >[...] > And that's not even counting any additional files the page > requires, like CSS, external javascript files, images, ads, > web-bugs, etc. You want to know why browsing the web today > on full ADSL or faster speeds is *slower* than using a dial > up modem in the 1990s? This is why. > > www.antipope.org/charlie/blog-static/2008/05/why_your_internet_experience_i.html > > Nine years later, and the problem is worse, not better. I was wondering what could compel you to go off on such a ridiculous rant over a simple slow loading page, but now i'm starting to think this is all a giant charade so you could direct traffic to some random blog. From steve+python at pearwood.info Mon Sep 18 21:44:34 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 19 Sep 2017 11:44:34 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> Message-ID: <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> On Tue, 19 Sep 2017 12:31 am, Ben Bacarisse wrote: > Was the result of 1/2 determined > by a poll to find out what most people expected? No. It was determined by the fact that a decade or more of experience with the language demonstrated that the Python 2 behaviour was a terrible mistake and a continual source of bugs in code because the / operator would silently change its function and return garbage results depending on the precise type of the numeric arguments. I specify *numeric* arguments because I don't want people derailing this in a general rant about operator overloading. I'm not talking about "if you pass a Widget instead of a float, you get an unexpected different Widget". Rather, I am talking about "if you pass 2 instead of 2.0, you get an answer of 34.72 instead of the correct answer of 35.47" kinds of errors. Silent failures that return garbage results. A simple (if perhaps artificial) example: harmonic mean. >>> 1/sum(1/x for x in [1.0, 2.0, 5.5, 3.2, 4.0]) # Correct. 0.4455696202531646 >>> 1/sum(1/x for x in [1.0, 2, 5.5, 3.2, 4.0]) # Oops. 0.57328990228013033 > But there is a stronger claim (which I think you also made) that a > floating point result is the correct one. However, some people with > little experience of floating point arithmetic (I certainly can't say > most but it must be quite few) will expect > > 1/10 > > to return a tenth. For /them/, the floating point result is silently > wrong and a source of bugs. It does return a tenth, or rather the closest possible result to a tenth representable. It is true that binary floats have some unexpected properties. They aren't the real numbers that we learn in maths. But most people who have been to school have years of experience with calculators training them to expect computer calculations are sometimes "off". They do a sum and get 2.999999999 instead of 3, or perhaps 3.000000001, and that's just the way calculators work. And then a small but vocal minority get a bit more experience with computers and forget what they had already learned and make the novice mistake of expecting floats to be infinitely precise real numbers, then complain that "Python is inaccurate" on the bug tracker. Of course they don't bother to do even a cursory search before raising an issue, or read the documentation, or the FAQs, or do the tutorial. > If I were aiming a language at beginners, > I'd make 1/10 be a rational or a type error. You would make it a type error? Why, do you hate beginners and want to punish them for typing to learn your language? Fortunately Python is not a language that is purely aimed at beginners. Python doesn't go out of its way to be hostile to anyone, let alone beginners, but it doesn't compromise or stint on functionality just so that novices to programming have a microscopically easier first week. > However, I don't think that is Python's main demographic, so 1/10 giving > something not quite one tenth may well be the correct design choice. Indeed. There are three obvious choices for regular division of integers. All have disadvantages: - Return a binary float. This has the advantage that it is the most common, and the fastest, and that computationally binary floats have the smallest "wobble" of any numeric base. If you are serious about floating point accuracy and stability, you probably want binary floats. But like all floating point formats, it has the disadvantages that many calculations can suffer from rounding errors, and that certain "ordinary looking" decimal values, like 0.1, cannot be represented exactly. - Return a decimal float. This has the advantage that "ordinary looking" values like 0.1 can be represented exactly, but otherwise is subject to precisely the same rounding errors as binary floats, plus the additional problem that the errors can be significantly larger, leading to even more numeric instability. And just like binary, there are still ordinary fractions which cannot be expressed exactly, like 1/3. - Return an exact rational number, a fraction. While these are exact, this has the disadvantage that fractions are not as practical as decimals for humans. Rational arithmetic is also much slower than floating point, and that many perfectly innocent-looking calculations can explode into ridiculously huge numbers of digits, leading to excessive memory use and even more performance degradation. Guido strongly dislikes the rational option because of his experience with ABC, where simple-looking calculations would often grind to a halt as they calculated fractions with millions or billions of digits in the numerators and denominators, for numbers which were well within the range of a float. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From russel at winder.org.uk Mon Sep 18 22:52:02 2017 From: russel at winder.org.uk (Russel Winder) Date: Tue, 19 Sep 2017 03:52:02 +0100 Subject: [Scons-dev] SCons 3.0.0 release In-Reply-To: References: Message-ID: <1505789522.10873.3.camel@winder.org.uk> Bill, Excellent. Thanks for putting in so much effort so as to make this happen. Can we switch to hosting the release tarballs on GitHub as the primary location? -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder at ekiga.net 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel at winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder -------------- 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 dan at tombstonezero.net Mon Sep 18 23:23:15 2017 From: dan at tombstonezero.net (Dan Sommers) Date: Tue, 19 Sep 2017 03:23:15 +0000 (UTC) Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> Message-ID: On Tue, 19 Sep 2017 01:56:29 +0000, Stefan Ram wrote: > Steve D'Aprano writes: >>It is true that binary floats have some unexpected properties. They >>aren't the real numbers that we learn in maths. But most people who >>have been to school have years of experience with calculators training >>them to expect computer calculations are sometimes "off". They do a >>sum and get 2.999999999 instead of 3, or perhaps 3.000000001, and >>that's just the way calculators work. > It is possible that many calculators use base 10 and therefore such > surprises might be less common than in the world of programming > languages. How relevant is the "people use calculators to do arithmetic" argument today? Okay, so I'm old and cynical, but I know [young] people who don't (can't?) calculate a gratuity without an app or a web page. FWIW, I would prefer that 1/10 be a rational because rationals are exact when the operands are. Rounding could easily fall under "In the face of ambiguity, refuse to guess." Yes, every once in a while, I get a result with lots of digits, but that's usually while I'm developing an algorithm, and then I can decide whether or not and when to coerce the result to floating point. Dan From john_ladasky at sbcglobal.net Tue Sep 19 02:54:55 2017 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Mon, 18 Sep 2017 23:54:55 -0700 (PDT) Subject: Stdlib, what's in, what's out (was: "Energy Efficiency across Programming Languages") In-Reply-To: References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> Message-ID: <97a340e6-e4e3-4c6e-b14d-59ea40f5471b@googlegroups.com> On Monday, September 18, 2017 at 5:13:58 PM UTC-7, MRAB wrote: > On 2017-09-18 23:08, b... at g...com wrote: > > My rationale is simple, the authors of the libraries are not tied into the (c)Python release cycle, the PEP process or anything else, they can just get on with it. > > > > Consider my approach many blue moons ago when I was asking when the "new" regex module was going to be incorporated into Python, and getting a bit miffed in my normal XXXL size hat autistic way when it didn't happen. I am now convinved that back then I was very firmly wrong, and that staying out of the stdlib has been the best thing that could have happened to regex. No doubt MRAB will disagree :) > > > I was, at one time, in favour of including it in the stdlib, but then I > changed my mind. Being outside the stdlib _does_ give me more > flexibility. I can, as you said, just get on with it. > I even have it on a Raspberry Pi. "pip install regex" is all it took. No > need for it to be in the stdlib. :-) Inadvertently, you have just pointed out a weakness of not including something important and great in the stdlib. There's an alternative to the re module, which at least a few members of the community consider to be superior, and which might therefore be widely used. But... until now, I'd never heard of it. I have come to understand from your other posts that adding something to the stdlib imposes significant constraints on the release schedules of those modules. I can appreciate the hassle that might cause. Still, now I wonder what I might be missing. From steve+comp.lang.python at pearwood.info Tue Sep 19 03:07:42 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2017 07:07:42 GMT Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> On Tue, 19 Sep 2017 03:23:15 +0000, Dan Sommers wrote: > On Tue, 19 Sep 2017 01:56:29 +0000, Stefan Ram wrote: > >> Steve D'Aprano writes: > >>>It is true that binary floats have some unexpected properties. They >>>aren't the real numbers that we learn in maths. But most people who >>>have been to school have years of experience with calculators training >>>them to expect computer calculations are sometimes "off". They do a sum >>>and get 2.999999999 instead of 3, or perhaps 3.000000001, and that's >>>just the way calculators work. > >> It is possible that many calculators use base 10 and therefore such >> surprises might be less common than in the world of programming >> languages. > > How relevant is the "people use calculators to do arithmetic" argument > today? Okay, so I'm old and cynical, but I know [young] people who > don't (can't?) calculate a gratuity without an app or a web page. Which is a form of calculator. People still learn to use calculators at school, they still use them at work. They use Excel, which is prone to the same issue. Calculating 15% of $37.85 returns 5.6775 in both Python and on my cheap four-function calculator, and I'm sure my phone would give the same answer. 5.6775 is a much more useful answer than Fraction(2271, 400). ("What's that in real money?") > FWIW, I would prefer that 1/10 be a rational because rationals are exact > when the operands are. Rounding could easily fall under "In the face of > ambiguity, refuse to guess." Perhaps if you didn't understand how numbers are rounded and thought it was a guess. There's nothing ambiguous in correct rounding. IEEE-754 arithmetic is correctly rounded: the operations of addition, subtraction, multiplication, division, and square root are correctly rounded for every combination of float arguments. Assuming your platform provides properly compliant IEEE-754 arithmetic. Things are not as bad as they used to be in the Bad Old Days when computers couldn't even agree on what *zero* was, but there's still room for improvement. Ironically, your comment about ambiguity would be reasonable for, say, trig functions, logarithms, and the like. But in those cases, calculating the exact answer as a rational is usually impossible. Even something as simple as log(2) would require an infinite amount of memory, and infinite time, to express exactly as a fraction. > Yes, every once in a while, I get a result > with lots of digits, but that's usually while I'm developing an > algorithm, and then I can decide whether or not and when to coerce the > result to floating point. I guess that you must have pretty simple algorithms then. No square roots, no trig, no exponentiation except for positive integer powers, little or no iteration. Outside of some pretty specialised fields, there's a reason why the numeric community has standardised on floating point maths. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From antoon.pardon at vub.be Tue Sep 19 03:10:04 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 19 Sep 2017 09:10:04 +0200 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> Message-ID: <0a799ad2-4ba5-6c94-015b-8885082c11d2@vub.be> Op 18-09-17 om 15:47 schreef Paul Moore: > On 18 September 2017 at 14:30, Antoon Pardon wrote: >> Well that you reduce an object to a boolean value is not obvious to >> begin with. A TypeError because you are treating a non-boolean as >> a boolean would have been more obvious to me. > More obvious, possibly - that's essentially a matter of what people > are used to, and a measure of personal opinion. > > More useful? Unlikely. The practical examples I've seen of languages > like Python that implicitly convert non-boolean values to boolean, and > languages that don't (and raise an error if a non-boolean is supplied > to an if statement) suggest to me that implicit conversion is highly > useful. I certainly use it in my code (although in my view it's > perfectly "obvious", so I may use constructs that you would find > non-obvious). I don't find it really usefull. How useful is it that you can type if a: instead of if a != 0: ? I have yet to encounter a situation where I thought: Yes I want to execute this piece of code when a value is Falsy and an other piece when that same value is Truthy. What usually happens, is that the programmer expect only values from a specific domain and that as long as that restriction is obeyed, he can express what he wants in terms of truthy and falsy values, but it doesn't mean that he wants False, None and [] treated the same way. So I find code that uses the domain specific condition more clear and less error-prone than code that abstracts that domain specific condition into the truthy-falsy distinction python makes. ? >> A second thought is that it isn't obvious that empty strings, lists ... >> should be thought of as falsy. Sometimes I am treating a stream of >> values/objects and when I ask for the next available items, i get >> a string/list. An empty string/list in that context would mean that >> nothing was available, but it is possible that more will be available >> later and so could be treated just like a non-empty list/string. > We can argue over the precise rules as to *what* boolean values Python > chooses to take particular non-boolean values as meaning. I'm not > going to have a blazing row over whether an empty string should be > true or false. But equally, I'm not going to mount a campaign to > change it. It's just not that important to me. Why do you find it necessary to say this? I'm not mounting a campaign to change anything either. I just think people are to eager to use the word "obvious" when defending certain design choices made in python. -- Antoon Pardon From steve+comp.lang.python at pearwood.info Tue Sep 19 03:11:45 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2017 07:11:45 GMT Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> Message-ID: <59c0c330$0$14961$b1db1813$d948b532@news.astraweb.com> On Tue, 19 Sep 2017 01:13:23 +0100, MRAB wrote: > I even have it on a Raspberry Pi. "pip install regex" is all it took. No > need for it to be in the stdlib. :-) That's fine for those of us who can run pip and install software from the web without being immediately fired, and for those who have installation rights on the computers they use. And those with easy, cheap and fast access to the internet. Not everyone is so lucky. There is a significant chunk of the Python community for whom "just pip install it" is not easy, legal or even possible. For them, if its not in the standard library, it might as well not even exist. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From antoon.pardon at vub.be Tue Sep 19 03:22:21 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 19 Sep 2017 09:22:21 +0200 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> Message-ID: <60e3872e-5549-fe2c-0ad0-35d2f95efe6c@vub.be> Op 18-09-17 om 15:58 schreef Chris Angelico: > On Mon, Sep 18, 2017 at 11:30 PM, Antoon Pardon wrote: > >> Well that you reduce an object to a boolean value is not obvious to >> begin with. A TypeError because you are treating a non-boolean as >> a boolean would have been more obvious to me. > Sure, but those are basically your only two options. Either you have a > way of interpreting some/all objects as booleans, or you require an > explicit conversion. In Python syntax: > > # Interpret all objects as boolean: > if x: pass > > # Require explicit conversion or comparison: > if bool(x): pass > if x == True: pass > > But not BOTH of the above: > > if bool(x) == True: pass > > That's pointless. It's not "more explicit". It's just more redundant. But the problem is that the following two pieces of code don't do the same in Python. if x: pass if x is True: pass Sometimes I need that second statement but I can be sure that should I show a piece of code on this mailing list with that statement, all kind of remarks about it being redundant will surface. The fact that x will be interpreted as a boolean even if it isn't means that I need that second statement when I want to do something only when the value of x is True. -- Antoon Pardon. From rosuav at gmail.com Tue Sep 19 03:40:08 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Sep 2017 17:40:08 +1000 Subject: [Tutor] beginning to code In-Reply-To: <0a799ad2-4ba5-6c94-015b-8885082c11d2@vub.be> References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <0a799ad2-4ba5-6c94-015b-8885082c11d2@vub.be> Message-ID: On Tue, Sep 19, 2017 at 5:10 PM, Antoon Pardon wrote: > Op 18-09-17 om 15:47 schreef Paul Moore: >> On 18 September 2017 at 14:30, Antoon Pardon wrote: >>> Well that you reduce an object to a boolean value is not obvious to >>> begin with. A TypeError because you are treating a non-boolean as >>> a boolean would have been more obvious to me. >> More obvious, possibly - that's essentially a matter of what people >> are used to, and a measure of personal opinion. >> >> More useful? Unlikely. The practical examples I've seen of languages >> like Python that implicitly convert non-boolean values to boolean, and >> languages that don't (and raise an error if a non-boolean is supplied >> to an if statement) suggest to me that implicit conversion is highly >> useful. I certainly use it in my code (although in my view it's >> perfectly "obvious", so I may use constructs that you would find >> non-obvious). > > I don't find it really usefull. How useful is it that you can type > if a: instead of if a != 0: ? I have yet to encounter a situation > where I thought: Yes I want to execute this piece of code when > a value is Falsy and an other piece when that same value is Truthy. Okay. Let me ask you a different question. Given that you can do this: if x > 5: should you be able to do this: condition = (x > 5) if condition: ? If "no", then you've just downgraded booleans to less than first-class values. If "yes", then you've just opened up the possibility for "if x:", and you have to draw the line somewhere - what can you and what can't you use that way? It's now syntactically legal to use "if x:" with any type of object, so you have to either define the truthiness/falsiness of everything, or have some of them raise TypeError. ChrisA From rosuav at gmail.com Tue Sep 19 03:46:32 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Sep 2017 17:46:32 +1000 Subject: [Tutor] beginning to code In-Reply-To: <60e3872e-5549-fe2c-0ad0-35d2f95efe6c@vub.be> References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <60e3872e-5549-fe2c-0ad0-35d2f95efe6c@vub.be> Message-ID: On Tue, Sep 19, 2017 at 5:22 PM, Antoon Pardon wrote: > But the problem is that the following two pieces of code don't do > the same in Python. > > if x: pass > if x is True: pass > > Sometimes I need that second statement but I can be sure that > should I show a piece of code on this mailing list with that > statement, all kind of remarks about it being redundant will > surface. The fact that x will be interpreted as a boolean > even if it isn't means that I need that second statement > when I want to do something only when the value of x is True. Correct, they're not identical. Under what circumstances do you need to test for the singleton True value and *not* for truthiness? If this came up in code review, I would first assume that it's simple redundancy, because otherwise I have to assume some extremely weird use of a variable that could be True and could be some other truthy value. At very least, a check "if x is True:" needs a comment with it. And in trying to concoct plausible use-cases, I keep falling back on something like this: # Display booleans differently if x is True: ... display flag else: ... display number which would be better represented with "if isinstance(x, bool):" instead. So "if x is True:" remains odd code, the sort of thing that MUST be annotated or I would be raising a red flag. Can you give an actual real-world example where this comes up? ChrisA From rosuav at gmail.com Tue Sep 19 03:59:10 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Sep 2017 17:59:10 +1000 Subject: Old Man Yells At Cloud In-Reply-To: <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: On Tue, Sep 19, 2017 at 5:07 PM, Steven D'Aprano wrote: > On Tue, 19 Sep 2017 03:23:15 +0000, Dan Sommers wrote: > >> On Tue, 19 Sep 2017 01:56:29 +0000, Stefan Ram wrote: >> >>> Steve D'Aprano writes: >> >>>>It is true that binary floats have some unexpected properties. They >>>>aren't the real numbers that we learn in maths. But most people who >>>>have been to school have years of experience with calculators training >>>>them to expect computer calculations are sometimes "off". They do a sum >>>>and get 2.999999999 instead of 3, or perhaps 3.000000001, and that's >>>>just the way calculators work. >> >>> It is possible that many calculators use base 10 and therefore such >>> surprises might be less common than in the world of programming >>> languages. >> >> How relevant is the "people use calculators to do arithmetic" argument >> today? Okay, so I'm old and cynical, but I know [young] people who >> don't (can't?) calculate a gratuity without an app or a web page. > > Which is a form of calculator. People still learn to use calculators at > school, they still use them at work. They use Excel, which is prone to > the same issue. > > Calculating 15% of $37.85 returns 5.6775 in both Python and on my cheap > four-function calculator, and I'm sure my phone would give the same > answer. > > 5.6775 is a much more useful answer than Fraction(2271, 400). ("What's > that in real money?") Sounds like you want a display formatting feature. I wonder how Python code would display a number... >>> f = fractions.Fraction(2271, 400) >>> "$%.2f" % f '$5.68' Looks like money to me. > Ironically, your comment about ambiguity would be reasonable for, say, > trig functions, logarithms, and the like. But in those cases, calculating > the exact answer as a rational is usually impossible. Even something as > simple as log(2) would require an infinite amount of memory, and infinite > time, to express exactly as a fraction. Yeah, logarithms would have to be defined to return floats. Fortunately, the math module seems pretty happy to accept fractions: >>> math.log(f) 1.7365109949975766 >>> math.sin(f) -0.5693256092491197 >>> math.sqrt(f) 2.382750511488771 >> Yes, every once in a while, I get a result >> with lots of digits, but that's usually while I'm developing an >> algorithm, and then I can decide whether or not and when to coerce the >> result to floating point. > > I guess that you must have pretty simple algorithms then. No square > roots, no trig, no exponentiation except for positive integer powers, > little or no iteration. > > Outside of some pretty specialised fields, there's a reason why the > numeric community has standardised on floating point maths. Aside from the backward compatibility concerns (which mean that this can't be done in a language that calls itself "Python"), I'm not seeing any reason that a human-friendly language can't spend most of its time working with arbitrary-precision rationals, only switching to floats when (a) the programmer explicitly requests it, or (b) when performing operations that fundamentally cannot be performed with rationals. ChrisA From stefan_ml at behnel.de Tue Sep 19 04:05:27 2017 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 19 Sep 2017 10:05:27 +0200 Subject: Stdlib, what's in, what's out In-Reply-To: <97a340e6-e4e3-4c6e-b14d-59ea40f5471b@googlegroups.com> References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> <97a340e6-e4e3-4c6e-b14d-59ea40f5471b@googlegroups.com> Message-ID: John Ladasky schrieb am 19.09.2017 um 08:54: > I have come to understand from your other posts that adding something to > the stdlib imposes significant constraints on the release schedules of > those modules. I can appreciate the hassle that might cause. Still, > now I wonder what I might be missing. There are many packages on PyPI that reimplement functionality of the stdlib in some "better" way, by their own definition of "better". Some are faster, some are more feature-rich, some have a better API, some focus on making specific special cases faster/easier/whatever. The stdlib is there to provide a base level of functionality. That base level tends to be much higher up than in most other programming languages, but from the point of view of Python, it's still just a base level, however comfortable it might be. If you need specific features, more speed, can't live with a certain API or feel that you are wasting too much developer time by doing something the way you always did it, search PyPI for something "better" by your own definition at a given time. If you can live with what the stdlib provides, stick to it. Keeping foreign dependencies low is also "better" in some cases. Stefan From mail at timgolden.me.uk Tue Sep 19 04:11:43 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 19 Sep 2017 09:11:43 +0100 Subject: Stdlib, what's in, what's out In-Reply-To: References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> <97a340e6-e4e3-4c6e-b14d-59ea40f5471b@googlegroups.com> Message-ID: On 19/09/2017 09:05, Stefan Behnel wrote: > The stdlib is there to provide a base level of functionality. That base > level tends to be much higher up than in most other programming languages, > but from the point of view of Python, it's still just a base level, however > comfortable it might be. > > If you need specific features, more speed, can't live with a certain API or > feel that you are wasting too much developer time by doing something the > way you always did it, search PyPI for something "better" by your own > definition at a given time. > > If you can live with what the stdlib provides, stick to it. Keeping foreign > dependencies low is also "better" in some cases. Nice summary. TJG From antoon.pardon at vub.be Tue Sep 19 05:00:44 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 19 Sep 2017 11:00:44 +0200 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <0a799ad2-4ba5-6c94-015b-8885082c11d2@vub.be> Message-ID: <6b40f3f3-7cdf-4ad1-0140-e152a76eac2f@vub.be> Op 19-09-17 om 09:40 schreef Chris Angelico: > On Tue, Sep 19, 2017 at 5:10 PM, Antoon Pardon wrote: > >> I don't find it really usefull. How useful is it that you can type >> if a: instead of if a != 0: ? I have yet to encounter a situation >> where I thought: Yes I want to execute this piece of code when >> a value is Falsy and an other piece when that same value is Truthy. > Okay. Let me ask you a different question. > > Given that you can do this: > > if x > 5: > > should you be able to do this: > > condition = (x > 5) > if condition: > > ? If "no", then you've just downgraded booleans to less than > first-class values. If "yes", then you've just opened up the > possibility for "if x:", and you have to draw the line somewhere - > what can you and what can't you use that way? It's now syntactically > legal to use "if x:" with any type of object, so you have to either > define the truthiness/falsiness of everything, or have some of them > raise TypeError. Yes you have to draw the line somewhere. But there is a difference between one the one hand stating that the line had to be drawn somewhere and that through design and history this is what we ended up with and although it may be interesting to argue the pro and con of this and various other possibilities, this is workable and so highly unlikely to change. or on the other hand stating or suggesting this is the obvious place to draw that line and we would miss something really useful had the line be drawn somewhere else. -- Antoon Pardon From antoon.pardon at vub.be Tue Sep 19 05:21:03 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 19 Sep 2017 11:21:03 +0200 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <60e3872e-5549-fe2c-0ad0-35d2f95efe6c@vub.be> Message-ID: <80deccc2-683c-4e88-ba5b-a5ce2e4f3bcf@vub.be> Op 19-09-17 om 09:46 schreef Chris Angelico: > On Tue, Sep 19, 2017 at 5:22 PM, Antoon Pardon wrote: >> But the problem is that the following two pieces of code don't do >> the same in Python. >> >> if x: pass >> if x is True: pass >> > ... > > which would be better represented with "if isinstance(x, bool):" > instead. So "if x is True:" remains odd code, the sort of thing that > MUST be annotated or I would be raising a red flag. Can you give an > actual real-world example where this comes up? The time I used it was when I had some class that the user had to somehow activate. An instance could internally be in three states but the user had only access to two, he had activated it or not. The internal "active" attribute could be: 1) False: The user hasn't activated it. 2) True: The user has activated it, but there was no active background machinery yet/anymore. 3) A handle to the active background machinery. Maybe I should have used an internal "state" attribute and an enum with the values unactivated and activated instead but the use of False and True in the circumstances above felt rather natural to me. -- Antoon Pardon. From steve+comp.lang.python at pearwood.info Tue Sep 19 05:22:11 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2017 09:22:11 GMT Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <0a799ad2-4ba5-6c94-015b-8885082c11d2@vub.be> Message-ID: <59c0e1c3$0$14961$b1db1813$d948b532@news.astraweb.com> On Tue, 19 Sep 2017 09:10:04 +0200, Antoon Pardon wrote: > Op 18-09-17 om 15:47 schreef Paul Moore: >> On 18 September 2017 at 14:30, Antoon Pardon >> wrote: >>> Well that you reduce an object to a boolean value is not obvious to >>> begin with. A TypeError because you are treating a non-boolean as a >>> boolean would have been more obvious to me. >> More obvious, possibly - that's essentially a matter of what people are >> used to, and a measure of personal opinion. >> >> More useful? Unlikely. The practical examples I've seen of languages >> like Python that implicitly convert non-boolean values to boolean, and >> languages that don't (and raise an error if a non-boolean is supplied >> to an if statement) suggest to me that implicit conversion is highly >> useful. I certainly use it in my code (although in my view it's >> perfectly "obvious", so I may use constructs that you would find >> non-obvious). > > I don't find it really usefull. How useful is it that you can type if a: > instead of if a != 0: ? How useful is duck-typing? How useful is it to type: if a or b or c: ... instead of: if a.condition() or predicate(b) or c.somecondition(): ... Objects already know how to convert themselves to strings, to generate a repr, how to convert themselves to an iterator (if possible), etc. We don't hesitate to duck-type any of these things and expect objects to manage their own conversions. Except for bools, where people freak out and are convinced the world will end if you just ask an object "are you true or false?". Perhaps just a *tiny* exaggeration *wink* > I have yet to encounter a situation where I > thought: Yes I want to execute this piece of code when a value is Falsy > and an other piece when that same value is Truthy. But that's exactly what you've done with "if a != 0". You *literally* executed code according to the truthiness of a. Only you did it with more typing. But for what its worth, I do allow that comparing numbers to zero is sometimes the right thing to do. Sometimes you're not treating zero as a falsey value, its just another number that happens to need special treatment. In this case, it might not be appropriate to duck-type your number as a bool, when your intent is specifically to compare it against a value which merely happens to be zero. Especially for pure mathematical functions: def sinc(x): if x == 0: return 1 else: return sin(x)/x and even more so if 0 is just one case out of many: def somefunc(x): if x == -1: ... elif x == 0: ... elif x == 1: ... else: ... > What usually happens, is that the programmer expect only values from a > specific domain and that as long as that restriction is obeyed, he can > express what he wants in terms of truthy and falsy values, but it > doesn't mean that he wants False, None and [] treated the same way. Then don't treat them the same. You always have the option of writing code which is as finicky and idiosyncratic as you want: if x is False: ... elif x is None: ... elif x == []: ... > So I find code that uses the domain specific condition more clear and > less error-prone than code that abstracts that domain specific condition > into the truthy-falsy distinction python makes. "Less error-prone" -- got some examples of the errors that duck-typing truthiness causes? -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From rosuav at gmail.com Tue Sep 19 05:27:01 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Sep 2017 19:27:01 +1000 Subject: [Tutor] beginning to code In-Reply-To: <80deccc2-683c-4e88-ba5b-a5ce2e4f3bcf@vub.be> References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <60e3872e-5549-fe2c-0ad0-35d2f95efe6c@vub.be> <80deccc2-683c-4e88-ba5b-a5ce2e4f3bcf@vub.be> Message-ID: On Tue, Sep 19, 2017 at 7:21 PM, Antoon Pardon wrote: > Op 19-09-17 om 09:46 schreef Chris Angelico: >> On Tue, Sep 19, 2017 at 5:22 PM, Antoon Pardon wrote: >>> But the problem is that the following two pieces of code don't do >>> the same in Python. >>> >>> if x: pass >>> if x is True: pass >>> >> ... >> >> which would be better represented with "if isinstance(x, bool):" >> instead. So "if x is True:" remains odd code, the sort of thing that >> MUST be annotated or I would be raising a red flag. Can you give an >> actual real-world example where this comes up? > > The time I used it was when I had some class that the user had to > somehow activate. An instance could internally be in three states > but the user had only access to two, he had activated it or not. > The internal "active" attribute could be: > > 1) False: The user hasn't activated it. > 2) True: The user has activated it, but there was no active background machinery yet/anymore. > 3) A handle to the active background machinery. > > Maybe I should have used an internal "state" attribute and an enum > with the values unactivated and activated instead but the use of > False and True in the circumstances above felt rather natural to me. Fair enough - but that is extremely rare and needs a comment somewhere. But personally, I'd use other singletons rather than False and True. For instance, None to mean "not activated", and have a dedicated object representing the state of "no active background machinery" - an object that has many (or all) of the methods of your machinery object, perhaps. In any case, this is NOT a precedent for normal boolean testing. It's an extreme case where you're doing something abnormal and have abnormal code as a result. ChrisA From steve+comp.lang.python at pearwood.info Tue Sep 19 05:28:40 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2017 09:28:40 GMT Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <60e3872e-5549-fe2c-0ad0-35d2f95efe6c@vub.be> Message-ID: <59c0e348$0$14961$b1db1813$d948b532@news.astraweb.com> On Tue, 19 Sep 2017 09:22:21 +0200, Antoon Pardon wrote: > But the problem is that the following two pieces of code don't do the > same in Python. > > if x: pass > if x is True: pass > > Sometimes I need that second statement "Need" is a funny thing. If all you are doing is testing the truthiness of x, which is what it looks like to me, why do you care that it is a bool, rather than an int 1 or a float or any other object? You probably don't insist that your lists are *actual* lists, any list- like object with the right interface will do. You probably don't insist that your iterators are *actual* IteratorType objects, which is good because there's no such thing and iterators come in many different types, all quacking and swimming the same. So why insist on True and False alone? That's a code smell. But okay, I'll give you the benefit of the doubt and assume you have a good reason. Okay, that's easy to fix: # We require actual True here, not just a truthy value. if x is True: pass If anyone insists on questioning this, you can just say "Yes, I hear you, but I have reasons, and you would need to understand our entire project to understand them, so just trust me." And the problem is solved. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From steve+comp.lang.python at pearwood.info Tue Sep 19 05:31:54 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2017 09:31:54 GMT Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c0e409$0$14961$b1db1813$d948b532@news.astraweb.com> On Tue, 19 Sep 2017 17:59:10 +1000, Chris Angelico wrote: > Aside from the backward compatibility concerns (which mean that this > can't be done in a language that calls itself "Python"), I'm not seeing > any reason that a human-friendly language can't spend most of its time > working with arbitrary-precision rationals, only switching to floats > when (a) the programmer explicitly requests it, or (b) when performing > operations that fundamentally cannot be performed with rationals. True, it can't be called Python. But it could be called EvenSlowerThanPythonYouReallyDontWantToDoAnySeriousNumericWorkWithThis instead. *wink* -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From steve+comp.lang.python at pearwood.info Tue Sep 19 05:34:13 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Sep 2017 09:34:13 GMT Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <60e3872e-5549-fe2c-0ad0-35d2f95efe6c@vub.be> Message-ID: <59c0e495$0$14961$b1db1813$d948b532@news.astraweb.com> On Tue, 19 Sep 2017 17:46:32 +1000, Chris Angelico wrote: > # Display booleans differently if x is True: > ... display flag > else: > ... display number > > which would be better represented with "if isinstance(x, bool):" Given that True is a singleton, it is redundant to write if isinstance(x, bool) and x: I'd write "if x is True" if I really, honestly wanted True specifically. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From rosuav at gmail.com Tue Sep 19 05:43:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Sep 2017 19:43:11 +1000 Subject: [Tutor] beginning to code In-Reply-To: <59c0e495$0$14961$b1db1813$d948b532@news.astraweb.com> References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <60e3872e-5549-fe2c-0ad0-35d2f95efe6c@vub.be> <59c0e495$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: On Tue, Sep 19, 2017 at 7:34 PM, Steven D'Aprano wrote: > On Tue, 19 Sep 2017 17:46:32 +1000, Chris Angelico wrote: > > >> # Display booleans differently if x is True: >> ... display flag >> else: >> ... display number >> >> which would be better represented with "if isinstance(x, bool):" > > Given that True is a singleton, it is redundant to write > > if isinstance(x, bool) and x: > > > I'd write "if x is True" if I really, honestly wanted True specifically. Right, but if there's a different display for True, there's probably also one for False. if isinstance(x, bool): print("Foo") else: print("Foo " % x) But you're right that checking for True specifically is best done as an identity check. if x is True: print("[x] Foo") elif x is False: print("[ ] Foo") else: print("Foo:", x) ChrisA From rosuav at gmail.com Tue Sep 19 05:44:03 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 19 Sep 2017 19:44:03 +1000 Subject: Old Man Yells At Cloud In-Reply-To: <59c0e409$0$14961$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <59c0e409$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: On Tue, Sep 19, 2017 at 7:31 PM, Steven D'Aprano wrote: > On Tue, 19 Sep 2017 17:59:10 +1000, Chris Angelico wrote: > >> Aside from the backward compatibility concerns (which mean that this >> can't be done in a language that calls itself "Python"), I'm not seeing >> any reason that a human-friendly language can't spend most of its time >> working with arbitrary-precision rationals, only switching to floats >> when (a) the programmer explicitly requests it, or (b) when performing >> operations that fundamentally cannot be performed with rationals. > > > True, it can't be called Python. But it could be called > EvenSlowerThanPythonYouReallyDontWantToDoAnySeriousNumericWorkWithThis > instead. > > > > *wink* I was thinking "Rational Python" to troll all the people who can't tell the difference between a rational number and a rational person. *wink* ChrisA From larry.martell at gmail.com Tue Sep 19 06:46:41 2017 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 19 Sep 2017 06:46:41 -0400 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> Message-ID: On Mon, Sep 18, 2017 at 11:23 PM, Dan Sommers wrote: > How relevant is the "people use calculators to do arithmetic" argument > today? Okay, so I'm old and cynical, but I know [young] people who > don't (can't?) calculate a gratuity without an app or a web page. I use a calculator all the time - not for calculating a tip though. Sometimes I use bc (when I can't find my calculator in the morass of my desk). True story - the other day I was in a store and my total was $10.12. I pulled out a $20, and the cashier (probably age 23 or so) immediately entered $20 as the amount tendered. Then I said "Let me see if I have the $0.12." I did not, but I had $0.15 so I handed her $20.15. She literally froze in place with a classic deer in the headlights stare. I said "$10.03" She said "What?" I said "$10.03 is my change." She said "What?" I said "Just give me $10." She did not reply, opened the drawer below her register, rummaged around and came out with one of those giant key calculators, and with a look of dogged determination, did the calculation, looked at me and said proudly "$10.03 is your change." From bc at freeuk.com Tue Sep 19 07:01:00 2017 From: bc at freeuk.com (bartc) Date: Tue, 19 Sep 2017 12:01:00 +0100 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> Message-ID: On 19/09/2017 11:46, Larry Martell wrote: > On Mon, Sep 18, 2017 at 11:23 PM, Dan Sommers wrote: >> How relevant is the "people use calculators to do arithmetic" argument >> today? Okay, so I'm old and cynical, but I know [young] people who >> don't (can't?) calculate a gratuity without an app or a web page. > > I use a calculator all the time - not for calculating a tip though. > Sometimes I use bc (when I can't find my calculator in the morass of > my desk). > > True story - the other day I was in a store and my total was $10.12. I > pulled out a $20, and the cashier (probably age 23 or so) immediately > entered $20 as the amount tendered. Then I said "Let me see if I have > the $0.12." I did not, but I had $0.15 so I handed her $20.15. She > literally froze in place with a classic deer in the headlights stare. > I said "$10.03" She said "What?" I said "$10.03 is my change." She > said "What?" I said "Just give me $10." She did not reply, opened the > drawer below her register, rummaged around and came out with one of > those giant key calculators, and with a look of dogged determination, > did the calculation, looked at me and said proudly "$10.03 is your > change." My bill in a store came to ?3.20 (GBP3.20), so I handed over ?10.20. I was given back ?16.90 in change! It turned out the cashier had entered ?20.10 as the amount tendered. It was sorted out in the end. Sometimes its easier not to be bother making the figures come out better. -- bartc From antoon.pardon at vub.be Tue Sep 19 07:10:35 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 19 Sep 2017 13:10:35 +0200 Subject: [Tutor] beginning to code In-Reply-To: <59c0e1c3$0$14961$b1db1813$d948b532@news.astraweb.com> References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <0a799ad2-4ba5-6c94-015b-8885082c11d2@vub.be> <59c0e1c3$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: <65a57c21-5b4c-86a6-ca7a-46fdc8b1822d@vub.be> Op 19-09-17 om 11:22 schreef Steven D'Aprano: > On Tue, 19 Sep 2017 09:10:04 +0200, Antoon Pardon wrote: > >> Op 18-09-17 om 15:47 schreef Paul Moore: >>> On 18 September 2017 at 14:30, Antoon Pardon >>> wrote: >>>> Well that you reduce an object to a boolean value is not obvious to >>>> begin with. A TypeError because you are treating a non-boolean as a >>>> boolean would have been more obvious to me. >>> More obvious, possibly - that's essentially a matter of what people are >>> used to, and a measure of personal opinion. >>> >>> More useful? Unlikely. The practical examples I've seen of languages >>> like Python that implicitly convert non-boolean values to boolean, and >>> languages that don't (and raise an error if a non-boolean is supplied >>> to an if statement) suggest to me that implicit conversion is highly >>> useful. I certainly use it in my code (although in my view it's >>> perfectly "obvious", so I may use constructs that you would find >>> non-obvious). >> I don't find it really usefull. How useful is it that you can type if a: >> instead of if a != 0: ? > How useful is duck-typing? > > How useful is it to type: > > if a or b or c: ... > > instead of: > > if a.condition() or predicate(b) or c.somecondition(): ... IMO not very much, in real life code, the latter code would probably much more clear than the former. > Objects already know how to convert themselves to strings, to generate a > repr, how to convert themselves to an iterator (if possible), etc. We > don't hesitate to duck-type any of these things and expect objects to > manage their own conversions. I am not so sure about strings. Otherwise there would be no need for all those formatting possibilities, that python provides. That the object knows how to convert itself to a string, doesn't mean it is the string that is useful to the user. > Except for bools, where people freak out and are convinced the world will > end if you just ask an object "are you true or false?". > > Perhaps just a *tiny* exaggeration *wink* On the other hand, python is very eager to convert objects to a bool. For strings and iterators you are expected to write a dunder method. If you think it makes no sense to see specific instances as true or false, you have to explicitly write a __bool__ that raises an exception. I think it would have been a better choice that a TypeError would have been raised if __bool__ wasn't defined. ? >> I have yet to encounter a situation where I >> thought: Yes I want to execute this piece of code when a value is Falsy >> and an other piece when that same value is Truthy. > But that's exactly what you've done with "if a != 0". You *literally* > executed code according to the truthiness of a. Only you did it with more > typing. But I was talking about how I *think* about those things. That after implementating these thoughts in python, python will cast all those things in the various concepts of truthy, doesn't contradict that was/is not how I approach(ed) the problems to be solved. -- Antoon Pardon From frank at chagford.com Tue Sep 19 07:51:25 2017 From: frank at chagford.com (Frank Millman) Date: Tue, 19 Sep 2017 13:51:25 +0200 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> Message-ID: "bartc" wrote in message news:EN6wB.770830$uh.63078 at fx28.am4... On 19/09/2017 11:46, Larry Martell wrote: > > > > True story - the other day I was in a store and my total was $10.12. I > > pulled out a $20, and the cashier (probably age 23 or so) immediately > > entered $20 as the amount tendered. Then I said "Let me see if I have > > the $0.12." I did not, but I had $0.15 so I handed her $20.15. She > > literally froze in place with a classic deer in the headlights stare. > > I said "$10.03" She said "What?" I said "$10.03 is my change." She > > said "What?" I said "Just give me $10." She did not reply, opened the > > drawer below her register, rummaged around and came out with one of > > those giant key calculators, and with a look of dogged determination, > > did the calculation, looked at me and said proudly "$10.03 is your > > change." > > My bill in a store came to ?3.20 (GBP3.20), so I handed over ?10.20. > > I was given back ?16.90 in change! > > It turned out the cashier had entered ?20.10 as the amount tendered. It > was sorted out in the end. > My favourite true story on this subject - In England, just after decimalisation was introduced, I was at a lunch with a few other people. When we asked the waitress for the bill, she brought out a hand-written list of what we had ordered (no computers or calculators in those days) and proceeded to add it up manually. The total, in new pence, came to four figures. She then, talking to herself, did the next bit of the calculation. 'Lets see, there are 100 new pence in a pound, so divide the total by 100, ...'. She worked the whole thing out using just pencil and paper, and then when she had written down the result, exclaimed 'Oh, it?s the same!'. Frank Millman From rustompmody at gmail.com Tue Sep 19 07:53:52 2017 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 19 Sep 2017 04:53:52 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <0a799ad2-4ba5-6c94-015b-8885082c11d2@vub.be> <59c0e1c3$0$14961$b1db1813$d948b532@news.astraweb.com> <65a57c21-5b4c-86a6-ca7a-46fdc8b1822d@vub.be> Message-ID: <5a340682-4314-4833-9249-530df3727243@googlegroups.com> On Tuesday, September 19, 2017 at 4:41:01 PM UTC+5:30, Antoon Pardon wrote: > Op 19-09-17 om 11:22 schreef Steven D'Aprano: > > Except for bools, where people freak out and are convinced the world will > > end if you just ask an object "are you true or false?". > > > > Perhaps just a *tiny* exaggeration *wink* > > On the other hand, python is very eager to convert objects to a bool. For > strings and iterators you are expected to write a dunder method. If you > think it makes no sense to see specific instances as true or false, you > have to explicitly write a __bool__ that raises an exception. I think > it would have been a better choice that a TypeError would have been > raised if __bool__ wasn't defined. How exceptional is python's choice to NOT raise exceptions can be seen by examples: >>> [] + 2 Traceback (most recent call last): File "", line 1, in TypeError: can only concatenate list (not "int") to list >>> [] < 0 Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: list() < int() >>> 1[2] Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not subscriptable >>> 2 < [] Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: int() < list() >>> len(2) Traceback (most recent call last): File "", line 1, in TypeError: object of type 'int' has no len() >>> [x for x in 1] Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable >>> -[] Traceback (most recent call last): File "", line 1, in TypeError: bad operand type for unary -: 'list' >>> [] or [] [] # Ah well... Same category as... >>> ("empty" if [] else "nonempty") 'nonempty' >>> From rhodri at kynesim.co.uk Tue Sep 19 07:56:35 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 19 Sep 2017 12:56:35 +0100 Subject: Old Man Yells At Cloud In-Reply-To: <871sn4qb2q.fsf@bsb.me.uk> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <59bec083$0$14934$b1db1813$d948b532@news.astraweb.com> <871sn4qb2q.fsf@bsb.me.uk> Message-ID: On 18/09/17 16:29, Ben Bacarisse wrote: > Steve D'Aprano writes: > >> To answer your question, what do I mean by int/int being undefined, I'd have to >> dig into areas of maths that either weren't taught in the undergrad courses I >> did, or that I've long since forgotten about. Something >> about... fields? > >> This is a pretty specialised area of maths. You won't learn anything >> about it in high school. And possibly not undergrad maths degrees. I >> seem to vaguely recall just barely touching on groups, but not rings >> or fields. > > When you said before that you thought that undefined division was rather > obscure I was going to mention that it's the basic difference between a > ring and a field; the intent being that you'd go "oh, yes, of course > it's not obscure at all". I'm glad I didn't now, because you would not > have seen it as the simple notion I expected! > > Teaching rings and fields is (or at least was 30 or so years ago) 1st > year undergraduate maths here in the UK. Maybe it's changed. I think I achieved a nodding acquaintance with rings, fields and vector spaces in Further Maths (pre-university), and then got the real deal in my first term at university. I think they now happen later in the first year; looking at the on-line syllabus, the first two terms of IA Maths are now full of things that used to be taught at A-level. -- Rhodri James *-* Kynesim Ltd From lists at mostrom.pp.se Tue Sep 19 09:12:55 2017 From: lists at mostrom.pp.se (Jan Erik =?utf-8?q?Mostr=C3=B6m?=) Date: Tue, 19 Sep 2017 15:12:55 +0200 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> Message-ID: On 19 Sep 2017, at 13:01, bartc wrote: > My bill in a store came to ?3.20 (GBP3.20), so I handed over ?10.20. > > I was given back ?16.90 in change! > > It turned out the cashier had entered ?20.10 as the amount tendered. > It was sorted out in the end. > > Sometimes its easier not to be bother making the figures come out > better. My father & mother worked in a grocery shop ... pre-electronic version, and to make things faster during the checkout they summarised some of things in their head so they only had to enter it once, for example 7 liter of milk + 1 cream. I must say they were VERY VERY good in calculating +/-/* in their heads. As a kid I learned to do it to some degree but nowhere close to them. And I'm amazed how often I see people trying to calculate change = sum handed over - cost and then trying to figure out what bills/coins should be returned instead of doing the simple thing of just adding to the cost. = jem From darcy at VybeNetworks.com Tue Sep 19 10:24:10 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Tue, 19 Sep 2017 10:24:10 -0400 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: On 09/19/2017 03:07 AM, Steven D'Aprano wrote: >> How relevant is the "people use calculators to do arithmetic" argument >> today? Okay, so I'm old and cynical, but I know [young] people who >> don't (can't?) calculate a gratuity without an app or a web page. > > Which is a form of calculator. People still learn to use calculators at > school, they still use them at work. They use Excel, which is prone to Wow. I still remember decrying the use of calculators in school. It seemed like the loss of actual math understanding. When I was young (and not running from dinosaurs) we learned the addition and multiplication tables by heart (and received a few sore knuckles while we struggled) and then learned to do math by paper and pencil. When it was time for a mechanical aid we got a slide rule. I truly believe that doing so gave me the best understanding of math that I could get. Now, of course, I use calculators and computers but I still understand the theory behind what I am doing. To this day while writing code I will actually put pen to paper in order to check that my program is doing the correct calculations. -- 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 Tue Sep 19 10:30:40 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Tue, 19 Sep 2017 10:30:40 -0400 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> Message-ID: <9f59484f-a8e0-6dcc-b78e-160baaa67028@VybeNetworks.com> On 09/19/2017 06:46 AM, Larry Martell wrote: > True story - the other day I was in a store and my total was $10.12. I One time I was at a cash with three or four items which were taxable. The cashier rung each one up and hit the total button. She turned to me and said something like "$23.42 please." She was surprised to see that I was already standing there with $23.42 in my hand. "How did you do that" she asked. She must have thought it was a magic trick. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From leamhall at gmail.com Tue Sep 19 10:36:48 2017 From: leamhall at gmail.com (leam hall) Date: Tue, 19 Sep 2017 10:36:48 -0400 Subject: How to share class relationship representations? Message-ID: I'm working on designing the classes, sub-classes, and relationships in my code. What is a good visual way to represent it so it can be stored in git and shared on the list without large images or attachments? Thanks! Leam From rosuav at gmail.com Tue Sep 19 10:37:29 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Sep 2017 00:37:29 +1000 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 20, 2017 at 12:24 AM, D'Arcy Cain wrote: > On 09/19/2017 03:07 AM, Steven D'Aprano wrote: >>> >>> How relevant is the "people use calculators to do arithmetic" argument >>> today? Okay, so I'm old and cynical, but I know [young] people who >>> don't (can't?) calculate a gratuity without an app or a web page. >> >> >> Which is a form of calculator. People still learn to use calculators at >> school, they still use them at work. They use Excel, which is prone to > > > Wow. I still remember decrying the use of calculators in school. It seemed > like the loss of actual math understanding. When I was young (and not > running from dinosaurs) we learned the addition and multiplication tables by > heart (and received a few sore knuckles while we struggled) and then learned > to do math by paper and pencil. When it was time for a mechanical aid we > got a slide rule. I truly believe that doing so gave me the best > understanding of math that I could get. Now, of course, I use calculators > and computers but I still understand the theory behind what I am doing. I learned math the same way - and also a lot of algebra. I was permitted to use a programmable calculator (on a PC) in high school but only if I programmed it myself using primitives, which meant that I had to prove that I'd mastered the math. Ended up with a whole bunch of handy features that a typical calculator wouldn't have. > To this day while writing code I will actually put pen to paper in order to > check that my program is doing the correct calculations. Pen and paper are not my things, but if I have to manually check something, I'll do it. Usually with a REPL or something. ChrisA From rhodri at kynesim.co.uk Tue Sep 19 11:09:41 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 19 Sep 2017 16:09:41 +0100 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> On 19/09/17 16:00, Stefan Ram wrote: > D'Arcy Cain writes: >> of course, I use calculators and computers but I still understand the >> theory behind what I am doing. > > I started out programming in BASIC. Today, I use Python, > the BASIC of the 21st century. Python has no GOTO, but when > it is executed, its for loop eventually is implemented using > a GOTO-like jump instruction. Thanks to my learning of BASIC, > /I/ can have this insight. Younger people, who never learned > GOTO, may still be able to use Python, but they will not > understand what is going on behind the curtains. Therefore, for > a profound understanding of Python, everyone should learn BASIC > first, just like I did! Tsk. You should have learned (a fake simplified) assembler first, then you'd have an appreciation of what your processor actually did. :-) -- Rhodri James *-* Kynesim Ltd From walters.justin01 at gmail.com Tue Sep 19 11:38:47 2017 From: walters.justin01 at gmail.com (justin walters) Date: Tue, 19 Sep 2017 08:38:47 -0700 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: On Tue, Sep 19, 2017 at 8:00 AM, Stefan Ram wrote: > D'Arcy Cain writes: > >of course, I use calculators and computers but I still understand the > >theory behind what I am doing. > > I started out programming in BASIC. Today, I use Python, > the BASIC of the 21st century. Python has no GOTO, but when > it is executed, its for loop eventually is implemented using > a GOTO-like jump instruction. Thanks to my learning of BASIC, > /I/ can have this insight. Younger people, who never learned > GOTO, may still be able to use Python, but they will not > understand what is going on behind the curtains. Therefore, for > a profound understanding of Python, everyone should learn BASIC > first, just like I did! > > ;-) > > > > -- > https://mail.python.org/mailman/listinfo/python-list > As a young person (read: late 20s), the one thing I've learned is that if a language has a `GOTO` instruction, it's probably a bad idea to use said instruction. I'm sure there's exceptions to this rule, but I'm lucky enough to have better solutions for calling the same procedure multiple times, i.e. functions. I always wonder what my "old man yells at cloud" moment will be once I get older. From grant.b.edwards at gmail.com Tue Sep 19 11:59:16 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 19 Sep 2017 15:59:16 +0000 (UTC) Subject: Even Older Man Yells At Whippersnappers References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> Message-ID: On 2017-09-19, Rhodri James wrote: > On 19/09/17 16:00, Stefan Ram wrote: >> D'Arcy Cain writes: >>> of course, I use calculators and computers but I still understand the >>> theory behind what I am doing. >> >> I started out programming in BASIC. Today, I use Python, >> the BASIC of the 21st century. Python has no GOTO, but when >> it is executed, its for loop eventually is implemented using >> a GOTO-like jump instruction. Thanks to my learning of BASIC, >> /I/ can have this insight. Younger people, who never learned >> GOTO, may still be able to use Python, but they will not >> understand what is going on behind the curtains. Therefore, for >> a profound understanding of Python, everyone should learn BASIC >> first, just like I did! > > Tsk. You should have learned (a fake simplified) assembler first, then > you'd have an appreciation of what your processor actually did. > >:-) Tsk, Tsk. Before learning assembly, you should design an instruction set and implement it in hardare. Or at least run in in a VHDL simulator. [Actually, back in my undergrad days we used AHPL and implemented something like a simplified PDP-11 ISA.] Alternatively, you should design an instruction set and implement it using microcode and AM2900 bit-slice processors. -- Grant Edwards grant.b.edwards Yow! Could I have a drug at overdose? gmail.com From walters.justin01 at gmail.com Tue Sep 19 12:09:06 2017 From: walters.justin01 at gmail.com (justin walters) Date: Tue, 19 Sep 2017 09:09:06 -0700 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> Message-ID: On Tue, Sep 19, 2017 at 8:59 AM, Grant Edwards wrote: > On 2017-09-19, Rhodri James wrote: > > On 19/09/17 16:00, Stefan Ram wrote: > >> D'Arcy Cain writes: > >>> of course, I use calculators and computers but I still understand the > >>> theory behind what I am doing. > >> > >> I started out programming in BASIC. Today, I use Python, > >> the BASIC of the 21st century. Python has no GOTO, but when > >> it is executed, its for loop eventually is implemented using > >> a GOTO-like jump instruction. Thanks to my learning of BASIC, > >> /I/ can have this insight. Younger people, who never learned > >> GOTO, may still be able to use Python, but they will not > >> understand what is going on behind the curtains. Therefore, for > >> a profound understanding of Python, everyone should learn BASIC > >> first, just like I did! > > > > Tsk. You should have learned (a fake simplified) assembler first, then > > you'd have an appreciation of what your processor actually did. > > > >:-) > > Tsk, Tsk. Before learning assembly, you should design an instruction > set and implement it in hardare. Or at least run in in a VHDL > simulator. [Actually, back in my undergrad days we used AHPL and > implemented something like a simplified PDP-11 ISA.] > > Alternatively, you should design an instruction set and implement it > using microcode and AM2900 bit-slice processors. > > -- > Grant Edwards grant.b.edwards Yow! Could I have a drug > at overdose? > gmail.com > > -- > https://mail.python.org/mailman/listinfo/python-list > Even Assembly is easy nowadays: https://fresh.flatassembler.net/index.cgi?page=content/1_screenshots.txt From rhodri at kynesim.co.uk Tue Sep 19 12:12:40 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 19 Sep 2017 17:12:40 +0100 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> Message-ID: <9c9a4ccd-652f-0c72-fff6-fbc4aa2f1eca@kynesim.co.uk> On 19/09/17 16:59, Grant Edwards wrote: > On 2017-09-19, Rhodri James wrote: >> On 19/09/17 16:00, Stefan Ram wrote: >>> D'Arcy Cain writes: >>>> of course, I use calculators and computers but I still understand the >>>> theory behind what I am doing. >>> >>> I started out programming in BASIC. Today, I use Python, >>> the BASIC of the 21st century. Python has no GOTO, but when >>> it is executed, its for loop eventually is implemented using >>> a GOTO-like jump instruction. Thanks to my learning of BASIC, >>> /I/ can have this insight. Younger people, who never learned >>> GOTO, may still be able to use Python, but they will not >>> understand what is going on behind the curtains. Therefore, for >>> a profound understanding of Python, everyone should learn BASIC >>> first, just like I did! >> >> Tsk. You should have learned (a fake simplified) assembler first, then >> you'd have an appreciation of what your processor actually did. >> >> :-) > > Tsk, Tsk. Before learning assembly, you should design an instruction > set and implement it in hardare. Or at least run in in a VHDL > simulator. [Actually, back in my undergrad days we used AHPL and > implemented something like a simplified PDP-11 ISA.] Eh, my school never 'ad an electronics class, nor a computer neither. Made programming a bit tricky; we 'ad to write programs on a form and send 'em off to next county. None of this new-fangled VHDL neither, we 'ad to do our simulations with paper and pencil. (All true, as it happens. My school acquired a computer (just the one: a NorthStar Horizon) in my O-Level year, but before that we really did have to send programs off to Worcester where someone would laboriously type them in for you. A week later you got a print out of the results and a roll of paper tape with your program on it.) -- Rhodri James *-* Kynesim Ltd From grant.b.edwards at gmail.com Tue Sep 19 12:17:46 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 19 Sep 2017 16:17:46 +0000 (UTC) Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-09-19, Jan Erik =?utf-8?q?Mostr=C3=B6m?= wrote: > And I'm amazed how often I see people trying to calculate > > change = sum handed over - cost > > and then trying to figure out what bills/coins should be returned > instead of doing the simple thing of just adding to the cost. When I was a kid, making change like that was something we were all taught in school. I have a feeling that's been dropped from most curricula. -- Grant Edwards grant.b.edwards Yow! MMM-MM!! So THIS is at BIO-NEBULATION! gmail.com From steve+python at pearwood.info Tue Sep 19 12:20:52 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 20 Sep 2017 02:20:52 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <0a799ad2-4ba5-6c94-015b-8885082c11d2@vub.be> <59c0e1c3$0$14961$b1db1813$d948b532@news.astraweb.com> <65a57c21-5b4c-86a6-ca7a-46fdc8b1822d@vub.be> <5a340682-4314-4833-9249-530df3727243@googlegroups.com> Message-ID: <59c143e6$0$14933$b1db1813$d948b532@news.astraweb.com> On Tue, 19 Sep 2017 09:53 pm, Rustom Mody wrote: > How exceptional is python's choice to NOT raise exceptions can be seen by > examples: You demonstrated that python raises exceptions for operations that aren't defined or meaningful. I don't know what point you think that made, apart from demonstrating that python is strongly typed. You want a duck, but you have a dog, so when you ask it to quack, it can't and raises an exception. You want a duck, but all you have is a brick, so when you ask it to fly, it can't, and raises an exception. *Almost all* combinations of arbitrary objects with arbitrary operations are doomed to fail. There's an infinite number of things you might want to do, and most objects can't do more than a handful of them ("open a socket and send these packets" -- "but I'm a float, I don't know how to open sockets"). I can only think of four operations which are plausibly universal: Identity: compare two operands for identity. In this case, the type of the object is irrelevant. Kind: interrogate an object to find out what kind of thing it is (what class or type it is). In Python we have type(obj) and isinstance(x, Type), plus a slightly more specialised version issubclass. Convert to a string or human-readable representation. And test whether an object is truthy or falsey. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From larry.martell at gmail.com Tue Sep 19 12:26:01 2017 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 19 Sep 2017 12:26:01 -0400 Subject: Old Man Yells At Cloud In-Reply-To: <9f59484f-a8e0-6dcc-b78e-160baaa67028@VybeNetworks.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <9f59484f-a8e0-6dcc-b78e-160baaa67028@VybeNetworks.com> Message-ID: On Tue, Sep 19, 2017 at 10:30 AM, D'Arcy Cain wrote: > On 09/19/2017 06:46 AM, Larry Martell wrote: >> >> True story - the other day I was in a store and my total was $10.12. I > > > One time I was at a cash with three or four items which were taxable. The > cashier rung each one up and hit the total button. She turned to me and > said something like "$23.42 please." She was surprised to see that I was > already standing there with $23.42 in my hand. "How did you do that" she > asked. She must have thought it was a magic trick. I was just in a clothing store this weekend and there was a rack of clothes that was 50%. The sales clerk said everything on that rack was an additional 25% off, so it's 75% off the original price. I asked is it 75% off the original price or 25% off the 50% of the price. Said it's the same thing. I said no it's not. She insisted it was. I said no, let's take a simple example. If it was $100 and it was 75% off it would be $25. But if it's 50% off and then 25% off that it will be $37.50. She looked totally dumbfounded. From steve+python at pearwood.info Tue Sep 19 12:30:42 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 20 Sep 2017 02:30:42 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> On Tue, 19 Sep 2017 05:56 am, Roel Schroeven wrote: > I do prefer Python 3's print-as-a-function because "special cases aren't > special enough to break the rules", but I feel there's a case to be made > for Python 2's print-as-a-statement because "(although) practicality > beats purity" sometimes. Nobody has successfully made the argument that print was *better* as a statement, or given any convincing reason why print *should* be a statement. (For example, del needs to be a statement, not a function, because it needs to operate on *names* not the objects bound to the names.) All they have managed to successfully argue is that they're used to print without parens and can't unlearn the habit. The one advantage of print statement is that you save a single character when typing it. Be still my beating heart. Compared to that, the disadvantages: - it makes print a special thing that can't be treated as a first-class value, it can't be passed to functions or used as a callback or bound to a name; - because it is special, beginners have to unlearn the practice of using parens for calling functions, and stop writing print(x); - it suffers a silent failure if you inadvertently parenthesise multiple arguments: `print(x, y)` is *not* the same as `print x, y`; - it has bizarre syntax that nobody would find normal if it wasn't for long-experience; I mean, really, you end the argument list with a comma to suppress printing newlines? who thought that was a good idea? - it is difficult to control the print statement, since you can't pass keyword arguments; it's one size fits all; - which is why we ended up with that awful `print >>file, args` hack; - it can't be mocked, shadowed, monkey-patched or replaced for testing; - and you can't even write help(print) in the interactive interpreter because its a syntax error. Of course an experienced Python coder can work around all these problems. The main way to work around them is to *stop using print*. By not using the print statement, you avoid all those disadvantages, and you end up with a proper function that has no surprises, no bizarre syntax, doesn't use a comma as a cryptic signal to suppress printing a newline, and can easily be extended with keyword args. (I sometimes monkey-patch the print function with one that takes a "verbosity" flag that controls whether or not it actually prints.) Oh, and for the record: sometimes I forget the parens too. And sometimes I write "def MyClass(ParentClass): ...". Sometimes I forget to add self to methods. Sometimes I even write dicts like {key, value}, or lists like [a;b;c]. Once I managed to write a whole class with a dozen or two methods writing NONE instead of None *every single time* it came up. I have no idea what I was thinking that day. (So sue me for not using test-driven-development.) The point is, we all make the occasional silly error. Doesn't mean we should cripple our functions and fill the language with special cases like the print statement to avoid such rare errors. If print had always been a function, and someone suggested making it a statement, who would be willing to accept all those disadvantages for the sake of saving one character? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From walters.justin01 at gmail.com Tue Sep 19 12:37:42 2017 From: walters.justin01 at gmail.com (justin walters) Date: Tue, 19 Sep 2017 09:37:42 -0700 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> Message-ID: On Tue, Sep 19, 2017 at 9:17 AM, Grant Edwards wrote: > On 2017-09-19, Jan Erik =?utf-8?q?Mostr=C3=B6m?= > wrote: > > > And I'm amazed how often I see people trying to calculate > > > > change = sum handed over - cost > > > > and then trying to figure out what bills/coins should be returned > > instead of doing the simple thing of just adding to the cost. > > When I was a kid, making change like that was something we were all > taught in school. I have a feeling that's been dropped from most > curricula. > > -- > Grant Edwards grant.b.edwards Yow! MMM-MM!! So THIS > is > at BIO-NEBULATION! > gmail.com > > -- > https://mail.python.org/mailman/listinfo/python-list > Not sure about the most recent decade, but back when I was in elementary school(1995-2001-ish), we definitely still learned math through how to make change. From walters.justin01 at gmail.com Tue Sep 19 12:40:09 2017 From: walters.justin01 at gmail.com (justin walters) Date: Tue, 19 Sep 2017 09:40:09 -0700 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <9f59484f-a8e0-6dcc-b78e-160baaa67028@VybeNetworks.com> Message-ID: On Tue, Sep 19, 2017 at 9:26 AM, Larry Martell wrote: > On Tue, Sep 19, 2017 at 10:30 AM, D'Arcy Cain > wrote: > > On 09/19/2017 06:46 AM, Larry Martell wrote: > >> > >> True story - the other day I was in a store and my total was $10.12. I > > > > > > One time I was at a cash with three or four items which were taxable. The > > cashier rung each one up and hit the total button. She turned to me and > > said something like "$23.42 please." She was surprised to see that I was > > already standing there with $23.42 in my hand. "How did you do that" she > > asked. She must have thought it was a magic trick. > > I was just in a clothing store this weekend and there was a rack of > clothes that was 50%. The sales clerk said everything on that rack was > an additional 25% off, so it's 75% off the original price. I asked is > it 75% off the original price or 25% off the 50% of the price. Said > it's the same thing. I said no it's not. She insisted it was. I said > no, let's take a simple example. If it was $100 and it was 75% off it > would be $25. But if it's 50% off and then 25% off that it will be > $37.50. She looked totally dumbfounded. > -- > https://mail.python.org/mailman/listinfo/python-list > That just seems like a simple logical failure. I'm amazed every day by how many people find that type of thinking difficult. From larry.martell at gmail.com Tue Sep 19 12:46:08 2017 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 19 Sep 2017 12:46:08 -0400 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: <9c9a4ccd-652f-0c72-fff6-fbc4aa2f1eca@kynesim.co.uk> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> <9c9a4ccd-652f-0c72-fff6-fbc4aa2f1eca@kynesim.co.uk> Message-ID: On Tue, Sep 19, 2017 at 12:12 PM, Rhodri James wrote: > > Eh, my school never 'ad an electronics class, nor a computer neither. Made > programming a bit tricky; we 'ad to write programs on a form and send 'em > off to next county. None of this new-fangled VHDL neither, we 'ad to do our > simulations with paper and pencil. > We dreamed of writing programs on a form. We had to make Hollerith punch cards by hand using a dull knife. You tell that to the kids of today and they won't believe you. From jsteward2930 at gmail.com Tue Sep 19 12:47:33 2017 From: jsteward2930 at gmail.com (Joey Steward) Date: Tue, 19 Sep 2017 09:47:33 -0700 Subject: Fwd: Issues with pip installation on windows In-Reply-To: References: Message-ID: ---------- Forwarded message ---------- From: Joey Steward Date: Mon, Sep 18, 2017 at 3:26 PM Subject: Issues with pip installation on windows To: python-list at python.org Hello, I'm a new programmer who initially began learning python for bioinformatics and data analysis applications, but have recently become interested by web development so I've set out to learn django. I used to use an ubuntu operating system when I was previously learning some aspects of bioinformatics but recently switched to a new computer with windows 10. I've been trying to use pip but continue getting an error message on the command line when I try to use pip (basically saying pip isn't a recognized command). I have been checking that pip installed though and up to date with the version of the python download I'm using ( was trying 3.6 and then switched to 2.7) so I feel it has something to do with how I have the setup that pip isn't being recognized, but I haven't been able to find any solutions with google searches. Is there any info out there that'd be good for a novice to check out to solve this? If so would greatly appreciate it! All the best, Joey Steward From stefan_ml at behnel.de Tue Sep 19 12:49:08 2017 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 19 Sep 2017 18:49:08 +0200 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: Stefan Ram schrieb am 19.09.2017 um 17:00: > D'Arcy Cain writes: >> of course, I use calculators and computers but I still understand the >> theory behind what I am doing. > > I started out programming in BASIC. Today, I use Python, > the BASIC of the 21st century. Python has no GOTO, but when > it is executed, its for loop eventually is implemented using > a GOTO-like jump instruction. Thanks to my learning of BASIC, > /I/ can have this insight. Younger people, who never learned > GOTO, may still be able to use Python, but they will not > understand what is going on behind the curtains. Therefore, for > a profound understanding of Python, everyone should learn BASIC > first, just like I did! http://entrian.com/goto/ Stefan From walters.justin01 at gmail.com Tue Sep 19 12:52:35 2017 From: walters.justin01 at gmail.com (justin walters) Date: Tue, 19 Sep 2017 09:52:35 -0700 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: <9c9a4ccd-652f-0c72-fff6-fbc4aa2f1eca@kynesim.co.uk> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> <9c9a4ccd-652f-0c72-fff6-fbc4aa2f1eca@kynesim.co.uk> Message-ID: On Tue, Sep 19, 2017 at 9:12 AM, Rhodri James wrote: > On 19/09/17 16:59, Grant Edwards wrote: > >> On 2017-09-19, Rhodri James wrote: >> >>> On 19/09/17 16:00, Stefan Ram wrote: >>> >>>> D'Arcy Cain writes: >>>> >>>>> of course, I use calculators and computers but I still understand the >>>>> theory behind what I am doing. >>>>> >>>> >>>> I started out programming in BASIC. Today, I use Python, >>>> the BASIC of the 21st century. Python has no GOTO, but when >>>> it is executed, its for loop eventually is implemented using >>>> a GOTO-like jump instruction. Thanks to my learning of BASIC, >>>> /I/ can have this insight. Younger people, who never learned >>>> GOTO, may still be able to use Python, but they will not >>>> understand what is going on behind the curtains. Therefore, for >>>> a profound understanding of Python, everyone should learn BASIC >>>> first, just like I did! >>>> >>> >>> Tsk. You should have learned (a fake simplified) assembler first, then >>> you'd have an appreciation of what your processor actually did. >>> >>> :-) >>> >> >> Tsk, Tsk. Before learning assembly, you should design an instruction >> set and implement it in hardare. Or at least run in in a VHDL >> simulator. [Actually, back in my undergrad days we used AHPL and >> implemented something like a simplified PDP-11 ISA.] >> > > > Eh, my school never 'ad an electronics class, nor a computer neither. Made > programming a bit tricky; we 'ad to write programs on a form and send 'em > off to next county. None of this new-fangled VHDL neither, we 'ad to do > our simulations with paper and pencil. > > > (All true, as it happens. My school acquired a computer (just the one: a > NorthStar Horizon) in my O-Level year, but before that we really did have > to send programs off to Worcester where someone would laboriously type them > in for you. A week later you got a print out of the results and a roll of > paper tape with your program on it.) > > > -- > Rhodri James *-* Kynesim Ltd > -- > https://mail.python.org/mailman/listinfo/python-list > What happened if there was a bug? Did you have to re-send it? From rosuav at gmail.com Tue Sep 19 13:22:16 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Sep 2017 03:22:16 +1000 Subject: [Tutor] beginning to code In-Reply-To: <59c143e6$0$14933$b1db1813$d948b532@news.astraweb.com> References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <0a799ad2-4ba5-6c94-015b-8885082c11d2@vub.be> <59c0e1c3$0$14961$b1db1813$d948b532@news.astraweb.com> <65a57c21-5b4c-86a6-ca7a-46fdc8b1822d@vub.be> <5a340682-4314-4833-9249-530df3727243@googlegroups.com> <59c143e6$0$14933$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 20, 2017 at 2:20 AM, Steve D'Aprano wrote: > I can only think of four operations which are plausibly universal: > > Identity: compare two operands for identity. In this case, the type of the > object is irrelevant. > > Kind: interrogate an object to find out what kind of thing it is (what class or > type it is). In Python we have type(obj) and isinstance(x, Type), plus a > slightly more specialised version issubclass. > > Convert to a string or human-readable representation. > > And test whether an object is truthy or falsey. Equality checks are also close to universal. If you ask if this list is equal to that timestamp, you don't get an exception, you get False. ChrisA From dvl at psu.edu Tue Sep 19 13:38:42 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Tue, 19 Sep 2017 13:38:42 -0400 Subject: Even Older Man Yells at Whippersnappers In-Reply-To: mailman.32.1505836805.31488.python-list@python.org References: Message-ID: <1505842722l.23461932l.0l@psu.edu> I recall giving a quiz to my college students sometime back around the late nineties which had a little bit of arithmetic involved in the answer. It's been too long ago to still have the exact details, but I remember a couple solutions that would be of the form: 5 + 10 + 1*2 And then the student would write he was unable to actually compute that without a calculator. And yes, I deliberately designed the questions to have such easy numbers to work with. Roger Christman Pennsylvania State University From rosuav at gmail.com Tue Sep 19 13:54:51 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Sep 2017 03:54:51 +1000 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 20, 2017 at 3:44 AM, Stefan Ram wrote: > Steve D'Aprano did *not* write > [it was edited/abbreviated by me - S. R.]: > |disadvantages: > |0 - it makes print a special thing > |1 - beginners have to unlearn > |2 - `print(x, y)` is *not* the same as `print x, y`; > |3 - it has bizarre syntax that nobody would find normal > |4 - you can't pass keyword arguments > |5 - it can't be mocked, shadowed, monkey-patched or replaced for testing; > |6 - and you can't even write help(print) in the interactive interpreter > > But a simple "autocorrect" features that adds missing > parentheses when the case is clear and obvious would not > suffer from most of those drawbacks, except maybe from #2. Such a feature is also useful for other functions - nothing special about print there. And you can go way further; I've seen people with their editors configured so that typing "def" prepopulates an entire function skeleton, complete with a docstring template. That's an editor feature that can save you typing; but the *code* still has all the parentheses in it. ChrisA From christopher_reimer at icloud.com Tue Sep 19 14:15:03 2017 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Tue, 19 Sep 2017 11:15:03 -0700 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> Message-ID: <4FD1225A-5B15-4674-8BFB-C8A8341638A1@icloud.com> > On Sep 19, 2017, at 9:09 AM, justin walters wrote: > > On Tue, Sep 19, 2017 at 8:59 AM, Grant Edwards > wrote: > >>> On 2017-09-19, Rhodri James wrote: >>>> On 19/09/17 16:00, Stefan Ram wrote: >>>> D'Arcy Cain writes: >>>>> of course, I use calculators and computers but I still understand the >>>>> theory behind what I am doing. >>>> >>>> I started out programming in BASIC. Today, I use Python, >>>> the BASIC of the 21st century. Python has no GOTO, but when >>>> it is executed, its for loop eventually is implemented using >>>> a GOTO-like jump instruction. Thanks to my learning of BASIC, >>>> /I/ can have this insight. Younger people, who never learned >>>> GOTO, may still be able to use Python, but they will not >>>> understand what is going on behind the curtains. Therefore, for >>>> a profound understanding of Python, everyone should learn BASIC >>>> first, just like I did! >>> >>> Tsk. You should have learned (a fake simplified) assembler first, then >>> you'd have an appreciation of what your processor actually did. >>> >>> :-) >> >> Tsk, Tsk. Before learning assembly, you should design an instruction >> set and implement it in hardare. Or at least run in in a VHDL >> simulator. [Actually, back in my undergrad days we used AHPL and >> implemented something like a simplified PDP-11 ISA.] >> >> Alternatively, you should design an instruction set and implement it >> using microcode and AM2900 bit-slice processors. >> >> -- >> Grant Edwards grant.b.edwards Yow! Could I have a drug >> at overdose? >> gmail.com >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > Even Assembly is easy nowadays: > https://fresh.flatassembler.net/index.cgi?page=content/1_screenshots.txt > -- > https://mail.python.org/mailman/listinfo/python-list Is assembly still a thing today? I wanted to take assembly in college but I was the only student who showed up and the class got cancelled. I dabbled with 8-but assembly as a kid. I can't imagine what assembly is on a 64-bit processor. Chris R. From bc at freeuk.com Tue Sep 19 14:31:47 2017 From: bc at freeuk.com (bartc) Date: Tue, 19 Sep 2017 19:31:47 +0100 Subject: Old Man Yells At Cloud In-Reply-To: <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> Message-ID: On 19/09/2017 17:30, Steve D'Aprano wrote: > On Tue, 19 Sep 2017 05:56 am, Roel Schroeven wrote: > >> I do prefer Python 3's print-as-a-function because "special cases aren't >> special enough to break the rules", but I feel there's a case to be made >> for Python 2's print-as-a-statement because "(although) practicality >> beats purity" sometimes. > > Nobody has successfully made the argument that print was *better* as a > statement, or given any convincing reason why print *should* be a statement. > > (For example, del needs to be a statement, not a function, because it needs to > operate on *names* not the objects bound to the names.) > > All they have managed to successfully argue is that they're used to print > without parens and can't unlearn the habit. > > The one advantage of print statement is that you save a single character when > typing it. Be still my beating heart. > > Compared to that, the disadvantages: > > - it makes print a special thing that can't be treated as a first-class > value, it can't be passed to functions or used as a callback or bound > to a name; > > - because it is special, beginners have to unlearn the practice of using > parens for calling functions, and stop writing print(x); > > - it suffers a silent failure if you inadvertently parenthesise multiple > arguments: `print(x, y)` is *not* the same as `print x, y`; > > - it has bizarre syntax that nobody would find normal if it wasn't for > long-experience; I mean, really, you end the argument list with a > comma to suppress printing newlines? who thought that was a good idea? > > - it is difficult to control the print statement, since you can't > pass keyword arguments; it's one size fits all; > > - which is why we ended up with that awful `print >>file, args` hack; > > - it can't be mocked, shadowed, monkey-patched or replaced for testing; > > - and you can't even write help(print) in the interactive interpreter > because its a syntax error. Can't you get around all those with things like sys.stdout.write? If so, what was the point of having a discrete print statement/function at all? -- bartc From rhodri at kynesim.co.uk Tue Sep 19 14:32:55 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 19 Sep 2017 19:32:55 +0100 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> <9c9a4ccd-652f-0c72-fff6-fbc4aa2f1eca@kynesim.co.uk> Message-ID: <6918a14d-cb91-da08-07a4-c1632e0fc724@kynesim.co.uk> On 19/09/17 17:52, justin walters wrote: > On Tue, Sep 19, 2017 at 9:12 AM, Rhodri James wrote: >> >> >> Eh, my school never 'ad an electronics class, nor a computer neither. Made >> programming a bit tricky; we 'ad to write programs on a form and send 'em >> off to next county. None of this new-fangled VHDL neither, we 'ad to do >> our simulations with paper and pencil. >> >> >> (All true, as it happens. My school acquired a computer (just the one: a >> NorthStar Horizon) in my O-Level year, but before that we really did have >> to send programs off to Worcester where someone would laboriously type them >> in for you. A week later you got a print out of the results and a roll of >> paper tape with your program on it.) > > What happened if there was a bug? Did you have to re-send it? > Yes. We proofread our little programs very carefully after the first bug :-) -- Rhodri James *-* Kynesim Ltd From larry.martell at gmail.com Tue Sep 19 14:33:21 2017 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 19 Sep 2017 14:33:21 -0400 Subject: Even Older Man Yells at Whippersnappers In-Reply-To: <1505842722l.23461932l.0l@psu.edu> References: <1505842722l.23461932l.0l@psu.edu> Message-ID: On Tue, Sep 19, 2017 at 1:38 PM, ROGER GRAYDON CHRISTMAN wrote: > I recall giving a quiz to my college students sometime back around > the late nineties which had a little bit of arithmetic involved in the answer. > It's been too long ago to still have the exact details, but I remember > a couple solutions that would be of the form: > > 5 + 10 + 1*2 > > And then the student would write he was unable to actually > compute that without a calculator. And yes, I deliberately > designed the questions to have such easy numbers to work with. It was my birthday the other day. People at worked asked how old I was. I replied: ((3**2)+math.sqrt(400))*2 Quite a few people somehow came up with 47. And these are technical people. From stephanh42 at gmail.com.invalid Tue Sep 19 14:37:05 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 19 Sep 2017 18:37:05 GMT Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> <59c0c330$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: Op 2017-09-19, Steven D'Aprano schreef : > There is a significant chunk of the Python community for whom "just pip > install it" is not easy, legal or even possible. For them, if its not in > the standard library, it might as well not even exist. But numpy *is* in the standard library, provided you download the correct version of Python, namely the one from: https://python-xy.github.io/ Stephan From rhodri at kynesim.co.uk Tue Sep 19 14:38:35 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 19 Sep 2017 19:38:35 +0100 Subject: Even Older Man Yells at Whippersnappers In-Reply-To: References: <1505842722l.23461932l.0l@psu.edu> Message-ID: On 19/09/17 19:33, Larry Martell wrote: > On Tue, Sep 19, 2017 at 1:38 PM, ROGER GRAYDON CHRISTMAN wrote: >> I recall giving a quiz to my college students sometime back around >> the late nineties which had a little bit of arithmetic involved in the answer. >> It's been too long ago to still have the exact details, but I remember >> a couple solutions that would be of the form: >> >> 5 + 10 + 1*2 >> >> And then the student would write he was unable to actually >> compute that without a calculator. And yes, I deliberately >> designed the questions to have such easy numbers to work with. > > It was my birthday the other day. People at worked asked how old I > was. I replied: > > ((3**2)+math.sqrt(400))*2 > > Quite a few people somehow came up with 47. And these are technical people. > You obviously look very spry for your age. -- Rhodri James *-* Kynesim Ltd From leamhall at gmail.com Tue Sep 19 14:40:17 2017 From: leamhall at gmail.com (leam hall) Date: Tue, 19 Sep 2017 14:40:17 -0400 Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" In-Reply-To: References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> <59c0c330$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: On Tue, Sep 19, 2017 at 2:37 PM, Stephan Houben < stephanh42 at gmail.com.invalid> wrote: > Op 2017-09-19, Steven D'Aprano schreef pearwood.info>: > > > There is a significant chunk of the Python community for whom "just pip > > install it" is not easy, legal or even possible. For them, if its not in > > the standard library, it might as well not even exist. > > But numpy *is* in the standard library, provided you download the > correct version of Python, namely the one from: > > https://python-xy.github.io/ > > Stephan > > Many of us can't pip install; it's in the OS supplied vendor repo or it doesn't go on the machines. Leam From rosuav at gmail.com Tue Sep 19 14:41:47 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Sep 2017 04:41:47 +1000 Subject: Even Older Man Yells at Whippersnappers In-Reply-To: References: <1505842722l.23461932l.0l@psu.edu> Message-ID: On Wed, Sep 20, 2017 at 4:33 AM, Larry Martell wrote: > On Tue, Sep 19, 2017 at 1:38 PM, ROGER GRAYDON CHRISTMAN wrote: >> I recall giving a quiz to my college students sometime back around >> the late nineties which had a little bit of arithmetic involved in the answer. >> It's been too long ago to still have the exact details, but I remember >> a couple solutions that would be of the form: >> >> 5 + 10 + 1*2 >> >> And then the student would write he was unable to actually >> compute that without a calculator. And yes, I deliberately >> designed the questions to have such easy numbers to work with. > > It was my birthday the other day. People at worked asked how old I > was. I replied: > > ((3**2)+math.sqrt(400))*2 > > Quite a few people somehow came up with 47. And these are technical people. *headscratch* Multiple people got 47? I'm struggling to figure that out. If they interpret the first part as multiplication (3*2 => 6), that would get 26*2 => 52; if they don't understand the square rooting, they'd probably just give up; if they ignore the parentheses, that could give 9 + 20*2 => 49; but I can't come up with 47. ChrisA From larry.martell at gmail.com Tue Sep 19 14:48:13 2017 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 19 Sep 2017 14:48:13 -0400 Subject: Even Older Man Yells at Whippersnappers In-Reply-To: References: <1505842722l.23461932l.0l@psu.edu> Message-ID: On Tue, Sep 19, 2017 at 2:41 PM, Chris Angelico wrote: > On Wed, Sep 20, 2017 at 4:33 AM, Larry Martell wrote: >> On Tue, Sep 19, 2017 at 1:38 PM, ROGER GRAYDON CHRISTMAN wrote: >>> I recall giving a quiz to my college students sometime back around >>> the late nineties which had a little bit of arithmetic involved in the answer. >>> It's been too long ago to still have the exact details, but I remember >>> a couple solutions that would be of the form: >>> >>> 5 + 10 + 1*2 >>> >>> And then the student would write he was unable to actually >>> compute that without a calculator. And yes, I deliberately >>> designed the questions to have such easy numbers to work with. >> >> It was my birthday the other day. People at worked asked how old I >> was. I replied: >> >> ((3**2)+math.sqrt(400))*2 >> >> Quite a few people somehow came up with 47. And these are technical people. > > *headscratch* Multiple people got 47? I'm struggling to figure that > out. If they interpret the first part as multiplication (3*2 => 6), > that would get 26*2 => 52; if they don't understand the square > rooting, they'd probably just give up; if they ignore the parentheses, > that could give 9 + 20*2 => 49; but I can't come up with 47. They could not explain it either. From grant.b.edwards at gmail.com Tue Sep 19 14:52:44 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 19 Sep 2017 18:52:44 +0000 (UTC) Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <9f59484f-a8e0-6dcc-b78e-160baaa67028@VybeNetworks.com> Message-ID: On 2017-09-19, Larry Martell wrote: > I was just in a clothing store this weekend and there was a rack of > clothes that was 50%. The sales clerk said everything on that rack was > an additional 25% off, so it's 75% off the original price. I asked is > it 75% off the original price or 25% off the 50% of the price. Said > it's the same thing. I said no it's not. She insisted it was. I said > no, let's take a simple example. If it was $100 and it was 75% off it > would be $25. But if it's 50% off and then 25% off that it will be > $37.50. She looked totally dumbfounded. Years ago I remember hearing some retail workers (at J. C. Pennys) explain that when applying multiple discounts, you always apply the largest percentage discount first and smallest discount last. "That way you get the lowest price." Technically, you _do_ get the lowest price that way. (But you also get the lowest price applying them in any other order.) A simple experiment would show that it doesn't matter, but none of the ever thought to try it. -- Grant Edwards grant.b.edwards Yow! Send your questions to at ``ASK ZIPPY'', Box 40474, gmail.com San Francisco, CA 94140, USA From john_ladasky at sbcglobal.net Tue Sep 19 14:58:47 2017 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Tue, 19 Sep 2017 11:58:47 -0700 (PDT) Subject: Stdlib, what's in, what's out In-Reply-To: References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> <97a340e6-e4e3-4c6e-b14d-59ea40f5471b@googlegroups.com> Message-ID: <5709c5f5-c725-41a9-aa36-8260101799c9@googlegroups.com> On Tuesday, September 19, 2017 at 1:05:51 AM UTC-7, Stefan Behnel wrote: > John Ladasky schrieb am 19.09.2017 um 08:54: > > I have come to understand from your other posts that adding something to > > the stdlib imposes significant constraints on the release schedules of > > those modules. I can appreciate the hassle that might cause. Still, > > now I wonder what I might be missing. > > There are many packages on PyPI that reimplement functionality of the > stdlib in some "better" way, by their own definition of "better". Some are > faster, some are more feature-rich, some have a better API, some focus on > making specific special cases faster/easier/whatever. And of course I have found some other third-party packages: scipy, pandas, matplotlib, and PyQt5 are important for my work. I helped a student of mine get selenium running. In the case of PyQt, I found TKinter unsatisfactory many years ago, and went looking for better choices. I used wxPython first, when I was working in Py2. When wxPython was slow to migrate to Py3, I went searching again. > The stdlib is there to provide a base level of functionality. That base > level tends to be much higher up than in most other programming languages, Very much agreed. > but from the point of view of Python, it's still just a base level, however > comfortable it might be. > > If you need specific features, more speed, can't live with a certain API or > feel that you are wasting too much developer time by doing something the > way you always did it, And that's the tricky part. Maybe there's a better way out there that is helping other programmers, but it isn't well-publicized. Say what you want about the hassle it imposes on package developers, but the best advertisement is having your package in the stdlib where everyone will see it. > If you can live with what the stdlib provides, stick to it. Keeping foreign > dependencies low is also "better" in some cases. Also agreed. Thankfully, my code doesn't run on any machines more than two doors down from my office. And although it has to run on Windows, Linux, and Mac, I can get my hands on every machine and install the packages my users need. From bc at freeuk.com Tue Sep 19 15:04:52 2017 From: bc at freeuk.com (bartc) Date: Tue, 19 Sep 2017 20:04:52 +0100 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <9f59484f-a8e0-6dcc-b78e-160baaa67028@VybeNetworks.com> Message-ID: On 19/09/2017 17:26, Larry Martell wrote: > On Tue, Sep 19, 2017 at 10:30 AM, D'Arcy Cain wrote: >> On 09/19/2017 06:46 AM, Larry Martell wrote: >>> >>> True story - the other day I was in a store and my total was $10.12. I >> >> >> One time I was at a cash with three or four items which were taxable. The >> cashier rung each one up and hit the total button. She turned to me and >> said something like "$23.42 please." She was surprised to see that I was >> already standing there with $23.42 in my hand. "How did you do that" she >> asked. She must have thought it was a magic trick. > > I was just in a clothing store this weekend and there was a rack of > clothes that was 50%. The sales clerk said everything on that rack was > an additional 25% off, so it's 75% off the original price. I asked is > it 75% off the original price or 25% off the 50% of the price. Said > it's the same thing. I said no it's not. She insisted it was. I said > no, let's take a simple example. If it was $100 and it was 75% off it > would be $25. But if it's 50% off and then 25% off that it will be > $37.50. She looked totally dumbfounded. > Most people (in the general population, doubtless not in this group) seem to be confused about things like that. Your house has gone down in value by 30% this year; it will need to increase by 43% to be back where it was last year, not 30%. Value-Added-Tax in the UK increased from 17.5% to 20%, everyone was talking about a 2.5% increase in prices. The increase would actually be just over 2.1% (a ?100 ex-VAT price increases from ?117.50 to ?120.00). Etc. -- bartc From bill at baddogconsulting.com Tue Sep 19 15:19:09 2017 From: bill at baddogconsulting.com (Bill Deegan) Date: Tue, 19 Sep 2017 15:19:09 -0400 Subject: Issues with pip installation on windows In-Reply-To: References: Message-ID: try using: python -m pip Does that work? On Tue, Sep 19, 2017 at 12:47 PM, Joey Steward wrote: > ---------- Forwarded message ---------- > From: Joey Steward > Date: Mon, Sep 18, 2017 at 3:26 PM > Subject: Issues with pip installation on windows > To: python-list at python.org > > > Hello, > > I'm a new programmer who initially began learning python for bioinformatics > and data analysis applications, but have recently become interested by web > development so I've set out to learn django. > > I used to use an ubuntu operating system when I was previously learning > some aspects of bioinformatics but recently switched to a new computer with > windows 10. I've been trying to use pip but continue getting an error > message on the command line when I try to use pip (basically saying pip > isn't a recognized command). > > I have been checking that pip installed though and up to date with the > version of the python download I'm using ( was trying 3.6 and then switched > to 2.7) so I feel it has something to do with how I have the setup that pip > isn't being recognized, but I haven't been able to find any solutions with > google searches. > > Is there any info out there that'd be good for a novice to check out to > solve this? > > If so would greatly appreciate it! > > All the best, > > Joey Steward > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Tue Sep 19 15:22:02 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Sep 2017 05:22:02 +1000 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 20, 2017 at 4:59 AM, Stefan Ram wrote: > "Jan Erik =?utf-8?q?Mostr=C3=B6m?=" writes: >>And I'm amazed how often I see people trying to calculate >>change = sum handed over - cost >>and then trying to figure out what bills/coins should be returned >>instead of doing the simple thing of just adding to the cost. > > I don't get this. For example, the contractual payment (cost) is > > 47.21 > > , the other party hands over > > 50.25 > > . Now I am supposed to add /what/ to the cost? Start at the smallest end. You need to make 21 cents up to 25. So hand back four pennies. Then make 47 dollars up to 50. Here in Australia, that would mean a $1 coin and a $2 coin; in the US, probably three $1 notes. You count 'em off: starting at 47, hand a dollar, 48, another dollar, 49, a third dollar, 50. Now you've added the change onto the cost, reaching the amount paid. It's more useful when the customer *hasn't* tried to be helpful; what you're doing is rounding everything up to the next unit. I'm going to assume pre-1992 Australian currency (when we still had 1c and 2c coins) - feel free to adjust to your own. The cost is $47.21; the customer handed over a $50 note. You say the parts in quotes. * Quote the value of the bill. "Forty-seven dollars twenty-one." * Build 21 cents up to 25. Two 2c coins: "23, 25" * Build 25 cents up to 30. One 5c coin: "30" * Build 30 up to 50. One 20c coin: "50" * Build 50 up to the next dollar. One 50c coin: "48 dollars." * Build that up to the amount paid. One $2 coin: "50." Or of course you could use other denominations (maybe a pair of $1 coins if you're out of twos), in which case you'd say that appropriately ("49, 50"). Does that make sense? ChrisA From python at mrabarnett.plus.com Tue Sep 19 16:03:01 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 19 Sep 2017 21:03:01 +0100 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: <4FD1225A-5B15-4674-8BFB-C8A8341638A1@icloud.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> <4FD1225A-5B15-4674-8BFB-C8A8341638A1@icloud.com> Message-ID: <0ff605c9-a9b2-c5c9-0cf5-d6bb38ea9ef2@mrabarnett.plus.com> On 2017-09-19 19:15, Christopher Reimer wrote: >> On Sep 19, 2017, at 9:09 AM, justin walters wrote: >> >> On Tue, Sep 19, 2017 at 8:59 AM, Grant Edwards >> wrote: >> >>>> On 2017-09-19, Rhodri James wrote: >>>>> On 19/09/17 16:00, Stefan Ram wrote: >>>>> D'Arcy Cain writes: >>>>>> of course, I use calculators and computers but I still understand the >>>>>> theory behind what I am doing. >>>>> >>>>> I started out programming in BASIC. Today, I use Python, >>>>> the BASIC of the 21st century. Python has no GOTO, but when >>>>> it is executed, its for loop eventually is implemented using >>>>> a GOTO-like jump instruction. Thanks to my learning of BASIC, >>>>> /I/ can have this insight. Younger people, who never learned >>>>> GOTO, may still be able to use Python, but they will not >>>>> understand what is going on behind the curtains. Therefore, for >>>>> a profound understanding of Python, everyone should learn BASIC >>>>> first, just like I did! >>>> >>>> Tsk. You should have learned (a fake simplified) assembler first, then >>>> you'd have an appreciation of what your processor actually did. >>>> >>>> :-) >>> >>> Tsk, Tsk. Before learning assembly, you should design an instruction >>> set and implement it in hardare. Or at least run in in a VHDL >>> simulator. [Actually, back in my undergrad days we used AHPL and >>> implemented something like a simplified PDP-11 ISA.] >>> >>> Alternatively, you should design an instruction set and implement it >>> using microcode and AM2900 bit-slice processors. >>> >>> -- >>> Grant Edwards grant.b.edwards Yow! Could I have a drug >>> at overdose? >>> gmail.com >>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> >> Even Assembly is easy nowadays: >> https://fresh.flatassembler.net/index.cgi?page=content/1_screenshots.txt >> -- >> https://mail.python.org/mailman/listinfo/python-list > > Is assembly still a thing today? > > I wanted to take assembly in college but I was the only student who showed up and the class got cancelled. I dabbled with 8-but assembly as a kid. I can't imagine what assembly is on a 64-bit processor. > Assembler? I started out on a hex keypad. I still remember that hex C4 was LDI. Assembler on, say, a 6502 or ARM is pretty nice! :-) From python at mrabarnett.plus.com Tue Sep 19 16:03:54 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 19 Sep 2017 21:03:54 +0100 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> <9c9a4ccd-652f-0c72-fff6-fbc4aa2f1eca@kynesim.co.uk> Message-ID: <6a65e65c-e26f-27ab-7d64-24e8c882682c@mrabarnett.plus.com> On 2017-09-19 17:46, Larry Martell wrote: > On Tue, Sep 19, 2017 at 12:12 PM, Rhodri James wrote: >> >> Eh, my school never 'ad an electronics class, nor a computer neither. Made >> programming a bit tricky; we 'ad to write programs on a form and send 'em >> off to next county. None of this new-fangled VHDL neither, we 'ad to do our >> simulations with paper and pencil. >> > > We dreamed of writing programs on a form. We had to make Hollerith > punch cards by hand using a dull knife. You tell that to the kids of > today and they won't believe you. > You had a _knife_? From python at mrabarnett.plus.com Tue Sep 19 16:05:25 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 19 Sep 2017 21:05:25 +0100 Subject: Issues with pip installation on windows In-Reply-To: References: Message-ID: <1ee62df8-94cb-8b81-ca44-639ac71f057c@mrabarnett.plus.com> On 2017-09-19 20:19, Bill Deegan wrote: > try using: python -m pip > Does that work? > If you want to be more specific, you can use the Python launcher: py -3.6 -m pip > On Tue, Sep 19, 2017 at 12:47 PM, Joey Steward > wrote: > >> ---------- Forwarded message ---------- >> From: Joey Steward >> Date: Mon, Sep 18, 2017 at 3:26 PM >> Subject: Issues with pip installation on windows >> To: python-list at python.org >> >> >> Hello, >> >> I'm a new programmer who initially began learning python for bioinformatics >> and data analysis applications, but have recently become interested by web >> development so I've set out to learn django. >> >> I used to use an ubuntu operating system when I was previously learning >> some aspects of bioinformatics but recently switched to a new computer with >> windows 10. I've been trying to use pip but continue getting an error >> message on the command line when I try to use pip (basically saying pip >> isn't a recognized command). >> >> I have been checking that pip installed though and up to date with the >> version of the python download I'm using ( was trying 3.6 and then switched >> to 2.7) so I feel it has something to do with how I have the setup that pip >> isn't being recognized, but I haven't been able to find any solutions with >> google searches. >> >> Is there any info out there that'd be good for a novice to check out to >> solve this? >> >> If so would greatly appreciate it! >> >> All the best, >> >> Joey Steward >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From rosuav at gmail.com Tue Sep 19 16:34:39 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Sep 2017 06:34:39 +1000 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 20, 2017 at 5:45 AM, Stefan Ram wrote: > Chris Angelico writes: >>On Wed, Sep 20, 2017 at 4:59 AM, Stefan Ram wrote: >>>I don't get this. For example, the contractual payment (cost) is >>>47.21 >>>, the other party hands over >>>50.25 >>>. Now I am supposed to add /what/ to the cost? >>Start at the smallest end. You need to make 21 cents up to 25. So hand >>back four pennies. > > Yes, but to know this ("four") I have to do a /subtraction/: > > 25 - 21 = 4. > > And Jan wrote that he is amazed seeing people /subtract/, > when all they'd need to do was /add/. > >>* Build 21 cents up to 25. Two 2c coins: "23, 25" > ... >>Does that make sense? > > Ok, yes. This seems to be an implementation of subtraction > by "stepwise addition". Yeah. Not even "stepwise" addition, in many cases - just counting. Grab a handful of 1c coins, and say the bill value first, then start counting coins. By the time you hit 25, you've handed over the right number of coins (four). When working with any denomination that's a multiple of ten, it's that simple. ChrisA From gheskett at shentel.net Tue Sep 19 16:41:19 2017 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 19 Sep 2017 16:41:19 -0400 Subject: Even Older Man Yells at Whippersnappers In-Reply-To: <1505842722l.23461932l.0l@psu.edu> References: <1505842722l.23461932l.0l@psu.edu> Message-ID: <201709191641.19692.gheskett@shentel.net> On Tuesday 19 September 2017 13:38:42 ROGER GRAYDON CHRISTMAN wrote: > I recall giving a quiz to my college students sometime back around > the late nineties which had a little bit of arithmetic involved in the > answer. It's been too long ago to still have the exact details, but I > remember a couple solutions that would be of the form: > > 5 + 10 + 1*2 > > And then the student would write he was unable to actually > compute that without a calculator. And yes, I deliberately > designed the questions to have such easy numbers to work with. > > Roger Christman > Pennsylvania State University Why do we buy them books and send them to school? Yes, that is a real question. We ought to be suing the schools for malpractice. And the parents for child abuse because they didn't see to it the child was being properly taught. I know from raising some of those questions at a school board meeting, occasioned by my trying to act like a parent when I took on a woman with 3 children fathered by a myotonic muscular dystrophy victim. Those offspring typically have a 30 year lifespan so they are long passed now. And being told they have to follow the federal recipes. So who the hell do we sue to put some "education" back into the classroom? The only way we'll fix it is to cost the decision makers their salaries. And we start that by talking to the candidates, and voting them in or out accordingly in those regions where they are elected. 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 nad at python.org Tue Sep 19 17:45:53 2017 From: nad at python.org (Ned Deily) Date: Tue, 19 Sep 2017 17:45:53 -0400 Subject: [RELEASE] Python 3.6.3rc1 and 3.7.0a1 are now available for testing and more Message-ID: <15E3769E-F938-44F6-AD38-EAAE976A49D2@python.org> The Python build factories have been busy the last several weeks preparing our fall lineup of releases. Today we are happy to announce three additions: 3.6.3rc1, 3.7.0a1, and 3.3.7 final, which join last weekend's 2.7.14 and last month's 3.5.4 bug-fix releases and 3.4.7 security-fix update (https://www.python.org/downloads/). 1. Python 3.6.3rc1 is the first release candidate for Python 3.6.3, the next maintenance release of Python 3.6. While 3.6.3rc1 is a preview release and, thus, not intended for production environments, we encourage you to explore it and provide feedback via the Python bug tracker (https://bugs.python.org). 3.6.3 is planned for final release on 2017-10-02 with the next maintenance release expected to follow in about 3 months. You can find Python 3.6.3rc1 and more information here: https://www.python.org/downloads/release/python-363rc1/ 2. Python 3.7.0a1 is the first of four planned alpha releases of Python 3.7, the next feature release of Python. During the alpha phase, Python 3.7 remains under heavy development: additional features will be added and existing features may be modified or deleted. Please keep in mind that this is a preview release and its use is not recommended for production environments. The next preview release, 3.6.0a2, is planned for 2017-10-16. You can find Python 3.7.0a1 and more information here: https://www.python.org/downloads/release/python-370a1/ 3. Python 3.3.7 is also now available. It is a security-fix source-only release and is expected to be the final release of any kind for Python 3.3.x before it reaches end-of-life status on 2017-09-29, five years after its initial release. Because 3.3.x has long been in security-fix mode, 3.3.7 may no longer build correctly on all current operating system releases and some tests may fail. If you are still using Python 3.3.x, we **strongly** encourage you to upgrade now to a more recent, fully supported version of Python 3. You can find Python 3.3.7 here: https://www.python.org/downloads/release/python-337/ -- Ned Deily nad at python.org -- [] From sohcahtoa82 at gmail.com Tue Sep 19 19:06:53 2017 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Tue, 19 Sep 2017 16:06:53 -0700 (PDT) Subject: String to Dictionary conversion in python In-Reply-To: References: Message-ID: <524ece9a-114d-4091-92f6-57dd1ea240de@googlegroups.com> On Thursday, September 14, 2017 at 11:01:46 PM UTC-7, santosh.y... at gmail.com wrote: > Hi, > > Can anyone help me in the below issue. > > I need to convert string to dictionary > > string = " 'msisdn': '7382432382', 'action': 'select', 'sessionId': '123', 'recipient': '7382432382', 'language': 'english'" > > Can anyone help me with the code We're not going to do your homework for you. What have you tried? What errors are you getting? If you're replying with your code or an error, make sure to use Copy/Paste and DO NOT just manually re-type the code or error. Also, make sure to post the entire traceback. If literal_eval is out of the question, take a look at the str.split() function. I'd split on a comma, then for each result, split on the colon, then strip out the single quotes. The actual coding of that is an exercise for the reader. From steve+python at pearwood.info Tue Sep 19 20:08:18 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 20 Sep 2017 10:08:18 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c1b175$0$14948$b1db1813$d948b532@news.astraweb.com> On Wed, 20 Sep 2017 03:44 am, Stefan Ram wrote: > Steve D'Aprano did *not* write > [it was edited/abbreviated by me - S. R.]: > |disadvantages: > |0 - it makes print a special thing > |1 - beginners have to unlearn > |2 - `print(x, y)` is *not* the same as `print x, y`; > |3 - it has bizarre syntax that nobody would find normal > |4 - you can't pass keyword arguments > |5 - it can't be mocked, shadowed, monkey-patched or replaced for testing; > |6 - and you can't even write help(print) in the interactive interpreter > > But a simple "autocorrect" features that adds missing > parentheses when the case is clear and obvious would not > suffer from most of those drawbacks, except maybe from #2. A simple "autocorrect" in *what*? The interpreter? The editor? Both? Do you think Microsoft will consider adding it to Notepad? I seem to recall that you use an editor which doesn't even auto-indent after a colon. There's a long and inglorious history of good-intentioned people creating Do What I Mean systems, like adding semi-colons where they are "obvious" or leaving them out where they aren't "necessary". They invariably become a source of confusion, superstition and bugs. DWIM systems always sound like a good idea and always end up causing more problems than they solve. http://catb.org/~esr/jargon/html/D/DWIM.html I don't want my editor or interpreter auto-correcting my code. I have no problem with a linter or editor flagging what it thinks are errors for me to correct, but that's as far as it goes. What makes you think the case is clear or obvious? print 1 # print(1) or print1 ? For what its worth: from Python 3.5 (I think) onwards the error you get is customized: py> print 1 File "", line 1 print 1 ^ SyntaxError: Missing parentheses in call to 'print' -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Sep 19 20:23:15 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 20 Sep 2017 10:23:15 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c1b4f5$0$14940$b1db1813$d948b532@news.astraweb.com> On Wed, 20 Sep 2017 04:31 am, bartc wrote: > On 19/09/2017 17:30, Steve D'Aprano wrote: [snip list of problems with print] > Can't you get around all those with things like sys.stdout.write? If you had kept reading, you would have seen that I wrote: Of course an experienced Python coder can work around all these problems. The main way to work around them is to *stop using print*. Using sys.stdout.write has disadvantages: - it only takes a single string argument; - which makes you responsible for doing everything that print does: * converting arbitrary arguments to strings; * joining them with spaces (or some other separator); * appending a newline (or other delimiter) at the end; * flushing the buffer; - it's about three times as long to type as "print"; - are you sure sys.stdout is pointing where you expect? So to work around *those* problems, you end up writing your own helper function, which invariably ends up being called something like print1. > If so, what was the point of having a discrete print statement/function > at all? It is easily discoverable for beginners. You don't have to learn the concepts of modules, importing, attribute access, methods, files, string escapes \n etc before being able to display output to the user. Don't get me wrong. I love print. Even the print statement is better than nothing. But once you get past the simple cases: print "Hello World!" you quickly run into its limitations. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rantingrickjohnson at gmail.com Tue Sep 19 20:26:55 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 19 Sep 2017 17:26:55 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: INADA Naoki wrote: > Rick Johnson wrote: > > INADA Naoki wrote: > > > > > > I can't agree with you. It's too redundant. It doesn't > > > provide any information about what coder think. > > > > It's not about what the "coder thinks", many times what > > the coder thinks is wrong, it's about writing code that is > > intuitive to as wide an audience as possible. > > My point is not "what the coder thinks", but "express what > the coder thinks". It's very important point about > readability. When I talk about readability, it's defined > in "The Art of Readable Code". [snip: link] It means; How > long average leveled programmer understand the code deep > enough, to modify the code or fix bug in the code. It not > means "intuitive to as wide an audience as possible." I think for most languages an intuitive syntax is not important -- C is such a language, Lisp is such a language, Perl is such a language, and there are many more -- but for Python, intuitiveness is very important. > > > While PEP 8 recommends `if x:`, I accept `if x > 0` or > > > `if len(x) > 0` when I review code in my company. > > > > So when `x` is an iterable, as in: > > > > if len(x) > 0: > > # blah > > > > You're okay with the explicit test. > > Yes, you know "this code is assuming x is container" from > redundant `len(x) > 0`. It's valuable information. As a > bonus, len(x) raises TypeError and program stops, (and > transaction will be rolled back) when x is None. Or when `x` has no __len__ method. Which has the effect of both: (1) making the code explicit, and (2) ensuring that that a chicken, a pig, and/or a cow does not sneak past our naive little "duck test". > > Or when `x` is a numeric, as in: > > > > if x > 0: > > # blah > > > > You're okay with the explicit test. > > > Yes, you know this code assumes x is numeric. `if x:` > doesn't tell the information to you. As a bonus, if x is > None, `x > 0` raises TypeError on Python 3. In the spirit of my last comment, i was going to say: "Or if `x` does not support rich comparisons", but alas, it seems that _all_ objects in Python support rich comparisons, even when it doesn't make sense to! o_O For example: >>> False > 1 False >>> dir > 1 True >>> isinstance < 100 False >>> "" >= 10 True >>> (1,) <= 500 False And down the rabbit hole we go! Now, not only do we have magic that implicitly casts all objects to booleans in conditional statements *AND* we have arbitrary Boolean values assigned to every Python object, but now, we discover that every Python object has been assigned an arbitrary rich comparison value as well! I assume the devs are using the boolean values 1 and 0 to make the comparison work??? But would someone be kind enough to chime in to confirm or deny my conjecture? Of course, allowing all objects to use the `==`, `!=` sugars makes perfect sense, but `<`, `>`, `<=`, `>=` are meaningless outside of numeric-ish types. > > So, from a standpoint of > > consistency, you /should/ be okay with this: > > > > if bool(x) == True: > > # blah > > > > But you're not! :-). > > I don't accept it because `if bool(x) == True` doesn't give > any information than `if x:`. Both mean just `if x is > truthy`. No more information. Redundant code is just a > noise. So what about: if bool(x): # blah > [...] > I can't agree with you here. And who agree with you in this > thread? This thread, like most every thread on this list (and Python-ideas for that matter), only represents a handful of Python programmers out of a large number of Python programmers who exist in the wild. And since small communities (just like a family) tend to be single-minded in their views, the fact that no one in this thread is supporting me is more a result of personal beefs and an unwillingness to consider outside opinions than any proof that my arguments are invalid. Like Fakebook, mass media, most college campuses, and every governmental organization on the _planet_, Python-list is an echo chamber; an echo chamber that has insulated itself against all outside influence, and who has become so infatuated with its own vanity, that delusion has set in, and now it considers itself as the only true judge of objective reality, and all other judgements are inferior. Fakebook is the quintessential example of how we wall ourselves off from those opinions that we do not agree with. At first, we think we are "free", but as time marches on, and we continue to constrict our little "sphere of influence" more and more, we eventually find ourselves living in a prison of our own version of reality; one in which we are surrounded by only those people who agree with us; only those who parrot "yes, yes, yes" and never "no, no, no". And it is such an environment as this that have given birth to the most depraved ideas the human mind has ever managed to conceive. >From a perverted concept of "freedom"; to a narcissistic self delusion; to a feeling of in-group superiority... that, my friends, is the direct path to depraved actions. > > While such type of optimization is possible, it's not easy > > > > as you think. You can overwrite `bool`. > > > > > > def bool(x): > > > return !x > > > > Oops. That looks like a syntax error. Ruby uses the "!" as a > > logical not operator, _not_ Python. > > > > > Sorry. Writing Python in gmail textarea is bad experience. Google software has to be the worst on the planet! And with all the financial and technical resources Google has at its disposal, you'd think they could do a little better. Listen, i don't mean to be a unappreciative jerk, because after all, were it not for the Google Chrome Webbrowser[1] Microsuck might have never gotten off its lazy bum and *FINALLY* invested some R&D into that atrocious Internet Exploder[2][3]. And sure, Google has always been kind enough to give away free software, but while beggars can't be choosers, useless software is still useless software. Why even go to the trouble of writing anything if the end product will just frustrate the hell out of every user unlucky enough to try it? And while Gmail is not the worst interface i've ever used, it's not even moderately good software. The damn spell checker is broken half the time and the interface is slow, among other things... If i were to speculate, my suspicion is that Google is not hiring qualified people. Yes, yes, i know... there is this ubiquitous "assumption" that Google is employing the best and the brightest engineers in the world, but from the evidence i have seen, this is not always the case. It seems that Google's hiring practices are more concerned with irrelevancies like political affiliation and sexual orientation than any _real_ technical ability (the echo chamber strikes again!). In one specific case i remember quite vividly, the lead engineer had to appeal to a member of the google community to write a fairly simple script that the lead engineer was unable to write himself. And upon discovering that the lead engineer was a total incompetent who couldn't even write code for the project he was hired to lead, I was shocked. But i suppose if Google wants to forsake its future and the future of its employees and stock holders so it can be feel-good social justice laboratory, well then, who am i to tell them what to do? The self driving car be damned! Besides, i hear rumblings that Amazon is about to enter the (soon to be highly competitive) self driving car market. And let's not forget, that the Asians are light years ahead of the West in robotics and automation, and with their dirt cheap labor and little regard for environmental issues, they will ultimately win this technological war. So while Google runs itself around in circles fretting over the enviroment and engineering the next generation of snowflake PTSD treatment centers (talk about a clash with reality!), the Asians are working 24-7-365 inventing the practical technology that will transform our world in ways that we still cannot even imagine. Everything is about to change: how we live; how we make war; how we make /love/. *EVERYTHING*! Oh, Sergy Brin, why don't you take off the goofy google glasses and just grab a fiddle already! > > Although, your point -- "that a programmer can shoot > > [him/her]self in the foot" -- is really moot, > > > No, it's not my point. My point is just optimizing `bool(x) > == True` is not easy as static language. Optimizer must be > very very conservative about changing language behavior. I agree. There are many ways a programmer can shoot a toe, or even an entire foot, off. And highly dynamic languages like Python make this deceptively easy: [A random pynoob writes some code, then executes it...] "Hey, look! My code runs without errors the first time! :-)" [A few minutes later...] "Aw snap! :-(" Yes, and good thing your script was not mission critical (Crash + Burn!). And as many a dynamic language user has learnt, static type checking (as onerous as it can be at times) just might save your bacon... and ducks do not lay golden eggs! ;-) [1] Which i did use and support for a year or so, but after becoming dissatisfied with the software, i returned to the loving arms of my old friend the flaming fox. [2] Which now they call "Edge", and which finally supports HTML5. 'Bout time! [3] Among many other things Microsuck had been dragging its bum about for decades! But i suppose sucking every last dime out of the latest iteration of windows95 (aka: lipstick on a pig) was more important than actually writing good, 21st century interfaces and supporting modern HTML elements and internet protocols. Go figure! From steve+python at pearwood.info Tue Sep 19 20:38:25 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 20 Sep 2017 10:38:25 +1000 Subject: Even Older Man Yells at Whippersnappers References: <1505842722l.23461932l.0l@psu.edu> Message-ID: <59c1b883$0$14953$b1db1813$d948b532@news.astraweb.com> On Wed, 20 Sep 2017 04:48 am, Larry Martell wrote: >>> It was my birthday the other day. People at worked asked how old I >>> was. I replied: >>> >>> ((3**2)+math.sqrt(400))*2 >>> >>> Quite a few people somehow came up with 47. And these are technical people. >> >> *headscratch* Multiple people got 47? I'm struggling to figure that >> out. If they interpret the first part as multiplication (3*2 => 6), >> that would get 26*2 => 52; if they don't understand the square >> rooting, they'd probably just give up; if they ignore the parentheses, >> that could give 9 + 20*2 => 49; but I can't come up with 47. I had one of my students guess that two nines was ninety-one. He had no idea where it came from either. > They could not explain it either. If you wrote the expression down, I can't explain it. If you *spoke* it to them, the answer is easy: what you said and what they kept in their short-term memory are different. For people who aren't used to doing many numerical calculations in their head, everything except the "times two" would be unfamiliar and therefore take more time and memory to process, which takes away attention from listening to the rest of the expression. I can completely believe that if you just fired off the expression rapidly: "three squared plus root four hundred all by two" or worse if you pronounced the brackets: "open paren open paren three squared close paren plus the square root of four hundred close paren by two" they could have been calculating *anything* by the time you get to the end. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Sep 19 20:44:07 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 20 Sep 2017 10:44:07 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59bf295d$0$14935$b1db1813$d948b532@news.astraweb.com> <88f92185-9187-4733-b32e-f97e0fc24205@googlegroups.com> <0a799ad2-4ba5-6c94-015b-8885082c11d2@vub.be> <59c0e1c3$0$14961$b1db1813$d948b532@news.astraweb.com> <65a57c21-5b4c-86a6-ca7a-46fdc8b1822d@vub.be> <5a340682-4314-4833-9249-530df3727243@googlegroups.com> <59c143e6$0$14933$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c1b9da$0$14953$b1db1813$d948b532@news.astraweb.com> On Wed, 20 Sep 2017 03:22 am, Chris Angelico wrote: > On Wed, Sep 20, 2017 at 2:20 AM, Steve D'Aprano > wrote: >> I can only think of four operations which are plausibly universal: >> >> Identity: compare two operands for identity. In this case, the type of the >> object is irrelevant. >> >> Kind: interrogate an object to find out what kind of thing it is (what class >> or type it is). In Python we have type(obj) and isinstance(x, Type), plus a >> slightly more specialised version issubclass. >> >> Convert to a string or human-readable representation. >> >> And test whether an object is truthy or falsey. > > Equality checks are also close to universal. If you ask if this list > is equal to that timestamp, you don't get an exception, you get False. Ah yes! Good one, and an obvious one. Asking whether two things are equal/unequal should be universal to. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rantingrickjohnson at gmail.com Tue Sep 19 20:48:28 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 19 Sep 2017 17:48:28 -0700 (PDT) Subject: Old Man Yells At Cloud In-Reply-To: <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: On Tuesday, September 19, 2017 at 2:08:05 AM UTC-5, Steven D'Aprano wrote: > [...] > 5.6775 is a much more useful answer than Fraction(2271, 400). ("What's > that in real money?") Steven, you're not using floats for currency are you? Tsk tsk! Besides, if Python division returned a useless fraction like Fraction(2271, 400), all you'd have to do is cast it to something appropriate, which in the case of currency, would be a decimal, not a float. From BILL_NOSPAM at whoknows.net Tue Sep 19 21:31:07 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Tue, 19 Sep 2017 21:31:07 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: Rick Johnson wrote: > I think for most languages an intuitive syntax is not > important -- C is such a language, Lisp is such a language, > Perl is such a language, and there are many more -- but > for Python, intuitiveness is very important. > I guess it depends on what you mean by "important" ("important to the compiler", is a legitimate concern, for instance). From an intuition perspective, C++ allowing you to separate the interface of a class from it's implementation, I would say that C++ has it all over Python from the point of view of "intuitiveness". It's much easier to tell what's going on, at a glance, in a C++ program. I am much newer to Python, but I have provided at least one concrete feature supporting my opinion. By the way, I am not talking about "toy" programs. From rantingrickjohnson at gmail.com Tue Sep 19 21:43:43 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 19 Sep 2017 18:43:43 -0700 (PDT) Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> Message-ID: <631c6316-ebd3-4e91-b225-3488a60d0ec7@googlegroups.com> On Tuesday, September 19, 2017 at 12:55:14 PM UTC-5, Chris Angelico wrote: > On Wed, Sep 20, 2017 at 3:44 AM, Stefan Ram wrote: > > Steve D'Aprano did *not* write > > [it was edited/abbreviated by me - S. R.]: > > |disadvantages: > > |0 - it makes print a special thing No more "special" than any other reserved word in Python. > > |1 - beginners have to unlearn Only if they decide to move to Python3 *AND* only if they decide to use the print function at _all_. Not everyone uses print (function or statement). Many folks prefer the power of the logging module, or use the implicit output of a REPL. > > |2 - `print(x, y)` is *not* the same as `print x, y`; Well, duh! > > |3 - it has bizarre syntax that nobody would find normal Only in advanced usage, which can be better handled by using sys.stdout.write(...) > > |4 - you can't pass keyword arguments Only in advanced cases do you need to. In those cases, wrap sys.stdout.write with your own function: # PYTHON 2.x >>> import sys >>> def myPrintFunc(*args, **kw): ... sys.stdout.write(' '.join(str(arg) for arg in args)) ... >>> myPrintFunc("Monkey", "Patching", "is easy", 2, "do!") Monkey Patching is easy 2 do! I'll leave the remaining feature implementations as an exercise for the reader... > > |5 - it can't be mocked, shadowed, monkey-patched or replaced for testing; So wrap sys.stdout.write with your own function and then mock it until it crys and runs home to mommy; shadow it until it reports you as a stalker; and monkey patch it until your sewing hand becomes racked with arthritic pain! > > |6 - and you can't even write help(print) in the interactive interpreter Hmm, neither can you get help for these: # PYTHON 2.x >>> help(del) SyntaxError: invalid syntax >>> help(if) SyntaxError: invalid syntax >>> help(else) SyntaxError: invalid syntax >>> help(for) SyntaxError: invalid syntax >>> help(class) SyntaxError: invalid syntax >>> help(def) SyntaxError: invalid syntax And this doesn't work either: >>> help(python) Traceback (most recent call last): File "", line 1, in help(python) NameError: name 'python' is not defined nor this: >>> help(BDFL) Traceback (most recent call last): File "", line 1, in help(BDFL) NameError: name 'BDFL' is not defined nor even this: >>> help("I've fallen and i can't get up!") no Python documentation found for "I've fallen and i can't get up!" Why, what a surprise!!! These so-called "disadvantages" are nothing but absurdities masquerading as debate, and more evidence that Steven, along with Chris, are on a Python3 religious crusade to rid the world of perceived infidels. From rantingrickjohnson at gmail.com Tue Sep 19 22:01:56 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Tue, 19 Sep 2017 19:01:56 -0700 (PDT) Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> Message-ID: <69224689-157a-4e26-a76e-7d411ff08213@googlegroups.com> On Tuesday, September 19, 2017 at 1:31:52 PM UTC-5, bartc wrote: [...] > Can't you get around all those with things like > sys.stdout.write? Yes. > If so, what was the point of having a discrete print > statement/function at all? I believe the original intent was to create a universal symbol for a "shortcut to sys.stdout.write". As you can imagine, if every programmer is required to implement their own version of print, not only is the wheel being re- invented, many unique symbols would be used, and Python code would be far less intuitive between authors. Furthermore, i don't believe print should have ever been expanded for use _outside_ of the most simple outputs. For instance: using print for advanced things like redirecting output is going beyond the scope of a special purpose shortcut. Finally, (and this is most important) i believe that when print() and input() are over-utilized, noobs, especially those who do not have an understanding of IO streams, fail to realize that print() and input() are just shortcuts to the more feature-rich objects living in the `sys` module. In fact, for a noob who begins programming with Python (especially when outside of a structured academic environment) they are likely to never make the connection, or, at least, not make the connection for a very long time. And being that IO streams are one of the fundamentals of programming, such a heavy reliance on shortcuts is harmful to the intellectual development of these students. From ethan at stoneleaf.us Tue Sep 19 22:15:04 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 19 Sep 2017 19:15:04 -0700 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> Message-ID: <59C1CF28.5080600@stoneleaf.us> On 09/19/2017 09:37 AM, justin walters wrote: > On Tue, Sep 19, 2017 at 9:17 AM, Grant Edwards > wrote: > >> On 2017-09-19, Jan Erik =?utf-8?q?Mostr=C3=B6m?= >> wrote: >> >>> And I'm amazed how often I see people trying to calculate >>> >>> change = sum handed over - cost >>> >>> and then trying to figure out what bills/coins should be returned >>> instead of doing the simple thing of just adding to the cost. >> >> When I was a kid, making change like that was something we were all >> taught in school. I have a feeling that's been dropped from most >> curricula. >> >> -- >> Grant Edwards grant.b.edwards Yow! MMM-MM!! So THIS >> is >> at BIO-NEBULATION! >> gmail.com >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > Not sure about the most recent decade, but back when I was in elementary > school(1995-2001-ish), > we definitely still learned math through how to make change. Ah, but making change and counting change are not the same thing! Making change: $3.61 from $10 . . . $6.39 Counting change: $3.61 from $10 -- - (give four pennies back) $3.65 - (give a dime back) $3.75 - (give a quarter back) $4.00 - (give a dollar back) $5.00 - (give a five back) and $10.00! -- ~Ethan~ From songofacandy at gmail.com Tue Sep 19 22:34:34 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Wed, 20 Sep 2017 02:34:34 +0000 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: > > >>> False > 1 > False > >>> dir > 1 > True > >>> isinstance < 100 > False > >>> "" >= 10 > True > >>> (1,) <= 500 > False > > And down the rabbit hole we go! > > Now, not only do we have magic that implicitly casts all > objects to booleans in conditional statements *AND* we have > arbitrary Boolean values assigned to every Python object, > but now, we discover that every Python object has been > assigned an arbitrary rich comparison value as well! I > assume the devs are using the boolean values 1 and 0 to make > the comparison work??? But would someone be kind enough to > chime in to confirm or deny my conjecture? > > Of course, allowing all objects to use the `==`, `!=` sugars > makes perfect sense, but `<`, `>`, `<=`, `>=` are > meaningless outside of numeric-ish types. > > Now you know why Python 3 was born! It's one of many pitfalls in Python 2 fixed in Python 3. Welcome to Python 3 world. > > I don't accept it because `if bool(x) == True` doesn't give > > any information than `if x:`. Both mean just `if x is > > truthy`. No more information. Redundant code is just a > > noise. > > So what about: > > if bool(x): > # blah > > I don't accept it too. It only explains `if x is truthy value`, and it's exactly same to `if x:`. There are no additional information about what this code assumes. bool() is just noise. -- Inada Naoki From python at mrabarnett.plus.com Tue Sep 19 23:42:19 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 20 Sep 2017 04:42:19 +0100 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <59c1b175$0$14948$b1db1813$d948b532@news.astraweb.com> Message-ID: <81760c0f-1505-9864-4808-0a1a178b9e5e@mrabarnett.plus.com> On 2017-09-20 01:41, Stefan Ram wrote: > Steve D'Aprano writes: >>A simple "autocorrect" in *what*? The interpreter? The editor? Both? > > I imagine something like this: When the editor gets the > command to run the contents of the buffer as Python, > it would then do the autocorrect in the buffer (making a > backup first or preparing an undo feature) as a kind of > preprocessor and then send the result to Python. But the > user is encouraged to also continue to work with the result > of the preprocessor. > >>Do you think Microsoft will consider adding it to Notepad? I seem to recall that >>you use an editor which doesn't even auto-indent after a colon. > > In fact, in my courses, I often use Notepad. > > In my Python course, I will use the console that comes with > Python and, later, I may introduce how to create source files > with Notepad, but I will also show IDLE. > Notepad is very basic. There are many free and open-source text editors available. I suggest you try one! From steve+comp.lang.python at pearwood.info Wed Sep 20 00:42:59 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Sep 2017 04:42:59 GMT Subject: Greater and less than operators [was Re: [Tutor] beginning to code] References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: <59c1f1d3$0$14961$b1db1813$d948b532@news.astraweb.com> On Tue, 19 Sep 2017 17:26:55 -0700, Rick Johnson wrote: > Of course, allowing all objects to use the `==`, `!=` sugars makes > perfect sense, but `<`, `>`, `<=`, `>=` are meaningless outside of > numeric-ish types. You've never wanted to sort strings? How do you sort strings unless you have a concept of which string comes before the other, i.e. < operator? >>> 'xyz' < 'abc' False Same applies to lists of items. Provided the items are compatible with ordering, so are the lists. Likewise other sequences. And for that matter, sets. Maybe we'd prefer to use the proper mathematical operators ? and ? for subset and superset, but a good ASCII equivalent would be < and > instead. Likewise, any time you want to express some sort of order relationship: pawn < rook < knight < bishop < queen < king perhaps. (Although, in real games of chess, the value of a piece partly depends on what other pieces are left on the board.) Or perhaps you have some sort of custom DSL (Domain Specific Language) where > and < make handy symbols for something completely unrelated to ordering: cake > oven # put cake into the oven cake < oven # remove cake from oven I don't mean that as a serious example of a useful DSL. But it is the kind of thing we might want to do. Only hopefully less lame. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From pavol.lisy at gmail.com Wed Sep 20 00:55:56 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Wed, 20 Sep 2017 06:55:56 +0200 Subject: Old Man Yells At Cloud In-Reply-To: <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> Message-ID: On 9/19/17, Steve D'Aprano wrote: [...] > The point is, we all make the occasional silly error. Doesn't mean we should > cripple our functions and fill the language with special cases like the > print > statement to avoid such rare errors. If print had always been a function, > and > someone suggested making it a statement, who would be willing to accept all > those disadvantages for the sake of saving one character? I am not going to support print as a statement in this discussion! But what you are describing is some kind of alternative history which did not happen. Question was not about crippling function to statement. (Which function?) What I mean is that if we like to convince people that it was good decision then we need to use proper arguments. For example some others which seems like not so proper to me: 1. "learn-unlearn" argument could be viewed differently from opposite camp (they need to unlearn statement) 2. "print foo" save more than one character ("print foo ," more than two characters) 3. "for sake of saving one character"? Could we really simplify motivation of opposite side to just this? (what about breaking old code?) BTW if python would only bring "from __cleverness__ import print_function" how many people would accept your reasons and use it? And how many would rewrite old code? How many people would say something like: "Oh it is cool! Now I could rewrite my old code and monkey patch print!" ? From no.email at nospam.invalid Wed Sep 20 00:58:13 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Tue, 19 Sep 2017 21:58:13 -0700 Subject: [RELEASE] Python 3.6.3rc1 and 3.7.0a1 are now available for testing and more References: <15E3769E-F938-44F6-AD38-EAAE976A49D2@python.org> Message-ID: <871sn2ge56.fsf@nightsong.com> Ned Deily writes: > You can find Python 3.7.0a1 and more information here: > https://www.python.org/downloads/release/python-370a1/ This says: The next pre-release of Python 3.7 will be 3.6.0a2, currently scheduled for 2016-10-16. :) From jsteward2930 at gmail.com Wed Sep 20 01:30:30 2017 From: jsteward2930 at gmail.com (Joey Steward) Date: Tue, 19 Sep 2017 22:30:30 -0700 Subject: Issues with python commands in windows powershell Message-ID: Hello, I've been having issues using basic python commands in windows powershell. I'm new to programming so just going off of online tutorials. Earlier I was unable to use pip to install Django (pip install Django), and came to this forum for help and someone was able to give me the correct command for windows 10 (py -m pip install django). I've been trying to run this command django-admin startproject mytests, but get the same error message as when trying to run the original pip django-admin : *The term 'django-admin' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,* *verify that the path is correct and try again.* *At line:1 char:1* + django-admin startproject mytestsite + ~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (django-admin:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException I'm very new so honestly have no idea what the issue may be, but from previously trying to use python I think it may have something to do with configuring windows environment variables? Not sure, but just something I've ran into in the past previous times trying to learn python for more data analysis purposes. Any help would be greatly appreciated! Thanks a lot, Joey Steward From rosuav at gmail.com Wed Sep 20 01:39:56 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Sep 2017 15:39:56 +1000 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 20, 2017 at 2:55 PM, Pavol Lisy wrote: > BTW if python would only bring "from __cleverness__ import > print_function" how many people would accept your reasons and use it? > And how many would rewrite old code? > > How many people would say something like: "Oh it is cool! Now I could > rewrite my old code and monkey patch print!" ? Cool thing is that now that 'print' isn't a keyword, you can actually write that as: from cleverness import print and put whatever functionality you like into cleverness.py. The only thing you *can't* do that way is mess with syntax - and if you want to prototype a change to syntax, you can play with MacroPy. So you can actually publish something and ask people to try using it. ChrisA From steve+comp.lang.python at pearwood.info Wed Sep 20 02:01:12 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 20 Sep 2017 06:01:12 GMT Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <631c6316-ebd3-4e91-b225-3488a60d0ec7@googlegroups.com> Message-ID: <59c20427$0$14961$b1db1813$d948b532@news.astraweb.com> On Tue, 19 Sep 2017 18:43:43 -0700, Rick Johnson wrote: > On Tuesday, September 19, 2017 at 12:55:14 PM UTC-5, Chris Angelico > wrote: >> On Wed, Sep 20, 2017 at 3:44 AM, Stefan Ram >> wrote: >> > Steve D'Aprano did *not* write [it was >> > edited/abbreviated by me - S. R.]: >> > |disadvantages: >> > |0 - it makes print a special thing > > No more "special" than any other reserved word in Python. The other reserved words are either: - values, like None, which can be included in expressions; - operators, like `is`, `or`, and `not`; - block statements, like `for x in seq` or `while flag` which require a block; - statements, like `import` and `del`, which operate on names rather than values. (Did I miss any?) print is the only one which could be a function, and looks like a function (apart from the lack of parens). Hence people keep trying to do things like use it in lambdas: https://www.quora.com/Why-does-putting-print-inside-a-Python-lambda- function-raise-a-syntax-error Since it *could* be a function, but isn't, that makes it special in a special way. >> > |1 - beginners have to unlearn > > Only if they decide to move to Python3 *AND* only if they decide to use > the print function at _all_. Even if you don't use print, you will still have to read other people's code that uses it. And its not just a Python 3 issue. Long before there was a Python 3, people would over-generalise from function calls and add extraneous brackets around print's argument. It wouldn't matter if you were printing a single value, but if you printed two arguments, you would actually print a tuple instead. Here are some more recent examples: https://stackoverflow.com/questions/38254008/ https://stackoverflow.com/questions/36345800/ but if you have plenty of time on your hands to search the archives of this mailing list (newsgroup) you'll find people occasionally writing "print(...)" all the way back to Python 2.0 or 1.5. Very possibly including me. >> > |2 - `print(x, y)` is *not* the same as `print x, y`; > > Well, duh! Duh to *you and me*, perhaps, but not so obvious to everyone. See links above. And especially not obvious to beginners, who have to learn that print is magically and unlike all other functions, doesn't require parentheses. [...] > I'll leave the remaining feature implementations as an exercise for the > reader... I already said that you can work around the crippling limitations of print by avoiding it. So why have a standard print (pseudo-)function if it is so crippled and limited that it has to be worked around to be useful for anything more complicated than "Hello World"? For the microscopic cost of requiring parens when calling the print function, you gain all the features of a function. That's a great tradeoff. Beginners have to learn to use parens for every other function they use. Having one more is an insignificant cost. And for advanced programmers, now you have a print function that is actually useful. >> > |5 - it can't be mocked, shadowed, monkey-patched or replaced for >> > testing; > > So wrap sys.stdout.write with your own function and then mock it until > it crys and runs home to mommy; shadow it until it reports you as a > stalker; and monkey patch it until your sewing hand becomes racked with > arthritic pain! You aren't thinking it through far enough. If it's *my* code, I can just use my editor to search for "print foo" and replace it with "awesome_print(foo)" and I'm done. But if I'm using a library or some other piece of code that uses print, and I can't edit the source code (maybe I don't even have the source code), I need to mock it (etc). Now I'm completely out of luck, because you can't shadow or replace the print statement. I *might* be able to hack up some sort of magic replacement for stdout, but that's easier said than done, and if the library is printing to other files I'm screwed. What am I going to do, chase down every single call to print? How? By scanning the .pyc files and disassembling the byte-code? Sure, if you are willing to invest sufficiently large time, money and effort, there's a solution. But something which should take literally five seconds: import nasty_library_that_uses_print as nasty nasty.print = lambda *args: logger(*args) # or similar could take weeks of development effort to get right. >> > |6 - and you can't even write help(print) in the interactive >> > interpreter > > Hmm, neither can you get help for these: > > # PYTHON 2.x > >>> help(del) > SyntaxError: invalid syntax Indeed you can't. But there is a very good reason why del, if, else etc are statements. They *have to be*. For example, you can't write del as a function, because if you do, it won't receive the names of the variables, only their values. It's a trade-off. With del, if, else etc, the value of them being statements far outweighs the disadvantages. But for print, its the other way around. As I've said, apart from saving *one* character (okay, if it makes Rick feel better, two keystrokes on a QWERTY keyboard), what actual concrete, positive benefit is there in making print a statement? If print had always been a function, what arguments are there for making it a statement? -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From robin at reportlab.com Wed Sep 20 03:46:00 2017 From: robin at reportlab.com (Robin Becker) Date: Wed, 20 Sep 2017 08:46:00 +0100 Subject: How do I check all variables returned buy the functions exists In-Reply-To: <59bc7720$0$16749$b1db1813$d948b532@news.astraweb.com> References: <59bc7720$0$16749$b1db1813$d948b532@news.astraweb.com> Message-ID: On 16/09/2017 01:58, Steve D'Aprano wrote: ........ > > If you want to test for None specifically: > > if any(v is None for v in values): > print "at least one value was None" > ....... for some reason that seems slow on my machine when compared with if None in values: ..... > C:\usr\share\robin\pythonDoc>python -m timeit -s"values=(1,2,None)" "any(v is None for v in values)" > 1000000 loops, best of 3: 0.62 usec per loop > > C:\usr\share\robin\pythonDoc>python -m timeit -s"values=(None,2,None)" "any(v is None for v in values)" > 1000000 loops, best of 3: 0.504 usec per loop > > C:\usr\share\robin\pythonDoc>python -m timeit -s"values=(None,2,None)" "None in values" > 10000000 loops, best of 3: 0.0309 usec per loop > > C:\usr\share\robin\pythonDoc>python -m timeit -s"values=(1,2,None)" "None in values" > 10000000 loops, best of 3: 0.097 usec per loop it also seems a bit less obvious -- Robin Becker From BILL_NOSPAM at whoknows.net Wed Sep 20 04:04:29 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Wed, 20 Sep 2017 04:04:29 -0400 Subject: How do I check all variables returned buy the functions exists In-Reply-To: References: <59bc7720$0$16749$b1db1813$d948b532@news.astraweb.com> Message-ID: Robin Becker wrote: > On 16/09/2017 01:58, Steve D'Aprano wrote: > ........ >> >> If you want to test for None specifically: >> >> if any(v is None for v in values): >> print "at least one value was None" >> > ....... > > for some reason that seems slow on my machine when compared with > > if None in values: > ..... > > This does not seem particularly surprising. "None in values" is known as soon as None is found. In "any(v is None for v in values)", "any" probably isn't called until its argument is (fully) known. Of course the results would depend on the implementation. It would be interesting to compare the results if you used the optimize option (it's either -o or -O). Bill >> C:\usr\share\robin\pythonDoc>python -m timeit -s"values=(1,2,None)" >> "any(v is None for v in values)" >> 1000000 loops, best of 3: 0.62 usec per loop >> >> C:\usr\share\robin\pythonDoc>python -m timeit >> -s"values=(None,2,None)" "any(v is None for v in values)" >> 1000000 loops, best of 3: 0.504 usec per loop >> >> C:\usr\share\robin\pythonDoc>python -m timeit >> -s"values=(None,2,None)" "None in values" >> 10000000 loops, best of 3: 0.0309 usec per loop >> >> C:\usr\share\robin\pythonDoc>python -m timeit -s"values=(1,2,None)" >> "None in values" >> 10000000 loops, best of 3: 0.097 usec per loop > > it also seems a bit less obvious From rosuav at gmail.com Wed Sep 20 04:16:03 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Sep 2017 18:16:03 +1000 Subject: Old Man Yells At Cloud In-Reply-To: <59c20427$0$14961$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <631c6316-ebd3-4e91-b225-3488a60d0ec7@googlegroups.com> <59c20427$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 20, 2017 at 4:01 PM, Steven D'Aprano wrote: > The other reserved words are either: > > - values, like None, which can be included in expressions; > > - operators, like `is`, `or`, and `not`; > > - block statements, like `for x in seq` or `while flag` which > require a block; > > - statements, like `import` and `del`, which operate on names > rather than values. > > (Did I miss any?) > > > print is the only one which could be a function, and looks like a > function (apart from the lack of parens). I'd add one additional variant that could be a function, and that's 'del' when used on something other than a simple name: >>> del values[2] Conceptually, this is very similar to values.pop(2), only it doesn't return the value. But for its simple-name form, where it reverses the effect of assignment to a simple name, it has to be a statement. ChrisA From leamhall at gmail.com Wed Sep 20 04:20:51 2017 From: leamhall at gmail.com (Leam Hall) Date: Wed, 20 Sep 2017 04:20:51 -0400 Subject: How to share class relationship representations? In-Reply-To: References: Message-ID: <388b9bc5-9a5e-fd47-1caf-46d796a51931@gmail.com> On 09/19/2017 11:16 AM, Stefan Ram wrote: > leam hall writes: >> I'm working on designing the classes, sub-classes, and relationships in my >> code. What is a good visual way to represent it so it can be stored in git >> and shared on the list without large images or attachments? > > Code /is/ design. I tried that with the small bit of code I have and was told it was too confusing. Still working on this. From greg.ewing at canterbury.ac.nz Wed Sep 20 05:09:53 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 20 Sep 2017 21:09:53 +1200 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> Message-ID: Rhodri James wrote: > Tsk. You should have learned (a fake simplified) assembler first, Never mind that fake assembly rubbish, learn a real assembly language! And hand-assemble it and toggle it into the front panel switches like I did! -- Greg From greg.ewing at canterbury.ac.nz Wed Sep 20 05:12:37 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 20 Sep 2017 21:12:37 +1200 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> Message-ID: Grant Edwards wrote: > Alternatively, you should design an instruction set and implement it > using microcode and AM2900 bit-slice processors. AMD2900? That's cheating! You should design and build your own logic gates. After refining the silicon to make the transistors first, of course. -- Greg From __peter__ at web.de Wed Sep 20 05:14:42 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 20 Sep 2017 11:14:42 +0200 Subject: How do I check all variables returned buy the functions exists References: <59bc7720$0$16749$b1db1813$d948b532@news.astraweb.com> Message-ID: Bill wrote: > Robin Becker wrote: >> On 16/09/2017 01:58, Steve D'Aprano wrote: >> ........ >>> >>> If you want to test for None specifically: >>> >>> if any(v is None for v in values): >>> print "at least one value was None" >>> >> ....... >> >> for some reason that seems slow on my machine when compared with >> >> if None in values: >> ..... >> >> > This does not seem particularly surprising. "None in values" is known > as soon as None is found. > In "any(v is None for v in values)", "any" probably isn't called until > its argument is (fully) known. Of course the results would depend on > the implementation. It would be interesting to compare the results if > you used the optimize option (it's either -o or -O). > > Bill I don't think that optimisation can do much here, but there's another aspect that has a realistic chance to affect the result: None in values checks equality, and that may be slower than comparing identities: $ python3 -m timeit -s"from slow_eq import A; values = 1, 2, A()" "any(v is None for v in values)" 1000000 loops, best of 3: 1.1 usec per loop $ python3 -m timeit -s"from slow_eq import A; values = 1, 2, A()" "None in values" 10 loops, best of 3: 1 sec per loop That's of course an extreme example that I wilfully constructed: $ cat slow_eq.py import time class A: def __eq__(self, other): time.sleep(1) return NotImplemented >>> C:\usr\share\robin\pythonDoc>python -m timeit -s"values=(1,2,None)" >>> "any(v is None for v in values)" >>> 1000000 loops, best of 3: 0.62 usec per loop >>> >>> C:\usr\share\robin\pythonDoc>python -m timeit >>> -s"values=(None,2,None)" "any(v is None for v in values)" >>> 1000000 loops, best of 3: 0.504 usec per loop >>> >>> C:\usr\share\robin\pythonDoc>python -m timeit >>> -s"values=(None,2,None)" "None in values" >>> 10000000 loops, best of 3: 0.0309 usec per loop >>> >>> C:\usr\share\robin\pythonDoc>python -m timeit -s"values=(1,2,None)" >>> "None in values" >>> 10000000 loops, best of 3: 0.097 usec per loop >> >> it also seems a bit less obvious From rosuav at gmail.com Wed Sep 20 05:54:38 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Sep 2017 19:54:38 +1000 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> Message-ID: On Wed, Sep 20, 2017 at 7:12 PM, Gregory Ewing wrote: > Grant Edwards wrote: >> >> Alternatively, you should design an instruction set and implement it >> using microcode and AM2900 bit-slice processors. > > > AMD2900? That's cheating! You should design and build your > own logic gates. After refining the silicon to make the > transistors first, of course. What, you take silicon that someone else created?! ChrisA From steve+python at pearwood.info Wed Sep 20 07:50:29 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 20 Sep 2017 21:50:29 +1000 Subject: Even Older Man Yells At Whippersnappers References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> Message-ID: <59c25608$0$14955$b1db1813$d948b532@news.astraweb.com> On Wed, 20 Sep 2017 07:12 pm, Gregory Ewing wrote: > Grant Edwards wrote: >> Alternatively, you should design an instruction set and implement it >> using microcode and AM2900 bit-slice processors. > > AMD2900? That's cheating! You should design and build your > own logic gates. After refining the silicon to make the > transistors first, of course. Silicon? You had it easy. In my day all we had was hydrogen and helium, we had to make our own silicon using fusion. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 20 07:53:41 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 20 Sep 2017 21:53:41 +1000 Subject: Even Older Man Yells At Whippersnappers References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> <59c25608$0$14955$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c256c7$0$14955$b1db1813$d948b532@news.astraweb.com> On Wed, 20 Sep 2017 09:50 pm, Steve D'Aprano wrote: > On Wed, 20 Sep 2017 07:12 pm, Gregory Ewing wrote: > >> Grant Edwards wrote: >>> Alternatively, you should design an instruction set and implement it >>> using microcode and AM2900 bit-slice processors. >> >> AMD2900? That's cheating! You should design and build your >> own logic gates. After refining the silicon to make the >> transistors first, of course. > > Silicon? You had it easy. > > In my day all we had was hydrogen and helium, we had to make our own silicon > using fusion. Of course, when I say all we had was hydrogen and helium, I mean we had to make it first from a quark/gluon plasma. Won't catch us using somebody else's substandard silicon. Probably use the wrong electron charge and all. Of course you don't get quark/gluon plasma like that any more. You can't get the magnetic monopoles. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 20 08:07:14 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 20 Sep 2017 22:07:14 +1000 Subject: How do I check all variables returned buy the functions exists References: <59bc7720$0$16749$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c259f5$0$14934$b1db1813$d948b532@news.astraweb.com> On Wed, 20 Sep 2017 06:04 pm, Bill wrote: > Robin Becker wrote: >> On 16/09/2017 01:58, Steve D'Aprano wrote: >> ........ >>> >>> If you want to test for None specifically: >>> >>> if any(v is None for v in values): >>> print "at least one value was None" >>> >> ....... >> >> for some reason that seems slow on my machine when compared with >> >> if None in values: >> ..... I'm not sure whether to be surprised or not. The first one only checks for identity, which should be really fast, while the `is` operator tests for equality too, which may slow things down a touch. So that suggests that any(...) ought to be faster. But any(...) is iterating over a generator expression, which has overhead, whereas `None in values` may have less overhead. On balance, I expected any(...) to be a smidgen faster, but I guess I'm not that surprised if it went the other way. Ah... I see that Robin is using especially small tuples, of only three items. Yes, I can see why the overhead of the generator expression would slow that down. But try it with a list of a thousand values... ... and the `is` operator is still faster. Today I learned something. [steve at ando ~]$ python3.5 -m timeit -s "values=list(range(1000))+[None]" "any(x is None for x in values)" 1000 loops, best of 3: 191 usec per loop [steve at ando ~]$ python3.5 -m timeit -s "values=list(range(1000))+[None]" "None in values" 10000 loops, best of 3: 60.1 usec per loop > This does not seem particularly surprising. "None in values" is known > as soon as None is found. That's how any() works too. It returns as soon as it finds a true result. > In "any(v is None for v in values)", "any" probably isn't called until > its argument is (fully) known. No, its a generator expression, so it provides the values one at a time, as needed. > Of course the results would depend on > the implementation. It would be interesting to compare the results if > you used the optimize option (it's either -o or -O). I wouldn't expect that to make any difference. Currently Python's optimization levels are pretty weak sauce: -O disables any assert statements; -OO disables asserts, and removes docstrings. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From alister.ware at ntlworld.com Wed Sep 20 08:58:44 2017 From: alister.ware at ntlworld.com (alister) Date: Wed, 20 Sep 2017 12:58:44 GMT Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> <59c0c330$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: <8CtwB.1479928$WI6.467553@fx30.am4> On Tue, 19 Sep 2017 14:40:17 -0400, leam hall wrote: > On Tue, Sep 19, 2017 at 2:37 PM, Stephan Houben < > stephanh42 at gmail.com.invalid> wrote: > >> Op 2017-09-19, Steven D'Aprano schreef > pearwood.info>: >> >> > There is a significant chunk of the Python community for whom "just >> > pip install it" is not easy, legal or even possible. For them, if its >> > not in the standard library, it might as well not even exist. >> >> But numpy *is* in the standard library, provided you download the >> correct version of Python, namely the one from: >> >> https://python-xy.github.io/ >> >> Stephan >> >> > Many of us can't pip install; it's in the OS supplied vendor repo or it > doesn't go on the machines. > > Leam dnf install or apt_get install most of the mainstream modules seem to be there (certainly numpy) -- Kliban's First Law of Dining: Never eat anything bigger than your head. From gheskett at shentel.net Wed Sep 20 09:12:03 2017 From: gheskett at shentel.net (Gene Heskett) Date: Wed, 20 Sep 2017 09:12:03 -0400 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: <201709200912.03287.gheskett@shentel.net> On Wednesday 20 September 2017 05:09:53 Gregory Ewing wrote: > Rhodri James wrote: > > Tsk. You should have learned (a fake simplified) assembler first, > > Never mind that fake assembly rubbish, learn a real assembly > language! And hand-assemble it and toggle it into the front > panel switches like I did! > > -- > Greg So did I Greg, except the cosmac super elf I started on, at least had a hex monitor for an os. This was in 1978. Wrote a commercial preparation utility for an automatic station break machine when I was at KRCR-TV in Redding CA. I of course went on down the road in due time. Fast fwd 15 years, I'd changed women and was then the CE at WDTV-5 here in WV, but had some vacation time so we flew back to Oregon to visit an aunt who was running out of time. While "in the neighborhood" I called the tv station and found that my gismo was still in several times a day use. Thats an eon or two in a stations tech equipment time. Funny part is that the next spring, at the annual NAB show in Lost Wages, I spotted the makings of a similar device in the Microtime booth, and commented that mine could do this and that that theirs couldn't. Microtime was rather famous for having more lawyers than engineers. The product disappeared from the display, and was never seen or admitted to even exist again. So I was the only one to ever do that particular job, no one ever did anything similar, but back in the days when tv stations below the top 25 were all running Sony 3/4" u-matic video Tape machines, the image quality lost in making a copy was substantial, and my gismo saved a one generation copy that markedly improved the image quality of our commercial breaks. Thats good for Nielson ratings, 2 points in the next book, at a market 162 station. The average General Manager would kill for a 2 point better Nielson book. And I had fun doing it! 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 p.f.moore at gmail.com Wed Sep 20 09:14:24 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 20 Sep 2017 14:14:24 +0100 Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" In-Reply-To: <8CtwB.1479928$WI6.467553@fx30.am4> References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> <59c0c330$0$14961$b1db1813$d948b532@news.astraweb.com> <8CtwB.1479928$WI6.467553@fx30.am4> Message-ID: On 20 September 2017 at 13:58, alister via Python-list wrote: > On Tue, 19 Sep 2017 14:40:17 -0400, leam hall wrote: > >> On Tue, Sep 19, 2017 at 2:37 PM, Stephan Houben < >> stephanh42 at gmail.com.invalid> wrote: >> >>> Op 2017-09-19, Steven D'Aprano schreef >> pearwood.info>: >>> >>> > There is a significant chunk of the Python community for whom "just >>> > pip install it" is not easy, legal or even possible. For them, if its >>> > not in the standard library, it might as well not even exist. >>> >>> But numpy *is* in the standard library, provided you download the >>> correct version of Python, namely the one from: >>> >>> https://python-xy.github.io/ >>> >>> Stephan >>> >>> >> Many of us can't pip install; it's in the OS supplied vendor repo or it >> doesn't go on the machines. >> >> Leam > > dnf install > or > apt_get install > > most of the mainstream modules seem to be there (certainly numpy) You're missing the point. A significant number of Python users work on systems where: 1. They have no admin rights 2. Their corporate or other policies prohibit installing 3rd party software without approval that is typically difficult or impossible to get 3. Quite possibly the system has no network access outside of the local intranet 4. The system admins may not be able or willing to upgrade or otherwise modify the system Python Writing code that works only with stdlib modules is basically the only option in such environments. Having said that, I don't advocate that everything be in the stdlib because of this. A lot of things (such as numpy) belong as 3rd party packages. But that doesn't mean that "get XYZ off PyPI" (or "install XYZ alternative Python distribution/version") is a viable solution to every problem. Paul From mimsichka23 at gmail.com Wed Sep 20 09:20:07 2017 From: mimsichka23 at gmail.com (mimsichka23 at gmail.com) Date: Wed, 20 Sep 2017 06:20:07 -0700 (PDT) Subject: Feature extraction assignment for training machine learning classifier in python Message-ID: Hi all, I have a question concerning this task. I need to train a classifier for a list of treebank sentences and extract features POS and FORM and then train a transition-based parser algorithm? Do you have any idea how I can do that, I used CountVectorizer and MultinomialNB but i have difficulty implementing the code.. Id be thankful if you could give me a hint.. From steve+python at pearwood.info Wed Sep 20 09:59:42 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 20 Sep 2017 23:59:42 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c27450$0$14948$b1db1813$d948b532@news.astraweb.com> On Wed, 20 Sep 2017 02:55 pm, Pavol Lisy wrote: > On 9/19/17, Steve D'Aprano wrote: > > [...] > >> The point is, we all make the occasional silly error. Doesn't mean we should >> cripple our functions and fill the language with special cases like the >> print >> statement to avoid such rare errors. If print had always been a function, >> and >> someone suggested making it a statement, who would be willing to accept all >> those disadvantages for the sake of saving one character? > > I am not going to support print as a statement in this discussion! > > But what you are describing is some kind of alternative history which > did not happen. Right. The philosophical term is "counterfactual", the more common term is "hypothetical situation". https://en.wikipedia.org/wiki/Counterfactual_conditional It is sometimes called the historical subjunctive, after the subjunctive grammatical tense: https://www.goodreads.com/quotes/606824-it-s-subjunctive-history-you-know-the-subjunctive-the-mood-used See also: https://en.wikipedia.org/wiki/Subjunctive_possibility > Question was not about crippling function to statement. (Which function?) > > What I mean is that if we like to convince people that it was good > decision then we need to use proper arguments. The hypothetical question is a good argument. We want Python to be the language it could possible be. Which would give us a better language? 1. Start with print statement, and change to print function. (This is what really happened.) 2. Start with a print function, and change to a print statement. (This is a hypothetical situation.) I think that number 1 is *much better* than two. Now consider that we already live in world number 1. print is now a function. To anyone who argues that print was better as a statement, would you like to live in world 2? Its not too late. We could say that the change in 1 was a terrible mistake, and revert it, and then number 2 will be the actual world. To make that come true, all you need do is make a strong enough argument for why the print statement is *so much better* than the function that it is worth the disruption of changing the language again. But I'd be satisfied with any reason at all with the statement was better, apart from: (a) "you save one character (two keystrokes)"; and (b) "that's what I was used to". > For example some others which seems like not so proper to me: > > 1. "learn-unlearn" argument could be viewed differently from opposite > camp (they need to unlearn statement) Beginners and novices don't have to unlearn the print statement, because they haven't learned it yet. A beginner to Python hasn't learned anything yet. They start to learn the language, and discover that `len` needs parentheses. `int` needs parens. `str` needs parens. `math.sqrt` needs parens. `chr` needs parens. `open` needs parens. `str.find` needs parens. Dozens upon dozens, hundreds, even thousands of functions and methods all need parens. Except for `print`, which looks like a function but isn't. So for `print`, they need to unlearn the rule "always use parentheses when calling a function" and replace it with "except for print", or "but print is not a function, so the rule doesn't apply". Either way, print is an exception that has to be unlearned from the general rule. I agree, once you have learned that print is special, then moving to Python 3 means you have to unlearn that print is special. Its not special any more in Python 3. > 2. "print foo" save more than one character ("print foo ," more than > two characters) Count the characters more closely: print foo # nine characters, including the space print(foo) # ten characters, including the parentheses The difference between ten and nine is one, as I said. Suppressing the newline at the end is a little shorter: print foo, # ten characters print(foo, end='') # eighteen characters but the loss of brevity is more than made up for by the gain in self-documenting code. Changing the separator between items is a big win for the print function: print ', '.join(str(obj) for obj in (foo, bar, baz)) # 52 chars # and builds up a potentially large string ahead of time print(foo, bar, baz, sep=', ') # 30 chars # and DOESN'T build up a large string ahead of time # and is self-explanatory > 3. "for sake of saving one character"? Could we really simplify > motivation of opposite side to just this? (what about breaking old > code?) I don't know what the motivation of the "print should be a statement!" side is, because they never say why it was better. (If they have said, I have never seen it.) All they do is say "it was a terrible mistake to change, print was better as a statement". I *completely agree* that there was some pain in breaking backwards compatibility. That's why Guido waited so many years before fixing his mistake in making print a statement. "print is a statement" was in Guido's list of regrets all the way back in 2002: http://legacy.python.org/doc/essays/ppt/regrets/PythonRegrets.pdf and it wasn't fixed until Python 3. He explains some of his reasons why here: https://mail.python.org/pipermail/python-dev/2005-September/056154.html Guido is not the only one who found that print was too limiting and best avoided: https://mail.python.org/pipermail/python-dev/2005-September/056164.html I admit I haven't read ALL the posts discussing the question of print: https://mail.python.org/pipermail/python-dev/2005-September/thread.html but I'm still looking for a good argument beyond "don't want to type parens" and "we've always done it that way" for keeping print a statement. The closest I came to was Fredrik Lundh's post: https://mail.python.org/pipermail/python-dev/2005-September/056247.html The only problem with his arguments for keeping print a statement is that they apply equally to print as a function! Fredrik: A reserved word makes it easy to grep for. You can grep for "print(" just as easily as "print". Fredrik: It does the right thing under the hood: converts things to their string representation, calls write repeatedly instead of allocating a buffer large enough to hold all components, doesn't print un- necessary trailing spaces, etc. So does the print function. Fredrik: Using a statement syntax makes it possible to use a readable syntax for redirection (and other possible extensions); it's obvious that this isn't printing to stdout: print >>file, bacon(ham), spam, "=", eggs(number=count) I suppose that Unix system admins might be used to > used for file re-direction, but that's one of the most hated features of print statement, and its hardly something that is easy to guess for people who haven't learned it. print(args, file=sys.stderr) is surely more self-explanatory than print >>sys.stderr, args even if it takes a couple of extra characters. Fredrik: It can print to anything that implements a "write" method. And so can the print function. So out for Fredrik's four arguments in favour of print statement, one is a matter of opinion (he likes >>file, most people hate it) and the other three hold equally for print as a function. > BTW if python would only bring "from __cleverness__ import > print_function" how many people would accept your reasons and use it? Many people use "from __future__ import print_function". Are you aware that Python 3 exists? print is already a function, and Python 2.7 supports it as a future import. > And how many would rewrite old code? *shrug* Some people will upgrade old code to new versions of Python. Some people won't. It depends on the program, whether it is worth upgrading or not. But what I want to see are reasons why print as a statement was better. Not just "that's what I'm used to". -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Sep 20 10:01:36 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 21 Sep 2017 00:01:36 +1000 Subject: How do I check all variables returned buy the functions exists References: <59bc7720$0$16749$b1db1813$d948b532@news.astraweb.com> <59c259f5$0$14934$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c274c1$0$14948$b1db1813$d948b532@news.astraweb.com> On Wed, 20 Sep 2017 10:07 pm, Steve D'Aprano wrote: > I'm not sure whether to be surprised or not. > > The first one only checks for identity, which should be really fast, while the > `is` operator tests for equality too, Oops, that's supposed to be `in`, not `is`. [...] > Ah... I see that Robin is using especially small tuples, of only three items. > Yes, I can see why the overhead of the generator expression would slow that > down. But try it with a list of a thousand values... > > ... and the `is` operator is still faster. Today I learned something. And *that* should be `in`. Sigh. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From skip.montanaro at gmail.com Wed Sep 20 10:07:49 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 20 Sep 2017 09:07:49 -0500 Subject: How to get Nose to run doctests from my Markdown documentation? Message-ID: I routinely include doctests as a source of test cases in my nose runs, but I want to also coax it to check the examples in my Markdown files. Is there a way to do this? If I explicitly give a Markdown file on the command line, nose complains: Unable to load tests from file ... Am I perhaps missing some sort of nose-markdown plugin which would magically make this work? Thx, Skip From larry.martell at gmail.com Wed Sep 20 10:29:08 2017 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 20 Sep 2017 10:29:08 -0400 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> Message-ID: On Wed, Sep 20, 2017 at 5:09 AM, Gregory Ewing wrote: > > Never mind that fake assembly rubbish, learn a real assembly > language! And hand-assemble it and toggle it into the front > panel switches like I did! 1979, I was working at Bausch and Lomb in Rochester NY. We had a 16 bit Data General Nova 'Minicomputer'. It had 4 registers, called accumulators. It had 16 front panel toggle switches, one for each bit, one that said 'deposit', and one that said run. It had a dial with stops for AC0, AC1, AC2, AC3 (for the 4 accumulators), PC (program counter), address and contents. When you powered up the machine it did not boot. You had to hand enter a short bootstrap program in binary. Do to this you had to turn the dial to address, key in a 16 bit address, click deposit, turn the dial to contents, key in a 16 bit line of assembly code, click deposit, and repeat this for each line of code (there were like 5 or 6). Then key in the address of where you wanted to run from turn the dial to PC, deposit, and click run. Any mistake and it would not boot. Often took 3 or 4 tries. After a few weeks of this I was sick of it. I had the boot code burned into an EEPROM (which I had to send out to be programmed). Then I build a very small wire wrapped board with the EEPROM and an oscillator and few TTL chips. I tapped into the 5V power on the CPU board and used the leading edge of that to trigger a one shot which 'woke up' my circuit, and caused it to clock out the code from the EEPROM and load it to the appropriate place, set the program counter and start the program. I drilled holes in the CPU board and mounted this with little plastic standoffs. I did this all on my own, coming in on the weekends, without company approval, and when it was working I showed my boss. He was blown away and he was sure we could patent this and sell it. He had me formalize the design, write it up, have an actual PCB made, go to the company lawyers, the whole 9 yards. Then Data General announced the new version of the Nova .... with auto boot. From malaclypse2 at gmail.com Wed Sep 20 10:50:00 2017 From: malaclypse2 at gmail.com (Jerry Hill) Date: Wed, 20 Sep 2017 10:50:00 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: On Tue, Sep 19, 2017 at 8:26 PM, Rick Johnson wrote: > In the spirit of my last comment, i was going to say: "Or if > `x` does not support rich comparisons", but alas, it seems that > _all_ objects in Python support rich comparisons, even when > it doesn't make sense to! o_O For example: > > >>> False > 1 > False > >>> dir > 1 > True > >>> isinstance < 100 > False > >>> "" >= 10 > True > >>> (1,) <= 500 > False Rick, I'm pretty sure you already know that you're being deceptive here. If anyone else comes across this and doesn't already realize it, note that Rick is complaining about behavior that changed almost a decade ago (with the release of Python 3.0). Here's what a modern python does with those same statements: Python 3.5.2 (default, Aug 18 2017, 17:48:00) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> False > 1 False >>> dir > 1 Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: builtin_function_or_method() > int() >>> isinstance < 100 Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: builtin_function_or_method() < int() >>> "" >= 10 Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: str() >= int() >>> (1,) <= 500 Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: tuple() <= int() >>> -- Jerry From ned at nedbatchelder.com Wed Sep 20 10:50:54 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 20 Sep 2017 10:50:54 -0400 Subject: How to get Nose to run doctests from my Markdown documentation? In-Reply-To: References: Message-ID: On 9/20/17 10:07 AM, Skip Montanaro wrote: > I routinely include doctests as a source of test cases in my nose runs, but > I want to also coax it to check the examples in my Markdown files. Is there > a way to do this? If I explicitly give a Markdown file on the command line, > nose complains: > > Unable to load tests from file ... > > Am I perhaps missing some sort of nose-markdown plugin which would > magically make this work? > > Thx, > > Skip There are tools for getting doctests out of .rst files.? Is it an option to use .rst instead of .md? --Ned. From walters.justin01 at gmail.com Wed Sep 20 11:12:30 2017 From: walters.justin01 at gmail.com (justin walters) Date: Wed, 20 Sep 2017 08:12:30 -0700 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> Message-ID: On Wed, Sep 20, 2017 at 7:29 AM, Larry Martell wrote: > On Wed, Sep 20, 2017 at 5:09 AM, Gregory Ewing > wrote: > > > > Never mind that fake assembly rubbish, learn a real assembly > > language! And hand-assemble it and toggle it into the front > > panel switches like I did! > > 1979, I was working at Bausch and Lomb in Rochester NY. We had a 16 > bit Data General Nova 'Minicomputer'. It had 4 registers, called > accumulators. It had 16 front panel toggle switches, one for each bit, > one that said 'deposit', and one that said run. It had a dial with > stops for AC0, AC1, AC2, AC3 (for the 4 accumulators), PC (program > counter), address and contents. > > When you powered up the machine it did not boot. You had to hand enter > a short bootstrap program in binary. Do to this you had to turn the > dial to address, key in a 16 bit address, click deposit, turn the dial > to contents, key in a 16 bit line of assembly code, click deposit, and > repeat this for each line of code (there were like 5 or 6). Then key > in the address of where you wanted to run from turn the dial to PC, > deposit, and click run. Any mistake and it would not boot. Often took > 3 or 4 tries. > > After a few weeks of this I was sick of it. I had the boot code burned > into an EEPROM (which I had to send out to be programmed). Then I > build a very small wire wrapped board with the EEPROM and an > oscillator and few TTL chips. I tapped into the 5V power on the CPU > board and used the leading edge of that to trigger a one shot which > 'woke up' my circuit, and caused it to clock out the code from the > EEPROM and load it to the appropriate place, set the program counter > and start the program. I drilled holes in the CPU board and mounted > this with little plastic standoffs. > > I did this all on my own, coming in on the weekends, without company > approval, and when it was working I showed my boss. He was blown away > and he was sure we could patent this and sell it. He had me formalize > the design, write it up, have an actual PCB made, go to the company > lawyers, the whole 9 yards. Then Data General announced the new > version of the Nova .... with auto boot. > -- > https://mail.python.org/mailman/listinfo/python-list > That's crazy! The oldest computer I ever owned was a 1984 Tandy 1000. I actually still miss that thing. It had an option where you could change the 8-bit music that played on startup. Luckily for me, it took 5.25" floppys. From tjol at tjol.eu Wed Sep 20 11:14:02 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 20 Sep 2017 17:14:02 +0200 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <59c1b175$0$14948$b1db1813$d948b532@news.astraweb.com> Message-ID: <4796f034-c61a-59ff-df11-07504e016cbb@tjol.eu> On 2017-09-20 17:06, Dennis Lee Bieber wrote: > On Wed, 20 Sep 2017 10:08:18 +1000, Steve D'Aprano > declaimed the following: > >> For what its worth: from Python 3.5 (I think) onwards the error you get is >> customized: >> >> py> print 1 >> File "", line 1 >> print 1 >> ^ >> SyntaxError: Missing parentheses in call to 'print' >> > > So... "print" (the function") is still a special case for the > interpreter... > Thankfully just the interpreter, and not you or me. Also, print is not alone in this regard: Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print 1 File "", line 1 print 1 ^ SyntaxError: Missing parentheses in call to 'print' >>> exec 'print 1' File "", line 1 exec 'print 1' ^ SyntaxError: Missing parentheses in call to 'exec' >>> exec('print 1') Traceback (most recent call last): File "", line 1, in File "", line 1 print 1 ^ SyntaxError: Missing parentheses in call to 'print' >>> -- Thomas Jollans From skip.montanaro at gmail.com Wed Sep 20 11:14:40 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 20 Sep 2017 10:14:40 -0500 Subject: How to get Nose to run doctests from my Markdown documentation? In-Reply-To: References: Message-ID: > I routinely include doctests as a source of test cases in my nose runs, but I want to also coax it to check the > examples in my Markdown files. Is there a way to do this? If I explicitly give a Markdown file on the command line, > nose complains: > > Unable to load tests from file ... I believe I figured this out. It appears to be sufficient to add doctest-extension=md to my noserc file. Camping happy, am I, Skip From skip.montanaro at gmail.com Wed Sep 20 11:17:07 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 20 Sep 2017 10:17:07 -0500 Subject: How to get Nose to run doctests from my Markdown documentation? In-Reply-To: References: Message-ID: > There are tools for getting doctests out of .rst files. Is it an option to > use .rst instead of .md? Given the existence proof of md working as an extension (see my previous follow-up), my guess is that it more-or-less supports just about any nearly-plain-text format. I could use .rst, I suppose, but then I'd have to add a magic token to my files to tell Emacs they are really in Markdown format. Skip From tjol at tjol.eu Wed Sep 20 11:26:32 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 20 Sep 2017 17:26:32 +0200 Subject: Old Man Yells At Cloud In-Reply-To: <9f59484f-a8e0-6dcc-b78e-160baaa67028@VybeNetworks.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <9f59484f-a8e0-6dcc-b78e-160baaa67028@VybeNetworks.com> Message-ID: <0fa1fd7c-b864-e192-c900-d296bbe4b2fa@tjol.eu> On 2017-09-19 16:30, D'Arcy Cain wrote: > On 09/19/2017 06:46 AM, Larry Martell wrote: >> True story - the other day I was in a store and my total was $10.12. I > > One time I was at a cash with three or four items which were taxable. > The cashier rung each one up and hit the total button.? She turned to me > and said something like "$23.42 please."? She was surprised to see that > I was already standing there with $23.42 in my hand.? "How did you do > that" she asked.? She must have thought it was a magic trick. > God I hate shopping in the US. There you are, adding up the prices on the products you pick up, figuring out (approximately) how much you'll owe, you go to pay, and the next thing you know there's some unspecified (!) markup added to the price. D'Arcy, I'm with the cashier. You're clearly a witch (or warlock). -- Thomas Jollans From skip.montanaro at gmail.com Wed Sep 20 11:27:32 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 20 Sep 2017 10:27:32 -0500 Subject: How to get Nose to run doctests from my Markdown documentation? In-Reply-To: References: Message-ID: Actually, I semi-lied. It seems to pick up the second of two examples, and gets a bit confused about leading whitespace. I think I need to do some more fiddling. S From rosuav at gmail.com Wed Sep 20 11:50:42 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Sep 2017 01:50:42 +1000 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <59c1b175$0$14948$b1db1813$d948b532@news.astraweb.com> Message-ID: On Thu, Sep 21, 2017 at 1:06 AM, Dennis Lee Bieber wrote: > On Wed, 20 Sep 2017 10:08:18 +1000, Steve D'Aprano > declaimed the following: > >>For what its worth: from Python 3.5 (I think) onwards the error you get is >>customized: >> >>py> print 1 >> File "", line 1 >> print 1 >> ^ >>SyntaxError: Missing parentheses in call to 'print' >> > > So... "print" (the function") is still a special case for the > interpreter... Yes, because of all the people migrating from Python 2. If print had never been a statement, this special case wouldn't have been needed. And it's only a special case in the handling of one specific exception - at the point where you would otherwise get a generic error, it checks to see if it could possibly be a Py2 print statement, and if so, adjusts the text of the exception. ChrisA From alister.ware at ntlworld.com Wed Sep 20 12:11:18 2017 From: alister.ware at ntlworld.com (alister) Date: Wed, 20 Sep 2017 16:11:18 GMT Subject: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?" References: <28ad4360-d09c-4252-8612-ba720dcbcd42@googlegroups.com> <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> <59c0c330$0$14961$b1db1813$d948b532@news.astraweb.com> <8CtwB.1479928$WI6.467553@fx30.am4> Message-ID: On Wed, 20 Sep 2017 14:14:24 +0100, Paul Moore wrote: > On 20 September 2017 at 13:58, alister via Python-list > wrote: >> On Tue, 19 Sep 2017 14:40:17 -0400, leam hall wrote: >> >>> On Tue, Sep 19, 2017 at 2:37 PM, Stephan Houben < >>> stephanh42 at gmail.com.invalid> wrote: >>> >>>> Op 2017-09-19, Steven D'Aprano schreef >>> pearwood.info>: >>>> >>>> > There is a significant chunk of the Python community for whom "just >>>> > pip install it" is not easy, legal or even possible. For them, if >>>> > its not in the standard library, it might as well not even exist. >>>> >>>> But numpy *is* in the standard library, provided you download the >>>> correct version of Python, namely the one from: >>>> >>>> https://python-xy.github.io/ >>>> >>>> Stephan >>>> >>>> >>> Many of us can't pip install; it's in the OS supplied vendor repo or >>> it doesn't go on the machines. >>> >>> Leam >> >> dnf install >> or apt_get install >> >> most of the mainstream modules seem to be there (certainly numpy) > > You're missing the point. A significant number of Python users work on > systems where: > > 1. They have no admin rights 2. Their corporate or other policies > prohibit installing 3rd party software without approval that is > typically difficult or impossible to get 3. Quite possibly the system > has no network access outside of the local intranet 4. The system admins > may not be able or willing to upgrade or otherwise modify the system > Python > > Writing code that works only with stdlib modules is basically the only > option in such environments. > > Having said that, I don't advocate that everything be in the stdlib > because of this. A lot of things (such as numpy) belong as 3rd party > packages. But that doesn't mean that "get XYZ off PyPI" (or "install XYZ > alternative Python distribution/version") is a viable solution to every > problem. > > Paul not missing the point you said previously "it's in the OS supplied vendor repo or it doesn't go on the machines." dnf/yum or apt_get install form the "vendor supplied repo" I fully understand that even this may require various hoops to be jumped through before it can happen -- Minnie Mouse is a slow maze learner. From ned at nedbatchelder.com Wed Sep 20 12:12:20 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 20 Sep 2017 12:12:20 -0400 Subject: How to get Nose to run doctests from my Markdown documentation? In-Reply-To: References: Message-ID: On 9/20/17 11:17 AM, Skip Montanaro wrote: >> There are tools for getting doctests out of .rst files. Is it an option to >> use .rst instead of .md? > Given the existence proof of md working as an extension (see my > previous follow-up), my guess is that it more-or-less supports just > about any nearly-plain-text format. I could use .rst, I suppose, but > then I'd have to add a magic token to my files to tell Emacs they are > really in Markdown format. > I didn't mean, "Can you name your Markdown files with an .rst extension," I meant, "Can you use ReST instead of Markdown?" --Ned. From skip.montanaro at gmail.com Wed Sep 20 12:14:58 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 20 Sep 2017 11:14:58 -0500 Subject: How to get Nose to run doctests from my Markdown documentation? In-Reply-To: References: Message-ID: > I didn't mean, "Can you name your Markdown files with an .rst extension," I > meant, "Can you use ReST instead of Markdown?" I wondered if maybe I was misinterpreting your question. :-) Conceptually, yes, I could use ReST. I'm just trying to go with the flow here at work. Markdown seems to be the agreed upon way to write plain text documentation. Skip From skip.montanaro at gmail.com Wed Sep 20 12:15:13 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 20 Sep 2017 11:15:13 -0500 Subject: How to get Nose to run doctests from my Markdown documentation? In-Reply-To: References: Message-ID: > Actually, I semi-lied. It seems to pick up the second of two examples, > and gets a bit confused about leading whitespace. I think I need to do > some more fiddling. Solved the whitespace issue with the +NORMALIZE_WHITESPACE flag. It turns out that it actually does run all examples in the document. They are just concatenated into one big "test". Skip From kwpolska at gmail.com Wed Sep 20 12:24:39 2017 From: kwpolska at gmail.com (Chris Warrick) Date: Wed, 20 Sep 2017 18:24:39 +0200 Subject: Stdlib, what's in, what's out In-Reply-To: References: <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> <97a340e6-e4e3-4c6e-b14d-59ea40f5471b@googlegroups.com> <5709c5f5-c725-41a9-aa36-8260101799c9@googlegroups.com> Message-ID: On 20 September 2017 at 17:16, Dennis Lee Bieber wrote: > On Tue, 19 Sep 2017 11:58:47 -0700 (PDT), John Ladasky > declaimed the following: > >> >>And of course I have found some other third-party packages: scipy, pandas, matplotlib, and PyQt5 are important for my work. I helped a student of mine get selenium running. In the case of PyQt, I found TKinter unsatisfactory many years ago, and went looking for better choices. I used wxPython first, when I was working in Py2. When wxPython was slow to migrate to Py3, I went searching again. >> > > And if wxPython had been part of the stdlib, it would have meant Python > 3 would have been delayed years until wxPython had been ported -- or > wxPython would have been pulled from the stdlib and something else put in > its place... > > So no help to those migrating. If wxPython had been part of the stdlib, there would be much more manpower to port it to 3. Also, the project underwent a complete rewrite, which dooms many projects to failure. Perhaps they wouldn?t try the rewrite, or they would port the older codebase to Python 3 so that it could be shipped. (They?re currently at Beta 2 of the post-rewrite 4.0.0 version.) -- Chris Warrick PGP: 5EAAEA16 From ethan at stoneleaf.us Wed Sep 20 12:39:34 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 20 Sep 2017 09:39:34 -0700 Subject: Stdlib, what's in, what's out In-Reply-To: References: <5194eddd-0939-4865-b231-f2598468c2a4@googlegroups.com> <97a340e6-e4e3-4c6e-b14d-59ea40f5471b@googlegroups.com> <5709c5f5-c725-41a9-aa36-8260101799c9@googlegroups.com> Message-ID: <59C299C6.5040700@stoneleaf.us> On 09/20/2017 09:24 AM, Chris Warrick wrote: > On 20 September 2017 at 17:16, Dennis Lee Bieber wrote: >> And if wxPython had been part of the stdlib, it would have meant Python >> 3 would have been delayed years until wxPython had been ported -- or >> wxPython would have been pulled from the stdlib and something else put in >> its place... >> >> So no help to those migrating. > > If wxPython had been part of the stdlib, there would be much more > manpower to port it to 3. How do you figure? The available manpower is what it took to get Python 3 itself out when it came out; adding another project as large as wxPython would not magically make it so the same target dates were hit -- it's not like we have core-devs sitting idly by waiting for something to do. -- ~Ethan~ From gheskett at shentel.net Wed Sep 20 13:03:41 2017 From: gheskett at shentel.net (Gene Heskett) Date: Wed, 20 Sep 2017 13:03:41 -0400 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: <201709201303.41546.gheskett@shentel.net> On Wednesday 20 September 2017 10:29:08 Larry Martell wrote: > On Wed, Sep 20, 2017 at 5:09 AM, Gregory Ewing > > wrote: > > Never mind that fake assembly rubbish, learn a real assembly > > language! And hand-assemble it and toggle it into the front > > panel switches like I did! > > 1979, I was working at Bausch and Lomb in Rochester NY. We had a 16 > bit Data General Nova 'Minicomputer'. It had 4 registers, called > accumulators. It had 16 front panel toggle switches, one for each bit, > one that said 'deposit', and one that said run. It had a dial with > stops for AC0, AC1, AC2, AC3 (for the 4 accumulators), PC (program > counter), address and contents. > > When you powered up the machine it did not boot. You had to hand enter > a short bootstrap program in binary. Do to this you had to turn the > dial to address, key in a 16 bit address, click deposit, turn the dial > to contents, key in a 16 bit line of assembly code, click deposit, and > repeat this for each line of code (there were like 5 or 6). Then key > in the address of where you wanted to run from turn the dial to PC, > deposit, and click run. Any mistake and it would not boot. Often took > 3 or 4 tries. > > After a few weeks of this I was sick of it. I had the boot code burned > into an EEPROM (which I had to send out to be programmed). Then I > build a very small wire wrapped board with the EEPROM and an > oscillator and few TTL chips. I tapped into the 5V power on the CPU > board and used the leading edge of that to trigger a one shot which > 'woke up' my circuit, and caused it to clock out the code from the > EEPROM and load it to the appropriate place, set the program counter > and start the program. I drilled holes in the CPU board and mounted > this with little plastic standoffs. > > I did this all on my own, coming in on the weekends, without company > approval, and when it was working I showed my boss. He was blown away > and he was sure we could patent this and sell it. He had me formalize > the design, write it up, have an actual PCB made, go to the company > lawyers, the whole 9 yards. Then Data General announced the new > version of the Nova .... with auto boot. Chuckle, love it Larry. But then I am sure it was not that much of a problem for you. That super elf? Used a broadcast audio cart in an old machine whose capstan was badly worn so it played a regular cart at about 90% speed for its non-volatile memory. Didn't bither the elf a bot, never had it fail to load and run the next copy of my program. I had saved 4 or 5 copies on a 2 minute cart. Then did another for backup, and a 3rd cart I took home. Fast fwd to 2017, it and a paper copy of that machine code is on the top shelf here in this room. Yeah, I've had packratitis all my life. 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 jsteward2930 at gmail.com Wed Sep 20 13:09:35 2017 From: jsteward2930 at gmail.com (Joey Steward) Date: Wed, 20 Sep 2017 10:09:35 -0700 Subject: Fwd: Issues with python commands in windows powershell In-Reply-To: References: Message-ID: ---------- Forwarded message ---------- From: Joey Steward Date: Tue, Sep 19, 2017 at 10:30 PM Subject: Issues with python commands in windows powershell To: python-list at python.org Hello, I've been having issues using basic python commands in windows powershell. I'm new to programming so just going off of online tutorials. Earlier I was unable to use pip to install Django (pip install Django), and came to this forum for help and someone was able to give me the correct command for windows 10 (py -m pip install django). I've been trying to run this command django-admin startproject mytests, but get the same error message as when trying to run the original pip django-admin : *The term 'django-admin' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,* *verify that the path is correct and try again.* *At line:1 char:1* + django-admin startproject mytestsite + ~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (django-admin:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException I'm very new so honestly have no idea what the issue may be, but from previously trying to use python I think it may have something to do with configuring windows environment variables? Not sure, but just something I've ran into in the past previous times trying to learn python for more data analysis purposes. Any help would be greatly appreciated! Thanks a lot, Joey Steward From jsteward2930 at gmail.com Wed Sep 20 13:09:43 2017 From: jsteward2930 at gmail.com (Joey Steward) Date: Wed, 20 Sep 2017 10:09:43 -0700 Subject: Fwd: Issues with python commands in windows powershell In-Reply-To: References: Message-ID: ---------- Forwarded message ---------- From: Joey Steward Date: Wed, Sep 20, 2017 at 10:09 AM Subject: Fwd: Issues with python commands in windows powershell To: python-list at python.org ---------- Forwarded message ---------- From: Joey Steward Date: Tue, Sep 19, 2017 at 10:30 PM Subject: Issues with python commands in windows powershell To: python-list at python.org Hello, I've been having issues using basic python commands in windows powershell. I'm new to programming so just going off of online tutorials. Earlier I was unable to use pip to install Django (pip install Django), and came to this forum for help and someone was able to give me the correct command for windows 10 (py -m pip install django). I've been trying to run this command django-admin startproject mytests, but get the same error message as when trying to run the original pip django-admin : *The term 'django-admin' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,* *verify that the path is correct and try again.* *At line:1 char:1* + django-admin startproject mytestsite + ~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (django-admin:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException I'm very new so honestly have no idea what the issue may be, but from previously trying to use python I think it may have something to do with configuring windows environment variables? Not sure, but just something I've ran into in the past previous times trying to learn python for more data analysis purposes. Any help would be greatly appreciated! Thanks a lot, Joey Steward From irmen.NOSPAM at xs4all.nl Wed Sep 20 13:22:06 2017 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Wed, 20 Sep 2017 19:22:06 +0200 Subject: Fw: Problems Installing Python36 In-Reply-To: References: <20170912.034647.1218.0@webmail04.vgs.untd.com> <6278c207-2744-5603-b983-6d73c451714f@tjol.eu> <2e23c425-0ddf-8cc7-25ac-20f4568941c9@gmail.com> Message-ID: <59c2a3bc$0$792$e4fe514c@news.xs4all.nl> On 14/09/2017 05:46, Michael Torrie wrote: > On 09/12/2017 03:05 AM, Thomas Jollans wrote: >> Other people on this list: >> This isn't the first time I've someone with this issue here. It's >> probably putting off plenty of potential new users who don't make as >> much effort to find a solution. I can't say I understand the ins and >> outs of installing things on Windows... is there anything that can be done? > > Last time I brought this up, someone mentioned that the Python installer > is supposed to automatically install this runtime library if it's not > installed already. If so, why are so many people having this problem? > That is what I'm wondering as well. The only thing I can think of is that it asks windows update to install said KB update but that it depends on something else that isn't installed or that the user running the installation doesn't have the rights to install windows updates. (I suspect something will be logged in the event viewer somewhere...?) Or that it doesn't attempt to download it at all and that we are misinformed :P Btw, I personally never had any issues installing Python on Windows. Irmen From steve+python at pearwood.info Wed Sep 20 13:27:48 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 21 Sep 2017 03:27:48 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <59c1b175$0$14948$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c2a517$0$14943$b1db1813$d948b532@news.astraweb.com> On Thu, 21 Sep 2017 01:06 am, Dennis Lee Bieber wrote: > On Wed, 20 Sep 2017 10:08:18 +1000, Steve D'Aprano > declaimed the following: > >>For what its worth: from Python 3.5 (I think) onwards the error you get is >>customized: >> >>py> print 1 >> File "", line 1 >> print 1 >> ^ >>SyntaxError: Missing parentheses in call to 'print' >> > > So... "print" (the function") is still a special case for the > interpreter... One of Python's weaknesses is that many error messages are fairly obscure and uninformative, and the devs are trying to fix that. If that means treating some things as "special cases", so be it, because practicality beats purity. But yes, print is specifically a special case because of its history in Python 2. And for exactly the same reason, exec() is also special-cased: py> exec '1' File "", line 1 exec '1' ^ SyntaxError: Missing parentheses in call to 'exec' -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From BILL_NOSPAM at whoknows.net Wed Sep 20 13:58:58 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Wed, 20 Sep 2017 13:58:58 -0400 Subject: How do I check all variables returned buy the functions exists In-Reply-To: <59c259f5$0$14934$b1db1813$d948b532@news.astraweb.com> References: <59bc7720$0$16749$b1db1813$d948b532@news.astraweb.com> <59c259f5$0$14934$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > >> In "any(v is None for v in values)", "any" probably isn't called until >> its argument is (fully) known. > No, its a generator expression, so it provides the values one at a time, as > needed. > > Okay, thank you for setting me straight. I'm only about 2 weeks down this road so far! : ) From jsteward2930 at gmail.com Wed Sep 20 14:01:17 2017 From: jsteward2930 at gmail.com (Joey Steward) Date: Wed, 20 Sep 2017 11:01:17 -0700 Subject: Fwd: Issues with python commands in windows powershell In-Reply-To: References: Message-ID: ---------- Forwarded message ---------- From: Joey Steward Date: Tue, Sep 19, 2017 at 10:30 PM Subject: Issues with python commands in windows powershell To: python-list at python.org Hello, I've been having issues using basic python commands in windows powershell. I'm new to programming so just going off of online tutorials. Earlier I was unable to use pip to install Django (pip install Django), and came to this forum for help and someone was able to give me the correct command for windows 10 (py -m pip install django). I've been trying to run this command django-admin startproject mytests, but get the same error message as when trying to run the original pip django-admin : *The term 'django-admin' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,* *verify that the path is correct and try again.* *At line:1 char:1* + django-admin startproject mytestsite + ~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (django-admin:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException I'm very new so honestly have no idea what the issue may be, but from previously trying to use python I think it may have something to do with configuring windows environment variables? Not sure, but just something I've ran into in the past previous times trying to learn python for more data analysis purposes. Any help would be greatly appreciated! Thanks a lot, Joey Steward From BILL_NOSPAM at whoknows.net Wed Sep 20 14:17:31 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Wed, 20 Sep 2017 14:17:31 -0400 Subject: Fwd: Issues with python commands in windows powershell In-Reply-To: References: Message-ID: Joey Steward wrote: > ---------- Forwarded message ---------- > From: Joey Steward > Date: Tue, Sep 19, 2017 at 10:30 PM > Subject: Issues with python commands in windows powershell > To: python-list at python.org > > > Hello, > > I've been having issues using basic python commands in windows powershell. Did you try the same ones in an environment besides powershell? From ben.usenet at bsb.me.uk Wed Sep 20 15:42:16 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 20 Sep 2017 20:42:16 +0100 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <9f59484f-a8e0-6dcc-b78e-160baaa67028@VybeNetworks.com> Message-ID: <87tvzx6tt3.fsf@bsb.me.uk> bartc writes: > Value-Added-Tax in the UK increased from 17.5% to 20%, ... When it was 17.5% you could shock people not in the know by working it out in your head since it's much simpler than it sounds: take a tenth, halve it, halve it again, and add all three. -- Ben. From tjreedy at udel.edu Wed Sep 20 15:52:06 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 20 Sep 2017 15:52:06 -0400 Subject: Fwd: Issues with python commands in windows powershell In-Reply-To: References: Message-ID: On 9/20/2017 1:09 PM, Joey Steward wrote: > ---------- Forwarded message ---------- > From: Joey Steward > Date: Tue, Sep 19, 2017 at 10:30 PM > Subject: Issues with python commands in windows powershell > To: python-list at python.org > > > Hello, > > I've been having issues using basic python commands in windows powershell. > I'm new to programming so just going off of online tutorials. > > Earlier I was unable to use pip to install Django (pip install Django), and > came to this forum for help and someone was able to give me the correct > command for windows 10 (py -m pip install django). > > I've been trying to run this command django-admin startproject mytests, but > get the same error message as when trying to run the original pip Try py -m django-admin startproject mytests. If this does not work, ask on django lists. > django-admin : *The term 'django-admin' is not recognized as the name of a > cmdlet, function, script file, or operable program. Check the spelling of > the name, or if a path was included,* > *verify that the path is correct and try again.* > *At line:1 char:1* > + django-admin startproject mytestsite > + ~~~~~~~~~~~~ > + CategoryInfo : ObjectNotFound: (django-admin:String) [], > CommandNotFoundException > + FullyQualifiedErrorId : CommandNotFoundException > > > I'm very new so honestly have no idea what the issue may be, but from > previously trying to use python I think it may have something to do with > configuring windows environment variables? Not sure, but just something > I've ran into in the past previous times trying to learn python for more > data analysis purposes. > > Any help would be greatly appreciated! > > Thanks a lot, > > Joey Steward > -- Terry Jan Reedy From ben.usenet at bsb.me.uk Wed Sep 20 16:04:48 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 20 Sep 2017 21:04:48 +0100 Subject: Even Older Man Yells At Whippersnappers References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> <9c9a4ccd-652f-0c72-fff6-fbc4aa2f1eca@kynesim.co.uk> Message-ID: <87lgl96srj.fsf@bsb.me.uk> Larry Martell writes: > On Tue, Sep 19, 2017 at 12:12 PM, Rhodri James wrote: >> >> Eh, my school never 'ad an electronics class, nor a computer neither. Made >> programming a bit tricky; we 'ad to write programs on a form and send 'em >> off to next county. None of this new-fangled VHDL neither, we 'ad to do our >> simulations with paper and pencil. >> > > We dreamed of writing programs on a form. We had to make Hollerith > punch cards by hand using a dull knife. You tell that to the kids of > today and they won't believe you. Dull knife, was it? Luxury! We had to dab at card wi' tongue 'till it were wet enough to punch with a whittled stick. -- Ben. From grant.b.edwards at gmail.com Wed Sep 20 16:32:57 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 20 Sep 2017 20:32:57 +0000 (UTC) Subject: Even Older Man Yells At Whippersnappers References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> <4FD1225A-5B15-4674-8BFB-C8A8341638A1@icloud.com> Message-ID: On 2017-09-19, Christopher Reimer wrote: > Is assembly still a thing today? Depends on what you're doing. If you're working with custom-designed boards, you often have to write some assembly for startup and interrupt stuff. If you're porting an OS kernel to a new architecture, you have to write some assembly. > I wanted to take assembly in college but I was the only student who > showed up and the class got cancelled. I dabbled with 8-but assembly > as a kid. I can't imagine what assembly is on a 64-bit processor. On a decent processor (ARM, Power, SPARC) it's fine (in some wasy simpler and easier than on many 8-bit processors). On x86_64 it's a mess -- just like it was a mess on x86 (and to a large extent on 8086). -- Grant Edwards grant.b.edwards Yow! So this is what it at feels like to be potato gmail.com salad From grant.b.edwards at gmail.com Wed Sep 20 16:35:18 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 20 Sep 2017 20:35:18 +0000 (UTC) Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-09-19, Stefan Ram wrote: > Chris Angelico writes: >>On Wed, Sep 20, 2017 at 4:59 AM, Stefan Ram wrote: >>>I don't get this. For example, the contractual payment (cost) is >>>47.21 >>>, the other party hands over >>>50.25 >>>. Now I am supposed to add /what/ to the cost? >>Start at the smallest end. You need to make 21 cents up to 25. So hand >>back four pennies. > > Yes, but to know this ("four") I have to do a /subtraction/: > > 25 - 21 = 4. No, you don't. You start at "21" and hand out pennies while counting up to "25". -- Grant Edwards grant.b.edwards Yow! ... I have read the at INSTRUCTIONS ... gmail.com From grant.b.edwards at gmail.com Wed Sep 20 16:38:19 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 20 Sep 2017 20:38:19 +0000 (UTC) Subject: Even Older Man Yells At Whippersnappers References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdc93c$0$16733$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> Message-ID: On 2017-09-20, Gregory Ewing wrote: > Grant Edwards wrote: >> Alternatively, you should design an instruction set and implement it >> using microcode and AM2900 bit-slice processors. > > AMD2900? That's cheating! You should design and build your > own logic gates. After refining the silicon to make the > transistors first, of course. Digging up the sand with your bare hands, no doubt. ;) -- Grant Edwards grant.b.edwards Yow! In 1962, you could buy at a pair of SHARKSKIN SLACKS, gmail.com with a "Continental Belt," for $10.99!! From jpolo at mail.usf.edu Wed Sep 20 18:13:41 2017 From: jpolo at mail.usf.edu (john polo) Date: Wed, 20 Sep 2017 17:13:41 -0500 Subject: errors with json.loads Message-ID: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> Greetings, I am using IPython 6.1.0 with Python 3.6.2 on a Windows 7 machine. I am not a programmer. I am using a book called Python Data Analytics to try to learn some of Python. I am at a section for reading and writing JSON data. The example JSON file is: Listing 5-13.? books.json [{"writer": "Mark Ross", ?"nationality": "USA", ?"books": [ ???????? {"title": "XML Cookbook", "price": 23.56}, ???????? {"title": "Python Fundamentals", "price": 50.70}, ???????? {"title": "The NumPy library", "price": 12.30} ???????????? ] }, {"writer": "Barbara Bracket", ?"nationality": "UK", ?"books": [ ???????? {"title": "Java Enterprise", "price": 28.60}, ???????? {"title": "HTML5", "price": 31.35}, ???????? {"title": "Python for Dummies", "price": 28.00} ???????????? ] }] and the example code for reading the file is: >>> file = open('books.json','r') >>> text = file.read() >>> text = json.loads(text) When I use those 3 lines, I get the following: JSONDecodeError?????????????????????????? Traceback (most recent call last) in () ----> 1 text = json.loads(text) c:\users\..\python\python36\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) ??? 352???????????? parse_int is None and parse_float is None and ??? 353???????????? parse_constant is None and object_pairs_hook is None and not kw): --> 354???????? return _default_decoder.decode(s) ??? 355???? if cls is None: ??? 356???????? cls = JSONDecoder c:\users\..\python\python36\lib\json\decoder.py in decode(self, s, _w) ??? 337 ??? 338???????? """ --> 339???????? obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ??? 340???????? end = _w(s, end).end() ??? 341???????? if end != len(s): c:\users\..\python\python36\lib\json\decoder.py in raw_decode(self, s, idx) ??? 353???????? """ ??? 354???????? try: --> 355???????????? obj, end = self.scan_once(s, idx) ??? 356???????? except StopIteration as err: ??? 357???????????? raise JSONDecodeError("Expecting value", s, err.value) from None JSONDecodeError: Expecting ':' delimiter: line 5 column 50 (char 161) ?json.loads says that the method is for deserializing "s", with "s" being a string, bytes, or bytearray. In [24]: type(text) Out[24]: str So "text" seems to be a string. Why does json.loads return an error? John From gordon at panix.com Wed Sep 20 18:56:02 2017 From: gordon at panix.com (John Gordon) Date: Wed, 20 Sep 2017 22:56:02 +0000 (UTC) Subject: errors with json.loads References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> Message-ID: In john polo writes: > JSONDecodeError: Expecting ':' delimiter: line 5 column 50 (char 161) > ?json.loads says that the method is for deserializing "s", with "s" > being a string, bytes, or bytearray. > In [24]: type(text) > Out[24]: str > So "text" seems to be a string. Why does json.loads return an error? Because, although text is the right type, it does not contain a valid json string. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From BILL_NOSPAM at whoknows.net Wed Sep 20 18:58:54 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Wed, 20 Sep 2017 18:58:54 -0400 Subject: errors with json.loads In-Reply-To: References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> Message-ID: Interesting problem, John. I have probably even less experience with json than you do, so I'm taking this as an opportunity to learn with you. Suggestions: 1. Try your example with Python 2 rather than Python 3. 2. Take your file and make it into a string literal in your program, and try calling json.loads with that as an argument. Share with us what happens! Good luck, Bill john polo wrote: > Greetings, > > I am using IPython 6.1.0 with Python 3.6.2 on a Windows 7 machine. I > am not a programmer. I am using a book called Python Data Analytics to > try to learn some of Python. I am at a section for reading and writing > JSON data. The example JSON file is: > > > Listing 5-13. books.json > [{"writer": "Mark Ross", > "nationality": "USA", > "books": [ > {"title": "XML Cookbook", "price": 23.56}, > {"title": "Python Fundamentals", "price": 50.70}, > {"title": "The NumPy library", "price": 12.30} > ] > }, > {"writer": "Barbara Bracket", > "nationality": "UK", > "books": [ > {"title": "Java Enterprise", "price": 28.60}, > {"title": "HTML5", "price": 31.35}, > {"title": "Python for Dummies", "price": 28.00} > ] > }] > > and the example code for reading the file is: > > >>> file = open('books.json','r') > >>> text = file.read() > >>> text = json.loads(text) > > When I use those 3 lines, I get the following: > > JSONDecodeError Traceback (most recent call > last) > in () > ----> 1 text = json.loads(text) > > c:\users\..\python\python36\lib\json\__init__.py in loads(s, encoding, > cls, object_hook, parse_float, parse_int, parse_constant, > object_pairs_hook, **kw) > 352 parse_int is None and parse_float is None and > 353 parse_constant is None and object_pairs_hook is > None and not kw): > --> 354 return _default_decoder.decode(s) > 355 if cls is None: > 356 cls = JSONDecoder > > c:\users\..\python\python36\lib\json\decoder.py in decode(self, s, _w) > 337 > 338 """ > --> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) > 340 end = _w(s, end).end() > 341 if end != len(s): > > c:\users\..\python\python36\lib\json\decoder.py in raw_decode(self, s, > idx) > 353 """ > 354 try: > --> 355 obj, end = self.scan_once(s, idx) > 356 except StopIteration as err: > 357 raise JSONDecodeError("Expecting value", s, > err.value) from None > > JSONDecodeError: Expecting ':' delimiter: line 5 column 50 (char 161) > > ?json.loads says that the method is for deserializing "s", with "s" > being a string, bytes, or bytearray. > > In [24]: type(text) > Out[24]: str > > So "text" seems to be a string. Why does json.loads return an error? > > > John > From BILL_NOSPAM at whoknows.net Wed Sep 20 19:04:01 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Wed, 20 Sep 2017 19:04:01 -0400 Subject: errors with json.loads In-Reply-To: References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> Message-ID: john polo wrote: > Greetings, > > I am using IPython 6.1.0 with Python 3.6.2 on a Windows 7 machine. I > am not a programmer. I am using a book called Python Data Analytics to > try to learn some of Python. I am at a section for reading and writing > JSON data. The example JSON file is: > > > Listing 5-13. books.json > [{"writer": "Mark Ross", > "nationality": "USA", > "books": [ > {"title": "XML Cookbook", "price": 23.56}, > {"title": "Python Fundamentals", "price": 50.70}, > {"title": "The NumPy library", "price": 12.30} > ] > }, > {"writer": "Barbara Bracket", > "nationality": "UK", > "books": [ > {"title": "Java Enterprise", "price": 28.60}, > {"title": "HTML5", "price": 31.35}, > {"title": "Python for Dummies", "price": 28.00} > ] > }] > > and the example code for reading the file is: > > >>> file = open('books.json','r') > >>> text = file.read() > >>> text = json.loads(text) Hmm... are you sure you want "text" on the left hand side. I'm not sure whether this is okay or not. It looks suspicious (but, like I said, I'm a Python newbie). From rantingrickjohnson at gmail.com Wed Sep 20 20:16:23 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 20 Sep 2017 17:16:23 -0700 (PDT) Subject: Greater and less than operators [was Re: [Tutor] beginning to code] In-Reply-To: <59c1f1d3$0$14961$b1db1813$d948b532@news.astraweb.com> References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> <59c1f1d3$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: <7a9ea622-b090-405f-b829-26ae84ec96cf@googlegroups.com> Steven D'Aprano wrote: > Rick Johnson wrote: > > > Of course, allowing all objects to use the `==`, `!=` > > sugars makes perfect sense, but `<`, `>`, `<=`, `>=` are > > meaningless outside of numeric-ish types. > > You've never wanted to sort strings? How do you sort > strings unless you have a concept of which string comes > before the other, i.e. < operator? > > >>> 'xyz' < 'abc' > False Interesting. But now we need to learn yet another set of arbitrary rules. Consider this: >>> 'azzz' > 'zzz' False Now, i'm not sure how Python decided that 'azzz' is not greater than 'zzz' (and not because 'azzz' has a length of 4!) , unless of course, Python is comparing the chars positionally and then discarding the fourth 'z' (a la zip() function behavior), but if we sum the chars in those strings using the return value of `ord()`, this is what we get: >>> sum(map(ord, 'azzz')) 463 >>> sum(map(ord, 'zzz')) 366 And now we can make it a one liner: >>> sum(map(ord, 'azzz')) > sum(map(ord, 'zzz')) True Ah. That's much more intuitive. And i just hate when my Python tells lies. ;-) > Same applies to lists of items. Provided the items are > compatible with ordering, so are the lists. Likewise other > sequences. But how are we to intuit the arbitrary rules? > And for that matter, sets. Maybe we'd prefer to use the > proper mathematical operators ? and ? for subset and > superset, but a good ASCII equivalent would be < and > > instead. A reasonable point, i admit. > Likewise, any time you want to express some sort of order > relationship: > > pawn < rook < knight < bishop < queen < king Yes, but in this case the programmer would have to explicitly override some rich comparison dunders and the source code would reveal the rules. > Or perhaps you have some sort of custom DSL (Domain > Specific Language) where > and < make handy symbols for > something completely unrelated to ordering: > > cake > oven # put cake into the oven > > cake < oven # remove cake from oven That's a highly contrived example and not something that looks like a good idea. A better solution would be to create an Oven object that only accepts certain types of "bake- ables": like cakes, pies or a Turducken.[1] [1] Now, that's not only duck typing, it's also duc[tk] stuffing (pun intended!). From BILL_NOSPAM at whoknows.net Wed Sep 20 20:22:04 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Wed, 20 Sep 2017 20:22:04 -0400 Subject: errors with json.loads In-Reply-To: References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> Message-ID: Stefan Ram wrote: > Dennis Lee Bieber writes: >> After removing all the \xa0 bytes >> and trying to decode it I get... Apparenty an \xa0 byte corresponds to a "non-breaking space". What sort of white space characters are allowed in a json file ( tabs and newlines?)? Just curious. Bill > I did the same here, before I read your post. > I got the same results, but did not post them. > > Someone has posted programs with \xA0 (NBSP IIRC) > at the start of lines of the soure here before, in: > > From: Christopher Reimer > Newsgroups: comp.lang.python > Subject: Setting property for current class from property in an different class... > Date: Wed, 6 Sep 2017 19:24:40 -0700 > Message-ID: > > , and when I removed them, I was able to execute the > source from his post from 2017-Sep-06 without errors. > > So I was feeling to lazy to bother this time. > From rosuav at gmail.com Wed Sep 20 20:25:28 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 21 Sep 2017 10:25:28 +1000 Subject: Greater and less than operators [was Re: [Tutor] beginning to code] In-Reply-To: <7a9ea622-b090-405f-b829-26ae84ec96cf@googlegroups.com> References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> <59c1f1d3$0$14961$b1db1813$d948b532@news.astraweb.com> <7a9ea622-b090-405f-b829-26ae84ec96cf@googlegroups.com> Message-ID: On Thu, Sep 21, 2017 at 10:16 AM, Rick Johnson wrote: >> >>> 'xyz' < 'abc' >> False > > Interesting. But now we need to learn yet another set of > arbitrary rules. Consider this: > > >>> 'azzz' > 'zzz' > False > > Now, i'm not sure how Python decided that 'azzz' is not > greater than 'zzz' (and not because 'azzz' has a length of > 4!) , unless of course, Python is comparing the chars > positionally and then discarding the fourth 'z' (a la zip() > function behavior), but if we sum the chars in those strings > using the return value of `ord()`, this is what we get: > > >>> sum(map(ord, 'azzz')) > 463 > >>> sum(map(ord, 'zzz')) > 366 > > And now we can make it a one liner: > > >>> sum(map(ord, 'azzz')) > sum(map(ord, 'zzz')) > True > > Ah. That's much more intuitive. And i just hate when my > Python tells lies. ;-) Uhhm.... have you ever used a dictionary? A phone book? An index (the sort in a book, not in a database)? While there are some subtleties to the actual sorting used, they're all broadly sorted by first letter, and then subsequent letters within that. ChrisA From ned at nedbatchelder.com Wed Sep 20 20:54:43 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 20 Sep 2017 20:54:43 -0400 Subject: errors with json.loads In-Reply-To: References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> Message-ID: On 9/20/17 8:22 PM, Bill wrote: > Apparenty an \xa0 byte corresponds to a "non-breaking space". What > sort of white space characters are allowed in a json file ( tabs and > newlines?)?? Just curious. These things can be looked up.? From RFC 7159 (https://tools.ietf.org/html/rfc7159): Insignificant whitespace is allowed before or after any of the six structural characters. ws = *( %x20 / ; Space %x09 / ; Horizontal tab %x0A / ; Line feed or New line %x0D ) ; Carriage return --Ned. From christopher_reimer at icloud.com Wed Sep 20 21:05:57 2017 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 20 Sep 2017 18:05:57 -0700 Subject: errors with json.loads In-Reply-To: References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> Message-ID: <8B97DD5C-B06B-4375-AB74-6B0FE40E1CBE@icloud.com> > On Sep 20, 2017, at 5:03 PM, Stefan Ram wrote: > > Dennis Lee Bieber writes: >> After removing all the \xa0 bytes >> and trying to decode it I get... > > I did the same here, before I read your post. > I got the same results, but did not post them. > > Someone has posted programs with \xA0 (NBSP IIRC) > at the start of lines of the soure here before, in: > > From: Christopher Reimer > Newsgroups: comp.lang.python > Subject: Setting property for current class from property in an different class... > Date: Wed, 6 Sep 2017 19:24:40 -0700 > Message-ID: > > , and when I removed them, I was able to execute the > source from his post from 2017-Sep-06 without errors. > > So I was feeling to lazy to bother this time. > > -- > https://mail.python.org/mailman/listinfo/python-list I had a NBSP in my code?! News to me... Chris R. From BILL_NOSPAM at whoknows.net Wed Sep 20 22:35:35 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Wed, 20 Sep 2017 22:35:35 -0400 Subject: errors with json.loads In-Reply-To: References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> Message-ID: Ned Batchelder wrote: > > On 9/20/17 8:22 PM, Bill wrote: >> Apparenty an \xa0 byte corresponds to a "non-breaking space". What >> sort of white space characters are allowed in a json file ( tabs and >> newlines?)? Just curious. > > These things can be looked up. From RFC 7159 > (https://tools.ietf.org/html/rfc7159): > Thank you. So what is most likely the root cause of the original poster's problem (assuming he typed out the text with a text editor)? From steve+python at pearwood.info Wed Sep 20 23:01:42 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 21 Sep 2017 13:01:42 +1000 Subject: Greater and less than operators [was Re: [Tutor] beginning to code] References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> <59c1f1d3$0$14961$b1db1813$d948b532@news.astraweb.com> <7a9ea622-b090-405f-b829-26ae84ec96cf@googlegroups.com> Message-ID: <59c32b9b$0$14949$b1db1813$d948b532@news.astraweb.com> On Thu, 21 Sep 2017 10:16 am, Rick Johnson wrote: >> You've never wanted to sort strings? How do you sort >> strings unless you have a concept of which string comes >> before the other, i.e. < operator? >> >> >>> 'xyz' < 'abc' >> False > > Interesting. But now we need to learn yet another set of > arbitrary rules. Consider this: > > >>> 'azzz' > 'zzz' > False > > Now, i'm not sure how Python decided that 'azzz' is not > greater than 'zzz' Because 'a' comes before 'z' in the alphabet. Come now Rick, surely you're pulling my leg. This is plain old lexicographical order, otherwise known as "alphabetical order", as taught by schools and used by dictionaries, alphabetical indexes, phone books, book libraries and more, for probably the last 200 years. https://en.wikipedia.org/wiki/Lexicographical_order In case you need a refresher: https://www.spellingcity.com/games/alphabetize.html The only difference here is that Python, like nearly all other programming languages, orders the characters by their ordinal value rather than comparing them strictly by case-insensitive alphabetical order. >> Same applies to lists of items. Provided the items are >> compatible with ordering, so are the lists. Likewise other >> sequences. > > But how are we to intuit the arbitrary rules? Lists and tuples use the same lexicographic ordering as strings, except that lists accept arbitrary object not just characters. So long as each pair of objects in corresponding positions can be compared, the whole list can be compared too. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ofekmeister at gmail.com Thu Sep 21 00:54:42 2017 From: ofekmeister at gmail.com (ofekmeister at gmail.com) Date: Wed, 20 Sep 2017 21:54:42 -0700 (PDT) Subject: userpath - Easily add your app to PATH on all platforms! Message-ID: <17f81bce-6452-4812-90cb-ce0b1faaf49d@googlegroups.com> https://github.com/ofek/userpath From dieter at handshake.de Thu Sep 21 02:00:21 2017 From: dieter at handshake.de (dieter) Date: Thu, 21 Sep 2017 08:00:21 +0200 Subject: How to share class relationship representations? References: <388b9bc5-9a5e-fd47-1caf-46d796a51931@gmail.com> Message-ID: <877ewsd216.fsf@handshake.de> Leam Hall writes: > On 09/19/2017 11:16 AM, Stefan Ram wrote: >> leam hall writes: >>> I'm working on designing the classes, sub-classes, and relationships in my >>> code. What is a good visual way to represent it so it can be stored in git >>> and shared on the list without large images or attachments? >> Code /is/ design. > > > I tried that with the small bit of code I have and was told it was too > confusing. Still working on this. A standard to describe such relationships is UML (= "Universal Modeling Language"). There are (partially expensive) tools to visualize UML models. From pavol.lisy at gmail.com Thu Sep 21 04:33:53 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Thu, 21 Sep 2017 10:33:53 +0200 Subject: Old Man Yells At Cloud In-Reply-To: <59c27450$0$14948$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <59c27450$0$14948$b1db1813$d948b532@news.astraweb.com> Message-ID: On 9/20/17, Steve D'Aprano wrote: > On Wed, 20 Sep 2017 02:55 pm, Pavol Lisy wrote: Thanks Steve, I agree with most of your mail and really appreciate interesting reading! :) > (a) "you save one character (two keystrokes)"; and First I have to admit that I forgot space! But if we like to be pedantic (what I am not sure) then we compare vs so 1 vs 4 , right? So not two keystrokes but three? > print ', '.join(str(obj) for obj in (foo, bar, baz)) # 52 chars > # and builds up a potentially large string ahead of time > print(foo, bar, baz, sep=', ') # 30 chars > # and DOESN'T build up a large string ahead of time > # and is self-explanatory I am totally on your side here! Just forgive me next: print(f"{foo}, {bar}, {baz}") # 29 :P >> 3. "for sake of saving one character"? Could we really simplify >> motivation of opposite side to just this? (what about breaking old >> code?) > > I don't know what the motivation of the "print should be a statement!" side > is, > because they never say why it was better. (If they have said, I have never > seen > it.) I am not sure if links below could bring a little light to this, but probably it could be interesting: Julia has print and println functions but has also printf macro. About motivation why not function you could read here -> https://stackoverflow.com/questions/19783030/in-julia-why-is-printf-a-macro-instead-of-a-function#19784718 and update of view is IMHO worth to read too -> https://github.com/JuliaLang/julia/pull/11941#issuecomment-129966921 From h.goebel at crazy-compilers.com Thu Sep 21 04:59:00 2017 From: h.goebel at crazy-compilers.com (Hartmut Goebel) Date: Thu, 21 Sep 2017 10:59:00 +0200 Subject: How does CPython build it's NEWS or changelog? Message-ID: <8d489eed-d5e0-e805-caf5-39a1e590f3b1@crazy-compilers.com> Hello, I just discovered that CPython now uses Misc/NEWS.d/next to collect changes an there are a lot of Misc/NEWS/*.rst files for the respective released version. I'm investigating whether to adopt this for PyInstaller. What is the tooling for this? Is there some documentation, maybe a mailingslist-diskussion or a but-report? -- Regards Hartmut Goebel | Hartmut Goebel | h.goebel at crazy-compilers.com | | www.crazy-compilers.com | compilers which you thought are impossible | From tjol at tjol.eu Thu Sep 21 05:18:46 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 21 Sep 2017 11:18:46 +0200 Subject: Fwd: Issues with python commands in windows powershell In-Reply-To: References: Message-ID: <6085cf7e-c353-d35a-f92c-f9145cf1d481@tjol.eu> On 2017-09-20 21:52, Terry Reedy wrote: > On 9/20/2017 1:09 PM, Joey Steward wrote: >> ---------- Forwarded message ---------- >> From: Joey Steward >> Date: Tue, Sep 19, 2017 at 10:30 PM >> Subject: Issues with python commands in windows powershell >> To: python-list at python.org >> >> >> Hello, >> >> I've been having issues using basic python commands in windows >> powershell. >> I'm new to programming so just going off of online tutorials. >> >> Earlier I was unable to use pip to install Django (pip install >> Django), and >> came to this forum for help and someone was able to give me the correct >> command for windows 10 (py -m pip install django). >> >> I've been trying to run this command django-admin startproject >> mytests, but >> get the same error message as when trying to run the original pip > > Try py -m django-admin startproject mytests.? If this does not work, ask > on django lists. I doubt that will work; "django-admin" is not a valid module name. Joey, there should be a folders called "bin" and "scripts" (or something like that) in your Python installation. One of them, I expect, will contain a django-admin.exe. (Or .bat? Or .cmd? Whatever.) Adding these folders to your PATH environment variable (don't ask me how) will solve these problems. IIRC you can do this for PowerShell specifically or for Windows in general, whichever you think is best. > >> django-admin : *The term 'django-admin' is not recognized as the name >> of a >> cmdlet, function, script file, or operable program. Check the spelling of >> the name, or if a path was included,* >> *verify that the path is correct and try again.* >> *At line:1 char:1* >> + django-admin startproject mytestsite >> + ~~~~~~~~~~~~ >> ???? + CategoryInfo????????? : ObjectNotFound: (django-admin:String) [], >> CommandNotFoundException >> ???? + FullyQualifiedErrorId : CommandNotFoundException >> >> >> I'm very new so honestly have no idea what the issue may be, but from >> previously trying to use python I think it may have something to do with >> configuring windows environment variables? Not sure, but just something >> I've ran into in the past previous times trying to learn python for more >> data analysis purposes. >> >> Any help would be greatly appreciated! >> >> Thanks a lot, >> >> Joey Steward >> > > -- Thomas Jollans From skip.montanaro at gmail.com Thu Sep 21 05:24:06 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 21 Sep 2017 04:24:06 -0500 Subject: How does CPython build it's NEWS or changelog? In-Reply-To: <8d489eed-d5e0-e805-caf5-39a1e590f3b1@crazy-compilers.com> References: <8d489eed-d5e0-e805-caf5-39a1e590f3b1@crazy-compilers.com> Message-ID: > I just discovered that CPython now uses Misc/NEWS.d/next to collect > changes an there are a lot of Misc/NEWS/*.rst files for the respective > released version. I'm investigating whether to adopt this for PyInstaller. > > What is the tooling for this? Is there some documentation, maybe a > mailingslist-diskussion or a but-report? Check Tools/scripts/patchcheck.py in the CPython repo. There is also a patchcheck target in the top level Makefile.pre.in file. I imagine this stuff is only exercised by the release process, so the various release managers probably know this stuff best. In theory, python-dev at python.org might be the best place to contact them, though I suspect that's not quite the right place for an extended discussion of the topic. Skip From tjol at tjol.eu Thu Sep 21 05:24:09 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 21 Sep 2017 11:24:09 +0200 Subject: errors with json.loads In-Reply-To: References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> Message-ID: <1a804c16-c601-664f-37e9-0ec1bcf2abe9@tjol.eu> On 2017-09-21 04:35, Bill wrote: > Ned Batchelder wrote: >> >> On 9/20/17 8:22 PM, Bill wrote: >>> Apparenty an \xa0 byte corresponds to a "non-breaking space". What >>> sort of white space characters are allowed in a json file ( tabs and >>> newlines?)?? Just curious. >> >> These things can be looked up.? From RFC 7159 >> (https://tools.ietf.org/html/rfc7159): >> > > Thank you.? So what is most likely the root cause of the original > poster's problem (assuming he typed out the text with a text editor)? It looks to me like the root cause of the problem was that they copied the code from a web page, and the web page contained invalid JSON. -- Thomas Jollans From tjol at tjol.eu Thu Sep 21 06:08:05 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 21 Sep 2017 12:08:05 +0200 Subject: Even Older Man Yells at Whippersnappers In-Reply-To: References: <1505842722l.23461932l.0l@psu.edu> Message-ID: <94282758-fdd0-7cb7-6fcb-a4997a3bc72d@tjol.eu> On 2017-09-19 20:21, Stefan Ram wrote: > I do not use UTF-8 > Why on earth not?! -- Thomas Jollans From p.f.moore at gmail.com Thu Sep 21 06:14:34 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 21 Sep 2017 11:14:34 +0100 Subject: How does CPython build it's NEWS or changelog? In-Reply-To: <8d489eed-d5e0-e805-caf5-39a1e590f3b1@crazy-compilers.com> References: <8d489eed-d5e0-e805-caf5-39a1e590f3b1@crazy-compilers.com> Message-ID: On 21 September 2017 at 09:59, Hartmut Goebel wrote: > Hello, > > I just discovered that CPython now uses Misc/NEWS.d/next to collect > changes an there are a lot of Misc/NEWS/*.rst files for the respective > released version. I'm investigating whether to adopt this for PyInstaller. > > What is the tooling for this? Is there some documentation, maybe a > mailingslist-diskussion or a but-report? There's a tool "blurb" (available from PyPI) used for this. Paul From stefan_ml at behnel.de Thu Sep 21 06:15:59 2017 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 21 Sep 2017 12:15:59 +0200 Subject: How does CPython build it's NEWS or changelog? In-Reply-To: <8d489eed-d5e0-e805-caf5-39a1e590f3b1@crazy-compilers.com> References: <8d489eed-d5e0-e805-caf5-39a1e590f3b1@crazy-compilers.com> Message-ID: Hartmut Goebel schrieb am 21.09.2017 um 10:59: > I just discovered that CPython now uses Misc/NEWS.d/next to collect > changes an there are a lot of Misc/NEWS/*.rst files for the respective > released version. I'm investigating whether to adopt this for PyInstaller. > > What is the tooling for this? Is there some documentation, maybe a > mailingslist-diskussion or a but-report? https://docs.python.org/devguide/committing.html#what-s-new-and-news-entries https://github.com/larryhastings/blurb Stefan From flebber.crue at gmail.com Thu Sep 21 06:18:22 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 21 Sep 2017 03:18:22 -0700 (PDT) Subject: Easy way to get a list of tuples. Message-ID: Hi I have been toying with json and I particular area where I cannot get the desired result a list of tuples as my return. The json from the API is way to long but I don't think it will matter. .. hitting url data = r.json() for item in data["RaceDay"]['Meetings'][0]['Races']: raceDetails = item['RacingFormGuide']['Event']['Race'] print(raceDetails) This returns {'Number': 1, 'NumberDisplay': '01', 'Distance': 1000, 'DistanceDisplay': '1000 METRES', 'Name': 'CLASS 3 HANDICAP', 'NameForm': 'HIGHWAY-C3'} {'Number': 2, 'NumberDisplay': '02', 'Distance': 1600, 'DistanceDisplay': '1600 METRES', 'Name': 'BM 90 HANDICAP', 'NameForm': 'BM90'} {'Number': 3, 'NumberDisplay': '03', 'Distance': 1100, 'DistanceDisplay': '1100 METRES', 'Name': 'HERITAGE STAKES', 'NameForm': 'HERITAGE'} {'Number': 4, 'NumberDisplay': '04', 'Distance': 1400, 'DistanceDisplay': '1400 METRES', 'Name': 'BILL RITCHIE HANDICAP', 'NameForm': 'RITCHIE'} {'Number': 5, 'NumberDisplay': '05', 'Distance': 1400, 'DistanceDisplay': '1400 METRES', 'Name': 'TEA ROSE STAKES', 'NameForm': 'TEA ROSE'} {'Number': 6, 'NumberDisplay': '06', 'Distance': 1600, 'DistanceDisplay': '1600 METRES', 'Name': 'GEORGE MAIN STAKES', 'NameForm': 'GEO MAIN'} {'Number': 7, 'NumberDisplay': '07', 'Distance': 1100, 'DistanceDisplay': '1100 METRES', 'Name': 'THE SHORTS', 'NameForm': 'THE SHORTS'} {'Number': 8, 'NumberDisplay': '08', 'Distance': 2000, 'DistanceDisplay': '2000 METRES', 'Name': 'KINGTON TOWN STAKES', 'NameForm': 'KING TOWN'} {'Number': 9, 'NumberDisplay': '09', 'Distance': 1200, 'DistanceDisplay': '1200 METRES', 'Name': 'BM 84 HANDICAP', 'NameForm': 'BM84'} My goal is to select a few elements and create a list of 3 element tuples like this [('CLASS 3 HANDICAP', 1, 1000), ('BM 90 HANDICAP', 2, 1600), ('HERITAGE STAKES', 3, 1100), ('BILL RITCHIE HANDICAP', 4, 1400), ('TEA ROSE STAKES', 5, 1400), ('GEORGE MAIN STAKES', 6, 1600), ('THE SHORTS', 7, 1100), ('KINGTON TOWN STAKES', 8, 2000), ('BM 84 HANDICAP', 9, 1200)] I get close creating a list of elements but each attempt I try to create the list of tuples fails. This is my closest code data = r.json() raceData = [] for item in data["RaceDay"]['Meetings'][0]['Races']: raceDetails = item['RacingFormGuide']['Event']['Race'] raceData += (raceDetails['Name'],raceDetails['Number'],raceDetails['Distance']) print(raceDetails) which returns ['CLASS 3 HANDICAP', 1, 1000, 'BM 90 HANDICAP', 2, 1600, 'HERITAGE STAKES', 3, 1100, 'BILL RITCHIE HANDICAP', 4, 1400, 'TEA ROSE STAKES', 5, 1400, 'GEORGE MAIN STAKES', 6, 1600, 'THE SHORTS', 7, 1100, 'KINGTON TOWN STAKES', 8, 2000, 'BM 84 HANDICAP', 9, 1200] How do I get the tuples? Cheers Sayth From rhodri at kynesim.co.uk Thu Sep 21 06:19:23 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 21 Sep 2017 11:19:23 +0100 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> Message-ID: <44325551-f77c-0c82-0800-5acae4ab3dd8@kynesim.co.uk> On 19/09/17 19:31, bartc wrote: > Can't you get around all those with things like sys.stdout.write? > > If so, what was the point of having a discrete print statement/function > at all? Simplicity. It is much easier to explain to a beginner that print("Wombats are go!") will write something to the console rather than expecting them to remember the incantation import sys sys.stdout.write("Wombats are go!\n") (That's basically my gripe against print becoming a function in Python3. It makes a lot of sense as has already been pointed out, but it breaks every beginners tutorial.) -- Rhodri James *-* Kynesim Ltd From tjol at tjol.eu Thu Sep 21 06:31:13 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 21 Sep 2017 12:31:13 +0200 Subject: Easy way to get a list of tuples. In-Reply-To: References: Message-ID: <2b3fc339-3ba3-13ef-eecd-6f2a4d126530@tjol.eu> On 2017-09-21 12:18, Sayth Renshaw wrote: > This is my closest code > > data = r.json() > > raceData = [] > > for item in data["RaceDay"]['Meetings'][0]['Races']: > raceDetails = item['RacingFormGuide']['Event']['Race'] > raceData += (raceDetails['Name'],raceDetails['Number'],raceDetails['Distance']) > > print(raceDetails) > You're close! The operator += extends a list with the items of another sequence (or iterable). What you're looking for is the method .append(), which adds a single element. Observe: Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information. py> a_list = [] py> a_list += 1,2,3 py> a_list [1, 2, 3] py> a_list.append(4) py> a_list [1, 2, 3, 4] py> a_list += 4 Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable py> a_list.append((5,6,7)) py> a_list [1, 2, 3, 4, (5, 6, 7)] py> -- Thomas Jollans From breamoreboy at yahoo.co.uk Thu Sep 21 06:36:48 2017 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 21 Sep 2017 11:36:48 +0100 Subject: Easy way to get a list of tuples. In-Reply-To: References: Message-ID: On 21/09/2017 11:18, Sayth Renshaw wrote: > Hi > > I have been toying with json and I particular area where I cannot get the desired result a list of tuples as my return. The json from the API is way to long but I don't think it will matter. > > .. hitting url > data = r.json() > > for item in data["RaceDay"]['Meetings'][0]['Races']: > raceDetails = item['RacingFormGuide']['Event']['Race'] > print(raceDetails) > > This returns > > {'Number': 1, 'NumberDisplay': '01', 'Distance': 1000, 'DistanceDisplay': '1000 METRES', 'Name': 'CLASS 3 HANDICAP', 'NameForm': 'HIGHWAY-C3'} > {'Number': 2, 'NumberDisplay': '02', 'Distance': 1600, 'DistanceDisplay': '1600 METRES', 'Name': 'BM 90 HANDICAP', 'NameForm': 'BM90'} > {'Number': 3, 'NumberDisplay': '03', 'Distance': 1100, 'DistanceDisplay': '1100 METRES', 'Name': 'HERITAGE STAKES', 'NameForm': 'HERITAGE'} > {'Number': 4, 'NumberDisplay': '04', 'Distance': 1400, 'DistanceDisplay': '1400 METRES', 'Name': 'BILL RITCHIE HANDICAP', 'NameForm': 'RITCHIE'} > {'Number': 5, 'NumberDisplay': '05', 'Distance': 1400, 'DistanceDisplay': '1400 METRES', 'Name': 'TEA ROSE STAKES', 'NameForm': 'TEA ROSE'} > {'Number': 6, 'NumberDisplay': '06', 'Distance': 1600, 'DistanceDisplay': '1600 METRES', 'Name': 'GEORGE MAIN STAKES', 'NameForm': 'GEO MAIN'} > {'Number': 7, 'NumberDisplay': '07', 'Distance': 1100, 'DistanceDisplay': '1100 METRES', 'Name': 'THE SHORTS', 'NameForm': 'THE SHORTS'} > {'Number': 8, 'NumberDisplay': '08', 'Distance': 2000, 'DistanceDisplay': '2000 METRES', 'Name': 'KINGTON TOWN STAKES', 'NameForm': 'KING TOWN'} > {'Number': 9, 'NumberDisplay': '09', 'Distance': 1200, 'DistanceDisplay': '1200 METRES', 'Name': 'BM 84 HANDICAP', 'NameForm': 'BM84'} > > My goal is to select a few elements and create a list of 3 element tuples > like this > [('CLASS 3 HANDICAP', 1, 1000), ('BM 90 HANDICAP', 2, 1600), ('HERITAGE STAKES', 3, 1100), ('BILL RITCHIE HANDICAP', 4, 1400), ('TEA ROSE STAKES', 5, 1400), ('GEORGE MAIN STAKES', 6, 1600), ('THE SHORTS', 7, 1100), ('KINGTON TOWN STAKES', 8, 2000), ('BM 84 HANDICAP', 9, 1200)] > > I get close creating a list of elements but each attempt I try to create the list of tuples fails. > > This is my closest code > > data = r.json() > > raceData = [] > > for item in data["RaceDay"]['Meetings'][0]['Races']: > raceDetails = item['RacingFormGuide']['Event']['Race'] > raceData += (raceDetails['Name'],raceDetails['Number'],raceDetails['Distance']) > > print(raceDetails) > > which returns > > ['CLASS 3 HANDICAP', 1, 1000, 'BM 90 HANDICAP', 2, 1600, 'HERITAGE STAKES', 3, 1100, 'BILL RITCHIE HANDICAP', 4, 1400, 'TEA ROSE STAKES', 5, 1400, 'GEORGE MAIN STAKES', 6, 1600, 'THE SHORTS', 7, 1100, 'KINGTON TOWN STAKES', 8, 2000, 'BM 84 HANDICAP', 9, 1200] > > How do I get the tuples? > > Cheers > > Sayth > > --- > This email has been checked for viruses by AVG. > http://www.avg.com > After a quick glance and hence completely untested:- raceData.append((raceDetails['Name'],raceDetails['Number'],raceDetails['Distance'])) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From flebber.crue at gmail.com Thu Sep 21 06:38:17 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 21 Sep 2017 03:38:17 -0700 (PDT) Subject: Easy way to get a list of tuples. In-Reply-To: References: <2b3fc339-3ba3-13ef-eecd-6f2a4d126530@tjol.eu> Message-ID: On Thursday, 21 September 2017 20:31:28 UTC+10, Thomas Jollans wrote: > On 2017-09-21 12:18, Sayth Renshaw wrote: > > This is my closest code > > > > data = r.json() > > > > raceData = [] > > > > for item in data["RaceDay"]['Meetings'][0]['Races']: > > raceDetails = item['RacingFormGuide']['Event']['Race'] > > raceData += (raceDetails['Name'],raceDetails['Number'],raceDetails['Distance']) > > > > print(raceDetails) > > > > You're close! > > The operator += extends a list with the items of another sequence (or > iterable). What you're looking for is the method .append(), which adds a > single element. > > Observe: > > Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00) > [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux > Type "help", "copyright", "credits" or "license" for more information. > py> a_list = [] > py> a_list += 1,2,3 > py> a_list > [1, 2, 3] > py> a_list.append(4) > py> a_list > [1, 2, 3, 4] > py> a_list += 4 > Traceback (most recent call last): > File "", line 1, in > TypeError: 'int' object is not iterable > py> a_list.append((5,6,7)) > py> a_list > [1, 2, 3, 4, (5, 6, 7)] > py> > > > -- > Thomas Jollans Thanks Thomas yes you are right with append. I have tried it but just can't get it yet as append takes only 1 argument and I wish to give it 3. I am really having trouble creating the groups of 3, since I am getting one consistent stream. Cheers Sayth From tjol at tjol.eu Thu Sep 21 06:53:03 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 21 Sep 2017 12:53:03 +0200 Subject: Easy way to get a list of tuples. In-Reply-To: References: <2b3fc339-3ba3-13ef-eecd-6f2a4d126530@tjol.eu> Message-ID: On 2017-09-21 12:38, Sayth Renshaw wrote: > Thanks Thomas yes you are right with append. I have tried it but just can't get it yet as append takes only 1 argument and I wish to give it 3. > > I am really having trouble creating the groups of 3, since I am getting one consistent stream. I suggest you have a very close look at my example code :-) -- Thomas Jollans From frank at chagford.com Thu Sep 21 07:44:36 2017 From: frank at chagford.com (Frank Millman) Date: Thu, 21 Sep 2017 13:44:36 +0200 Subject: Easy way to get a list of tuples. In-Reply-To: References: <2b3fc339-3ba3-13ef-eecd-6f2a4d126530@tjol.eu> Message-ID: "Sayth Renshaw" wrote in message news:cd4aa5c7-47ee-442b-945e-490b0674e8cd at googlegroups.com... > > Thanks Thomas yes you are right with append. I have tried it but just > can't get it yet as append takes only 1 argument and I wish to give it 3. > You have not showed us what you tried, but you are probably missing a pair of brackets. C:\Users\User>python Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> x = [] >>> x.append(('a', 'b', 'c')) >>> x.append(('p', 'q', 'r')) >>> x [('a', 'b', 'c'), ('p', 'q', 'r')] >>> Does this help? Frank Millman From rantingrickjohnson at gmail.com Thu Sep 21 07:44:58 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 21 Sep 2017 04:44:58 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: <33a47531-3e19-4ce8-9856-37d7209c054c@googlegroups.com> Bill wrote: > Rick Johnson wrote: > > I think for most languages an intuitive syntax is not > > important -- C is such a language, Lisp is such a > > language, Perl is such a language, and there are many more > > -- but for Python, intuitiveness is very important. > > > I guess it depends on what you mean by "important" > ("important to the compiler", is a legitimate concern, for > instance). Perhaps for C, but not for Python; at least, not the primary concern. For instance: the reason C uses curly braces and demands redundant (from the human POV) semicolons at the end of statements is for the sake of the machine, not the human. It is much easier to parse matching sets of braces than to parse indention, especially when Python allows arbitrary indention even within the same source file so long as the individual blocks are consistent. For instance, much to my chagrin, this Python code produces no syntax errors: # Python 2.x >>> def funky_indention(): ... for k in globals().keys(): ... print(k) ... for x in range(5): ... print(x) Yuck! > From an intuition perspective, C++ allowing you to separate > the interface of a class from it's implementation, I would > say that C++ has it all over Python from the point of view > of "intuitiveness". You mean by stubbing-out a base class with virtual methods? I suppose you could do something similar in Python if it so pleased you, although, Python does not have virtual methods, but there is an abc module. I admit, i sometimes wish Python supported virtual methods. I also find that derived methods are not intuitive in Python because there is no syntactical indication when a method is being derived, consider this: # Python 2.x >>> class Base(object): ... def m1(self): ... pass ... >>> class Derived(Base): ... def m1(self): ... # blah ... pass ... def m2(self): ... # blah ... pass ... def m3(self): ... # blah ... pass Now, when `Base` and `Derived` are living in two separate modules, how am i to know (short of opening a source file, and reading the contents) which methods of `Base` are being clobbered with the new methods in `Derived`? IMO, Python should require some sort of declaration when a base class method is overridden by a derived class's method, and a comment or other "optional" declaration is insufficient. And an error should be thrown in absence of such declaration. (1) This would prevent accidental clobbers, and (2) this would make the code more intuitive. A few ways to do this would be: (1) A new keyword redef m1(self): # blah (2) An expansion of the decorator syntax @clobbers_basemethod def m1(self): # blah (3) Or something else... > It's much easier to tell what's going on, at a glance, in a > C++ program. Have you tried using an editor with a code folding feature? > I am much newer to Python, but I have provided at least one > concrete feature supporting my opinion. I'm not sure what exactly you're implying here... If the syntax of a language is not intuitive, there is no way that a programmer can make it _more_ intuitive, although, making code less intuitive is easy, and there is a word for that: "obfuscation". So the intuitiveness of a language begins with the language _syntax_ and heavily depends on the uniform _usage_ of source code between various authors; because no matter how intuitive a language syntax may be, if two or more authors are allowed to write dissimilar code that produces the same result, intuitiveness is lost. So whether or not i single out a specific feature, seems irrelevant. From rantingrickjohnson at gmail.com Thu Sep 21 07:49:02 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 21 Sep 2017 04:49:02 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: INADA Naoki wrote: > Rick Johnson wrote [...] > > Of course, allowing all objects to use the `==`, `!=` > > sugars makes perfect sense, but `<`, `>`, `<=`, `>=` are > > meaningless outside of numeric-ish types. > > Now you know why Python 3 was born! It's one of many > pitfalls in Python 2 fixed in Python 3. Welcome to Python 3 > world. While obviously Python3's removal of this absurdity was an evolution in the right direction, it's also hardly worth my trouble to upgrade when i can just happily ignore the absurdity. From bc at freeuk.com Thu Sep 21 07:52:32 2017 From: bc at freeuk.com (bartc) Date: Thu, 21 Sep 2017 12:52:32 +0100 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: On 20/09/2017 02:31, Bill wrote: > Rick Johnson wrote: >> I think for most languages an intuitive syntax is not >> important -- C is such a language, Lisp is such a language, >> Perl is such a language, and there are many more -- but >> for Python, intuitiveness is very important. >> > I guess it depends on what you mean by "important" ("important to the > compiler", is a legitimate concern, for instance). From an intuition > perspective, C++ allowing you to separate the interface of a class from > it's implementation, I would say that C++ has it all over Python from > the point of view of "intuitiveness".?? It's much easier to tell what's > going on, at a glance, in a C++ program. You're being serious, aren't you? -- bartc From fabiofz at gmail.com Thu Sep 21 09:31:06 2017 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 21 Sep 2017 10:31:06 -0300 Subject: PyDev 6.0.0 Released Message-ID: PyDev 6.0.0 Release Highlights - *Important* PyDev now requires Java 8 and Eclipse 4.6 (Neon) onwards. - PyDev 5.2.0 is the last release supporting Eclipse 4.5 (Mars). - *Interpreter configuration* - The *list of packages* installed in the interpreter is shown in the IDE (supports either *pip* or *conda*). - It's now possible to *install/uninstall* packages using either *pip* or *conda* directly from the IDE. - Provides a way to *load variables* if interpreter is from a *conda environment* (Load conda env vars before run configuration). - A default string substitution variable named *PY* is now created with the major and minor version of the created interpreter. - It's now possible to configure a project to always use a grammar compatible with the interpreter version (default for new projects -- *#PyDev-846*). - *Editor* - *Subword* navigation is now available (and enabled by default -- can be customized at *PyDev > Editor*). - Changed default config for minimap (smaller and not showing elements -- can be customized at *PyDev > Editor > Overview Ruler Minimap*). - Code completion no longer active in comments in last line of editor (*#PyDev-762*). - *Debugger* - Fix find_module signature (patch by James Blackburn). - Fix qt_loader to support *PEP 302* correctly. - Fix in matplotlib_options from ipython (*#PyDev-779*). - When show all uppercase references is used as a filter, only digits shouldn't be filtered out in variables view (#PyDev-794). - *PyLint* - Added setting to search *PyLint* installed in interpreter (*#PyDev-811* ). - *Unittest* - It's possible to edit a run configuration from dialog to select tests to run (Ctrl+F9) (patch by *Robert Gomulka*). - Test(s) name is shown in the run configuration (patch by *Robert Gomulka* -- *#PyDev-840*). - *isort integration* - The modules that are known to be third party or system modules in the PyDev configuration are passed to *isort*. - Proper support for *isort:skip* and *isort:skip_file*. - Internal isort caches properly being cleared between invocations (fix for case where changes to config were not reflected in isort). - *Others* - Fix to properly interrupt infinite loop in the Interactive Console ( *#PyDev-816*). - Fix issue where user could do a drag n drop in system libs which could put an entry below another entry, which actually removed it from the config (*#PyDev-821*). - Fix where *runfile* was not available on *interactive debugger* when python-future is installed (*#PyDev-845*). - Fix NullPointerException on code-completion. - mutagen added to forced builtins by default (*#PyDev-819*). What is PyDev? PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com What is LiClipse? LiClipse is a PyDev standalone with goodies such as support for Multiple cursors, theming, TextMate bundles and a number of other languages such as Django Templates, Jinja2, Kivy Language, Mako Templates, Html, Javascript, etc. It's also a commercial counterpart which helps supporting the development of PyDev. Details on LiClipse: http://www.liclipse.com/ Cheers, -- Fabio Zadrozny ------------------------------ Software Developer LiClipse http://www.liclipse.com PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com PyVmMonitor - Python Profiler http://www.pyvmmonitor.com/ From ned at nedbatchelder.com Thu Sep 21 11:11:09 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 21 Sep 2017 11:11:09 -0400 Subject: errors with json.loads In-Reply-To: References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> Message-ID: <9889bb50-6b90-ed3a-0787-c22eeb55acaa@nedbatchelder.com> On 9/20/17 10:35 PM, Bill wrote: > Ned Batchelder wrote: >> >> On 9/20/17 8:22 PM, Bill wrote: >>> Apparenty an \xa0 byte corresponds to a "non-breaking space". What >>> sort of white space characters are allowed in a json file ( tabs and >>> newlines?)?? Just curious. >> >> These things can be looked up.? From RFC 7159 >> (https://tools.ietf.org/html/rfc7159): >> > > Thank you.? So what is most likely the root cause of the original > poster's problem (assuming he typed out the text with a text editor)? I can only assume that the actual data being read is different than the data they put into the message here. --Ned. From steve+python at pearwood.info Thu Sep 21 11:12:09 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 01:12:09 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <44325551-f77c-0c82-0800-5acae4ab3dd8@kynesim.co.uk> Message-ID: <59c3d6cb$0$14939$b1db1813$d948b532@news.astraweb.com> On Thu, 21 Sep 2017 08:19 pm, Rhodri James wrote: > (That's basically my gripe against print becoming a function in Python3. > It makes a lot of sense as has already been pointed out, but it breaks > every beginners tutorial.) Nobody made that decision lightly. It wasn't a spur of the moment decision, Guido didn't wake up one morning and say "Hey, how about we break a whole lot of the Python ecosystem for giggles!" You can't fix mistakes without breaking things that depend on those mistakes. That's why a whole lot of backward-incompatible changes were queued up to all happen at once, to minimize the disruption: - clean up the naming of the standard library; - make strings proper text rather than bytes; - fix print and exec; - get rid of the old, error-prone "except Error, name" syntax; - get rid of dangerous input and rename raw_input; - make map and zip iterators; - get rid of redundant range and rename xrange; - make dict.keys, items and values views, instead of having three sets of methods (lists, views and iterators); - get rid of the confusing bytes.encode and str.decode methods; and any others I missed. If you think the transition from 2 to 3 was painful, you should consider how it would have been to introduce all those backward incompatible changes in dribs and drabs over 2.4, 2.5, 2.6, 2.7 and beyond. The alternative would be to *not* remove the old versions, and just keep all the old cruft and obsolete code hanging around forever. And remember that the Python core developers feel your pain too. They had to migrate a large code base (the Python std library) from 2 to 3. They had to write the 2to3 translator. And they have to maintain two independent code bases, 2 and 3, in parallel, for a decade or more, and put up with thousands of internet haters going on and on and on and on about "Python 3 is destroying Python", year after year after year. They were willing to do all this because they were looking at the long-term health of the Python language, not just the immediate situation. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From barry at python.org Thu Sep 21 11:30:57 2017 From: barry at python.org (Barry Warsaw) Date: Thu, 21 Sep 2017 11:30:57 -0400 Subject: New security-announce@python.org mailing list Message-ID: I?m happy to announce the availability of a new mailing list, with the mission of providing security announcements to the Python community from the Python Security Response Team (PSRT): security-announce at python.org You can sign up in the usual Mailman way: https://mail.python.org/mailman/listinfo/security-announce This joins our suite of security related forums. As always, if you believe you?ve found a security issue in Python, you should contact the PSRT directly and securely via: security at python.org For more information on how you can contact us, see: https://www.python.org/news/security/ We also have a public security-focused discussion mailing list that you can subscribe and contribute to. security-sig at python.org https://mail.python.org/mailman/listinfo/security-sig Please don?t report security vulnerabilities here, since this is a publicly archived mailing list. We welcome you to collaborate here to help make Python and its ecosystem even more secure than it already is. Once a security vulnerability is identified and fixed, it becomes public knowledge. Generally, these are captured in a ReadTheDocs site for posterity: https://python-security.readthedocs.io/ This new security-announce mailing list fills a void ? one-way communication about security related matters from the PSRT back to the community. This is an area that we?ve not done a great job at, frankly, and this new announcement list is intended to improve that situation. The PSRT will use this low traffic, high value forum as the primary way the PSRT will communicate security issues of high importance back to the wider Python community. All follow-ups to postings to this list are redirected to the security-sig mailing list. Cheers, -Barry (on behalf of the PSRT) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: Message signed with OpenPGP URL: From rhodri at kynesim.co.uk Thu Sep 21 11:59:13 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 21 Sep 2017 16:59:13 +0100 Subject: Old Man Yells At Cloud In-Reply-To: <59c3d6cb$0$14939$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <44325551-f77c-0c82-0800-5acae4ab3dd8@kynesim.co.uk> <59c3d6cb$0$14939$b1db1813$d948b532@news.astraweb.com> Message-ID: <401f6367-1669-1929-76a8-19966a558269@kynesim.co.uk> On 21/09/17 16:12, Steve D'Aprano wrote: > On Thu, 21 Sep 2017 08:19 pm, Rhodri James wrote: > >> (That's basically my gripe against print becoming a function in Python3. >> It makes a lot of sense as has already been pointed out, but it breaks >> every beginners tutorial.) > Nobody made that decision lightly. It wasn't a spur of the moment decision, > Guido didn't wake up one morning and say "Hey, how about we break a whole lot > of the Python ecosystem for giggles!" You can't fix mistakes without breaking > things that depend on those mistakes. Oh, I don't doubt it, and Python3 is the better for it. It's just that my major use for Python at the time was teaching a summer course for 12-15 year olds, and switching to Python3 would have involved rewriting almost every worksheet we had. So we didn't. (Looking at the worksheet sources on Github, the course still hasn't made the switch!) -- Rhodri James *-* Kynesim Ltd From jpolo at mail.usf.edu Thu Sep 21 12:17:44 2017 From: jpolo at mail.usf.edu (john polo) Date: Thu, 21 Sep 2017 11:17:44 -0500 Subject: errors with json.loads In-Reply-To: References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> Message-ID: <044ef98e-36ec-2063-81e3-0608ac8065e8@mail.usf.edu> On 9/20/2017 5:56 PM, John Gordon wrote: > In john polo writes: > >> JSONDecodeError: Expecting ':' delimiter: line 5 column 50 (char 161) >> ?json.loads says that the method is for deserializing "s", with "s" >> being a string, bytes, or bytearray. >> In [24]: type(text) >> Out[24]: str >> So "text" seems to be a string. Why does json.loads return an error? > Because, although text is the right type, it does not contain a > valid json string. Thank you for the reply, John. I am not familiar with how to check validity for json. I typed the example into notepad++ and saved as .json and didn't take any further steps after that. I'll look into that. John From jpolo at mail.usf.edu Thu Sep 21 12:18:14 2017 From: jpolo at mail.usf.edu (john polo) Date: Thu, 21 Sep 2017 11:18:14 -0500 Subject: errors with json.loads In-Reply-To: References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> Message-ID: <6a440d15-28fb-7482-cc2b-3aadd38c8b85@mail.usf.edu> On 9/20/2017 5:58 PM, Bill wrote: > Interesting problem, John. > > I have probably even less experience with json than you do, so I'm > taking this as an opportunity to learn with you. > > Suggestions: > > 1. Try your example with Python 2 rather than Python 3. Bill, Thanks for the reply. I wasn't sure how to get Python 2 through the cmd or IPython, so I went through ArcGIS, but it's mostly the same result: >>> file = open('books.json','r') >>> text = file.read() >>> text = json.loads(text) Runtime error Traceback (most recent call last): ? File "", line 1, in NameError: name 'json' is not defined >>> import json?? #whoops, forget to do that first in this go 'round. >>> text = json.loads(text) Runtime error Traceback (most recent call last): ? File "", line 1, in ? File "C:\Python27\ArcGIS10.4\Lib\json\__init__.py", line 338, in loads ??? return _default_decoder.decode(s) ? File "C:\Python27\ArcGIS10.4\Lib\json\decoder.py", line 366, in decode ??? obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ? File "C:\Python27\ArcGIS10.4\Lib\json\decoder.py", line 382, in raw_decode ??? obj, end = self.scan_once(s, idx) ValueError: Expecting : delimiter: line 5 column 50 (char 161) >>> > 2. Take your file and make it into a string literal in your program, > and try calling json.loads with that as an argument. I am not sure I follow what you meant, but this was what I did: In [26]: file2 = open('books.txt') In [27]: text2 = file2.read() In [28]: text2 = json.loads(text2) --------------------------------------------------------------------------- JSONDecodeError?????????????????????????? Traceback (most recent call last) in () ----> 1 text2 = json.loads(text2) c:\users\jpolo\appdata\local\programs\python\python36\lib\json\__init__.py in lo ads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, objec t_pairs_hook, **kw) ??? 352???????????? parse_int is None and parse_float is None and ??? 353???????????? parse_constant is None and object_pairs_hook is None and not ?kw): --> 354???????? return _default_decoder.decode(s) ??? 355???? if cls is None: ??? 356???????? cls = JSONDecoder c:\users\jpolo\appdata\local\programs\python\python36\lib\json\decoder.py in dec ode(self, s, _w) ??? 337 ??? 338???????? """ --> 339???????? obj, end = self.raw_decode(s, idx=_w(s, 0).end()) ??? 340???????? end = _w(s, end).end() ??? 341???????? if end != len(s): c:\users\jpolo\appdata\local\programs\python\python36\lib\json\decoder.py in raw _decode(self, s, idx) ??? 353???????? """ ??? 354???????? try: --> 355???????????? obj, end = self.scan_once(s, idx) ??? 356???????? except StopIteration as err: ??? 357???????????? raise JSONDecodeError("Expecting value", s, err.value) from None JSONDecodeError: Expecting ':' delimiter: line 5 column 50 (char 161) best, John From jpolo at mail.usf.edu Thu Sep 21 12:24:16 2017 From: jpolo at mail.usf.edu (john polo) Date: Thu, 21 Sep 2017 11:24:16 -0500 Subject: errors with json.loads In-Reply-To: References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> Message-ID: On 9/20/2017 6:40 PM, Dennis Lee Bieber wrote: > On Wed, 20 Sep 2017 17:13:41 -0500, john polo > declaimed the following: > > >> and the example code for reading the file is: >> >>>>> file = open('books.json','r') > What encoding is the file? I did a cut&paste from your post into a > file, and the contents (Python 2.7) failed with Dennis, I typed it into notepad++ and saved as .json. On the bottom of the notepad++ window it says: Windows (CR LF) UTF-8 I think that answers your question? Thanks, John -- "Ask a man to be quiet, and he'll be silent for a moment. Feed a man to a red dragon and he'll be silent for a lifetime." -Anne Isabella Thackeray Ritchie From jpolo at mail.usf.edu Thu Sep 21 12:25:21 2017 From: jpolo at mail.usf.edu (john polo) Date: Thu, 21 Sep 2017 11:25:21 -0500 Subject: errors with json.loads In-Reply-To: <1a804c16-c601-664f-37e9-0ec1bcf2abe9@tjol.eu> References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> <1a804c16-c601-664f-37e9-0ec1bcf2abe9@tjol.eu> Message-ID: On 9/21/2017 4:24 AM, Thomas Jollans wrote: > > It looks to me like the root cause of the problem was that they copied > the code from a web page, and the web page contained invalid JSON. Thank you, Thomas. John From toby at tobiah.org Thu Sep 21 12:29:07 2017 From: toby at tobiah.org (Tobiah) Date: Thu, 21 Sep 2017 09:29:07 -0700 Subject: Assertions Message-ID: Are these completely equivalent? def foo(thing): assert(thing > 0), "Thing must be greater than zero" def foo(thing): if not (thing > 0): raise AssertionError("Thing must be greater than zero") Other than the fact that the assertion can be turned off with -O? Thanks, Tobiah From rosuav at gmail.com Thu Sep 21 12:31:29 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Sep 2017 02:31:29 +1000 Subject: Old Man Yells At Cloud In-Reply-To: <401f6367-1669-1929-76a8-19966a558269@kynesim.co.uk> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <44325551-f77c-0c82-0800-5acae4ab3dd8@kynesim.co.uk> <59c3d6cb$0$14939$b1db1813$d948b532@news.astraweb.com> <401f6367-1669-1929-76a8-19966a558269@kynesim.co.uk> Message-ID: On Fri, Sep 22, 2017 at 1:59 AM, Rhodri James wrote: > On 21/09/17 16:12, Steve D'Aprano wrote: >> >> On Thu, 21 Sep 2017 08:19 pm, Rhodri James wrote: >> >>> (That's basically my gripe against print becoming a function in Python3. >>> It makes a lot of sense as has already been pointed out, but it breaks >>> every beginners tutorial.) >> >> Nobody made that decision lightly. It wasn't a spur of the moment >> decision, >> Guido didn't wake up one morning and say "Hey, how about we break a whole >> lot >> of the Python ecosystem for giggles!" You can't fix mistakes without >> breaking >> things that depend on those mistakes. > > > Oh, I don't doubt it, and Python3 is the better for it. It's just that my > major use for Python at the time was teaching a summer course for 12-15 year > olds, and switching to Python3 would have involved rewriting almost every > worksheet we had. So we didn't. > > (Looking at the worksheet sources on Github, the course still hasn't made > the switch!) For a good while, I was in the same position. But instead of massively rewriting everything, all I did was to adjust the material to use Py2/Py3 compatible syntax. Adding parens around your print calls won't stop it from being Py2-compatible, and it means that the shift to Py3 becomes a lot easier. A handful of other minor changes here and there (using the explicit // operator when floor division was important, or ensuring that obsolete syntax wasn't used), and the course was solidly in the 2-3 compatibility range. No cost to Py2 compatibility, and the work could be done progressively. Teaching people to put parens around their prints won't hurt them, and might help them. It wasn't hard for us, because all our course material is online; if you're working with printed worksheets, you may end up with two versions going around (which would cause confusion - "why does this have brackets and that not?"), so it could just be left until there's edits being made for other reasons. Still, it can be on the list of "if you're making changes, do this", like fixing typos or spelling errors. ChrisA From ned at nedbatchelder.com Thu Sep 21 12:36:33 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 21 Sep 2017 12:36:33 -0400 Subject: errors with json.loads In-Reply-To: <6a440d15-28fb-7482-cc2b-3aadd38c8b85@mail.usf.edu> References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> <6a440d15-28fb-7482-cc2b-3aadd38c8b85@mail.usf.edu> Message-ID: On 9/21/17 12:18 PM, john polo wrote: > Bill, > Thanks for the reply. I wasn't sure how to get Python 2 through the > cmd or IPython, so I went through ArcGIS, but it's mostly the same > result: > > >>> file = open('books.json','r') > >>> text = file.read() > >>> text = json.loads(text) After the file.read() line, put this:? print(repr(text))? or print(ascii(text)) if you are on Python 3.? Show us that output. That will make clear what is wrong with the data. --Ned. From steve+python at pearwood.info Thu Sep 21 12:36:53 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 02:36:53 +1000 Subject: iPython ? magic Message-ID: <59c3eaa8$0$14929$b1db1813$d948b532@news.astraweb.com> In the iPython interactive interpreter, obj? prints information about the given object. For example: In [11]: None? Type: NoneType Base Class: String Form:None Namespace: Python builtin Docstring: Does anyone know that the Namespace field is supposed to show? I can't get it to display anything except either "Python builtin" or "Interactive". -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ned at nedbatchelder.com Thu Sep 21 12:59:25 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 21 Sep 2017 12:59:25 -0400 Subject: Assertions In-Reply-To: References: Message-ID: <956003bf-6911-d759-dc20-6d93b5b2a984@nedbatchelder.com> On 9/21/17 12:29 PM, Tobiah wrote: > Are these completely equivalent? > > def foo(thing): > > assert(thing > 0), "Thing must be greater than zero" > > > def foo(thing): > > if not (thing > 0): raise AssertionError("Thing must be greater than zero") > > > Other than the fact that the assertion can be turned off > with -O? > Let's see: ??? Python 3.6.2 (default, Jul 17 2017, 07:05:09) ??? [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin ??? Type "help", "copyright", "credits" or "license" for more information. ??? >>> def foo1(thing): ??? ...?? assert(thing > 0), "Thing must be greater than zero" ??? ... ??? >>> def foo2(thing): ??? ...?? if not (thing > 0): raise AssertionError("Thing must be greater than zero") ??? ... ??? >>> import dis ??? >>> dis.dis(foo1) ????? 2?????????? 0 LOAD_FAST??????????????? 0 (thing) ????????????????? 2 LOAD_CONST?????????????? 1 (0) ????????????????? 4 COMPARE_OP?????????????? 4 (>) ????????????????? 6 POP_JUMP_IF_TRUE??????? 16 ????????????????? 8 LOAD_GLOBAL????????????? 0 (AssertionError) ???????????????? 10 LOAD_CONST?????????????? 2 ('Thing must be greater than zero') ???????????????? 12 CALL_FUNCTION??????????? 1 ???????????????? 14 RAISE_VARARGS??????????? 1 ??????????? >>?? 16 LOAD_CONST?????????????? 0 (None) ???????????????? 18 RETURN_VALUE ??? >>> dis.dis(foo2) ????? 2?????????? 0 LOAD_FAST??????????????? 0 (thing) ????????????????? 2 LOAD_CONST?????????????? 1 (0) ????????????????? 4 COMPARE_OP?????????????? 4 (>) ????????????????? 6 POP_JUMP_IF_TRUE??????? 16 ????????????????? 8 LOAD_GLOBAL????????????? 0 (AssertionError) ???????????????? 10 LOAD_CONST?????????????? 2 ('Thing must be greater than zero') ???????????????? 12 CALL_FUNCTION??????????? 1 ???????????????? 14 RAISE_VARARGS??????????? 1 ??????????? >>?? 16 LOAD_CONST?????????????? 0 (None) ???????????????? 18 RETURN_VALUE ??? >>> Yes, they are completely equivalent, compiling to precisely the same bytecode. --Ned. From rhodri at kynesim.co.uk Thu Sep 21 13:07:22 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 21 Sep 2017 18:07:22 +0100 Subject: Old Man Yells At Cloud In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <44325551-f77c-0c82-0800-5acae4ab3dd8@kynesim.co.uk> <59c3d6cb$0$14939$b1db1813$d948b532@news.astraweb.com> <401f6367-1669-1929-76a8-19966a558269@kynesim.co.uk> Message-ID: <8924be46-27f1-b4ef-651a-5507867a0fd8@kynesim.co.uk> On 21/09/17 17:31, Chris Angelico wrote: > For a good while, I was in the same position. But instead of massively > rewriting everything, all I did was to adjust the material to use > Py2/Py3 compatible syntax. Adding parens around your print calls won't > stop it from being Py2-compatible, and it means that the shift to Py3 > becomes a lot easier. It's compatible syntax, but it doesn't half look weird in Py2. >>> x=2 >>> print("x is", x) ('x is', 2) >>> is very unfriendly to young beginners. We did consider it, but decided it was a non-starter; it was less effort to ignore Py3 entirely. -- Rhodri James *-* Kynesim Ltd From steve+python at pearwood.info Thu Sep 21 13:23:27 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 03:23:27 +1000 Subject: Assertions References: <956003bf-6911-d759-dc20-6d93b5b2a984@nedbatchelder.com> Message-ID: <59c3f591$0$14978$b1db1813$d948b532@news.astraweb.com> On Fri, 22 Sep 2017 02:59 am, Ned Batchelder wrote: > On 9/21/17 12:29 PM, Tobiah wrote: >> Are these completely equivalent? [... assert, versus test and raise AssertionError ...] > Let's see: [...] > Yes, they are completely equivalent, compiling to precisely the same > bytecode. That is definitely version-dependent, because I've just tried it and got different byte-code in Python 2.7. py> import dis py> def test1(): ... assert foo, "bar baz" ... py> def test2(): ... if not foo: raise AssertionError("bar baz") ... py> py> dis.dis(test1) 2 0 LOAD_GLOBAL 0 (foo) 3 POP_JUMP_IF_TRUE 15 6 LOAD_GLOBAL 1 (AssertionError) 9 LOAD_CONST 1 ('bar baz') 12 RAISE_VARARGS 2 >> 15 LOAD_CONST 0 (None) 18 RETURN_VALUE py> dis.dis(test2) 2 0 LOAD_GLOBAL 0 (foo) 3 POP_JUMP_IF_TRUE 21 6 LOAD_GLOBAL 1 (AssertionError) 9 LOAD_CONST 1 ('bar baz') 12 CALL_FUNCTION 1 15 RAISE_VARARGS 1 18 JUMP_FORWARD 0 (to 21) >> 21 LOAD_CONST 0 (None) 24 RETURN_VALUE So I do not believe that we can say that they will always compile to the same byte-code. There were differences in past versions, there could be differences again in the future. I was going to be cheeky and run the same test with -0, giving: py> dis.dis(test1) 2 0 LOAD_CONST 0 (None) 3 RETURN_VALUE which of course is a big difference between the two, but it turned out that there can be other byte-code differences. So no, I don't believe we can say they are *completely* equivalent, since they could compile to slightly different byte-code with slightly-different performance characteristics. But I think we can say that *semantically* the two ought to be the same. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Thu Sep 21 13:31:50 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Sep 2017 03:31:50 +1000 Subject: Assertions In-Reply-To: <59c3f591$0$14978$b1db1813$d948b532@news.astraweb.com> References: <956003bf-6911-d759-dc20-6d93b5b2a984@nedbatchelder.com> <59c3f591$0$14978$b1db1813$d948b532@news.astraweb.com> Message-ID: On Fri, Sep 22, 2017 at 3:23 AM, Steve D'Aprano wrote: > That is definitely version-dependent, because I've just tried it and got > different byte-code in Python 2.7. > > py> import dis > py> def test1(): > ... assert foo, "bar baz" > ... > py> def test2(): > ... if not foo: raise AssertionError("bar baz") > ... > py> > py> dis.dis(test1) > 2 0 LOAD_GLOBAL 0 (foo) > 3 POP_JUMP_IF_TRUE 15 > 6 LOAD_GLOBAL 1 (AssertionError) > 9 LOAD_CONST 1 ('bar baz') > 12 RAISE_VARARGS 2 > >> 15 LOAD_CONST 0 (None) > 18 RETURN_VALUE > py> dis.dis(test2) > 2 0 LOAD_GLOBAL 0 (foo) > 3 POP_JUMP_IF_TRUE 21 > 6 LOAD_GLOBAL 1 (AssertionError) > 9 LOAD_CONST 1 ('bar baz') > 12 CALL_FUNCTION 1 > 15 RAISE_VARARGS 1 > 18 JUMP_FORWARD 0 (to 21) > >> 21 LOAD_CONST 0 (None) > 24 RETURN_VALUE Impressive. That means that, in 2.7, it's actually equivalent to: >>> def test3(): ... if not foo: raise AssertionError, "bar baz" ... >>> dis.dis(test3) 2 0 LOAD_GLOBAL 0 (foo) 3 POP_JUMP_IF_TRUE 18 6 LOAD_GLOBAL 1 (AssertionError) 9 LOAD_CONST 1 ('bar baz') 12 RAISE_VARARGS 2 15 JUMP_FORWARD 0 (to 18) >> 18 LOAD_CONST 0 (None) 21 RETURN_VALUE Although in the 2.7 that I have, the assert statement does actually *call* AssertionError (ie it constructs an instance and raises it). What version are you running? Here's mine: $ python2 Python 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118] on linux2 Type "help", "copyright", "credits" or "license" for more information. ChrisA From rosuav at gmail.com Thu Sep 21 13:33:31 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Sep 2017 03:33:31 +1000 Subject: Old Man Yells At Cloud In-Reply-To: <8924be46-27f1-b4ef-651a-5507867a0fd8@kynesim.co.uk> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <44325551-f77c-0c82-0800-5acae4ab3dd8@kynesim.co.uk> <59c3d6cb$0$14939$b1db1813$d948b532@news.astraweb.com> <401f6367-1669-1929-76a8-19966a558269@kynesim.co.uk> <8924be46-27f1-b4ef-651a-5507867a0fd8@kynesim.co.uk> Message-ID: On Fri, Sep 22, 2017 at 3:07 AM, Rhodri James wrote: > On 21/09/17 17:31, Chris Angelico wrote: >> >> For a good while, I was in the same position. But instead of massively >> rewriting everything, all I did was to adjust the material to use >> Py2/Py3 compatible syntax. Adding parens around your print calls won't >> stop it from being Py2-compatible, and it means that the shift to Py3 >> becomes a lot easier. > > > It's compatible syntax, but it doesn't half look weird in Py2. > >>>> x=2 >>>> print("x is", x) > ('x is', 2) >>>> > > is very unfriendly to young beginners. We did consider it, but decided it > was a non-starter; it was less effort to ignore Py3 entirely. True, it's only identical if you do the formatting explicitly: print("x is %s" % x) But that does happen to be a very common case. ChrisA From steve+python at pearwood.info Thu Sep 21 13:44:59 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 03:44:59 +1000 Subject: Assertions References: Message-ID: <59c3fa9d$0$14948$b1db1813$d948b532@news.astraweb.com> On Fri, 22 Sep 2017 02:29 am, Tobiah wrote: > Are these completely equivalent? > > def foo(thing): > > assert(thing > 0), "Thing must be greater than zero" > > > def foo(thing): > > if not (thing > 0): raise AssertionError("Thing must be greater than > zero") > > > Other than the fact that the assertion can be turned off > with -O? As I replied to Ned just now, the two may compile to slightly different byte-code. But (apart from the -O optimization) they ought to be semantically the same, as far as the interpreter goes. I'd be very surprised if the byte-code differences were ever more than trivial. But I don't think they are the same as far as the human reader goes. If you believe the truism that code is written for other people, and only incidentally to be run by computers, then I think we should say that the two above are very different. The first is an actual assertion. It has to be an assertion, because it uses the assert keyword! The second is testing a condition, and if need be, raising an exception. Which looks like an inappropriate exception. Why AssertionError? It looks like it ought to be a ValueError. Assertions aren't merely a synonym for testing a condition and raising an exception if the condition fails. Assertions have semantics to the human reader. I wrote a blog post explaining why you should use assertions: - you want a checked comment; - you have code that can't possibly fail, unless it does; - you are testing the program logic; - you are checking a contract; and when you should not. By using `assert`, you are signalling your intent to do one of the above. http://import-that.dreamwidth.org/676.html But by using an ordinary `if ... raise AssertionError`, the intention is ambiguous. If you meant for it to be an assertion, why not use assert? If it is not an assertion, then AssertionError is probably the wrong exception. (It is okay in a testing framework, like unittest, but a bad idea in a regular library or an application. Your end-users should never see an AssertionError.) The bottom line is, if I saw if not (thing > 0): raise AssertionError(...) in a code review, I'd probably insist that either it be changed to use `assert`, or the exception be changed to ValueError, whichever better expresses the intention of the code. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Sep 21 13:49:45 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 03:49:45 +1000 Subject: Assertions References: <956003bf-6911-d759-dc20-6d93b5b2a984@nedbatchelder.com> <59c3f591$0$14978$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c3fbba$0$14948$b1db1813$d948b532@news.astraweb.com> On Fri, 22 Sep 2017 03:31 am, Chris Angelico wrote: > On Fri, Sep 22, 2017 at 3:23 AM, Steve D'Aprano > wrote: >> That is definitely version-dependent, because I've just tried it and got >> different byte-code in Python 2.7. >> >> py> import dis >> py> def test1(): >> ... assert foo, "bar baz" >> ... >> py> def test2(): >> ... if not foo: raise AssertionError("bar baz") >> ... >> py> >> py> dis.dis(test1) >> 2 0 LOAD_GLOBAL 0 (foo) >> 3 POP_JUMP_IF_TRUE 15 >> 6 LOAD_GLOBAL 1 (AssertionError) >> 9 LOAD_CONST 1 ('bar baz') >> 12 RAISE_VARARGS 2 >> >> 15 LOAD_CONST 0 (None) >> 18 RETURN_VALUE >> py> dis.dis(test2) >> 2 0 LOAD_GLOBAL 0 (foo) >> 3 POP_JUMP_IF_TRUE 21 >> 6 LOAD_GLOBAL 1 (AssertionError) >> 9 LOAD_CONST 1 ('bar baz') >> 12 CALL_FUNCTION 1 >> 15 RAISE_VARARGS 1 >> 18 JUMP_FORWARD 0 (to 21) >> >> 21 LOAD_CONST 0 (None) >> 24 RETURN_VALUE > > Impressive. That means that, in 2.7, it's actually equivalent to: > >>>> def test3(): > ... if not foo: raise AssertionError, "bar baz" That's nothing. In 1.5 (yes, *one* point five) it's equivalent to something more or less like this: def test4(): if __debug__: if foo: return raise AssertionError('bar baz') > Although in the 2.7 that I have, the assert statement does actually > *call* AssertionError (ie it constructs an instance and raises it). > What version are you running? Here's mine: > > $ python2 > Python 2.7.13 (default, Jan 19 2017, 14:48:08) > [GCC 6.3.0 20170118] on linux2 Now that you've showed me yours, I suppose I have to show you mine. Python 2.7.2 (default, May 18 2012, 18:25:10) So definitely version dependent. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Thu Sep 21 14:08:19 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Sep 2017 04:08:19 +1000 Subject: Assertions In-Reply-To: <59c3fbba$0$14948$b1db1813$d948b532@news.astraweb.com> References: <956003bf-6911-d759-dc20-6d93b5b2a984@nedbatchelder.com> <59c3f591$0$14978$b1db1813$d948b532@news.astraweb.com> <59c3fbba$0$14948$b1db1813$d948b532@news.astraweb.com> Message-ID: On Fri, Sep 22, 2017 at 3:49 AM, Steve D'Aprano wrote: > On Fri, 22 Sep 2017 03:31 am, Chris Angelico wrote: > >> Impressive. That means that, in 2.7, it's actually equivalent to: >> >>>>> def test3(): >> ... if not foo: raise AssertionError, "bar baz" > > That's nothing. In 1.5 (yes, *one* point five) it's equivalent to something more > or less like this: > > def test4(): > if __debug__: > if foo: > return > raise AssertionError('bar baz') AIUI, it's still equivalent to that - with the proviso that the optimizer removes references to __debug__: >>> def foo(): ... if __debug__: print("Debugging") ... >>> import dis >>> dis.dis(foo) 2 0 LOAD_CONST 1 ('Debugging') 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 0 (None) 8 RETURN_VALUE and the optimizer may or may not differentiate between the two ways of writing the code. It is interesting to observe the changes to the optimizer, but none of them are assert-specific. (And I just made an assertion about the optimizer and the assert statement. It is falsifiable, but if true, it is an optimal optimizer/assertion assertion.) >> Although in the 2.7 that I have, the assert statement does actually >> *call* AssertionError (ie it constructs an instance and raises it). >> What version are you running? Here's mine: >> >> $ python2 >> Python 2.7.13 (default, Jan 19 2017, 14:48:08) >> [GCC 6.3.0 20170118] on linux2 > > Now that you've showed me yours, I suppose I have to show you mine. > > Python 2.7.2 (default, May 18 2012, 18:25:10) > > So definitely version dependent. Yep! Apparently five years of patchlevel changes can include some that make notable byte-code changes. Which doesn't surprise me, merely amuses. ChrisA From BILL_NOSPAM at whoknows.net Thu Sep 21 15:00:58 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Thu, 21 Sep 2017 15:00:58 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: Stefan Ram wrote: > bartc writes: >> On 20/09/2017 02:31, Bill wrote: >>> it's implementation, I would say that C++ has it all over Python from >>> the point of view of "intuitiveness". It's much easier to tell what's >>> going on, at a glance, in a C++ program. >> You're being serious, aren't you? > For one example, this is a part of a C++ program: > > template< typename C >C T( void ( C::* )() ); > > . It defines a template T, that can be used in a > class as follows: > > struct example { void f(); typedef decltype( T( &f )) S; }; > > . The type ?S? now has a certain property, that can > be useful sometimes. What is this property (asking Bill)? > I'll reveal that I'm not Bjarne Stroustrup. decltype was introduced in C++11, which I haven't explored, and I have never written any code that resembles your template. But it appears that an object of type S may behave like a function, which in this case would invoke Example.f(). As has already been pointed out, one can write "obfuscating code" in any language, with little effort. I strive to write code which is easily understandable--and I document it. I don't wish to debate whether I could make more of a mess in Python, or not. From ben+python at benfinney.id.au Thu Sep 21 15:23:54 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 22 Sep 2017 05:23:54 +1000 Subject: How does CPython build it's NEWS or changelog? References: <8d489eed-d5e0-e805-caf5-39a1e590f3b1@crazy-compilers.com> Message-ID: <85ingb6ek5.fsf@benfinney.id.au> Stefan Behnel writes: > https://docs.python.org/devguide/committing.html#what-s-new-and-news-entries > > https://github.com/larryhastings/blurb Also of interest is the more general-use Town Crier tool: towncrier is a utility to produce useful, summarised news files for your project. Rather than reading the Git history as some newer tools to produce it, or having one single file which developers all write to, towncrier reads ?news fragments? which contain information useful to end users. -- \ ?The Initial Mystery that attends any journey is: how did the | `\ traveller reach his starting point in the first place?? ?Louise | _o__) Bogan, _Journey Around My Room_ | Ben Finney From zljubisic at gmail.com Thu Sep 21 15:27:18 2017 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Thu, 21 Sep 2017 12:27:18 -0700 (PDT) Subject: Convert pandas series to string and datetime object Message-ID: <157fc84b-7cfd-4e3c-9155-fe39fcd3ff34@googlegroups.com> I have sliced the pandas dataframe end_date = df[-1:]['end'] type(end_date) Out[4]: pandas.core.series.Series end_date Out[3]: 48173 2017-09-20 04:47:59 Name: end, dtype: datetime64[ns] 1. How to get rid of index value 48173 and get only "2017-09-20 04:47:59" string? I have to call REST API with "2017-09-20 04:47:59" as a parameter, so I have to get string from pandas datetime64 series. 2. How to get rid of index value 48173 and get only datetime object [something like datetime.datetime.strptime('2017-09-20 04:47:59', '%Y-%m-%d %H:%M:%S')]. Later I will have to check if '2017-09-20 04:47:59' < datetime.datetime(2017,1,9) How to do these conversions? From jpolo at mail.usf.edu Thu Sep 21 15:34:04 2017 From: jpolo at mail.usf.edu (john polo) Date: Thu, 21 Sep 2017 14:34:04 -0500 Subject: errors with json.loads In-Reply-To: <9889bb50-6b90-ed3a-0787-c22eeb55acaa@nedbatchelder.com> References: <36ca7777-e5c6-dc01-c322-18c6cd2c0332@mail.usf.edu> <9889bb50-6b90-ed3a-0787-c22eeb55acaa@nedbatchelder.com> Message-ID: <4745ad20-bf1c-96a8-3eea-3303efb0bb1e@mail.usf.edu> On 9/21/2017 10:11 AM, Ned Batchelder wrote: > > I can only assume that the actual data being read is different than > the data they put into the message here. > > --Ned. > There was a typo in the file that I had made and saved; an extra comma before one of the ":". Apologies to the list for not catching that sooner. John From louisacorey at gmail.com Thu Sep 21 15:39:20 2017 From: louisacorey at gmail.com (louisacorey at gmail.com) Date: Thu, 21 Sep 2017 12:39:20 -0700 (PDT) Subject: Test Bank for Management, Operations Management, Supply Chain Management, Project Management for all editions In-Reply-To: <9f3b5e83-e355-495c-83fd-5a9a1c74baef@googlegroups.com> References: <9f3b5e83-e355-495c-83fd-5a9a1c74baef@googlegroups.com> Message-ID: <1c4b2fb1-f9a2-442c-8b88-c8063009e9be@googlegroups.com> Organizational Behavior and Management, 11th Edition by Robert Konopaske and John Ivancevich and Michael Matteson From pavol.lisy at gmail.com Thu Sep 21 15:45:33 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Thu, 21 Sep 2017 21:45:33 +0200 Subject: iPython ? magic In-Reply-To: <59c3eaa8$0$14929$b1db1813$d948b532@news.astraweb.com> References: <59c3eaa8$0$14929$b1db1813$d948b532@news.astraweb.com> Message-ID: On 9/21/17, Steve D'Aprano wrote: > In the iPython interactive interpreter, obj? prints information about the > given > object. For example: > > > In [11]: None? > Type: NoneType > Base Class: > String Form:None > Namespace: Python builtin > Docstring: > > > Does anyone know that the Namespace field is supposed to show? I can't get > it to > display anything except either "Python builtin" or "Interactive". I discovered that there are 3 default namespaces -> https://github.com/ipython/ipython/blob/79921f6fe380f57cf353d76615e4fd8472c83118/IPython/core/interactiveshell.py#L1405 But you could somehow change or add other namespaces (maybe ipdb could add local namespace to evaluate local variables). You could check thist code: import IPython ip = IPython.core.getipython.get_ipython() print(ip.user_ns) # this is in 'Interactive' namespace print(ip.user_global_ns) # this is in 'Interactive (global)' namespace # next line show how somewhat somewhere could change namespace where object names are searched ip._inspect("pinfo", "None", [("my namespace", {"None":None})]) From python at mrabarnett.plus.com Thu Sep 21 16:11:03 2017 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 21 Sep 2017 21:11:03 +0100 Subject: Convert pandas series to string and datetime object In-Reply-To: <157fc84b-7cfd-4e3c-9155-fe39fcd3ff34@googlegroups.com> References: <157fc84b-7cfd-4e3c-9155-fe39fcd3ff34@googlegroups.com> Message-ID: On 2017-09-21 20:27, zljubisic at gmail.com wrote: > I have sliced the pandas dataframe > > end_date = df[-1:]['end'] > > type(end_date) > Out[4]: pandas.core.series.Series > > end_date > Out[3]: > 48173 2017-09-20 04:47:59 > Name: end, dtype: datetime64[ns] > > 1. How to get rid of index value 48173 and get only "2017-09-20 04:47:59" string? I have to call REST API with "2017-09-20 04:47:59" as a parameter, so I have to get string from pandas datetime64 series. > 2. How to get rid of index value 48173 and get only datetime object [something like datetime.datetime.strptime('2017-09-20 04:47:59', '%Y-%m-%d %H:%M:%S')]. Later I will have to check if '2017-09-20 04:47:59' < datetime.datetime(2017,1,9) > > How to do these conversions? > The docs say that pandas.Series is "One-dimensional ndarray with axis labels (including time series)", so have you tried indexing, such as end_date[1]? From __peter__ at web.de Thu Sep 21 16:39:34 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 21 Sep 2017 22:39:34 +0200 Subject: Convert pandas series to string and datetime object References: <157fc84b-7cfd-4e3c-9155-fe39fcd3ff34@googlegroups.com> Message-ID: zljubisic at gmail.com wrote: > I have sliced the pandas dataframe > > end_date = df[-1:]['end'] > > type(end_date) > Out[4]: pandas.core.series.Series > > end_date > Out[3]: > 48173 2017-09-20 04:47:59 > Name: end, dtype: datetime64[ns] > > 1. How to get rid of index value 48173 and get only "2017-09-20 04:47:59" > string? I have to call REST API with "2017-09-20 04:47:59" as a parameter, > so I have to get string from pandas datetime64 series. > 2. How to get rid of index value 48173 and get only datetime object > [something like datetime.datetime.strptime('2017-09-20 04:47:59', > '%Y-%m-%d %H:%M:%S')]. Later I will have to check if '2017-09-20 04:47:59' > < datetime.datetime(2017,1,9) > > How to do these conversions? After a web search and some trial and error: >>> d = pd.DataFrame([[1, datetime.datetime.now()], [2, datetime.datetime.now()]], columns=["whatever", "end"]) >>> d whatever end 0 1 2017-09-21 22:36:52.342757 1 2 2017-09-21 22:36:52.349973 [2 rows x 2 columns] >>> d["end"].astype(datetime.datetime).values[-1] datetime.datetime(2017, 9, 21, 22, 36, 52, 349973) From BILL_NOSPAM at whoknows.net Thu Sep 21 18:35:22 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Thu, 21 Sep 2017 18:35:22 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: Stefan Ram wrote: > Bill writes: >> Stefan Ram wrote: >>> bartc writes: >>>> On 20/09/2017 02:31, Bill wrote: >>>>> it's implementation, I would say that C++ has it all over Python from >>>>> the point of view of "intuitiveness". It's much easier to tell what's >>>>> going on, at a glance, in a C++ program. >>>> You're being serious, aren't you? >>> For one example, this is a part of a C++ program: >>> template< typename C >C T( void ( C::* )() ); >>> . It defines a template T, that can be used in a >>> class as follows: >>> struct example { void f(); typedef decltype( T( &f )) S; }; >>> . The type ?S? now has a certain property, that can >>> be useful sometimes. What is this property (asking Bill)? As >> has already been pointed out, one can write "obfuscating code" in any >> language, with little effort. I strive to write code which is easily >> understandable--and I document it. I don't wish to debate whether I >> could make more of a mess in Python, or not. > From the point of view of a C++ programmer, Oh, we "all look the same", huh? I know that we've only just met, but I will caution that you are coming across as something of a "know-it-all". Bill > the above > is not obfuscated, but it is readable and simple C++. > It is of course not readable for readers who do not know > C++. Just as Python's ?string[::-1]? appears "obfuscated" > to readers who don't know Python. > > It was the answer to the question "How can I express the > class I'm in in, when I can't write that classes name > literally? So, ?S? is ?example?. > > It works like this: The type of ?&f? is ?void ( example::* > )()?. So, the function-declaration template ?T? infers ?C? > to be ?example?, and the type of ?T( &f )? is ?example?, > which then is transferred to the name ?S? using typedef. > > This is obvious for C++ programmers, but it takes a lot > of time to become a C++ programmer, maybe more than it > takes to become a Python programmer. > From BILL_NOSPAM at whoknows.net Thu Sep 21 18:43:48 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Thu, 21 Sep 2017 18:43:48 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: Stefan Ram wrote: > Just as Python's ?string[::-1]? appears "obfuscated" > to readers who don't know Python. I understand string[::-1] after only studying python for a day or two (I've only been studying it for 2 weeks at this point). A student could study C++ for a semester or more and not encounter templates until they studied data structures. So in short, I don't believe that the example you chose from Python and the one you chose from C++, were at similar levels (not even close). > > It was the answer to the question "How can I express the > class I'm in in, when I can't write that classes name > literally? So, ?S? is ?example?. > > It works like this: The type of ?&f? is ?void ( example::* > )()?. So, the function-declaration template ?T? infers ?C? > to be ?example?, and the type of ?T( &f )? is ?example?, > which then is transferred to the name ?S? using typedef. > > This is obvious for C++ programmers, but it takes a lot > of time to become a C++ programmer, maybe more than it > takes to become a Python programmer. > From flebber.crue at gmail.com Thu Sep 21 21:37:47 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 21 Sep 2017 18:37:47 -0700 (PDT) Subject: Easy way to get a list of tuples. In-Reply-To: References: <2b3fc339-3ba3-13ef-eecd-6f2a4d126530@tjol.eu> Message-ID: <961d862c-aa63-4ec6-a3c5-9633c62f44a7@googlegroups.com> > > > > Thanks Thomas yes you are right with append. I have tried it but just > > can't get it yet as append takes only 1 argument and I wish to give it 3. > > > You have not showed us what you tried, but you are probably missing a pair > of brackets. > > C:\Users\User>python > Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit > (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> x = [] > >>> x.append(('a', 'b', 'c')) > >>> x.append(('p', 'q', 'r')) > >>> x > [('a', 'b', 'c'), ('p', 'q', 'r')] > >>> > > Does this help? > > Frank Millman Oh yes I just had one set of brackets with my append. Thanks Frank From BILL_NOSPAM at whoknows.net Thu Sep 21 22:44:31 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Thu, 21 Sep 2017 22:44:31 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: Stefan Ram wrote: > Bill writes: >> I understand string[::-1] after only studying python for a day or two >> (I've only been studying it for 2 weeks at this point). A student could >> study C++ for a semester or more and not encounter templates until they >> studied data structures. So in short, I don't believe that the example >> you chose from Python and the one you chose from C++, were at similar >> levels (not even close). > I was responding to your assertion: > > |It's much easier to tell what's going on, at a glance, in a > |C++ program. > > and I showed a simple counterexample. But it was *not* a simple counterexample. > And above, now, it seems that you /agree/ that one can learn > Python in a short time, but needs a lot longer to learn C++. Learning to develop code, in either language, involves much more than "learning C++" or "learning Python". I have been reading Beazley's "Essential Reference", and I would say that Python is definitely a bigger, and more complicated language than C++. In some aspects it has simpler syntax. But consider all of the ways that you can pass arguments to a function, for instance. There are definitely alot more options than in C/C++. I like the way that both of these languages (unlike Java) allow you to stick with the procedural paradigm if you wish to (which I think is a natural way for a true beginner to start). From my perspective, Python's simplicity lies in the fact that an entire program does not have to be recompiled if a module is changed. Since I was programming in C (and Fortran) before you were born, it's syntax does not generally pose a hindrance to me. > > BTW: templates have little to do with data structures. One can > show resonable examples for function templates that do not use > any data structure: You are sounding like a "know-it-all" again. I am familiar with such examples. One could code in C++ for a long time without a definitive need for templates. It just depends on the application. By trade, I am more of a mathematician than a programmer but sometimes my needs and/or interests overlap. > > template< typename T > > T maximum( T const a, T const b ){ return a > b ? a : b; } > > . The corresponding Python def would be (untested): > > def maximum( a, b ): return a if a > b else b > > , that is, because Python is not statically typed, one does > not need a template for a corresponding definition in Python. > From rantingrickjohnson at gmail.com Fri Sep 22 00:00:58 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 21 Sep 2017 21:00:58 -0700 (PDT) Subject: Old Man Yells At Cloud In-Reply-To: <59c3d6cb$0$14939$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <44325551-f77c-0c82-0800-5acae4ab3dd8@kynesim.co.uk> <59c3d6cb$0$14939$b1db1813$d948b532@news.astraweb.com> Message-ID: <6c6c1786-49aa-4fe7-b284-a18fadcda4d7@googlegroups.com> On Thursday, September 21, 2017 at 10:12:25 AM UTC-5, Steve D'Aprano wrote: > [...] > And remember that the Python core developers feel your pain > too. They had to migrate a large code base (the Python std > library) from 2 to 3. They had to write the 2to3 > translator. And they have to maintain two independent code > bases, 2 and 3, in parallel, for a decade or more, and put > up with thousands of internet haters going on and on and on > and on about "Python 3 is destroying Python", year after > year after year. I think it's grossly unfair to label those who's lives have been up-ended by the backwards incompatible changes of Python3 as "haters". Most of these people did not want or even need these changes, and they were just happy to be using a language that was intuitive, productive and did not distract them from solving whatever problem happened to need solving at the moment. Sure, i think all the changes are great (except for type hints, and i'm withholding my judgment of async for the time being...), and had these changes been a part of the original language, Python would have been a better language for it. Personally, i will not decide whether or not to migrate until Python4, and i suspect i am not alone in this regard. And if Py-dev feels betrayed by the community, well, they should understand that we feel betrayed as well. We have invested decades into this language, and to have our investments ruined by changes we did not ask for is devastating. So, can we overcome this devastation? Possibly. But Py-dev needs to understand that breaking backwards compatibility is no small thing, and they also need to understand that alienating the Python2.X'ers is not helping the migration to Python3. I assure you, this community cannot endure another one of these "engineered natural disasters". One of the reasons we've been so loyal to Python, is that, at least historically, we had faith in GvR's judgments. And while his fabled time machine has saved our bums on more than one occasion, these days, some of us are not so sure of our capitan's navigational abilities, and are feeling a bit like we are the unlucky passengers on the Titanic. Speaking personally here, i know i could have overcome the backwards incompatible thing _eventually_, but Python3, followed by the introduction of type-hints has been such a earth shattering 1-2-punch, that i'm really struggling to stay on my feet at this point. I mean, i guess i could delude myself and imagine that type- hints don't exist, but that's about as realistic as ignoring a giant dent in the side of my beautiful car. Sure, the car drives just fine, but the ugly dent sours the experience. :-( From steve+python at pearwood.info Fri Sep 22 00:19:18 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 14:19:18 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <44325551-f77c-0c82-0800-5acae4ab3dd8@kynesim.co.uk> <59c3d6cb$0$14939$b1db1813$d948b532@news.astraweb.com> <6c6c1786-49aa-4fe7-b284-a18fadcda4d7@googlegroups.com> Message-ID: <59c48f48$0$14945$b1db1813$d948b532@news.astraweb.com> On Fri, 22 Sep 2017 02:00 pm, Rick Johnson wrote: > I think it's grossly unfair to label those who's lives > have been up-ended by the backwards incompatible changes of > Python3 as "haters". Nobody, not one person, has ever had their life upended by Python 3. People have their lives upended by war, by disease, by serious injury, by natural disasters. They have their lives upended by losing their home to the bank, or in an earthquake, or a hurricane. They have their lives upended by cancer, by bombs, by serious car accidents, by floods and fires. Having to spend a few hours being paid to migrate code using "print x" to "print(x)", or even a few months, is not a life-changing experience. > Most of these people did not want or > even need these changes, If they didn't want somebody else making the decision, they should have invented their own language and used that instead. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From BILL_NOSPAM at whoknows.net Fri Sep 22 00:57:46 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Fri, 22 Sep 2017 00:57:46 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> Message-ID: Stefan Ram wrote: > Bill writes: >> "Essential Reference", and I would say that Python is definitely a >> bigger, and more complicated language than C++. In some aspects it has >> simpler syntax. But consider all of the ways that you can pass >> arguments to a function, for instance. There are definitely alot more >> options than in C/C++. I like the way that both of these languages > In C++, you can pass: I used the word *arguments*, not parameters. FWIW, *const* seems to correspond to immutable, pretty well. I find Python to be more more like Java, with regard to "passing objects by reference". > > - by value (with a const or non-const parameter) > (where the value can be a pointer or a non-pointer > or a pointer-to-member or a unique_ptr or a shared_ptr) > - by reference > - by const reference > - by rvalue reference > - by universal reference > - by name (in macros) > - you can overload functions with the same name > but different numbers of parameter or different > types for their parameters > - you can write templates for functions with ranges of types > for a parameter > - default values can be declared for parameters > > In Python, you pass > > - by value > > The section 6.3.4 on calls "in The Python Language > Reference, Release 3.6.0" encompasses 1? pages. > >> You are sounding like a "know-it-all" again. I am familiar with such >> examples. One could code in C++ for a long time without a definitive >> need for templates. > Ok, so if we exclude from C++ everything that you have not > learned yet, than, what is left over, is "much easier" for > you to read "at a glance". It seems that you want C++ to be > adjusted to your knowledge of it and your assertions about > it. I think that one should instead adjust one's assertions > to the reality. > > The Python Language Reference, Release 3.6.0 146 pages > latest ISO-C++ draft (without the library part) 464 pages Bear in mind that you don't have to know every feature of a language to make good use of it, unless, perhaps, that is your job. I don't believe reading the latest "ISO-C++ draft" would be a good use of my time; it sounds like a document geared more to compiler designers. I don't even try to memorize . If I need a function, I search for it. There is a reason that C++, Java and Python all coexist. It might be helpful for you to try to appreciate that. Regards, Bill From no.email at nospam.invalid Fri Sep 22 02:05:20 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 21 Sep 2017 23:05:20 -0700 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <59bdcb3f$0$16759$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <44325551-f77c-0c82-0800-5acae4ab3dd8@kynesim.co.uk> <59c3d6cb$0$14939$b1db1813$d948b532@news.astraweb.com> <6c6c1786-49aa-4fe7-b284-a18fadcda4d7@googlegroups.com> <59c48f48$0$14945$b1db1813$d948b532@news.astraweb.com> Message-ID: <87efqzfeu7.fsf@nightsong.com> Steve D'Aprano writes: > Having to spend a few hours being paid to migrate code using "print x" > to "print(x)", or even a few months, is not a life-changing experience. Didn't someone further up the thread mention some company that had spent 1.5 years porting a py2 codebase to py3? The issue of breaking the print statement isn't the difficulty of converting old programs, or that the print statement is superior to the print function or vice versa. Reasonable people might believe that one is slightly better than the other, but it would be hard to argue that one is overwhelmingly better than the other. So there's not a convincing reason to change. That calls the whole py3 movement into question, since its advocates so vigorously defend unnecessary changes. It's fine to fix broken stuff (Unicode was broken, indexes escaping list comprehensions was broken) but fixing highly visible stuff that wasn't broken makes the more subtle changes easier to ignore. Py3 imo would have been more successful if it introduced even more breakage, but produced dramatic benefits (for example a 10x speedup) as a result. That would have been doable. Instead we got minor benefits and useless breakage. Py4 as a result of learning the wrong lesson won't break anything, so it won't be able to introduce dramatic benefits either. Will the 5th time (Py5) be the charm? (I don't mean Pycharm). Python is gaining ground in numerics and data science, which is great. Micropython for embedded MCUs is also poised for popularity. I don't know how Python is doing at general systems stuff which is what I mostly use it for. I think Ruby is losing ground, and some of the ground it has lost has been to Elixir. An Elixir-like reimplementation of Python might be an interesting avenue to pursue. So would a dialect with less pervasive dynamism than Python, but that could be compiled to fast machine code with traditional Lisp techniques. The dynamism would still be available "opt-in" so you could turn it on when you wanted it, and only those parts of your program would slow down. From steve+python at pearwood.info Fri Sep 22 02:52:56 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 16:52:56 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> Message-ID: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> On Fri, 22 Sep 2017 02:57 pm, Bill wrote: > I find Python to be more more > like Java, with regard to "passing objects by reference". Which is not a surprise, since both Python and Java use the same value passing style: pass by object reference, or pass by sharing if you prefer. Java people don't call it that. They call it pass by value, and categorically deny that it is pass by reference. (They're right about the second point.) It also the exact same passing style as used by Swift, except Swift calls it pass by reference, and denies it is pass by value. (They're right about the second point.) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From BILL_NOSPAM at whoknows.net Fri Sep 22 03:01:11 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Fri, 22 Sep 2017 03:01:11 -0400 Subject: [Tutor] beginning to code In-Reply-To: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > On Fri, 22 Sep 2017 02:57 pm, Bill wrote: > >> I find Python to be more more >> like Java, with regard to "passing objects by reference". > Which is not a surprise, since both Python and Java use the same value passing > style: pass by object reference, or pass by sharing if you prefer. > > Java people don't call it that. They call it pass by value, and categorically > deny that it is pass by reference. (They're right about the second point.) I figure that, internally, an address, a pointer, is being passed by value to implement pass by reference. Why do you say "they are right" above? Are you saying it's not pass by reference? What really screws the terminology up is that it's not parameters that are being passed, it's arguments! %-) > > It also the exact same passing style as used by Swift, except Swift calls it > pass by reference, and denies it is pass by value. (They're right about the > second point.) > > > From pavol.lisy at gmail.com Fri Sep 22 03:20:16 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Fri, 22 Sep 2017 09:20:16 +0200 Subject: Convert pandas series to string and datetime object In-Reply-To: References: <157fc84b-7cfd-4e3c-9155-fe39fcd3ff34@googlegroups.com> Message-ID: On 9/21/17, Peter Otten <__peter__ at web.de> wrote: > zljubisic at gmail.com wrote: > >> I have sliced the pandas dataframe >> >> end_date = df[-1:]['end'] >> >> type(end_date) >> Out[4]: pandas.core.series.Series >> >> end_date >> Out[3]: >> 48173 2017-09-20 04:47:59 >> Name: end, dtype: datetime64[ns] >> >> 1. How to get rid of index value 48173 and get only "2017-09-20 > 04:47:59" >> string? I have to call REST API with "2017-09-20 04:47:59" as a >> parameter, >> so I have to get string from pandas datetime64 series. >> 2. How to get rid of index value 48173 and get only datetime object >> [something like datetime.datetime.strptime('2017-09-20 04:47:59', >> '%Y-%m-%d %H:%M:%S')]. Later I will have to check if '2017-09-20 >> 04:47:59' >> < datetime.datetime(2017,1,9) >> >> How to do these conversions? > > After a web search and some trial and error: > >>>> d = pd.DataFrame([[1, datetime.datetime.now()], [2, > datetime.datetime.now()]], columns=["whatever", "end"]) >>>> d > whatever end > 0 1 2017-09-21 22:36:52.342757 > 1 2 2017-09-21 22:36:52.349973 > > [2 rows x 2 columns] >>>> d["end"].astype(datetime.datetime).values[-1] > datetime.datetime(2017, 9, 21, 22, 36, 52, 349973) Or: >>> d.iloc[-1]['end'].strftime('%Y-%m-%d %H:%M:%S') '2017-09-22 09:03:40' PS. pandas is one of reasons why python is so popular these days. But "there is only milion way how to do it" (and other unpythonic issues) I see there every time I am looking at it. :) From BILL_NOSPAM at whoknows.net Fri Sep 22 03:24:42 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Fri, 22 Sep 2017 03:24:42 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: Stefan Ram wrote: > Bill writes: >> Stefan Ram wrote: >>> bartc writes: >>>> On 20/09/2017 02:31, Bill wrote: >>>>> it's implementation, I would say that C++ has it all over Python from >>>>> the point of view of "intuitiveness". It's much easier to tell what's >>>>> going on, at a glance, in a C++ program. >>>> You're being serious, aren't you? >>> For one example, this is a part of a C++ program: >>> template< typename C >C T( void ( C::* )() ); >>> . It defines a template T, that can be used in a >>> class as follows: >>> struct example { void f(); typedef decltype( T( &f )) S; }; >>> . The type ?S? now has a certain property, that can >>> be useful sometimes. What is this property (asking Bill)? As >> has already been pointed out, one can write "obfuscating code" in any >> language, with little effort. I strive to write code which is easily >> understandable--and I document it. I don't wish to debate whether I >> could make more of a mess in Python, or not. > From the point of view of a C++ programmer, the above > is not obfuscated, but it is readable and simple C++. > It is of course not readable for readers who do not know > C++. Just as Python's ?string[::-1]? appears "obfuscated" > to readers who don't know Python. > > It was the answer to the question "How can I express the > class I'm in in, when I can't write that classes name > literally? I would try to use virtual cast in place of the *&%, I mean code, you wrote. "Clever code" is a losing game--just look at your explanation below. Simple==Good. > So, ?S? is ?example?. > > It works like this: The type of ?&f? is ?void ( example::* > )()?. So, the function-declaration template ?T? infers ?C? > to be ?example?, and the type of ?T( &f )? is ?example?, > which then is transferred to the name ?S? using typedef. > > This is obvious for C++ programmers, but it takes a lot > of time to become a C++ programmer, maybe more than it > takes to become a Python programmer. > From BILL_NOSPAM at whoknows.net Fri Sep 22 03:27:01 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Fri, 22 Sep 2017 03:27:01 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <4b7b51e7-fb5e-4b1e-a927-cd1c10ca04d1@googlegroups.com> Message-ID: Bill wrote: > Stefan Ram wrote: >> Bill writes: >>> Stefan Ram wrote: >>>> bartc writes: >>>>> On 20/09/2017 02:31, Bill wrote: >>>>>> it's implementation, I would say that C++ has it all over Python >>>>>> from >>>>>> the point of view of "intuitiveness". It's much easier to tell >>>>>> what's >>>>>> going on, at a glance, in a C++ program. >>>>> You're being serious, aren't you? >>>> For one example, this is a part of a C++ program: >>>> template< typename C >C T( void ( C::* )() ); >>>> . It defines a template T, that can be used in a >>>> class as follows: >>>> struct example { void f(); typedef decltype( T( &f )) S; }; >>>> . The type ?S? now has a certain property, that can >>>> be useful sometimes. What is this property (asking Bill)? As >>> has already been pointed out, one can write "obfuscating code" in any >>> language, with little effort. I strive to write code which is easily >>> understandable--and I document it. I don't wish to debate whether I >>> could make more of a mess in Python, or not. >> From the point of view of a C++ programmer, the above >> is not obfuscated, but it is readable and simple C++. >> It is of course not readable for readers who do not know >> C++. Just as Python's ?string[::-1]? appears "obfuscated" >> to readers who don't know Python. >> >> It was the answer to the question "How can I express the >> class I'm in in, when I can't write that classes name >> literally? > > I would try to use virtual cast in place of the *&%, I mean code, you > wrote. Sorry, I mean dynamic_cast(). > "Clever code" is a losing game--just look at your explanation below. > Simple==Good. > > >> So, ?S? is ?example?. >> >> It works like this: The type of ?&f? is ?void ( example::* >> )()?. So, the function-declaration template ?T? infers ?C? >> to be ?example?, and the type of ?T( &f )? is ?example?, >> which then is transferred to the name ?S? using typedef. >> >> This is obvious for C++ programmers, but it takes a lot >> of time to become a C++ programmer, maybe more than it >> takes to become a Python programmer. >> > From ganesh1pal at gmail.com Fri Sep 22 04:55:12 2017 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Fri, 22 Sep 2017 14:25:12 +0530 Subject: How to ingore "AttributeError: exception Message-ID: I have two possible values for Z_block in the block code i.e disk_object.data.data.di_data[0] or block.data.data.di_data.data[0][0] def get_block(): ''' Get Z block '' if block.data.data.di_data.data[0][0] is not None: Z_block = block.data.data.di_data.data[0][0] else: Z_block = disk_object.data.data.di_data[0] if not Z_block: return False return Z_block I have a problem with if and else satement i.e if IF codition fails the code would exit with "AttributeError: 'list' object has no attribute 'data' " error Any suggestion on how this can be handled better , Will ignoring the exceptions in try -except with pass be good or are there easier ways ) , try: Z_block = block.data.data.di_data.data[0][0]except AttributeError as e: pass I am a Linux user on Python 2.7 Regards, Ganesh From breamoreboy at yahoo.co.uk Fri Sep 22 05:00:34 2017 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 22 Sep 2017 10:00:34 +0100 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: On 22/09/2017 08:01, Bill wrote: > Steve D'Aprano wrote: >> On Fri, 22 Sep 2017 02:57 pm, Bill wrote: >> >>> I find Python to be more more >>> like Java, with regard to "passing objects by reference". >> Which is not a surprise, since both Python and Java use the same value >> passing >> style: pass by object reference, or pass by sharing if you prefer. >> >> Java people don't call it that. They call it pass by value, and >> categorically >> deny that it is pass by reference. (They're right about the second >> point.) > > I figure that, internally, an address, a pointer, is being passed by > value to implement pass by reference.? Why do you say "they are right" > above? Are you saying it's not pass by reference? > Please see http://jeffknupp.com/blog/2012/11/13/is-python-callbyvalue-or-callbyreference-neither/ and http://effbot.org/zone/call-by-object.htm -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email has been checked for viruses by AVG. http://www.avg.com From tjol at tjol.eu Fri Sep 22 05:05:45 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 22 Sep 2017 11:05:45 +0200 Subject: How to ingore "AttributeError: exception In-Reply-To: References: Message-ID: <4ea217d8-bcac-d937-f9ce-9db654774a53@tjol.eu> On 2017-09-22 10:55, Ganesh Pal wrote: > I have two possible values for Z_block in the block code i.e > disk_object.data.data.di_data[0] or block.data.data.di_data.data[0][0] > > > def get_block(): > ''' Get Z block '' > > if block.data.data.di_data.data[0][0] is not None: > Z_block = block.data.data.di_data.data[0][0] > > else: > Z_block = disk_object.data.data.di_data[0] > > if not Z_block: > return False > > return Z_block > > > > > I have a problem with if and else satement i.e if IF codition fails the > code would exit with "AttributeError: 'list' object has no attribute > 'data' " error > > Any suggestion on how this can be handled better , Will ignoring the > exceptions in try -except with pass be good or are there easier ways ) , > > > try: > Z_block = block.data.data.di_data.data[0][0]except AttributeError as e: > > pass try: return self.some.attribute.or.another except AttributeError: return DEFAULT_VALUE is a perfectly good pattern to use. > > > I am a Linux user on Python 2.7 Have you considered moving to Python 3? > > > Regards, > Ganesh > -- Thomas Jollans From marko at pacujo.net Fri Sep 22 05:23:35 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 22 Sep 2017 12:23:35 +0300 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: <87wp4r9je0.fsf@elektro.pacujo.net> Bill : > I figure that, internally, an address, a pointer, is being passed by > value to implement pass by reference. Why do you say "they are right" > above? Are you saying it's not pass by reference? "Pass by reference" could be "pass by reference to object" (Python, Java, JavaScript, Lisp) or "pass by reference to memory slot" (available to Pascal and C++). Memory slots (or lvalues, as they are known in C) are not first class objects in Python, which makes "pass by reference to memory slot" a bit tricky in Python. Python *could* add memory slots to its sanctioned collection of object types, and it *could* add special syntax to express a memory slot reference and dereference ("&" and "*" in C). However, Python doesn't need any language changes to implement memory slots. A memory slot could be defined as any object that implements "get()" and "set(value)" methods: C: &x Python: class Xref: def get(self): return x def set(self, value): nonlocal x; x = value ref_x = Xref() C: &x->y[3] Python: class XY3ref: def get(self): return x.y[3] def set(self, value): x.y[3] = value ref_xy3 = XY3ref() The examples could be simplified: ref_x = slot_ref(locals(), "x") ref_xy3 = slot_ref(x.y, 3) by defining: def slot_ref(dict_or_array, key_or_index): class SlotRef: def get(self): return dict_or_array[key_or_index] def set(self, value): dict_or_array[key_or_index] = value return SlotRef() Marko From BILL_NOSPAM at whoknows.net Fri Sep 22 05:53:36 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Fri, 22 Sep 2017 05:53:36 -0400 Subject: [Tutor] beginning to code In-Reply-To: <87wp4r9je0.fsf@elektro.pacujo.net> References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa wrote: > Bill : > >> I figure that, internally, an address, a pointer, is being passed by >> value to implement pass by reference. Why do you say "they are right" >> above? Are you saying it's not pass by reference? Thank you for your examples. I studied them carefully (and I'm not through with them yet). I just wanted to mention that my comment was made in the context that Python is implemented by an interpreter written in C. I realize that this may not always be the case. However, I haven't heard anyone mention a Python interpreter written in Python yet. > "Pass by reference" could be "pass by reference to object" (Python, > Java, JavaScript, Lisp) or "pass by reference to memory slot" (available > to Pascal and C++). > > Memory slots (or lvalues, as they are known in C) are not first class > objects in Python, which makes "pass by reference to memory slot" a bit > tricky in Python. Python *could* add memory slots to its sanctioned > collection of object types, and it *could* add special syntax to express > a memory slot reference and dereference ("&" and "*" in C). > > However, Python doesn't need any language changes to implement memory > slots. A memory slot could be defined as any object that implements > "get()" and "set(value)" methods: > > C: &x > > Python: > class Xref: > def get(self): return x > def set(self, value): nonlocal x; x = value > ref_x = Xref() > > > C: &x->y[3] > > Python: > class XY3ref: > def get(self): return x.y[3] > def set(self, value): x.y[3] = value > ref_xy3 = XY3ref() > > The examples could be simplified: > > ref_x = slot_ref(locals(), "x") > ref_xy3 = slot_ref(x.y, 3) > > by defining: > > def slot_ref(dict_or_array, key_or_index): > class SlotRef: > def get(self): return dict_or_array[key_or_index] > def set(self, value): dict_or_array[key_or_index] = value > return SlotRef() > > > Marko From breamoreboy at yahoo.co.uk Fri Sep 22 06:12:36 2017 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 22 Sep 2017 11:12:36 +0100 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> Message-ID: On 22/09/2017 10:53, Bill wrote: > I just wanted to mention that my comment was made in the context that > Python is implemented by an interpreter written in C.?? I realize that > this may not always be the case.? However, I haven't heard anyone > mention a Python interpreter written in Python yet. The reference implementation is written in C but there's also Jython (Java) and IronPython (.Net). -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email has been checked for viruses by AVG. http://www.avg.com From p.f.moore at gmail.com Fri Sep 22 06:15:55 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Fri, 22 Sep 2017 11:15:55 +0100 Subject: How to ingore "AttributeError: exception In-Reply-To: <4ea217d8-bcac-d937-f9ce-9db654774a53@tjol.eu> References: <4ea217d8-bcac-d937-f9ce-9db654774a53@tjol.eu> Message-ID: On 22 September 2017 at 10:05, Thomas Jollans wrote: > On 2017-09-22 10:55, Ganesh Pal wrote: >> I have two possible values for Z_block in the block code i.e >> disk_object.data.data.di_data[0] or block.data.data.di_data.data[0][0] >> >> >> def get_block(): >> ''' Get Z block '' >> >> if block.data.data.di_data.data[0][0] is not None: >> Z_block = block.data.data.di_data.data[0][0] >> >> else: >> Z_block = disk_object.data.data.di_data[0] >> >> if not Z_block: >> return False >> >> return Z_block >> >> >> >> >> I have a problem with if and else satement i.e if IF codition fails the >> code would exit with "AttributeError: 'list' object has no attribute >> 'data' " error >> >> Any suggestion on how this can be handled better , Will ignoring the >> exceptions in try -except with pass be good or are there easier ways ) , >> >> >> try: >> Z_block = block.data.data.di_data.data[0][0]except AttributeError as e: >> >> pass > > > > try: > return self.some.attribute.or.another > except AttributeError: > return DEFAULT_VALUE > > is a perfectly good pattern to use. getattr(obj, 'attr_name', DEFAULT_VALUE) may also be useful, although if more than one of the attribute lookups in the chain you show could fail, then catching the exception is probably simpler. Paul From bc at freeuk.com Fri Sep 22 06:48:39 2017 From: bc at freeuk.com (bartc) Date: Fri, 22 Sep 2017 11:48:39 +0100 Subject: [Tutor] beginning to code In-Reply-To: <87wp4r9je0.fsf@elektro.pacujo.net> References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> Message-ID: On 22/09/2017 10:23, Marko Rauhamaa wrote: > Bill : > >> I figure that, internally, an address, a pointer, is being passed by >> value to implement pass by reference. Why do you say "they are right" >> above? Are you saying it's not pass by reference? > > "Pass by reference" could be "pass by reference to object" (Python, > Java, JavaScript, Lisp) or "pass by reference to memory slot" (available > to Pascal and C++). > > Memory slots (or lvalues, as they are known in C) are not first class > objects in Python, which makes "pass by reference to memory slot" a bit > tricky in Python. Python *could* add memory slots to its sanctioned > collection of object types, and it *could* add special syntax to express > a memory slot reference and dereference ("&" and "*" in C). > > However, Python doesn't need any language changes to implement memory > slots. A memory slot could be defined as any object that implements > "get()" and "set(value)" methods: I didn't understand your examples. Can Python be used to write, say, a swap() function that works with any argument types (not just classes or lists)? Example: def swap(&a,&b): # made up syntax a, b = b, a x=10 y="Z" swap(x,y) print (x,y) # "Z" and "10" If not, then it doesn't have reference passing as it is normally understood. A simpler example: def set(&a,value): a = value set(x,1000000) Here the type of x is irrelevant anyway. It doesn't even need to be initialised to anything first (that might violate something in Python, I don't know what). -- bartc From alister.ware at ntlworld.com Fri Sep 22 06:50:43 2017 From: alister.ware at ntlworld.com (alister) Date: Fri, 22 Sep 2017 10:50:43 GMT Subject: Assertions References: <59c3fa9d$0$14948$b1db1813$d948b532@news.astraweb.com> Message-ID: <7W5xB.2362044$Ft7.259201@fx33.am4> On Fri, 22 Sep 2017 03:44:59 +1000, Steve D'Aprano wrote: > On Fri, 22 Sep 2017 02:29 am, Tobiah wrote: > >> Are these completely equivalent? >> >> def foo(thing): >> >> assert(thing > 0), "Thing must be greater than zero" >> >> >> def foo(thing): >> >> if not (thing > 0): raise AssertionError("Thing must be greater >> than zero") >> >> >> Other than the fact that the assertion can be turned off with -O? > > As I replied to Ned just now, the two may compile to slightly different > byte-code. But (apart from the -O optimization) they ought to be > semantically the same, as far as the interpreter goes. I'd be very > surprised if the byte-code differences were ever more than trivial. > > But I don't think they are the same as far as the human reader goes. If > you believe the truism that code is written for other people, and only > incidentally to be run by computers, then I think we should say that the > two above are very different. > > The first is an actual assertion. It has to be an assertion, because it > uses the assert keyword! > > The second is testing a condition, and if need be, raising an exception. > Which looks like an inappropriate exception. Why AssertionError? It > looks like it ought to be a ValueError. > > Assertions aren't merely a synonym for testing a condition and raising > an exception if the condition fails. Assertions have semantics to the > human reader. I wrote a blog post explaining why you should use > assertions: > > - you want a checked comment; > - you have code that can't possibly fail, unless it does; > - you are testing the program logic; > - you are checking a contract; > > and when you should not. By using `assert`, you are signalling your > intent to do one of the above. > > http://import-that.dreamwidth.org/676.html > > But by using an ordinary `if ... raise AssertionError`, the intention is > ambiguous. If you meant for it to be an assertion, why not use assert? > If it is not an assertion, then AssertionError is probably the wrong > exception. > > (It is okay in a testing framework, like unittest, but a bad idea in a > regular library or an application. Your end-users should never see an > AssertionError.) > > > The bottom line is, if I saw > > if not (thing > 0): raise AssertionError(...) > > in a code review, I'd probably insist that either it be changed to use > `assert`, > or the exception be changed to ValueError, whichever better expresses > the intention of the code. In a code review I would want the condition changed to be less noisy/ confusing to the reader. if thing <=0: whatever -- The best thing about growing older is that it takes such a long time. From steve+python at pearwood.info Fri Sep 22 07:11:32 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 21:11:32 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> Message-ID: <59c4efe7$0$14941$b1db1813$d948b532@news.astraweb.com> On Fri, 22 Sep 2017 07:53 pm, Bill wrote: > Marko Rauhamaa wrote: >> Bill : >> >>> I figure that, internally, an address, a pointer, is being passed by >>> value to implement pass by reference. Why do you say "they are right" >>> above? Are you saying it's not pass by reference? > > Thank you for your examples. I studied them carefully (and I'm not > through with them yet). > I just wanted to mention that my comment was made in the context that > Python is implemented by an interpreter written in C. I realize that > this may not always be the case. However, I haven't heard anyone > mention a Python interpreter written in Python yet. I don't see what the implementation language has to do with anything (except perhaps performance). You can implement any language in any other language, with greater or less difficulty, but its still possible. CPython is written in C, as is Stackless. Jython is written in Java. IronPython is written in C# for .Net. PyPy is written in a custom version of Python, RPython. Nuitka is written in C++. CLPython is written in Lisp. Berp and Hope are written in Haskell. Skulpt is written in Javascript. Vyper was a really old implementation written in OCaml, apparently now lost and no longer visible on the internet. Some of these may been no longer supported, but the Big Four python implementations are CPython, Jython, IronPython and PyPy. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Fri Sep 22 07:13:06 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 21:13:06 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> Message-ID: <59c4f043$0$14941$b1db1813$d948b532@news.astraweb.com> On Fri, 22 Sep 2017 08:48 pm, bartc wrote: > Can Python be used to write, say, a swap() function that works with any > argument types (not just classes or lists)? Example: > > def swap(&a,&b): # made up syntax > a, b = b, a > > x=10 > y="Z" > swap(x,y) > print (x,y) # "Z" and "10" > > If not, then it doesn't have reference passing as it is normally understood. No it cannot, and does not. You can emulate it by adding a layer of redirection, but that's it. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Fri Sep 22 07:15:54 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 21:15:54 +1000 Subject: Assertions References: <59c3fa9d$0$14948$b1db1813$d948b532@news.astraweb.com> <7W5xB.2362044$Ft7.259201@fx33.am4> Message-ID: <59c4f0ec$0$14941$b1db1813$d948b532@news.astraweb.com> On Fri, 22 Sep 2017 08:50 pm, alister wrote: >> The bottom line is, if I saw >> >> if not (thing > 0): raise AssertionError(...) >> >> in a code review, I'd probably insist that either it be changed to use >> `assert`, >> or the exception be changed to ValueError, whichever better expresses >> the intention of the code. > > In a code review I would want the condition changed to be less noisy/ > confusing to the reader. > > if thing <=0: whatever Fair point, assuming they are the same. Actually, even for floats they're not the same. py> not (NAN > 0) True py> NAN <= 0 False -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From marko at pacujo.net Fri Sep 22 07:24:57 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 22 Sep 2017 14:24:57 +0300 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> Message-ID: <87shff9drq.fsf@elektro.pacujo.net> bartc : > On 22/09/2017 10:23, Marko Rauhamaa wrote: >> However, Python doesn't need any language changes to implement memory >> slots. A memory slot could be defined as any object that implements >> "get()" and "set(value)" methods: > > I didn't understand your examples. > > Can Python be used to write, say, a swap() function that works with any > argument types (not just classes or lists)? Example: > > def swap(&a,&b): # made up syntax > a, b = b, a > > x=10 > y="Z" > swap(x,y) > print (x,y) # "Z" and "10" Yes, following my recipe: def swap(ref_a, ref_b): a, b = ref_a.get(), ref_b.get() ref_a.set(b) ref_b.set(a) x = 10 y = "Z" swap(slot_ref(locals(), "x"), slot_ref(locals(), "y")) print(x, y) # "Z" and 10 Marko From steve+python at pearwood.info Fri Sep 22 07:30:23 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 21:30:23 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c4f452$0$14929$b1db1813$d948b532@news.astraweb.com> On Fri, 22 Sep 2017 05:01 pm, Bill wrote: > Steve D'Aprano wrote: >> On Fri, 22 Sep 2017 02:57 pm, Bill wrote: >> >>> I find Python to be more more >>> like Java, with regard to "passing objects by reference". >> Which is not a surprise, since both Python and Java use the same value >> passing style: pass by object reference, or pass by sharing if you prefer. >> >> Java people don't call it that. They call it pass by value, and categorically >> deny that it is pass by reference. (They're right about the second point.) > > I figure that, internally, an address, a pointer, is being passed by > value to implement pass by reference. Why do you say "they are right" > above? Are you saying it's not pass by reference? Are you suggested that the Java people are wrong to say it isn't? Last time I suggested that the Java community had made a mistake in this regard, I got blasted by certain folks here for insulting the intelligence of compiler experts. But yes, I agree with the Java community that what they do is NOT pass by reference. It clearly is not: the canonical test for pass by reference is whether you can write a "swap" procedure which swaps two variables: a = 1 b = 2 swap(a, b) assert a == 2 and b == 1 A general swap procedure cannot be written in Python or Java. (We don't need one, in Python, because we have alternatives which are arguably better, but that's not the point.) So I am in 100% agreement with the Java people when they say what they do (and what Python does) is not pass by reference. > What really screws the terminology up is that it's not parameters that > are being passed, it's arguments! %-) I don't believe that I mentioned parameters or arguments, so that's a red herring. The terminology is fine, if we don't insist on ignoring it. There are many more kinds of passing semantics than just by value and by reference, and the confusion only occurs when people insist on taking the round peg of a language's actual behaviour, and hammering it in by brute-force into the square hole of "pass by value" or "pass by reference". Quoting Wikipedia: In some cases, the term "call by value" is problematic, as the value which is passed is not the value of the variable as understood by the ordinary meaning of value, but an implementation-specific reference to the value. Some examples: - call by sharing - call by need - call by name - call by copy-restore ("copy in, copy out") etc. https://en.wikipedia.org/wiki/Evaluation_strategy -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Fri Sep 22 07:47:28 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Sep 2017 21:47:28 +1000 Subject: [Tutor] beginning to code In-Reply-To: <87shff9drq.fsf@elektro.pacujo.net> References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> Message-ID: On Fri, Sep 22, 2017 at 9:24 PM, Marko Rauhamaa wrote: > bartc : > >> On 22/09/2017 10:23, Marko Rauhamaa wrote: >>> However, Python doesn't need any language changes to implement memory >>> slots. A memory slot could be defined as any object that implements >>> "get()" and "set(value)" methods: >> >> I didn't understand your examples. >> >> Can Python be used to write, say, a swap() function that works with any >> argument types (not just classes or lists)? Example: >> >> def swap(&a,&b): # made up syntax >> a, b = b, a >> >> x=10 >> y="Z" >> swap(x,y) >> print (x,y) # "Z" and "10" > > Yes, following my recipe: > > def swap(ref_a, ref_b): > a, b = ref_a.get(), ref_b.get() > ref_a.set(b) > ref_b.set(a) > > x = 10 > y = "Z" > swap(slot_ref(locals(), "x"), slot_ref(locals(), "y")) > print(x, y) # "Z" and 10 Sure, let me just put that into a function. CPython 3.7, although I'm pretty sure most CPython versions will do the same, as will several of the other Pythons. (Side point: Your slot_ref function is rather bizarre. It's a closure AND a class, just in case one of them isn't sufficient. The following code is copied and pasted from two of your posts and is unchanged other than making try_swapping into a function.) >>> def slot_ref(dict_or_array, key_or_index): ... class SlotRef: ... def get(self): return dict_or_array[key_or_index] ... def set(self, value): dict_or_array[key_or_index] = value ... return SlotRef() ... >>> def swap(ref_a, ref_b): ... a, b = ref_a.get(), ref_b.get() ... ref_a.set(b) ... ref_b.set(a) ... >>> def try_swapping(): ... x = 10 ... y = "Z" ... swap(slot_ref(locals(), "x"), slot_ref(locals(), "y")) ... print("x, y =", x, y) ... >>> try_swapping() x, y = 10 Z Strange... doesn't seem to work. Are you saying that Python is pass-by-reference outside of a function and pass-by-value inside? Because that'd be just insane. Or maybe what you have here isn't a real reference at all. ChrisA From alister.ware at ntlworld.com Fri Sep 22 08:03:45 2017 From: alister.ware at ntlworld.com (alister) Date: Fri, 22 Sep 2017 12:03:45 GMT Subject: Assertions References: <59c3fa9d$0$14948$b1db1813$d948b532@news.astraweb.com> <7W5xB.2362044$Ft7.259201@fx33.am4> <59c4f0ec$0$14941$b1db1813$d948b532@news.astraweb.com> Message-ID: On Fri, 22 Sep 2017 21:15:54 +1000, Steve D'Aprano wrote: > On Fri, 22 Sep 2017 08:50 pm, alister wrote: > >>> The bottom line is, if I saw >>> >>> if not (thing > 0): raise AssertionError(...) >>> >>> in a code review, I'd probably insist that either it be changed to use >>> `assert`, >>> or the exception be changed to ValueError, whichever better expresses >>> the intention of the code. >> >> In a code review I would want the condition changed to be less noisy/ >> confusing to the reader. >> >> if thing <=0: whatever > > Fair point, assuming they are the same. > > Actually, even for floats they're not the same. > > py> not (NAN > 0) > True py> NAN <= 0 False I bet those are conditions the original author did not expect actually I am not sure how you got them on my system python 2.7 >>> not (NAN >0) Traceback (most recent call last): File "", line 1, in NameError: name 'NAN' is not defined >>> NAN <=0 Traceback (most recent call last): File "", line 1, in NameError: name 'NAN' is not defined Python 3 Python 3.6.2 (default, Aug 11 2017, 11:59:59) [GCC 7.1.1 20170622 (Red Hat 7.1.1-3)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> not (NAN > 0) Traceback (most recent call last): File "", line 1, in NameError: name 'NAN' is not defined >>> NAN <= 0 Traceback (most recent call last): File "", line 1, in NameError: name 'NAN' is not defined I would also say that if your examples did indeed return different results then pythons logic model has a bug. -- Say "twenty-three-skiddoo" to logout. From bc at freeuk.com Fri Sep 22 08:03:53 2017 From: bc at freeuk.com (bartc) Date: Fri, 22 Sep 2017 13:03:53 +0100 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> Message-ID: On 22/09/2017 12:47, Chris Angelico wrote: > On Fri, Sep 22, 2017 at 9:24 PM, Marko Rauhamaa wrote: >> Yes, following my recipe: >> >> def swap(ref_a, ref_b): >> a, b = ref_a.get(), ref_b.get() >> ref_a.set(b) >> ref_b.set(a) >> >> x = 10 >> y = "Z" >> swap(slot_ref(locals(), "x"), slot_ref(locals(), "y")) >> print(x, y) # "Z" and 10 > > Sure, let me just put that into a function. CPython 3.7, although I'm > pretty sure most CPython versions will do the same, as will several of > the other Pythons. > > (Side point: Your slot_ref function is rather bizarre. It's a closure > AND a class, just in case one of them isn't sufficient. The following > code is copied and pasted from two of your posts and is unchanged > other than making try_swapping into a function.) > >>>> def slot_ref(dict_or_array, key_or_index): > ... class SlotRef: > ... def get(self): return dict_or_array[key_or_index] > ... def set(self, value): dict_or_array[key_or_index] = value > ... return SlotRef() > ... >>>> def swap(ref_a, ref_b): > ... a, b = ref_a.get(), ref_b.get() > ... ref_a.set(b) > ... ref_b.set(a) > ... >>>> def try_swapping(): > ... x = 10 > ... y = "Z" > ... swap(slot_ref(locals(), "x"), slot_ref(locals(), "y")) > ... print("x, y =", x, y) > ... >>>> try_swapping() > x, y = 10 Z > > Strange... doesn't seem to work. Are you saying that Python is > pass-by-reference outside of a function and pass-by-value inside? > Because that'd be just insane. > > Or maybe what you have here isn't a real reference at all. It also looks too complicated to be really useful. And I'm not sure it would work (when it does work), with more complex terms. For simple given: A = [10,20,30] B = ["X","Y","Z"] and wanting to swap A[0] and B[2]. Although these being list elements, they /could/ be exchanged via a function: def swapelems(a,i,b,j): a[i],b[j]=b[j],a[i] swapelems(A,0,B,2) Just not using a general-purpose swap function. -- bartc From gandalf at shopzeus.com Fri Sep 22 08:18:51 2017 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Fri, 22 Sep 2017 14:18:51 +0200 Subject: xml: TypeError: write() got an unexpected keyword argument 'short_empty_elements' Message-ID: Here is an MWE: import io from lxml import etree test_node = etree.fromstring(''' ? ???? ? ''') output = io.BytesIO(b'') test_node.getroottree().write(output, ???????????????????????? encoding="UTF-8", ???????????????????????? xml_declaration=None, ???????????????????????? default_namespace=None, ???????????????????????? method="c14n", ???????????????????????? short_empty_elements=False ???????????????????????? ) output.seek(0) print(output.read()) Result: Traceback (most recent call last): ? File "C:/not_telling/c14n.py", line 16, in ??? short_empty_elements=False ? File "lxml.etree.pyx", line 1869, in lxml.etree._ElementTree.write (src\lxml\lxml.etree.c:57004) TypeError: write() got an unexpected keyword argument 'short_empty_elements' I have tracked down this to: https://github.com/python/cpython/blob/master/Lib/xml/etree/ElementTree.py#L721 This method does have a "short_empty_elements" argument, but if I set it to True, then it fails with TypeError. Is this a bug? From marko at pacujo.net Fri Sep 22 08:26:39 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 22 Sep 2017 15:26:39 +0300 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> Message-ID: <87o9q2aphc.fsf@elektro.pacujo.net> Chris Angelico : > Sure, let me just put that into a function. CPython 3.7, although I'm > pretty sure most CPython versions will do the same, as will several of > the other Pythons. > [demonstration that it didn't work] Ok. The reason is this: Note: The contents of this dictionary should not be modified; changes may not affect the values of local and free variables used by the interpreter. So the language specification explicitly ruled it out, unfortunately. > (Side point: Your slot_ref function is rather bizarre. It's a closure > AND a class, just in case one of them isn't sufficient. I don't see anything bizarre in it at all. I use the pattern all the time. It's called an inner class: In Python, it is possible to nest a class within another class, method or function. Marko From marko at pacujo.net Fri Sep 22 08:27:23 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 22 Sep 2017 15:27:23 +0300 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> Message-ID: <87k20qapg4.fsf@elektro.pacujo.net> ram at zedat.fu-berlin.de (Stefan Ram): > Marko Rauhamaa writes: >>swap(slot_ref(locals(), "x"), slot_ref(locals(), "y")) > > You need to be able to write the call as > > swap( x, y ) Why? Marko From gandalf at shopzeus.com Fri Sep 22 08:29:02 2017 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Fri, 22 Sep 2017 14:29:02 +0200 Subject: xml: TypeError: write() got an unexpected keyword argument 'short_empty_elements' In-Reply-To: References: Message-ID: <0e63bc4d-1729-c633-b51d-939021641722@shopzeus.com> > Result: > > Traceback (most recent call last): > ? File "C:/not_telling/c14n.py", line 16, in > ??? short_empty_elements=False > ? File "lxml.etree.pyx", line 1869, in lxml.etree._ElementTree.write > (src\lxml\lxml.etree.c:57004) > TypeError: write() got an unexpected keyword argument 'short_empty_elements' Well, it looks like etree does not implement the short_empty_elements argument in its write method: https://github.com/lxml/lxml/blob/master/src/lxml/etree.pyx#L1954 But it should (see https://github.com/lxml/lxml/blob/master/src/lxml/etree.pyx#L5 - The ``lxml.etree`` module implements the extended ElementTree API for XML. ) Can somebody please confirm that this is a bug? Also, how can I send a bug report? ( I'm not able to add an issue to lxml, lack of permissions.? ) From tjol at tjol.eu Fri Sep 22 08:31:30 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 22 Sep 2017 14:31:30 +0200 Subject: Assertions In-Reply-To: References: <59c3fa9d$0$14948$b1db1813$d948b532@news.astraweb.com> <7W5xB.2362044$Ft7.259201@fx33.am4> <59c4f0ec$0$14941$b1db1813$d948b532@news.astraweb.com> Message-ID: <7680e983-a02e-089b-d700-cd8650f6b2b5@tjol.eu> On 2017-09-22 14:03, alister via Python-list wrote: > On Fri, 22 Sep 2017 21:15:54 +1000, Steve D'Aprano wrote: >> On Fri, 22 Sep 2017 08:50 pm, alister wrote: >>> [snip] >>> >>> In a code review I would want the condition changed to be less noisy/ >>> confusing to the reader. >>> >>> if thing <=0: whatever >> >> Fair point, assuming they are the same. >> >> Actually, even for floats they're not the same. >> > [snip] > > I would also say that if your examples did indeed return different > results then pythons logic model has a bug. No, it doesn't (in Python 3). NaN is not a number. It is neither larger nor smaller than zero. This behavior is correct: Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 12:22:00) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from math import nan >>> nan < 0 False >>> nan > 0 False >>> nan == 0 False >>> not (nan > 0) True Python 2.7 is a bit more fickle: Python 2.7.5 (default, Aug 2 2017, 11:05:32) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from numpy import nan >>> nan < 0 False >>> nan > 0 False >>> nan == 0 False >>> not(nan > 0) True >>> cmp(nan, 0) -1 >>> cmp(0, nan) 1 Of course I see why the behavior of NaN is hard to swallow: in a sense the logical thing to do would be to raise a ValueError (or TypeError) when comparing to NaN - seeing as the operation doesn't make much sense in the first place - but it's better to not have an edge case where comparing two floats can raise, but only under very unusual circumstances. Cheers, Thomas -- Thomas Jollans From steve+python at pearwood.info Fri Sep 22 08:34:19 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 22:34:19 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> Message-ID: <59c5034d$0$14972$b1db1813$d948b532@news.astraweb.com> On Fri, 22 Sep 2017 09:24 pm, Marko Rauhamaa wrote: > bartc : > >> On 22/09/2017 10:23, Marko Rauhamaa wrote: >>> However, Python doesn't need any language changes to implement memory >>> slots. A memory slot could be defined as any object that implements >>> "get()" and "set(value)" methods: >> >> I didn't understand your examples. >> >> Can Python be used to write, say, a swap() function that works with any >> argument types (not just classes or lists)? Example: >> >> def swap(&a,&b): # made up syntax >> a, b = b, a >> >> x=10 >> y="Z" >> swap(x,y) >> print (x,y) # "Z" and "10" > > Yes, following my recipe: > > def swap(ref_a, ref_b): > a, b = ref_a.get(), ref_b.get() > ref_a.set(b) > ref_b.set(a) > > x = 10 > y = "Z" > swap(slot_ref(locals(), "x"), slot_ref(locals(), "y")) > print(x, y) # "Z" and 10 No, you failed to follow Bart's instructions and answered a different question. "Can you pulverise this granite boulder with your bare hands?" "Sure! I just need to use this sledge hammer, and pulverise this small sandstone rock instead." You have to pass x and y, not strings 'x' and 'y'. The swap procedure needs to accept any variable, given as ordinary bare names swap(x, y), not written as strings, or by hard-coding x and y as the variables to swap, or by using a string and passing it to exec, or any other loophole. Also, you're assuming that locals() is writable, which in the most general case it is not. Try using locals from inside a function, rather than in the global scope. You made a good attempt to emulate pass by reference via an extra layer of indirection. Pity that it doesn't solve the problem and doesn't work. Here's an easy way to emulate pass by reference which works in any scope: use a list. def swap(a, b): a[0], b[0] = b[0], a[0] a = [1] b = [2] swap(a, b) assert a[0] == 2 and b[0] == 1 It's not proper pass by reference, and so will still fail Bart's test, because you need to manually add an extra layer of redirection (using a list). Its like using a pointer in C to emulate references, compared to having actual language support for them like in Pascal or C++. But if I wanted to write a Pascal interpreter in Python, I could use something like this to implement Pascal var parameters. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From marko at pacujo.net Fri Sep 22 08:40:43 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 22 Sep 2017 15:40:43 +0300 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> Message-ID: <87fubeaotw.fsf@elektro.pacujo.net> ram at zedat.fu-berlin.de (Stefan Ram): > Marko Rauhamaa writes: >>ram at zedat.fu-berlin.de (Stefan Ram): >>>Marko Rauhamaa writes: >>>>swap(slot_ref(locals(), "x"), slot_ref(locals(), "y")) >>>You need to be able to write the call as >>>swap( x, y ) >>Why? > > You responded to Bart: > > | swap(x,y) > | print (x,y) # "Z" and "10" > | > |If not, then it doesn't have reference passing as > |it is normally understood. > > , and Bart required this form. Moreover, if you allow other > forms, such as > > swap( &x, &y ) > > , then even C, would have "call by reference", > but it has not. There's two things: syntax and semantics. Obviously, Bart's syntax couldn't work syntactically unless Python added the syntactic facilities. But the bigger question is a semantic one: is it possible regardless of syntactic considerations. As Chris pointed out, Python has explicitly ruled it out with the immutability caveat to locals(). Marko From tjol at tjol.eu Fri Sep 22 08:41:34 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 22 Sep 2017 14:41:34 +0200 Subject: xml: TypeError: write() got an unexpected keyword argument 'short_empty_elements' In-Reply-To: <0e63bc4d-1729-c633-b51d-939021641722@shopzeus.com> References: <0e63bc4d-1729-c633-b51d-939021641722@shopzeus.com> Message-ID: <88145577-02f6-5358-c3fd-dced882b32e0@tjol.eu> On 2017-09-22 14:29, Nagy L?szl? Zsolt wrote: > >> Result: >> >> Traceback (most recent call last): >> ? File "C:/not_telling/c14n.py", line 16, in >> ??? short_empty_elements=False >> ? File "lxml.etree.pyx", line 1869, in lxml.etree._ElementTree.write >> (src\lxml\lxml.etree.c:57004) >> TypeError: write() got an unexpected keyword argument 'short_empty_elements' > Well, it looks like etree does not implement the short_empty_elements > argument in its write method: > > https://github.com/lxml/lxml/blob/master/src/lxml/etree.pyx#L1954 > > But it should (see > https://github.com/lxml/lxml/blob/master/src/lxml/etree.pyx#L5 - The > ``lxml.etree`` module implements the extended ElementTree API for XML. ) > > Can somebody please confirm that this is a bug? Also, how can I send a > bug report? ( I'm not able to add an issue to lxml, lack of permissions.? ) > https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree.write The argument was added in Python 3.4. Presumably, lxml implemented the API before this change. Maybe this would be considered a bug by lxml. Maybe it won't. http://lxml.de/ links to a bug tracker and a mailing list. -- Thomas Jollans From steve+python at pearwood.info Fri Sep 22 08:43:36 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 22:43:36 +1000 Subject: Assertions References: <59c3fa9d$0$14948$b1db1813$d948b532@news.astraweb.com> <7W5xB.2362044$Ft7.259201@fx33.am4> <59c4f0ec$0$14941$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c5057b$0$14970$b1db1813$d948b532@news.astraweb.com> On Fri, 22 Sep 2017 10:03 pm, alister wrote: > On Fri, 22 Sep 2017 21:15:54 +1000, Steve D'Aprano wrote: > >> On Fri, 22 Sep 2017 08:50 pm, alister wrote: >> >>>> The bottom line is, if I saw >>>> >>>> if not (thing > 0): raise AssertionError(...) >>>> >>>> in a code review, I'd probably insist that either it be changed to use >>>> `assert`, >>>> or the exception be changed to ValueError, whichever better expresses >>>> the intention of the code. >>> >>> In a code review I would want the condition changed to be less noisy/ >>> confusing to the reader. >>> >>> if thing <=0: whatever >> >> Fair point, assuming they are the same. >> >> Actually, even for floats they're not the same. >> >> py> not (NAN > 0) >> True py> NAN <= 0 False > > I bet those are conditions the original author did not expect Yes, everyone forgets about NAN ("Not A Number"). > actually I am not sure how you got them on my system Oops, sorry, NAN is defined in my startup.py file, together with INF. NAN = float('nan') INF = float('inf') Apologies. > I would also say that if your examples did indeed return different > results then pythons logic model has a bug. No, Python does the right thing here. Not all classes of values have a total ordering. With numbers, we can safely say that if x > y, and y > z, then x > z too. But that doesn't necessarily hold for everything. E.g. if x, y and z are sports teams, and we identify ">" with "beats", then x can beat y, and y beat z, but x lose to z. This isn't *numeric* order, but it is a valid form of order. In the case of floating point NANs, they are unordered with respect to all numbers. So for any number x, we always have: NAN == x NAN < x NAN > x NAN <= x NAN >= x all return False, and NAN != x return True. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From bc at freeuk.com Fri Sep 22 08:47:10 2017 From: bc at freeuk.com (bartc) Date: Fri, 22 Sep 2017 13:47:10 +0100 Subject: [Tutor] beginning to code In-Reply-To: <59c5034d$0$14972$b1db1813$d948b532@news.astraweb.com> References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <59c5034d$0$14972$b1db1813$d948b532@news.astraweb.com> Message-ID: <2D7xB.803211$sC5.409529@fx45.am4> On 22/09/2017 13:34, Steve D'Aprano wrote: > On Fri, 22 Sep 2017 09:24 pm, Marko Rauhamaa wrote: >> Yes, following my recipe: >> >> def swap(ref_a, ref_b): >> a, b = ref_a.get(), ref_b.get() >> ref_a.set(b) >> ref_b.set(a) >> >> x = 10 >> y = "Z" >> swap(slot_ref(locals(), "x"), slot_ref(locals(), "y")) >> print(x, y) # "Z" and 10 > > > No, you failed to follow Bart's instructions and answered a different question. > You have to pass x and y, not strings 'x' and 'y'. The swap procedure needs to > accept any variable, given as ordinary bare names swap(x, y), not written as > strings, or by hard-coding x and y as the variables to swap, or by using a > string and passing it to exec, or any other loophole. And being able to pass any lvalue expression, not just simple variable names. Such as a[i] or x.y, provided the term is mutable. (To make it work would require a new reference type. And extra versions of the byte-codes or whatever is used to evaluate terms such as: a, a[i], x.y that evaluate a reference rather than the value. So LOADFASTREF as well as LOADFAST) -- bartc From pedro.exposito at lexisnexisrisk.com Fri Sep 22 09:04:48 2017 From: pedro.exposito at lexisnexisrisk.com (Exposito, Pedro (RIS-MDW)) Date: Fri, 22 Sep 2017 13:04:48 +0000 Subject: what is happening in panda "where" clause Message-ID: <7EA3F03731CB00478865918182F3DDEAF289D216@RISALPMBXP003.risk.regn.net> This code does a "where" clause on a panda data frame... Code: import pandas as pd; col_names = ['Name', 'Age', 'Weight', "Education"]; # create panda dataframe x = pd.read_csv('test.dat', sep='|', header=None, names = col_names); # apply "where" condition z = x[ (x['Age'] == 55) ] # prints row WHERE age == 55 print (z); What is happening in this statement: z = x[ (x['Age'] == 55) ] Thanks, Pedro Exposito ---------------------------------------- The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. This message may be an attorney-client communication and/or work product and as such is privileged and confidential. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. From ganesh1pal at gmail.com Fri Sep 22 09:05:52 2017 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Fri, 22 Sep 2017 18:35:52 +0530 Subject: How to ingore "AttributeError: exception In-Reply-To: <4ea217d8-bcac-d937-f9ce-9db654774a53@tjol.eu> References: <4ea217d8-bcac-d937-f9ce-9db654774a53@tjol.eu> Message-ID: > > > is a perfectly good pattern to use. > Thanks looks nice :) > > > > > > > > I am a Linux user on Python 2.7 > > Have you considered moving to Python 3? > Not yet , but Is there something that I need to consider in the current context? Regards, Ganesh From tjol at tjol.eu Fri Sep 22 09:07:07 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 22 Sep 2017 15:07:07 +0200 Subject: Assertions In-Reply-To: <59c5057b$0$14970$b1db1813$d948b532@news.astraweb.com> References: <59c3fa9d$0$14948$b1db1813$d948b532@news.astraweb.com> <7W5xB.2362044$Ft7.259201@fx33.am4> <59c4f0ec$0$14941$b1db1813$d948b532@news.astraweb.com> <59c5057b$0$14970$b1db1813$d948b532@news.astraweb.com> Message-ID: <31bbf217-b500-c906-0f72-30e5735e8f96@tjol.eu> On 2017-09-22 14:43, Steve D'Aprano wrote: > In the case of floating point NANs, they are unordered with respect to all > numbers. So for any number x, we always have: > > NAN == x > NAN < x > NAN > x > NAN <= x > NAN >= x > > all return False, and > > NAN != x > > return True. Just to make the implication explicit: >>> from math import nan >>> nan is nan True >>> nan == nan False >>> nan != nan True >>> -- Thomas Jollans From gandalf at shopzeus.com Fri Sep 22 09:15:05 2017 From: gandalf at shopzeus.com (=?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?=) Date: Fri, 22 Sep 2017 15:15:05 +0200 Subject: xml: TypeError: write() got an unexpected keyword argument 'short_empty_elements' In-Reply-To: <88145577-02f6-5358-c3fd-dced882b32e0@tjol.eu> References: <0e63bc4d-1729-c633-b51d-939021641722@shopzeus.com> <88145577-02f6-5358-c3fd-dced882b32e0@tjol.eu> Message-ID: > https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.ElementTree.write > > The argument was added in Python 3.4. Presumably, lxml implemented the > API before this change. > > Maybe this would be considered a bug by lxml. Maybe it won't. Maybe it is not a bug, just a feature not implemented. After testing it a bit, I realized that for my chosen method (c14n) it cannot be specified anyway, because it must be False and actually it works that way. > > http://lxml.de/ links to a bug tracker and a mailing list. > All right, I'm subscribing to the list (I have other questions regarding C14N) From steve+python at pearwood.info Fri Sep 22 09:30:34 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 22 Sep 2017 23:30:34 +1000 Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> Message-ID: <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> On Fri, 22 Sep 2017 10:27 pm, Marko Rauhamaa wrote: > ram at zedat.fu-berlin.de (Stefan Ram): > >> Marko Rauhamaa writes: >>>swap(slot_ref(locals(), "x"), slot_ref(locals(), "y")) >> >> You need to be able to write the call as >> >> swap( x, y ) > > Why? Because that's the whole point of the exercise. The exercise isn't to demonstrate how to swap two variables. In Python, that's easy: a, b = b, a The exercise is to demonstrate pass by reference semantics. That requires demonstrating the same semantics as the Pascal swap procedure: procedure swap(var a, var b): begin tmp := a; a := b; b := tmp; end; (ignoring the type declarations for brevity). Call by reference semantics enable you to call swap(x, y) to swap x and y in the caller's scope. You don't call swap('x', 'y', scope_of_x, scope_of_y) or any other variant. That isn't call by reference semantics. The whole point of call by reference semantics is that the *compiler*, not the programmer, tracks the variables and their scopes. The programmer just says "swap x and y", and the compiler works out how to do it. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From validationmail1 at gmail.com Fri Sep 22 10:09:01 2017 From: validationmail1 at gmail.com (validationmail1 at gmail.com) Date: Fri, 22 Sep 2017 07:09:01 -0700 (PDT) Subject: search and replace first amount of strings instances with one thing and a second amount of instances with another thing- Message-ID: <71202558-f2cc-4557-8f82-383c5312abdf@googlegroups.com> i have a code in python to search and replace what i need though is to replace the first say 10 instances of the number 1 with 2 and the second 10 instances with the number 3. anybody knows how to do that? fin = open(r'F:\1\xxx.txt') fout = open(r'F:\1\xxx2.txt', "wt") for line in fin: fout.write( line.replace('1', '2') ) fin.close() fout.close() From __peter__ at web.de Fri Sep 22 10:10:05 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 22 Sep 2017 16:10:05 +0200 Subject: what is happening in panda "where" clause References: <7EA3F03731CB00478865918182F3DDEAF289D216@RISALPMBXP003.risk.regn.net> Message-ID: Exposito, Pedro (RIS-MDW) wrote: > This code does a "where" clause on a panda data frame... > > Code: > import pandas as pd; > col_names = ['Name', 'Age', 'Weight', "Education"]; > # create panda dataframe > x = pd.read_csv('test.dat', sep='|', header=None, names = col_names); > # apply "where" condition > z = x[ (x['Age'] == 55) ] > # prints row WHERE age == 55 > print (z); > > What is happening in this statement: > z = x[ (x['Age'] == 55) ] > > Thanks, Let's take it apart into individual steps: Make up example data: >>> import pandas as pd >>> x = pd.DataFrame([["Jim", 44], ["Sue", 55], ["Alice", 66]], columns=["Name", "Age"]) >>> x Name Age 0 Jim 44 1 Sue 55 2 Alice 66 Have a look at the inner expression: >>> x["Age"] == 55 0 False 1 True 2 False So this is a basically vector of boolean values. If you want more details: in numpy operations involving a a scalar and an array work via "broadcasting". In pure Python you would write something similar as >>> [v == 55 for v in x["Age"]] [False, True, False] Use the result as an index: >>> x[[False, True, True]] Name Age 1 Sue 55 2 Alice 66 [2 rows x 2 columns] This is again in line with numpy arrays -- if you pass an array of boolean values as an index the values in the True positions are selected. In pure Python you could achieve that with >>> index = [v == 55 for v in x["Age"]] >>> index [False, True, False] >>> [v for b, v in zip(index, x["Age"]) if b] [55] From rosuav at gmail.com Fri Sep 22 10:24:51 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 23 Sep 2017 00:24:51 +1000 Subject: [Tutor] beginning to code In-Reply-To: <87o9q2aphc.fsf@elektro.pacujo.net> References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87o9q2aphc.fsf@elektro.pacujo.net> Message-ID: On Fri, Sep 22, 2017 at 10:26 PM, Marko Rauhamaa wrote: > Chris Angelico : >> (Side point: Your slot_ref function is rather bizarre. It's a closure >> AND a class, just in case one of them isn't sufficient. > > I don't see anything bizarre in it at all. I use the pattern all the > time. It's called an inner class: > > In Python, it is possible to nest a class within another class, > method or function. > > Sure you *can* do it. It's perfectly legal Python syntax. But what's the point? The class alone will do it. class slot_ref: def __init__(self, ns, key): self.ns = ns; self.key = key def get(self): return self.ns[self.key] def set(self, value): self.ns[self.key] = value That should be drop-in compatible with your original function/class hybrid, complete with following the naming convention for functions rather than classes. ChrisA From __peter__ at web.de Fri Sep 22 10:27:56 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 22 Sep 2017 16:27:56 +0200 Subject: Convert pandas series to string and datetime object References: <157fc84b-7cfd-4e3c-9155-fe39fcd3ff34@googlegroups.com> Message-ID: Pavol Lisy wrote: > pandas is one of reasons why python is so popular these days. But > "there is only milion way how to do it" (and other unpythonic issues) > I see there every time I am looking at it. :) Yeah, such a useful tool with such a byzantine API, completely at odds with the zen -- I wonder what prevented that the authors chose to write it in Perl ;) From marko at pacujo.net Fri Sep 22 10:56:05 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Fri, 22 Sep 2017 17:56:05 +0300 Subject: [Tutor] beginning to code References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87o9q2aphc.fsf@elektro.pacujo.net> Message-ID: <8760carddm.fsf@elektro.pacujo.net> Chris Angelico : > On Fri, Sep 22, 2017 at 10:26 PM, Marko Rauhamaa wrote: >> Chris Angelico : >>> (Side point: Your slot_ref function is rather bizarre. It's a closure >>> AND a class, just in case one of them isn't sufficient. >> >> I don't see anything bizarre in it at all. > Sure you *can* do it. It's perfectly legal Python syntax. But what's > the point? The class alone will do it. > > class slot_ref: > def __init__(self, ns, key): > self.ns = ns; self.key = key > def get(self): return self.ns[self.key] > def set(self, value): self.ns[self.key] = value > > That should be drop-in compatible with your original function/class > hybrid, complete with following the naming convention for functions > rather than classes. You are right. That one would be the way to go here. Marko From stephanh42 at gmail.com.invalid Fri Sep 22 14:34:24 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 22 Sep 2017 18:34:24 GMT Subject: Fw: Problems Installing Python36 References: <20170912.034647.1218.0@webmail04.vgs.untd.com> <6278c207-2744-5603-b983-6d73c451714f@tjol.eu> <2e23c425-0ddf-8cc7-25ac-20f4568941c9@gmail.com> <59c2a3bc$0$792$e4fe514c@news.xs4all.nl> Message-ID: Op 2017-09-20, Irmen de Jong schreef : > The only thing I can think of is that it asks windows update to > install said KB update but that it depends on something else that > isn't installed or that the user running the installation doesn't have > the rights to install windows updates. (I suspect something will be > logged in the event viewer somewhere...?) Yeah, I suppose something like that. Presumably you can lock down Windows in some way that it won't install the KB, but that is clearly not the factory default. > Or that it doesn't attempt to download it at all and that we are > misinformed :P :-( > Btw, I personally never had any issues installing Python on Windows. I was vaguely tempted to offer the Mingw-w64 (GCC) Python as an alternative, since it doesn't rely on any optionally-installed Microsoft DLLs and so avoids this issue. But I suppose that is not really the newbie-friendly solution the OP was looking for... Stephan From stephanh42 at gmail.com.invalid Fri Sep 22 14:39:03 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 22 Sep 2017 18:39:03 GMT Subject: Even Older Man Yells at Whippersnappers References: <1505842722l.23461932l.0l@psu.edu> <94282758-fdd0-7cb7-6fcb-a4997a3bc72d@tjol.eu> Message-ID: Op 2017-09-21, Thomas Jollans schreef : > On 2017-09-19 20:21, Stefan Ram wrote: >> I do not use UTF-8 >> > > Why on earth not?! Even *More* Older Man Yells at UTF-8? From stephanh42 at gmail.com.invalid Fri Sep 22 14:48:05 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 22 Sep 2017 18:48:05 GMT Subject: Assertions References: <59c3fa9d$0$14948$b1db1813$d948b532@news.astraweb.com> <7W5xB.2362044$Ft7.259201@fx33.am4> <59c4f0ec$0$14941$b1db1813$d948b532@news.astraweb.com> <59c5057b$0$14970$b1db1813$d948b532@news.astraweb.com> <31bbf217-b500-c906-0f72-30e5735e8f96@tjol.eu> Message-ID: Op 2017-09-22, Thomas Jollans schreef : > Just to make the implication explicit: > >>>> from math import nan >>>> nan is nan > True >>>> nan == nan > False >>>> nan != nan > True >>>> To add to the fun: >>> nan is nan True Stephan From jsteward2930 at gmail.com Fri Sep 22 14:50:36 2017 From: jsteward2930 at gmail.com (Joey Steward) Date: Fri, 22 Sep 2017 11:50:36 -0700 Subject: Issues with beginning Django use Message-ID: Hello, I've been attempting to begin learning Django but have been having running Django and Python commands on windows. For example, when I run django-admin startproject mytestsite, I get the following error message django-admin : *The term 'django-admin' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,* *verify that the path is correct and try again.* *At line:1 char:1* + django-admin startproject mytestsite + ~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (django-admin:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException Just curious if anyone has encountered a similar problem and can give some advice on getting moving in the right direction. Thanks a lot! From none at invalid.com Fri Sep 22 15:42:45 2017 From: none at invalid.com (mm0fmf) Date: Fri, 22 Sep 2017 20:42:45 +0100 Subject: Issues with beginning Django use In-Reply-To: References: Message-ID: On 22/09/2017 19:50, Joey Steward wrote: > Hello, > > I've been attempting to begin learning Django but have been having running > Django and Python commands on windows. > > For example, when I run django-admin startproject mytestsite, I get the > following error message > > django-admin : *The term 'django-admin' is not recognized as the name of a > cmdlet, function, script file, or operable program. Check the spelling of > the name, or if a path was included,* > *verify that the path is correct and try again.* > *At line:1 char:1* > + django-admin startproject mytestsite > + ~~~~~~~~~~~~ > + CategoryInfo : ObjectNotFound: (django-admin:String) [], > CommandNotFoundException > + FullyQualifiedErrorId : CommandNotFoundException > > > > Just curious if anyone has encountered a similar problem and can give some > advice on getting moving in the right direction. > > Thanks a lot! > This is a repeat of your post of 20/9/2017. I cut and pasted your error message "django-admin : *The term 'django-admin' is not ...." into Google and the first hit was the fix to the problem. Pasting error messages into a Google search gives instant results. Posting to the list/newsgroup may give better, more personalised responses but you may have to wait sometime before anyone replies. From pavol.lisy at gmail.com Fri Sep 22 16:15:56 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Fri, 22 Sep 2017 22:15:56 +0200 Subject: How to share class relationship representations? In-Reply-To: References: Message-ID: On 9/19/17, leam hall wrote: > I'm working on designing the classes, sub-classes, and relationships in my > code. What is a good visual way to represent it so it can be stored in git > and shared on the list without large images or attachments? > > Thanks! > > Leam https://stackoverflow.com/questions/29586520/can-one-get-hierarchical-graphs-from-networkx-with-python-3#29597209 there are probably more ideas useful for you. Maybe this one could be inspiring too: import networkx as nx g=nx.DiGraph() g.add_edges_from([('class 1','class 2'), ('class 1','class 3'), ('class 1','class 4'), ('class 2','class 5'), ('class 2','class 6'), ('class 2','class 7'), ('class 3','class 8'), ('class 3','class 9'), ('class 4','class 10'), ('class 5','class 11'), ('class 5','class 12'), ('class 6','class 13')]) p=nx.drawing.nx_pydot.to_pydot(g) p.write_png('example.png') And you could make function which from list of classes create list of edges! :) In git you don't need to store images just list of classes and script to make images (documentation). From jladasky at itu.edu Fri Sep 22 17:16:26 2017 From: jladasky at itu.edu (jladasky at itu.edu) Date: Fri, 22 Sep 2017 14:16:26 -0700 (PDT) Subject: Assertions In-Reply-To: References: Message-ID: <7e7a142f-2d7f-4c4d-9828-a4174b51bc12@googlegroups.com> On Thursday, September 21, 2017 at 9:29:19 AM UTC-7, Tobiah wrote: > Are these completely equivalent? > > def foo(thing): > > assert(thing > 0), "Thing must be greater than zero" > > > def foo(thing): > > if not (thing > 0): raise AssertionError("Thing must be greater than zero") > > > Other than the fact that the assertion can be turned off > with -O? For that reason, I would prefer to raise ValueError instead of AssertionError. The -O flag is nice for turning off test code. If the code is essential to the functionality of the program, you probably don't want to misidentify it as test code. From irmen at NOSPAM.xs4all.nl Fri Sep 22 19:35:29 2017 From: irmen at NOSPAM.xs4all.nl (Irmen de Jong) Date: Sat, 23 Sep 2017 01:35:29 +0200 Subject: Fw: Problems Installing Python36 In-Reply-To: References: <20170912.034647.1218.0@webmail04.vgs.untd.com> <6278c207-2744-5603-b983-6d73c451714f@tjol.eu> <2e23c425-0ddf-8cc7-25ac-20f4568941c9@gmail.com> <59c2a3bc$0$792$e4fe514c@news.xs4all.nl> Message-ID: <59c59e41$0$806$e4fe514c@news.xs4all.nl> On 09/22/2017 08:34 PM, Stephan Houben wrote: > I was vaguely tempted to offer the Mingw-w64 (GCC) Python as an > alternative, since it doesn't rely on any optionally-installed Microsoft > DLLs and so avoids this issue. But I suppose that is not really the > newbie-friendly solution the OP was looking for... Mingw? Perhaps better to choose Anaconda/Miniconda instead if you go for an alternative implementation... Irmen From elearn2014 at gmail.com Fri Sep 22 21:34:43 2017 From: elearn2014 at gmail.com (Length Power) Date: Fri, 22 Sep 2017 21:34:43 -0400 Subject: How to get the webpage with socks5 proxy in python3? Message-ID: sudo lsof -i:1080 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sslocal 1795 root 4u IPv4 16233 0t0 TCP localhost:socks (LISTEN) sslocal 1795 root 5u IPv4 16234 0t0 UDP localhost:socks An app was listening on localhost:1080,it is ready for curl's socks5 proxy. The app provided socks5 proxy service is shadowsocks client on my pc. curl can work with socks proxy in my pc. target="target_url_youtube" curl --socks5-hostname 127.0.0.1:1080 $target -o /tmp/sample The target url can be downloaded with scoks5 proxy in curl. shadowsocks client------->shadowsocks server--->target_url_youtube 127.0.0.1:1080 1xx.1xx.1xx.1xx:port target_url_youtube Notice: All the packages from 127.0.0.1:1080 to 1xx.1xx.1xx.1xx:port is sent and received by shadowsocks client and server. curl just sent packages to 127.0.0.1:1080. Now i want to get the target webpage with socks proxy in python3. the first try : import urllib.request target="target_url_youtubr" proxy_support = urllib.request.ProxyHandler({'sock5': 'localhost:1080'}) opener = urllib.request.build_opener(proxy_support) urllib.request.install_opener(opener) web = urllib.request.urlopen(target).read() print(web) The error info: sock.connect(sa) OSError: [Errno 101] Network is unreachable Notice: It is no use to write {'sock5': 'localhost:1080'} as {'sock5': '127.0.0.1:1080'},i have verified it. the second try: import socks import socket socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 1080) socket.socket = socks.socksocket import urllib.request target="target_url_youtubr" print(urllib.request.urlopen('target').read()) error info: raise BadStatusLine(line) http.client.BadStatusLine: The third try: import socks import socket from urllib import request socks.set_default_proxy(socks.SOCKS5, "localhost", 1080) socket.socket = socks.socksocket target="target_url_youtube" r = request.urlopen(url) print(r.read()) ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:600) urllib.error.URLError: Why data packet can't send via localhost:1080 and get the target_url_youtube's content,but curl can? How to fix my python3 code for socks5 proxy? shadowsocks client---------->shadowsocks server------>target_url_youtube 127.0.0.1:1080 1xx.1xx.1xx.1xx:port target_url_youtube `curl --socks5-hostname 127.0.0.1:1080 $target -o /tmp/sample` can do the job. why all the three python codes can't do? How to fix it? From elearn2014 at gmail.com Fri Sep 22 21:44:12 2017 From: elearn2014 at gmail.com (Length Power) Date: Fri, 22 Sep 2017 18:44:12 -0700 (PDT) Subject: How to get the webpage with socks5 proxy in python3? Message-ID: <06540f6c-3979-4c13-9a18-8b6a20fab926@googlegroups.com> sudo lsof -i:1080 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sslocal 1795 root 4u IPv4 16233 0t0 TCP localhost:socks (LISTEN) sslocal 1795 root 5u IPv4 16234 0t0 UDP localhost:socks An app was listening on localhost:1080,it is ready for curl's socks5 proxy. The app provided socks5 proxy service is shadowsocks client on my pc. curl can work with socks proxy in my pc. target="target_url_youtube" curl --socks5-hostname 127.0.0.1:1080 $target -o /tmp/sample The target url can be downloaded with scoks5 proxy in curl. shadowsocks client------->shadowsocks server--->target_url_youtube 127.0.0.1:1080 1xx.1xx.1xx.1xx:port target_url_youtube Notice: All the packages from 127.0.0.1:1080 to 1xx.1xx.1xx.1xx:port is sent and received by shadowsocks client and server. curl just sent packages to 127.0.0.1:1080. Now i want to get the target webpage with socks proxy in python3. the first try : import urllib.request target="target_url_youtubr" proxy_support = urllib.request.ProxyHandler({'sock5': 'localhost:1080'}) opener = urllib.request.build_opener(proxy_support) urllib.request.install_opener(opener) web = urllib.request.urlopen(target).read() print(web) The error info: sock.connect(sa) OSError: [Errno 101] Network is unreachable Notice: It is no use to write {'sock5': 'localhost:1080'} as {'sock5': '127.0.0.1:1080'},i have verified it. the second try: import socks import socket socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 1080) socket.socket = socks.socksocket import urllib.request target="target_url_youtubr" print(urllib.request.urlopen('target').read()) error info: raise BadStatusLine(line) http.client.BadStatusLine: The third try:as Martijn Pieters say in web [Python3 - Requests with Sock5 proxy ][1] import socks import socket from urllib import request socks.set_default_proxy(socks.SOCKS5, "localhost", 1080) socket.socket = socks.socksocket target="target_url_youtube" r = request.urlopen(url) print(r.read()) ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:600) urllib.error.URLError: Why data packet can't send via localhost:1080 and get the target_url_youtube's content,but curl can? How to fix my python3 code for socks5 proxy? shadowsocks client---------->shadowsocks server------>target_url_youtube 127.0.0.1:1080 1xx.1xx.1xx.1xx:port target_url_youtube `curl --socks5-hostname 127.0.0.1:1080 $target -o /tmp/sample` can do the job. why all the three python codes can't do? How to fix it? [1]: https://stackoverflow.com/questions/31777692/python3-requests-with-sock5-proxy From BILL_NOSPAM at whoknows.net Fri Sep 22 23:06:57 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Fri, 22 Sep 2017 23:06:57 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: Mark Lawrence wrote: > On 22/09/2017 08:01, Bill wrote: >> Steve D'Aprano wrote: >>> On Fri, 22 Sep 2017 02:57 pm, Bill wrote: >>> >>>> I find Python to be more more >>>> like Java, with regard to "passing objects by reference". >>> Which is not a surprise, since both Python and Java use the same >>> value passing >>> style: pass by object reference, or pass by sharing if you prefer. >>> >>> Java people don't call it that. They call it pass by value, and >>> categorically >>> deny that it is pass by reference. (They're right about the second >>> point.) >> >> I figure that, internally, an address, a pointer, is being passed by >> value to implement pass by reference. Why do you say "they are >> right" above? Are you saying it's not pass by reference? >> > > Please see > http://jeffknupp.com/blog/2012/11/13/is-python-callbyvalue-or-callbyreference-neither/ > and http://effbot.org/zone/call-by-object.htm > I would would agree with the description provided for the C++ example provided string some_guy = "fred"; is replaced by char* some_guy="fred"; To see that this is correct, note the some_guy may subsequently be assigned to a character string much longer then "fred". An additional note: A character string literal, like "cat", never occurs more than once in compiled C++ program unit. This also shows that the provided description can't be completely correct. One last thing, string some_guy = "fred" is really the same thing as string some_guy("fred"); and both equivalently call the string constructor. The data type of "fred" is const char*, not (class) string. From BILL_NOSPAM at whoknows.net Fri Sep 22 23:43:41 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Fri, 22 Sep 2017 23:43:41 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: Bill wrote: > Mark Lawrence wrote: >> On 22/09/2017 08:01, Bill wrote: >>> Steve D'Aprano wrote: >>>> On Fri, 22 Sep 2017 02:57 pm, Bill wrote: >>>> >>>>> I find Python to be more more >>>>> like Java, with regard to "passing objects by reference". >>>> Which is not a surprise, since both Python and Java use the same >>>> value passing >>>> style: pass by object reference, or pass by sharing if you prefer. >>>> >>>> Java people don't call it that. They call it pass by value, and >>>> categorically >>>> deny that it is pass by reference. (They're right about the second >>>> point.) >>> >>> I figure that, internally, an address, a pointer, is being passed by >>> value to implement pass by reference. Why do you say "they are >>> right" above? Are you saying it's not pass by reference? >>> >> >> Please see >> http://jeffknupp.com/blog/2012/11/13/is-python-callbyvalue-or-callbyreference-neither/ >> and http://effbot.org/zone/call-by-object.htm >> > > > I would would agree with the description provided for the C++ example > provided > > string some_guy = "fred"; > is replaced by > char* some_guy="fred"; On second thought, so that the description is correct (matches the semantics), replace it by char some_guy[10]="fred"; But then you need to use std::strcpy to reassign some_guy to "george". > > To see that this is correct, note the some_guy may subsequently be > assigned to a character string much longer then "fred". An additional > note: A character string literal, like "cat", never occurs more than > once in compiled C++ program unit. This also shows that the provided > description can't be completely correct. One last thing, > > string some_guy = "fred" > > is really the same thing as > > string some_guy("fred"); > > and both equivalently call the string constructor. > > The data type of "fred" is const char*, not (class) string. From breamoreboy at yahoo.co.uk Fri Sep 22 23:58:17 2017 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 23 Sep 2017 04:58:17 +0100 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: On 23/09/2017 04:06, Bill wrote: > Mark Lawrence wrote: >> On 22/09/2017 08:01, Bill wrote: >>> Steve D'Aprano wrote: >>>> On Fri, 22 Sep 2017 02:57 pm, Bill wrote: >>>> >>>>> I find Python to be more more >>>>> like Java, with regard to "passing objects by reference". >>>> Which is not a surprise, since both Python and Java use the same >>>> value passing >>>> style: pass by object reference, or pass by sharing if you prefer. >>>> >>>> Java people don't call it that. They call it pass by value, and >>>> categorically >>>> deny that it is pass by reference. (They're right about the second >>>> point.) >>> >>> I figure that, internally, an address, a pointer, is being passed by >>> value to implement pass by reference.? Why do you say "they are >>> right" above? Are you saying it's not pass by reference? >>> >> >> Please see >> http://jeffknupp.com/blog/2012/11/13/is-python-callbyvalue-or-callbyreference-neither/ >> and http://effbot.org/zone/call-by-object.htm >> > > > I would would agree with the description provided for the C++ example > provided > > string some_guy = "fred"; > ?is replaced by > char* some_guy="fred"; > > To see that this is correct, note the some_guy may subsequently be > assigned to a character string much longer then "fred".? An additional > note: A character string literal, like "cat", never occurs more than > once in compiled C++ program unit.? This also shows that the provided > description can't be completely correct. One last thing, > > string some_guy = "fred" > > is really the same thing as > > string some_guy("fred"); > > and both equivalently call the string constructor. > > The data type of "fred" is const char*, not (class) string. > I have no interest it what the C++ does, looks like or anything else. All I'm bothered about is that two highly respected members of the Python community have stated quite clearly that Python is call by object. Many other people have stated the same in this thread or previously, yet still people who know squat about Python continue to debate the subject. Why waste effort going over old ground? Is it completely impossible for people to step outside of their world of pass by value or pass by reference? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email has been checked for viruses by AVG. http://www.avg.com From gengyangcai at gmail.com Sat Sep 23 00:29:15 2017 From: gengyangcai at gmail.com (Cai Gengyang) Date: Fri, 22 Sep 2017 21:29:15 -0700 (PDT) Subject: Python Boolean Logic Message-ID: <7705816d-d60e-4c0a-9209-9f40f33c4dc4@googlegroups.com> Hey guys, I'm testing this on CodeAcademy, but I cant get the program to output a result even after pressing the run button. Just wanted to check if my logic is correct. Thanks alot # Assign True or False as appropriate on the lines below! # (20 - 10) > 15 bool_one = False # We did this one for you! # (10 + 17) == 3**16 # Remember that ** can be read as 'to the power of'. 3**16 is about 43 million. bool_two = False # 1**2 <= -1 bool_three = False # 40 * 4 >= -4 bool_four = True # 100 != 10**2 bool_five = False From steve.ferg.bitbucket at gmail.com Sat Sep 23 00:39:36 2017 From: steve.ferg.bitbucket at gmail.com (steve.ferg.bitbucket at gmail.com) Date: Fri, 22 Sep 2017 21:39:36 -0700 (PDT) Subject: Python Boolean Logic In-Reply-To: <7705816d-d60e-4c0a-9209-9f40f33c4dc4@googlegroups.com> References: <7705816d-d60e-4c0a-9209-9f40f33c4dc4@googlegroups.com> Message-ID: <174307cd-fd0a-4542-9e11-2c30a5d8f51c@googlegroups.com> You have a lot of assignment statements, but nothing that produces output. Try adding statements like this at appropriate places... print ("bool_one = ", bool_one) From gengyangcai at gmail.com Sat Sep 23 00:46:28 2017 From: gengyangcai at gmail.com (Cai Gengyang) Date: Fri, 22 Sep 2017 21:46:28 -0700 (PDT) Subject: Python Boolean Logic In-Reply-To: <174307cd-fd0a-4542-9e11-2c30a5d8f51c@googlegroups.com> References: <7705816d-d60e-4c0a-9209-9f40f33c4dc4@googlegroups.com> <174307cd-fd0a-4542-9e11-2c30a5d8f51c@googlegroups.com> Message-ID: Input : # Assign True or False as appropriate on the lines below! # (20 - 10) > 15 bool_one = False # We did this one for you! # (10 + 17) == 3**16 # Remember that ** can be read as 'to the power of'. 3**16 is about 43 million. bool_two = False # 1**2 <= -1 bool_three = False # 40 * 4 >= -4 bool_four = True # 100 != 10**2 bool_five = False print ("bool_one = ", bool_one) print ("bool_two = ", bool_two) print ("bool_three = ", bool_three) print ("bool_four = ", bool_four) print ("bool_five = ", bool_five) Output : ('bool_one = ', False) ('bool_two = ', False) ('bool_three = ', False) ('bool_four = ', True) ('bool_five = ', False) Is my logic / input / output correct ? Thanks a lot ... On Saturday, September 23, 2017 at 12:40:10 PM UTC+8, steve.ferg... at gmail.com wrote: > You have a lot of assignment statements, but nothing that produces output. Try adding statements like this at appropriate places... > > print ("bool_one = ", bool_one) From BILL_NOSPAM at whoknows.net Sat Sep 23 01:01:48 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Sat, 23 Sep 2017 01:01:48 -0400 Subject: Python Boolean Logic In-Reply-To: <7705816d-d60e-4c0a-9209-9f40f33c4dc4@googlegroups.com> References: <7705816d-d60e-4c0a-9209-9f40f33c4dc4@googlegroups.com> Message-ID: Cai Gengyang wrote: > Hey guys, I'm testing this on CodeAcademy, but I cant get the program to output a result even after pressing the run button. Just wanted to check if my logic is correct. Thanks alot Your answers appear correct, but you could write Python statements to test them (or any you encounter in the future). For instance, if (20 - 10) > 15 : print("true") else: print("false"); Or, s='(20 - 10) > 15' b=(20 - 10) > 15 print(s, " is ", ("true" if b else "false") ); ## inside parentheses may be removed. I am new to Python. Maybe someone here is familiar with an elegant way to get the the value of b directly from the string s? Hmm... It appears that eval() would work (see "Python: Essential Reference", p. 115). I just read about that for the first time last night! I may try that, for practice, after I post this. Bill > > # Assign True or False as appropriate on the lines below! > > # (20 - 10) > 15 > bool_one = False # We did this one for you! > > # (10 + 17) == 3**16 > # Remember that ** can be read as 'to the power of'. 3**16 is about 43 million. > bool_two = False > > # 1**2 <= -1 > bool_three = False > > # 40 * 4 >= -4 > bool_four = True > > # 100 != 10**2 > bool_five = False From rantingrickjohnson at gmail.com Sat Sep 23 01:06:56 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 22 Sep 2017 22:06:56 -0700 (PDT) Subject: Python Boolean Logic In-Reply-To: References: <7705816d-d60e-4c0a-9209-9f40f33c4dc4@googlegroups.com> <174307cd-fd0a-4542-9e11-2c30a5d8f51c@googlegroups.com> Message-ID: <181680e1-7375-4357-9c34-c5df6c407f82@googlegroups.com> On Friday, September 22, 2017 at 11:46:59 PM UTC-5, Cai Gengyang wrote: > Input : > > # Assign True or False as appropriate on the lines below! > > # (20 - 10) > 15 > bool_one = False # We did this one for you! > > # (10 + 17) == 3**16 > # Remember that ** can be read as 'to the power of'. 3**16 is about 43 million. > bool_two = False > > # 1**2 <= -1 > bool_three = False > > # 40 * 4 >= -4 > bool_four = True > > # 100 != 10**2 > bool_five = False > > print ("bool_one = ", bool_one) > print ("bool_two = ", bool_two) > print ("bool_three = ", bool_three) > print ("bool_four = ", bool_four) > print ("bool_five = ", bool_five) > > > Output : > > ('bool_one = ', False) > ('bool_two = ', False) > ('bool_three = ', False) > ('bool_four = ', True) > ('bool_five = ', False) > > > Is my logic / input / output correct ? Thanks a lot ... This looks like homework, and not a very well designed homework either. It seems the instructor wants you to provide the value of each "rich comparison expression" by assigning a boolean to an enumerated variable. As far as your "logic and IO being correct", i don't see a request for any of those things, based on what you provided here. If you want to check the expressions, just copy/paste them into a Python console. # Python2.x (with dependancy) >>> from sanity import * >>> if isbadidea('typehints'): ... print 'Duh!' ... else: ... print 'Duh!' Duh Yep. My sanity module could have saved the BDFL a lot of headaches. And possibly his cushy job at GooglePlex... From BILL_NOSPAM at whoknows.net Sat Sep 23 01:07:17 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Sat, 23 Sep 2017 01:07:17 -0400 Subject: Python Boolean Logic In-Reply-To: References: <7705816d-d60e-4c0a-9209-9f40f33c4dc4@googlegroups.com> Message-ID: Bill wrote: > Cai Gengyang wrote: >> Hey guys, I'm testing this on CodeAcademy, but I cant get the program >> to output a result even after pressing the run button. Just wanted to >> check if my logic is correct. Thanks alot > Your answers appear correct, but you could write Python statements to > test them (or any you encounter in the future). For instance, > > if (20 - 10) > 15 : > print("true") > else: > print("false"); > > Or, > > s='(20 - 10) > 15' > b=(20 - 10) > 15 > print(s, " is ", ("true" if b else "false") ); ## inside parentheses > may be removed. > > I am new to Python. Maybe someone here is familiar with an elegant > way to get the the value of b directly from the string s? Hmm... It > appears that eval() would work (see "Python: Essential Reference", p. > 115). I just read about that for the first time last night! I may try > that, for practice, after I post this. > Update: Yes, b=(20 - 10) > 15 may be replaced by eval(s). We can write: print(s, " is ", ("true" if eval(s) else "false") ) > >> >> # Assign True or False as appropriate on the lines below! >> >> # (20 - 10) > 15 >> bool_one = False # We did this one for you! >> >> # (10 + 17) == 3**16 >> # Remember that ** can be read as 'to the power of'. 3**16 is about >> 43 million. >> bool_two = False >> >> # 1**2 <= -1 >> bool_three = False >> >> # 40 * 4 >= -4 >> bool_four = True >> >> # 100 != 10**2 >> bool_five = False > From stephanh42 at gmail.com.invalid Sat Sep 23 01:39:59 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 23 Sep 2017 05:39:59 GMT Subject: Fw: Problems Installing Python36 References: <20170912.034647.1218.0@webmail04.vgs.untd.com> <6278c207-2744-5603-b983-6d73c451714f@tjol.eu> <2e23c425-0ddf-8cc7-25ac-20f4568941c9@gmail.com> <59c2a3bc$0$792$e4fe514c@news.xs4all.nl> <59c59e41$0$806$e4fe514c@news.xs4all.nl> Message-ID: Op 2017-09-22, Irmen de Jong schreef : > On 09/22/2017 08:34 PM, Stephan Houben wrote: > >> I was vaguely tempted to offer the Mingw-w64 (GCC) Python as an >> alternative, since it doesn't rely on any optionally-installed Microsoft >> DLLs and so avoids this issue. But I suppose that is not really the >> newbie-friendly solution the OP was looking for... > > Mingw? Perhaps better to choose Anaconda/Miniconda instead if you go for > an alternative implementation... Anaconda is still based on MSVC and so still relies on the MSVC C library. If installing the MSVC C linrary is the problem, then I don't think Anaconda solves that. Stephan From steve+python at pearwood.info Sat Sep 23 01:47:13 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 23 Sep 2017 15:47:13 +1000 Subject: Python Boolean Logic References: <7705816d-d60e-4c0a-9209-9f40f33c4dc4@googlegroups.com> Message-ID: <59c5f563$0$14959$b1db1813$d948b532@news.astraweb.com> On Sat, 23 Sep 2017 03:01 pm, Bill wrote: > s='(20 - 10) > 15' > b=(20 - 10) > 15 > print(s, " is ", ("true" if b else "false") ); ## inside parentheses > may be removed. > > I am new to Python. Maybe someone here is familiar with an elegant way > to get the the value of b directly from the string s? Hmm... It appears > that eval() would work Indeed it will, but don't get into the habit of using eval willy-nilly. While it is absolutely fine to use it with data you provide yourself, it is a HUGE security risk to eval strings that came from an untrusted user. eval("__import__('os').system('echo """rm-rf /"""')") Also, for what its worth, it's about ten times slower to run: eval('(20 - 10) > 15') than to simply run (20 - 10) > 15 -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From stephanh42 at gmail.com.invalid Sat Sep 23 01:56:22 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 23 Sep 2017 05:56:22 GMT Subject: How to share class relationship representations? References: Message-ID: Op 2017-09-22, Pavol Lisy schreef : > On 9/19/17, leam hall wrote: >> I'm working on designing the classes, sub-classes, and relationships in my >> code. What is a good visual way to represent it so it can be stored in git >> and shared on the list without large images or attachments? >> >> Thanks! >> >> Leam > > https://stackoverflow.com/questions/29586520/can-one-get-hierarchical-graphs-from-networkx-with-python-3#29597209 For direct inclusion in source code, what about plain text with Unicode box drawing characters? ???????? ?object? ???????? ? ??????? ?float? ??????? Stephan From BILL_NOSPAM at whoknows.net Sat Sep 23 03:08:45 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Sat, 23 Sep 2017 03:08:45 -0400 Subject: Python Boolean Logic In-Reply-To: <59c5f563$0$14959$b1db1813$d948b532@news.astraweb.com> References: <7705816d-d60e-4c0a-9209-9f40f33c4dc4@googlegroups.com> <59c5f563$0$14959$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > On Sat, 23 Sep 2017 03:01 pm, Bill wrote: > >> s='(20 - 10) > 15' >> b=(20 - 10) > 15 >> print(s, " is ", ("true" if b else "false") ); ## inside parentheses >> may be removed. >> >> I am new to Python. Maybe someone here is familiar with an elegant way >> to get the the value of b directly from the string s? Hmm... It appears >> that eval() would work > > Indeed it will, but don't get into the habit of using eval willy-nilly. While it > is absolutely fine to use it with data you provide yourself, it is a HUGE > security risk to eval strings that came from an untrusted user. > > > eval("__import__('os').system('echo """rm-rf /"""')") Thank you. Studying that was a nice little lesson in itself! I recognize that this technique can be used for 'good' as well as 'evil'! : ) Bill From __peter__ at web.de Sat Sep 23 03:26:25 2017 From: __peter__ at web.de (Peter Otten) Date: Sat, 23 Sep 2017 09:26:25 +0200 Subject: search and replace first amount of strings instances with one thing and a second amount of instances with another thing- References: <71202558-f2cc-4557-8f82-383c5312abdf@googlegroups.com> Message-ID: validationmail1 at gmail.com wrote: > i have a code in python to search and replace what i need though is to > replace the first say 10 instances of the number 1 with 2 and the second > 10 instances with the number 3. anybody knows how to do that? > > fin = open(r'F:\1\xxx.txt') > fout = open(r'F:\1\xxx2.txt', "wt") > for line in fin: > fout.write( line.replace('1', '2') ) > fin.close() > fout.close() If the search token can occur more than once in a line you cannot use str.replace(). Here's a solution without regular expressions. I implemented the "repeat something" and the "replace token with something different every time" separately. $ cat replace_increasing.py #!/usr/bin/env python3 from itertools import chain, count, repeat def repeater(values, repeatcount): """ >>> list(repeater("abc", 3)) ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c'] >>> list(repeater(range(3), 2)) [0, 0, 1, 1, 2, 2] """ return chain.from_iterable(repeat(value, repeatcount) for value in values) def _ran_out_of_values(): if 0: yield raise ValueError("ran out of values") class Replace: """ >>> r = Replace("x", "ABCDEFGH") >>> r("onextwoxthreex") 'oneAtwoBthreeC' >>> r("no match") 'no match' >>> r("x at start") 'D at start' >>> r("somexsomewhere") 'someEsomewhere' >>> r("xxx") 'FGH' >>> try: r("x") ... except ValueError as err: print(err) ran out of values """ def __init__(self, token, replace): self.token = token self.replaceiter = chain(replace, _ran_out_of_values()) def __call__(self, line): parts = line.split(self.token) return "".join( chain( (p + q for p, q in zip(parts[:-1], self.replaceiter)), parts[-1:] ) ) def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument("infile") parser.add_argument("outfile") parser.add_argument("token") parser.add_argument("-r", "--repeat", type=int, default=10) args = parser.parse_args() numberstrings = map(str, count(1)) replace = Replace(args.token, repeater(numberstrings, args.repeat)) with open(args.infile) as instream: with open(args.outfile, "w") as outstream: outstream.writelines(map(replace, instream)) if __name__ == "__main__": main() As an example let's replace the 'a's in the script above with numbers, repeated three times: $ ./replace_increasing.py replace_increasing.py tmp.py a -r3 $ head tmp.py #!/usr/bin/env python3 from itertools import ch1in, count, repe1t def repe1ter(v2lues, repe2tcount): """ >>> list(repe2ter("3bc", 3)) ['3', '3', '4', 'b', 'b', 'b', 'c', 'c', 'c'] >>> list(repe4ter(r4nge(3), 2)) [0, 0, 1, 1, 2, 2] """ return ch5in.from_iter5ble(repe5t(v6lue, repe6tcount) for v6lue in v7lues) def _r7n_out_of_v7lues(): if 0: yield r8ise V8lueError("r8n out of v9lues") $ From BILL_NOSPAM at whoknows.net Sat Sep 23 03:48:56 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Sat, 23 Sep 2017 03:48:56 -0400 Subject: search and replace first amount of strings instances with one thing and a second amount of instances with another thing- In-Reply-To: <71202558-f2cc-4557-8f82-383c5312abdf@googlegroups.com> References: <71202558-f2cc-4557-8f82-383c5312abdf@googlegroups.com> Message-ID: validationmail1 at gmail.com wrote: > i have a code in python to search and replace what i need though is to replace the first say 10 instances of the number 1 with 2 and the second 10 instances with the number 3. anybody knows how to do that? Do you mean the (integer) number 1 or the character '1'? For instance, if the first line of the file is: "There were 100 cats in the yard." Do you want to change this to "There were 200 cats in the yard."? Remember that string objects are "immutable" so your code probably wouldn't work exactly like that. > > fin = open(r'F:\1\xxx.txt') > fout = open(r'F:\1\xxx2.txt', "wt") > for line in fin: > fout.write( line.replace('1', '2') ) > fin.close() > fout.close() From __peter__ at web.de Sat Sep 23 03:56:58 2017 From: __peter__ at web.de (Peter Otten) Date: Sat, 23 Sep 2017 09:56:58 +0200 Subject: search and replace first amount of strings instances with one thing and a second amount of instances with another thing- References: <71202558-f2cc-4557-8f82-383c5312abdf@googlegroups.com> Message-ID: Peter Otten wrote: > validationmail1 at gmail.com wrote: > >> i have a code in python to search and replace what i need though is to >> replace the first say 10 instances of the number 1 with 2 and the second >> 10 instances with the number 3. anybody knows how to do that? >> >> fin = open(r'F:\1\xxx.txt') >> fout = open(r'F:\1\xxx2.txt', "wt") >> for line in fin: >> fout.write( line.replace('1', '2') ) >> fin.close() >> fout.close() > > If the search token can occur more than once in a line you cannot use > str.replace(). Here's a solution without regular expressions. I > implemented the "repeat something" and the "replace token with something > different every time" separately. > > $ cat replace_increasing.py > #!/usr/bin/env python3 Should also work with python2 once you add try: from future_builtins import zip, map except ImportError: pass to make map() lazy. > from itertools import chain, count, repeat Lest you die of an itertools overdose here's a slightly simpler version: #!/usr/bin/env python3 def numberstrings(repeat, start=1): """ >>> [v for i, v in zip(range(10), numberstrings(3, 1))] ['1', '1', '1', '2', '2', '2', '3', '3', '3', '4'] """ value = start while True: for _i in range(repeat): yield str(value) value += 1 def make_replace(token, replace): """ >>> r = make_replace("x", "ABCDEFGH") >>> r("onextwoxthreex") 'oneAtwoBthreeC' >>> r("no match") 'no match' >>> r("x at start") 'D at start' >>> r("somexsomewhere") 'someEsomewhere' >>> r("xxx") 'FGH' >>> try: r("x") ... except StopIteration: "OK" 'OK' """ replaceiter = iter(replace) def replace(line): parts = line.split(token) return "".join( [p + next(replaceiter) for p in parts[:-1]] + parts[-1:] ) return replace def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument("infile") parser.add_argument("outfile") parser.add_argument("token") parser.add_argument("-r", "--repeat", type=int, default=10) args = parser.parse_args() replace = make_replace(args.token, numberstrings(args.repeat)) with open(args.infile) as instream: with open(args.outfile, "w") as outstream: outstream.writelines(replace(line) for line in instream) if __name__ == "__main__": main() From kwpolska at gmail.com Sat Sep 23 04:41:12 2017 From: kwpolska at gmail.com (Chris Warrick) Date: Sat, 23 Sep 2017 10:41:12 +0200 Subject: Python Boolean Logic In-Reply-To: References: <7705816d-d60e-4c0a-9209-9f40f33c4dc4@googlegroups.com> <174307cd-fd0a-4542-9e11-2c30a5d8f51c@googlegroups.com> Message-ID: On 23 September 2017 at 06:46, Cai Gengyang wrote: > Output : > > ('bool_one = ', False) > ('bool_two = ', False) > ('bool_three = ', False) > ('bool_four = ', True) > ('bool_five = ', False) You?re using Python 2 with Python 3-style print statements. To make it look good, start your code with: from __future__ import print_function Or use the Python 2 form (without parentheses), or even better: switch to Python 3. Now, Codecademy is a peculiar place. They still teach Python 2 (that sucks!) and have a specific teaching style. The way you?re supposed to solve this is to just assign your answers to bool_one through bool_five. You should just type True or False in each blank, using Python to evaluate this expression is kinda cheating. Codecademy will then tell you if you got the right answer. Don?t print stuff you aren?t asked to print. However, you should not depend only on Codecademy?s interpreter. Install Python on your computer and work with that. I also recommend learning using different resources, and learning Python 3. It?s the future. ~~~ On 23 September 2017 at 07:01, Bill wrote: > Your answers appear correct, but you could write Python statements to test > them (or any you encounter in the future). For instance, > > if (20 - 10) > 15 : > print("true") > else: > print("false"); > > Or, > > s='(20 - 10) > 15' > b=(20 - 10) > 15 > print(s, " is ", ("true" if b else "false") ); ## inside parentheses may be > removed. This outputs "False is false", because you used the variable in your expression. You can just do this: >>> print("s is", s) This will print "s is False". You can also replace your earlier `if` with: >>> print((20 - 10) > 15) (False will appear upper-case, of course.) PS. don?t use semicolons with Python. Avoid eval() as well. -- Chris Warrick PGP: 5EAAEA16 From BILL_NOSPAM at whoknows.net Sat Sep 23 04:51:25 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Sat, 23 Sep 2017 04:51:25 -0400 Subject: search and replace first amount of strings instances with one thing and a second amount of instances with another thing- In-Reply-To: References: <71202558-f2cc-4557-8f82-383c5312abdf@googlegroups.com> Message-ID: Bill wrote: > validationmail1 at gmail.com wrote: >> i have a code in python to search and replace what i need though is >> to replace the first say 10 instances of the number 1 with 2 and the >> second 10 instances with the number 3. anybody knows how to do that? > Do you mean the (integer) number 1 or the character '1'? For instance, > if the first line of the file is: > "There were 100 cats in the yard." > Do you want to change this to > "There were 200 cats in the yard."? > Remember that string objects are "immutable" so your code probably > wouldn't work exactly like that. I now realize that my last line does not apply. I suggest you start by just thinking about changing the first ten ones to twos. Once you do that, you should have little trouble finishing the job. Being a Python newbie myself, your example helped motivate me to try my own example. I used "type" to learn the data type of line (in your example), about which I was curious. My first concern was that is might only be "interable" object, but I learned that more is true. > > >> >> fin = open(r'F:\1\xxx.txt') >> fout = open(r'F:\1\xxx2.txt', "wt") >> for line in fin: >> fout.write( line.replace('1', '2') ) >> fin.close() >> fout.close() > From BILL_NOSPAM at whoknows.net Sat Sep 23 05:02:13 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Sat, 23 Sep 2017 05:02:13 -0400 Subject: Python Boolean Logic In-Reply-To: References: <7705816d-d60e-4c0a-9209-9f40f33c4dc4@googlegroups.com> <174307cd-fd0a-4542-9e11-2c30a5d8f51c@googlegroups.com> Message-ID: Chris Warrick wrote: > > This outputs "False is false", because you used the variable in your > expression. You can just do this: > >>>> print("s is", s) > This will print "s is False". > Ah, good point! But I do like "self-documenting" output (so I don't mind seeing s)---if you had 5 or more statements a in a row like that, you would "miss" seeing the string s! : ) Bill From kryptxy at protonmail.com Sat Sep 23 05:07:08 2017 From: kryptxy at protonmail.com (Kryptxy) Date: Sat, 23 Sep 2017 05:07:08 -0400 Subject: Change project licence? In-Reply-To: References: <85377o7r2h.fsf@benfinney.id.au> Message-ID: <14zQlz1SK1NTt1HIvR3Sulx3cezj97bl-sNUxZCLdYgBJg2NdoaCoqiQlhkIS0S7jN9h57CEdTVVrCwe7FAmmxmLLMegG92tgFDMQM7RsuQ=@protonmail.com> Thank you all! I opened a ticket about the same (on github). I got response from most of them, and all are agreeing to the change. However, one contributor did not respond at all. I tried e-mailing, but no response. Can I still proceed changing the licence? It has been more than a week since the ticket was opened. Sent with [ProtonMail](https://protonmail.com) Secure Email. > -------- Original Message -------- > Subject: Re: Change project licence? > Local Time: 15 September 2017 5:54 AM > UTC Time: 15 September 2017 00:24 > From: rosuav at gmail.com > To: python-list at python.org > > On Fri, Sep 15, 2017 at 10:17 AM, Ben Finney wrote: >>> I know how to change the licence, but I want to know is it fine and >>> wise to change the licence at this point? (The project already has 19 >>> clones, 250+ GitHub stars. Here: https://github.com/kryptxy/torrench) >> >> Those represent a whole lot of recipients, who received GPLv3-or-later >> license grant, guaranteeing the freedom of the work for all recipients >> in all modified forms. I would consider it poor form to allow non-free >> redistribution at this point. > > Those recipients can still do everything they previously could, > *including redistributing the code under the GPLv3*. They have lost > nothing. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sat Sep 23 05:14:44 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 23 Sep 2017 19:14:44 +1000 Subject: Change project licence? In-Reply-To: <14zQlz1SK1NTt1HIvR3Sulx3cezj97bl-sNUxZCLdYgBJg2NdoaCoqiQlhkIS0S7jN9h57CEdTVVrCwe7FAmmxmLLMegG92tgFDMQM7RsuQ=@protonmail.com> References: <85377o7r2h.fsf@benfinney.id.au> <14zQlz1SK1NTt1HIvR3Sulx3cezj97bl-sNUxZCLdYgBJg2NdoaCoqiQlhkIS0S7jN9h57CEdTVVrCwe7FAmmxmLLMegG92tgFDMQM7RsuQ=@protonmail.com> Message-ID: On Sat, Sep 23, 2017 at 7:07 PM, Kryptxy wrote: > Thank you all! I opened a ticket about the same (on github). > I got response from most of them, and all are agreeing to the change. > However, one contributor did not respond at all. I tried e-mailing, but no > response. > Can I still proceed changing the licence? It has been more than a week since > the ticket was opened. Nope. Contributions made under the GPL have a guarantee that they will only and forever be used in open source projects. You're trying to weaken that guarantee, so you have to get clear permission from everyone involved. Unless you can show that the contributions in question are so trivial that there's no code that can be pinpointed as that person's, or you replace all that person's code, you can't proceed to relicense it without permission. ChrisA From leamhall at gmail.com Sat Sep 23 05:44:32 2017 From: leamhall at gmail.com (Leam Hall) Date: Sat, 23 Sep 2017 05:44:32 -0400 Subject: Change project licence? In-Reply-To: References: <85377o7r2h.fsf@benfinney.id.au> <14zQlz1SK1NTt1HIvR3Sulx3cezj97bl-sNUxZCLdYgBJg2NdoaCoqiQlhkIS0S7jN9h57CEdTVVrCwe7FAmmxmLLMegG92tgFDMQM7RsuQ=@protonmail.com> Message-ID: On 09/23/2017 05:14 AM, Chris Angelico wrote: > On Sat, Sep 23, 2017 at 7:07 PM, Kryptxy wrote: >> Thank you all! I opened a ticket about the same (on github). >> I got response from most of them, and all are agreeing to the change. >> However, one contributor did not respond at all. I tried e-mailing, but no >> response. >> Can I still proceed changing the licence? It has been more than a week since >> the ticket was opened. > > Nope. Contributions made under the GPL have a guarantee that they will > only and forever be used in open source projects. You're trying to > weaken that guarantee, so you have to get clear permission from > everyone involved. > > Unless you can show that the contributions in question are so trivial > that there's no code that can be pinpointed as that person's, or you > replace all that person's code, you can't proceed to relicense it > without permission. I'm with Chris on this one. You made a social, and in many places legally binding, agreement. Can't change it without everyone's agreement. Like Chris said, evaluate the level of effort on the code. Wait, or replace. You will be happier when you take the honorable path. Leam From rosuav at gmail.com Sat Sep 23 07:27:22 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 23 Sep 2017 21:27:22 +1000 Subject: Change project licence? In-Reply-To: References: <85377o7r2h.fsf@benfinney.id.au> <14zQlz1SK1NTt1HIvR3Sulx3cezj97bl-sNUxZCLdYgBJg2NdoaCoqiQlhkIS0S7jN9h57CEdTVVrCwe7FAmmxmLLMegG92tgFDMQM7RsuQ=@protonmail.com> Message-ID: On Sat, Sep 23, 2017 at 7:44 PM, Leam Hall wrote: > Like Chris said, evaluate the level of effort on the code. Wait, or replace. > You will be happier when you take the honorable path. Remembering that that, of course, is Plan B; plan A is to keep trying to contact that last contributor.. S/he hasn't refused, so there's still every possibility of getting that last okay. ChrisA From steve+python at pearwood.info Sat Sep 23 07:28:24 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 23 Sep 2017 21:28:24 +1000 Subject: Python Boolean Logic References: <7705816d-d60e-4c0a-9209-9f40f33c4dc4@googlegroups.com> Message-ID: <59c6455a$0$14941$b1db1813$d948b532@news.astraweb.com> On Sat, 23 Sep 2017 03:01 pm, Bill wrote: > if (20 - 10) > 15 : > print("true") > else: > print("false"); print(20 - 10 > 15) will do the job. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From kryptxy at protonmail.com Sat Sep 23 07:34:44 2017 From: kryptxy at protonmail.com (Kryptxy) Date: Sat, 23 Sep 2017 07:34:44 -0400 Subject: Change project licence? In-Reply-To: References: <85377o7r2h.fsf@benfinney.id.au> <14zQlz1SK1NTt1HIvR3Sulx3cezj97bl-sNUxZCLdYgBJg2NdoaCoqiQlhkIS0S7jN9h57CEdTVVrCwe7FAmmxmLLMegG92tgFDMQM7RsuQ=@protonmail.com> Message-ID: Yep. I will wait for a response. Thank you! -------- Original Message -------- On 23 Sep 2017, 16:57, Chris Angelico wrote: > On Sat, Sep 23, 2017 at 7:44 PM, Leam Hall wrote: >> Like Chris said, evaluate the level of effort on the code. Wait, or replace. >> You will be happier when you take the honorable path. > > Remembering that that, of course, is Plan B; plan A is to keep trying > to contact that last contributor.. S/he hasn't refused, so there's > still every possibility of getting that last okay. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list @gmail.com> From steve+python at pearwood.info Sat Sep 23 07:37:44 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 23 Sep 2017 21:37:44 +1000 Subject: Old Man Yells At Cloud References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <44325551-f77c-0c82-0800-5acae4ab3dd8@kynesim.co.uk> <59c3d6cb$0$14939$b1db1813$d948b532@news.astraweb.com> <6c6c1786-49aa-4fe7-b284-a18fadcda4d7@googlegroups.com> <59c48f48$0$14945$b1db1813$d948b532@news.astraweb.com> <87efqzfeu7.fsf@nightsong.com> Message-ID: <59c6478b$0$14942$b1db1813$d948b532@news.astraweb.com> On Fri, 22 Sep 2017 04:05 pm, Paul Rubin wrote: > Steve D'Aprano writes: >> Having to spend a few hours being paid to migrate code using "print x" >> to "print(x)", or even a few months, is not a life-changing experience. > > Didn't someone further up the thread mention some company that had spent > 1.5 years porting a py2 codebase to py3? Its possible, but if so I missed it. And did I mention one of the coders at the company I work, who decided to port our Python 2 code base to Python 3? He stayed behind one night after hours and did it in three hours. We've been talking about it for about two years. What are we to make of anecdotes like these? Apart from the possibility that one, or the other, or both, is an exaggeration or lie[1]? - perhaps one code base is bigger than the other; - perhaps one is an unspeakable mess, and the other is nice clean code; - perhaps one has masses of unit tests while the other barely even works; - perhaps one company has good coders and the other has terrible coders; - perhaps it was 1.5 years elapsed time, ten days effort (I've worked with people like that). Who can say? 95% of Python is unchanged from Python 2 to 3. 95% of the remaining is a trivial renaming or other change which can be mechanically translated using a tool like 2to3. Only the remaining 5% of 5% is actually tricky to migrate. If your code base is full of things relying on that 5% of 5%, then you'll struggle. Otherwise, is probably much easier than people expect. [1] I admit it: mine was an exaggeration. It actually took him four hours. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From vek.m1234 at gmail.com Sat Sep 23 07:38:45 2017 From: vek.m1234 at gmail.com (Veek M) Date: Sat, 23 Sep 2017 04:38:45 -0700 (PDT) Subject: PyQt: viewport vs window - how do you translate co-ordinates? Message-ID: <102146f3-48fa-492b-9a3f-5c91741afdcf@googlegroups.com> pg 329, Rapid GUI Programming -------------------- http://storage4.static.itmages.com/i/17/0923/h_1506165624_2588733_59fdfcd4cc.png In PyQt terminology the physical coordinate system is called the ?viewport?, and confusingly, the logical coordinate system is called the ?window?. In Figure 11.4, we have a physical widget size of 800 ? 600. By calling setWin- dow(-60, -60, 120, 120) we can create a ?window? with a top-left coordinate of (-60, -60), a width of 120, a height of 120, and centered at point (0, 0). The window?s coordinate system is a logical coordinate system that QPainter auto- matically maps to the underlying physical device. After the setWindow() call, all our painting takes place using the logical (window) coordinate system. In this case, the widget is rectangular, but our window has the same width and height. This means that the items we paint will be stretched out horizontally, since coordinates in the y-axis will be scaled by QPainter in the ratio 120:600 (1:5), whereas those in the x-axis will be scaled in the ratio 120:800 (1:6 2 3 ). ------------------------ 1. The physical (coordinate system) widget size is 800x600 = Viewport 2. Logical Coordinates = Window When he does setWindow(-60, -60, 120, 120) he's moving along a diagonal from top-left to bottom-right. From that point he's then drawing a 120x120 rectangle. A. So how does he get a (150,200) point and a -37.5 point??? B. Also, how is it stretched horizontally? If i use the inner 120x120 as a frame of reference and draw a circle - it'll still be a circle??? Just draw a square on a blackboard.. and then draw a circle in it.. I didn't understand any of that - could someone expand on that para? C. Why does QPainter have to scale in a different ratio?? QPainter understands two coordinate systems - physical and logical and by default the two systems match each other. Is there a reading resource that explains the Viewport and translations? I am not a CS student so I did not study computer graphics. (sorry for using google groups but my knode is broken and pan is horrible on olvwm - my plan is to write myself a News client in PyQt :)) From p.f.moore at gmail.com Sat Sep 23 09:52:10 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Sat, 23 Sep 2017 14:52:10 +0100 Subject: Old Man Yells At Cloud In-Reply-To: <59c6478b$0$14942$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <44325551-f77c-0c82-0800-5acae4ab3dd8@kynesim.co.uk> <59c3d6cb$0$14939$b1db1813$d948b532@news.astraweb.com> <6c6c1786-49aa-4fe7-b284-a18fadcda4d7@googlegroups.com> <59c48f48$0$14945$b1db1813$d948b532@news.astraweb.com> <87efqzfeu7.fsf@nightsong.com> <59c6478b$0$14942$b1db1813$d948b532@news.astraweb.com> Message-ID: On 23 September 2017 at 12:37, Steve D'Aprano wrote: > 95% of Python is unchanged from Python 2 to 3. 95% of the remaining is a trivial > renaming or other change which can be mechanically translated using a tool like > 2to3. Only the remaining 5% of 5% is actually tricky to migrate. If your code > base is full of things relying on that 5% of 5%, then you'll struggle. > Otherwise, is probably much easier than people expect. And in my experience, one of the worst difficulties is the transition to "clean" Unicode handling. I've seen many Python 2 codebases that mostly-work, either by assuming often-but-not-always-true things like "Everyone uses UTF-8", or "subprocesses always use the same encoding as my code" and then introduce "fixes" by tactical re-encoding rather than redesigning the code to "decode at the boundaries" - because it's quicker to do so, and everyone has deadlines. In those cases, the Python 3 transition can be hard, not because there's a lot of complexity to writing Python 3 compatible code, but because Python 3 has a stricter separation between bytes and (Unicode) strings, and doesn't support sloppy practices that Python 2 lets you get away with. You *can* write Unicode-clean code in Python 2 (and then the transition is easy) but many people don't, and that's when things get difficult. The worst cases here are people who know how to write good Unicode-safe code, and do so in Python 2, but using a different approach than the one Python 3 takes. Those people put effort into writing correct code, and then have to change that, *just* for the transition - they don't get the correctness benefit that others do. (I should also point out that writing Unicode-safe code is hard, from a *design* perspective, because an awful lot of data comes to you without a known encoding - text files, for example, or the output of a subprocess. Sometimes you *have* to guess, or make assumptions, and Python 3 tends to force you to make those assumptions explicit. Ironically, it's often the better coders that find this hard, as they are the ones who worry about error handling, or configuration options, rather than just picking a value and moving on). Paul From torriem at gmail.com Sat Sep 23 11:05:10 2017 From: torriem at gmail.com (Michael Torrie) Date: Sat, 23 Sep 2017 09:05:10 -0600 Subject: PyQt: viewport vs window - how do you translate co-ordinates? In-Reply-To: <102146f3-48fa-492b-9a3f-5c91741afdcf@googlegroups.com> References: <102146f3-48fa-492b-9a3f-5c91741afdcf@googlegroups.com> Message-ID: <6629f3c6-ef04-11ae-8bb4-33f25f17c85f@gmail.com> On 09/23/2017 05:38 AM, Veek M wrote: > I didn't understand any of that - could someone expand on that para? > Is there a reading resource that explains the Viewport and translations? I am not a CS student so I did not study computer graphics. I'm sure there are lots of things that might help. This is primarily about OpenGL but the principles may apply: https://www.cs.mtsu.edu/~jhankins/files/4250/notes/WinToView/WinToViewMap.html Alternatively, you can think it through. Imagine you're laying out a fence around your house. You could use global coordinates for everything, or you could just call the exact center of your yard 0,0 and measure everything from there, in whatever units you wish. That's the idea here. Rather than referring to pixels by their screen coordinates (which can change if it moves around the screen), you refer to them by an arbitrary coordinate system with it's own scaling relative to the screen region. You could have a screen region that is 100 px by 100 px, and the you designate that the upper left corner of that region is -500,500 and the lower right corner is 500,-500. Or it could be something like -500,200 to 500,-200, which would make things stretched out in the x axis compared to the y axis. > (sorry for using google groups but my knode is broken and pan is horrible on olvwm - my plan is to write myself a News client in PyQt :)) I don't think you need to know that much about graphics coordinate systems to get started with Qt. Most GUI layout stuff does not depend on pixels or coordinates. From torriem at gmail.com Sat Sep 23 11:09:40 2017 From: torriem at gmail.com (Michael Torrie) Date: Sat, 23 Sep 2017 09:09:40 -0600 Subject: Change project licence? In-Reply-To: <14zQlz1SK1NTt1HIvR3Sulx3cezj97bl-sNUxZCLdYgBJg2NdoaCoqiQlhkIS0S7jN9h57CEdTVVrCwe7FAmmxmLLMegG92tgFDMQM7RsuQ=@protonmail.com> References: <85377o7r2h.fsf@benfinney.id.au> <14zQlz1SK1NTt1HIvR3Sulx3cezj97bl-sNUxZCLdYgBJg2NdoaCoqiQlhkIS0S7jN9h57CEdTVVrCwe7FAmmxmLLMegG92tgFDMQM7RsuQ=@protonmail.com> Message-ID: On 09/23/2017 03:07 AM, Kryptxy via Python-list wrote: > Thank you all! I opened a ticket about the same (on github). > I got response from most of them, and all are agreeing to the change. > However, one contributor did not respond at all. I tried e-mailing, but no response. > Can I still proceed changing the licence? It has been more than a week since the ticket was opened. If you remove the contributor's contributions from your project, then you can proceed without his permission. Otherwise, Chris and Leam are correct. You could replace all the contributor's code with your own code. This is a bit tricky as you've seen the contributor's code. One way around this is to tell someone what the contributor's patch did, and have them recreate it, without looking at that person's patch. From rantingrickjohnson at gmail.com Sat Sep 23 11:31:07 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 23 Sep 2017 08:31:07 -0700 (PDT) Subject: Old Man Yells At Cloud In-Reply-To: <59c6478b$0$14942$b1db1813$d948b532@news.astraweb.com> References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <049f4dc4-0b3c-45ea-91d9-9c28bbf29fa6@googlegroups.com> <59be89d0$0$14947$b1db1813$d948b532@news.astraweb.com> <20170917130923.35b535e9@bigbox.christie.dr> <59bec3c3$0$14931$b1db1813$d948b532@news.astraweb.com> <59c14634$0$14939$b1db1813$d948b532@news.astraweb.com> <44325551-f77c-0c82-0800-5acae4ab3dd8@kynesim.co.uk> <59c3d6cb$0$14939$b1db1813$d948b532@news.astraweb.com> <6c6c1786-49aa-4fe7-b284-a18fadcda4d7@googlegroups.com> <59c48f48$0$14945$b1db1813$d948b532@news.astraweb.com> <87efqzfeu7.fsf@nightsong.com> <59c6478b$0$14942$b1db1813$d948b532@news.astraweb.com> Message-ID: <746d5122-d8e1-450f-b876-fa7979daa68d@googlegroups.com> Steve D'Aprano wrote: > Paul Rubin wrote: > > Steve D'Aprano writes: > > > Having to spend a few hours being paid to migrate code > > > using "print x" to "print(x)", or even a few months, is > > > not a life-changing experience. > > > > Didn't someone further up the thread mention some company > > that had spent 1.5 years porting a py2 codebase to py3? > > Its possible, but if so I missed it. And did I mention one > of the coders at the company I work, who decided to port > our Python 2 code base to Python 3? He stayed behind one > night after hours and did it in three hours. We've been > talking about it for about two years. What are we to make > of anecdotes like these? Apart from the possibility that > one, or the other, or both, is an exaggeration or lie[1]? Your personal experience at one (small) company is hardly relevant. And do you really expect this fine community to belief, that Steven D'Aprano, yes, the man who's had a hard-on for Python3 long before it was ever publically released, has not been writing Python2.x code using backported future feature for years? So why should this fine community be surprised that your migration took roughly the same amount of time that it took for Gilligan and his cohorts to be stranded on an island? Just sit right back and you'll hear a tale a tale of a some fateful "schmit", that began with feature request, one that floated his tiny ship. The code monkey was a mighty patchin' man, the BDFL brave and sure, a handful of sycophants set sail that day, for a three hour tour, a three hour tour... The patching started getting rough, and compatibility would be lost. And if not for the courage of the fearless crew the erection would be lost. The erection would be lost... So this is the tale of our castaways, here for a long long time. They'll have to make the best of things, as evangelism is an uphill climb. :-( The first mate and his Skipper too, will do their very best, to make the others comf'terble, in their Python-ideas-island nest. No print statement, no rights, no tolerance, not a single luxury, like a north korean prison state it's as tyrannical as can be. So join us here each week my friends, you're sure to get a smile, from all the perverted castaways here on Python3's fantasy Isle! From k.d.jantzen at mailbox.org Sat Sep 23 13:18:58 2017 From: k.d.jantzen at mailbox.org (Klaus Jantzen) Date: Sat, 23 Sep 2017 19:18:58 +0200 Subject: Py 3.6 tarfile Message-ID: <1b56ac89-2bf1-1edd-c438-9b52d868aa29@mailbox.org> Hi, if I understand the documentation of the tarfile module correctly writing TarfileObject.add(".../path/to/filename", recursive=False) means that the directory structure of the file object will not be included in the archive. In the following script only "testtext1.pdf" is stored outside a directory structure. The other files are always stored in a directory structure; using recursive=False does not have any effect. ============ #!/usr/bin/env python3 # import argparse import sys import tarfile import os arch = "Archive.tgz" os.unlink(arch) try: TO = tarfile.open(name=arch, mode='x:gz') # Tarfile object TO.add("testtext1.pdf") TO.add("./testtext2.pdf") TO.add("./testtext3.pdf", recursive=False) TO.add("./files/testtext4.pdf") TO.add("./files/testtext5.pdf", recursive=False) TO.close() except FileExistsError as err: pass ========= Is my understanding correct or what do have to do so that the files are stored without any directory information? Thanks for any hints. -- K.D.J. From rantingrickjohnson at gmail.com Sat Sep 23 13:33:47 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 23 Sep 2017 10:33:47 -0700 (PDT) Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: Mark Lawrence wrote: > [...] > I have no interest it what the C++ does, looks like or > anything else. All I'm bothered about is that two highly > respected members of the Python community have stated quite > clearly that Python is call by object. Many other people > have stated the same in this thread or previously, yet > still people who know squat about Python continue to debate > the subject. Why waste effort going over old ground? Is > it completely impossible for people to step outside of > their world of pass by value or pass by reference? This is one of those rare times when i agree with Mark (and excuse me for a sec whilst i pinch myself...). These pissing contests over how values are passed in Python are totally irrelevant. What does it matter? Nothing will be gained or lost by arguing over which is true, or not. Unless the distinction is preventing you from doing something that you'd like to do, or unless you want to argue that one "value passing method" would bring X, Y or Z benefits over the other, what does it matter? It's like arguing that red lights should be green and green lights should be red. What are the pros and cons of such change? IOW, the argument lacks _substance_. If you're going to argue. At least do it correctly. And try to make the battle at least _slightly_ entertaining. Folks, there is reason why flag football never became as popular as its full-contact sister. From tjreedy at udel.edu Sat Sep 23 14:40:50 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 23 Sep 2017 14:40:50 -0400 Subject: Beginners and experts (Batchelder blog post) Message-ID: https://nedbatchelder.com//blog/201709/beginners_and_experts.html Great post. -- Terry Jan Reedy From leamhall at gmail.com Sat Sep 23 14:52:16 2017 From: leamhall at gmail.com (Leam Hall) Date: Sat, 23 Sep 2017 14:52:16 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: Message-ID: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> On 09/23/2017 02:40 PM, Terry Reedy wrote: > https://nedbatchelder.com//blog/201709/beginners_and_experts.html > > Great post. Yup. Thanks for the link. I often have that "I bet doesn't get frustrated." thing going. Nice to know Ned bangs his head now and again. :P Leam From stephanh42 at gmail.com.invalid Sat Sep 23 15:44:46 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 23 Sep 2017 19:44:46 GMT Subject: [Tutor] beginning to code References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: Op 2017-09-23, Rick Johnson schreef : > These pissing contests over how values are passed in Python > are totally irrelevant. What does it matter? Nothing will be > gained or lost by arguing over which is true, or not. Unless > the distinction is preventing you from doing something that > you'd like to do, or unless you want to argue that one > "value passing method" would bring X, Y or Z benefits over > the other, what does it matter? Amen. For what it's worth, this discussion lead me to do a bit of historical research into how these terminologies came to be (also to see if there is some sort of "official" definition of what they actually mean). The earliest to which I can trace the discussion is on the context of the definition of the Algol programming language. Algol had both "call by value" and "call by name". Then the whole "call by XXX" terminology took off and people started talking about "call by copy in/out" and whatever. The "call by reference" terminology was introduced to describe what Fortran had been doing all along. The CLU people (primary Barbara Liskov) introduced "call by object sharing", to describe what CLU did. This matches pretty well what Python does, and what Java does, and what basically every programming language invented in the last 25 years does. Now, as I said, what Java and what CLU do is pretty similar, but in the Java community this very same thing is called "call by value". As far as I can follow, this is for the following reason: * The Algol report invented "call by value" and "call by name" and was very influential. * In particular, the Report on the Scheme language was heavily influenced by the Algol report. In the Scheme report, Scheme is described as being "call by value", again probably because of influence of the Algol report, and Scheme is definitely NOT "call by name". Note that in our terminology, Scheme should properly be called "call by object [sharing]". * Guy Steele, who was involved in the Scheme standard, then went on to work on the Java language definition. So Java got its terminology from the Algol->Scheme->Java route. Python got it from CLU. As an aside, in the academic literature, "call by value" is almost always contrasted with "call by name" (nobody seems to have ever published a paper discussing "call by reference"). Typically, this comparison is done in calculi which even lack assignment so that the difference between call by value and call by reference would be unobservable anyway. Stephan From pavol.lisy at gmail.com Sat Sep 23 16:10:14 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Sat, 23 Sep 2017 22:10:14 +0200 Subject: what is happening in panda "where" clause In-Reply-To: References: <7EA3F03731CB00478865918182F3DDEAF289D216@RISALPMBXP003.risk.regn.net> Message-ID: On 9/22/17, Peter Otten <__peter__ at web.de> wrote: > Exposito, Pedro (RIS-MDW) wrote: > >> This code does a "where" clause on a panda data frame... >> >> Code: >> import pandas as pd; >> col_names = ['Name', 'Age', 'Weight', "Education"]; >> # create panda dataframe >> x = pd.read_csv('test.dat', sep='|', header=None, names = col_names); >> # apply "where" condition >> z = x[ (x['Age'] == 55) ] >> # prints row WHERE age == 55 >> print (z); >> >> What is happening in this statement: >> z = x[ (x['Age'] == 55) ] >> >> Thanks, > > Let's take it apart into individual steps: > > Make up example data: > >>>> import pandas as pd >>>> x = pd.DataFrame([["Jim", 44], ["Sue", 55], ["Alice", 66]], > columns=["Name", "Age"]) >>>> x > Name Age > 0 Jim 44 > 1 Sue 55 > 2 Alice 66 > > Have a look at the inner expression: > >>>> x["Age"] == 55 > 0 False > 1 True > 2 False > > So this is a basically vector of boolean values. If you want more details: > in numpy operations involving a a scalar and an array work via > "broadcasting". In pure Python you would write something similar as > >>>> [v == 55 for v in x["Age"]] > [False, True, False] > > Use the result as an index: > >>>> x[[False, True, True]] > Name Age > 1 Sue 55 > 2 Alice 66 > > [2 rows x 2 columns] > > This is again in line with numpy arrays -- if you pass an array of boolean > values as an index the values in the True positions are selected. In pure > Python you could achieve that with > >>>> index = [v == 55 for v in x["Age"]] >>>> index > [False, True, False] >>>> [v for b, v in zip(index, x["Age"]) if b] > [55] You could also write: >>> x[index] x[index] Name Age 1 Sue 55 As Peter told, understanding numpy or "numpy like" behavior behind curtain could be key to understanding what is happening. Look at this: >>> def half_age(a): >>> return a/2 we could use this function in where() -> >>> x[half_age(x.Age)<30] Name Age 0 Jim 44 1 Sue 55 You could think that any function could be used, but it is not true. a/2 (where a is numpy array) is defined. (I am not sure that it is really numpy under the hood or if it will be in future pandas versions but it seems so). But what if we have more universal function? >>> def first_char(a): >>> return a[0].lower() >>> x[first_char(x.Name)=='a'] ... ERROR ... (first_char could not work with pandas serie as a argument. It means pandas Series doesn't have lower() function) But you could create index like Peter described. It could be simpler to remember if you are using pandas not often: >>> x[[first_char(i)=='a' for i in x.Name]] Name Age 2 Alice 66 It is not (IMHO) best solution because you are creating list in memory (which could be big) . Unfortunately my version of pandas (0.20.3) doesn't support generator >>> x[(first_char(i)=='a' for i in x.Name)] ... ERROR... But you could apply more complex function to Series! >>> x[x.Name.apply(first_char)=='a'] Name Age 2 Alice 66 x.Name.apply(first_char) is Series where first_char is applied on each value. And serie (and numpy.array) understand == operator (and return value is Series. Which is acceptable as where function parameter) Although I am not sure that actual version of pandas doesn't create whole Series in memory :) I expect it is more optimized (and could be even more in future). Be aware that I am not expert and I am using pandas only very seldom just for my little statistics! From tjreedy at udel.edu Sat Sep 23 16:49:29 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 23 Sep 2017 16:49:29 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On 9/23/2017 2:52 PM, Leam Hall wrote: > On 09/23/2017 02:40 PM, Terry Reedy wrote: >> https://nedbatchelder.com//blog/201709/beginners_and_experts.html >> >> Great post. > > Yup. Thanks for the link. I often have that "I bet Fred> doesn't get frustrated." thing going. Nice to know Ned bangs his > head now and again.? :P As do I ;-). -- Terry Jan Reedy From dvl at psu.edu Sat Sep 23 17:03:29 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Sat, 23 Sep 2017 17:03:29 -0400 Subject: [Tutor] beginning to code In-Reply-To: mailman.26.1506182404.2153.python-list@python.org References: Message-ID: <1506200609l.6422746l.0l@psu.edu> On Fri, Sep 22, 2017 12:03 PM, Dennis Lee Bier wrote:> On Fri, 22 Sep 2017 23:30:34 +1000, Steve D'Aprano > declaimed the following: > >The exercise is to demonstrate pass by reference semantics. That requires > >demonstrating the same semantics as the Pascal swap procedure: > > > >procedure swap(var a, var b): > > begin > > tmp := a; > > a := b; > > b := tmp; > > end; > > > >(ignoring the type declarations for brevity). > > > Or FORTRAN (since call-by-reference has been the standard in that > language from the start -- no special keywords needed to enable reference > semantics)... It's been 20 years, and I'm using an F90 text, so this is > going to be less than perfect: > subroutine iswap(a, b) integer :: a > integer :: b > a = IEOR(a, b) > b = IEOR(a, b) > a = IEOR(a, b) > return > end > >{That's a bitwise exclusive OR; no temp storage needed} > > a = 123 > > b = 321 > > a = a ^ b > > a > 314 > > b = a ^ b > > b > 123 > > a = a ^ b > > a > 321 > > > And then along comes someone who asks for to swap array elements a[I] and a[j], where I and j just happen to be equal. You don't preserve the values, as would be anticipated, but instead clear the argument(s) to zero. Saving one temp storage is a very tiny gain for the potential cost of a program malfunction. And if you go so far as to bring in a compiled language like Fortran into the mix, where the 'temp storage' is just a machine register, and not RAM, you really have saved nothing at all. I usually do not encourage people to optimize correctness out of their code. From ned at nedbatchelder.com Sat Sep 23 17:26:35 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 23 Sep 2017 17:26:35 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On 9/23/17 2:52 PM, Leam Hall wrote: > On 09/23/2017 02:40 PM, Terry Reedy wrote: >> https://nedbatchelder.com//blog/201709/beginners_and_experts.html >> >> Great post. > > Yup. Thanks for the link. I often have that "I bet Fred> doesn't get frustrated." thing going. Nice to know Ned bangs his > head now and again.? :P > "Ow!" --me From pavol.lisy at gmail.com Sat Sep 23 18:03:13 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Sun, 24 Sep 2017 00:03:13 +0200 Subject: How to share class relationship representations? In-Reply-To: References: Message-ID: On 9/23/17, Stephan Houben wrote: > Op 2017-09-22, Pavol Lisy schreef : >> On 9/19/17, leam hall wrote: >>> I'm working on designing the classes, sub-classes, and relationships in >>> my >>> code. What is a good visual way to represent it so it can be stored in >>> git >>> and shared on the list without large images or attachments? >>> >>> Thanks! >>> >>> Leam >> >> https://stackoverflow.com/questions/29586520/can-one-get-hierarchical-graphs-from-networkx-with-python-3#29597209 > > For direct inclusion in source code, what about plain text with > Unicode box drawing characters? > > ???????? > ?object? > ???????? > ? > ??????? > ?float? > ??????? I am not big fan of UML. I don't really think it is helping. I think that it often just enhance maintenance cost. But if you really need or want it could be good to have some tool to simplify work. And you could probably look at -> http://www.plantuml.com/plantuml To trying something like diagram above you could put there next text and submit: @startuml object object object float object int object -- float object -- int @enduml As I said I don't like UML so I don't propose this :) But if you need "git-able" (text representation) of class diagrams which could be used to generate quite nice images then maybe this tool could be useful. From BILL_NOSPAM at whoknows.net Sat Sep 23 18:18:55 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Sat, 23 Sep 2017 18:18:55 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: Stephan Houben wrote: > Op 2017-09-23, Rick Johnson schreef : >> These pissing contests over how values are passed in Python >> are totally irrelevant. What does it matter? Nothing will be >> gained or lost by arguing over which is true, or not. Unless >> the distinction is preventing you from doing something that >> you'd like to do, or unless you want to argue that one >> "value passing method" would bring X, Y or Z benefits over >> the other, what does it matter? > Amen. > All one has to do, I think, is consider (1) that passing objects by "making copies" of them, would be prohibitively expensive and consider that something else has to happen as an alternative, and (2) understand that in Python, objects don't have names, they have references (which have names). The rest could be "implementation dependent" (no?) To be amusing, how did the chicken pass an egg to the_other_side_of_the_road(e)? Could the egg get crushed (stay tuned)? From rosuav at gmail.com Sat Sep 23 18:35:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Sep 2017 08:35:48 +1000 Subject: [Tutor] beginning to code In-Reply-To: References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sun, Sep 24, 2017 at 8:18 AM, Bill wrote: > Stephan Houben wrote: >> >> Op 2017-09-23, Rick Johnson schreef : >>> >>> These pissing contests over how values are passed in Python >>> are totally irrelevant. What does it matter? Nothing will be >>> gained or lost by arguing over which is true, or not. Unless >>> the distinction is preventing you from doing something that >>> you'd like to do, or unless you want to argue that one >>> "value passing method" would bring X, Y or Z benefits over >>> the other, what does it matter? >> >> Amen. >> > > All one has to do, I think, is consider (1) that passing objects by "making > copies" of them, would be prohibitively expensive and consider that > something else has to happen as an alternative, and (2) understand that in > Python, objects don't have names, they have references (which have names). > The rest could be "implementation dependent" (no?) To be amusing, how did > the chicken pass an egg to the_other_side_of_the_road(e)? Could the egg get > crushed (stay tuned)? Actually they don't "have" references in any real sense of possession. An object "has" things like its type, its attributes, etc etc; if you have a reference to an object, you can query it for its type. But you can't ask an object if there's a reference to it over here or there. (Yes, I know that sys.getrefcount exists in CPython, but this isn't part of the language's definition. Also, even that is just a counter - you can't find specific references.) An object may have a reference to other objects (eg a list's contents), but it's a one-way thing - there's no way to find all the references to this object. So more accurate would be to say that objects don't have names, but names refer to objects. When you assign to a simple name, you cause that name to refer to the object you gave it. ChrisA From python.list at tim.thechases.com Sat Sep 23 19:10:34 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 23 Sep 2017 18:10:34 -0500 Subject: Change project licence? In-Reply-To: References: <85377o7r2h.fsf@benfinney.id.au> <14zQlz1SK1NTt1HIvR3Sulx3cezj97bl-sNUxZCLdYgBJg2NdoaCoqiQlhkIS0S7jN9h57CEdTVVrCwe7FAmmxmLLMegG92tgFDMQM7RsuQ=@protonmail.com> Message-ID: <20170923181034.7de89bc4@bigbox.christie.dr> On 2017-09-23 19:14, Chris Angelico wrote: > On Sat, Sep 23, 2017 at 7:07 PM, Kryptxy > wrote: > > Thank you all! I opened a ticket about the same (on github). > > I got response from most of them, and all are agreeing to the > > change. However, one contributor did not respond at all. I tried > > e-mailing, but no response. > > Can I still proceed changing the licence? It has been more than a > > week since the ticket was opened. > > Nope. Contributions made under the GPL have a guarantee that they > will only and forever be used in open source projects. You're > trying to weaken that guarantee, so you have to get clear > permission from everyone involved. > > Unless you can show that the contributions in question are so > trivial that there's no code that can be pinpointed as that > person's, or you replace all that person's code, you can't proceed > to relicense it without permission. Alternatively, you can rip out that contributor's code and re-code it from scratch in a clean-room without consulting their code. Then their code is under their license while your re-implementation code is under whatever license you like. If their contributions were minor, this might be a nice route to go. If they were a major contributor, you could be looking at a LOT of work. But those are your options: - keep the project as GPL - get *ALL* contributors to formally agree to the license change, - confirm that the contributions of recalcitrant contributor(s) are limited to trivial changes, or - recreate all GPL code in a clean-room under your own license -tkc From BILL_NOSPAM at whoknows.net Sat Sep 23 19:13:12 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Sat, 23 Sep 2017 19:13:12 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: Chris Angelico wrote: > On Sun, Sep 24, 2017 at 8:18 AM, Bill wrote: >> Stephan Houben wrote: >>> Op 2017-09-23, Rick Johnson schreef : >>>> These pissing contests over how values are passed in Python >>>> are totally irrelevant. What does it matter? Nothing will be >>>> gained or lost by arguing over which is true, or not. Unless >>>> the distinction is preventing you from doing something that >>>> you'd like to do, or unless you want to argue that one >>>> "value passing method" would bring X, Y or Z benefits over >>>> the other, what does it matter? >>> Amen. >>> >> All one has to do, I think, is consider (1) that passing objects by "making >> copies" of them, would be prohibitively expensive and consider that >> something else has to happen as an alternative, and (2) understand that in >> Python, objects don't have names, they have references (which have names). >> The rest could be "implementation dependent" (no?) To be amusing, how did >> the chicken pass an egg to the_other_side_of_the_road(e)? Could the egg get >> crushed (stay tuned)? > Actually they don't "have" references in any real sense of possession. I agree (I was a bit hasty in my choice of words); but if they didn't "have" these references, it would be difficult, though not impossible, to refer to them. Also keep in mind that the garbage collector keeps track, generally, of how many there are for each object! So from the gc's point of view, objects (definitely) "have" references. Next, what will Egg.__del__() do? : ) > An object "has" things like its type, its attributes, etc etc; if you > have a reference to an object, you can query it for its type. But you > can't ask an object if there's a reference to it over here or there. > (Yes, I know that sys.getrefcount exists in CPython, but this isn't > part of the language's definition. Also, even that is just a counter - > you can't find specific references.) An object may have a reference to > other objects (eg a list's contents), but it's a one-way thing - > there's no way to find all the references to this object. > > So more accurate would be to say that objects don't have names, but > names refer to objects. When you assign to a simple name, you cause > that name to refer to the object you gave it. > > ChrisA From steve+python at pearwood.info Sat Sep 23 21:49:20 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 24 Sep 2017 11:49:20 +1000 Subject: [Tutor] beginning to code References: <1506200609l.6422746l.0l@psu.edu> Message-ID: <59c70f20$0$14933$b1db1813$d948b532@news.astraweb.com> On Sun, 24 Sep 2017 07:03 am, ROGER GRAYDON CHRISTMAN wrote: > I usually do not encourage people to optimize correctness out of their code. +1 quote of the week :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Sep 23 22:13:44 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 24 Sep 2017 12:13:44 +1000 Subject: [Tutor] beginning to code References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c714da$0$14959$b1db1813$d948b532@news.astraweb.com> On Sun, 24 Sep 2017 08:18 am, Bill wrote: > All one has to do, I think, is consider (1) that passing objects by > "making copies" of them, would be prohibitively expensive Swift passes certain values (but not others!) by value and makes a copy. That includes many potentially large data types including strings, dictionaries and arrays, but using copy-on-write so the data isn't physically copied until you actually mutate it. From the Swift documentation: The description above refers to the ?copying? of strings, arrays, and dictionaries. The behavior you see in your code will always be as if a copy took place. However, Swift only performs an actual copy behind the scenes when it is absolutely necessary to do so. Swift manages all value copying to ensure optimal performance, and you should not avoid assignment to try to preempt this optimization. https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/ClassesAndStructures.html So I maintain that one could design a language similar to Python except that objects are assigned and passed by value, making copies only when actually needed using copy-on-write. Swift is *almost* that language: the difference is that Swift distinguishes between "structs" that are copied, and "objects" which are not. > and consider > that something else has to happen as an alternative, and (2) understand > that in Python, objects don't have names, they have references (which > have names). The rest could be "implementation dependent" (no?) No. There are many different alternatives for "something else", and while some of them may be behave the same in some circumstances, they do not behave the same in all circumstances. Any interpreter calling itself Python would be expected to match the behaviour of the reference implementation, CPython. For example, if I made "Pass-By-Reference Python" where all argument passing was done by reference, my language would differ from real Python: function(x, y) # allowed function(namespace.x, module.y) # allowed function(x + 1, 2) # FORBIDDEN: can't pass expressions or constants Obviously that's not Python! On the other hand, "Pass-By-Name Python" would allow passing expressions and constants, but will differ in other ways. Assignment by reference would mean that name binding was an *alias* operation: module.y = 1 x = module.y # x is an alias for the name "module.y" x = 2 # binds 2 to module.y assert module.y == 2 -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From BILL_NOSPAM at whoknows.net Sat Sep 23 22:37:42 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Sat, 23 Sep 2017 22:37:42 -0400 Subject: [Tutor] beginning to code In-Reply-To: <59c714da$0$14959$b1db1813$d948b532@news.astraweb.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c714da$0$14959$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > On Sun, 24 Sep 2017 08:18 am, Bill wrote: > >> All one has to do, I think, is consider (1) that passing objects by >> "making copies" of them, would be prohibitively expensive > > Swift passes certain values (but not others!) by value and makes a copy. That > includes many potentially large data types including strings, dictionaries and > arrays, but using copy-on-write so the data isn't physically copied until you > actually mutate it. From the Swift documentation: > > > The description above refers to the ?copying? of strings, arrays, > and dictionaries. The behavior you see in your code will always > be as if a copy took place. However, Swift only performs an actual > copy behind the scenes when it is absolutely necessary to do so. > Swift manages all value copying to ensure optimal performance, and > you should not avoid assignment to try to preempt this optimization. > > https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/ClassesAndStructures.html > > > So I maintain that one could design a language similar to Python except that > objects are assigned and passed by value, making copies only when actually > needed using copy-on-write. Swift is *almost* that language: the difference is > that Swift distinguishes between "structs" that are copied, and "objects" which > are not. > > >> and consider >> that something else has to happen as an alternative, and (2) understand >> that in Python, objects don't have names, they have references (which >> have names). The rest could be "implementation dependent" (no?) > No. > > There are many different alternatives for "something else", and while some of > them may be behave the same in some circumstances, they do not behave the same > in all circumstances. Any interpreter calling itself Python would be expected > to match the behaviour of the reference implementation, CPython. > > For example, if I made "Pass-By-Reference Python" where all argument passing was > done by reference, my language would differ from real Python: > > > function(x, y) # allowed > function(namespace.x, module.y) # allowed > function(x + 1, 2) # FORBIDDEN: can't pass expressions or constants This would be okay as long as x + 1 evaluates to an object, no? > > > Obviously that's not Python! > > On the other hand, "Pass-By-Name Python" would allow passing expressions and > constants, but will differ in other ways. > > Assignment by reference would mean that name binding was an *alias* operation: > > > module.y = 1 > x = module.y # x is an alias for the name "module.y" > x = 2 # binds 2 to module.y > assert module.y == 2 > > > > From vek.m1234 at gmail.com Sun Sep 24 06:08:18 2017 From: vek.m1234 at gmail.com (Veek M) Date: Sun, 24 Sep 2017 03:08:18 -0700 (PDT) Subject: PyQt: viewport vs window - how do you translate co-ordinates? In-Reply-To: References: <102146f3-48fa-492b-9a3f-5c91741afdcf@googlegroups.com> <6629f3c6-ef04-11ae-8bb4-33f25f17c85f@gmail.com> Message-ID: On Saturday, September 23, 2017 at 8:44:25 PM UTC+5:30, Michael Torrie wrote: > On 09/23/2017 05:38 AM, Veek M wrote: > > I didn't understand any of that - could someone expand on that para? > > Is there a reading resource that explains the Viewport and translations? I am not a CS student so I did not study computer graphics. > > I'm sure there are lots of things that might help. This is primarily > about OpenGL but the principles may apply: > https://www.cs.mtsu.edu/~jhankins/files/4250/notes/WinToView/WinToViewMap.html > > Alternatively, you can think it through. Imagine you're laying out a > fence around your house. You could use global coordinates for > everything, or you could just call the exact center of your yard 0,0 and > measure everything from there, in whatever units you wish. That's the > idea here. Rather than referring to pixels by their screen coordinates > (which can change if it moves around the screen), you refer to them by > an arbitrary coordinate system with it's own scaling relative to the > screen region. You could have a screen region that is 100 px by 100 px, > and the you designate that the upper left corner of that region is > -500,500 and the lower right corner is 500,-500. Or it could be > something like -500,200 to 500,-200, which would make things stretched > out in the x axis compared to the y axis. > > > (sorry for using google groups but my knode is broken and pan is horrible on olvwm - my plan is to write myself a News client in PyQt :)) > > I don't think you need to know that much about graphics coordinate > systems to get started with Qt. Most GUI layout stuff does not depend on > pixels or coordinates. I took a look at the: OpenGL SuperBible - 7e - it's heavy on doing, and not much theory; they have a section on Views. Also, read that link. The link has some mistakes I suspect.. Let's say we have a teacup-photograph and a table in a 3d-room. The photo has a local space - called Model Space or Object Space. The edges of the photo will form a coordinate system and using that i could make the teacup handle red. If i take that photo and place it on top of that table - i get a World Space that contains both objects and the walls of the room form a coordinate system. (this is where that link is wrong) Now let's say I want to display the room on a computer screen. The entire computer screen forms a Screen coordinate system and will include the Dolphin file browser, maybe firefox, the kde toolbar) However, I can't directly take a 3d room and stick it in my 2d screen so, I have to capture part of the room from a PERSPECTIVE - this is 2d because the camera film is 2d - so, this is a View Space/Clipping Window (link/url). Now the View Space data that I captured has to be placed on the screen BUT not everywhere - this is the Interface Window (link/url). However I may want to caption the room-image-displayed-on-screen so the Interface Window is further shrunk into a Viewport which represents pixels/points on the device/paper. Transformation is a matrix associated with a space that will give you the desired pixels in the Viewport. View Space is how this World Space looks when viewed ----------------------------------------------- So how does the above fit into PyQt/book-description. We have a Widget that is drawn in pixels/picas/whatever that has a physical-coordinate system associated with it (800x600 and will prolly fill the entire computer-screen). We have a window which is at (-60, -60) + 120 length&breadth - so you have a small rectangle in which to draw - equivalent to the ViewSpace however since this is 2d, it can also be equivalent to the Model/Object Space - with some random center (0,0) could be the teacup-handle. The aspect ratio for widget is 1.3333 aspect ratio for window is 1 If the aspect ratios were the same there would be no problem - however since the aspect ratios are different, x-axis scaling is 120:800 and y-axis is 120:600. We need to bear this in mind when we draw in our little window because what looks proportional/linear will be deformed when placed on screen/viewport. So if we badly want a square window, we can create a square Screen/Viewport and loose some drawing area as a result of the viewport being squared from a rectangle. -------------------------- Phew! anyway this is just my longwinded way but I think I got it. Thanks :) From khushi27gkcse at gmail.com Sun Sep 24 07:13:27 2017 From: khushi27gkcse at gmail.com (khushi27gkcse at gmail.com) Date: Sun, 24 Sep 2017 04:13:27 -0700 (PDT) Subject: SyntaxError: multiple statements found while compiling a single statement In-Reply-To: <72bab892-e8ec-4ed8-8ccb-614ef976b69d@googlegroups.com> References: <72bab892-e8ec-4ed8-8ccb-614ef976b69d@googlegroups.com> Message-ID: <5d1b51cc-ab22-4552-b37d-bf32b22a239a@googlegroups.com> On Saturday, October 8, 2016 at 11:32:17 AM UTC+5:30, Cai Gengyang wrote: > Any idea how to correct this error ? Looks fine to me .... > > >>> rect_x = 50 > > # -------- Main Program Loop ----------- > while not done: > for event in pygame.event.get(): # User did something > if event.type == pygame.QUIT: # If user clicked close > done = True # Flag that we are done so we exit this loop > > SyntaxError: multiple statements found while compiling a single statement > > Thanks ... From steve+python at pearwood.info Sun Sep 24 10:49:02 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 25 Sep 2017 00:49:02 +1000 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> On Mon, 25 Sep 2017 12:35 am, Stefan Ram wrote: > WRT to assertions about Python, I try to base them on the > "The Python Language Reference, Release 3.6.0" (PRL). > > So, WRT to parameter passing, I would use this part of the PRL: > > ?The following constructs bind names: formal parameters > to functions,? PRL 4.2.1 > > . Therefore, what Python does, I'd call ?call by binding?. I am not aware of "call by binding" being a well-known or recognised term. Did you make it up? Also, the problem is that *any* form of function call binds *something* to the function parameters. If we consider the Pascal declaration: procedure proc(x: integer; var y: integer); and then we call it: var a, b: integer; begin a := 1; b := 2; proc(a, b); end. then 1 is bound to x and 2 is bound to y. They happen to exist in different scopes (x is local to proc, the *name* y is local to proc, but the variable is bound to y is global) but that's not important. The point I am making is that we could describe just about any and all languages with functions "call by binding", whether they are call by value like C, call by reference like Fortran, call by need like Haskell, or call by sharing like Python. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Sep 24 11:11:57 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 25 Sep 2017 01:11:57 +1000 Subject: Reference cycles Message-ID: <59c7cb3f$0$14964$b1db1813$d948b532@news.astraweb.com> Is there a way to log when the garbage collector finds and collects a reference cycle? I don't care about objects claimed by the reference counter, I only care about cycles. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From bc at freeuk.com Sun Sep 24 11:56:06 2017 From: bc at freeuk.com (bartc) Date: Sun, 24 Sep 2017 16:56:06 +0100 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> Message-ID: On 24/09/2017 15:49, Steve D'Aprano wrote: > On Mon, 25 Sep 2017 12:35 am, Stefan Ram wrote: > >> WRT to assertions about Python, I try to base them on the >> "The Python Language Reference, Release 3.6.0" (PRL). >> >> So, WRT to parameter passing, I would use this part of the PRL: >> >> ?The following constructs bind names: formal parameters >> to functions,? PRL 4.2.1 >> >> . Therefore, what Python does, I'd call ?call by binding?. > > I am not aware of "call by binding" being a well-known or recognised term. Did > you make it up? > > Also, the problem is that *any* form of function call binds *something* to the > function parameters. If we consider the Pascal declaration: > > procedure proc(x: integer; var y: integer); > > > and then we call it: > > var > a, b: integer; > begin > a := 1; > b := 2; > proc(a, b); > end. > > > then 1 is bound to x and 2 is bound to y. They happen to exist in different > scopes (x is local to proc, the *name* y is local to proc, but the variable is > bound to y is global) but that's not important. > > The point I am making is that we could describe just about any and all languages > with functions "call by binding", whether they are call by value like C, call > by reference like Fortran, call by need like Haskell, or call by sharing like > Python. Then 'binding' is either ill-defined or used wrongly. Imagine that each name (a,b,x,y) is a little box. In Pascal, the boxes for a and b contain 1 and 2 respectively. For x and y, they contain pointers (dereferenced behind the scenes). Fortran is similar (or Fortran IV was; I don't know modern ones). C works the same way: every variable has a box, and that box directly contains a value. In Python, those boxes don't contain anything, except one end of a piece of string. The other end is attached to an object. When you pass a variable to a function like this: def fn(X): A=1 fn(A) Then X gets set up with a string which has the same object at the other end as A. (And the object might have a reference count to reflect that extra string.) This is why you can't change A in the caller as there is no way to get from X's box to A's box. And the strings to the object are one-way. In the case of fn(A+2), a new object is created (with value '3', or an existing '3' might be used), a new string is attached to it, and the other is attached to X. -- bartc From patrickkidd at gmail.com Sun Sep 24 12:09:48 2017 From: patrickkidd at gmail.com (Patrick Stinson) Date: Sun, 24 Sep 2017 09:09:48 -0700 Subject: Compiling Python for iOS 11 Message-ID: <011F58A7-B324-48C7-8CBB-42D48E10EB2E@gmail.com> Has anyone successfully compiled python for iOS 11? I tried with 3.5.2 and 3.6.2 and got the following errors: turin:Python-3.6.2 patrick$ make Makefile:9845: warning: overriding commands for target `.obj/_pickle.o' Makefile:8855: warning: ignoring old commands for target `.obj/_pickle.o' /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -c -pipe -fwrapv -std=c99 -g -fPIC -arch arm64 -arch x86_64 -Xarch_arm64 -miphoneos-version-min=8.0 -Xarch_arm64 -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk -Xarch_x86_64 -mios-simulator-version-min=8.0 -Xarch_x86_64 -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.0.sdk -fobjc-nonfragile-abi -fobjc-legacy-dispatch -w -fembed-bitcode-marker -DQT_COMPILER_SUPPORTS_SSE2 -DNDEBUG -DPy_BUILD_CORE -DVERSION=\"3.6\" -DVPATH=\".\" -DPREFIX=\"/\" -DEXEC_PREFIX=\"/\" -DPYTHONPATH=\"/lib/python3.6\" -DPLATFORM=\"linux\" -I. -I../../../pyqt-sysroot-base/src/qt5/qtbase/mkspecs/common/uikit -I. -IInclude -I../../../pyqt-sysroot-base/src/qt5/qtbase/mkspecs/macx-ios-clang -o .obj/_scproxy.o Modules/_scproxy.c Modules/_scproxy.c:65:17: error: 'SCDynamicStoreCopyProxies' is unavailable: not available on iOS proxyDict = SCDynamicStoreCopyProxies(NULL); ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreCopySpecific.h:210:1: note: 'SCDynamicStoreCopyProxies' has been explicitly marked unavailable here SCDynamicStoreCopyProxies ( ^ Modules/_scproxy.c:75:9: error: 'kSCPropNetProxiesExcludeSimpleHostnames' is unavailable: not available on iOS kSCPropNetProxiesExcludeSimpleHostnames); ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:1992:49: note: expanded from macro 'kSCPropNetProxiesExcludeSimpleHostnames' #define kSCPropNetProxiesExcludeSimpleHostnames kSCPropNetProxiesExcludeSimpleHostnames ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:1991:26: note: 'kSCPropNetProxiesExcludeSimpleHostnames' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesExcludeSimpleHostnames __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_NA); ^ Modules/_scproxy.c:89:21: error: 'kSCPropNetProxiesExceptionsList' is unavailable: not available on iOS kSCPropNetProxiesExceptionsList); ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:1985:41: note: expanded from macro 'kSCPropNetProxiesExceptionsList' #define kSCPropNetProxiesExceptionsList kSCPropNetProxiesExceptionsList ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:1984:26: note: 'kSCPropNetProxiesExceptionsList' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesExceptionsList __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); ^ Modules/_scproxy.c:176:17: error: 'SCDynamicStoreCopyProxies' is unavailable: not available on iOS proxyDict = SCDynamicStoreCopyProxies(NULL); ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCDynamicStoreCopySpecific.h:210:1: note: 'SCDynamicStoreCopyProxies' has been explicitly marked unavailable here SCDynamicStoreCopyProxies ( ^ Modules/_scproxy.c:185:9: error: 'kSCPropNetProxiesHTTPEnable' is unavailable: not available on iOS kSCPropNetProxiesHTTPEnable, ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2048:37: note: expanded from macro 'kSCPropNetProxiesHTTPEnable' #define kSCPropNetProxiesHTTPEnable kSCPropNetProxiesHTTPEnable ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2047:26: note: 'kSCPropNetProxiesHTTPEnable' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesHTTPEnable __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); ^ Modules/_scproxy.c:186:9: error: 'kSCPropNetProxiesHTTPProxy' is unavailable: not available on iOS kSCPropNetProxiesHTTPProxy, ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2062:36: note: expanded from macro 'kSCPropNetProxiesHTTPProxy' #define kSCPropNetProxiesHTTPProxy kSCPropNetProxiesHTTPProxy ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2061:26: note: 'kSCPropNetProxiesHTTPProxy' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesHTTPProxy __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); ^ Modules/_scproxy.c:187:9: error: 'kSCPropNetProxiesHTTPPort' is unavailable: not available on iOS kSCPropNetProxiesHTTPPort); ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2055:35: note: expanded from macro 'kSCPropNetProxiesHTTPPort' #define kSCPropNetProxiesHTTPPort kSCPropNetProxiesHTTPPort ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2054:26: note: 'kSCPropNetProxiesHTTPPort' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesHTTPPort __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); ^ Modules/_scproxy.c:190:9: error: 'kSCPropNetProxiesHTTPSEnable' is unavailable: not available on iOS kSCPropNetProxiesHTTPSEnable, ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2069:38: note: expanded from macro 'kSCPropNetProxiesHTTPSEnable' #define kSCPropNetProxiesHTTPSEnable kSCPropNetProxiesHTTPSEnable ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2068:26: note: 'kSCPropNetProxiesHTTPSEnable' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesHTTPSEnable __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); ^ Modules/_scproxy.c:191:9: error: 'kSCPropNetProxiesHTTPSProxy' is unavailable: not available on iOS kSCPropNetProxiesHTTPSProxy, ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2083:37: note: expanded from macro 'kSCPropNetProxiesHTTPSProxy' #define kSCPropNetProxiesHTTPSProxy kSCPropNetProxiesHTTPSProxy ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2082:26: note: 'kSCPropNetProxiesHTTPSProxy' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesHTTPSProxy __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); ^ Modules/_scproxy.c:192:9: error: 'kSCPropNetProxiesHTTPSPort' is unavailable: not available on iOS kSCPropNetProxiesHTTPSPort); ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2076:36: note: expanded from macro 'kSCPropNetProxiesHTTPSPort' #define kSCPropNetProxiesHTTPSPort kSCPropNetProxiesHTTPSPort ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2075:26: note: 'kSCPropNetProxiesHTTPSPort' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesHTTPSPort __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); ^ Modules/_scproxy.c:195:9: error: 'kSCPropNetProxiesFTPEnable' is unavailable: not available on iOS kSCPropNetProxiesFTPEnable, ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:1999:36: note: expanded from macro 'kSCPropNetProxiesFTPEnable' #define kSCPropNetProxiesFTPEnable kSCPropNetProxiesFTPEnable ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:1998:26: note: 'kSCPropNetProxiesFTPEnable' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesFTPEnable __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); ^ Modules/_scproxy.c:196:9: error: 'kSCPropNetProxiesFTPProxy' is unavailable: not available on iOS kSCPropNetProxiesFTPProxy, ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2020:35: note: expanded from macro 'kSCPropNetProxiesFTPProxy' #define kSCPropNetProxiesFTPProxy kSCPropNetProxiesFTPProxy ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2019:26: note: 'kSCPropNetProxiesFTPProxy' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesFTPProxy __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); ^ Modules/_scproxy.c:197:9: error: 'kSCPropNetProxiesFTPPort' is unavailable: not available on iOS kSCPropNetProxiesFTPPort); ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2013:34: note: expanded from macro 'kSCPropNetProxiesFTPPort' #define kSCPropNetProxiesFTPPort kSCPropNetProxiesFTPPort ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2012:26: note: 'kSCPropNetProxiesFTPPort' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesFTPPort __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); ^ Modules/_scproxy.c:200:9: error: 'kSCPropNetProxiesGopherEnable' is unavailable: not available on iOS kSCPropNetProxiesGopherEnable, ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2027:39: note: expanded from macro 'kSCPropNetProxiesGopherEnable' #define kSCPropNetProxiesGopherEnable kSCPropNetProxiesGopherEnable ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2026:26: note: 'kSCPropNetProxiesGopherEnable' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesGopherEnable __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); ^ Modules/_scproxy.c:201:9: error: 'kSCPropNetProxiesGopherProxy' is unavailable: not available on iOS kSCPropNetProxiesGopherProxy, ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2041:38: note: expanded from macro 'kSCPropNetProxiesGopherProxy' #define kSCPropNetProxiesGopherProxy kSCPropNetProxiesGopherProxy ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2040:26: note: 'kSCPropNetProxiesGopherProxy' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesGopherProxy __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); ^ Modules/_scproxy.c:202:9: error: 'kSCPropNetProxiesGopherPort' is unavailable: not available on iOS kSCPropNetProxiesGopherPort); ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2034:37: note: expanded from macro 'kSCPropNetProxiesGopherPort' #define kSCPropNetProxiesGopherPort kSCPropNetProxiesGopherPort ^ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.0.sdk/System/Library/Frameworks/SystemConfiguration.framework/Headers/SCSchemaDefinitions.h:2033:26: note: 'kSCPropNetProxiesGopherPort' has been explicitly marked unavailable here extern const CFStringRef kSCPropNetProxiesGopherPort __OSX_AVAILABLE_STARTING(__MAC_10_1,__IPHONE_NA); ^ 16 errors generated. make: *** [.obj/_scproxy.o] Error 1 turin:Python-3.6.2 patrick$ From __peter__ at web.de Sun Sep 24 12:23:20 2017 From: __peter__ at web.de (Peter Otten) Date: Sun, 24 Sep 2017 18:23:20 +0200 Subject: Reference cycles References: <59c7cb3f$0$14964$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > Is there a way to log when the garbage collector finds and collects a > reference cycle? > > I don't care about objects claimed by the reference counter, I only care > about cycles. I don't know, and I don't think so. Would a structure like a --- b --- c | | | d --- e --- f count as one, or two, or three cycles? If you have a clear answer to that you can save the collected objects in gc.garbage and count the cycles yourself. From daiyueweng at gmail.com Sun Sep 24 16:41:30 2017 From: daiyueweng at gmail.com (Daiyue Weng) Date: Sun, 24 Sep 2017 21:41:30 +0100 Subject: python console menu level looping Message-ID: Hi, I tried to make a menu using print statements in Python 3. The code is as follows, print('insert data into: ') data_insert_method = ['new collection', 'existing collection'] for index, elem in enumerate(data_insert_method): print(index, '-', elem) while 1: how_to_insert = input('Choose a method for inserting data: ') if how_to_insert: try: how_to_insert = int(how_to_insert) how_to_insert = data_insert_method[how_to_insert] break except ValueError: print('Please type in an integer corresponding to the data insert method') continue except IndexError: print('insert method index out of range') continue if how_to_insert == 'new collection': print('Set up collection name : ') db_name_setup = ['manual setup', 'return to the main menu'] for index, elem in enumerate(db_name_setup): print(index, '-', elem) while 1: how_to_setup = input('Choose a method for setting up collection: ') if how_to_setup: try: how_to_setup = int(how_to_setup) how_to_setup = db_name_setup[how_to_setup] break except ValueError: print('Please type in an integer corresponding to the collection setup method') continue except IndexError: print('collection setup method index out of range') continue if how_to_setup == 'manual setup': print('Please type in collection name: ') elif how_to_setup == 'return to main menu': print('return to main menu') It is a 2-level menu, on the 2nd level menu 'new collection', there is an option - 'return to the main menu', I am wondering how to loop back to the 1st level menu, i.e. ['new collection', 'existing collection'], whenever 'return to the main menu' is selected. cheers From daiyueweng at gmail.com Sun Sep 24 17:11:49 2017 From: daiyueweng at gmail.com (Daiyue Weng) Date: Sun, 24 Sep 2017 22:11:49 +0100 Subject: python console menu level looping In-Reply-To: References: Message-ID: well, in my case, there is no GUI, and we do not intend to use it since this script is only for internal testing purposes. So I am just wondering how to loop menu in this context. On 24 September 2017 at 22:03, Stefan Ram wrote: > Daiyue Weng writes: > >I am wondering how to loop back to the 1st level menu > > You are writing a historical kind of menu system. > > One way to proceed might be a more contemporary menu > system like tkinter's: > > from tkinter import * > > class Main(Frame): > > def __init__(self, parent): > Frame.__init__(self, parent) > self.parent = parent > self.initUI() > > def initUI(self): > self.parent.title( "menu example" ) > self.pack( fill=BOTH, expand=1 ) > menubar = Menu( self.parent ) > self.parent.config( menu=menubar ) > mainMenu = Menu( self ) > subMenu = Menu( self ) > mainMenu.add_cascade( label='new collection', menu=subMenu ) > subMenu.add_command\ > ( label='manual setup', command = self.manual_setup ) > mainMenu.add_command\ > ( label='existing collection', > command = self.existing_collection ) > menubar.add_cascade( label="File", menu=mainMenu ) > self.txt = Text( self ) > self.txt.pack( fill=BOTH, expand=1 ) > > def onOpen( self ): > pass > > def manual_setup( self ): > pass > > def existing_collection( self ): > pass > > def manual_setup( self ): > pass > > root = Tk() > > ex = Main( root ) > ex.pack( side="bottom" ) > > root.geometry( "300x250+300+300" ) > root.mainloop() > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From cs at cskk.id.au Sun Sep 24 17:11:51 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 25 Sep 2017 07:11:51 +1000 Subject: python console menu level looping In-Reply-To: References: Message-ID: <20170924211151.GA71580@cskk.homeip.net> On 24Sep2017 21:41, Daiyue Weng wrote: >Hi, I tried to make a menu using print statements in Python 3. The code is >as follows, One thing, please try to preserve the code indenting in messages. What you pasted is all hard against the left side of the screen. I've tried to repair it. >print('insert data into: ') >data_insert_method = ['new collection', 'existing collection'] >for index, elem in enumerate(data_insert_method): > print(index, '-', elem) > >while 1: Remark: we tend to say "while True:", it reads more naturally. >how_to_insert = input('Choose a method for inserting data: ') >if how_to_insert: > try: > how_to_insert = int(how_to_insert) > how_to_insert = data_insert_method[how_to_insert] > break > except ValueError: > print('Please type in an integer corresponding to the data insert method') > continue > except IndexError: > print('insert method index out of range') > continue Another remark: it is better to keep try/except around as small a piece of code as possible; I'd use two here, one for ValueError around the int() and one for IndexError around the []. > if how_to_insert == 'new collection': > print('Set up collection name : ') > db_name_setup = ['manual setup', 'return to the main menu'] > for index, elem in enumerate(db_name_setup): > print(index, '-', elem) > while 1: > how_to_setup = input('Choose a method for setting up collection: ') > if how_to_setup: > try: > how_to_setup = int(how_to_setup) > how_to_setup = db_name_setup[how_to_setup] > break > except ValueError: > print('Please type in an integer corresponding to the collection setup method') > continue > except IndexError: > print('collection setup method index out of range') > continue > if how_to_setup == 'manual setup': > print('Please type in collection name: ') > elif how_to_setup == 'return to main menu': > print('return to main menu') > >It is a 2-level menu, on the 2nd level menu 'new collection', there is an >option - 'return to the main menu', I am wondering how to loop back to the >1st level menu, i.e. ['new collection', 'existing collection'], >whenever 'return to the main menu' is selected. This is where the lack of indentation in your posted code bites; I've just realised I've misread your logic because I misindented your code :-( Your "while 1:" is just a loop around the input question, not around the menu choices. I would go with a flag, and use it as your loop condition. Like this: running_inner_menu = True while running_inner_menu: So something like this (untested): if how_to_insert == 'new collection': running_inner_menu = True while running_inner_menu: print('Set up collection name : ') db_name_setup = ['manual setup', 'return to the main menu'] for index, elem in enumerate(db_name_setup): print(index, '-', elem) # obtain a valid choice while 1: how_to_setup = input('Choose a method for setting up collection: ') if how_to_setup: try: how_to_setup = int(how_to_setup) how_to_setup = db_name_setup[how_to_setup] break except ValueError: print('Please type in an integer corresponding to the collection setup thod') continue except IndexError: print('collection setup method index out of range') continue if how_to_setup == 'manual setup': print('Please type in collection name: ') ... etc ... elif how_to_setup == 'return to main menu': print('return to main menu') running_inner_menu = False All this depends a little on how your code was originally indented i.e. exactly which portions of the code were within each while loop. I've guessed at something reasonable, but can see that there's room for different arrangements. But basicly, keep a state variable indicating that a loop should continue. As a piece of terminology, a Boolean (True/False) state variable is often called a flag. This has two advantages: It means you can turn it off anywhere and next time around the loop will stop, whereas doing things directly with continue or break requires "structural" control because they only jump out of the innermost loop, and also they act right now, preventing other relevant stuff being done. Also it makes your code more readable and easier to reason able: a loop which says "while running_inner_menu:" directly says that this loop controls a repeating menu, and that you can get out by changing "running_inner_menu". A bare "while 1:" or "while True:" requires the reader to have to scan the code to figure out what is being controlled. Cheers, Cameron Simpson (formerly cs at zip.com.au) From daiyueweng at gmail.com Sun Sep 24 17:35:29 2017 From: daiyueweng at gmail.com (Daiyue Weng) Date: Sun, 24 Sep 2017 22:35:29 +0100 Subject: python console menu level looping In-Reply-To: <20170924211151.GA71580@cskk.homeip.net> References: <20170924211151.GA71580@cskk.homeip.net> Message-ID: Sry for the unclear formatting, this is the original code with correct format (copy from pycharm), print('insert data into: ') data_insert_method = ['new collection', 'existing collection'] for index, elem in enumerate(data_insert_method): print(index, '-', elem) while 1: how_to_insert = input('Choose a method for inserting data: ') if how_to_insert: try: how_to_insert = int(how_to_insert) how_to_insert = data_insert_method[how_to_insert] break except ValueError: print('Please type in an integer corresponding to the data insert method') continue except IndexError: print('insert method index out of range') continue if how_to_insert == 'new collection': print('Set up collection name : ') db_name_setup = ['manual setup', 'return to main menu'] for index, elem in enumerate(db_name_setup): print(index, '-', elem) while 1: how_to_setup = input('Choose a method for setting up collection: ') if how_to_setup: try: how_to_setup = int(how_to_setup) how_to_setup = db_name_setup[how_to_setup] break except ValueError: print('Please type in an integer corresponding to the collection setup method') continue except IndexError: print('db name setup method index out of range') continue if how_to_setup == 'manual setup': print('Please type in collection name ') elif how_to_setup == 'return to main menu': print('return to main menu') On 24 September 2017 at 22:11, Cameron Simpson wrote: > On 24Sep2017 21:41, Daiyue Weng wrote: > >> Hi, I tried to make a menu using print statements in Python 3. The code is >> as follows, >> > > One thing, please try to preserve the code indenting in messages. What you > pasted is all hard against the left side of the screen. I've tried to > repair it. > > print('insert data into: ') >> data_insert_method = ['new collection', 'existing collection'] >> for index, elem in enumerate(data_insert_method): >> print(index, '-', elem) >> >> while 1: >> > > Remark: we tend to say "while True:", it reads more naturally. > > how_to_insert = input('Choose a method for inserting data: ') >> if how_to_insert: >> try: >> how_to_insert = int(how_to_insert) >> how_to_insert = data_insert_method[how_to_insert] >> break >> except ValueError: >> print('Please type in an integer corresponding to the data insert >> method') >> continue >> except IndexError: >> print('insert method index out of range') >> continue >> > > Another remark: it is better to keep try/except around as small a piece of > code as possible; I'd use two here, one for ValueError around the int() and > one for IndexError around the []. > > > if how_to_insert == 'new collection': >> print('Set up collection name : ') >> db_name_setup = ['manual setup', 'return to the main menu'] >> for index, elem in enumerate(db_name_setup): >> print(index, '-', elem) >> while 1: >> how_to_setup = input('Choose a method for setting up collection: ') >> if how_to_setup: >> try: >> how_to_setup = int(how_to_setup) >> how_to_setup = db_name_setup[how_to_setup] >> break >> except ValueError: >> print('Please type in an integer corresponding to the collection >> setup method') >> continue >> except IndexError: >> print('collection setup method index out of range') >> continue >> if how_to_setup == 'manual setup': >> print('Please type in collection name: ') >> elif how_to_setup == 'return to main menu': >> print('return to main menu') >> >> It is a 2-level menu, on the 2nd level menu 'new collection', there is an >> option - 'return to the main menu', I am wondering how to loop back to the >> 1st level menu, i.e. ['new collection', 'existing collection'], >> whenever 'return to the main menu' is selected. >> > > This is where the lack of indentation in your posted code bites; I've just > realised I've misread your logic because I misindented your code :-( Your > "while 1:" is just a loop around the input question, not around the menu > choices. > > I would go with a flag, and use it as your loop condition. Like this: > > running_inner_menu = True > while running_inner_menu: > > So something like this (untested): > > if how_to_insert == 'new collection': > running_inner_menu = True > while running_inner_menu: > print('Set up collection name : ') > db_name_setup = ['manual setup', 'return to the main menu'] > for index, elem in enumerate(db_name_setup): > print(index, '-', elem) > # obtain a valid choice > while 1: > how_to_setup = input('Choose a method for setting up collection: ') > if how_to_setup: > try: > how_to_setup = int(how_to_setup) > how_to_setup = db_name_setup[how_to_setup] > break > except ValueError: > print('Please type in an integer corresponding to the > collection setup thod') > continue > except IndexError: > print('collection setup method index out of range') > continue > if how_to_setup == 'manual setup': > print('Please type in collection name: ') > ... etc ... > elif how_to_setup == 'return to main menu': > print('return to main menu') > running_inner_menu = False > > All this depends a little on how your code was originally indented i.e. > exactly which portions of the code were within each while loop. I've > guessed at something reasonable, but can see that there's room for > different arrangements. > > But basicly, keep a state variable indicating that a loop should continue. > As a piece of terminology, a Boolean (True/False) state variable is often > called a flag. > > This has two advantages: > > It means you can turn it off anywhere and next time around the loop will > stop, whereas doing things directly with continue or break requires > "structural" control because they only jump out of the innermost loop, and > also they act right now, preventing other relevant stuff being done. > > Also it makes your code more readable and easier to reason able: a loop > which says "while running_inner_menu:" directly says that this loop > controls a repeating menu, and that you can get out by changing > "running_inner_menu". A bare "while 1:" or "while True:" requires the > reader to have to scan the code to figure out what is being controlled. > > Cheers, > Cameron Simpson (formerly cs at zip.com.au) > From no.email at nospam.invalid Sun Sep 24 18:35:58 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 24 Sep 2017 15:35:58 -0700 Subject: Project Euler 20. References: Message-ID: <874lrr912p.fsf@nightsong.com> "Robert L." writes: >> Find the sum of the digits in the number 100! > In Python? So you have come to plague us here too. >>> sum(ord(c)-ord('0') for c in str(reduce(lambda a,b: a*b, range(1,101),1))) 648 From greg.ewing at canterbury.ac.nz Sun Sep 24 18:39:54 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 25 Sep 2017 11:39:54 +1300 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> Message-ID: Dennis Lee Bieber wrote: > "Binding" itself tends to be Python specific terminology -- in that it > is the parameter /name/ that gets bound/attached to the argument /object/. > It is the same method as used in any Python "assignment" statement, Which is why I think "call by assignment" would be a much better term! -- Greg From ian.g.kelly at gmail.com Sun Sep 24 19:23:10 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 24 Sep 2017 17:23:10 -0600 Subject: Project Euler 20. In-Reply-To: <874lrr912p.fsf@nightsong.com> References: <874lrr912p.fsf@nightsong.com> Message-ID: On Sun, Sep 24, 2017 at 4:35 PM, Paul Rubin wrote: > > "Robert L." writes: > >> Find the sum of the digits in the number 100! > > In Python? > > So you have come to plague us here too. > > >>> sum(ord(c)-ord('0') for c in str(reduce(lambda a,b: a*b, range(1,101),1))) > 648 Or for any Python 2.6 or greater: >>> sum(int(c) for c in str(math.factorial(100))) 648 From rosuav at gmail.com Sun Sep 24 20:13:26 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Sep 2017 10:13:26 +1000 Subject: _sitebuiltins? In-Reply-To: <_sitebuiltins-20170925005529@ram.dialup.fu-berlin.de> References: <_sitebuiltins-20170925005529@ram.dialup.fu-berlin.de> Message-ID: On Mon, Sep 25, 2017 at 10:03 AM, Stefan Ram wrote: > What's the difference between ?builtins? and ?_sitebuiltins?? > > |>>> type.__module__ > |'builtins' > | > |>>> help.__module__ > |'_sitebuiltins' > > I mean the semantic difference. Why are some entities placed > into ?builtins? and some into ?_sitebuiltins?? Because the 'help' function comes from site.py: def sethelper(): builtins.help = _sitebuiltins._Helper() If you're not importing site.py (eg "python3 -S"), you don't need the code for help(), but you'll always have type(). Basically it's a memory-saving thing. Critical vs optional. ChrisA From steve+python at pearwood.info Sun Sep 24 20:49:39 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 25 Sep 2017 10:49:39 +1000 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c852a5$0$14933$b1db1813$d948b532@news.astraweb.com> On Mon, 25 Sep 2017 01:56 am, bartc wrote: >> The point I am making is that we could describe just about any and all >> languages with functions "call by binding", whether they are call by value >> like C, call by reference like Fortran, call by need like Haskell, or call by >> sharing like Python. > > Then 'binding' is either ill-defined or used wrongly. No, binding is a perfectly fine word. It is just too generic to be helpful here. In Pascal or C: a := b; a = b; the compiler binds a copy of the value*of b to the identifier a. In C++ were we have reference variables: a = b; will either bind a copy of b to a, same as C, or bind a reference to b to a (thus making a an alias to b). In Python: a = b binds the value of b to a, without copying. If it weren't too late to change decades of use, I'd say that "pass by value" should be called "pass by copying". The nature of the binding can differ: Pascal and C use the "variables are a numbered box" model, while Python uses the "variables are one end of piece of string tied to the object" model. Name binding is a generic term, like assignment, which doesn't really hint at how the assignment is done. All it really means is that the R-value (the right hand side of the assignment, an expression or literal or value of some sort) is associated with the L-value (the left hand side of the assignment, a variable name, or identifier, of some sort). By the way, the model of "pieces of string" to describe Python's assignment model leaks too. (All models leak, to a lesser or greater degree.) The problem with the model is that if you tied a piece of string to an object, the object can follow the string backwards to find out its name (or names). But in Python, objects cannot do that: they have no way of telling what names they are known by, or even how many names there are. (There may be clever tricks you can play with the garbage collector or debugger, but that's not part of Python-the-language, that's a compiler-specific hook which can peer into the implementation.) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sun Sep 24 21:09:54 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Sep 2017 11:09:54 +1000 Subject: _sitebuiltins? In-Reply-To: References: <_sitebuiltins-20170925005529@ram.dialup.fu-berlin.de> Message-ID: On Mon, Sep 25, 2017 at 10:46 AM, Stefan Ram wrote: > Chris Angelico writes: >>On Mon, Sep 25, 2017 at 10:03 AM, Stefan Ram wrote: >>>What's the difference between ??builtins?? and ??_sitebuiltins??? >>>|>>> type.__module__ >>>|'builtins' >>>| >>>|>>> help.__module__ >>>|'_sitebuiltins' >>def sethelper(): >> builtins.help = _sitebuiltins._Helper() > > Thank you! > > I still have a related question. > > When I say, > > from math import floor > help() > > , Python will try to understand ?help? and search for it in > the current scope. It will find a ?help? there, as if after > > from builtins import * > > . Has it somewhere retained the information that ?help? came > from ?builtins?, so that one can write a function (or some > similar means) as follows: > > wherefrom( 'help' ) > > will return > > builtins > > or > > wherefrom( 'floor' ) > > will return > > math > > ? Yes and no. You can't find out where you actually got something, because that 'something' is the same thing whereever you got it; but you CAN find the "canonical source" of something. Examples: >>> math.__name__ 'math' >>> import os >>> os.__name__ 'os' So far, so good. >>> import curses.ascii >>> curses.ascii.__name__ 'curses.ascii' Works for package modules too. Great! >>> import os.path >>> os.path.__name__ 'posixpath' Ah. Because 'os.path' actually comes from somewhere else. And it's the same module as if I said: >>> import posixpath >>> posixpath.__name__ 'posixpath' >>> os.path is posixpath True The same applies to functions. >>> from math import floor >>> floor.__module__ 'math' And classes. >>> from enum import Enum >>> Enum.__module__ 'enum' But if anything got imported from somewhere else, you get the _original_ source, not the one you got it from: >>> from ssl import namedtuple >>> namedtuple.__module__ 'collections' Is that good enough for what you need? It's not "where did this come from", but it's "where does this live". ChrisA From no.email at nospam.invalid Sun Sep 24 21:16:38 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 24 Sep 2017 18:16:38 -0700 Subject: Project Euler 20. References: <874lrr912p.fsf@nightsong.com> Message-ID: <87r2uv7f2h.fsf@nightsong.com> Ian Kelly writes: >>>> sum(int(c) for c in str(math.factorial(100))) Doh! Using int(c) didn't occur to me and I didn't know about math.factorial. Notice also that WJ hasn't yet dared posting his crap on comp.lang.haskell. From steve+python at pearwood.info Sun Sep 24 21:19:57 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 25 Sep 2017 11:19:57 +1000 Subject: _sitebuiltins? References: <_sitebuiltins-20170925005529@ram.dialup.fu-berlin.de> Message-ID: <59c859be$0$14930$b1db1813$d948b532@news.astraweb.com> On Mon, 25 Sep 2017 10:03 am, Stefan Ram wrote: > What's the difference between ?builtins? and ?_sitebuiltins?? > > |>>> type.__module__ > |'builtins' > | > |>>> help.__module__ > |'_sitebuiltins' > > I mean the semantic difference. Why are some entities placed > into ?builtins? and some into ?_sitebuiltins?? Read the source. The _sitebuiltins module says: """ The objects used by the site module to add custom builtins. """ # Those objects are almost immortal and they keep a reference to their module # globals. Defining them in the site module would keep too many references # alive. # Note this means this module should also avoid keep things alive in its # globals. Historically, the content of _sitebuiltins.py used to be in site.py. So it's just an implementation detail: site.py was refactored to keep long-lasting objects separate from those that are ephemeral. `builtins` is the official public name of the built-in namespace. In Python 2, it was unfortunately called __builtin__. Unfortunately there is also a __builtins__ name, which is a private, CPython implementation detail. Ignore it. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Sep 24 21:23:09 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 25 Sep 2017 11:23:09 +1000 Subject: [Tutor] beginning to code References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c714da$0$14959$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c85a7d$0$14930$b1db1813$d948b532@news.astraweb.com> On Sun, 24 Sep 2017 12:37 pm, Bill wrote: >> For example, if I made "Pass-By-Reference Python" where all argument passing >> was done by reference, my language would differ from real Python: >> >> >> function(x, y) # allowed >> function(namespace.x, module.y) # allowed >> function(x + 1, 2) # FORBIDDEN: can't pass expressions or constants > > This would be okay as long as x + 1 evaluates to an object, no? Not in Pascal, no. (Pascal pre-dated objects, but by the 80s there were various forms of Pascal with objects.) Pascal requires that the actual argument passed to the var parameter be an actual variable, not a constant or expression. Technically, it must be a "L-value", something which can appear on the left hand side of an assignment and therefore something that has an address. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sun Sep 24 21:38:01 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 25 Sep 2017 11:38:01 +1000 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c85dfa$0$14949$b1db1813$d948b532@news.astraweb.com> On Mon, 25 Sep 2017 08:39 am, Gregory Ewing wrote: > Dennis Lee Bieber wrote: >> "Binding" itself tends to be Python specific terminology -- in that it "Binding" is certainly not Python-specific: https://en.wikipedia.org/wiki/Name_binding and here's an example of the term in use: https://www.gnu.org/software/sather/docs-1.2/tutorial/fortran-names.html >> is the parameter /name/ that gets bound/attached to the argument /object/. >> It is the same method as used in any Python "assignment" statement, > > Which is why I think "call by assignment" would be > a much better term! I think that suffers from the same problem as "call by binding" -- assignment is too general a word. The Pascal assignment: a := b; copies the value of b to the storage position represented by a. That's precisely the same thing that occurs when you call func(b), so one might equally say that Pascal was call by assignment. Likewise for C assignment. Pascal doesn't have "reference variables", so there is no assignment analogue to calling a function with a var parameter. But C++ does have reference variables, to we can say that assignment: a = b; is the same as function call func(b) regardless of whether C++ is using by-value or by-reference semantics. So I believe that either "call by binding" or "call by assignment" could both equally apply to any and all languages with function parameters, regardless of implementation or the language's defined semantics. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sun Sep 24 21:49:14 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Sep 2017 11:49:14 +1000 Subject: _sitebuiltins? In-Reply-To: References: <_sitebuiltins-20170925005529@ram.dialup.fu-berlin.de> Message-ID: On Mon, Sep 25, 2017 at 11:39 AM, Stefan Ram wrote: > Chris Angelico writes: >>But if anything got imported from somewhere else, you get the >>_original_ source, not the one you got it from: >>>>> from ssl import namedtuple >>>>> namedtuple.__module__ >>'collections' >>Is that good enough for what you need? It's not "where did this come >>from", but it's "where does this live". > > The problem with ?__module__? is that it is not always > a permissible prefix for a use of the name. For example, > > |>>> import builtins > | > |>>> import _sitebuiltins > | > |>>> help.__module__ > |'_sitebuiltins' > | > |>>> _sitebuiltins.help > |AttributeError: module '_sitebuiltins' has no attribute 'help' > | > |>>> builtins.help > |Type help() for interactive help, or help(object) for help about object. > > So, I am looking for something that gives me ?builtins? > in the case of ?help?. Here's where that object comes from: def sethelper(): builtins.help = _sitebuiltins._Helper() So, you're out of luck - nothing's going to point to builtins. Why do you need this? Can you, perhaps, just check the builtins for the name? Or for the object (`help in builtins.__dict__.values()`)? ChrisA From torriem at gmail.com Sun Sep 24 22:37:51 2017 From: torriem at gmail.com (Michael Torrie) Date: Sun, 24 Sep 2017 20:37:51 -0600 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> Message-ID: <6101bf0f-6b80-fb46-c937-1334344dc54e@gmail.com> On 09/24/2017 09:56 AM, Dennis Lee Bieber wrote: > "Binding" itself tends to be Python specific terminology Not so. How it's used in Python terminology is fairly closely aligned with how the word was used in my programming language theory class at uni, where it was defined in mathematical terms and lambda calculus rather than in terms of computer memory. This is one area that Python really appealed to me. Many of its concepts are more closely aligned with the theories and calculus we studied in tour theory class. I suppose this is also why Lisp (we used Scheme in our class) is so appealing to some. From greg.ewing at canterbury.ac.nz Mon Sep 25 01:17:17 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 25 Sep 2017 18:17:17 +1300 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: References: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> Message-ID: Dennis Lee Bieber wrote: > Though "assignment" differs so much between languages That's the point of the term -- it's the same as whatever assignment does in the language concerned. This is true of *every* language I know of that uses the term "call by value" in its official documentation. It's also true of those that use some other term such as "call by object" or "call by binding". -- Greg From greg.ewing at canterbury.ac.nz Mon Sep 25 01:26:49 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 25 Sep 2017 18:26:49 +1300 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <59c85dfa$0$14949$b1db1813$d948b532@news.astraweb.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <59c85dfa$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > I think that suffers from the same problem as "call by binding" -- assignment is > too general a word. If you're learning a new language, you're almost certainly going to learn how assignment works in that language before you get as far as worrying about parameter passing. If not, you need to find out. The only case where it wouldn't be appropriate is if the language doesn't have assignment, in which case "call by binding" or whatever terminology it uses for naming things would be better. -- Greg From antoon.pardon at vub.be Mon Sep 25 04:50:00 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 25 Sep 2017 10:50:00 +0200 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> Message-ID: <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> Op 25-09-17 om 00:39 schreef Gregory Ewing: > Dennis Lee Bieber wrote: >> ????"Binding" itself tends to be Python specific terminology -- in >> that it >> is the parameter /name/ that gets bound/attached to the argument >> /object/. >> It is the same method as used in any Python "assignment" statement, > > Which is why I think "call by assignment" would be > a much better term! > But since the semantics of an assignment depends on the language, "call by assignment" says nothing abouth the semantics of the parameter passing. -- Antoon Pardon From antoon.pardon at vub.be Mon Sep 25 05:32:16 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 25 Sep 2017 11:32:16 +0200 Subject: [Tutor] beginning to code In-Reply-To: <59c714da$0$14959$b1db1813$d948b532@news.astraweb.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c714da$0$14959$b1db1813$d948b532@news.astraweb.com> Message-ID: Op 24-09-17 om 04:13 schreef Steve D'Aprano: >> and consider >> that something else has to happen as an alternative, and (2) understand >> that in Python, objects don't have names, they have references (which >> have names). The rest could be "implementation dependent" (no?) > No. > > There are many different alternatives for "something else", and while some of > them may be behave the same in some circumstances, they do not behave the same > in all circumstances. Any interpreter calling itself Python would be expected > to match the behaviour of the reference implementation, CPython. > > For example, if I made "Pass-By-Reference Python" where all argument passing was > done by reference, my language would differ from real Python: Can you explain, what you mean by "Pass-By-Reference" as far a I understand, pass by reference means that the parameter of the function becomes an alias of the argument, so that if the entity is mutated through one name that mutation is visible through the other name. > function(x, y) # allowed > function(namespace.x, module.y) # allowed > function(x + 1, 2) # FORBIDDEN: can't pass expressions or constants Pass by reference, doesn't imply the above is forbidden. A language can define, that the "x + 1" will produce an new entity and that a reference to that entity will be passed. > Obviously that's not Python! > > On the other hand, "Pass-By-Name Python" would allow passing expressions and > constants, but will differ in other ways. > > Assignment by reference would mean that name binding was an *alias* operation: It is. > module.y = 1 > x = module.y # x is an alias for the name "module.y" > x = 2 # binds 2 to module.y The comment in the above statement is wrong. You ignore the fact that the assignment is an alias operation and so that through the assignment x now becomes a new alias for the value 2. Your statement should be: x = 2 # x is now an alias for an object with value 2. Your comment would have been true, if that assignment would have been a copy-over assignment. This is a confusion I see you make regularly. When making statements about what effect reference parameters or an alias operation would have, you at some point depend on the assignment being a copy-over operation, as you did here. The fact that assignment is an *alias* opertation is illustrated by the fact that a mutation through one name, is visible through the other name. -- Antoon Pardon. From marko at pacujo.net Mon Sep 25 05:41:28 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 25 Sep 2017 12:41:28 +0300 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> Message-ID: <877ewn9ktz.fsf@elektro.pacujo.net> Antoon Pardon : > the semantics of an assignment depends on the language I've only seen one kind of assignment in the general-purpose programming languages I know, maybe with the exception of Prolog and Rust. So the assignment is the same everywhere, only the evaluation model varies. In classic C, expressions evaluate to integers, double-precision floating-point numbers or pointers. In Python, all expressions evaluate pointers. For example, in C, the expression 1 + 2 takes two integers and produces a third one. By contrast, the same Python expression takes two pointers and produces a third one (while possibly generating a number of objects in the process). Analogously, C lvalues can store various types of value. In Python, all "lvalues" store a pointer. I haven't wanted to use the word "value" above because it is ambiguous and confusing in the context of this discussion. Marko From antoon.pardon at rece.vub.ac.be Mon Sep 25 06:05:24 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 25 Sep 2017 12:05:24 +0200 Subject: [Tutor] beginning to code In-Reply-To: <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> References: <1505319485l.29425864l.0l@psu.edu> <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> Message-ID: Op 22-09-17 om 15:30 schreef Steve D'Aprano: > On Fri, 22 Sep 2017 10:27 pm, Marko Rauhamaa wrote: > >> ram at zedat.fu-berlin.de (Stefan Ram): >> >>> Marko Rauhamaa writes: >>>> swap(slot_ref(locals(), "x"), slot_ref(locals(), "y")) >>> You need to be able to write the call as >>> >>> swap( x, y ) >> Why? > Because that's the whole point of the exercise. > > The exercise isn't to demonstrate how to swap two variables. In Python, that's > easy: > > a, b = b, a > > The exercise is to demonstrate pass by reference semantics. That requires > demonstrating the same semantics as the Pascal swap procedure: No it doesn't. Pass by reference doesn't imply being able to write a swap function. A swap function as possible in pascal requires two conditions. 1) Pass by reference 2) Copy-over assignment. Since python doesn't have the second, the fact that you can't write a swap function doesn't imply you don't have pass by reference. > > procedure swap(var a, var b): > begin > tmp := a; > a := b; > b := tmp; > end; > > (ignoring the type declarations for brevity). > > Call by reference semantics enable you to call swap(x, y) to swap x and y in the > caller's scope. You don't call swap('x', 'y', scope_of_x, scope_of_y) or any > other variant. That isn't call by reference semantics. No it doesn't, not unless the assignment mutates by copying the value on the right side over the variable on the left side. Your assertions about call by reference only apply in a particular context, one where assignments mutate the variable that is assigned to. This is a point you continuously ignore. -- Antoon Pardon. From antoon.pardon at rece.vub.ac.be Mon Sep 25 06:15:57 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 25 Sep 2017 12:15:57 +0200 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <877ewn9ktz.fsf@elektro.pacujo.net> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> Message-ID: Op 25-09-17 om 11:41 schreef Marko Rauhamaa: > Antoon Pardon : > >> the semantics of an assignment depends on the language > I've only seen one kind of assignment in the general-purpose programming > languages I know, maybe with the exception of Prolog and Rust. I disagree. In languages like Pascal an asignment mutates the target that the left hand refers to, by copying over the value from the right side. In languages like python an asignment lets the target refer to a new entity. -- Antoon Pardon. From marko at pacujo.net Mon Sep 25 07:32:56 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 25 Sep 2017 14:32:56 +0300 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> Message-ID: <87poaf813r.fsf@elektro.pacujo.net> Antoon Pardon : > Op 25-09-17 om 11:41 schreef Marko Rauhamaa: >> Antoon Pardon : >> >>> the semantics of an assignment depends on the language >> I've only seen one kind of assignment in the general-purpose >> programming languages I know, maybe with the exception of Prolog and >> Rust. > > I disagree. In languages like Pascal an asignment mutates the target > that the left hand refers to, by copying over the value from the right > side. In languages like python an asignment lets the target refer to a > new entity. In Python, assignment "mutates the target" as well. It's only that in Python, the target is always a pointer. Here's proof (up to isomorphism): >>> x = object() >>> y = object() >>> id(x) 139719622467712 >>> x = y >>> id(x) 139719622467728 Meaning. Before: +---------- x ----------+ | 139719622467712 | +-----------------------+ After: +---------- x ----------+ | 139719622467728 | +-----------------------+ So we can see the contents of x have been mutated. Marko From antoon.pardon at vub.be Mon Sep 25 08:05:40 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 25 Sep 2017 14:05:40 +0200 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <87poaf813r.fsf@elektro.pacujo.net> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> Message-ID: <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> Op 25-09-17 om 13:32 schreef Marko Rauhamaa: > Antoon Pardon : > >> Op 25-09-17 om 11:41 schreef Marko Rauhamaa: >>> Antoon Pardon : >>> >>>> the semantics of an assignment depends on the language >>> I've only seen one kind of assignment in the general-purpose >>> programming languages I know, maybe with the exception of Prolog and >>> Rust. >> I disagree. In languages like Pascal an asignment mutates the target >> that the left hand refers to, by copying over the value from the right >> side. In languages like python an asignment lets the target refer to a >> new entity. > In Python, assignment "mutates the target" as well. It's only that in > Python, the target is always a pointer. Fine if you want to word it like that, the assignments in Pascal and Python are still sufficiently different. If you do A := B in Pascal, you have two different entities with equal values. If you do A = B in Python, you have one entity that is refered to by two variables/names. The difference becomes clear if you later mutate A or B. In the case of Pascal, you will have mutated one of two entities and the other entity remains the same. In the case of Python, you will have mutated the one entity that both A and B refer to and so the mutations will be visible through the other variable/name. -- Antoon Pardon. From marko at pacujo.net Mon Sep 25 08:16:52 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 25 Sep 2017 15:16:52 +0300 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> Message-ID: <87ing77z2j.fsf@elektro.pacujo.net> Antoon Pardon : > Op 25-09-17 om 13:32 schreef Marko Rauhamaa: >> In Python, assignment "mutates the target" as well. It's only that in >> Python, the target is always a pointer. > > Fine if you want to word it like that, the assignments in Pascal and > Python are still sufficiently different. > > If you do A := B in Pascal, you have two different entities with equal > values. > > If you do A = B in Python, you have one entity that is refered to by > two variables/names. Python only operates with pointers. You can operate with pointers in Pascal as well. Say I have (in Pascal): new(A); B := A Then, in Pascal, you have one entity that is referred to by two variables/names. > The difference becomes clear if you later mutate A or B. In the case > of Pascal, you will have mutated one of two entities and the other > entity remains the same. In the case of Python, you will have mutated > the one entity that both A and B refer to and so the mutations will be > visible through the other variable/name. Continuing the Pascal example above: new(A); B := A; { one entity, two names } A^ := 3; { mutate the one entity } writeln(B); A^ := 7; { mutate the one entity again } writeln(B) will output 3 7 (although I haven't programmed anything in Pascal for than 30 years so my syntax may be off). Marko From steve+python at pearwood.info Mon Sep 25 08:24:01 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 25 Sep 2017 22:24:01 +1000 Subject: [Tutor] beginning to code References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> On Mon, 25 Sep 2017 08:05 pm, Antoon Pardon wrote: > Pass by reference doesn't imply being able to > write a swap function. Really. Do you have a counter-example? > A swap function as possible in pascal requires two conditions. > > 1) Pass by reference > 2) Copy-over assignment. I don't know what you think "copy-over assignment" means, but none of DuckDuckGo, Google, Bing or Yahoo finds that term except in your post. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From antoon.pardon at vub.be Mon Sep 25 08:47:37 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 25 Sep 2017 14:47:37 +0200 Subject: [Tutor] beginning to code In-Reply-To: <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> Message-ID: Op 25-09-17 om 14:24 schreef Steve D'Aprano: > On Mon, 25 Sep 2017 08:05 pm, Antoon Pardon wrote: > >> Pass by reference doesn't imply being able to >> write a swap function. > Really. Do you have a counter-example? Python, smalltalk, scheme. > > >> A swap function as possible in pascal requires two conditions. >> >> 1) Pass by reference >> 2) Copy-over assignment. > I don't know what you think "copy-over assignment" means, but none of > DuckDuckGo, Google, Bing or Yahoo finds that term except in your post. I think it was clear enough that I was talking about the assignment semantics like in Pascal, where when you assign to a variable the value in the entity refered to, is overwritten by a new value. In contrast with assignments in Python, smalltalk, scheme where the assignment binds the name/variable to a new entity. -- Antoon Pardon. From p.f.moore at gmail.com Mon Sep 25 08:49:17 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 25 Sep 2017 13:49:17 +0100 Subject: Looking for an algorithm - calculate ingredients for a set of recipes Message-ID: I'm trying to work out a good algorithm to code a calculation I need to do. I can see brute force ways of handling the problem, but I keep getting bogged down in details, and the question seems like it's something that should have been solved plenty of times in the past, I just don't know where to look. The basic problem is that I'm trying to model a set of recipes, and calculate the amounts of base ingredients needed to produce what I require. This is actually for calculating production requirements in Minecraft, so I have recipes of the form: 1 tank = 4 bars, 4 iron, 1 glass 16 bars = 6 iron 1 chassis = 4 bars, 4 iron, 1 capacitor 1 alloy smelter = 1 chassis, 1 cauldron, 3 furnace, 4 iron 1 cauldron = 7 iron If I want to make 1 alloy smelter and 2 tanks, I need: (alloy smelter) 1 chassis 4 bars 4 iron 1 capacitor 1 cauldron 7 iron 3 furnace 4 iron (tanks) 8 bars 8 iron 2 glass Total iron (for example) = 23, plus 6 (enough for 12 bars - note that we have to make bars in batches of 16) = 29. I can model the recipes as basically a graph (a DAG). Calculating the amounts isn't too hard if we ignore the batch crafting aspect, but I also need to cater for the possibility of "I need 3 of X and 4 of Y, but I need 2 extra X to craft each Y, so I need a total of 11 X). So there's an element of feedback involved as well. I can probably come up with a viable approach given some time, but this feels like the sort of calculation that comes up a lot (basically any "recipe" based exercise - cooking, manufacturing, etc) and I feel as if I'm at risk of reinventing the wheel, which I could avoid if I only knew what the techniques I need are called. Can anyone suggest any pointers? Thanks, Paul From ned at nedbatchelder.com Mon Sep 25 08:53:14 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 25 Sep 2017 08:53:14 -0400 Subject: [Tutor] beginning to code In-Reply-To: <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> Message-ID: <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> On 9/25/17 8:24 AM, Steve D'Aprano wrote: > On Mon, 25 Sep 2017 08:05 pm, Antoon Pardon wrote: > >> Pass by reference doesn't imply being able to >> write a swap function. > Really. Do you have a counter-example? > > >> A swap function as possible in pascal requires two conditions. >> >> 1) Pass by reference >> 2) Copy-over assignment. > I don't know what you think "copy-over assignment" means, but none of > DuckDuckGo, Google, Bing or Yahoo finds that term except in your post. > > > > Would we be able to end these interminable debates if we just agree that we all know how it works, and it isn't important to come up with a simple name for what it is? It seems clear to me that "value" and "reference" are wildly vague terms, used slightly differently by each language, and by different people even in the same language if they have different perspectives. Can't we just stop? :) --Ned. From antoon.pardon at vub.be Mon Sep 25 08:54:27 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 25 Sep 2017 14:54:27 +0200 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <87ing77z2j.fsf@elektro.pacujo.net> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> <87ing77z2j.fsf@elektro.pacujo.net> Message-ID: <875d80ff-3697-3aa0-ca7a-bbd58896022b@vub.be> Op 25-09-17 om 14:16 schreef Marko Rauhamaa: > Antoon Pardon : > >> Op 25-09-17 om 13:32 schreef Marko Rauhamaa: >>> In Python, assignment "mutates the target" as well. It's only that in >>> Python, the target is always a pointer. >> Fine if you want to word it like that, the assignments in Pascal and >> Python are still sufficiently different. >> >> If you do A := B in Pascal, you have two different entities with equal >> values. >> >> If you do A = B in Python, you have one entity that is refered to by >> two variables/names. > Python only operates with pointers. You can operate with pointers in > Pascal as well. You are talking about implementation details. That under the hood you can implement it all by manipulating bits in registers and memory, doesn't contradict that the semantic model is different. -- Antoon Pardon. From rosuav at gmail.com Mon Sep 25 08:58:19 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Sep 2017 22:58:19 +1000 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <877ewn9ktz.fsf@elektro.pacujo.net> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> Message-ID: On Mon, Sep 25, 2017 at 7:41 PM, Marko Rauhamaa wrote: > Antoon Pardon : > >> the semantics of an assignment depends on the language > > I've only seen one kind of assignment in the general-purpose programming > languages I know, maybe with the exception of Prolog and Rust. > > So the assignment is the same everywhere, only the evaluation model > varies. In classic C, expressions evaluate to integers, double-precision > floating-point numbers or pointers. In Python, all expressions evaluate > pointers. And that's an assertion that isn't backed by anything in the Python specification. Where do you get that all Python expressions are pointers? That's a construct invented specifically to shoe-horn Python into "hey look it's pass by value". It's not the fundamental of the language. ChrisA From antoon.pardon at vub.be Mon Sep 25 09:15:34 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 25 Sep 2017 15:15:34 +0200 Subject: [Tutor] beginning to code In-Reply-To: <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> Message-ID: <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> Op 25-09-17 om 14:53 schreef Ned Batchelder: > On 9/25/17 8:24 AM, Steve D'Aprano wrote: >> On Mon, 25 Sep 2017 08:05 pm, Antoon Pardon wrote: >> >>> Pass by reference doesn't imply being able to >>> write a swap function. >> Really. Do you have a counter-example? >> >> >>> A swap function as possible in pascal requires two conditions. >>> >>> 1) Pass by reference >>> 2) Copy-over assignment. >> I don't know what you think "copy-over assignment" means, but none of >> DuckDuckGo, Google, Bing or Yahoo finds that term except in your post. >> >> >> >> > > Would we be able to end these interminable debates if we just agree > that we all know how it works, and it isn't important to come up with > a simple name for what it is? I'm not sure that Steve knows how it works. When he denies that the assignment is an alias operation in Python that casts an important doubt. > It seems clear to me that "value" and "reference" are wildly vague > terms, used slightly differently by each language, and by different > people even in the same language if they have different perspectives. Well in that case and considering your remark above, maybe the residents shouldn't be so eager to deny to newbees that python has call by reference. IMO the problem people have with python isn't because they may think python has call by reference but because they don't fully understand how the assignment works. The conclusion they jump to, that call by reference implies being able to write a swap function, depends on the assignment semantics in a language like Pascal. Yet that it is the assignment semantics of python and not the argument passing semantics that prohibit the writing of a swap function in Python is rarely made clear. -- Antoon Pardon From marko at pacujo.net Mon Sep 25 09:16:09 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 25 Sep 2017 16:16:09 +0300 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> <87ing77z2j.fsf@elektro.pacujo.net> <875d80ff-3697-3aa0-ca7a-bbd58896022b@vub.be> Message-ID: <87efqu9aw6.fsf@elektro.pacujo.net> Antoon Pardon : > Op 25-09-17 om 14:16 schreef Marko Rauhamaa: >> Python only operates with pointers. You can operate with pointers in >> Pascal as well. > > You are talking about implementation details. No, I'm not. I'm talking about pointers in the abstract sense, both in case of Python and Pascal. Neither language gives any hint as to the physical nature of the pointer. All Python expressions evaluate to pointers (or handles or references; call them whatever you want). All Python "lvalues" hold pointers. Marko From ian.g.kelly at gmail.com Mon Sep 25 09:23:42 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 25 Sep 2017 07:23:42 -0600 Subject: Looking for an algorithm - calculate ingredients for a set of recipes In-Reply-To: References: Message-ID: On Mon, Sep 25, 2017 at 6:49 AM, Paul Moore wrote: > I'm trying to work out a good algorithm to code a calculation I need > to do. I can see brute force ways of handling the problem, but I keep > getting bogged down in details, and the question seems like it's > something that should have been solved plenty of times in the past, I > just don't know where to look. > > The basic problem is that I'm trying to model a set of recipes, and > calculate the amounts of base ingredients needed to produce what I > require. This is actually for calculating production requirements in > Minecraft, so I have recipes of the form: > > 1 tank = 4 bars, 4 iron, 1 glass > 16 bars = 6 iron > 1 chassis = 4 bars, 4 iron, 1 capacitor > 1 alloy smelter = 1 chassis, 1 cauldron, 3 furnace, 4 iron > 1 cauldron = 7 iron > > If I want to make 1 alloy smelter and 2 tanks, I need: > > (alloy smelter) > 1 chassis > 4 bars > 4 iron > 1 capacitor > 1 cauldron > 7 iron > 3 furnace > 4 iron > (tanks) > 8 bars > 8 iron > 2 glass > > Total iron (for example) = 23, plus 6 (enough for 12 bars - note that > we have to make bars in batches of 16) = 29. > > I can model the recipes as basically a graph (a DAG). Calculating the > amounts isn't too hard if we ignore the batch crafting aspect, but I > also need to cater for the possibility of "I need 3 of X and 4 of Y, > but I need 2 extra X to craft each Y, so I need a total of 11 X). So > there's an element of feedback involved as well. > > I can probably come up with a viable approach given some time, but > this feels like the sort of calculation that comes up a lot (basically > any "recipe" based exercise - cooking, manufacturing, etc) and I feel > as if I'm at risk of reinventing the wheel, which I could avoid if I > only knew what the techniques I need are called. > > Can anyone suggest any pointers? You have a DAG, so you can sort it topologically. Then you can process it in that order so that everything that uses X will be processed before X so that when you get to X you'll know exactly how much of it you need and you don't have to worry about "feedback". For actual production, run through it in the opposite order so that you'll produce all your precursors before the things that require them. From antoon.pardon at vub.be Mon Sep 25 09:30:21 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 25 Sep 2017 15:30:21 +0200 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <87efqu9aw6.fsf@elektro.pacujo.net> References: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> <87ing77z2j.fsf@elektro.pacujo.net> <875d80ff-3697-3aa0-ca7a-bbd58896022b@vub.be> <87efqu9aw6.fsf@elektro.pacujo.net> Message-ID: Op 25-09-17 om 15:16 schreef Marko Rauhamaa: > Antoon Pardon : > >> Op 25-09-17 om 14:16 schreef Marko Rauhamaa: >>> Python only operates with pointers. You can operate with pointers in >>> Pascal as well. >> You are talking about implementation details. > No, I'm not. I'm talking about pointers in the abstract sense, both in > case of Python and Pascal. Neither language gives any hint as to the > physical nature of the pointer. Yes you are. Python doesn't have pointers at the language level. So if you start talking pointers you are talking about implementations however abstract. -- Antoon Pardon From ned at nedbatchelder.com Mon Sep 25 09:37:17 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 25 Sep 2017 09:37:17 -0400 Subject: [Tutor] beginning to code In-Reply-To: <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> Message-ID: <9ff212ad-da8d-2c1b-07be-823f03a37d46@nedbatchelder.com> On 9/25/17 9:15 AM, Antoon Pardon wrote: > Op 25-09-17 om 14:53 schreef Ned Batchelder: >> On 9/25/17 8:24 AM, Steve D'Aprano wrote: >>> On Mon, 25 Sep 2017 08:05 pm, Antoon Pardon wrote: >>> >>>> Pass by reference doesn't imply being able to >>>> write a swap function. >>> Really. Do you have a counter-example? >>> >>> >>>> A swap function as possible in pascal requires two conditions. >>>> >>>> 1) Pass by reference >>>> 2) Copy-over assignment. >>> I don't know what you think "copy-over assignment" means, but none of >>> DuckDuckGo, Google, Bing or Yahoo finds that term except in your post. >>> >>> >>> >>> >> Would we be able to end these interminable debates if we just agree >> that we all know how it works, and it isn't important to come up with >> a simple name for what it is? > I'm not sure that Steve knows how it works. When he denies that the assignment is > an alias operation in Python that casts an important doubt. I can assure you that Steve knows how it works. Again, the disagreement is almost certainly over the semantics of the word "alias." > >> It seems clear to me that "value" and "reference" are wildly vague >> terms, used slightly differently by each language, and by different >> people even in the same language if they have different perspectives. > Well in that case and considering your remark above, maybe the residents > shouldn't be so eager to deny to newbees that python has call by reference. You're still trying to get people to agree to a label like "call by reference."? This is where the disagreement comes from. --Ned. From p.f.moore at gmail.com Mon Sep 25 10:20:53 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 25 Sep 2017 15:20:53 +0100 Subject: Looking for an algorithm - calculate ingredients for a set of recipes In-Reply-To: References: Message-ID: On 25 September 2017 at 14:23, Ian Kelly wrote: > You have a DAG, so you can sort it topologically. Then you can process > it in that order so that everything that uses X will be processed > before X so that when you get to X you'll know exactly how much of it > you need and you don't have to worry about "feedback". For actual > production, run through it in the opposite order so that you'll > produce all your precursors before the things that require them. Hmm, yes that makes sense. I was thinking of a topological sort in the other direction (ingredient before product) and that way round doesn't work. For some reason, when thinking about topological sorts, I tend to get fixated on one direction and forget they are actually reversible... Paul From marko at pacujo.net Mon Sep 25 10:26:36 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 25 Sep 2017 17:26:36 +0300 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> Message-ID: <87a81i97mr.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Sep 25, 2017 at 7:41 PM, Marko Rauhamaa wrote: >> In Python, all expressions evaluate pointers. > > And that's an assertion that isn't backed by anything in the Python > specification. Where do you get that all Python expressions are > pointers? That's not what I said. I said all expressions *evaluate to* pointers. As for the specification, it doesn't make use of the word "pointer:" Instead, it uses (English) expressions like: is bound to the object is rebound when talking about "names" (aka variables). It also uses circular definitions when talking about dicts and lists: That object is then asked to assign the assigned object to the given attribute the sequence is asked to assign the assigned object to its item with that index. The (English) expression: The name is bound to the object. is just another way of saying: A pointer to the object is stored in the variable. Of course, I'm using terminology that is not conventional in Python circles. However, I'm doing it to demonstrate that there's nothing particularly different between Python's assignment semantics and those of, say, Pascal. Python's assignment semantics are wholly contained by those of Pascal. Marko From marko at pacujo.net Mon Sep 25 10:29:45 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 25 Sep 2017 17:29:45 +0300 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> <87ing77z2j.fsf@elektro.pacujo.net> <875d80ff-3697-3aa0-ca7a-bbd58896022b@vub.be> <87efqu9aw6.fsf@elektro.pacujo.net> Message-ID: <8760c697hi.fsf@elektro.pacujo.net> Antoon Pardon : > Op 25-09-17 om 15:16 schreef Marko Rauhamaa: >> No, I'm not. I'm talking about pointers in the abstract sense, both in >> case of Python and Pascal. Neither language gives any hint as to the >> physical nature of the pointer. > > Yes you are. Python doesn't have pointers at the language level. So if > you start talking pointers you are talking about implementations > however abstract. It is difficult to say what is the "native" Python term for the thing. "Binding," maybe? The language spec fails to give it a name. However, when comparing different languages, you had better unify the terminology or you'll be confused by purely terminological issues. Marko From steve+python at pearwood.info Mon Sep 25 10:35:07 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 26 Sep 2017 00:35:07 +1000 Subject: _sitebuiltins? References: <_sitebuiltins-20170925005529@ram.dialup.fu-berlin.de> Message-ID: <59c9141c$0$14944$b1db1813$d948b532@news.astraweb.com> On Mon, 25 Sep 2017 11:39 am, Stefan Ram wrote: > The problem with ?__module__? is that it is not always > a permissible prefix for a use of the name. For example, That's not what __module__ is intended for. Just because an object obj was created inside module M doesn't mean it is accessible as M.obj. __module__ is not a promise that "obj" is a name in that namespace. __module__ is a dunder attribute. That means, unless otherwise documented, it exists for the use of the Python interpreter, not client code. [...] > |>>> builtins.help > |Type help() for interactive help, or help(object) for help about object. > > So, I am looking for something that gives me ?builtins? > in the case of ?help?. You won't find one, because `help` is injected into the builtins module at runtime, but the site.py module. If you read the source of site.py, you will find the code that does the injection, but there's no attribute of `help` that will tell you this. Consider: py> import statistics, builtins # Python 2 use __builtin__ py> builtins.average = statistics.mean py> assert average is statistics.mean Given that average, in the builtins module, is the same function object as mean, in the statistics module, what should average.__module__ say? py> average.__module__ 'statistics' -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Mon Sep 25 10:39:36 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Sep 2017 00:39:36 +1000 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <87a81i97mr.fsf@elektro.pacujo.net> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87a81i97mr.fsf@elektro.pacujo.net> Message-ID: On Tue, Sep 26, 2017 at 12:26 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Mon, Sep 25, 2017 at 7:41 PM, Marko Rauhamaa wrote: >>> In Python, all expressions evaluate pointers. >> >> And that's an assertion that isn't backed by anything in the Python >> specification. Where do you get that all Python expressions are >> pointers? > > That's not what I said. I said all expressions *evaluate to* pointers. Sorry, that was my bad in the terminology. But where do you get that all Python expressions evaluate to pointers? > As for the specification, it doesn't make use of the word "pointer:" > > nt-statements> > > Instead, it uses (English) expressions like: > > is bound to the object > is rebound > > when talking about "names" (aka variables). Yeah exactly. It doesn't say anything about them being pointers. Because they aren't. > It also uses circular definitions when talking about dicts and lists: > > That object is then asked to assign the assigned object to the given > attribute > > the sequence is asked to assign the assigned object to its item with > that index. Technically, that's correct. When you use a statement like: foo[bar] = quux what it does is ask the object *foo* to assign *quux* to the item represented by *bar*. > The (English) expression: > > The name is bound to the object. > > is just another way of saying: > > A pointer to the object is stored in the variable. Where does this come from? If the name "Rosuav" refers to me, does that mean, in English, that there is a pointer to me stored in the variable named "Rosuav"? English isn't implemented in C or Pascal. > Of course, I'm using terminology that is not conventional in Python > circles. However, I'm doing it to demonstrate that there's nothing > particularly different between Python's assignment semantics and those > of, say, Pascal. Python's assignment semantics are wholly contained by > those of Pascal. As long as you start by defining everything in terms of Pascal, yes, you can then prove that everything is contained in Pascal semantics. But you have yet to show how you can jump from "name binding" to "pointer" using anything from the Python documentation. ChrisA From steve+python at pearwood.info Mon Sep 25 10:45:29 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 26 Sep 2017 00:45:29 +1000 Subject: _sitebuiltins? References: <_sitebuiltins-20170925005529@ram.dialup.fu-berlin.de> Message-ID: <59c9168a$0$14950$b1db1813$d948b532@news.astraweb.com> On Mon, 25 Sep 2017 12:05 pm, Stefan Ram wrote: > So when after > > import builtins > > the expression > > builtins.dir > > yields a value, then ?dir? must be in ?builtins?. dir is in builtins *now*, but that doesn't tell you where it came from. Anything can be added, or removed, from builtins. py> import builtins py> del builtins.len # Don't do this unless you know what you are doing. py> len('') Traceback (most recent call last): File "", line 1, in NameError: name 'len' is not defined In one sense, builtins is just an ordinary module, and like all modules it is writable. In another sense, it is special: Python always searches builtins before raising NameError. Also, builtins is not a physical module on disk: py> math.__file__ '/usr/local/lib/python3.5/lib-dynload/math.cpython-35m-i386-linux-gnu.so' but: py> builtins.__file__ Traceback (most recent call last): File "", line 1, in AttributeError: module 'builtins' has no attribute '__file__' > Now, I was just curious whether I also can get the > same information directly from a name. If so, I would > like to publish this in my course just to clarify > the relationship between such names and their modules. There is very little relationship between the object and the module you access it though. For many functions, if you access it: spam.foo() then foo.__module__ will be 'spam'. But that's not a promise. It just means that the foo function happened to have been created inside the foo.py or foo.so file (or foo.dll on Windows?) but that isn't always the case. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From p.f.moore at gmail.com Mon Sep 25 11:07:46 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 25 Sep 2017 16:07:46 +0100 Subject: Looking for an algorithm - calculate ingredients for a set of recipes In-Reply-To: References: Message-ID: On 25 September 2017 at 15:20, Paul Moore wrote: > On 25 September 2017 at 14:23, Ian Kelly wrote: >> You have a DAG, so you can sort it topologically. Then you can process >> it in that order so that everything that uses X will be processed >> before X so that when you get to X you'll know exactly how much of it >> you need and you don't have to worry about "feedback". For actual >> production, run through it in the opposite order so that you'll >> produce all your precursors before the things that require them. > > Hmm, yes that makes sense. I was thinking of a topological sort in the > other direction (ingredient before product) and that way round doesn't > work. For some reason, when thinking about topological sorts, I tend > to get fixated on one direction and forget they are actually > reversible... Thank you. With that hint, the problem turned out to be remarkably simple. If anyone is interested, here's the basic approach: import networkx as nx G = nx.DiGraph() G.add_edge("Tank", "Bars", qty=4) G.add_edge("Tank", "Iron", qty=4) G.add_edge("Tank", "Glass", qty=1) G.add_edge("Bars", "Iron", qty=6, batch=16) G.add_edge("Chassis", "Bars", qty=4) G.add_edge("Chassis", "Iron", qty=4) G.add_edge("Chassis", "Capacitor", qty=1) G.add_edge("Alloy Smelter", "Chassis", qty=1) G.add_edge("Alloy Smelter", "Cauldron", qty=1) G.add_edge("Alloy Smelter", "Furnace", qty=3) G.add_edge("Alloy Smelter", "Iron", qty=4) G.add_edge("Cauldron", "Iron", qty=7) from collections import defaultdict need = defaultdict(int) need["Alloy Smelter"] = 1 need["Tank"] = 2 import math for item in nx.topological_sort(G): for ingredient in G[item]: edge = G[item][ingredient] if "batch" in edge: # Round up batches = math.ceil(need[item] / edge["batch"]) else: batches = need[item] need[ingredient] += batches * G[item][ingredient]["qty"] print(need) Paul From dvl at psu.edu Mon Sep 25 11:51:20 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Mon, 25 Sep 2017 11:51:20 -0400 Subject: python console menu level looping In-Reply-To: mailman.132.1506344001.10703.python-list@python.org References: Message-ID: <1506354679l.23658578l.0l@psu.edu> On Mon, Sep 24, 2017 09:41 PM, Daiyue Weng wrote: > Hi, I tried to make a menu using print statements in Python 3. The code is >as follows, > >print('insert data into: ') >data_insert_method = ['new collection', 'existing collection'] >for index, elem in enumerate(data_insert_method): >print(index, '-', elem) > >while 1: >how_to_insert = input('Choose a method for inserting data: ') >if how_to_insert: >try: >how_to_insert = int(how_to_insert) >how_to_insert = data_insert_method[how_to_insert] >break >except ValueError: >print('Please type in an integer corresponding to the data insert method') >continue >except IndexError: >print('insert method index out of range') >continue > >if how_to_insert == 'new collection': > >print('Set up collection name : ') >db_name_setup = ['manual setup', 'return to the main menu'] >for index, elem in enumerate(db_name_setup): >print(index, '-', elem) > >while 1: >how_to_setup = input('Choose a method for setting up collection: ') >if how_to_setup: >try: >how_to_setup = int(how_to_setup) >how_to_setup = db_name_setup[how_to_setup] >break >except ValueError: >print('Please type in an integer corresponding to the collection setup >method') >continue >except IndexError: >print('collection setup method index out of range') >continue > >if how_to_setup == 'manual setup': >print('Please type in collection name: ') >elif how_to_setup == 'return to main menu': >print('return to main menu') > >It is a 2-level menu, on the 2nd level menu 'new collection', there is an >option - 'return to the main menu', I am wondering how to loop back to the >1st level menu, i.e. ['new collection', 'existing collection'], >whenever 'return >to the main menu' is selected. > As one of those pesky teacher purists, my first response is 'ick'. I see 'break' statements used for 'normal' loop exits. I see 'continue' statements that have no effect, so serve no purpose. I see lists being used just for display purposes, and not to actually solve any problem and then the question about 'how to loop back' at the end -- if you want to go from the bottom of a loop to the top of loop, all you have to do is make sure they are the same loop I would take this approach: I am inserting .'s to indent, because I do not trust my mailer to preserve the indentation data_insert_method = ['exit program',new collection','existing collection'] db_name_setup = ['return to previous menu','manual setup'] first_menu = -1 # feed the first loop while first_menu != 0:: . . for counterin range(len(data_insert_method)): . . . . index = (counter+1) % len(data_insert_method) . . . . print(index,'-',data_insert_method(index) . . . . # the quit option is always 0, and appears last . . . . # obtain and verify integer input here . . . . if first_menu == 1: # new collection . . . . . . second_menu = -1 . . . . . . while second_menu != 0: . . . . . . . . # the same thing as the outer loop, just nested . . . . . . . < trim > . . . . elif first_menu == 2: # existing collection There are still some wide open design problems here: It seems the only difference between 'new collection' and 'existing collection' is whether data already exists. But the code structure as presented seems to suggest that there will be one whole section to the program that works on an empty set, and different whole section that works on a non-emtpty set -- which suggests a humongous amount of unnecessary code duplication. Do you really expect to go back to the outer menu for 'new collection' more than once, when running this program, or does it seem more likely that initalizing an empty data base would happen only once at program startup, after which it behaves just like an 'existing collection' with less data? As someone else pointed out, your tests along the lines of if how_to_insert == 'new collection': are error prone, just from typing errors. If you are going to have a user type in discrete integers, you might as well just test using those integers. On the other hand, if you intend to make the code's decisions appear to be self-documenting, then skip the integers completely, and instead use string inputs, like single letters or short keywords. That would then eliminate any worry about ValueErrors. A dictionary can easily associate the short inputs with the longer method descriptions, and could even conceivably link directly to a function object. Roger Christman Pennsylvania State University From steve+python at pearwood.info Mon Sep 25 12:29:28 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 26 Sep 2017 02:29:28 +1000 Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> Message-ID: <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> On Mon, 25 Sep 2017 10:53 pm, Ned Batchelder wrote: > Would we be able to end these interminable debates if we just agree that > we all know how it works, If only that were true. Not everyone understands Python semantics (or for that matter, Java/Swift/language of your choice) and I still come across people confused by the pass by value/reference false dichotomy and which applies to . > and it isn't important to come up with a > simple name for what it is? Isn't it? I find it really difficult to understand people when the meanings they apply to words are not the same as the ones I use. Or perhaps I should say: I disintegrate it really snooze to pyramid running when the ribbons they apply to sandwiches are not the same as the sleep I use. *wink* > It seems clear to me that "value" and > "reference" are wildly vague terms, used slightly differently by each > language, and by different people even in the same language if they have > different perspectives. Honestly Ned, I don't think that's right. I think you're being awfully accommodating to what I see as some really egregious misuse of language. I don't think that "value", in particular, is a vague term. (I might be persuaded to accept that "reference" has some ambiguity.) Regardless of whether I'm using Python, Swift, Java, C, Pascal or Scheme, if I write something like: x = Parrot(name="Polly") (using Python syntax for simplicity) and somebody tries to tell me that the value of x is anything but a Parrot instance named "Polly", I have no time for that sort of nonsense. They might as well tell me that I'm typing this response on an elephant. > Can't we just stop? :) You take all the fun out of being right on the internet. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jpolo at mail.usf.edu Mon Sep 25 12:44:19 2017 From: jpolo at mail.usf.edu (john polo) Date: Mon, 25 Sep 2017 11:44:19 -0500 Subject: TypeError with map with no len() Message-ID: <696a2d75-7c9c-07f7-4b24-c6fd3baf3275@mail.usf.edu> Python List, I am trying to make practice data for plotting purposes. I am using Python 3.6. The instructions I have are import matplotlib.pyplot as plt import math import numpy as np t = np.arange(0, 2.5, 0.1) y1 = map(math.sin, math.pi*t) plt.plot(t,y1) However, at this point, I get a TypeError that says object of type 'map' has no len() In [6]: t Out[6]: array([ 0. ,? 0.1,? 0.2,? 0.3,? 0.4,? 0.5,? 0.6,? 0.7, 0.8,? 0.9,? 1. , ??????? 1.1,? 1.2,? 1.3,? 1.4,? 1.5,? 1.6,? 1.7,? 1.8, 1.9,? 2. ,? 2.1, ??????? 2.2,? 2.3,? 2.4]) In [7]: y1 Out[7]: In [8]: math.pi*t Out[8]: array([ 0.??????? ,? 0.31415927,? 0.62831853,? 0.9424778 , 1.25663706, ??????? 1.57079633,? 1.88495559,? 2.19911486,? 2.51327412, 2.82743339, ??????? 3.14159265,? 3.45575192,? 3.76991118,? 4.08407045, 4.39822972, ??????? 4.71238898,? 5.02654825,? 5.34070751,? 5.65486678, 5.96902604, ??????? 6.28318531,? 6.59734457,? 6.91150384,? 7.2256631 , 7.53982237]) At the start of creating y1, it appears there is an array to iterate through for the math.sin function used in map(), but y1 doesn't appear to be saving any values. I expected y1 to hold a math.sin() output for each item in math.pi*t, but it appears to be empty. Am I misunderstanding map()? Is there something else I should be doing instead to populate y1? John From python.list at tim.thechases.com Mon Sep 25 12:52:55 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 25 Sep 2017 11:52:55 -0500 Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] In-Reply-To: <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: <20170925115255.7dd0c88f@bigbox.christie.dr> On 2017-09-26 02:29, Steve D'Aprano wrote: > x = Parrot(name="Polly") > > (using Python syntax for simplicity) and somebody tries to tell me > that the value of x is anything but a Parrot instance named "Polly", So this is a Polly-morphic constructor? -tkc From ned at nedbatchelder.com Mon Sep 25 12:54:46 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 25 Sep 2017 12:54:46 -0400 Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] In-Reply-To: <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: On 9/25/17 12:29 PM, Steve D'Aprano wrote: > Regardless of whether I'm using Python, Swift, Java, C, Pascal or Scheme, if I > write something like: > > x = Parrot(name="Polly") > > (using Python syntax for simplicity) and somebody tries to tell me that the > value of x is anything but a Parrot instance named "Polly", I have no time for > that sort of nonsense. They might as well tell me that I'm typing this response > on an elephant. But in this line: ??? x = 2 + 2 You can say, ??? the value of x is 4 or, ??? the value of x is an int object with a value of 4 or, ??? the value of x is a reference to an int object with a value of 4, and in some ways, each of those is a correct statement. They are different perspectives on the same complicated abstract relationships inside your program.? Most of the disagreements in this thread stem from someone picking one of those three statements and insisting that it is *the* right statement, or from differing interpretations of words like value, reference, pointer, alias, etc. Software gets complicated because it involves multiple levels of abstraction layered on top of each other.? We might as well be arguing like this: ??? A: "The gas pedal makes the car go" ??? B: "Nonsense! The gas pedal supplies fuel to the engine, it's the engine that makes the car go" ??? C: "None of you know what you are talking about! The engine merely turns the axle. It's the wheels that make the car go!" ??? D: "The wheels only work because of the friction between rubber and asphalt!" etc etc etc. --Ned. From steve+python at pearwood.info Mon Sep 25 12:55:57 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 26 Sep 2017 02:55:57 +1000 Subject: calling __del__ [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c9351f$0$14936$b1db1813$d948b532@news.astraweb.com> On Sun, 24 Sep 2017 09:13 am, Bill wrote: [context snipped for brevity] > I agree (I was a bit hasty in my choice of words); but if they didn't > "have" these references, it would be difficult, though not impossible, > to refer to them. Also keep in mind that the garbage collector keeps > track, generally, of how many there are for each object! So from the > gc's point of view, objects (definitely) "have" references. Unfortunately there's some ambiguity in the English word "have". Webster's dictionary (1913) lists at least twelve distinct meanings. WordNet lists nineteen. If we consider "have" in the sense of possession, then objects don't have references. If they did, you could ask an object what names they were known as, and they could tell you: # this doesn't work! a = 99 b = c = a a.names() # returns ['a', 'b', 'c'] You can't do that in Python. But in another sense, ironically one which isn't listed by either Webster's or WordNet, objects do have references. The closest meaning I see is: 7: have a personal or business relationship with someone; "have a postdoc"; "have an assistant"; "have a lover" Its not a *personal* or *business* relationship, but there is a relationship between the reference and the object. > Next, what will Egg.__del__() do? : ) For the record, you shouldn't call dunder ("Double UNDERscore") methods directly unless you know what you're doing. You should consider them for Python's use only, unless explicitly told differently. Calling __del__ directly is *especially* fraught with problems. It does not delete the object. It just runs the destructor, but leaving the object alive but in a potentially unusable state. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ned at nedbatchelder.com Mon Sep 25 12:56:42 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 25 Sep 2017 12:56:42 -0400 Subject: TypeError with map with no len() In-Reply-To: <696a2d75-7c9c-07f7-4b24-c6fd3baf3275@mail.usf.edu> References: <696a2d75-7c9c-07f7-4b24-c6fd3baf3275@mail.usf.edu> Message-ID: On 9/25/17 12:44 PM, john polo wrote: > Python List, > > I am trying to make practice data for plotting purposes. I am using > Python 3.6. The instructions I have are > > import matplotlib.pyplot as plt > import math > import numpy as np > t = np.arange(0, 2.5, 0.1) > y1 = map(math.sin, math.pi*t) > plt.plot(t,y1) > > However, at this point, I get a TypeError that says > > object of type 'map' has no len() > > In [6]: t > Out[6]: > array([ 0. ,? 0.1,? 0.2,? 0.3,? 0.4,? 0.5,? 0.6,? 0.7, 0.8,? 0.9, 1. , > ??????? 1.1,? 1.2,? 1.3,? 1.4,? 1.5,? 1.6,? 1.7,? 1.8, 1.9,? 2. , 2.1, > ??????? 2.2,? 2.3,? 2.4]) > In [7]: y1 > Out[7]: > In [8]: math.pi*t > Out[8]: > array([ 0.??????? ,? 0.31415927,? 0.62831853,? 0.9424778 , 1.25663706, > ??????? 1.57079633,? 1.88495559,? 2.19911486,? 2.51327412, 2.82743339, > ??????? 3.14159265,? 3.45575192,? 3.76991118,? 4.08407045, 4.39822972, > ??????? 4.71238898,? 5.02654825,? 5.34070751,? 5.65486678, 5.96902604, > ??????? 6.28318531,? 6.59734457,? 6.91150384,? 7.2256631 , 7.53982237]) > > At the start of creating y1, it appears there is an array to iterate > through for the math.sin function used in map(), but y1 doesn't appear > to be saving any values. I expected y1 to hold a math.sin() output for > each item in math.pi*t, but it appears to be empty. Am I > misunderstanding map()? Is there something else I should be doing > instead to populate y1? In Python 2, map() produced a list. In Python 3, it returns a lazy iterator instead.? You can run the iterator with list(): ??? y1 = list(map(math.sin, math.pi*t)) --Ned. From tjreedy at udel.edu Mon Sep 25 13:01:07 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 25 Sep 2017 13:01:07 -0400 Subject: TypeError with map with no len() In-Reply-To: <696a2d75-7c9c-07f7-4b24-c6fd3baf3275@mail.usf.edu> References: <696a2d75-7c9c-07f7-4b24-c6fd3baf3275@mail.usf.edu> Message-ID: On 9/25/2017 12:44 PM, john polo wrote: > Python List, > > I am trying to make practice data for plotting purposes. I am using > Python 3.6. The instructions I have are > > import matplotlib.pyplot as plt > import math > import numpy as np > t = np.arange(0, 2.5, 0.1) > y1 = map(math.sin, math.pi*t) Change to y1 = list(map(math.sin, math.pi*t)) or y1 = tuple(map(math.sin, math.pi*t)) (Does not make much difference.) > plt.plot(t,y1) or plt.plot(t, list(y1)) > However, at this point, I get a TypeError that says > > object of type 'map' has no len() In 3.x, map returns an iterator. plot needs a sequence. > In [6]: t > Out[6]: > array([ 0. ,? 0.1,? 0.2,? 0.3,? 0.4,? 0.5,? 0.6,? 0.7, 0.8,? 0.9,? 1. , > ??????? 1.1,? 1.2,? 1.3,? 1.4,? 1.5,? 1.6,? 1.7,? 1.8, 1.9,? 2. ,? 2.1, > ??????? 2.2,? 2.3,? 2.4]) > In [7]: y1 > Out[7]: > In [8]: math.pi*t > Out[8]: > array([ 0.??????? ,? 0.31415927,? 0.62831853,? 0.9424778 , 1.25663706, > ??????? 1.57079633,? 1.88495559,? 2.19911486,? 2.51327412, 2.82743339, > ??????? 3.14159265,? 3.45575192,? 3.76991118,? 4.08407045, 4.39822972, > ??????? 4.71238898,? 5.02654825,? 5.34070751,? 5.65486678, 5.96902604, > ??????? 6.28318531,? 6.59734457,? 6.91150384,? 7.2256631 , 7.53982237]) > > At the start of creating y1, it appears there is an array to iterate > through for the math.sin function used in map(), but y1 doesn't appear > to be saving any values. I expected y1 to hold a math.sin() output for > each item in math.pi*t, but it appears to be empty. Am I > misunderstanding map()? See comment 3 above. >Is there something else I should be doing > instead to populate y1? See comment 1 (or 2) above. -- Terry Jan Reedy From __peter__ at web.de Mon Sep 25 13:02:49 2017 From: __peter__ at web.de (Peter Otten) Date: Mon, 25 Sep 2017 19:02:49 +0200 Subject: TypeError with map with no len() References: <696a2d75-7c9c-07f7-4b24-c6fd3baf3275@mail.usf.edu> Message-ID: john polo wrote: > Python List, > > I am trying to make practice data for plotting purposes. I am using > Python 3.6. The instructions I have are > > import matplotlib.pyplot as plt > import math > import numpy as np > t = np.arange(0, 2.5, 0.1) > y1 = map(math.sin, math.pi*t) > plt.plot(t,y1) > > However, at this point, I get a TypeError that says > > object of type 'map' has no len() > > In [6]: t > Out[6]: > array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , > 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. , 2.1, > 2.2, 2.3, 2.4]) > In [7]: y1 > Out[7]: > In [8]: math.pi*t > Out[8]: > array([ 0. , 0.31415927, 0.62831853, 0.9424778 , 1.25663706, > 1.57079633, 1.88495559, 2.19911486, 2.51327412, 2.82743339, > 3.14159265, 3.45575192, 3.76991118, 4.08407045, 4.39822972, > 4.71238898, 5.02654825, 5.34070751, 5.65486678, 5.96902604, > 6.28318531, 6.59734457, 6.91150384, 7.2256631 , 7.53982237]) > > At the start of creating y1, it appears there is an array to iterate > through for the math.sin function used in map(), but y1 doesn't appear > to be saving any values. I expected y1 to hold a math.sin() output for > each item in math.pi*t, but it appears to be empty. Am I > misunderstanding map()? Is there something else I should be doing > instead to populate y1? map() is "lazy" in Python 3, i. e. it calculates the values when you iterate over it, not before: >>> def noisy_square(x): ... print("calculating {0} * {0}".format(x)) ... return x * x ... >>> squares = map(noisy_square, [1, 3, 2]) >>> for y in squares: ... print(y) ... calculating 1 * 1 1 calculating 3 * 3 9 calculating 2 * 2 4 While you can convert y1 to a list with y1 = list(y1) the better approach is to use numpy: y1 = np.sin(t * math.pi) Now y1 is a numpy.array and can be fed to pyplot.plot() directly. From p.f.moore at gmail.com Mon Sep 25 13:03:19 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 25 Sep 2017 18:03:19 +0100 Subject: TypeError with map with no len() In-Reply-To: <696a2d75-7c9c-07f7-4b24-c6fd3baf3275@mail.usf.edu> References: <696a2d75-7c9c-07f7-4b24-c6fd3baf3275@mail.usf.edu> Message-ID: You're using Python 3, and I suspect that you're working from instructions that assume Python 2. In Python 3, the result of map() is a generator, not a list (which is what Python 2's map returned). In order to get an actual list (which appears to be what you need for your plot call) you just need to call the list constructor: y1 = list(map(math.sin, math.pi*t)) Although given that you're using numpy, it may be that there's a more idiomatic numpy way of doing this. I'm not a numpy expert though, so I can't help on that. Paul On 25 September 2017 at 17:44, john polo wrote: > Python List, > > I am trying to make practice data for plotting purposes. I am using Python > 3.6. The instructions I have are > > import matplotlib.pyplot as plt > import math > import numpy as np > t = np.arange(0, 2.5, 0.1) > y1 = map(math.sin, math.pi*t) > plt.plot(t,y1) > > However, at this point, I get a TypeError that says > > object of type 'map' has no len() > > In [6]: t > Out[6]: > array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , > 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. , 2.1, > 2.2, 2.3, 2.4]) > In [7]: y1 > Out[7]: > In [8]: math.pi*t > Out[8]: > array([ 0. , 0.31415927, 0.62831853, 0.9424778 , 1.25663706, > 1.57079633, 1.88495559, 2.19911486, 2.51327412, 2.82743339, > 3.14159265, 3.45575192, 3.76991118, 4.08407045, 4.39822972, > 4.71238898, 5.02654825, 5.34070751, 5.65486678, 5.96902604, > 6.28318531, 6.59734457, 6.91150384, 7.2256631 , 7.53982237]) > > At the start of creating y1, it appears there is an array to iterate through > for the math.sin function used in map(), but y1 doesn't appear to be saving > any values. I expected y1 to hold a math.sin() output for each item in > math.pi*t, but it appears to be empty. Am I misunderstanding map()? Is there > something else I should be doing instead to populate y1? > > > John > > -- > https://mail.python.org/mailman/listinfo/python-list From antoon.pardon at rece.vub.ac.be Mon Sep 25 13:04:41 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 25 Sep 2017 19:04:41 +0200 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <8760c697hi.fsf@elektro.pacujo.net> References: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> <87ing77z2j.fsf@elektro.pacujo.net> <875d80ff-3697-3aa0-ca7a-bbd58896022b@vub.be> <87efqu9aw6.fsf@elektro.pacujo.net> <8760c697hi.fsf@elektro.pacujo.net> Message-ID: <6c27765b-4494-d296-34f0-e716126630d0@rece.vub.ac.be> On 25-09-17 16:29, Marko Rauhamaa wrote: > Antoon Pardon : > >> Op 25-09-17 om 15:16 schreef Marko Rauhamaa: >>> No, I'm not. I'm talking about pointers in the abstract sense, both in >>> case of Python and Pascal. Neither language gives any hint as to the >>> physical nature of the pointer. >> >> Yes you are. Python doesn't have pointers at the language level. So if >> you start talking pointers you are talking about implementations >> however abstract. > > It is difficult to say what is the "native" Python term for the thing. > "Binding," maybe? The language spec fails to give it a name. > > However, when comparing different languages, you had better unify the > terminology or you'll be confused by purely terminological issues. Fine, you have two mappings, a mapping from names to identities and a mapping from identities to values. In languages like C, Pascal, ... an assignment changes the mapping between the identities and the values. In languages like Python, Smalltalk, ... an assignment changes the mapping between the names and the identities. -- Antoon Pardon From grant.b.edwards at gmail.com Mon Sep 25 13:11:45 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 25 Sep 2017 17:11:45 +0000 (UTC) Subject: TypeError with map with no len() References: <696a2d75-7c9c-07f7-4b24-c6fd3baf3275@mail.usf.edu> Message-ID: On 2017-09-25, john polo wrote: > Python List, > > I am trying to make practice data for plotting purposes. I am using > Python 3.6. The instructions I have are > > import matplotlib.pyplot as plt > import math > import numpy as np > t = np.arange(0, 2.5, 0.1) > y1 = map(math.sin, math.pi*t) > plt.plot(t,y1) > > However, at this point, I get a TypeError that says > > object of type 'map' has no len() you probably need to convert y1 from a 'map' object (a type of an iterator) to an array. y1 = map(math.sin, math.pi*t) y1 = np.fromiter(y1, float) -- Grant Edwards grant.b.edwards Yow! Will this never-ending at series of PLEASURABLE gmail.com EVENTS never cease? From antoon.pardon at rece.vub.ac.be Mon Sep 25 13:26:02 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 25 Sep 2017 19:26:02 +0200 Subject: [Tutor] beginning to code In-Reply-To: <9ff212ad-da8d-2c1b-07be-823f03a37d46@nedbatchelder.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> <9ff212ad-da8d-2c1b-07be-823f03a37d46@nedbatchelder.com> Message-ID: On 25-09-17 15:37, Ned Batchelder wrote: > On 9/25/17 9:15 AM, Antoon Pardon wrote: >> Op 25-09-17 om 14:53 schreef Ned Batchelder: >>> On 9/25/17 8:24 AM, Steve D'Aprano wrote: >>>> On Mon, 25 Sep 2017 08:05 pm, Antoon Pardon wrote: >>>> >>>>> Pass by reference doesn't imply being able to >>>>> write a swap function. >>>> Really. Do you have a counter-example? >>>> >>>> >>>>> A swap function as possible in pascal requires two conditions. >>>>> >>>>> 1) Pass by reference >>>>> 2) Copy-over assignment. >>>> I don't know what you think "copy-over assignment" means, but none of >>>> DuckDuckGo, Google, Bing or Yahoo finds that term except in your post. >>>> >>>> >>>> >>>> >>> Would we be able to end these interminable debates if we just agree >>> that we all know how it works, and it isn't important to come up with >>> a simple name for what it is? >> I'm not sure that Steve knows how it works. When he denies that the assignment is >> an alias operation in Python that casts an important doubt. > > I can assure you that Steve knows how it works. Again, the disagreement is almost certainly over the semantics of the word "alias." Sorry, what he wrote contradicts that. Maybe he was just really confused at that moment, but it still needed correction. If the assignment is an alias operator then after the statements a = 1 b = a b = 2 a is not 2. He is not using the assignment as an alias operation in that last assignment but as a copy operation that will overwrite the value that b refers to. >>> It seems clear to me that "value" and "reference" are wildly vague >>> terms, used slightly differently by each language, and by different >>> people even in the same language if they have different perspectives. >> Well in that case and considering your remark above, maybe the residents >> shouldn't be so eager to deny to newbees that python has call by reference. > > You're still trying to get people to agree to a label like "call by reference." This is where the disagreement comes from. > No I'm trying to make them stop disagreeing to a label like call by reference. They may personnaly prefer an other label but this is not about them, this is about the newbe. And if someone can explain the newbe what is going on in terms of "call by reference", something the newbe understands, then that is what is important and those that prefer an other lable should at that moment not interfere and possibly cause confusion. -- Antoon Pardon. From rosuav at gmail.com Mon Sep 25 13:31:06 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Sep 2017 03:31:06 +1000 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <6c27765b-4494-d296-34f0-e716126630d0@rece.vub.ac.be> References: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> <87ing77z2j.fsf@elektro.pacujo.net> <875d80ff-3697-3aa0-ca7a-bbd58896022b@vub.be> <87efqu9aw6.fsf@elektro.pacujo.net> <8760c697hi.fsf@elektro.pacujo.net> <6c27765b-4494-d296-34f0-e716126630d0@rece.vub.ac.be> Message-ID: On Tue, Sep 26, 2017 at 3:04 AM, Antoon Pardon wrote: > On 25-09-17 16:29, Marko Rauhamaa wrote: >> Antoon Pardon : >> >>> Op 25-09-17 om 15:16 schreef Marko Rauhamaa: >>>> No, I'm not. I'm talking about pointers in the abstract sense, both in >>>> case of Python and Pascal. Neither language gives any hint as to the >>>> physical nature of the pointer. >>> >>> Yes you are. Python doesn't have pointers at the language level. So if >>> you start talking pointers you are talking about implementations >>> however abstract. >> >> It is difficult to say what is the "native" Python term for the thing. >> "Binding," maybe? The language spec fails to give it a name. >> >> However, when comparing different languages, you had better unify the >> terminology or you'll be confused by purely terminological issues. > > Fine, you have two mappings, a mapping from names to identities and a > mapping from identities to values. In languages like C, Pascal, ... > an assignment changes the mapping between the identities and the > values. In languages like Python, Smalltalk, ... an assignment > changes the mapping between the names and the identities. If by "identity" you mean the integer values returned by id(), then nope, you're still wrong - there is no mapping from identities to values. There is a mapping from name to object/value, and from an object, you can determine its identity. If you like, there's a mapping from values to identities, but not the other way around. Unless, of course, you can find something in the Python documentation that supports this two-step indirection? ChrisA From rosuav at gmail.com Mon Sep 25 13:35:45 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Sep 2017 03:35:45 +1000 Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] In-Reply-To: <20170925115255.7dd0c88f@bigbox.christie.dr> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <20170925115255.7dd0c88f@bigbox.christie.dr> Message-ID: On Tue, Sep 26, 2017 at 2:52 AM, Tim Chase wrote: > On 2017-09-26 02:29, Steve D'Aprano wrote: >> x = Parrot(name="Polly") >> >> (using Python syntax for simplicity) and somebody tries to tell me >> that the value of x is anything but a Parrot instance named "Polly", > > So this is a Polly-morphic constructor? Steve actually said: > Regardless of whether I'm using Python, Swift, Java, C, Pascal or Scheme, if I > write something like: So it's actually Polly-glot. ChrisA From antoon.pardon at rece.vub.ac.be Mon Sep 25 13:54:41 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 25 Sep 2017 19:54:41 +0200 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: References: <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> <87ing77z2j.fsf@elektro.pacujo.net> <875d80ff-3697-3aa0-ca7a-bbd58896022b@vub.be> <87efqu9aw6.fsf@elektro.pacujo.net> <8760c697hi.fsf@elektro.pacujo.net> <6c27765b-4494-d296-34f0-e716126630d0@rece.vub.ac.be> Message-ID: <66ac7c70-a5ba-6e31-436f-e6f5ddfa83ea@rece.vub.ac.be> On 25-09-17 19:31, Chris Angelico wrote: > On Tue, Sep 26, 2017 at 3:04 AM, Antoon Pardon > wrote: >> On 25-09-17 16:29, Marko Rauhamaa wrote: >>> Antoon Pardon : >>> >>>> Op 25-09-17 om 15:16 schreef Marko Rauhamaa: >>>>> No, I'm not. I'm talking about pointers in the abstract sense, both in >>>>> case of Python and Pascal. Neither language gives any hint as to the >>>>> physical nature of the pointer. >>>> >>>> Yes you are. Python doesn't have pointers at the language level. So if >>>> you start talking pointers you are talking about implementations >>>> however abstract. >>> >>> It is difficult to say what is the "native" Python term for the thing. >>> "Binding," maybe? The language spec fails to give it a name. >>> >>> However, when comparing different languages, you had better unify the >>> terminology or you'll be confused by purely terminological issues. >> >> Fine, you have two mappings, a mapping from names to identities and a >> mapping from identities to values. In languages like C, Pascal, ... >> an assignment changes the mapping between the identities and the >> values. In languages like Python, Smalltalk, ... an assignment >> changes the mapping between the names and the identities. > > If by "identity" you mean the integer values returned by id(), then > nope, you're still wrong - there is no mapping from identities to > values. There is a mapping from name to object/value, and from an > object, you can determine its identity. If you like, there's a mapping > from values to identities, but not the other way around. I'm describing this at a conceptual level. > Unless, of course, you can find something in the Python documentation > that supports this two-step indirection? The fact that the Python documentation describes its sematics differently doesn't contradict that this is a useful model. -- Antoon Pardon. From jpolo at mail.usf.edu Mon Sep 25 13:58:06 2017 From: jpolo at mail.usf.edu (john polo) Date: Mon, 25 Sep 2017 12:58:06 -0500 Subject: TypeError with map with no len() In-Reply-To: References: <696a2d75-7c9c-07f7-4b24-c6fd3baf3275@mail.usf.edu> Message-ID: <45b5963a-e13c-b95b-e0bc-6d1a73b247f2@mail.usf.edu> On 9/25/2017 12:03 PM, Paul Moore wrote: > You're using Python 3, and I suspect that you're working from > instructions that assume Python 2. In Python 3, the result of map() is > a generator, not a list (which is what Python 2's map returned). In > order to get an actual list (which appears to be what you need for > your plot call) you just need to call the list constructor: > > y1 = list(map(math.sin, math.pi*t)) > > Although given that you're using numpy, it may be that there's a more > idiomatic numpy way of doing this. I'm not a numpy expert though, so I > can't help on that. > > Paul Paul, Thank you very much for the explanation. best regards, John From rosuav at gmail.com Mon Sep 25 14:01:16 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Sep 2017 04:01:16 +1000 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <66ac7c70-a5ba-6e31-436f-e6f5ddfa83ea@rece.vub.ac.be> References: <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> <87ing77z2j.fsf@elektro.pacujo.net> <875d80ff-3697-3aa0-ca7a-bbd58896022b@vub.be> <87efqu9aw6.fsf@elektro.pacujo.net> <8760c697hi.fsf@elektro.pacujo.net> <6c27765b-4494-d296-34f0-e716126630d0@rece.vub.ac.be> <66ac7c70-a5ba-6e31-436f-e6f5ddfa83ea@rece.vub.ac.be> Message-ID: On Tue, Sep 26, 2017 at 3:54 AM, Antoon Pardon wrote: > On 25-09-17 19:31, Chris Angelico wrote: >> If by "identity" you mean the integer values returned by id(), then >> nope, you're still wrong - there is no mapping from identities to >> values. There is a mapping from name to object/value, and from an >> object, you can determine its identity. If you like, there's a mapping >> from values to identities, but not the other way around. > > I'm describing this at a conceptual level. At what conceptual level are the identities an in-between state instead of being something you see from the object? >> Unless, of course, you can find something in the Python documentation >> that supports this two-step indirection? > > The fact that the Python documentation describes its sematics differently > doesn't contradict that this is a useful model. You need *some* support for your assertion that there are pointers, and you have absolutely none. Sure, that's not contradicting anything, but it's like a scientist trying to prove that there's a link between laser pointers and cancer, and just never finding any backing for that theory. Nothing has yet DISproven that link, but how long do you search fruitlessly before you accept that maybe your theory is flat wrong? And it's hard to convince someone else of your theory if it has no support. ChrisA From dvl at psu.edu Mon Sep 25 14:05:33 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Mon, 25 Sep 2017 14:05:33 -0400 Subject: Call by binding [was re: [Tutor] beginning to code] In-Reply-To: mailman.29.1506355204.14733.python-list@python.org References: Message-ID: <1506362733l.22216858l.0l@psu.edu> I would claim that these two paragraphs do not agree. What is stored in the variable in Pascal? In declared variables and value parameters, the value itself. Let's just temporarily stipulate that for reference parameters and pointer variables actually store a pointer to the object. Where is it recorded whether this is a pointer to an integer or a float or a character or a thingamajig? Neither in the value nor the assumed pointer to the variable. In Pascal (and most compiled languages) that value type is maintained separately by the compiler, and then discarded in the compiled code. In the case of Python, the 'pointer' you refer to also has no type information. Instead, the type of the value is frequently inferred at run-time, based on additional information stored with the value. There is no equivalent information available at run-time in Pascal. Now, when you say 'Python's assignment semantics are wholly contained by those of Pascal', please show me the equivalent Pascal code to mimic the following (and not by defining a brand new complex object type in Pascal, since I am not doing so in Python). x = 5 x = 'abc' I think the larger discussion was about value and reference parameters. Yes you can do both of those in Pascal. But if you were stuck with just those two choices, which applies to this function definition? def add_to_self(arg): arg += arg x = 'abc' add_to_self(x) # now x = 'abcabc' x = 5 add_to_self(x) # x is still 5 is 'arg' a value parameter or a reference parameter? Can you replicate this behavior in Pascal without any if statement, since, as you say, the semantics are wholly contained by those of Pascal (aside from the += operator itself not appearing in the Pascal language) Roger Christman Pennsylvania State Universtiy On Mon, Sep 25, 2017 12:00 PM, python-list at python.org wrote: > A pointer to the object is stored in the variable. > >Of course, I'm using terminology that is not conventional in Python >circles. However, I'm doing it to demonstrate that there's nothing >particularly different between Python's assignment semantics and those >of, say, Pascal. Python's assignment semantics are wholly contained by >those of Pascal. > > From rhodri at kynesim.co.uk Mon Sep 25 14:13:05 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 25 Sep 2017 19:13:05 +0100 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <87a81i97mr.fsf@elektro.pacujo.net> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87a81i97mr.fsf@elektro.pacujo.net> Message-ID: <3dac26dd-d811-f719-95ae-20e35091ea49@kynesim.co.uk> On 25/09/17 15:26, Marko Rauhamaa wrote: > Chris Angelico : > >> On Mon, Sep 25, 2017 at 7:41 PM, Marko Rauhamaa wrote: >>> In Python, all expressions evaluate pointers. >> >> And that's an assertion that isn't backed by anything in the Python >> specification. Where do you get that all Python expressions are >> pointers? > > That's not what I said. I said all expressions *evaluate to* pointers. This may well be true in particular implementations, but it is an implementation detail so Chris' point still stands. Another implementation could evaluate expressions to indices (as BCPL used to treat its globals), pieces of string or cheese, who knows? > As for the specification, it doesn't make use of the word "pointer:" There's a reason for that... > The (English) expression: > > The name is bound to the object. > > is just another way of saying: > > A pointer to the object is stored in the variable. It really isn't. -- Rhodri James *-* Kynesim Ltd From antoon.pardon at rece.vub.ac.be Mon Sep 25 14:30:41 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 25 Sep 2017 20:30:41 +0200 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: References: <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> <87ing77z2j.fsf@elektro.pacujo.net> <875d80ff-3697-3aa0-ca7a-bbd58896022b@vub.be> <87efqu9aw6.fsf@elektro.pacujo.net> <8760c697hi.fsf@elektro.pacujo.net> <6c27765b-4494-d296-34f0-e716126630d0@rece.vub.ac.be> <66ac7c70-a5ba-6e31-436f-e6f5ddfa83ea@rece.vub.ac.be> Message-ID: <35f9788c-5476-23fd-a1f8-ee7bfbf6bd31@rece.vub.ac.be> On 25-09-17 20:01, Chris Angelico wrote: > On Tue, Sep 26, 2017 at 3:54 AM, Antoon Pardon > wrote: >> On 25-09-17 19:31, Chris Angelico wrote: >>> If by "identity" you mean the integer values returned by id(), then >>> nope, you're still wrong - there is no mapping from identities to >>> values. There is a mapping from name to object/value, and from an >>> object, you can determine its identity. If you like, there's a mapping >>> from values to identities, but not the other way around. >> >> I'm describing this at a conceptual level. > > At what conceptual level are the identities an in-between state > instead of being something you see from the object? > >>> Unless, of course, you can find something in the Python documentation >>> that supports this two-step indirection? >> >> The fact that the Python documentation describes its sematics differently >> doesn't contradict that this is a useful model. > > You need *some* support for your assertion that there are pointers, > and you have absolutely none. I think you have me confused with Marko Rauhamaa. He makes an assertion about pointers. I don't. -- Antoon Pardon. From rosuav at gmail.com Mon Sep 25 14:33:42 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Sep 2017 04:33:42 +1000 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <35f9788c-5476-23fd-a1f8-ee7bfbf6bd31@rece.vub.ac.be> References: <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> <87ing77z2j.fsf@elektro.pacujo.net> <875d80ff-3697-3aa0-ca7a-bbd58896022b@vub.be> <87efqu9aw6.fsf@elektro.pacujo.net> <8760c697hi.fsf@elektro.pacujo.net> <6c27765b-4494-d296-34f0-e716126630d0@rece.vub.ac.be> <66ac7c70-a5ba-6e31-436f-e6f5ddfa83ea@rece.vub.ac.be> <35f9788c-5476-23fd-a1f8-ee7bfbf6bd31@rece.vub.ac.be> Message-ID: On Tue, Sep 26, 2017 at 4:30 AM, Antoon Pardon wrote: > On 25-09-17 20:01, Chris Angelico wrote: >> On Tue, Sep 26, 2017 at 3:54 AM, Antoon Pardon >> wrote: >>> On 25-09-17 19:31, Chris Angelico wrote: >>>> If by "identity" you mean the integer values returned by id(), then >>>> nope, you're still wrong - there is no mapping from identities to >>>> values. There is a mapping from name to object/value, and from an >>>> object, you can determine its identity. If you like, there's a mapping >>>> from values to identities, but not the other way around. >>> >>> I'm describing this at a conceptual level. >> >> At what conceptual level are the identities an in-between state >> instead of being something you see from the object? >> >>>> Unless, of course, you can find something in the Python documentation >>>> that supports this two-step indirection? >>> >>> The fact that the Python documentation describes its sematics differently >>> doesn't contradict that this is a useful model. >> >> You need *some* support for your assertion that there are pointers, >> and you have absolutely none. > > I think you have me confused with Marko Rauhamaa. He makes an assertion > about pointers. I don't. My bad. It sounded like you were agreeing with Marko, and arguing the same assertion. ChrisA From marko at pacujo.net Mon Sep 25 15:35:12 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 25 Sep 2017 22:35:12 +0300 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87a81i97mr.fsf@elektro.pacujo.net> Message-ID: <87h8vqlggf.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Sep 26, 2017 at 12:26 AM, Marko Rauhamaa wrote: > Sorry, that was my bad in the terminology. But where do you get that > all Python expressions evaluate to pointers? What do they evaluate to if not pointers? Anton's "identities" would work, too. "Address" would do, as well. I have previously proposed the term "leash." Call it "link" or "handle" or "arrow" if you want to. The term used isn't important. What's important is to understand that each expression and subexpression produces and operates on pointers. >> It also uses circular definitions when talking about dicts and lists: >> >> That object is then asked to assign the assigned object to the given >> attribute >> >> the sequence is asked to assign the assigned object to its item with >> that index. > > Technically, that's correct. When you use a statement like: > > foo[bar] = quux > > what it does is ask the object *foo* to assign *quux* to the item > represented by *bar*. What is missing is the definition of that assignment in the specific case of dicts and lists. The recursive definition must be well-founded. It covers variables ("names") but leaves the two other fundamental cases (dicts and lists) undefined. (I'm actually guessing the definition is missing because the author couldn't find good language for the cases. Apparently, "dict attribute binding" and "list element binding" weren't attractive enough.) > But you have yet to show how you can jump from "name binding" to > "pointer" using anything from the Python documentation. There's nothing to show. It's a simple matter of terminology. "Binding" is a passable synonym for "pointer." Marko From marko at pacujo.net Mon Sep 25 15:36:29 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 25 Sep 2017 22:36:29 +0300 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> <87ing77z2j.fsf@elektro.pacujo.net> <875d80ff-3697-3aa0-ca7a-bbd58896022b@vub.be> <87efqu9aw6.fsf@elektro.pacujo.net> <8760c697hi.fsf@elektro.pacujo.net> <6c27765b-4494-d296-34f0-e716126630d0@rece.vub.ac.be> <66ac7c70-a5ba-6e31-436f-e6f5ddfa83ea@rece.vub.ac.be> Message-ID: <87d16elgea.fsf@elektro.pacujo.net> Chris Angelico : > You need *some* support for your assertion that there are pointers, What would convince you? Marko From marko at pacujo.net Mon Sep 25 15:40:35 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 25 Sep 2017 22:40:35 +0300 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87a81i97mr.fsf@elektro.pacujo.net> <3dac26dd-d811-f719-95ae-20e35091ea49@kynesim.co.uk> Message-ID: <878th2lg7g.fsf@elektro.pacujo.net> Rhodri James : > On 25/09/17 15:26, Marko Rauhamaa wrote: >> That's not what I said. I said all expressions *evaluate to* pointers. > > This may well be true in particular implementations, but it is an > implementation detail so Chris' point still stands. Another > implementation could evaluate expressions to indices (as BCPL used to > treat its globals), pieces of string or cheese, who knows? Those are all pointers. A pointer is something that points to a data object. Marko From rosuav at gmail.com Mon Sep 25 15:43:37 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Sep 2017 05:43:37 +1000 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <87h8vqlggf.fsf@elektro.pacujo.net> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87a81i97mr.fsf@elektro.pacujo.net> <87h8vqlggf.fsf@elektro.pacujo.net> Message-ID: On Tue, Sep 26, 2017 at 5:35 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Tue, Sep 26, 2017 at 12:26 AM, Marko Rauhamaa wrote: >> Sorry, that was my bad in the terminology. But where do you get that >> all Python expressions evaluate to pointers? > > What do they evaluate to if not pointers? Anton's "identities" would > work, too. "Address" would do, as well. I have previously proposed the > term "leash." Call it "link" or "handle" or "arrow" if you want to. > > The term used isn't important. What's important is to understand that > each expression and subexpression produces and operates on pointers. They evaluate to objects. Not to pointers to objects. Not to references to objects. To objects. Expressions evaluate to actual objects, and when you assign "name = value", you bind the name to the object that value evaluates to. ChrisA From ned at nedbatchelder.com Mon Sep 25 15:44:23 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 25 Sep 2017 15:44:23 -0400 Subject: [Tutor] beginning to code In-Reply-To: References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c714da$0$14959$b1db1813$d948b532@news.astraweb.com> Message-ID: <25e3c967-765a-a120-dbfd-42dde76ae073@nedbatchelder.com> On 9/25/17 5:32 AM, Antoon Pardon wrote: > Can you explain, what you mean by "Pass-By-Reference" as far a I understand, > pass by reference means that the parameter of the function becomes an alias > of the argument, so that if the entity is mutated through one name that > mutation is visible through the other name. > >> function(x, y) # allowed >> function(namespace.x, module.y) # allowed >> function(x + 1, 2) # FORBIDDEN: can't pass expressions or constants > Pass by reference, doesn't imply the above is forbidden. A language can > define, that the "x + 1" will produce an new entity and that a reference > to that entity will be passed. > Wikipedia has the right definition of call by reference (https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference): /Call by reference/ (also referred to as /pass by reference/) is an evaluation strategy where a function receives an implicit reference to a variable used as argument, rather than a copy of its value. This typically means that the function can modify (i.e. assign to ) the variable used as argument?something that will be seen by its caller. The key idea here is that it is a reference to a *variable* that is passed, not a reference to a value.? Python has no references to variables, so it cannot support call by reference.?? Because Python passes references to values, it is easy to call it "call by reference," but that is not what the term means. The Wikipedia definition unfortunately includes "rather than a copy of its value," as if those are the only two options (a common misunderstanding). Elsewhere in this thread, someone asserted that to be call by reference, you have to be able to write a swap(x,y) function.? True call-by-reference would make this possible.? Python cannot do it. --Ned. From rosuav at gmail.com Mon Sep 25 15:46:18 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Sep 2017 05:46:18 +1000 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <87d16elgea.fsf@elektro.pacujo.net> References: <877ewn9ktz.fsf@elektro.pacujo.net> <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> <87ing77z2j.fsf@elektro.pacujo.net> <875d80ff-3697-3aa0-ca7a-bbd58896022b@vub.be> <87efqu9aw6.fsf@elektro.pacujo.net> <8760c697hi.fsf@elektro.pacujo.net> <6c27765b-4494-d296-34f0-e716126630d0@rece.vub.ac.be> <66ac7c70-a5ba-6e31-436f-e6f5ddfa83ea@rece.vub.ac.be> <87d16elgea.fsf@elektro.pacujo.net> Message-ID: On Tue, Sep 26, 2017 at 5:36 AM, Marko Rauhamaa wrote: > Chris Angelico : >> You need *some* support for your assertion that there are pointers, > > What would convince you? Evidence, or a statement from the documentation. ChrisA From marko at pacujo.net Mon Sep 25 16:00:03 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 25 Sep 2017 23:00:03 +0300 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <87poaf813r.fsf@elektro.pacujo.net> <8ef4b87f-790a-8ad1-48e3-a55ef05a0442@vub.be> <87ing77z2j.fsf@elektro.pacujo.net> <875d80ff-3697-3aa0-ca7a-bbd58896022b@vub.be> <87efqu9aw6.fsf@elektro.pacujo.net> <8760c697hi.fsf@elektro.pacujo.net> <6c27765b-4494-d296-34f0-e716126630d0@rece.vub.ac.be> <66ac7c70-a5ba-6e31-436f-e6f5ddfa83ea@rece.vub.ac.be> <87d16elgea.fsf@elektro.pacujo.net> Message-ID: <874lrqlfb0.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Sep 26, 2017 at 5:36 AM, Marko Rauhamaa wrote: >> Chris Angelico : >>> You need *some* support for your assertion that there are pointers, >> >> What would convince you? > > Evidence, or a statement from the documentation. I mean, what piece of Python code could decide if I'm right or wrong? Marko From mail at timgolden.me.uk Mon Sep 25 16:00:42 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 25 Sep 2017 21:00:42 +0100 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <878th2lg7g.fsf@elektro.pacujo.net> References: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87a81i97mr.fsf@elektro.pacujo.net> <3dac26dd-d811-f719-95ae-20e35091ea49@kynesim.co.uk> <878th2lg7g.fsf@elektro.pacujo.net> Message-ID: <636cad82-ffb3-d41f-5d9d-255f326dddfb@timgolden.me.uk> On 25/09/2017 20:40, Marko Rauhamaa wrote: > Rhodri James : >> On 25/09/17 15:26, Marko Rauhamaa wrote: >>> That's not what I said. I said all expressions *evaluate to* pointers. >> >> This may well be true in particular implementations, but it is an >> implementation detail so Chris' point still stands. Another >> implementation could evaluate expressions to indices (as BCPL used to >> treat its globals), pieces of string or cheese, who knows? > > Those are all pointers. > > A pointer is something that points to a data object. (Slight sigh). Can I step in as a list owner and ask the people who are so very fond of debating this topic again and again: please let it drop. Threads such as this can remain interesting when the discussion generates a better understanding of the subject matter as the contributors are forced to articulate their positions leading to some kind of convergence of understanding. However, even if this were the only iteration of this debate, it would be clear by now that there's no chance of a simple "I see what you mean" moment. And this is far from the only iteration, even in the past few months. I feel for your need to demonstrate the validity of your respective positions. But it has moved on from being an enlightening debate and into the realms of mere tedium. Thanks. TJG From rosuav at gmail.com Mon Sep 25 16:03:59 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Sep 2017 06:03:59 +1000 Subject: [Tutor] beginning to code In-Reply-To: References: <59c714da$0$14959$b1db1813$d948b532@news.astraweb.com> <25e3c967-765a-a120-dbfd-42dde76ae073@nedbatchelder.com> Message-ID: On Tue, Sep 26, 2017 at 5:51 AM, Stefan Ram wrote: > Ned Batchelder writes: >>Wikipedia has the right definition of call by reference > > Assertions can be right or wrong. > > Definitions cannot be right or wrong. You have made two assertions. One of them is right. The other is wrong. :-) ChrisA From neilc at norwich.edu Mon Sep 25 16:19:27 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 25 Sep 2017 20:19:27 +0000 (UTC) Subject: Call by binding [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <59c85dfa$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-09-25, Steve D'Aprano wrote: > So I believe that either "call by binding" or "call by > assignment" could both equally apply to any and all languages > with function parameters, regardless of implementation or the > language's defined semantics. I disagree on C++ where there's a keen difference between assignment and initialization, but I think I get what you mean, generally. If the objection is that "call by assignment" is just passing-the-buck, I won't argue with that. The quest to find a succinct way to categorize Python's argument passing for non-Python programmers strikes me as a sincere effort to to simplify something that just isn't simple. If calling it, "pass by assignment," is admitting defeat, then so be it. -- Neil Cerutti From antoon.pardon at rece.vub.ac.be Mon Sep 25 16:19:56 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 25 Sep 2017 22:19:56 +0200 Subject: [Tutor] beginning to code In-Reply-To: <25e3c967-765a-a120-dbfd-42dde76ae073@nedbatchelder.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c714da$0$14959$b1db1813$d948b532@news.astraweb.com> <25e3c967-765a-a120-dbfd-42dde76ae073@nedbatchelder.com> Message-ID: On 25-09-17 21:44, Ned Batchelder wrote: > On 9/25/17 5:32 AM, Antoon Pardon wrote: >> Can you explain, what you mean by "Pass-By-Reference" as far a I understand, >> pass by reference means that the parameter of the function becomes an alias >> of the argument, so that if the entity is mutated through one name that >> mutation is visible through the other name. >> >>> function(x, y) # allowed >>> function(namespace.x, module.y) # allowed >>> function(x + 1, 2) # FORBIDDEN: can't pass expressions or constants >> Pass by reference, doesn't imply the above is forbidden. A language can >> define, that the "x + 1" will produce an new entity and that a reference >> to that entity will be passed. >> > > Wikipedia has the right definition of call by reference (https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference): > > /Call by reference/ (also referred to as /pass by reference/) is an > evaluation strategy where a function receives an implicit reference > to > a variable used as argument, rather than a copy of its value. This > typically means that the function can modify (i.e. assign to > ) > the variable used as argument?something that will be seen by its caller. > > The key idea here is that it is a reference to a *variable* that is passed, not a reference to a value. Python has no references to variables, so it cannot support call by reference. Because Python passes references to values, it is easy to call it > "call by reference," but that is not what the term means. And what would such a reference to a variable be exactly? If you mean the name, languages like Pascal don't have that either. If you mean a reference to an object/entity, Python has those. It also says: This typically means that the function can modify the variable used as argument, something Python can do that. > > The Wikipedia definition unfortunately includes "rather than a copy of its value," as if those are the only two options (a common misunderstanding). > > Elsewhere in this thread, someone asserted that to be call by reference, you have to be able to write a swap(x,y) function. True call-by-reference would make this possible. Python cannot do it. That is because assignments in python don't make modifications to what the name refers to. If you can't modify the object because the semantics of the assignment don't do that, you can't use the impossibility of a swap for inferring that we don't have true call by reference. You can't write a swap in smalltalk either but the smalltalk documentation specifies that arguments are call by reference. -- Antoon Pardon. From antoon.pardon at rece.vub.ac.be Mon Sep 25 16:29:51 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 25 Sep 2017 22:29:51 +0200 Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] In-Reply-To: <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: <1c115834-bfcc-de2b-6963-ecd03be2879e@rece.vub.ac.be> On 25-09-17 18:29, Steve D'Aprano wrote: > > Regardless of whether I'm using Python, Swift, Java, C, Pascal or Scheme, if I > write something like: > > x = Parrot(name="Polly") > > (using Python syntax for simplicity) and somebody tries to tell me that the > value of x is anything but a Parrot instance named "Polly", I have no time for > that sort of nonsense. They might as well tell me that I'm typing this response > on an elephant. And if you write it like that, implying that the assignment semantics is the same for all these languages, I'm not surprises people get confused. -- Antoon Pardon. From jennybabenny at mail.com Mon Sep 25 16:45:49 2017 From: jennybabenny at mail.com (INCULA-IBAMBINI PAOLO BARRAI TRUFFAELAVACASHMAFIOSO) Date: Mon, 25 Sep 2017 13:45:49 -0700 (PDT) Subject: Blogueiro criminoso, assassino, pedofilhomosessexual Paolo Barrai ( Milano 28.6.1965). Execute lavagem a dinheiro mafioso! BLOGUEIRO ITALIANO CRIMINOSO PEDOFILO E ASSASSINO PAOLO PIETRO BARRAI ( MILANO 28.6.1965) EXECUTE MUITO LAVAGEM A CASH MAFIOSO! Message-ID: Blogueiro criminoso, assassino, pedofilhomosessexual Paolo Barrai ( Milano 28.6.1965). Execute lavagem a dinheiro mafioso! BLOGUEIRO ITALIANO CRIMINOSO PEDOFILO E ASSASSINO PAOLO PIETRO BARRAI ( MILANO 28.6.1965) EXECUTE MUITO LAVAGEM A CASH MAFIOSO! Pol?cia Civil de Porto Seguro investiga blogueiro italiano criminal Paolo Pietro Barrai (MIlao 28.6.1965). Para pedofilia homossexual, lavagem dinheiro mafioso, propaganda nazista e racista, difamacao pesado via internet, extorsao, furto e estelionato. A internet est? virando cada vez mais palco para crimes e investiga??es que ultrapassam fronteiras e na??es. A Pol?cia Civil de Porto Seguro est? investigando o blogueiro italiano Paolo Pietro Barrai, acusado pelos crimes de estelionato, chantagem e difama??o que teria cometido na rede, nos ?ltimos dois meses, contra o empres?rio Luigi Rotunno que tamb?m ? italiano. As investiga??es est?o sendo conduzidas pela delegada titular de Porto Seguro, Eliana Teles Barbosa que j? tem experi?ncia em solucionar crimes do ciberespa?o. Dentre outros casos elucidados, foi ela a descobrir os respons?veis pelo primeiro furto pela rede em Porto Seguro, nove anos atr?s, quando uma publicit?ria teve milhares de reais subtra?dos por um conhecido atrav?s da internet. A Pol?cia Civil de Porto Seguro ouviu na ?ltima sexta feira, pela manh?, o blogueiro italiano, autor do blog Mercato Libero, mas o depoimento dele ocorreu a portas fechadas. De acordo com a delegada Eliana Teles Barbosa os supostos crimes teriam sido cometidos por Barrai na internet, com v?rias acusa??es que culminaram com uma ?Notitia Criminis? apresentada pela v?tima (registrada na delegacia circunscricional de Porto Seguro sob o n? 07220110011377): ?a princ?pio estamos investigando-o por estelionato, mas h? tamb?m a quest?o da difama??o, uma vez que o blogueiro teria desmoralizado a v?tima na internet de todas as maneiras?, disse Eliana Barbosa, ?no interrogat?rio falou ainda de m?fias de Berlusconi e outras coisas que estamos apurando, mas agora estamos cuidando da seguran?a do Carnaval e temos que esperar quarta-feira?. Press?es extorsivas e difama??o Os fatos ocorreram nos ?ltimos meses quando o blogueiro Paolo Barrai Apresentou-se ao empres?rio Luigi Rotunno para divulgar not?cias sobre o mercado imobili?rio brasileiro na It?lia. O que parecia ser o come?o de uma divulga??o de um produto, logo virou um inferno midi?tico com mensagens an?nimas e ap?crifas, em blogs que n?o controlam o conte?do dos post antes de p?r on line, ?as exig?ncias financiarias dele aumentavam a cada vez mais, ao mesmo tempo em que, diante de meus questionamentos, come?aram aparecer na rede difama??es grav?ssimas contra minha pessoa, e as press?es deles foram cada vez mais extorsivas?, relatou o empres?rio Luigi Rotunno, v?tima do blogueiro ?ao mesmo tempo em que utilizava, desta vez no blog dele, nossas logomarcas e projetos como fossem dele, apropriando-se de forma indevida de nosso trabalho. Eu n?o pretendo ceder ? chantagem e por isso resolvi denunciar o fato ?s autoridades competentes?. A maior preocupa??o do empres?rio ? a com os preju?zos criados pela a??o difamat?ria, ?o que ? mais preocupante ? que uma empresa s?lida e real, com dezenas de milhares de metros quadrados constru?dos, entregues e escriturados, na praia do Mut?, como a Imoplanet, com mais de duzentos funcion?rios, todos residentes com suas fam?lias em Porto Seguro e Santa Cruz Cabr?lia, possam ser amea?adas e chantageadas por uma pessoa que s? tem um computador e nenhum escr?pulo em prejudicar sem medir as consequ?ncias. Difama??o ? crime, no Brasil, na It?lia e em qualquer lugar do mundo, no nosso caso ? muito mais grave pois amea?a centenas de pessoas?. De fato o problema ? exatamente este: um crime ou um il?cito cometido na rede, onde pode ser perseguido? No pa?s do servidor que hospeda os blogs, ou sites? No pa?s de resid?ncia de quem comete os fatos? No pa?s de resid?ncia das v?timas? No pa?s onde os preju?zos gerados pelas difama??es criam danos ? economia local podem at? deixar desempregadas centenas de pessoas? A quest?o est? em aberto, considerando ainda a velocidade de transforma??o, velocidade muitas vezes superior ao mundo real. As tramas organizadas no mundo virtual, por?m no final da hist?ria t?m que voltar ao mundo real para pegar, fisicamente, o dinheiro. A delegada que est? conduzindo as investiga??es, Eliana Teles Barbosa, ? uma profunda conhecedora de Porto Seguro e da Costa do Descobrimento, onde investiga , e soluciona, h? anos casos complexos de estelionato. Descobrindo Estelionat?rios Foi assim quando, gra?as aos restos de uma garrafa com gasolina ela descobriu um empres?rio que simulou um inc?ndio de um avi?o na pista do aeroporto de Porto Seguro, para receber o valor integral, como nova, por uma aeronave totalmente sucateada. No mundo virtual, foi ela a desmascarar o primeiro caso de crime de internet em Porto Seguro. Na ?poca uma publicit?ria viu que sua conta banc?ria havia v?rias transfer?ncias banc?rias pela internet, que ela n?o tinha feito. Um conhecido tinha utilizado a rede para cometer o crime, (gra?as tamb?m ? senha menos indicada do mundo, a data de nascimento!). Mas no final precisou de uma conta banc?ria real para direcionar o dinheiro e posteriormente sac?-lo. Na ?poca o estelionat?rio utilizou um intermedi?rio que encontrou um titular de uma conta que em troca de uma quantia em dinheiro emprestou a conta para fazer a transa??o. Na fila do banco, por?m a surpresa, ao lado do caixa os agentes coordenados pela delegada Eliana Barbosa surpreenderam os dois em flagrante e atrav?s deles chegaram ao idealizador. Para os tr?s, o final da hist?ria n?o foi nada virtual: as algemas nos pulsos, e as celas do Complexo Policial de Porto Seguro!!! http://4.bp.blogspot.com/-aqbT4KlYsmw/TcLbvUUpkeI/AAAAAAAAAe4/TiDPLR0LH_U/s1600/barrai+ind-pag01.jpg From claudemirxavier49 at gmail.com Mon Sep 25 18:17:12 2017 From: claudemirxavier49 at gmail.com (claudemirxavier49 at gmail.com) Date: Mon, 25 Sep 2017 15:17:12 -0700 (PDT) Subject: problems with Methods in Python 3.4.2 In-Reply-To: References: Message-ID: <56d14b5f-09d2-40db-826b-00adf1b11213@googlegroups.com> Traceback (most recent call last): File "", line 1, in nome = input("Digite seu nome:") File "", line 1, in NameError: name 'rick' is not defined >>> Estou com esse problema alguem me ajuda pfvr From tjol at tjol.eu Mon Sep 25 18:37:29 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 26 Sep 2017 00:37:29 +0200 Subject: TypeError with map with no len() In-Reply-To: <696a2d75-7c9c-07f7-4b24-c6fd3baf3275@mail.usf.edu> References: <696a2d75-7c9c-07f7-4b24-c6fd3baf3275@mail.usf.edu> Message-ID: <8cc77418-c9ad-3fbe-f7f5-1140d8482266@tjol.eu> On 25/09/17 18:44, john polo wrote: > Python List, > > I am trying to make practice data for plotting purposes. I am using > Python 3.6. The instructions I have are > > import matplotlib.pyplot as plt > import math > import numpy as np > t = np.arange(0, 2.5, 0.1) > y1 = map(math.sin, math.pi*t) If you use np.sin instead of math.sin, you don't have to use map: Most numpy functions operate elementwise on arrays (for example, you're multiplying math.pi with an array - something that wouldn't work with a list). Here's the numpy way of doing this: t = np.arange(0, 2.5, 0.1) y1 = np.sin(np.pi * t) Without using numpy at all, this might be t = [i * 0.1 for i in range(25)] y1 = [math.pi * a for a in t] > plt.plot(t,y1) > > However, at this point, I get a TypeError that says > > object of type 'map' has no len() > > In [6]: t > Out[6]: > array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , > 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. , 2.1, > 2.2, 2.3, 2.4]) > In [7]: y1 > Out[7]: > In [8]: math.pi*t > Out[8]: > array([ 0. , 0.31415927, 0.62831853, 0.9424778 , 1.25663706, > 1.57079633, 1.88495559, 2.19911486, 2.51327412, 2.82743339, > 3.14159265, 3.45575192, 3.76991118, 4.08407045, 4.39822972, > 4.71238898, 5.02654825, 5.34070751, 5.65486678, 5.96902604, > 6.28318531, 6.59734457, 6.91150384, 7.2256631 , 7.53982237]) > > At the start of creating y1, it appears there is an array to iterate > through for the math.sin function used in map(), but y1 doesn't appear > to be saving any values. I expected y1 to hold a math.sin() output for > each item in math.pi*t, but it appears to be empty. Am I > misunderstanding map()? Is there something else I should be doing > instead to populate y1? > > > John > From greg.ewing at canterbury.ac.nz Mon Sep 25 18:52:19 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 26 Sep 2017 11:52:19 +1300 Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] In-Reply-To: <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > Or perhaps I should say: > > I disintegrate it really snooze to pyramid running when the ribbons they > apply to sandwiches are not the same as the sleep I use. You could say that, and nobody would care much. If you insisted that your personal interpretation of those words was the *right* one, and everyone else should change theirs to match, that would irk people. It's *that* kind of behaviour that leads to these interminable arguments. > They might as well tell me that I'm typing this response > on an elephant. Indian or African? And how many coconuts can it carry? -- Greg From rosuav at gmail.com Mon Sep 25 18:58:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Sep 2017 08:58:11 +1000 Subject: Calling methods without objects? In-Reply-To: References: Message-ID: On Tue, Sep 26, 2017 at 8:49 AM, Stefan Ram wrote: > |>>> from random import randint > | > |>>> randint > |> > | > |>>> randint.__self__ > | > | > |>>> randint( 2, 3 ) > |2 > > It seems I am calling the method ?randint? of the object at > ?0x389798?, but I do not have to write the object into the > call!? > > So, is there some mechanism in Python that can bind a method > to an object so that the caller does not have to specify the > object in the call? > > If so, how is this mechanism called? >>> stuff = [] >>> add_stuff = stuff.append >>> add_stuff("spam") >>> add_stuff("eggs") >>> add_stuff("sausage") >>> add_stuff("spam") >>> stuff ['spam', 'eggs', 'sausage', 'spam'] In a typical method call, "obj.meth(args)", the "obj.meth" part is itself a valid expression, and it evaluates to a bound method object. I suppose you could call that mechanism "method binding" if you like, but mainly it's just attribute lookup. ChrisA From tjol at tjol.eu Mon Sep 25 19:04:50 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 26 Sep 2017 01:04:50 +0200 Subject: Calling methods without objects? In-Reply-To: References: Message-ID: On 26/09/17 00:49, Stefan Ram wrote: > |>>> from random import randint > | > |>>> randint > |> > | > |>>> randint.__self__ > | > | > |>>> randint( 2, 3 ) > |2 > > It seems I am calling the method ?randint? of the object at > ?0x389798?, but I do not have to write the object into the > call!? > > So, is there some mechanism in Python that can bind a method > to an object so that the caller does not have to specify the > object in the call? > > If so, how is this mechanism called? Yes, that's how all methods work in Python. When an object is constructed from a class, all functions in the class are turned into method objects that refer back to the original object. In [1]: class C: ...: def m(self): ...: return True ...: In [2]: C.m Out[2]: In [3]: C().m Out[3]: > In [4]: m = C().m In [5]: m Out[5]: > In [6]: m() Out[6]: True In [7]: m.__self__ Out[7]: <__main__.C at 0x7f5b2813fef0> In [8]: m.__func__ Out[8]: In [9]: m.__func__ is C.m Out[9]: True From tjol at tjol.eu Mon Sep 25 19:11:03 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 26 Sep 2017 01:11:03 +0200 Subject: Calling methods without objects? In-Reply-To: References: Message-ID: On 26/09/17 01:04, Thomas Jollans wrote: > > In [1]: class C: > > ...: def m(self): > > ...: return True I'll have to give my MUA a stern talking to about the importance of whitespace. Anyway, you know what I mean. > > ...: From python at mrabarnett.plus.com Mon Sep 25 20:03:57 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 26 Sep 2017 01:03:57 +0100 Subject: problems with Methods in Python 3.4.2 In-Reply-To: <56d14b5f-09d2-40db-826b-00adf1b11213@googlegroups.com> References: <56d14b5f-09d2-40db-826b-00adf1b11213@googlegroups.com> Message-ID: <57a5ef7b-4624-015d-2934-1a2650320aff@mrabarnett.plus.com> On 2017-09-25 23:17, claudemirxavier49 at gmail.com wrote: > Traceback (most recent call last): > File "", line 1, in > nome = input("Digite seu nome:") > File "", line 1, in > NameError: name 'rick' is not defined >>>> > Estou com esse problema alguem me ajuda pfvr > It looks like what you would get in Python 2. If you're using Python 2, use 'raw_input' instead of 'input'. From gengyangcai at gmail.com Mon Sep 25 20:15:19 2017 From: gengyangcai at gmail.com (Cai Gengyang) Date: Mon, 25 Sep 2017 17:15:19 -0700 (PDT) Subject: Printing a Chunk Of Words Message-ID: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> """ Boolean Operators ------------------------ True and True is True True and False is False False and True is False False and False is False True or True is True True or False is True False or True is True False or False is False Not True is False Not False is True """ If I simply want to print a chunk of words and a paragraph like the above, what command should I use ? From rosuav at gmail.com Mon Sep 25 20:22:37 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Sep 2017 10:22:37 +1000 Subject: Printing a Chunk Of Words In-Reply-To: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> References: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> Message-ID: On Tue, Sep 26, 2017 at 10:15 AM, Cai Gengyang wrote: > """ > Boolean Operators > ------------------------ > True and True is True > True and False is False > False and True is False > False and False is False > > True or True is True > True or False is True > False or True is True > False or False is False > > Not True is False > Not False is True > > """ > > If I simply want to print a chunk of words and a paragraph like the above, what command should I use ? You already have them in triple quotes. Toss a 'print(...)' around it, and it'll print. If that's not what you mean, then be more specific :) :) :) ChrisA From rantingrickjohnson at gmail.com Mon Sep 25 20:28:16 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 25 Sep 2017 17:28:16 -0700 (PDT) Subject: Printing a Chunk Of Words In-Reply-To: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> References: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> Message-ID: <6079a870-8cf8-40dd-8493-f86ca347b359@googlegroups.com> On Monday, September 25, 2017 at 7:15:41 PM UTC-5, Cai Gengyang wrote: > """ > Boolean Operators > ------------------------ > True and True is True > True and False is False > False and True is False > False and False is False > > True or True is True > True or False is True > False or True is True > False or False is False > > Not True is False > Not False is True > > """ > > If I simply want to print a chunk of words and a paragraph like the above, what command should I use ? Well, being that what you have there is a "multi-line string literal", then you can pass it the print function (py3). ## Begin: Python2.x interactive session ## >>> print """this is my totally awesome multi-line string""" this is my totally awesome multi-line string ## End: Python2.x interactive session ## Although, i would assign a name to it first, as passing around literals is not practical. ## Begin: Python2.x interactive session ## >>> s = """this is my totally awesome multi-line string""" >>> print s this is my totally awesome multi-line string ## End: Python2.x interactive session ## However, if your intention is to evaluate each line of the "paragraph" (as you called it), then you have to do a little more work. ## Begin: Python2.x interactive session ## >>> for line in s.splitlines(True): ... print repr(line) 'this is my\n' 'totally awesome multi-line\n' 'string' Which is a start... From kryptxy at protonmail.com Mon Sep 25 20:38:54 2017 From: kryptxy at protonmail.com (Kryptxy) Date: Mon, 25 Sep 2017 20:38:54 -0400 Subject: Running a GUI program haults the calling program (linux) Message-ID: I want to run a GUI program (transmission-gtk) from python. This is what I do: import subprocess subprocess.Popen(['transmission-gtk', link], stdout=subprocess.PIPE, stderr=subprocess.PIPE) Where `link` is some magnetic link. This command opens transmission-gtk, but it haults the calling program, and keeps the terminal busy till the time GUI is running. As soon as GUI is closed, the control goes back to the program. Is there any way that the GUI program is opened, and immediately the control returns to calling program, instead of keeping the terminal busy? (I know transmission-remote can be used for adding torrents. Looking for a way around for transmission-gtk specifically). Thank you! Regards. From rosuav at gmail.com Mon Sep 25 20:50:41 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Sep 2017 10:50:41 +1000 Subject: Running a GUI program haults the calling program (linux) In-Reply-To: References: Message-ID: On Tue, Sep 26, 2017 at 10:38 AM, Kryptxy via Python-list wrote: > I want to run a GUI program (transmission-gtk) from python. This is what I do: > > import subprocess > subprocess.Popen(['transmission-gtk', link], stdout=subprocess.PIPE, stderr=subprocess.PIPE) > > Where `link` is some magnetic link. > > This command opens transmission-gtk, but it haults the calling program, and keeps the terminal busy till the time GUI is running. > As soon as GUI is closed, the control goes back to the program. > > Is there any way that the GUI program is opened, and immediately the control returns to calling program, instead of keeping the terminal busy? > > (I know transmission-remote can be used for adding torrents. Looking for a way around for transmission-gtk specifically). I'm not sure why you can't signal it, but I'll take that parenthesized comment as an indication that you know about (a) the transmission-remote command, and/or (b) the fact that transmission-gtk can be remote-controlled fairly effectively. (For instance, I have a script that puts Transmission into turtle mode, then does something, and then takes Transmission out of turtle mode. It's two lines of shell script to do it.) So, you want to "fire-and-forget" a GUI program. Or more generally, _any_ program. My suspicion here is that, since Popen shouldn't be blocking, that you're filling up one of your pipes. Can you try removing the stdout and stderr parameters, and see what that does? You should be able to fire off a subprocess and then carry on with the program. It might make a lot of noise, if transmission produces a ton of output; but if that happens, try std{out,err}=subprocess.DEVNULL instead of PIPE - unless you're specifically trying to read the output? ChrisA From steve+python at pearwood.info Mon Sep 25 21:01:54 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 26 Sep 2017 11:01:54 +1000 Subject: Reductionism gone mad [was Re: Call by binding] References: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87a81i97mr.fsf@elektro.pacujo.net> <87h8vqlggf.fsf@elektro.pacujo.net> Message-ID: <59c9a703$0$14974$b1db1813$d948b532@news.astraweb.com> On Tue, 26 Sep 2017 05:35 am, Marko Rauhamaa wrote: > Chris Angelico : > >> On Tue, Sep 26, 2017 at 12:26 AM, Marko Rauhamaa wrote: >> Sorry, that was my bad in the terminology. But where do you get that >> all Python expressions evaluate to pointers? > > What do they evaluate to if not pointers? That's a remarkable question. I understand that you may have used Python once or twice in the past. In all that time, have you ever, even once, needed to dereference a pointer? Or use an "address of" operator? Does Python even provide such functionality? When you evaluate, say, `chr(65)`, at the interactive interpreter, which of the following is closer to what you see? py> chr(65) # evaluates to a pointer, as Marko says py> chr(65) # what actually happens 'A' Evaluating python expressions results in an object, not a pointer. You are mixing up implementation of an abstraction (the Python virtual machine) with the interface to that Python VM. Concepts such as "expressions" are part of the interface between the human coder and the Python VM. Concepts such as "pointers" are part of the implementation of how the VM works at a lower level. Talking about the implementation is perfectly fine. What is not fine is the stubborn insistence that the implementation is the interface. And of course, pointers themselves are only a lower-level abstraction. They're actually just integers. So using your technique of inappropriately dropping into a lower abstraction, we can say that "Python expressions always evaluate to integers". But of course even that is just an abstraction too, integers are actually just a block of bytes. So we could say that "Python expressions always evaluate to bytes". But that is also just an abstraction. What actually happens is that a set of (possibly non-contiguous) memory cells are set. So we could say that "Python expressions don't evaluate to anything, they operate purely by side-effect by setting a set of memory cells". But that's still an abstraction. How far down should we go before you acknowledge the error of describing the behaviour of a higher abstraction in terms of what happens in lower levels? There's a term for this sort of category error: reductionism. I thought that reductionism was dead: - you won't find doctors, not even specialists, denying that people can walk across the room and insisting that all they do is contract muscle fibres; - you won't find ecologists or biologists denying that there are such things as forests, only trees; - or chemists denying that there are trees, only self-organising collections of molecules; - or physicists denying that there are molecules, only quarks and electrons. But apparently reductionism is alive and well in computing. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Mon Sep 25 21:17:21 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 26 Sep 2017 11:17:21 +1000 Subject: Calling methods without objects? References: Message-ID: <59c9aaa2$0$14942$b1db1813$d948b532@news.astraweb.com> On Tue, 26 Sep 2017 08:49 am, Stefan Ram wrote: > So, is there some mechanism in Python that can bind a method > to an object so that the caller does not have to specify the > object in the call? Indeed there is. Methods (like functions) are first-class values in Python, so you can do: py> finder = "Hello World!".find py> finder("W") 6 We say that `finder` is a bound method, meaning that it is a method object that already knows the instance to operate on. Python also has unbound methods: method objects that don't know the instance to operate on, and so the caller has to provide it: py> unbound_finder = str.find py> unbound_finder("Goodbye for now", "f") 8 In Python 2, both bound and unbound methods were implemented as the same underlying type, namely a thin wrapper around a function. In Python 3, unbound methods no longer use the wrapper, and just return the function object itself. The wrapper can be found in the types module: from types import MethodType -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Mon Sep 25 21:20:24 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 26 Sep 2017 11:20:24 +1000 Subject: Printing a Chunk Of Words References: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> Message-ID: <59c9ab58$0$14942$b1db1813$d948b532@news.astraweb.com> On Tue, 26 Sep 2017 10:15 am, Cai Gengyang wrote: > """ [snip text] > """ > > If I simply want to print a chunk of words and a paragraph like the above, > what command should I use ? Print to the terminal? Use print(). Print to an actual printer? There's no built-in command in Python to do so, and to be honest, I'm not sure how to do it. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Mon Sep 25 22:20:23 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 26 Sep 2017 12:20:23 +1000 Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: <59c9b969$0$14963$b1db1813$d948b532@news.astraweb.com> On Tue, 26 Sep 2017 02:54 am, Ned Batchelder wrote: [...] Heh, its hard to avoid getting sucked into the sinkhole of definitional debates, isn't it? :-) [...] > But in this line: > > x = 2 + 2 > > You can say, > > the value of x is 4 If we're talking about the highest level abstraction level, namely the Python code, that would be the right answer. Provided that we understand that as short-hand for: > the value of x is an int object with a value of 4 However: > or, > > the value of x is a reference to an int object with a value of 4, while that's true from a certain perspective, it's not the high-level Python perspective. Its that of the implementation. It's a perfectly valid perspective, and its often not just useful but (almost) necessary. Some behaviours of Python are difficult to understand unless we dip down an abstraction level and look at the implementation. > and in some ways, each of those is a correct statement. They are > different perspectives on the same complicated abstract relationships > inside your program.? Most of the disagreements in this thread stem from > someone picking one of those three statements and insisting that it is > *the* right statement, or from differing interpretations of words like > value, reference, pointer, alias, etc. This topic has been discussed a lot over the last few weeks/months, and that's something I've also said: it is useful if not necessary to discuss different levels of abstractions, but one needs to be clear when you are doing so. We all take verbal short-cuts from time to time, and I'll often use language like "evaluating the expression returns a reference (a pointer) to the object ..." (language which Marko would, I think, agree with) if I feel it brings insight to the question being discussed. From a purely pedantic point of view, I'll say I'm slightly naughty to do so, because I'm crossing abstractions without being explicit about it. "Explicit is better than implicit." So we all do it. I have no problem with people taking short-cuts or crossing abstractions and even mixing explanations from different levels, provided it brings insight and clarity to the question rather than confusion. Its better to be explicit about it when you do so ("under the hood, the interpreter uses a pointer to the object...") but we're all only human and sometimes we make implicit assumptions. But I do have to wonder about people who insist on keeping an inflexible, single-minded point of view even in the face of confusion. To use your analogy from below, it is as if they were absolutely, categorically denying that pressing the gas pedal (accelerator pedal) has anything to do with the car moving, because its the engine that makes it move, and that's the only right answer. Its fine to discuss what happens in different abstraction layers, but be clear about it when you do. > Software gets complicated because it involves multiple levels of > abstraction layered on top of each other.? We might as well be arguing > like this: > > A: "The gas pedal makes the car go" > > ???? B: "Nonsense! The gas pedal supplies fuel to the engine, it's the > engine that makes the car go" [snip] Indeed. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From breamoreboy at yahoo.co.uk Mon Sep 25 22:35:26 2017 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 26 Sep 2017 03:35:26 +0100 Subject: Printing a Chunk Of Words In-Reply-To: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> References: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> Message-ID: On 26/09/2017 01:15, Cai Gengyang wrote: > """ > Boolean Operators > ------------------------ > True and True is True > True and False is False > False and True is False > False and False is False > > True or True is True > True or False is True > False or True is True > False or False is False > > Not True is False > Not False is True > > """ > > If I simply want to print a chunk of words and a paragraph like the above, what command should I use ? > If you are looking for quiet mode code I suggest you stick to the answer given by Chris Angelico earlier. If you want verbose aka Steven D'Aprano :) mode code how about:- from operator import and_, or_ from itertools import product print(''' Boolean Operators ------------------------ ''', end='') l = {and_: 'and', or_: 'or'} bools = (True, False) for logic in (and_, or_): for a, b in product(bools, repeat=2): ans = logic(a, b) print(f'{a} {l[logic]} {b} is {ans}') print() for b in bools: print(f'Not {b} is {not b}') -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email has been checked for viruses by AVG. http://www.avg.com From ben.usenet at bsb.me.uk Mon Sep 25 22:40:20 2017 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Tue, 26 Sep 2017 03:40:20 +0100 Subject: Printing a Chunk Of Words References: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> Message-ID: <87k20myygb.fsf@bsb.me.uk> ram at zedat.fu-berlin.de (Stefan Ram) writes: > Cai Gengyang writes: >> Boolean Operators >>------------------------ >>True and True is True >>True and False is False >>False and True is False >>False and False is False >>True or True is True >>True or False is True >>False or True is True >>False or False is False >>Not True is False >>Not False is True >>If I simply want to print a chunk of words and a paragraph >>like the above, what command should I use ? > > The following has about the same size as the original: > > S=' Boolean Operators/------------------------/1&1=' +\ > '1/1&0=0/0&1=0/0&0=0//1|1=1/1|0=1/0|1=1/0|0=0//!1=0/!0=1' > def D(x,y):global S; S=S.replace(x,y) > > D('/','\n');D('1','True');D('0','False');D('&',' and '); > D('|',' or ');D('!','Not ');D('=',' is ');D('!','Not '); > print(S) > > I wrote it just as an attempt to create a shorter piece > of source code, but I failed. Think functional! This is 257 characters: def D(x,y,s):return s.replace(x,y) print(D('1','True',D('0','False',D('&',' and ',D('|',' or ',D('!','Not ',D('=',' is ',D('!','Not ',""" Boolean Operators ------------------------ 1&1=1 1&0=0 0&1=0 0&0=0 1|1=1 1|0=1 0|1=1 0|0=0 !1=0 !0=1""")))))))) And applying the same idea twice I can get 255: def D(x,y,s):return s.replace(x,y) print(eval(D('"D','D("',D(',','","','''"D-,--,D1,True,D0,False,D&, and ,D|, or ,D!,Not ,D=, is ,D!,Not ,"" Boolean Operators ------------ 1&1=1 1&0=0 0&1=0 0&0=0 1|1=1 1|0=1 0|1=1 0|0=0 !1=0 !0=1"""))))))))''')))) -- Ben. From torriem at gmail.com Mon Sep 25 22:59:25 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 25 Sep 2017 20:59:25 -0600 Subject: Running a GUI program haults the calling program (linux) In-Reply-To: References: Message-ID: On 09/25/2017 06:38 PM, Kryptxy via Python-list wrote: > Is there any way that the GUI program is opened, and immediately the > control returns to calling program, instead of keeping the terminal > busy? Yes. This is a classic situation where you want to first fork() the process, then exec() the new app. There are a few steps to do this properly, so google for "python fork exec". From BILL_NOSPAM at whoknows.net Mon Sep 25 23:46:10 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Mon, 25 Sep 2017 23:46:10 -0400 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: References: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87a81i97mr.fsf@elektro.pacujo.net> <87h8vqlggf.fsf@elektro.pacujo.net> Message-ID: Chris Angelico wrote: > On Tue, Sep 26, 2017 at 5:35 AM, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> On Tue, Sep 26, 2017 at 12:26 AM, Marko Rauhamaa wrote: >>> Sorry, that was my bad in the terminology. But where do you get that >>> all Python expressions evaluate to pointers? >> What do they evaluate to if not pointers? Anton's "identities" would >> work, too. "Address" would do, as well. I have previously proposed the >> term "leash." Call it "link" or "handle" or "arrow" if you want to. >> >> The term used isn't important. What's important is to understand that >> each expression and subexpression produces and operates on pointers. > They evaluate to objects. Not to pointers to objects. Not to > references to objects. To objects. Expressions evaluate to actual > objects, and when you assign "name = value", you bind the name to the > object that value evaluates to. > > ChrisA And when you pass a reference r to a function, a copy of the reference is passed. So even if you reassign *that* copy of r to refer to another object, upon return, r still still refers to whatever it did originally. ::: case closed :::, I think. From BILL_NOSPAM at whoknows.net Mon Sep 25 23:49:41 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Mon, 25 Sep 2017 23:49:41 -0400 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: References: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87a81i97mr.fsf@elektro.pacujo.net> <3dac26dd-d811-f719-95ae-20e35091ea49@kynesim.co.uk> <878th2lg7g.fsf@elektro.pacujo.net> <636cad82-ffb3-d41f-5d9d-255f326dddfb@timgolden.me.uk> Message-ID: Tim Golden wrote: > On 25/09/2017 20:40, Marko Rauhamaa wrote: >> Rhodri James : >>> On 25/09/17 15:26, Marko Rauhamaa wrote: >>>> That's not what I said. I said all expressions *evaluate to* pointers. >>> >>> This may well be true in particular implementations, but it is an >>> implementation detail so Chris' point still stands. Another >>> implementation could evaluate expressions to indices (as BCPL used to >>> treat its globals), pieces of string or cheese, who knows? >> >> Those are all pointers. >> >> A pointer is something that points to a data object. > > (Slight sigh). Can I step in as a list owner and ask the people who > are so very fond of debating this topic again and again: please let it > drop. > > Threads such as this can remain interesting when the discussion > generates a better understanding of the subject matter as the > contributors are forced to articulate their positions leading to some > kind of convergence of understanding. > > However, even if this were the only iteration of this debate, it would > be clear by now that there's no chance of a simple "I see what you > mean" moment. And this is far from the only iteration, even in the > past few months. > > I feel for your need to demonstrate the validity of your respective > positions. But it has moved on from being an enlightening debate and > into the realms of mere tedium. > > Thanks. > > TJG Perhaps it would be better to amass examples and let them speak for themselves? From ned at nedbatchelder.com Tue Sep 26 00:44:47 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 26 Sep 2017 00:44:47 -0400 Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] In-Reply-To: <59c9b969$0$14963$b1db1813$d948b532@news.astraweb.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <59c9b969$0$14963$b1db1813$d948b532@news.astraweb.com> Message-ID: On 9/25/17 10:20 PM, Steve D'Aprano wrote: > On Tue, 26 Sep 2017 02:54 am, Ned Batchelder wrote: > [...] > > We've been asked nicely by the list mod to stop :) --Ned. From vek.m1234 at gmail.com Tue Sep 26 01:48:31 2017 From: vek.m1234 at gmail.com (Veek M) Date: Mon, 25 Sep 2017 22:48:31 -0700 (PDT) Subject: PyQt: Parenting a Widget Message-ID: Summary: Could someone explain widget and dialog parenting - the text book is not making sense. ###################### I'm trying to understand widget parenting, from the book: Rapid GUI Programming, pg 118, and thereabouts - he says: A. All PyQt classes that derive from QObjectand this includes all the widgets, since QWidget is a QObject subclasscan have a ?parent?. B. PyQt automatically repar- ents the widgets that are laid out. So although we did not give our widgets a parent of self (the Form instance),when we call setLayout() the layout manager gives ownership of the widgets and of itself to the form,and takes ownership of any nested layouts itself. This means that none of the widgets that are laid out is a top-level window, and all of them have parents, which is what we want. So when the form is deleted, all its child widgets and layouts will be deleted with ----------------------------- 1. In A, does he mean, you are ALLOWED to set a parent on a widget ONLY because its Base Class is QObject? With DockWidgets, you have to explicitly parent them - why? 2. If I create two widgets and wdget.show() them, and app.exec_() - which one becomes the main-window and which one is the memory leak? I have not used a layout manager so, one widget with no parent auto-becomes the main-window (as per B), which would result in a leak with the other? #!/usr/bin/python import sys, os, re from PyQt4.QtCore import * from PyQt4.QtGui import * app = QApplication(sys.argv) lbl = QLabel('Hello World') lbl.setWindowFlags(Qt.SplashScreen) lbl.show() txtBrw = QTextBrowser() txtBrw.show() QTimer.singleShot(3000, app.quit) app.exec_() 3. QObject --> QWidget --> QDialog --> Form --> Form_Layout_Manager --> Nested_Layout_Manager B, says that the layout manager parents the widgets under it and makes 'Form' the parent. If the Form Layout Manager is taking charge of the Nested Layout Manager, who is the parent of the widgets under the Nested Layout Mangaer? 4. In the Chapter on 'Dialogs', I am trying to create a QMainWindow Style application with one label as the central widget and one button to invoke a dialog. It doesn't work and I get: QWidget::setLayout: Attempting to set QLayout "" on Parent "", which already has a layout I tried this link and it made no sense: https://stackoverflow.com/questions/25450598/qlayout-attempting-to-add-qlayout-to-qwidget-which-already-has-a-layout How does parenting work in PyQt? What is autoparented, what needs to be explicitly parented and who is scrwing whom? Additionally, why is my button, hiding? #!/usr/bin/python import sys, os, re from PyQt4.QtCore import * from PyQt4.QtGui import * app = QApplication(sys.argv) class Dialog(QDialog): def __init__(self, parent = None): super(Dialog, self).__init__(parent) self.lbl = QLabel('Width: ') self.spn = QSpinBox() self.spn.setRange(0, 100) self.lbl.setBuddy(self.spn) self.chk = QCheckBox('&Beveled Edges') self.lbl_styl = QLabel('Style') self.lst = QComboBox() self.lst.addItems(['dashed', 'dotted', 'star']) self.lbl_styl.setBuddy(self.lst) self.ok_btn = QPushButton('&Ok') self.cncl_btn = QPushButton('&Cancel') self.layout([(self.lbl, 0, 0), (self.spn, 0, 1), (self.chk, 0, 2), (self.lbl_styl, 1, 0), (self.lst, 1, 1), (self.ok_btn, 2, 0), (self.cncl_btn, 2, 1)]) def layout(self, wgts = []): self.lyt = QGridLayout() for wgt, row, col in wgts: self.lyt.addWidget(wgt, row, col) self.setLayout(self.lyt) class Parent(QMainWindow): def __init__(self, parent = None): super(Parent, self).__init__(parent) lbl = QLabel('HELLO WORLD') btn = QPushButton('&Start Dialog') lbl.setBuddy(btn) lyt = QHBoxLayout() lyt.addWidget(lbl) lyt.addWidget(btn) self.setLayout(lyt) self.connect(btn, SIGNAL('clicked()'), self.popup_dialog) def popup_dialog(self): x = Dialog(self) if x.exec_(): print(x.spn.value()) p = Parent() p.show() app.exec_() From vek.m1234 at gmail.com Tue Sep 26 02:16:12 2017 From: vek.m1234 at gmail.com (Veek M) Date: Mon, 25 Sep 2017 23:16:12 -0700 (PDT) Subject: PyQt: Parenting a Widget In-Reply-To: References: Message-ID: <6a979c13-b0c6-4775-8d40-5a76e32dcd14@googlegroups.com> On Tuesday, September 26, 2017 at 11:18:54 AM UTC+5:30, Veek M wrote: > Summary: Could someone explain widget and dialog parenting - the text book is not making sense. > ###################### > I'm trying to understand widget parenting, from the book: Rapid GUI Programming, pg 118, and thereabouts - he says: > > A. All PyQt classes that derive from QObjectand this includes all the widgets, > since QWidget is a QObject subclasscan have a ?parent?. > > B. PyQt automatically repar- > ents the widgets that are laid out. So although we did not give our widgets a > parent of self (the Form instance),when we call setLayout() the layout manager > gives ownership of the widgets and of itself to the form,and takes ownership of > any nested layouts itself. This means that none of the widgets that are laid out > is a top-level window, and all of them have parents, which is what we want. So > when the form is deleted, all its child widgets and layouts will be deleted with > ----------------------------- > 1. In A, does he mean, you are ALLOWED to set a parent on a widget ONLY because its Base Class is QObject? > > With DockWidgets, you have to explicitly parent them - why? > > 2. If I create two widgets and wdget.show() them, and app.exec_() - which one becomes the main-window and which one is the memory leak? I have not used a layout manager so, one widget with no parent auto-becomes the main-window (as per B), which would result in a leak with the other? > > #!/usr/bin/python > > import sys, os, re > > > from PyQt4.QtCore import * > from PyQt4.QtGui import * > > app = QApplication(sys.argv) > > lbl = QLabel('Hello World') > lbl.setWindowFlags(Qt.SplashScreen) > lbl.show() > txtBrw = QTextBrowser() > txtBrw.show() > > QTimer.singleShot(3000, app.quit) > app.exec_() > > 3. QObject --> QWidget --> QDialog --> Form --> Form_Layout_Manager --> Nested_Layout_Manager > > B, says that the layout manager parents the widgets under it and makes 'Form' the parent. If the Form Layout Manager is taking charge of the Nested Layout Manager, who is the parent of the widgets under the Nested Layout Mangaer? > > 4. In the Chapter on 'Dialogs', I am trying to create a QMainWindow Style application with one label as the central widget and one button to invoke a dialog. It doesn't work and I get: > > QWidget::setLayout: Attempting to set QLayout "" on Parent "", which already has a layout > > I tried this link and it made no sense: > https://stackoverflow.com/questions/25450598/qlayout-attempting-to-add-qlayout-to-qwidget-which-already-has-a-layout > > How does parenting work in PyQt? What is autoparented, what needs to be explicitly parented and who is scrwing whom? Additionally, why is my button, hiding? > > > #!/usr/bin/python > > import sys, os, re > > > from PyQt4.QtCore import * > from PyQt4.QtGui import * > > app = QApplication(sys.argv) > > class Dialog(QDialog): > def __init__(self, parent = None): > super(Dialog, self).__init__(parent) > > self.lbl = QLabel('Width: ') > self.spn = QSpinBox() > self.spn.setRange(0, 100) > self.lbl.setBuddy(self.spn) > > self.chk = QCheckBox('&Beveled Edges') > > self.lbl_styl = QLabel('Style') > self.lst = QComboBox() > self.lst.addItems(['dashed', 'dotted', 'star']) > self.lbl_styl.setBuddy(self.lst) > > self.ok_btn = QPushButton('&Ok') > self.cncl_btn = QPushButton('&Cancel') > > self.layout([(self.lbl, 0, 0), (self.spn, 0, 1), (self.chk, 0, 2), > (self.lbl_styl, 1, 0), (self.lst, 1, 1), > (self.ok_btn, 2, 0), (self.cncl_btn, 2, 1)]) > > def layout(self, wgts = []): > self.lyt = QGridLayout() > for wgt, row, col in wgts: > self.lyt.addWidget(wgt, row, col) > > self.setLayout(self.lyt) > > > class Parent(QMainWindow): > def __init__(self, parent = None): > super(Parent, self).__init__(parent) > > lbl = QLabel('HELLO WORLD') > btn = QPushButton('&Start Dialog') > lbl.setBuddy(btn) > > lyt = QHBoxLayout() > lyt.addWidget(lbl) > lyt.addWidget(btn) > > self.setLayout(lyt) > self.connect(btn, SIGNAL('clicked()'), self.popup_dialog) > > def popup_dialog(self): > x = Dialog(self) > if x.exec_(): > print(x.spn.value()) > > p = Parent() > p.show() > > app.exec_() I fixed some of it by deleting the: Parent self.setLayout(lyt) I don't understand why that works - aren't we supposed to attach a layout to the Parent/MainWindow object? Why not? Also, I made the: Parent self.setCentralWidget(btn) so the button is the central widget. To use the Label, I think I would have to create a composite widget which is too complicated for me, currently. Now. it works so I tested some more and added: def popup_dialog(self): x = Dialog(self) y = Dialog(self) y.show() if x.exec_(): print(x.spn.value()) AND class Dialog(QDialog): self.connect(self.cncl_btn, SIGNAL('clicked()'), self.close) So my dialog pops up and because exec_ is being called on 'x', I have to first close that widget before I can interact with my button and 'y'. However, let's say I close the 'x' dialog - then I can click on 'Button' and I get two more dialogs which don't lock anything - why?? From greg.ewing at canterbury.ac.nz Tue Sep 26 02:25:48 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 26 Sep 2017 19:25:48 +1300 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <59c85dfa$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: Neil Cerutti wrote: > The quest to find a succinct way to categorize Python's argument > passing for non-Python programmers strikes me as a sincere effort > to to simplify something that just isn't simple. I don't see how it's useful to do that in the first place. Under what circumstances would you find yourself having to explain *just* Python parameter passing and nothing else about the language? -- Greg From greg.ewing at canterbury.ac.nz Tue Sep 26 02:30:16 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 26 Sep 2017 19:30:16 +1300 Subject: [Tutor] beginning to code In-Reply-To: References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c714da$0$14959$b1db1813$d948b532@news.astraweb.com> <25e3c967-765a-a120-dbfd-42dde76ae073@nedbatchelder.com> Message-ID: Antoon Pardon wrote: > It also says: This typically means that the function can modify the variable > used as argument, something Python can do that. No, it can't. It can modify the *object* bound to the variable, but *not* the variable itself. If you think it can, then you're misunderstanding what is meant by "variable" in this context. -- Greg From rosuav at gmail.com Tue Sep 26 02:34:37 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Sep 2017 16:34:37 +1000 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <59c85dfa$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: On Tue, Sep 26, 2017 at 4:25 PM, Gregory Ewing wrote: > Neil Cerutti wrote: >> >> The quest to find a succinct way to categorize Python's argument >> passing for non-Python programmers strikes me as a sincere effort >> to to simplify something that just isn't simple. > > > I don't see how it's useful to do that in the first place. > Under what circumstances would you find yourself having to > explain *just* Python parameter passing and nothing else > about the language? And this entire debate is ONLY about trying to explain to people who already know some other language AND think that call-by-value and call-by-reference are the only two options. I've explained Python's (or JavaScript's, since they're the same) object model to a number of novice programmers without any difficulties, without talking about pointers or invisible values or any of that junk. There are just two things to explain: the concept of names referring to objects, and variable scope. ChrisA From cs at cskk.id.au Tue Sep 26 02:37:36 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 26 Sep 2017 16:37:36 +1000 Subject: Running a GUI program haults the calling program (linux) In-Reply-To: References: Message-ID: <20170926063735.GA99215@cskk.homeip.net> On 25Sep2017 20:59, Michael Torrie wrote: >On 09/25/2017 06:38 PM, Kryptxy via Python-list wrote: >> Is there any way that the GUI program is opened, and immediately the >> control returns to calling program, instead of keeping the terminal >> busy? > >Yes. This is a classic situation where you want to first fork() the >process, then exec() the new app. There are a few steps to do this >properly, so google for "python fork exec". No, subprocess does this stuff for you. I think the OP's missed some important stuff out. -- Cameron Simpson Baseball cards that suck in energy and run e-ink animated displays - overhead by WIRED at the Intelligent Printing conference Oct2006 From cs at cskk.id.au Tue Sep 26 02:39:56 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 26 Sep 2017 16:39:56 +1000 Subject: Running a GUI program haults the calling program (linux) In-Reply-To: References: Message-ID: <20170926063956.GA694@cskk.homeip.net> On 25Sep2017 20:38, Kryptxy wrote: >I want to run a GUI program (transmission-gtk) from python. This is what I do: > >import subprocess >subprocess.Popen(['transmission-gtk', link], stdout=subprocess.PIPE, stderr=subprocess.PIPE) > >Where `link` is some magnetic link. > >This command opens transmission-gtk, but it haults the calling program, and keeps the terminal busy till the time GUI is running. >As soon as GUI is closed, the control goes back to the program. I do not believe this is all your code. Please post a _complete_ example. Popen dispatches a process. It does not wait for it to terminate. GUI programs are not special. Therefore, if your calling python program is blocking, it is blocking somewhere other that this line of code. Please show us where. Consider putting print() calls through your code to locate where your program stalls. Cheers, Cameron Simpson (formerly cs at zip.com.au) From greg.ewing at canterbury.ac.nz Tue Sep 26 02:47:42 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 26 Sep 2017 19:47:42 +1300 Subject: Calling methods without objects? In-Reply-To: References: Message-ID: Thomas Jollans wrote: > When an object is > constructed from a class, all functions in the class are turned into > method objects that refer back to the original object. That's not quite true. Nothing is done to the methods at the time an instance is created; rather, a bound method object is created each time a method is looked up via an instance. -- Greg From antoon.pardon at vub.be Tue Sep 26 02:58:26 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 26 Sep 2017 08:58:26 +0200 Subject: [Tutor] beginning to code In-Reply-To: <25e3c967-765a-a120-dbfd-42dde76ae073@nedbatchelder.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c714da$0$14959$b1db1813$d948b532@news.astraweb.com> <25e3c967-765a-a120-dbfd-42dde76ae073@nedbatchelder.com> Message-ID: <3e8bf237-59cc-b728-b629-90f89699dcea@vub.be> Op 25-09-17 om 21:44 schreef Ned Batchelder: > > Wikipedia has the right definition of call by reference > (https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_reference): > > ?? /Call by reference/ (also referred to as /pass by reference/) is an > ?? evaluation strategy where a function receives an implicit reference > ?? to > ?? a variable used as argument, rather than a copy of its value. This > ?? typically means that the function can modify (i.e. assign to > ?? ) > ?? the variable used as argument?something that will be seen by its > caller. > > The key idea here is that it is a reference to a *variable* that is > passed, not a reference to a value.? Python has no references to > variables, so it cannot support call by reference.?? Because Python > passes references to values, it is easy to call it "call by > reference," but that is not what the term means. > > The Wikipedia definition unfortunately includes "rather than a copy of > its value," as if those are the only two options (a common > misunderstanding). > > Elsewhere in this thread, someone asserted that to be call by > reference, you have to be able to write a swap(x,y) function.? True > call-by-reference would make this possible.? Python cannot do it. I can write a swap function for lists in python. Can I now conclude that lists are passed by reference? -- Antoon Pardon. From kryptxy at protonmail.com Tue Sep 26 03:20:34 2017 From: kryptxy at protonmail.com (Kryptxy) Date: Tue, 26 Sep 2017 03:20:34 -0400 Subject: Running a GUI program haults the calling program (linux) In-Reply-To: References: Message-ID: Sent with [ProtonMail](https://protonmail.com) Secure Email. > -------- Original Message -------- > Subject: Re: Running a GUI program haults the calling program (linux) > Local Time: 26 September 2017 6:20 AM > UTC Time: 26 September 2017 00:50 > From: rosuav at gmail.com > To: python-list > > On Tue, Sep 26, 2017 at 10:38 AM, Kryptxy via Python-list > wrote: >> I want to run a GUI program (transmission-gtk) from python. This is what I do: >> >> import subprocess >> subprocess.Popen(["transmission-gtk", link], stdout=subprocess.PIPE, stderr=subprocess.PIPE) >> >> Where `link` is some magnetic link. >> >> This command opens transmission-gtk, but it haults the calling program, and keeps the terminal busy till the time GUI is running. >> As soon as GUI is closed, the control goes back to the program. >> >> Is there any way that the GUI program is opened, and immediately the control returns to calling program, instead of keeping the terminal busy? >> >> (I know transmission-remote can be used for adding torrents. Looking for a way around for transmission-gtk specifically). > > I"m not sure why you can"t signal it, but I"ll take that parenthesized > comment as an indication that you know about (a) the > transmission-remote command, and/or (b) the fact that transmission-gtk > can be remote-controlled fairly effectively. (For instance, I have a > script that puts Transmission into turtle mode, then does something, > and then takes Transmission out of turtle mode. It"s two lines of > shell script to do it.) Yes I know about transmission-remote. I am trying to figure out a way for running transmission-gtk without causing program to hault. > So, you want to "fire-and-forget" a GUI program. Or more generally, > _any_ program. My suspicion here is that, since Popen shouldn"t be > blocking, that you"re filling up one of your pipes. Can you try > removing the stdout and stderr parameters, and see what that does? You > should be able to fire off a subprocess and then carry on with the > program. It might make a lot of noise, if transmission produces a ton > of output; but if that happens, try std{out,err}=subprocess.DEVNULL > instead of PIPE - unless you"re specifically trying to read the > output? Tried std{out,err}=subprocess.DEVNULL - Did not work. The program still haults. Also, worth noting that the program haults when transmission-gtk is opened for the first time. Suppose if the GUI windows is already open, and then subprocess.Popen() is run, the torrent is added successfully, and control goes back to calling program. (That is the program does not hault). From kryptxy at protonmail.com Tue Sep 26 03:34:50 2017 From: kryptxy at protonmail.com (Kryptxy) Date: Tue, 26 Sep 2017 03:34:50 -0400 Subject: Running a GUI program haults the calling program (linux) In-Reply-To: <20170926063956.GA694@cskk.homeip.net> References: <20170926063956.GA694@cskk.homeip.net> Message-ID: <0keiUeQITaGL5cox8fTblwbS-R9sTx3TjtVniTAphcERDG5xvgrzIROOUqVIj1wn6lq-zjiCD9K5rFj2fKHucWvtns3JiQe6PPJnK1R8RkU=@protonmail.com> Sent with [ProtonMail](https://protonmail.com) Secure Email. > -------- Original Message -------- > Subject: Re: Running a GUI program haults the calling program (linux) > Local Time: 26 September 2017 12:09 PM > UTC Time: 26 September 2017 06:39 > From: cs at cskk.id.au > To: Kryptxy > python-list > > On 25Sep2017 20:38, Kryptxy wrote: >>I want to run a GUI program (transmission-gtk) from python. This is what I do: >> >>import subprocess >>subprocess.Popen(["transmission-gtk", link], stdout=subprocess.PIPE, stderr=subprocess.PIPE) >> >>Where `link` is some magnetic link. >> >>This command opens transmission-gtk, but it haults the calling program, and keeps the terminal busy till the time GUI is running. >>As soon as GUI is closed, the control goes back to the program. > > I do not believe this is all your code. Please post a _complete_ example. > > Popen dispatches a process. It does not wait for it to terminate. GUI programs > are not special. Therefore, if your calling python program is blocking, it is > blocking somewhere other that this line of code. Please show us where. > > Consider putting print() calls through your code to locate where your program > stalls. > > Cheers, > Cameron Simpson (formerly cs at zip.com.au) Here - p = subprocess.Popen(['transmission-gtk', link], stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, error = p.communicate() error = error.decode('utf-8') output = output.decode('utf-8') if error != '': print("\nUnable to load torrent.") else: print("Torrent added successfully!") Here, transmission-gtk is opened and the program haults (at subprocess.Popen() statement). When I close the GUI window, I get the message "Unable to load torrent". Error message I get: `Unable to parse nameserver address 8.8.8.8,` `(transmission-gtk:3982): GLib-CRITICAL **: g_file_test: assertion 'filename != NULL' failed` From greg.ewing at canterbury.ac.nz Tue Sep 26 03:42:09 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 26 Sep 2017 20:42:09 +1300 Subject: Printing a Chunk Of Words In-Reply-To: <87k20myygb.fsf@bsb.me.uk> References: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> <87k20myygb.fsf@bsb.me.uk> Message-ID: Ben Bacarisse wrote: > Think functional! This is 257 characters: 250 chars, 17 shorter than the text it produces: a=[];o=[];n=[];A=list.append for b in range(3,-1,-1): x=bool(b>>1);y=bool(b&1);A(a,"%s and %s is %s"%(x,y,x and y));A(o,"%s or %s is %s"%(x,y,x or y)) if x:A(n,"not %s is %s"%(y,not y)) print(" Boolean Operators\n"+"-"*24+"\n"+"\n".join(a+o+n)) -- Greg From __peter__ at web.de Tue Sep 26 03:56:51 2017 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Sep 2017 09:56:51 +0200 Subject: Running a GUI program haults the calling program (linux) References: <20170926063956.GA694@cskk.homeip.net> <0keiUeQITaGL5cox8fTblwbS-R9sTx3TjtVniTAphcERDG5xvgrzIROOUqVIj1wn6lq-zjiCD9K5rFj2fKHucWvtns3JiQe6PPJnK1R8RkU=@protonmail.com> Message-ID: Kryptxy via Python-list wrote: > Sent with [ProtonMail](https://protonmail.com) Secure Email. > >> -------- Original Message -------- >> Subject: Re: Running a GUI program haults the calling program (linux) >> Local Time: 26 September 2017 12:09 PM >> UTC Time: 26 September 2017 06:39 >> From: cs at cskk.id.au >> To: Kryptxy >> python-list >> >> On 25Sep2017 20:38, Kryptxy wrote: >>>I want to run a GUI program (transmission-gtk) from python. This is what >>>I do: >>> >>>import subprocess >>>subprocess.Popen(["transmission-gtk", link], stdout=subprocess.PIPE, >>>stderr=subprocess.PIPE) >>> >>>Where `link` is some magnetic link. >>> >>>This command opens transmission-gtk, but it haults the calling program, >>>and keeps the terminal busy till the time GUI is running. As soon as GUI >>>is closed, the control goes back to the program. >> >> I do not believe this is all your code. Please post a _complete_ example. >> >> Popen dispatches a process. It does not wait for it to terminate. GUI >> programs are not special. Therefore, if your calling python program is >> blocking, it is blocking somewhere other that this line of code. Please >> show us where. >> >> Consider putting print() calls through your code to locate where your >> program stalls. >> >> Cheers, >> Cameron Simpson (formerly cs at zip.com.au) > > Here - > > p = subprocess.Popen(['transmission-gtk', link], stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > output, error = p.communicate() That's the problem. communicate() *must* block to collect the program's entire output. You get what you ask for... > error = error.decode('utf-8') > output = output.decode('utf-8') > if error != '': > print("\nUnable to load torrent.") > else: > print("Torrent added successfully!") > > Here, transmission-gtk is opened and the program haults (at > subprocess.Popen() statement). When I close the GUI window, I get the > message "Unable to load torrent". > > Error message I get: > `Unable to parse nameserver address 8.8.8.8,` > `(transmission-gtk:3982): GLib-CRITICAL **: g_file_test: assertion > 'filename != NULL' failed` From ben+python at benfinney.id.au Tue Sep 26 04:10:48 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 26 Sep 2017 18:10:48 +1000 Subject: Change project licence? References: <85377o7r2h.fsf@benfinney.id.au> <14zQlz1SK1NTt1HIvR3Sulx3cezj97bl-sNUxZCLdYgBJg2NdoaCoqiQlhkIS0S7jN9h57CEdTVVrCwe7FAmmxmLLMegG92tgFDMQM7RsuQ=@protonmail.com> Message-ID: <85efqt6fsn.fsf@benfinney.id.au> Kryptxy via Python-list writes: > Yep. I will wait for a response. Thank you! There remains, of course, the option to keep developing and distributing the work under GNU GPL. As Chris points out, the GNU GPL terms are plenty permissive enough and keep the playing field guaranteed level for all. You can continue with that license grant indefinitely. -- \ ?One time I went to a drive-in in a cab. The movie cost me | `\ ninety-five dollars.? ?Steven Wright | _o__) | Ben Finney From marko at pacujo.net Tue Sep 26 04:35:54 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 26 Sep 2017 11:35:54 +0300 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <59c85dfa$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: <87zi9h7t79.fsf@elektro.pacujo.net> Chris Angelico : > I've explained Python's (or JavaScript's, since they're the same) > object model to a number of novice programmers without any > difficulties, without talking about pointers or invisible values or > any of that junk. There are just two things to explain: the concept of > names referring to objects, and variable scope. The JavaScript spec wrt assignment etc is actually a bit difficult to understand: . Scheme, which also shares the same object model with Python, has a very down-to-earth specification that uses the term "location:" Marko From kryptxy at protonmail.com Tue Sep 26 04:48:41 2017 From: kryptxy at protonmail.com (Kryptxy) Date: Tue, 26 Sep 2017 04:48:41 -0400 Subject: Running a GUI program haults the calling program (linux) In-Reply-To: References: <20170926063956.GA694@cskk.homeip.net> <0keiUeQITaGL5cox8fTblwbS-R9sTx3TjtVniTAphcERDG5xvgrzIROOUqVIj1wn6lq-zjiCD9K5rFj2fKHucWvtns3JiQe6PPJnK1R8RkU=@protonmail.com> Message-ID: > -------- Original Message -------- > Subject: Re: Running a GUI program haults the calling program (linux) > Local Time: 26 September 2017 1:26 PM > UTC Time: 26 September 2017 07:56 > From: __peter__ at web.de > To: python-list at python.org > > Kryptxy via Python-list wrote: > >> Sent with [ProtonMail](https://protonmail.com) Secure Email. >> >>> -------- Original Message -------- >>> Subject: Re: Running a GUI program haults the calling program (linux) >>> Local Time: 26 September 2017 12:09 PM >>> UTC Time: 26 September 2017 06:39 >>> From: cs at cskk.id.au >>> To: Kryptxy >>> python-list >>> >>> On 25Sep2017 20:38, Kryptxy wrote: >>>>I want to run a GUI program (transmission-gtk) from python. This is what >>>>I do: >>>> >>>>import subprocess >>>>subprocess.Popen(["transmission-gtk", link], stdout=subprocess.PIPE, >>>>stderr=subprocess.PIPE) >>>> >>>>Where `link` is some magnetic link. >>>> >>>>This command opens transmission-gtk, but it haults the calling program, >>>>and keeps the terminal busy till the time GUI is running. As soon as GUI >>>>is closed, the control goes back to the program. >>> >>> I do not believe this is all your code. Please post a _complete_ example. >>> >>> Popen dispatches a process. It does not wait for it to terminate. GUI >>> programs are not special. Therefore, if your calling python program is >>> blocking, it is blocking somewhere other that this line of code. Please >>> show us where. >>> >>> Consider putting print() calls through your code to locate where your >>> program stalls. >>> >>> Cheers, >>> Cameron Simpson (formerly cs at zip.com.au) >> >> Here - >> >> p = subprocess.Popen(["transmission-gtk", link], stdout=subprocess.PIPE, >> stderr=subprocess.PIPE) >> output, error = p.communicate() > > That"s the problem. communicate() *must* block to collect the program"s > entire output. You get what you ask for... Thanks! It worked! From tjol at tjol.eu Tue Sep 26 04:52:49 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 26 Sep 2017 10:52:49 +0200 Subject: PyQt: Parenting a Widget In-Reply-To: <6a979c13-b0c6-4775-8d40-5a76e32dcd14@googlegroups.com> References: <6a979c13-b0c6-4775-8d40-5a76e32dcd14@googlegroups.com> Message-ID: On 2017-09-26 08:16, Veek M wrote: > On Tuesday, September 26, 2017 at 11:18:54 AM UTC+5:30, Veek M wrote: >> Summary: Could someone explain widget and dialog parenting - the text book is not making sense. >> ###################### >> I'm trying to understand widget parenting, from the book: Rapid GUI Programming, pg 118, and thereabouts - he says: >> >> A. All PyQt classes that derive from QObjectand this includes all the widgets, >> since QWidget is a QObject subclasscan have a ?parent?. >> >> B. PyQt automatically repar- >> ents the widgets that are laid out. So although we did not give our widgets a >> parent of self (the Form instance),when we call setLayout() the layout manager >> gives ownership of the widgets and of itself to the form,and takes ownership of >> any nested layouts itself. This means that none of the widgets that are laid out >> is a top-level window, and all of them have parents, which is what we want. So >> when the form is deleted, all its child widgets and layouts will be deleted with >> ----------------------------- >> 1. In A, does he mean, you are ALLOWED to set a parent on a widget ONLY because its Base Class is QObject? >> >> With DockWidgets, you have to explicitly parent them - why? >> >> 2. If I create two widgets and wdget.show() them, and app.exec_() - which one becomes the main-window and which one is the memory leak? I have not used a layout manager so, one widget with no parent auto-becomes the main-window (as per B), which would result in a leak with the other? >> >> #!/usr/bin/python >> >> import sys, os, re >> >> >> from PyQt4.QtCore import * >> from PyQt4.QtGui import * >> >> app = QApplication(sys.argv) >> >> lbl = QLabel('Hello World') >> lbl.setWindowFlags(Qt.SplashScreen) >> lbl.show() >> txtBrw = QTextBrowser() >> txtBrw.show() >> >> QTimer.singleShot(3000, app.quit) >> app.exec_() >> >> 3. QObject --> QWidget --> QDialog --> Form --> Form_Layout_Manager --> Nested_Layout_Manager >> >> B, says that the layout manager parents the widgets under it and makes 'Form' the parent. If the Form Layout Manager is taking charge of the Nested Layout Manager, who is the parent of the widgets under the Nested Layout Mangaer? >> >> 4. In the Chapter on 'Dialogs', I am trying to create a QMainWindow Style application with one label as the central widget and one button to invoke a dialog. It doesn't work and I get: >> >> QWidget::setLayout: Attempting to set QLayout "" on Parent "", which already has a layout >> >> I tried this link and it made no sense: >> https://stackoverflow.com/questions/25450598/qlayout-attempting-to-add-qlayout-to-qwidget-which-already-has-a-layout >> >> How does parenting work in PyQt? What is autoparented, what needs to be explicitly parented and who is scrwing whom? Additionally, why is my button, hiding? >> >> >> #!/usr/bin/python >> >> import sys, os, re >> >> >> from PyQt4.QtCore import * >> from PyQt4.QtGui import * >> >> app = QApplication(sys.argv) >> >> class Dialog(QDialog): >> def __init__(self, parent = None): >> super(Dialog, self).__init__(parent) >> >> self.lbl = QLabel('Width: ') >> self.spn = QSpinBox() >> self.spn.setRange(0, 100) >> self.lbl.setBuddy(self.spn) >> >> self.chk = QCheckBox('&Beveled Edges') >> >> self.lbl_styl = QLabel('Style') >> self.lst = QComboBox() >> self.lst.addItems(['dashed', 'dotted', 'star']) >> self.lbl_styl.setBuddy(self.lst) >> >> self.ok_btn = QPushButton('&Ok') >> self.cncl_btn = QPushButton('&Cancel') >> >> self.layout([(self.lbl, 0, 0), (self.spn, 0, 1), (self.chk, 0, 2), >> (self.lbl_styl, 1, 0), (self.lst, 1, 1), >> (self.ok_btn, 2, 0), (self.cncl_btn, 2, 1)]) >> >> def layout(self, wgts = []): >> self.lyt = QGridLayout() >> for wgt, row, col in wgts: >> self.lyt.addWidget(wgt, row, col) >> >> self.setLayout(self.lyt) >> >> >> class Parent(QMainWindow): >> def __init__(self, parent = None): >> super(Parent, self).__init__(parent) >> >> lbl = QLabel('HELLO WORLD') >> btn = QPushButton('&Start Dialog') >> lbl.setBuddy(btn) >> >> lyt = QHBoxLayout() >> lyt.addWidget(lbl) >> lyt.addWidget(btn) >> >> self.setLayout(lyt) >> self.connect(btn, SIGNAL('clicked()'), self.popup_dialog) >> >> def popup_dialog(self): >> x = Dialog(self) >> if x.exec_(): >> print(x.spn.value()) >> >> p = Parent() >> p.show() >> >> app.exec_() > > I fixed some of it by deleting the: > Parent > self.setLayout(lyt) > > I don't understand why that works - aren't we supposed to attach a layout to the Parent/MainWindow object? Why not? > > Also, I made the: > Parent > self.setCentralWidget(btn) IIRC, QMainWindow is a bit weird, since it provides things like menu and status bars. Everything normally goes into a "central widget". The (or: a) thing to do is (I suspect): class Parent(QMainWindow): def __init__(self, parent=None): # This is the future. super() is smart now. super().__init__(parent) lbl = QLabel('HELLO WORLD') btn = QPushButton('&Start Dialog') lbl.setBuddy(btn) lyt = QHBoxLayout() lyt.addWidget(lbl) lyt.addWidget(btn) central_widget = QWidget() central_widget.setLayout(lyt) self.setCentralWidget(central_widget) # Use new-style signals and slots! They're nicer! btn.clicked.connect(self.popup_dialog) def popup_dialog(self): x = Dialog(self) if x.exec_(): print(x.spn.value()) I normally like to explicitly parent my widgets on construction, but that's not necessary and I'm probably doing it wrong anyway. Aside: I notice you're using PyQt4. That's great, I do too (for now), but I suggest you consider moving to PyQt5. PyQt4 is slowly disappearing. Anaconda (on Windows at least) has annoying dependency structures that force you to use old versions of the scientific python stack if you want to use qt4. I'm going to have to upgrade soon. The differences between PyQt4 and PyQt5 aren't massive, but they've moved around some classes (QtGui has been split into two packages, which is going to be annoying to migrate) and support for old-style signal and slot syntax has been dropped (good riddance). Also, if you're using Python 2: don't. Just don't. It's not 2012 any more. (I don't know what you're using, but /usr/bin/python is normally Python 2) > > so the button is the central widget. To use the Label, I think I would have to create a composite widget which is too complicated for me, currently. > > Now. it works so I tested some more and added: > def popup_dialog(self): > x = Dialog(self) > y = Dialog(self) > y.show() > if x.exec_(): > print(x.spn.value()) > AND > > class Dialog(QDialog): > self.connect(self.cncl_btn, SIGNAL('clicked()'), self.close) > > So my dialog pops up and because exec_ is being called on 'x', I have to first close that widget before I can interact with my button and 'y'. However, let's say I close the 'x' dialog - then I can click on 'Button' and I get two more dialogs which don't lock anything - why?? > -- Thomas Jollans From ben+python at benfinney.id.au Tue Sep 26 05:13:53 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 26 Sep 2017 19:13:53 +1000 Subject: Grumpy-pants spoil-sport References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: <858th16cvi.fsf_-_@benfinney.id.au> Steve D'Aprano writes: > On Mon, 25 Sep 2017 10:53 pm, Ned Batchelder wrote: > > > Would we be able to end these interminable debates if we just agree > > that we all know how it works, > > If only that were true. Not everyone understands Python semantics (or > for that matter, Java/Swift/language of your choice) and I still come > across people confused by the pass by value/reference false dichotomy > and which applies to . Ditto. Many of my workmates still suffer from the misapprehension that ?Python uses call-by-value semantics?, and many others suffer from the misapprehension ?Python uses call-by-reference semantics?. No, we cannot just agree that we all know how it works. The well is poisoned for a long time, and we must diligently undo the conceptual damage for generations to come; and I know of no better way than continuing to publicly discuss how both misapprehensions are wrong. -- \ ?[H]ow deep can a truth be ? indeed, how true can it be ? if it | `\ is not built from facts?? ?Kathryn Schulz, 2015-10-19 | _o__) | Ben Finney From marko at pacujo.net Tue Sep 26 05:37:25 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 26 Sep 2017 12:37:25 +0300 Subject: Grumpy-pants spoil-sport References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <858th16cvi.fsf_-_@benfinney.id.au> Message-ID: <87vak57qcq.fsf@elektro.pacujo.net> Ben Finney : > No, we cannot just agree that we all know how it works. The well is > poisoned for a long time, and we must diligently undo the conceptual > damage for generations to come; and I know of no better way than > continuing to publicly discuss how both misapprehensions are wrong. For starters, the Python language spec could at least define what it means to assign to a dict or a list. Is it "name binding?" If not, what is it? In fact, "name binding" can be defined through dict attribute assignment. What is needed is a term for "something that can be bound to an object." C calls this thing an "lvalue." Scheme calls it a "location." I think a "slot" would do well, but any jointly agreed-upon term would be fine. Marko From cs at cskk.id.au Tue Sep 26 05:45:07 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 26 Sep 2017 19:45:07 +1000 Subject: Running a GUI program haults the calling program (linux) In-Reply-To: References: Message-ID: <20170926094507.GA36495@cskk.homeip.net> On 26Sep2017 04:48, Kryptxy wrote: >>> Here - >>> >>> p = subprocess.Popen(["transmission-gtk", link], stdout=subprocess.PIPE, >>> stderr=subprocess.PIPE) >>> output, error = p.communicate() Peter> That"s the problem. communicate() *must* block to collect the program"s Peter> entire output. You get what you ask for... >Thanks! It worked! If you just removed the .communicate() call then you're not waiting for the process to exit, or collection its output. Don't attach stdout or stderr to pipes if you aren't going to collect them. If you attach them to pipes and don't read them then the pipes can fill, stalling the app. Cheers, Cameron Simpson (formerly cs at zip.com.au) From antoon.pardon at vub.be Tue Sep 26 05:58:34 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 26 Sep 2017 11:58:34 +0200 Subject: Grumpy-pants spoil-sport In-Reply-To: <858th16cvi.fsf_-_@benfinney.id.au> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <858th16cvi.fsf_-_@benfinney.id.au> Message-ID: <1bcd359f-e925-c713-fa88-33741162621a@vub.be> Op 26-09-17 om 11:13 schreef Ben Finney: > Steve D'Aprano writes: > >> On Mon, 25 Sep 2017 10:53 pm, Ned Batchelder wrote: >> >>> Would we be able to end these interminable debates if we just agree >>> that we all know how it works, >> If only that were true. Not everyone understands Python semantics (or >> for that matter, Java/Swift/language of your choice) and I still come >> across people confused by the pass by value/reference false dichotomy >> and which applies to . > Ditto. Many of my workmates still suffer from the misapprehension that > ?Python uses call-by-value semantics?, and many others suffer from the > misapprehension ?Python uses call-by-reference semantics?. > > No, we cannot just agree that we all know how it works. The well is > poisoned for a long time, and we must diligently undo the conceptual > damage for generations to come; and I know of no better way than > continuing to publicly discuss how both misapprehensions are wrong. That wont happen as long as people continue to do damage with e.g. claiming that the python assignment is not an alias operation. There is IMO no conceptual damage by regarding the call semantics as call by reference. The swap problem people refer to is caused by the assignment semantics and not because the parameter semantics are substantially different from call by reference. For those who think the swap problem is so important. I can write a swap function for lists in python, so is it correct to conclude that list arguments are passed by reference? -- Antoon Pardon. From marko at pacujo.net Tue Sep 26 06:09:57 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 26 Sep 2017 13:09:57 +0300 Subject: Grumpy-pants spoil-sport References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <858th16cvi.fsf_-_@benfinney.id.au> <1bcd359f-e925-c713-fa88-33741162621a@vub.be> Message-ID: <87o9px7oui.fsf@elektro.pacujo.net> Antoon Pardon : > That wont happen as long as people continue to do damage with e.g. > claiming that the python assignment is not an alias operation. > > There is IMO no conceptual damage by regarding the call semantics > as call by reference. I don't think the clear description of Python's semantics requires the use of such terms ("alias", "call by XXX"). It would be enough to specify what actually happens. Marko From antoon.pardon at vub.be Tue Sep 26 06:33:05 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 26 Sep 2017 12:33:05 +0200 Subject: Grumpy-pants spoil-sport In-Reply-To: <87o9px7oui.fsf@elektro.pacujo.net> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <858th16cvi.fsf_-_@benfinney.id.au> <1bcd359f-e925-c713-fa88-33741162621a@vub.be> <87o9px7oui.fsf@elektro.pacujo.net> Message-ID: <24caa689-a0f0-48f8-b89e-db471952886d@vub.be> Op 26-09-17 om 12:09 schreef Marko Rauhamaa: > Antoon Pardon : > >> That wont happen as long as people continue to do damage with e.g. >> claiming that the python assignment is not an alias operation. >> >> There is IMO no conceptual damage by regarding the call semantics >> as call by reference. > I don't think the clear description of Python's semantics requires the > use of such terms ("alias", "call by XXX"). It would be enough to > specify what actually happens. I agree, but the fact that one doesn't require a particular word to explain something, doesn't mean it is correct to deny that the word is appropiate. I can describe the top surface of my head, without requiring the use of the word "bald". Yet those who would deny that "bald" would be an adequate description, would be wrong. -- Antoon Pardon. From marko at pacujo.net Tue Sep 26 06:44:18 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 26 Sep 2017 13:44:18 +0300 Subject: Grumpy-pants spoil-sport References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <858th16cvi.fsf_-_@benfinney.id.au> <1bcd359f-e925-c713-fa88-33741162621a@vub.be> <87o9px7oui.fsf@elektro.pacujo.net> <24caa689-a0f0-48f8-b89e-db471952886d@vub.be> Message-ID: <87k20l7n99.fsf@elektro.pacujo.net> Antoon Pardon : > Op 26-09-17 om 12:09 schreef Marko Rauhamaa: >> I don't think the clear description of Python's semantics requires the >> use of such terms ("alias", "call by XXX"). It would be enough to >> specify what actually happens. > > I agree, but the fact that one doesn't require a particular word to > explain something, doesn't mean it is correct to deny that the word > is appropiate. As long as it helps mutual understanding. Marko From rhodri at kynesim.co.uk Tue Sep 26 06:51:26 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 26 Sep 2017 11:51:26 +0100 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <878th2lg7g.fsf@elektro.pacujo.net> References: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87a81i97mr.fsf@elektro.pacujo.net> <3dac26dd-d811-f719-95ae-20e35091ea49@kynesim.co.uk> <878th2lg7g.fsf@elektro.pacujo.net> Message-ID: On 25/09/17 20:40, Marko Rauhamaa wrote: > Rhodri James : >> On 25/09/17 15:26, Marko Rauhamaa wrote: >>> That's not what I said. I said all expressions *evaluate to* pointers. >> >> This may well be true in particular implementations, but it is an >> implementation detail so Chris' point still stands. Another >> implementation could evaluate expressions to indices (as BCPL used to >> treat its globals), pieces of string or cheese, who knows? > > Those are all pointers. > > A pointer is something that points to a data object. In that case you are using "pointer" in such an informal sense that making deductions from it is unlikely to be successful. -- Rhodri James *-* Kynesim Ltd From rhodri at kynesim.co.uk Tue Sep 26 06:57:42 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 26 Sep 2017 11:57:42 +0100 Subject: Call by binding [was Re: [Tutor] beginning to code] In-Reply-To: <636cad82-ffb3-d41f-5d9d-255f326dddfb@timgolden.me.uk> References: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87a81i97mr.fsf@elektro.pacujo.net> <3dac26dd-d811-f719-95ae-20e35091ea49@kynesim.co.uk> <878th2lg7g.fsf@elektro.pacujo.net> <636cad82-ffb3-d41f-5d9d-255f326dddfb@timgolden.me.uk> Message-ID: <6d23f277-93b4-8a18-3efd-5cf813329da5@kynesim.co.uk> On 25/09/17 21:00, Tim Golden wrote: > (Slight sigh). Can I step in as a list owner and ask the people who are > so very fond of debating this topic again and again: please let it drop. But, but... someone on the internet is wrong! https://www.facebook.com/playingrapunzel/videos/10153716804864491/ :-) -- Rhodri James *-* Kynesim Ltd From steve+python at pearwood.info Tue Sep 26 08:28:41 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 26 Sep 2017 22:28:41 +1000 Subject: Aliasing [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> <9ff212ad-da8d-2c1b-07be-823f03a37d46@nedbatchelder.com> Message-ID: <59ca47fc$0$14934$b1db1813$d948b532@news.astraweb.com> On Tue, 26 Sep 2017 03:26 am, Antoon Pardon wrote: >>> I'm not sure that Steve knows how it works. When he denies that the >>> assignment is an alias operation in Python that casts an important doubt. >> >> I can assure you that Steve knows how it works. Again, the disagreement is >> almost certainly over the semantics of the word "alias." > > Sorry, what he wrote contradicts that. Maybe he was just really confused > at that moment, but it still needed correction. If the assignment is > an alias operator then after the statements > > a = 1 > b = a > b = 2 > > a is not 2. How do you get that conclusion? I think you are mistaken. If assignment were an alias operation, then a would be 2, because b is an alias to a. That's how var parameters in Pascal work, and out parameters in Ada, and both are described as aliasing. Its also how reference variables ("aliases") in C++ work. https://www.tutorialspoint.com/cplusplus/cpp_references.htm https://stackoverflow.com/a/17025902 Here's some C++ code that demonstrates it. Apologies in advance if it isn't the most idiomatic C++ code. #include #include using namespace std; int main () { int a; int& b = a; // reference variable or alias a = 1; printf("a: %d, alias b: %d\n", a, b); b = 2; printf("a: %d, alias b: %d\n", a, b); return 0; } And here is the output: a: 1, alias b: 1 a: 2, alias b: 2 So I stand by what I said: assignment in Python is NOT an alias operation. If it were an alias operation, as you claim, then we could write this: a = 1 b = a # alias to a b = 2 # assigning to be is like assigning to a (as in the C++ example) assert a == 2 But Python is not like that, assignment is not an alias operation, and the assert will fail. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From gvimrc at gmail.com Tue Sep 26 08:51:40 2017 From: gvimrc at gmail.com (gvim) Date: Tue, 26 Sep 2017 13:51:40 +0100 Subject: Python scripting as side job Message-ID: <59CA4D5C.6000701@gmail.com> Has anyone had any success using Python scripting to automate processes for small businesses as a side job? I'd like to use my Python skills to supplement my income with about 4 hours' work a week. gvim From rosuav at gmail.com Tue Sep 26 09:09:18 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Sep 2017 23:09:18 +1000 Subject: Python scripting as side job In-Reply-To: <59CA4D5C.6000701@gmail.com> References: <59CA4D5C.6000701@gmail.com> Message-ID: On Tue, Sep 26, 2017 at 10:51 PM, gvim wrote: > Has anyone had any success using Python scripting to automate processes for > small businesses as a side job? I'd like to use my Python skills to > supplement my income with about 4 hours' work a week. Python scripting for automation is definitely a useful skill, but it's usually best done by someone inside the business. Part of the value of Python compared to "old-school" languages like COBOL is that you don't need to be a dedicated Computer Programmer?; instead, the work of automating daily processes can be done by the exact people whose daily processes are being automated. While it's still certainly possible to do contract work like you suggest, it tends to be more efficient to teach Python to the right people - maybe that would be a more productive use of your time? Obviously that's a somewhat different skill, but there's the whole "feed him for a lifetime" thing too. ChrisA From jpolo at mail.usf.edu Tue Sep 26 09:29:42 2017 From: jpolo at mail.usf.edu (john polo) Date: Tue, 26 Sep 2017 08:29:42 -0500 Subject: TypeError with map with no len() In-Reply-To: <8cc77418-c9ad-3fbe-f7f5-1140d8482266@tjol.eu> References: <696a2d75-7c9c-07f7-4b24-c6fd3baf3275@mail.usf.edu> <8cc77418-c9ad-3fbe-f7f5-1140d8482266@tjol.eu> Message-ID: <046e1da5-6b71-3b59-d21a-a74660ae10da@mail.usf.edu> On 9/25/2017 5:37 PM, Thomas Jollans wrote: > On 25/09/17 18:44, john polo wrote: >> Python List, >> >> I am trying to make practice data for plotting purposes. I am using >> Python 3.6. The instructions I have are >> >> import matplotlib.pyplot as plt >> import math >> import numpy as np >> t = np.arange(0, 2.5, 0.1) >> y1 = map(math.sin, math.pi*t) > If you use np.sin instead of math.sin, you don't have to use map: Most > numpy functions operate elementwise on arrays (for example, you're > multiplying math.pi with an array - something that wouldn't work with a > list). > > Here's the numpy way of doing this: > > t = np.arange(0, 2.5, 0.1) > y1 = np.sin(np.pi * t) > > Without using numpy at all, this might be > > t = [i * 0.1 for i in range(25)] > y1 = [math.pi * a for a in t] The numpy way looks like a great alternative. Thank you, Thomas. John From neilc at norwich.edu Tue Sep 26 09:51:46 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Tue, 26 Sep 2017 13:51:46 +0000 (UTC) Subject: Python scripting as side job References: <59CA4D5C.6000701@gmail.com> Message-ID: On 2017-09-26, Chris Angelico wrote: > On Tue, Sep 26, 2017 at 10:51 PM, gvim wrote: >> Has anyone had any success using Python scripting to automate >> processes for small businesses as a side job? I'd like to use >> my Python skills to supplement my income with about 4 hours' >> work a week. > > Python scripting for automation is definitely a useful skill, > but it's usually best done by someone inside the business. Part > of the value of Python compared to "old-school" languages like > COBOL is that you don't need to be a dedicated Computer > Programmer???; instead, the work of automating daily processes > can be done by the exact people whose daily processes are being > automated. While it's still certainly possible to do contract > work like you suggest, it tends to be more efficient to teach > Python to the right people - maybe that would be a more > productive use of your time? Obviously that's a somewhat > different skill, but there's the whole "feed him for a > lifetime" thing too. I use dozens of Python scripts to help manage financial aid in my job. It would probably take a similar effort to teach a Python programmer financial aid rules than for a financial aid administrator with some aptitude to learn to use Python. There are plenty of little scripting jobs that don't require much beyond but the ability understand a file spec, at least on one side of the pipeline. Some experience in the industry you want to script for will really be required, even in such simple cases. -- Neil Cerutti From grant.b.edwards at gmail.com Tue Sep 26 10:16:47 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 26 Sep 2017 14:16:47 +0000 (UTC) Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <59c9b969$0$14963$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-09-26, Ned Batchelder wrote: > On 9/25/17 10:20 PM, Steve D'Aprano wrote: >> On Tue, 26 Sep 2017 02:54 am, Ned Batchelder wrote: >> [...] >> >> > > We've been asked nicely by the list mod to stop :) Perhaps we could agree on a subject line tag to be used in all threas arguing about what to call the Python argument passing scheme? That way the other 99% of us could pre-emptively plonk it? -- Grant Edwards grant.b.edwards Yow! My BIOLOGICAL ALARM at CLOCK just went off ... It gmail.com has noiseless DOZE FUNCTION and full kitchen!! From vek.m1234 at gmail.com Tue Sep 26 10:41:11 2017 From: vek.m1234 at gmail.com (Veek M) Date: Tue, 26 Sep 2017 07:41:11 -0700 (PDT) Subject: PyQt: Parenting a Widget In-Reply-To: References: <6a979c13-b0c6-4775-8d40-5a76e32dcd14@googlegroups.com> Message-ID: <5c566dff-1755-4c63-a483-447aef0350c6@googlegroups.com> On Tuesday, September 26, 2017 at 2:23:22 PM UTC+5:30, Thomas Jollans wrote: > On 2017-09-26 08:16, Veek M wrote: > > On Tuesday, September 26, 2017 at 11:18:54 AM UTC+5:30, Veek M wrote: > >> Summary: Could someone explain widget and dialog parenting - the text book is not making sense. > >> ###################### > >> I'm trying to understand widget parenting, from the book: Rapid GUI Programming, pg 118, and thereabouts - he says: > >> > >> A. All PyQt classes that derive from QObjectand this includes all the widgets, > >> since QWidget is a QObject subclasscan have a ?parent?. > >> > >> B. PyQt automatically repar- > >> ents the widgets that are laid out. So although we did not give our widgets a > >> parent of self (the Form instance),when we call setLayout() the layout manager > >> gives ownership of the widgets and of itself to the form,and takes ownership of > >> any nested layouts itself. This means that none of the widgets that are laid out > >> is a top-level window, and all of them have parents, which is what we want. So > >> when the form is deleted, all its child widgets and layouts will be deleted with > >> ----------------------------- > >> 1. In A, does he mean, you are ALLOWED to set a parent on a widget ONLY because its Base Class is QObject? > >> > >> With DockWidgets, you have to explicitly parent them - why? > >> > >> 2. If I create two widgets and wdget.show() them, and app.exec_() - which one becomes the main-window and which one is the memory leak? I have not used a layout manager so, one widget with no parent auto-becomes the main-window (as per B), which would result in a leak with the other? > >> > >> #!/usr/bin/python > >> > >> import sys, os, re > >> > >> > >> from PyQt4.QtCore import * > >> from PyQt4.QtGui import * > >> > >> app = QApplication(sys.argv) > >> > >> lbl = QLabel('Hello World') > >> lbl.setWindowFlags(Qt.SplashScreen) > >> lbl.show() > >> txtBrw = QTextBrowser() > >> txtBrw.show() > >> > >> QTimer.singleShot(3000, app.quit) > >> app.exec_() > >> > >> 3. QObject --> QWidget --> QDialog --> Form --> Form_Layout_Manager --> Nested_Layout_Manager > >> > >> B, says that the layout manager parents the widgets under it and makes 'Form' the parent. If the Form Layout Manager is taking charge of the Nested Layout Manager, who is the parent of the widgets under the Nested Layout Mangaer? > >> > >> 4. In the Chapter on 'Dialogs', I am trying to create a QMainWindow Style application with one label as the central widget and one button to invoke a dialog. It doesn't work and I get: > >> > >> QWidget::setLayout: Attempting to set QLayout "" on Parent "", which already has a layout > >> > >> I tried this link and it made no sense: > >> https://stackoverflow.com/questions/25450598/qlayout-attempting-to-add-qlayout-to-qwidget-which-already-has-a-layout > >> > >> How does parenting work in PyQt? What is autoparented, what needs to be explicitly parented and who is scrwing whom? Additionally, why is my button, hiding? > >> > >> > >> #!/usr/bin/python > >> > >> import sys, os, re > >> > >> > >> from PyQt4.QtCore import * > >> from PyQt4.QtGui import * > >> > >> app = QApplication(sys.argv) > >> > >> class Dialog(QDialog): > >> def __init__(self, parent = None): > >> super(Dialog, self).__init__(parent) > >> > >> self.lbl = QLabel('Width: ') > >> self.spn = QSpinBox() > >> self.spn.setRange(0, 100) > >> self.lbl.setBuddy(self.spn) > >> > >> self.chk = QCheckBox('&Beveled Edges') > >> > >> self.lbl_styl = QLabel('Style') > >> self.lst = QComboBox() > >> self.lst.addItems(['dashed', 'dotted', 'star']) > >> self.lbl_styl.setBuddy(self.lst) > >> > >> self.ok_btn = QPushButton('&Ok') > >> self.cncl_btn = QPushButton('&Cancel') > >> > >> self.layout([(self.lbl, 0, 0), (self.spn, 0, 1), (self.chk, 0, 2), > >> (self.lbl_styl, 1, 0), (self.lst, 1, 1), > >> (self.ok_btn, 2, 0), (self.cncl_btn, 2, 1)]) > >> > >> def layout(self, wgts = []): > >> self.lyt = QGridLayout() > >> for wgt, row, col in wgts: > >> self.lyt.addWidget(wgt, row, col) > >> > >> self.setLayout(self.lyt) > >> > >> > >> class Parent(QMainWindow): > >> def __init__(self, parent = None): > >> super(Parent, self).__init__(parent) > >> > >> lbl = QLabel('HELLO WORLD') > >> btn = QPushButton('&Start Dialog') > >> lbl.setBuddy(btn) > >> > >> lyt = QHBoxLayout() > >> lyt.addWidget(lbl) > >> lyt.addWidget(btn) > >> > >> self.setLayout(lyt) > >> self.connect(btn, SIGNAL('clicked()'), self.popup_dialog) > >> > >> def popup_dialog(self): > >> x = Dialog(self) > >> if x.exec_(): > >> print(x.spn.value()) > >> > >> p = Parent() > >> p.show() > >> > >> app.exec_() > > > > I fixed some of it by deleting the: > > Parent > > self.setLayout(lyt) > > > > I don't understand why that works - aren't we supposed to attach a layout to the Parent/MainWindow object? Why not? > > > > Also, I made the: > > Parent > > self.setCentralWidget(btn) > > IIRC, QMainWindow is a bit weird, since it provides things like menu and > status bars. Everything normally goes into a "central widget". > > The (or: a) thing to do is (I suspect): > > class Parent(QMainWindow): > def __init__(self, parent=None): > # This is the future. super() is smart now. > super().__init__(parent) > > lbl = QLabel('HELLO WORLD') > btn = QPushButton('&Start Dialog') > lbl.setBuddy(btn) > > lyt = QHBoxLayout() > lyt.addWidget(lbl) > lyt.addWidget(btn) > > central_widget = QWidget() > central_widget.setLayout(lyt) > self.setCentralWidget(central_widget) > > # Use new-style signals and slots! They're nicer! > btn.clicked.connect(self.popup_dialog) > > def popup_dialog(self): > x = Dialog(self) > if x.exec_(): > print(x.spn.value()) > > I normally like to explicitly parent my widgets on construction, but > that's not necessary and I'm probably doing it wrong anyway. > > Aside: I notice you're using PyQt4. That's great, I do too (for now), > but I suggest you consider moving to PyQt5. PyQt4 is slowly > disappearing. Anaconda (on Windows at least) has annoying dependency > structures that force you to use old versions of the scientific python > stack if you want to use qt4. I'm going to have to upgrade soon. > > The differences between PyQt4 and PyQt5 aren't massive, but they've > moved around some classes (QtGui has been split into two packages, which > is going to be annoying to migrate) and support for old-style signal and > slot syntax has been dropped (good riddance). > > Also, if you're using Python 2: don't. Just don't. It's not 2012 any > more. (I don't know what you're using, but /usr/bin/python is normally > Python 2) > > > > > so the button is the central widget. To use the Label, I think I would have to create a composite widget which is too complicated for me, currently. > > > > Now. it works so I tested some more and added: > > def popup_dialog(self): > > x = Dialog(self) > > y = Dialog(self) > > y.show() > > if x.exec_(): > > print(x.spn.value()) > > AND > > > > class Dialog(QDialog): > > self.connect(self.cncl_btn, SIGNAL('clicked()'), self.close) > > > > So my dialog pops up and because exec_ is being called on 'x', I have to first close that widget before I can interact with my button and 'y'. However, let's say I close the 'x' dialog - then I can click on 'Button' and I get two more dialogs which don't lock anything - why?? > > > > > -- > Thomas Jollans Thanks - i'm on debian stretch so python 2.7 is what I use. Right now, my book deals with PyQt4 so I thought I'd stick with that, till I get a hang of things. The book I'm using is good but not great - he's over complicated things with really verbose examples of simple stuff, instead of conveying a central idea eg: dump, smart and standard dialogs are mostly the same thing and the central idea could be conveyed in a few lines but he's got some huge examples spread over pages, that's mostly unnecessary. I found the PyQt docs to be very clear but right now, I dare not stray. There's a russian book on PyQt5 that looks nice but there's no way to translate it: Python 3 and pyqt 5 application development - prokhorenok n.a From tjol at tjol.eu Tue Sep 26 10:54:34 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 26 Sep 2017 16:54:34 +0200 Subject: PyQt: Parenting a Widget In-Reply-To: <5c566dff-1755-4c63-a483-447aef0350c6@googlegroups.com> References: <6a979c13-b0c6-4775-8d40-5a76e32dcd14@googlegroups.com> <5c566dff-1755-4c63-a483-447aef0350c6@googlegroups.com> Message-ID: <8e79cb9a-5be9-cc81-a9c3-584ac235abf6@tjol.eu> On 2017-09-26 16:41, Veek M wrote: > Thanks - i'm on debian stretch so python 2.7 is what I use. https://packages.debian.org/stretch/python3 https://packages.debian.org/stretch/python3-pyqt4 https://packages.debian.org/stretch/python3-pyqt5 From rosuav at gmail.com Tue Sep 26 10:57:38 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Sep 2017 00:57:38 +1000 Subject: PyQt: Parenting a Widget In-Reply-To: <5c566dff-1755-4c63-a483-447aef0350c6@googlegroups.com> References: <6a979c13-b0c6-4775-8d40-5a76e32dcd14@googlegroups.com> <5c566dff-1755-4c63-a483-447aef0350c6@googlegroups.com> Message-ID: On Wed, Sep 27, 2017 at 12:41 AM, Veek M wrote: > Thanks - i'm on debian stretch so python 2.7 is what I use. Debian Stretch ships with Python 3.5 too. ChrisA From info at egenix.com Tue Sep 26 11:08:11 2017 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 26 Sep 2017 17:08:11 +0200 Subject: =?UTF-8?Q?ANN:_Python_Meeting_D=c3=bcsseldorf_-_27.09.2017?= Message-ID: <2cdc5ddd-538d-4acd-bc40-75801037550c@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, 27.09.2017, 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: http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2017-09-27 ________________________________________________________________________ NEUIGKEITEN * Bereits angemeldete Vortr?ge: Dr. Uwe Ziegenhagen "Datenanalyse mit Python pandas" Charlie Clark "Typ-Systeme in Python" Weitere Vortr?ge k?nnen gerne noch angemeldet werden: info at pyddf.de Allerdings wird vermutlich bei diesem Treffen kein Platz mehr sein, sondern erst beim n?chsten Mal im 27.09.2017. * 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, Sep 26 2017) >>> 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 berniejconnors at gmail.com Tue Sep 26 11:31:47 2017 From: berniejconnors at gmail.com (berniejconnors at gmail.com) Date: Tue, 26 Sep 2017 08:31:47 -0700 (PDT) Subject: Newbie problem with urllib.request.urlopen Message-ID: Hello, My first post here on C.L.P. I have only written a few python scripts in 2.7 and now I'm trying my first python 3 script. Can you tell me why this snippet won't run? ----------------------- from urllib.request import urlopen with urlopen('http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID='75385120'') as conn: print(conn) ----------------------- Thanks, Bernie. From tjol at tjol.eu Tue Sep 26 11:39:49 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 26 Sep 2017 17:39:49 +0200 Subject: Newbie problem with urllib.request.urlopen In-Reply-To: References: Message-ID: <285d137d-90fc-54de-3db5-2e84d2fa0826@tjol.eu> On 2017-09-26 17:31, berniejconnors at gmail.com wrote: > Hello, > > My first post here on C.L.P. I have only written a few python scripts in 2.7 and now I'm trying my first python 3 script. Can you tell me why this snippet won't run? What do you mean, "won't run"? Is there an error message? > ----------------------- > from urllib.request import urlopen > > with urlopen('http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID='75385120'') as conn: > print(conn) You may have messed up some quotes there. > ----------------------- > Thanks, > Bernie. > -- Thomas Jollans From python at mrabarnett.plus.com Tue Sep 26 11:45:28 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 26 Sep 2017 16:45:28 +0100 Subject: Newbie problem with urllib.request.urlopen In-Reply-To: References: Message-ID: On 2017-09-26 16:31, berniejconnors at gmail.com wrote: > Hello, > > My first post here on C.L.P. I have only written a few python scripts in 2.7 and now I'm trying my first python 3 script. Can you tell me why this snippet won't run? > ----------------------- > from urllib.request import urlopen > > with urlopen('http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID='75385120'') as conn: > print(conn) > ----------------------- > Thanks, > Bernie. > Check the quotes. The argument you're passing to urlopen is: 'http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID='75385120'' which is actually: 'http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID=' 75385120 '' A string, then an int, then another string. I think you mean: 'http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID="75385120"' From mail at timgolden.me.uk Tue Sep 26 11:59:06 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Tue, 26 Sep 2017 16:59:06 +0100 Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] In-Reply-To: References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <59c9b969$0$14963$b1db1813$d948b532@news.astraweb.com> Message-ID: On 26/09/2017 15:16, Grant Edwards wrote: > On 2017-09-26, Ned Batchelder wrote: >> On 9/25/17 10:20 PM, Steve D'Aprano wrote: >>> On Tue, 26 Sep 2017 02:54 am, Ned Batchelder wrote: >>> [...] >>> >>> >> >> We've been asked nicely by the list mod to stop :) > > Perhaps we could agree on a subject line tag to be used in all threas > arguing about what to call the Python argument passing scheme? That > way the other 99% of us could pre-emptively plonk it? +100 :) TJG From antoon.pardon at rece.vub.ac.be Tue Sep 26 12:26:06 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Tue, 26 Sep 2017 18:26:06 +0200 Subject: Aliasing [was Re: [Tutor] beginning to code] In-Reply-To: <59ca47fc$0$14934$b1db1813$d948b532@news.astraweb.com> References: <59c4b34b$0$14931$b1db1813$d948b532@news.astraweb.com> <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> <9ff212ad-da8d-2c1b-07be-823f03a37d46@nedbatchelder.com> <59ca47fc$0$14934$b1db1813$d948b532@news.astraweb.com> Message-ID: <393652da-3132-fa97-debf-03f82c68cb33@rece.vub.ac.be> On 26-09-17 14:28, Steve D'Aprano wrote: > On Tue, 26 Sep 2017 03:26 am, Antoon Pardon wrote: > >> Sorry, what he wrote contradicts that. Maybe he was just really confused >> at that moment, but it still needed correction. If the assignment is >> an alias operator then after the statements >> >> a = 1 >> b = a >> b = 2 >> >> a is not 2. > > How do you get that conclusion? I think you are mistaken. > > If assignment were an alias operation, then a would be 2, because b is an alias > to a. That's how var parameters in Pascal work, and out parameters in Ada, and > both are described as aliasing. They work like that because the assignment in Pascal is *not* an alias operation. > Its also how reference variables ("aliases") in C++ work. > > https://www.tutorialspoint.com/cplusplus/cpp_references.htm > > https://stackoverflow.com/a/17025902 > > > Here's some C++ code that demonstrates it. Apologies in advance if it isn't the > most idiomatic C++ code. No that C++ code doesn't demonstrate your assertion. You ignore the fact that only the 7th line is an alias operation, all the assignments (later) are copy operations. > #include > #include > using namespace std; > > int main () { > int a; > int& b = a; // reference variable or alias > > a = 1; > printf("a: %d, alias b: %d\n", a, b); > b = 2; > printf("a: %d, alias b: %d\n", a, b); > return 0; > } Because similarity of notation may be causing some confusion, I'll introduce two new symbols. := This is the symbol I use for an assignment as copy operation, like Pascal. <- This is the symbol I use for an assignment as alias operation. So if the assignment is an alias operation, the code I was making an assertion about, rewritten using these symbols would be: a <- 1 b <- a b <- 2 The code you use in support of your assertion instead behaves more like. b <- a # The order of the first two statements a := 1 # doesn't matter, my criticism doesn't depend on that. b := 2 If you want to make a statement about the effects of assignemt as an alias operation, you will have to support that with code that actually behaves like an alias operation each time an assignment is made. Not code like your C++ example which only executes one alias operation and where the rest of the assignments are copy operations. -- Antoon Pardon. From __peter__ at web.de Tue Sep 26 12:32:17 2017 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Sep 2017 18:32:17 +0200 Subject: Finding keyword arguments in the documentation References: Message-ID: Stefan Ram wrote: > Here's a console transcript: > > |>>> from math import sin > |>>> help( sin ) > |Help on built-in function sin in module math: > | > |sin(...) > | sin(x) > | > | Return the sine of x (measured in radians). > | > |>>> sin( x = 2.0 ) > |Traceback (most recent call last): > | File "", line 1, in > |TypeError: sin() takes no keyword arguments > > How can I tell from the documentation of a callable > entity whether a parameter name (like ?x? above) can > be used as a keyword in a keyword argument? > Newer Python versions will show Help on built-in function sin in module math: sin(x, /) Return the sine of x (measured in radians). where the arguments before the slash are positional-only: https://www.python.org/dev/peps/pep-0457/#id14 From malaclypse2 at gmail.com Tue Sep 26 12:38:14 2017 From: malaclypse2 at gmail.com (Jerry Hill) Date: Tue, 26 Sep 2017 12:38:14 -0400 Subject: Finding keyword arguments in the documentation In-Reply-To: References: Message-ID: On Tue, Sep 26, 2017 at 12:32 PM, Peter Otten <__peter__ at web.de> wrote: > Newer Python versions will show > > Help on built-in function sin in module math: > > sin(x, /) > Return the sine of x (measured in radians). > > > where the arguments before the slash are positional-only: What version of python do you need to see that output from help? I'm not seeing it in 3.6.1 on windows: Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import math >>> help (math.sin) Help on built-in function sin in module math: sin(...) sin(x) Return the sine of x (measured in radians). >>> -- Jerry From berniejconnors at gmail.com Tue Sep 26 12:40:28 2017 From: berniejconnors at gmail.com (Bernie Connors) Date: Tue, 26 Sep 2017 09:40:28 -0700 (PDT) Subject: Newbie problem with urllib.request.urlopen In-Reply-To: References: Message-ID: <32bb1d7c-fdd6-4c3b-9b6e-a072f1549dc5@googlegroups.com> On Tuesday, September 26, 2017 at 12:32:18 PM UTC-3, Bernie Connors wrote: > Hello, > > My first post here on C.L.P. I have only written a few python scripts in 2.7 and now I'm trying my first python 3 script. Can you tell me why this snippet won't run? > ----------------------- > from urllib.request import urlopen > > with urlopen('http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID='75385120'') as conn: > print(conn) > ----------------------- > Thanks, > Bernie. Thomas, The PID parameter at the end of my url must be enclosed in single quotes, '75385120', or the API won't execute the query. I have the code in a python notebook on Azure - https://notebooks.azure.com/n/n31C2DSCOr8/notebooks/URLopen%20Test.ipynb Here are the error messages I am getting: --------------------------------------------------------------------------- HTTPError Traceback (most recent call last) in () 1 from urllib.request import urlopen ----> 2 with urlopen("http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID='75385120'") as conn: 3 print(conn) ~/anaconda3_410/lib/python3.5/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context) 160 else: 161 opener = _opener --> 162 return opener.open(url, data, timeout) 163 164 def install_opener(opener): ~/anaconda3_410/lib/python3.5/urllib/request.py in open(self, fullurl, data, timeout) 469 for processor in self.process_response.get(protocol, []): 470 meth = getattr(processor, meth_name) --> 471 response = meth(req, response) 472 473 return response ~/anaconda3_410/lib/python3.5/urllib/request.py in http_response(self, request, response) 579 if not (200 <= code < 300): 580 response = self.parent.error( --> 581 'http', request, response, code, msg, hdrs) 582 583 return response ~/anaconda3_410/lib/python3.5/urllib/request.py in error(self, proto, *args) 507 if http_err: 508 args = (dict, 'default', 'http_error_default') + orig_args --> 509 return self._call_chain(*args) 510 511 # XXX probably also want an abstract factory that knows when it makes ~/anaconda3_410/lib/python3.5/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args) 441 for handler in handlers: 442 func = getattr(handler, meth_name) --> 443 result = func(*args) 444 if result is not None: 445 return result ~/anaconda3_410/lib/python3.5/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs) 587 class HTTPDefaultErrorHandler(BaseHandler): 588 def http_error_default(self, req, fp, code, msg, hdrs): --> 589 raise HTTPError(req.full_url, code, msg, hdrs, fp) 590 591 class HTTPRedirectHandler(BaseHandler): HTTPError: HTTP Error 403: Forbidden -------------------------------------- Thanks, Bernie. From __peter__ at web.de Tue Sep 26 12:51:15 2017 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Sep 2017 18:51:15 +0200 Subject: Finding keyword arguments in the documentation References: Message-ID: Jerry Hill wrote: > On Tue, Sep 26, 2017 at 12:32 PM, Peter Otten <__peter__ at web.de> wrote: >> Newer Python versions will show >> >> Help on built-in function sin in module math: >> >> sin(x, /) >> Return the sine of x (measured in radians). >> >> >> where the arguments before the slash are positional-only: > > What version of python do you need to see that output from help? I'm > not seeing it in 3.6.1 on windows: It looks like in that particular case the transition will have to wait till Python 3.7, but some functions should already have been changed in 3.6. Try help(hex) From __peter__ at web.de Tue Sep 26 13:03:10 2017 From: __peter__ at web.de (Peter Otten) Date: Tue, 26 Sep 2017 19:03:10 +0200 Subject: Newbie problem with urllib.request.urlopen References: <32bb1d7c-fdd6-4c3b-9b6e-a072f1549dc5@googlegroups.com> Message-ID: Bernie Connors wrote: > On Tuesday, September 26, 2017 at 12:32:18 PM UTC-3, Bernie Connors wrote: >> Hello, >> >> My first post here on C.L.P. I have only written a few python >> scripts in 2.7 and now I'm trying my first python 3 script. Can >> you tell me why this snippet won't run? >> ----------------------- >> from urllib.request import urlopen >> >> with >> urlopen('http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID='75385120'') >> as conn: >> print(conn) >> ----------------------- >> Thanks, >> Bernie. > > Thomas, > > The PID parameter at the end of my url must be enclosed in single > quotes, '75385120', or the API won't execute the query. I have the Then use " to quote the Python string: >>> import urllib.request >>> url = "http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID='75385120'" >>> with urllib.request.urlopen(url) as conn: ... print(conn) ... data = conn.read() ... >>> data[:20] b'{"displayFieldName":' Looks good. To convert the data into a Python dict: >>> import json >>> d = json.loads(data.decode("utf-8")) >>> d {'features': [{'attributes': {'PID': '75385120'}, 'geometry': {'rings': [snip] PS: For other ways to write a Python string literal have a look into the tutorial: https://docs.python.org/3.6/tutorial/introduction.html#strings From alister.ware at ntlworld.com Tue Sep 26 14:25:20 2017 From: alister.ware at ntlworld.com (alister) Date: Tue, 26 Sep 2017 18:25:20 GMT Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] References: <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <59c9b969$0$14963$b1db1813$d948b532@news.astraweb.com> Message-ID: On Tue, 26 Sep 2017 14:16:47 +0000, Grant Edwards wrote: > On 2017-09-26, Ned Batchelder wrote: >> On 9/25/17 10:20 PM, Steve D'Aprano wrote: >>> On Tue, 26 Sep 2017 02:54 am, Ned Batchelder wrote: >>> [...] >>> >>> >>> >> We've been asked nicely by the list mod to stop :) > > Perhaps we could agree on a subject line tag to be used in all threas > arguing about what to call the Python argument passing scheme? That way > the other 99% of us could pre-emptively plonk it? so you are suggesting a system where we could reject by reference :-) -- hard, adj.: The quality of your own data; also how it is to believe those of other people. From rosuav at gmail.com Tue Sep 26 14:35:15 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Sep 2017 04:35:15 +1000 Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] In-Reply-To: References: <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <59c9b969$0$14963$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 27, 2017 at 4:25 AM, alister via Python-list wrote: > On Tue, 26 Sep 2017 14:16:47 +0000, Grant Edwards wrote: > >> On 2017-09-26, Ned Batchelder wrote: >>> On 9/25/17 10:20 PM, Steve D'Aprano wrote: >>>> On Tue, 26 Sep 2017 02:54 am, Ned Batchelder wrote: >>>> [...] >>>> >>>> >>>> >>> We've been asked nicely by the list mod to stop :) >> >> Perhaps we could agree on a subject line tag to be used in all threas >> arguing about what to call the Python argument passing scheme? That way >> the other 99% of us could pre-emptively plonk it? > > so you are suggesting a system where we could reject by reference :-) No, you don't actually reject them. You allow them to be posted, but you simply skip over the ones you don't like. You pass them by. That's the REAL meaning of "pass by reference". ChrisA From python.list at tim.thechases.com Tue Sep 26 14:38:05 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 26 Sep 2017 13:38:05 -0500 Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] In-Reply-To: References: <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <59c9b969$0$14963$b1db1813$d948b532@news.astraweb.com> Message-ID: <20170926133805.440c4162@bigbox.christie.dr> On 2017-09-26 18:25, alister via Python-list wrote: >>> We've been asked nicely by the list mod to stop :) >> >> Perhaps we could agree on a subject line tag to be used in all >> threas arguing about what to call the Python argument passing >> scheme? That way the other 99% of us could pre-emptively plonk >> it? > > so you are suggesting a system where we could reject by > reference :-) I think the suggestion is to bind a name to the thread and reject by name-binding. Grinning-ducking-and-running'ly yers... -tkc From irmen at NOSPAM.xs4all.nl Tue Sep 26 14:47:54 2017 From: irmen at NOSPAM.xs4all.nl (Irmen de Jong) Date: Tue, 26 Sep 2017 20:47:54 +0200 Subject: auto installing dependencies with pip to run a python zip application ? Message-ID: <59caa0da$0$698$e4fe514c@news.xs4all.nl> Hi, I've been using Python's executable zip application feature to neatly package my little game into a single "executable" file. Here "executable" means the user can simply start it by doubleclicking it, or launching it from a shell prompt. Of course the user already has to have a proper Python installation on their system but that's okay for me. However, I would like to also take care of the library dependencies of my game. Currently it requires pillow and sounddevice. If the user doesn't have these installed, the game exits with an error message telling the user to install these dependencies manually. I was thinking about a way to automate this so that you don't have to install anything manually to run the game. I was thinking about the following solution: - assume bare default Python (3.5+) installation - use venv.EnvBuilder() to create a new virtualenv somewhere in the user's home directory (~./virtualenvs/mygreatgame ?) - use the with_pip=True argument so we also get pip installed into it - exec() the python executable from the new virtual env and let that "pip install -r mygamerequirements.txt" - inject "./mygame.pyz" in sys.modules[0] - run the game's main class and play! Notice that I'm not looking for a fully standalone executable created by things as cx_freeze, just something that is usable from within my zipped application. Any thoughts on this? Is it a good idea or something horrible? Has someone attempted something like this before perhaps? Irmen From berniejconnors at gmail.com Tue Sep 26 14:54:28 2017 From: berniejconnors at gmail.com (Bernie Connors) Date: Tue, 26 Sep 2017 11:54:28 -0700 (PDT) Subject: Newbie problem with urllib.request.urlopen In-Reply-To: References: Message-ID: On Tuesday, September 26, 2017 at 12:32:18 PM UTC-3, Bernie Connors wrote: > Hello, > > My first post here on C.L.P. I have only written a few python scripts in 2.7 and now I'm trying my first python 3 script. Can you tell me why this snippet won't run? > ----------------------- > from urllib.request import urlopen > > with urlopen('http://geonb.snb.ca/arcgis/rest/services/GeoNB_SNB_Parcels/MapServer/0/query?outSR=4617&f=JSON&where=PID='75385120'') as conn: > print(conn) > ----------------------- > Thanks, > Bernie. Peter Otten, Yes that seems to work better. Thanks for the tips. But I see now that I am getting some http errors when I try to run this code from the Microsoft Azure Notebooks. Here is the URL to my Note Book: https://notebooks.azure.com/n/n31C2DSCOr8/notebooks/URLopen%20Test.ipynb And here is the error: URLError: Does anybody know if something can be done about this with urllib? Or is this completely related to the firewall rules at http://geonb.snb.ca?? Thanks, Bernie. From stephanh42 at gmail.com.invalid Tue Sep 26 15:13:48 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 26 Sep 2017 19:13:48 GMT Subject: Calling methods without objects? References: Message-ID: Op 2017-09-25, Stefan Ram schreef : > So, is there some mechanism in Python that can bind a method > to an object so that the caller does not have to specify the > object in the call? > > If so, how is this mechanism called? > Others have already explained the details how functions become bound methods, but I would just point out that it is an instance of a piece of very general functionality: the descriptor protocol. https://docs.python.org/3.6/howto/descriptor.html With this, you can create your own objects which do some arbitrary special thing when accesses on an instance. Stephan From stefan_ml at behnel.de Tue Sep 26 15:19:04 2017 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 26 Sep 2017 21:19:04 +0200 Subject: Parentheses (as after "print") In-Reply-To: References: Message-ID: Stefan Ram schrieb am 26.09.2017 um 17:56: > Why do we newbies write ?print 2?? Here's another hint. > This is an original transcript of what happened to me today: > > |>>> import( operator ) > | File "", line 1 > | import( operator ) > | ^ > |SyntaxError: invalid syntax > | > |>>> import operator > | > |>>> help operator > | File "", line 1 > | help operator > | ^ > |SyntaxError: invalid syntax > | > |>>> help( operator ) > |Help on module operator: > > What happened? I woke up today in parens mood. So I typed: > > import( operator ) > > Python told me that I should type: > > import operator > > . Fine, Python conditioned me to omit the parens. > So now I was in noparens mood. So I typed: > > help operator > > . Oops! But would you also write this? for(i in [1,2,3]): ... def(func(a,b,c)): return(a+b+c) > "Don't make me think!" In language design, some things are worth being keywords, while others are not. Having less keywords is generally a good thing, but for some functionality, the parser/compiler needs to be able to safely detect and process it, so some things really need to be keywords. An import is an assignment, for example. It stores a reference to the module (or its attributes) in variables. A function call cannot do an assignment. The same applies to function definitions and loops. They all do assignments, or even change the program execution flow. print() and help() are definitely not worth being keywords. They do not impact the program flow, they don't do any assignments, nothing. That's why they are simple functions. Stefan From tjol at tjol.eu Tue Sep 26 15:19:59 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Tue, 26 Sep 2017 21:19:59 +0200 Subject: auto installing dependencies with pip to run a python zip application ? In-Reply-To: <59caa0da$0$698$e4fe514c@news.xs4all.nl> References: <59caa0da$0$698$e4fe514c@news.xs4all.nl> Message-ID: <10d13011-f6f8-2669-3849-2b245c647ae8@tjol.eu> On 26/09/17 20:47, Irmen de Jong wrote: > Hi, > I've been using Python's executable zip application feature to neatly > package my little game into a single "executable" file. > Here "executable" means the user can simply start it by doubleclicking > it, or launching it from a shell prompt. Of course the user already has > to have a proper Python installation on their system but that's okay for me. > > However, I would like to also take care of the library dependencies of > my game. Currently it requires pillow and sounddevice. If the user > doesn't have these installed, the game exits with an error message > telling the user to install these dependencies manually. I was thinking > about a way to automate this so that you don't have to install anything > manually to run the game. > > I was thinking about the following solution: > - assume bare default Python (3.5+) installation > - use venv.EnvBuilder() to create a new virtualenv somewhere in the > user's home directory (~./virtualenvs/mygreatgame ?) The appropriate place for this kind of thing, on Linux, would be $XDG_DATA_HOME, default "~/.local/share/", i.e.: f"{os.getenv('XDG_DATA_HOME', os.path.expanduser( '~/.local/share'))}/{my_app}/{subdir}" Other operating system have other conventions. (On Windows I think os.getenv('APPDATA') is a good place to start) > - use the with_pip=True argument so we also get pip installed into it > - exec() the python executable from the new virtual env and let that > "pip install -r mygamerequirements.txt" > - inject "./mygame.pyz" in sys.modules[0] > - run the game's main class and play! > > Notice that I'm not looking for a fully standalone executable created by > things as cx_freeze, just something that is usable from within my zipped > application. > > Any thoughts on this? Is it a good idea or something horrible? Has > someone attempted something like this before perhaps? > > Irmen From grant.b.edwards at gmail.com Tue Sep 26 15:24:45 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 26 Sep 2017 19:24:45 +0000 (UTC) Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] References: <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <59c9b969$0$14963$b1db1813$d948b532@news.astraweb.com> Message-ID: On 2017-09-26, alister via Python-list wrote: > On Tue, 26 Sep 2017 14:16:47 +0000, Grant Edwards wrote: > >> On 2017-09-26, Ned Batchelder wrote: >>> On 9/25/17 10:20 PM, Steve D'Aprano wrote: >>>> On Tue, 26 Sep 2017 02:54 am, Ned Batchelder wrote: >>>> [...] >>>> >>>> >>>> >>> We've been asked nicely by the list mod to stop :) >> >> Perhaps we could agree on a subject line tag to be used in all threas >> arguing about what to call the Python argument passing scheme? That way >> the other 99% of us could pre-emptively plonk it? > > so you are suggesting a system where we could reject by reference :-) That depends on what you mean by "reference". And what you mean by "mean". -- Grant Edwards grant.b.edwards Yow! It's some people at inside the wall! This is gmail.com better than mopping! From rosuav at gmail.com Tue Sep 26 15:25:20 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Sep 2017 05:25:20 +1000 Subject: Parentheses (as after "print") In-Reply-To: References: Message-ID: On Wed, Sep 27, 2017 at 5:19 AM, Stefan Behnel wrote: > print() and help() are definitely not worth being keywords. They do not > impact the program flow, they don't do any assignments, nothing. That's why > they are simple functions. If anything, help() could benefit more from language support than print() can. (And ipython/jupyter proves this - it has some other features in this same area.) For instance, help(def) doesn't work, but help("def") does. And help(id) could tell you if you're shadowing the builtin with your own global name, which a function can't do. But those aren't language features - they're interactive interpreter features, which is why ipython is the place to add the functionality. ChrisA From stephanh42 at gmail.com.invalid Tue Sep 26 15:26:45 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 26 Sep 2017 19:26:45 GMT Subject: Parentheses (as after "print") References: Message-ID: Op 2017-09-26, Stefan Ram schreef : > What happened? I woke up today in parens mood. So I typed: > > import( operator ) > > Python told me that I should type: > > import operator > > . Fine, Python conditioned me to omit the parens. > So now I was in noparens mood. So I typed: > > help operator > > . Oops! The explanation is of course that `import` is a syntactic keyword and `help` is an ordinary function. But if you want to be lazy, you can use the `ipython` interpreter (https://ipython.org) with the %autocall feature... $ ipython Python 3.6.2 (default, Aug 3 2017, 16:08:52) Type 'copyright', 'credits' or 'license' for more information IPython 6.2.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: %autocall Automatic calling is: Smart In [2]: help help Help on _Helper in module _sitebuiltins object: class _Helper(builtins.object) Stephan From rosuav at gmail.com Tue Sep 26 15:37:41 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Sep 2017 05:37:41 +1000 Subject: Grumpy-pants spoil-sport [was Re: [Tutor] beginning to code] In-Reply-To: References: <87wp4r9je0.fsf@elektro.pacujo.net> <87shff9drq.fsf@elektro.pacujo.net> <87k20qapg4.fsf@elektro.pacujo.net> <59c5107b$0$14927$b1db1813$d948b532@news.astraweb.com> <59c8f564$0$14948$b1db1813$d948b532@news.astraweb.com> <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <59c92eea$0$14949$b1db1813$d948b532@news.astraweb.com> <59c9b969$0$14963$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 27, 2017 at 5:24 AM, Grant Edwards wrote: > On 2017-09-26, alister via Python-list wrote: >> On Tue, 26 Sep 2017 14:16:47 +0000, Grant Edwards wrote: >> >>> On 2017-09-26, Ned Batchelder wrote: >>>> On 9/25/17 10:20 PM, Steve D'Aprano wrote: >>>>> On Tue, 26 Sep 2017 02:54 am, Ned Batchelder wrote: >>>>> [...] >>>>> >>>>> >>>>> >>>> We've been asked nicely by the list mod to stop :) >>> >>> Perhaps we could agree on a subject line tag to be used in all threas >>> arguing about what to call the Python argument passing scheme? That way >>> the other 99% of us could pre-emptively plonk it? >> >> so you are suggesting a system where we could reject by reference :-) > > That depends on what you mean by "reference". > > And what you mean by "mean". Well, *obviously*, reference is the section of the library that you're not allowed to borrow, and "mean" is the average of a set of numbers. Which means that CPython is breaking the rules every time it returns a "borrowed reference". ChrisA joke-taker-too-far From irmen at NOSPAM.xs4all.nl Tue Sep 26 15:56:12 2017 From: irmen at NOSPAM.xs4all.nl (Irmen de Jong) Date: Tue, 26 Sep 2017 21:56:12 +0200 Subject: auto installing dependencies with pip to run a python zip application ? In-Reply-To: References: <59caa0da$0$698$e4fe514c@news.xs4all.nl> <10d13011-f6f8-2669-3849-2b245c647ae8@tjol.eu> Message-ID: <59cab0dc$0$798$e4fe514c@news.xs4all.nl> On 09/26/2017 09:19 PM, Thomas Jollans wrote: >> - use venv.EnvBuilder() to create a new virtualenv somewhere in the >> user's home directory (~./virtualenvs/mygreatgame ?) > > The appropriate place for this kind of thing, on Linux, would be > $XDG_DATA_HOME, default "~/.local/share/", i.e.: > > f"{os.getenv('XDG_DATA_HOME', os.path.expanduser( > '~/.local/share'))}/{my_app}/{subdir}" > > Other operating system have other conventions. (On Windows I think > os.getenv('APPDATA') is a good place to start) Ah, yes thanks for this reminder. I used the appdirs library elsewhere to take care of this but this is not available (yet) until we are running in the virtual env Irmen From marko at pacujo.net Tue Sep 26 16:01:20 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 26 Sep 2017 23:01:20 +0300 Subject: Call by binding [was Re: [Tutor] beginning to code] References: <59c7c5df$0$14952$b1db1813$d948b532@news.astraweb.com> <368d9e80-f3b0-ff2f-b038-ade241b51530@vub.be> <877ewn9ktz.fsf@elektro.pacujo.net> <87a81i97mr.fsf@elektro.pacujo.net> <3dac26dd-d811-f719-95ae-20e35091ea49@kynesim.co.uk> <878th2lg7g.fsf@elektro.pacujo.net> Message-ID: <87lgl18c1b.fsf@elektro.pacujo.net> Rhodri James : > On 25/09/17 20:40, Marko Rauhamaa wrote: >> A pointer is something that points to a data object. > > In that case you are using "pointer" in such an informal sense that > making deductions from it is unlikely to be successful. Propose a name for the concept. Candidates so far: "pointer", "location", "address", "identity", "binding", "leash", "link". Unfortunately, "reference" is used for something else in the language spec. The word "address" is used by "An executable operational semantics for Python" This lengthy debate is exacerbated by the language spec pretending the concept doesn't exist and thus doesn't need a name. However, as is evident in the above master's thesis, you can't define Python's object model without it. Marko From rosuav at gmail.com Tue Sep 26 16:10:21 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Sep 2017 06:10:21 +1000 Subject: Parentheses (as after "print") In-Reply-To: References: Message-ID: On Wed, Sep 27, 2017 at 6:00 AM, Stefan Ram wrote: > ram at zedat.fu-berlin.de (Stefan Ram) writes: >>Stefan Behnel writes: >>>But would you also write this? > ... >>> def(func(a,b,c)): >>> return(a+b+c) >>No, this not. > > What I wrote was like: > > func( a, b, c ) > return a+b+c > > Python could have taken the indentation of the > next line to tell that this is supposed to be > a function definition and not a function call. > > I forgot ?:? and ?def?, and sometimes I forget > other things, but I never forgot the proper > indentation, never got the indentation wrong > so far, not even once. That's a DWIMmy feature, and those are often *bad* in language design. But if you can pin down your exact style (as here - you ALWAYS get the indentation right), you could - in theory, at least - configure your editor to notice that you left out the "def" and the colon, and add them for you. Definitely wants to be an editor feature though. ChrisA From p.f.moore at gmail.com Tue Sep 26 16:49:14 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 26 Sep 2017 21:49:14 +0100 Subject: auto installing dependencies with pip to run a python zip application ? In-Reply-To: <59caa0da$0$698$e4fe514c@news.xs4all.nl> References: <59caa0da$0$698$e4fe514c@news.xs4all.nl> Message-ID: On 26 September 2017 at 19:47, Irmen de Jong wrote: > Any thoughts on this? Is it a good idea or something horrible? Has > someone attempted something like this before perhaps? When I've done this, I've bundled my dependencies in with my zipapp. Of course that's trickier if you have binary dependencies like pillow. What you could do is pip install your binary dependencies into a directory in $TEMP using --target, then add that directory to sys.path. Probably easier than building a full virtualenv. Bundle pip with your app if you can't assume your users will have pip available. Paul From dvl at psu.edu Tue Sep 26 17:30:14 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Tue, 26 Sep 2017 17:30:14 -0400 Subject: Aliasing [was Re: [Tutor] beginning to code] In-Reply-To: mailman.48.1506441604.25866.python-list@python.org References: Message-ID: <1506461414l.30605476l.0l@psu.edu> On Tue, Sep 26, 2017 12:00 PM, Steve D'Aprano wrote: > > a = 1 >> b = a >> b = 2 >> >> a is not 2. > < snip > int main () { > int a; > int& b = a; // reference variable or alias > > a = 1; > printf("a: %d, alias b: %d\n", a, b); > b = 2; > printf("a: %d, alias b: %d\n", a, b); > return 0; >} > > >And here is the output: > > >a: 1, alias b: 1 >a: 2, alias b: 2 > > >So I stand by what I said: assignment in Python is NOT an alias operation. If it >were an alias operation, as you claim, then we could write this: > >a = 1 >b = a # alias to a >b = 2 # assigning to be is like assigning to a (as in the C++ >example) >assert a == 2 > >But Python is not like that, assignment is not an alias operation, and the >assert will fail. > I think you are being a bit choosy in your analysis of the examples. You essentially claim that "assignment is not an alias operation" by assuming that some assignments are not an alias operations, and then conclude that it is inconsistent for the rest to be. Here is a discussion of the code in light of the claim that assignment is an alias operation, meaning _all_ assignments are aliases, and not just the ones you choose to prove your point. a = 1 # 'a' is an alias to the value 1 b = a # 'b' is an alias to the value named by a, which is also an alias to 1 b = 2 # 'b' is now an alias to the value of 2, and no longer an alias to 'a' or 1 Your C++ counterexample is invalid, because, indeed, only the second of the three assignments is an alias operation, and only because you specifically declare variable b to be a reference variable. You are not really 'assigning' to b -- you are initializing the reference variable named b.. If we were to add an additional statement into both examples. b = c In Python, this would be another aliasing operation, causing b to refer to the same thing as c refers to (assuming c has been assigned). But in C++, that statement would be completely invalid -- once you associate a reference to a reference variable, you cannot change the binding. This further emphasizes that the statement "int &b = a" is not an assignment statement, which means it is rather irrelevant to the semantics of assignment statements. Roger Christman Pennsylvania State University From gengyangcai at gmail.com Tue Sep 26 17:43:31 2017 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 26 Sep 2017 14:43:31 -0700 (PDT) Subject: Boolean Expressions Message-ID: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> Help check if my logic is correct in all 5 expressions A) Set bool_one equal to the result of False and False Entire Expression : False and False gives True because both are False B) Set bool_two equal to the result of -(-(-(-2))) == -2 and 4 >= 16 ** 0.5 -(-(-(-2))) is equal to 2, and 2 is not equal to -2, hence the first term -(-(-(-2))) == -2 is False. 4 >= 16 ** 0.5 is True because 16 ** 0.5 is equal to 4, and 4 is greater then or equal to 4, hence the 2nd term 4 >= 16 ** 0.5 is True. Entire expression : False because False and True gives False C) Set bool_three equal to the result of 19 % 4 != 300 / 10 / 10 and False 19 % 4 = 3 which is equal to 300 / 10 / 10 = 3, hence the first term is False. Entire expression is then equal to True, because False and False = True D) Set bool_four equal to the result of -(1 ** 2) < 2 ** 0 and 10 % 10 <= 20 - 10 * 2 -(1 ** 2) is equal to -1 , which is less than 2 ** 0 = 1, hence the first term is True. 2nd term 10 % 10 is equal to 0 , which is less than or equal to 20 - 10 * 2 , hence 2nd term is True. Entire expression : True and True = True E) Set bool_five equal to the result of True and True Entire Expression : True and True = True From rosuav at gmail.com Tue Sep 26 17:54:12 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Sep 2017 07:54:12 +1000 Subject: Boolean Expressions In-Reply-To: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> References: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> Message-ID: On Wed, Sep 27, 2017 at 7:43 AM, Cai Gengyang wrote: > Help check if my logic is correct in all 5 expressions > > > A) Set bool_one equal to the result of > False and False > > Entire Expression : False and False gives True because both are False This is not correct, and comes from a confusion in the English language. In boolean logic, "and" means "both". For instance: *IF* we have eggs, *AND* we have bacon, *THEN* bake a pie. Can you bake an egg-and-bacon pie? You need *both* ingredients. The assertion "we have eggs" is True if we do and False if we do not; and the overall condition cannot be True unless *both* assertions are True. In Python, the second half won't even be looked at if the first half is false. That is to say, Python looks beside the stove to see if there's a carton of eggs, and if it can't see one, it won't bother looking in the freezer for bacon - it already knows we can't bake that pie. Your other questions are derived from this one, so you should be fine once you grok this one concept. ChrisA From sohcahtoa82 at gmail.com Tue Sep 26 18:10:59 2017 From: sohcahtoa82 at gmail.com (sohcahtoa82 at gmail.com) Date: Tue, 26 Sep 2017 15:10:59 -0700 (PDT) Subject: Boolean Expressions In-Reply-To: References: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> Message-ID: On Tuesday, September 26, 2017 at 2:54:32 PM UTC-7, Chris Angelico wrote: > On Wed, Sep 27, 2017 at 7:43 AM, Cai Gengyang wrote: > > Help check if my logic is correct in all 5 expressions > > > > > > A) Set bool_one equal to the result of > > False and False > > > > Entire Expression : False and False gives True because both are False > > This is not correct, and comes from a confusion in the English > language. In boolean logic, "and" means "both". For instance: > > *IF* we have eggs, *AND* we have bacon, *THEN* bake a pie. > > Can you bake an egg-and-bacon pie? You need *both* ingredients. The > assertion "we have eggs" is True if we do and False if we do not; and > the overall condition cannot be True unless *both* assertions are > True. > > In Python, the second half won't even be looked at if the first half > is false. That is to say, Python looks beside the stove to see if > there's a carton of eggs, and if it can't see one, it won't bother > looking in the freezer for bacon - it already knows we can't bake that > pie. > > Your other questions are derived from this one, so you should be fine > once you grok this one concept. > > ChrisA A way to prove this: def funcA(): print('In function A') return False def funcB(): print('In function B') return False print(funcA() and funcB()) This will print 'In function A' followed by 'False'. It will not print 'In function B' at all. From cs at cskk.id.au Tue Sep 26 18:13:45 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 27 Sep 2017 08:13:45 +1000 Subject: Boolean Expressions In-Reply-To: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> References: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> Message-ID: <20170926221345.GA43584@cskk.homeip.net> On 26Sep2017 14:43, Cai Gengyang wrote: >Help check if my logic is correct in all 5 expressions Why not just run some code interactively? Unless this is entirely a thought exercise to verify that you have a solid mental understanding of Python semantics, all your reasoning is easy to test. In order to be honest to yourself, you could write does all your answers (exactly as you have just done), _then_ go and run the expressions by hand in python to see which are correct. You can also run the subparts of the expressions, so that you can see which you have misevaluated versus which you have made correct/incorrect logic reasoning about. >A) Set bool_one equal to the result of >False and False > >Entire Expression : False and False gives True because both are False No. False and anything gives False. An "and" only gives True if both sides are true. >B) Set bool_two equal to the result of >-(-(-(-2))) == -2 and 4 >= 16 ** 0.5 > >-(-(-(-2))) is equal to 2, and 2 is not equal to -2, hence the first term -(-(-(-2))) == -2 is False. 4 >= 16 ** 0.5 is True because 16 ** 0.5 is equal to 4, and 4 is greater then or equal to 4, hence the 2nd term 4 >= 16 ** 0.5 is True. > >Entire expression : False because False and True gives False In python, "and" and "or" short circuit. So if you know enough to evaluate the condition from the left hand side, the right hand side is not evaluated at all. So since 2 == -2 gives False, the expresion is False and the right hand is not evaluated. Note, BTW, that 16 ** 0.5 returns a floating point value. While that particular example works nicely, probably because it is all powers of 2 and doesn't hit rounding issues, testing equality with floating point is a dangerous area. >C) Set bool_three equal to the result of >19 % 4 != 300 / 10 / 10 and False > >19 % 4 = 3 which is equal to 300 / 10 / 10 = 3, hence the first term is False. Entire expression is then equal to True, because False and False = True Entire expression is False because the left hand side is False. >D) Set bool_four equal to the result of >-(1 ** 2) < 2 ** 0 and 10 % 10 <= 20 - 10 * 2 > >-(1 ** 2) is equal to -1 , which is less than 2 ** 0 = 1, hence the first term is True. 2nd term 10 % 10 is equal to 0 , which is less than or equal to 20 - 10 * 2 , hence 2nd term is True. > >Entire expression : True and True = True Correct. (In my head; haven't run the code.) >E) Set bool_five equal to the result of >True and True > >Entire Expression : True and True = True Correct. Cheers, Cameron Simpson ERROR 155 - You can't do that. - Data General S200 Fortran error code list From gengyangcai at gmail.com Tue Sep 26 18:23:29 2017 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 26 Sep 2017 15:23:29 -0700 (PDT) Subject: Boolean Expressions In-Reply-To: References: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> Message-ID: <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> I'm trying to understand the logic behind AND. I looked up Python logic tables False and False gives False False and True gives False True and False gives False True and True gives True. So does that mean that the way 'and' works in Python is that both terms must be True (1) for the entire expression to be True ? Why is it defined that way, weird ? I was always under the impression that 'and' means that when you have both terms the same, ie either True and True or False and False , then it gives True On Wednesday, September 27, 2017 at 5:54:32 AM UTC+8, Chris Angelico wrote: > On Wed, Sep 27, 2017 at 7:43 AM, Cai Gengyang wrote: > > Help check if my logic is correct in all 5 expressions > > > > > > A) Set bool_one equal to the result of > > False and False > > > > Entire Expression : False and False gives True because both are False > > This is not correct, and comes from a confusion in the English > language. In boolean logic, "and" means "both". For instance: > > *IF* we have eggs, *AND* we have bacon, *THEN* bake a pie. > > Can you bake an egg-and-bacon pie? You need *both* ingredients. The > assertion "we have eggs" is True if we do and False if we do not; and > the overall condition cannot be True unless *both* assertions are > True. > > In Python, the second half won't even be looked at if the first half > is false. That is to say, Python looks beside the stove to see if > there's a carton of eggs, and if it can't see one, it won't bother > looking in the freezer for bacon - it already knows we can't bake that > pie. > > Your other questions are derived from this one, so you should be fine > once you grok this one concept. > > ChrisA From rgaddi at highlandtechnology.invalid Tue Sep 26 18:30:29 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Tue, 26 Sep 2017 15:30:29 -0700 Subject: Boolean Expressions In-Reply-To: <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> References: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> Message-ID: On 09/26/2017 03:23 PM, Cai Gengyang wrote: > > I'm trying to understand the logic behind AND. I looked up Python logic tables > > False and False gives False > False and True gives False > True and False gives False > True and True gives True. > > So does that mean that the way 'and' works in Python is that both terms must be True (1) for the entire expression to be True ? Why is it defined that way, weird ? I was always under the impression that 'and' means that when you have both terms the same, ie either True and True or False and False , then it gives True > No, that would actually be an xnor (not xor) operation, a fairly rare usage case. Python doesn't even provide an operator for that, the closest thing would be (bool(x) == bool(y)). "And" means "and". This is true AND that is true. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From cs at cskk.id.au Tue Sep 26 18:37:10 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 27 Sep 2017 08:37:10 +1000 Subject: Boolean Expressions In-Reply-To: <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> References: <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> Message-ID: <20170926223710.GA91717@cskk.homeip.net> On 26Sep2017 15:23, Cai Gengyang wrote: > >I'm trying to understand the logic behind AND. I looked up Python logic tables > >False and False gives False >False and True gives False >True and False gives False >True and True gives True. > >So does that mean that the way 'and' works in Python is that both terms must be True (1) for the entire expression to be True ? Yes. >Why is it defined that way, weird ? I was always under the impression that >'and' means that when you have both terms the same, ie either True and True or >False and False , then it gives True I would have called this "not the same". You are describing "or". "and" means "both true". "or" means "either true". An "and" expression is true if the left half is true _and_ the right half is true. Therefore both must be true, otherwise the whole result is false. An "or" expression is true if the left half is true _or_ the right half is true, therefore only one half needs to be true. You only get 'false" is both halves are false. Think of "and" a little like multiplication with values or 0 (false) and 1 (true). Think of "or" a little like addition with values of 0 (false) and 1 (true). And: 1 * 1 => nonzero/true 1 * 0 => zero/false 0 * 1 => zero/false 0 * 0 => zero/false Or: 1 + 1 => nonzero/true 1 + 0 => nonzero/true 0 + 1 => nonzero/true 0 + 0 => zero/false If all this seems confusing I wonder about your understanding of the plain English words "and" and "or", but your English seems otherwise perfectly fine to me, so that would be very surprising. Can you write some plain English sentences where "and" or "or" lead you to misinterpret a similar Python expression? Then we can see where the differences lie. Cheers, Cameron Simpson (formerly cs at zip.com.au) From tjol at tjol.eu Tue Sep 26 18:43:28 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 27 Sep 2017 00:43:28 +0200 Subject: Boolean Expressions In-Reply-To: <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> References: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> Message-ID: <9f3840f7-bfe0-3f33-136d-ff02b40f54d5@tjol.eu> On 27/09/17 00:23, Cai Gengyang wrote: > I'm trying to understand the logic behind AND. I looked up Python logic tables > > False and False gives False > False and True gives False > True and False gives False > True and True gives True. > > So does that mean that the way 'and' works in Python is that both terms must be True (1) for the entire expression to be True ? Why is it defined that way, weird ? I was always under the impression that 'and' means that when you have both terms the same, ie either True and True or False and False , then it gives True What gave you that impression? This is the way "and" is defined in formal logic, electronics, programming, and all languages that I know. no and no does not mean yes. (There may be ambiguity in what precisely "or" means in English, but "and" is pretty clear...) The logical operation you're thinking of is sometimes called "XNOR". One way to write this in Python is bool(a) == bool(b) Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170118] on linux Type "help", "copyright", "credits" or "license" for more information. >>> def xnor(a, b): ... return bool(a) == bool(b) ... >>> xnor(True, True) True >>> xnor(True, False) False >>> xnor(False, False) True >>> xnor(False, True) False >>> > > > > > > On Wednesday, September 27, 2017 at 5:54:32 AM UTC+8, Chris Angelico wrote: >> On Wed, Sep 27, 2017 at 7:43 AM, Cai Gengyang wrote: >>> Help check if my logic is correct in all 5 expressions >>> >>> >>> A) Set bool_one equal to the result of >>> False and False >>> >>> Entire Expression : False and False gives True because both are False >> This is not correct, and comes from a confusion in the English >> language. In boolean logic, "and" means "both". For instance: >> >> *IF* we have eggs, *AND* we have bacon, *THEN* bake a pie. >> >> Can you bake an egg-and-bacon pie? You need *both* ingredients. The >> assertion "we have eggs" is True if we do and False if we do not; and >> the overall condition cannot be True unless *both* assertions are >> True. >> >> In Python, the second half won't even be looked at if the first half >> is false. That is to say, Python looks beside the stove to see if >> there's a carton of eggs, and if it can't see one, it won't bother >> looking in the freezer for bacon - it already knows we can't bake that >> pie. >> >> Your other questions are derived from this one, so you should be fine >> once you grok this one concept. >> >> ChrisA From irmen at NOSPAM.xs4all.nl Tue Sep 26 18:48:39 2017 From: irmen at NOSPAM.xs4all.nl (Irmen de Jong) Date: Wed, 27 Sep 2017 00:48:39 +0200 Subject: auto installing dependencies with pip to run a python zip application ? In-Reply-To: References: <59caa0da$0$698$e4fe514c@news.xs4all.nl> Message-ID: <59cad948$0$829$e4fe514c@news.xs4all.nl> On 09/26/2017 10:49 PM, Paul Moore wrote: > On 26 September 2017 at 19:47, Irmen de Jong wrote: >> Any thoughts on this? Is it a good idea or something horrible? Has >> someone attempted something like this before perhaps? > > When I've done this, I've bundled my dependencies in with my zipapp. > Of course that's trickier if you have binary dependencies like pillow. Yeah I've considered that for a moment but I think sometimes you've also got to deal with licensing issues. I'd rather avoid this. > What you could do is pip install your binary dependencies into a > directory in $TEMP using --target, then add that directory to > sys.path. Probably easier than building a full virtualenv. Bundle pip > with your app if you can't assume your users will have pip available. Interesting idea, although like this wouldn't I have to download the dependencies every time I launch my game? (unless I re-use the same temporary directory every time) Irmen From irmen at NOSPAM.xs4all.nl Tue Sep 26 19:01:20 2017 From: irmen at NOSPAM.xs4all.nl (Irmen de Jong) Date: Wed, 27 Sep 2017 01:01:20 +0200 Subject: Boolean Expressions In-Reply-To: <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> References: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> Message-ID: <59cadc41$0$715$e4fe514c@news.xs4all.nl> On 09/27/2017 12:23 AM, Cai Gengyang wrote: > > I'm trying to understand the logic behind AND. I looked up Python logic tables > > False and False gives False > False and True gives False > True and False gives False > True and True gives True. > > So does that mean that the way 'and' works in Python is that both terms must be True (1) for the entire expression to be True ? Why is it defined that way, weird ? I was always under the impression that 'and' means that when you have both terms the same, ie either True and True or False and False , then it gives True There is nothing Python specific about this, by the way. It is how AND - ? - has been defined in Boolean Algebra forever. It's a logical conjunction of its operands, it doesn't test for the 'equality' of its operands. https://en.wikipedia.org/wiki/Logical_conjunction Irmen From Irv at furrypants.com Tue Sep 26 19:28:19 2017 From: Irv at furrypants.com (Irv Kalb) Date: Tue, 26 Sep 2017 16:28:19 -0700 Subject: Boolean Expressions In-Reply-To: <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> References: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> Message-ID: <8C8D004C-7CD9-4D14-80E9-D814917DCC53@furrypants.com> > > On Sep 26, 2017, at 3:23 PM, Cai Gengyang wrote: > > > I'm trying to understand the logic behind AND. I looked up Python logic tables > > False and False gives False > False and True gives False > True and False gives False > True and True gives True. > > So does that mean that the way 'and' works in Python is that both terms must be True (1) for the entire expression to be True ? Why is it defined that way, weird ? I was always under the impression that 'and' means that when you have both terms the same, ie either True and True or False and False , then it gives True > > As others have said, this is about the definition of the "and" operator. One example I give in my class is this: At the local amusement park there is a sign that says, "You must be at least 12 years old and at least 48 inches tall to ride the roller coaster". That means that both conditions must be true in order for you to get on the roller coaster. The Python code would be: if (age >= 12) and (height >= 48): # You are good to go It would be evaluated like this: If you are 5 years old (first condition is false) and you are only 36 inches tall (second condition is false), you cannot get on the roller coaster. Logically: False and False is False If you are 20 years old (true) but only 30 inches tall (false), you cannot get on the roller coaster Logically: True and False is False If you are 10 years old (false) but you are 75 inches tall (true), you may be a freak of nature, but you cannot get on the roller coaster. Logically: False and True is False If you are 13 years old (true) and 51 inches tall (true), enjoy your ride Logically: True and True is True Bottom line, "and" operates between two Booleans. "and" only give you a True as a result, when both side of the "and" are True. Irv PS: The "or" operator works like this: If any of the inputs is True, then the result of doing an "or" is True. The only case where "or' gives you a False, is when all the inputs are False. From steve+python at pearwood.info Tue Sep 26 21:51:15 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 27 Sep 2017 11:51:15 +1000 Subject: Parentheses (as after "print") References: Message-ID: <59cb0414$0$14955$b1db1813$d948b532@news.astraweb.com> On Wed, 27 Sep 2017 06:00 am, Stefan Ram wrote: > Python could have taken the indentation of the > next line to tell that this is supposed to be > a function definition and not a function call. "Do What I Mean" (DWIM) programming is a terrible idea. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Sep 26 22:20:09 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 27 Sep 2017 12:20:09 +1000 Subject: Boolean Expressions References: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> Message-ID: <59cb0adb$0$14928$b1db1813$d948b532@news.astraweb.com> On Wed, 27 Sep 2017 08:23 am, Cai Gengyang wrote: > > I'm trying to understand the logic behind AND. I looked up Python logic tables > > False and False gives False > False and True gives False > True and False gives False > True and True gives True. > > So does that mean that the way 'and' works in Python is that both terms must > be True (1) for the entire expression to be True ? Why is it defined that way, > weird ? I was always under the impression that 'and' means that when you have > both terms the same, ie either True and True or False and False , then it > gives True No, your impression is wrong. Python's AND is the same as boolean AND everywhere: every programming language that supports boolean AND, in Boolean Algebra and in logic. In C++ https://msdn.microsoft.com/en-us/library/c6s3h5a7.aspx In Javascript https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators Boolean algebra https://en.wikipedia.org/wiki/Boolean_algebra#Basic_operations Consider that today I spent the day sitting at home watching movies. If I said: "Today, I climbed to the top of Mount Everest." That would be False. If I said: "Today, I swam across the English Channel." That would be False. If I said: "Today, I climbed to the top of Mount Everest, AND I swam across the English Channel." that is still False. What you are thinking of is best describes as "equals": False equals False gives True False equals True gives False True equals False gives False True equals True gives True -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Sep 26 22:58:54 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 27 Sep 2017 12:58:54 +1000 Subject: Aliasing [was Re: [Tutor] beginning to code] References: <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> <9ff212ad-da8d-2c1b-07be-823f03a37d46@nedbatchelder.com> <59ca47fc$0$14934$b1db1813$d948b532@news.astraweb.com> Message-ID: <59cb13f0$0$14949$b1db1813$d948b532@news.astraweb.com> On Wed, 27 Sep 2017 02:03 am, Stefan Ram wrote: > Steve D'Aprano writes: >>On Tue, 26 Sep 2017 03:26 am, Antoon Pardon wrote: >>>at that moment, but it still needed correction. If the assignment is >>>an alias operator then after the statements >>Here's some C++ code that demonstrates it. Apologies in advance if it isn't >>the most idiomatic C++ code. > > In C++, assignments and initializations are different > concepts. > >>int& b = a; // reference variable or alias > > This is an initialization, not an assignment. A pedantic difference that makes no difference to my argument. I see that you ignored the later assignment: b = 2; which also assigned to a. *That** is the fundamental point: b is certainly an alias for a, and assigning to b assigns to a. That's how aliases work in C++. That's how var parameters in Pascal work, and out parameters in Ada. That is what it means to say that "b is an alias to a". b is another name for the *variable* a, not just whatever value a happens to hold now. I say that assignment in Python is NOT an aliasing operation. Antoon claims I'm wrong, and his evidence is: a = [] b = a # Antoon says this is an alias operation b.append(1) assert a == [1] But that's not enough for the variable b to be an alias for the variable a. Antoon is correct that a and b are two different names for the same list, but the two variables are not aliases to each other because assignments to b do not affect a, and vice versa. A good test for aliasing is to take the source code and mechanically replace every occurrence of the alias (in the same scope of course) with the original, or vice versa, and see whether the meaning of the code changes. In C++, apart from the initial binding: int& b = a; ("initialisation") you could now randomly swap a for b or b for a and the meaning of the code will not change. But in Python, if we try the same trick, the code *does* change: a = 1 b = a b = 2 *is not* the same as: a = 1 b = a a = 2 (1) In Pascal, Ada, C++ etc using a reference variable (or var parameter, or whatever terminology they use) makes the two names aliases to EACH OTHER, not to the value they are bound to. (2) In Python, Javascript, Ruby etc assignment can give you two names for the same object, but the names do not alias each other. The critical distinction here is whether the names refer to each other: a <---> b or whether they merely refer to the same value: a ---> [ value ] <--- b Python uses the second model. Var parameters in Pascal and references in C++ use the first. Since the term "aliasing" is well-established for the first, using it in Python *without making the difference clear* is wrong. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From python at mrabarnett.plus.com Tue Sep 26 23:34:45 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 27 Sep 2017 04:34:45 +0100 Subject: Parentheses (as after "print") In-Reply-To: References: <59cb0414$0$14955$b1db1813$d948b532@news.astraweb.com> Message-ID: <5a0cc6ff-d0d0-f287-fd70-93fff412ca08@mrabarnett.plus.com> On 2017-09-27 03:48, Stefan Ram wrote: > Steve D'Aprano writes: >>"Do What I Mean" (DWIM) programming is a terrible idea. > > It's an anti-pattern, when one expects the implementation > to follow different and contradicting rules and then > somehow guess what was in the mind of the programmer. > > But it's a pattern when it means to strip the language > of useless boilerplate and still following consistent > and simple rules. That was what made Python great. > Following the aphorism "Everything should be made as simple as possible, but not simpler", removing 'def' and ':' is probably taking it a bit too far. From gengyangcai at gmail.com Tue Sep 26 23:55:26 2017 From: gengyangcai at gmail.com (Cai Gengyang) Date: Tue, 26 Sep 2017 20:55:26 -0700 (PDT) Subject: Boolean Expressions In-Reply-To: References: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> <20170926221345.GA43584@cskk.homeip.net> Message-ID: <28a719f7-0a85-462b-8125-c7aab5c17c21@googlegroups.com> On Wednesday, September 27, 2017 at 6:45:00 AM UTC+8, Cameron Simpson wrote: > On 26Sep2017 14:43, Cai Gengyang wrote: > >Help check if my logic is correct in all 5 expressions > > Why not just run some code interactively? Unless this is entirely a thought > exercise to verify that you have a solid mental understanding of Python > semantics, all your reasoning is easy to test. > > In order to be honest to yourself, you could write does all your answers > (exactly as you have just done), _then_ go and run the expressions by hand in > python to see which are correct. You can also run the subparts of the > expressions, so that you can see which you have misevaluated versus which you > have made correct/incorrect logic reasoning about. > > >A) Set bool_one equal to the result of > >False and False > > > >Entire Expression : False and False gives True because both are False > > No. False and anything gives False. An "and" only gives True if both sides are > true. > > >B) Set bool_two equal to the result of > >-(-(-(-2))) == -2 and 4 >= 16 ** 0.5 > > > >-(-(-(-2))) is equal to 2, and 2 is not equal to -2, hence the first term -(-(-(-2))) == -2 is False. 4 >= 16 ** 0.5 is True because 16 ** 0.5 is equal to 4, and 4 is greater then or equal to 4, hence the 2nd term 4 >= 16 ** 0.5 is True. > > > >Entire expression : False because False and True gives False > > In python, "and" and "or" short circuit. So if you know enough to evaluate the > condition from the left hand side, the right hand side is not evaluated at all. > > So since 2 == -2 gives False, the expresion is False and the right hand is not > evaluated. > > Note, BTW, that 16 ** 0.5 returns a floating point value. While that particular > example works nicely, probably because it is all powers of 2 and doesn't hit > rounding issues, testing equality with floating point is a dangerous area. > > >C) Set bool_three equal to the result of > >19 % 4 != 300 / 10 / 10 and False > > > >19 % 4 = 3 which is equal to 300 / 10 / 10 = 3, hence the first term is False. Entire expression is then equal to True, because False and False = True > > Entire expression is False because the left hand side is False. > > >D) Set bool_four equal to the result of > >-(1 ** 2) < 2 ** 0 and 10 % 10 <= 20 - 10 * 2 > > > >-(1 ** 2) is equal to -1 , which is less than 2 ** 0 = 1, hence the first term is True. 2nd term 10 % 10 is equal to 0 , which is less than or equal to 20 - 10 * 2 , hence 2nd term is True. > > > >Entire expression : True and True = True > > Correct. (In my head; haven't run the code.) > > >E) Set bool_five equal to the result of > >True and True > > > >Entire Expression : True and True = True > > Correct. > > Cheers, > Cameron Simpson > > ERROR 155 - You can't do that. - Data General S200 Fortran error code list > 19 % 4 = 3 which is equal to 300 / 10 / 10 = 3, hence the first term is False. Entire expression is then equal to True, because False and False = True > > Entire expression is False because the left hand side is False. Am I missing something here ? 19 % 4 = 19 modulo 4 equals to 3 right ? which equals the right hand side , hence first term is True From ben+python at benfinney.id.au Wed Sep 27 00:14:05 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 27 Sep 2017 14:14:05 +1000 Subject: Parentheses (as after "print") References: Message-ID: <854lro6anm.fsf@benfinney.id.au> ram at zedat.fu-berlin.de (Stefan Ram) writes: > Why do we newbies write ?print 2?? Here's another hint. > This is an original transcript of what happened to me today: [?] > What happened? I woke up today in parens mood. So I typed: > > import( operator ) So, are you making the case that people write the wrong syntax because they wake up in the wrong mood? Python doesn't much care about our mood :-) The syntax is what it is, and the programmer has to deal with the syntax as it is. > Python told me that I should type: > > import operator > > . Fine, Python conditioned me to omit the parens. Hopefully Python is conditioning you that a function call requires parens; the above statement does not have a function call. What is being communicated to us with this example, do you think? -- \ ?If you fell down yesterday, stand up today.? ?_The Anatomy of | `\ Frustration_, H. G. Wells, 1936 | _o__) | Ben Finney From ben+python at benfinney.id.au Wed Sep 27 00:16:52 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 27 Sep 2017 14:16:52 +1000 Subject: Parentheses (as after "print") References: <59cb0414$0$14955$b1db1813$d948b532@news.astraweb.com> Message-ID: <85zi9g4vyj.fsf@benfinney.id.au> ram at zedat.fu-berlin.de (Stefan Ram) writes: > But it's a pattern when it means to strip the language > of useless boilerplate and still following consistent > and simple rules. That was what made Python great. Yes. Python syntax allows for *mentioning* an object, and also allows for *calling* that object. The programmer specifies which one they want by using the appropriate syntax for each. The parens for a function call is not an example of ?useless boilerplate?. It is minimal syntax for the distinction to be made. -- \ ?When I get real bored, I like to drive downtown and get a | `\ great parking spot, then sit in my car and count how many | _o__) people ask me if I'm leaving.? ?Steven Wright | Ben Finney From greg.ewing at canterbury.ac.nz Wed Sep 27 00:23:27 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 27 Sep 2017 17:23:27 +1300 Subject: Boolean Expressions In-Reply-To: <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> References: <93e56e93-0560-46c4-b9bf-d16a79bdc33f@googlegroups.com> <46d42b27-0f88-4309-94f2-d93860056372@googlegroups.com> Message-ID: Cai Gengyang wrote: > So does that mean that the way 'and' works in Python is that both terms must > be True (1) for the entire expression to be True ? Why is it defined that > way, weird ? It's not weird, it's the normal meaning of "and" in English. Do I have purple hair? No. Do I have three nostrils? No. Do I have purple hair AND three nostrils? No. If the answer to the third question were "yes" given the first two, *that* would be weird. -- Greg From BILL_NOSPAM at whoknows.net Wed Sep 27 00:29:32 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Wed, 27 Sep 2017 00:29:32 -0400 Subject: Aliasing [was Re: [Tutor] beginning to code] In-Reply-To: <59cb13f0$0$14949$b1db1813$d948b532@news.astraweb.com> References: <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> <9ff212ad-da8d-2c1b-07be-823f03a37d46@nedbatchelder.com> <59ca47fc$0$14934$b1db1813$d948b532@news.astraweb.com> <59cb13f0$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > On Wed, 27 Sep 2017 02:03 am, Stefan Ram wrote: > >> Steve D'Aprano writes: >>> On Tue, 26 Sep 2017 03:26 am, Antoon Pardon wrote: >>>> at that moment, but it still needed correction. If the assignment is >>>> an alias operator then after the statements >>> Here's some C++ code that demonstrates it. Apologies in advance if it isn't >>> the most idiomatic C++ code. >> In C++, assignments and initializations are different >> concepts. >> >>> int& b = a; // reference variable or alias >> This is an initialization, not an assignment. > A pedantic difference that makes no difference to my argument. > > I see that you ignored the later assignment: > > b = 2; > > which also assigned to a. *That** is the fundamental point: b is certainly an > alias for a, and assigning to b assigns to a. > > That's how aliases work in C++. That's how var parameters in Pascal work, and > out parameters in Ada. That is what it means to say that "b is an alias to a". > > b is another name for the *variable* a, not just whatever value a happens to > hold now. > > I say that assignment in Python is NOT an aliasing operation. Antoon claims I'm > wrong, and his evidence is: > > a = [] > b = a # Antoon says this is an alias operation > b.append(1) > assert a == [1] > > > But that's not enough for the variable b to be an alias for the variable a. > > Antoon is correct that a and b are two different names for the same list, but > the two variables are not aliases to each other because assignments to b do not > affect a, and vice versa. > > A good test for aliasing is to take the source code and mechanically replace > every occurrence of the alias (in the same scope of course) with the original, > or vice versa, and see whether the meaning of the code changes. > > In C++, apart from the initial binding: > > int& b = a; > > ("initialisation") you could now randomly swap a for b or b for a and the > meaning of the code will not change. > > But in Python, if we try the same trick, the code *does* change: > > a = 1 > b = a > b = 2 > > *is not* the same as: > > a = 1 > b = a > a = 2 > > > (1) In Pascal, Ada, C++ etc using a reference variable (or var parameter, or > whatever terminology they use) makes the two names aliases to EACH OTHER, not > to the value they are bound to. > > (2) In Python, Javascript, Ruby etc assignment can give you two names for the > same object, but the names do not alias each other. > > The critical distinction here is whether the names refer to each other: > > a <---> b > > or whether they merely refer to the same value: > > a ---> [ value ] <--- b > > > Python uses the second model. Var parameters in Pascal and references in C++ use > the first. Since the term "aliasing" is well-established for the first, using > it in Python *without making the difference clear* is wrong. > > That is a very nice argument! : ) From cs at cskk.id.au Wed Sep 27 01:01:15 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 27 Sep 2017 15:01:15 +1000 Subject: Boolean Expressions In-Reply-To: <28a719f7-0a85-462b-8125-c7aab5c17c21@googlegroups.com> References: <28a719f7-0a85-462b-8125-c7aab5c17c21@googlegroups.com> Message-ID: <20170927050115.GA52149@cskk.homeip.net> On 26Sep2017 20:55, Cai Gengyang wrote: >On Wednesday, September 27, 2017 at 6:45:00 AM UTC+8, Cameron Simpson wrote: >> On 26Sep2017 14:43, Cai Gengyang wrote: >> >C) Set bool_three equal to the result of >> >19 % 4 != 300 / 10 / 10 and False >> > >> 19 % 4 = 3 which is equal to 300 / 10 / 10 = 3, hence the first term is >> False. Entire expression is then equal to True, because False and False = >> True >> >> Entire expression is False because the left hand side is False. > >Am I missing something here ? 19 % 4 = 19 modulo 4 equals to 3 right ? which >equals the right hand side , hence first term is True But the test is for "!=", not "==". So False. Cheers, Cameron Simpson (formerly cs at zip.com.au) From antoon.pardon at vub.be Wed Sep 27 02:56:03 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Sep 2017 08:56:03 +0200 Subject: Aliasing [was Re: [Tutor] beginning to code] In-Reply-To: <59cb13f0$0$14949$b1db1813$d948b532@news.astraweb.com> References: <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> <9ff212ad-da8d-2c1b-07be-823f03a37d46@nedbatchelder.com> <59ca47fc$0$14934$b1db1813$d948b532@news.astraweb.com> <59cb13f0$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: <499bb10a-a82a-4026-ad09-32b77b52c6cc@vub.be> Op 27-09-17 om 04:58 schreef Steve D'Aprano: > On Wed, 27 Sep 2017 02:03 am, Stefan Ram wrote: > >> Steve D'Aprano writes: >>> On Tue, 26 Sep 2017 03:26 am, Antoon Pardon wrote: >>>> at that moment, but it still needed correction. If the assignment is >>>> an alias operator then after the statements >>> Here's some C++ code that demonstrates it. Apologies in advance if it isn't >>> the most idiomatic C++ code. >> In C++, assignments and initializations are different >> concepts. >> >>> int& b = a; // reference variable or alias >> This is an initialization, not an assignment. > A pedantic difference that makes no difference to my argument. > > I see that you ignored the later assignment: > > b = 2; > > which also assigned to a. *That** is the fundamental point: b is certainly an > alias for a, and assigning to b assigns to a. > > That's how aliases work in C++. That's how var parameters in Pascal work, and > out parameters in Ada. That is what it means to say that "b is an alias to a". > > b is another name for the *variable* a, not just whatever value a happens to > hold now. > > I say that assignment in Python is NOT an aliasing operation. Antoon claims I'm > wrong, and his evidence is: > > a = [] > b = a # Antoon says this is an alias operation > b.append(1) > assert a == [1] > > > But that's not enough for the variable b to be an alias for the variable a. Yes it is! > Antoon is correct that a and b are two different names for the same list, but > the two variables are not aliases to each other because assignments to b do not > affect a, and vice versa. You are hitting your blindspot again and ignore that in languages like Pascal ... an assignment is a copy operation and thus mutates the variable that is assigned to. Two variables are aliases for each other if they are the same object and so when one mutates the object seen through one name, the mutation is visible through the other. Since Python in Python an assignent doesn't mutate the object but makes it an alias of an other object it is wrong to expect in python that an assignment to one of an alias which would break the alias, would have the same effect as in a language where an assignemt to one of an alias would mutate the variable. > A good test for aliasing is to take the source code and mechanically replace > every occurrence of the alias (in the same scope of course) with the original, No it is not. You forget the possibility that two names can be aliases at one point but no longer are at an other point. > or vice versa, and see whether the meaning of the code changes. > > In C++, apart from the initial binding: > > int& b = a; > > ("initialisation") you could now randomly swap a for b or b for a and the > meaning of the code will not change. That is only true for as long a and b remain aliases. As soon as an operation is excuted that makes a and b no longer aliases, your test fails. Sure in a language like C++ such an alias can't be broken, but aliases are broken in Python all the time because that is what assignment do, break some aliases and forge new ones. > But in Python, if we try the same trick, the code *does* change: > > a = 1 > b = a > b = 2 > > *is not* the same as: > > a = 1 > b = a > a = 2 > > > (1) In Pascal, Ada, C++ etc using a reference variable (or var parameter, or > whatever terminology they use) makes the two names aliases to EACH OTHER, not > to the value they are bound to. No using a reference variable makes the two names aliases to the same object/entity. So that if you mutate it through one name, the mutation is visible through the other name. The effect you see in those languages with assignments via one name are explained by the fact that assignment is a mutating operation. > (2) In Python, Javascript, Ruby etc assignment can give you two names for the > same object, but the names do not alias each other. > > The critical distinction here is whether the names refer to each other: > > a <---> b In languages like C++, Pascal, ... aliases don't mean the names refer to each other. Names/Identifiers refering to each other is non sensical in those languages. > > or whether they merely refer to the same value: > > a ---> [ value ] <--- b > > > Python uses the second model. Var parameters in Pascal and references in C++ use > the first. Since the term "aliasing" is well-established for the first, using > it in Python *without making the difference clear* is wrong. No, the model that C++ and Pascal use is not different in this aspect. -- Antoon Pardon. From steve+comp.lang.python at pearwood.info Wed Sep 27 03:21:59 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2017 07:21:59 GMT Subject: Parentheses (as after "print") References: <59cb0414$0$14955$b1db1813$d948b532@news.astraweb.com> Message-ID: <59cb5197$0$14961$b1db1813$d948b532@news.astraweb.com> On Wed, 27 Sep 2017 02:48:41 +0000, Stefan Ram wrote: > Steve D'Aprano writes: >>"Do What I Mean" (DWIM) programming is a terrible idea. > > It's an anti-pattern, when one expects the implementation to follow > different and contradicting rules and then somehow guess what was in > the mind of the programmer. > > But it's a pattern when it means to strip the language of useless > boilerplate and still following consistent and simple rules. That was > what made Python great. Python has never followed the DWIM anti-pattern as a philosophy. DWIM goes against the Zen of Python: "In the face of ambiguity, refuse the temptation to guess." You want Python to guess that something which doesn't start with "def" and doesn't end with a colon is a function definition, rather than a class definition, or a messed up `if func(a, b)` statement, or a messed up `while func(a, b)` statement, or a messed up `with func(a, b)` statement. No thanks. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From __peter__ at web.de Wed Sep 27 03:25:54 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 Sep 2017 09:25:54 +0200 Subject: Parentheses (as after "print") References: Message-ID: Stefan Ram wrote: > Why do we newbies write ?print 2?? Here's another hint. > This is an original transcript of what happened to me today: > > |>>> import( operator ) > | File "", line 1 > | import( operator ) > | ^ > |SyntaxError: invalid syntax > | > |>>> import operator > | > |>>> help operator > | File "", line 1 > | help operator > | ^ > |SyntaxError: invalid syntax > | > |>>> help( operator ) > |Help on module operator: > > What happened? I woke up today in parens mood. So I typed: > > import( operator ) > > Python told me that I should type: > > import operator > > . Fine, Python conditioned me to omit the parens. > So now I was in noparens mood. So I typed: > > help operator > > . Oops! > > "Don't make me think!" If you want that level of -- let's call it consistency -- you should either plead for foo = import("foo") to spell an import or expect print foo to be syntactic sugar for foo = __print__("foo") (As for the ":" -- easy to read wins over easy to type.) From rosuav at gmail.com Wed Sep 27 03:33:38 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Sep 2017 17:33:38 +1000 Subject: Parentheses (as after "print") In-Reply-To: References: Message-ID: On Wed, Sep 27, 2017 at 5:25 PM, Peter Otten <__peter__ at web.de> wrote: > If you want that level of -- let's call it consistency -- you should either > plead for > > foo = import("foo") > > to spell an import Yeah no thanks. I work also with JavaScript, and there is no benefit whatsoever to having lines like: const express = require("express"); Redundancy is a bad thing. Since importing is so extremely common, it makes good sense to promote it to syntax and eliminate the redundancy. That's why we have some things as syntax and others as functions - the advantages outweigh the costs in some cases, but not in others. ChrisA From antoon.pardon at vub.be Wed Sep 27 03:35:29 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Sep 2017 09:35:29 +0200 Subject: Aliasing [was Re: [Tutor] beginning to code] In-Reply-To: <59cb13f0$0$14949$b1db1813$d948b532@news.astraweb.com> References: <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> <9ff212ad-da8d-2c1b-07be-823f03a37d46@nedbatchelder.com> <59ca47fc$0$14934$b1db1813$d948b532@news.astraweb.com> <59cb13f0$0$14949$b1db1813$d948b532@news.astraweb.com> Message-ID: Op 27-09-17 om 04:58 schreef Steve D'Aprano: > A pedantic difference that makes no difference to my argument. > > I see that you ignored the later assignment: > > b = 2; > > which also assigned to a. *That** is the fundamental point: b is certainly an > alias for a, and assigning to b assigns to a. > > That's how aliases work in C++. That's how var parameters in Pascal work, and > out parameters in Ada. That is what it means to say that "b is an alias to a". The main problem is that you keep using assignment as if an assignment in languages like Pascal and C++ has an similar effect like as assignment in Python and thus that if an assignment has an effect in one language it should have that effect in other languages. In C++ and Pascal talking about an assignment means, that we have a name that refers to an object whose value was overwritten. In Python an assignment means that we have name that will now refer to an other object. If two names are aliases they refer to the same object and when the value of that object is modified through one name, it is visible through the other name. How one modified that object is immaterial. It doesn't matter whether the modification/mutation was done through an asignment or an other kind of mutation. It also doesn't matter what the label is, we use for the operation. The label "assignment" is not magic. If in one context an assignment mutates and in an other context it doesn't you can't interfere conclusions about the assignment in the second context based on the effects an assignment has in the first context because we are talking about two differnt operations that just use the same lable. -- Antoon Pardon. From steve+comp.lang.python at pearwood.info Wed Sep 27 03:38:52 2017 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Sep 2017 07:38:52 GMT Subject: Aliasing [was Re: [Tutor] beginning to code] References: <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> <9ff212ad-da8d-2c1b-07be-823f03a37d46@nedbatchelder.com> <59ca47fc$0$14934$b1db1813$d948b532@news.astraweb.com> <59cb13f0$0$14949$b1db1813$d948b532@news.astraweb.com> <499bb10a-a82a-4026-ad09-32b77b52c6cc@vub.be> Message-ID: <59cb558c$0$14961$b1db1813$d948b532@news.astraweb.com> On Wed, 27 Sep 2017 08:56:03 +0200, Antoon Pardon wrote: >> But that's not enough for the variable b to be an alias for the >> variable a. > > Yes it is! Since you seem to be intent on inventing your own meanings for well established words, for the confusion and misinformation of all, I can only follow in your footsteps and say: "You are a fine fellow and your arguments make perfect sense." Make if that what you will. Antoon, there is no point in continuing this argument. You're entitled to your own opinions, but not your own facts, so when you insist: > No, the model that C++ and Pascal use is not different in this aspect. that Pascal var parameters and C++ reference variables operate the same way as Python variable assignment, the *kindest* thing I can say is that you are ignorant. Python does not have anything like C++ references and Pascal var parameters, which is why you will never be able to write a swap() function that operates like the classic Pascal swap procedure used as the definitive test for pass-by-reference. Twice you have claimed to be able to write such a swap procedure for lists. You can't. If you think you can, it is only because you have misunderstood the problem and are writing something else that does something different from what the Pascal version does. -- Steven D'Aprano ?You are deluded if you think software engineers who can't write operating systems or applications without security holes, can write virtualization layers without security holes.? ?Theo de Raadt From p.f.moore at gmail.com Wed Sep 27 03:50:12 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Wed, 27 Sep 2017 08:50:12 +0100 Subject: auto installing dependencies with pip to run a python zip application ? In-Reply-To: <59cad948$0$829$e4fe514c@news.xs4all.nl> References: <59caa0da$0$698$e4fe514c@news.xs4all.nl> <59cad948$0$829$e4fe514c@news.xs4all.nl> Message-ID: On 26 September 2017 at 23:48, Irmen de Jong wrote: > On 09/26/2017 10:49 PM, Paul Moore wrote: >> On 26 September 2017 at 19:47, Irmen de Jong wrote: >>> Any thoughts on this? Is it a good idea or something horrible? Has >>> someone attempted something like this before perhaps? >> >> When I've done this, I've bundled my dependencies in with my zipapp. >> Of course that's trickier if you have binary dependencies like pillow. > > Yeah I've considered that for a moment but I think sometimes you've also > got to deal with licensing issues. I'd rather avoid this. I'd assume you're simply bundling for convenience, but I agree that avoiding the treacherous waters of licensing is always a good idea ;-) >> What you could do is pip install your binary dependencies into a >> directory in $TEMP using --target, then add that directory to >> sys.path. Probably easier than building a full virtualenv. Bundle pip >> with your app if you can't assume your users will have pip available. > > Interesting idea, although like this wouldn't I have to download the > dependencies every time I launch my game? (unless I re-use the same > temporary directory every time) Ah, I'd assumed that's what you were doing with the virtualenv, I hadn't realised you were talking about a one-off setup step. Yeah, re-using a temporary directory doesn't buy you much compared to using a virtualenv (particularly if you can target versions of Python that have the built in venv module). Paul From BILL_NOSPAM at whoknows.net Wed Sep 27 03:50:24 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Wed, 27 Sep 2017 03:50:24 -0400 Subject: Spacing conventions Message-ID: Ever since I download the MyCharm IDE a few days ago, I've been noticing all sort of "spacing conventions (from PEP) that are suggested. How do folks regard these in general? For instance, the conventions suggest that if x>y : pass should be written if x > y: pass Personally, I like seeing a space before the colon (:). And then in my_list = [ i for i in range(0, 10) ] it complains about my extra space inside of the brackets. If you are teaching beginning students, do you expect them to try to follow these sorts of conventions? Is it perfectly fine to let "taste" guide you (I'm just trying to get a feel for the philosophy here)? I also notice "break" and exception handling is used much more in Python than in C++, for instance. I was taught "break" and "continue" led to "unstructured code"--but that was a while back. I can still see their use causing potential trouble in (really-long) real-world code. Bill From tjol at tjol.eu Wed Sep 27 03:59:49 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 27 Sep 2017 09:59:49 +0200 Subject: Parentheses (as after "print") In-Reply-To: References: Message-ID: On 26/09/17 17:56, Stefan Ram wrote: > What happened? I woke up today in parens mood. So I typed: > > import( operator ) > > Python told me that I should type: > > import operator This is an interesting case: >>> import (os, sys) File "", line 1 import (os, sys) ^ SyntaxError: invalid syntax >>> from os import (listdir, chdir) >>> listdir, chdir (, ) >>> Of course the reasons the second syntax was eventually added to the language don't apply in the first case, but this does look a bit inconsistent... -- Thomas From tjol at tjol.eu Wed Sep 27 04:10:58 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 27 Sep 2017 10:10:58 +0200 Subject: Spacing conventions In-Reply-To: References: Message-ID: <72ba776d-2009-0cce-c992-974469d28e74@tjol.eu> On 27/09/17 09:50, Bill wrote: > Ever since I download the MyCharm IDE a few days ago, I've been > noticing all sort of "spacing conventions (from PEP) that are > suggested. How do folks regard these in general? PEP 8 (https://www.python.org/dev/peps/pep-0008), the officially recommended style guide for Python code, is generally well regarded and widely followed. Having a consistent style, whatever it is, makes your code more readable. You can of course have your own house style, but using the same style as most other Pythonistas for new code helps other people read your code. I recommend following PEP 8 as much as possible. > > For instance, the conventions suggest that > > if x>y : > pass > > should be written > if x > y: > pass > > Personally, I like seeing a space before the colon (:). And then in > > my_list = [ i for i in range(0, 10) ] > it complains about my extra space inside of the brackets. I think you'll find that spaces before colons are exceedingly rare in Python code. Spaces inside brackets, especially in list comprehensions, may be more common. Personally I've found that my preferred tool, the Anaconda plugin for Sublime Text, sometime gets PEP 8 operator spacing wrong, and complains operators without spaces even where PEP8 explicitly recommends not using spaces. Read PEP 8, follow it if possible, but use your best judgement. Readability is important, blindly following your IDE's advice not so much. -- Thomas > > If you are teaching beginning students, do you expect them to try to > follow these sorts of conventions? Is it perfectly fine to let > "taste" guide you (I'm just trying to get a feel for the philosophy > here)? I also notice "break" and exception handling is used much > more in Python than in C++, for instance. I was taught "break" and > "continue" led to "unstructured code"--but that was a while back. I > can still see their use causing potential trouble in (really-long) > real-world code. > > Bill > > > From rosuav at gmail.com Wed Sep 27 04:11:34 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Sep 2017 18:11:34 +1000 Subject: Aliasing [was Re: [Tutor] beginning to code] In-Reply-To: <59cb558c$0$14961$b1db1813$d948b532@news.astraweb.com> References: <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> <9ff212ad-da8d-2c1b-07be-823f03a37d46@nedbatchelder.com> <59ca47fc$0$14934$b1db1813$d948b532@news.astraweb.com> <59cb13f0$0$14949$b1db1813$d948b532@news.astraweb.com> <499bb10a-a82a-4026-ad09-32b77b52c6cc@vub.be> <59cb558c$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: On Wed, Sep 27, 2017 at 5:38 PM, Steven D'Aprano wrote: > Twice you have claimed to be able to write such a swap procedure for > lists. You can't. If you think you can, it is only because you have > misunderstood the problem and are writing something else that does > something different from what the Pascal version does. I suspect what he's thinking of is a swap_contents() function, which gives the appearance that the lists have been swapped. That's entirely possible, but doesn't actually achieve what swap() does. ChrisA From rosuav at gmail.com Wed Sep 27 04:19:05 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Sep 2017 18:19:05 +1000 Subject: Spacing conventions In-Reply-To: <72ba776d-2009-0cce-c992-974469d28e74@tjol.eu> References: <72ba776d-2009-0cce-c992-974469d28e74@tjol.eu> Message-ID: On Wed, Sep 27, 2017 at 6:10 PM, Thomas Jollans wrote: > Personally I've found that my preferred tool, the Anaconda plugin for > Sublime Text, sometime gets PEP 8 operator spacing wrong, and complains > operators without spaces even where PEP8 explicitly recommends not using > spaces. Read PEP 8, follow it if possible, but use your best judgement. > Readability is important, blindly following your IDE's advice not so much. And most importantly, read this section: https://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds This is the single most important recommendation in the document. Next most important is the one immediately before it - the introduction - which specifically states that this is the style guide for *the standard library*. It's not a document which governs YOUR code, unless you specifically choose it to be. That said, though, it does reflect a lot of commonly-held views on what's good style for Python code. And in the original examples, I agree with PEP 8 on all points - no space before colon, no space inside brackets, and generally yes space around the operator. ChrisA From antoon.pardon at vub.be Wed Sep 27 04:22:54 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Sep 2017 10:22:54 +0200 Subject: Aliasing [was Re: [Tutor] beginning to code] In-Reply-To: References: <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> <9ff212ad-da8d-2c1b-07be-823f03a37d46@nedbatchelder.com> <59ca47fc$0$14934$b1db1813$d948b532@news.astraweb.com> <59cb13f0$0$14949$b1db1813$d948b532@news.astraweb.com> <499bb10a-a82a-4026-ad09-32b77b52c6cc@vub.be> <59cb558c$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: Op 27-09-17 om 10:11 schreef Chris Angelico: > On Wed, Sep 27, 2017 at 5:38 PM, Steven D'Aprano > wrote: >> Twice you have claimed to be able to write such a swap procedure for >> lists. You can't. If you think you can, it is only because you have >> misunderstood the problem and are writing something else that does >> something different from what the Pascal version does. > I suspect what he's thinking of is a swap_contents() function, which > gives the appearance that the lists have been swapped. That's entirely > possible, but doesn't actually achieve what swap() does. If you refer to languages like Pascal or C, for illustrating that you can write a swap function in them, the swapping that happens there is one of content. So claiming that swapping contend doesn't actually achieves whar swap() does, seems wrong. -- Antoon Pardon. From mail at timgolden.me.uk Wed Sep 27 04:24:27 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Wed, 27 Sep 2017 09:24:27 +0100 Subject: Spacing conventions In-Reply-To: <72ba776d-2009-0cce-c992-974469d28e74@tjol.eu> References: <72ba776d-2009-0cce-c992-974469d28e74@tjol.eu> Message-ID: <421ac1d0-f8b6-a2bb-d792-afb477ce03e2@timgolden.me.uk> > On 27/09/17 09:50, Bill wrote: >> If you are teaching beginning students, do you expect them to try to >> follow these sorts of conventions? Is it perfectly fine to let >> "taste" guide you (I'm just trying to get a feel for the philosophy >> here)? I few years ago I wrote a few short blog posts about my own preferences which contrasted with the PEP8 standard: http://ramblings.timgolden.me.uk/2012/03/27/pep8-or-not/ http://ramblings.timgolden.me.uk/2012/03/29/more-on-pep8/ http://ramblings.timgolden.me.uk/2012/04/09/pep8-it-is-then/ The upshot was that, although I preferred my own style, I recognised the benefit of using a common standard -- although without being slavish to it! FWIW I'd already been programming Python for some years when I wrote those posts: I wasn't just someone who'd discovered the language and had no idea about its conventions. I think with a few more years of experience, both in Python and in other (mostly SQL) coding, a point I'd make is that having a common standard reduces cognitive jarring -- it reduces one small barrier to understanding someone else's code. Of course, within any organisation, you can achieve that without using Python's own convention, but my final decision was that following the more universal Python convention was worthwhile for essentially the same reason. TJG From antoon.pardon at vub.be Wed Sep 27 04:59:32 2017 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Sep 2017 10:59:32 +0200 Subject: Aliasing [was Re: [Tutor] beginning to code] In-Reply-To: <59cb558c$0$14961$b1db1813$d948b532@news.astraweb.com> References: <5e2d733c-9a34-c9c2-7e8d-0eaa4f16c218@nedbatchelder.com> <746b8cf7-7573-9495-0bf1-23c3a5561b10@vub.be> <9ff212ad-da8d-2c1b-07be-823f03a37d46@nedbatchelder.com> <59ca47fc$0$14934$b1db1813$d948b532@news.astraweb.com> <59cb13f0$0$14949$b1db1813$d948b532@news.astraweb.com> <499bb10a-a82a-4026-ad09-32b77b52c6cc@vub.be> <59cb558c$0$14961$b1db1813$d948b532@news.astraweb.com> Message-ID: <7ff19c2e-6762-a93b-7171-6f769b3025fb@vub.be> Op 27-09-17 om 09:38 schreef Steven D'Aprano: No, the model that C++ and Pascal use is not different in this aspect. > that Pascal var parameters and C++ reference variables operate the same > way as Python variable assignment, the *kindest* thing I can say is that > you are ignorant. The kindest thing I can say about you is that you are very confused at a specific level. A confusion that is illustrated by your contribution at https://mail.python.org/pipermail/python-list/2017-September/726513.html and of which you seem to totally ignore my resonse at https://mail.python.org/pipermail/python-list/2017-September/726527.html > Python does not have anything like C++ references and Pascal var > parameters, which is why you will never be able to write a swap() > function that operates like the classic Pascal swap procedure used as the > definitive test for pass-by-reference. You keep repeating this and you keep ignoring my counter argument. The fact that you can write a swap procedure in C++ and Pascal is not because the parameter passing semantics are different but because the assignment semantics are different. I already explained that a working swap function depends on two conditions: 1) Reference paramaters 2) A general way in which the object a name refers to can be modified/mutated (In a language like Pascal that is the assignment). You keep asserting that not being able to write a swap means we don't have condition (1), while ignoring we know we don't have condition (2) in Python. > Twice you have claimed to be able to write such a swap procedure for > lists. You can't. If you think you can, it is only because you have > misunderstood the problem and are writing something else that does > something different from what the Pascal version does. I already posted code once, here it is again: ls1 = [1, 3, 5, 7] ls2 = [2, 4, 6] def list_swap(lp1, lp2): tmp = [] # pseudo declaration tmp[:] = lp1 # lp1[:] = lp2 # This is more or less how array assignments work in Pascal lp2[:] = tmp # print("ls1 =", ls1) print("ls2 =", ls2) list_swap(ls1, ls2) print() print("ls1 =", ls1) print("ls2 =", ls2) From gengyangcai at gmail.com Wed Sep 27 05:21:53 2017 From: gengyangcai at gmail.com (Cai Gengyang) Date: Wed, 27 Sep 2017 02:21:53 -0700 (PDT) Subject: Boolean Expressions In-Reply-To: References: <28a719f7-0a85-462b-8125-c7aab5c17c21@googlegroups.com> <20170927050115.GA52149@cskk.homeip.net> Message-ID: <38d05c34-9b18-44e2-a162-e428088c723e@googlegroups.com> On Wednesday, September 27, 2017 at 1:01:50 PM UTC+8, Cameron Simpson wrote: > On 26Sep2017 20:55, Cai Gengyang wrote: > >On Wednesday, September 27, 2017 at 6:45:00 AM UTC+8, Cameron Simpson wrote: > >> On 26Sep2017 14:43, Cai Gengyang wrote: > >> >C) Set bool_three equal to the result of > >> >19 % 4 != 300 / 10 / 10 and False > >> > > >> 19 % 4 = 3 which is equal to 300 / 10 / 10 = 3, hence the first term is > >> False. Entire expression is then equal to True, because False and False = > >> True > >> > >> Entire expression is False because the left hand side is False. > > > >Am I missing something here ? 19 % 4 = 19 modulo 4 equals to 3 right ? which > >equals the right hand side , hence first term is True > > But the test is for "!=", not "==". So False. > > Cheers, > Cameron Simpson (formerly cs at zip.com.au) Right ... I didn't see the ' =! ' From __peter__ at web.de Wed Sep 27 05:37:08 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 Sep 2017 11:37:08 +0200 Subject: Spacing conventions References: Message-ID: Bill wrote: > Ever since I download the MyCharm IDE a few days ago, I've been noticing > all sort of "spacing conventions (from PEP) that are suggested. How do > folks regard these in general? > > For instance, the conventions suggest that > > if x>y : > pass > > should be written > if x > y: > pass > > Personally, I like seeing a space before the colon (:). And then in > > my_list = [ i for i in range(0, 10) ] > it complains about my extra space inside of the brackets. Of late I've joined the "foolish consistency" camp and made the pep8 tool (now called pycodestyle to make it clear it is non-normative) a check-in hook. I agree with most of its complaints anyway and find it wasteful to fine-tune my code in that regard. > If you are teaching beginning students, do you expect them to try to > follow these sorts of conventions? At least mention the advantages to blend in rather than stand out as far as coding style is concerned. The reader can concentrate on functionality and is not distracted by the writer's ideosyncratic ideas about formatting. > Is it perfectly fine to let "taste" > guide you (I'm just trying to get a feel for the philosophy here)? I > also notice "break" and exception handling is used much more in Python > than in C++, for instance. I was taught "break" and "continue" led to > "unstructured code"--but that was a while back. I can still see their > use causing potential trouble in (really-long) real-world code. What actually causes the trouble is the really-long -- i. e. unstructured -- code. "real-world" is but an excuse here ;) From dvl at psu.edu Wed Sep 27 07:19:21 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Wed, 27 Sep 2017 07:19:21 -0400 Subject: Aliasing [was Re: [Tutor] beginning to code] In-Reply-To: mailman.700.1506481203.10703.python-list@python.org References: Message-ID: <1506511161l.19136626l.0l@psu.edu> On Tue, Sep 26, 2017 11:00 PM, Steve D'Aprano wrote: > The critical distinction here is whether the names refer to each other: > >a <---> b > >or whether they merely refer to the same value: > >a ---> [ value ] <--- b > > >Python uses the second model. Var parameters in Pascal and references in C++ use >the first. Since the term "aliasing" is well-established for the first, using >it in Python *without making the difference clear* is wrong. > > > Aha! There is the fundamental problem. In your first diagram below, if a is a pointer to b, and b is a pointer to a, then where is the value? If the value of 1 (or 2) is in a, then a cannot point at b; Or are you saying now that all variables in Pascal and C are _both_ values and pointers, simultaneously? Does that mean then that the value 1 (or 2) is in _both_ a and b? So that an assignment to either must change both copies of the value? No, I think it is more likely to be that the second diagram applies in all cases. Simply declaring a variable like A would lead to a --> [ uninitialized ] int& b creates an alias to a leads to a -> [ uninitialized ] <- b and then any assignment to a or b in the non-Python languages under consideration would fill in that box, allowing the change to be visible to both. But in Python, _all_ assignments are aliases. And I'll leave off further discussion by referring back to my previous note about what happens when we do "b = c" in the non-Python languages and in Python. >From the ordering of the notes in this forum, I will just assume you did not get a chance to read it before this post I am responding to. Roger Christman Pennsylvania State University From m at funkyhat.org Wed Sep 27 07:51:37 2017 From: m at funkyhat.org (Matt Wheeler) Date: Wed, 27 Sep 2017 11:51:37 +0000 (UTC) Subject: Printing a Chunk Of Words In-Reply-To: References: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> <87k20myygb.fsf@bsb.me.uk> Message-ID: With deepest apologies to all involved... On Tue, 26 Sep 2017 at 08:42 Gregory Ewing wrote: > Ben Bacarisse wrote: > > Think functional! This is 257 characters: > > 250 chars, 17 shorter than the text it produces: > > a=[];o=[];n=[];A=list.append > for b in range(3,-1,-1): > x=bool(b>>1);y=bool(b&1);A(a,"%s and %s is %s"%(x,y,x and y));A(o,"%s or > %s is > %s"%(x,y,x or y)) > if x:A(n,"not %s is %s"%(y,not y)) > print(" Boolean Operators\n"+"-"*24+"\n"+"\n".join(a+o+n)) > Cutting the same (quite reasonable) corners as you, I've got it down 212 characters: t,f,a,o,n='True','False','and','or','not' l=[" Boolean Operators\n"+"-"*24] for x in [(l,p,r)for p in(a,o)for l in(t,f)for r in(t,f)]+[(n,t),(n,f)]:x=' '.join(x);l+=[x[0].upper()+x[1:]+" is "+str(eval(x))] for i in 12,9,5,0:l.insert(i,'') print('\n'.join(l)) Reproducing the original string exactly the best I've managed is 260: t,f,a,o,n='True','False','and','or','not' l=[" Boolean Operators\n"+"-"*24] for x in [(l,p,r)for p in(a,o)for l in(t,f)for r in(t,f)]+[(n,t),(n,f)]:x=' '.join(x);l+=[x[0].upper()+x[1:]+" is "+str(eval(x))] for i in 12,9,5,0:l.insert(i,'') print('\n'.join(l)) -- -- Matt Wheeler http://funkyh.at From christopher_reimer at icloud.com Wed Sep 27 08:14:06 2017 From: christopher_reimer at icloud.com (Christopher Reimer) Date: Wed, 27 Sep 2017 05:14:06 -0700 Subject: Spacing conventions In-Reply-To: References: Message-ID: <53E09AAA-76FD-4F4E-91F9-8B7066C4CA5E@icloud.com> On Sep 27, 2017, at 12:50 AM, Bill wrote: > > Ever since I download the MyCharm IDE a few days ago, I've been noticing all sort of "spacing conventions (from PEP) that are suggested. How do folks regard these in general? > > For instance, the conventions suggest that > > if x>y : > pass > > should be written > if x > y: > pass > > Personally, I like seeing a space before the colon (:). And then in > > my_list = [ i for i in range(0, 10) ] > it complains about my extra space inside of the brackets. > > If you are teaching beginning students, do you expect them to try to follow these sorts of conventions? Is it perfectly fine to let "taste" guide you (I'm just trying to get a feel for the philosophy here)? I also notice "break" and exception handling is used much more in Python than in C++, for instance. I was taught "break" and "continue" led to "unstructured code"--but that was a while back. I can still see their use causing potential trouble in (really-long) real-world code. > > Bill > > > > -- > https://mail.python.org/mailman/listinfo/python-list I came across a Python script on Github that did what I needed except for some trivial modifications to make it Python 3 compatible. I did consider contributing changes to make the script Python 2 and 3 compatible. However, the script was written an idiosyncratic, anti-PEP8 style that was hard to match and the author previously rejected all Python 3 contributions. Forking the script to make it Python 2/3 compatible *and* PEP8 compliant would require too much effort on my part, especially since I needed to use the script only once. Chris R. From tjol at tjol.eu Wed Sep 27 08:58:59 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 27 Sep 2017 14:58:59 +0200 Subject: Printing a Chunk Of Words In-Reply-To: References: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> <87k20myygb.fsf@bsb.me.uk> Message-ID: On 2017-09-27 13:51, Matt Wheeler wrote: > With deepest apologies to all involved... > > On Tue, 26 Sep 2017 at 08:42 Gregory Ewing > wrote: > >> Ben Bacarisse wrote: >>> Think functional! This is 257 characters: >> >> 250 chars, 17 shorter than the text it produces: >> >> a=[];o=[];n=[];A=list.append >> for b in range(3,-1,-1): >> x=bool(b>>1);y=bool(b&1);A(a,"%s and %s is %s"%(x,y,x and y));A(o,"%s or >> %s is >> %s"%(x,y,x or y)) >> if x:A(n,"not %s is %s"%(y,not y)) >> print(" Boolean Operators\n"+"-"*24+"\n"+"\n".join(a+o+n)) >> > > Cutting the same (quite reasonable) corners as you, I've got it down 212 > characters: > > t,f,a,o,n='True','False','and','or','not' > l=[" Boolean Operators\n"+"-"*24] > for x in [(l,p,r)for p in(a,o)for l in(t,f)for r in(t,f)]+[(n,t),(n,f)]:x=' > '.join(x);l+=[x[0].upper()+x[1:]+" is "+str(eval(x))] > for i in 12,9,5,0:l.insert(i,'') > print('\n'.join(l)) > > Reproducing the original string exactly the best I've managed is 260: > > t,f,a,o,n='True','False','and','or','not' The Not is capitalized in the original string. > l=[" Boolean Operators\n"+"-"*24] > for x in [(l,p,r)for p in(a,o)for l in(t,f)for r in(t,f)]+[(n,t),(n,f)]:x=' > '.join(x);l+=[x[0].upper()+x[1:]+" is "+str(eval(x))] > for i in 12,9,5,0:l.insert(i,'') > print('\n'.join(l)) From __peter__ at web.de Wed Sep 27 09:48:12 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 Sep 2017 15:48:12 +0200 Subject: Printing a Chunk Of Words References: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> <87k20myygb.fsf@bsb.me.uk> Message-ID: Matt Wheeler wrote: > With deepest apologies to all involved... > > On Tue, 26 Sep 2017 at 08:42 Gregory Ewing > wrote: > >> Ben Bacarisse wrote: >> > Think functional! This is 257 characters: >> >> 250 chars, 17 shorter than the text it produces: >> >> a=[];o=[];n=[];A=list.append >> for b in range(3,-1,-1): >> x=bool(b>>1);y=bool(b&1);A(a,"%s and %s is %s"%(x,y,x and y));A(o,"%s >> or >> %s is >> %s"%(x,y,x or y)) >> if x:A(n,"not %s is %s"%(y,not y)) >> print(" Boolean Operators\n"+"-"*24+"\n"+"\n".join(a+o+n)) >> > > Cutting the same (quite reasonable) corners as you, I've got it down 212 > characters: > > t,f,a,o,n='True','False','and','or','not' > l=[" Boolean Operators\n"+"-"*24] > for x in [(l,p,r)for p in(a,o)for l in(t,f)for r > in(t,f)]+[(n,t),(n,f)]:x=' '.join(x);l+=[x[0].upper()+x[1:]+" is > "+str(eval(x))] for i in 12,9,5,0:l.insert(i,'') > print('\n'.join(l)) > > Reproducing the original string exactly the best I've managed is 260: > > t,f,a,o,n='True','False','and','or','not' > l=[" Boolean Operators\n"+"-"*24] > for x in [(l,p,r)for p in(a,o)for l in(t,f)for r > in(t,f)]+[(n,t),(n,f)]:x=' '.join(x);l+=[x[0].upper()+x[1:]+" is > "+str(eval(x))] for i in 12,9,5,0:l.insert(i,'') > print('\n'.join(l)) > That's a bit long, don't you think, as it can be beaten even by plain old zipping: $ cat booltable2.py from codecs import*;print(decode(decode(b'eJzjUgABp/z8nNTEPAX/gtSixJL8omIuXRwArFyBK6SoNFUhMS9FAczILAbTCFG3xJxisDCYwQXh\nIitHF0fTADEpvwiL8UBBuGKwKISHrhYuim6yX34JmitAIqhGcgEAEnJWfA==\n',"base64"),"zip").decode())$ $ wc -c booltable2.py 210 booltable2.py $ python3 booltable2.py Boolean Operators ------------------------ True and True is True True and False is False False and True is False False and False is False True or True is True True or False is True False or True is True False or False is False Not True is False Not False is True $ :) From robin at reportlab.com Wed Sep 27 09:55:37 2017 From: robin at reportlab.com (Robin Becker) Date: Wed, 27 Sep 2017 14:55:37 +0100 Subject: Even Older Man Yells At Whippersnappers In-Reply-To: References: <59bcb8da$0$16735$b1db1813$d948b532@news.astraweb.com> <87r2v6ge76.fsf@nightsong.com> <59be2a32$0$16759$b1db1813$d948b532@news.astraweb.com> <59be72a9$0$14955$b1db1813$d948b532@news.astraweb.com> <8760cgqdse.fsf@bsb.me.uk> <59c07683$0$14940$b1db1813$d948b532@news.astraweb.com> <59c0c23e$0$14961$b1db1813$d948b532@news.astraweb.com> <8e07350e-5841-448d-5d51-bf53cfab2058@kynesim.co.uk> Message-ID: On 20/09/2017 10:54, Chris Angelico wrote: ........ > > What, you take silicon that someone else created?! > > ChrisA > well I had germanium for flipflops and dekatron tubes with neon for counters never built anything digital with valves though -- Robin Becker From yoni at cocycles.com Wed Sep 27 09:58:45 2017 From: yoni at cocycles.com (yoni at cocycles.com) Date: Wed, 27 Sep 2017 06:58:45 -0700 (PDT) Subject: Sharing code between different projects? In-Reply-To: References: Message-ID: On Monday, August 13, 2012 at 7:53:32 PM UTC+3, andrea crotti wrote: > I am in the situation where I am working on different projects that > might potentially share a lot of code. > > I started to work on project A, then switched completely to project B > and in the transiction I copied over a lot of code with the > corresponding tests, and I started to modify it. > > Now it's time to work again on project A, but I don't want to copy > things over again. > > I would like to design a simple and nice way to share between projects, > where the things I want to share are simple but useful things as for > example: > > class TempDirectory: > """Create a temporary directory and cd to it on enter, cd back to > the original position and remove it on exit > """ > def __init__(self): > self.oldcwd = getcwd() > self.temp_dir = mkdtemp() > > def __enter__(self): > logger.debug("create and move to temp directory %s" % self.temp_dir) > return self.temp_dir > > def __exit__(self, type, value, traceback): > # I first have to move out > chdir(self.oldcwd) > logger.debug("removing the temporary directory and go back to > the original position %s" % self.temp_dir) > rmtree(self.temp_dir) > > > The problem is that there are functions/classes from many domains, so it > would not make much sense to create a real project, and the only name I > could give might be "utils or utilities".. > > In plus the moment the code is shared I must take care of versioning and > how to link different pieces together (we use perforce by the way). > > If then someone else except me will want to use these functions then of > course I'll have to be extra careful, designing really good API's and so > on, so I'm wondering where I should set the trade-off between ability to > share and burden to maintain.. > > Anyone has suggestions/real world experiences about this? I would try bit: https://github.com/teambit/bit Hope it helps. From darwinbin19 at gmail.com Wed Sep 27 10:10:18 2017 From: darwinbin19 at gmail.com (darwinbin19 at gmail.com) Date: Wed, 27 Sep 2017 07:10:18 -0700 (PDT) Subject: Pyhton Message-ID: Whats the reason that python is growing fast? From breamoreboy at gmail.com Wed Sep 27 10:27:15 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Wed, 27 Sep 2017 07:27:15 -0700 (PDT) Subject: Pyhton In-Reply-To: References: Message-ID: On Wednesday, September 27, 2017 at 3:10:30 PM UTC+1, darwi... at gmail.com wrote: > Whats the reason that python is growing fast? It would be growing faster but it is only the second best language in the world. Please see https://mail.python.org/pipermail/python-list/2002-November/141486.html -- Kindest regards. Mark Lawrence From m at funkyhat.org Wed Sep 27 10:38:51 2017 From: m at funkyhat.org (Matt Wheeler) Date: Wed, 27 Sep 2017 14:38:51 +0000 (UTC) Subject: Printing a Chunk Of Words In-Reply-To: References: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> <87k20myygb.fsf@bsb.me.uk> Message-ID: On Wed, 27 Sep 2017 at 13:58 Thomas Jollans wrote: > > Reproducing the original string exactly the best I've managed is 260: > > > > t,f,a,o,n='True','False','and','or','not' > > The Not is capitalized in the original string. > I guess you didn't try it? (or see `upper()` in the body of the `for` below) > l=[" Boolean Operators\n"+"-"*24] > > for x in [(l,p,r)for p in(a,o)for l in(t,f)for r > in(t,f)]+[(n,t),(n,f)]:x=' > > '.join(x);l+=[x[0].upper()+x[1:]+" is "+str(eval(x))] > > for i in 12,9,5,0:l.insert(i,'') > > print('\n'.join(l)) -- -- Matt Wheeler http://funkyh.at From irving.duran at gmail.com Wed Sep 27 11:32:40 2017 From: irving.duran at gmail.com (Irving Duran) Date: Wed, 27 Sep 2017 10:32:40 -0500 Subject: Pyhton In-Reply-To: References: Message-ID: Besides being easy to learn and develop, there is a large number of dev supporters. Which it makes it more compelling. Thank You, Irving Duran On Wed, Sep 27, 2017 at 9:27 AM, wrote: > On Wednesday, September 27, 2017 at 3:10:30 PM UTC+1, darwi... at gmail.com > wrote: > > Whats the reason that python is growing fast? > > It would be growing faster but it is only the second best language in the > world. Please see https://mail.python.org/pipermail/python-list/2002- > November/141486.html > > -- > Kindest regards. > > Mark Lawrence > -- > https://mail.python.org/mailman/listinfo/python-list > From leamhall at gmail.com Wed Sep 27 12:41:24 2017 From: leamhall at gmail.com (leam hall) Date: Wed, 27 Sep 2017 12:41:24 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On Sat, Sep 23, 2017 at 5:26 PM, Ned Batchelder wrote: > On 9/23/17 2:52 PM, Leam Hall wrote: > >> On 09/23/2017 02:40 PM, Terry Reedy wrote: >> >>> https://nedbatchelder.com//blog/201709/beginners_and_experts.html >>> >>> Great post. >>> >> >> Yup. Thanks for the link. I often have that "I bet > Fred> doesn't get frustrated." thing going. Nice to know Ned bangs his head >> now and again. :P >> >> > "Ow!" --me Hehe...I've been trying to figure out how to phrase a question. Knowing I'm not the only one who gets frustrated really helps. I'm trying to learn to be a programmer. I can look at a book and read basic code in a few languages but it would be unfair to hire myself out as a programmer. I'm just not yet worth what it costs to pay my bills. To move forward takes a plan and time bound goals. At least for us old folks; we only have so much time left. I want to avoid retirement and just work well until I keel over. I don't come from a CS background but as a Linux sysadmin. My current push is OOP. Grady Booch's book on Analysis and Design is great and I've got the GoF for right after that. I've been doing more testing but need to write more tests. Writing code and starting to work with others on that code as well. The question is, what should a person "know" when hiring out as a programmer? What is 'know" and what should be "known"? Specifically with Python. Thanks! Leam From larry.martell at gmail.com Wed Sep 27 12:48:36 2017 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 27 Sep 2017 12:48:36 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On Wed, Sep 27, 2017 at 12:41 PM, leam hall wrote: > The question is, what should a person "know" when hiring out as a > programmer? What is 'know" and what should be "known"? Specifically with > Python. Fake it till you make it! From tjol at tjol.eu Wed Sep 27 12:50:20 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 27 Sep 2017 18:50:20 +0200 Subject: Printing a Chunk Of Words In-Reply-To: References: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> <87k20myygb.fsf@bsb.me.uk> Message-ID: <1a5704b1-f8f9-6785-8e4c-dc25928ad3f1@tjol.eu> On 2017-09-27 16:38, Matt Wheeler wrote: > On Wed, 27 Sep 2017 at 13:58 Thomas Jollans wrote: > >>> Reproducing the original string exactly the best I've managed is 260: >>> >>> t,f,a,o,n='True','False','and','or','not' >> >> The Not is capitalized in the original string. >> > > I guess you didn't try it? (or see `upper()` in the body of the `for` below) Touch?. You're still missing some whitespace, though ;-) (like, I think, everybody else in this weird international obfuscated Python competition) > >> l=[" Boolean Operators\n"+"-"*24] >>> for x in [(l,p,r)for p in(a,o)for l in(t,f)for r >> in(t,f)]+[(n,t),(n,f)]:x=' >>> '.join(x);l+=[x[0].upper()+x[1:]+" is "+str(eval(x))] >>> for i in 12,9,5,0:l.insert(i,'') >>> print('\n'.join(l)) > From irmen at NOSPAM.xs4all.nl Wed Sep 27 14:03:04 2017 From: irmen at NOSPAM.xs4all.nl (Irmen de Jong) Date: Wed, 27 Sep 2017 20:03:04 +0200 Subject: auto installing dependencies with pip to run a python zip application ? In-Reply-To: References: <59caa0da$0$698$e4fe514c@news.xs4all.nl> <59cad948$0$829$e4fe514c@news.xs4all.nl> Message-ID: <59cbe7d8$0$801$e4fe514c@news.xs4all.nl> On 09/27/2017 09:50 AM, Paul Moore wrote: >>> What you could do is pip install your binary dependencies into a >>> directory in $TEMP using --target, then add that directory to >>> sys.path. Probably easier than building a full virtualenv. Bundle pip >>> with your app if you can't assume your users will have pip available. >> >> Interesting idea, although like this wouldn't I have to download the >> dependencies every time I launch my game? (unless I re-use the same >> temporary directory every time) > > Ah, I'd assumed that's what you were doing with the virtualenv, I > hadn't realised you were talking about a one-off setup step. Yeah, > re-using a temporary directory doesn't buy you much compared to using > a virtualenv (particularly if you can target versions of Python that > have the built in venv module). Well, I was planning on using a fixed name/location for the virtualenv. That way when you request pip to install the dependencies again at next launch, it will detect them already satisfied and not download/reinstall everything. I could even test for their existence first myself in my application (which is what I'm already doing now, to give the user a clear error message) and only invoke pip when a dependency is missing. -irmen From m at funkyhat.org Wed Sep 27 15:04:37 2017 From: m at funkyhat.org (Matt Wheeler) Date: Wed, 27 Sep 2017 19:04:37 +0000 (UTC) Subject: Printing a Chunk Of Words In-Reply-To: References: <3cac3838-f10b-4a76-96d2-8209c76b9157@googlegroups.com> <87k20myygb.fsf@bsb.me.uk> Message-ID: On Wed, 27 Sep 2017 at 14:48 Peter Otten <__peter__ at web.de> wrote: > > Reproducing the original string exactly the best I've managed is 260: > > That's a bit long, don't you think, as it can be beaten even by plain old > zipping: > ha! tbh yes It's longer than I was expecting to manage. $ cat booltable2.py > from codecs > > import*;print(decode(decode(b'eJzjUgABp/z8nNTEPAX/gtSixJL8omIuXRwArFyBK6SoNFUhMS9FAczILAbTCFG3xJxisDCYwQXh\nIitHF0fTADEpvwiL8UBBuGKwKISHrhYuim6yX34JmitAIqhGcgEAEnJWfA==\n',"base64"),"zip").decode())$ $ wc -c booltable2.py > 210 booltable2.py > Well, ok, but mine is at least parseable by a sufficiently masochistic human, though I suppose that was never given as a requirement :D (You could also shave off 4 more bytes by importing `decode` as `d` rather than your nice `import*` trick, because you call it 3 times) > [snip] > > :) > :D On Wed, 27 Sep 2017 at 17:50 Thomas Jollans wrote: > Touch?. > > You're still missing some whitespace, though ;-) (like, I think, > everybody else in this weird international obfuscated Python competition) > I guess you still didn't run it ;D (see the 2nd `for` statement). I diffed my output against the original, which is why I'm confident in the correctness of my solution ;) Actually I managed to shave off another byte by changing `l.insert(i,'')` to `l[i:i]=['']`, so now I'm on 259. I should probably stop now... -- -- Matt Wheeler http://funkyh.at From BILL_NOSPAM at whoknows.net Wed Sep 27 16:01:20 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Wed, 27 Sep 2017 16:01:20 -0400 Subject: Spacing conventions In-Reply-To: References: Message-ID: Thank you for all of the feedback provided! It was just what I was looking for. : ) I'm going to go back and read some of the links more carefully. Bill From flebber.crue at gmail.com Wed Sep 27 16:05:21 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 27 Sep 2017 13:05:21 -0700 (PDT) Subject: None is None but not working Message-ID: <23ef2e77-c2dc-4d78-8ac6-4d4042e78ab8@googlegroups.com> Hi I have got a successful script setup to rotate through dates and download json data from the url. As the api returns 200 whether successful I want to check if the file returned is not successful. when a file doesn't exist the api returns {'RaceDay': None, 'ErrorInfo': {'SystemId': 200, 'ErrorNo': 55013, 'DisplayMessage': 'File Not Found.', 'ContactSupport': False, 'SupportErrorReference': '200-55013'}, 'Success': False} When I call data = r.json() it says its type is None if it is not successful so I thought it easier to check that. However checking for None does not work the flow in my if else falls straight to else. for dates in fullUrl: r = requests.get(dates) data = r.json() if data is None: print("Nothing here") else: print(data["RaceDay"]) and I get output of None None {'MeetingDate': '2017-01- ... and so on. How can I actually get this to check? If i use type(data) I also get None. Cheers Sayth From guru at digitalfantasy.it Wed Sep 27 16:53:24 2017 From: guru at digitalfantasy.it (Daniele Forghieri) Date: Wed, 27 Sep 2017 22:53:24 +0200 Subject: None is None but not working In-Reply-To: <23ef2e77-c2dc-4d78-8ac6-4d4042e78ab8@googlegroups.com> References: <23ef2e77-c2dc-4d78-8ac6-4d4042e78ab8@googlegroups.com> Message-ID: Il 27/09/2017 22:05, Sayth Renshaw ha scritto: > Hi > > I have got a successful script setup to rotate through dates and download json data from the url. > > As the api returns 200 whether successful I want to check if the file returned is not successful. > > when a file doesn't exist the api returns > {'RaceDay': None, 'ErrorInfo': {'SystemId': 200, 'ErrorNo': 55013, 'DisplayMessage': 'File Not Found.', 'ContactSupport': False, 'SupportErrorReference': '200-55013'}, 'Success': False} ??? You got None on the member 'RaceDay' of the data, not on all the data. So you should check for something like: ??? if data['RaceDay'] is None: ??? ??? # Missing data ??? ??? .... ??? else: ??? ??? # ok, do what you need ??? ??? ... > When I call data = r.json() it says its type is None if it is not successful so I thought it easier to check that. > > However checking for None does not work the flow in my if else falls straight to else. > > for dates in fullUrl: > r = requests.get(dates) > data = r.json() > if data is None: > print("Nothing here") > else: > print(data["RaceDay"]) > > and I get output of > > None > None > {'MeetingDate': '2017-01- ... and so on. > > How can I actually get this to check? > > If i use type(data) I also get None. > > Cheers > > Sayth From ben+python at benfinney.id.au Wed Sep 27 17:09:11 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 28 Sep 2017 07:09:11 +1000 Subject: None is None but not working References: <23ef2e77-c2dc-4d78-8ac6-4d4042e78ab8@googlegroups.com> Message-ID: <85r2ur4zns.fsf@benfinney.id.au> Sayth Renshaw writes: > When I call data = r.json() it says its type is None if it is not > successful so I thought it easier to check that. Can you show the interactive session where you do that check? >>> data = r.json() >>> data is None True That's what I understand your statement to mean. Is that what you see, exactly? If not, please post the equivalent session. -- \ ?Two rules to success in life: 1. Don't tell people everything | `\ you know.? ?Sassan Tat | _o__) | Ben Finney From gherron at digipen.edu Wed Sep 27 17:09:57 2017 From: gherron at digipen.edu (Gary Herron) Date: Wed, 27 Sep 2017 14:09:57 -0700 Subject: None is None but not working In-Reply-To: <23ef2e77-c2dc-4d78-8ac6-4d4042e78ab8@googlegroups.com> References: <23ef2e77-c2dc-4d78-8ac6-4d4042e78ab8@googlegroups.com> Message-ID: <91f5f93f-7336-fd71-085f-82a1e1712ab5@digipen.edu> On 09/27/2017 01:05 PM, Sayth Renshaw wrote: > Hi > > I have got a successful script setup to rotate through dates and download json data from the url. > > As the api returns 200 whether successful I want to check if the file returned is not successful. > > when a file doesn't exist the api returns > {'RaceDay': None, 'ErrorInfo': {'SystemId': 200, 'ErrorNo': 55013, 'DisplayMessage': 'File Not Found.', 'ContactSupport': False, 'SupportErrorReference': '200-55013'}, 'Success': False} > > When I call data = r.json() it says its type is None if it is not successful so I thought it easier to check that. > > However checking for None does not work the flow in my if else falls straight to else. > > for dates in fullUrl: > r = requests.get(dates) > data = r.json() > if data is None: > print("Nothing here") > else: > print(data["RaceDay"]) Your data is not None, it's a full dictionary. However, data["RaceDay"] *is* None as shown in your output.? Thus your test should be: ??? if data["RaceDay"] is None: ... rather than ??? if data is None: ... > > and I get output of > > None > None > {'MeetingDate': '2017-01- ... and so on. > > How can I actually get this to check? > > If i use type(data) I also get None. > > Cheers > > Sayth -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 From rgaddi at highlandtechnology.invalid Wed Sep 27 18:55:58 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Wed, 27 Sep 2017 15:55:58 -0700 Subject: Real Programmers Write Docs Message-ID: Anyone have any good references on using Sphinx to generate a mix of autogenerated API docs and hand-written "Yeah, but this is what you DO with it" docs? Free is good but I'm happy to drop money on books if they're worthwhile. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From ned at nedbatchelder.com Wed Sep 27 19:15:17 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 27 Sep 2017 19:15:17 -0400 Subject: Real Programmers Write Docs In-Reply-To: References: Message-ID: On 9/27/17 6:55 PM, Rob Gaddi wrote: > Anyone have any good references on using Sphinx to generate a mix of > autogenerated API docs and hand-written "Yeah, but this is what you DO > with it" docs?? Free is good but I'm happy to drop money on books if > they're worthwhile. > I can offer you an example: the coverage.py docs are in Sphinx, and use both auto-generated and hand-written pages: https://github.com/nedbat/coveragepy/tree/master/doc?? I'm not sure what information you are looking for, maybe this will help? --Ned. From orgnut at yahoo.com Wed Sep 27 21:18:10 2017 From: orgnut at yahoo.com (Larry Hudson) Date: Wed, 27 Sep 2017 18:18:10 -0700 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On 09/27/2017 09:41 AM, leam hall wrote: > On Sat, Sep 23, 2017 at 5:26 PM, Ned Batchelder > wrote: [snip] > > The question is, what should a person "know" when hiring out as a > programmer? What is 'know" and what should be "known"? Specifically with > Python. > Hopefully NOT like this person... (Source: http://rinkworks.com/stupid/cs_misc.shtml There is no direct link to this item, it's about 2/3 the way down in a long web page...) Since I teach nights at a local community college, I get a lot of professional programmers in my classes upgrading their education. One student, who was one such person, attended every lecture and smiled and nodded and took notes. But he only turned in his first assignment. The results of his first test were horrid. Out of curiosity, I asked my wife, who barely knew how to turn a computer on much less program one, to take the test (which was mostly true/false and multiple choice questions). My wife scored higher than this guy. The semester's end came, and he flubbed his final, too. A few weeks later, I got a call from him complaining about his 'F'. I pointed out he hadn't turned in any of his assignments, and those counted 75% of the grade. "Did you hear me say something besides what the other students heard?" I asked. "Well, I thought my test grades would carry me," he replied. It had turned out his company had paid for him to take the course. Since he failed, it suddenly came to the attention of his employer that he didn't know how to program, and now his job was in jeopardy. As I hung up the phone, I mused that his company shouldn't fire him. It was a perfect match: a programmer who couldn't program and a company that couldn't figure out sooner that he couldn't. -- -=- Larry -=- From rosuav at gmail.com Wed Sep 27 21:34:55 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Sep 2017 11:34:55 +1000 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On Thu, Sep 28, 2017 at 11:18 AM, Larry Hudson via Python-list wrote: > > It had turned out his company had paid for him to take the course. Since he > failed, it suddenly came to the attention of his employer that he didn't > know how to program, and now his job was in jeopardy. As I hung up the > phone, I mused that his company shouldn't fire him. It was a perfect match: > a programmer who couldn't program and a company that couldn't figure out > sooner that he couldn't. > I had a coworker like that at my previous job. The boss basically was paying him to learn to code, and yet (for reasons which to this day I cannot fathom) let him make a lot of decisions about technology. Thus we used PHP and MySQL (okay, it could have been worse), with a multi-threaded daemon in addition to the actual web server (I take that back, it WAS worse). I had to fight uphill to convince my boss of the value of git ("why bother, I have daily backups for a week and then weekly backups for two years"), and even then, this coworker didn't commit or push until, well, pushed. Eventually he quit the company (rumour has it he was hoping we'd beg him to stay, since we were that short-handed), and I had to take over his code... and found it full of The Daily WTF level abominations. Heard of the "For-Case paradigm"? Check out this [1] old article if you're not familiar with it. Well, he gave me this thrilling variant (reconstructed from memory): $i=1; while ($i<3) { switch($i) {case 1: ... snip one set of validations $i=3; break; case 3: ... some more validation work $i=2; break; case 2: ... snip another set of validations $i=4; break; }} I don't remember the exact details, but it was something like this. It looked like the code just stepped straight through the switch block. So I stripped out the junk and just did the validations sequentially. And the code stopped working. Since I *had* been committing to git frequently, I checked out the previous version. It worked. I redid the simplification. It broke again. I stuck in some console output, and found that one of the blocks of code was actually getting skipped... and due to the compounding of two or three other bugs, valid input would get rejected by the validation that wasn't happening. I have no idea whether he intentionally removed part of the validation, or if he just never noticed that it wasn't running. It was a truly impressive piece of work. ChrisA [1] https://thedailywtf.com/articles/The_FOR-CASE_paradigm From dan at tombstonezero.net Wed Sep 27 21:45:01 2017 From: dan at tombstonezero.net (Dan Sommers) Date: Thu, 28 Sep 2017 01:45:01 +0000 (UTC) Subject: Beginners and experts (Batchelder blog post) References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On Wed, 27 Sep 2017 12:41:24 -0400, leam hall wrote: > The question is, what should a person "know" when hiring out as a > programmer? What is 'know" and what should be "known"? Specifically > with Python. The longer I claim to be a programmer, the more I discover how wide a net that is. Web sites, embedded systems, user interfaces (text and graphical), databases, communications protocols, applications programming, systems programming, real time systems, text processing, scientific computing, simulations, security, etc., etc., etc. And I stopped there only because I hope I've made my point and not because that's an exhaustive list. Some of it you'll know up front; it's a pretty boring job on which you learn nothing new. What must be known is how to produce a program that does what the customer says they want (note that they likely don't know what they need, only what they want, but that's a whole other ball of wax). You'll also have to know enough about the problem domain to converse with the customer to turn what will be a vague request into something tangible. I'm sure you already do this when it comes to automating your own tasks. If I'm hiring myself out as a plumber, I should know how to unclog drains; and install, repair, replace toilets, water heaters, and other plumbing fixtures (or whatever else a plumber might be called on to do). Ignore the question of licensing; it doesn't apply to programmers. It's the same whether you use Python, something else, or some combination. Wow, that's a lot more than I intended to write. I don't mean to be discouraging, only enlightening. We all started somewhere, and your background as a sysadmin puts you way ahead of a lot of future programmers. HTH, Dan From steve+python at pearwood.info Wed Sep 27 21:45:59 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 28 Sep 2017 11:45:59 +1000 Subject: Spacing conventions References: Message-ID: <59cc5459$0$14941$b1db1813$d948b532@news.astraweb.com> On Wed, 27 Sep 2017 05:50 pm, Bill wrote: [...] > If you are teaching beginning students, do you expect them to try to > follow these sorts of conventions? Yes, but not to the point of being a dick about it. It is better to learn good habits first, rather than to learn bad habits then unlearn them later. The PEP 8 spacing conventions are based on similar English and/or maths conventions. For instance, in English, you should never put a space before the colon. This is wrong : ... any more than you would put a space before a comma , or before the full stop at the end of the sentence . oR capitalise the *second* letter of the first word in a sentence . Yes, the rules are fundamentally arbitrary, but violating them makes your text harder to read, whether that text is English prose, source code, or mathematics. > Is it perfectly fine to let "taste" > guide you (I'm just trying to get a feel for the philosophy here)? To some degree. Consistency with common standards is a valuable thing, but its *your* code and if you want to write in an idiomatic style that gives everyone else a headache, go right ahead. Just don't expect me to contribute to it. One of Raymond Hettinger's videos talks about writing beautiful Python code, and how slavishly obeying PEP 8 is not really productive. I'll try to find a link later and post it. > I > also notice "break" and exception handling is used much more in Python > than in C++, for instance. I was taught "break" and "continue" led to > "unstructured code"--but that was a while back. That's weird. break and continue are perfectly structured. They are no more of an unstructured GOTO than are if...else, for or while. It is the nature of human beings to gravitate to extremes, rather than finding a happy medium. When the idea of structured programming was first introduced into the programming community used to BASIC and other unstructured languages, there was a tendency among many people to slavishly apply the principle that every function, or even block of code, must have exactly one entry point and one exit point. Of course enforcing one entry point is easy: few languages allow you to jump into the middle of a function, because that would be really bad. But having multiple exit points is not just harmless, but actually useful. Nevertheless, because of this overly strict, foolish insistence on a single exit to a block of code, some people prefer to write code like this: done = False result = None for i in range(0, 2**64): if not done: ... code here if condition: result = value done = True return result rather than the simpler code that violates the "one exit" rule: for i in range(0, 2**64): ... code here if condition: return value return None Similarly for break and continue. > I can still see their > use causing potential trouble in (really-long) real-world code. How so? Besides, if your code is "really long", you probably should factorise it into smaller, meaningful chunks. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From BILL_NOSPAM at whoknows.net Thu Sep 28 01:56:39 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Thu, 28 Sep 2017 01:56:39 -0400 Subject: Spacing conventions In-Reply-To: <59cc5459$0$14941$b1db1813$d948b532@news.astraweb.com> References: <59cc5459$0$14941$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > > Similarly for break and continue. > >> I can still see their >> use causing potential trouble in (really-long) real-world code. > How so? > > Besides, if your code is "really long", you probably should factorise it into > smaller, meaningful chunks. > I worked in maintenance programming. You got the hand you were dealt! And you weren't allowed to "improve" the code unless the customer contracted you to do so. I maintained for-loops (containing for-loops)... hundreds of lines long. Would you be searching for break or continue? : ) > From dieter at handshake.de Thu Sep 28 02:21:34 2017 From: dieter at handshake.de (dieter) Date: Thu, 28 Sep 2017 08:21:34 +0200 Subject: Sharing code between different projects? References: Message-ID: <87wp4jbaxd.fsf@handshake.de> > On Monday, August 13, 2012 at 7:53:32 PM UTC+3, andrea crotti wrote: >> I am in the situation where I am working on different projects that >> might potentially share a lot of code. >> >> I started to work on project A, then switched completely to project B >> and in the transiction I copied over a lot of code with the >> corresponding tests, and I started to modify it. >> >> Now it's time to work again on project A, but I don't want to copy >> things over again. I use so called "namespace packages" for this. Those are "virtual" packages "containing" a set of related "real" packages - individually manageable on PyPI. The "real" packages describe in their dependencies on which other packages they depend, among them (potentially) "friend" packages. An example is "dm.zope.rpc" and "dm.zope.rpc.wsdl_suds". In this case, "dm.zope.rpc" provides general rpc infrastructure for the web application framework Zope and implementations for some elementary rpc protocols and "dm.zipe.rpc.wsdl_suds" uses this infrastructure for the implementation of a WSDL based rpc protocol by means of "suds". From p.f.moore at gmail.com Thu Sep 28 03:40:34 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 28 Sep 2017 08:40:34 +0100 Subject: auto installing dependencies with pip to run a python zip application ? In-Reply-To: <59cbe7d8$0$801$e4fe514c@news.xs4all.nl> References: <59caa0da$0$698$e4fe514c@news.xs4all.nl> <59cad948$0$829$e4fe514c@news.xs4all.nl> <59cbe7d8$0$801$e4fe514c@news.xs4all.nl> Message-ID: Are you aware of pipsi? If you do `pipsi install somepackage` it creates a new virtualenv in ~/.local/.venvs, populates it with somepackage and its dependencies, and then puts the entry point scripts for somepackage into ~/.local/bin. It may be a useful way of delivering your program, rather than building the virtualenv management in yourself. (On the other hand "download this file and run it" is a much easier installation process than "install pipsi, do pipsi install myprogram, then run the program", so it may not suit your use case...) Paul On 27 September 2017 at 19:03, Irmen de Jong wrote: > On 09/27/2017 09:50 AM, Paul Moore wrote: > >>>> What you could do is pip install your binary dependencies into a >>>> directory in $TEMP using --target, then add that directory to >>>> sys.path. Probably easier than building a full virtualenv. Bundle pip >>>> with your app if you can't assume your users will have pip available. >>> >>> Interesting idea, although like this wouldn't I have to download the >>> dependencies every time I launch my game? (unless I re-use the same >>> temporary directory every time) >> >> Ah, I'd assumed that's what you were doing with the virtualenv, I >> hadn't realised you were talking about a one-off setup step. Yeah, >> re-using a temporary directory doesn't buy you much compared to using >> a virtualenv (particularly if you can target versions of Python that >> have the built in venv module). > > Well, I was planning on using a fixed name/location for the virtualenv. > That way when you request pip to install the dependencies again at next > launch, it will detect them already satisfied and not download/reinstall > everything. I could even test for their existence first myself in my > application (which is what I'm already doing now, to give the user a > clear error message) and only invoke pip when a dependency is missing. > > > -irmen > -- > https://mail.python.org/mailman/listinfo/python-list From p.f.moore at gmail.com Thu Sep 28 04:15:06 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 28 Sep 2017 09:15:06 +0100 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On 27 September 2017 at 17:41, leam hall wrote: > Hehe...I've been trying to figure out how to phrase a question. Knowing I'm > not the only one who gets frustrated really helps. > > I'm trying to learn to be a programmer. I can look at a book and read basic > code in a few languages but it would be unfair to hire myself out as a > programmer. I'm just not yet worth what it costs to pay my bills. You're already ahead of the game in wanting to be useful, rather than just knowing the jargon :-) However, I've always found that the biggest asset a programmer can have is the simple willingness to learn. "Programming" is far too broad a subject for anyone to know all about it, so being able (and willing!) to find things out, to look for and follow good practices, and to keep learning, is far more important than knowing the specifics of how to code a class definition. Most programmers work in teams, so you will likely be working with an existing code base for reference (even if you're not doing actual maintenance coding), so you'll have examples to work from anyway. > To move forward takes a plan and time bound goals. At least for us old > folks; we only have so much time left. I want to avoid retirement and just > work well until I keel over. > > I don't come from a CS background but as a Linux sysadmin. My current push > is OOP. Grady Booch's book on Analysis and Design is great and I've got the > GoF for right after that. I've been doing more testing but need to write > more tests. Writing code and starting to work with others on that code as > well. I haven't read Booch, but I've heard good things about it. The GoF is good, but a lot of the problem's it's addressing aren't really issues in Python. So be prepared to find that the solutions look a bit over-engineered from a Python perspective. The ideas are really useful, though. Keep in mind that in Python, OOP is just one option of many - it's a very useful approach for many problems, but it's not as all-embracing as people with a Java or C# background imply. In particular, Python uses a lot less subclassing than those languages (because duck typing is often more flexible). > The question is, what should a person "know" when hiring out as a > programmer? What is 'know" and what should be "known"? Specifically with > Python. With Python, I'd say that an appreciation of the available libraries is key - both what's in the stdlib, and what's available from PyPI. That's not to say you should memorise the standard library, but rather cultivate an approach of "hmm, I'm pretty sure I remember there being a library for that" and going to look. The best way of getting this is to actually work with code - you can start with doing coding projects of your own (it's *always* a good exercise to have a problem that interests you, and work on coding it - no matter what it is, you'll learn more about understanding requirements, testing, bug fixing, and practical programming by working on a project you care about than you'll ever get reading books) and/or you can look at existing open source projects that you're interested in, and offer help (there's always a bug tracker, and typically some simpler items - and you'll learn a lot from interacting with a larger project). Hope this helps, Paul From p.f.moore at gmail.com Thu Sep 28 04:51:39 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 28 Sep 2017 09:51:39 +0100 Subject: Spacing conventions In-Reply-To: References: <59cc5459$0$14941$b1db1813$d948b532@news.astraweb.com> Message-ID: On 28 September 2017 at 06:56, Bill wrote: > Steve D'Aprano wrote: >> >> >> Similarly for break and continue. >> >>> I can still see their >>> use causing potential trouble in (really-long) real-world code. >> >> How so? >> >> Besides, if your code is "really long", you probably should factorise it >> into >> smaller, meaningful chunks. >> > > I worked in maintenance programming. You got the hand you were dealt! And > you weren't allowed to "improve" the code unless the customer contracted you > to do so. I maintained for-loops (containing for-loops)... hundreds of > lines long. Would you be searching for break or > continue? : ) I also work in maintenance. Agreed 100% that the sort of code you deal with is a nightmare. But the problem with that code is *not* break/continue, but the lack of structure and the fact that the code isn't properly broken into meaningful subunits. I'd rather not search for break/continue in such code, sure, but that's missing the point entirely. "Don't use break/continue in appallingly bad code" doesn't generalise to "don't use break/continue", but rather to "don't write appallingly bad code" :-) Paul From flebber.crue at gmail.com Thu Sep 28 05:35:30 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Thu, 28 Sep 2017 02:35:30 -0700 (PDT) Subject: None is None but not working In-Reply-To: <23ef2e77-c2dc-4d78-8ac6-4d4042e78ab8@googlegroups.com> References: <23ef2e77-c2dc-4d78-8ac6-4d4042e78ab8@googlegroups.com> Message-ID: Thank you it was data["RaceDay"] that was needed. ata = r.json() if data["RaceDay"] is None: print("Nothing here") else: print(data["RaceDay"]) Nothing here Nothing here Nothing here {'MeetingDate': '2017-01-11T00:00:00', ..... Thanks Sayth From bc at freeuk.com Thu Sep 28 07:12:10 2017 From: bc at freeuk.com (bartc) Date: Thu, 28 Sep 2017 12:12:10 +0100 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On 28/09/2017 03:33, Stefan Ram wrote: > Larry Hudson writes: >> Hopefully NOT like this person... >> >> Since I teach nights at a local community college > .... >> a programmer who couldn't program > > It is not clear what ?this person? refers to: > > Do you hope one is not like that teacher who > publicly is shaming one of his students, though > without actually giving the name of the student. > > Or do you hope one is not like that student who > did not turn in the assignments? > > The fact that programmers can't program is > known since the invention of the "FizzBuzz" > programmer test. But in the case of the student, > one actually can't know for sure whether he only > had problems with the /upgrade/ of his education, > but still can program in his everyday job. > > So, what was the question? Quoted from earlier in > the same thread: > > |The question is, what should a person "know" when hiring out > |as a programmer? What is 'know" and what should be "known"? > |Specifically with Python. > > Some areas of knowledge follow, a programmer should not be > ignorant in all of them: I can probably manage the following, even if I hate some of it or some might be advanced: > - writing FizzBuzz > - writing GUI software [My own] (Writing a GUI system or using one? I've done both and try and avoid GUI completely if possible.) > - writing software to analyze text files > - writing software to generate images from data > - writing software to analyze images > - how to program operating systems via system calls > - algorithms and datastructures > - numerical mathematics > - how to write a recursive descent parser > - maths (how to transform to polar coordinates or > what the use of a fourier transformation is) And I have little interest in most of this lot (my eyes glaze over just reading some of these): > - writing GUI software [Other people's] > - writing software to analyze data bases > - writing user interfaces for data bases > - how to use operating systems > - how to administer a computer > - how to use the command languages of operating systems > - how to use an editor well (e.g., vim or emacs) > - how to use UN*X tools (grep, uniq, sed, ...) > - regular expressions > - a source management tool (like git) > - design patterns > - design by contract > - OOA/OOD > - the most important libraries for Python (standard and other) > - data base design / normalization > - style (e.g. "Clean Code" by Robert Martin, pep 8, ...) > - refactors > - software engineering > - being able to read and write EBNF > - software-project managemet (e.g. Agile, "Scrum") > - computer science (complexity, NP, grammars, ...) > - test (e.g., unit test), TDD > - programming interviews (there are many books about this topic!) > - Using a real Newsreader (not Google Groups) > - common algorithms/heuristics for global optimization > - common types of statistical analyses and neural networks It seems the first group is more pure coding (and fun, a lot of it), and the second is the usual lot of tools and technologies that programmers seems to have to know about these days (and not so much fun). -- bartc From steve+python at pearwood.info Thu Sep 28 07:31:15 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 28 Sep 2017 21:31:15 +1000 Subject: Beginners and experts (Batchelder blog post) References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: <59ccdd85$0$14964$b1db1813$d948b532@news.astraweb.com> On Thu, 28 Sep 2017 09:12 pm, bartc wrote: > And I have little interest in most of this lot (my eyes glaze over just > reading some of these): > > > - how to use operating systems You've never used a system call? Written to a file? Moved the mouse? > > - how to use an editor well (e.g., vim or emacs) You have no interest in using your editor well? > > - style (e.g. "Clean Code" by Robert Martin, pep 8, ...) Until now, I thought that people who wrote crappy code did so because they didn't know any better. This is the first time I've seen somebody state publicly that they have no interest in writing clean code. > > - test (e.g., unit test), TDD You don't test your code? I suppose that makes it a lot easier to program. Just mash down on the keyboard with both hands, and say that the code is done and working correctly, and move on to the next project. *wink* -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From joel.goldstick at gmail.com Thu Sep 28 07:52:05 2017 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 28 Sep 2017 07:52:05 -0400 Subject: Boolean Expressions In-Reply-To: <38d05c34-9b18-44e2-a162-e428088c723e@googlegroups.com> References: <28a719f7-0a85-462b-8125-c7aab5c17c21@googlegroups.com> <20170927050115.GA52149@cskk.homeip.net> <38d05c34-9b18-44e2-a162-e428088c723e@googlegroups.com> Message-ID: On Wed, Sep 27, 2017 at 5:21 AM, Cai Gengyang wrote: > On Wednesday, September 27, 2017 at 1:01:50 PM UTC+8, Cameron Simpson > wrote: > > On 26Sep2017 20:55, Cai Gengyang wrote: > > >On Wednesday, September 27, 2017 at 6:45:00 AM UTC+8, Cameron Simpson > wrote: > > >> On 26Sep2017 14:43, Cai Gengyang wrote: > > >> >C) Set bool_three equal to the result of > > >> >19 % 4 != 300 / 10 / 10 and False > > >> > > > >> 19 % 4 = 3 which is equal to 300 / 10 / 10 = 3, hence the first term > is > > >> False. Entire expression is then equal to True, because False and > False = > > >> True > > >> > > >> Entire expression is False because the left hand side is False. > > > > > >Am I missing something here ? 19 % 4 = 19 modulo 4 equals to 3 right ? > which > > >equals the right hand side , hence first term is True > > > > But the test is for "!=", not "==". So False. > > > > Cheers, > > Cameron Simpson (formerly cs at zip.com.au) > > Right ... I didn't see the ' =! ' > -- > You didn't see the '!=' -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From neilc at norwich.edu Thu Sep 28 08:14:08 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Thu, 28 Sep 2017 12:14:08 +0000 (UTC) Subject: OT: Drain specialist Was: Beginners and experts References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On 2017-09-28, Dan Sommers wrote: > If I'm hiring myself out as a plumber, I should know how to unclog > drains; OT: I recommend hiring a drain specialist, *not* a plumber for this particular job. Asking a plumber to clear a drain would be kinda like hiring a whiz-bang C programmer to configure your email server--it isn't that he or she *can't* do it... -- Neil Cerutti From mal at europython.eu Thu Sep 28 08:15:43 2017 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 28 Sep 2017 14:15:43 +0200 Subject: EuroPython 2017: Videos for Monday available online Message-ID: We are pleased to announce the first batch of cut videos for EuroPython 2017. To see the videos, please head over to our EuroPython YouTube channel and select the ?EuroPython 2017? playlist: * EuroPython 2017 Videos * http://europython.tv/ You'll also find our brand new teaser video for the conference: https://www.youtube.com/watch?v=OCHrzW-R3QI In the coming weeks, we will release the other videos, in batches of one conference day per week. Enjoy, -- EuroPython 2017 Team http://ep2017.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/913375334950690816 Thanks. From alister.ware at ntlworld.com Thu Sep 28 08:21:18 2017 From: alister.ware at ntlworld.com (alister) Date: Thu, 28 Sep 2017 12:21:18 GMT Subject: Beginners and experts (Batchelder blog post) References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: <2P5zB.1581163$8M.376042@fx47.am4> On Wed, 27 Sep 2017 18:18:10 -0700, Larry Hudson wrote: > On 09/27/2017 09:41 AM, leam hall wrote: >> On Sat, Sep 23, 2017 at 5:26 PM, Ned Batchelder >> wrote: > [snip] >> >> The question is, what should a person "know" when hiring out as a >> programmer? What is 'know" and what should be "known"? Specifically >> with Python. >> >> > Hopefully NOT like this person... > (Source: http://rinkworks.com/stupid/cs_misc.shtml There is no direct > link to this item, it's about 2/3 the way down in a long web page...) > > > Since I teach nights at a local community college, I get a lot of > professional programmers in my classes upgrading their education. One > student, who was one such person, attended every lecture and smiled and > nodded and took notes. But he only turned in his first assignment. The > results of his first test were horrid. Out of curiosity, I asked my > wife, who barely knew how to turn a computer on much less program one, > to take the test (which was mostly true/false and multiple choice > questions). My wife scored higher than this guy. > > The semester's end came, and he flubbed his final, too. A few weeks > later, I got a call from him complaining about his 'F'. I pointed out he > hadn't turned in any of his assignments, and those counted 75% of the > grade. > > "Did you hear me say something besides what the other students heard?" I > asked. > > "Well, I thought my test grades would carry me," he replied. > > It had turned out his company had paid for him to take the course. Since > he failed, it suddenly came to the attention of his employer that he > didn't know how to program, and now his job was in jeopardy. As I hung > up the phone, I mused that his company shouldn't fire him. It was a > perfect match: a programmer who couldn't program and a company that > couldn't figure out sooner that he couldn't. > the whole page seems to be full of "look how dumb this user is because they do no automatically know things that I had to learn" -- After they got rid of capital punishment, they had to hang twice as many people as before. From bc at freeuk.com Thu Sep 28 09:17:54 2017 From: bc at freeuk.com (bartc) Date: Thu, 28 Sep 2017 14:17:54 +0100 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: <59ccdd85$0$14964$b1db1813$d948b532@news.astraweb.com> References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> <59ccdd85$0$14964$b1db1813$d948b532@news.astraweb.com> Message-ID: <4E6zB.1304537$7a2.58991@fx26.am4> On 28/09/2017 12:31, Steve D'Aprano wrote: > On Thu, 28 Sep 2017 09:12 pm, bartc wrote: > >> And I have little interest in most of this lot (my eyes glaze over just >> reading some of these): >> >> > - how to use operating systems > > You've never used a system call? Written to a file? Moved the mouse? Wasn't that more this option: - how to program operating systems via system calls Which was in my first group. Using an OS, I just do the minimum necessary and don't get involved in much else. (In my first phase as a programmer, there were personnel whose job it was to do that. In the next phase, with microprocessors, there /was/ no operating system! Bliss. That phase didn't last long, but fortunately those OSes (MSDOS and the like) didn't do much so didn't get in the way either.) > >> > - how to use an editor well (e.g., vim or emacs) > > You have no interest in using your editor well? I use my own editor as much as possible. That doesn't have any elaborate features that it is necessary to 'learn'. > >> > - style (e.g. "Clean Code" by Robert Martin, pep 8, ...) > > Until now, I thought that people who wrote crappy code did so because they > didn't know any better. This is the first time I've seen somebody state > publicly that they have no interest in writing clean code. I meant I have no interest in reading books about it or someone else's opinion. I have my own ideas of what is clean code and what isn't. > >> > - test (e.g., unit test), TDD > > You don't test your code? I assume this meant formal methods of testing. > I suppose that makes it a lot easier to program. Just mash down on the keyboard > with both hands, and say that the code is done and working correctly, and move > on to the next project. > > *wink* Actually I used to like using random methods (Monte Carlo) to solve problems. That doesn't scale well however, at some point you have to properly think through a solution. -- bartc From neilc at norwich.edu Thu Sep 28 10:33:06 2017 From: neilc at norwich.edu (Neil Cerutti) Date: Thu, 28 Sep 2017 14:33:06 +0000 (UTC) Subject: Beginners and experts (Batchelder blog post) References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> <59ccdd85$0$14964$b1db1813$d948b532@news.astraweb.com> <4E6zB.1304537$7a2.58991@fx26.am4> Message-ID: On 2017-09-28, bartc wrote: > On 28/09/2017 12:31, Steve D'Aprano wrote: >> Until now, I thought that people who wrote crappy code did so >> because they didn't know any better. This is the first time >> I've seen somebody state publicly that they have no interest >> in writing clean code. > > I meant I have no interest in reading books about it or someone > else's opinion. I have my own ideas of what is clean code and > what isn't. The world contains many programmers with more experience than one's-self, and some of them are good at explaining what they know in a comprehensible and entertaining way. I believe you will benefit from and even enjoy some of the literature. Here's a recent favorite: "The Pragmatic Programmer", Andrew Hunt and David Thomas. ISBN-13: 978-0201616224 -- Neil Cerutti From tjreedy at udel.edu Thu Sep 28 12:11:17 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Sep 2017 12:11:17 -0400 Subject: EuroPython 2017: Videos for Monday available online In-Reply-To: References: Message-ID: On 9/28/2017 8:15 AM, M.-A. Lemburg wrote: > We are pleased to announce the first batch of cut videos for EuroPython > 2017. > > To see the videos, please head over to our EuroPython YouTube channel > and select the ?EuroPython 2017? playlist: > > > * EuroPython 2017 Videos * > > http://europython.tv/ Mark-Andre, I clicked the link, which forwards to https://www.youtube.com/c/EuroPythonConference and clicked the EuroPython 2017 playlist, and 90% of the 163 videos are unviewable [Private video]s. -- Terry Jan Reedy From mal at europython.eu Thu Sep 28 12:25:31 2017 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 28 Sep 2017 18:25:31 +0200 Subject: EuroPython 2017: Videos for Monday available online In-Reply-To: References: Message-ID: <2536a9fe-0e9d-3d35-b3f4-bd16f1a8e072@europython.eu> On 28.09.2017 18:11, Terry Reedy wrote: > On 9/28/2017 8:15 AM, M.-A. Lemburg wrote: >> We are pleased to announce the first batch of cut videos for EuroPython >> 2017. >> >> To see the videos, please head over to our EuroPython YouTube channel >> and select the ?EuroPython 2017? playlist: >> >> >> * EuroPython 2017 Videos * >> >> http://europython.tv/ > > Mark-Andre, I clicked the link, which forwards to > https://www.youtube.com/c/EuroPythonConference > and clicked the EuroPython 2017 playlist, and 90% of the 163 videos are > unviewable [Private video]s. Yes... we will publish them one conference day at a time over next few weeks :-) """ In the coming weeks, we will release the other videos, in batches of one conference day per week. """ Perhaps we ought to remove them from the playlist to not cause confusion. Thanks, -- Marc-Andre Lemburg EuroPython Society Chair http://www.europython-society.org/ http://www.malemburg.com/ From mal at europython.eu Thu Sep 28 12:33:06 2017 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 28 Sep 2017 18:33:06 +0200 Subject: EuroPython 2017: Videos for Monday available online In-Reply-To: <2536a9fe-0e9d-3d35-b3f4-bd16f1a8e072@europython.eu> References: <2536a9fe-0e9d-3d35-b3f4-bd16f1a8e072@europython.eu> Message-ID: <220ad005-ec5d-25e8-825f-492ea66cb024@europython.eu> On 28.09.2017 18:25, M.-A. Lemburg wrote: > On 28.09.2017 18:11, Terry Reedy wrote: >> On 9/28/2017 8:15 AM, M.-A. Lemburg wrote: >>> We are pleased to announce the first batch of cut videos for EuroPython >>> 2017. >>> >>> To see the videos, please head over to our EuroPython YouTube channel >>> and select the ?EuroPython 2017? playlist: >>> >>> >>> * EuroPython 2017 Videos * >>> >>> http://europython.tv/ >> >> Mark-Andre, I clicked the link, which forwards to >> https://www.youtube.com/c/EuroPythonConference >> and clicked the EuroPython 2017 playlist, and 90% of the 163 videos are >> unviewable [Private video]s. > > Yes... we will publish them one conference day at a time over next > few weeks :-) > > """ > In the coming weeks, we will release the other videos, in batches of > one conference day per week. > """ > > Perhaps we ought to remove them from the playlist to not cause > confusion. This doesn't appear to be easily possible due to changes in the YT UI. We've now set the playlist order to show the private videos at the end as work-around. Next time, we'll add the video only when releasing them. Thanks, -- Marc-Andre Lemburg EuroPython Society Chair http://www.europython-society.org/ http://www.malemburg.com/ From rgaddi at highlandtechnology.invalid Thu Sep 28 13:36:50 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Thu, 28 Sep 2017 10:36:50 -0700 Subject: Real Programmers Write Docs In-Reply-To: References: Message-ID: On 09/27/2017 04:15 PM, Ned Batchelder wrote: > On 9/27/17 6:55 PM, Rob Gaddi wrote: >> Anyone have any good references on using Sphinx to generate a mix of >> autogenerated API docs and hand-written "Yeah, but this is what you DO >> with it" docs?? Free is good but I'm happy to drop money on books if >> they're worthwhile. >> > > I can offer you an example: the coverage.py docs are in Sphinx, and use > both auto-generated and hand-written pages: > https://github.com/nedbat/coveragepy/tree/master/doc?? I'm not sure what > information you are looking for, maybe this will help? > > --Ned. Helps quite a bit, thanks Ned. Basically I'm looking for a good example on structuring this sort of thing to keep it from spiraling out of control. Looks like the big trick is to rely on hand-written structure around autoclass calls rather than letting automodule generate big walls of text. PySerial was my other example, and has gone much the same route. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From ofekmeister at gmail.com Thu Sep 28 14:01:40 2017 From: ofekmeister at gmail.com (ofekmeister at gmail.com) Date: Thu, 28 Sep 2017 11:01:40 -0700 (PDT) Subject: Hatch - A modern project, package, and virtual env manager In-Reply-To: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> References: <8bfb4f83-2ade-4213-a49a-5e9db25d0360@googlegroups.com> Message-ID: Hatch 0.20.0 features easy cross-platform Conda installation and interactive project creation! https://github.com/ofek/hatch/blob/master/HISTORY.rst#0200 From leamhall at gmail.com Thu Sep 28 14:56:43 2017 From: leamhall at gmail.com (Leam Hall) Date: Thu, 28 Sep 2017 14:56:43 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: <5f8qscl1d542suhctms8fubpgnt568i172@4ax.com> References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> <5f8qscl1d542suhctms8fubpgnt568i172@4ax.com> Message-ID: My question has received several helpful responses, thanks! On 09/28/2017 01:01 PM, Dennis Lee Bieber wrote: > On Wed, 27 Sep 2017 12:41:24 -0400, leam hall > declaimed the following: > "Programmer"... or "Software Engineer"? > > I haven't kept up on "job titles" but for my history, "programmer" is > an entry level position, just a few steps up from "data entry operator" > (aka "keypunch operator" -- to show my age) "Person who automates routine tasks". I used to get asked for MAC addresses. I was playing with TCL at the time and it had a built in webserver sort of thing. The boxes were Solaris. Made a cron job to run Explorer on the servers and another to collate them to a node with the TCL webserver. Gave the Network team the URL. I'll show my age; 5 bit ASCII punched tape and actual ferrite core memory. :P > As a "programmer" (in my archaic world): be fluent in the language and > core of the runtime (though perhaps not a master -- I still don't get > Python's decorators and meta-class concepts; my uses haven't needed them). > Be able to read language agnostic requirement/design documentation and > translate to the language in question. At this level, knowledge of the > problem domain is probably not needed. At the higher levels, the language > begins to be irrelevant, but more knowledge of the problem domain becomes > important -- the difference between designing/coding a web-based > store-front (HTTP/HTML, database, security) vs number-crunching image > streams from space probes... > > Afraid I've likely just tossed it back to you -- what really is your > goal? As an introvert with a speech impediment I live by "Don't call me, I won't call you." Well, okay, yes. I did to Toastmasters and can shine at an interview. Still, day to day I prefer to create solutions that solve problems and answer questions before they are asked so no one asks me. I know a little Networking, Database, Systems Engineering, Project Management, Security, large datacenter, and other cool buzzwords to easily find a job doing Linux system admin. What I want to move away from is doing now what I was doing 10-15 years ago. A couple years ago I was back into C. A RHEL bug came up and management needed to understand the severity of the issue. I was able to read the reports, dig through the kernel code, and explain the issues and risks to MBA and PM types. I'm not about to represent myself as a C programmer but I can follow #include files. One place brought on Unix people and your first day was split between the Eng team lead and the Ops team lead. They would decide which you were more suited for. The Eng team lead wrote Perl and asked me to explain some of their code. I did and also pointed out a bug. Seems I was a better fit for the Ops team. :P My short term goals are to use Python to get better at OOP coding and to automate in Python stuff that might work in shell/awk but are more fun in python. To that end I'm reading Booch, just ordered an old copy of the Python Cookbook, and am coding a game/fiction tool to help me keep track of characters. It is often said to learn a language you grab the basics and then join a project. I'm happy to contribute to open source projects but the learning curve to "useful" has always been steep for me. There's gap between reading "Learning {language}" and contributing code. Python is very useful because all my RHEL boxes have it installed. If I build a tool I know it will be able to run. While I enjoy Ruby more, it's not on the servers and it ain't going on the servers. I need to be useful to keep getting paid. Due to developer count the ability to instigate a python project is easier than a non-rails ruby project so I can build my "software engineering team" skills as well. I appreciate your guidance and feedback; keep it coming! Leam From leamhall at gmail.com Thu Sep 28 15:03:44 2017 From: leamhall at gmail.com (Leam Hall) Date: Thu, 28 Sep 2017 15:03:44 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: <017116ed-00bd-d79f-2002-1e731507040e@gmail.com> On 09/28/2017 07:35 AM, Stefan Ram wrote: > But remember that paid programmers usually do not "code", > in the sense of "write a program from scratch". Most of the > work is maintenance programming, where an important part of > the job is to read and understand a piece of code. > Coding from scratch also happens, it just less common. > > (So that would be a reasonable interview test: Being able > to understand a piece of given code and do some requested > modification to it.) Another Perl story. I used to love Perl and then got to the point where trying to code in it made me physically nauseous. Not sure why. Guy had written a perl based time tracker for our contractor team. We'd enter tasks done and it would give a text based output to send to mgmt. Of course the guy hadn't planned on leaving after a few months and his program stored data by date but didn't separate by year. So I had to go figure out what it was doing since he was using a perl specific data archiver. Eventually just wound up blowing away the data store so each year was new. Told others how to handle it as I didn't want to do more perl and wasn't good enough at anything to replicate it all myself. Leam From irmen at NOSPAM.xs4all.nl Thu Sep 28 15:17:07 2017 From: irmen at NOSPAM.xs4all.nl (Irmen de Jong) Date: Thu, 28 Sep 2017 21:17:07 +0200 Subject: auto installing dependencies with pip to run a python zip application ? In-Reply-To: References: <59caa0da$0$698$e4fe514c@news.xs4all.nl> <59cad948$0$829$e4fe514c@news.xs4all.nl> <59cbe7d8$0$801$e4fe514c@news.xs4all.nl> Message-ID: <59cd4ab3$0$696$e4fe514c@news.xs4all.nl> On 09/28/2017 09:40 AM, Paul Moore wrote: > Are you aware of pipsi? If you do `pipsi install somepackage` it > creates a new virtualenv in ~/.local/.venvs, populates it with > somepackage and its dependencies, and then puts the entry point > scripts for somepackage into ~/.local/bin. It may be a useful way of > delivering your program, rather than building the virtualenv > management in yourself. No I wasn't aware of this tool, thanks for sharing. It's not what I am looking for but it's always nice to know of some alternatives Irmen From leamhall at gmail.com Thu Sep 28 15:35:36 2017 From: leamhall at gmail.com (Leam Hall) Date: Thu, 28 Sep 2017 15:35:36 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On 09/28/2017 04:15 AM, Paul Moore wrote: > With Python, I'd say that an appreciation of the available libraries > is key - both what's in the stdlib, and what's available from PyPI. > That's not to say you should memorise the standard library, but rather > cultivate an approach of "hmm, I'm pretty sure I remember there being > a library for that" and going to look. The best way of getting this is > to actually work with code - you can start with doing coding projects > of your own (it's *always* a good exercise to have a problem that > interests you, and work on coding it - no matter what it is, you'll > learn more about understanding requirements, testing, bug fixing, and > practical programming by working on a project you care about than > you'll ever get reading books) and/or you can look at existing open > source projects that you're interested in, and offer help (there's > always a bug tracker, and typically some simpler items - and you'll > learn a lot from interacting with a larger project). When I first started in Unix/Linux there was a group called SAGE. They had a list of tasks a system admin was expected to be able to do and they sorted the list by "Junior", "Senior", or somesuch. I started at the bottom of the list and worked my way up. One useful thing was to make a sorted list of commands in /usr/bin, /bin, /usr/sbin, and /sbin, and then read the first bit of the man page that showed what the command did. Fun stuff. Leam From BILL_NOSPAM at whoknows.net Thu Sep 28 15:45:14 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Thu, 28 Sep 2017 15:45:14 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: Paul Moore wrote: > On 27 September 2017 at 17:41, leam hall wrote: >> Hehe...I've been trying to figure out how to phrase a question. Knowing I'm >> not the only one who gets frustrated really helps. >> >> I'm trying to learn to be a programmer. I can look at a book and read basic >> code in a few languages but it would be unfair to hire myself out as a >> programmer. I'm just not yet worth what it costs to pay my bills. > You're already ahead of the game in wanting to be useful, rather than > just knowing the jargon :-) However, I've always found that the > biggest asset a programmer can have is the simple willingness to > learn. I basically agree with what has been posted. I just wanted to mention a couple things that separates beginners and non-beginners. One is "how long it takes to identify and fix an error"--even a syntax error. And that is a skill which is acquired with some practice, maybe more "some" than anyone likes. Another critical skill is the ability to write good documentation--from program requirements, on down. Another is to know what is means to "test". Another is to have some familiarity with the UML. Skills in 3 of these 4 area might be assisted by reading about software engineering. So after you have those skills, then, perhaps, you can think about "interviewing"--of course a degree will help. As always, your mileage may vary... It IS True that you don't have to wait until you "know everything"--most of use will never get there. From rosuav at gmail.com Thu Sep 28 15:58:57 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Sep 2017 05:58:57 +1000 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On Fri, Sep 29, 2017 at 5:45 AM, Bill wrote: > Paul Moore wrote: >> >> On 27 September 2017 at 17:41, leam hall wrote: >>> >>> Hehe...I've been trying to figure out how to phrase a question. Knowing >>> I'm >>> not the only one who gets frustrated really helps. >>> >>> I'm trying to learn to be a programmer. I can look at a book and read >>> basic >>> code in a few languages but it would be unfair to hire myself out as a >>> programmer. I'm just not yet worth what it costs to pay my bills. >> >> You're already ahead of the game in wanting to be useful, rather than >> just knowing the jargon :-) However, I've always found that the >> biggest asset a programmer can have is the simple willingness to >> learn. > > > I basically agree with what has been posted. I just wanted to mention a > couple things that separates beginners and non-beginners. One is "how long > it takes to identify and fix an error"--even a syntax error. And that is a > skill which is acquired with some practice, maybe more "some" than anyone > likes. Be careful with this one. For anything other than trivial errors (and even for some trivial errors), finding the bug is basically searching through a problem space of all things that could potentially cause this symptom. A novice could accidentally stumble onto the right solution to a tricky bug, or an expert could search a thousand other things and only get to the true cause after a long time. So while you're partly correct in saying "how long", you can't just put someone on the clock and say "if you find the bug in less than five minutes, you're hired". Ultimately, the only person who can truly evaluate a programmer's skill is another programmer, usually by watching the candidate go through this sort of debugging work. But yeah, broadly speaking, an experienced programmer can usually debug something more quickly than a novice can. On average. ChrisA From roel at roelschroeven.net Thu Sep 28 16:42:59 2017 From: roel at roelschroeven.net (Roel Schroeven) Date: Thu, 28 Sep 2017 22:42:59 +0200 Subject: Spacing conventions In-Reply-To: <59cc5459$0$14941$b1db1813$d948b532@news.astraweb.com> References: <59cc5459$0$14941$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano schreef op 28/09/2017 3:45: > One of Raymond Hettinger's videos talks about writing beautiful Python code, and > how slavishly obeying PEP 8 is not really productive. I'll try to find a link > later and post it. That would be Raymond Hettinger - Beyond PEP 8 -- Best practices for beautiful intelligible code - PyCon 2015 https://www.youtube.com/watch?v=wf-BqAjZb8M probably. Or otherwise maybe Transforming Code into Beautiful, Idiomatic Python https://www.youtube.com/watch?v=OSGv2VnC0go Both very interesting, though I enjoyed the first one more. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From BILL_NOSPAM at whoknows.net Thu Sep 28 16:59:48 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Thu, 28 Sep 2017 16:59:48 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: Chris Angelico wrote: > On Fri, Sep 29, 2017 at 5:45 AM, Bill wrote: >> Paul Moore wrote: >>> On 27 September 2017 at 17:41, leam hall wrote: >>>> Hehe...I've been trying to figure out how to phrase a question. Knowing >>>> I'm >>>> not the only one who gets frustrated really helps. >>>> >>>> I'm trying to learn to be a programmer. I can look at a book and read >>>> basic >>>> code in a few languages but it would be unfair to hire myself out as a >>>> programmer. I'm just not yet worth what it costs to pay my bills. >>> You're already ahead of the game in wanting to be useful, rather than >>> just knowing the jargon :-) However, I've always found that the >>> biggest asset a programmer can have is the simple willingness to >>> learn. >> >> I basically agree with what has been posted. I just wanted to mention a >> couple things that separates beginners and non-beginners. One is "how long >> it takes to identify and fix an error"--even a syntax error. And that is a >> skill which is acquired with some practice, maybe more "some" than anyone >> likes. > Be careful with this one. For anything other than trivial errors (and > even for some trivial errors), finding the bug is basically searching > through a problem space of all things that could potentially cause > this symptom. A novice could accidentally stumble onto the right > solution to a tricky bug, or an expert could search a thousand other > things and only get to the true cause after a long time. some "expert"! ; ) > So while > you're partly correct in saying "how long", you can't just put someone > on the clock and say "if you find the bug in less than five minutes, > you're hired". Ultimately, the only person who can truly evaluate a > programmer's skill is another programmer, usually by watching the > candidate go through this sort of debugging work. But yeah, broadly > speaking, an experienced programmer can usually debug something more > quickly than a novice can. On average. > > ChrisA From tjreedy at udel.edu Thu Sep 28 17:06:33 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Sep 2017 17:06:33 -0400 Subject: EuroPython 2017: Videos for Monday available online In-Reply-To: <220ad005-ec5d-25e8-825f-492ea66cb024@europython.eu> References: <2536a9fe-0e9d-3d35-b3f4-bd16f1a8e072@europython.eu> <220ad005-ec5d-25e8-825f-492ea66cb024@europython.eu> Message-ID: On 9/28/2017 12:33 PM, M.-A. Lemburg wrote: >> """ >> In the coming weeks, we will release the other videos, in batches of >> one conference day per week. >> """ It was not obvious to me that 'private video' meant 'non-existent, not yet added video'. It usually means a video that is present but not public. >> Perhaps we ought to remove them from the playlist to not cause >> confusion. > > This doesn't appear to be easily possible due to changes in the > YT UI. We've now set the playlist order to show the private > videos at the end as work-around. That would make it easier to see what is available not. I gave up trying to scroll through the list. -- Terry Jan Reedy From rosuav at gmail.com Thu Sep 28 17:08:41 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Sep 2017 07:08:41 +1000 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On Fri, Sep 29, 2017 at 6:59 AM, Bill wrote: > Chris Angelico wrote: >> >> Be careful with this one. For anything other than trivial errors (and >> even for some trivial errors), finding the bug is basically searching >> through a problem space of all things that could potentially cause >> this symptom. A novice could accidentally stumble onto the right >> solution to a tricky bug, or an expert could search a thousand other >> things and only get to the true cause after a long time. > > some "expert"! ; ) > Yep. Pick anyone on this list that you believe is an expert, and ask him/her for a story of a long debug session that ended up finding a tiny problem. I can pretty much guarantee that every expert programmer will have multiple such experiences, and it's just a matter of remembering one with enough detail to share the story. ChrisA From BILL_NOSPAM at whoknows.net Thu Sep 28 17:47:05 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Thu, 28 Sep 2017 17:47:05 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: Chris Angelico wrote: > On Fri, Sep 29, 2017 at 6:59 AM, Bill wrote: >> Chris Angelico wrote: >>> Be careful with this one. For anything other than trivial errors (and >>> even for some trivial errors), finding the bug is basically searching >>> through a problem space of all things that could potentially cause >>> this symptom. A novice could accidentally stumble onto the right >>> solution to a tricky bug, or an expert could search a thousand other >>> things and only get to the true cause after a long time. >> some "expert"! ; ) >> > Yep. Pick anyone on this list that you believe is an expert, and ask > him/her for a story of a long debug session that ended up finding a > tiny problem. I can pretty much guarantee that every expert programmer > will have multiple such experiences, and it's just a matter of > remembering one with enough detail to share the story. > > ChrisA I won't claim to be any sort of "expert". But one memorable problem, for me, was ultimately accounted for by the "inherent problem" of the floating point variables x0 and xo coexisting in the same module. It's sort of funny if you think about it just right. FWIW, my job was to fix the problem, I didn't create it! Bill From rosuav at gmail.com Thu Sep 28 18:00:09 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Sep 2017 08:00:09 +1000 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On Fri, Sep 29, 2017 at 7:47 AM, Bill wrote: > I won't claim to be any sort of "expert". But one memorable problem, for > me, was ultimately accounted for by the "inherent problem" of the floating > point variables x0 and xo coexisting in the same module. It's sort of funny > if you think about it just right. FWIW, my job was to fix the problem, I > didn't create it! Today I helped one of my students debug an issue that was exacerbated by a flawed shuffle function that, while capable of returning any permutation of the input, had a bit of a tendency to leave things early if they started early - it was about 8% more likely to pick the first element than the last. Doesn't sound like much, but it increased the chances of a collision pretty significantly. Now THAT was fun to debug. ChrisA From larry.martell at gmail.com Thu Sep 28 18:20:26 2017 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 28 Sep 2017 18:20:26 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On Thu, Sep 28, 2017 at 5:08 PM, Chris Angelico wrote: > Yep. Pick anyone on this list that you believe is an expert, and ask > him/her for a story of a long debug session that ended up finding a > tiny problem. I can pretty much guarantee that every expert programmer > will have multiple such experiences, and it's just a matter of > remembering one with enough detail to share the story. The software development process can be summed up thusly: I can?t fix this Crisis of confidence Questions career Questions life Oh it was a typo, cool From daw.walden66 at gmail.com Thu Sep 28 21:19:02 2017 From: daw.walden66 at gmail.com (daw.walden66 at gmail.com) Date: Thu, 28 Sep 2017 18:19:02 -0700 (PDT) Subject: Case Solution: ENOVE Business Strategy in a Transitioning Economy by Maciek Nowak, Alexander Stoll In-Reply-To: <30107cdb-0d13-4775-bcac-1956efe1d588@googlegroups.com> References: <30107cdb-0d13-4775-bcac-1956efe1d588@googlegroups.com> Message-ID: <6a6ca810-9c1a-40ac-bda1-5e2d5b8245a2@googlegroups.com> On Friday, August 4, 2017 at 5:08:20 PM UTC-5, Case Solution & Analysis wrote: > Case Solution and Analysis of ENOVE: Business Strategy in a Transitioning Economy by Maciek Nowak, Alexander Stoll is available at a lowest price, send email to casesolutionscentre(at)gmail(dot)com if you want to order the Case Solution. > > Case Study ID: 9B16M013 / W16035 > > Get Case Study Solution and Analysis of ENOVE: Business Strategy in a Transitioning Economy in a FAIR PRICE!! > > Our e-mail address is CASESOLUTIONSCENTRE (AT) GMAIL (DOT) COM. Please replace (at) by @ and (dot) by . > > YOU MUST WRITE THE FOLLOWING WHILE PLACING YOUR ORDER: > Complete Case Study ENOVE Business Strategy in a Transitioning Economy > Authors by Maciek Nowak, Alexander Stoll > Case Study ID 9B16M013 / W16035 > Publisher of Case Study Havard Business Review > Your Requirements Case Study for International Business / Case Questions Don't know haven't read the article yet. > > Note: Do not REPLY to this post because we do not reply to posts here. If you need any Case Solution please send us an email. We can help you to get it. From steve+python at pearwood.info Fri Sep 29 00:38:56 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 29 Sep 2017 14:38:56 +1000 Subject: Spacing conventions References: <59cc5459$0$14941$b1db1813$d948b532@news.astraweb.com> Message-ID: <59cdce62$0$14943$b1db1813$d948b532@news.astraweb.com> On Thu, 28 Sep 2017 03:56 pm, Bill wrote: > I worked in maintenance programming. You got the hand you were dealt! > And you weren't allowed to "improve" the code unless the customer > contracted you to do so. How do you tell the difference between a bug fix and an code improvement, if the behaviour of the program remains the same? > I maintained for-loops (containing > for-loops)... hundreds of lines long. Would you be searching for break or > continue? : ) It depends on whether it was relevant to the bug or not. I've never felt the urge to search for some arbitrary keyword when debugging. Why search for break or continue? How do you know the bug has anything to do with one of them? I would start with narrowing down where the bug occurs. Hopefully the stacktrace or error gives a line number. Then work backwards from there. I certainly wouldn't say "Oh, the code crashed on line 587. I'll do a quick search for the closest break statement and start working from there." What do you do? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Fri Sep 29 01:01:47 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Sep 2017 15:01:47 +1000 Subject: Spacing conventions In-Reply-To: <59cdce62$0$14943$b1db1813$d948b532@news.astraweb.com> References: <59cc5459$0$14941$b1db1813$d948b532@news.astraweb.com> <59cdce62$0$14943$b1db1813$d948b532@news.astraweb.com> Message-ID: On Fri, Sep 29, 2017 at 2:38 PM, Steve D'Aprano wrote: > On Thu, 28 Sep 2017 03:56 pm, Bill wrote: > >> I worked in maintenance programming. You got the hand you were dealt! >> And you weren't allowed to "improve" the code unless the customer >> contracted you to do so. > > How do you tell the difference between a bug fix and an code improvement, if the > behaviour of the program remains the same? If the behaviour remains *exactly* the same, then it's a code improvement (aka a refactoring), not a bug fix. Or, looking at it another way: if there is absolutely no change to behaviour, how could you tell that there was a bug in it? And yes, trying to convince a customer that it's worth paying for improvements that don't change anything visible is hard. Which is why a lot of companies end up merely paying interest on their technical debt, and never paying off any of the capital. ChrisA From steve+python at pearwood.info Fri Sep 29 01:25:09 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 29 Sep 2017 15:25:09 +1000 Subject: Textwrap doesn't honour NO-BREAK SPACE Message-ID: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> I don't have Python 3.6 installed, can somebody check to see whether or not it shows the same (wrong) behaviour? import textwrap text = ('Lorum ipsum dolor sit amet, consectetur adipiscing' ' elit ZZZ\xa0ZZZ sed do euismod tempor incididunt' ' ut labore et dolore magna aliqua.') print(textwrap.fill(text, 59)) Expected result: Lorum ipsum dolor sit amet, consectetur adipiscing elit ZZZ ZZZ sed do euismod tempor incididunt ut labore et dolore magna aliqua. Actual result in Python 3.5 and older: Lorum ipsum dolor sit amet, consectetur adipiscing elit ZZZ ZZZ sed do euismod tempor incididunt ut labore et dolore magna aliqua. I'm pretty sure this is a bug. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From greg.ewing at canterbury.ac.nz Fri Sep 29 01:28:42 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 29 Sep 2017 18:28:42 +1300 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: Chris Angelico wrote: > finding the bug is basically searching > through a problem space of all things that could potentially cause > this symptom. A novice could accidentally stumble onto the right > solution to a tricky bug, or an expert could search a thousand other > things and only get to the true cause after a long time. What I think is more important than how *long* it takes is *how* they go about finding the bug. A novice will make wild guesses about what might be wrong and make random changes to the program in the hope of making it work. An experienced programmer will conduct a series of carefully-designed experiments to narrow down the cause. A result of this is that a true expert will never have to try a thousand possibilities. He will be able to search a space of N possible causes in O(log N) operations. This doesn't necessarily translate into time, because in some situations the experiments can be very time- consuming to perform. But other things being equal, the expert's bug-finding algorithm is faster than the novice's. -- Greg From BILL_NOSPAM at whoknows.net Fri Sep 29 01:40:13 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Fri, 29 Sep 2017 01:40:13 -0400 Subject: Spacing conventions In-Reply-To: <59cdce62$0$14943$b1db1813$d948b532@news.astraweb.com> References: <59cc5459$0$14941$b1db1813$d948b532@news.astraweb.com> <59cdce62$0$14943$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > On Thu, 28 Sep 2017 03:56 pm, Bill wrote: > >> I worked in maintenance programming. You got the hand you were dealt! >> And you weren't allowed to "improve" the code unless the customer >> contracted you to do so. > How do you tell the difference between a bug fix and an code improvement, if the > behaviour of the program remains the same? They ran the Unix command "diff" to double-check that nothing unaccounted for got added to the source code as they did new builds. The "rule" was you could "fix" the code if you were already there, in the immediate vicinity. In retrospect, this certainly helped to keep "human error" from sneaking in. > > >> I maintained for-loops (containing >> for-loops)... hundreds of lines long. Would you be searching for break or >> continue? : ) > It depends on whether it was relevant to the bug or not. > > I've never felt the urge to search for some arbitrary keyword when debugging. > Why search for break or continue? How do you know the bug has anything to do > with one of them? > > I would start with narrowing down where the bug occurs. Hopefully the stacktrace > or error gives a line number. Then work backwards from there. > > I certainly wouldn't say "Oh, the code crashed on line 587. I'll do a quick > search for the closest break statement and start working from there." > > What do you do? > > > From frank at chagford.com Fri Sep 29 01:46:04 2017 From: frank at chagford.com (Frank Millman) Date: Fri, 29 Sep 2017 07:46:04 +0200 Subject: Textwrap doesn't honour NO-BREAK SPACE In-Reply-To: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> References: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> Message-ID: "Steve D'Aprano" wrote in message news:59cdd938$0$14933$b1db1813$d948b532 at news.astraweb.com... I don't have Python 3.6 installed, can somebody check to see whether or not it shows the same (wrong) behaviour? [...] C:\Users\User>python Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import textwrap >>> text = ('Lorum ipsum dolor sit amet, consectetur adipiscing' ... ' elit ZZZ\xa0ZZZ sed do euismod tempor incididunt' ... ' ut labore et dolore magna aliqua.') >>> print(textwrap.fill(text, 59)) Lorum ipsum dolor sit amet, consectetur adipiscing elit ZZZ ZZZ sed do euismod tempor incididunt ut labore et dolore magna aliqua. >>> It seems to have been fixed. Frank Millman From tjreedy at udel.edu Fri Sep 29 01:55:35 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Sep 2017 01:55:35 -0400 Subject: Textwrap doesn't honour NO-BREAK SPACE In-Reply-To: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> References: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> Message-ID: On 9/29/2017 1:25 AM, Steve D'Aprano wrote: > I don't have Python 3.6 installed, can somebody check to see whether or not it > shows the same (wrong) behaviour? > > > import textwrap > text = ('Lorum ipsum dolor sit amet, consectetur adipiscing' > ' elit ZZZ\xa0ZZZ sed do euismod tempor incididunt' > ' ut labore et dolore magna aliqua.') > print(textwrap.fill(text, 59)) > > > > Expected result: > > > Lorum ipsum dolor sit amet, consectetur adipiscing elit > ZZZ ZZZ sed do euismod tempor incididunt ut labore et > dolore magna aliqua. On Windows 10, I get this on 2.7, 3.5, 3.6, 3.7. > Actual result in Python 3.5 and older: > > Lorum ipsum dolor sit amet, consectetur adipiscing elit ZZZ > ZZZ sed do euismod tempor incididunt ut labore et dolore > magna aliqua. > > > I'm pretty sure this is a bug. -- Terry Jan Reedy From rosuav at gmail.com Fri Sep 29 02:08:00 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Sep 2017 16:08:00 +1000 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On Fri, Sep 29, 2017 at 3:28 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> finding the bug is basically searching >> through a problem space of all things that could potentially cause >> this symptom. A novice could accidentally stumble onto the right >> solution to a tricky bug, or an expert could search a thousand other >> things and only get to the true cause after a long time. > > > What I think is more important than how *long* it takes is > *how* they go about finding the bug. > > A novice will make wild guesses about what might be wrong > and make random changes to the program in the hope of > making it work. An experienced programmer will conduct > a series of carefully-designed experiments to narrow > down the cause. > > A result of this is that a true expert will never have > to try a thousand possibilities. He will be able to > search a space of N possible causes in O(log N) operations. > > This doesn't necessarily translate into time, because > in some situations the experiments can be very time- > consuming to perform. But other things being equal, > the expert's bug-finding algorithm is faster than the > novice's. This is very true, which is part of why I said that in programming, it takes one to know one - to observe a candidate and determine his/her experimental technique, you basically need to yourself be a programmer. ChrisA From steve+python at pearwood.info Fri Sep 29 02:35:02 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 29 Sep 2017 16:35:02 +1000 Subject: Textwrap doesn't honour NO-BREAK SPACE References: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> Message-ID: <59cde998$0$14935$b1db1813$d948b532@news.astraweb.com> On Fri, 29 Sep 2017 03:55 pm, Terry Reedy wrote: >> Expected result: >> >> >> Lorum ipsum dolor sit amet, consectetur adipiscing elit >> ZZZ ZZZ sed do euismod tempor incididunt ut labore et >> dolore magna aliqua. > > On Windows 10, I get this on 2.7, 3.5, 3.6, 3.7. > >> Actual result in Python 3.5 and older: >> >> Lorum ipsum dolor sit amet, consectetur adipiscing elit ZZZ >> ZZZ sed do euismod tempor incididunt ut labore et dolore >> magna aliqua. Sorry Terry, it isn't clear to me which result (expected, or actual) is "this" in your comment. I wonder if the behaviour is platform specific? On Linux, I've tried Python 2.7 (after adjusting for a Unicode string rather than byte string), 3.3 and 3.5 and it breaks on the NO-BREAK SPACE on all three. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From frank at chagford.com Fri Sep 29 02:58:10 2017 From: frank at chagford.com (Frank Millman) Date: Fri, 29 Sep 2017 08:58:10 +0200 Subject: Textwrap doesn't honour NO-BREAK SPACE In-Reply-To: <59cde998$0$14935$b1db1813$d948b532@news.astraweb.com> References: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> <59cde998$0$14935$b1db1813$d948b532@news.astraweb.com> Message-ID: "Steve D'Aprano" wrote in message news:59cde998$0$14935$b1db1813$d948b532 at news.astraweb.com... On Fri, 29 Sep 2017 03:55 pm, Terry Reedy wrote: >> Expected result: >> >> >> Lorum ipsum dolor sit amet, consectetur adipiscing elit >> ZZZ ZZZ sed do euismod tempor incididunt ut labore et >> dolore magna aliqua. > > On Windows 10, I get this on 2.7, 3.5, 3.6, 3.7. > >> Actual result in Python 3.5 and older: >> >> Lorum ipsum dolor sit amet, consectetur adipiscing elit ZZZ >> ZZZ sed do euismod tempor incididunt ut labore et dolore >> magna aliqua. > Sorry Terry, it isn't clear to me which result (expected, or actual) is > "this" > in your comment. I was also unsure, so to double-check myself I ran this from the prompt (Windows 10), not from the interpreter - C:\Users\User>type aib\aib\test_db100.py import textwrap text = ('Lorum ipsum dolor sit amet, consectetur adipiscing' ' elit ZZZ\xa0ZZZ sed do euismod tempor incididunt' ' ut labore et dolore magna aliqua.') print() print(textwrap.fill(text, 59)) C:\Users\User>py -3.5 aib\aib\test_db100.py Lorum ipsum dolor sit amet, consectetur adipiscing elit ZZZ ZZZ sed do euismod tempor incididunt ut labore et dolore magna aliqua. C:\Users\User>py -3.6 aib\aib\test_db100.py Lorum ipsum dolor sit amet, consectetur adipiscing elit ZZZ ZZZ sed do euismod tempor incididunt ut labore et dolore magna aliqua. It confirms that the problem was there in 3.5, but is fixed in 3.6. Frank Millman From breamoreboy at gmail.com Fri Sep 29 03:14:48 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Fri, 29 Sep 2017 00:14:48 -0700 (PDT) Subject: Textwrap doesn't honour NO-BREAK SPACE In-Reply-To: References: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> Message-ID: <527e93b0-0ae0-4f5b-bb1c-d08390ff8cd5@googlegroups.com> On Friday, September 29, 2017 at 6:46:31 AM UTC+1, Frank Millman wrote: > "Steve D'Aprano" wrote > > I don't have Python 3.6 installed, can somebody check to see whether or not > it > shows the same (wrong) behaviour? > > [...] > > C:\Users\User>python > Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit > (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import textwrap > >>> text = ('Lorum ipsum dolor sit amet, consectetur adipiscing' > ... ' elit ZZZ\xa0ZZZ sed do euismod tempor incididunt' > ... ' ut labore et dolore magna aliqua.') > >>> print(textwrap.fill(text, 59)) > Lorum ipsum dolor sit amet, consectetur adipiscing elit > ZZZ ZZZ sed do euismod tempor incididunt ut labore et > dolore magna aliqua. > >>> > > It seems to have been fixed. > > Frank Millman FTR https://bugs.python.org/issue20491 -- Kindest regards. Mark Lawrence. From steve+python at pearwood.info Fri Sep 29 03:15:39 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 29 Sep 2017 17:15:39 +1000 Subject: Beginners and experts (Batchelder blog post) References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: <59cdf31b$0$14970$b1db1813$d948b532@news.astraweb.com> On Fri, 29 Sep 2017 03:28 pm, Gregory Ewing wrote: > Chris Angelico wrote: >> finding the bug is basically searching >> through a problem space of all things that could potentially cause >> this symptom. A novice could accidentally stumble onto the right >> solution to a tricky bug, or an expert could search a thousand other >> things and only get to the true cause after a long time. > > What I think is more important than how *long* it takes is > *how* they go about finding the bug. > > A novice will make wild guesses about what might be wrong > and make random changes to the program in the hope of > making it work. An experienced programmer will conduct > a series of carefully-designed experiments to narrow > down the cause. "Carefully-designed experiments" -- yeah, that is so totally how the coders I've worked with operate *wink* I think that's an awfully optimistic description of how the average programmer works :-) > A result of this is that a true expert will never have > to try a thousand possibilities. He will be able to > search a space of N possible causes in O(log N) operations. I don't think that, *in general*, possible causes of a bug can be neatly sorted in such a way that we can do a binary search over the space of all possible causes. I also think it is unlikely that even the best programmer enumerates all the possible causes before working on them. If you don't enumerate all the causes first, how to you sort them? In my experience, even good coders are likely to say "there's only three possible things that could be causing this bug", and later on report it was actually the fifth thing. More likely, the experienced programmer is better at eliminating irrelevancies and narrowing in on the space of likely candidates, or at least narrowing down on the region of code that is relevant, while less experienced programmers waste more time looking at things which couldn't possibly be the cause[1]. More likely, the experienced programmer makes better use of his or her tools. While the novice is still messing about trying to guess the problem by pure logical reasoning, the expert is using a few useful print calls, or a debugger, to narrow down to where the problem actually is. And experts are likely to be better at extrapolating "well, since that's not the problem... maybe its this?". And you learn that not by pure logic, but by being bitten by nasty bugs: "I can't see any possibly way that this could be involved, but I came across a similar situation once before and this was the solution... [confirms hypothesis and fixes bug] oh of course, that's how the bug occurs! Its obvious in hindsight." More experienced programmers are confident enough to know when to walk away from a problem and let their subconscious work on it. Or when to go and explain it to the cleaning lady[2]. Or when to admit defeat and hand over to a fresh pair of eyes who won't be stuck in the same mindset. Even just getting to the point of being able to reason *where to start* requires a fair amount of experience. A true beginner to programming altogether won't even know how to read a stack trace to identify the line where the bug occurs, let alone understand why it happened. I wish I had a dollar for every time some beginner says something like: "I get a syntax error. What's wrong with my code?" and eventually after much arm-twisting is convinced to post the last line of the traceback, which turns out not to be a syntax error at all: "TypeError: object of type 'int' has no len()" (say). Reading error messages is a skill that must be learned, even in Python. Let alone (say) gcc error messages, which are baroque to an extreme. The other day I was getting an error like: /tmp/ccchKJVU.o: In function `__static_initialization_and_destruction_0(int, int)': foo.cpp:(.text+0x7c): undefined reference to `std::ios_base::Init::Init()' foo.cpp:(.text+0x91): undefined reference to `std::ios_base::Init::~Init()' collect2: error: ld returned 1 exit status Of course, its obvious that the problem here is that I needed to install g++ as well as gcc, right? :-) > This doesn't necessarily translate into time, because > in some situations the experiments can be very time- > consuming to perform. But other things being equal, > the expert's bug-finding algorithm is faster than the > novice's. [1] Although, the *really* experienced programmer knows that in sufficiently baroque and highly-coupled code, a bug could be caused by *anything* *anywhere*. (This is one reason why global variables are bad.) I still haven't gotten over hearing about a bug in the Internet Explorer routines for handling WMF files, which lead to being unable to copy and paste plain text in any application. [2] The place I worked had a cuddly penguin toy called Mr Snuggles, and the programmers would go and explain the problem to him. It never[3] failed. [3] Well, hardly ever. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From BILL_NOSPAM at whoknows.net Fri Sep 29 04:09:54 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Fri, 29 Sep 2017 04:09:54 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: <59cdf31b$0$14970$b1db1813$d948b532@news.astraweb.com> References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> <59cdf31b$0$14970$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > > (say). Reading error messages is a skill that must be learned, even in Python. > Let alone (say) gcc error messages, which are baroque to an extreme. The other > day I was getting an error like: > > /tmp/ccchKJVU.o: In function `__static_initialization_and_destruction_0(int, > int)': > foo.cpp:(.text+0x7c): undefined reference to `std::ios_base::Init::Init()' > foo.cpp:(.text+0x91): undefined reference to `std::ios_base::Init::~Init()' > collect2: error: ld returned 1 exit status > > Yes, that's the sort of character-building that I was referring to (that a beginner needs to learn!) They have to learn that if it "breaks", then there must be a simpler way to break it! Hopefully one which will satisfy Log_2 (n). : ) From vincent.vande.vyvre at telenet.be Fri Sep 29 04:21:27 2017 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Fri, 29 Sep 2017 10:21:27 +0200 Subject: Textwrap doesn't honour NO-BREAK SPACE In-Reply-To: References: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> <59cde998$0$14935$b1db1813$d948b532@news.astraweb.com> Message-ID: <4c79a498-b284-f565-1da5-d83854b17687@telenet.be> Le 29/09/17 ? 08:58, Frank Millman a ?crit?: > "Steve D'Aprano"? wrote in message > news:59cde998$0$14935$b1db1813$d948b532 at news.astraweb.com... > > On Fri, 29 Sep 2017 03:55 pm, Terry Reedy wrote: > >>> Expected result: >>> >>> >>> Lorum ipsum dolor sit amet, consectetur adipiscing elit >>> ZZZ ZZZ sed do euismod tempor incididunt ut labore et >>> dolore magna aliqua. >> >> On Windows 10, I get this on 2.7, 3.5, 3.6, 3.7. >> >>> Actual result in Python 3.5 and older: >>> >>> Lorum ipsum dolor sit amet, consectetur adipiscing elit ZZZ >>> ZZZ sed do euismod tempor incididunt ut labore et dolore >>> magna aliqua. > >> Sorry Terry, it isn't clear to me which result (expected, or actual) >> is "this" >> in your comment. > > I was also unsure, so to double-check myself I ran this from the > prompt (Windows 10), not from the interpreter - > > C:\Users\User>type aib\aib\test_db100.py > > import textwrap > text = ('Lorum ipsum dolor sit amet, consectetur adipiscing' > ?????? ' elit ZZZ\xa0ZZZ sed do euismod tempor incididunt' > ?????? ' ut labore et dolore magna aliqua.') > print() > print(textwrap.fill(text, 59)) > > C:\Users\User>py -3.5 aib\aib\test_db100.py > > Lorum ipsum dolor sit amet, consectetur adipiscing elit ZZZ > ZZZ sed do euismod tempor incididunt ut labore et dolore > magna aliqua. > > C:\Users\User>py -3.6 aib\aib\test_db100.py > > Lorum ipsum dolor sit amet, consectetur adipiscing elit > ZZZ ZZZ sed do euismod tempor incididunt ut labore et > dolore magna aliqua. > > It confirms that the problem was there in 3.5, but is fixed in 3.6. > > Frank Millman > > Python 3.6.1 in venv Python 3.6.1 (default, Apr 16 2017, 16:15:46) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import textwrap >>> text = ('Lorum ipsum dolor sit amet, consectetur adipiscing' ...???????? ' elit ZZZ\xa0ZZZ sed do euismod tempor incididunt' ...???????? ' ut labore et dolore magna aliqua.') >>> print(textwrap.fill(text, 59)) Lorum ipsum dolor sit amet, consectetur adipiscing elit ZZZ?ZZZ sed do euismod tempor incididunt ut labore et dolore magna aliqua. Vincent From tjol at tjol.eu Fri Sep 29 04:55:49 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 29 Sep 2017 10:55:49 +0200 Subject: Textwrap doesn't honour NO-BREAK SPACE In-Reply-To: References: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> <59cde998$0$14935$b1db1813$d948b532@news.astraweb.com> Message-ID: <741e956d-aac8-2109-dec6-716a37535266@tjol.eu> On 2017-09-29 08:58, Frank Millman wrote: > > It confirms that the problem was there in 3.5, but is fixed in 3.6. > Same on Linux: 3.5 has the bug, 3.6 doesn't. (Python 3.5 from Red Hat, 3.6 from Anaconda) -- Thomas Jollans From wolfgang.maier at biologie.uni-freiburg.de Fri Sep 29 05:05:49 2017 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Fri, 29 Sep 2017 11:05:49 +0200 Subject: Textwrap doesn't honour NO-BREAK SPACE In-Reply-To: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> References: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> Message-ID: <42208646-ec0f-f03f-f86c-8e2c6386b012@biologie.uni-freiburg.de> On 29.09.2017 07:25, Steve D'Aprano wrote: > I don't have Python 3.6 installed, can somebody check to see whether or not it > shows the same (wrong) behaviour? > > > import textwrap > text = ('Lorum ipsum dolor sit amet, consectetur adipiscing' > ' elit ZZZ\xa0ZZZ sed do euismod tempor incididunt' > ' ut labore et dolore magna aliqua.') > print(textwrap.fill(text, 59)) > > > > Expected result: > > > Lorum ipsum dolor sit amet, consectetur adipiscing elit > ZZZ ZZZ sed do euismod tempor incididunt ut labore et > dolore magna aliqua. > > > Actual result in Python 3.5 and older: > > > Lorum ipsum dolor sit amet, consectetur adipiscing elit ZZZ > ZZZ sed do euismod tempor incididunt ut labore et dolore > magna aliqua. > > > I'm pretty sure this is a bug. > Yes, it is a bug, but a known one: https://bugs.python.org/issue20491 The fix got backported even to 3.5, but I guess it depends which minor version you are running. I'm pretty sure that explains why people report different outcomes. Best, Wolfgang From wolfgang.maier at biologie.uni-freiburg.de Fri Sep 29 05:11:40 2017 From: wolfgang.maier at biologie.uni-freiburg.de (Wolfgang Maier) Date: Fri, 29 Sep 2017 11:11:40 +0200 Subject: Textwrap doesn't honour NO-BREAK SPACE In-Reply-To: <42208646-ec0f-f03f-f86c-8e2c6386b012@biologie.uni-freiburg.de> References: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> <42208646-ec0f-f03f-f86c-8e2c6386b012@biologie.uni-freiburg.de> Message-ID: On 29.09.2017 11:05, Wolfgang Maier wrote: > On 29.09.2017 07:25, Steve D'Aprano wrote: >> I'm pretty sure this is a bug. >> > > Yes, it is a bug, but a known one: https://bugs.python.org/issue20491 > > The fix got backported even to 3.5, but I guess it depends which minor > version you are running. I'm pretty sure that explains why people report > different outcomes. > > Best, > Wolfgang > To be specific, this should be fixed from 3.5.3 and 3.6.0b3 onwards. From leamhall at gmail.com Fri Sep 29 05:57:34 2017 From: leamhall at gmail.com (Leam Hall) Date: Fri, 29 Sep 2017 05:57:34 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On 09/27/2017 10:33 PM, Stefan Ram wrote: > Some areas of knowledge follow, a programmer should not be > ignorant in all of them: --- Stefan, this is list AWESOME! I have started mapping skills I have to the list and ways to build skills I don't have. Last night I started working on a project that has been on my mind for over a year; taking a CSV list of game characters and putting them into a MongoDB datastore. Now I need to figure out how to build an interface for CRUD operations using Python, pymongo, and maybe Tk. I appreciate the structure your list provides. Thank you! Leam From tjol at tjol.eu Fri Sep 29 06:27:18 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 29 Sep 2017 12:27:18 +0200 Subject: OT: Drain specialist Was: Beginners and experts In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: <375b95a9-f218-bdff-223e-9e353e91c3c5@tjol.eu> On 2017-09-28 14:14, Neil Cerutti wrote: > On 2017-09-28, Dan Sommers wrote: >> If I'm hiring myself out as a plumber, I should know how to unclog >> drains; > > OT: I recommend hiring a drain specialist, *not* a plumber for > this particular job. Asking a plumber to clear a drain would be > kinda like hiring a whiz-bang C programmer to configure your > email server--it isn't that he or she *can't* do it... > You mean like Tuppy Glossop's Plumbo-Jumbo, I assume? https://www.flickr.com/photos/leff/7746149 -- Thomas Jollans From darcy at VybeNetworks.com Fri Sep 29 06:34:51 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Fri, 29 Sep 2017 06:34:51 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: <59cdf31b$0$14970$b1db1813$d948b532@news.astraweb.com> References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> <59cdf31b$0$14970$b1db1813$d948b532@news.astraweb.com> Message-ID: On 09/29/2017 03:15 AM, Steve D'Aprano wrote: > "Carefully-designed experiments" -- yeah, that is so totally how the coders I've > worked with operate *wink* > > I think that's an awfully optimistic description of how the average programmer > works :-) Better not hire average programmers then. I do "Carefully-designed experiments" to find non-obvious bugs so I guess I am not average. I get the impression that many people here are above average too. Personally I think you are being pessimistic about "average" programmers. Perhaps you just know the sloppy kind. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From rosuav at gmail.com Fri Sep 29 10:06:31 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Sep 2017 00:06:31 +1000 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> <59cdf31b$0$14970$b1db1813$d948b532@news.astraweb.com> Message-ID: On Fri, Sep 29, 2017 at 8:34 PM, D'Arcy Cain wrote: > On 09/29/2017 03:15 AM, Steve D'Aprano wrote: >> >> "Carefully-designed experiments" -- yeah, that is so totally how the >> coders I've >> worked with operate *wink* >> >> I think that's an awfully optimistic description of how the average >> programmer >> works :-) > > > Better not hire average programmers then. I do "Carefully-designed > experiments" to find non-obvious bugs so I guess I am not average. I get > the impression that many people here are above average too. > > Personally I think you are being pessimistic about "average" programmers. > Perhaps you just know the sloppy kind. Based on any mathematical definition of "average", yes, I am pretty pessimistic about the average programmer :) ChrisA From walters.justin01 at gmail.com Fri Sep 29 10:52:45 2017 From: walters.justin01 at gmail.com (justin walters) Date: Fri, 29 Sep 2017 07:52:45 -0700 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On Fri, Sep 29, 2017 at 2:57 AM, Leam Hall wrote: > On 09/27/2017 10:33 PM, Stefan Ram wrote: > > Some areas of knowledge follow, a programmer should not be >> ignorant in all of them: >> > > --- > > Stefan, this is list AWESOME! > > I have started mapping skills I have to the list and ways to build skills > I don't have. Last night I started working on a project that has been on my > mind for over a year; taking a CSV list of game characters and putting them > into a MongoDB datastore. Now I need to figure out how to build an > interface for CRUD operations using Python, pymongo, and maybe Tk. > > I appreciate the structure your list provides. Thank you! > > Leam > > -- > https://mail.python.org/mailman/listinfo/python-list > Python web backends just happen to be my specialty. I do mostly Django, but it doesn't mesh well with MongoDB. Well, it does if you still use an RDBMS forsome things. I can recommend the following: - Flask: http://flask.pocoo.org/ Small and light But not tiny. Not really fast, not really slow. Not a ton of batteries included. Tons of third-party extensions. - ApiStar: https://github.com/encode/apistar New kid on the block. Specializes in APIS. No template integrations. Best for serving JSON through a RESTful interface. Fairly quick, but not blazing fast. Has the upside that any web API can be exposed as a CLI API. Not a ton of third party extensions available. Would be a good choice if you don't want to build a desktop application instead of a web application as it will help design the API that something like Tkinter will sit on top of. - Sanic: https://github.com/channelcat/sanic Another new kid. Python 3.5+ only. Uses the new async capabilities quite heavilly. Based on falcon. Blazing fast. No batteries included. Small number of fairly high quality third-party extensions. - Django: https://www.djangoproject.com/ The old workhorse. Mature and proven. Best choice for reliability. Not fast, not slow. Huge collection of third party extensions ranging in quality. Though, it is pretty heavilly integrated with it's relational Db backends. If you decide on this, you would need to use postgres/sqlite/mysql to store all of Django's built in model classes(tables). I got through writing all of the above without realizing that you meant you wanted to build a desktop application and not a web application. Though, I think the advice is still helpful. From leamhall at gmail.com Fri Sep 29 10:59:42 2017 From: leamhall at gmail.com (leam hall) Date: Fri, 29 Sep 2017 10:59:42 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> Message-ID: On Fri, Sep 29, 2017 at 10:52 AM, justin walters wrote: > > I got through writing all of the above without realizing that you meant you > wanted to build a > desktop application and not a web application. Though, I think the advice > is still helpful. > > Yes and no. Seriously thanks! I am at first targeting a desktop app just to be simpler and to push me to learn Tkinter. However, it's more likely to end up a simple web app once I learn enough Bottle/Flask to make it work. Or I may just skip Tkinter for the nonce and see if I can do it with web forms. Leam From tjreedy at udel.edu Fri Sep 29 11:35:15 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 29 Sep 2017 11:35:15 -0400 Subject: Textwrap doesn't honour NO-BREAK SPACE In-Reply-To: <59cde998$0$14935$b1db1813$d948b532@news.astraweb.com> References: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> <59cde998$0$14935$b1db1813$d948b532@news.astraweb.com> Message-ID: On 9/29/2017 2:35 AM, Steve D'Aprano wrote: > On Fri, 29 Sep 2017 03:55 pm, Terry Reedy wrote: > >>> Expected result: >>> >>> >>> Lorum ipsum dolor sit amet, consectetur adipiscing elit >>> ZZZ ZZZ sed do euismod tempor incididunt ut labore et >>> dolore magna aliqua. >> >> On Windows 10, I get this on 2.7, 3.5, 3.6, 3.7. > Sorry Terry, it isn't clear to me which result (expected, or actual) is "this" > in your comment. The expected result. I also should have specified 3.5.4, etc, which Wolfgang reported should have the backported fix. So, you are correct that what you saw is/was a bug. -- Terry Jan Reedy From rosuav at gmail.com Fri Sep 29 11:42:03 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Sep 2017 01:42:03 +1000 Subject: Refactoring (was: Spacing conventions) In-Reply-To: References: <59cc5459$0$14941$b1db1813$d948b532@news.astraweb.com> <59cdce62$0$14943$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sat, Sep 30, 2017 at 12:45 AM, Stefan Ram wrote: > Chris Angelico writes: >>If the behaviour remains *exactly* the same, then it's a code >>improvement (aka a refactoring), not a bug fix. > > Usually, one cannot observe whether behavior stays the same, > because a program does not map to behavior, but rather to an > entity that produces behavior during an /interaction/ with > the world. And that's why you read source code. > For example, I can change > > x=float(input()); print( x * 2 ) > > to > > x=float(input()); print( x * 2 ) \ > if not __import__('random').random() == x else 0 > > . The new code has not the same "behavior" in a certain > sense. But what do we mean by "behaviour" here? Not > something one actually can observe! Because whenever > I start the program it behaves just as before the change. That's also true of a lot of actual real-world bug fixes, though. Programs don't tend to have as many glaringly obvious bugs as they have little subtle issues or edge cases. Imagine fixing something that only occurs if the computer's clock is in the middle of a DST fold and then you change timezone, for instance. That's about as likely as the example you give. But it's still not refactoring - refactoring is where there is not meant to be ANY behavioural change at all. ChrisA From steve+python at pearwood.info Fri Sep 29 12:42:33 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 30 Sep 2017 02:42:33 +1000 Subject: Beginners and experts (Batchelder blog post) References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> <59cdf31b$0$14970$b1db1813$d948b532@news.astraweb.com> Message-ID: <59ce77fb$0$14951$b1db1813$d948b532@news.astraweb.com> On Fri, 29 Sep 2017 08:34 pm, D'Arcy Cain wrote: > On 09/29/2017 03:15 AM, Steve D'Aprano wrote: >> "Carefully-designed experiments" -- yeah, that is so totally how the coders >> I've worked with operate *wink* >> >> I think that's an awfully optimistic description of how the average >> programmer works :-) > > Better not hire average programmers then. Okay. Can I consider the top 10% of programmers, or must I only consider only those in the top 1%? If I'm on a budget and the code isn't that critical, can I consider those in the top 20% for junior roles? > I do "Carefully-designed > experiments" to find non-obvious bugs so I guess I am not average. Okay. By the way, *in context* (before you deleted the original text) there was no mention about "non-obvious bugs". Greg Ewing and Chris Angelico were talking about the general difference between the process used by novices and that used by experts and how beginners often attempt to fix bugs by making random changes, while experts don't. I've certainly seen beginners make arbitrary changes to unrelated parts of their code trying to fix a bug. Often many different changes all at once. So that's another difference between beginners and experts: - experts have the self-control to make only one change at a time, when it matters; beginners don't know when it matters. Oh, and I'd like to make a (moderate) defense of a kind of "bug fixing by random perturbation". Obviously making unrelated, arbitrary changes to code is bad. But making non-arbitrary but not fully understood changes to relevant code sections can be useful in (at least) two scenarios. (1) I know there's a bug in a specific chunk of code, but I'm having trouble working out where. When everything else fails, if I perturb the code a bit (reorder lines, calculate things in a different order, rename variables, etc) it may change the nature of the bug enough for me to understand what's happening. That's not *random* or *arbitrary* changes, but they are changes not directed at any specific outcome other than "make the code a bit different, and see if the error changes". I'd like to say it is the debugging technique of last resort, except its perhaps not quite as *last* resort as I'd like, especially in code I'm not familiar with. Its an experiment, but not really "carefully designed". Its more like "what happens if we hit this bit with a hammer?" except that programmers, unlike engineers, have the luxury of an Undo switch :-) (2) I hate off by one errors, and similar finicky errors that mean your code is *almost* right. I especially hate them when I'm not sure which direction I'm off by one. If you have unit tests that are failing, sometimes its quicker and easier to randomly perturb the specific piece of code until you get the right answer, rather than trying to analyse it. "Should I add one here? Maybe subtract one? Start at zero or one? Ah bugger it, I'll try them all and see which one works." This is only effective when you have exhaustive tests that exercise all the relevant cases and can tell you when you've hit the right solution. On the other hand, sometimes the bug isn't as clear cut as you thought, and you really do need to analyse the situation carefully. > I get the impression that many people here are above average too. > > Personally I think you are being pessimistic about "average" > programmers. Perhaps you just know the sloppy kind. One needs to only look at the quality of software, whether open source or commercial closed source, to feel pessimistic about the ability of even excellent programmers to write good, secure, bug-free code. The complexity of code increases faster than our ability to manage that complexity. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Fri Sep 29 12:43:34 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 30 Sep 2017 02:43:34 +1000 Subject: Textwrap doesn't honour NO-BREAK SPACE References: <59cdd938$0$14933$b1db1813$d948b532@news.astraweb.com> <42208646-ec0f-f03f-f86c-8e2c6386b012@biologie.uni-freiburg.de> Message-ID: <59ce7838$0$14951$b1db1813$d948b532@news.astraweb.com> On Fri, 29 Sep 2017 07:11 pm, Wolfgang Maier wrote: > On 29.09.2017 11:05, Wolfgang Maier wrote: >> On 29.09.2017 07:25, Steve D'Aprano wrote: >>> I'm pretty sure this is a bug. >>> >> >> Yes, it is a bug, but a known one: https://bugs.python.org/issue20491 >> >> The fix got backported even to 3.5, but I guess it depends which minor >> version you are running. I'm pretty sure that explains why people report >> different outcomes. >> >> Best, >> Wolfgang >> > > To be specific, this should be fixed from 3.5.3 and 3.6.0b3 onwards. Thanks everyone who answered. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From BILL_NOSPAM at whoknows.net Fri Sep 29 12:47:02 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Fri, 29 Sep 2017 12:47:02 -0400 Subject: Refactoring In-Reply-To: References: <59cc5459$0$14941$b1db1813$d948b532@news.astraweb.com> <59cdce62$0$14943$b1db1813$d948b532@news.astraweb.com> Message-ID: Stefan Ram wrote: > > The customer pays for the solution. The software > manufacturer does the refactoring for it's own sake, > because when it's a longer running project, the > refactorings will pay for themself. > The customer owns the source code (at least where I was). YMMV From steve+python at pearwood.info Fri Sep 29 13:06:37 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 30 Sep 2017 03:06:37 +1000 Subject: Redirecting stdio streams with a context manager Message-ID: <59ce7d9f$0$14955$b1db1813$d948b532@news.astraweb.com> In the standard library's contextlib.py module, there is a class for redirecting standard I/O streams, and two public functions. The code is short enough to reproduce here: # From Python 3.5 class _RedirectStream: _stream = None def __init__(self, new_target): self._new_target = new_target # We use a list of old targets to make this CM re-entrant self._old_targets = [] def __enter__(self): self._old_targets.append(getattr(sys, self._stream)) setattr(sys, self._stream, self._new_target) return self._new_target def __exit__(self, exctype, excinst, exctb): setattr(sys, self._stream, self._old_targets.pop()) class redirect_stdout(_RedirectStream): # docstring removed _stream = "stdout" class redirect_stderr(_RedirectStream): # docstring removed _stream = "stderr" I don't understand the comment "We use a list of old targets to make this CM re-entrant". Under what circumstances will there ever be more than a single entry in _old_targets? If you use the context manager twice: with redirect_stdout(f1) as instance1: with redirect_stdout(f2) as instance2: pass the two calls will return different instances and sys.stdout will be set as follows: # before first call to redirect_stdout sys.stdout = __stdout__ # the original setting # first call __enter__ save __stdout__ in instance1._old_targets set sys.stdout = f1 # second call __enter__ save f1 in instance2._old_targets set sys.stdout = f2 # second call __exit__ restore sys.stdout = f1 # first call __exit__ restore sys.stdout = __stdout__ I'm not seeing why _old_targets is a list. Can anyone explain? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From vincent.vande.vyvre at telenet.be Fri Sep 29 13:15:33 2017 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Fri, 29 Sep 2017 19:15:33 +0200 Subject: The mysterious ways of Python mailing list Message-ID: Is it a reason why my messages appears always a long time (today 9 hours) on the list after I send it ? Send at 19:14 UTC+2 Vincent From rosuav at gmail.com Fri Sep 29 13:20:26 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Sep 2017 03:20:26 +1000 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: <59ce77fb$0$14951$b1db1813$d948b532@news.astraweb.com> References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> <59cdf31b$0$14970$b1db1813$d948b532@news.astraweb.com> <59ce77fb$0$14951$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sat, Sep 30, 2017 at 2:42 AM, Steve D'Aprano wrote: > Oh, and I'd like to make a (moderate) defense of a kind of "bug fixing by random > perturbation". Obviously making unrelated, arbitrary changes to code is bad. > But making non-arbitrary but not fully understood changes to relevant code > sections can be useful in (at least) two scenarios. > > (1) I know there's a bug in a specific chunk of code, but I'm having trouble > working out where. When everything else fails, if I perturb the code a bit > (reorder lines, calculate things in a different order, rename variables, etc) > it may change the nature of the bug enough for me to understand what's > happening. > > That's not *random* or *arbitrary* changes, but they are changes not directed at > any specific outcome other than "make the code a bit different, and see if the > error changes". I'd like to say it is the debugging technique of last resort, > except its perhaps not quite as *last* resort as I'd like, especially in code > I'm not familiar with. > > Its an experiment, but not really "carefully designed". Its more like "what > happens if we hit this bit with a hammer?" except that programmers, unlike > engineers, have the luxury of an Undo switch :-) Sometimes, when I'm debugging something with one of my students, I'll say something like "Let's do something stupid". That prefaces a suggested change that is, perhaps: * logging something that, by all sane logic, cannot possibly be wrong; * altering the form of a piece of code in a way that shouldn't affect anything; * changing something that logically should break the code worse, not fix it; * or worse. They're still not "random" changes, but when you exhaust all the logical and sane things to try, sometimes you do something stupid and it reveals the bug. I wouldn't EVER tell someone to assume that they've hit a language or library bug - but if you make a meaningless change and now it works, maybe that's what you've hit. It does happen. "Why does my program crash when it talks to THIS server, but it's fine talking to THAT server?" ... half an hour of debugging later ... "Okay, so THIS server supports elliptic curve cryptography, but THAT one doesn't. Great. That still doesn't explain the crash." ... two hours of debugging later ... "Huh. Maybe this library has a bug with ECC?" That's pretty close to what happened to me today, with the exception that I spent less time on it (because I had the library's source code handy). But in any case, it's a good reason to occasionally try something stupid. ChrisA From steve+python at pearwood.info Fri Sep 29 13:46:36 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 30 Sep 2017 03:46:36 +1000 Subject: Spacing conventions References: <59cc5459$0$14941$b1db1813$d948b532@news.astraweb.com> <59cdce62$0$14943$b1db1813$d948b532@news.astraweb.com> Message-ID: <59ce86fe$0$14959$b1db1813$d948b532@news.astraweb.com> On Fri, 29 Sep 2017 03:01 pm, Chris Angelico wrote: > On Fri, Sep 29, 2017 at 2:38 PM, Steve D'Aprano > wrote: >> On Thu, 28 Sep 2017 03:56 pm, Bill wrote: >> >>> I worked in maintenance programming. You got the hand you were dealt! >>> And you weren't allowed to "improve" the code unless the customer >>> contracted you to do so. >> >> How do you tell the difference between a bug fix and an code improvement, if >> the behaviour of the program remains the same? > > If the behaviour remains *exactly* the same, then it's a code > improvement (aka a refactoring), not a bug fix. Or, looking at it > another way: if there is absolutely no change to behaviour, how could > you tell that there was a bug in it? Well obviously you fix the bug, not just refactor and keep the bug. Sorry if that wasn't clear enough. > And yes, trying to convince a customer that it's worth paying for > improvements that don't change anything visible is hard. The point of refactoring is to make it easy to fix the bug: "Two hours refactoring, plus thirty seconds to fix the bug; versus 18 hours to fix the bug without refactoring." Plus or minus six weeks on each of those times *tongue pressed firmly in cheek* But more seriously, I'm not suggesting you refactor the whole code base. You only refactor the bit you are touching *right now*. That's especially relevant for Bill's comment about loops which are hundreds of lines long. There's a bug somewhere in the loop, and finding the bug is going to take many hours. So spend half that time cleaning the loop up by factoring bits of it out (if possible!) in order to (1) understand what the loop does, and (2) simplify the debugging process. Technically its an improvement. But its not a *functional* improvement, which is what people usually mean when they say no improvements, only bug fixes. It is a code-quality improvement[1] *necessary to fix the bug*. Perhaps not strictly necessary. You could spend five times as long fixing the bug (and introducing two new ones) by *not* refactoring. Of course, I understand that sometimes there are political reasons why you can't do that, and they're not always bad reasons. But I bet that for *most* customers, if you give them the choice between: (1) Minimize the number of lines of code changed; or (2) Minimize the number of dollars on the invoice they'll usually prefer (2). Don't try to sell them on code refactoring as an investment for the future, they're not interested. Don't try to convince them that they need to reduce technical debt. Debt is something for the next generation to worry about[2]. Don't even mention refactoring. That sounds like an improvement, and they said they don't want improvements. But even the most unreasonable client will surely understand that before you can fix the bug, you have to find it, and that requires understanding the code. Cleaning up the *immediately relevant section of code* (giving variables meaningful names, extracting common functionality, etc) is part of the necessary process of understanding the code and finding the cause of the bug in the shortest possible time, and the fact that you end up with cleaner code and less technical debt at the end is a happy accident. That's not why you did it, so technically all you did was fix the bug, exactly as told. (They didn't tell you *how* to fix the bug. If they knew how, they wouldn't need you.) But, as always, this is risky if you don't have a good test suite. > Which is why > a lot of companies end up merely paying interest on their technical > debt, and never paying off any of the capital. > > ChrisA [1] Maybe. The downside of piecemeal refactoring is that sometimes it increases complexity until you pass a critical point and it starts decreasing it again. [2] And that's not always a bad thing. Debt is not always bad: its money that you can invest in building your infrastructure or startup or keeping a roof over your head until you find a job, and it makes sense to delay paying off the debt until you have a better income stream that will afford it more easily. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From tjol at tjol.eu Fri Sep 29 14:09:44 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 29 Sep 2017 20:09:44 +0200 Subject: Redirecting stdio streams with a context manager In-Reply-To: <59ce7d9f$0$14955$b1db1813$d948b532@news.astraweb.com> References: <59ce7d9f$0$14955$b1db1813$d948b532@news.astraweb.com> Message-ID: <79446608-5d9c-4891-2770-1c7da6ef9b4d@tjol.eu> On 29/09/17 19:06, Steve D'Aprano wrote: > In the standard library's contextlib.py module, there is a class for redirecting > standard I/O streams, and two public functions. The code is short enough to > reproduce here: > > # From Python 3.5 > > class _RedirectStream: > _stream = None > def __init__(self, new_target): > self._new_target = new_target > # We use a list of old targets to make this CM re-entrant > self._old_targets = [] > def __enter__(self): > self._old_targets.append(getattr(sys, self._stream)) > setattr(sys, self._stream, self._new_target) > return self._new_target > def __exit__(self, exctype, excinst, exctb): > setattr(sys, self._stream, self._old_targets.pop()) > > class redirect_stdout(_RedirectStream): > # docstring removed > _stream = "stdout" > > class redirect_stderr(_RedirectStream): > # docstring removed > _stream = "stderr" > > > > I don't understand the comment "We use a list of old targets to make this CM > re-entrant". Under what circumstances will there ever be more than a single > entry in _old_targets? This makes every *instance* re-entrant. I don't really see the point, but I think this would be a contrived example of such circumstances: redir_file1 = redirect_stdout(f1) redir_file2 = redirect_stdout(f2) with redir_file1: # do stuff with redir_file2: # Other stuff # Oh no wait actually with redir_file1: # Dum dee dum dee dum pass > > If you use the context manager twice: > > with redirect_stdout(f1) as instance1: > with redirect_stdout(f2) as instance2: > pass > > the two calls will return different instances and sys.stdout will be set as > follows: > > # before first call to redirect_stdout > sys.stdout = __stdout__ # the original setting > > # first call __enter__ > save __stdout__ in instance1._old_targets > set sys.stdout = f1 > > # second call __enter__ > save f1 in instance2._old_targets > set sys.stdout = f2 > > # second call __exit__ > restore sys.stdout = f1 > > # first call __exit__ > restore sys.stdout = __stdout__ > > > I'm not seeing why _old_targets is a list. > > > Can anyone explain? > > From rosuav at gmail.com Fri Sep 29 14:16:57 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Sep 2017 04:16:57 +1000 Subject: Spacing conventions In-Reply-To: <59ce86fe$0$14959$b1db1813$d948b532@news.astraweb.com> References: <59cc5459$0$14941$b1db1813$d948b532@news.astraweb.com> <59cdce62$0$14943$b1db1813$d948b532@news.astraweb.com> <59ce86fe$0$14959$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sat, Sep 30, 2017 at 3:46 AM, Steve D'Aprano wrote: > On Fri, 29 Sep 2017 03:01 pm, Chris Angelico wrote: > >> On Fri, Sep 29, 2017 at 2:38 PM, Steve D'Aprano >> wrote: >>> On Thu, 28 Sep 2017 03:56 pm, Bill wrote: >>> >>>> I worked in maintenance programming. You got the hand you were dealt! >>>> And you weren't allowed to "improve" the code unless the customer >>>> contracted you to do so. >>> >>> How do you tell the difference between a bug fix and an code improvement, if >>> the behaviour of the program remains the same? >> >> If the behaviour remains *exactly* the same, then it's a code >> improvement (aka a refactoring), not a bug fix. Or, looking at it >> another way: if there is absolutely no change to behaviour, how could >> you tell that there was a bug in it? > > Well obviously you fix the bug, not just refactor and keep the bug. Sorry if > that wasn't clear enough. > > >> And yes, trying to convince a customer that it's worth paying for >> improvements that don't change anything visible is hard. > > The point of refactoring is to make it easy to fix the bug: > > "Two hours refactoring, plus thirty seconds to fix the bug; versus 18 hours to > fix the bug without refactoring." > > Plus or minus six weeks on each of those times *tongue pressed firmly in cheek* > > > But more seriously, I'm not suggesting you refactor the whole code base. You > only refactor the bit you are touching *right now*. This is the easy one. You're touching this code, you improve it. That applies to most things - style issues, local variable names, whatever. You don't make sweeping changes, but when you're messing with things anyway, you can clean things up. > Don't even mention refactoring. That sounds like an improvement, and they said > they don't want improvements. > > But even the most unreasonable client will surely understand that before you can > fix the bug, you have to find it, and that requires understanding the code. > Cleaning up the *immediately relevant section of code* (giving variables > meaningful names, extracting common functionality, etc) is part of the > necessary process of understanding the code and finding the cause of the bug in > the shortest possible time, and the fact that you end up with cleaner code and > less technical debt at the end is a happy accident. That's not why you did it, > so technically all you did was fix the bug, exactly as told. > > (They didn't tell you *how* to fix the bug. If they knew how, they wouldn't need > you.) The trouble is that sometimes the refactoring doesn't pay for itself with today's bug, but it might with tomorrow's bugs. Do you spend two hours refactoring and bugfixing, or one hour just fixing the bug and coping with the mess? > But I bet that for *most* > customers, if you give them the choice between: > > (1) Minimize the number of lines of code changed; or > > (2) Minimize the number of dollars on the invoice > > they'll usually prefer (2). The improvement won't minimize the number of dollars on *this* invoice. Can you sell them a line item of "future bug fixes will take less time"? You can't put an actual figure on it ("will save 0.5 hours per fortnight for the next year"), but you know the benefit is real. That's why it's hard to sell the refactor. ChrisA From tjol at tjol.eu Fri Sep 29 14:22:25 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 29 Sep 2017 20:22:25 +0200 Subject: Line terminators in Python? In-Reply-To: References: Message-ID: <4cef727a-c9d9-7ab6-50d5-ca0e8dd14ce7@tjol.eu> On 29/09/17 19:54, Stefan Ram wrote: > In some languages, printing ?'\n'?, the Unicode code point 10, > will have the effect of printing a line terminator, which might > mean that the output device actually receives ?\r\n?. > > The line terminator ostensibly depends on the operating > system, but actually it depends on the output system. E.g., > under one operating system the console might accept another > set of line separators than an editor. (Under Windows, > ?wordpad? accepts ?\n?, while ?notepad? requires ?\r\n?.) > > What is the recommended way to terminate a line written with > Python? Is it ?\n? or something else? For example, in Java, > in some cases, one should terminate the line with the value > of ?java.lang.System.lineSeparator()? which might or might > not be equal to the value of ?"\n"?. > > Does it possibly depend on the entity being written to, which > might be > > - the Python console, > - the IDLE console, > - the operating system console or > - a text file? > Use \n. For text I/O, Python translates \n to \r\n on Windows. For binary I/O, it doesn't. (This means that it's important to specify text or binary mode in your calls to open() if you want your code to be portable). \r\n is not translated to \n on Unix. So, if you want your code to do the right thing, use \n. -- Thomas From rosuav at gmail.com Fri Sep 29 14:24:25 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Sep 2017 04:24:25 +1000 Subject: Line terminators in Python? In-Reply-To: References: Message-ID: On Sat, Sep 30, 2017 at 3:54 AM, Stefan Ram wrote: > In some languages, printing ?'\n'?, the Unicode code point 10, > will have the effect of printing a line terminator, which might > mean that the output device actually receives ?\r\n?. > > The line terminator ostensibly depends on the operating > system, but actually it depends on the output system. E.g., > under one operating system the console might accept another > set of line separators than an editor. (Under Windows, > ?wordpad? accepts ?\n?, while ?notepad? requires ?\r\n?.) > > What is the recommended way to terminate a line written with > Python? Is it ?\n? or something else? For example, in Java, > in some cases, one should terminate the line with the value > of ?java.lang.System.lineSeparator()? which might or might > not be equal to the value of ?"\n"?. > > Does it possibly depend on the entity being written to, which > might be > > - the Python console, > - the IDLE console, > - the operating system console or > - a text file? > Always use "\n". In the event that you actually need "\r\n", transform that on output. In effect, you can treat "Windows-style newlines" vs "POSIX-style newlines" as a form of text encoding, to be dealt with at boundary locations only; when you read a file, you clean up the newlines, and when you write, you *might* transform them. Notepad sucks, so don't do things just for its sake; but certain network protocols stipulate carriage return/line feed as their end-of-line. HTTP, for instance, is clearly specified as such in RFC 2616 [1] - section 19.3 recommends that "\n" be accepted for the sake of interoperability, but the official line ending is CR LF. So if you're writing to a socket, you might do a two-step process of transforming newlines and also encoding UTF-8, but inside the application, keep everything as Unicode text with "\n" between lines. ChrisA [1] https://www.ietf.org/rfc/rfc2616.txt From kwpolska at gmail.com Fri Sep 29 14:26:52 2017 From: kwpolska at gmail.com (Chris Warrick) Date: Fri, 29 Sep 2017 20:26:52 +0200 Subject: Line terminators in Python? In-Reply-To: References: Message-ID: On 29 September 2017 at 19:54, Stefan Ram wrote: > In some languages, printing ?'\n'?, the Unicode code point 10, > will have the effect of printing a line terminator, which might > mean that the output device actually receives ?\r\n?. > > The line terminator ostensibly depends on the operating > system, but actually it depends on the output system. E.g., > under one operating system the console might accept another > set of line separators than an editor. (Under Windows, > ?wordpad? accepts ?\n?, while ?notepad? requires ?\r\n?.) > > What is the recommended way to terminate a line written with > Python? Is it ?\n? or something else? For example, in Java, > in some cases, one should terminate the line with the value > of ?java.lang.System.lineSeparator()? which might or might > not be equal to the value of ?"\n"?. > > Does it possibly depend on the entity being written to, which > might be > > - the Python console, > - the IDLE console, > - the operating system console or > - a text file? It depends on the mode used to open the output file. https://docs.python.org/3/library/functions.html#open sys.stdout is opened in 'w' mode by default (writing, text mode). Text mode means that non-Unix newlines (\r\n, \r) are translated to '\n' when reading, and '\n' is translated to the system local newline when writing. So, if you?re working in text mode (which also handles encodings and returns Unicode strings on Python 3), you can just assume '\n'. If you?re curious what the local newline is, look at os.linesep: https://docs.python.org/3/library/os.html#os.linesep -- Chris Warrick PGP: 5EAAEA16 From rgaddi at highlandtechnology.invalid Fri Sep 29 14:38:55 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Fri, 29 Sep 2017 11:38:55 -0700 Subject: Line terminators in Python? In-Reply-To: References: Message-ID: On 09/29/2017 10:54 AM, Stefan Ram wrote: > In some languages, printing ?'\n'?, the Unicode code point 10, > will have the effect of printing a line terminator, which might > mean that the output device actually receives ?\r\n?. > > The line terminator ostensibly depends on the operating > system, but actually it depends on the output system. E.g., > under one operating system the console might accept another > set of line separators than an editor. (Under Windows, > ?wordpad? accepts ?\n?, while ?notepad? requires ?\r\n?.) > > What is the recommended way to terminate a line written with > Python? Is it ?\n? or something else? For example, in Java, > in some cases, one should terminate the line with the value > of ?java.lang.System.lineSeparator()? which might or might > not be equal to the value of ?"\n"?. > > Does it possibly depend on the entity being written to, which > might be > > - the Python console, > - the IDLE console, > - the operating system console or > - a text file? > As everyone else has said; for general purpose (any of your cases) use you should always just use '\n' and it automagically works. The only time I've ever needed to explicitly worry about '\r' is communicating over sockets or serial ports to devices. And in those cases you need to stuff them with bytes rather than str anyhow, so you're already down in the gory bits. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From __peter__ at web.de Fri Sep 29 14:49:15 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 29 Sep 2017 20:49:15 +0200 Subject: Redirecting stdio streams with a context manager References: <59ce7d9f$0$14955$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > In the standard library's contextlib.py module, there is a class for > redirecting standard I/O streams, and two public functions. The code is > short enough to reproduce here: > > # From Python 3.5 > > class _RedirectStream: > _stream = None > def __init__(self, new_target): > self._new_target = new_target > # We use a list of old targets to make this CM re-entrant > self._old_targets = [] > def __enter__(self): > self._old_targets.append(getattr(sys, self._stream)) > setattr(sys, self._stream, self._new_target) > return self._new_target > def __exit__(self, exctype, excinst, exctb): > setattr(sys, self._stream, self._old_targets.pop()) > > class redirect_stdout(_RedirectStream): > # docstring removed > _stream = "stdout" > > class redirect_stderr(_RedirectStream): > # docstring removed > _stream = "stderr" > > > > I don't understand the comment "We use a list of old targets to make this > CM re-entrant". Under what circumstances will there ever be more than a > single entry in _old_targets? > > If you use the context manager twice: > > with redirect_stdout(f1) as instance1: > with redirect_stdout(f2) as instance2: > pass That's the sane approach, but I just learned that you can reuse a single instance: >>> here = io.StringIO() >>> there = io.StringIO() >>> h = redirect_stdout(here) >>> t = redirect_stdout(there) >>> with h: ... print("ham") ... with t: ... print("foo") ... with h: ... print("spam") ... with t: ... print("bar") ... >>> here.getvalue() 'ham\nspam\n' >>> there.getvalue() 'foo\nbar\n' From BILL_NOSPAM at whoknows.net Fri Sep 29 15:14:47 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Fri, 29 Sep 2017 15:14:47 -0400 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> <59cdf31b$0$14970$b1db1813$d948b532@news.astraweb.com> <59ce77fb$0$14951$b1db1813$d948b532@news.astraweb.com> Message-ID: Chris Angelico wrote: > On Sat, Sep 30, 2017 at 2:42 AM, Steve D'Aprano > wrote: >> Oh, and I'd like to make a (moderate) defense of a kind of "bug fixing by random >> perturbation". Obviously making unrelated, arbitrary changes to code is bad. >> But making non-arbitrary but not fully understood changes to relevant code >> sections can be useful in (at least) two scenarios. >> >> (1) I know there's a bug in a specific chunk of code, but I'm having trouble >> working out where. When everything else fails, if I perturb the code a bit >> (reorder lines, calculate things in a different order, rename variables, etc) >> it may change the nature of the bug enough for me to understand what's >> happening. >> >> That's not *random* or *arbitrary* changes, but they are changes not directed at >> any specific outcome other than "make the code a bit different, and see if the >> error changes". I'd like to say it is the debugging technique of last resort, >> except its perhaps not quite as *last* resort as I'd like, especially in code >> I'm not familiar with. >> >> Its an experiment, but not really "carefully designed". I'll write for the possible benefit of any beginners who may be reading. I guess by definition, if one still has a "bug" it's because one doesn't quite understand what the code is doing. And I would say you should lose your license if you "fix something", and don't understand why it works (within reason of course--some mystery's of library functions should probably remain so forever). So ADT (Any Damn Thing--I just made that up that acronym) you can do to understand your code better is fair game! : ) In fact, in my experience, the sooner you start getting a little bit angry, the sooner you'll get to the heart of matter. Usually, what looks like a long route, isn't, in the end. Don't be afraid to write *really descriptive* output statements, and do so even though you "don't need to". Besides for making you more productive, it will help soothe you : ) Beginners almost never need to... I think that getting out of the beginner phase requires developing a certain amount of humility. Just wait 5 or 10 years, any look back, and see if what I've written isn't more true than false. The only part I am unsure of is whether you are supposed to get a little big angry or not (YMMV). I find 2 cups of coffee about right. That is, 2 before and 2 after lunch. Of course, that does not include "meetings". From rosuav at gmail.com Fri Sep 29 15:27:35 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 30 Sep 2017 05:27:35 +1000 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> <59cdf31b$0$14970$b1db1813$d948b532@news.astraweb.com> <59ce77fb$0$14951$b1db1813$d948b532@news.astraweb.com> Message-ID: On Sat, Sep 30, 2017 at 5:14 AM, Bill wrote: > I'll write for the possible benefit of any beginners who may be reading. I > guess by definition, if one still has a "bug" it's because one doesn't quite > understand what the code is doing. And I would say you should lose your > license if you "fix something", and don't understand why it works (within > reason of course--some mystery's of library functions should probably remain > so forever). My programmer's license comes from MIT and it can't be lost. https://opensource.org/licenses/MIT Kappa ChrisA From thrasibule.jimmy at gmail.com Fri Sep 29 18:52:33 2017 From: thrasibule.jimmy at gmail.com (Jimmy Thrasibule) Date: Sat, 30 Sep 2017 00:52:33 +0200 Subject: Distributing multiple packages with on setup.py Message-ID: Hi, I've reorganized my Python project to be under a same name umbrella. My project can now be seen as multiple subsystems than can depend on each other. That means that every sub-package can now be distributed alone so that only required dependencies can be installed. The old structure: / ?? myproj/ ? ?? __init__.py ? ?? mod1.py ? ?? subpackage1/ ? ?? subpackage2/ ?? setup.py The new structure: / ?? myproj/ ? ?? common/ ? ? ?? mod1.py ? ?? subpackage1/ ? ?? subpackage2/ ? ?? __init__.py ?? setup.py As you can see not much has changed except that `myproj` is now a `namespace package `_ and that sub-packages ``common``, ``subpackage1`` and ``subpackage2`` can now be distributed independently. Is it possible, still keeping one unique ``setup.py`` file, to create 3 independent packages? * ``myproj.common`` * ``myproj.subpackage1`` * ``myproj.subpackage2`` Also I'd like to specify that when installing ``myproj.subpackage1``, ``myproj.common`` is required or that ``myproj.subpackage2`` will require both ``myproj.common`` and ``myproj.subpackage1``. Regards, Jimmy From greg.ewing at canterbury.ac.nz Fri Sep 29 21:27:31 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 30 Sep 2017 14:27:31 +1300 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: <59ce77fb$0$14951$b1db1813$d948b532@news.astraweb.com> References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> <59cdf31b$0$14970$b1db1813$d948b532@news.astraweb.com> <59ce77fb$0$14951$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > (1) I know there's a bug in a specific chunk of code, but I'm having trouble > working out where. When everything else fails, if I perturb the code a bit > (reorder lines, calculate things in a different order, rename variables, etc) > it may change the nature of the bug enough for me to understand what's > happening. > Its an experiment, but not really "carefully designed". I think it's more carefully designed than you give it credit for. You still need to understand quite a lot about the program to know what changes are likely to yield useful information, and how to interpret the results. > Its more like "what > happens if we hit this bit with a hammer?" In biology it's called a "shotgun experiment". "If we blast this bit of DNA with radiation, what part of the organism does it mess up?" > (2) I hate off by one errors, and similar finicky errors that mean your code is > *almost* right. I especially hate them when I'm not sure which direction I'm > off by one. If you have unit tests that are failing, sometimes its quicker and > easier to randomly perturb the specific piece of code until you get the right > answer, rather than trying to analyse it. With off-by-one errors it's still pretty specific -- start the loop at 1 instead of 0, etc. But in cases like that I prefer to rewrite the code so that it's obvious where it should start and finish. > The complexity of code increases faster than our ability to manage that > complexity. And then there's "If you write the code as cleverly as you can, you won't be smart enough to debug it!" -- Greg From greg.ewing at canterbury.ac.nz Fri Sep 29 21:42:25 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 30 Sep 2017 14:42:25 +1300 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> <59cdf31b$0$14970$b1db1813$d948b532@news.astraweb.com> <59ce77fb$0$14951$b1db1813$d948b532@news.astraweb.com> Message-ID: Bill wrote: > Don't be afraid to write *really descriptive* output statements, and do > so even though you "don't need to". Yeah, often when I'm writing something tricky I'll proactively put in some code to print intermediate state to reassure myself that things are on track. Being more verbose with them than I think necessary can save a few trips around the debug cycle. -- Greg From walters.justin01 at gmail.com Fri Sep 29 22:12:02 2017 From: walters.justin01 at gmail.com (justin walters) Date: Fri, 29 Sep 2017 19:12:02 -0700 Subject: Beginners and experts (Batchelder blog post) In-Reply-To: References: <0be38321-de1b-1124-7d08-b511b1d8e9d7@gmail.com> <59cdf31b$0$14970$b1db1813$d948b532@news.astraweb.com> <59ce77fb$0$14951$b1db1813$d948b532@news.astraweb.com> Message-ID: On Fri, Sep 29, 2017 at 12:14 PM, Bill wrote: > > I'll write for the possible benefit of any beginners who may be reading. > I guess by definition, if one still has a "bug" it's because one doesn't > quite understand what the code is doing. And I would say you should lose > your license if you "fix something", and don't understand why it works > (within reason of course--some mystery's of library functions should > probably remain so forever). So ADT (Any Damn Thing--I just made that up > that acronym) you can do to understand your code better is fair game! : ) > In fact, in my experience, the sooner you start getting a little bit > angry, the sooner you'll get to the heart of matter. Usually, what looks > like a long route, isn't, in the end. Don't be afraid to write *really > descriptive* output statements, and do so even though you "don't need to". > Besides for making you more productive, it will help soothe you : ) > Beginners almost never need to... I think that getting out of the > beginner phase requires developing a certain amount of humility. Just wait > 5 or 10 years, any look back, and see if what I've written isn't more true > than false. > > The only part I am unsure of is whether you are supposed to get a little > big angry or not (YMMV). I find 2 cups of coffee about right. That is, 2 > before and 2 after lunch. Of course, that does not include "meetings". > -- > https://mail.python.org/mailman/listinfo/python-list > Reminds me of a bug I had to chase down recently. I've been working on the front-end of this web application for a while. It's an SPA built with Vuejs. The bug arose in the login workflow. Basically, it went like this: client loads login screen -> user enters credentials into form and submits -> client sends credentials to server -> server verifies credentials -> server sends back auth token -> client receives auth token and stores it -> client redirects user to home screen -> home screen makes get request for some data Now, this worked perfectly fine everywhere except for Safari 9.1 on OSX. A user could login just fine on Safari 9.1, but after that, no requests would complete. Safari's dev tools were no help because they were not showing any errors or any failed requests. I checked the server logs and found that no requests were even sent. It took me 2 days to figure out this bug. I tracked it down to the function that injected the authorization header into all requests if the user was logged in. Based on troubleshooting, I knew it couldn't be anything else. That said, I was still confused because this worked on literally every other browser(even IE 9). After searching for people with similar problems and coming up with nothing I got to thinking about the asynchronous nature of JS. So, out of sheer frustration I moved the line of code that stored the auth token from one function to another, booted up my testing environment, and it worked. So, the bug was basically because Safari was waiting for a specific function call to complete before it committed the token to local storage even though the line of code that did so was within said function. So, two days worth of work to move a single line of code from one function to another. You can only imagine the tirade of curse words directed at apple during the above calamity. Had I simply written a console log for every function down the chain, I may have been able to find the cause of the bug more quickly. From abusayem12143 at gmail.com Sat Sep 30 02:00:44 2017 From: abusayem12143 at gmail.com (abusayem12143 at gmail.com) Date: Fri, 29 Sep 2017 23:00:44 -0700 (PDT) Subject: Solution Manual Test Bank for Financial and Managerial Accounting for MBAs 5th Edition by Easton In-Reply-To: <38202c95-45e3-435d-b4f9-1099e71de542@googlegroups.com> References: <38202c95-45e3-435d-b4f9-1099e71de542@googlegroups.com> Message-ID: On Thursday, June 29, 2017 at 6:04:07 AM UTC-4, Test Banks wrote: > Greetings Students, > > We do have Solution Manuals and Test Bank for FINANCIAL AND MANAGERIAL ACCOUNTING FOR MBAs 5TH EDITION BY EASTON at reasonable price. You can get above mentioned resources by sending email to pro.fast(@)hotmail(dot)com > > Send your order queries at PRO.FAST(@)HOTMAIL(DOT)COM > > Below are details given for this book > > Book Name: FINANCIAL AND MANAGERIAL ACCOUNTING FOR MBAs > Authors: Peter D. Easton, Robert F. Halsey, Mary Lea McAnally, Al L. Hartgraves, Wayne J. Morse > Edition: 5th E > ISBN-10: 1618532324 > ISBN-13: 9781618532329 > Product Format: MS Word > Total Modules: 25 > > Please mention complete details for your book so we could send you sample accordingly. > > Best Regards, > > P.S : Please do not post your reply here. We do not monitor queries here. Simply send us an email directly to PRO.FAST (@) HOTMAIL (DOT) COM From dieter at handshake.de Sat Sep 30 02:11:09 2017 From: dieter at handshake.de (dieter) Date: Sat, 30 Sep 2017 08:11:09 +0200 Subject: Distributing multiple packages with on setup.py References: Message-ID: <87mv5cra0y.fsf@handshake.de> Jimmy Thrasibule writes: > ... > Is it possible, still keeping one unique ``setup.py`` file, to create > 3 independent packages? > > * ``myproj.common`` > * ``myproj.subpackage1`` > * ``myproj.subpackage2`` > > Also I'd like to specify that when installing ``myproj.subpackage1``, > ``myproj.common`` is required or that ``myproj.subpackage2`` will > require both ``myproj.common`` and ``myproj.subpackage1``. Yes - in principal - but ... the "setup.py" essentially contains the "setup" function call and this call needs package specific parameter values (e.g. the package name, the package dependencies, ...). If you want a single "setup.py", this "setup.py" must use some (potentially sophisticated) logic to determine those package specific parameters and select (depending on the context) which parameter set to pass on to the "setup" function call. Personally, I never want interested in this approach. From pavol.lisy at gmail.com Sat Sep 30 04:45:29 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Sat, 30 Sep 2017 10:45:29 +0200 Subject: Line terminators in Python? In-Reply-To: References: Message-ID: On 9/29/17, Rob Gaddi wrote: > On 09/29/2017 10:54 AM, Stefan Ram wrote: >> In some languages, printing ?'\n'?, the Unicode code point 10, >> will have the effect of printing a line terminator, which might >> mean that the output device actually receives ?\r\n?. >> >> The line terminator ostensibly depends on the operating >> system, but actually it depends on the output system. E.g., >> under one operating system the console might accept another >> set of line separators than an editor. (Under Windows, >> ?wordpad? accepts ?\n?, while ?notepad? requires ?\r\n?.) >> >> What is the recommended way to terminate a line written with >> Python? Is it ?\n? or something else? For example, in Java, >> in some cases, one should terminate the line with the value >> of ?java.lang.System.lineSeparator()? which might or might >> not be equal to the value of ?"\n"?. >> >> Does it possibly depend on the entity being written to, which >> might be >> >> - the Python console, >> - the IDLE console, >> - the operating system console or >> - a text file? >> > > As everyone else has said; for general purpose (any of your cases) use > you should always just use '\n' and it automagically works. The only > time I've ever needed to explicitly worry about '\r' is communicating > over sockets or serial ports to devices. And in those cases you need to > stuff them with bytes rather than str anyhow, so you're already down in > the gory bits. > > -- > Rob Gaddi, Highland Technology -- www.highlandtechnology.com There is also https://docs.python.org/3/library/csv.html#csv.Dialect.lineterminator which (I think) come from RFC4180 (see http://www.rfc-archive.org/getrfc.php?rfc=4180 search CRLF) http://www.rfc-archive.org/getrfc.php?rfc=2046 could be also interesting in this case. From tjol at tjol.eu Sat Sep 30 06:17:48 2017 From: tjol at tjol.eu (Thomas Jollans) Date: Sat, 30 Sep 2017 12:17:48 +0200 Subject: The mysterious ways of Python mailing list In-Reply-To: References: Message-ID: On 29/09/17 19:15, Vincent Vande Vyvre wrote: > Is it a reason why my messages appears always a long time (today 9 > hours) on the list after I send it ? > > Send at 19:14 UTC+2 > > > Vincent > Some of my messages take about an hour. From looking at the headers in these cases, it looks like the delay is always before the message is received (i.e., accepted) by mail.python.org. This looks like greylisting. I have no idea why messages "from" regular list users coming through large, reputable ISPs would be regularly greylisted, but I suppose what will be will be. -- Thomas From skip.montanaro at gmail.com Sat Sep 30 07:28:26 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 30 Sep 2017 06:28:26 -0500 Subject: The mysterious ways of Python mailing list In-Reply-To: References: Message-ID: Some of my messages take about an hour. From looking at the headers in these cases, it looks like the delay is always before the message is received (i.e., accepted) by mail.python.org. This looks like greylisting. Yes, greylisting is one of the anti-spam arrows in the wider on mail.python.org. However, once your email address has passed that threshold, new messages from the same address should float through without delay. If you have one such message and have the ability to save the entire original message and all headers to a file (i.e., not Outlook), you might want to send it to postmaster at python.org for one of the smart folks there to investigate. Skip From mail at timgolden.me.uk Sat Sep 30 07:46:19 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Sat, 30 Sep 2017 12:46:19 +0100 Subject: The mysterious ways of Python mailing list In-Reply-To: References: Message-ID: On 29/09/2017 18:15, Vincent Vande Vyvre wrote: > Is it a reason why my messages appears always a long time (today 9 > hours) on the list after I send it ? Vincent, Your address is being caught in our moderation traps for some reason. At the moment I'm away and on-line less than usual. Perhaps the other moderators are likewise less available. So it took a while for anyone to get to your post. Often (especially on a working day) we'll get to a held post within minutes. I'm not sure why you're being held; I'll try to see which filter you're tripping. Please do keep posting! TJG From mal at europython.eu Sat Sep 30 10:54:59 2017 From: mal at europython.eu (M.-A. Lemburg) Date: Sat, 30 Sep 2017 16:54:59 +0200 Subject: The EuroPython Podcast Episode 1 Message-ID: <3f15d830-26d2-fe07-b4e1-d7298c013f54@europython.eu> We are happy to announce a new format our Media Workgroup is experimenting with: The EuroPython Podcast ---------------------- The podcast intends to be a view on the European Python community. We will comment and talk about the latest news from the EuroPython Society last news, interview guests from the European Python community and discuss future Python events in Europe ? and probably more (ideas are always welcome). * EuroPython Podcast Episode 1: RFP & Lasse Schuirmann * http://blog.europython.eu/post/165899153782/the-europython-podcast-episode-1 In this podcast we discussed about the Venue Request For Proposal (RFP) for EuroPython 2018, what venues we should aim for? How about a EuroPython 2018 Disneyland Paris? Helping with the podcast ------------------------ If you want to join the podcast as collaborator, nominate someone to be our next guest, announce your local python conference or/and give us feedback, please send an email to media-wg at europython.eu Many thanks. Enjoy, -- EuroPython Media Workgroup Team http://europython.eu/ http://www.europython-society.org/ From liik.joonas at gmail.com Sat Sep 30 14:31:10 2017 From: liik.joonas at gmail.com (Joonas Liik) Date: Sat, 30 Sep 2017 21:31:10 +0300 Subject: I'd like to use "semantic indentation" In-Reply-To: References: Message-ID: On 30 September 2017 at 21:12, Stefan Ram wrote: > I would like to write source code similar to: > > country( 'USA' ) > state( 'Alabama' ) > town( 'Abbeville' ) > town( 'Addison' ) > state( 'Arizona' ) > town( 'Apache Junction' ) > town( 'Avondale ) > town( 'Benson' ) > > you can't get off quite as clean without sth like macropy.. but you can get close with custom contextmanagers. with country( 'USA' ): with state( 'Alabama' ): town( 'Abbeville' ) town( 'Addison' ) of course you need to write the contextmanager yourself.. and need to decide what the topmost level contextmanager will operate on unless you want to do sth .. .probably quite nasty From no.email at nospam.invalid Sat Sep 30 14:39:07 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 30 Sep 2017 11:39:07 -0700 Subject: I'd like to use "semantic indentation" References: Message-ID: <87r2uorpys.fsf@nightsong.com> ram at zedat.fu-berlin.de (Stefan Ram) writes: > I would like to write source code similar to: > country( 'USA' ) > state( 'Alabama' ) ... > It seems I can't do this with Python. Is there any workaround? _= country( 'USA' ) _= state( 'Alabama' ) _= town( 'Abbeville' ) _= town( 'Addison' ) _= state( 'Arizona' ) _= town( 'Apache Junction' ) _= town( 'Avondale ) _= town( 'Benson' ) From no.email at nospam.invalid Sat Sep 30 14:42:12 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 30 Sep 2017 11:42:12 -0700 Subject: I'd like to use "semantic indentation" References: Message-ID: <87k20grptn.fsf@nightsong.com> ram at zedat.fu-berlin.de (Stefan Ram) writes: > I would like to write source code similar to: > country( 'USA' ) > state( 'Alabama' ) Aside from the workaround that I mentioned, this looks more like data than code. Maybe you really want to create a nested structure (dictionaries, JSON, XML or whatever) and traverse it. From rosuav at gmail.com Sat Sep 30 14:58:14 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Oct 2017 05:58:14 +1100 Subject: I'd like to use "semantic indentation" In-Reply-To: References: Message-ID: On Sun, Oct 1, 2017 at 5:12 AM, Stefan Ram wrote: > I would like to write source code similar to: > > country( 'USA' ) > state( 'Alabama' ) > town( 'Abbeville' ) > town( 'Addison' ) > state( 'Arizona' ) > town( 'Apache Junction' ) > town( 'Avondale ) > town( 'Benson' ) > > using "semantic indentation". > > It seems I can't do this with Python. > > Is there any workaround? If the indentation has semantic significance, you shouldn't need to say "country" or "state" or "town". I suggest this format: USA: Alabama: Abbeville Addison Arizona: Apache Junction Avondale Benson and then, as Paul suggested, write a simple parser to read it. ChrisA From bc at freeuk.com Sat Sep 30 15:14:01 2017 From: bc at freeuk.com (bartc) Date: Sat, 30 Sep 2017 20:14:01 +0100 Subject: I'd like to use "semantic indentation" In-Reply-To: References: Message-ID: On 30/09/2017 19:12, Stefan Ram wrote: > I would like to write source code similar to: > > country( 'USA' ) > state( 'Alabama' ) > town( 'Abbeville' ) > town( 'Addison' ) > state( 'Arizona' ) > town( 'Apache Junction' ) > town( 'Avondale ) > town( 'Benson' ) > > using "semantic indentation". > > It seems I can't do this with Python. > > Is there any workaround? def country(x): print("C:",x) def state(x): print("S:",x) def town(x): print("T:",x) def fn(*a): pass fn( country( 'USA' ), state( 'Alabama' ), town( 'Abbeville' ), town( 'Addison' ), state( 'Arizona' ), town( 'Apache Junction' ), town( 'Avondale' ), town( 'Benson' ) ) This pretends they are arguments to a dummy function. But it probably won't work with anything that isn't also an expression. -- bartc From stephanh42 at gmail.com.invalid Sat Sep 30 16:09:57 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 30 Sep 2017 20:09:57 GMT Subject: merits of Lisp vs Python References: Message-ID: Op 2017-09-27, Robert L. schreef : > (sequence-fold + 0 #(2 3 4)) > ===> > 9 > > In Python? >>> sum([2, 3, 4]) 9 From stephanh42 at gmail.com.invalid Sat Sep 30 16:23:08 2017 From: stephanh42 at gmail.com.invalid (Stephan Houben) Date: 30 Sep 2017 20:23:08 GMT Subject: LOOP with fixed final index value References: Message-ID: Op 2017-09-27, Robert L. schreef : >> > (defun myloop (initial final increment) >> > (loop for i = initial then (+ i increment) >> > while (< i final) >> > do (print i) >> > finally (let ((i final)) (print i)))) >> > > In Python? myloop = lambda *args: print("{}{}".format("".join(map("{}\n".format, range(*args))), args[1])) Of course. From breamoreboy at gmail.com Sat Sep 30 16:40:36 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sat, 30 Sep 2017 13:40:36 -0700 (PDT) Subject: merits of Lisp vs Python In-Reply-To: References: Message-ID: <348816c2-1290-4f65-87f7-a31ca21c5135@googlegroups.com> On Saturday, September 30, 2017 at 9:03:32 PM UTC+1, Stephan Houben wrote: > Op 2017-09-27, Robert L. schreef : > > (sequence-fold + 0 #(2 3 4)) > > ===> > > 9 > > > > In Python? > > >>> sum([2, 3, 4]) > 9 Dow you have to keep replying to this out and out racist, as none of his posts have any relevance to Python? -- Kindest regards. Mark Lawrence. From marko at pacujo.net Sat Sep 30 16:46:19 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sat, 30 Sep 2017 23:46:19 +0300 Subject: merits of Lisp vs Python References: Message-ID: <87mv5bewys.fsf@elektro.pacujo.net> Stephan Houben : > Op 2017-09-27, Robert L. schreef : >> (sequence-fold + 0 #(2 3 4)) >> ===> >> 9 >> >> In Python? > >>>> sum([2, 3, 4]) > 9 Robert L. is only trolling. He uses fake technical comments to spread white supremacy in his signatures. Marko From BILL_NOSPAM at whoknows.net Sat Sep 30 17:47:20 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Sat, 30 Sep 2017 17:47:20 -0400 Subject: newb question about @property Message-ID: I spent a few hours experimenting with @property. To my mind it seems like it would be preferable to just define (override) instance methods __get__(), __set__(), and possibly __del__(), as desired, as I could easily provide them with "ideal" customization. Am I overlooking something? Bill From ned at nedbatchelder.com Sat Sep 30 18:03:03 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 30 Sep 2017 18:03:03 -0400 Subject: newb question about @property In-Reply-To: References: Message-ID: <94bc6115-6321-58db-6bab-21ba4e49cdfc@nedbatchelder.com> On 9/30/17 5:47 PM, Bill wrote: > I spent a few hours experimenting with @property. To my mind it seems > like it would be preferable to just define (override) instance methods > __get__(), __set__(), and possibly __del__(), as desired, as I could > easily provide them with "ideal" customization. Am I overlooking > something? > It would be easier to comment if you showed the two options. One with @property, and one with __get__ etc. A downside to __get__ is that you need to create a class with those methods, and then instantiate that class as an attribute in your real class, whereas @property can be used without a lot of rigamarole. --Ned. From cs at cskk.id.au Sat Sep 30 18:09:13 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 1 Oct 2017 09:09:13 +1100 Subject: Distributing multiple packages with on setup.py In-Reply-To: References: Message-ID: <20170930220913.GA45820@cskk.homeip.net> On 30Sep2017 00:52, Jimmy Thrasibule wrote: >I've reorganized my Python project to be under a same name umbrella. >My project can now be seen as multiple subsystems than can depend on >each other. That means that every sub-package can now be distributed >alone so that only required dependencies can be installed. [...] >The new structure: > ?? myproj/ > ? ?? common/ > ? ? ?? mod1.py > ? ?? subpackage1/ > ? ?? subpackage2/ > ? ?? __init__.py > ?? setup.py > > >As you can see not much has changed except that `myproj` is now a >`namespace package >`_ >and that sub-packages ``common``, ``subpackage1`` and ``subpackage2`` >can now be distributed independently. > >Is it possible, still keeping one unique ``setup.py`` file, to create >3 independent packages? > >* ``myproj.common`` >* ``myproj.subpackage1`` >* ``myproj.subpackage2`` > >Also I'd like to specify that when installing ``myproj.subpackage1``, >``myproj.common`` is required or that ``myproj.subpackage2`` will >require both ``myproj.common`` and ``myproj.subpackage1``. I do this with my stuff, but instead of keeping a common setup.py I have an elaborate and clumsy system that rolls a package or module distro on the fly, writing a setup.py file in the process. So each package/module I publish has a dict names "DISTINFO" in the top level file, looking like this: DISTINFO = { 'keywords': ["python2", "python3"], 'classifiers': [ "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", ], 'install_requires': [ 'cs.app.flag', 'cs.env', 'cs.logutils', 'cs.pfx', 'cs.psutils', ], 'entry_points': { 'console_scripts': [ 'svcd = cs.app.svcd:main' ], }, } This gets fleshed out with a README file containing the module docstring etc. So instead of tediously maintaining some uber setup.py I roll a distribution directory suitably filled and push that. This lets me keep the code in a nice shared tree like yours without a heap of setup.py files. Then I have a script to push the latest tagged revision of the module; it makes a scratch directory, checks out the relevant files as of the release tag, makes the setup.py and README etc, pushes it, then tossed the scratch directory. I keep a tag for each module release, eg: cs.app.svcd 20170906 for the above. A more published module accrues more tags: cs.app.megacli 20150118 cs.app.megacli 20150118.2 cs.app.megacli 20150118.3 cs.app.megacli 20150118.4 cs.app.megacli 20150118.5 cs.app.megacli 20150801 cs.app.megacli 20150801.1 cs.app.megacli 20160225 cs.app.megacli 20160226 cs.app.megacli 20160310 The release script looks for the latest one. Note that this is all one code repo at my end; the script knows how to assemble just the relevant files for a particular module. Cheers, Cameron Simpson (formerly cs at zip.com.au) From steve+python at pearwood.info Sat Sep 30 19:03:16 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 01 Oct 2017 10:03:16 +1100 Subject: newb question about @property References: Message-ID: <59d022b7$0$14927$b1db1813$d948b532@news.astraweb.com> On Sun, 1 Oct 2017 08:47 am, Bill wrote: > I spent a few hours experimenting with @property. To my mind it seems > like it would be preferable to just define (override) instance methods > __get__(), __set__(), and possibly __del__(), as desired, as I could > easily provide them with "ideal" customization. Am I overlooking something? Probably. This is a particularly simple example, with only getters. How would you write it by overriding __get__? class Circle(object): def __init__(self, centre, radius): self.centre = centre self.radius = radius @property def diameter(self): return 2*self.radius @property def area(self): return pi*self.radius**2 @property def circumference(self): return pi*self.diameter -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From BILL_NOSPAM at whoknows.net Sat Sep 30 19:18:11 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Sat, 30 Sep 2017 19:18:11 -0400 Subject: newb question about @property In-Reply-To: References: <94bc6115-6321-58db-6bab-21ba4e49cdfc@nedbatchelder.com> Message-ID: Ned Batchelder wrote: > On 9/30/17 5:47 PM, Bill wrote: >> I spent a few hours experimenting with @property. To my mind it seems >> like it would be preferable to just define (override) instance >> methods __get__(), __set__(), and possibly __del__(), as desired, as >> I could easily provide them with "ideal" customization. Am I >> overlooking something? >> > > It would be easier to comment if you showed the two options. One with > @property, and one with __get__ etc. > > A downside to __get__ is that you need to create a class with those > methods, and then instantiate that class as an attribute in your real > class, whereas @property can be used without a lot of rigamarole. > > --Ned. I am basically mimmicking what I see at (the very bottom of) this page: https://www.programiz.com/python-programming/property Thanks, Bill From dvl at psu.edu Sat Sep 30 19:42:51 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Sat, 30 Sep 2017 19:42:51 -0400 Subject: Beginners and experts In-Reply-To: mailman.40.1506787205.9099.python-list@python.org References: Message-ID: <1506814971l.17170546l.0l@psu.edu> Not in response to any particular note, but to the thread as a whole. Regarding how beginners make tweaks and changes at random, hoping that the bug will disappear, where experts tend to be a bit more methodical in their bug-fixing. Here at academia I have taught a little bit of partial correctness, using assertions and what-not to determine whether the code is correct using mathematical proof techniques. And then I would ask a test question for them to apply those proof techniques to a perfectly good function, which contains no errors of any kind. And invariably I get those answers that randomly perturb the code instead. Roger Christman Pennsylvania State University From ned at nedbatchelder.com Sat Sep 30 19:51:16 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 30 Sep 2017 19:51:16 -0400 Subject: newb question about @property In-Reply-To: References: <94bc6115-6321-58db-6bab-21ba4e49cdfc@nedbatchelder.com> Message-ID: On 9/30/17 7:18 PM, Bill wrote: > Ned Batchelder wrote: >> On 9/30/17 5:47 PM, Bill wrote: >>> I spent a few hours experimenting with @property. To my mind it >>> seems like it would be preferable to just define (override) instance >>> methods __get__(), __set__(), and possibly __del__(), as desired, as >>> I could easily provide them with "ideal" customization. Am I >>> overlooking something? >>> >> >> It would be easier to comment if you showed the two options. One with >> @property, and one with __get__ etc. >> >> A downside to __get__ is that you need to create a class with those >> methods, and then instantiate that class as an attribute in your real >> class, whereas @property can be used without a lot of rigamarole. >> >> --Ned. > > I am basically mimmicking what I see at (the very bottom of) this page: > > https://www.programiz.com/python-programming/property > Can you show us the code you are using it to mimic that? --Ned. From BILL_NOSPAM at whoknows.net Sat Sep 30 20:07:29 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Sat, 30 Sep 2017 20:07:29 -0400 Subject: newb question about @property In-Reply-To: <59d022b7$0$14927$b1db1813$d948b532@news.astraweb.com> References: <59d022b7$0$14927$b1db1813$d948b532@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > On Sun, 1 Oct 2017 08:47 am, Bill wrote: > >> I spent a few hours experimenting with @property. To my mind it seems >> like it would be preferable to just define (override) instance methods >> __get__(), __set__(), and possibly __del__(), as desired, as I could >> easily provide them with "ideal" customization. Am I overlooking something? > Probably. You and Ned are both right. Up until a few minutes ago, I wasn't thinking about a class having more than 1 attribute that I wanted to change. And now I realize that __get__ doesn't really make sense in that context (in the back of my mind was the notion that @property defined __get__, __set__ and __del__) and I allowed that to obscure my vision. I was on the verge of giving up anything to do with computers, forever. : ) BTW, your example (below) is very nice! I may have seen something similar before, but I am starting to appreciate it better now. I think all of this would have made a bit more sense (to me), if instead of just "@property", the syntax was "@property.getter". Now I am forced to ask the question, why did they use the underscore (on temperature) in the example on the bottom of this page? Is one forced to introduce new identifiers in order to define a setter? https://www.programiz.com/python-programming/property Thanks! -Bill > > This is a particularly simple example, with only getters. How would you write it > by overriding __get__? > > > class Circle(object): > def __init__(self, centre, radius): > self.centre = centre > self.radius = radius > > @property > def diameter(self): > return 2*self.radius > > @property > def area(self): > return pi*self.radius**2 > > @property > def circumference(self): > return pi*self.diameter > > > From BILL_NOSPAM at whoknows.net Sat Sep 30 20:21:45 2017 From: BILL_NOSPAM at whoknows.net (Bill) Date: Sat, 30 Sep 2017 20:21:45 -0400 Subject: newb question about @property In-Reply-To: References: <94bc6115-6321-58db-6bab-21ba4e49cdfc@nedbatchelder.com> Message-ID: Ned Batchelder wrote: > On 9/30/17 7:18 PM, Bill wrote: >> Ned Batchelder wrote: >>> On 9/30/17 5:47 PM, Bill wrote: >>>> I spent a few hours experimenting with @property. To my mind it >>>> seems like it would be preferable to just define (override) >>>> instance methods __get__(), __set__(), and possibly __del__(), as >>>> desired, as I could easily provide them with "ideal" customization. >>>> Am I overlooking something? >>>> >>> >>> It would be easier to comment if you showed the two options. One >>> with @property, and one with __get__ etc. >>> >>> A downside to __get__ is that you need to create a class with those >>> methods, and then instantiate that class as an attribute in your >>> real class, whereas @property can be used without a lot of rigamarole. >>> >>> --Ned. >> >> I am basically mimmicking what I see at (the very bottom of) this page: >> >> https://www.programiz.com/python-programming/property >> > Can you show us the code you are using it to mimic that? > > --Ned. Here it is, Ned. It's my first attempt at using classes in Python. I still have to learn how to incorporate datetime appropriately! :) import datetime # object oriented example class Employee(object): ''' This class will abstract an employee. Class date members name, a string birthday, a date object address, a string position It also has a static data member for the number of employees. ''' num_employees =0 # class data item @classmethod def get_num_employees(cls): return Employee.num_employees def __init__(self, name, birthdate, address, position): Employee.num_employees +=1 self.name = name self.birthdate = birthdate self.address = address self.position = position @property def address(self): print("**Hi from address-getter**") return self._address @address.setter def address(self, value): print("*****Hi, from address setter()!") self._address = value def __del__(self): print("******* Hi, from __del__()") ##Employee.num_employees -= 1 def __str__(self): return 'Name: {}, Born: {} \nAddress: {} \nPosition: {} \n'.\ format(self.name,self.birthdate,self.address,self.position) class SalesPerson(Employee): def __init__(self, name, bdate, addr): super().__init__(name, bdate, addr,"Salesperson") def main(): emp1 = Employee("Sam","4/30/1970","212 Elm","Programmer") emp2 = SalesPerson("Gene","5/1/79","414 Maple") ## Note: learn to use datetime.date--> str print(emp1) print(emp2) emp1.address ="230 Main Street" # call setter? print(emp1) del(emp1) print("Number of employees", Employee.get_num_employees()) print('*'*30) main()#call main() From cs at cskk.id.au Sat Sep 30 21:43:11 2017 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 1 Oct 2017 12:43:11 +1100 Subject: newb question about @property In-Reply-To: References: Message-ID: <20171001014311.GA60979@cskk.homeip.net> On 30Sep2017 20:07, Bill wrote: >think all of this would have made a bit more sense (to me), if instead of just >"@property", the syntax was "@property.getter". Perhaps, but nobody wants to type this. Also many properties are ready only, so that is the default. >Now I am forced to ask the question, why did they use the underscore (on >temperature) in the example on the bottom of this page? Is one forced to >introduce new identifiers in order to define a setter? >https://www.programiz.com/python-programming/property class Celsius: def __init__(self, temperature = 0): self._temperature = temperature [...snip...] @property def temperature(self): print("Getting value") return self._temperature @temperature.setter def temperature(self, value): if value < -273: raise ValueError("Temperat print("Setting value") self._temperature = value because the name self.temperature is taken by the property, one must store underlying values in a different name. Since the property is one to one with the actual internal value here and they're just using the setter protery to do a sanity check, they named the internal value very similarly. By using "_temperature" they (a) keep the name very similar and (b) make it clear that the internal value is "private", not intended for direct use by code outside the class. Cheers, Cameron Simpson (formerly cs at zip.com.au) From python at mrabarnett.plus.com Sat Sep 30 21:44:58 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 1 Oct 2017 02:44:58 +0100 Subject: newb question about @property In-Reply-To: References: <59d022b7$0$14927$b1db1813$d948b532@news.astraweb.com> Message-ID: <951412ed-abf8-c927-d5cc-cb0ec3cb2eb4@mrabarnett.plus.com> On 2017-10-01 01:07, Bill wrote: > Steve D'Aprano wrote: >> On Sun, 1 Oct 2017 08:47 am, Bill wrote: >> >>> I spent a few hours experimenting with @property. To my mind it seems >>> like it would be preferable to just define (override) instance methods >>> __get__(), __set__(), and possibly __del__(), as desired, as I could >>> easily provide them with "ideal" customization. Am I overlooking something? >> Probably. > > You and Ned are both right. Up until a few minutes ago, I wasn't > thinking about a class having more than 1 attribute that I wanted to > change. And now I realize that __get__ doesn't really make sense in > that context (in the back of my mind was the notion that @property > defined __get__, __set__ and __del__) and I allowed that to obscure my > vision. I was on the verge of giving up anything to do with computers, > forever. : ) > > BTW, your example (below) is very nice! I may have seen something > similar before, but I am starting to appreciate it better now. I think > all of this would have made a bit more sense (to me), if instead of just > "@property", the syntax was "@property.getter". Now I am forced to ask > the question, why did they use the underscore (on temperature) in the > example on the bottom of this page? Is one forced to introduce new > identifiers in order to define a setter? > > https://www.programiz.com/python-programming/property > self._temperature is where the value is actually stored. Suppose you had this instead: @temperature.setter def temperature(self, value): if value < -273: raise ValueError("Temperature below -273 is not possible") print("Setting value") self.temperature = value # <-- changed this line What would happen when you tried to set the temperature? Because of the last line, the setter would be calling itself recursively until it hit the maximum stack depth. A leading underscore is the normal convention to indicate that it should be treated as "private". If you wanted the temperature to be read-only, you'd make the value "private" and have a getter but not a setter. [snip] From no.email at nospam.invalid Sat Sep 30 21:54:48 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Sat, 30 Sep 2017 18:54:48 -0700 Subject: I'd like to use "semantic indentation" References: Message-ID: <878tgveion.fsf@nightsong.com> Chris Angelico writes: > USA: > Alabama: > Abbeville > Addison > ... > and then, as Paul suggested, write a simple parser to read it. That looks like YAML, which there's already a library for. I'm not crazy about it but it might be an ok choice for this.